Créer un site internet

HTML

In HTML

Inject Html In Page With Json Datas

By On 31/10/2023

Display json datas in your existing html page to debug

 


class fdiRender {
    constructor(element_id) {
        if (element_id == undefined)
            this.TARGETELEMENTID = "fdiPopup";
        else
            this.TARGETELEMENTID = element_id;
        this.element = document.getElementById(this.TARGETELEMENTID);
        //debugger;
        if (this.element == null) {
            let body = document.getElementsByTagName("body")[0];
            body.insertAdjacentHTML("afterbegin", "<div id='" + this.TARGETELEMENTID + "'>coucou</div>");
            this.element = document.getElementById(this.TARGETELEMENTID);
        }

        /*beforebegin (before an element)
        afterbegin (first child)
        beforeend (last child)
        afterend (after an element)*/

        this.buildCss();
        this.render();
    }

    buildCss() {

        this.css = {};
        this.css.container = "width: 100%;margin-right: auto;margin-left: auto;";
        this.css.row = "display: flex;flex-wrap: wrap;margin-top: calc(0);margin-right: 0.75rem;margin-left: 0.75rem;";
        this.css.col = "flex: 0 0 auto;width: 50%;";
        this.css.colArray = "flex: 0 0 auto;";
        this.css.border = "border: 1px solid black;padding: 0.15rem;";
    }

    render(obj) {

        if (obj != undefined && obj != null) {

            let keys = Object.keys(obj)

            let html = [];
            html.push("<div style='" + this.css.container + "' id='" + this.TARGETELEMENTID + "'>");
            for (let i = 0; i < keys.length; i++) {
                //rows
                html.push("<div style='" + this.css.row + "'>");

                //columns
                if (typeof (obj[keys[i]]) != typeof ([])) {
                    html.push("<div style='" + this.css.col + "'>");
                    html.push("<div style='" + this.css.border + "'>" + keys[i] + "</div>");
                    html.push("</div>");
                    html.push("<div style='" + this.css.col + "'>");
                    html.push("<div style='" + this.css.border + "'>" + obj[keys[i]] + "</div>");
                    html.push("</div>");
                } else {
                    html.push("<div style='" + this.css.col + "'>");
                    html.push("<div style='" + this.css.border + "'>" + keys[i] + "</div>");
                    html.push("</div>");
                    const css = this.css.colArray + "width: " + 100 / keys.length + "%;"
                    html.push("<div style='" + this.css.col + "'>");
                    html.push(this.renderArray(obj[keys[i]], true));
                    html.push("</div>");
                }

                html.push("</div>");//end row
            }
            html.push("</div>");
            this.element.innerHTML = html.join("");
            return;
        }

        this.element.innerHTML = "<div style='" + this.css.container + "' id='" + this.TARGETELEMENTID + "'>yes</div>";
    }

    renderArray(obj, isChild, exportCSV) {

        if (obj != undefined && obj != null && obj.length != undefined && obj.length > 0) {

            let keys = Object.keys(obj[0]);
            let exportCSVSTR = "";

            let html = [];
            if (isChild == undefined)
                html.push("<div class='demo' style='" + this.css.container + "' id='" + this.TARGETELEMENTID + "'>");
            const css = this.css.colArray + "width: " + 100 / keys.length + "%;"
            html.push("<div class='demo2' style='" + this.css.row + "'>");
            for (let i = 0; i < keys.length; i++) {//columns
                html.push("<div style='" + css + "'>");
                html.push("<div style='" + this.css.border + "'>" + keys[i] + "</div>");
                html.push("</div>");
                if (exportCSV != undefined)
                    exportCSVSTR += keys[i] + exportCSV;
            }
            exportCSVSTR += "\r\n";
            html.push("</div>");//end row


            for (let j = 0; j < obj.length; j++) {//elements in array
                html.push("<div style='" + this.css.row + "'>");
                for (let i = 0; i < keys.length; i++) {//columns
                    if (typeof (obj[j][keys[i]]) != typeof ([])) {
                        html.push("<div style='" + css + "'>");
                        html.push("<div style='" + this.css.border + "'>" + obj[j][keys[i]] + "</div>");
                        html.push("</div>");
                        if (exportCSV != undefined)
                            exportCSVSTR += obj[j][keys[i]] + exportCSV;
                    } else {
                        html.push("<div style='" + css + "'>");
                        html.push(this.renderArray(obj[j][keys[i]], true));
                        html.push("</div>");
                        if (exportCSV != undefined)
                            exportCSVSTR += "array" + exportCSV;
                    }
                }
                exportCSVSTR += "\r\n";

                html.push("</div>");//end row
            }

            //end div
            if (isChild == undefined)
                html.push("</div>");
            if (isChild == undefined)
                this.element.innerHTML = html.join("");
            console.log(exportCSVSTR);
            return html.join("");
        }
        this.element.innerHTML = "<div style='" + this.css.container + "' id='" + this.TARGETELEMENTID + "'>yes</div>";
    }
}

function test() {
    let fdi = new fdiRender();
    let obj1 = {
        "name": "toto",
        "age": 23,
        "town": "fontenay sous bois",
        "pays": "france"
    }
    let arr2 = [];
    arr2.push(obj1);
    arr2.push(obj1);
    arr2.push(obj1);

    let obj = {
        "name": "tata popo",
        "age": 28,
        "town": "Selestat",
        "pays": "france",
        "monTableau": arr2,
        "department": "Alsace"
    }
    let arr = [];
    arr.push(obj);
    arr.push(obj);
    arr.push(obj);
    arr.push(obj);
    //fdi.render(obj);
    fdi.renderArray(arr, undefined, ";");

}

Table
In HTML

Inject CSS with javascript in html page

By On 30/10/2023

How to inject css in your page with javascript

 


// The content of the stylesheet
const styleSheetContent = `
    .demo{
        background:red;
        color: yellow;
    }

    .demo2 {
        font-size: 1.2rem;
        color: black;
    }
`;

// Creates the style element
function createStyleElement(id, content) {
    var style = document.createElement("style");
    style.type = "text/css";
    style.id = id;
    style.innerHTML = content;

    if (style.styleSheet) {
        style.styleSheet.cssText = content;
    } else {
        let st = document.getElementById(id);
        if(st == undefined){
            var head = document.head || document.getElementsByTagName("head")[0];
            head.appendChild(style);
        } else {
            st.innerHTML = content;
        }
    }
    return style;
}

createStyleElement("fdiStyle", styleSheetContent);

 

In HTML

SPFX React Override Native CSS

By On 12/07/2023

How to override native SharePoint css in SPFX react webparts 

 


:global .webPartContainer{
  display: none;
}

 

In HTML

Css Add a Line Above

By On 05/12/2018

Add a line with css above an html element

 

salut Fred

html
 
 
css
 

When the text is too long and goes outside the div or span, add this : white-space: normal;

 

ul li in line



<ul style="display:inline; list-style: none;">
          <li  style="display:inline;"><div style="background-color: #FF0000;width: 8px;height: 8px;">&nbsp;</div></li>
          <li style="display:inline;">plop</li>
          <li style="display:inline;">plop</li>
          <li style="display:inline;">plop</li>
        </ul>
 display: inline; list-style: none;
In HTML

HTML templates

By On 03/11/2018

my html clipboard tool