Skip to content

Commit

Permalink
Using prototype methods so public methods don't get reinitialized eve…
Browse files Browse the repository at this point in the history
…ry time.
  • Loading branch information
jonricaurte committed Apr 30, 2013
1 parent 5c1813d commit 14d894d
Show file tree
Hide file tree
Showing 3 changed files with 188 additions and 189 deletions.
141 changes: 72 additions & 69 deletions src/classes/aggregate.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,77 @@
var ngAggregate = function (aggEntity, rowFactory, rowHeight, groupInitState) {
var self = this;
self.rowIndex = 0;
self.offsetTop = self.rowIndex * rowHeight;
self.entity = aggEntity;
self.label = aggEntity.gLabel;
self.field = aggEntity.gField;
self.depth = aggEntity.gDepth;
self.parent = aggEntity.parent;
self.children = aggEntity.children;
self.aggChildren = aggEntity.aggChildren;
self.aggIndex = aggEntity.aggIndex;
self.collapsed = groupInitState;
self.isAggRow = true;
self.offsetLeft = aggEntity.gDepth * 25;
self.aggLabelFilter = aggEntity.aggLabelFilter;
self.toggleExpand = function() {
self.collapsed = self.collapsed ? false : true;
if (self.orig) {
self.orig.collapsed = self.collapsed;
}
self.notifyChildren();
};
self.setExpand = function(state) {
self.collapsed = state;
self.notifyChildren();
};
self.notifyChildren = function () {
var longest = Math.max(rowFactory.aggCache.length, self.children.length);
for (var i = 0; i < longest; i++) {
if (self.aggChildren[i]) {
self.aggChildren[i].entity[NG_HIDDEN] = self.collapsed;
if (self.collapsed) {
self.aggChildren[i].setExpand(self.collapsed);
}
}
if (self.children[i]) {
self.children[i][NG_HIDDEN] = self.collapsed;
this.rowIndex = 0;
this.offsetTop = this.rowIndex * rowHeight;
this.entity = aggEntity;
this.label = aggEntity.gLabel;
this.field = aggEntity.gField;
this.depth = aggEntity.gDepth;
this.parent = aggEntity.parent;
this.children = aggEntity.children;
this.aggChildren = aggEntity.aggChildren;
this.aggIndex = aggEntity.aggIndex;
this.collapsed = groupInitState;
this.groupInitState = groupInitState;
this.rowFactory = rowFactory;
this.rowHeight = rowHeight;
this.isAggRow = true;
this.offsetLeft = aggEntity.gDepth * 25;
this.aggLabelFilter = aggEntity.aggLabelFilter;
};

ngAggregate.prototype.toggleExpand = function () {
this.collapsed = this.collapsed ? false : true;
if (this.orig) {
this.orig.collapsed = this.collapsed;
}
this.notifyChildren();
};
ngAggregate.prototype.setExpand = function (state) {
this.collapsed = state;
this.notifyChildren();
};
ngAggregate.prototype.notifyChildren = function () {
var longest = Math.max(this.rowFactory.aggCache.length, this.children.length);
for (var i = 0; i < longest; i++) {
if (this.aggChildren[i]) {
this.aggChildren[i].entity[NG_HIDDEN] = this.collapsed;
if (this.collapsed) {
this.aggChildren[i].setExpand(this.collapsed);
}
if (i > self.aggIndex && rowFactory.aggCache[i]) {
var agg = rowFactory.aggCache[i];
var offset = (30 * self.children.length);
agg.offsetTop = self.collapsed ? agg.offsetTop - offset : agg.offsetTop + offset;
}
if (this.children[i]) {
this.children[i][NG_HIDDEN] = this.collapsed;
}
if (i > this.aggIndex && this.rowFactory.aggCache[i]) {
var agg = this.rowFactory.aggCache[i];
var offset = (30 * this.children.length);
agg.offsetTop = this.collapsed ? agg.offsetTop - offset : agg.offsetTop + offset;
}
}
this.rowFactory.renderedChange();
};
ngAggregate.prototype.aggClass = function () {
return this.collapsed ? "ngAggArrowCollapsed" : "ngAggArrowExpanded";
};
ngAggregate.prototype.totalChildren = function () {
if (this.aggChildren.length > 0) {
var i = 0;
var recurse = function (cur) {
if (cur.aggChildren.length > 0) {
angular.forEach(cur.aggChildren, function (a) {
recurse(a);
});
} else {
i += cur.children.length;
}
};
rowFactory.renderedChange();
};
self.aggClass = function() {
return self.collapsed ? "ngAggArrowCollapsed" : "ngAggArrowExpanded";
};
self.totalChildren = function() {
if (self.aggChildren.length > 0) {
var i = 0;
var recurse = function(cur) {
if (cur.aggChildren.length > 0) {
angular.forEach(cur.aggChildren, function(a) {
recurse(a);
});
} else {
i += cur.children.length;
}
};
recurse(self);
return i;
} else {
return self.children.length;
}
};
self.copy = function () {
var ret = new ngAggregate(self.entity, rowFactory, rowHeight, groupInitState);
ret.orig = self;
return ret;
};
recurse(this);
return i;
} else {
return this.children.length;
}
};
ngAggregate.prototype.copy = function () {
var ret = new ngAggregate(this.entity, this.rowFactory, this.rowHeight, this.groupInitState);
ret.orig = this;
return ret;
};
94 changes: 47 additions & 47 deletions src/classes/domAccessProvider.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
var ngDomAccessProvider = function (grid) {
var self = this, previousColumn;
self.selectInputElement = function(elm){
var node = elm.nodeName.toLowerCase();
if(node == 'input' || node == 'textarea'){
elm.select();
}
};

self.focusCellElement = function($scope, index){
if($scope.selectionProvider.lastClickedRow){
var columnIndex = index != undefined ? index : previousColumn;
var elm = $scope.selectionProvider.lastClickedRow.clone ? $scope.selectionProvider.lastClickedRow.clone.elm : $scope.selectionProvider.lastClickedRow.elm;
if (columnIndex != undefined && elm) {
var columns = angular.element(elm[0].children).filter(function () { return this.nodeType != 8;}); //Remove html comments for IE8
var i = Math.max(Math.min($scope.renderedColumns.length - 1, columnIndex), 0);
if(grid.config.showSelectionCheckbox && angular.element(columns[i]).scope() && angular.element(columns[i]).scope().col.index == 0){
i = 1; //don't want to focus on checkbox
}
if (columns[i]) {
columns[i].children[0].focus();
}
previousColumn = columnIndex;
}
}
};

var changeUserSelect = function(elm, value) {
this.previousColumn = null;
this.grid = grid;

var changeUserSelect = function (elm, value) {
elm.css({
'-webkit-touch-callout': value,
'-webkit-user-select': value,
'-khtml-user-select': value,
'-moz-user-select': value == 'none'
'-moz-user-select': value === 'none'
? '-moz-none'
: value,
'-ms-user-select': value,
'user-select': value
});
};

self.selectionHandlers = function($scope, elm){
var doingKeyDown = false;
elm.bind('keydown', function(evt) {
if (evt.keyCode == 16) { //shift key
changeUserSelect(elm, 'none', evt);
return true;
} else if (!doingKeyDown) {
doingKeyDown = true;
var ret = ngMoveSelectionHandler($scope, elm, evt, grid);
doingKeyDown = false;
return ret;
};

ngDomAccessProvider.prototype.selectInputElement = function (elm) {
var node = elm.nodeName.toLowerCase();
if (node === 'input' || node === 'textarea') {
elm.select();
}
};
ngDomAccessProvider.prototype.focusCellElement = function ($scope, index) {
if ($scope.selectionProvider.lastClickedRow) {
var columnIndex = index !== undefined ? index : previousColumn;
var elm = $scope.selectionProvider.lastClickedRow.clone ? $scope.selectionProvider.lastClickedRow.clone.elm : $scope.selectionProvider.lastClickedRow.elm;
if (columnIndex !== undefined && elm) {
var columns = angular.element(elm[0].children).filter(function () { return this.nodeType !== 8; }); //Remove html comments for IE8
var i = Math.max(Math.min($scope.renderedColumns.length - 1, columnIndex), 0);
if (this.grid.config.showSelectionCheckbox && angular.element(columns[i]).scope() && angular.element(columns[i]).scope().col.index === 0) {
i = 1; //don't want to focus on checkbox
}
return true;
});
elm.bind('keyup', function(evt) {
if (evt.keyCode == 16) { //shift key
changeUserSelect(elm, 'text', evt);
if (columns[i]) {
columns[i].children[0].focus();
}
previousColumn = columnIndex;
}
}
};
ngDomAccessProvider.prototype.selectionHandlers = function ($scope, elm) {
var doingKeyDown = false;
elm.bind('keydown', function (evt) {
if (evt.keyCode === 16) { //shift key
changeUserSelect(elm, 'none', evt);
return true;
});
};
} else if (!doingKeyDown) {
doingKeyDown = true;
var ret = ngMoveSelectionHandler($scope, elm, evt, this.grid);
doingKeyDown = false;
return ret;
}
return true;
});
elm.bind('keyup', function (evt) {
if (evt.keyCode === 16) { //shift key
changeUserSelect(elm, 'text', evt);
}
return true;
});
};
Loading

0 comments on commit 14d894d

Please sign in to comment.