Added WCF.EditableItemList
authorAlexander Ebert <ebert@woltlab.com>
Thu, 10 May 2012 16:39:15 +0000 (18:39 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 10 May 2012 16:39:15 +0000 (18:39 +0200)
wcfsetup/install/files/js/WCF.js

index 9846a5d4125a86283ab7c25e2e97f5caad9d50fa..a0a83d0772ff703569d63c6c35a74c04e74f0444 100644 (file)
@@ -993,7 +993,7 @@ WCF.Clipboard = {
         * Closes the clipboard editor item list.
         */
        _closeLists: function() {
-               $('.jsClipboardEditor ul').removeClass('dropdownOpen')
+               $('.jsClipboardEditor ul').removeClass('dropdownOpen');
        },
        
        /**
@@ -3965,7 +3965,7 @@ WCF.Search.Base = Class.extend({
                
                this._list.parent().addClass('dropdownOpen');
                
-               WCF.CloseOverlayHandler.addCallback('WCF.Search.Base', $.proxy(function() { this._clearList(true) }, this));
+               WCF.CloseOverlayHandler.addCallback('WCF.Search.Base', $.proxy(function() { this._clearList(true); }, this));
        },
        
        /**
@@ -5339,7 +5339,7 @@ WCF.Popover = Class.extend({
                return {
                        x: $orientationX,
                        y: $orientationY
-               }
+               };
        },
        
        /**
@@ -5454,6 +5454,52 @@ WCF.Popover = Class.extend({
        }
 });
 
+WCF.EditableItemList = Class.extend({
+       _data: { },
+       _itemList: null,
+       _search: null,
+       _searchInput: null,
+       
+       init: function(itemListSelector, searchInputSelector) {
+               this._itemList = $(itemListSelector);
+               this._searchInput = $(searchInputSelector);
+               
+               if (!this._itemList.length || !this._searchInput.length) {
+                       console.debug("[WCF.EditableItemList] Item list and/or search input do not exist, aborting.");
+                       return;
+               }
+               
+               // bind item listener
+               this._itemList.find('.jsEditableItem').click($.proxy(this._click, this));
+       },
+       
+       /**
+        * Loads raw data and converts it into internal structure. Override this methods
+        * in your derived classes.
+        * 
+        * @param       object          data
+        */
+       load: function(data) { },
+       
+       _click: function(event) {
+               var $element = $(event.currentTarget);
+               var $objectID = $element.data('objectID');
+               
+               if (this._data[$objectID]) {
+                       delete this._data[$objectID];
+               }
+               
+               $element.remove();
+               
+               event.stopPropagation();
+               return false;
+       },
+       
+       addItem: function() {
+               
+       }
+});
+
 /**
  * Provides a toggleable sidebar.
  */