| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 /* 2 * jQuery UI Droppable 1.6 3 * 4 * Copyright (c) 2008 AUTHORS.txt (http://ui.jquery.com/about) 5 * Dual licensed under the MIT (MIT-LICENSE.txt) 6 * and GPL (GPL-LICENSE.txt) licenses. 7 * 8 * http://docs.jquery.com/UI/Droppables 9 * 10 * Depends: 11 * ui.core.js 12 * ui.draggable.js 13 */ 14 (function($) { 15 16 $.widget("ui.droppable", { 17 18 _init: function() { 19 20 var o = this.options, accept = o.accept; 21 this.isover = 0; this.isout = 1; 22 23 this.options.accept = this.options.accept && $.isFunction(this.options.accept) ? this.options.accept : function(d) { 24 return d.is(accept); 25 }; 26 27 //Store the droppable's proportions 28 this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight }; 29 30 // Add the reference and positions to the manager 31 $.ui.ddmanager.droppables[this.options.scope] = $.ui.ddmanager.droppables[this.options.scope] || []; 32 $.ui.ddmanager.droppables[this.options.scope].push(this); 33 34 (this.options.cssNamespace && this.element.addClass(this.options.cssNamespace+"-droppable")); 35 36 }, 37 38 destroy: function() { 39 var drop = $.ui.ddmanager.droppables[this.options.scope]; 40 for ( var i = 0; i < drop.length; i++ ) 41 if ( drop[i] == this ) 42 drop.splice(i, 1); 43 44 this.element 45 .removeClass("ui-droppable-disabled") 46 .removeData("droppable") 47 .unbind(".droppable"); 48 }, 49 50 _setData: function(key, value) { 51 52 if(key == 'accept') { 53 this.options.accept = value && $.isFunction(value) ? value : function(d) { 54 return d.is(accept); 55 }; 56 } else { 57 $.widget.prototype._setData.apply(this, arguments); 58 } 59 60 }, 61 62 _activate: function(event) { 63 64 var draggable = $.ui.ddmanager.current; 65 $.ui.plugin.call(this, 'activate', [event, this.ui(draggable)]); 66 if(draggable) this.element.triggerHandler("dropactivate", [event, this.ui(draggable)], this.options.activate); 67 68 }, 69 70 _deactivate: function(event) { 71 72 var draggable = $.ui.ddmanager.current; 73 $.ui.plugin.call(this, 'deactivate', [event, this.ui(draggable)]); 74 if(draggable) this.element.triggerHandler("dropdeactivate", [event, this.ui(draggable)], this.options.deactivate); 75 76 }, 77 78 _over: function(event) { 79 80 var draggable = $.ui.ddmanager.current; 81 if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element 82 83 if (this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) { 84 $.ui.plugin.call(this, 'over', [event, this.ui(draggable)]); 85 this.element.triggerHandler("dropover", [event, this.ui(draggable)], this.options.over); 86 } 87 88 }, 89 90 _out: function(event) { 91 92 var draggable = $.ui.ddmanager.current; 93 if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return; // Bail if draggable and droppable are same element 94 95 if (this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) { 96 $.ui.plugin.call(this, 'out', [event, this.ui(draggable)]); 97 this.element.triggerHandler("dropout", [event, this.ui(draggable)], this.options.out); 98 } 99 100 }, 101 102 _drop: function(event,custom) { 103 104 var draggable = custom || $.ui.ddmanager.current; 105 if (!draggable || (draggable.currentItem || draggable.element)[0] == this.element[0]) return false; // Bail if draggable and droppable are same element 106 107 var childrenIntersection = false; 108 this.element.find(":data(droppable)").not(".ui-draggable-dragging").each(function() { 109 var inst = $.data(this, 'droppable'); 110 if(inst.options.greedy && $.ui.intersect(draggable, $.extend(inst, { offset: inst.element.offset() }), inst.options.tolerance)) { 111 childrenIntersection = true; return false; 112 } 113 }); 114 if(childrenIntersection) return false; 115 116 if(this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) { 117 $.ui.plugin.call(this, 'drop', [event, this.ui(draggable)]); 118 this.element.triggerHandler("drop", [event, this.ui(draggable)], this.options.drop); 119 return this.element; 120 } 121 122 return false; 123 124 }, 125 126 plugins: {}, 127 128 ui: function(c) { 129 return { 130 draggable: (c.currentItem || c.element), 131 helper: c.helper, 132 position: c.position, 133 absolutePosition: c.positionAbs, 134 options: this.options, 135 element: this.element 136 }; 137 } 138 139 }); 140 141 $.extend($.ui.droppable, { 142 version: "1.6", 143 defaults: { 144 accept: '*', 145 activeClass: null, 146 cssNamespace: 'ui', 147 greedy: false, 148 hoverClass: null, 149 scope: 'default', 150 tolerance: 'intersect' 151 } 152 }); 153 154 $.ui.intersect = function(draggable, droppable, toleranceMode) { 155 156 if (!droppable.offset) return false; 157 158 var x1 = (draggable.positionAbs || draggable.position.absolute).left, x2 = x1 + draggable.helperProportions.width, 159 y1 = (draggable.positionAbs || draggable.position.absolute).top, y2 = y1 + draggable.helperProportions.height; 160 var l = droppable.offset.left, r = l + droppable.proportions.width, 161 t = droppable.offset.top, b = t + droppable.proportions.height; 162 163 switch (toleranceMode) { 164 case 'fit': 165 return (l < x1 && x2 < r 166 && t < y1 && y2 < b); 167 break; 168 case 'intersect': 169 return (l < x1 + (draggable.helperProportions.width / 2) // Right Half 170 && x2 - (draggable.helperProportions.width / 2) < r // Left Half 171 && t < y1 + (draggable.helperProportions.height / 2) // Bottom Half 172 && y2 - (draggable.helperProportions.height / 2) < b ); // Top Half 173 break; 174 case 'pointer': 175 var draggableLeft = ((draggable.positionAbs || draggable.position.absolute).left + (draggable.clickOffset || draggable.offset.click).left), 176 draggableTop = ((draggable.positionAbs || draggable.position.absolute).top + (draggable.clickOffset || draggable.offset.click).top), 177 isOver = $.ui.isOver(draggableTop, draggableLeft, t, l, droppable.proportions.height, droppable.proportions.width); 178 return isOver; 179 break; 180 case 'touch': 181 return ( 182 (y1 >= t && y1 <= b) || // Top edge touching 183 (y2 >= t && y2 <= b) || // Bottom edge touching 184 (y1 < t && y2 > b) // Surrounded vertically 185 ) && ( 186 (x1 >= l && x1 <= r) || // Left edge touching 187 (x2 >= l && x2 <= r) || // Right edge touching 188 (x1 < l && x2 > r) // Surrounded horizontally 189 ); 190 break; 191 default: 192 return false; 193 break; 194 } 195 196 }; 197 198 /* 199 This manager tracks offsets of draggables and droppables 200 */ 201 $.ui.ddmanager = { 202 current: null, 203 droppables: { 'default': [] }, 204 prepareOffsets: function(t, event) { 205 206 var m = $.ui.ddmanager.droppables[t.options.scope]; 207 var type = event ? event.type : null; // workaround for #2317 208 var list = (t.currentItem || t.element).find(":data(droppable)").andSelf(); 209 210 droppablesLoop: for (var i = 0; i < m.length; i++) { 211 212 if(m[i].options.disabled || (t && !m[i].options.accept.call(m[i].element,(t.currentItem || t.element)))) continue; //No disabled and non-accepted 213 for (var j=0; j < list.length; j++) { if(list[j] == m[i].element[0]) { m[i].proportions.height = 0; continue droppablesLoop; } }; //Filter out elements in the current dragged item 214 m[i].visible = m[i].element.css("display") != "none"; if(!m[i].visible) continue; //If the element is not visible, continue 215 216 m[i].offset = m[i].element.offset(); 217 m[i].proportions = { width: m[i].element[0].offsetWidth, height: m[i].element[0].offsetHeight }; 218 219 if(type == "dragstart" || type == "sortactivate") m[i]._activate.call(m[i], event); //Activate the droppable if used directly from draggables 220 221 } 222 223 }, 224 drop: function(draggable, event) { 225 226 var dropped = false; 227 $.each($.ui.ddmanager.droppables[draggable.options.scope], function() { 228 229 if(!this.options) return; 230 if (!this.options.disabled && this.visible && $.ui.intersect(draggable, this, this.options.tolerance)) 231 dropped = this._drop.call(this, event); 232 233 if (!this.options.disabled && this.visible && this.options.accept.call(this.element,(draggable.currentItem || draggable.element))) { 234 this.isout = 1; this.isover = 0; 235 this._deactivate.call(this, event); 236 } 237 238 }); 239 return dropped; 240 241 }, 242 drag: function(draggable, event) { 243 244 //If you have a highly dynamic page, you might try this option. It renders positions every time you move the mouse. 245 if(draggable.options.refreshPositions) $.ui.ddmanager.prepareOffsets(draggable, event); 246 247 //Run through all droppables and check their positions based on specific tolerance options 248 249 $.each($.ui.ddmanager.droppables[draggable.options.scope], function() { 250 251 if(this.options.disabled || this.greedyChild || !this.visible) return; 252 var intersects = $.ui.intersect(draggable, this, this.options.tolerance); 253 254 var c = !intersects && this.isover == 1 ? 'isout' : (intersects && this.isover == 0 ? 'isover' : null); 255 if(!c) return; 256 257 var parentInstance; 258 if (this.options.greedy) { 259 var parent = this.element.parents(':data(droppable):eq(0)'); 260 if (parent.length) { 261 parentInstance = $.data(parent[0], 'droppable'); 262 parentInstance.greedyChild = (c == 'isover' ? 1 : 0); 263 } 264 } 265 266 // we just moved into a greedy child 267 if (parentInstance && c == 'isover') { 268 parentInstance['isover'] = 0; 269 parentInstance['isout'] = 1; 270 parentInstance._out.call(parentInstance, event); 271 } 272 273 this[c] = 1; this[c == 'isout' ? 'isover' : 'isout'] = 0; 274 this[c == "isover" ? "_over" : "_out"].call(this, event); 275 276 // we just moved out of a greedy child 277 if (parentInstance && c == 'isout') { 278 parentInstance['isout'] = 0; 279 parentInstance['isover'] = 1; 280 parentInstance._over.call(parentInstance, event); 281 } 282 }); 283 284 } 285 }; 286 287 /* 288 * Droppable Extensions 289 */ 290 291 $.ui.plugin.add("droppable", "activeClass", { 292 activate: function(event, ui) { 293 $(this).addClass(ui.options.activeClass); 294 }, 295 deactivate: function(event, ui) { 296 $(this).removeClass(ui.options.activeClass); 297 }, 298 drop: function(event, ui) { 299 $(this).removeClass(ui.options.activeClass); 300 } 301 }); 302 303 $.ui.plugin.add("droppable", "hoverClass", { 304 over: function(event, ui) { 305 $(this).addClass(ui.options.hoverClass); 306 }, 307 out: function(event, ui) { 308 $(this).removeClass(ui.options.hoverClass); 309 }, 310 drop: function(event, ui) { 311 $(this).removeClass(ui.options.hoverClass); 312 } 313 }); 314 315 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |