diff --git a/slick.compositeeditor.js b/slick.compositeeditor.js index cd26388d..7d3efc13 100644 --- a/slick.compositeeditor.js +++ b/slick.compositeeditor.js @@ -46,7 +46,6 @@ options = Slick.Utils.extend({}, defaultOptions, options); - function getContainerBox(i) { var c = containers[i]; var offset = Slick.Utils.offset(c); @@ -64,7 +63,6 @@ }; } - function editor(args) { var editors = []; @@ -99,7 +97,6 @@ }, 0); } - this.destroy = function () { var idx = 0; while (idx < editors.length) { @@ -108,7 +105,7 @@ } options.destroy && options.destroy(); - editors = []; + editors = []; }; @@ -117,7 +114,6 @@ (firstInvalidEditor || editors[0]).focus(); }; - this.isValueChanged = function () { var idx = 0; while (idx < editors.length) { @@ -129,7 +125,6 @@ return false; }; - this.serializeValue = function () { var serializedValue = []; var idx = 0; @@ -140,7 +135,6 @@ return serializedValue; }; - this.applyValue = function (item, state) { var idx = 0; while (idx < editors.length) { @@ -158,11 +152,10 @@ } }; - - this.validate = function (targetElm) { + this.validate = function (target) { var validationResults; var errors = []; - var targetElm = targetElm ? targetElm : null; + var targetElm = target ? target : null; firstInvalidEditor = null; @@ -204,7 +197,7 @@ } idx++; } - targetElm = null; + targetElm = null; if (errors.length) { return { @@ -220,7 +213,6 @@ } }; - this.hide = function () { var idx = 0; while (idx < editors.length) { @@ -230,7 +222,6 @@ options.hide && options.hide(); }; - this.show = function () { var idx = 0; while (idx < editors.length) { @@ -240,12 +231,10 @@ options.show && options.show(); }; - this.position = function (box) { options.position && options.position(box); }; - init(); } diff --git a/slick.core.js b/slick.core.js index 2c8ac959..a712c880 100644 --- a/slick.core.js +++ b/slick.core.js @@ -22,6 +22,7 @@ let returnValue = undefined; // when we already have an event, we want to keep some of the event properties + // looping through some props is the only way to keep and sync these properties to the returned EventData if (event) { const eventProps = [ 'altKey', 'ctrlKey', 'metaKey', 'shiftKey', 'key', 'keyCode', @@ -40,7 +41,7 @@ */ this.stopPropagation = function () { isPropagationStopped = true; - if(nativeEvent) { + if (nativeEvent) { nativeEvent.stopPropagation(); } }; @@ -60,7 +61,7 @@ */ this.stopImmediatePropagation = function () { isImmediatePropagationStopped = true; - if(nativeEvent) { + if (nativeEvent) { nativeEvent.stopImmediatePropagation(); } }; @@ -79,14 +80,14 @@ } this.preventDefault = function() { - if(nativeEvent) { + if (nativeEvent) { nativeEvent.preventDefault(); } isDefaultPrevented = true; } this.isDefaultPrevented = function() { - if(nativeEvent) { + if (nativeEvent) { return nativeEvent.defaultPrevented; } return isDefaultPrevented; @@ -518,7 +519,6 @@ * @constructor */ function TreeColumns(treeColumns) { - var columnsById = {}; function init() { @@ -530,19 +530,19 @@ .forEach(function (column) { columnsById[column.id] = column; - if (column.columns) + if (column.columns) { mapToId(column.columns); + } }); } function filter(node, condition) { - return node.filter(function (column) { - var valid = condition.call(column); - if (valid && column.columns) + if (valid && column.columns) { column.columns = filter(column.columns, condition); + } return valid && (!column.columns || column.columns.length); }); @@ -558,8 +558,9 @@ return indexA - indexB; }) .forEach(function (column) { - if (column.columns) + if (column.columns) { sort(column.columns, grid); + } }); } @@ -568,13 +569,15 @@ } function getDepth(node) { - if (node.length) - for (var i in node) + if (node.length) { + for (var i in node) { return getDepth(node[i]); - else if (node.columns) + } + } else if (node.columns) { return 1 + getDepth(node.columns); - else + } else { return 1; + } } function getColumnsInDepth(node, depth, current) { @@ -582,21 +585,23 @@ current = current || 0; if (depth == current) { - - if (node.length) + if (node.length) { node.forEach(function(n) { - if (n.columns) + if (n.columns) { n.extractColumns = function() { return extractColumns(n); }; + } }); - + } return node; - } else - for (var i in node) + } else { + for (var i in node) { if (node[i].columns) { columns = columns.concat(getColumnsInDepth(node[i].columns, depth, current + 1)); } + } + } return columns; } @@ -605,19 +610,15 @@ var result = []; if (node.hasOwnProperty('length')) { - - for (var i = 0; i < node.length; i++) + for (var i = 0; i < node.length; i++) { result = result.concat(extractColumns(node[i])); - + } } else { - - if (node.hasOwnProperty('columns')) - + if (node.hasOwnProperty('columns')) { result = result.concat(extractColumns(node.columns)); - - else + } else { return node; - + } } return result; @@ -630,9 +631,7 @@ init(); this.hasDepth = function () { - - for (var i in treeColumns) - { + for (var i in treeColumns) { if (treeColumns[i].hasOwnProperty('columns')) return true; } @@ -739,24 +738,24 @@ } // With help from https://youmightnotneedjquery.com/ - function grep( elems, callback, invert ) { - var callbackInverse, - matches = [], - i = 0, - length = elems.length, - callbackExpect = !invert; - - // Go through the array, only saving the items - // that pass the validator function - for ( ; i < length; i++ ) { - callbackInverse = !callback( elems[ i ], i ); - if ( callbackInverse !== callbackExpect ) { - matches.push( elems[ i ] ); - } - } - - return matches; - } + function grep(elems, callback, invert) { + var callbackInverse, + matches = [], + i = 0, + length = elems.length, + callbackExpect = !invert; + + // Go through the array, only saving the items + // that pass the validator function + for (; i < length; i++) { + callbackInverse = !callback(elems[i], i); + if (callbackInverse !== callbackExpect) { + matches.push(elems[i]); + } + } + + return matches; + } function emptyElement(element) { if (element && element.firstChild) { @@ -803,22 +802,20 @@ function setStyleSize(el, style, val) { if (typeof val === 'function') { val = val(); - } - else if (typeof val === 'string') { + } else if (typeof val === 'string') { el.style[style] = val; - } - else { + } else { el.style[style] = val + 'px'; } } function contains(parent, child) { - if(!parent || !child) { + if (!parent || !child) { return false; } const parentList = parents(child); - return !parentList.every(function (p) { + return !parentList.every(function (p) { if(parent == p) { return false; } @@ -836,21 +833,15 @@ const hidden = selector == ":hidden"; while ((el = el.parentNode) && el !== document) { - - if(hidden) - { + if (hidden) { if(isHidden(el)) { parents.push(el); } - } - else if (visible) - { + } else if (visible) { if(!isHidden(el)) { parents.push(el); } - } - else if (!selector || el.matches(selector)) - { + } else if (!selector || el.matches(selector)) { parents.push(el); } } @@ -862,8 +853,7 @@ template.innerHTML = html.trim(); const first = template.content.firstChild; - if(parent) - { + if (parent) { [].forEach.call(template.content.children, function (child) { parent.appendChild(child); }); @@ -873,7 +863,7 @@ } function toFloat(value) { - var x = parseFloat(value) + var x = parseFloat(value); if (isNaN(x)) { return 0; } @@ -881,46 +871,40 @@ } function show(el, type) { - type = type ? type : ""; - if(Array.isArray(el)) { + if (Array.isArray(el)) { el.forEach(function (e) { e.style.display = type; }) - } - else { + } else { el.style.display = type; } } function hide(el) { - if(Array.isArray(el)) { + if (Array.isArray(el)) { el.forEach(function (e) { e.style.display = "none"; }); - } - else { + } else { el.style.display = "none"; } } function slideUp(el, callback) { - if(window.jQuery !== undefined) { - window.jQuery(el).slideUp("fast", callback); - return; - } - - hide(el); - callback(); + return slideAnimation(el, 'slideUp', callback); } function slideDown(el, callback) { - if(window.jQuery !== undefined) { - window.jQuery(el).slideDown("fast", callback); + return slideAnimation(el, 'slideDown', callback); + } + + function slideAnimation(el, slideDirection, callback) { + if (window.jQuery !== undefined) { + window.jQuery(el)[slideDirection]("fast", callback); return; } - - show(el); + (slideDirection === 'slideUp') ? hide(el) : show(el); callback(); } @@ -955,19 +939,17 @@ length = arguments.length, deep = false; - if ( typeof target === "boolean" ) { + if (typeof target === "boolean") { deep = target; target = arguments[ i ] || {}; i++; - } - else - { + } else { target = target || {} } - if ( typeof target !== "object" && !isFunction( target ) ) { + if (typeof target !== "object" && !isFunction(target)) { target = {}; } - if ( i === length ) { + if (i === length) { target = this; i--; } @@ -1000,7 +982,7 @@ } /** - * A simple binding event service to keep track of all events being subscribed to, + * A simple binding event service to keep track of all JavaScript events with callback listeners, * it allows us to unbind event(s) and their listener(s) by calling a simple unbind method call. * Unbinding is a necessary step to make sure that all event listeners are removed to avoid memory leaks when destroing the grid */ diff --git a/slick.dataview.js b/slick.dataview.js index 02c58841..7aa869a8 100644 --- a/slick.dataview.js +++ b/slick.dataview.js @@ -634,8 +634,7 @@ // item affects sorting -> must use sorted add deleteItem(id); sortedAddItem(item); - } - else { // update does not affect sorting -> regular update works fine + } else { // update does not affect sorting -> regular update works fine updateItem(id, item); } } @@ -647,8 +646,7 @@ var mid = low + high >>> 1; if (sortComparer(items[mid], searchItem) === -1) { low = mid + 1; - } - else { + } else { high = mid; } } @@ -842,7 +840,7 @@ } } - if(groups.length) { + if (groups.length) { addTotals(groups, level); } @@ -966,8 +964,7 @@ fn.name = setFunctionName(fn, fnName); return fn; } else { - return function noAccumulator() { - } + return function noAccumulator() { } } } diff --git a/slick.editors.js b/slick.editors.js index 47c903b8..58cc4fc2 100644 --- a/slick.editors.js +++ b/slick.editors.js @@ -5,7 +5,6 @@ */ (function (window) { - const utils = Slick.Utils; function TextEditor(args) { diff --git a/slick.grid.js b/slick.grid.js index 19bb4229..2cfc47b3 100644 --- a/slick.grid.js +++ b/slick.grid.js @@ -10,7 +10,7 @@ * SlickGrid v3.0.4 * * NOTES: - * Cell/row DOM manipulations are done directly bypassing jQuery's DOM manipulation methods. + * Cell/row DOM manipulations are done directly bypassing JS DOM manipulation methods. * This increases the speed dramatically, but can only be done safely because there are no event handlers * or data associated with any cell/row DOM nodes. Cell editors must make sure they implement .destroy() * and do proper cleanup. @@ -399,7 +399,6 @@ if (typeof Slick === "undefined") { _groupHeadersL[index] = utils.template("
", _headerScrollerL); _groupHeadersR[index] = utils.template("
", _headerScrollerR); } - _groupHeaders = [_groupHeadersL, _groupHeadersR]; } @@ -485,8 +484,9 @@ if (typeof Slick === "undefined") { _activeCanvasNode = _canvasTopL; // pre-header - if (_preHeaderPanelSpacer) + if (_preHeaderPanelSpacer) { utils.width(_preHeaderPanelSpacer, getCanvasWidth() + scrollbarDimensions.width); + } _headers.forEach(function (el) { utils.width(el, getHeadersWidth()); @@ -634,16 +634,16 @@ if (typeof Slick === "undefined") { }); } - if (!options.suppressCssChangesOnHiddenInit) + if (!options.suppressCssChangesOnHiddenInit) { restoreCssFromHiddenInit(); + } } } function cacheCssForHiddenInit() { // handle display:none on container or container parents _hiddenParents = utils.parents(_container, ":hidden"); - for (const el of _hiddenParents) - { + for (const el of _hiddenParents) { var old = {}; for ( const name in cssShow ) { old[ name ] = el.style[ name ]; @@ -657,11 +657,10 @@ if (typeof Slick === "undefined") { // finish handle display:none on container or container parents // - put values back the way they were let i = 0; - for (const el of _hiddenParents) - { + for (const el of _hiddenParents) { var old = oldProps[i++]; - for ( const name in cssShow ) { - el.style[ name ] = old[ name ]; + for (const name in cssShow) { + el.style[name] = old[name]; } } } @@ -721,7 +720,7 @@ if (typeof Slick === "undefined") { function getActiveCanvasNode(e) { - if(e === undefined) { + if (e === undefined) { return _activeCanvasNode; } @@ -752,11 +751,9 @@ if (typeof Slick === "undefined") { } function setActiveViewportNode(e) { - if (e instanceof Slick.EventData) { e = e.getNativeEvent(); } - _activeViewportNode = e.target.closest('.slick-viewport'); return _activeViewportNode; } @@ -826,8 +823,9 @@ if (typeof Slick === "undefined") { headersWidthL =0; columns.forEach(function(column, i) { - if (!(( options.frozenColumn ) > -1 && ( i > options.frozenColumn ))) + if (!((options.frozenColumn) > -1 && (i > options.frozenColumn))) { headersWidthL += column.width; + } }); if (hasFrozenColumns()) { @@ -844,8 +842,9 @@ if (typeof Slick === "undefined") { headersWidthR =0; columns.forEach(function(column, i) { - if (( options.frozenColumn ) > -1 && ( i > options.frozenColumn )) + if ((options.frozenColumn) > -1 && (i > options.frozenColumn)) { headersWidthR += column.width; + } }); if (hasFrozenColumns()) { @@ -1063,8 +1062,7 @@ if (typeof Slick === "undefined") { var columnDef = columns[idx]; var header = getColumnByIndex(idx); - if(header) - { + if (header) { if (title !== undefined) { columns[idx].name = title; } @@ -1182,10 +1180,11 @@ if (typeof Slick === "undefined") { var m = columns[i]; const footerRowCell = utils.template("
", hasFrozenColumns() && (i > options.frozenColumn)? _footerRowR: _footerRowL); const className = hasFrozenColumns() && i <= options.frozenColumn? 'frozen': null; - if(className) + if (className) { footerRowCell.classList.add(className); + } - utils.storage.put(footerRowCell, "column", m) + utils.storage.put(footerRowCell, "column", m); trigger(self.onFooterRowCellRendered, { "node": footerRowCell, @@ -1200,11 +1199,11 @@ if (typeof Slick === "undefined") { var columnsLength = 0; var frozenColumnsValid = false; - if (!treeColumns.hasDepth()) + if (!treeColumns.hasDepth()) { return; + } for (var index = 0; index < _groupHeadersL.length; index++) { - _groupHeadersL[index].replaceChildren(); _groupHeadersR[index].replaceChildren(); @@ -1215,8 +1214,9 @@ if (typeof Slick === "undefined") { columnsLength += m.extractColumns().length; - if (hasFrozenColumns() && index === 0 && (columnsLength-1) === options.frozenColumn) + if (hasFrozenColumns() && index === 0 && (columnsLength - 1) === options.frozenColumn) { frozenColumnsValid = true; + } const el = utils.template("
", hasFrozenColumns() && (columnsLength - 1) > options.frozenColumn ? _groupHeadersR[index]: _groupHeadersL[index]); el.innerHTML = "" + m.name + ""; @@ -1331,11 +1331,13 @@ if (typeof Slick === "undefined") { header.setAttribute("data-id", m.id); let classname = m.headerCssClass || null; - if(classname) + if (classname) { header.classList.add(classname); + } classname = hasFrozenColumns() && i <= options.frozenColumn ? 'frozen' : null; - if(classname) + if (classname) { header.classList.add(classname); + } _bindingEventService.bind(header, "mouseenter", handleHeaderMouseEnter); _bindingEventService.bind(header, "mouseleave", handleHeaderMouseLeave); @@ -1372,8 +1374,9 @@ if (typeof Slick === "undefined") { if (options.showHeaderRow) { const headerRowCell = utils.template("
", headerRowTarget); const classname = hasFrozenColumns() && i <= options.frozenColumn? 'frozen' : null; - if(classname) + if (classname) { headerRowCell.classList.add(classname); + } _bindingEventService.bind(headerRowCell, "mouseenter", handleHeaderRowMouseEnter); _bindingEventService.bind(headerRowCell, "mouseleave", handleHeaderRowMouseLeave); @@ -1403,20 +1406,19 @@ if (typeof Slick === "undefined") { setupColumnResize(); if (options.enableColumnReorder) { if (typeof options.enableColumnReorder == 'function') { - options.enableColumnReorder(self, _headers, headerColumnWidthDiff, setColumns, setupColumnResize, columns, getColumnIndex, uid, trigger); + options.enableColumnReorder(self, _headers, headerColumnWidthDiff, setColumns, setupColumnResize, columns, getColumnIndex, uid, trigger); } else { - setupColumnReorder(); + setupColumnReorder(); } } } function setupColumnSort() { - _headers.forEach(function (header) { - _bindingEventService.bind(header, "click", function (e) { - if (columnResizeDragging) + if (columnResizeDragging) { return; + } if (e.target.classList.contains("slick-resizable-handle")) { return; @@ -1466,8 +1468,7 @@ if (typeof Slick === "undefined") { if (sortColumn) { sortColumns.splice(i, 1); } - } - else { + } else { if ((!e.shiftKey && !e.metaKey) || !options.multiColumnSort) { sortColumns = []; } @@ -1539,10 +1540,9 @@ if (typeof Slick === "undefined") { endLimit += groupColumn.columns.length; groupColumn.columns.some(function (column) { - - if (column.id === idColumn) + if (column.id === idColumn) { groupColumnOfPreviousPosition = groupColumn; - + } return groupColumnOfPreviousPosition; }); @@ -1560,7 +1560,7 @@ if (typeof Slick === "undefined") { function remove(arr, elem) { var index = arr.lastIndexOf(elem); - if(index > -1) { + if (index > -1) { arr.splice(index, 1); remove(arr, elem); } @@ -1572,7 +1572,7 @@ if (typeof Slick === "undefined") { var positionValid = limit.start <= currentPosition && currentPosition <= limit.end; return { - limit: limit, + limit: limit, valid: positionValid, message: positionValid ? '' : 'Column "'.concat(item.textContent, '" can be reordered only within the "', limit.group.name, '" group!') }; @@ -1610,13 +1610,11 @@ if (typeof Slick === "undefined") { if (canDragScroll && e.originalEvent.pageX > _container.clientWidth) { if (!(columnScrollTimer)) { - columnScrollTimer = setInterval( - scrollColumnsRight, 100); + columnScrollTimer = setInterval(scrollColumnsRight, 100); } } else if (canDragScroll && e.originalEvent.pageX < utils.offset(_viewportScrollContainerX).left) { if (!(columnScrollTimer)) { - columnScrollTimer = setInterval( - scrollColumnsLeft, 100); + columnScrollTimer = setInterval(scrollColumnsLeft, 100); } } else { clearInterval(columnScrollTimer); @@ -1663,28 +1661,24 @@ if (typeof Slick === "undefined") { sortableSideRightInstance = Sortable.create(_headerR, sortableOptions); } - function getHeaderChildren() - { + function getHeaderChildren() { const a = Array.from(_headers[0].children); const b = Array.from(_headers[1].children); return a.concat(b); } - function getImpactedColumns( limit ) { - var impactedColumns = []; - - if( limit ) { + function getImpactedColumns(limit) { + var impactedColumns = []; - for( var i = limit.start; i <= limit.end; i++ ) { - impactedColumns.push( columns[i] ); - } - } - else { - - impactedColumns = columns; - } + if (limit) { + for (var i = limit.start; i <= limit.end; i++) { + impactedColumns.push(columns[i]); + } + } else { + impactedColumns = columns; + } - return impactedColumns; + return impactedColumns; } function handleResizeableHandleDoubleClick(evt) { @@ -1708,8 +1702,9 @@ if (typeof Slick === "undefined") { handle.remove(); }); - if (i >= columns.length) + if (i >= columns.length) { return; + } if (columns[i].resizable) { if (firstResizable === undefined) { @@ -1719,8 +1714,9 @@ if (typeof Slick === "undefined") { } } - if (firstResizable === undefined) + if (firstResizable === undefined) { return; + } for (let i = 0; i < children.length; i++) { const colElm = children[i]; @@ -1748,8 +1744,9 @@ if (typeof Slick === "undefined") { var shrinkLeewayOnRight = null, stretchLeewayOnRight = null; // lock each column's width option to current width for(let pw = 0; pw < children.length; pw++) { - if (pw >= columns.length) + if (pw >= columns.length) { return; + } columns[pw].previousWidth = children[pw].offsetWidth; } if (options.forceFitColumns) { @@ -2408,8 +2405,9 @@ if (typeof Slick === "undefined") { if (columns[i].Id === columnOrIndexOrId) { colDef = columns[i]; colIndex = i; } } } - if (!colDef) + if (!colDef) { return; + } const gridCanvas = getCanvasNode(0, 0); getColAutosizeWidth(colDef, colIndex, gridCanvas, isInit, colIndex); } @@ -2495,7 +2493,9 @@ if (typeof Slick === "undefined") { } else { colWidth = c.autoSize.widthPx; } - if (c.rerenderOnResize && c.width != colWidth) { reRender = true; } + if (c.rerenderOnResize && c.width != colWidth) { + reRender = true; + } c.width = colWidth; } } else if ((options.viewportSwitchToScrollModeWidthPercent && totalWidthLessSTR + strColsMinWidth > viewportWidth * options.viewportSwitchToScrollModeWidthPercent / 100) @@ -2516,7 +2516,9 @@ if (typeof Slick === "undefined") { } else { // size width proportionally to free space (we know we have enough room due to the earlier calculations) colWidth = unallocatedViewportWidth / unallocatedColWidth * c.autoSize.widthPx - 1; - if (colWidth < c.minWidth) { colWidth = c.minWidth; } + if (colWidth < c.minWidth) { + colWidth = c.minWidth; + } // remove the just allocated widths from the allocation pool unallocatedColWidth -= c.autoSize.widthPx; @@ -2524,10 +2526,14 @@ if (typeof Slick === "undefined") { } } if (treatAsLocked(c.autoSize)) { - colWidth = c.autoSize.widthPx; - if (colWidth < c.minWidth) { colWidth = c.minWidth; } + colWidth = c.autoSize.widthPx; + if (colWidth < c.minWidth) { + colWidth = c.minWidth; + } + } + if (c.rerenderOnResize && c.width != colWidth) { + reRender = true; } - if (c.rerenderOnResize && c.width != colWidth) { reRender = true; } c.width = colWidth; } } @@ -2544,16 +2550,9 @@ if (typeof Slick === "undefined") { } } - //LogColWidths(); reRenderColumns(reRender); } - function LogColWidths () { - var s = "Col Widths:"; - for (var i = 0; i < columns.length; i++) { s += ' ' + columns[i].width; } - console.log(s); - } - function getColAutosizeWidth(columnDef, colIndex, gridCanvas, isInit, colArrayIndex) { var autoSize = columnDef.autoSize; @@ -2943,22 +2942,20 @@ if (typeof Slick === "undefined") { } function applyColumnGroupHeaderWidths() { - if (!treeColumns.hasDepth()) + if (!treeColumns.hasDepth()) { return; + } for (var depth = _groupHeadersL.length - 1; depth >= 0; depth--) { - var groupColumns = treeColumns.getColumnsInDepth(depth); const groupHeaders = [_groupHeadersL[depth], _groupHeadersR[depth]]; groupHeaders.forEach(function (groupHeader) { - var currentColumnIndex = 0; utils.width(groupHeader, i === 0 ? getHeadersWidthL() : getHeadersWidthR()); groupHeader.children.forEach(function (groupHeaderColumn) { - var m = utils.storage.get(groupHeaderColumn, "column"); m.width = 0; @@ -2975,9 +2972,9 @@ if (typeof Slick === "undefined") { } function applyColumnHeaderWidths() { - - if (!initialized) - return; + if (!initialized) { + return; + } let columnIndex = 0; _headers.forEach(function (header) { @@ -3020,8 +3017,7 @@ if (typeof Slick === "undefined") { let result = null; _headers.every(function (header) { const length = header.children.length; - if(id < length) - { + if (id < length) { result = header.children[id]; return false; } @@ -3037,7 +3033,6 @@ if (typeof Slick === "undefined") { const numberCols = options.numberedMultiColumnSort && sortColumns.length > 1; _headers.forEach(function (header) { - let indicators = header.querySelectorAll(".slick-header-column-sorted"); indicators.forEach(function (indicator) { indicator.classList.remove("slick-header-column-sorted"); @@ -3056,20 +3051,19 @@ if (typeof Slick === "undefined") { let i = 1; sortColumns.forEach(function (col) { - if (col.sortAsc == null) + if (col.sortAsc == null) { col.sortAsc = true; + } const columnIndex = getColumnIndex(col.columnId); if (columnIndex != null) { const column = getColumnByIndex(columnIndex); - if(column) - { + if (column) { column.classList.add("slick-header-column-sorted"); let indicator = column.querySelector(".slick-sort-indicator"); indicator.classList.add(col.sortAsc ? "slick-sort-indicator-asc" : "slick-sort-indicator-desc"); - if(numberCols) - { + if (numberCols) { indicator = column.querySelector(".slick-sort-indicator-numbered"); indicator.textContent = i; } @@ -3196,7 +3190,9 @@ if (typeof Slick === "undefined") { applyColumnHeaderWidths(); applyColumnWidths(); handleScroll(); - if (getSelectionModel() && getSelectionModel().refreshSelections) { getSelectionModel().refreshSelections(); } + if (getSelectionModel() && getSelectionModel().refreshSelections) { + getSelectionModel().refreshSelections(); + } } } @@ -3538,7 +3534,9 @@ if (typeof Slick === "undefined") { if (item) { value = getDataItemValueForColumn(item, m); formatterResult = getFormatter(row, m)(row, cell, value, m, item, self); - if (formatterResult === null || formatterResult === undefined) { formatterResult = ''; } + if (formatterResult === null || formatterResult === undefined) { + formatterResult = ''; + } } // get addl css class names from object type formatter return and from string type return of onBeforeAppendCell @@ -3548,7 +3546,7 @@ if (typeof Slick === "undefined") { var toolTip = formatterResult && formatterResult.toolTip ? "title='" + formatterResult.toolTip + "'" : ''; var customAttrStr = ''; - if(m.hasOwnProperty('cellAttrs') && m.cellAttrs instanceof Object) { + if (m.hasOwnProperty('cellAttrs') && m.cellAttrs instanceof Object) { for (var key in m.cellAttrs) { if (m.cellAttrs.hasOwnProperty(key)) { customAttrStr += ' ' + key + '="' + m.cellAttrs[key] + '" '; @@ -3909,9 +3907,9 @@ if (typeof Slick === "undefined") { render(); } - function updatePagingStatusFromView( pagingInfo ) { - pagingActive = (pagingInfo.pageSize !== 0); - pagingIsLastPage = (pagingInfo.pageNum == pagingInfo.totalPages - 1); + function updatePagingStatusFromView(pagingInfo) { + pagingActive = (pagingInfo.pageSize !== 0); + pagingIsLastPage = (pagingInfo.pageNum == pagingInfo.totalPages - 1); } function updateRowCount() { @@ -3943,7 +3941,9 @@ if (typeof Slick === "undefined") { removeRowFromCache(i); } } - if (options.enableAsyncPostRenderCleanup) { startPostProcessingCleanup(); } + if (options.enableAsyncPostRenderCleanup) { + startPostProcessingCleanup(); + } if (activeCellNode && activeRow > r1) { resetActiveCell(); @@ -4053,11 +4053,11 @@ if (typeof Slick === "undefined") { const cacheEntry = rowsCache[row]; if (cacheEntry) { if (cacheEntry.cellRenderQueue.length) { - const rowNode = cacheEntry.rowNode; let children = Array.from(rowNode[0].children); - if(rowNode.length > 1) - children = children.concat(Array.from(rowNode[1].children)) + if (rowNode.length > 1) { + children = children.concat(Array.from(rowNode[1].children)); + } let i = children.length - 1; while (cacheEntry.cellRenderQueue.length) { @@ -4338,26 +4338,19 @@ if (typeof Slick === "undefined") { // add new rows & missing cells in existing rows if (lastRenderedScrollLeft != scrollLeft) { - - if ( hasFrozenRows ) { - + if (hasFrozenRows) { var renderedFrozenRows = utils.extend(true, {}, rendered); - if (options.frozenBottom) { - - renderedFrozenRows.top=actualFrozenRow; - renderedFrozenRows.bottom=getDataLength(); - } - else { - - renderedFrozenRows.top=0; - renderedFrozenRows.bottom=options.frozenRow; - } - - cleanUpAndRenderCells(renderedFrozenRows); - } - - cleanUpAndRenderCells(rendered); + if (options.frozenBottom) { + renderedFrozenRows.top = actualFrozenRow; + renderedFrozenRows.bottom = getDataLength(); + } else { + renderedFrozenRows.top = 0; + renderedFrozenRows.bottom = options.frozenRow; + } + cleanUpAndRenderCells(renderedFrozenRows); + } + cleanUpAndRenderCells(rendered); } // render missing rows @@ -4365,16 +4358,15 @@ if (typeof Slick === "undefined") { // Render frozen rows if (hasFrozenRows) { - if (options.frozenBottom) { - renderRows({ - top: actualFrozenRow, bottom: getDataLength() - 1, leftPx: rendered.leftPx, rightPx: rendered.rightPx - }); - } - else { - renderRows({ - top: 0, bottom: options.frozenRow - 1, leftPx: rendered.leftPx, rightPx: rendered.rightPx - }); - } + if (options.frozenBottom) { + renderRows({ + top: actualFrozenRow, bottom: getDataLength() - 1, leftPx: rendered.leftPx, rightPx: rendered.rightPx + }); + } else { + renderRows({ + top: 0, bottom: options.frozenRow - 1, leftPx: rendered.leftPx, rightPx: rendered.rightPx + }); + } } postProcessFromRow = visible.top; @@ -4387,10 +4379,6 @@ if (typeof Slick === "undefined") { trigger(self.onRendered, { startRow: visible.top, endRow: visible.bottom, grid: self }); } - function handleHeaderScroll() { - handleElementScroll(_headerScrollContainer); - } - function handleHeaderRowScroll() { var scrollLeft = _headerRowScrollContainer.scrollLeft; if (scrollLeft != _viewportScrollContainerX.scrollLeft) { @@ -4528,7 +4516,7 @@ if (typeof Slick === "undefined") { trigger(self.onScroll, {scrollLeft: scrollLeft, scrollTop: scrollTop}); - if (hScrollDist || vScrollDist) return true; + if (hScrollDist || vScrollDist) { return true; } return false; } @@ -4538,7 +4526,6 @@ if (typeof Slick === "undefined") { call dequeue to cancel any pending action. */ function ActionThrottle(action, minPeriod_ms) { - var blocked = false; var queued = false; @@ -4712,10 +4699,11 @@ if (typeof Slick === "undefined") { } setTimeout(function () { - if(times % 2 == 0) + if (times % 2 == 0) { cellNode.classList.add(options.cellFlashingCssClass); - else + } else { cellNode.classList.remove(options.cellFlashingCssClass); + } toggleCellClass(cellNode, times - 1); }, speed); } @@ -4854,18 +4842,16 @@ if (typeof Slick === "undefined") { } // ignore exceptions - setting the original event's keycode throws access denied exception for "Ctrl" // (hitting control key only, nothing else), "Shift" (maybe others) - catch (error) { - } + catch (error) { } } } function handleClick(evt) { let e = evt; - if(e instanceof Slick.EventData) { + if (e instanceof Slick.EventData) { e = evt.getNativeEvent(); - } - else { + } else { evt = undefined; } @@ -4936,8 +4922,9 @@ if (typeof Slick === "undefined") { function handleHeaderMouseEnter(e) { const c = utils.storage.get(e.target.closest(".slick-header-column"), "column"); - if(!c) + if (!c) { return; + } trigger(self.onHeaderMouseEnter, { "column": c, "grid": self @@ -4946,8 +4933,9 @@ if (typeof Slick === "undefined") { function handleHeaderMouseLeave(e) { const c = utils.storage.get(e.target.closest(".slick-header-column"), "column"); - if(!c) + if (!c) { return; + } trigger(self.onHeaderMouseLeave, { "column": c, "grid": self @@ -4956,8 +4944,9 @@ if (typeof Slick === "undefined") { function handleHeaderRowMouseEnter(e) { const c = utils.storage.get(e.target.closest(".slick-headerrow-column"), "column"); - if(!c) + if (!c) { return; + } trigger(self.onHeaderRowMouseEnter, { "column": c, "grid": self @@ -4966,8 +4955,9 @@ if (typeof Slick === "undefined") { function handleHeaderRowMouseLeave(e) { const c = utils.storage.get(e.target.closest(".slick-headerrow-column"), "column"); - if(!c) + if (!c) { return; + } trigger(self.onHeaderRowMouseLeave, { "column": c, "grid": self @@ -4981,8 +4971,9 @@ if (typeof Slick === "undefined") { } function handleHeaderClick(e) { - if (columnResizeDragging) + if (columnResizeDragging) { return; + } var header = e.target.closest(".slick-header-column"); var column = header && utils.storage.get(header, "column"); @@ -5044,8 +5035,9 @@ if (typeof Slick === "undefined") { function getRowFromNode(rowNode) { for (var row in rowsCache) { for (var i in rowsCache[row].rowNode) { - if (rowsCache[row].rowNode[i] === rowNode) + if (rowsCache[row].rowNode[i] === rowNode) { return (row ? parseInt(row) : 0); + } } } return null; @@ -5054,32 +5046,28 @@ if (typeof Slick === "undefined") { function getFrozenRowOffset(row) { //var offset = ( hasFrozenRows ) ? ( options.frozenBottom ) ? ( row >= actualFrozenRow ) ? ( h < viewportTopH ) ? ( actualFrozenRow * options.rowHeight ) : h : 0 : ( row >= actualFrozenRow ) ? frozenRowsHeight : 0 : 0; // WTF? let offset = 0; - if(hasFrozenRows) - { - if(options.frozenBottom) - { - if(row >= actualFrozenRow) - { - if(h < viewportTopH) - offset = ( actualFrozenRow * options.rowHeight ); - else - offset = h; + if (hasFrozenRows) { + if (options.frozenBottom) { + if (row >= actualFrozenRow) { + if (h < viewportTopH) { + offset = (actualFrozenRow * options.rowHeight); + } else { + offset = h; + } } - else - { + else { offset = 0; } } - else - { - if(row >= actualFrozenRow) + else { + if (row >= actualFrozenRow) { offset = frozenRowsHeight; - else + } else { offset = 0; + } } } - else - { + else { offset = 0; } @@ -5087,7 +5075,7 @@ if (typeof Slick === "undefined") { } function getCellFromEvent(e) { - if(e instanceof Slick.EventData) { + if (e instanceof Slick.EventData) { e = e.getNativeEvent(); } @@ -5102,7 +5090,6 @@ if (typeof Slick === "undefined") { row = getRowFromNode(cellNode.parentNode); if (hasFrozenRows) { - var c = utils.offset(utils.parents(cellNode, '.grid-canvas')[0]); var rowOffset = 0; @@ -5426,8 +5413,9 @@ if (typeof Slick === "undefined") { // walk up the tree var offsetParent = elem.offsetParent; while ((elem = elem.parentNode) != document.body) { - if (elem == null) + if (elem == null) { break; + } const styles = getComputedStyle(elem); if (box.visible && elem.scrollHeight != elem.offsetHeight && styles["overflowY"] != "visible") { @@ -5609,29 +5597,32 @@ if (typeof Slick === "undefined") { } function navigateToRow(row) { - var num_rows = getDataLength(); - if (!num_rows) return true; + var num_rows = getDataLength(); + if (!num_rows) { return true; } - if (row < 0) row = 0; - else if (row >= num_rows) row = num_rows - 1; + if (row < 0) { + row = 0; + } else if (row >= num_rows) { + row = num_rows - 1; + } scrollCellIntoView(row, 0, true); if (options.enableCellNavigation && activeRow != null) { - var cell = 0, prevCell = null; - var prevActivePosX = activePosX; - while (cell <= activePosX) { - if (canCellBeActive(row, cell)) { - prevCell = cell; - } - cell += getColspan(row, cell); - } + var cell = 0, prevCell = null; + var prevActivePosX = activePosX; + while (cell <= activePosX) { + if (canCellBeActive(row, cell)) { + prevCell = cell; + } + cell += getColspan(row, cell); + } - if (prevCell !== null) { - setActiveCellInternal(getCellNode(row, prevCell)); - activePosX = prevActivePosX; - } else { - resetActiveCell(); - } + if (prevCell !== null) { + setActiveCellInternal(getCellNode(row, prevCell)); + activePosX = prevActivePosX; + } else { + resetActiveCell(); + } } return true; } @@ -6190,13 +6181,17 @@ if (typeof Slick === "undefined") { var logMessageMaxCount = 30; function sanitizeHtmlString(dirtyHtml, suppressLogging) { - if (!options.sanitizer || typeof dirtyHtml !== 'string') return dirtyHtml; + if (!options.sanitizer || typeof dirtyHtml !== 'string') { + return dirtyHtml; + } var cleanHtml = options.sanitizer(dirtyHtml); if (!suppressLogging && options.logSanitizedHtml && logMessageCount <= logMessageMaxCount && cleanHtml !== dirtyHtml) { console.log("sanitizer altered html: " + dirtyHtml + " --> " + cleanHtml); - if (logMessageCount === logMessageMaxCount) { console.log("sanitizer: silencing messages after first " + logMessageMaxCount); } + if (logMessageCount === logMessageMaxCount) { + console.log("sanitizer: silencing messages after first " + logMessageMaxCount); + } logMessageCount++; } return cleanHtml;