source: trunk/style/jquery-ui.js

Last change on this file was 60, checked in by george, 15 years ago
  • Přidáno: Informace o překladu pro klienta a server přesunuty do samostatné stránky Informace.
  • Upraveno: Grafický vzhled slovníčku.
  • Přidáno: Složky download a české fonty přímo ke stažení.
  • Přidáno: Chybějící javascript soubory.
File size: 59.5 KB
Line 
1/*
2 * jQuery UI 1.5.3
3 *
4 * Copyright (c) 2008 Paul Bakaus (ui.jquery.com)
5 * Dual licensed under the MIT (MIT-LICENSE.txt)
6 * and GPL (GPL-LICENSE.txt) licenses.
7 *
8 * http://docs.jquery.com/UI
9 */
10;(function($) {
11
12$.ui = {
13 plugin: {
14 add: function(module, option, set) {
15 var proto = $.ui[module].prototype;
16 for(var i in set) {
17 proto.plugins[i] = proto.plugins[i] || [];
18 proto.plugins[i].push([option, set[i]]);
19 }
20 },
21 call: function(instance, name, args) {
22 var set = instance.plugins[name];
23 if(!set) { return; }
24
25 for (var i = 0; i < set.length; i++) {
26 if (instance.options[set[i][0]]) {
27 set[i][1].apply(instance.element, args);
28 }
29 }
30 }
31 },
32 cssCache: {},
33 css: function(name) {
34 if ($.ui.cssCache[name]) { return $.ui.cssCache[name]; }
35 var tmp = $('<div class="ui-gen">').addClass(name).css({position:'absolute', top:'-5000px', left:'-5000px', display:'block'}).appendTo('body');
36
37 //if (!$.browser.safari)
38 //tmp.appendTo('body');
39
40 //Opera and Safari set width and height to 0px instead of auto
41 //Safari returns rgba(0,0,0,0) when bgcolor is not set
42 $.ui.cssCache[name] = !!(
43 (!(/auto|default/).test(tmp.css('cursor')) || (/^[1-9]/).test(tmp.css('height')) || (/^[1-9]/).test(tmp.css('width')) ||
44 !(/none/).test(tmp.css('backgroundImage')) || !(/transparent|rgba\(0, 0, 0, 0\)/).test(tmp.css('backgroundColor')))
45 );
46 try { $('body').get(0).removeChild(tmp.get(0)); } catch(e){}
47 return $.ui.cssCache[name];
48 },
49 disableSelection: function(el) {
50 $(el).attr('unselectable', 'on').css('MozUserSelect', 'none');
51 },
52 enableSelection: function(el) {
53 $(el).attr('unselectable', 'off').css('MozUserSelect', '');
54 },
55 hasScroll: function(e, a) {
56 var scroll = /top/.test(a||"top") ? 'scrollTop' : 'scrollLeft', has = false;
57 if (e[scroll] > 0) return true; e[scroll] = 1;
58 has = e[scroll] > 0 ? true : false; e[scroll] = 0;
59 return has;
60 }
61};
62
63
64/** jQuery core modifications and additions **/
65
66var _remove = $.fn.remove;
67$.fn.remove = function() {
68 $("*", this).add(this).triggerHandler("remove");
69 return _remove.apply(this, arguments );
70};
71
72// $.widget is a factory to create jQuery plugins
73// taking some boilerplate code out of the plugin code
74// created by Scott González and Jörn Zaefferer
75function getter(namespace, plugin, method) {
76 var methods = $[namespace][plugin].getter || [];
77 methods = (typeof methods == "string" ? methods.split(/,?\s+/) : methods);
78 return ($.inArray(method, methods) != -1);
79}
80
81$.widget = function(name, prototype) {
82 var namespace = name.split(".")[0];
83 name = name.split(".")[1];
84
85 // create plugin method
86 $.fn[name] = function(options) {
87 var isMethodCall = (typeof options == 'string'),
88 args = Array.prototype.slice.call(arguments, 1);
89
90 if (isMethodCall && getter(namespace, name, options)) {
91 var instance = $.data(this[0], name);
92 return (instance ? instance[options].apply(instance, args)
93 : undefined);
94 }
95
96 return this.each(function() {
97 var instance = $.data(this, name);
98 if (isMethodCall && instance && $.isFunction(instance[options])) {
99 instance[options].apply(instance, args);
100 } else if (!isMethodCall) {
101 $.data(this, name, new $[namespace][name](this, options));
102 }
103 });
104 };
105
106 // create widget constructor
107 $[namespace][name] = function(element, options) {
108 var self = this;
109
110 this.widgetName = name;
111 this.widgetBaseClass = namespace + '-' + name;
112
113 this.options = $.extend({}, $.widget.defaults, $[namespace][name].defaults, options);
114 this.element = $(element)
115 .bind('setData.' + name, function(e, key, value) {
116 return self.setData(key, value);
117 })
118 .bind('getData.' + name, function(e, key) {
119 return self.getData(key);
120 })
121 .bind('remove', function() {
122 return self.destroy();
123 });
124 this.init();
125 };
126
127 // add widget prototype
128 $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
129};
130
131$.widget.prototype = {
132 init: function() {},
133 destroy: function() {
134 this.element.removeData(this.widgetName);
135 },
136
137 getData: function(key) {
138 return this.options[key];
139 },
140 setData: function(key, value) {
141 this.options[key] = value;
142
143 if (key == 'disabled') {
144 this.element[value ? 'addClass' : 'removeClass'](
145 this.widgetBaseClass + '-disabled');
146 }
147 },
148
149 enable: function() {
150 this.setData('disabled', false);
151 },
152 disable: function() {
153 this.setData('disabled', true);
154 }
155};
156
157$.widget.defaults = {
158 disabled: false
159};
160
161
162/** Mouse Interaction Plugin **/
163
164$.ui.mouse = {
165 mouseInit: function() {
166 var self = this;
167
168 this.element.bind('mousedown.'+this.widgetName, function(e) {
169 return self.mouseDown(e);
170 });
171
172 // Prevent text selection in IE
173 if ($.browser.msie) {
174 this._mouseUnselectable = this.element.attr('unselectable');
175 this.element.attr('unselectable', 'on');
176 }
177
178 this.started = false;
179 },
180
181 // TODO: make sure destroying one instance of mouse doesn't mess with
182 // other instances of mouse
183 mouseDestroy: function() {
184 this.element.unbind('.'+this.widgetName);
185
186 // Restore text selection in IE
187 ($.browser.msie
188 && this.element.attr('unselectable', this._mouseUnselectable));
189 },
190
191 mouseDown: function(e) {
192 // we may have missed mouseup (out of window)
193 (this._mouseStarted && this.mouseUp(e));
194
195 this._mouseDownEvent = e;
196
197 var self = this,
198 btnIsLeft = (e.which == 1),
199 elIsCancel = (typeof this.options.cancel == "string" ? $(e.target).parents().add(e.target).filter(this.options.cancel).length : false);
200 if (!btnIsLeft || elIsCancel || !this.mouseCapture(e)) {
201 return true;
202 }
203
204 this._mouseDelayMet = !this.options.delay;
205 if (!this._mouseDelayMet) {
206 this._mouseDelayTimer = setTimeout(function() {
207 self._mouseDelayMet = true;
208 }, this.options.delay);
209 }
210
211 if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) {
212 this._mouseStarted = (this.mouseStart(e) !== false);
213 if (!this._mouseStarted) {
214 e.preventDefault();
215 return true;
216 }
217 }
218
219 // these delegates are required to keep context
220 this._mouseMoveDelegate = function(e) {
221 return self.mouseMove(e);
222 };
223 this._mouseUpDelegate = function(e) {
224 return self.mouseUp(e);
225 };
226 $(document)
227 .bind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
228 .bind('mouseup.'+this.widgetName, this._mouseUpDelegate);
229
230 return false;
231 },
232
233 mouseMove: function(e) {
234 // IE mouseup check - mouseup happened when mouse was out of window
235 if ($.browser.msie && !e.button) {
236 return this.mouseUp(e);
237 }
238
239 if (this._mouseStarted) {
240 this.mouseDrag(e);
241 return false;
242 }
243
244 if (this.mouseDistanceMet(e) && this.mouseDelayMet(e)) {
245 this._mouseStarted =
246 (this.mouseStart(this._mouseDownEvent, e) !== false);
247 (this._mouseStarted ? this.mouseDrag(e) : this.mouseUp(e));
248 }
249
250 return !this._mouseStarted;
251 },
252
253 mouseUp: function(e) {
254 $(document)
255 .unbind('mousemove.'+this.widgetName, this._mouseMoveDelegate)
256 .unbind('mouseup.'+this.widgetName, this._mouseUpDelegate);
257
258 if (this._mouseStarted) {
259 this._mouseStarted = false;
260 this.mouseStop(e);
261 }
262
263 return false;
264 },
265
266 mouseDistanceMet: function(e) {
267 return (Math.max(
268 Math.abs(this._mouseDownEvent.pageX - e.pageX),
269 Math.abs(this._mouseDownEvent.pageY - e.pageY)
270 ) >= this.options.distance
271 );
272 },
273
274 mouseDelayMet: function(e) {
275 return this._mouseDelayMet;
276 },
277
278 // These are placeholder methods, to be overriden by extending plugin
279 mouseStart: function(e) {},
280 mouseDrag: function(e) {},
281 mouseStop: function(e) {},
282 mouseCapture: function(e) { return true; }
283};
284
285$.ui.mouse.defaults = {
286 cancel: null,
287 distance: 1,
288 delay: 0
289};
290
291})(jQuery);
292/*
293 * jQuery UI Draggable
294 *
295 * Copyright (c) 2008 Paul Bakaus
296 * Dual licensed under the MIT (MIT-LICENSE.txt)
297 * and GPL (GPL-LICENSE.txt) licenses.
298 *
299 * http://docs.jquery.com/UI/Draggables
300 *
301 * Depends:
302 * ui.core.js
303 */
304(function($) {
305
306$.widget("ui.draggable", $.extend({}, $.ui.mouse, {
307 init: function() {
308
309 //Initialize needed constants
310 var o = this.options;
311
312 //Position the node
313 if (o.helper == 'original' && !(/(relative|absolute|fixed)/).test(this.element.css('position')))
314 this.element.css('position', 'relative');
315
316 this.element.addClass('ui-draggable');
317 (o.disabled && this.element.addClass('ui-draggable-disabled'));
318
319 this.mouseInit();
320
321 },
322 mouseStart: function(e) {
323 var o = this.options;
324
325 if (this.helper || o.disabled || $(e.target).is('.ui-resizable-handle')) return false;
326
327 var handle = !this.options.handle || !$(this.options.handle, this.element).length ? true : false;
328
329
330 $(this.options.handle, this.element).find("*").andSelf().each(function() {
331 if(this == e.target) handle = true;
332 });
333 if (!handle) return false;
334
335 if($.ui.ddmanager) $.ui.ddmanager.current = this;
336
337 //Create and append the visible helper
338 this.helper = $.isFunction(o.helper) ? $(o.helper.apply(this.element[0], [e])) : (o.helper == 'clone' ? this.element.clone() : this.element);
339 if(!this.helper.parents('body').length) this.helper.appendTo((o.appendTo == 'parent' ? this.element[0].parentNode : o.appendTo));
340 if(this.helper[0] != this.element[0] && !(/(fixed|absolute)/).test(this.helper.css("position"))) this.helper.css("position", "absolute");
341
342 /*
343 * - Position generation -
344 * This block generates everything position related - it's the core of draggables.
345 */
346
347 this.margins = { //Cache the margins
348 left: (parseInt(this.element.css("marginLeft"),10) || 0),
349 top: (parseInt(this.element.css("marginTop"),10) || 0)
350 };
351
352 this.cssPosition = this.helper.css("position"); //Store the helper's css position
353 this.offset = this.element.offset(); //The element's absolute position on the page
354 this.offset = { //Substract the margins from the element's absolute offset
355 top: this.offset.top - this.margins.top,
356 left: this.offset.left - this.margins.left
357 };
358
359 this.offset.click = { //Where the click happened, relative to the element
360 left: e.pageX - this.offset.left,
361 top: e.pageY - this.offset.top
362 };
363
364 this.offsetParent = this.helper.offsetParent(); var po = this.offsetParent.offset(); //Get the offsetParent and cache its position
365 if(this.offsetParent[0] == document.body && $.browser.mozilla) po = { top: 0, left: 0 }; //Ugly FF3 fix
366 this.offset.parent = { //Store its position plus border
367 top: po.top + (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
368 left: po.left + (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
369 };
370
371 var p = this.element.position(); //This is a relative to absolute position minus the actual position calculation - only used for relative positioned helpers
372 this.offset.relative = this.cssPosition == "relative" ? {
373 top: p.top - (parseInt(this.helper.css("top"),10) || 0) + this.offsetParent[0].scrollTop,
374 left: p.left - (parseInt(this.helper.css("left"),10) || 0) + this.offsetParent[0].scrollLeft
375 } : { top: 0, left: 0 };
376
377 this.originalPosition = this.generatePosition(e); //Generate the original position
378 this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Cache the helper size
379
380 if(o.cursorAt) {
381 if(o.cursorAt.left != undefined) this.offset.click.left = o.cursorAt.left + this.margins.left;
382 if(o.cursorAt.right != undefined) this.offset.click.left = this.helperProportions.width - o.cursorAt.right + this.margins.left;
383 if(o.cursorAt.top != undefined) this.offset.click.top = o.cursorAt.top + this.margins.top;
384 if(o.cursorAt.bottom != undefined) this.offset.click.top = this.helperProportions.height - o.cursorAt.bottom + this.margins.top;
385 }
386
387
388 /*
389 * - Position constraining -
390 * Here we prepare position constraining like grid and containment.
391 */
392
393 if(o.containment) {
394 if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
395 if(o.containment == 'document' || o.containment == 'window') this.containment = [
396 0 - this.offset.relative.left - this.offset.parent.left,
397 0 - this.offset.relative.top - this.offset.parent.top,
398 $(o.containment == 'document' ? document : window).width() - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0),
399 ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0)
400 ];
401
402 if(!(/^(document|window|parent)$/).test(o.containment)) {
403 var ce = $(o.containment)[0];
404 var co = $(o.containment).offset();
405
406 this.containment = [
407 co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left,
408 co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top,
409 co.left+Math.max(ce.scrollWidth,ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.relative.left - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0),
410 co.top+Math.max(ce.scrollHeight,ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.relative.top - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0)
411 ];
412 }
413 }
414
415 //Call plugins and callbacks
416 this.propagate("start", e);
417
418 this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size
419 if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
420
421 this.helper.addClass("ui-draggable-dragging");
422 this.mouseDrag(e); //Execute the drag once - this causes the helper not to be visible before getting its correct position
423 return true;
424 },
425 convertPositionTo: function(d, pos) {
426 if(!pos) pos = this.position;
427 var mod = d == "absolute" ? 1 : -1;
428 return {
429 top: (
430 pos.top // the calculated relative position
431 + this.offset.relative.top * mod // Only for relative positioned nodes: Relative offset from element to offset parent
432 + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
433 - (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.offsetParent[0].scrollTop) * mod // The offsetParent's scroll position, not if the element is fixed
434 + (this.cssPosition == "fixed" ? $(document).scrollTop() : 0) * mod
435 + this.margins.top * mod //Add the margin (you don't want the margin counting in intersection methods)
436 ),
437 left: (
438 pos.left // the calculated relative position
439 + this.offset.relative.left * mod // Only for relative positioned nodes: Relative offset from element to offset parent
440 + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
441 - (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.offsetParent[0].scrollLeft) * mod // The offsetParent's scroll position, not if the element is fixed
442 + (this.cssPosition == "fixed" ? $(document).scrollLeft() : 0) * mod
443 + this.margins.left * mod //Add the margin (you don't want the margin counting in intersection methods)
444 )
445 };
446 },
447 generatePosition: function(e) {
448
449 var o = this.options;
450 var position = {
451 top: (
452 e.pageY // The absolute mouse position
453 - this.offset.click.top // Click offset (relative to the element)
454 - this.offset.relative.top // Only for relative positioned nodes: Relative offset from element to offset parent
455 - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
456 + (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.offsetParent[0].scrollTop) // The offsetParent's scroll position, not if the element is fixed
457 - (this.cssPosition == "fixed" ? $(document).scrollTop() : 0)
458 ),
459 left: (
460 e.pageX // The absolute mouse position
461 - this.offset.click.left // Click offset (relative to the element)
462 - this.offset.relative.left // Only for relative positioned nodes: Relative offset from element to offset parent
463 - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
464 + (this.cssPosition == "fixed" || (this.cssPosition == "absolute" && this.offsetParent[0] == document.body) ? 0 : this.offsetParent[0].scrollLeft) // The offsetParent's scroll position, not if the element is fixed
465 - (this.cssPosition == "fixed" ? $(document).scrollLeft() : 0)
466 )
467 };
468
469 if(!this.originalPosition) return position; //If we are not dragging yet, we won't check for options
470
471 /*
472 * - Position constraining -
473 * Constrain the position to a mix of grid, containment.
474 */
475 if(this.containment) {
476 if(position.left < this.containment[0]) position.left = this.containment[0];
477 if(position.top < this.containment[1]) position.top = this.containment[1];
478 if(position.left > this.containment[2]) position.left = this.containment[2];
479 if(position.top > this.containment[3]) position.top = this.containment[3];
480 }
481
482 if(o.grid) {
483 var top = this.originalPosition.top + Math.round((position.top - this.originalPosition.top) / o.grid[1]) * o.grid[1];
484 position.top = this.containment ? (!(top < this.containment[1] || top > this.containment[3]) ? top : (!(top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
485
486 var left = this.originalPosition.left + Math.round((position.left - this.originalPosition.left) / o.grid[0]) * o.grid[0];
487 position.left = this.containment ? (!(left < this.containment[0] || left > this.containment[2]) ? left : (!(left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
488 }
489
490 return position;
491 },
492 mouseDrag: function(e) {
493
494 //Compute the helpers position
495 this.position = this.generatePosition(e);
496 this.positionAbs = this.convertPositionTo("absolute");
497
498 //Call plugins and callbacks and use the resulting position if something is returned
499 this.position = this.propagate("drag", e) || this.position;
500
501 if(!this.options.axis || this.options.axis != "y") this.helper[0].style.left = this.position.left+'px';
502 if(!this.options.axis || this.options.axis != "x") this.helper[0].style.top = this.position.top+'px';
503 if($.ui.ddmanager) $.ui.ddmanager.drag(this, e);
504
505 return false;
506 },
507 mouseStop: function(e) {
508
509 //If we are using droppables, inform the manager about the drop
510 var dropped = false;
511 if ($.ui.ddmanager && !this.options.dropBehaviour)
512 var dropped = $.ui.ddmanager.drop(this, e);
513
514 if((this.options.revert == "invalid" && !dropped) || (this.options.revert == "valid" && dropped) || this.options.revert === true) {
515 var self = this;
516 $(this.helper).animate(this.originalPosition, parseInt(this.options.revert, 10) || 500, function() {
517 self.propagate("stop", e);
518 self.clear();
519 });
520 } else {
521 this.propagate("stop", e);
522 this.clear();
523 }
524
525 return false;
526 },
527 clear: function() {
528 this.helper.removeClass("ui-draggable-dragging");
529 if(this.options.helper != 'original' && !this.cancelHelperRemoval) this.helper.remove();
530 //if($.ui.ddmanager) $.ui.ddmanager.current = null;
531 this.helper = null;
532 this.cancelHelperRemoval = false;
533 },
534
535 // From now on bulk stuff - mainly helpers
536 plugins: {},
537 uiHash: function(e) {
538 return {
539 helper: this.helper,
540 position: this.position,
541 absolutePosition: this.positionAbs,
542 options: this.options
543 };
544 },
545 propagate: function(n,e) {
546 $.ui.plugin.call(this, n, [e, this.uiHash()]);
547 if(n == "drag") this.positionAbs = this.convertPositionTo("absolute"); //The absolute position has to be recalculated after plugins
548 return this.element.triggerHandler(n == "drag" ? n : "drag"+n, [e, this.uiHash()], this.options[n]);
549 },
550 destroy: function() {
551 if(!this.element.data('draggable')) return;
552 this.element.removeData("draggable").unbind(".draggable").removeClass('ui-draggable');
553 this.mouseDestroy();
554 }
555}));
556
557$.extend($.ui.draggable, {
558 defaults: {
559 appendTo: "parent",
560 axis: false,
561 cancel: ":input",
562 delay: 0,
563 distance: 1,
564 helper: "original"
565 }
566});
567
568$.ui.plugin.add("draggable", "cursor", {
569 start: function(e, ui) {
570 var t = $('body');
571 if (t.css("cursor")) ui.options._cursor = t.css("cursor");
572 t.css("cursor", ui.options.cursor);
573 },
574 stop: function(e, ui) {
575 if (ui.options._cursor) $('body').css("cursor", ui.options._cursor);
576 }
577});
578
579$.ui.plugin.add("draggable", "zIndex", {
580 start: function(e, ui) {
581 var t = $(ui.helper);
582 if(t.css("zIndex")) ui.options._zIndex = t.css("zIndex");
583 t.css('zIndex', ui.options.zIndex);
584 },
585 stop: function(e, ui) {
586 if(ui.options._zIndex) $(ui.helper).css('zIndex', ui.options._zIndex);
587 }
588});
589
590$.ui.plugin.add("draggable", "opacity", {
591 start: function(e, ui) {
592 var t = $(ui.helper);
593 if(t.css("opacity")) ui.options._opacity = t.css("opacity");
594 t.css('opacity', ui.options.opacity);
595 },
596 stop: function(e, ui) {
597 if(ui.options._opacity) $(ui.helper).css('opacity', ui.options._opacity);
598 }
599});
600
601$.ui.plugin.add("draggable", "iframeFix", {
602 start: function(e, ui) {
603 $(ui.options.iframeFix === true ? "iframe" : ui.options.iframeFix).each(function() {
604 $('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>')
605 .css({
606 width: this.offsetWidth+"px", height: this.offsetHeight+"px",
607 position: "absolute", opacity: "0.001", zIndex: 1000
608 })
609 .css($(this).offset())
610 .appendTo("body");
611 });
612 },
613 stop: function(e, ui) {
614 $("div.DragDropIframeFix").each(function() { this.parentNode.removeChild(this); }); //Remove frame helpers
615 }
616});
617
618$.ui.plugin.add("draggable", "scroll", {
619 start: function(e, ui) {
620 var o = ui.options;
621 var i = $(this).data("draggable");
622 o.scrollSensitivity = o.scrollSensitivity || 20;
623 o.scrollSpeed = o.scrollSpeed || 20;
624
625 i.overflowY = function(el) {
626 do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode);
627 return $(document);
628 }(this);
629 i.overflowX = function(el) {
630 do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode);
631 return $(document);
632 }(this);
633
634 if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') i.overflowYOffset = i.overflowY.offset();
635 if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') i.overflowXOffset = i.overflowX.offset();
636
637 },
638 drag: function(e, ui) {
639
640 var o = ui.options;
641 var i = $(this).data("draggable");
642
643 if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') {
644 if((i.overflowYOffset.top + i.overflowY[0].offsetHeight) - e.pageY < o.scrollSensitivity)
645 i.overflowY[0].scrollTop = i.overflowY[0].scrollTop + o.scrollSpeed;
646 if(e.pageY - i.overflowYOffset.top < o.scrollSensitivity)
647 i.overflowY[0].scrollTop = i.overflowY[0].scrollTop - o.scrollSpeed;
648
649 } else {
650 if(e.pageY - $(document).scrollTop() < o.scrollSensitivity)
651 $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
652 if($(window).height() - (e.pageY - $(document).scrollTop()) < o.scrollSensitivity)
653 $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
654 }
655
656 if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') {
657 if((i.overflowXOffset.left + i.overflowX[0].offsetWidth) - e.pageX < o.scrollSensitivity)
658 i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft + o.scrollSpeed;
659 if(e.pageX - i.overflowXOffset.left < o.scrollSensitivity)
660 i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft - o.scrollSpeed;
661 } else {
662 if(e.pageX - $(document).scrollLeft() < o.scrollSensitivity)
663 $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
664 if($(window).width() - (e.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
665 $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
666 }
667
668 }
669});
670
671$.ui.plugin.add("draggable", "snap", {
672 start: function(e, ui) {
673
674 var inst = $(this).data("draggable");
675 inst.snapElements = [];
676 $(ui.options.snap === true ? '.ui-draggable' : ui.options.snap).each(function() {
677 var $t = $(this); var $o = $t.offset();
678 if(this != inst.element[0]) inst.snapElements.push({
679 item: this,
680 width: $t.outerWidth(), height: $t.outerHeight(),
681 top: $o.top, left: $o.left
682 });
683 });
684
685 },
686 drag: function(e, ui) {
687
688 var inst = $(this).data("draggable");
689 var d = ui.options.snapTolerance || 20;
690 var x1 = ui.absolutePosition.left, x2 = x1 + inst.helperProportions.width,
691 y1 = ui.absolutePosition.top, y2 = y1 + inst.helperProportions.height;
692
693 for (var i = inst.snapElements.length - 1; i >= 0; i--){
694
695 var l = inst.snapElements[i].left, r = l + inst.snapElements[i].width,
696 t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
697
698 //Yes, I know, this is insane ;)
699 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))) continue;
700
701 if(ui.options.snapMode != 'inner') {
702 var ts = Math.abs(t - y2) <= 20;
703 var bs = Math.abs(b - y1) <= 20;
704 var ls = Math.abs(l - x2) <= 20;
705 var rs = Math.abs(r - x1) <= 20;
706 if(ts) ui.position.top = inst.convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top;
707 if(bs) ui.position.top = inst.convertPositionTo("relative", { top: b, left: 0 }).top;
708 if(ls) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left;
709 if(rs) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: r }).left;
710 }
711
712 if(ui.options.snapMode != 'outer') {
713 var ts = Math.abs(t - y1) <= 20;
714 var bs = Math.abs(b - y2) <= 20;
715 var ls = Math.abs(l - x1) <= 20;
716 var rs = Math.abs(r - x2) <= 20;
717 if(ts) ui.position.top = inst.convertPositionTo("relative", { top: t, left: 0 }).top;
718 if(bs) ui.position.top = inst.convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top;
719 if(ls) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: l }).left;
720 if(rs) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left;
721 }
722
723 };
724 }
725});
726
727$.ui.plugin.add("draggable", "connectToSortable", {
728 start: function(e,ui) {
729
730 var inst = $(this).data("draggable");
731 inst.sortables = [];
732 $(ui.options.connectToSortable).each(function() {
733 if($.data(this, 'sortable')) {
734 var sortable = $.data(this, 'sortable');
735 inst.sortables.push({
736 instance: sortable,
737 shouldRevert: sortable.options.revert
738 });
739 sortable.refreshItems(); //Do a one-time refresh at start to refresh the containerCache
740 sortable.propagate("activate", e, inst);
741 }
742 });
743
744 },
745 stop: function(e,ui) {
746
747 //If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
748 var inst = $(this).data("draggable");
749
750 $.each(inst.sortables, function() {
751 if(this.instance.isOver) {
752 this.instance.isOver = 0;
753 inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
754 this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
755 if(this.shouldRevert) this.instance.options.revert = true; //revert here
756 this.instance.mouseStop(e);
757
758 //Also propagate receive event, since the sortable is actually receiving a element
759 this.instance.element.triggerHandler("sortreceive", [e, $.extend(this.instance.ui(), { sender: inst.element })], this.instance.options["receive"]);
760
761 this.instance.options.helper = this.instance.options._helper;
762 } else {
763 this.instance.propagate("deactivate", e, inst);
764 }
765
766 });
767
768 },
769 drag: function(e,ui) {
770
771 var inst = $(this).data("draggable"), self = this;
772
773 var checkPos = function(o) {
774
775 var l = o.left, r = l + o.width,
776 t = o.top, b = t + o.height;
777
778 return (l < (this.positionAbs.left + this.offset.click.left) && (this.positionAbs.left + this.offset.click.left) < r
779 && t < (this.positionAbs.top + this.offset.click.top) && (this.positionAbs.top + this.offset.click.top) < b);
780 };
781
782 $.each(inst.sortables, function(i) {
783
784 if(checkPos.call(inst, this.instance.containerCache)) {
785
786 //If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
787 if(!this.instance.isOver) {
788 this.instance.isOver = 1;
789
790 //Now we fake the start of dragging for the sortable instance,
791 //by cloning the list group item, appending it to the sortable and using it as inst.currentItem
792 //We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
793 this.instance.currentItem = $(self).clone().appendTo(this.instance.element).data("sortable-item", true);
794 this.instance.options._helper = this.instance.options.helper; //Store helper option to later restore it
795 this.instance.options.helper = function() { return ui.helper[0]; };
796
797 e.target = this.instance.currentItem[0];
798 this.instance.mouseCapture(e, true);
799 this.instance.mouseStart(e, true, true);
800
801 //Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
802 this.instance.offset.click.top = inst.offset.click.top;
803 this.instance.offset.click.left = inst.offset.click.left;
804 this.instance.offset.parent.left -= inst.offset.parent.left - this.instance.offset.parent.left;
805 this.instance.offset.parent.top -= inst.offset.parent.top - this.instance.offset.parent.top;
806
807 inst.propagate("toSortable", e);
808
809 }
810
811 //Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
812 if(this.instance.currentItem) this.instance.mouseDrag(e);
813
814 } else {
815
816 //If it doesn't intersect with the sortable, and it intersected before,
817 //we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
818 if(this.instance.isOver) {
819 this.instance.isOver = 0;
820 this.instance.cancelHelperRemoval = true;
821 this.instance.options.revert = false; //No revert here
822 this.instance.mouseStop(e, true);
823 this.instance.options.helper = this.instance.options._helper;
824
825 //Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
826 this.instance.currentItem.remove();
827 if(this.instance.placeholder) this.instance.placeholder.remove();
828
829 inst.propagate("fromSortable", e);
830 }
831
832 };
833
834 });
835
836 }
837});
838
839$.ui.plugin.add("draggable", "stack", {
840 start: function(e,ui) {
841 var group = $.makeArray($(ui.options.stack.group)).sort(function(a,b) {
842 return (parseInt($(a).css("zIndex"),10) || ui.options.stack.min) - (parseInt($(b).css("zIndex"),10) || ui.options.stack.min);
843 });
844
845 $(group).each(function(i) {
846 this.style.zIndex = ui.options.stack.min + i;
847 });
848
849 this[0].style.zIndex = ui.options.stack.min + group.length;
850 }
851});
852
853})(jQuery);
854/*
855 * jQuery UI Sortable
856 *
857 * Copyright (c) 2008 Paul Bakaus
858 * Dual licensed under the MIT (MIT-LICENSE.txt)
859 * and GPL (GPL-LICENSE.txt) licenses.
860 *
861 * http://docs.jquery.com/UI/Sortables
862 *
863 * Depends:
864 * ui.core.js
865 */
866(function($) {
867
868function contains(a, b) {
869 var safari2 = $.browser.safari && $.browser.version < 522;
870 if (a.contains && !safari2) {
871 return a.contains(b);
872 }
873 if (a.compareDocumentPosition)
874 return !!(a.compareDocumentPosition(b) & 16);
875 while (b = b.parentNode)
876 if (b == a) return true;
877 return false;
878};
879
880$.widget("ui.sortable", $.extend({}, $.ui.mouse, {
881 init: function() {
882
883 var o = this.options;
884 this.containerCache = {};
885 this.element.addClass("ui-sortable");
886
887 //Get the items
888 this.refresh();
889
890 //Let's determine if the items are floating
891 this.floating = this.items.length ? (/left|right/).test(this.items[0].item.css('float')) : false;
892
893 //Let's determine the parent's offset
894 if(!(/(relative|absolute|fixed)/).test(this.element.css('position'))) this.element.css('position', 'relative');
895 this.offset = this.element.offset();
896
897 //Initialize mouse events for interaction
898 this.mouseInit();
899
900 },
901 plugins: {},
902 ui: function(inst) {
903 return {
904 helper: (inst || this)["helper"],
905 placeholder: (inst || this)["placeholder"] || $([]),
906 position: (inst || this)["position"],
907 absolutePosition: (inst || this)["positionAbs"],
908 options: this.options,
909 element: this.element,
910 item: (inst || this)["currentItem"],
911 sender: inst ? inst.element : null
912 };
913 },
914 propagate: function(n,e,inst, noPropagation) {
915 $.ui.plugin.call(this, n, [e, this.ui(inst)]);
916 if(!noPropagation) this.element.triggerHandler(n == "sort" ? n : "sort"+n, [e, this.ui(inst)], this.options[n]);
917 },
918 serialize: function(o) {
919
920 var items = ($.isFunction(this.options.items) ? this.options.items.call(this.element) : $(this.options.items, this.element)).not('.ui-sortable-helper'); //Only the items of the sortable itself
921 var str = []; o = o || {};
922
923 items.each(function() {
924 var res = ($(this).attr(o.attribute || 'id') || '').match(o.expression || (/(.+)[-=_](.+)/));
925 if(res) str.push((o.key || res[1])+'[]='+(o.key && o.expression ? res[1] : res[2]));
926 });
927
928 return str.join('&');
929
930 },
931 toArray: function(attr) {
932
933 var items = ($.isFunction(this.options.items) ? this.options.items.call(this.element) : $(this.options.items, this.element)).not('.ui-sortable-helper'); //Only the items of the sortable itself
934 var ret = [];
935
936 items.each(function() { ret.push($(this).attr(attr || 'id')); });
937 return ret;
938
939 },
940 /* Be careful with the following core functions */
941 intersectsWith: function(item) {
942
943 var x1 = this.positionAbs.left, x2 = x1 + this.helperProportions.width,
944 y1 = this.positionAbs.top, y2 = y1 + this.helperProportions.height;
945 var l = item.left, r = l + item.width,
946 t = item.top, b = t + item.height;
947
948 if(this.options.tolerance == "pointer" || this.options.forcePointerForContainers || (this.options.tolerance == "guess" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])) {
949 return (y1 + this.offset.click.top > t && y1 + this.offset.click.top < b && x1 + this.offset.click.left > l && x1 + this.offset.click.left < r);
950 } else {
951
952 return (l < x1 + (this.helperProportions.width / 2) // Right Half
953 && x2 - (this.helperProportions.width / 2) < r // Left Half
954 && t < y1 + (this.helperProportions.height / 2) // Bottom Half
955 && y2 - (this.helperProportions.height / 2) < b ); // Top Half
956
957 }
958
959 },
960 intersectsWithEdge: function(item) {
961 var x1 = this.positionAbs.left, x2 = x1 + this.helperProportions.width,
962 y1 = this.positionAbs.top, y2 = y1 + this.helperProportions.height;
963 var l = item.left, r = l + item.width,
964 t = item.top, b = t + item.height;
965
966 if(this.options.tolerance == "pointer" || (this.options.tolerance == "guess" && this.helperProportions[this.floating ? 'width' : 'height'] > item[this.floating ? 'width' : 'height'])) {
967
968 if(!(y1 + this.offset.click.top > t && y1 + this.offset.click.top < b && x1 + this.offset.click.left > l && x1 + this.offset.click.left < r)) return false;
969
970 if(this.floating) {
971 if(x1 + this.offset.click.left > l && x1 + this.offset.click.left < l + item.width/2) return 2;
972 if(x1 + this.offset.click.left > l+item.width/2 && x1 + this.offset.click.left < r) return 1;
973 } else {
974 if(y1 + this.offset.click.top > t && y1 + this.offset.click.top < t + item.height/2) return 2;
975 if(y1 + this.offset.click.top > t+item.height/2 && y1 + this.offset.click.top < b) return 1;
976 }
977
978 } else {
979
980 if (!(l < x1 + (this.helperProportions.width / 2) // Right Half
981 && x2 - (this.helperProportions.width / 2) < r // Left Half
982 && t < y1 + (this.helperProportions.height / 2) // Bottom Half
983 && y2 - (this.helperProportions.height / 2) < b )) return false; // Top Half
984
985 if(this.floating) {
986 if(x2 > l && x1 < l) return 2; //Crosses left edge
987 if(x1 < r && x2 > r) return 1; //Crosses right edge
988 } else {
989 if(y2 > t && y1 < t) return 1; //Crosses top edge
990 if(y1 < b && y2 > b) return 2; //Crosses bottom edge
991 }
992
993 }
994
995 return false;
996
997 },
998 refresh: function() {
999 this.refreshItems();
1000 this.refreshPositions();
1001 },
1002 refreshItems: function() {
1003
1004 this.items = [];
1005 this.containers = [this];
1006 var items = this.items;
1007 var self = this;
1008 var queries = [[$.isFunction(this.options.items) ? this.options.items.call(this.element, null, { options: this.options, item: this.currentItem }) : $(this.options.items, this.element), this]];
1009
1010 if(this.options.connectWith) {
1011 for (var i = this.options.connectWith.length - 1; i >= 0; i--){
1012 var cur = $(this.options.connectWith[i]);
1013 for (var j = cur.length - 1; j >= 0; j--){
1014 var inst = $.data(cur[j], 'sortable');
1015 if(inst && !inst.options.disabled) {
1016 queries.push([$.isFunction(inst.options.items) ? inst.options.items.call(inst.element) : $(inst.options.items, inst.element), inst]);
1017 this.containers.push(inst);
1018 }
1019 };
1020 };
1021 }
1022
1023 for (var i = queries.length - 1; i >= 0; i--){
1024 queries[i][0].each(function() {
1025 $.data(this, 'sortable-item', queries[i][1]); // Data for target checking (mouse manager)
1026 items.push({
1027 item: $(this),
1028 instance: queries[i][1],
1029 width: 0, height: 0,
1030 left: 0, top: 0
1031 });
1032 });
1033 };
1034
1035 },
1036 refreshPositions: function(fast) {
1037
1038 //This has to be redone because due to the item being moved out/into the offsetParent, the offsetParent's position will change
1039 if(this.offsetParent) {
1040 var po = this.offsetParent.offset();
1041 this.offset.parent = { top: po.top + this.offsetParentBorders.top, left: po.left + this.offsetParentBorders.left };
1042 }
1043
1044 for (var i = this.items.length - 1; i >= 0; i--){
1045
1046 //We ignore calculating positions of all connected containers when we're not over them
1047 if(this.items[i].instance != this.currentContainer && this.currentContainer && this.items[i].item[0] != this.currentItem[0])
1048 continue;
1049
1050 var t = this.options.toleranceElement ? $(this.options.toleranceElement, this.items[i].item) : this.items[i].item;
1051
1052 if(!fast) {
1053 this.items[i].width = t[0].offsetWidth;
1054 this.items[i].height = t[0].offsetHeight;
1055 }
1056
1057 var p = t.offset();
1058 this.items[i].left = p.left;
1059 this.items[i].top = p.top;
1060
1061 };
1062
1063 if(this.options.custom && this.options.custom.refreshContainers) {
1064 this.options.custom.refreshContainers.call(this);
1065 } else {
1066 for (var i = this.containers.length - 1; i >= 0; i--){
1067 var p =this.containers[i].element.offset();
1068 this.containers[i].containerCache.left = p.left;
1069 this.containers[i].containerCache.top = p.top;
1070 this.containers[i].containerCache.width = this.containers[i].element.outerWidth();
1071 this.containers[i].containerCache.height = this.containers[i].element.outerHeight();
1072 };
1073 }
1074
1075 },
1076 destroy: function() {
1077 this.element
1078 .removeClass("ui-sortable ui-sortable-disabled")
1079 .removeData("sortable")
1080 .unbind(".sortable");
1081 this.mouseDestroy();
1082
1083 for ( var i = this.items.length - 1; i >= 0; i-- )
1084 this.items[i].item.removeData("sortable-item");
1085 },
1086 createPlaceholder: function(that) {
1087
1088 var self = that || this, o = self.options;
1089
1090 if(o.placeholder.constructor == String) {
1091 var className = o.placeholder;
1092 o.placeholder = {
1093 element: function() {
1094 return $('<div></div>').addClass(className)[0];
1095 },
1096 update: function(i, p) {
1097 p.css(i.offset()).css({ width: i.outerWidth(), height: i.outerHeight() });
1098 }
1099 };
1100 }
1101
1102 self.placeholder = $(o.placeholder.element.call(self.element, self.currentItem)).appendTo('body').css({ position: 'absolute' });
1103 o.placeholder.update.call(self.element, self.currentItem, self.placeholder);
1104 },
1105 contactContainers: function(e) {
1106 for (var i = this.containers.length - 1; i >= 0; i--){
1107
1108 if(this.intersectsWith(this.containers[i].containerCache)) {
1109 if(!this.containers[i].containerCache.over) {
1110
1111
1112 if(this.currentContainer != this.containers[i]) {
1113
1114 //When entering a new container, we will find the item with the least distance and append our item near it
1115 var dist = 10000; var itemWithLeastDistance = null; var base = this.positionAbs[this.containers[i].floating ? 'left' : 'top'];
1116 for (var j = this.items.length - 1; j >= 0; j--) {
1117 if(!contains(this.containers[i].element[0], this.items[j].item[0])) continue;
1118 var cur = this.items[j][this.containers[i].floating ? 'left' : 'top'];
1119 if(Math.abs(cur - base) < dist) {
1120 dist = Math.abs(cur - base); itemWithLeastDistance = this.items[j];
1121 }
1122 }
1123
1124 if(!itemWithLeastDistance && !this.options.dropOnEmpty) //Check if dropOnEmpty is enabled
1125 continue;
1126
1127 //We also need to exchange the placeholder
1128 if(this.placeholder) this.placeholder.remove();
1129 if(this.containers[i].options.placeholder) {
1130 this.containers[i].createPlaceholder(this);
1131 } else {
1132 this.placeholder = null;;
1133 }
1134
1135 this.currentContainer = this.containers[i];
1136 itemWithLeastDistance ? this.rearrange(e, itemWithLeastDistance, null, true) : this.rearrange(e, null, this.containers[i].element, true);
1137 this.propagate("change", e); //Call plugins and callbacks
1138 this.containers[i].propagate("change", e, this); //Call plugins and callbacks
1139
1140 }
1141
1142 this.containers[i].propagate("over", e, this);
1143 this.containers[i].containerCache.over = 1;
1144 }
1145 } else {
1146 if(this.containers[i].containerCache.over) {
1147 this.containers[i].propagate("out", e, this);
1148 this.containers[i].containerCache.over = 0;
1149 }
1150 }
1151
1152 };
1153 },
1154 mouseCapture: function(e, overrideHandle) {
1155
1156 if(this.options.disabled || this.options.type == 'static') return false;
1157
1158 //We have to refresh the items data once first
1159 this.refreshItems();
1160
1161 //Find out if the clicked node (or one of its parents) is a actual item in this.items
1162 var currentItem = null, self = this, nodes = $(e.target).parents().each(function() {
1163 if($.data(this, 'sortable-item') == self) {
1164 currentItem = $(this);
1165 return false;
1166 }
1167 });
1168 if($.data(e.target, 'sortable-item') == self) currentItem = $(e.target);
1169
1170 if(!currentItem) return false;
1171 if(this.options.handle && !overrideHandle) {
1172 var validHandle = false;
1173
1174 $(this.options.handle, currentItem).find("*").andSelf().each(function() { if(this == e.target) validHandle = true; });
1175 if(!validHandle) return false;
1176 }
1177
1178 this.currentItem = currentItem;
1179 return true;
1180
1181 },
1182 mouseStart: function(e, overrideHandle, noActivation) {
1183
1184 var o = this.options;
1185 this.currentContainer = this;
1186
1187 //We only need to call refreshPositions, because the refreshItems call has been moved to mouseCapture
1188 this.refreshPositions();
1189
1190 //Create and append the visible helper
1191 this.helper = typeof o.helper == 'function' ? $(o.helper.apply(this.element[0], [e, this.currentItem])) : this.currentItem.clone();
1192 if (!this.helper.parents('body').length) $(o.appendTo != 'parent' ? o.appendTo : this.currentItem[0].parentNode)[0].appendChild(this.helper[0]); //Add the helper to the DOM if that didn't happen already
1193 this.helper.css({ position: 'absolute', clear: 'both' }).addClass('ui-sortable-helper'); //Position it absolutely and add a helper class
1194
1195 /*
1196 * - Position generation -
1197 * This block generates everything position related - it's the core of draggables.
1198 */
1199
1200 this.margins = { //Cache the margins
1201 left: (parseInt(this.currentItem.css("marginLeft"),10) || 0),
1202 top: (parseInt(this.currentItem.css("marginTop"),10) || 0)
1203 };
1204
1205 this.offset = this.currentItem.offset(); //The element's absolute position on the page
1206 this.offset = { //Substract the margins from the element's absolute offset
1207 top: this.offset.top - this.margins.top,
1208 left: this.offset.left - this.margins.left
1209 };
1210
1211 this.offset.click = { //Where the click happened, relative to the element
1212 left: e.pageX - this.offset.left,
1213 top: e.pageY - this.offset.top
1214 };
1215
1216 this.offsetParent = this.helper.offsetParent(); //Get the offsetParent and cache its position
1217 var po = this.offsetParent.offset();
1218
1219 this.offsetParentBorders = {
1220 top: (parseInt(this.offsetParent.css("borderTopWidth"),10) || 0),
1221 left: (parseInt(this.offsetParent.css("borderLeftWidth"),10) || 0)
1222 };
1223 this.offset.parent = { //Store its position plus border
1224 top: po.top + this.offsetParentBorders.top,
1225 left: po.left + this.offsetParentBorders.left
1226 };
1227
1228 this.originalPosition = this.generatePosition(e); //Generate the original position
1229 this.domPosition = { prev: this.currentItem.prev()[0], parent: this.currentItem.parent()[0] }; //Cache the former DOM position
1230
1231 //If o.placeholder is used, create a new element at the given position with the class
1232 this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Cache the helper size
1233 if(o.placeholder) this.createPlaceholder();
1234
1235 //Call plugins and callbacks
1236 this.propagate("start", e);
1237 this.helperProportions = { width: this.helper.outerWidth(), height: this.helper.outerHeight() };//Recache the helper size
1238
1239 if(o.cursorAt) {
1240 if(o.cursorAt.left != undefined) this.offset.click.left = o.cursorAt.left;
1241 if(o.cursorAt.right != undefined) this.offset.click.left = this.helperProportions.width - o.cursorAt.right;
1242 if(o.cursorAt.top != undefined) this.offset.click.top = o.cursorAt.top;
1243 if(o.cursorAt.bottom != undefined) this.offset.click.top = this.helperProportions.height - o.cursorAt.bottom;
1244 }
1245
1246 /*
1247 * - Position constraining -
1248 * Here we prepare position constraining like grid and containment.
1249 */
1250
1251 if(o.containment) {
1252 if(o.containment == 'parent') o.containment = this.helper[0].parentNode;
1253 if(o.containment == 'document' || o.containment == 'window') this.containment = [
1254 0 - this.offset.parent.left,
1255 0 - this.offset.parent.top,
1256 $(o.containment == 'document' ? document : window).width() - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.element.css("marginRight"),10) || 0),
1257 ($(o.containment == 'document' ? document : window).height() || document.body.parentNode.scrollHeight) - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.element.css("marginBottom"),10) || 0)
1258 ];
1259
1260 if(!(/^(document|window|parent)$/).test(o.containment)) {
1261 var ce = $(o.containment)[0];
1262 var co = $(o.containment).offset();
1263
1264 this.containment = [
1265 co.left + (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.parent.left,
1266 co.top + (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.parent.top,
1267 co.left+Math.max(ce.scrollWidth,ce.offsetWidth) - (parseInt($(ce).css("borderLeftWidth"),10) || 0) - this.offset.parent.left - this.helperProportions.width - this.margins.left - (parseInt(this.currentItem.css("marginRight"),10) || 0),
1268 co.top+Math.max(ce.scrollHeight,ce.offsetHeight) - (parseInt($(ce).css("borderTopWidth"),10) || 0) - this.offset.parent.top - this.helperProportions.height - this.margins.top - (parseInt(this.currentItem.css("marginBottom"),10) || 0)
1269 ];
1270 }
1271 }
1272
1273 //Set the original element visibility to hidden to still fill out the white space
1274 if(this.options.placeholder != 'clone')
1275 this.currentItem.css('visibility', 'hidden');
1276
1277 //Post 'activate' events to possible containers
1278 if(!noActivation) {
1279 for (var i = this.containers.length - 1; i >= 0; i--) { this.containers[i].propagate("activate", e, this); }
1280 }
1281
1282 //Prepare possible droppables
1283 if($.ui.ddmanager) $.ui.ddmanager.current = this;
1284 if ($.ui.ddmanager && !o.dropBehaviour) $.ui.ddmanager.prepareOffsets(this, e);
1285
1286 this.dragging = true;
1287
1288 this.mouseDrag(e); //Execute the drag once - this causes the helper not to be visible before getting its correct position
1289 return true;
1290
1291
1292 },
1293 convertPositionTo: function(d, pos) {
1294 if(!pos) pos = this.position;
1295 var mod = d == "absolute" ? 1 : -1;
1296 return {
1297 top: (
1298 pos.top // the calculated relative position
1299 + this.offset.parent.top * mod // The offsetParent's offset without borders (offset + border)
1300 - (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) * mod // The offsetParent's scroll position
1301 + this.margins.top * mod //Add the margin (you don't want the margin counting in intersection methods)
1302 ),
1303 left: (
1304 pos.left // the calculated relative position
1305 + this.offset.parent.left * mod // The offsetParent's offset without borders (offset + border)
1306 - (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft) * mod // The offsetParent's scroll position
1307 + this.margins.left * mod //Add the margin (you don't want the margin counting in intersection methods)
1308 )
1309 };
1310 },
1311 generatePosition: function(e) {
1312
1313 var o = this.options;
1314 var position = {
1315 top: (
1316 e.pageY // The absolute mouse position
1317 - this.offset.click.top // Click offset (relative to the element)
1318 - this.offset.parent.top // The offsetParent's offset without borders (offset + border)
1319 + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop) // The offsetParent's scroll position, not if the element is fixed
1320 ),
1321 left: (
1322 e.pageX // The absolute mouse position
1323 - this.offset.click.left // Click offset (relative to the element)
1324 - this.offset.parent.left // The offsetParent's offset without borders (offset + border)
1325 + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft) // The offsetParent's scroll position, not if the element is fixed
1326 )
1327 };
1328
1329 if(!this.originalPosition) return position; //If we are not dragging yet, we won't check for options
1330
1331 /*
1332 * - Position constraining -
1333 * Constrain the position to a mix of grid, containment.
1334 */
1335 if(this.containment) {
1336 if(position.left < this.containment[0]) position.left = this.containment[0];
1337 if(position.top < this.containment[1]) position.top = this.containment[1];
1338 if(position.left > this.containment[2]) position.left = this.containment[2];
1339 if(position.top > this.containment[3]) position.top = this.containment[3];
1340 }
1341
1342 if(o.grid) {
1343 var top = this.originalPosition.top + Math.round((position.top - this.originalPosition.top) / o.grid[1]) * o.grid[1];
1344 position.top = this.containment ? (!(top < this.containment[1] || top > this.containment[3]) ? top : (!(top < this.containment[1]) ? top - o.grid[1] : top + o.grid[1])) : top;
1345
1346 var left = this.originalPosition.left + Math.round((position.left - this.originalPosition.left) / o.grid[0]) * o.grid[0];
1347 position.left = this.containment ? (!(left < this.containment[0] || left > this.containment[2]) ? left : (!(left < this.containment[0]) ? left - o.grid[0] : left + o.grid[0])) : left;
1348 }
1349
1350 return position;
1351 },
1352 mouseDrag: function(e) {
1353
1354 //Compute the helpers position
1355 this.position = this.generatePosition(e);
1356 this.positionAbs = this.convertPositionTo("absolute");
1357
1358 //Call the internal plugins
1359 $.ui.plugin.call(this, "sort", [e, this.ui()]);
1360
1361 //Regenerate the absolute position used for position checks
1362 this.positionAbs = this.convertPositionTo("absolute");
1363
1364 //Set the helper's position
1365 this.helper[0].style.left = this.position.left+'px';
1366 this.helper[0].style.top = this.position.top+'px';
1367
1368 //Rearrange
1369 for (var i = this.items.length - 1; i >= 0; i--) {
1370 var intersection = this.intersectsWithEdge(this.items[i]);
1371 if(!intersection) continue;
1372
1373 if(this.items[i].item[0] != this.currentItem[0] //cannot intersect with itself
1374 && this.currentItem[intersection == 1 ? "next" : "prev"]()[0] != this.items[i].item[0] //no useless actions that have been done before
1375 && !contains(this.currentItem[0], this.items[i].item[0]) //no action if the item moved is the parent of the item checked
1376 && (this.options.type == 'semi-dynamic' ? !contains(this.element[0], this.items[i].item[0]) : true)
1377 ) {
1378
1379 this.direction = intersection == 1 ? "down" : "up";
1380 this.rearrange(e, this.items[i]);
1381 this.propagate("change", e); //Call plugins and callbacks
1382 break;
1383 }
1384 }
1385
1386 //Post events to containers
1387 this.contactContainers(e);
1388
1389 //Interconnect with droppables
1390 if($.ui.ddmanager) $.ui.ddmanager.drag(this, e);
1391
1392 //Call callbacks
1393 this.element.triggerHandler("sort", [e, this.ui()], this.options["sort"]);
1394
1395 return false;
1396
1397 },
1398 rearrange: function(e, i, a, hardRefresh) {
1399 a ? a[0].appendChild(this.currentItem[0]) : i.item[0].parentNode.insertBefore(this.currentItem[0], (this.direction == 'down' ? i.item[0] : i.item[0].nextSibling));
1400
1401 //Various things done here to improve the performance:
1402 // 1. we create a setTimeout, that calls refreshPositions
1403 // 2. on the instance, we have a counter variable, that get's higher after every append
1404 // 3. on the local scope, we copy the counter variable, and check in the timeout, if it's still the same
1405 // 4. this lets only the last addition to the timeout stack through
1406 this.counter = this.counter ? ++this.counter : 1;
1407 var self = this, counter = this.counter;
1408
1409 window.setTimeout(function() {
1410 if(counter == self.counter) self.refreshPositions(!hardRefresh); //Precompute after each DOM insertion, NOT on mousemove
1411 },0);
1412
1413 if(this.options.placeholder)
1414 this.options.placeholder.update.call(this.element, this.currentItem, this.placeholder);
1415 },
1416 mouseStop: function(e, noPropagation) {
1417
1418 //If we are using droppables, inform the manager about the drop
1419 if ($.ui.ddmanager && !this.options.dropBehaviour)
1420 $.ui.ddmanager.drop(this, e);
1421
1422 if(this.options.revert) {
1423 var self = this;
1424 var cur = self.currentItem.offset();
1425
1426 //Also animate the placeholder if we have one
1427 if(self.placeholder) self.placeholder.animate({ opacity: 'hide' }, (parseInt(this.options.revert, 10) || 500)-50);
1428
1429 $(this.helper).animate({
1430 left: cur.left - this.offset.parent.left - self.margins.left + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollLeft),
1431 top: cur.top - this.offset.parent.top - self.margins.top + (this.offsetParent[0] == document.body ? 0 : this.offsetParent[0].scrollTop)
1432 }, parseInt(this.options.revert, 10) || 500, function() {
1433 self.clear(e);
1434 });
1435 } else {
1436 this.clear(e, noPropagation);
1437 }
1438
1439 return false;
1440
1441 },
1442 clear: function(e, noPropagation) {
1443
1444 if(this.domPosition.prev != this.currentItem.prev().not(".ui-sortable-helper")[0] || this.domPosition.parent != this.currentItem.parent()[0]) this.propagate("update", e, null, noPropagation); //Trigger update callback if the DOM position has changed
1445 if(!contains(this.element[0], this.currentItem[0])) { //Node was moved out of the current element
1446 this.propagate("remove", e, null, noPropagation);
1447 for (var i = this.containers.length - 1; i >= 0; i--){
1448 if(contains(this.containers[i].element[0], this.currentItem[0])) {
1449 this.containers[i].propagate("update", e, this, noPropagation);
1450 this.containers[i].propagate("receive", e, this, noPropagation);
1451 }
1452 };
1453 };
1454
1455 //Post events to containers
1456 for (var i = this.containers.length - 1; i >= 0; i--){
1457 this.containers[i].propagate("deactivate", e, this, noPropagation);
1458 if(this.containers[i].containerCache.over) {
1459 this.containers[i].propagate("out", e, this);
1460 this.containers[i].containerCache.over = 0;
1461 }
1462 }
1463
1464 this.dragging = false;
1465 if(this.cancelHelperRemoval) {
1466 this.propagate("stop", e, null, noPropagation);
1467 return false;
1468 }
1469
1470 $(this.currentItem).css('visibility', '');
1471 if(this.placeholder) this.placeholder.remove();
1472 this.helper.remove(); this.helper = null;
1473 this.propagate("stop", e, null, noPropagation);
1474
1475 return true;
1476
1477 }
1478}));
1479
1480$.extend($.ui.sortable, {
1481 getter: "serialize toArray",
1482 defaults: {
1483 helper: "clone",
1484 tolerance: "guess",
1485 distance: 1,
1486 delay: 0,
1487 scroll: true,
1488 scrollSensitivity: 20,
1489 scrollSpeed: 20,
1490 cancel: ":input",
1491 items: '> *',
1492 zIndex: 1000,
1493 dropOnEmpty: true,
1494 appendTo: "parent"
1495 }
1496});
1497
1498/*
1499 * Sortable Extensions
1500 */
1501
1502$.ui.plugin.add("sortable", "cursor", {
1503 start: function(e, ui) {
1504 var t = $('body');
1505 if (t.css("cursor")) ui.options._cursor = t.css("cursor");
1506 t.css("cursor", ui.options.cursor);
1507 },
1508 stop: function(e, ui) {
1509 if (ui.options._cursor) $('body').css("cursor", ui.options._cursor);
1510 }
1511});
1512
1513$.ui.plugin.add("sortable", "zIndex", {
1514 start: function(e, ui) {
1515 var t = ui.helper;
1516 if(t.css("zIndex")) ui.options._zIndex = t.css("zIndex");
1517 t.css('zIndex', ui.options.zIndex);
1518 },
1519 stop: function(e, ui) {
1520 if(ui.options._zIndex) $(ui.helper).css('zIndex', ui.options._zIndex);
1521 }
1522});
1523
1524$.ui.plugin.add("sortable", "opacity", {
1525 start: function(e, ui) {
1526 var t = ui.helper;
1527 if(t.css("opacity")) ui.options._opacity = t.css("opacity");
1528 t.css('opacity', ui.options.opacity);
1529 },
1530 stop: function(e, ui) {
1531 if(ui.options._opacity) $(ui.helper).css('opacity', ui.options._opacity);
1532 }
1533});
1534
1535$.ui.plugin.add("sortable", "scroll", {
1536 start: function(e, ui) {
1537 var o = ui.options;
1538 var i = $(this).data("sortable");
1539
1540 i.overflowY = function(el) {
1541 do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-y'))) return el; el = el.parent(); } while (el[0].parentNode);
1542 return $(document);
1543 }(i.currentItem);
1544 i.overflowX = function(el) {
1545 do { if(/auto|scroll/.test(el.css('overflow')) || (/auto|scroll/).test(el.css('overflow-x'))) return el; el = el.parent(); } while (el[0].parentNode);
1546 return $(document);
1547 }(i.currentItem);
1548
1549 if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') i.overflowYOffset = i.overflowY.offset();
1550 if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') i.overflowXOffset = i.overflowX.offset();
1551
1552 },
1553 sort: function(e, ui) {
1554
1555 var o = ui.options;
1556 var i = $(this).data("sortable");
1557
1558 if(i.overflowY[0] != document && i.overflowY[0].tagName != 'HTML') {
1559 if((i.overflowYOffset.top + i.overflowY[0].offsetHeight) - e.pageY < o.scrollSensitivity)
1560 i.overflowY[0].scrollTop = i.overflowY[0].scrollTop + o.scrollSpeed;
1561 if(e.pageY - i.overflowYOffset.top < o.scrollSensitivity)
1562 i.overflowY[0].scrollTop = i.overflowY[0].scrollTop - o.scrollSpeed;
1563 } else {
1564 if(e.pageY - $(document).scrollTop() < o.scrollSensitivity)
1565 $(document).scrollTop($(document).scrollTop() - o.scrollSpeed);
1566 if($(window).height() - (e.pageY - $(document).scrollTop()) < o.scrollSensitivity)
1567 $(document).scrollTop($(document).scrollTop() + o.scrollSpeed);
1568 }
1569
1570 if(i.overflowX[0] != document && i.overflowX[0].tagName != 'HTML') {
1571 if((i.overflowXOffset.left + i.overflowX[0].offsetWidth) - e.pageX < o.scrollSensitivity)
1572 i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft + o.scrollSpeed;
1573 if(e.pageX - i.overflowXOffset.left < o.scrollSensitivity)
1574 i.overflowX[0].scrollLeft = i.overflowX[0].scrollLeft - o.scrollSpeed;
1575 } else {
1576 if(e.pageX - $(document).scrollLeft() < o.scrollSensitivity)
1577 $(document).scrollLeft($(document).scrollLeft() - o.scrollSpeed);
1578 if($(window).width() - (e.pageX - $(document).scrollLeft()) < o.scrollSensitivity)
1579 $(document).scrollLeft($(document).scrollLeft() + o.scrollSpeed);
1580 }
1581
1582 }
1583});
1584
1585$.ui.plugin.add("sortable", "axis", {
1586 sort: function(e, ui) {
1587
1588 var i = $(this).data("sortable");
1589
1590 if(ui.options.axis == "y") i.position.left = i.originalPosition.left;
1591 if(ui.options.axis == "x") i.position.top = i.originalPosition.top;
1592
1593 }
1594});
1595
1596})(jQuery);
Note: See TracBrowser for help on using the repository browser.