﻿var InitializedTinyMCEInstances={};function TinyMCEConfig(id){this.id=id;this.widget_config=eval("("+document.getElementById(this.id).title+")");this.toolbars=[];this.init=function(){if(typeof InitializedTinyMCEInstances[this.id]!="undefined")return;InitializedTinyMCEInstances[this.id]=1;this.initToolbars();var c=document.getElementById(this.id+"_text_format");if(c&&c.tagName.toLowerCase()=="input"&&c.value.indexOf("html")==-1)return;var a=tinymce.DOM.get(this.id);a=tinymce.DOM.getParent(a,".ArchetypesRichWidget");if(a!=null){a=tinymce.DOM.select("div.fieldTextFormat",a);if(a.length>0){tinymce.DOM.select("select",a[0])[0].value="text/html";tinymce.DOM.setStyle(a[0],"display","none")}}for(var b=0;b<this.widget_config.customplugins.length;b++)if(this.widget_config.customplugins[b].indexOf("|")!=-1){e=this.widget_config.customplugins[b].split("|");tinymce.PluginManager.load(e[0],config.getPortalUrl()+e[1])}window.tinyMCE.init({mode:"exact",elements:this.id,strict_loading_mode:true,theme:"advanced",language:this.getLanguage(),skin:"plone",inlinepopups_skin:"plonepopup",plugins:this.getPlugins(),theme_advanced_styles:this.getStyles(),theme_advanced_buttons1:this.getToolbar(0),theme_advanced_buttons2:this.getToolbar(1),theme_advanced_buttons3:this.getToolbar(2),theme_advanced_buttons4:this.getToolbar(3),theme_advanced_toolbar_location:this.getToolbarLocation(),theme_advanced_toolbar_align:"left",theme_advanced_path_location:this.getPathLocation(),theme_advanced_path:false,theme_advanced_resizing:this.getResizing(),theme_advanced_resizing_use_cookie:this.getResizingUseCookie(),theme_advanced_resize_horizontal:this.getResizeHorizontal(),theme_advanced_source_editor_width:this.getEditorWidth(),theme_advanced_source_editor_height:this.getEditorHeight(),table_styles:this.getTableStyles(),directionality:this.getDirectionality(),entity_encoding:this.getEntityEncoding(),content_css:this.getContentCSS(),body_class:"documentContent",document_base_url:this.getBase(),document_url:this.getDocumentUrl(),portal_url:this.getPortalUrl(),livesearch:this.getLivesearch(),valid_elements:this.getValidElements(),link_using_uids:this.getLinkUsingUids(),allow_captioned_images:this.getAllowCaptionedImages(),rooted:this.getRooted(),force_span_wrappers:true,fix_list_elements:false})};this.getButtonWidth=function(a){switch(a){case "style":return 150;case "forecolor":return 32;case "backcolor":return 32;case "tablecontrols":return 285}return 23};this.getTableStyles=function(){return this.widget_config.table_styles.join(";")};this.getToolbar=function(a){return this.toolbars[a]};this.initToolbars=function(){var a=[[],[],[],[]],d=0,e=0,b;for(var c=0;c<this.widget_config.buttons.length;c++){b=this.getButtonWidth(this.widget_config.buttons[c]);if(e+b>this.widget_config.toolbar_width){e=b;d++}else e+=b;if(d<=3)a[d].push(this.widget_config.buttons[c])}this.toolbars=[a[0].join(","),a[1].join(","),a[2].join(","),a[3].join(",")]};this.getStyles=function(){var a={Text:[],Selection:[],Tables:[],Lists:[],Print:[]},c="";a["Text"].push('{ title: "Text", tag: "", className: "-", type: "Text" }');a["Selection"].push('{ title: "Selection", tag: "", className: "-", type: "Selection" }');a["Tables"].push('{ title: "Tables", tag: "table", className: "-", type: "Tables" }');a["Lists"].push('{ title: "Lists", tag: "ul", className: "-", type: "Lists" }');a["Lists"].push('{ title: "Lists", tag: "ol", className: "-", type: "Lists" }');a["Lists"].push('{ title: "Lists", tag: "dl", className: "-", type: "Lists" }');a["Print"].push('{ title: "Print", tag: "", className: "-", type: "Print" }');a["Text"].push('{ title: "Normal paragraph", tag: "p", className: "", type: "Text" }');a["Lists"].push('{ title: "Disc", tag: "ul", className: "", listType: "disc", type: "Lists" }');a["Lists"].push('{ title: "Square", tag: "ul", className: "", listType: "square", type: "Lists" }');a["Lists"].push('{ title: "Circle", tag: "ul", className: "", listType: "circle", type: "Lists" }');a["Lists"].push('{ title: "Numbers", tag: "ol", className: "", listType: "1", type: "Lists" }');a["Lists"].push('{ title: "Lower Alpha", tag: "ol", className: "", listType: "a", type: "Lists" }');a["Lists"].push('{ title: "Upper Alpha", tag: "ol", className: "", listType: "A", type: "Lists" }');a["Lists"].push('{ title: "Lower Roman", tag: "ol", className: "", listType: "i", type: "Lists" }');a["Lists"].push('{ title: "Upper Roman", tag: "ol", className: "", listType: "I", type: "Lists" }');a["Lists"].push('{ title: "Definition term", tag: "dt", className: "", listType: "", type: "Lists" }');a["Lists"].push('{ title: "Definition description", tag: "dd", className: "", listType: "", type: "Lists" }');for(var b=0;b<this.widget_config.styles.length;b++){e=this.widget_config.styles[b].split("|");if(e.length<=2)e[2]="";switch(e[1].toLowerCase()){case "span":c="Selection";break;case "tr":case "td":case "th":case "table":c="Tables";break;default:c="Text"}if(e[2]=="pageBreak")c="Print";a[c].push('{ title: "'+e[0]+'", tag: "'+e[1]+'", className: "'+e[2]+'", type: "'+c+'" }')}a["Selection"].push('{ title: "(remove style)", tag: "", className: "", type: "Selection" }');a["Tables"].push('{ title: "Plain cell", tag: "td", className: "", type: "Tables" }');var d=[];if(a["Text"].length>1)for(var b=0;b<a["Text"].length;b++)d.push(a["Text"][b]);if(a["Selection"].length>1)for(var b=0;b<a["Selection"].length;b++)d.push(a["Selection"][b]);if(a["Tables"].length>1)for(var b=0;b<a["Tables"].length;b++)d.push(a["Tables"][b]);if(a["Lists"].length>1)for(var b=0;b<a["Lists"].length;b++)d.push(a["Lists"][b]);if(a["Print"].length>1)for(var b=0;b<a["Print"].length;b++)d.push(a["Print"][b]);return "["+d.join(",")+"]"};this.getValidElements=function(){a=[];for(var b in this.widget_config.valid_elements){var c=b;if(this.widget_config.valid_elements[b].length>0)c+="["+this.widget_config.valid_elements[b].join("|")+"]";a.push(c)}return a.join(",")};this.getDocumentUrl=function(){return this.widget_config.document_url};this.getBase=function(){return this.widget_config.parent};this.getToolbarLocation=function(){return this.widget_config.toolbar_location};this.getPathLocation=function(){return this.widget_config.path_location};this.getResizing=function(){return this.widget_config.resizing};this.getResizingUseCookie=function(){return this.widget_config.resizing_use_cookie};this.getResizeHorizontal=function(){return this.widget_config.resize_horizontal};this.getEditorWidth=function(){return this.widget_config.editor_width};this.getEditorHeight=function(){return this.widget_config.editor_height};this.getDirectionality=function(){return this.widget_config.directionality};this.getEntityEncoding=function(){return this.widget_config.entity_encoding};this.getContentCSS=function(){return this.widget_config.content_css};this.getLanguage=function(){return this.widget_config.language};this.getLinkUsingUids=function(){return this.widget_config.link_using_uids};this.getAllowCaptionedImages=function(){return this.widget_config.allow_captioned_images};this.getRooted=function(){return this.widget_config.rooted};this.getPortalUrl=function(){return this.widget_config.portal_url};this.getLivesearch=function(){return this.widget_config.livesearch};this.getPlugins=function(){var a="safari,pagebreak,table,save,advhr,emotions,iespell,insertdatetime,preview,media,searchreplace,print,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,inlinepopups,plonestyle,tabfocus,definitionlist";for(var b=0;b<this.widget_config.customplugins.length;b++)if(this.widget_config.customplugins[b].indexOf("|")==-1)a+=","+this.widget_config.customplugins[b];if(this.widget_config.contextmenu)a+=",contextmenu";if(this.widget_config.autoresize)a+=",autoresize";return a}}if(typeof kukit!="undefined"){kukit.actionsGlobalRegistry.register("init-tinymce",function(b){var a=new TinyMCEConfig(b.node.id);a.init()});kukit.actionsGlobalRegistry.register("save-tinymce",function(){tinymce.EditorManager.activeEditor.save()})}