mirror of
https://git.tt-rss.org/git/tt-rss.git
synced 2025-12-18 04:01:54 +00:00
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
This commit is contained in:
@@ -5,36 +5,77 @@
|
||||
*/
|
||||
|
||||
|
||||
if(!dojo._hasResource["dojo.dnd.TimedMoveable"]){
|
||||
dojo._hasResource["dojo.dnd.TimedMoveable"]=true;
|
||||
if(!dojo._hasResource["dojo.dnd.TimedMoveable"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
||||
dojo._hasResource["dojo.dnd.TimedMoveable"] = true;
|
||||
dojo.provide("dojo.dnd.TimedMoveable");
|
||||
|
||||
dojo.require("dojo.dnd.Moveable");
|
||||
|
||||
/*=====
|
||||
dojo.declare("dojo.dnd.__TimedMoveableArgs", [dojo.dnd.__MoveableArgs], {
|
||||
// timeout: Number
|
||||
// delay move by this number of ms,
|
||||
// accumulating position changes during the timeout
|
||||
timeout: 0
|
||||
});
|
||||
=====*/
|
||||
|
||||
(function(){
|
||||
var _1=dojo.dnd.Moveable.prototype.onMove;
|
||||
dojo.declare("dojo.dnd.TimedMoveable",dojo.dnd.Moveable,{timeout:40,constructor:function(_2,_3){
|
||||
if(!_3){
|
||||
_3={};
|
||||
}
|
||||
if(_3.timeout&&typeof _3.timeout=="number"&&_3.timeout>=0){
|
||||
this.timeout=_3.timeout;
|
||||
}
|
||||
},markupFactory:function(_4,_5){
|
||||
return new dojo.dnd.TimedMoveable(_5,_4);
|
||||
},onMoveStop:function(_6){
|
||||
if(_6._timer){
|
||||
clearTimeout(_6._timer);
|
||||
_1.call(this,_6,_6._leftTop);
|
||||
}
|
||||
dojo.dnd.Moveable.prototype.onMoveStop.apply(this,arguments);
|
||||
},onMove:function(_7,_8){
|
||||
_7._leftTop=_8;
|
||||
if(!_7._timer){
|
||||
var _9=this;
|
||||
_7._timer=setTimeout(function(){
|
||||
_7._timer=null;
|
||||
_1.call(_9,_7,_7._leftTop);
|
||||
},this.timeout);
|
||||
}
|
||||
}});
|
||||
// precalculate long expressions
|
||||
var oldOnMove = dojo.dnd.Moveable.prototype.onMove;
|
||||
|
||||
dojo.declare("dojo.dnd.TimedMoveable", dojo.dnd.Moveable, {
|
||||
// summary:
|
||||
// A specialized version of Moveable to support an FPS throttling.
|
||||
// This class puts an upper restriction on FPS, which may reduce
|
||||
// the CPU load. The additional parameter "timeout" regulates
|
||||
// the delay before actually moving the moveable object.
|
||||
|
||||
// object attributes (for markup)
|
||||
timeout: 40, // in ms, 40ms corresponds to 25 fps
|
||||
|
||||
constructor: function(node, params){
|
||||
// summary:
|
||||
// an object that makes a node moveable with a timer
|
||||
// node: Node||String
|
||||
// a node (or node's id) to be moved
|
||||
// params: dojo.dnd.__TimedMoveableArgs
|
||||
// object with additional parameters.
|
||||
|
||||
// sanitize parameters
|
||||
if(!params){ params = {}; }
|
||||
if(params.timeout && typeof params.timeout == "number" && params.timeout >= 0){
|
||||
this.timeout = params.timeout;
|
||||
}
|
||||
},
|
||||
|
||||
// markup methods
|
||||
markupFactory: function(params, node){
|
||||
return new dojo.dnd.TimedMoveable(node, params);
|
||||
},
|
||||
|
||||
onMoveStop: function(/* dojo.dnd.Mover */ mover){
|
||||
if(mover._timer){
|
||||
// stop timer
|
||||
clearTimeout(mover._timer)
|
||||
// reflect the last received position
|
||||
oldOnMove.call(this, mover, mover._leftTop)
|
||||
}
|
||||
dojo.dnd.Moveable.prototype.onMoveStop.apply(this, arguments);
|
||||
},
|
||||
onMove: function(/* dojo.dnd.Mover */ mover, /* Object */ leftTop){
|
||||
mover._leftTop = leftTop;
|
||||
if(!mover._timer){
|
||||
var _t = this; // to avoid using dojo.hitch()
|
||||
mover._timer = setTimeout(function(){
|
||||
// we don't have any pending requests
|
||||
mover._timer = null;
|
||||
// reflect the last received position
|
||||
oldOnMove.call(_t, mover, mover._leftTop);
|
||||
}, this.timeout);
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user