6 lines
18 KiB
JavaScript
6 lines
18 KiB
JavaScript
|
// script.aculo.us dragdrop.js v1.8.3, Thu Oct 08 11:23:33 +0200 2009
|
||
|
// Copyright (c) 2005-2009 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
||
|
//
|
||
|
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
||
|
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
||
|
if(Object.isUndefined(Effect))throw"dragdrop.js requires including script.aculo.us' effects.js library";var Droppables={drops:[],remove:function(e){this.drops=this.drops.reject(function(t){return t.element==$(e)})},add:function(e){e=$(e);var t=Object.extend({greedy:!0,hoverclass:null,tree:!1},arguments[1]||{});if(t.containment){t._containers=[];var n=t.containment;Object.isArray(n)?n.each(function(e){t._containers.push($(e))}):t._containers.push($(n))}t.accept&&(t.accept=[t.accept].flatten()),Element.makePositioned(e),t.element=e,this.drops.push(t)},findDeepestChild:function(e){deepest=e[0];for(i=1;i<e.length;++i)Element.isParent(e[i].element,deepest.element)&&(deepest=e[i]);return deepest},isContained:function(e,t){var n;return t.tree?n=e.treeNode:n=e.parentNode,t._containers.detect(function(e){return n==e})},isAffected:function(e,t,n){return n.element!=t&&(!n._containers||this.isContained(t,n))&&(!n.accept||Element.classNames(t).detect(function(e){return n.accept.include(e)}))&&Position.within(n.element,e[0],e[1])},deactivate:function(e){e.hoverclass&&Element.removeClassName(e.element,e.hoverclass),this.last_active=null},activate:function(e){e.hoverclass&&Element.addClassName(e.element,e.hoverclass),this.last_active=e},show:function(e,t){if(!this.drops.length)return;var n,r=[];this.drops.each(function(n){Droppables.isAffected(e,t,n)&&r.push(n)}),r.length>0&&(n=Droppables.findDeepestChild(r)),this.last_active&&this.last_active!=n&&this.deactivate(this.last_active),n&&(Position.within(n.element,e[0],e[1]),n.onHover&&n.onHover(t,n.element,Position.overlap(n.overlap,n.element)),n!=this.last_active&&Droppables.activate(n))},fire:function(e,t){if(!this.last_active)return;Position.prepare();if(this.isAffected([Event.pointerX(e),Event.pointerY(e)],t,this.last_active)&&this.last_active.onDrop)return this.last_active.onDrop(t,this.last_active.element,e),!0},reset:function(){this.last_active&&this.deactivate(this.last_active)}},Draggables={drags:[],observers:[],register:function(e){this.drags.length==0&&(this.eventMouseUp=this.endDrag.bindAsEventListener(this),this.eventMouseMove=this.updateDrag.bindAsEventListener(this),this.eventKeypress=this.keyPress.bindAsEventListener(this),Event.observe(document,"mouseup",this.eventMouseUp),Event.observe(document,"mousemove",this.eventMouseMove),Event.observe(document,"keypress",this.eventKeypress)),this.drags.push(e)},unregister:function(e){this.drags=this.drags.reject(function(t){return t==e}),this.drags.length==0&&(Event.stopObserving(document,"mouseup",this.eventMouseUp),Event.stopObserving(document,"mousemove",this.eventMouseMove),Event.stopObserving(document,"keypress",this.eventKeypress))},activate:function(e){e.options.delay?this._timeout=setTimeout(function(){Draggables._timeout=null,window.focus(),Draggables.activeDraggable=e}.bind(this),e.options.delay):(window.focus(),this.activeDraggable=e)},deactivate:function(){this.activeDraggable=null},updateDrag:function(e){if(!this.activeDraggable)return;var t=[Event.pointerX(e),Event.pointerY(e)];if(this._lastPointer&&this._lastPointer.inspect()==t.inspect())return;this._lastPointer=t,this.activeDraggable.updateDrag(e,t)},endDrag:function(e){this._timeout&&(clearTimeout(this._timeout),this._timeout=null);if(!this.activeDraggable)return;this._lastPointer=null,this.activeDraggable.endDrag(e),this.activeDraggable=null},keyPress:function(e){this.activeDraggable&&this.activeDraggable.keyPress(e)},addObserver:function(e){this.observers.push(e),this._cacheObserverCallbacks()},removeObserver:function(e){this.observers=this.observers.reject(function(t){return t.element==e}),this._cacheObserverCallbacks()},notify:function(e,t,n){this[e+"Count"]>0&&this.observers.each(function(r){r[e]&&r[e](e,t,n)}),t.options[e]&&t.options[e](t,n)},_cacheObserverCallbacks:function(){["onStart","onEnd","onDrag"].each(function(e){Draggables[e+"Count"]=Draggables.observers.select(function(t){return t[e]}).length})}},Draggable=Class.create({initialize:function(e){var t={handle:!1,reverteffect:function(e,t,n){var r=Math.sqrt(Math.abs(t^2)+Math.abs(n^2))*.02;new Effect.
|