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/Avatar.js | |
parent | cfad9259a6feacfa8194b1312770ae6db1ecce50 (diff) |
build custom layer of Dojo to speed up loading of tt-rss (refs #293)
Diffstat (limited to 'lib/dojo/dnd/Avatar.js')
-rw-r--r-- | lib/dojo/dnd/Avatar.js | 160 |
1 files changed, 106 insertions, 54 deletions
diff --git a/lib/dojo/dnd/Avatar.js b/lib/dojo/dnd/Avatar.js index 057668026..effd253f3 100644 --- a/lib/dojo/dnd/Avatar.js +++ b/lib/dojo/dnd/Avatar.js @@ -5,60 +5,112 @@ */ -if(!dojo._hasResource["dojo.dnd.Avatar"]){ -dojo._hasResource["dojo.dnd.Avatar"]=true; +if(!dojo._hasResource["dojo.dnd.Avatar"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojo.dnd.Avatar"] = true; dojo.provide("dojo.dnd.Avatar"); + dojo.require("dojo.dnd.common"); -dojo.declare("dojo.dnd.Avatar",null,{constructor:function(_1){ -this.manager=_1; -this.construct(); -},construct:function(){ -this.isA11y=dojo.hasClass(dojo.body(),"dijit_a11y"); -var a=dojo.create("table",{"class":"dojoDndAvatar",style:{position:"absolute",zIndex:"1999",margin:"0px"}}),_2=this.manager.source,_3,b=dojo.create("tbody",null,a),tr=dojo.create("tr",null,b),td=dojo.create("td",null,tr),_4=this.isA11y?dojo.create("span",{id:"a11yIcon",innerHTML:this.manager.copy?"+":"<"},td):null,_5=dojo.create("span",{innerHTML:_2.generateText?this._generateText():""},td),k=Math.min(5,this.manager.nodes.length),i=0; -dojo.attr(tr,{"class":"dojoDndAvatarHeader",style:{opacity:0.9}}); -for(;i<k;++i){ -if(_2.creator){ -_3=_2._normalizedCreator(_2.getItem(this.manager.nodes[i].id).data,"avatar").node; -}else{ -_3=this.manager.nodes[i].cloneNode(true); -if(_3.tagName.toLowerCase()=="tr"){ -var _6=dojo.create("table"),_7=dojo.create("tbody",null,_6); -_7.appendChild(_3); -_3=_6; -} -} -_3.id=""; -tr=dojo.create("tr",null,b); -td=dojo.create("td",null,tr); -td.appendChild(_3); -dojo.attr(tr,{"class":"dojoDndAvatarItem",style:{opacity:(9-i)/10}}); -} -this.node=a; -},destroy:function(){ -dojo.destroy(this.node); -this.node=false; -},update:function(){ -dojo[(this.manager.canDropFlag?"add":"remove")+"Class"](this.node,"dojoDndAvatarCanDrop"); -if(this.isA11y){ -var _8=dojo.byId("a11yIcon"); -var _9="+"; -if(this.manager.canDropFlag&&!this.manager.copy){ -_9="< "; -}else{ -if(!this.manager.canDropFlag&&!this.manager.copy){ -_9="o"; -}else{ -if(!this.manager.canDropFlag){ -_9="x"; -} -} -} -_8.innerHTML=_9; -} -dojo.query(("tr.dojoDndAvatarHeader td span"+(this.isA11y?" span":"")),this.node).forEach(function(_a){ -_a.innerHTML=this._generateText(); -},this); -},_generateText:function(){ -return this.manager.nodes.length.toString(); -}}); + +dojo.declare("dojo.dnd.Avatar", null, { + // summary: + // Object that represents transferred DnD items visually + // manager: Object + // a DnD manager object + + constructor: function(manager){ + this.manager = manager; + this.construct(); + }, + + // methods + construct: function(){ + // summary: + // constructor function; + // it is separate so it can be (dynamically) overwritten in case of need + this.isA11y = dojo.hasClass(dojo.body(),"dijit_a11y"); + var a = dojo.create("table", { + "class": "dojoDndAvatar", + style: { + position: "absolute", + zIndex: "1999", + margin: "0px" + } + }), + source = this.manager.source, node, + b = dojo.create("tbody", null, a), + tr = dojo.create("tr", null, b), + td = dojo.create("td", null, tr), + icon = this.isA11y ? dojo.create("span", { + id : "a11yIcon", + innerHTML : this.manager.copy ? '+' : "<" + }, td) : null, + span = dojo.create("span", { + innerHTML: source.generateText ? this._generateText() : "" + }, td), + k = Math.min(5, this.manager.nodes.length), i = 0; + // we have to set the opacity on IE only after the node is live + dojo.attr(tr, { + "class": "dojoDndAvatarHeader", + style: {opacity: 0.9} + }); + for(; i < k; ++i){ + if(source.creator){ + // create an avatar representation of the node + node = source._normalizedCreator(source.getItem(this.manager.nodes[i].id).data, "avatar").node; + }else{ + // or just clone the node and hope it works + node = this.manager.nodes[i].cloneNode(true); + if(node.tagName.toLowerCase() == "tr"){ + // insert extra table nodes + var table = dojo.create("table"), + tbody = dojo.create("tbody", null, table); + tbody.appendChild(node); + node = table; + } + } + node.id = ""; + tr = dojo.create("tr", null, b); + td = dojo.create("td", null, tr); + td.appendChild(node); + dojo.attr(tr, { + "class": "dojoDndAvatarItem", + style: {opacity: (9 - i) / 10} + }); + } + this.node = a; + }, + destroy: function(){ + // summary: + // destructor for the avatar; called to remove all references so it can be garbage-collected + dojo.destroy(this.node); + this.node = false; + }, + update: function(){ + // summary: + // updates the avatar to reflect the current DnD state + dojo[(this.manager.canDropFlag ? "add" : "remove") + "Class"](this.node, "dojoDndAvatarCanDrop"); + if (this.isA11y){ + var icon = dojo.byId("a11yIcon"); + var text = '+'; // assume canDrop && copy + if (this.manager.canDropFlag && !this.manager.copy) { + text = '< '; // canDrop && move + }else if (!this.manager.canDropFlag && !this.manager.copy) { + text = "o"; //!canDrop && move + }else if(!this.manager.canDropFlag){ + text = 'x'; // !canDrop && copy + } + icon.innerHTML=text; + } + // replace text + dojo.query(("tr.dojoDndAvatarHeader td span" +(this.isA11y ? " span" : "")), this.node).forEach( + function(node){ + node.innerHTML = this._generateText(); + }, this); + }, + _generateText: function(){ + // summary: generates a proper text to reflect copying or moving of items + return this.manager.nodes.length.toString(); + } +}); + } |