Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor selection batching code a bit; underscore internal methods

  • Loading branch information...
commit cfef930e264db279a91b51c877eb97977f133dcc 1 parent b661201
@kfranqueiro kfranqueiro authored
Showing with 43 additions and 39 deletions.
  1. +1 −1  CellSelection.js
  2. +27 −26 Selection.js
  3. +15 −12 Selector.js
View
2  CellSelection.js
@@ -62,7 +62,7 @@ return declare([Selection], {
}
}
if(value != previous && element){
- this.selectionEventQueue(value, "cells").push(cell);
+ this._selectionEventQueue(value, "cells").push(cell);
}
if(toCell){
// a range
View
53 Selection.js
@@ -179,29 +179,29 @@ return declare([List], {
return true;
},
- selectionEventQueue: function(value, type){
- var event = "dgrid-" + (value ? "select" : "deselect");
- // get the event queue
- var rows = this[event];
- if(!rows){
- var grid = this;
- // create a timeout to fire an event for the accumulated rows once everything is done
- setTimeout(this.fireSelectionEvent = function(){ // we setup a method here in case the event needs to fired immediately
- if(rows){
- var eventObject = {
- bubbles: true,
- grid: grid
- }
- eventObject[type] = rows;
- on.emit(grid.contentNode, event, eventObject);
- rows = null;
- // clear the queue, so we create a new one as needed
- delete grid[event];
- }
- });
- rows = this[event] = [];
- }
- return rows;
+ _selectionEventQueue: function(value, type){
+ var grid = this,
+ event = "dgrid-" + (value ? "select" : "deselect"),
+ rows = this[event]; // current event queue (actually cells for CellSelection)
+
+ if(rows){ return rows; } // return existing queue, allowing to push more
+
+ // Create a timeout to fire an event for the accumulated rows once everything is done.
+ // We expose the callback in case the event needs to be fired immediately.
+ setTimeout(this._fireSelectionEvent = function(){
+ if(!rows){ return; } // rows will be set only the first time this is called
+
+ var eventObject = {
+ bubbles: true,
+ grid: grid
+ };
+ eventObject[type] = rows;
+ on.emit(grid.contentNode, event, eventObject);
+ rows = null;
+ // clear the queue, so we create a new one as needed
+ delete grid[event];
+ }, 0);
+ return (rows = this[event] = []);
},
select: function(row, toRow, value){
if(value === undefined){
@@ -234,7 +234,7 @@ return declare([List], {
}
if(value != previousValue && element){
// add to the queue of row events
- this.selectionEventQueue(value, "rows").push(row);
+ this._selectionEventQueue(value, "rows").push(row);
}
if(toRow){
@@ -286,8 +286,9 @@ return declare([List], {
refresh: function(){
if(this.deselectOnRefresh){
this.clearSelection();
- // need to fire the selection event now because after the refresh the nodes that we will fire for will be gone
- this.fireSelectionEvent && this.fireSelectionEvent();
+ // Need to fire the selection event now because after the refresh,
+ // the nodes that we will fire for will be gone.
+ this._fireSelectionEvent && this._fireSelectionEvent();
}
this._lastSelected = null;
this.inherited(arguments);
View
27 Selector.js
@@ -8,8 +8,11 @@ define(["dojo/on", "dojo/aspect", "dojo/_base/sniff", "put-selector/put"], funct
function changeInput(value){
// creates a function that modifies the input on an event
return function(event){
- var rows = event.rows;
- for(var i = 0; i < rows.length; i++){
+ var rows = event.rows,
+ len = rows.length,
+ selection, mixed, i;
+
+ for(i = 0; i < len; i++){
var element = grid.cell(rows[i], column.id).element;
element = (element.contents || element).input;
if(!element.disabled){
@@ -17,17 +20,17 @@ define(["dojo/on", "dojo/aspect", "dojo/_base/sniff", "put-selector/put"], funct
element.checked = value;
}
}
- // see if the header checkbox needs to be indeterminate
- var mixed = false;
- var selection = grid.selection;
- for(var i in selection){
- // if there is anything in the selection, than it is indeterminate
- if(selection[i] != grid.allSelected){
- mixed = true;
- break;
- }
- }
if(headerCheckbox.type == "checkbox"){
+ selection = grid.selection;
+ mixed = false;
+ // see if the header checkbox needs to be indeterminate
+ for(i in selection){
+ // if there is anything in the selection, than it is indeterminate
+ if(selection[i] != grid.allSelected){
+ mixed = true;
+ break;
+ }
+ }
headerCheckbox.indeterminate = mixed;
headerCheckbox.checked = grid.allSelected;
}
Please sign in to comment.
Something went wrong with that request. Please try again.