Committer: atyurin
LJSUP-12132: Port image dialog from the old update.bml pageU trunk/htdocs/js/ck/plugins/livejournal/plugin.js
Modified: trunk/htdocs/js/ck/plugins/livejournal/plugin.js =================================================================== --- trunk/htdocs/js/ck/plugins/livejournal/plugin.js 2012-05-25 08:03:14 UTC (rev 22057) +++ trunk/htdocs/js/ck/plugins/livejournal/plugin.js 2012-05-25 08:23:33 UTC (rev 22058) @@ -1,58 +1,1632 @@ -(function(){function t(d){function f(){var b=this.getAttribute("lj-cmd");c.hasOwnProperty(b)&&(i[b].node=c[b].node,(new CKEDITOR.dom.selection(d.document)).selectElement(i[b].node),s=!0,d.execCommand(b),CKEDITOR.note.hide(!0));return!1}function l(){window.switchedRteOn||CKEDITOR.note.hide(!0);if(a){c=j;j=null;var d="",g;for(g in c)c.hasOwnProperty(g)&&(d+='<div class="noteItem">'+c[g].content+"</div>");e.innerHTML=decodeURIComponent(d);d=e.getElementsByTagName("a");g=0;for(var r=d.length;g<r;g++){var n= -d[g];i.hasOwnProperty(n.getAttribute("lj-cmd"))&&(n.onclick=f)}}else c=null;p(a);b=null}var b,a,c,j,e=document.createElement("lj-note"),h="string"!=typeof document.body.style.opacity,p=function(){function b(){var d=p.shift(),d=(c?d.time/a:-(d.time/a-1)).toFixed(1);p.length||(d=c?1:0);h?e.style.filter=1<=d?null:"progid:DXImageTransform.Microsoft.Alpha(opacity="+100*d+")":e.style.opacity=d;0==d&&e&&e.parentNode&&e.parentNode.removeChild(e)}var a=100,d=60*a/1E3,p=[],c,k=document.getElementById("draft-container")|| -document.body;return function(a){if((c=a)&&e.parentNode)h?e.style.filter=null:e.style.opacity=1;else for(a=1;a<=d;a++){var g=Math.floor(1E3/60)*a;p.push({time:g,timer:setTimeout(b,g)})}k.appendChild(e);e.style.marginTop=-e.offsetHeight/2+"px";e.style.marginLeft=-e.offsetWidth/2+"px"}}();e.className="note-popup";e.onmouseout=function(){(!c||!c.cmd)&&CKEDITOR.note.hide()};e.onmouseover=function(){b&&!a&&(a=1,b=clearTimeout(b))};h?e.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=0)":e.style.opacity= -0;CKEDITOR.note={show:function(d,p){if((p||d!=j)&&window.switchedRteOn)b&&(b=clearTimeout(b)),a=1,j=d,!0===p?l():b=setTimeout(l,1E3)},hide:function(d){a&&(a=0,b&&(b=clearTimeout(b)),e.parentNode&&(!0===d?l():b=setTimeout(l,500)))}}}var l=[{label:top.CKLang.LJLike_button_facebook,id:"facebook",abbr:"fb",html:'<span class="lj-like-item fb">'+top.CKLang.LJLike_button_facebook+"</span>",htmlOpt:'<li class="like-fb"><input type="checkbox" id="like-fb" /><label for="like-fb">'+top.CKLang.LJLike_button_facebook+ -"</label></li>"},{label:top.CKLang.LJLike_button_twitter,id:"twitter",abbr:"tw",html:'<span class="lj-like-item tw">'+top.CKLang.LJLike_button_twitter+"</span>",htmlOpt:'<li class="like-tw"><input type="checkbox" id="like-tw" /><label for="like-tw">'+top.CKLang.LJLike_button_twitter+"</label></li>"},{label:top.CKLang.LJLike_button_google,id:"google",abbr:"go",html:'<span class="lj-like-item go">'+top.CKLang.LJLike_button_google+"</span>",htmlOpt:'<li class="like-go"><input type="checkbox" id="like-go" /><label for="like-go">'+ -top.CKLang.LJLike_button_google+"</label></li>"},{label:top.CKLang.LJLike_button_vkontakte,id:"vkontakte",abbr:"vk",html:'<span class="lj-like-item vk">'+top.CKLang.LJLike_button_vkontakte+"</span>",htmlOpt:window.isSupUser?'<li class="like-vk"><input type="checkbox" id="like-vk" /><label for="like-vk">'+top.CKLang.LJLike_button_vkontakte+"</label></li>":""},{label:top.CKLang.LJLike_button_give,id:"livejournal",abbr:"lj",html:'<span class="lj-like-item lj">'+top.CKLang.LJLike_button_give+"</span>", -htmlOpt:'<li class="like-lj"><input type="checkbox" id="like-lj" /><label for="like-lj">'+top.CKLang.LJLike_button_give+"</label></li>"}],i={LJPollLink:{html:encodeURIComponent(top.CKLang.Poll_PollWizardNotice+'<br /><a href="#" lj-cmd="LJPollLink">'+top.CKLang.Poll_PollWizardNoticeLink+"</a>")},LJLike:{html:encodeURIComponent(top.CKLang.LJLike_WizardNotice+'<br /><a href="#" lj-cmd="LJLike">'+top.CKLang.LJLike_WizardNoticeLink+"</a>")},LJUserLink:{html:encodeURIComponent(top.CKLang.LJUser_WizardNotice+ -'<br /><a href="#" lj-cmd="LJUserLink">'+top.CKLang.LJUser_WizardNoticeLink+"</a>")},LJLink:{html:encodeURIComponent(top.CKLang.LJLink_WizardNotice+'<br /><a href="#" lj-cmd="LJLink">'+top.CKLang.LJLink_WizardNoticeLink+"</a>")},image:{html:encodeURIComponent(top.CKLang.LJImage_WizardNotice+'<br /><a href="#" lj-cmd="image">'+top.CKLang.LJImage_WizardNoticeLink+"</a>")},LJCut:{html:encodeURIComponent(top.CKLang.LJCut_WizardNotice+'<br /><a href="#" lj-cmd="LJCut">'+top.CKLang.LJCut_WizardNoticeLink+ -"</a>")},LJSpoiler:{html:encodeURIComponent(top.CKLang.LJSpoiler_WizardNotice+'<br /><a href="#" lj-cmd="LJSpoiler">'+top.CKLang.LJSpoiler_WizardNoticeLink+"</a>")}},o={},s,f=CKEDITOR.dtd;f.$block["lj-template"]=1;f.$block["lj-raw"]=1;f.$block["lj-cut"]=1;f.$block["lj-spoiler"]=1;f.$block["lj-poll"]=1;f.$block["lj-repost"]=1;f.$block["lj-pq"]=1;f.$block["lj-pi"]=1;f.$nonEditable["lj-template"]=1;f["lj-template"]={};f["lj-map"]={};f["lj-repost"]={};f["lj-raw"]=f.div;f["lj-poll"]={"lj-pq":1};f["lj-pq"]= -{"#":1,"lj-pi":1};f["lj-pi"]={"#":1};f.$block.iframe=f.$inline.iframe;delete f.$inline.iframe;CKEDITOR.tools.extend(f["lj-cut"]={},f.$block);CKEDITOR.tools.extend(f["lj-spoiler"]={},f.$block);CKEDITOR.tools.extend(f["lj-cut"],f.$inline);CKEDITOR.tools.extend(f["lj-spoiler"],f.$inline);CKEDITOR.tools.extend(f.div,f.$block);CKEDITOR.tools.extend(f.$body,f.$block);delete f["lj-cut"]["lj-cut"];CKEDITOR.plugins.add("livejournal",{init:function(d){function f(b){var a=b.data.element||b.data.getTarget(); -for(1!=a.type&&(a=a.getParent());a;){var g=a.getAttribute("lj-cmd");if(i.hasOwnProperty(g)){var c=d.getCommand(g);if(c.state==CKEDITOR.TRISTATE_ON){var n=new CKEDITOR.dom.selection(d.document);i[g].node=a.is("body")?new CKEDITOR.dom.element.get(a.getWindow().$.frameElement):a;n.selectElement(i[g].node);b.data.dialog="";s=!0;c.exec();break}}a=a.getParent()}}function u(a){this.$!=d.document.$&&(this.$.className=(this.frame.getAttribute("lj-class")||"")+" lj-selected","LJPollLink"==this.getAttribute("lj-cmd")&& -this.frame.setStyle("height",this.getDocument().$.body.scrollHeight+"px"),(new CKEDITOR.dom.selection(d.document)).selectElement(this.frame));1==a.data.getKey()&&a.data.preventDefault()}function b(a){if(46==a.data.getKey())for(var a=(new CKEDITOR.dom.selection(d.document)).getRanges(),b=a.length;b--;)a[b].deleteContents()}function a(){var a=this.$.contentWindow.document,d=new CKEDITOR.dom.element.get(a.body);d.on&&(d.on("dblclick",f),d.on("click",u),d.on("keyup",b),"LJPollLink"==this.getAttribute("lj-cmd")&& -this.hasAttribute("style")&&(a.body.className="lj-poll lj-poll-open"));a=new CKEDITOR.dom.element.get(a);a.frame=d.frame=this}function c(){var b=d.document.getElementsByTag("iframe"),c=b.count(),g,e,n,m;for(s=!1;c--;)g=b.getItem(c),e=g.getAttribute("lj-cmd"),n=g.$.contentWindow,n=n.document,m=g.getAttribute("lj-style")||"",g.removeListener("load",a),g.on("load",a),n.open(),n.write('<!DOCTYPE html><html style="'+m+'"><head><link rel="stylesheet" href="'+CKEDITOR.styleText+'" /></head><body scroll="no" class="'+ -(g.getAttribute("lj-class")||"")+'" style="'+m+'" '+(e?'lj-cmd="'+e+'"':"")+">"+decodeURIComponent(g.getAttribute("lj-content")||"")+"</body></html>"),n.close()}function j(a){if(!0===d.onSwitch)delete d.onSwitch;else{var b,g="click"==a.name,c="selectionChange"==a.name||g,e=a.data.element||a.data.getTarget(),m;g&&(1==a.data.getKey()||0==a.data.$.button)&&a.data.preventDefault();1!=e.type&&(e=e.getParent());a=e;if(c){var e=d.document.getElementsByTag("iframe"),k;g&&a.is("iframe")&&(k=a.$.contentWindow.document.body, -k.className=(a.getAttribute("lj-class")||"")+" lj-selected","LJPollLink"==a.getAttribute("lj-cmd")&&a.setStyle("height",k.scrollHeight+"px"));for(var h=0,q=e.count();h<q;h++)g=e.getItem(h),g.$!=a.$&&(k=g.$.contentWindow.document.body,k.className=g.getAttribute("lj-class")||"","LJPollLink"==g.getAttribute("lj-cmd")&&"lj-poll"==k.className&&g.removeAttribute("style"))}do if(e=a.getAttribute("lj-cmd"),!e&&1==a.type&&(g=a.getParent(),a.is("img")&&g.getParent()&&!g.getParent().hasAttribute("lj:user")? -(e="image",a.setAttribute("lj-cmd",e)):a.is("a")&&!g.hasAttribute("lj:user")&&(e="LJLink",a.setAttribute("lj-cmd",e))),e&&i.hasOwnProperty(e))c&&(i[e].node=a,d.getCommand(e).setState(CKEDITOR.TRISTATE_ON)),(b||(b={}))[e]={content:i[e].html,node:a};while(a=a.getParent());if(c)for(m in i)if(i.hasOwnProperty(m)&&(!b||!b.hasOwnProperty(m)))delete i[m].node,d.getCommand(m).setState(CKEDITOR.TRISTATE_OFF);b?CKEDITOR.note.show(b):CKEDITOR.note.hide()}}function e(a,b,g){var c,e=i[b].node;if(e){if(c=prompt(g.title, -e.getAttribute("text")||g.text))c==g.text?e.removeAttribute("text"):e.setAttribute("text",c)}else{if(c=prompt(g.title,g.text)){d.focus();var e=new CKEDITOR.dom.selection(d.document),m=e.getRanges(),k=new CKEDITOR.dom.element("iframe",d.document),h=k.clone();k.setAttribute("lj-cmd",b);k.setAttribute("lj-class",a+" "+a+"-open");k.setAttribute("class",a+"-wrap");k.setAttribute("frameBorder",0);k.setAttribute("allowTransparency","true");c!=g.text&&k.setAttribute("text",c);h.setAttribute("lj-class",a+ -" "+a+"-close");h.setAttribute("class",a+"-wrap");h.setAttribute("frameBorder",0);h.setAttribute("allowTransparency","true");a=m[0];e.lock();b=new CKEDITOR.dom.element("br",d.document);g=b.clone();c=b.clone();var q=new CKEDITOR.dom.documentFragment(d.document);q.append(b.clone());q.append(k);q.append(g);if(!1===a.collapsed)for(var k=0,j=m.length;k<j;k++)q.append(m[k].extractContents());q.append(c);d.insertElement(h);b.clone().insertAfter(h);h.insertBeforeMe(q);a.setStart(g,0);a.setEnd(c,0);e.unlock(); -e.selectRanges(m)}CKEDITOR.note&&CKEDITOR.note.hide(!0)}}(function(){function a(b){return"/>"==b.slice(-2)?b:b.slice(0,-1)+"/>"}function b(a){a=new Poll(a);return'<iframe class="lj-poll-wrap" lj-class="lj-poll" frameborder="0" lj-cmd="LJPollLink" allowTransparency="true" lj-data="'+a.outputLJtags()+'" lj-content="'+a.outputHTML()+'"></iframe>'}function c(a,b,d){return'<iframe class="lj-embed-wrap" lj-class="lj-embed" frameborder="0" allowTransparency="true" lj-data="'+encodeURIComponent(d)+'"'+b+ -"></iframe>"}function e(a,b,d,c){return b+d.replace(/\n/g,"")+c}function h(a,b,d,c){a=b||d||top.CKLang.LJRepost_Value;b=c.replace(/"/g,""");c=b+('<br /><input type="button" value="'+a+'" />').replace(/"/g,""");return'<iframe class="lj-repost-wrap" lj-class="lj-repost" frameborder="0" allowTransparency="true" lj-text="'+b+'" lj-button="'+a+'" lj-content="'+c+'"></iframe>'}d.dataProcessor.toHtml=function(d,k){d=d.replace(/<lj [^>]*?>/gi,a).replace(/<lj-map [^>]*?>/gi,a).replace(/<lj-template[^>]*?>/gi, -a).replace(/(<lj-cut[^>]*?)\/>/gi,"$1>").replace(/<((?!br)[^\s>]+)([^>]*?)\/>/gi,"<$1$2></$1>").replace(/<lj-poll.*?>[\s\S]*?<\/lj-poll>/gi,b).replace(/<lj-repost\s*(?:button\s*=\s*(?:"([^"]*?)")|(?:"([^']*?)"))?.*?>([\s\S]*?)<\/lj-repost>/gi,h).replace(/<lj-embed(.*?)>([\s\S]*?)<\/lj-embed>/gi,c);$("event_format").checked||(d=d.replace(/(<lj-raw.*?>)([\s\S]*?)(<\/lj-raw>)/gi,e),window.switchedRteOn||(d=d.replace(/\n/g,"<br />")));d=CKEDITOR.htmlDataProcessor.prototype.toHtml.call(this,d,k);CKEDITOR.env.ie&& -(d='<xml:namespace ns="livejournal" prefix="lj" />'+d);return d}})();d.dataProcessor.toDataFormat=function(a,b){a=CKEDITOR.htmlDataProcessor.prototype.toDataFormat.call(this,a,b);$("event_format").checked||(a=a.replace(/<br\s*\/>/gi,"\n"));return a.replace(/\t/g," ")};d.dataProcessor.writer.indentationChars="";d.dataProcessor.writer.lineBreakChars="";d.on("selectionChange",j);d.on("doubleclick",f);d.on("afterCommandExec",c);d.on("dialogHide",c);d.on("dataReady",function(){CKEDITOR.note||t(d);CKEDITOR.env.ie&& -(d.document.getBody().on("dragend",c),d.document.getBody().on("paste",function(){setTimeout(c,0)}));d.document.on("click",j);d.document.on("mouseout",CKEDITOR.note.hide);d.document.on("mouseover",j);d.document.getBody().on("keyup",b);c()});(function(){var a=top.Site.siteroot+"/tools/endpoints/ljuser.bml";d.addCommand("LJUserLink",{exec:function(b){var c="",b=new CKEDITOR.dom.selection(b.document),e=i.LJUserLink.node,h;e?(CKEDITOR.note&&CKEDITOR.note.hide(!0),h=i.LJUserLink.node.getElementsByTag("b").getItem(0).getText(), -c=prompt(top.CKLang.UserPrompt,h)):2==b.getType()&&(c=b.getSelectedText());""==c&&(c=prompt(top.CKLang.UserPrompt,c));c&&h!=c&&parent.HTTPReq.getJSON({data:parent.HTTPReq.formEncoded({username:c}),method:"POST",url:a,onData:function(a){var b=c;if(a.error)alert(a.error);else if(a.success){a.ljuser=a.ljuser.replace('<span class="useralias-value">*</span>',"");o[b]=a.ljuser;a=new CKEDITOR.dom.element.createFromHtml(a.ljuser);a.setAttribute("lj-cmd","LJUserLink");e?e.$.parentNode.replaceChild(a.$,e.$): -d.insertElement(a)}}})}});d.ui.addButton("LJUserLink",{label:top.CKLang.LJUser,command:"LJUserLink"})})();window.ljphotoEnabled&&window.ljphotoMigrationStatus===LJ.getConst("LJPHOTO_MIGRATION_NONE")?d.ui.addButton("image",{label:top.CKLang.LJImage_Title,command:"image"}):(d.addCommand("LJImage",{exec:function(){InOb.handleInsertImageBeta("upload")},editorFocus:!1}),d.ui.addButton("image",{label:top.CKLang.LJImage_Title,command:"LJImage"}));d.addCommand("LJLink",{exec:function(a){!s&&this.state==CKEDITOR.TRISTATE_ON? -a.execCommand("unlink"):a.openDialog("link");CKEDITOR.note&&CKEDITOR.note.hide(true)},editorFocus:!1});d.ui.addButton("LJLink",{label:d.lang.link.toolbar,command:"LJLink"});(function(){function a(b){if(b&&b.length&&window.switchedRteOn){var e=new CKEDITOR.dom.element("iframe",d.document);e.setAttribute("lj-data",encodeURIComponent(b));e.setAttribute("lj-class","lj-embed");e.setAttribute("class","lj-embed-wrap");e.setAttribute("frameBorder",0);e.setAttribute("allowTransparency","true");d.insertElement(e); -c()}}d.addCommand("LJEmbedLink",{exec:function(){top.LJ_IPPU.textPrompt(top.CKLang.LJEmbedPromptTitle,top.CKLang.LJEmbedPrompt,a,{width:"350px"})}});d.ui.addButton("LJEmbedLink",{label:top.CKLang.LJEmbed,command:"LJEmbedLink"})})();d.addCommand("LJCut",{exec:function(){e("lj-cut","LJCut",{title:top.CKLang.LJCut_PromptTitle,text:top.CKLang.LJCut_PromptText})},editorFocus:!1});d.ui.addButton("LJCut",{label:top.CKLang.LJCut_Title,command:"LJCut"});d.addCommand("LJSpoiler",{exec:function(){e("lj-spoiler", -"LJSpoiler",{title:top.CKLang.LJSpoiler_PromptTitle,text:top.CKLang.LJSpoiler_PromptText})},editorFocus:!1});d.ui.addButton("LJSpoiler",{label:top.CKLang.LJSpoiler_Title,command:"LJSpoiler"});(function(){function a(b,d){var d=d===void 0||d,c;if(i.LJLike.node)c=(c=b.getAttribute("lj-style"))?c.replace(/text-align:\s*(left|right|center)/i,"$1"):"left";else if(d)c=b.getComputedStyle("text-align");else{for(;!b.hasAttribute||!b.hasAttribute("align")&&!b.getStyle("text-align");){c=b.getParent();if(!c)break; -b=c}c=b.getStyle("text-align")||b.getAttribute("align")||""}c&&(c=c.replace(/-moz-|-webkit-|start|auto/i,""));!c&&d&&(c=b.getComputedStyle("direction")=="rtl"?"right":"left");return c}function b(c){if(!c.editor.readOnly){var e=c.editor.getCommand(this.name),c=c.data.element;e.state=(c.type==1&&c.hasAttribute("lj-cmd")&&c.getAttribute("lj-cmd"))=="LJLike"?a(c,d.config.useComputedState)==this.value?CKEDITOR.TRISTATE_ON:CKEDITOR.TRISTATE_OFF:!c||c.type!=1||c.getName()=="body"||c.getName()=="iframe"? -CKEDITOR.TRISTATE_OFF:a(c,d.config.useComputedState)==this.value?CKEDITOR.TRISTATE_ON:CKEDITOR.TRISTATE_OFF;e.fire("state")}}function c(a,b,d){this.name=b;this.value=d;if(a=a.config.justifyClasses){switch(d){case "left":this.cssClassName=a[0];break;case "center":this.cssClassName=a[1];break;case "right":this.cssClassName=a[2]}this.cssClassRegex=RegExp("(?:^|\\s+)(?:"+a.join("|")+")(?=$|\\s)")}}c.prototype={exec:function(b){var c=b.getSelection(),d=b.config.enterMode;if(c){var e=c.createBookmarks(); -if(i.LJLike.node)i.LJLike.node.setAttribute("lj-style","text-align: "+this.value);else for(var h=c.getRanges(true),g=this.cssClassName,j,f,n=b.config.useComputedState,n=n===void 0||n,r=h.length-1;r>=0;r--){j=h[r];if((f=j.getEnclosedNode())&&f.is("iframe"))return;j=j.createIterator();for(j.enlargeBr=d!=CKEDITOR.ENTER_BR;f=j.getNextParagraph(d==CKEDITOR.ENTER_P?"p":"div");){f.removeAttribute("align");f.removeStyle("text-align");var m=g&&(f.$.className=CKEDITOR.tools.ltrim(f.$.className.replace(this.cssClassRegex, -""))),l=this.state==CKEDITOR.TRISTATE_OFF&&(!n||a(f,true)!=this.value);g?l?f.addClass(g):m||f.removeAttribute("class"):l&&f.setStyle("text-align",this.value)}}b.focus();b.forceNextSelectionCheck();c.selectBookmarks(e)}}};var e=new c(d,"LJJustifyLeft","left"),h=new c(d,"LJJustifyCenter","center"),j=new c(d,"LJJustifyRight","right");d.addCommand("LJJustifyLeft",e);d.addCommand("LJJustifyCenter",h);d.addCommand("LJJustifyRight",j);d.ui.addButton("LJJustifyLeft",{label:d.lang.justify.left,command:"LJJustifyLeft"}); -d.ui.addButton("LJJustifyCenter",{label:d.lang.justify.center,command:"LJJustifyCenter"});d.ui.addButton("LJJustifyRight",{label:d.lang.justify.right,command:"LJJustifyRight"});d.on("selectionChange",CKEDITOR.tools.bind(b,e));d.on("selectionChange",CKEDITOR.tools.bind(b,j));d.on("selectionChange",CKEDITOR.tools.bind(b,h));d.on("dirChanged",function(a){var b=a.editor,c=new CKEDITOR.dom.range(b.document);c.setStartBefore(a.data.node);c.setEndAfter(a.data.node);for(var d=new CKEDITOR.dom.walker(c),e;e= -d.next();)if(e.type==CKEDITOR.NODE_ELEMENT){var g=b.config.justifyClasses;if(!e.equals(a.data.node)&&e.getDirection()){c.setStartAfter(e);d=new CKEDITOR.dom.walker(c)}else{if(g)if(e.hasClass(g[0])){e.removeClass(g[0]);e.addClass(g[2])}else if(e.hasClass(g[2])){e.removeClass(g[2]);e.addClass(g[0])}switch(e.getStyle("text-align")){case "left":e.setStyle("text-align","right");break;case "right":e.setStyle("text-align","left")}}}})})();if(top.canmakepoll){var h;CKEDITOR.dialog.add("LJPollDialog",function(){var a= -0,b,e,j,f=function(){this.removeListener&&this.removeListener("load",f);if(a&&b){h=new Poll(i.LJPollLink.node&&decodeURIComponent(i.LJPollLink.node.getAttribute("lj-data")),e.document,j.document,e.Questions);e.ready(h);j.ready(h);b.style.display="block";CKEDITOR.note&&CKEDITOR.note.hide(true)}else a++},m=[new CKEDITOR.ui.button({type:"button",id:"LJPoll_Ok",label:d.lang.common.ok,onClick:function(a){a.data.dialog.hide();var b=new Poll(h,e.document,j.document,e.Questions),a=b.outputHTML(),b=b.outputLJtags(); -if(a.length>0){var f=i.LJPollLink.node;if(f){f.setAttribute("lj-content",a);f.setAttribute("lj-data",b);f.removeAttribute("style");f.$.contentWindow.document.body.className="lj-poll"}else{f=new CKEDITOR.dom.element("iframe",d.document);f.setAttribute("lj-content",a);f.setAttribute("lj-cmd","LJPollLink");f.setAttribute("lj-data",b);f.setAttribute("lj-class","lj-poll");f.setAttribute("class","lj-poll-wrap");f.setAttribute("frameBorder",0);f.setAttribute("allowTransparency","true");d.insertElement(f)}i.LJPollLink.node= -null;c()}}}),CKEDITOR.dialog.cancelButton];CKEDITOR.env.mac&&m.reverse();return{title:top.CKLang.Poll_PollWizardTitle,width:420,height:270,resizable:false,onShow:function(){if(a){h=new Poll(i.LJPollLink.node&&unescape(i.LJPollLink.node.getAttribute("data")),e.document,j.document,e.Questions);e.ready(h);j.ready(h)}},contents:[{id:"LJPoll_Setup",label:"Setup",padding:0,elements:[{type:"html",html:'<iframe src="/tools/ck_poll_setup.bml" allowTransparency="true" frameborder="0" style="width:100%; height:320px;"></iframe>', -onShow:function(a){if(!b)(b=document.getElementById(a.sender.getButton("LJPoll_Ok").domId).parentNode).style.display="none";a=this.getElement("iframe");j=a.$.contentWindow;if(j.ready)f();else a.on("load",f)}}]},{id:"LJPoll_Questions",label:"Questions",padding:0,elements:[{type:"html",html:'<iframe src="/tools/ck_poll_questions.bml" allowTransparency="true" frameborder="0" style="width:100%; height:320px;"></iframe>',onShow:function(){var a=this.getElement("iframe");e=a.$.contentWindow;if(e.ready)f(); -else a.on("load",f)}}]}],buttons:m}});d.addCommand("LJPollLink",new CKEDITOR.dialogCommand("LJPollDialog"))}else d.addCommand("LJPollLink",{exec:function(){CKEDITOR.note&&CKEDITOR.note.show(top.CKLang.Poll_AccountLevelNotice,null,null,true)}}),d.getCommand("LJPollLink").setState(CKEDITOR.TRISTATE_DISABLED);d.ui.addButton("LJPollLink",{label:top.CKLang.Poll_Title,command:"LJPollLink"});(function(){function a(){if(d.getCommand("LJLike")==CKEDITOR.TRISTATE_OFF){this.$.checked?e++:e--;h.getButton("LJLike_Ok").getElement()[e== -0?"addClass":"removeClass"]("btn-disabled")}}var b=l.length,c='<div class="cke-dialog-likes"><ul class="cke-dialog-likes-list">',e=0,h,f;l.defaultButtons=[];for(var j=0;j<b;j++){var o=l[j];l[o.id]=l[o.abbr]=o;l.defaultButtons.push(o.id);c=c+o.htmlOpt}c=c+('</ul><p class="cke-dialog-likes-faq">'+window.faqLink+"</p></div>");CKEDITOR.dialog.add("LJLikeDialog",function(){var j=[new CKEDITOR.ui.button({type:"button",id:"LJLike_Ok",label:d.lang.common.ok,onClick:function(){var a=[],c='<span class="lj-like-wrapper">', -e=i.LJLike.node;if(h.getButton("LJLike_Ok").getElement().hasClass("btn-disabled"))return false;for(var f=0;f<b;f++){var j=l[f],g=document.getElementById("like-"+j.abbr),k=e&&e.getAttribute("buttons");if(g&&g.checked||k&&!j.htmlOpt&&(k.indexOf(j.abbr)+1||k.indexOf(j.id)+1)){a.push(j.id);c=c+j.html}}c=c+"</span>";if(a.length)if(e){i.LJLike.node.setAttribute("buttons",a.join(","));i.LJLike.node.setAttribute("lj-content",encodeURIComponent(c))}else{e=new CKEDITOR.dom.element("iframe",d.document);e.setAttribute("lj-class", -"lj-like");e.setAttribute("class","lj-like-wrap");e.setAttribute("buttons",a.join(","));e.setAttribute("lj-content",encodeURIComponent(c));e.setAttribute("lj-cmd","LJLike");e.setAttribute("frameBorder",0);e.setAttribute("allowTransparency","true");d.insertElement(e)}else e&&i.LJLike.node.remove();h.hide()}}),CKEDITOR.dialog.cancelButton];CKEDITOR.env.mac&&j.reverse();return{title:top.CKLang.LJLike_name,width:145,height:window.isSupUser?180:145,resizable:false,contents:[{id:"LJLike_Options",elements:[{type:"html", -html:c}]}],onShow:function(){var a=d.getCommand("LJLike"),c=e=0,a=a.state==CKEDITOR.TRISTATE_ON,j=i.LJLike.node&&i.LJLike.node.getAttribute("buttons");for(CKEDITOR.note&&CKEDITOR.note.hide(true);c<b;c++){var f=j?!!(j.indexOf(l[c].abbr)+1||j.indexOf(l[c].id)+1):true,g=document.getElementById("like-"+l[c].abbr);if(g){f&&!a&&e++;g.checked=f}}e>0&&h.getButton("LJLike_Ok").getElement().removeClass("btn-disabled")},onLoad:function(){h=this;f=h.parts.contents.getElementsByTag("input");for(var c=0;c<b;c++){var e= -f.getItem(c);e&&e.on("click",a)}},buttons:j}});d.addCommand("LJLike",new CKEDITOR.dialogCommand("LJLikeDialog"));d.ui.addButton("LJLike",{label:top.CKLang.LJLike_name,command:"LJLike"})})()},afterInit:function(d){function f(b,a,c,d){var d=d||"text",e=new CKEDITOR.htmlParser.element("iframe");e.attributes["lj-class"]=a+" "+a+"-open";e.attributes["class"]=a+"-wrap";e.attributes["lj-cmd"]=c;e.attributes.frameBorder=0;e.attributes.allowTransparency="true";b.attributes.hasOwnProperty(d)&&(e.attributes.text= -b.attributes[d]);b.children.unshift(e);c=new CKEDITOR.htmlParser.element("iframe");c.attributes["lj-class"]=a+" "+a+"-close";c.attributes["class"]=a+"-wrap";c.attributes.frameBorder=0;c.attributes.allowTransparency="true";b.children.push(c);delete b.name}var i=d.dataProcessor;i.dataFilter.addRules({elements:{"lj-like":function(b){var a=[],c=new CKEDITOR.htmlParser.element("iframe");c.attributes["lj-class"]="lj-like";c.attributes["class"]="lj-like-wrap";b.attributes.hasOwnProperty("style")&&(c.attributes["lj-style"]= -b.attributes.style);c.attributes["lj-cmd"]="LJLike";c.attributes["lj-content"]='<span class="lj-like-wrapper">';c.attributes.frameBorder=0;c.attributes.allowTransparency="true";for(var b=b.attributes.buttons&&b.attributes.buttons.split(",")||l.defaultButtons,d=b.length,e=0;e<d;e++){var f=b[e].replace(/^\s*([a-z]{2,})\s*$/i,"$1"),i=l[f];i&&(c.attributes["lj-content"]+=encodeURIComponent(i.html),a.push(f))}c.attributes["lj-content"]+="</span>";c.attributes.buttons=a.join(",");return c},lj:function(){function b(a){for(var c= -d.document.getElementsByTag("lj"),f=0,e=c.count();f<e;f++){var h=c.getItem(f);if(h){var i=h.getAttribute("user"),l=h.getAttribute("title");if(a==(l?i+":"+l:i))i=new CKEDITOR.dom.element.createFromHtml(o[a],d.document),i.setAttribute("lj-cmd","LJUserLink"),h.insertBeforeMe(i),h.remove()}}d.removeListener("dataReady",b)}return function(a){var c=a.attributes.user;if(c&&c.length){var f=(a=a.attributes.title)?c+":"+a:c;if(o.hasOwnProperty(f))return a=(new CKEDITOR.htmlParser.fragment.fromHtml(o[f])).children[0], -a.attributes["lj-cmd"]="LJUserLink",a;var e={username:c};a&&(e.usertitle=a);HTTPReq.getJSON({data:HTTPReq.formEncoded(e),method:"POST",url:Site.siteroot+"/tools/endpoints/ljuser.bml",onError:function(a){alert(a+' "'+c+'"')},onData:function(a){if(a.error)return alert(a.error+' "'+c+'"');if(a.success){o[f]=a.ljuser;a.ljuser=a.ljuser.replace('<span class="useralias-value">*</span>',"");if(d.document)b(f);else d.on("dataReady",function(){b(f)})}}})}}}(),"lj-map":function(b){var a=new CKEDITOR.htmlParser.element("iframe"), -c="",d="",e=Number(b.attributes.width),f=Number(b.attributes.height);isNaN(e)||(c+="width:"+e+"px;",d+="width:"+(e-2)+"px;");isNaN(f)||(c+="height:"+f+"px;",d+="height:"+(f-2)+"px;");c.length&&(a.attributes.style=c,a.attributes["lj-style"]=d);a.attributes["lj-url"]=b.attributes.url?encodeURIComponent(b.attributes.url):"";a.attributes["lj-class"]="lj-map";a.attributes["class"]="lj-map-wrap";a.attributes["lj-content"]='<p class="lj-map">map</p>';a.attributes.frameBorder=0;a.attributes.allowTransparency= -"true";return a},"lj-raw":function(b){b.name="lj:raw"},"lj-wishlist":function(b){b.name="lj:wishlist"},"lj-template":function(b){var a=new CKEDITOR.htmlParser.element("iframe");a.attributes["lj-class"]="lj-template";a.attributes["class"]="lj-template-wrap";a.attributes.frameBorder=0;a.attributes.allowTransparency="true";a.attributes["lj-attributes"]=encodeURIComponent(LiveJournal.JSON.stringify(b.attributes));return a},"lj-cut":function(b){f(b,"lj-cut","LJCut")},"lj-spoiler":function(b){f(b,"lj-spoiler", -"LJSpoiler","title")},iframe:function(b){if(b.attributes["lj-class"]&&1==b.attributes["lj-class"].indexOf("lj-")+1)return b;var a=new CKEDITOR.htmlParser.element("iframe"),c="",d="",e=Number(b.attributes.width),f=Number(b.attributes.height);isNaN(e)||(c+="width:"+e+"px;",d+="width:"+(e-2)+"px;");isNaN(f)||(c+="height:"+f+"px;",d+="height:"+(f-2)+"px;");c.length&&(a.attributes.style=c,a.attributes["lj-style"]=d);a.attributes["lj-url"]=b.attributes.src?encodeURIComponent(b.attributes.src):"";a.attributes["lj-class"]= -"lj-iframe";a.attributes["class"]="lj-iframe-wrap";a.attributes["lj-content"]='<p class="lj-iframe">iframe</p>';a.attributes.frameBorder=0;a.attributes.allowTransparency="true";return a},a:function(b){b.parent.attributes&&!b.parent.attributes["lj:user"]&&(b.attributes["lj-cmd"]="LJLink")},img:function(b){var a=b.parent&&b.parent.parent;if(!a||!a.attributes||!a.attributes["lj:user"])b.attributes["lj-cmd"]="image"},div:function(b){"lj-cut"==b.attributes["class"]&&f(b,"lj-cut","LJCut")}}},5);i.htmlFilter.addRules({elements:{iframe:function(b){var a= -b,c=!1,d="text",e=/lj-[a-z]+/i.exec(b.attributes["lj-class"]);if(e)e=e[0];else return b;switch(e){case "lj-like":a=new CKEDITOR.htmlParser.element("lj-like");a.attributes.buttons=b.attributes.buttons;b.attributes.hasOwnProperty("lj-style")&&(a.attributes.style=b.attributes["lj-style"]);a.isEmpty=!0;a.isOptionalClose=!0;break;case "lj-embed":a=new CKEDITOR.htmlParser.element("lj-embed");a.attributes.id=b.attributes.id;b.attributes.hasOwnProperty("source_user")&&(a.attributes.source_user=b.attributes.source_user); -a.children=(new CKEDITOR.htmlParser.fragment.fromHtml(decodeURIComponent(b.attributes["lj-data"]))).children;a.isOptionalClose=!0;break;case "lj-map":a=new CKEDITOR.htmlParser.element("lj-map");a.attributes.url=decodeURIComponent(b.attributes["lj-url"]);b.attributes.style&&(b.attributes.style+";").replace(/([a-z-]+):(.*?);/gi,function(b,c,d){a.attributes[c.toLowerCase()]=parseInt(d)});a.isOptionalClose=a.isEmpty=!0;break;case "lj-iframe":a=new CKEDITOR.htmlParser.element("iframe");a.attributes.src= -decodeURIComponent(b.attributes["lj-url"]);b.attributes.style&&(b.attributes.style+";").replace(/([a-z-]+):(.*?);/gi,function(b,c,d){a.attributes[c.toLowerCase()]=parseInt(d)});a.attributes.frameBorder=0;break;case "lj-poll":a=(new CKEDITOR.htmlParser.fragment.fromHtml(decodeURIComponent(b.attributes["lj-data"]))).children[0];break;case "lj-repost":a=new CKEDITOR.htmlParser.element("lj-repost");a.attributes.button=b.attributes["lj-button"];a.children=(new CKEDITOR.htmlParser.fragment.fromHtml(b.attributes["lj-text"])).children; -break;case "lj-template":a=new CKEDITOR.htmlParser.element("lj-template");a.attributes=LiveJournal.JSON.parse(encodeURIComponent(b.attributes["lj-attributes"]));a.isOptionalClose=a.isEmpty=!0;break;case "lj-spoiler":c=!0,d="title";case "lj-cut":if(b.attributes["lj-class"].indexOf(e+"-open")+1){var f=b.next,i=0,a=new CKEDITOR.htmlParser.element(e);for(b.attributes.hasOwnProperty("text")&&(a.attributes[d]=b.attributes.text);f;){if("iframe"==f.name)if(b=f.attributes["lj-class"],b.indexOf(e+"-close")+ -1)if(c&&i)i--;else{a.next=f;break}else if(b.indexOf(e+"-open")+1)if(c)i++;else{a.next=f;break}f.parent.children.remove(f);a.add(f);b=f.next;f.next=null;f=b}}else a=!1;break;default:b.children.length||(a=!1)}return a},span:function(b){var a=b.attributes["lj:user"];if(a){var c=new CKEDITOR.htmlParser.element("lj");c.attributes.user=a;try{var d=b.children[1].children[0].children[0].value}catch(e){return!1}d&&d!=a&&(c.attributes.title=d);c.isOptionalClose=c.isEmpty=!0;return c}if("display: none;"==b.attributes.style|| -!b.children.length)return!1},div:function(b){if(!b.children.length)return!1},"lj:raw":function(b){b.name="lj-raw"},"lj:wishlist":function(b){b.name="lj-wishlist"}},attributes:{"lj-cmd":function(){return!1},contenteditable:function(){return!1}}})},requires:["fakeobjects","domiterator"]})})(); + +(function() { + var likeButtons = [ + { + label: top.CKLang.LJLike_button_facebook, + id: 'facebook', + abbr: 'fb', + html: '<span class="lj-like-item fb">' + top.CKLang.LJLike_button_facebook + '</span>', + htmlOpt: '<li class="like-fb"><input type="checkbox" id="like-fb" /><label for="like-fb">' + top.CKLang.LJLike_button_facebook + '</label></li>' + }, + { + label: top.CKLang.LJLike_button_twitter, + id: 'twitter', + abbr: 'tw', + html: '<span class="lj-like-item tw">' + top.CKLang.LJLike_button_twitter + '</span>', + htmlOpt: '<li class="like-tw"><input type="checkbox" id="like-tw" /><label for="like-tw">' + top.CKLang.LJLike_button_twitter + '</label></li>' + }, + { + label: top.CKLang.LJLike_button_google, + id: 'google', + abbr: 'go', + html: '<span class="lj-like-item go">' + top.CKLang.LJLike_button_google + '</span>', + htmlOpt: '<li class="like-go"><input type="checkbox" id="like-go" /><label for="like-go">' + top.CKLang.LJLike_button_google + '</label></li>' + }, + { + label: top.CKLang.LJLike_button_vkontakte, + id: 'vkontakte', + abbr: 'vk', + html: '<span class="lj-like-item vk">' + top.CKLang.LJLike_button_vkontakte + '</span>', + htmlOpt: window.isSupUser ? '<li class="like-vk"><input type="checkbox" id="like-vk" /><label for="like-vk">' + top.CKLang.LJLike_button_vkontakte + '</label></li>' : '' + }, + { + label: top.CKLang.LJLike_button_give, + id: 'livejournal', + abbr: 'lj', + html: '<span class="lj-like-item lj">' + top.CKLang.LJLike_button_give + '</span>', + htmlOpt: '<li class="like-lj"><input type="checkbox" id="like-lj" /><label for="like-lj">' + top.CKLang.LJLike_button_give + '</label></li>' + } + ]; + + var ljTagsData = { + LJPollLink: { + html: encodeURIComponent(top.CKLang.Poll_PollWizardNotice + '<br /><a href="#" lj-cmd="LJPollLink">' + top.CKLang.Poll_PollWizardNoticeLink + '</a>') + }, + LJLike: { + html: encodeURIComponent(top.CKLang.LJLike_WizardNotice + '<br /><a href="#" lj-cmd="LJLike">' + top.CKLang.LJLike_WizardNoticeLink + '</a>') + }, + LJUserLink: { + html: encodeURIComponent(top.CKLang.LJUser_WizardNotice + '<br /><a href="#" lj-cmd="LJUserLink">' + top.CKLang.LJUser_WizardNoticeLink + '</a>') + }, + LJLink: { + html: encodeURIComponent(top.CKLang.LJLink_WizardNotice + '<br /><a href="#" lj-cmd="LJLink">' + top.CKLang.LJLink_WizardNoticeLink + '</a>') + }, + image: { + html: encodeURIComponent(top.CKLang.LJImage_WizardNotice + '<br /><a href="#" lj-cmd="image">' + top.CKLang.LJImage_WizardNoticeLink + '</a>') + }, + LJCut: { + html: encodeURIComponent(top.CKLang.LJCut_WizardNotice + '<br /><a href="#" lj-cmd="LJCut">' + top.CKLang.LJCut_WizardNoticeLink + '</a>') + }, + LJSpoiler: { + html: encodeURIComponent(top.CKLang.LJSpoiler_WizardNotice + '<br /><a href="#" lj-cmd="LJSpoiler">' + top.CKLang.LJSpoiler_WizardNoticeLink + '</a>') + } + }; + + var ljUsers = {}; + var execFromEditor; + + function createNote(editor) { + var timer, + state, + currentData, + tempData, + noteNode = document.createElement('lj-note'), + isIE = typeof(document.body.style.opacity) != 'string'; + + var animate = (function() { + var fps = 60, totalTime = 100, steps = totalTime * fps / 1000, timeOuts = [], type, parentContainer = document.getElementById('draft-container') || document.body; + + function apply() { + var data = timeOuts.shift(); + var currentStep = (type ? data.time / totalTime : -(data.time / totalTime - 1)).toFixed(1); + + if (!timeOuts.length) { + currentStep = type ? 1 : 0; + } + + if (isIE) { + noteNode.style.filter = (currentStep >= 1) ? null : 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + (currentStep * 100) + ')'; + } else { + noteNode.style.opacity = currentStep; + } + + if (currentStep == 0 && noteNode && noteNode.parentNode) { + noteNode.parentNode.removeChild(noteNode); + } + } + + return function(animateType) { + type = animateType; + + if (type && noteNode.parentNode) { + if (isIE) { + noteNode.style.filter = null; + } else { + noteNode.style.opacity = 1; + } + } else { + for (var i = 1; i <= steps; i++) { + var time = Math.floor(1000 / fps) * i; + timeOuts.push({ + time: time, + timer: setTimeout(apply, time) + }); + } + } + + parentContainer.appendChild(noteNode); + noteNode.style.marginTop = -noteNode.offsetHeight / 2 + 'px'; + noteNode.style.marginLeft = -noteNode.offsetWidth / 2 + 'px'; + } + })(); + + noteNode.className = 'note-popup'; + + noteNode.onmouseout = function() { + if (!currentData || !currentData.cmd) { + CKEDITOR.note.hide(); + } + }; + + noteNode.onmouseover = function() { + if (timer && !state) { + state = 1; + timer = clearTimeout(timer); + } + }; + + if (isIE) { + noteNode.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0)'; + } else { + noteNode.style.opacity = 0; + } + + function callCmd() { + var cmd = this.getAttribute('lj-cmd'); + if (currentData.hasOwnProperty(cmd)) { + ljTagsData[cmd].node = currentData[cmd].node; + var selection = new CKEDITOR.dom.selection(editor.document); + selection.selectElement(ljTagsData[cmd].node); + execFromEditor = true; + editor.execCommand(cmd); + CKEDITOR.note.hide(true); + } + + return false; + } + + function applyNote() { + if (!window.switchedRteOn) { + CKEDITOR.note.hide(true); + } + + if (state) { + currentData = tempData; + tempData = null; + + var html = ''; + for (var cmd in currentData) { + if (currentData.hasOwnProperty(cmd)) { + html += '<div class="noteItem">' + currentData[cmd].content + '</div>'; + } + } + + noteNode.innerHTML = decodeURIComponent(html); + + var links = noteNode.getElementsByTagName('a'); + for (var i = 0, l = links.length; i < l; i++) { + var link = links[i]; + if (ljTagsData.hasOwnProperty(link.getAttribute('lj-cmd'))) { + link.onclick = callCmd; + } + } + } else { + currentData = null; + } + + animate(state); + + timer = null; + } + + CKEDITOR.note = { + show: function(data, isNow) { + if ((!isNow && data == tempData) || !window.switchedRteOn) { + return; + } + + if (timer) { + timer = clearTimeout(timer); + } + + state = 1; + tempData = data; + isNow === true ? applyNote() : timer = setTimeout(applyNote, 1000); + }, + hide: function(isNow) { + if (state) { + state = 0; + + if (timer) { + timer = clearTimeout(timer); + } + + if (noteNode.parentNode) { + isNow === true ? applyNote() : timer = setTimeout(applyNote, 500); + } + } + } + }; + } + + var dtd = CKEDITOR.dtd; + + dtd.$block['lj-template'] = 1; + dtd.$block['lj-raw'] = 1; + dtd.$block['lj-cut'] = 1; + dtd.$block['lj-spoiler'] = 1; + dtd.$block['lj-poll'] = 1; + dtd.$block['lj-repost'] = 1; + dtd.$block['lj-pq'] = 1; + dtd.$block['lj-pi'] = 1; + dtd.$nonEditable['lj-template'] = 1; + + dtd['lj-template'] = {}; + dtd['lj-map'] = {}; + dtd['lj-repost'] = {}; + dtd['lj-raw'] = dtd.div; + + dtd['lj-poll'] = { + 'lj-pq': 1 + }; + + dtd['lj-pq'] = { + '#': 1, + 'lj-pi': 1 + }; + + dtd['lj-pi'] = { + '#': 1 + }; + + dtd.$block.iframe = dtd.$inline.iframe; + delete dtd.$inline.iframe; + + CKEDITOR.tools.extend(dtd['lj-cut'] = {}, dtd.$block); + CKEDITOR.tools.extend(dtd['lj-spoiler'] = {}, dtd.$block); + + CKEDITOR.tools.extend(dtd['lj-cut'], dtd.$inline); + CKEDITOR.tools.extend(dtd['lj-spoiler'], dtd.$inline); + + CKEDITOR.tools.extend(dtd.div, dtd.$block); + CKEDITOR.tools.extend(dtd.$body, dtd.$block); + + delete dtd['lj-cut']['lj-cut']; + + CKEDITOR.plugins.add('livejournal', { + init: function(editor) { + // The editor event listeners + function onDoubleClick(evt) { + var node = evt.data.element || evt.data.getTarget(); + + if (node.type != 1) { + node = node.getParent(); + } + + while (node) { + var cmdName = node.getAttribute('lj-cmd'); + if (ljTagsData.hasOwnProperty(cmdName)) { + var cmd = editor.getCommand(cmdName); + if (cmd.state == CKEDITOR.TRISTATE_ON) { + var selection = new CKEDITOR.dom.selection(editor.document); + ljTagsData[cmdName].node = node.is('body') ? new CKEDITOR.dom.element.get(node.getWindow().$.frameElement) : node; + selection.selectElement(ljTagsData[cmdName].node); + evt.data.dialog = ''; + execFromEditor = true; + cmd.exec(); + break; + } + } + + node = node.getParent(); + } + } + + function onClickFrame(evt) { + if (this.$ != editor.document.$) { + this.$.className = (this.frame.getAttribute('lj-class') || '') + ' lj-selected'; + if (this.getAttribute('lj-cmd') == 'LJPollLink') { + this.frame.setStyle('height', this.getDocument().$.body.scrollHeight + 'px'); + } + new CKEDITOR.dom.selection(editor.document).selectElement(this.frame); + } + + evt.data.getKey() == 1 && evt.data.preventDefault(); + } + + function onKeyUp(evt) { + if (evt.data.getKey() == 46) { + var ranges = new CKEDITOR.dom.selection(editor.document).getRanges(); + var length = ranges.length; + while (length--) { + ranges[length].deleteContents(); + } + } + } + + function onLoadFrame() { + var win = this.$.contentWindow, doc = win.document, iframeBody = new CKEDITOR.dom.element.get(doc.body); + + if (iframeBody.on) { + iframeBody.on('dblclick', onDoubleClick); + iframeBody.on('click', onClickFrame); + iframeBody.on('keyup', onKeyUp); + + if (this.getAttribute('lj-cmd') == 'LJPollLink' && this.hasAttribute('style')) { + doc.body.className = 'lj-poll lj-poll-open'; + } + } + + doc = new CKEDITOR.dom.element.get(doc); + doc.frame = iframeBody.frame = this; + } + + function updateFrames() { + var frames = editor.document.getElementsByTag('iframe'), length = frames.count(), frame, cmd, frameWin, doc, ljStyle; + execFromEditor = false; + + while (length--) { + frame = frames.getItem(length), cmd = frame.getAttribute('lj-cmd'), frameWin = frame.$.contentWindow, doc = frameWin.document, ljStyle = frame.getAttribute('lj-style') || ''; + frame.removeListener('load', onLoadFrame); + frame.on('load', onLoadFrame); + doc.open(); + doc.write('<!DOCTYPE html>' + + '<html style="' + ljStyle + '">' + + '<head><link rel="stylesheet" href="' + CKEDITOR.styleText + '" /></head>' + + '<body scroll="no" class="' + (frame.getAttribute('lj-class') || '') + '" style="' + ljStyle + '" ' + (cmd ? ('lj-cmd="' + cmd + '"') : '') + '>' + + decodeURIComponent(frame.getAttribute('lj-content') || '') + + '</body>' + + '</html>'); + doc.close(); + } + } + + function findLJTags(evt) { + if (editor.onSwitch === true) { + delete editor.onSwitch; + return; + } + + var noteData, isClick = evt.name == 'click', isSelection = evt.name == 'selectionChange' || isClick, target = evt.data.element || evt.data.getTarget(), node, command; + + if (isClick && (evt.data.getKey() == 1 || evt.data.$.button == 0)) { + evt.data.preventDefault(); + } + + if (target.type != 1) { + target = target.getParent(); + } + + node = target; + + if (isSelection) { + var frames = editor.document.getElementsByTag('iframe'), frame, body; + + if (isClick && node.is('iframe')) { + body = node.$.contentWindow.document.body; + body.className = (node.getAttribute('lj-class') || '') + ' lj-selected'; + if (node.getAttribute('lj-cmd') == 'LJPollLink') { + node.setStyle('height', body.scrollHeight + 'px'); + } + } + + for (var i = 0, l = frames.count(); i < l; i++) { + frame = frames.getItem(i); + if (frame.$ != node.$) { + body = frame.$.contentWindow.document.body; + body.className = frame.getAttribute('lj-class') || ''; + if (frame.getAttribute('lj-cmd') == 'LJPollLink' && body.className == 'lj-poll') { + frame.removeAttribute('style'); + } + } + } + } + + do { + var attr = node.getAttribute('lj-cmd'); + + if (!attr && node.type == 1) { + var parent = node.getParent(); + if (node.is('img') && parent.getParent() && !parent.getParent().hasAttribute('lj:user')) { + attr = 'image'; + node.setAttribute('lj-cmd', attr); + } else if (node.is('a') && !parent.hasAttribute('lj:user')) { + attr = 'LJLink'; + node.setAttribute('lj-cmd', attr); + } + } + + if (attr && ljTagsData.hasOwnProperty(attr)) { + if (isSelection) { + ljTagsData[attr].node = node; + editor.getCommand(attr).setState(CKEDITOR.TRISTATE_ON); + } + (noteData || (noteData = {}))[attr] = { + content: ljTagsData[attr].html, + node: node + }; + } + } while (node = node.getParent()); + + if (isSelection) { + for (command in ljTagsData) { + if (ljTagsData.hasOwnProperty(command) && (!noteData || !noteData.hasOwnProperty(command))) { + delete ljTagsData[command].node; + editor.getCommand(command).setState(CKEDITOR.TRISTATE_OFF); + } + } + } + + noteData ? CKEDITOR.note.show(noteData) : CKEDITOR.note.hide(); + } + + + // Configure editor + (function () { + function closeTag(result) { + return result.slice(-2) == '/>' ? result : result.slice(0, -1) + '/>'; + } + + function createPoll(ljtags) { + var poll = new Poll(ljtags); + return '<iframe class="lj-poll-wrap" lj-class="lj-poll" frameborder="0" lj-cmd="LJPollLink" allowTransparency="true" ' + 'lj-data="' + poll.outputLJtags() + '" lj-content="' + poll.outputHTML() + '"></iframe>'; + } + + function createEmbed(result, attrs, data) { + return '<iframe class="lj-embed-wrap" lj-class="lj-embed" frameborder="0" allowTransparency="true" lj-data="' + encodeURIComponent(data) + '"' + attrs + '></iframe>'; + } + + function createLJRaw(result, open, content, close) { + return open + content.replace(/\n/g, '') + close; + } + + function createRepost(result, firstAttr, secondAttr, content) { + var buttonTitle = firstAttr || secondAttr || top.CKLang.LJRepost_Value; + var text = content.replace(/"/g, '"'); + + content = text + ('<br /><input type="button" value="' + buttonTitle + '" />').replace(/"/g, '"'); + + return '<iframe class="lj-repost-wrap" lj-class="lj-repost" frameborder="0" allowTransparency="true" lj-text="' + text + '" lj-button="' + buttonTitle + '" lj-content="' + content + '"></iframe>'; + } + + editor.dataProcessor.toHtml = function(html, fixForBody) { + html = html.replace(/<lj [^>]*?>/gi, closeTag) + .replace(/<lj-map [^>]*?>/gi, closeTag) + .replace(/<lj-template[^>]*?>/gi, closeTag) + .replace(/(<lj-cut[^>]*?)\/>/gi, '$1>') + .replace(/<((?!br)[^\s>]+)([^>]*?)\/>/gi, '<$1$2></$1>') + .replace(/<lj-poll.*?>[\s\S]*?<\/lj-poll>/gi, createPoll) + .replace(/<lj-repost\s*(?:button\s*=\s*(?:"([^"]*?)")|(?:"([^']*?)"))?.*?>([\s\S]*?)<\/lj-repost>/gi, createRepost) + .replace(/<lj-embed(.*?)>([\s\S]*?)<\/lj-embed>/gi, createEmbed); + + if (!$('event_format').checked) { + html = html.replace(/(<lj-raw.*?>)([\s\S]*?)(<\/lj-raw>)/gi, createLJRaw); + + if (!window.switchedRteOn) { + html = html.replace(/\n/g, '<br />'); + } + } + + html = CKEDITOR.htmlDataProcessor.prototype.toHtml.call(this, html, fixForBody); + + if (CKEDITOR.env.ie) { + html = '<xml:namespace ns="livejournal" prefix="lj" />' + html; + } + + return html; + }; + })(); + + editor.dataProcessor.toDataFormat = function(html, fixForBody) { + html = CKEDITOR.htmlDataProcessor.prototype.toDataFormat.call(this, html, fixForBody); + + if (!$('event_format').checked) { + html = html.replace(/<br\s*\/>/gi, '\n'); + } + + return html.replace(/\t/g, ' '); + }; + + editor.dataProcessor.writer.indentationChars = ''; + editor.dataProcessor.writer.lineBreakChars = ''; + + editor.on('selectionChange', findLJTags); + editor.on('doubleclick', onDoubleClick); + editor.on('afterCommandExec', updateFrames); + editor.on('dialogHide', updateFrames); + + editor.on('dataReady', function() { + if (!CKEDITOR.note) { + createNote(editor); + } + + if (CKEDITOR.env.ie) { + editor.document.getBody().on('dragend', updateFrames); + editor.document.getBody().on('paste', function () { + setTimeout(updateFrames, 0); + }); + } + + editor.document.on('click', findLJTags); + editor.document.on('mouseout', CKEDITOR.note.hide); + editor.document.on('mouseover', findLJTags); + editor.document.getBody().on('keyup', onKeyUp); + updateFrames(); + }); + + + + // LJ Buttons + + // LJ User Button + (function () { + var url = top.Site.siteroot + '/tools/endpoints/ljuser.bml'; + + function onData(data, userName, LJUser) { + if (data.error) { + alert(data.error); + return; + } + + if (data.success) { + data.ljuser = data.ljuser.replace('<span class="useralias-value">*</span>', ''); + + ljUsers[userName] = data.ljuser; + + var tmpNode = new CKEDITOR.dom.element.createFromHtml(data.ljuser); + tmpNode.setAttribute('lj-cmd', 'LJUserLink'); + + if (LJUser) { + LJUser.$.parentNode.replaceChild(tmpNode.$, LJUser.$); + } else { + editor.insertElement(tmpNode); + } + } + + } + + editor.addCommand('LJUserLink', { + exec: function(editor) { + var userName = '', + selection = new CKEDITOR.dom.selection(editor.document), + LJUser = ljTagsData.LJUserLink.node, + currentUserName; + + if (LJUser) { + CKEDITOR.note && CKEDITOR.note.hide(true); + currentUserName = ljTagsData.LJUserLink.node.getElementsByTag('b').getItem(0).getText(); + userName = prompt(top.CKLang.UserPrompt, currentUserName); + } else if (selection.getType() == 2) { + userName = selection.getSelectedText(); + } + + if (userName == '') { + userName = prompt(top.CKLang.UserPrompt, userName); + } + + if (!userName || currentUserName == userName) { + return; + } + + parent.HTTPReq.getJSON({ + data: parent.HTTPReq.formEncoded({ + username: userName + }), + method: 'POST', + url: url, + onData: function (data) { + onData(data, userName, LJUser); + } + }); + } + }); + + editor.ui.addButton('LJUserLink', { + label: top.CKLang.LJUser, + command: 'LJUserLink' + }); + })(); + + // LJ Image Button + if (window.ljphotoEnabled && window.ljphotoMigrationStatus === LJ.getConst('LJPHOTO_MIGRATION_NONE')) { + editor.ui.addButton('image', { + label: top.CKLang.LJImage_Title, + command: 'image' + }); + } else { + editor.addCommand('LJImage', { + exec: function () { + if (typeof InOb !== 'undefined') { + InOb.handleInsertImageBeta('upload'); + } + jQuery('.b-updatepage-event-section').editor('handleImageUpload', 'upload'); + }, + editorFocus: false + }); + + editor.ui.addButton('image', { + label: top.CKLang.LJImage_Title, + command: 'LJImage' + }); + } + + // LJ Link Button + editor.addCommand('LJLink', { + exec: function(editor) { + !execFromEditor && this.state == CKEDITOR.TRISTATE_ON ? editor.execCommand('unlink') : editor.openDialog('link'); + CKEDITOR.note && CKEDITOR.note.hide(true); + }, + editorFocus: false + }); + + editor.ui.addButton('LJLink', { + label: editor.lang.link.toolbar, + command: 'LJLink' + }); + + // LJ Embed Media Button + (function () { + function doEmbed(content) { + if (content && content.length && window.switchedRteOn) { + var iframe = new CKEDITOR.dom.element('iframe', editor.document); + iframe.setAttribute('lj-data', encodeURIComponent(content)); + iframe.setAttribute('lj-class', 'lj-embed'); + iframe.setAttribute('class', 'lj-embed-wrap'); + iframe.setAttribute('frameBorder', 0); + iframe.setAttribute('allowTransparency', 'true'); + editor.insertElement(iframe); + updateFrames(); + } + } + + editor.addCommand('LJEmbedLink', { + exec: function() { + top.LJ_IPPU.textPrompt(top.CKLang.LJEmbedPromptTitle, top.CKLang.LJEmbedPrompt, doEmbed, { + width: '350px' + }); + } + }); + + editor.ui.addButton('LJEmbedLink', { + label: top.CKLang.LJEmbed, + command: 'LJEmbedLink' + }); + })(); + + function doubleFrameCommand (tagName, cmdName, promptData) { + var text, + ljNode = ljTagsData[cmdName].node; + + if (ljNode) { + if (text = prompt(promptData.title, ljNode.getAttribute('text') || promptData.text)) { + if (text == promptData.text) { + ljNode.removeAttribute('text'); + } else { + ljNode.setAttribute('text', text); + } + } + } else { + if (text = prompt(promptData.title, promptData.text)) { + editor.focus(); + + var selection = new CKEDITOR.dom.selection(editor.document), + ranges = selection.getRanges(), + iframeOpen = new CKEDITOR.dom.element('iframe', editor.document), + iframeClose = iframeOpen.clone(); + + iframeOpen.setAttribute('lj-cmd', cmdName); + iframeOpen.setAttribute('lj-class', tagName + ' ' + tagName + '-open'); + iframeOpen.setAttribute('class', tagName + '-wrap'); + iframeOpen.setAttribute('frameBorder', 0); + iframeOpen.setAttribute('allowTransparency', 'true'); + if (text != promptData.text) { + iframeOpen.setAttribute('text', text); + } + + iframeClose.setAttribute('lj-class', tagName + ' ' + tagName + '-close'); + iframeClose.setAttribute('class', tagName + '-wrap'); + iframeClose.setAttribute('frameBorder', 0); + iframeClose.setAttribute('allowTransparency', 'true'); + + var range = ranges[0]; + selection.lock(); + + var br = new CKEDITOR.dom.element('br', editor.document), + firstBR = br.clone(), + lastBR = br.clone(); + + var fragment = new CKEDITOR.dom.documentFragment(editor.document); + fragment.append(br.clone()); + fragment.append(iframeOpen); + fragment.append(firstBR); + + if (range.collapsed === false) { + for (var i = 0, l = ranges.length; i < l; i++) { + fragment.append(ranges[i].extractContents()); + } + } + + fragment.append(lastBR); + editor.insertElement(iframeClose); + br.clone().insertAfter(iframeClose); + iframeClose.insertBeforeMe(fragment); + + range.setStart(firstBR, 0); + range.setEnd(lastBR, 0); + selection.unlock(); + + selection.selectRanges(ranges); + } + + CKEDITOR.note && CKEDITOR.note.hide(true); + } + + } + + // LJ Cut Button + editor.addCommand('LJCut', { + exec: function() { + doubleFrameCommand('lj-cut', 'LJCut', { + title: top.CKLang.LJCut_PromptTitle, + text: top.CKLang.LJCut_PromptText + }); + }, + editorFocus: false + }); + + editor.ui.addButton('LJCut', { + label: top.CKLang.LJCut_Title, + command: 'LJCut' + }); + + // LJ Spoiler Button + editor.addCommand('LJSpoiler', { + exec: function() { + doubleFrameCommand('lj-spoiler', 'LJSpoiler', { + title: top.CKLang.LJSpoiler_PromptTitle, + text: top.CKLang.LJSpoiler_PromptText + }); + }, + editorFocus: false + }); + + editor.ui.addButton('LJSpoiler', { + label: top.CKLang.LJSpoiler_Title, + command: 'LJSpoiler' + }); + + // LJ Justify + (function() { + function getAlignment(element, useComputedState) { + useComputedState = useComputedState === undefined || useComputedState; + + var align, LJLike = ljTagsData.LJLike.node; + if (LJLike) { + var attr = element.getAttribute('lj-style'); + align = attr ? attr.replace(/text-align:\s*(left|right|center)/i, '$1') : 'left'; + } else if (useComputedState) { + align = element.getComputedStyle('text-align'); + } else { + while (!element.hasAttribute || !( element.hasAttribute('align') || element.getStyle('text-align') )) { + var parent = element.getParent(); + if (!parent) { + break; + } + element = parent; + } + align = element.getStyle('text-align') || element.getAttribute('align') || ''; + } + + align && ( align = align.replace(/-moz-|-webkit-|start|auto/i, '') ); + + !align && useComputedState && ( align = element.getComputedStyle('direction') == 'rtl' ? 'right' : 'left' ); + + return align; + } + + function onSelectionChange(evt) { + if (evt.editor.readOnly) { + return; + } + + var command = evt.editor.getCommand(this.name), element = evt.data.element; + if ((element.type == 1 && element.hasAttribute('lj-cmd') && element.getAttribute('lj-cmd')) == 'LJLike') { + command.state = getAlignment(element, editor.config.useComputedState) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF; + } else if (!element || element.type != 1 || element.getName() == 'body' || element.getName() == 'iframe') { + command.state = CKEDITOR.TRISTATE_OFF; + } else { + command.state = getAlignment(element, editor.config.useComputedState) == this.value ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF; + } + + command.fire('state'); + } + + function justifyCommand(editor, name, value) { + this.name = name; + this.value = value; + + var classes = editor.config.justifyClasses; + if (classes) { + switch (value) { + case 'left' : + this.cssClassName = classes[0]; + break; + case 'center' : + this.cssClassName = classes[1]; + break; + case 'right' : + this.cssClassName = classes[2]; + break; + } + + this.cssClassRegex = new RegExp('(?:^|\\s+)(?:' + classes.join('|') + ')(?=$|\\s)'); + } + } + + function onDirChanged(e) { + var editor = e.editor; + + var range = new CKEDITOR.dom.range(editor.document); + range.setStartBefore(e.data.node); + range.setEndAfter(e.data.node); + + var walker = new CKEDITOR.dom.walker(range), node; + + while (( node = walker.next() )) { + if (node.type == CKEDITOR.NODE_ELEMENT) { + var style = 'text-align', classes = editor.config.justifyClasses; + + if (!node.equals(e.data.node) && node.getDirection()) { + range.setStartAfter(node); + walker = new CKEDITOR.dom.walker(range); + continue; + } + + if (classes) { + if (node.hasClass(classes[ 0 ])) { + node.removeClass(classes[ 0 ]); + node.addClass(classes[ 2 ]); + } else if (node.hasClass(classes[ 2 ])) { + node.removeClass(classes[ 2 ]); + node.addClass(classes[ 0 ]); + } + } + + switch (node.getStyle(style)) { + case 'left': + node.setStyle(style, 'right'); + break; + case 'right': + node.setStyle(style, 'left'); + break; + } + } + } + } + + justifyCommand.prototype = { + exec : function(editor) { + var selection = editor.getSelection(), enterMode = editor.config.enterMode; + + if (!selection) { + return; + } + + var bookmarks = selection.createBookmarks(); + + if (ljTagsData.LJLike.node) { + ljTagsData.LJLike.node.setAttribute('lj-style', 'text-align: ' + this.value); + } else { + var ranges = selection.getRanges(true); + + var cssClassName = this.cssClassName, iterator, block; + + var useComputedState = editor.config.useComputedState; + useComputedState = useComputedState === undefined || useComputedState; + + for (var i = ranges.length - 1; i >= 0; i--) { + var range = ranges[i]; + var encloseNode = range.getEnclosedNode(); + if (encloseNode && encloseNode.is('iframe')) { + return; + } + + iterator = range.createIterator(); + iterator.enlargeBr = enterMode != CKEDITOR.ENTER_BR; + while (( block = iterator.getNextParagraph(enterMode == CKEDITOR.ENTER_P ? 'p' : 'div') )) { + block.removeAttribute('align'); + block.removeStyle('text-align'); + + var className = cssClassName && ( block.$.className = CKEDITOR.tools.ltrim(block.$.className.replace(this.cssClassRegex, '')) ); + + var apply = ( this.state == CKEDITOR.TRISTATE_OFF ) && ( !useComputedState || ( getAlignment(block, true) != this.value ) ); + + if (cssClassName) { + if (apply) { + block.addClass(cssClassName); + } else if (!className) { + block.removeAttribute('class'); + } + } else if (apply) { + block.setStyle('text-align', this.value); + } + } + + } + } + + editor.focus(); + editor.forceNextSelectionCheck(); + selection.selectBookmarks(bookmarks); + } + }; + + var left = new justifyCommand(editor, 'LJJustifyLeft', 'left'), center = new justifyCommand(editor, 'LJJustifyCenter', 'center'), right = n... (truncated)