datatable: previous commit was reverted, but apply the usable parts - jscancer - Javascript crap (relatively small)
 (HTM) git clone git://git.codemadness.org/jscancer
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit d5d0f00c5141d8df1bcdb7d659a7ee553d3c6ec4
 (DIR) parent c1bcedb1c1fc7c5869121f632a5c2ce5c369ae4a
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Thu, 17 Aug 2017 19:04:57 +0200
       
       datatable: previous commit was reverted, but apply the usable parts
       
       The previous commit used cloneNode which had undefined behaviour in
       this case.
       
       Diffstat:
         M datatable/datatable.js              |      26 ++++++++------------------
       
       1 file changed, 8 insertions(+), 18 deletions(-)
       ---
 (DIR) diff --git a/datatable/datatable.js b/datatable/datatable.js
       @@ -8,16 +8,10 @@ function datatable_sort_default(x, y) {
        }
        
        function datatable_init(el) {
       -        var thead = el.getElementsByTagName("thead");
       -        if (!thead.length)
       -                return null;
       -        var tbody = el.getElementsByTagName("tbody");
       -        if (!tbody.length)
       -                return null;
       -        var ths = thead[0].children[0].children;
       -        if (!ths.length)
       -                return null;
       -        var cols = [];
       +        var thead = el.tHead,
       +            tbody = el.tBodies[0];
       +        var ths = thead.children[0].children,
       +            cols = [];
                for (var i = 0; i < ths.length; i++)
                        cols.push({
                                filterable: ["1", "true"].indexOf(ths[i].getAttribute("data-filterable")   || "true") != -1,
       @@ -27,9 +21,9 @@ function datatable_init(el) {
                        });
                var d = {
                        table: el,
       -                thead: thead[0],
       +                thead: thead,
                        ths:   ths,
       -                tbody: tbody[0],
       +                tbody: tbody,
                        cols:  cols,
                        sort:  [], // sort options: [colidx, order (ASC = 0, DESC = 1)].
                        lazyscroll: ["1", "true"].indexOf(el.getAttribute("data-lazyscroll") || "") != -1,
       @@ -40,9 +34,7 @@ function datatable_init(el) {
                if (d.lazyscroll) {
                        var bodytable = document.createElement("table");
                        bodytable.className = el.className;
       -                bodytable.setAttribute("cellspacing", "0");
       -                bodytable.setAttribute("cellpadding", "0");
       -                bodytable.setAttribute("border", "0");
       +                bodytable.cellSpacing = bodytable.cellPadding = bodytable.border = "0";
        
                        var tr = document.createElement("tr");
                        for (var i = 0; i < ths.length; i++) {
       @@ -62,9 +54,7 @@ function datatable_init(el) {
                        elthead.appendChild(tr);
        
                        var headerstable = document.createElement("table");
       -                headerstable.setAttribute("cellspacing", "0");
       -                headerstable.setAttribute("cellpadding", "0");
       -                headerstable.setAttribute("border", "0");
       +                headerstable.cellSpacing = headerstable.cellPadding = headerstable.border = "0";
                        headerstable.className = el.className;
                        headerstable.appendChild(elthead);