/[drupal]/contributions/modules/ui/javascript/ui.droppable.js
ViewVC logotype

Diff of /contributions/modules/ui/javascript/ui.droppable.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Sun Sep 2 20:21:42 2007 UTC revision 1.2, Mon Sep 17 03:42:34 2007 UTC
# Line 1  Line 1 
1  (function($) {  (function($) {
2    
3            //Make nodes selectable by expression
4            $.extend($.expr[':'], { droppable: "(' '+a.className+' ').indexOf(' ui-droppable ')" });
5    
6            //Macros for external methods that support chaining
7            var methods = "destroy,enable,disable".split(",");
8            for(var i=0;i<methods.length;i++) {
9                    var cur = methods[i], f;
10                    eval('f = function() { var a = arguments; return this.each(function() { if(jQuery(this).is(".ui-droppable")) jQuery.data(this, "ui-droppable")["'+cur+'"](a); }); }');
11                    $.fn["droppable"+cur.substr(0,1).toUpperCase()+cur.substr(1)] = f;
12            };
13    
14            //get instance method
15            $.fn.droppableInstance = function() {
16                    if($(this[0]).is(".ui-droppable")) return $.data(this[0], "ui-droppable");
17                    return false;
18            };
19    
20          $.fn.droppable = function(o) {          $.fn.droppable = function(o) {
21                  return this.each(function() {                  return this.each(function() {
22                          new $.ui.droppable(this,o);                          new $.ui.droppable(this,o);
23                  });                  });
24          }          }
25    
         $.fn.undroppable = function() {  
   
         }  
   
26          $.ui.droppable = function(el,o) {          $.ui.droppable = function(el,o) {
27    
28                  if(!o) var o = {};                  if(!o) var o = {};
29                  this.element = el; if($.browser.msie) el.droppable = 1;                  this.element = el; if($.browser.msie) el.droppable = 1;
30                    $.data(el, "ui-droppable", this);
31    
32                  this.options = {};                  this.options = {};
33                  $.extend(this.options, o);                  $.extend(this.options, o);
# Line 28  Line 42 
42                  o = this.options;                  o = this.options;
43                  var self = this;                  var self = this;
44    
45                  $(this.element).bind("mousemove", function(e) { return self.move.apply(self, [e]); });                  this.mouseBindings = [function(e) { return self.move.apply(self, [e]); },function(e) { return self.drop.apply(self, [e]); }];
46                  $(this.element).bind("mouseup", function(e) { return self.drop.apply(self, [e]); });                  $(this.element).bind("mousemove", this.mouseBindings[0]);
47                    $(this.element).bind("mouseup", this.mouseBindings[1]);
48    
49                  $.ui.ddmanager.droppables.push({ item: this, over: 0, out: 1 }); // Add the reference and positions to the manager                  $.ui.ddmanager.droppables.push({ item: this, over: 0, out: 1 }); // Add the reference and positions to the manager
50                    $(this.element).addClass("ui-droppable");
51    
52          };          };
53    
# Line 42  Line 58 
58                                  draggable: c,                                  draggable: c,
59                                  droppable: this,                                  droppable: this,
60                                  element: c.element,                                  element: c.element,
61                                  helper: c.helper                                  helper: c.helper,
62                                    options: this.options
63                          }                          }
64                  },                  },
65                  destroy: function() {                  destroy: function() {
66                            $(this.element).removeClass("ui-droppable").removeClass("ui-droppable-disabled");
67                            $(this.element).unbind("mousemove", this.mouseBindings[0]);
68                            $(this.element).unbind("mouseup", this.mouseBindings[1]);
69    
70                            for(var i=0;i<$.ui.ddmanager.droppables.length;i++) {
71                                    if($.ui.ddmanager.droppables[i].item == this) $.ui.ddmanager.droppables.splice(i,1);
72                            }
73                    },
74                    enable: function() {
75                            $(this.element).removeClass("ui-droppable-disabled");
76                            this.disabled = false;
77                    },
78                    disable: function() {
79                            $(this.element).addClass("ui-droppable-disabled");
80                            this.disabled = true;
81                  },                  },
82                  move: function(e) {                  move: function(e) {
83    
# Line 74  Line 105 
105    
106                          var o = this.options;                          var o = this.options;
107                          if (o.accept(c.element)) {                          if (o.accept(c.element)) {
108                                  $.ui.plugin.call('over', this);                                  $.ui.plugin.call(this, 'over', [e, this.prepareCallbackObj(c)]);
109                                  $(this.element).triggerHandler("dropover", [e, this.prepareCallbackObj(c)], o.over);                                  $(this.element).triggerHandler("dropover", [e, this.prepareCallbackObj(c)], o.over);
110                          }                          }
111    
# Line 86  Line 117 
117    
118                          var o = this.options;                          var o = this.options;
119                          if (o.accept(c.element)) {                          if (o.accept(c.element)) {
120                                  $.ui.plugin.call('out', this);                                  $.ui.plugin.call(this, 'out', [e, this.prepareCallbackObj(c)]);
121                                  $(this.element).triggerHandler("dropout", [e, this.prepareCallbackObj(c)], o.out);                                  $(this.element).triggerHandler("dropout", [e, this.prepareCallbackObj(c)], o.out);
122                          }                          }
123    
# Line 100  Line 131 
131                          if(o.accept(c.element)) { // Fire callback                          if(o.accept(c.element)) { // Fire callback
132                                  if(o.greedy && !c.slowMode) {                                  if(o.greedy && !c.slowMode) {
133                                          if(c.currentTarget == this.element) {                                          if(c.currentTarget == this.element) {
134                                                  $.ui.plugin.call('drop', this);                                                  $.ui.plugin.call(this, 'drop', [e, {
135                                                            draggable: c,
136                                                            droppable: this,
137                                                            element: c.element,
138                                                            helper: c.helper
139                                                    }]);
140                                                  $(this.element).triggerHandler("drop", [e, {                                                  $(this.element).triggerHandler("drop", [e, {
141                                                          draggable: c,                                                          draggable: c,
142                                                          droppable: this,                                                          droppable: this,
# Line 109  Line 145 
145                                                  }], o.drop);                                                  }], o.drop);
146                                          }                                          }
147                                  } else {                                  } else {
148                                          $.ui.plugin.call('drop', this);                                          $.ui.plugin.call(this, 'drop', [e, this.prepareCallbackObj(c)]);
149                                          $(this.element).triggerHandler("drop", [e, this.prepareCallbackObj(c)], o.drop);                                          $(this.element).triggerHandler("drop", [e, this.prepareCallbackObj(c)], o.drop);
150                                  }                                  }
151                          }                          }
# Line 117  Line 153 
153                  },                  },
154                  activate: function(e) {                  activate: function(e) {
155                          var c = $.ui.ddmanager.current;                          var c = $.ui.ddmanager.current;
156                          $.ui.plugin.call('activate', this);                          $.ui.plugin.call(this, 'activate', [e, this.prepareCallbackObj(c)]);
157                          if(c) $(this.element).triggerHandler("dropactivate", [e, this.prepareCallbackObj(c)], this.options.activate);                          if(c) $(this.element).triggerHandler("dropactivate", [e, this.prepareCallbackObj(c)], this.options.activate);
158                  },                  },
159                  deactivate: function(e) {                  deactivate: function(e) {
160                          var c = $.ui.ddmanager.current;                          var c = $.ui.ddmanager.current;
161                          $.ui.plugin.call('deactivate', this);                          $.ui.plugin.call(this, 'deactivate', [e, this.prepareCallbackObj(c)]);
162                          if(c) $(this.element).triggerHandler("dropdeactivate", [e, this.prepareCallbackObj(c)], this.options.deactivate);                          if(c) $(this.element).triggerHandler("dropdeactivate", [e, this.prepareCallbackObj(c)], this.options.deactivate);
163                  }                  }
164          });          });

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.2