r1613 - in branches/dev/selectable: tests/visual ui

r1613 - in branches/dev/selectable: tests/visual ui


Author: paul.bakaus
Date: Thu Jan 15 12:34:59 2009
New Revision: 1613
Modified:
branches/dev/selectable/tests/visual/selectable_keyboard.html
branches/dev/selectable/ui/ui.selectable.js
Log:
dev-selectable: fixed event propagation, now includes added/removed in the
ui hash for the appropriate events
Modified: branches/dev/selectable/tests/visual/selectable_keyboard.html
==============================================================================
--- branches/dev/selectable/tests/visual/selectable_keyboard.html    (original)
+++ branches/dev/selectable/tests/visual/selectable_keyboard.html    Thu Jan
15 12:34:59 2009
@@ -30,11 +30,11 @@
                    lasso: true,
                    select: function(event, ui) {
-                        console.log('select: ', ui.item);
+                        console.log('select: ', ui.added);
                    },
                    
                    unselect: function(event, ui) {
-                        console.log('unselect', ui.item);
+                        console.log('unselect', ui.removed);
                    }
                });
Modified: branches/dev/selectable/ui/ui.selectable.js
==============================================================================
--- branches/dev/selectable/ui/ui.selectable.js    (original)
+++ branches/dev/selectable/ui/ui.selectable.js    Thu Jan 15 12:34:59 2009
@@ -180,13 +180,16 @@
        _clearSelection: function(triggerEvent) {
+            var triggerItems = [];
+
            for (var i = this._selection.length - 1; i >= 0; i--){
-                if(triggerEvent &&
this._selection[i].data('selectable-item').selected)
this._trigger('unselect', triggerEvent, this._uiHash(this._selection[i]));
+                if(triggerEvent &&
this._selection[i].data('selectable-item').selected)
triggerItems.push(this._selection[i]);
                this._selection[i].removeClass('ui-selected');
                this._selection[i].data('selectable-item').selected = false;
            };
            this._selection = [];
+            if(triggerEvent) this._trigger('unselect', triggerEvent,
this._uiHash($($.map(triggerItems, function(i) { return i[0];
})), 'removed'));
        },
@@ -219,7 +222,7 @@
                    this._selection[i].removeClass('ui-selected');
                    this._selection[i].data('selectable-item').selected = false;
                    this._selection.splice(i,1);
-                    if(triggerEvent) this._trigger('unselect', triggerEvent,
this._uiHash($(item)));
+                    if(triggerEvent) this._trigger('unselect', triggerEvent,
this._uiHash($(item), 'remove'));
                    break;
                }
            };
@@ -238,12 +241,12 @@
                var dir = $(this.options.filter,
this.element).index(this.latestWithoutModifier[0]) > $(this.options.filter,
this.element).index(this.currentFocus[0]) ? 'prev' : 'next';
                var i = this.latestWithoutModifier.data('selectable-item').selected ?
this.latestWithoutModifier[dir]() : this.latestWithoutModifier;
                while(i.length && i[0] != this.currentFocus[0]) {
-                    newlySelected.push(this._addToSelection(i));
+                    i[0] == this.previousFocus[0] ? this._addToSelection(i) :
newlySelected.push(this._addToSelection(i));
                    i = i[dir]();
                }
                //Readd the item with the current focus
-                this._addToSelection(this.currentFocus);
+                newlySelected.push(this._addToSelection(this.currentFocus));
            } else {
@@ -280,7 +283,7 @@
                        }
                    }
-                    this._addToSelection(this.currentFocus);
+                    newlySelected.push(this._addToSelection(this.currentFocus));
                }
@@ -313,7 +316,7 @@
            var newlySelected = this._updateSelectionMouse(event);
            //Trigger select event
-            this._trigger('select', event, this._uiHash(newlySelected));
+            if(newlySelected && newlySelected.length) this._trigger('select',
event, this._uiHash(newlySelected, 'added'));
        },
@@ -334,7 +337,7 @@
            var newlySelected = this._updateSelection(event, dir);
            //Trigger select event
-            this._trigger('select', event, this._uiHash(newlySelected));
+            if(newlySelected && newlySelected.length) this._trigger('select',
event, this._uiHash(newlySelected, 'added'));
        },
@@ -363,13 +366,14 @@
        },
-        _uiHash: function(item) {
-            return {
+        _uiHash: function(items, specialKey) {
+            var uiHash = {
                previousFocus: this.previousFocus,
                currentFocus: this.currentFocus,
-                selection: $($.map(this._selection, function(i) { return i[0]; })),
-                item: item
+                selection: $($.map(this._selection, function(i) { return i[0]; }))
            };
+            if(specialKey) uiHash[specialKey] = items;
+            return uiHash;
        }
    }));