?
Path : /home/admin/public_html/old/promice/components/com_linkr/assets/js/ |
Current File : /home/admin/public_html/old/promice/components/com_linkr/assets/js/related.js |
var LinkrRelated={msg:[],setMsg:function(m,r){var ms=false;if($type(m)=='string'&&m.length>0){this.msg[this.msg.length]=m;ms=m}else if($type(m)=='array'&&m.length>0){this.msg.merge(m);ms=m.join('; ')}if(ms)Linkr.setError('[LinkrRelated: message] '+ms);return r},display:function(c,e){var h=new Element('div');this.setMsg(Linkr.getAllErrors());Linkr.insertMsgDiv(this.msg,h);this.msg=[];Linkr.htmlContent(h,c,false);if(['element','string'].contains($type(e))){h.injectInside($(e).empty())}else{Linkr.htmlLayout(this._('RELATED_ARTICLES'),h)}},landing:function(){Linkr.delayIdleDiv('layout',this.home.bind(this))},home:function(a){Linkr.setReturnPage(['LinkrRelated','home']);if(this.isPluginInstalled===false)return this.display(this._('NOTICE_INSTALL'));if(this.loadedByDefault===true)this.setMsg(this._('NOTICE_RELATED'));var c=new Element('div').setStyle('text-align','center');new Element('span').setHTML(this._('TYPE_IN_KEYWORDS')).injectInside(c);new Element(document.createElement('input'),{id:'words',type:'text',styles:{margin:'0 5px'}}).injectInside(c);new Element(document.createElement('input'),{type:'button',value:this._('PREVIEW'),events:{click:function(e){new Event(e).stop();LinkrRelated.preview()}}}).injectInside(c);new Element('div',{id:'preview'}).injectInside(c);this.display(c);a=this.parseAnchor(a);if(a&&a.keywords&&a.keywords.length>0){$('words').value=a.keywords;this.preview(a)}},preview:function(a){var w=$('words').value;if(w.length<1){alert(this._('TYPE_IN_KEYWORDS'));return $('words').focus()}Linkr.delayIdleDiv('preview',true,70);LinkrRelated._psc.delay(90,LinkrRelated,[w,a])},_psc:function(w,a){var u=Linkr.createRequest('ra');u+='&kw='+Linkr.Base64.Encode(w,true);if(a){u+='&title='+Linkr.Base64.Encode((a.title||''),true);u+='&limit='+(a.limit||'5');u+='&exclude='+(a.exclude||'')}Linkr.json(u,this.displayPreview.bind(this))},displayPreview:function(i){if($type(i)!='object')return this.display('An error occured','preview');if(Linkr.isError(i))return this.display('Error: '+i.msg,'preview');if($type(i.articles)=='string')return this.display(i.articles,'preview');if($type(i.articles)!='array')return this.display('An error occured','preview');Linkr.delayDisplay('preview',70,[this,'_dpsc'],i)},_dpsc:function(i){var c=[];var ls=[];ls.include(['trs',this._('RL_CONFIG_TITLE')]);ls.include(['tal',this._('RL_CONFIG_SHOW_ALL')]);ls.include([false,this._('RL_CONFIG_UPDATE'),[this,'update']]);ls.include([false,this._('GET_REL'),[this,'insert']]);var tb=Linkr.htmlTBLinks(ls);c.include(tb);var cfg=Linkr.htmlConfig('',[['title',this._('TITLE'),Linkr.UTF8.Decode(i.title)],['limit',this._('RL_CONFIG_LIMIT'),i.limit.toInt()]],this._('RL_CONFIG_TITLE'));c.include(cfg);var li=new Element('div',{id:'articles',styles:{padding:5,'margin-bottom':5,'background-color':'#eeeeee'}});var chk=new Element(document.createElement('input'),{type:'checkbox','class':'rl-exclude-check',styles:{border:'none'}});new Element('div',{styles:{padding:'0 30px','text-align':'center','font-weight':'bold'}}).setHTML(this._('NOTICE_RELATED_RANDOM')).injectInside(li);var fa=[];i.articles.each(function(a){var ti=new Element('a',{href:'javascript:void(0)',title:Linkr.UTF8.Decode(a.title),styles:{'padding-left':5},events:{click:function(e){$(a.id).checked=!$(a.id).checked}}}).setHTML(Linkr.UTF8.Decode(a.stitle));var cb=chk.clone().setProperty('id',a.id);var el=new Element('div',{styles:{padding:5,width:275,'float':'left','text-align':'left'}});if(i.exclude.contains(a.id.toInt()))cb.checked=true;else fa.include(a);cb.injectInside(el);ti.injectInside(el);el.injectInside(li)});new Element('div',{styles:{clear:'both'}}).injectInside(li);c.include(li);var pw=new Element('div');new Element('div',{styles:{'letter-spacing':5,'font-weight':'bold','background-color':'#dddddd'}}).setHTML(this._('PREVIEW')).injectInside(pw);var pre=new Element('div',{styles:{padding:5,'text-align':'left',border:'1px solid #dddddd','background-color':'#f9f9f9'}}).injectInside(pw);new Element('div',{styles:{'font-weight':'bold','text-align':'center'}}).setHTML(Linkr.UTF8.Decode(i.title)).injectInside(pre);var ul=new Element('ul').injectInside(pre);var limit=Math.max(1,Math.min(i.limit,fa.length-1));if(fa.length>0){for(n=0;n<limit;n++){var li=new Element('li').injectInside(ul);var ti=Linkr.UTF8.Decode(fa[n].title);new Element('a',{href:'javascript:void(0)'}).setHTML(ti).injectInside(li)}}ul.injectInside(pre);c.include(pw);this.display(c,'preview');Linkr.createToggleLink('settings','trs');Linkr.createToggleLink('articles','tal');if(window.ie&&i.exclude.length>0){i.exclude.each(function(id){var el=document.getElementById(id);if($type(el)=='element'){el.checked=true}})}},update:function(){var w=$('words').value||'';if(w.length<1){alert(this._('TYPE_IN_KEYWORDS'));return $('words').focus()}var l=$('limit').value||5;var t=$('title').value||'';var x=this.getExcludeList();Linkr.delayIdleDiv('preview',true,70);LinkrRelated._usc.delay(90,LinkrRelated,[w,l,t,x])},_usc:function(w,l,t,x){var u=Linkr.createRequest('ra')+'&kw='+Linkr.Base64.Encode(w,true)+'&limit='+l.toInt()+'&title='+Linkr.Base64.Encode(t,true);if(x)u+='&exclude='+x.join(',');Linkr.json(u,this.displayPreview.bind(this))},getExcludeList:function(){var l=[];$$('.rl-exclude-check').each(function(el){if(el.checked==true)l.include(el.getProperty('id'))});return l.length>0?l:false},insert:function(){var w=$('words').value||'';if(w.length<1){alert(this._('TYPE_IN_KEYWORDS'));return $('words').focus()}w=Linkr.urlencode(Linkr.UTF8.Encode(w));var a='{linkr:related;keywords:'+w;var x=this.getExcludeList();if(x)a+=';exclude:'+x.join(',');var l=$('limit').value.toInt();if(l>0)a+=';limit:'+l;var t=$('title').value;if(t.length)a+=';title:'+Linkr.urlencode(Linkr.UTF8.Encode(t));var r=(Linkr.linkrAnchor==true);return r?Linkr.insert(a+'}'):Linkr.insertAtEnd(a+'}')},parseAnchor:function(an){if($type(an)!='string'||!an.contains('{linkr:related;'))return false;var a={};an=an.substr(an.indexOf('{')+1);an=an.substr(0,an.lastIndexOf('}'));p=an.split(';');p.each(function(kv){if(kv.indexOf(':')>0){var k=kv.substr(0,kv.indexOf(':'));var v=kv.substr(kv.indexOf(':')+1);v=Linkr.UTF8.Decode(Linkr.urldecode(v))}else{var k=kv;var v=true}a[k]=v});a.anchor=an;return a},_:function(t,a){return Linkr.getL18N(t,a)},dump:function(a){var dump=Linkr.dump(a,false,true);dump=dump.replace(/\n/g,'<br/>');dump=dump.replace(/\s/g,' ');this.display(dump);return false}};