From 633793c4ec0f7ebbfe3a3515b262cf816e49e8ac Mon Sep 17 00:00:00 2001 From: Robert Plummer Date: Sun, 7 Feb 2016 18:24:18 -0500 Subject: [PATCH] Got bar highlighter nearly back online --- Sheet/Highlighter.js | 32 ++++++++-------- Sheet/Loader/HTML.js | 2 +- Sheet/Loader/JSON.js | 2 +- Sheet/Loader/XML.js | 2 +- Sheet/sheet.js | 53 ++++++++++---------------- jquery.sheet.js | 91 +++++++++++++++++++------------------------- 6 files changed, 80 insertions(+), 102 deletions(-) diff --git a/Sheet/Highlighter.js b/Sheet/Highlighter.js index 3b1c2f0..2298297 100644 --- a/Sheet/Highlighter.js +++ b/Sheet/Highlighter.js @@ -20,36 +20,38 @@ Sheet.Highlighter = (function(document, window, $) { }; Constructor.prototype = { - set: function (obj) { - if (obj.parentNode !== undefined) { - obj = [obj]; + set: function (objs) { + if (objs.parentNode !== undefined) { + objs = [objs]; } var i, - oldObjects = this.last; + obj, + lastHighlighted = this.last; //_obj is the old selected items - if (oldObjects && oldObjects.length > 0) { - i = oldObjects.length - 1; + if (lastHighlighted && lastHighlighted.length > 0) { + i = lastHighlighted.length - 1; do { - oldObjects[i].isHighlighted = false; + lastHighlighted[i].isHighlighted = false; } while (i-- > 0); } - if (obj.length > 0) { - i = obj.length - 1; + if (objs.length > 0) { + i = objs.length - 1; do { - if (!obj[i].isHighlighted) { - obj[i].isHighlighted = true; - if (!obj[i].className.match(this.cssClass)) { - obj[i].className += ' ' + this.cssClass; + obj = objs[i]; + if (!obj.isHighlighted) { + obj.isHighlighted = true; + if (!obj.className.match(this.cssClass)) { + obj.className += ' ' + this.cssClass; } } } while (i-- > 0); } - this.clear(oldObjects); - this.last = obj; + this.clear(lastHighlighted); + this.last = objs; this.callBack(); return this; diff --git a/Sheet/Loader/HTML.js b/Sheet/Loader/HTML.js index 25470e9..3dcb69d 100644 --- a/Sheet/Loader/HTML.js +++ b/Sheet/Loader/HTML.js @@ -751,7 +751,7 @@ if (row * 1 == 1) { col = document.createElement('col'); - col.style.width = $(jS.col(null, column)).css('width'); + col.style.width = $(jS.col(column)).css('width'); colGroup.insertBefore(col, colGroup.firstChild); } } diff --git a/Sheet/Loader/JSON.js b/Sheet/Loader/JSON.js index 6b5adb5..04f7fdd 100644 --- a/Sheet/Loader/JSON.js +++ b/Sheet/Loader/JSON.js @@ -984,7 +984,7 @@ if (attr['colspan']) jsonColumn['colspan'] = attr['colspan'].value; if (row * 1 == 1) { - jsonSpreadsheet.metadata.widths.unshift($(jS.col(null, column)).css('width').replace('px', '')); + jsonSpreadsheet.metadata.widths.unshift($(jS.col(column)).css('width').replace('px', '')); } } } while (column-- > 1); diff --git a/Sheet/Loader/XML.js b/Sheet/Loader/XML.js index 80ea8df..5874673 100644 --- a/Sheet/Loader/XML.js +++ b/Sheet/Loader/XML.js @@ -397,7 +397,7 @@ xmlColumns = xmlColumn + xmlColumns; if (row * 1 == 1) { - widths[column] = '' + $(jS.col(null, column)).css('width').replace('px', '') + ''; + widths[column] = '' + $(jS.col(column)).css('width').replace('px', '') + ''; } } diff --git a/Sheet/sheet.js b/Sheet/sheet.js index cffbd5d..0c790be 100644 --- a/Sheet/sheet.js +++ b/Sheet/sheet.js @@ -3605,7 +3605,7 @@ $.sheet = { * @memberOf jS */ isCell:function (element) { - return element.nodeName === 'TD'; + return element.nodeName === 'TD' && element.parentNode.parentNode.parentNode.parentNode === jS.obj.pane(); }, /** @@ -4383,12 +4383,15 @@ $.sheet = { } }, - cycleTableArea: function (fn, row1, col1, row2, col2, groupify) { + cycleTableArea: function (fn, td1, td2, groupify) { var trs = jS.obj.pane().tBody.children, tr, td, tds = [], - cells = [], + row1 = td1.parentNode.rowIndex, + col1 = td1.cellIndex, + row2 = td2.parentNode.rowIndex, + col2 = td2.cellIndex, _row1, _col1, _row2, @@ -4415,9 +4418,8 @@ $.sheet = { while (_col1 <= _col2 && (td = tr.children[_col1]) !== u) { if (groupify) { tds.push(td); - cells.push(jS.cellFromTd(td)); } else { - fn(td, jS.cellFromTd(td)); + fn(td); } _col1++; } @@ -4425,7 +4427,7 @@ $.sheet = { } if (groupify) { - fn(tds, cells); + fn(tds); } }, /** @@ -4768,8 +4770,6 @@ $.sheet = { return false; } - if (target.jSCell === u) return false; - var touchedCell = jS.cellFromTd(target), ok = true; @@ -4787,11 +4787,7 @@ $.sheet = { //highlight the cells jS.cycleTableArea(function (tds) { highlighter.set(tds); - }, - cell.rowIndex, - cell.columnIndex, - touchedCell.rowIndex, - touchedCell.columnIndex, true); + }, td, target, true); } jS.followMe(target); @@ -5853,7 +5849,7 @@ $.sheet = { } }, obj = [], - scrolledArea = jS.obj.pane().actionUI.scrolledArea, + scrolledArea = jS.obj.pane().actionUI.scrolledArea, index, row, td, @@ -5892,30 +5888,30 @@ $.sheet = { highlighter.startRowIndex = 0; highlighter.endRowIndex = size.rows; - obj.push(begin); + obj.push(jS.col(begin + 1)); for (;index < endIndex;index++) { obj.push(obj[obj.length - 1].nextSibling); } break; case 'left': - start.row = first; + start.row = begin; start.col = scrolledArea.col; - stop.row = last; + stop.row = end; stop.col = scrolledArea.col; - highlighter.startRowIndex = first; + highlighter.startRowIndex = begin; highlighter.startColumnIndex = 0; - highlighter.endRowIndex = last; + highlighter.endRowIndex = end; highlighter.endColumnIndex = size.cols; - row = last; + row = begin; do { td = jS.getTd(-1, row, 0); if (td === null) continue; obj.push(td.parentNode); - } while(row-- > first); + } while(row-- > begin); break; case 'corner': //all start.row = 0; @@ -6311,21 +6307,12 @@ $.sheet = { /** * get col associated with a sheet/table within an instance - * @param {jQuery|HTMLElement} table - * @param {Number} [i] Index of column, default is last + * @param {Number} i Index of column * @returns {Element} * @memberOf jS */ - col:function (table, i) { - table = table || jS.obj.table()[0]; - - var cols = jS.cols(table); - - if (i === u) { - i = cols.length - 1; - } - - return cols[i]; + col:function (i) { + return jS.obj.pane().actionUI.megaTable.col(i); }, /** diff --git a/jquery.sheet.js b/jquery.sheet.js index d0696c4..5f525ac 100644 --- a/jquery.sheet.js +++ b/jquery.sheet.js @@ -6015,7 +6015,7 @@ $.sheet = { * @memberOf jS */ isCell:function (element) { - return element.nodeName === 'TD'; + return element.nodeName === 'TD' && element.parentNode.parentNode.parentNode.parentNode === jS.obj.pane(); }, /** @@ -6793,12 +6793,15 @@ $.sheet = { } }, - cycleTableArea: function (fn, row1, col1, row2, col2, groupify) { + cycleTableArea: function (fn, td1, td2, groupify) { var trs = jS.obj.pane().tBody.children, tr, td, tds = [], - cells = [], + row1 = td1.parentNode.rowIndex, + col1 = td1.cellIndex, + row2 = td2.parentNode.rowIndex, + col2 = td2.cellIndex, _row1, _col1, _row2, @@ -6825,9 +6828,8 @@ $.sheet = { while (_col1 <= _col2 && (td = tr.children[_col1]) !== u) { if (groupify) { tds.push(td); - cells.push(jS.cellFromTd(td)); } else { - fn(td, jS.cellFromTd(td)); + fn(td); } _col1++; } @@ -6835,7 +6837,7 @@ $.sheet = { } if (groupify) { - fn(tds, cells); + fn(tds); } }, /** @@ -7178,8 +7180,6 @@ $.sheet = { return false; } - if (target.jSCell === u) return false; - var touchedCell = jS.cellFromTd(target), ok = true; @@ -7197,11 +7197,7 @@ $.sheet = { //highlight the cells jS.cycleTableArea(function (tds) { highlighter.set(tds); - }, - cell.rowIndex, - cell.columnIndex, - touchedCell.rowIndex, - touchedCell.columnIndex, true); + }, td, target, true); } jS.followMe(target); @@ -8263,7 +8259,7 @@ $.sheet = { } }, obj = [], - scrolledArea = jS.obj.pane().actionUI.scrolledArea, + scrolledArea = jS.obj.pane().actionUI.scrolledArea, index, row, td, @@ -8302,30 +8298,30 @@ $.sheet = { highlighter.startRowIndex = 0; highlighter.endRowIndex = size.rows; - obj.push(begin); + obj.push(jS.col(begin)); for (;index < endIndex;index++) { obj.push(obj[obj.length - 1].nextSibling); } break; case 'left': - start.row = first; + start.row = begin; start.col = scrolledArea.col; - stop.row = last; + stop.row = end; stop.col = scrolledArea.col; - highlighter.startRowIndex = first; + highlighter.startRowIndex = begin; highlighter.startColumnIndex = 0; - highlighter.endRowIndex = last; + highlighter.endRowIndex = end; highlighter.endColumnIndex = size.cols; - row = last; + row = begin; do { td = jS.getTd(-1, row, 0); if (td === null) continue; obj.push(td.parentNode); - } while(row-- > first); + } while(row-- > begin); break; case 'corner': //all start.row = 0; @@ -8721,21 +8717,12 @@ $.sheet = { /** * get col associated with a sheet/table within an instance - * @param {jQuery|HTMLElement} table - * @param {Number} [i] Index of column, default is last + * @param {Number} i Index of column * @returns {Element} * @memberOf jS */ - col:function (table, i) { - table = table || jS.obj.table()[0]; - - var cols = jS.cols(table); - - if (i === u) { - i = cols.length - 1; - } - - return cols[i]; + col:function (i) { + return jS.obj.pane().actionUI.megaTable.col(i); }, /** @@ -11053,7 +11040,7 @@ $.printSource = function (s) { if (row * 1 == 1) { col = document.createElement('col'); - col.style.width = $(jS.col(null, column)).css('width'); + col.style.width = $(jS.col(column)).css('width'); colGroup.insertBefore(col, colGroup.firstChild); } } @@ -12067,7 +12054,7 @@ $.printSource = function (s) { if (attr['colspan']) jsonColumn['colspan'] = attr['colspan'].value; if (row * 1 == 1) { - jsonSpreadsheet.metadata.widths.unshift($(jS.col(null, column)).css('width').replace('px', '')); + jsonSpreadsheet.metadata.widths.unshift($(jS.col(column)).css('width').replace('px', '')); } } } while (column-- > 1); @@ -12638,7 +12625,7 @@ $.printSource = function (s) { xmlColumns = xmlColumn + xmlColumns; if (row * 1 == 1) { - widths[column] = '' + $(jS.col(null, column)).css('width').replace('px', '') + ''; + widths[column] = '' + $(jS.col(column)).css('width').replace('px', '') + ''; } } @@ -14722,36 +14709,38 @@ Sheet.Highlighter = (function(document, window, $) { }; Constructor.prototype = { - set: function (obj) { - if (obj.parentNode !== undefined) { - obj = [obj]; + set: function (objs) { + if (objs.parentNode !== undefined) { + objs = [objs]; } var i, - oldObjects = this.last; + obj, + lastHighlighted = this.last; //_obj is the old selected items - if (oldObjects && oldObjects.length > 0) { - i = oldObjects.length - 1; + if (lastHighlighted && lastHighlighted.length > 0) { + i = lastHighlighted.length - 1; do { - oldObjects[i].isHighlighted = false; + lastHighlighted[i].isHighlighted = false; } while (i-- > 0); } - if (obj.length > 0) { - i = obj.length - 1; + if (objs.length > 0) { + i = objs.length - 1; do { - if (!obj[i].isHighlighted) { - obj[i].isHighlighted = true; - if (!obj[i].className.match(this.cssClass)) { - obj[i].className += ' ' + this.cssClass; + obj = objs[i]; + if (!obj.isHighlighted) { + obj.isHighlighted = true; + if (!obj.className.match(this.cssClass)) { + obj.className += ' ' + this.cssClass; } } } while (i-- > 0); } - this.clear(oldObjects); - this.last = obj; + this.clear(lastHighlighted); + this.last = objs; this.callBack(); return this;