tinymce-editor/copy_this/modules/hdi/hdi-tinymce/tinymce/plugins/fullpage/plugin.min.js
2013-07-25 23:50:43 +02:00

1 line
5.5 KiB
JavaScript
Executable File

tinymce.PluginManager.add("fullpage",function(e){function t(){var t=l();e.windowManager.open({title:"Document properties",data:t,defaults:{type:"textbox",size:40},body:[{name:"title",label:"Title"},{name:"keywords",label:"Keywords"},{name:"description",label:"Description"},{name:"robots",label:"Robots"},{name:"author",label:"Author"},{name:"docencoding",label:"Encoding"}],onSubmit:function(e){n(tinymce.extend(t,e.data))}})}function l(){function t(e,t){var l=e.attr(t);return l||""}var l,n,a=i(),o={};return o.fontface=e.getParam("fullpage_default_fontface",""),o.fontsize=e.getParam("fullpage_default_fontsize",""),l=a.firstChild,7==l.type&&(o.xml_pi=!0,n=/encoding="([^"]+)"/.exec(l.value),n&&(o.docencoding=n[1])),l=a.getAll("#doctype")[0],l&&(o.doctype="<!DOCTYPE"+l.value+">"),l=a.getAll("title")[0],l&&l.firstChild&&(o.title=l.firstChild.value),c(a.getAll("meta"),function(e){var t,l=e.attr("name"),n=e.attr("http-equiv");l?o[l.toLowerCase()]=e.attr("content"):"Content-Type"==n&&(t=/charset\s*=\s*(.*)\s*/gi.exec(e.attr("content")),t&&(o.docencoding=t[1]))}),l=a.getAll("html")[0],l&&(o.langcode=t(l,"lang")||t(l,"xml:lang")),l=a.getAll("link")[0],l&&"stylesheet"==l.attr("rel")&&(o.stylesheet=l.attr("href")),l=a.getAll("body")[0],l&&(o.langdir=t(l,"dir"),o.style=t(l,"style"),o.visited_color=t(l,"vlink"),o.link_color=t(l,"link"),o.active_color=t(l,"alink")),o}function n(t){function l(e,t,l){e.attr(t,l?l:void 0)}function n(e){o.firstChild?o.insert(e,o.firstChild):o.append(e)}var a,o,r,s,m,u=e.dom;a=i(),o=a.getAll("head")[0],o||(s=a.getAll("html")[0],o=new g("head",1),s.firstChild?s.insert(o,s.firstChild,!0):s.append(o)),s=a.firstChild,t.xml_pi?(m='version="1.0"',t.docencoding&&(m+=' encoding="'+t.docencoding+'"'),7!=s.type&&(s=new g("xml",7),a.insert(s,a.firstChild,!0)),s.value=m):s&&7==s.type&&s.remove(),s=a.getAll("#doctype")[0],t.doctype?(s||(s=new g("#doctype",10),t.xml_pi?a.insert(s,a.firstChild):n(s)),s.value=t.doctype.substring(9,t.doctype.length-1)):s&&s.remove(),t.docencoding&&(s=null,c(a.getAll("meta"),function(e){"Content-Type"==e.attr("http-equiv")&&(s=e)}),s||(s=new g("meta",1),s.attr("http-equiv","Content-Type"),s.shortEnded=!0,n(s)),s.attr("content","text/html; charset="+t.docencoding)),s=a.getAll("title")[0],t.title?s||(s=new g("title",1),s.append(new g("#text",3)).value=t.title,n(s)):s&&s.remove(),c("keywords,description,author,copyright,robots".split(","),function(e){var l,i,o=a.getAll("meta"),r=t[e];for(l=0;l<o.length;l++)if(i=o[l],i.attr("name")==e)return r?i.attr("content",r):i.remove(),void 0;r&&(s=new g("meta",1),s.attr("name",e),s.attr("content",r),s.shortEnded=!0,n(s))}),s=a.getAll("link")[0],s&&"stylesheet"==s.attr("rel")?t.stylesheet?s.attr("href",t.stylesheet):s.remove():t.stylesheet&&(s=new g("link",1),s.attr({rel:"stylesheet",text:"text/css",href:t.stylesheet}),s.shortEnded=!0,n(s)),s=a.getAll("body")[0],s&&(l(s,"dir",t.langdir),l(s,"style",t.style),l(s,"vlink",t.visited_color),l(s,"link",t.link_color),l(s,"alink",t.active_color),u.setAttribs(e.getBody(),{style:t.style,dir:t.dir,vLink:t.visited_color,link:t.link_color,aLink:t.active_color})),s=a.getAll("html")[0],s&&(l(s,"lang",t.langcode),l(s,"xml:lang",t.langcode)),o.firstChild||o.remove(),r=new tinymce.html.Serializer({validate:!1,indent:!0,apply_source_formatting:!0,indent_before:"head,html,body,meta,title,script,link,style",indent_after:"head,html,body,meta,title,script,link,style"}).serialize(a),d=r.substring(0,r.indexOf("</body>"))}function i(){return new tinymce.html.DomParser({validate:!1,root_name:"#document"}).parse(d)}function a(t){function l(e){return e.replace(/<\/?[A-Z]+/g,function(e){return e.toLowerCase()})}var n,a,r,g,m=t.content,u="",f=e.dom;t.selection||"raw"==t.format&&d||t.source_view&&e.getParam("fullpage_hide_in_source_view")||(m=m.replace(/<(\/?)BODY/gi,"<$1body"),n=m.indexOf("<body"),-1!=n?(n=m.indexOf(">",n),d=l(m.substring(0,n+1)),a=m.indexOf("</body",n),-1==a&&(a=m.length),t.content=m.substring(n+1,a),s=l(m.substring(a))):(d=o(),s="\n</body>\n</html>"),r=i(),c(r.getAll("style"),function(e){e.firstChild&&(u+=e.firstChild.value)}),g=r.getAll("body")[0],g&&f.setAttribs(e.getBody(),{style:g.attr("style")||"",dir:g.attr("dir")||"",vLink:g.attr("vlink")||"",link:g.attr("link")||"",aLink:g.attr("alink")||""}),f.remove("fullpage_styles"),u&&(f.add(e.getDoc().getElementsByTagName("head")[0],"style",{id:"fullpage_styles"},u),g=f.get("fullpage_styles"),g.styleSheet&&(g.styleSheet.cssText=u)))}function o(){var t,l="",n="";return e.getParam("fullpage_default_xml_pi")&&(l+='<?xml version="1.0" encoding="'+e.getParam("fullpage_default_encoding","ISO-8859-1")+'" ?>\n'),l+=e.getParam("fullpage_default_doctype","<!DOCTYPE html>"),l+="\n<html>\n<head>\n",(t=e.getParam("fullpage_default_title"))&&(l+="<title>"+t+"</title>\n"),(t=e.getParam("fullpage_default_encoding"))&&(l+='<meta http-equiv="Content-Type" content="text/html; charset='+t+'" />\n'),(t=e.getParam("fullpage_default_font_family"))&&(n+="font-family: "+t+";"),(t=e.getParam("fullpage_default_font_size"))&&(n+="font-size: "+t+";"),(t=e.getParam("fullpage_default_text_color"))&&(n+="color: "+t+";"),l+="</head>\n<body"+(n?' style="'+n+'"':"")+">\n"}function r(t){t.selection||t.source_view&&e.getParam("fullpage_hide_in_source_view")||(t.content=tinymce.trim(d)+"\n"+tinymce.trim(t.content)+"\n"+tinymce.trim(s))}var d,s,c=tinymce.each,g=tinymce.html.Node;e.addCommand("mceFullPageProperties",t),e.addButton("fullpage",{title:"Document properties",cmd:"mceFullPageProperties"}),e.addMenuItem("fullpage",{text:"Document properties",cmd:"mceFullPageProperties",context:"file"}),e.on("BeforeSetContent",a),e.on("GetContent",r)});