Commits

zindel  committed 0a4a7ad

replacing data-onclick with data-onuserselect

  • Participants
  • Parent commits f548789

Comments (0)

Files changed (1)

File htraf/jquery.htraf.js

         SERVER: 'data-server',
         HTSQL_PREFIX: 'data-htsql-prefix',
         CHANGE: 'change',
-        CLICK: 'click',
+        USERSELECT: 'userselect',
         BEFORELOAD: 'beforeload',
         AFTERLOAD: 'afterload',
         EMPTY: 'empty',
 
 // {{{ Widget Utils
 function selectable(obj, property, attribute) {
+    // TODO: consider using $.delegate() here
+
     obj._selectable = function() {
         var set = this[property], self = this;
         set.mouseover(function() {
             return null;
         return this.data.data[this._index] || null;
     };
+
+    obj.removeUserSelect = function() {
+        if(this[property])
+            this[property].unbind('click.userselect');                  
+    };
+
+    obj.addUserSelect = function() {
+        var self = this;
+        this[property].bind('click.userselect', function() {
+            self._trigger(USERSELECT); 
+        });  
+    };
 }
 $.fn.htrafProc = function() {
     var args = $.makeArray(arguments);
         this._setupSource();
 
         bindPlugin('pre');
-        this.element.bind([CHANGE, CLICK, BEFORELOAD, AFTERLOAD, EMPTY].join(' '),
+        this.element.bind(
+            [CHANGE, BEFORELOAD, AFTERLOAD, EMPTY, USERSELECT].join(' '),
             function(e) {
                 var code = $(this).attr('data-on' + e.type);
                 if(!code)
         return this._htsqlPrefix + url;
     },
 
+    removeUserSelect: function() {
+    
+    },
+
+    addUserSelect: function() {
+                   
+    },
+
     _loaded: function(data) {
+        this.removeUserSelect();
         this.data = data;
         this.clear();
         this.render();
         this.setup();
+        this.addUserSelect();
     },
 
     loadLocal: function() {
     setValue: function(value) {
         value = value === null ? '':value + '';          
         this.element._valOrig(value);
+    },
+
+    removeUserSelect: function() {
+        this.element.unbind('change.userselect');                  
+    },
+
+    addUserSelect: function() {
+        var self = this;
+        this.element.bind('change.userselect', function() {
+            self._trigger(USERSELECT); 
+        });               
     }
 });
 // }}}