{"version":3,"sources":["webpack:///./modules/responsive_table/responsive_table.js"],"names":["vpDetect","ViewportDetect","ResponsiveTableClass","container","_getHeights","scrollable","getElementsByTagName","map","tr","offsetHeight","_markFirstChildren","table","forEach","tableRow","children","className","_removeOriginalTable","parentNode","removeChild","removeWidthsAndHeights","removeAttribute","querySelectorAll","elm","_setHeights","pinned","heights","i","style","height","this","querySelector","switched","_updateTables","window","innerWidth","addCallback","d","w","call","track","tablesWrapper","document","createElement","setAttribute","appendChild","divclass","newTable","innerHTML","outerHTML","_processTable","_createAndPopulateTablesWrapper","_processHeights","width","_splitTable","_unsplitTable"],"mappings":"4lCAGA,IAAMA,E,MAAWC,KAEXC,E,WA+CJ,WAAYC,GAAY,IAAD,Q,4FAAA,cA7CvBC,YAAc,SAAAC,GAKZ,OAJkB,EAAOA,EAAWC,qBAAqB,OAE5BC,KAAI,SAAAC,GAAE,OAAIA,EAAGC,iBA0CrB,KApCvBC,mBAAqB,SAAAC,GACJ,EAAOA,EAAML,qBAAqB,OAEvCM,SAAQ,SAAAC,GAChBA,EAASC,SAAS,GAAGC,UAAY,oBAgCd,KA3BvBC,qBAAuB,SAAAL,GACrBA,EAAMM,WAAWC,YAAYP,IA0BR,KAvBvBQ,uBAAyB,SAAAR,GAWvB,OAVAA,EAAMS,gBAAgB,SACtBT,EAAMS,gBAAgB,UAEZ,EAAOT,EAAMU,iBAAiB,WAEnCT,SAAQ,SAAAU,GACXA,EAAIF,gBAAgB,SACpBE,EAAIF,gBAAgB,aAGfT,GAYc,KARvBY,YAAc,SAACC,EAAQC,GACP,EAAOD,EAAOlB,qBAAqB,OAExCM,SAAQ,SAACJ,EAAIkB,GACpBlB,EAAGmB,MAAMC,OAAT,UAAqBH,EAAQC,GAA7B,UAKFG,KAAK1B,UAAYA,EAAU2B,cAAc,YAElB,OAAnBD,KAAK1B,YACP0B,KAAK1B,UAAYA,EAAU2B,cAAc,qBAE3CD,KAAKE,UAAW,EAChBF,KAAKlB,MAAQkB,KAAK1B,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 'lodash';\nimport ViewportDetect from '@djforth/viewport-detection-fp';\n\nconst vpDetect = ViewportDetect();\n\nclass ResponsiveTableClass {\n // Get the heights of the scrollable table rows\n _getHeights = scrollable => {\n const trScrollable = [...scrollable.getElementsByTagName('tr')];\n\n const heights = trScrollable.map(tr => tr.offsetHeight);\n\n return heights;\n };\n\n // Add a \"first\" class to the first children of each row\n _markFirstChildren = table => {\n const tableRows = [...table.getElementsByTagName('tr')];\n\n tableRows.forEach(tableRow => {\n tableRow.children[0].className = 'first-element';\n });\n };\n\n // Remove the original table from the DOM\n _removeOriginalTable = table => {\n table.parentNode.removeChild(table);\n };\n\n removeWidthsAndHeights = table => {\n table.removeAttribute('width');\n table.removeAttribute('height');\n\n const elms = [...table.querySelectorAll('tr, td')];\n\n elms.forEach(elm => {\n elm.removeAttribute('width');\n elm.removeAttribute('height');\n });\n\n return table;\n };\n\n // Set the heights of the pinned table rows\n _setHeights = (pinned, heights) => {\n const trPinned = [...pinned.getElementsByTagName('tr')];\n\n trPinned.forEach((tr, i) => {\n tr.style.height = `${heights[i]}px`;\n });\n };\n\n constructor(container) {\n this.container = container.querySelector('.tinymce');\n // Really nasty - I need to re-factor this module. IH 01/04/16\n if (this.container === null) {\n this.container = container.querySelector('.table-container');\n }\n this.switched = false;\n this.table = this.container.querySelector('table');\n\n if (isElement(this.container) && isElement(this.table)) {\n this._updateTables(window.innerWidth);\n\n vpDetect.addCallback((d, w) => {\n this._updateTables.call(this, w);\n });\n\n vpDetect.track();\n }\n }\n\n // Create a tables wrapper div for both tables\n _createAndPopulateTablesWrapper(pinned, scrollable) {\n const tablesWrapper = document.createElement('div');\n\n tablesWrapper.setAttribute('class', 'table-wrapper');\n\n // Append the new tables into the tables wrapper\n tablesWrapper.appendChild(pinned);\n tablesWrapper.appendChild(scrollable);\n\n // Append the tables wrapper to the container\n this.container.appendChild(tablesWrapper);\n\n return tablesWrapper;\n }\n\n // Process the table row heights\n _processHeights(pinned, scrollable) {\n const heights = this._getHeights(scrollable);\n\n this._setHeights(pinned, heights);\n }\n\n // Create a wrapper div for each table\n _processTable(table, divclass) {\n const newTable = document.createElement('div');\n\n newTable.setAttribute('class', divclass);\n newTable.innerHTML = table.outerHTML;\n\n this._markFirstChildren(newTable);\n\n return newTable;\n }\n\n // Split the original table into two separate tables\n _splitTable(table) {\n // Remove the original table from the DOM\n this._removeOriginalTable(table);\n\n // Process the pinned table\n this.pinned = this._processTable(this.removeWidthsAndHeights(table), 'pinned');\n\n // Process the scrollable table\n this.scrollable = this._processTable(table, 'scrollable');\n\n // Create a tables wrapper div for both tables\n this.tablesWrapper = this._createAndPopulateTablesWrapper(this.pinned, this.scrollable);\n\n // Set the heights of the pinned table based on the scrollable table\n this._processHeights(this.pinned, this.scrollable);\n }\n\n _unsplitTable(table) {\n // Remove the pinned table from the DOM\n this.pinned.parentNode.removeChild(this.pinned);\n\n // Remove the tables wrapper from the DOM\n this.tablesWrapper.parentNode.removeChild(this.tablesWrapper);\n\n // Append the original table to the container\n this.container.appendChild(table);\n }\n\n _updateTables(width) {\n if (width <= 768 && !this.switched) {\n this.switched = true;\n this._splitTable(this.table);\n } else if (width > 768 && this.switched) {\n this.switched = false;\n this._unsplitTable(this.table);\n }\n }\n}\n\nexport default ResponsiveTableClass;\n"],"sourceRoot":""}