]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - include/javascript/yui3/build/dd/dd-delegate.js
Release 6.2.2
[Github/sugarcrm.git] / include / javascript / yui3 / build / dd / dd-delegate.js
1 /*
2  Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3  Code licensed under the BSD License:
4  http://developer.yahoo.com/yui/license.html
5  version: 3.3.0
6  build: 3167
7  */
8 YUI.add('dd-delegate',function(Y){var Delegate=function(o){Delegate.superclass.constructor.apply(this,arguments);},CONT='container',NODES='nodes',_tmpNode=Y.Node.create('<div>Temp Node</div>');Y.extend(Delegate,Y.Base,{_bubbleTargets:Y.DD.DDM,dd:null,_shimState:null,_handles:null,_onNodeChange:function(e){this.set('dragNode',e.newVal);},_afterDragEnd:function(e){Y.DD.DDM._noShim=this._shimState;this.set('lastNode',this.dd.get('node'));this.get('lastNode').removeClass(Y.DD.DDM.CSS_PREFIX+'-dragging');this.dd._unprep();this.dd.set('node',_tmpNode);},_delMouseDown:function(e){var tar=e.currentTarget,dd=this.dd;if(tar.test(this.get(NODES))&&!tar.test(this.get('invalid'))){this._shimState=Y.DD.DDM._noShim;Y.DD.DDM._noShim=true;this.set('currentNode',tar);dd.set('node',tar);if(dd.proxy){dd.set('dragNode',Y.DD.DDM._proxy);}else{dd.set('dragNode',tar);}
9 dd._prep();dd.fire('drag:mouseDown',{ev:e});}},_onMouseEnter:function(e){this._shimState=Y.DD.DDM._noShim;Y.DD.DDM._noShim=true;},_onMouseLeave:function(e){Y.DD.DDM._noShim=this._shimState;},initializer:function(cfg){this._handles=[];var conf=Y.clone(this.get('dragConfig')||{}),cont=this.get(CONT);conf.node=_tmpNode.cloneNode(true);conf.bubbleTargets=this;if(this.get('handles')){conf.handles=this.get('handles');}
10 this.dd=new Y.DD.Drag(conf);this.dd.after('drag:end',Y.bind(this._afterDragEnd,this));this.dd.on('dragNodeChange',Y.bind(this._onNodeChange,this));this.dd.after('drag:mouseup',function(){this._unprep();});this._handles.push(Y.delegate(Y.DD.Drag.START_EVENT,Y.bind(this._delMouseDown,this),cont,this.get(NODES)));this._handles.push(Y.on('mouseenter',Y.bind(this._onMouseEnter,this),cont));this._handles.push(Y.on('mouseleave',Y.bind(this._onMouseLeave,this),cont));Y.later(50,this,this.syncTargets);Y.DD.DDM.regDelegate(this);},syncTargets:function(){if(!Y.Plugin.Drop||this.get('destroyed')){return;}
11 var items,groups,config;if(this.get('target')){items=Y.one(this.get(CONT)).all(this.get(NODES));groups=this.dd.get('groups');config=this.get('dragConfig');if(config&&'groups'in config){groups=config.groups;}
12 items.each(function(i){this.createDrop(i,groups);},this);}
13 return this;},createDrop:function(node,groups){var config={useShim:false,bubbleTargets:this};if(!node.drop){node.plug(Y.Plugin.Drop,config);}
14 node.drop.set('groups',groups);return node;},destructor:function(){if(this.dd){this.dd.destroy();}
15 if(Y.Plugin.Drop){var targets=Y.one(this.get(CONT)).all(this.get(NODES));targets.unplug(Y.Plugin.Drop);}
16 Y.each(this._handles,function(v){v.detach();});}},{NAME:'delegate',ATTRS:{container:{value:'body'},nodes:{value:'.dd-draggable'},invalid:{value:'input, select, button, a, textarea'},lastNode:{value:_tmpNode},currentNode:{value:_tmpNode},dragNode:{value:_tmpNode},over:{value:false},target:{value:false},dragConfig:{value:null},handles:{value:null}}});Y.mix(Y.DD.DDM,{_delegates:[],regDelegate:function(del){this._delegates.push(del);},getDelegate:function(node){var del=null;node=Y.one(node);Y.each(this._delegates,function(v){if(node.test(v.get(CONT))){del=v;}},this);return del;}});Y.namespace('DD');Y.DD.Delegate=Delegate;},'3.3.0',{requires:['dd-drag','event-mouseenter'],skinnable:false,optional:['dd-drop-plugin']});