From ef68436ac04da078ffdcacd7e1f785473a303d45 Mon Sep 17 00:00:00 2001 From: Giulio Cesare Solaroli Date: Sun, 02 Oct 2011 23:56:18 +0000 Subject: First version of the newly restructured repository --- (limited to 'frontend/beta/js/YUI-extensions/dd') diff --git a/frontend/beta/js/YUI-extensions/dd/DragSource.js b/frontend/beta/js/YUI-extensions/dd/DragSource.js new file mode 100644 index 0000000..efee2d6 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/dd/DragSource.js @@ -0,0 +1,218 @@ +// kill drag drop dependency +if(YAHOO.util.DragDrop){ + +YAHOO.ext.dd.DragSource = function(el, config){ + this.el = getEl(el); + this.dragData = {}; + + YAHOO.ext.util.Config.apply(this, config); + + if(!this.proxy){ + this.proxy = new YAHOO.ext.dd.StatusProxy(); + } + this.el.on('mouseup', this.handleMouseUp); + YAHOO.ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, + {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true}); + + this.dragging = false; +}; + +YAHOO.extendX(YAHOO.ext.dd.DragSource, YAHOO.util.DDProxy, { + dropAllowed : 'ydd-drop-ok', + dropNotAllowed : 'ydd-drop-nodrop', + + getDragData : function(e){ + return this.dragData; + }, + + onDragEnter : function(e, id){ + var target = YAHOO.util.DragDropMgr.getDDById(id); + this.cachedTarget = target; + if(this.beforeDragEnter(target, e, id) !== false){ + if(target.isNotifyTarget){ + var status = target.notifyEnter(this, e, this.dragData); + this.proxy.setStatus(status); + }else{ + this.proxy.setStatus(this.dropAllowed); + } + + if(this.afterDragEnter){ + this.afterDragEnter(target, e, id); + } + } + }, + + beforeDragEnter : function(target, e, id){ + return true; + }, + + alignElWithMouse: function() { + YAHOO.ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments); + this.proxy.sync(); + }, + + onDragOver : function(e, id){ + var target = this.cachedTarget || YAHOO.util.DragDropMgr.getDDById(id); + if(this.beforeDragOver(target, e, id) !== false){ + if(target.isNotifyTarget){ + var status = target.notifyOver(this, e, this.dragData); + this.proxy.setStatus(status); + } + + if(this.afterDragOver){ + this.afterDragOver(target, e, id); + } + } + }, + + beforeDragOver : function(target, e, id){ + return true; + }, + + onDragOut : function(e, id){ + var target = this.cachedTarget || YAHOO.util.DragDropMgr.getDDById(id); + if(this.beforeDragOut(target, e, id) !== false){ + if(target.isNotifyTarget){ + target.notifyOut(this, e, this.dragData); + } + this.proxy.reset(); + if(this.afterDragOut){ + this.afterDragOut(target, e, id); + } + } + this.cachedTarget = null; + }, + + beforeDragOut : function(target, e, id){ + return true; + }, + + + onDragDrop : function(e, id){ + var target = this.cachedTarget || YAHOO.util.DragDropMgr.getDDById(id); + if(this.beforeDragDrop(target, e, id) !== false){ + if(target.isNotifyTarget){ + if(target.notifyDrop(this, e, this.dragData)){ // valid drop? + this.onValidDrop(target, e, id); + }else{ + this.onInvalidDrop(target, e, id); + } + }else{ + this.onValidDrop(target, e, id); + } + + if(this.afterDragDrop){ + this.afterDragDrop(target, e, id); + } + } + }, + + beforeDragDrop : function(target, e, id){ + return true; + }, + + onValidDrop : function(target, e, id){ + this.hideProxy(); + }, + + getRepairXY : function(e, data){ + return this.el.getXY(); + }, + + onInvalidDrop : function(target, e, id){ + this.beforeInvalidDrop(target, e, id); + if(this.cachedTarget){ + if(this.cachedTarget.isNotifyTarget){ + this.cachedTarget.notifyOut(this, e, this.dragData); + } + this.cacheTarget = null; + } + this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this); + if(this.afterInvalidDrop){ + this.afterInvalidDrop(e, id); + } + }, + + afterRepair : function(){ + this.el.highlight(this.hlColor || 'c3daf9'); + this.dragging = false; + }, + + beforeInvalidDrop : function(target, e, id){ + return true; + }, + + handleMouseDown : function(e){ + if(this.dragging) { + return; + } + if(YAHOO.ext.QuickTips){ + YAHOO.ext.QuickTips.disable(); + } + var data = this.getDragData(e); + if(data && this.onBeforeDrag(data, e) !== false){ + this.dragData = data; + this.proxy.stop(); + YAHOO.ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments); + } + }, + + handleMouseUp : function(e){ + if(YAHOO.ext.QuickTips){ + YAHOO.ext.QuickTips.enable(); + } + }, + + onBeforeDrag : function(data, e){ + return true; + }, + + startDrag : function(e){ + this.proxy.reset(); + this.dragging = true; + this.proxy.update(''); + this.onInitDrag(e); + this.proxy.show(); + }, + + onInitDrag : function(e){ + var clone = this.el.dom.cloneNode(true); + clone.id = YAHOO.util.Dom.generateId(); // prevent duplicate ids + this.proxy.update(clone); + return true; + }, + + + getProxy : function(){ + return this.proxy; + }, + + hideProxy : function(){ + this.proxy.hide(); + this.proxy.reset(true); + this.dragging = false; + }, + + triggerCacheRefresh : function(){ + YAHOO.util.DDM.refreshCache(this.groups); + }, + + // override to prevent hiding + b4EndDrag: function(e) { + }, + + // override to prevent moving + endDrag : function(e){ + this.onEndDrag(this.dragData, e); + }, + + onEndDrag : function(data, e){ + + }, + + // pin to cursor + autoOffset : function(x, y) { + this.setDelta(-12, -20); + } +}); +} diff --git a/frontend/beta/js/YUI-extensions/dd/DragZone.js b/frontend/beta/js/YUI-extensions/dd/DragZone.js new file mode 100644 index 0000000..7a6edb6 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/dd/DragZone.js @@ -0,0 +1,64 @@ +// kill drag drop dependency +if(YAHOO.util.DragDrop){ +/** + * @class YAHOO.ext.dd.DragZone + * @extends YAHOO.ext.dd.Source + * This class provides a container DD instance that proxies for multiple child node sources.
+ * By default, this class requires that draggable child nodes are registered with + * {@link YAHOO.ext.dd.Registry}. + * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager + * for auto scrolling during drag operations. + * @constructor + * @param {String/HTMLElement/Element} el The container element + * @param {Object} config + */ +YAHOO.ext.dd.DragZone = function(el, config){ + YAHOO.ext.dd.DragZone.superclass.constructor.call(this, el, config); + if(this.containerScroll){ + YAHOO.ext.dd.ScrollManager.register(this.el); + } +}; + +YAHOO.extendX(YAHOO.ext.dd.DragZone, YAHOO.ext.dd.DragSource, { + /** + * Called when a mousedown occurs in this container. Looks in {@link YAHOO.ext.dd.Registry} + * for a valid target to drag based on the mouse down. Override this method + * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned + * object has a "ddel" attribute (with an HTML Element) for other functions to work. + * @param {EventObject} e The mouse down event + * @return {Object} The dragData + */ + getDragData : function(e){ + return YAHOO.ext.dd.Registry.getHandleFromEvent(e); + }, + + /** + * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the + * this.dragData.ddel + * @param {EventObject} e The current event + * @return {Boolean} true to continue the drag, false to cancel + */ + onInitDrag : function(e){ + this.proxy.update(this.dragData.ddel.cloneNode(true)); + return true; + }, + + /** + * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel + */ + afterRepair : function(){ + YAHOO.ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || 'c3daf9'); + this.dragging = false; + }, + + /** + * Called before a repair of an invalid drop to get the XY to animate to. By default returns + * the XY of this.dragData.ddel + * @param {EventObject} e The mouse up event + * @return {Array} The xy location (e.g. [100, 200]) + */ + getRepairXY : function(e){ + return YAHOO.ext.Element.fly(this.dragData.ddel).getXY(); + } +}); +} diff --git a/frontend/beta/js/YUI-extensions/dd/DropTarget.js b/frontend/beta/js/YUI-extensions/dd/DropTarget.js new file mode 100644 index 0000000..30e59cd --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/dd/DropTarget.js @@ -0,0 +1,45 @@ +// kill drag drop dependency +if(YAHOO.util.DragDrop){ + +YAHOO.ext.dd.DropTarget = function(el, config){ + this.el = getEl(el); + + YAHOO.ext.util.Config.apply(this, config); + + if(this.containerScroll){ + YAHOO.ext.dd.ScrollManager.register(this.el); + } + + YAHOO.ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group, + {isTarget: true}); + +}; + +YAHOO.extendX(YAHOO.ext.dd.DropTarget, YAHOO.util.DDTarget, { + isTarget : true, + isNotifyTarget : true, + dropAllowed : 'ydd-drop-ok', + dropNotAllowed : 'ydd-drop-nodrop', + + notifyEnter : function(dd, e, data){ + if(this.overClass){ + this.el.addClass(this.overClass); + } + return this.dropAllowed; + }, + + notifyOver : function(dd, e, data){ + return this.dropAllowed; + }, + + notifyOut : function(dd, e, data){ + if(this.overClass){ + this.el.removeClass(this.overClass); + } + }, + + notifyDrop : function(dd, e, data){ + return false; + } +}); +} diff --git a/frontend/beta/js/YUI-extensions/dd/DropZone.js b/frontend/beta/js/YUI-extensions/dd/DropZone.js new file mode 100644 index 0000000..ce446fb --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/dd/DropZone.js @@ -0,0 +1,81 @@ +// kill drag drop dependency +if(YAHOO.util.DragDrop){ +YAHOO.ext.dd.DropZone = function(el, config){ + YAHOO.ext.dd.DropZone.superclass.constructor.call(this, el, config); +}; + +YAHOO.extendX(YAHOO.ext.dd.DropZone, YAHOO.ext.dd.DropTarget, { + getTargetFromEvent : function(e){ + return YAHOO.ext.dd.Registry.getTargetFromEvent(e); + }, + + onNodeEnter : function(n, dd, e, data){ + + }, + + onNodeOver : function(n, dd, e, data){ + return this.dropAllowed; + }, + + onNodeOut : function(n, dd, e, data){ + + }, + + onNodeDrop : function(n, dd, e, data){ + return false; + }, + + onContainerOver : function(n, dd, e, data){ + return this.dropNotAllowed; + }, + + onContainerDrop : function(n, dd, e, data){ + return false; + }, + + notifyEnter : function(dd, e, data){ + return this.dropNotAllowed; + }, + + notifyOver : function(dd, e, data){ + var n = this.getTargetFromEvent(e); + if(!n){ // not over valid drop target + if(this.lastOverNode){ + this.onNodeOut(this.lastOverNode, dd, e, data); + this.lastOverNode = null; + } + return this.onContainerOver(dd, e, data); + } + if(this.lastOverNode != n){ + if(this.lastOverNode){ + this.onNodeOut(this.lastOverNode, dd, e, data); + } + this.onNodeEnter(n, dd, e, data); + this.lastOverNode = n; + } + return this.onNodeOver(n, dd, e, data); + }, + + notifyOut : function(dd, e, data){ + if(this.lastOverNode){ + this.onNodeOut(this.lastOverNode, dd, e, data); + this.lastOverNode = null; + } + }, + + notifyDrop : function(dd, e, data){ + if(this.lastOverNode){ + this.onNodeOut(this.lastOverNode, dd, e, data); + this.lastOverNode = null; + } + var n = this.getTargetFromEvent(e); + return n ? + this.onNodeDrop(n, dd, e, data) : + this.onContainerDrop(n, dd, e, data); + }, + + triggerCacheRefresh : function(){ + YAHOO.util.DDM.refreshCache(this.groups); + } +}); +} diff --git a/frontend/beta/js/YUI-extensions/dd/Registry.js b/frontend/beta/js/YUI-extensions/dd/Registry.js new file mode 100644 index 0000000..983b874 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/dd/Registry.js @@ -0,0 +1,80 @@ +// kill drag drop dependency +if(YAHOO.util.DragDrop){ + +YAHOO.ext.dd.Registry = function(){ + var elements = {}; + var handles = {}; + var autoIdSeed = 0; + var doc = document; // local reference for IE + + var getId = function(el, autogen){ + if(typeof el == 'string'){ + return el; + } + var id = el.id; + if(!id && autogen !== false){ + id = 'yddgen-' + (++autoIdSeed); + el.id = id; + } + return id; + }; + + return { + register : function(el, data){ + data = data || {}; + if(typeof el == 'string'){ + el = doc.getElementById(el); + } + data.ddel = el; + elements[getId(el)] = data; + if(data.isHandle !== false){ + handles[data.ddel.id] = data; + } + if(data.handles){ + var hs = data.handles; + for(var i = 0, len = hs.length; i < len; i++){ + handles[getId(hs[i])] = data; + } + } + }, + + unregister : function(el){ + var id = getId(el, false); + var data = elements[id]; + if(data){ + delete elements[id]; + if(data.handles){ + var hs = data.handles; + for(var i = 0, len = hs.length; i < len; i++){ + delete handles[getId(hs[i], false)]; + } + } + } + }, + + getHandle : function(id){ + if(typeof id != 'string'){ // must be element? + id = id.id; + } + return handles[id]; + }, + + getHandleFromEvent : function(e){ + var t = YAHOO.util.Event.getTarget(e); + return t ? handles[t.id] : null; + }, + + getTarget : function(id){ + if(typeof id != 'string'){ // must be element? + id = id.id; + } + return elements[id]; + }, + + getTargetFromEvent : function(e){ + var t = YAHOO.util.Event.getTarget(e); + return t ? elements[t.id] || handles[t.id] : null; + } + }; +}(); +} diff --git a/frontend/beta/js/YUI-extensions/dd/ScrollManager.js b/frontend/beta/js/YUI-extensions/dd/ScrollManager.js new file mode 100644 index 0000000..615aadf --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/dd/ScrollManager.js @@ -0,0 +1,171 @@ +// kill dependency issue +if(YAHOO.util.DragDrop){ +/** + * @class YAHOO.ext.dd.ScrollManager + * Provides automatic scrolling of overflow regions in the page during drag operations.

