Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

column-resizer

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

column-resizer - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

15

CHANGELOG.md

@@ -0,1 +1,16 @@

<a name="v1.0.3"></a>
# [v1.1.0](https://github.com/MonsantoCo/column-resizer/compare/v1.0.3...v1.1.0) (2018-05-29)
## Bug fixes
## Enhancement
* Updates to dependencies([4eb2351](https://github.com/MonsantoCo/column-resizer/commit/4eb2351f298728318bce55b1067857bcaca86b4f))
* Better documentation.
<a name="v1.0.3"></a>
# [v1.0.3](https://github.com/MonsantoCo/column-resizer/compare/v1.0.2...v1.0.3) (2018-05-16)
## Bug fixes
* Fix text selection prevention([c90e486](https://github.com/MonsantoCo/column-resizer/commit/c90e486004482cf41957d55bb55b91637010a0b1))
## Enhancement
<a name="v1.0.2"></a>

@@ -2,0 +17,0 @@ # [v1.0.2](https://github.com/MonsantoCo/column-resizer/compare/v1.0.1...v1.0.2) (2017-09-12)

2

dist/column-resizer.js

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ColumnResizer=t():e.ColumnResizer=t()}(this,function(){return function(e){function t(i){if(r[i])return r[i].exports;var o=r[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var r={};return t.m=e,t.c=r,t.d=function(e,r,i){t.o(e,r)||Object.defineProperty(e,r,{configurable:!1,enumerable:!0,get:i})},t.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(r,"a",r),r},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="/",t(t.s=0)}([function(e,t,r){"use strict";function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var o=r(1),n=function(e){return e&&e.__esModule?e:{default:e}}(o),l=function(){var e=0;return function(){return e++}}(),a=function e(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};i(this,e),s.call(this);try{this.store=sessionStorage}catch(t){this.store={}}this.grip=null,this.tb=t,window.addEventListener("resize",this.onResize),this.init(r)},s=function(){var e=this;this.ID="id",this.PX="px",this.RESIZABLE="grip-resizable",this.FLEX="grip-flex",this.IE=navigator.userAgent.indexOf("Trident/4.0")>0,this.reset=function(t){return e.init(t)},this.onResize=function(){var t=e.tb;if(t.classList.remove(e.RESIZABLE),t.opt.fixed){t.tableWidth=Number(window.getComputedStyle(t).width.replace(/px/,"")).valueOf();for(var r=0,i=0;i<t.columnCnt;i++)r+=t.columns[i].w;for(var o=0;o<t.columnCnt;o++)t.columns[o].style.width=Math.round(1e3*t.columns[o].w/r)/10+"%",t.columns[o].locked=!0}else e.applyBounds(),"flex"===t.opt.resizeMode&&e.serializeStore();t.classList.add(e.RESIZABLE),e.syncGrips()},this.onGripMouseDown=function(t){var r=t.target.parentNode.data,i=e.tb,o=i.grips[r.i],n=t.touches;if(o.ox=n?n[0].pageX:t.pageX,o.l=o.offsetLeft,o.x=o.l,e.createStyle(document.querySelector("head"),"*{cursor:"+i.opt.dragCursor+"!important}"),document.addEventListener("touchmove",e.onGripDrag),document.addEventListener("mousemove",e.onGripDrag),document.addEventListener("touchend",e.onGripDragOver),document.addEventListener("mouseup",e.onGripDragOver),o.classList.add(i.opt.draggingClass),e.grip=o,i.columns[r.i].locked)for(var l,a=0;a<i.columnCnt;a++)l=i.columns[a],l.locked=!1,l.w=Number(window.getComputedStyle(l).width.replace(/px/,"")).valueOf();t.preventDefault()},this.onGripDrag=function(t){var r=e.grip;if(r){var i=r.t,o=t.touches,n=o?o[0].pageX:t.pageX,l=n-r.ox+r.l,a=i.opt.minWidth,s=r.i,d=1.5*i.cellSpace+a+i.borderSpace,u=s===i.columnCnt-1,c=s?i.grips[s-1].offsetLeft+i.cellSpace+a:d,p=i.opt.fixed?s===i.columnCnt-1?i.tableWidth-d:i.grips[s+1].offsetLeft-i.cellSpace-a:1/0;if(l=Math.max(c,Math.min(p,l)),r.x=l,r.style.left=l+e.PX,u&&(r.w=i.columns[s].w+l-r.l),i.opt.liveDrag){u?(i.columns[s].style.width=r.w+e.PX,!i.opt.fixed&&i.opt.overflow?i.style.minWidth=i.tableWidth+l-r.l+e.PX:i.tableWidth=Number(window.getComputedStyle(i).width.replace(/px/,"")).valueOf()):e.syncCols(i,s,!1,i.opt),e.syncGrips();var f=i.opt.onDrag;f&&f(t)}return!1}},this.onGripDragOver=function(t){var r=e.grip;document.removeEventListener("touchend",e.onGripDragOver),document.removeEventListener("mouseup",e.onGripDragOver),document.removeEventListener("touchmove",e.onGripDrag),document.removeEventListener("mousemove",e.onGripDrag);var i=document.querySelector("head").lastChild;if(i.parentNode.removeChild(i),r){if(r.classList.remove(r.t.opt.draggingClass),r.x-r.l!=0){var o=r.t,n=o.opt.onResize,l=r.i;if(l===o.columnCnt-1){var a=o.columns[l];a.style.width=r.w+e.PX,a.w=r.w}else e.syncCols(o,l,!0,o.opt);o.opt.fixed||e.applyBounds(),e.syncGrips(),n&&n(t),e.serializeStore()}e.grip=null}},this.init=function(t){if(t.disable)return e.destroy();var r=e.tb,i=r.getAttribute(e.ID)||e.RESIZABLE+l();if(!r.matches("table")||r.extended&&!t.partialRefresh)return null;var o=document.querySelector("head");if(e.createStyle(o," .grip-resizable{table-layout:fixed;} .grip-resizable > tbody > tr > td, .grip-resizable > tbody > tr > th{overflow:hidden} .grip-padding > tbody > tr > td, .grip-padding > tbody > tr > th{padding-left:0!important; padding-right:0!important;} .grip-container{ height:0px; position:relative;} .grip-handle{margin-left:-5px; position:absolute; z-index:5; } .grip-handle .grip-resizable{position:absolute;background-color:red;filter:alpha(opacity=1);opacity:0;width:10px;height:100%;cursor: col-resize;top:0px} .grip-lastgrip{position:absolute; width:1px; } .grip-drag{ border-left:1px dotted black;\t} .grip-flex{width:auto!important;} .grip-handle.grip-disabledgrip .grip-resizable{cursor:default; display:none;}"),t.hoverCursor&&"col-resize"!==t.hoverCursor){var n=".grip-handle .grip-resizable:hover{cursor:"+t.hoverCursor+"!important}";e.createStyle(o,n)}r.setAttribute(e.ID,i);var a=r.opt;r.opt=e.extendOptions(t);var s=e.getTableHeaders(r);if(e.extendTable(s),t.remoteTable&&t.remoteTable.matches("table")){var d=e.getTableHeaders(r.opt.remoteTable);s.length===d.length?e.extendRemoteTable(r.opt.remoteTable,d,r):console.warn("column count for remote table did not match")}return a},this.applyBounds=function(){var t=e.tb,r=t.columns.map(function(e){return window.getComputedStyle(e).width});t.style.width=window.getComputedStyle(t).width,t.tableWidth=Number(t.style.width.replace(/px/,"")).valueOf(),t.classList.remove(e.FLEX),t.columns.forEach(function(e,t){e.style.width=r[t],e.w=Number(e.style.width.replace(/px/,"")).valueOf()}),t.opt.fixed||t.classList.add(e.FLEX)},this.serializeStore=function(){var t=e.store,r=e.tb;t[r.getAttribute(e.ID)]="";for(var i=0,o=0;o<r.columns.length;o++){var n=window.getComputedStyle(r.columns[o]).width.replace(/px/,"");t[r.getAttribute(e.ID)]+=n+";",i+=Number(n).valueOf()}t[r.getAttribute(e.ID)]+=i.toString(),r.opt.fixed||(t[r.getAttribute(e.ID)]+=";"+window.getComputedStyle(r).width.replace(/px/,""))},this.syncGrips=function(){var t=e.tb;t.gripContainer.style.width=t.tableWidth+e.PX;for(var r=0;r<t.columnCnt;r++){var i=t.columns[r];t.opt.widths[r]=i.w;var o=i.getBoundingClientRect(),n=t.getBoundingClientRect();t.grips[r].style.left=o.left-n.left+i.offsetWidth+t.cellSpace/2+e.PX,t.grips[r].style.height=(t.opt.headerOnly?t.columns[0].offsetHeight:t.offsetHeight)+e.PX}},this.destroy=function(){var t=e.tb,r=t.getAttribute(e.ID);if(r)return e.store[r]="",t.classList.remove(e.RESIZABLE),t.classList.remove(e.FLEX),t.remote&&(t.remote.classList.remove(e.RESIZABLE),t.remote.classList.remove(e.FLEX)),t.gripContainer&&t.gripContainer.parentNode&&t.gripContainer.parentNode.removeChild(t.gripContainer),delete t.extended,t.opt},this.createStyle=function(e,t){var r=(0,n.default)(t).toString(),i=e.querySelectorAll("style");if(!Array.from(i).filter(function(e){return e.gripid===r}).length){var o=document.createElement("style");o.type="text/css",o.gripid=r,o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t)),e.appendChild(o)}},this.extendOptions=function(e){var t=Object.assign({},a.DEFAULTS,e);switch(t.fixed=!0,t.overflow=!1,t.resizeMode){case"flex":t.fixed=!1;break;case"overflow":t.fixed=!1,t.overflow=!0}return t},this.getTableHeaders=function(t){var r="#"+t.id,i=Array.from(t.querySelectorAll(r+">thead>tr:nth-of-type(1)>th"));return i=i.concat(Array.from(t.querySelectorAll(r+">thead>tr:nth-of-type(1)>td"))),i.length||(i=Array.from(t.querySelectorAll(r+">tbody>tr:nth-of-type(1)>th")),i=i.concat(Array.from(t.querySelectorAll(r+">tr:nth-of-type(1)>th"))),i=i.concat(Array.from(t.querySelectorAll(r+">tbody>tr:nth-of-type(1)>td"))),i=i.concat(Array.from(t.querySelectorAll(r+">tr:nth-of-type(1)>td")))),e.filterInvisible(i,!1)},this.filterInvisible=function(e,t){return e.filter(function(e){var r=t?-1:e.offsetWidth,i=t?-1:e.offsetHeight;return!(0===r&&0===i||e.style&&e.style.display&&"none"===window.getComputedStyle(e).display)})},this.extendTable=function(t){var r=e.tb;r.opt.removePadding&&r.classList.add("grip-padding"),r.classList.add(e.RESIZABLE),r.insertAdjacentHTML("beforebegin",'<div class="grip-container"/>'),r.grips=[],r.columns=[],r.tableWidth=Number(window.getComputedStyle(r).width.replace(/px/,"")).valueOf(),r.gripContainer=r.previousElementSibling,r.opt.marginLeft&&(r.gripContainer.style.marginLeft=r.opt.marginLeft),r.opt.marginRight&&(r.gripContainer.style.marginRight=r.opt.marginRight),r.cellSpace=parseInt(e.IE?r.cellSpacing||r.currentStyle.borderSpacing:window.getComputedStyle(r).borderSpacing.split(" ")[0].replace(/px/,""))||2,r.borderSpace=parseInt(e.IE?r.border||r.currentStyle.borderLeftWidth:window.getComputedStyle(r).borderLeftWidth.replace(/px/,""))||1,r.extended=!0,e.createGrips(t)},this.extendRemoteTable=function(t,r,i){i.opt.removePadding&&t.classList.add("grip-padding"),t.classList.add(e.RESIZABLE),t.getAttribute(e.ID)||t.setAttribute(e.ID,i.getAttribute(e.ID)+"remote"),t.columns=[],r.forEach(function(o,n){var l=r[n];l.w=i.columns[n].w,l.style.width=l.w+e.PX,l.removeAttribute("width"),t.columns.push(l)}),t.tableWidth=i.tableWidth,t.cellSpace=i.cellSpace,t.borderSpace=i.borderSpace;var o=Array.from(t.querySelectorAll("col"));t.columnGrp=e.filterInvisible(o,!0),t.columnGrp.forEach(function(e,t){e.removeAttribute("width"),e.style.width=i.columnGrp[t].style.width}),i.remote=t},this.createGrips=function(t){var r=e.tb;r.columnGrp=e.filterInvisible(Array.from(r.querySelectorAll("col")),!0),r.columnGrp.forEach(function(e){e.removeAttribute("width")}),r.columnCnt=t.length,e.store[r.getAttribute(e.ID)]&&e.deserializeStore(t),r.opt.widths||(r.opt.widths=[]),t.forEach(function(i,o){var n=t[o],l=-1!==r.opt.disabledColumns.indexOf(o);e.createDiv(r.gripContainer,"grip-handle");var a=r.gripContainer.lastChild;!l&&r.opt.gripInnerHtml&&(a.innerHTML=r.opt.gripInnerHtml),e.createDiv(a,e.RESIZABLE),o===r.columnCnt-1&&(a.classList.add("grip-lastgrip"),r.opt.fixed&&(a.innerHTML="")),a.addEventListener("touchstart",e.onGripMouseDown,{capture:!0,passive:!0}),a.addEventListener("mousedown",e.onGripMouseDown,!0),l?a.classList.add("grip-disabledgrip"):(a.classList.remove("grip-disabledgrip"),a.addEventListener("touchstart",e.onGripMouseDown,{capture:!0,passive:!0}),a.addEventListener("mousedown",e.onGripMouseDown,!0)),a.t=r,a.i=o,r.opt.widths[o]?n.w=r.opt.widths[o]:(n.w=Number(window.getComputedStyle(n).width.replace(/px/,"")).valueOf(),r.opt.widths[o]=n.w),n.style.width=n.w+e.PX,n.removeAttribute("width"),a.data={i:o,t:r.getAttribute(e.ID),last:o===r.columnCnt-1},r.grips.push(a),r.columns.push(n)});var i=Array.from(r.querySelectorAll("td"));i.concat(Array.from(r.querySelectorAll("th"))),i=i.filter(function(e){for(var r=0;r<t.length;r++)if(t[r]===e)return!1;return!0}),i=i.filter(function(e){return!(e.querySelectorAll("table th").length||e.querySelectorAll("table td").length)}),i.forEach(function(e){e.removeAttribute("width")}),r.opt.fixed||(r.removeAttribute("width"),r.classList.add(e.FLEX)),e.syncGrips()},this.deserializeStore=function(t){var r=e.tb;if(r.columnGrp.forEach(function(e){e.removeAttribute("width")}),r.opt.flush)return void(e.store[r.getAttribute(e.ID)]="");var i=e.store[r.getAttribute(e.ID)].split(";"),o=i[r.columnCnt+1];!r.opt.fixed&&o&&(r.style.width=o+e.PX,r.opt.overflow&&(r.style.minWidth=o+e.PX,r.tableWidth=Number(o).valueOf()));for(var n=0;n<r.columnCnt;n++){var l=100*Number(i[n]).valueOf()/Number(i[r.columnCnt]).valueOf()+"%";t[n].style.width=l,r.columnGrp[n]&&(r.columnGrp[n].style.width=l)}},this.createDiv=function(e,t,r){var i=document.createElement("div");i.classList.add(t),r&&(i.innerHTML=r),e.appendChild(i)},this.syncCols=function(t,r,i,o){var n=t.remote,l=e.grip.x-e.grip.l,a=t.columns[r],s=t.columns[r+1];if(a&&s){var d=a.w+l,u=s.w-l,c=d+e.PX;if(a.style.width=c,t.columnGrp[r]&&t.columnGrp[r].style.width&&(t.columnGrp[r].style.width=c),n&&(n.columns[r].style.width=c,n.columnGrp[r]&&n.columnGrp[r].style.width&&(n.columnGrp[r].style.width=c)),o.fixed){var p=u+e.PX;s.style.width=p,t.columnGrp[r+1]&&t.columnGrp[r+1].style.width&&(t.columnGrp[r+1].style.width=p),n&&(n.columns[r+1].style.width=p,n.columnGrp[r+1]&&n.columnGrp[r+1].style.width&&(n.columnGrp[r+1].style.width=p))}else o.overflow&&(t.style.minWidth=t.tableWidth+l+e.PX);i&&(a.w=d,s.w=o.fixed?u:s.w,n&&(n.columns[r].w=d,n.columns[r+1].w=o.fixed?u:s.w))}}};t.default=a,a.DEFAULTS={resizeMode:"fit",draggingClass:"grip-drag",gripInnerHtml:"",liveDrag:!1,minWidth:15,headerOnly:!1,hoverCursor:"col-resize",dragCursor:"col-resize",flush:!1,marginLeft:null,marginRight:null,remoteTable:null,disable:!1,partialRefresh:!1,disabledColumns:[],removePadding:!0,widths:[],onDrag:null,onResize:null}},function(e,t,r){"use strict";function i(e){for(var t=5381,r=e.length;r;)t=33*t^e.charCodeAt(--r);return t>>>0}e.exports=i}])});
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ColumnResizer=t():e.ColumnResizer=t()}(window,function(){return function(e){var t={};function __webpack_require__(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,__webpack_require__),i.l=!0,i.exports}return __webpack_require__.m=e,__webpack_require__.c=t,__webpack_require__.d=function(e,t,r){__webpack_require__.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},__webpack_require__.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},__webpack_require__.t=function(e,t){if(1&t&&(e=__webpack_require__(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(__webpack_require__.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)__webpack_require__.d(r,i,function(t){return e[t]}.bind(null,i));return r},__webpack_require__.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return __webpack_require__.d(t,"a",t),t},__webpack_require__.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},__webpack_require__.p="/",__webpack_require__(__webpack_require__.s=1)}([function(e,t,r){"use strict";e.exports=function(e){for(var t=5381,r=e.length;r;)t=33*t^e.charCodeAt(--r);return t>>>0}},function(e,t,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var i,o=r(0),n=(i=o)&&i.__esModule?i:{default:i};var l,a=(l=0,function(){return l++}),s=function ColumnResizer(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,ColumnResizer),d.call(this);try{this.store=sessionStorage}catch(e){this.store={}}this.grip=null,this.tb=e,window.addEventListener("resize",this.onResize),this.init(t)},d=function(){var e=this;this.ID="id",this.PX="px",this.RESIZABLE="grip-resizable",this.FLEX="grip-flex",this.IE=navigator.userAgent.indexOf("Trident/4.0")>0,this.reset=function(t){return e.init(t)},this.onResize=function(){var t=e.tb;if(t.classList.remove(e.RESIZABLE),t.opt.fixed){t.tableWidth=Number(window.getComputedStyle(t).width.replace(/px/,"")).valueOf();for(var r=0,i=0;i<t.columnCnt;i++)r+=t.columns[i].w;for(var o=0;o<t.columnCnt;o++)t.columns[o].style.width=Math.round(1e3*t.columns[o].w/r)/10+"%",t.columns[o].locked=!0}else e.applyBounds(),"flex"===t.opt.resizeMode&&e.serializeStore();t.classList.add(e.RESIZABLE),e.syncGrips()},this.onGripMouseDown=function(t){var r=t.target.parentNode.data,i=e.tb,o=i.grips[r.i],n=t.touches;if(o.ox=n?n[0].pageX:t.pageX,o.l=o.offsetLeft,o.x=o.l,e.createStyle(document.querySelector("head"),"*{cursor:"+i.opt.dragCursor+"!important}"),document.addEventListener("touchmove",e.onGripDrag),document.addEventListener("mousemove",e.onGripDrag),document.addEventListener("touchend",e.onGripDragOver),document.addEventListener("mouseup",e.onGripDragOver),o.classList.add(i.opt.draggingClass),e.grip=o,i.columns[r.i].locked)for(var l,a=0;a<i.columnCnt;a++)(l=i.columns[a]).locked=!1,l.w=Number(window.getComputedStyle(l).width.replace(/px/,"")).valueOf();t.preventDefault()},this.onGripDrag=function(t){var r=e.grip;if(r){var i=r.t,o=t.touches,n=(o?o[0].pageX:t.pageX)-r.ox+r.l,l=i.opt.minWidth,a=r.i,s=1.5*i.cellSpace+l+i.borderSpace,d=a===i.columnCnt-1,u=a?i.grips[a-1].offsetLeft+i.cellSpace+l:s,c=i.opt.fixed?a===i.columnCnt-1?i.tableWidth-s:i.grips[a+1].offsetLeft-i.cellSpace-l:1/0;if(n=Math.max(u,Math.min(c,n)),r.x=n,r.style.left=n+e.PX,d&&(r.w=i.columns[a].w+n-r.l),i.opt.liveDrag){d?(i.columns[a].style.width=r.w+e.PX,!i.opt.fixed&&i.opt.overflow?i.style.minWidth=i.tableWidth+n-r.l+e.PX:i.tableWidth=Number(window.getComputedStyle(i).width.replace(/px/,"")).valueOf()):e.syncCols(i,a,!1,i.opt),e.syncGrips();var p=i.opt.onDrag;p&&p(t)}t.preventDefault()}},this.onGripDragOver=function(t){var r=e.grip;document.removeEventListener("touchend",e.onGripDragOver),document.removeEventListener("mouseup",e.onGripDragOver),document.removeEventListener("touchmove",e.onGripDrag),document.removeEventListener("mousemove",e.onGripDrag);var i=document.querySelector("head").lastChild;if(i.parentNode.removeChild(i),r){if(r.classList.remove(r.t.opt.draggingClass),r.x-r.l!=0){var o=r.t,n=o.opt.onResize,l=r.i;if(l===o.columnCnt-1){var a=o.columns[l];a.style.width=r.w+e.PX,a.w=r.w}else e.syncCols(o,l,!0,o.opt);o.opt.fixed||e.applyBounds(),e.syncGrips(),n&&n(t),e.serializeStore()}e.grip=null}},this.init=function(t){if(t.disable)return e.destroy();var r=e.tb,i=r.getAttribute(e.ID)||e.RESIZABLE+a();if(!r.matches("table")||r.extended&&!t.partialRefresh)return null;var o=document.querySelector("head");if(e.createStyle(o," .grip-resizable{table-layout:fixed;} .grip-resizable > tbody > tr > td, .grip-resizable > tbody > tr > th{overflow:hidden} .grip-padding > tbody > tr > td, .grip-padding > tbody > tr > th{padding-left:0!important; padding-right:0!important;} .grip-container{ height:0px; position:relative;} .grip-handle{margin-left:-5px; position:absolute; z-index:5; } .grip-handle .grip-resizable{position:absolute;background-color:red;filter:alpha(opacity=1);opacity:0;width:10px;height:100%;cursor: col-resize;top:0px} .grip-lastgrip{position:absolute; width:1px; } .grip-drag{ border-left:1px dotted black;\t} .grip-flex{width:auto!important;} .grip-handle.grip-disabledgrip .grip-resizable{cursor:default; display:none;}"),t.hoverCursor&&"col-resize"!==t.hoverCursor){var n=".grip-handle .grip-resizable:hover{cursor:"+t.hoverCursor+"!important}";e.createStyle(o,n)}r.setAttribute(e.ID,i);var l=r.opt;r.opt=e.extendOptions(t);var s=e.getTableHeaders(r);if(e.extendTable(s),t.remoteTable&&t.remoteTable.matches("table")){var d=e.getTableHeaders(r.opt.remoteTable);s.length===d.length?e.extendRemoteTable(r.opt.remoteTable,d,r):console.warn("column count for remote table did not match")}return l},this.applyBounds=function(){var t=e.tb,r=t.columns.map(function(e){return window.getComputedStyle(e).width});t.style.width=window.getComputedStyle(t).width,t.tableWidth=Number(t.style.width.replace(/px/,"")).valueOf(),t.classList.remove(e.FLEX),t.columns.forEach(function(e,t){e.style.width=r[t],e.w=Number(e.style.width.replace(/px/,"")).valueOf()}),t.opt.fixed||t.classList.add(e.FLEX)},this.serializeStore=function(){var t=e.store,r=e.tb;t[r.getAttribute(e.ID)]="";for(var i=0,o=0;o<r.columns.length;o++){var n=window.getComputedStyle(r.columns[o]).width.replace(/px/,"");t[r.getAttribute(e.ID)]+=n+";",i+=Number(n).valueOf()}t[r.getAttribute(e.ID)]+=i.toString(),r.opt.fixed||(t[r.getAttribute(e.ID)]+=";"+window.getComputedStyle(r).width.replace(/px/,""))},this.syncGrips=function(){var t=e.tb;t.gripContainer.style.width=t.tableWidth+e.PX;for(var r=0;r<t.columnCnt;r++){var i=t.columns[r];t.opt.widths[r]=i.w;var o=i.getBoundingClientRect(),n=t.getBoundingClientRect();t.grips[r].style.left=o.left-n.left+i.offsetWidth+t.cellSpace/2+e.PX,t.grips[r].style.height=(t.opt.headerOnly?t.columns[0].offsetHeight:t.offsetHeight)+e.PX}},this.destroy=function(){var t=e.tb,r=t.getAttribute(e.ID);return r?(e.store[r]="",t.classList.remove(e.RESIZABLE),t.classList.remove(e.FLEX),t.remote&&(t.remote.classList.remove(e.RESIZABLE),t.remote.classList.remove(e.FLEX)),t.gripContainer&&t.gripContainer.parentNode&&t.gripContainer.parentNode.removeChild(t.gripContainer),delete t.extended,t.opt):null},this.createStyle=function(e,t){var r=(0,n.default)(t).toString(),i=e.querySelectorAll("style");if(!Array.from(i).filter(function(e){return e.gripid===r}).length){var o=document.createElement("style");o.type="text/css",o.gripid=r,o.styleSheet?o.styleSheet.cssText=t:o.appendChild(document.createTextNode(t)),e.appendChild(o)}},this.extendOptions=function(e){var t=Object.assign({},s.DEFAULTS,e);switch(t.fixed=!0,t.overflow=!1,t.resizeMode){case"flex":t.fixed=!1;break;case"overflow":t.fixed=!1,t.overflow=!0}return t},this.getTableHeaders=function(t){var r="#"+t.id,i=Array.from(t.querySelectorAll(r+">thead>tr:nth-of-type(1)>th"));return(i=i.concat(Array.from(t.querySelectorAll(r+">thead>tr:nth-of-type(1)>td")))).length||(i=(i=(i=(i=Array.from(t.querySelectorAll(r+">tbody>tr:nth-of-type(1)>th"))).concat(Array.from(t.querySelectorAll(r+">tr:nth-of-type(1)>th")))).concat(Array.from(t.querySelectorAll(r+">tbody>tr:nth-of-type(1)>td")))).concat(Array.from(t.querySelectorAll(r+">tr:nth-of-type(1)>td")))),e.filterInvisible(i,!1)},this.filterInvisible=function(e,t){return e.filter(function(e){var r=t?-1:e.offsetWidth,i=t?-1:e.offsetHeight;return!(0===r&&0===i||e.style&&e.style.display&&"none"===window.getComputedStyle(e).display||!1)})},this.extendTable=function(t){var r=e.tb;r.opt.removePadding&&r.classList.add("grip-padding"),r.classList.add(e.RESIZABLE),r.insertAdjacentHTML("beforebegin",'<div class="grip-container"/>'),r.grips=[],r.columns=[],r.tableWidth=Number(window.getComputedStyle(r).width.replace(/px/,"")).valueOf(),r.gripContainer=r.previousElementSibling,r.opt.marginLeft&&(r.gripContainer.style.marginLeft=r.opt.marginLeft),r.opt.marginRight&&(r.gripContainer.style.marginRight=r.opt.marginRight),r.cellSpace=parseInt(e.IE?r.cellSpacing||r.currentStyle.borderSpacing:window.getComputedStyle(r).borderSpacing.split(" ")[0].replace(/px/,""))||2,r.borderSpace=parseInt(e.IE?r.border||r.currentStyle.borderLeftWidth:window.getComputedStyle(r).borderLeftWidth.replace(/px/,""))||1,r.extended=!0,e.createGrips(t)},this.extendRemoteTable=function(t,r,i){i.opt.removePadding&&t.classList.add("grip-padding"),t.classList.add(e.RESIZABLE),t.getAttribute(e.ID)||t.setAttribute(e.ID,i.getAttribute(e.ID)+"remote"),t.columns=[],r.forEach(function(o,n){var l=r[n];l.w=i.columns[n].w,l.style.width=l.w+e.PX,l.removeAttribute("width"),t.columns.push(l)}),t.tableWidth=i.tableWidth,t.cellSpace=i.cellSpace,t.borderSpace=i.borderSpace;var o=Array.from(t.querySelectorAll("col"));t.columnGrp=e.filterInvisible(o,!0),t.columnGrp.forEach(function(e,t){e.removeAttribute("width"),e.style.width=i.columnGrp[t].style.width}),i.remote=t},this.createGrips=function(t){var r=e.tb;r.columnGrp=e.filterInvisible(Array.from(r.querySelectorAll("col")),!0),r.columnGrp.forEach(function(e){e.removeAttribute("width")}),r.columnCnt=t.length,e.store[r.getAttribute(e.ID)]&&e.deserializeStore(t),r.opt.widths||(r.opt.widths=[]),t.forEach(function(i,o){var n=t[o],l=-1!==r.opt.disabledColumns.indexOf(o);e.createDiv(r.gripContainer,"grip-handle");var a=r.gripContainer.lastChild;!l&&r.opt.gripInnerHtml&&(a.innerHTML=r.opt.gripInnerHtml),e.createDiv(a,e.RESIZABLE),o===r.columnCnt-1&&(a.classList.add("grip-lastgrip"),r.opt.fixed&&(a.innerHTML="")),a.addEventListener("touchstart",e.onGripMouseDown,{capture:!0,passive:!0}),a.addEventListener("mousedown",e.onGripMouseDown,!0),l?a.classList.add("grip-disabledgrip"):(a.classList.remove("grip-disabledgrip"),a.addEventListener("touchstart",e.onGripMouseDown,{capture:!0,passive:!0}),a.addEventListener("mousedown",e.onGripMouseDown,!0)),a.t=r,a.i=o,r.opt.widths[o]?n.w=r.opt.widths[o]:(n.w=Number(window.getComputedStyle(n).width.replace(/px/,"")).valueOf(),r.opt.widths[o]=n.w),n.style.width=n.w+e.PX,n.removeAttribute("width"),a.data={i:o,t:r.getAttribute(e.ID),last:o===r.columnCnt-1},r.grips.push(a),r.columns.push(n)});var i=Array.from(r.querySelectorAll("td"));i.concat(Array.from(r.querySelectorAll("th"))),(i=(i=i.filter(function(e){for(var r=0;r<t.length;r++)if(t[r]===e)return!1;return!0})).filter(function(e){return!(e.querySelectorAll("table th").length||e.querySelectorAll("table td").length)})).forEach(function(e){e.removeAttribute("width")}),r.opt.fixed||(r.removeAttribute("width"),r.classList.add(e.FLEX)),e.syncGrips()},this.deserializeStore=function(t){var r=e.tb;if(r.columnGrp.forEach(function(e){e.removeAttribute("width")}),r.opt.flush)e.store[r.getAttribute(e.ID)]="";else{var i=e.store[r.getAttribute(e.ID)].split(";"),o=i[r.columnCnt+1];!r.opt.fixed&&o&&(r.style.width=o+e.PX,r.opt.overflow&&(r.style.minWidth=o+e.PX,r.tableWidth=Number(o).valueOf()));for(var n=0;n<r.columnCnt;n++){var l=100*Number(i[n]).valueOf()/Number(i[r.columnCnt]).valueOf()+"%";t[n].style.width=l,r.columnGrp[n]&&(r.columnGrp[n].style.width=l)}}},this.createDiv=function(e,t,r){var i=document.createElement("div");i.classList.add(t),r&&(i.innerHTML=r),e.appendChild(i)},this.syncCols=function(t,r,i,o){var n=t.remote,l=e.grip.x-e.grip.l,a=t.columns[r],s=t.columns[r+1];if(a&&s){var d=a.w+l,u=s.w-l,c=d+e.PX;if(a.style.width=c,t.columnGrp[r]&&t.columnGrp[r].style.width&&(t.columnGrp[r].style.width=c),n&&(n.columns[r].style.width=c,n.columnGrp[r]&&n.columnGrp[r].style.width&&(n.columnGrp[r].style.width=c)),o.fixed){var p=u+e.PX;s.style.width=p,t.columnGrp[r+1]&&t.columnGrp[r+1].style.width&&(t.columnGrp[r+1].style.width=p),n&&(n.columns[r+1].style.width=p,n.columnGrp[r+1]&&n.columnGrp[r+1].style.width&&(n.columnGrp[r+1].style.width=p))}else o.overflow&&(t.style.minWidth=t.tableWidth+l+e.PX);i&&(a.w=d,s.w=o.fixed?u:s.w,n&&(n.columns[r].w=d,n.columns[r+1].w=o.fixed?u:s.w))}}};t.default=s,s.DEFAULTS={resizeMode:"fit",draggingClass:"grip-drag",gripInnerHtml:"",liveDrag:!1,minWidth:15,headerOnly:!1,hoverCursor:"col-resize",dragCursor:"col-resize",flush:!1,marginLeft:null,marginRight:null,remoteTable:null,disable:!1,partialRefresh:!1,disabledColumns:[],removePadding:!0,widths:[],onDrag:null,onResize:null}}])});
//# sourceMappingURL=column-resizer.js.map
{
"name": "column-resizer",
"version": "1.0.3",
"version": "1.1.0",
"description": "Javascript to resize table columns",

@@ -12,3 +12,3 @@ "title": "ColumnResizer",

"scripts": {
"test": "mocha $(find test -path '*Spec.js')",
"test": "mocha-chrome test/sample1.html",
"build": "cross-env NODE_ENV=production webpack -p",

@@ -22,3 +22,3 @@ "lint": "eslint src/*.js test/*.js"

"engines": {
"node": ">=0.10.0"
"node": ">=6.0.0"
},

@@ -40,14 +40,17 @@ "bugs": {

"devDependencies": {
"babel-core": "~6.24.1",
"babel-eslint": "~7.2.3",
"babel-loader": "~7.1.2",
"babel-preset-es2015": "~6.24.1",
"babel-core": "~6.26.3",
"babel-eslint": "~8.2.3",
"babel-loader": "~7.1.4",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "~6.24.1",
"babel-register": "~6.24.1",
"chai": "~4.0.2",
"cross-env": "~5.0.0",
"eslint": "~3.19.0",
"jsdom": "~9.9.1",
"mocha": "~3.4.2",
"webpack": "~3.5.6"
"babel-register": "~6.26.0",
"chai": "~4.1.2",
"cross-env": "~5.1.5",
"eslint": "~4.19.1",
"jsdom": "~11.10.0",
"mocha": "~5.2.0",
"mocha-chrome": "^1.1.0",
"uglifyjs-webpack-plugin": "^1.2.5",
"webpack": "~4.10.1",
"webpack-cli": "^2.1.4"
},

@@ -54,0 +57,0 @@ "dependencies": {

@@ -20,2 +20,7 @@ /**

/**
*
* @param {HTMLTableElement} tb
* @param {Object} options
*/
constructor(tb, options = {}) {

@@ -36,3 +41,3 @@ try {

* @param {Object} options
* @returns {Object} current option object
* @returns {Object} previous options object if any
*/

@@ -43,2 +48,5 @@ reset = options => {

/**
* Remove column resizing properties from the table then re-apply them
*/
onResize = () => {

@@ -70,3 +78,3 @@ const t = this.tb;

* and store some values used while dragging.
* @param {event} e - grip's mousedown event
* @param {UIEvent} e - grip's mousedown/touchstart event
*/

@@ -101,3 +109,3 @@ onGripMouseDown = (e) => {

* Event handler used while dragging a grip. It checks if the next grip's position is valid and updates it.
* @param {event} e - mousemove event bound to the window object
* @param {UIEvent} e - mousemove/touchmove event bound to the window object
*/

@@ -142,3 +150,3 @@ onGripDrag = (e) => {

}
return false;//prevent text selection while dragging
e.preventDefault(); //prevent text selection while dragging
};

@@ -148,3 +156,3 @@

* Event handler fired when the dragging is over, updating table layout
* @param {event} e - grip's drag over event
* @param {UIEvent} e - grip's drag over event
*/

@@ -187,2 +195,7 @@ onGripDragOver = (e) => {

/**
* Prepares the table set in the constructor for resizing.
* @param {Object} options
* @returns {Object} previous options object if any
*/
init = (options) => {

@@ -250,2 +263,5 @@ if (options.disable) {

/**
* Writes the current column widths to storage.
*/
serializeStore = () => {

@@ -286,2 +302,3 @@ const store = this.store;

* This function removes any enhancements from the table being processed.
* @returns {Object} current option object if any
*/

@@ -292,3 +309,3 @@ destroy = () => {

if (!id) {
return;
return null;
}

@@ -309,2 +326,7 @@ this.store[id] = '';

/**
* Utility method to add a <style> to an element
* @param {HTMLElement} element
* @param {string} css
*/
createStyle = (element, css) => {

@@ -330,2 +352,7 @@ const hash = stringHash(css).toString();

/**
* Populates unset options with defaults and sets resizeMode properties.
* @param {Object} options
* @returns {Object}
*/
extendOptions = (options) => {

@@ -347,11 +374,16 @@ const extOptions = Object.assign({}, ColumnResizer.DEFAULTS, options);

getTableHeaders = (t) => {
const id = '#' + t.id;
let th = Array.from(t.querySelectorAll(id + '>thead>tr:nth-of-type(1)>th'));
th = th.concat(Array.from(t.querySelectorAll(id + '>thead>tr:nth-of-type(1)>td')));
/**
* Finds all the visible table header elements from a given table.
* @param {HTMLTableElement} table
* @returns {HTMLElement[]}
*/
getTableHeaders = (table) => {
const id = '#' + table.id;
let th = Array.from(table.querySelectorAll(id + '>thead>tr:nth-of-type(1)>th'));
th = th.concat(Array.from(table.querySelectorAll(id + '>thead>tr:nth-of-type(1)>td')));
if (!th.length) {
th = Array.from(t.querySelectorAll(id + '>tbody>tr:nth-of-type(1)>th'));
th = th.concat(Array.from(t.querySelectorAll(id + '>tr:nth-of-type(1)>th')));
th = th.concat(Array.from(t.querySelectorAll(id + '>tbody>tr:nth-of-type(1)>td')));
th = th.concat(Array.from(t.querySelectorAll(id + '>tr:nth-of-type(1)>td')));
th = Array.from(table.querySelectorAll(id + '>tbody>tr:nth-of-type(1)>th'));
th = th.concat(Array.from(table.querySelectorAll(id + '>tr:nth-of-type(1)>th')));
th = th.concat(Array.from(table.querySelectorAll(id + '>tbody>tr:nth-of-type(1)>td')));
th = th.concat(Array.from(table.querySelectorAll(id + '>tr:nth-of-type(1)>td')));
}

@@ -362,5 +394,6 @@ return this.filterInvisible(th, false);

/**
* filter invisible columns
* @param nodes
* @param column
* Filter invisible columns.
* @param {HTMLElement[]} nodes
* @param {boolean} column
* @return {HTMLElement[]}
*/

@@ -377,2 +410,6 @@ filterInvisible = (nodes, column) => {

/**
* Add properties to the table for resizing
* @param {HTMLTableElement} th
*/
extendTable = (th) => {

@@ -401,2 +438,8 @@ const tb = this.tb;

/**
* Add properties to the remote table for resizing
* @param {HTMLTableElement} tb - the remote table
* @param {HTMLElement[]} th - table header array
* @param {HTMLTableElement} controller - the controlling table
*/
extendRemoteTable = (tb, th, controller) => {

@@ -430,5 +473,6 @@ const options = controller.opt;

};
/**
* Function to create all the grips associated with the table given by parameters
* @param {Array} th - table header array
* @param {HTMLElement[]} th - table header array
*/

@@ -514,2 +558,6 @@ createGrips = (th) => {

/**
* Get the stored table headers.
* @param {HTMLElement[]} th - table header array
*/
deserializeStore = (th) => {

@@ -544,2 +592,8 @@ const t = this.tb;

/**
* Utility method to wrap HTML text in a <div/> and appent to an element.
* @param {HTMLElement} element - the HTML element to append the div to
* @param {string} className - class name for the new div for styling
* @param {string} text - inner HTML text
*/
createDiv = (element, className, text) => {

@@ -558,5 +612,5 @@ const div = document.createElement('div');

* event handler to synchronize grip's position with their related columns.
* @param {Node} t - table object
* @param {HTMLTableElement} t - table object
* @param {number} i - index of the grip being dragged
* @param {bool} isOver - to identify when the function is being called from the onGripDragOver event
* @param {boolean} isOver - to identify when the function is being called from the onGripDragOver event
* @param {Object} options - used for chaining options with remote tables

@@ -563,0 +617,0 @@ */

@@ -1,2 +0,2 @@

import {jsdom} from 'jsdom';
import {JSDOM} from 'jsdom';
import fs from 'fs';

@@ -6,5 +6,8 @@

if (!global.document) {
global.document = jsdom(fs.readFileSync('test/sample1.html'));
global.window = document.defaultView;
global.navigator = window.navigator;
const dom = new JSDOM(fs.readFileSync('test/sample1.html'), { pretendToBeVisual: true, resources: 'usable' });
global.window = dom.window;
global.document = dom.window.document;
global.navigator = {
userAgent: 'node.js',
};
global.getComputedStyle = window.getComputedStyle;

@@ -18,9 +21,10 @@ // eslint-disable-next-line no-console

// from mocha-jsdom https://github.com/rstacruz/mocha-jsdom/blob/master/index.js#L80
function propagateToGlobal(window) {
for (let key in window) {
if (!window.hasOwnProperty(key)) continue;
if (key in global) continue;
global[key] = window[key];
}
const props = Object.getOwnPropertyNames(window)
.filter(prop => typeof global[prop] === 'undefined')
.reduce((result, prop) => ({
...result,
[prop]: Object.getOwnPropertyDescriptor(window, prop),
}), {});
Object.defineProperties(global, props);
}
const webpack = require('webpack');
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

@@ -28,22 +29,26 @@ module.exports = {

},
optimization: {
nodeEnv: 'production',
minimizer: [
new UglifyJSPlugin({
sourceMap: true,
uglifyOptions: {
ecma: 6,
compress: {
warnings: false
},
mangle: {
keep_fnames: true },
output: {
comments: false
}
}
})
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
beatify: false,
compress: {
screw_ie8: true,
warnings: false
},
mangle: {
screw_ie8: true,
keep_fnames: true
},
dead_code: true,
minimize: true,
sourceMap: true,
comments: false
})
]
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc