summaryrefslogtreecommitdiff
path: root/program/js/tinymce/plugins/fullpage/plugin.min.js
blob: c0dfa2d3ded282f3b208a4bb7032f2c5c4fd0238 (plain)
1
tinymce.PluginManager.add("fullpage",function(e){function t(){var t=n();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){l(tinymce.extend(t,e.data))}})}function n(){function t(e,t){var n=e.attr(t);return n||""}var n,l,a=i(),r={};return r.fontface=e.getParam("fullpage_default_fontface",""),r.fontsize=e.getParam("fullpage_default_fontsize",""),n=a.firstChild,7==n.type&&(r.xml_pi=!0,l=/encoding="([^"]+)"/.exec(n.value),l&&(r.docencoding=l[1])),n=a.getAll("#doctype")[0],n&&(r.doctype="<!DOCTYPE"+n.value+">"),n=a.getAll("title")[0],n&&n.firstChild&&(r.title=n.firstChild.value),s(a.getAll("meta"),function(e){var t,n=e.attr("name"),l=e.attr("http-equiv");n?r[n.toLowerCase()]=e.attr("content"):"Content-Type"==l&&(t=/charset\s*=\s*(.*)\s*/gi.exec(e.attr("content")),t&&(r.docencoding=t[1]))}),n=a.getAll("html")[0],n&&(r.langcode=t(n,"lang")||t(n,"xml:lang")),r.stylesheets=[],tinymce.each(a.getAll("link"),function(e){"stylesheet"==e.attr("rel")&&r.stylesheets.push(e.attr("href"))}),n=a.getAll("body")[0],n&&(r.langdir=t(n,"dir"),r.style=t(n,"style"),r.visited_color=t(n,"vlink"),r.link_color=t(n,"link"),r.active_color=t(n,"alink")),r}function l(t){function n(e,t,n){e.attr(t,n?n:void 0)}function l(e){r.firstChild?r.insert(e,r.firstChild):r.append(e)}var a,r,o,d,u,g=e.dom;a=i(),r=a.getAll("head")[0],r||(d=a.getAll("html")[0],r=new m("head",1),d.firstChild?d.insert(r,d.firstChild,!0):d.append(r)),d=a.firstChild,t.xml_pi?(u='version="1.0"',t.docencoding&&(u+=' encoding="'+t.docencoding+'"'),7!=d.type&&(d=new m("xml",7),a.insert(d,a.firstChild,!0)),d.value=u):d&&7==d.type&&d.remove(),d=a.getAll("#doctype")[0],t.doctype?(d||(d=new m("#doctype",10),t.xml_pi?a.insert(d,a.firstChild):l(d)),d.value=t.doctype.substring(9,t.doctype.length-1)):d&&d.remove(),d=null,s(a.getAll("meta"),function(e){"Content-Type"==e.attr("http-equiv")&&(d=e)}),t.docencoding?(d||(d=new m("meta",1),d.attr("http-equiv","Content-Type"),d.shortEnded=!0,l(d)),d.attr("content","text/html; charset="+t.docencoding)):d&&d.remove(),d=a.getAll("title")[0],t.title?(d?d.empty():(d=new m("title",1),l(d)),d.append(new m("#text",3)).value=t.title):d&&d.remove(),s("keywords,description,author,copyright,robots".split(","),function(e){var n,i,r=a.getAll("meta"),o=t[e];for(n=0;n<r.length;n++)if(i=r[n],i.attr("name")==e)return void(o?i.attr("content",o):i.remove());o&&(d=new m("meta",1),d.attr("name",e),d.attr("content",o),d.shortEnded=!0,l(d))});var f={};tinymce.each(a.getAll("link"),function(e){"stylesheet"==e.attr("rel")&&(f[e.attr("href")]=e)}),tinymce.each(t.stylesheets,function(e){f[e]||(d=new m("link",1),d.attr({rel:"stylesheet",text:"text/css",href:e}),d.shortEnded=!0,l(d)),delete f[e]}),tinymce.each(f,function(e){e.remove()}),d=a.getAll("body")[0],d&&(n(d,"dir",t.langdir),n(d,"style",t.style),n(d,"vlink",t.visited_color),n(d,"link",t.link_color),n(d,"alink",t.active_color),g.setAttribs(e.getBody(),{style:t.style,dir:t.dir,vLink:t.visited_color,link:t.link_color,aLink:t.active_color})),d=a.getAll("html")[0],d&&(n(d,"lang",t.langcode),n(d,"xml:lang",t.langcode)),r.firstChild||r.remove(),o=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),c=o.substring(0,o.indexOf("</body>"))}function i(){return new tinymce.html.DomParser({validate:!1,root_name:"#document"}).parse(c)}function a(t){function n(e){return e.replace(/<\/?[A-Z]+/g,function(e){return e.toLowerCase()})}var l,a,o,m,u=t.content,g="",f=e.dom;if(!t.selection&&!("raw"==t.format&&c||t.source_view&&e.getParam("fullpage_hide_in_source_view"))){0!==u.length||t.source_view||(u=tinymce.trim(c)+"\n"+tinymce.trim(u)+"\n"+tinymce.trim(d)),u=u.replace(/<(\/?)BODY/gi,"<$1body"),l=u.indexOf("<body"),-1!=l?(l=u.indexOf(">",l),c=n(u.substring(0,l+1)),a=u.indexOf("</body",l),-1==a&&(a=u.length),t.content=u.substring(l+1,a),d=n(u.substring(a))):(c=r(),d="\n</body>\n</html>"),o=i(),s(o.getAll("style"),function(e){e.firstChild&&(g+=e.firstChild.value)}),m=o.getAll("body")[0],m&&f.setAttribs(e.getBody(),{style:m.attr("style")||"",dir:m.attr("dir")||"",vLink:m.attr("vlink")||"",link:m.attr("link")||"",aLink:m.attr("alink")||""}),f.remove("fullpage_styles");var y=e.getDoc().getElementsByTagName("head")[0];g&&(f.add(y,"style",{id:"fullpage_styles"},g),m=f.get("fullpage_styles"),m.styleSheet&&(m.styleSheet.cssText=g));var h={};tinymce.each(y.getElementsByTagName("link"),function(e){"stylesheet"==e.rel&&e.getAttribute("data-mce-fullpage")&&(h[e.href]=e)}),tinymce.each(o.getAll("link"),function(e){var t=e.attr("href");h[t]||"stylesheet"!=e.attr("rel")||f.add(y,"link",{rel:"stylesheet",text:"text/css",href:t,"data-mce-fullpage":"1"}),delete h[t]}),tinymce.each(h,function(e){e.parentNode.removeChild(e)})}}function r(){var t,n="",l="";return e.getParam("fullpage_default_xml_pi")&&(n+='<?xml version="1.0" encoding="'+e.getParam("fullpage_default_encoding","ISO-8859-1")+'" ?>\n'),n+=e.getParam("fullpage_default_doctype","<!DOCTYPE html>"),n+="\n<html>\n<head>\n",(t=e.getParam("fullpage_default_title"))&&(n+="<title>"+t+"</title>\n"),(t=e.getParam("fullpage_default_encoding"))&&(n+='<meta http-equiv="Content-Type" content="text/html; charset='+t+'" />\n'),(t=e.getParam("fullpage_default_font_family"))&&(l+="font-family: "+t+";"),(t=e.getParam("fullpage_default_font_size"))&&(l+="font-size: "+t+";"),(t=e.getParam("fullpage_default_text_color"))&&(l+="color: "+t+";"),n+="</head>\n<body"+(l?' style="'+l+'"':"")+">\n"}function o(t){t.selection||t.source_view&&e.getParam("fullpage_hide_in_source_view")||(t.content=tinymce.trim(c)+"\n"+tinymce.trim(t.content)+"\n"+tinymce.trim(d))}var c,d,s=tinymce.each,m=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",o)});