r805 - in branches/1.7: . tests/visual

r805 - in branches/1.7: . tests/visual


Author: paul.bakaus
Date: Fri Oct 17 03:45:53 2008
New Revision: 805
Added:
branches/1.7/ui.selectable.js
Removed:
branches/1.7/ui.keyboardSelectable.js
Modified:
branches/1.7/tests/visual/keyboard_selection.html
Log:
selectable: renamed keyboardSelectable to selectable because it now
features mouse selection (no caret!)
Modified: branches/1.7/tests/visual/keyboard_selection.html
==============================================================================
--- branches/1.7/tests/visual/keyboard_selection.html    (original)
+++ branches/1.7/tests/visual/keyboard_selection.html    Fri Oct 17 03:45:53
2008
@@ -25,10 +25,10 @@
            
            $(document).ready(function() {
-                $("ul").keyboardSelectable({
+                $("ul").selectable({
                    
                    select: function(e, ui) {
-                        console.log(ui.selection);
+                        //console.log(ui.selection);
                    }
                    
                });
Added: branches/1.7/ui.selectable.js
==============================================================================
--- (empty file)
+++ branches/1.7/ui.selectable.js    Fri Oct 17 03:45:53 2008
@@ -0,0 +1,235 @@
+/*
+ * jQuery UI Resizable @VERSION
+ *
+ * Copyright (c) 2008 Paul Bakaus
+ * Dual licensed under the MIT (MIT-LICENSE.txt)
+ * and GPL (GPL-LICENSE.txt) licenses.
+ *
+ * http://docs.jquery.com/UI/Selectables
+ *
+ * Depends:
+ *    ui.core.js
+ */
+(function($) {
+    
+    $.widget('ui.selectable', {
+        
+        _init: function() {
+            
+            var self = this;
+            
+            //Set the currentFocus to the first item
+            this.currentFocus = $($('> *', this.element)[0]);
+            
+            //Disable text selection
+            $.ui.disableSelection(this.element);
+            
+            $('> *', this.element).bind('mousedown', function(e) {
+                self._select(e, this);
+                self.element[0].focus();
+                e.preventDefault();
+            });
+            
+            this.element
+                .bind('focus.selectable', function() {
+                    self.currentFocus.addClass(self.options.focusClass);    
+                })
+                .bind('blur.selectable', function() {
+                    self.currentFocus.removeClass(self.options.focusClass);
+                })
+                .bind('keydown.selectable', function(e) {
+
+                    if(e.keyCode == $.keyCode.DOWN || e.keyCode == $.keyCode.RIGHT) {
+                        self.selectNext(e);
+                        e.preventDefault();
+                    }
+                        
+                    if(e.keyCode == $.keyCode.UP || e.keyCode == $.keyCode.LEFT) {
+                        self.selectPrevious(e);
+                        e.preventDefault();
+                    }
+
+                });
+            
+        },
+
+        _selection: [],
+        
+        _clearSelection: function() {
+            
+            for (var i = this._selection.length - 1; i >= 0; i--){
+                this._selection[i]
+                    .removeClass(this.options.selectClass)
+                    .data('ui-selected', false);
+            };
+            
+            this._selection = [];
+                
+        },
+        
+        _toggleSelection: function(item) {
+            if(item.data('ui-selected')) {
+                this._removeFromSelection(item);
+            } else {
+                this._addToSelection(item);
+            }
+        },
+
+        _addToSelection: function(item) {
+            
+            if(item.data('ui-selected'))
+                return;
+            
+            this._selection.push(item);
+            this.latestSelection = item;
+            item
+                .addClass(this.options.selectClass)
+                .data('ui-selected', true);
+            
+        },
+        
+        _removeFromSelection: function(item) {
+
+            for (var i=0; i < this._selection.length; i++) {
+                if(this._selection[i][0] == item[0]) {
+                    this._selection[i]
+                        .removeClass(this.options.selectClass)
+                        .data('ui-selected', false);
+                    this._selection.splice(i,1);
+                    break;
+                }
+            };
+
+        },
+
+        _updateSelectionMouse: function(e) {
+
+            if(e.shiftKey && this.options.multiple) {
+
+                //Clear the previous selection to make room for a shift selection
+                this._clearSelection();
+                
+                var dir = $('> *', this.element).index(this.latestWithoutModifier[0])