diff options
author | Andrew Dolgov <[email protected]> | 2011-03-04 19:02:28 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2011-03-04 19:02:59 +0300 |
commit | a089699c8915636ba4f158d77dba9b012bc93208 (patch) | |
tree | b2d7d051f1f55d44a6be07d3ee137e5a7ccfcefb /lib/dojo/dnd/move.js | |
parent | cfad9259a6feacfa8194b1312770ae6db1ecce50 (diff) |
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
Diffstat (limited to 'lib/dojo/dnd/move.js')
-rw-r--r-- | lib/dojo/dnd/move.js | 351 |
1 files changed, 240 insertions, 111 deletions
diff --git a/lib/dojo/dnd/move.js b/lib/dojo/dnd/move.js index af7cd98dc..f2abc1b41 100644 --- a/lib/dojo/dnd/move.js +++ b/lib/dojo/dnd/move.js @@ -5,121 +5,250 @@ */ -if(!dojo._hasResource["dojo.dnd.move"]){ -dojo._hasResource["dojo.dnd.move"]=true; +if(!dojo._hasResource["dojo.dnd.move"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojo.dnd.move"] = true; dojo.provide("dojo.dnd.move"); + dojo.require("dojo.dnd.Mover"); dojo.require("dojo.dnd.Moveable"); -dojo.declare("dojo.dnd.move.constrainedMoveable",dojo.dnd.Moveable,{constraints:function(){ -},within:false,markupFactory:function(_1,_2){ -return new dojo.dnd.move.constrainedMoveable(_2,_1); -},constructor:function(_3,_4){ -if(!_4){ -_4={}; -} -this.constraints=_4.constraints; -this.within=_4.within; -},onFirstMove:function(_5){ -var c=this.constraintBox=this.constraints.call(this,_5); -c.r=c.l+c.w; -c.b=c.t+c.h; -if(this.within){ -var mb=dojo.marginBox(_5.node); -c.r-=mb.w; -c.b-=mb.h; -} -},onMove:function(_6,_7){ -var c=this.constraintBox,s=_6.node.style; -s.left=(_7.l<c.l?c.l:c.r<_7.l?c.r:_7.l)+"px"; -s.top=(_7.t<c.t?c.t:c.b<_7.t?c.b:_7.t)+"px"; -}}); -dojo.declare("dojo.dnd.move.boxConstrainedMoveable",dojo.dnd.move.constrainedMoveable,{box:{},markupFactory:function(_8,_9){ -return new dojo.dnd.move.boxConstrainedMoveable(_9,_8); -},constructor:function(_a,_b){ -var _c=_b&&_b.box; -this.constraints=function(){ -return _c; -}; -}}); -dojo.declare("dojo.dnd.move.parentConstrainedMoveable",dojo.dnd.move.constrainedMoveable,{area:"content",markupFactory:function(_d,_e){ -return new dojo.dnd.move.parentConstrainedMoveable(_e,_d); -},constructor:function(_f,_10){ -var _11=_10&&_10.area; -this.constraints=function(){ -var n=this.node.parentNode,s=dojo.getComputedStyle(n),mb=dojo._getMarginBox(n,s); -if(_11=="margin"){ -return mb; -} -var t=dojo._getMarginExtents(n,s); -mb.l+=t.l,mb.t+=t.t,mb.w-=t.w,mb.h-=t.h; -if(_11=="border"){ -return mb; -} -t=dojo._getBorderExtents(n,s); -mb.l+=t.l,mb.t+=t.t,mb.w-=t.w,mb.h-=t.h; -if(_11=="padding"){ -return mb; -} -t=dojo._getPadExtents(n,s); -mb.l+=t.l,mb.t+=t.t,mb.w-=t.w,mb.h-=t.h; -return mb; -}; -}}); -dojo.dnd.move.constrainedMover=function(fun,_12){ -dojo.deprecated("dojo.dnd.move.constrainedMover, use dojo.dnd.move.constrainedMoveable instead"); -var _13=function(_14,e,_15){ -dojo.dnd.Mover.call(this,_14,e,_15); -}; -dojo.extend(_13,dojo.dnd.Mover.prototype); -dojo.extend(_13,{onMouseMove:function(e){ -dojo.dnd.autoScroll(e); -var m=this.marginBox,c=this.constraintBox,l=m.l+e.pageX,t=m.t+e.pageY; -l=l<c.l?c.l:c.r<l?c.r:l; -t=t<c.t?c.t:c.b<t?c.b:t; -this.host.onMove(this,{l:l,t:t}); -},onFirstMove:function(){ -dojo.dnd.Mover.prototype.onFirstMove.call(this); -var c=this.constraintBox=fun.call(this); -c.r=c.l+c.w; -c.b=c.t+c.h; -if(_12){ -var mb=dojo.marginBox(this.node); -c.r-=mb.w; -c.b-=mb.h; -} -}}); -return _13; -}; -dojo.dnd.move.boxConstrainedMover=function(box,_16){ -dojo.deprecated("dojo.dnd.move.boxConstrainedMover, use dojo.dnd.move.boxConstrainedMoveable instead"); -return dojo.dnd.move.constrainedMover(function(){ -return box; -},_16); + +/*===== +dojo.declare("dojo.dnd.move.__constrainedMoveableArgs", [dojo.dnd.__MoveableArgs], { + // constraints: Function + // Calculates a constraint box. + // It is called in a context of the moveable object. + constraints: function(){}, + + // within: Boolean + // restrict move within boundaries. + within: false +}); +=====*/ + +dojo.declare("dojo.dnd.move.constrainedMoveable", dojo.dnd.Moveable, { + // object attributes (for markup) + constraints: function(){}, + within: false, + + // markup methods + markupFactory: function(params, node){ + return new dojo.dnd.move.constrainedMoveable(node, params); + }, + + constructor: function(node, params){ + // summary: + // an object that makes a node moveable + // node: Node + // a node (or node's id) to be moved + // params: dojo.dnd.move.__constrainedMoveableArgs? + // an optional object with additional parameters; + // the rest is passed to the base class + if(!params){ params = {}; } + this.constraints = params.constraints; + this.within = params.within; + }, + onFirstMove: function(/* dojo.dnd.Mover */ mover){ + // summary: + // called during the very first move notification; + // can be used to initialize coordinates, can be overwritten. + var c = this.constraintBox = this.constraints.call(this, mover); + c.r = c.l + c.w; + c.b = c.t + c.h; + if(this.within){ + var mb = dojo.marginBox(mover.node); + c.r -= mb.w; + c.b -= mb.h; + } + }, + onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){ + // summary: + // called during every move notification; + // should actually move the node; can be overwritten. + var c = this.constraintBox, s = mover.node.style; + s.left = (leftTop.l < c.l ? c.l : c.r < leftTop.l ? c.r : leftTop.l) + "px"; + s.top = (leftTop.t < c.t ? c.t : c.b < leftTop.t ? c.b : leftTop.t) + "px"; + } +}); + +/*===== +dojo.declare("dojo.dnd.move.__boxConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], { + // box: Object + // a constraint box + box: {} +}); +=====*/ + +dojo.declare("dojo.dnd.move.boxConstrainedMoveable", dojo.dnd.move.constrainedMoveable, { + // box: + // object attributes (for markup) + box: {}, + + // markup methods + markupFactory: function(params, node){ + return new dojo.dnd.move.boxConstrainedMoveable(node, params); + }, + + constructor: function(node, params){ + // summary: + // an object, which makes a node moveable + // node: Node + // a node (or node's id) to be moved + // params: dojo.dnd.move.__boxConstrainedMoveableArgs? + // an optional object with parameters + var box = params && params.box; + this.constraints = function(){ return box; }; + } +}); + +/*===== +dojo.declare("dojo.dnd.move.__parentConstrainedMoveableArgs", [dojo.dnd.move.__constrainedMoveableArgs], { + // area: String + // A parent's area to restrict the move. + // Can be "margin", "border", "padding", or "content". + area: "" +}); +=====*/ + +dojo.declare("dojo.dnd.move.parentConstrainedMoveable", dojo.dnd.move.constrainedMoveable, { + // area: + // object attributes (for markup) + area: "content", + + // markup methods + markupFactory: function(params, node){ + return new dojo.dnd.move.parentConstrainedMoveable(node, params); + }, + + constructor: function(node, params){ + // summary: + // an object, which makes a node moveable + // node: Node + // a node (or node's id) to be moved + // params: dojo.dnd.move.__parentConstrainedMoveableArgs? + // an optional object with parameters + var area = params && params.area; + this.constraints = function(){ + var n = this.node.parentNode, + s = dojo.getComputedStyle(n), + mb = dojo._getMarginBox(n, s); + if(area == "margin"){ + return mb; // Object + } + var t = dojo._getMarginExtents(n, s); + mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h; + if(area == "border"){ + return mb; // Object + } + t = dojo._getBorderExtents(n, s); + mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h; + if(area == "padding"){ + return mb; // Object + } + t = dojo._getPadExtents(n, s); + mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h; + return mb; // Object + }; + } +}); + +// WARNING: below are obsolete objects, instead of custom movers use custom moveables (above) + +dojo.dnd.move.constrainedMover = function(fun, within){ + // summary: + // returns a constrained version of dojo.dnd.Mover + // description: + // this function produces n object, which will put a constraint on + // the margin box of dragged object in absolute coordinates + // fun: Function + // called on drag, and returns a constraint box + // within: Boolean + // if true, constraints the whole dragged object withtin the rectangle, + // otherwise the constraint is applied to the left-top corner + + dojo.deprecated("dojo.dnd.move.constrainedMover, use dojo.dnd.move.constrainedMoveable instead"); + var mover = function(node, e, notifier){ + dojo.dnd.Mover.call(this, node, e, notifier); + }; + dojo.extend(mover, dojo.dnd.Mover.prototype); + dojo.extend(mover, { + onMouseMove: function(e){ + // summary: event processor for onmousemove + // e: Event: mouse event + dojo.dnd.autoScroll(e); + var m = this.marginBox, c = this.constraintBox, + l = m.l + e.pageX, t = m.t + e.pageY; + l = l < c.l ? c.l : c.r < l ? c.r : l; + t = t < c.t ? c.t : c.b < t ? c.b : t; + this.host.onMove(this, {l: l, t: t}); + }, + onFirstMove: function(){ + // summary: called once to initialize things; it is meant to be called only once + dojo.dnd.Mover.prototype.onFirstMove.call(this); + var c = this.constraintBox = fun.call(this); + c.r = c.l + c.w; + c.b = c.t + c.h; + if(within){ + var mb = dojo.marginBox(this.node); + c.r -= mb.w; + c.b -= mb.h; + } + } + }); + return mover; // Object }; -dojo.dnd.move.parentConstrainedMover=function(_17,_18){ -dojo.deprecated("dojo.dnd.move.parentConstrainedMover, use dojo.dnd.move.parentConstrainedMoveable instead"); -var fun=function(){ -var n=this.node.parentNode,s=dojo.getComputedStyle(n),mb=dojo._getMarginBox(n,s); -if(_17=="margin"){ -return mb; -} -var t=dojo._getMarginExtents(n,s); -mb.l+=t.l,mb.t+=t.t,mb.w-=t.w,mb.h-=t.h; -if(_17=="border"){ -return mb; -} -t=dojo._getBorderExtents(n,s); -mb.l+=t.l,mb.t+=t.t,mb.w-=t.w,mb.h-=t.h; -if(_17=="padding"){ -return mb; -} -t=dojo._getPadExtents(n,s); -mb.l+=t.l,mb.t+=t.t,mb.w-=t.w,mb.h-=t.h; -return mb; + +dojo.dnd.move.boxConstrainedMover = function(box, within){ + // summary: + // a specialization of dojo.dnd.constrainedMover, which constrains to the specified box + // box: Object + // a constraint box (l, t, w, h) + // within: Boolean + // if true, constraints the whole dragged object withtin the rectangle, + // otherwise the constraint is applied to the left-top corner + + dojo.deprecated("dojo.dnd.move.boxConstrainedMover, use dojo.dnd.move.boxConstrainedMoveable instead"); + return dojo.dnd.move.constrainedMover(function(){ return box; }, within); // Object }; -return dojo.dnd.move.constrainedMover(fun,_18); + +dojo.dnd.move.parentConstrainedMover = function(area, within){ + // summary: + // a specialization of dojo.dnd.constrainedMover, which constrains to the parent node + // area: String + // "margin" to constrain within the parent's margin box, "border" for the border box, + // "padding" for the padding box, and "content" for the content box; "content" is the default value. + // within: Boolean + // if true, constraints the whole dragged object within the rectangle, + // otherwise the constraint is applied to the left-top corner + + dojo.deprecated("dojo.dnd.move.parentConstrainedMover, use dojo.dnd.move.parentConstrainedMoveable instead"); + var fun = function(){ + var n = this.node.parentNode, + s = dojo.getComputedStyle(n), + mb = dojo._getMarginBox(n, s); + if(area == "margin"){ + return mb; // Object + } + var t = dojo._getMarginExtents(n, s); + mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h; + if(area == "border"){ + return mb; // Object + } + t = dojo._getBorderExtents(n, s); + mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h; + if(area == "padding"){ + return mb; // Object + } + t = dojo._getPadExtents(n, s); + mb.l += t.l, mb.t += t.t, mb.w -= t.w, mb.h -= t.h; + return mb; // Object + }; + return dojo.dnd.move.constrainedMover(fun, within); // Object }; -dojo.dnd.constrainedMover=dojo.dnd.move.constrainedMover; -dojo.dnd.boxConstrainedMover=dojo.dnd.move.boxConstrainedMover; -dojo.dnd.parentConstrainedMover=dojo.dnd.move.parentConstrainedMover; + +// patching functions one level up for compatibility + +dojo.dnd.constrainedMover = dojo.dnd.move.constrainedMover; +dojo.dnd.boxConstrainedMover = dojo.dnd.move.boxConstrainedMover; +dojo.dnd.parentConstrainedMover = dojo.dnd.move.parentConstrainedMover; + } |