Skip to content

Commit

Permalink
Got bar highlighter nearly back online
Browse files Browse the repository at this point in the history
  • Loading branch information
robertleeplummerjr committed Feb 7, 2016
1 parent f9a5572 commit 633793c
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 102 deletions.
32 changes: 17 additions & 15 deletions Sheet/Highlighter.js
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Sheet/Loader/HTML.js
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sheet/Loader/JSON.js
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Sheet/Loader/XML.js
Expand Up @@ -397,7 +397,7 @@
xmlColumns = xmlColumn + xmlColumns;

if (row * 1 == 1) {
widths[column] = '<width>' + $(jS.col(null, column)).css('width').replace('px', '') + '</width>';
widths[column] = '<width>' + $(jS.col(column)).css('width').replace('px', '') + '</width>';
}
}

Expand Down
53 changes: 20 additions & 33 deletions Sheet/sheet.js
Expand Up @@ -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();
},

/**
Expand Down Expand Up @@ -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,
Expand All @@ -4415,17 +4418,16 @@ $.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++;
}
_row1++;
}

if (groupify) {
fn(tds, cells);
fn(tds);
}
},
/**
Expand Down Expand Up @@ -4768,8 +4770,6 @@ $.sheet = {
return false;
}

if (target.jSCell === u) return false;

var touchedCell = jS.cellFromTd(target),
ok = true;

Expand All @@ -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);
Expand Down Expand Up @@ -5853,7 +5849,7 @@ $.sheet = {
}
},
obj = [],
scrolledArea = jS.obj.pane().actionUI.scrolledArea,
scrolledArea = jS.obj.pane().actionUI.scrolledArea,
index,
row,
td,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
},

/**
Expand Down

0 comments on commit 633793c

Please sign in to comment.