
(function(){tinymce.create('tinymce.ui.OpenPNEColorButton:tinymce.ui.ColorSplitButton',{renderHTML:function(){var s=this.settings,h='<a id="'+this.id+'" href="javascript:;" class="mceButton mceButtonEnabled '+s['class']
+'" onmousedown="return false;" onclick="return false;" title="'+tinymce.DOM.encode(s.title)+'">';if(s.image){h+='<img class="mceIcon" src="'+s.image+'" /></a>';}else{h+='<span class="mceIcon '+s['class']+'"></span></a>';}
return h;},postRender:function(){tinymce.dom.Event.add(this.id,'click',this.showMenu,this);},setColor:function(c){this.value=c;this.hideMenu();this.settings.onselect(c);}});tinymce.create('tinymce.ui.OpenPNEEmojiButton:tinymce.ui.ColorSplitButton',{OpenPNEEmojiButton:function(id,s){var t=this;t.parent(id,s);t.settings=s;},renderMenu:function(){var t=this,m,i=0,s=t.settings,n,tb,tr,w;var DOM=tinymce.DOM,Event=tinymce.dom.Event,is=tinymce.is,each=tinymce.each;w=DOM.add(s.menu_container,'div',{id:t.id+'_menu',dir:'ltr','class':s['menu_class']+' '+s['class'],style:'position:absolute;left:0;top:-1000px;width:402px;'});m=DOM.add(w,'div',{'class':s['class']+' mceSplitButtonMenu'});DOM.add(m,'span',{'class':'mceMenuLine'});n=DOM.add(m,'table',{'class':'mceEmojiSplitMenu'});tb=DOM.add(n,'tbody');for(var num in s.emoji){var emoji=s.emoji[num];for(var i=emoji.start;i<=emoji.end;i++){if(i==emoji.start||i%25==0){tr=DOM.add(tb,'tr');}
n=DOM.add(tr,'td');n=DOM.add(n,'img',{src:"./skin/default/img/emoji/"+s.carrier+"/"+s.carrier+i+".gif",alt:"["+s.carrier+":"+i+"]"});Event.add(n,'mousedown',function(e){if(Prototype.Browser.IE){tinyMCE.execCommand("mceInsertContent",false,e.srcElement.getAttribute("alt"));}else{tinyMCE.execCommand("mceInsertContent",false,e.element().getAttribute("alt"));}});}}
DOM.addClass(m,'mceColorSplitMenu');return w;},renderHTML:function(){var s=this.settings,h='<a id="'+this.id+'" href="javascript:;" class="mceButton mceButtonEnabled '+s['class']
+'" onmousedown="return false;" onclick="return false;" title="'+tinymce.DOM.encode(s.title)+'">';if(s.image){h+='<img class="mceIcon" src="'+s.image+'" /></a>';}else{h+='<span class="mceIcon '+s['class']+'"></span></a>';}
return h;},showMenu:function(){var t=this,r,p,e;var DOM=tinymce.DOM,Event=tinymce.dom.Event,is=tinymce.is,each=tinymce.each;if(t.isDisabled())
return;if(!t.isMenuRendered){t.renderMenu();t.isMenuRendered=true;}
e=DOM.get(t.id);DOM.show(t.id+'_menu');DOM.addClass(e,'mceSplitButtonSelected');p2=DOM.getPos(e);DOM.setStyles(t.id+'_menu',{left:720-DOM.get(t.id+'_menu').clientWidth,top:p2.y+e.clientHeight,zIndex:150});e=0;Event.add(document,'mousedown',t.hideMenu,t);},postRender:function(){tinymce.dom.Event.add(this.id,'click',this.showMenu,this);}});tinymce.create('tinymce.ui.OpenPNECmdButton:tinymce.ui.Button',{renderHTML:function(){var s=this.settings;var h='<a id="'+this.id+'" href="javascript:;" class="mceButton mceButtonEnabled '+s['class']+'" style="width:40px; margin-left: 25px;" onmousedown="return false;" onclick="return false;" title="'+tinymce.DOM.encode(s.title)+'"><img class="mceIcon" style="width:40px;" src="'+s.image+'" /></a>';return h;}});tinymce.PluginManager.requireLangPack('openpne');var config=pne_mce_editor_get_config();tinymce.create('tinymce.plugins.OpenPNEPlugin',{init:function(ed,url){var t=this;ed.settings.content_css=url+"/css/editor.css";ed.addCommand('mceOpenPNE_op_b',function(){tinyMCE.execCommand("Bold");});ed.addCommand('mceOpenPNE_op_u',function(){tinyMCE.execCommand("Underline");});ed.addCommand('mceOpenPNE_op_s',function(){tinyMCE.execCommand("Strikethrough");});ed.addCommand('mceOpenPNE_op_i',function(){tinyMCE.execCommand("Italic");});ed.addCommand('mceOpenPNE_op_large',function(){tinyMCE.execCommand("Fontsize",false,5);});ed.addCommand('mceOpenPNE_op_small',function(){tinyMCE.execCommand("Fontsize",false,1);});ed.addCommand('mceOpenPNE_op_image',function(){window.open(config.op_image.contentURL.unescapeHTML(),'','width=600,height=550,toolbar=no,scrollbars=yes,left=10,top=10');});ed.addCommand('mceOpenPNE_op_cmd',function(){window.open(config.op_cmd.contentURL.unescapeHTML());});for(var key in config){var value=config[key];if(value.isEnabled&&key!="op_color"){ed.addButton(key,{title:'{#openpne.'+key+'}',image:value.imageURL,cmd:'mceOpenPNE_'+key});}}
ed.onBeforeSetContent.add(function(ed,o){o.content=t._textToPreview(o.content);});ed.onPostProcess.add(function(ed,o){if(o.save){if(ed.isHidden()){o.content=ed.getElement().value.replace(/\n\n/g,"\n \n");}else{o.content=t._previewToText(o.content,ed);}}});ed.onNodeChange.add(function(ed,cm,n){cm.setActive('mce_editor_textarea_op_b',false);cm.setActive('mce_editor_textarea_op_u',false);cm.setActive('mce_editor_textarea_op_s',false);cm.setActive('mce_editor_textarea_op_i',false);cm.setActive('mce_editor_textarea_op_large',false);cm.setActive('mce_editor_textarea_op_small',false);var elm=n;while(elm.parentNode){var tagname=t._getTagName(elm);if((tagname=="large"||tagname=="small")&&(cm.get('mce_editor_textarea_op_large').isActive()||cm.get('mce_editor_textarea_op_small').isActive())){elm=elm.parentNode;continue;}
cm.setActive('mce_editor_textarea_op_'+tagname,true);elm=elm.parentNode;}});},createControl:function(n,cm){var c=null;if(n=="op_color"&&config["op_color"].isEnabled){c=this._createOpenPNEColorButton("op_color",{title:"{#openpne.op_color}",image:config["op_color"].imageURL,cmd:"ForeColor"},cm);}
if(n=="op_emoji_docomo"||n=="op_emoji_au"&&config["op_emoji_au"].isEnabled||n=="op_emoji_softbank"&&config["op_emoji_softbank"].isEnabled){var emoji_config={op_emoji_docomo:{carrier:"i",emoji:[{start:1,end:252}],title:"{#openpne."+n+"}",image:config[n].imageURL},op_emoji_au:{carrier:"e",emoji:[{start:1,end:518},{start:700,end:822}],title:"{#openpne."+n+"}",image:config[n].imageURL},op_emoji_softbank:{carrier:"s",emoji:[{start:1,end:485}],title:"{#openpne."+n+"}",image:config[n].imageURL}}
c=this._createOpenPNEEmojiButton(n,emoji_config[n],cm);}
if(n=="op_cmd"&&config["op_cmd"].isEnabled){c=this._createOpenPNECmdButton(n,{title:"{#openpne.op_cmd}",image:config["op_cmd"].imageURL,cmd:"mceOpenPNE_op_cmd"},cm);}
return c;},getInfo:function(){return{longname:'OpenPNE plugin',author:'Kousuke Ebihara',version:"1.0"}},_getTagName:function(elm){var tagname=elm.nodeName.toLowerCase();if(Prototype.Browser.WebKit&&tagname=="span"){if(elm.style.fontWeight=='bold'){return'b';}
if(elm.style.textDecoration=='underline'){return'u';}
if(elm.style.textDecoration=='line-through'){return's';}
if(elm.style.fontStyle=='italic'){return'i';}
if(elm.style.fontSize=='x-large'){return'large';}
if(elm.style.fontSize=='x-small'){return'small';}}else if(tagname!="span"){var convertList={strike:"s",strong:"b",em:"i"};if(convertList[tagname]){return convertList[tagname];}
var size=elm.getAttribute("size");if(tagname=="font"&&size=="5"){return"large";}
if(tagname=="font"&&size=="1"){return"small";}}
return tagname;},_createOpenPNEColorButton:function(id,s,cm){var t=cm,ed=t.editor,cmd,c;if(t.get(id)){return null;}
s.title=ed.translate(s.title);s.scope=s.scope||ed;if(!s.onclick){s.onclick=function(v){ed.execCommand(s.cmd,s.ui||false,v||s.value);};}
if(!s.onselect){s.onselect=function(v){ed.execCommand(s.cmd,s.ui||false,v||s.value);};}
id=t.prefix+id;s=tinymce.extend({title:s.title,'class':'mce_'+id,'menu_class':ed.getParam('skin')+'Skin',scope:s.scope,more_colors_title:ed.getLang('more_colors')},s);c=new tinymce.ui.OpenPNEColorButton(id,s);ed.onMouseDown.add(c.hideMenu,c);ed.onRemove.add(function(){c.destroy();});return t.add(c);},_createOpenPNEEmojiButton:function(id,s,cm){var t=cm,ed=t.editor,cmd,c;if(t.get(id)){return null;}
s.title=ed.translate(s.title);s.scope=s.scope||ed;if(!s.onclick){s.onclick=function(v){ed.execCommand(s.cmd,s.ui||false,v||s.value);};}
if(!s.onselect){s.onselect=function(v){ed.execCommand(s.cmd,s.ui||false,v||s.value);};}
id=t.prefix+id;s=tinymce.extend({title:s.title,'class':'mce_'+id,'menu_class':ed.getParam('skin')+'Skin',scope:s.scope},s);c=new tinymce.ui.OpenPNEEmojiButton(id,s);ed.onMouseDown.add(c.hideMenu,c);ed.onRemove.add(function(){c.destroy();});return t.add(c);},_createOpenPNECmdButton:function(id,s,cm){var t=cm,ed=t.editor,cmd,c;if(t.get(id)){return null;}
s.title=ed.translate(s.title);s.scope=s.scope||ed;if(!s.onclick){s.onclick=function(v){ed.execCommand(s.cmd,s.ui||false,v||s.value);};}
if(!s.onselect){s.onselect=function(v){ed.execCommand(s.cmd,s.ui||false,v||s.value);};}
id=t.prefix+id;s=tinymce.extend({title:s.title,'class':'mce_'+id,'menu_class':ed.getParam('skin')+'Skin',scope:s.scope},s);c=new tinymce.ui.OpenPNECmdButton(id,s);ed.onPostRender.add(function(){var parentContainer=document.getElementById(c.id).parentNode;parentContainer.style.width="70px";});ed.onRemove.add(function(){c.destroy();});return t.add(c);},_previewToText:function(s,editor){var editorDoc=editor.getBody();function rep(re,str){s=s.replace(re,str);};if(!tinymce.isWebKit){s=tinymce.trim(s);rep('/<(\/?)strong>/gi','<\1b>');rep('/<(\/?)strike>/gi','<\1s>');rep('/<(\/?)em>/gi','<\1i>');editor.dom.setHTML(editor.getBody(),s);}
function convertHtmlTagToDecoTag(doc,tagname)
{var tagList=doc.getElementsByTagName(tagname);var org_tagname=tagname;var args={};if(Prototype.Browser.IE&&org_tagname!="font"){return;}
while(tagList.length){targetObj=tagList[0];args={};if(org_tagname=="font"){var size=targetObj.getAttribute("size");var color=targetObj.getAttribute("color");if(size&&color){if(tinymce.isIE){targetObj.removeAttribute("color");targetObj.innerHTML='<font color="'+color+'">'+targetObj.innerHTML+"</font>";}else{var fontSize=document.createElement("font");fontSize.setAttribute("size",size);fontSize.removeAttribute("color");var clone=targetObj.cloneNode(true);clone.removeAttribute("size");fontSize.appendChild(clone);targetObj.parentNode.replaceChild(fontSize,targetObj);}
tagList=doc.getElementsByTagName(org_tagname);continue;}
if(size=='5'){tagname='op:large';}else if(size=='1'){tagname='op:small';}
if(color){tagname='op:color';args={code:color};}
if(tagname==org_tagname){editor.dom.remove(targetObj,true);tagList=doc.getElementsByTagName(org_tagname);continue;}}else if(org_tagname=='span'){if(targetObj.style.fontWeight=='bold'){tagname='op:b';}else if(targetObj.style.textDecoration=='underline'){tagname='op:u';}else if(targetObj.style.textDecoration=='line-through'){tagname='op:s';}else if(targetObj.style.fontStyle=='italic'){tagname='op:i';}else if(targetObj.style.color){var color=tinyMCE.activeEditor.dom.toHex(targetObj.style.color);tagname='op:color';args={code:color};}else if(targetObj.style.fontSize=='x-large'){tagname='op:large';}else if(targetObj.style.fontSize=='x-small'){tagname='op:small';}else{editor.dom.remove(targetObj,true);continue;}}else{tagname='op:'+org_tagname;}
if(tinymce.isIE){tagname=tagname.replace("op:","op");}
var newObj=editor.dom.create(tagname);editor.dom.setAttribs(newObj,args);if(tinymce.isIE){newObj.innerHTML=targetObj.innerHTML;targetObj.parentNode.replaceChild(newObj,targetObj);}else{editor.dom.replace(newObj,targetObj,true);}
tagList=doc.getElementsByTagName(org_tagname);}
s=editorDoc.innerHTML;}
var convertList=new Array('span','font','b','u','s','i');for(var i=0;i<convertList.length;i++){convertHtmlTagToDecoTag(editor.getBody(),convertList[i]);}
rep(/<\/?div>/gi,"");if(Prototype.Browser.IE){rep(/<(\/?)(b|u|s|i)>/gi,'<$1op:$2>');rep(/<(\/?)op(large|small|color)/gi,'<$1op:$2');}
rep(/<br\s?\/?[^>]*>/gi,"\n\n");rep(/&nbsp;/gi," ");rep(/&quot;/gi,"\"");rep(/&lt;/gi,"<");rep(/&gt;/gi,">");rep(/&amp;/gi,"&");return s;},_textToPreview:function(s){s=tinymce.trim(s);var rule=/&lt;op:(b|u|s|i|large|small|color)( code="(#[0-9a-f]{3,6})"|)&gt;(.*?)&lt;\/op:\1&gt;/i;function rep(re,str){s=s.replace(re,str);};rep(/</gi,"&lt;");rep(/>/gi,"&gt;");rep(/\n/gi,"<br />");rep(/&lt;(\/|)op:(b|u|s|i|large|small|color)( code="(#[0-9a-f]{3,6})"|)&gt;/gi,function(str,isEndTag,org_tagname,isColor,color){var opt="";var tagname=org_tagname;if(tagname=="color"||tagname=="large"||tagname=="small"){tagname="font";}
if(isEndTag){return"</"+tagname+">";}
if(org_tagname=="color"&&color){opt=' color="'+color+'"';}
if(org_tagname=="large"){opt=' size="5"';}
if(org_tagname=="small"){opt=' size="1"';}
return"<"+tagname+opt+">";});return s;}});tinymce.PluginManager.add('openpne',tinymce.plugins.OpenPNEPlugin);})();