root / trunk / web / dojo / dojox / widget / FeedPortlet.js @ 12
History | View | Annotate | Download (6.73 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.widget.FeedPortlet"]){ |
| 9 |
dojo._hasResource["dojox.widget.FeedPortlet"]=true; |
| 10 |
dojo.provide("dojox.widget.FeedPortlet");
|
| 11 |
dojo.require("dojox.widget.Portlet");
|
| 12 |
dojo.require("dijit.Tooltip");
|
| 13 |
dojo.require("dijit.form.TextBox");
|
| 14 |
dojo.require("dijit.form.Button");
|
| 15 |
dojo.require("dojox.data.GoogleFeedStore");
|
| 16 |
dojo.declare("dojox.widget.FeedPortlet",dojox.widget.Portlet,{local:false,maxResults:5,url:"",openNew:true,showFeedTitle:true,postCreate:function(){ |
| 17 |
this.inherited(arguments); |
| 18 |
if(this.local&&!dojox.data.AtomReadStore){ |
| 19 |
throw Error(this.declaredClass+": To use local feeds, you must include dojox.data.AtomReadStore on the page."); |
| 20 |
} |
| 21 |
},onFeedError:function(){ |
| 22 |
this.containerNode.innerHTML="Error accessing the feed."; |
| 23 |
},addChild:function(_1){ |
| 24 |
this.inherited(arguments); |
| 25 |
var _2=_1.attr("feedPortletUrl"); |
| 26 |
if(_2){
|
| 27 |
this.set("url",_2); |
| 28 |
} |
| 29 |
},_getTitle:function(_3){ |
| 30 |
var t=this.store.getValue(_3,"title"); |
| 31 |
return this.local?t.text:t; |
| 32 |
},_getLink:function(_4){ |
| 33 |
var l=this.store.getValue(_4,"link"); |
| 34 |
return this.local?l.href:l; |
| 35 |
},_getContent:function(_5){ |
| 36 |
var c=this.store.getValue(_5,"summary"); |
| 37 |
if(!c){
|
| 38 |
return null; |
| 39 |
} |
| 40 |
if(this.local){ |
| 41 |
c=c.text; |
| 42 |
} |
| 43 |
c=c.split("<script").join("<!--").split("</script>").join("-->"); |
| 44 |
c=c.split("<iframe").join("<!--").split("</iframe>").join("-->"); |
| 45 |
return c;
|
| 46 |
},_setUrlAttr:function(_6){ |
| 47 |
this.url=_6;
|
| 48 |
if(this._started){ |
| 49 |
this.load();
|
| 50 |
} |
| 51 |
},startup:function(){ |
| 52 |
if(this.started||this._started){ |
| 53 |
return;
|
| 54 |
} |
| 55 |
this.inherited(arguments); |
| 56 |
if(!this.url||this.url==""){ |
| 57 |
throw new Error(this.id+": A URL must be specified for the feed portlet"); |
| 58 |
} |
| 59 |
if(this.url&&this.url!=""){ |
| 60 |
this.load();
|
| 61 |
} |
| 62 |
},load:function(){ |
| 63 |
if(this._resultList){ |
| 64 |
dojo.destroy(this._resultList);
|
| 65 |
} |
| 66 |
var _7,_8;
|
| 67 |
if(this.local){ |
| 68 |
_7=new dojox.data.AtomReadStore({url:this.url}); |
| 69 |
_8={};
|
| 70 |
}else{
|
| 71 |
_7=new dojox.data.GoogleFeedStore();
|
| 72 |
_8={url:this.url};
|
| 73 |
} |
| 74 |
var _9={query:_8,count:this.maxResults,onComplete:dojo.hitch(this,function(_a){ |
| 75 |
if(this.showFeedTitle&&_7.getFeedValue){ |
| 76 |
var _b=this.store.getFeedValue("title"); |
| 77 |
if(_b){
|
| 78 |
this.set("title",_b.text?_b.text:_b); |
| 79 |
} |
| 80 |
} |
| 81 |
this.generateResults(_a);
|
| 82 |
}),onError:dojo.hitch(this,"onFeedError")}; |
| 83 |
this.store=_7;
|
| 84 |
_7.fetch(_9); |
| 85 |
},generateResults:function(_c){ |
| 86 |
var _d=this.store; |
| 87 |
var _e;
|
| 88 |
var ul=(this._resultList=dojo.create("ul",{"class":"dojoxFeedPortletList"},this.containerNode)); |
| 89 |
dojo.forEach(_c,dojo.hitch(this,function(_f){ |
| 90 |
var li=dojo.create("li",{innerHTML:"<a href=\""+this._getLink(_f)+"\""+(this.openNew?" target=\"_blank\"":"")+">"+this._getTitle(_f)+"</a>"},ul); |
| 91 |
dojo.connect(li,"onmouseover",dojo.hitch(this,function(evt){ |
| 92 |
if(_e){
|
| 93 |
clearTimeout(_e); |
| 94 |
} |
| 95 |
_e=setTimeout(dojo.hitch(this,function(){ |
| 96 |
_e=null;
|
| 97 |
var _10=this._getContent(_f); |
| 98 |
if(!_10){
|
| 99 |
return;
|
| 100 |
} |
| 101 |
var _11="<div class=\"dojoxFeedPortletPreview\">"+_10+"</div>"; |
| 102 |
dojo.query("li",ul).forEach(function(_12){ |
| 103 |
if(_12!=evt.target){
|
| 104 |
dijit.hideTooltip(_12); |
| 105 |
} |
| 106 |
}); |
| 107 |
dijit.showTooltip(_11,li.firstChild,!this.isLeftToRight());
|
| 108 |
}),500);
|
| 109 |
})); |
| 110 |
dojo.connect(li,"onmouseout",function(){ |
| 111 |
if(_e){
|
| 112 |
clearTimeout(_e); |
| 113 |
_e=null;
|
| 114 |
} |
| 115 |
dijit.hideTooltip(li.firstChild); |
| 116 |
}); |
| 117 |
})); |
| 118 |
this.resize();
|
| 119 |
}}); |
| 120 |
dojo.declare("dojox.widget.ExpandableFeedPortlet",dojox.widget.FeedPortlet,{onlyOpenOne:false,generateResults:function(_13){ |
| 121 |
var _14=this.store; |
| 122 |
var _15="dojoxPortletToggleIcon"; |
| 123 |
var _16="dojoxPortletItemCollapsed"; |
| 124 |
var _17="dojoxPortletItemOpen"; |
| 125 |
var _18;
|
| 126 |
var ul=(this._resultList=dojo.create("ul",{"class":"dojoxFeedPortletExpandableList"},this.containerNode)); |
| 127 |
dojo.forEach(_13,dojo.hitch(this,dojo.hitch(this,function(_19){ |
| 128 |
var li=dojo.create("li",{"class":_16},ul); |
| 129 |
var _1a=dojo.create("div",{style:"width: 100%;"},li); |
| 130 |
var _1b=dojo.create("div",{"class":"dojoxPortletItemSummary",innerHTML:this._getContent(_19)},li); |
| 131 |
dojo.create("span",{"class":_15,innerHTML:"<img src='"+dojo.config.baseUrl+"/resources/blank.gif'>"},_1a); |
| 132 |
var a=dojo.create("a",{href:this._getLink(_19),innerHTML:this._getTitle(_19)},_1a); |
| 133 |
if(this.openNew){ |
| 134 |
dojo.attr(a,"target","_blank"); |
| 135 |
} |
| 136 |
}))); |
| 137 |
dojo.connect(ul,"onclick",dojo.hitch(this,function(evt){ |
| 138 |
if(dojo.hasClass(evt.target,_15)||dojo.hasClass(evt.target.parentNode,_15)){
|
| 139 |
dojo.stopEvent(evt); |
| 140 |
var li=evt.target.parentNode;
|
| 141 |
while(li.tagName!="LI"){ |
| 142 |
li=li.parentNode; |
| 143 |
} |
| 144 |
if(this.onlyOpenOne){ |
| 145 |
dojo.query("li",ul).filter(function(_1c){ |
| 146 |
return _1c!=li;
|
| 147 |
}).removeClass(_17).addClass(_16); |
| 148 |
} |
| 149 |
var _1d=dojo.hasClass(li,_17);
|
| 150 |
dojo.toggleClass(li,_17,!_1d); |
| 151 |
dojo.toggleClass(li,_16,_1d); |
| 152 |
} |
| 153 |
})); |
| 154 |
}}); |
| 155 |
dojo.declare("dojox.widget.PortletFeedSettings",dojox.widget.PortletSettings,{"class":"dojoxPortletFeedSettings",urls:null,selectedIndex:0,buildRendering:function(){ |
| 156 |
if(this.urls&&this.urls.length>0){ |
| 157 |
var s=dojo.create("select"); |
| 158 |
if(this.srcNodeRef){ |
| 159 |
dojo.place(s,this.srcNodeRef,"before"); |
| 160 |
dojo.destroy(this.srcNodeRef);
|
| 161 |
} |
| 162 |
this.srcNodeRef=s;
|
| 163 |
dojo.forEach(this.urls,function(url){ |
| 164 |
dojo.create("option",{value:url.url||url,innerHTML:url.label||url},s); |
| 165 |
}); |
| 166 |
} |
| 167 |
if(this.srcNodeRef.tagName=="SELECT"){ |
| 168 |
this.text=this.srcNodeRef; |
| 169 |
var div=dojo.create("div",{},this.srcNodeRef,"before"); |
| 170 |
div.appendChild(this.text);
|
| 171 |
this.srcNodeRef=div;
|
| 172 |
dojo.query("option",this.text).filter("return !item.value;").forEach("item.value = item.innerHTML"); |
| 173 |
if(!this.text.value){ |
| 174 |
dojo.attr(s||this.text,"value",this.text.options[this.selectedIndex].value); |
| 175 |
} |
| 176 |
} |
| 177 |
this.inherited(arguments); |
| 178 |
},postCreate:function(){ |
| 179 |
if(!this.text){ |
| 180 |
var _1e=this.text=new dijit.form.TextBox({}); |
| 181 |
dojo.create("span",{innerHTML:"Choose Url: "},this.domNode); |
| 182 |
this.addChild(_1e);
|
| 183 |
} |
| 184 |
this.addChild(new dijit.form.Button({label:"Load",onClick:dojo.hitch(this,function(){ |
| 185 |
this.portlet.attr("url",(this.text.tagName=="SELECT")?this.text.value:this.text.attr("value")); |
| 186 |
if(this.text.tagName=="SELECT"){ |
| 187 |
dojo.some(this.text.options,dojo.hitch(this,function(opt,idx){ |
| 188 |
if(opt.selected){
|
| 189 |
this.set("selectedIndex",idx); |
| 190 |
return true; |
| 191 |
} |
| 192 |
return false; |
| 193 |
})); |
| 194 |
} |
| 195 |
this.toggle();
|
| 196 |
})})); |
| 197 |
this.addChild(new dijit.form.Button({label:"Cancel",onClick:dojo.hitch(this,"toggle")})); |
| 198 |
this.inherited(arguments); |
| 199 |
},startup:function(){ |
| 200 |
if(this._started){ |
| 201 |
return;
|
| 202 |
} |
| 203 |
this.inherited(arguments); |
| 204 |
if(!this.portlet){ |
| 205 |
throw Error(this.declaredClass+": A PortletFeedSettings widget cannot exist without a Portlet."); |
| 206 |
} |
| 207 |
if(this.text.tagName=="SELECT"){ |
| 208 |
dojo.forEach(this.text.options,dojo.hitch(this,function(opt,_1f){ |
| 209 |
dojo.attr(opt,"selected",_1f==this.selectedIndex); |
| 210 |
})); |
| 211 |
} |
| 212 |
var url=this.portlet.attr("url"); |
| 213 |
if(url){
|
| 214 |
if(this.text.tagName=="SELECT"){ |
| 215 |
if(!this.urls&&dojo.query("option[value='"+url+"']",this.text).length<1){ |
| 216 |
dojo.place(dojo.create("option",{value:url,innerHTML:url,selected:"true"}),this.text,"first"); |
| 217 |
} |
| 218 |
}else{
|
| 219 |
this.text.attr("value",url); |
| 220 |
} |
| 221 |
}else{
|
| 222 |
this.portlet.attr("url",this.get("feedPortletUrl")); |
| 223 |
} |
| 224 |
},_getFeedPortletUrlAttr:function(){ |
| 225 |
return this.text.value; |
| 226 |
}}); |
| 227 |
} |