+ * Note: This class uses "Point Mode" and is untested in "Intersect Mode". + * @singleton + */ +YAHOO.ext.dd.ScrollManager = function(){ + var ddm = YAHOO.util.DragDropMgr; + var els = {}; + var dragEl = null; + var proc = {}; + + var onStop = function(e){ + dragEl = null; + clearProc(); + }; + + var triggerRefresh = function(){ + if(ddm.dragCurrent){ + ddm.refreshCache(ddm.dragCurrent.groups); + } + } + + var doScroll = function(){ + if(ddm.dragCurrent){ + var dds = YAHOO.ext.dd.ScrollManager; + if(!dds.animate || !YAHOO.util.Scroll){ + if(proc.el.scroll(proc.dir, dds.increment)){ + triggerRefresh(); + } + }else{ + proc.el.scroll(proc.dir, dds.increment, true, dds.animDuration, triggerRefresh); + } + } + }; + + var clearProc = function(){ + if(proc.id){ + clearInterval(proc.id); + } + proc.id = 0; + proc.el = null; + proc.dir = ''; + }; + + var startProc = function(el, dir){ + clearProc(); + proc.el = el; + proc.dir = dir; + proc.id = setInterval(doScroll, YAHOO.ext.dd.ScrollManager.frequency); + }; + + var onFire = function(e, isDrop){ + if(isDrop || !ddm.dragCurrent){ return; } + var dds = YAHOO.ext.dd.ScrollManager; + if(!dragEl || dragEl != ddm.dragCurrent){ + dragEl = ddm.dragCurrent; + // refresh regions on drag start + dds.refreshCache(); + } + + var xy = YAHOO.util.Event.getXY(e); + var pt = new YAHOO.util.Point(xy[0], xy[1]); + for(var id in els){ + var el = els[id], r = el._region; + if(r.contains(pt) && el.isScrollable()){ + if(r.bottom - pt.y <= dds.thresh){ + if(proc.el != el){ + startProc(el, 'down'); + } + return; + }else if(r.right - pt.x <= dds.thresh){ + if(proc.el != el){ + startProc(el, 'left'); + } + return; + }else if(pt.y - r.top <= dds.thresh){ + if(proc.el != el){ + startProc(el, 'up'); + } + return; + }else if(pt.x - r.left <= dds.thresh){ + if(proc.el != el){ + startProc(el, 'right'); + } + return; + } + } + } + clearProc(); + }; + + ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm); + ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm); + + return { + /** + * Registers new overflow element(s) to auto scroll + * @param {String/HTMLElement/Element/Array} el The id of or the element to be scrolled or an array of either + */ + register : function(el){ + if(el instanceof Array){ + for(var i = 0, len = el.length; i < len; i++) { + this.register(el[i]); + } + }else{ + el = getEl(el); + els[el.id] = el; + } + }, + + /** + * Unregisters overflow element(s) so they are no longer scrolled + * @param {String/HTMLElement/Element/Array} el The id of or the element to be removed or an array of either + */ + unregister : function(el){ + if(el instanceof Array){ + for(var i = 0, len = el.length; i < len; i++) { + this.unregister(el[i]); + } + }else{ + el = getEl(el); + delete els[el.id]; + } + }, + + /** + * The number of pixels from the edge of a container the pointer needs to be to + * trigger scrolling (defaults to 25) + * @type Number + */ + thresh : 25, + + /** + * The number of pixels to scroll in each scroll increment (defaults to 50) + * @type Number + */ + increment : 100, + + /** + * The frequency of scrolls in milliseconds (defaults to 500) + * @type Number + */ + frequency : 500, + + /** + * True to animate the scroll (defaults to true) + * @type Boolean + */ + animate: true, + + /** + * The animation duration in seconds - + * MUST BE less than YAHOO.ext.dd.ScrollManager.frequency! (defaults to .4) + * @type Number + */ + animDuration: .4, + + /** + * Manually trigger a cache refresh. + */ + refreshCache : function(){ + for(var id in els){ + els[id]._region = els[id].getRegion(); + } + } + } +}(); +} diff --git a/frontend/beta/js/YUI-extensions/dd/StatusProxy.js b/frontend/beta/js/YUI-extensions/dd/StatusProxy.js new file mode 100644 index 0000000..97de4d9 --- a/dev/null +++ b/frontend/beta/js/YUI-extensions/dd/StatusProxy.js @@ -0,0 +1,110 @@ +YAHOO.ext.dd.StatusProxy = function(config){ + YAHOO.ext.util.Config.apply(this, config); + this.id = this.id || YAHOO.util.Dom.generateId(); + this.el = new YAHOO.ext.Layer({ + dh: { + id: this.id, tag: 'div', cls: 'ydd-drag-proxy '+this.dropNotAllowed, children: [ + {tag: 'div', cls: 'ydd-drop-icon'}, + {tag: 'div', cls: 'ydd-drag-ghost'} + ] + }, + shadow: !config || config.shadow !== false + }); + /*this.el = YAHOO.ext.DomHelper.insertBefore(document.body.firstChild, { + id: this.id, tag: 'div', cls: 'ydd-drag-proxy '+this.dropNotAllowed, children: [ + {tag: 'div', cls: 'ydd-drop-icon'}, + {tag: 'div', cls: 'ydd-drag-ghost'} + ] + }, true);*/ + this.ghost = getEl(this.el.dom.childNodes[1]); + this.dropStatus = this.dropNotAllowed; +}; + +YAHOO.ext.dd.StatusProxy.prototype = { + dropAllowed : 'ydd-drop-ok', + dropNotAllowed : 'ydd-drop-nodrop', + /** + * Updates the DD visual element to allow/not allow a drop + * @param {String} cssClass The css class for the new drop status indicator image + */ + setStatus : function(cssClass){ + cssClass = cssClass || this.dropNotAllowed; + if(this.dropStatus != cssClass){ + this.el.replaceClass(this.dropStatus, cssClass); + this.dropStatus = cssClass; + } + }, + + reset : function(clearGhost){ + this.el.dom.className = 'ydd-drag-proxy ' + this.dropNotAllowed; + this.dropStatus = this.dropNotAllowed; + if(clearGhost){ + this.ghost.update(''); + } + }, + + update : function(html){ + if(typeof html == 'string'){ + this.ghost.update(html); + }else{ + this.ghost.update(''); + html.style.margin = '0'; + this.ghost.dom.appendChild(html); + } + }, + + getEl : function(){ + return this.el; + }, + + getGhost : function(){ + return this.ghost; + }, + + hide : function(clear){ + this.el.hide(); + if(clear){ + this.reset(true); + } + }, + + stop : function(){ + if(this.anim && this.anim.isAnimated()){ + this.anim.stop(); + } + }, + + show : function(){ + this.el.show(); + }, + + sync : function(){ + this.el.syncLocalXY(); + }, + + repair : function(xy, callback, scope){ + this.callback = callback; + this.scope = scope; + if(xy && this.animRepair !== false && YAHOO.util.Anim){ + this.el.addClass('ydd-drag-repair'); + this.el.hideUnders(true); + if(!this.anim){ + this.anim = new YAHOO.util.Motion(this.el.dom, {}, this.repairDuration || .5, YAHOO.util.Easing.easeOut); + this.anim.onComplete.subscribe(this.afterRepair, this, true); + } + this.anim.attributes = {points: {to:xy}}; + this.anim.animate(); + }else{ + this.afterRepair(); + } + }, + + afterRepair : function(){ + this.hide(true); + if(typeof this.callback == 'function'){ + this.callback.call(this.scope || this); + } + this.callback == null; + this.scope == null; + } +}; -- cgit v0.9.0.2