Permalink
Browse files

Remove cancelable behavior on select and update selection before even…

…t is fired
  • Loading branch information...
1 parent 463545e commit f6bbb4cdfad367cd5ba20eab26bddc0bc9ad6e2b @kriszyp committed Feb 6, 2012
Showing with 54 additions and 61 deletions.
  1. +29 −30 CellSelection.js
  2. +20 −21 Selection.js
  3. +5 −10 test/Selection.html
View
@@ -35,40 +35,31 @@ return declare([Selection], {
// indicates a toggle
value = !previous;
}
- var element = cell.element,
- notPrevented = true;
- if(previous == value ||
- (!element || (notPrevented = listen.emit(element, "dgrid-" + (value ? "select" : "deselect"), {
- cancelable: true,
- bubbles: true,
- cell: cell,
- grid: this
- })))){
- previousRow = previousRow || {};
- previousRow[cell.column.id] = value;
- this.selection[rowId] = previousRow;
-
- // Check for all-false objects to see if it can be deleted.
- // This prevents build-up of unnecessary iterations later.
- var hasSelected = false;
- for(var i in previousRow){
- if(previousRow[i] === true){
- hasSelected = true;
- break;
- }
+ var element = cell.element;
+ previousRow = previousRow || {};
+ previousRow[cell.column.id] = value;
+ this.selection[rowId] = previousRow;
+
+ // Check for all-false objects to see if it can be deleted.
+ // This prevents build-up of unnecessary iterations later.
+ var hasSelected = false;
+ for(var i in previousRow){
+ if(previousRow[i] === true){
+ hasSelected = true;
+ break;
}
- if(!hasSelected){ delete this.selection[rowId]; }
+ }
+ if(!hasSelected){ delete this.selection[rowId]; }
- if(element){
- // add or remove classes as appropriate
- if(value){
- put(element, ".dgrid-selected.ui-state-active");
- }else{
- put(element, "!dgrid-selected!ui-state-active");
- }
+ if(element){
+ // add or remove classes as appropriate
+ if(value){
+ put(element, ".dgrid-selected.ui-state-active");
+ }else{
+ put(element, "!dgrid-selected!ui-state-active");
}
}
- if(toCell && notPrevented){
+ if(toCell){
// a range
if(!toCell.element){
toCell = this.cell(toCell);
@@ -110,6 +101,14 @@ return declare([Selection], {
}
}while(nextNode = cell.row.element[traverser]);
}
+ if(value != previous && element){
+ listen.emit(element, "dgrid-" + (value ? "select" : "deselect"), {
+ cancelable: true,
+ bubbles: true,
+ cell: cell,
+ grid: this
+ });
+ }
},
isSelected: function(object, columnId){
if(!object){
View
@@ -159,30 +159,21 @@ return declare([List], {
// indicates a toggle
value = !previousValue;
}
- var element = row.element,
- notPrevented = true;
- if(value == previousValue ||
- (!element || (notPrevented = on.emit(element, "dgrid-" + (value ? "select" : "deselect"), {
- cancelable: true,
- bubbles: true,
- row: row,
- grid: this
- })))){
- if(!value && !this.allSelected){
- delete this.selection[row.id];
+ var element = row.element;
+ if(!value && !this.allSelected){
+ delete this.selection[row.id];
+ }else{
+ selection[row.id] = value;
+ }
+ if(element){
+ // add or remove classes as appropriate
+ if(value){
+ put(element, ".dgrid-selected.ui-state-active");
}else{
- selection[row.id] = value;
- }
- if(element){
- // add or remove classes as appropriate
- if(value){
- put(element, ".dgrid-selected.ui-state-active");
- }else{
- put(element, "!dgrid-selected!ui-state-active");
- }
+ put(element, "!dgrid-selected!ui-state-active");
}
}
- if(toRow && notPrevented){
+ if(toRow){
if(!toRow.element){
toRow = this.row(toRow);
}
@@ -199,6 +190,14 @@ return declare([List], {
}
}
}
+ if(value != previousValue && element){
+ on.emit(element, "dgrid-" + (value ? "select" : "deselect"), {
+ cancelable: true,
+ bubbles: true,
+ row: row,
+ grid: this
+ });
+ }
},
deselect: function(row, toRow){
this.select(row, toRow, false);
View
@@ -41,15 +41,14 @@
}else{
console.log(msg + event.grid.id + ": row " + event.row.id);
}
- if(prevent){ event.preventDefault(); }
+ var selection = [];
+ for(var id in event.grid.selection){
+ selection.push(id);
+ }
+ console.log("selection", selection);
}
);
- on(document.getElementById("btnPreventDefaultOn"), "click",
- function(){ prevent = true; });
- on(document.getElementById("btnPreventDefaultOff"), "click",
- function(){ prevent = false; });
-
gridRowNavigation = dojo.declare([Grid, Selection, Keyboard])({
store: testStore,
cellNavigation: false,
@@ -91,10 +90,6 @@
</script>
</head>
<body class="nihilo">
- <div>preventDefault on selection in all grids?
- <button type="button" id="btnPreventDefaultOn">Yes</button>
- <button type="button" id="btnPreventDefaultOff">No</button>
- </div>
<h2>A grid with row-level selection (and row-level navigation)</h2>
<div>Set selectionMode:
<button type="button" onclick="gridRowNavigation.setSelectionMode('none');">None</button>

0 comments on commit f6bbb4c

Please sign in to comment.