| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
(function( $, undefined ) { |
| 17 |
|
| 18 |
$.widget("ui.draggable", $.ui.mouse, { |
| 19 |
version: "1.9.2", |
| 20 |
widgetEventPrefix: "drag", |
| 21 |
options: { |
| 22 |
addClasses: true, |
| 23 |
appendTo: "parent", |
| 24 |
axis: false, |
| 25 |
connectToSortable: false, |
| 26 |
containment: false, |
| 27 |
cursor: "auto", |
| 28 |
cursorAt: false, |
| 29 |
grid: false, |
| 30 |
handle: false, |
| 31 |
helper: "original", |
| 32 |
iframeFix: false, |
| 33 |
opacity: false, |
| 34 |
refreshPositions: false, |
| 35 |
revert: false, |
| 36 |
revertDuration: 500, |
| 37 |
scope: "default", |
| 38 |
scroll: true, |
| 39 |
scrollSensitivity: 20, |
| 40 |
scrollSpeed: 20, |
| 41 |
snap: false, |
| 42 |
snapMode: "both", |
| 43 |
snapTolerance: 20, |
| 44 |
stack: false, |
| 45 |
zIndex: false |
| 46 |
}, |
| 47 |
_create: function() { |
| 48 |
|
| 49 |
if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position"))) |
| 50 |
this.element[0].style.position = 'relative'; |
| 51 |
|
| 52 |
(this.options.addClasses && this.element.addClass("ui-draggable")); |
| 53 |
(this.options.disabled && this.element.addClass("ui-draggable-disabled")); |
| 54 |
|
| 55 |
this._mouseInit(); |
| 56 |
|
| 57 |
}, |
| 58 |
|
| 59 |
_destroy: function() { |
| 60 |
this.element.removeClass( "ui-draggable ui-draggable-dragging ui-draggable-disabled" ); |
| 61 |
this._mouseDestroy(); |
| 62 |
}, |
| 63 |
|
| 64 |
_mouseCapture: function(event) { |
| 65 |
|
| 66 |
var o = this.options; |
| 67 |
|
| 68 |
|
| 69 |
if (this.helper || o.disabled || $(event.target).is('.ui-resizable-handle')) |
| 70 |
return false; |
| 71 |
|
| 72 |
|
| 73 |
this.handle = this._getHandle(event); |
| 74 |
if (!this.handle) |
| 75 |
return false; |
| 76 |
|
| 77 |
$(o.iframeFix === true ? "iframe" : o.iframeFix).each(function() { |
| 78 |
$('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>') |
| 79 |
.css({ |
| 80 |
width: this.offsetWidth+"px", height: this.offsetHeight+"px", |
| 81 |
position: "absolute", opacity: "0.001", zIndex: 1000 |
| 82 |
}) |
| 83 |
.css($(this).offset()) |
| 84 |
.appendTo("body"); |
| 85 |
}); |
| 86 |
|
| 87 |
return true; |
| 88 |
|
| 89 |
}, |
| 90 |
|
| 91 |
_mouseStart: function(event) { |
| 92 |
|
| 93 |
var o = this.options; |
| 94 |
|
| 95 |
|
| 96 |
this.helper = this._createHelper(event); |
| 97 |
|
| 98 |
this.helper.addClass("ui-draggable-dragging"); |
| 99 |
|
| 100 |
|
| 101 |
this._cacheHelperProportions(); |
| 102 |
|
| 103 |
|
| 104 |
if($.ui.ddmanager) |
| 105 |
$.ui.ddmanager.current = this; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
this._cacheMargins(); |
| 114 |
|
| 115 |
|
| 116 |
this.cssPosition = this.helper.css("position"); |
| 117 |
this.scrollParent = this.helper.scrollParent(); |
| 118 |
|
| 119 |
|
| 120 |
this.offset = this.positionAbs = this.element.offset(); |
| 121 |
this.offset = { |
| 122 |
top: this.offset.top - this.margins.top, |
| 123 |
left: this.offset.left - this.margins.left |
| 124 |
}; |
| 125 |
|
| 126 |
$.extend(this.offset, { |
| 127 |
click: { |
| 128 |
left: event.pageX - this.offset.left, |
| 129 |
top: event.pageY - this.offset.top |
| 130 |
}, |
| 131 |
parent: this._getParentOffset(), |
| 132 |
relative: this._getRelativeOffset() |
| 133 |
}); |
| 134 |
|
| 135 |
|
| 136 |
this.originalPageX = event.pageX; |
| 137 |
this.originalPageY = event.pageY; |
| 138 |
this.originalPosition = this.position = this._generatePosition(event); |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
(o.cursorAt && this._adjustOffsetFromHelper(o.cursorAt)); |
| 146 |
|
| 147 |
|
| 148 |
if(o.containment) |
| 149 |
this._setContainment(); |
| 150 |
|
| 151 |
|
| 152 |
if(this._trigger("start", event) === false) { |
| 153 |
this._clear(); |
| 154 |
return false; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
this._cacheHelperProportions(); |
| 159 |
|
| 160 |
|
| 161 |
if ($.ui.ddmanager && !o.dropBehaviour) |
| 162 |
$.ui.ddmanager.prepareOffsets(this, event); |
| 163 |
|
| 164 |
|
| 165 |
this._mouseDrag(event, true); |
| 166 |
|
| 167 |
|
| 168 |
if ( $.ui.ddmanager ) $.ui.ddmanager.dragStart(this, event); |
| 169 |
|
| 170 |
return true; |
| 171 |
}, |
| 172 |
|
| 173 |
_mouseDrag: function(event, noPropagation) { |
| 174 |
|
| 175 |
|
| 176 |
this.position = this._generatePosition(event); |
| 177 |
this.positionAbs = this._convertPositionTo("absolute"); |
| 178 |
|
| 179 |
|
| 180 |
if (!noPropagation) { |
| 181 |
var ui = this._uiHash(); |
| 182 |
if(this._trigger('drag', event, ui) === false) { |
| 183 |
this._mouseUp({}); |
| 184 |
return false; |
| 185 |
} |
| 186 |
this.position = ui.position; |
| 187 |
} |
| 188 |
|
| 189 |
if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px'; |
| 190 |
if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px'; |
| 191 |
if($.ui.ddmanager) $.ui.ddmanager.drag(this, event); |
| 192 |
|
| 193 |
return false; |
| 194 |
}, |
| 195 |
|
| 196 |
_mouseStop: function(event) { |
| 197 |
|
| 198 |
|
| 199 |
var dropped = false; |
| 200 |
if ($.ui.ddmanager && !this.options.dropBehaviour) |
| 201 |
dropped = $.ui.ddmanager.drop(this, event); |
| 202 |
|
| 203 |
|
| 204 |
if(this.dropped) { |
| 205 |
dropped = this.dropped; |
| 206 |
this.dropped = false; |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
var element = this.element[0], elementInDom = false; |
| 211 |
while ( element && (element = element.parentNode) ) { |
| 212 |
if (element == document ) { |
| 213 |
elementInDom = true; |
| 214 |
} |
| 215 |
} |
| 216 |
if ( !elementInDom && this.options.helper === "original" ) |
| 217 |
return false; |
| 218 |
|
| 219 |
if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true || (typeof this.options.revert === 'function' && this.options.revert.call(this.element, dropped))) { |
| 220 |
var that = this; |
| 221 |
$(this.helper).animate(this.originalPosition, parseInt(this.options.revertDuration, 10), function() { |
| 222 |
if(that._trigger("stop", event) !== false) { |
| 223 |
that._clear(); |
| 224 |
} |
| 225 |
}); |
| 226 |
} else { |
| 227 |
if(this._trigger("stop", event) !== false) { |
| 228 |
this._clear(); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
return false; |
| 233 |
}, |
| 234 |
|
| 235 |
_mouseUp: function(event) { |
| 236 |
|
| 237 |
$("div.ui-draggable-iframeFix").each(function() { |
| 238 |
this.parentNode.removeChild(this); |
| 239 |
}); |
| 240 |
|
| 241 |
|
| 242 |
if( $.ui.ddmanager ) $.ui.ddmanager.dragStop(this, event); |
| 243 |
|
| 244 |
return $.ui.mouse.prototype._mouseUp.call(this, event); |
| 245 |
}, |
| 246 |
|
| 247 |
cancel: function() { |
| 248 |
|
| 249 |
if(this.helper.is(".ui-draggable-dragging")) { |
| 250 |
this._mouseUp({}); |
| 251 |
} else { |
| 252 |
this._clear(); |
| 253 |
} |
| 254 |
|
| 255 |
return this; |
| 256 |
|
| 257 |
}, |
| 258 |
|
| 259 |
_getHandle: function(event) { |
| 260 |
|
| 261 |
var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false; |
| 262 |
$(this.options.handle, this.element) |
| 263 |
.find("*") |
| 264 |
.addBack() |
| 265 |
.each(function() { |
| 266 |
if(this == event.target) handle = true; |
| 267 |
}); |
| 268 |
|
| 269 |
return handle; |
| 270 |
|
| 271 |
}, |
| 272 |
|
| 273 |
_createHelper: function(event) { |
| 274 |
|
| 275 |
var o = this.options; |
| 276 |
var helper = typeof o.helper === 'function' ? $(o.helper.apply(this.element[0], [event])) : (o.helper == 'clone' ? this.element.clone().removeAttr('id') : this.element); |
| 277 |
|
| 278 |
if(!helper.parents('body').length) |
| 279 |
helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo)); |
| 280 |
|
| 281 |
if(helper[0] != this.element[0] && !(/(fixed|absolute)/).test(helper.css("position"))) |
| 282 |
helper.css("position", "absolute"); |
| 283 |
|
| 284 |
return helper; |
| 285 |
|
| 286 |
}, |
| 287 |
|
| 288 |
_adjustOffsetFromHelper: function(obj) { |
| 289 |
if (typeof obj == 'string') { |
| 290 |
obj = obj.split(' '); |
| 291 |
} |
| 292 |
if (Array.isArray(obj)) { |
| 293 |
obj = {left: +obj[0], top: +obj[1] || 0}; |
| 294 |
} |
| 295 |
if ('left' in obj) { |
| 296 |
this.offset.click.left = obj.left + this.margins.left; |
| 297 |
} |
| 298 |
if ('right' in obj) { |
| 299 |
this.offset.click.left = this.helperProportions.width - obj.right + this.margins.left; |
| 300 |
} |
| 301 |
if ('top' in obj) { |
| 302 |
this.offset.click.top = obj.top + this.margins.top; |
| 303 |
} |
| 304 |
if ('bottom' in obj) { |
| 305 |
this.offset.click.top = this.helperProportions.height - obj.bottom + this.margins.top; |
| 306 |
} |
| 307 |
}, |
| 308 |
|
| 309 |
_getParentOffset: function() { |
| 310 |
|
| 311 |
|
| 312 |
this.offsetParent = this.helper.offsetParent(); |
| 313 |
var po = this.offsetParent.offset(); |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
if(this.cssPosition == 'absolute' && this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) { |
| 320 |
po.left += this.scrollParent.scrollLeft(); |
| 321 |
po.top += this.scrollParent.scrollTop(); |
| 322 |
} |
| 323 |
|
| 324 |
if((this.offsetParent[0] == document.body) |
| 325 |
|| (this.offsetParent[0].tagName && this.offsetParent[0].tagName.toLowerCase() == 'html' && $.ui.ie)) |
| 326 |
po = { top: 0, left: 0 }; |
| 327 |
|
| 328 |
return { |
| 329 |
top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0), |
| 330 |
left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0) |
| 331 |
}; |
| 332 |
|
| 333 |
}, |
| 334 |
|
| 335 |
_getRelativeOffset: function() { |
| 336 |
|
| 337 |
if(this.cssPosition == "relative") { |
| 338 |
var p = this.element.position(); |
| 339 |
return { |
| 340 |
top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.scrollParent.scrollTop(), |
| 341 |
left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.scrollParent.scrollLeft() |
| 342 |
}; |
| 343 |
} else { |
| 344 |
return { top: 0, left: 0 }; |
| 345 |
} |
| 346 |
|
| 347 |
}, |
| 348 |
|
| 349 |
_cacheMargins: function() { |
| 350 |
this.margins = { |
| 351 |
left: (parseInt(this.element.css("marginLeft"),10) || 0), |
| 352 |
top: (parseInt(this.element.css("marginTop"),10) || 0), |
| 353 |
right: (parseInt(this.element.css("marginRight"),10) || 0), |
| 354 |
bottom: (parseInt(this.element.css("marginBottom"),10) || 0) |
| 355 |
}; |
| 356 |
}, |
| 357 |
|
| 358 |
_cacheHelperProportions: function() { |
| 359 |
this.helperProportions = { |
| 360 |
width: this.helper.outerWidth(), |
| 361 |
height: this.helper.outerHeight() |
| 362 |
}; |
| 363 |
}, |
| 364 |
|
| 365 |
_setContainment: function() { |
| 366 |
|
| 367 |
var o = this.options; |
| 368 |
if(o.containment == 'parent') o.containment = this.helper[0].parentNode; |
| 369 |
if(o.containment == 'document' || o.containment == 'window') this.containment = [ |
| 370 |
o.containment == 'document' ? 0 : $(window).scrollLeft() - this.offset.relative.left - this.offset.parent.left, |
| 371 |
o.containment == 'document' ? 0 : $(window).scrollTop() - this.offset.relative.top - this.offset.parent.top, |
| 372 |
(o.containment == 'document' ? 0 : $(window).scrollLeft()) + $(o.containment == 'document' ? document : window).width() - this.helperProportions.width - this.margins.left, |
| 373 |
(o.containment == 'document' ? 0 : $(window).scrollTop()) + ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.helperProportions.height - this.margins.top |
| 374 |
]; |
| 375 |
|
| 376 |
if(!(/^(document|window|parent)$/).test(o.containment) && o.containment.constructor != Array) { |
| 377 |
var c = $(o.containment); |
| 378 |
var ce = c[0]; if(!ce) return; |
| 379 |
var co = c.offset(); |
| 380 |
var over = ($(ce).css("overflow") != 'hidden'); |
| 381 |
|
| 382 |
this.containment = [ |
| 383 |
(parseInt($(ce).css("borderLeftWidth"),10) || 0) + (parseInt($(ce).css("paddingLeft"),10) || 0), |
| 384 |
(parseInt($(ce).css("borderTopWidth"),10) || 0) + (parseInt($(ce).css("paddingTop"),10) || 0), |
| 385 |
(over ? Math.max(ce.scrollWidth,ce.offsetWidth) : ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - (parseInt($(ce).css("paddingRight"),10) || 0) - this.helperProportions.width - this.margins.left - this.margins.right, |
| 386 |
(over ? Math.max(ce.scrollHeight,ce.offsetHeight) : ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - (parseInt($(ce).css("paddingBottom"),10) || 0) - this.helperProportions.height - this.margins.top - this.margins.bottom |
| 387 |
]; |
| 388 |
this.relative_container = c; |
| 389 |
|
| 390 |
} else if(o.containment.constructor == Array) { |
| 391 |
this.containment = o.containment; |
| 392 |
} |
| 393 |
|
| 394 |
}, |
| 395 |
|
| 396 |
_convertPositionTo: function(d, pos) { |
| 397 |
|
| 398 |
if(!pos) pos = this.position; |
| 399 |
var mod = d == "absolute" ? 1 : -1; |
| 400 |
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); |
| 401 |
|
| 402 |
return { |
| 403 |
top: ( |
| 404 |
pos.top |
| 405 |
+ this.offset.relative.top * mod |
| 406 |
+ this.offset.parent.top * mod |
| 407 |
- ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) ) * mod) |
| 408 |
), |
| 409 |
left: ( |
| 410 |
pos.left |
| 411 |
+ this.offset.relative.left * mod |
| 412 |
+ this.offset.parent.left * mod |
| 413 |
- ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() ) * mod) |
| 414 |
) |
| 415 |
}; |
| 416 |
|
| 417 |
}, |
| 418 |
|
| 419 |
_generatePosition: function(event) { |
| 420 |
|
| 421 |
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName); |
| 422 |
var pageX = event.pageX; |
| 423 |
var pageY = event.pageY; |
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
if(this.originalPosition) { |
| 431 |
var containment; |
| 432 |
if(this.containment) { |
| 433 |
if (this.relative_container){ |
| 434 |
var co = this.relative_container.offset(); |
| 435 |
containment = [ this.containment[0] + co.left, |
| 436 |
this.containment[1] + co.top, |
| 437 |
this.containment[2] + co.left, |
| 438 |
this.containment[3] + co.top ]; |
| 439 |
} |
| 440 |
else { |
| 441 |
containment = this.containment; |
| 442 |
} |
| 443 |
|
| 444 |
if(event.pageX - this.offset.click.left < containment[0]) pageX = containment[0] + this.offset.click.left; |
| 445 |
if(event.pageY - this.offset.click.top < containment[1]) pageY = containment[1] + this.offset.click.top; |
| 446 |
if(event.pageX - this.offset.click.left > containment[2]) pageX = containment[2] + this.offset.click.left; |
| 447 |
if(event.pageY - this.offset.click.top > containment[3]) pageY = containment[3] + this.offset.click.top; |
| 448 |
} |
| 449 |
|
| 450 |
if(o.grid) { |
| 451 |
|
| 452 |
var top = o.grid[1] ? this.originalPageY + Math.round((pageY - this.originalPageY) / o.grid[1]) * o.grid[1] : this.originalPageY; |
| 453 |
pageY = containment ? (!(top - this.offset.click.top < containment[1] || top - this.offset.click.top > containment[3]) ? top : (!(top - this.offset.click.top < containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top; |
| 454 |
|
| 455 |
var left = o.grid[0] ? this.originalPageX + Math.round((pageX - this.originalPageX) / o.grid[0]) * o.grid[0] : this.originalPageX; |
| 456 |
pageX = containment ? (!(left - this.offset.click.left < containment[0] || left - this.offset.click.left > containment[2]) ? left : (!(left - this.offset.click.left < containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left; |
| 457 |
} |
| 458 |
|
| 459 |
} |
| 460 |
|
| 461 |
return { |
| 462 |
top: ( |
| 463 |
pageY |
| 464 |
- this.offset.click.top |
| 465 |
- this.offset.relative.top |
| 466 |
- this.offset.parent.top |
| 467 |
+ ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollTop() : ( scrollIsRootNode ? 0 : scroll.scrollTop() ) )) |
| 468 |
), |
| 469 |
left: ( |
| 470 |
pageX |
| 471 |
- this.offset.click.left |
| 472 |
- this.offset.relative.left |
| 473 |
- this.offset.parent.left |
| 474 |
+ ( ( this.cssPosition == 'fixed' ? -this.scrollParent.scrollLeft() : scrollIsRootNode ? 0 : scroll.scrollLeft() )) |
| 475 |
) |
| 476 |
}; |
| 477 |
|
| 478 |
}, |
| 479 |
|
| 480 |
_clear: function() { |
| 481 |
this.helper.removeClass("ui-draggable-dragging"); |
| 482 |
if(this.helper[0] != this.element[0] && !this.cancelHelperRemoval) this.helper.remove(); |
| 483 |
|
| 484 |
this.helper = null; |
| 485 |
this.cancelHelperRemoval = false; |
| 486 |
}, |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
_trigger: function(type, event, ui) { |
| 491 |
ui = ui || this._uiHash(); |
| 492 |
$.ui.plugin.call(this, type, [event, ui]); |
| 493 |
if(type == "drag") this.positionAbs = this._convertPositionTo("absolute"); |
| 494 |
return $.Widget.prototype._trigger.call(this, type, event, ui); |
| 495 |
}, |
| 496 |
|
| 497 |
plugins: {}, |
| 498 |
|
| 499 |
_uiHash: function(event) { |
| 500 |
return { |
| 501 |
helper: this.helper, |
| 502 |
position: this.position, |
| 503 |
originalPosition: this.originalPosition, |
| 504 |
offset: this.positionAbs |
| 505 |
}; |
| 506 |
} |
| 507 |
|
| 508 |
}); |
| 509 |
|
| 510 |
$.ui.plugin.add("draggable", "connectToSortable", { |
| 511 |
start: function(event, ui) { |
| 512 |
|
| 513 |
var inst = $(this).data("draggable"), o = inst.options, |
| 514 |
uiSortable = $.extend({}, ui, { item: inst.element }); |
| 515 |
inst.sortables = []; |
| 516 |
$(o.connectToSortable).each(function() { |
| 517 |
var sortable = $.data(this, 'sortable'); |
| 518 |
if (sortable && !sortable.options.disabled) { |
| 519 |
inst.sortables.push({ |
| 520 |
instance: sortable, |
| 521 |
shouldRevert: sortable.options.revert |
| 522 |
}); |
| 523 |
sortable.refreshPositions(); |
| 524 |
sortable._trigger("activate", event, uiSortable); |
| 525 |
} |
| 526 |
}); |
| 527 |
|
| 528 |
}, |
| 529 |
stop: function(event, ui) { |
| 530 |
|
| 531 |
|
| 532 |
var inst = $(this).data("draggable"), |
| 533 |
uiSortable = $.extend({}, ui, { item: inst.element }); |
| 534 |
|
| 535 |
$.each(inst.sortables, function() { |
| 536 |
if(this.instance.isOver) { |
| 537 |
|
| 538 |
this.instance.isOver = 0; |
| 539 |
|
| 540 |
inst.cancelHelperRemoval = true; |
| 541 |
this.instance.cancelHelperRemoval = false; |
| 542 |
|
| 543 |
|
| 544 |
if(this.shouldRevert) this.instance.options.revert = true; |
| 545 |
|
| 546 |
|
| 547 |
this.instance._mouseStop(event); |
| 548 |
|
| 549 |
this.instance.options.helper = this.instance.options._helper; |
| 550 |
|
| 551 |
|
| 552 |
if(inst.options.helper == 'original') |
| 553 |
this.instance.currentItem.css({ top: 'auto', left: 'auto' }); |
| 554 |
|
| 555 |
} else { |
| 556 |
this.instance.cancelHelperRemoval = false; |
| 557 |
this.instance._trigger("deactivate", event, uiSortable); |
| 558 |
} |
| 559 |
|
| 560 |
}); |
| 561 |
|
| 562 |
}, |
| 563 |
drag: function(event, ui) { |
| 564 |
|
| 565 |
var inst = $(this).data("draggable"), that = this; |
| 566 |
|
| 567 |
var checkPos = function(o) { |
| 568 |
var dyClick = this.offset.click.top, dxClick = this.offset.click.left; |
| 569 |
var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left; |
| 570 |
var itemHeight = o.height, itemWidth = o.width; |
| 571 |
var itemTop = o.top, itemLeft = o.left; |
| 572 |
|
| 573 |
return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth); |
| 574 |
}; |
| 575 |
|
| 576 |
$.each(inst.sortables, function(i) { |
| 577 |
|
| 578 |
var innermostIntersecting = false; |
| 579 |
var thisSortable = this; |
| 580 |
|
| 581 |
this.instance.positionAbs = inst.positionAbs; |
| 582 |
this.instance.helperProportions = inst.helperProportions; |
| 583 |
this.instance.offset.click = inst.offset.click; |
| 584 |
|
| 585 |
if(this.instance._intersectsWith(this.instance.containerCache)) { |
| 586 |
innermostIntersecting = true; |
| 587 |
$.each(inst.sortables, function () { |
| 588 |
this.instance.positionAbs = inst.positionAbs; |
| 589 |
this.instance.helperProportions = inst.helperProportions; |
| 590 |
this.instance.offset.click = inst.offset.click; |
| 591 |
if (this != thisSortable |
| 592 |
&& this.instance._intersectsWith(this.instance.containerCache) |
| 593 |
&& $.ui.contains(thisSortable.instance.element[0], this.instance.element[0])) |
| 594 |
innermostIntersecting = false; |
| 595 |
return innermostIntersecting; |
| 596 |
}); |
| 597 |
} |
| 598 |
|
| 599 |
|
| 600 |
if(innermostIntersecting) { |
| 601 |
|
| 602 |
if(!this.instance.isOver) { |
| 603 |
|
| 604 |
this.instance.isOver = 1; |
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
this.instance.currentItem = $(that).clone().removeAttr('id').appendTo(this.instance.element).data("sortable-item", true); |
| 609 |
this.instance.options._helper = this.instance.options.helper; |
| 610 |
this.instance.options.helper = function() { return ui.helper[0]; }; |
| 611 |
|
| 612 |
event.target = this.instance.currentItem[0]; |
| 613 |
this.instance._mouseCapture(event, true); |
| 614 |
this.instance._mouseStart(event, true, true); |
| 615 |
|
| 616 |
|
| 617 |
this.instance.offset.click.top = inst.offset.click.top; |
| 618 |
this.instance.offset.click.left = inst.offset.click.left; |
| 619 |
this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left; |
| 620 |
this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top; |
| 621 |
|
| 622 |
inst._trigger("toSortable", event); |
| 623 |
inst.dropped = this.instance.element; |
| 624 |
|
| 625 |
inst.currentItem = inst.element; |
| 626 |
this.instance.fromOutside = inst; |
| 627 |
|
| 628 |
} |
| 629 |
|
| 630 |
|
| 631 |
if(this.instance.currentItem) this.instance._mouseDrag(event); |
| 632 |
|
| 633 |
} else { |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
if(this.instance.isOver) { |
| 638 |
|
| 639 |
this.instance.isOver = 0; |
| 640 |
this.instance.cancelHelperRemoval = true; |
| 641 |
|
| 642 |
|
| 643 |
this.instance.options.revert = false; |
| 644 |
|
| 645 |
|
| 646 |
this.instance._trigger('out', event, this.instance._uiHash(this.instance)); |
| 647 |
|
| 648 |
this.instance._mouseStop(event, true); |
| 649 |
this.instance.options.helper = this.instance.options._helper; |
| 650 |
|
| 651 |
|
| 652 |
this.instance.currentItem.remove(); |
| 653 |
if(this.instance.placeholder) this.instance.placeholder.remove(); |
| 654 |
|
| 655 |
inst._trigger("fromSortable", event); |
| 656 |
inst.dropped = false; |
| 657 |
} |
| 658 |
|
| 659 |
}; |
| 660 |
|
| 661 |
}); |
| 662 |
|
| 663 |
} |
| 664 |
}); |
| 665 |
|
| 666 |
$.ui.plugin.add("draggable", "cursor", { |
| 667 |
start: function(event, ui) { |
| 668 |
var t = $('body'), o = $(this).data('draggable').options; |
| 669 |
if (t.css("cursor")) o._cursor = t.css("cursor"); |
| 670 |
t.css("cursor", o.cursor); |
| 671 |
}, |
| 672 |
stop: function(event, ui) { |
| 673 |
var o = $(this).data('draggable').options; |
| 674 |
if (o._cursor) $('body').css("cursor", o._cursor); |
| 675 |
} |
| 676 |
}); |
| 677 |
|
| 678 |
$.ui.plugin.add("draggable", "opacity", { |
| 679 |
start: function(event, ui) { |
| 680 |
var t = $(ui.helper), o = $(this).data('draggable').options; |
| 681 |
if(t.css("opacity")) o._opacity = t.css("opacity"); |
| 682 |
t.css('opacity', o.opacity); |
| 683 |
}, |
| 684 |
stop: function(event, ui) { |
| 685 |
var o = $(this).data('draggable').options; |
| 686 |
if(o._opacity) $(ui.helper).css('opacity', o._opacity); |
| 687 |
} |
| 688 |
}); |
| 689 |
|
| 690 |
$.ui.plugin.add("draggable", "scroll", { |
| 691 |
start: function(event, ui) { |
| 692 |
var i = $(this).data("draggable"); |
| 693 |
if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') i.overflowOffset = i.scrollParent.offset(); |
| 694 |
}, |
| 695 |
drag: function(event, ui) { |
| 696 |
|
| 697 |
var i = $(this).data("draggable"), o = i.options, scrolled = false; |
| 698 |
|
| 699 |
if(i.scrollParent[0] != document && i.scrollParent[0].tagName != 'HTML') { |
| 700 |
|
| 701 |
if(!o.axis || o.axis != 'x') { |
| 702 |
if((i.overflowOffset.top + i.scrollParent[0].offsetHeight) - event.pageY < o.scrollSensitivity) |
| 703 |
i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop + o.scrollSpeed; |
| 704 |
else if(event.pageY - i.overflowOffset.top < o.scrollSensitivity) |
| 705 |
i.scrollParent[0].scrollTop = scrolled = i.scrollParent[0].scrollTop - o.scrollSpeed; |
| 706 |
} |
| 707 |
|
| 708 |
if(!o.axis || o.axis != 'y') { |
| 709 |
if((i.overflowOffset.left + i.scrollParent[0].offsetWidth) - event.pageX < o.scrollSensitivity) |
| 710 |
i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft + o.scrollSpeed; |
| 711 |
else if(event.pageX - i.overflowOffset.left < o.scrollSensitivity) |
| 712 |
i.scrollParent[0].scrollLeft = scrolled = i.scrollParent[0].scrollLeft - o.scrollSpeed; |
| 713 |
} |
| 714 |
|
| 715 |
} else { |
| 716 |
|
| 717 |
if(!o.axis || o.axis != 'x') { |
| 718 |
if(event.pageY - $(document).scrollTop() < o.scrollSensitivity) |
| 719 |
scrolled = $(document).scrollTop($(document).scrollTop() - o.scrollSpeed); |
| 720 |
else if($(window).height() - (event.pageY - $(document).scrollTop()) < o.scrollSensitivity) |
| 721 |
scrolled = $(document).scrollTop($(document).scrollTop() + o.scrollSpeed); |
| 722 |
} |
| 723 |
|
| 724 |
if(!o.axis || o.axis != 'y') { |
| 725 |
if(event.pageX - $(document).scrollLeft() < o.scrollSensitivity) |
| 726 |
scrolled = $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed); |
| 727 |
else if($(window).width() - (event.pageX - $(document).scrollLeft()) < o.scrollSensitivity) |
| 728 |
scrolled = $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed); |
| 729 |
} |
| 730 |
|
| 731 |
} |
| 732 |
|
| 733 |
if(scrolled !== false && $.ui.ddmanager && !o.dropBehaviour) |
| 734 |
$.ui.ddmanager.prepareOffsets(i, event); |
| 735 |
|
| 736 |
} |
| 737 |
}); |
| 738 |
|
| 739 |
$.ui.plugin.add("draggable", "snap", { |
| 740 |
start: function(event, ui) { |
| 741 |
|
| 742 |
var i = $(this).data("draggable"), o = i.options; |
| 743 |
i.snapElements = []; |
| 744 |
|
| 745 |
$(o.snap.constructor != String ? ( o.snap.items || ':data(draggable)' ) : o.snap).each(function() { |
| 746 |
var $t = $(this); var $o = $t.offset(); |
| 747 |
if(this != i.element[0]) i.snapElements.push({ |
| 748 |
item: this, |
| 749 |
width: $t.outerWidth(), height: $t.outerHeight(), |
| 750 |
top: $o.top, left: $o.left |
| 751 |
}); |
| 752 |
}); |
| 753 |
|
| 754 |
}, |
| 755 |
drag: function(event, ui) { |
| 756 |
|
| 757 |
var inst = $(this).data("draggable"), o = inst.options; |
| 758 |
var d = o.snapTolerance; |
| 759 |
|
| 760 |
var x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width, |
| 761 |
y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height; |
| 762 |
|
| 763 |
for (var i = inst.snapElements.length - 1; i >= 0; i--){ |
| 764 |
|
| 765 |
var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width, |
| 766 |
t = inst.snapElements[i].top, b = t + inst.snapElements[i].height; |
| 767 |
|
| 768 |
|
| 769 |
if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) { |
| 770 |
if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); |
| 771 |
inst.snapElements[i].snapping = false; |
| 772 |
continue; |
| 773 |
} |
| 774 |
|
| 775 |
if(o.snapMode != 'inner') { |
| 776 |
var ts = Math.abs(t - y2) <= d; |
| 777 |
var bs = Math.abs(b - y1) <= d; |
| 778 |
var ls = Math.abs(l - x2) <= d; |
| 779 |
var rs = Math.abs(r - x1) <= d; |
| 780 |
if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top; |
| 781 |
if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top; |
| 782 |
if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left; |
| 783 |
if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left; |
| 784 |
} |
| 785 |
|
| 786 |
var first = (ts || bs || ls || rs); |
| 787 |
|
| 788 |
if(o.snapMode != 'outer') { |
| 789 |
var ts = Math.abs(t - y1) <= d; |
| 790 |
var bs = Math.abs(b - y2) <= d; |
| 791 |
var ls = Math.abs(l - x1) <= d; |
| 792 |
var rs = Math.abs(r - x2) <= d; |
| 793 |
if(ts) ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top; |
| 794 |
if(bs) ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top; |
| 795 |
if(ls) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left; |
| 796 |
if(rs) ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left; |
| 797 |
} |
| 798 |
|
| 799 |
if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first)) |
| 800 |
(inst.options.snap.snap && inst.options.snap.snap.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item }))); |
| 801 |
inst.snapElements[i].snapping = (ts || bs || ls || rs || first); |
| 802 |
|
| 803 |
}; |
| 804 |
|
| 805 |
} |
| 806 |
}); |
| 807 |
|
| 808 |
$.ui.plugin.add("draggable", "stack", { |
| 809 |
start: function(event, ui) { |
| 810 |
|
| 811 |
var o = $(this).data("draggable").options; |
| 812 |
|
| 813 |
var group = $.makeArray($(o.stack)).sort(function(a,b) { |
| 814 |
return (parseInt($(a).css("zIndex"),10) || 0) - (parseInt($(b).css("zIndex"),10) || 0); |
| 815 |
}); |
| 816 |
if (!group.length) { return; } |
| 817 |
|
| 818 |
var min = parseInt(group[0].style.zIndex) || 0; |
| 819 |
$(group).each(function(i) { |
| 820 |
this.style.zIndex = min + i; |
| 821 |
}); |
| 822 |
|
| 823 |
this[0].style.zIndex = min + group.length; |
| 824 |
|
| 825 |
} |
| 826 |
}); |
| 827 |
|
| 828 |
$.ui.plugin.add("draggable", "zIndex", { |
| 829 |
start: function(event, ui) { |
| 830 |
var t = $(ui.helper), o = $(this).data("draggable").options; |
| 831 |
if(t.css("zIndex")) o._zIndex = t.css("zIndex"); |
| 832 |
t.css('zIndex', o.zIndex); |
| 833 |
}, |
| 834 |
stop: function(event, ui) { |
| 835 |
var o = $(this).data("draggable").options; |
| 836 |
if(o._zIndex) $(ui.helper).css('zIndex', o._zIndex); |
| 837 |
} |
| 838 |
}); |
| 839 |
|
| 840 |
})(jQuery); |