annotate WebContent/jscripts/tiny_mce/plugins/fullpage/editor_plugin_src.js @ 5:0be9d53a6967

editor for annotations
author dwinter
date Tue, 13 Dec 2011 17:43:46 +0100
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
1 /**
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
2 * editor_plugin_src.js
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
3 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
4 * Copyright 2009, Moxiecode Systems AB
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
5 * Released under LGPL License.
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
6 *
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
7 * License: http://tinymce.moxiecode.com/license
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
8 * Contributing: http://tinymce.moxiecode.com/contributing
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
9 */
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
10
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
11 (function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
12 var each = tinymce.each, Node = tinymce.html.Node;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
13
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
14 tinymce.create('tinymce.plugins.FullPagePlugin', {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
15 init : function(ed, url) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
16 var t = this;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
17
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
18 t.editor = ed;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
19
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
20 // Register commands
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
21 ed.addCommand('mceFullPageProperties', function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
22 ed.windowManager.open({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
23 file : url + '/fullpage.htm',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
24 width : 430 + parseInt(ed.getLang('fullpage.delta_width', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
25 height : 495 + parseInt(ed.getLang('fullpage.delta_height', 0)),
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
26 inline : 1
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
27 }, {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
28 plugin_url : url,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
29 data : t._htmlToData()
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
30 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
31 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
32
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
33 // Register buttons
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
34 ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'});
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
35
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
36 ed.onBeforeSetContent.add(t._setContent, t);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
37 ed.onGetContent.add(t._getContent, t);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
38 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
39
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
40 getInfo : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
41 return {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
42 longname : 'Fullpage',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
43 author : 'Moxiecode Systems AB',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
44 authorurl : 'http://tinymce.moxiecode.com',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
45 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
46 version : tinymce.majorVersion + "." + tinymce.minorVersion
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
47 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
48 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
49
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
50 // Private plugin internal methods
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
51
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
52 _htmlToData : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
53 var headerFragment = this._parseHeader(), data = {}, nodes, elm, matches, editor = this.editor;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
54
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
55 function getAttr(elm, name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
56 var value = elm.attr(name);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
57
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
58 return value || '';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
59 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
60
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
61 // Default some values
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
62 data.fontface = editor.getParam("fullpage_default_fontface", "");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
63 data.fontsize = editor.getParam("fullpage_default_fontsize", "");
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
64
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
65 // Parse XML PI
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
66 elm = headerFragment.firstChild;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
67 if (elm.type == 7) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
68 data.xml_pi = true;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
69 matches = /encoding="([^"]+)"/.exec(elm.value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
70 if (matches)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
71 data.docencoding = matches[1];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
72 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
73
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
74 // Parse doctype
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
75 elm = headerFragment.getAll('#doctype')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
76 if (elm)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
77 data.doctype = '<!DOCTYPE' + elm.value + ">";
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
78
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
79 // Parse title element
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
80 elm = headerFragment.getAll('title')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
81 if (elm && elm.firstChild) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
82 data.metatitle = elm.firstChild.value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
83 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
84
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
85 // Parse meta elements
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
86 each(headerFragment.getAll('meta'), function(meta) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
87 var name = meta.attr('name'), httpEquiv = meta.attr('http-equiv'), matches;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
88
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
89 if (name)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
90 data['meta' + name.toLowerCase()] = meta.attr('content');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
91 else if (httpEquiv == "Content-Type") {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
92 matches = /charset\s*=\s*(.*)\s*/gi.exec(meta.attr('content'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
93
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
94 if (matches)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
95 data.docencoding = matches[1];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
96 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
97 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
98
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
99 // Parse html attribs
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
100 elm = headerFragment.getAll('html')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
101 if (elm)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
102 data.langcode = getAttr(elm, 'lang') || getAttr(elm, 'xml:lang');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
103
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
104 // Parse stylesheet
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
105 elm = headerFragment.getAll('link')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
106 if (elm && elm.attr('rel') == 'stylesheet')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
107 data.stylesheet = elm.attr('href');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
108
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
109 // Parse body parts
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
110 elm = headerFragment.getAll('body')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
111 if (elm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
112 data.langdir = getAttr(elm, 'dir');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
113 data.style = getAttr(elm, 'style');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
114 data.visited_color = getAttr(elm, 'vlink');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
115 data.link_color = getAttr(elm, 'link');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
116 data.active_color = getAttr(elm, 'alink');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
117 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
118
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
119 return data;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
120 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
121
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
122 _dataToHtml : function(data) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
123 var headerFragment, headElement, html, elm, value, dom = this.editor.dom;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
124
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
125 function setAttr(elm, name, value) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
126 elm.attr(name, value ? value : undefined);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
127 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
128
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
129 function addHeadNode(node) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
130 if (headElement.firstChild)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
131 headElement.insert(node, headElement.firstChild);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
132 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
133 headElement.append(node);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
134 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
135
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
136 headerFragment = this._parseHeader();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
137 headElement = headerFragment.getAll('head')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
138 if (!headElement) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
139 elm = headerFragment.getAll('html')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
140 headElement = new Node('head', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
141
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
142 if (elm.firstChild)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
143 elm.insert(headElement, elm.firstChild, true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
144 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
145 elm.append(headElement);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
146 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
147
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
148 // Add/update/remove XML-PI
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
149 elm = headerFragment.firstChild;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
150 if (data.xml_pi) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
151 value = 'version="1.0"';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
152
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
153 if (data.docencoding)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
154 value += ' encoding="' + data.docencoding + '"';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
155
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
156 if (elm.type != 7) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
157 elm = new Node('xml', 7);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
158 headerFragment.insert(elm, headerFragment.firstChild, true);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
159 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
160
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
161 elm.value = value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
162 } else if (elm && elm.type == 7)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
163 elm.remove();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
164
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
165 // Add/update/remove doctype
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
166 elm = headerFragment.getAll('#doctype')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
167 if (data.doctype) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
168 if (!elm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
169 elm = new Node('#doctype', 10);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
170
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
171 if (data.xml_pi)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
172 headerFragment.insert(elm, headerFragment.firstChild);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
173 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
174 addHeadNode(elm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
175 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
176
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
177 elm.value = data.doctype.substring(9, data.doctype.length - 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
178 } else if (elm)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
179 elm.remove();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
180
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
181 // Add/update/remove title
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
182 elm = headerFragment.getAll('title')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
183 if (data.metatitle) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
184 if (!elm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
185 elm = new Node('title', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
186 elm.append(new Node('#text', 3)).value = data.metatitle;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
187 addHeadNode(elm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
188 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
189 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
190
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
191 // Add meta encoding
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
192 if (data.docencoding) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
193 elm = null;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
194 each(headerFragment.getAll('meta'), function(meta) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
195 if (meta.attr('http-equiv') == 'Content-Type')
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
196 elm = meta;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
197 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
198
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
199 if (!elm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
200 elm = new Node('meta', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
201 elm.attr('http-equiv', 'Content-Type');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
202 elm.shortEnded = true;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
203 addHeadNode(elm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
204 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
205
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
206 elm.attr('content', 'text/html; charset=' + data.docencoding);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
207 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
208
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
209 // Add/update/remove meta
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
210 each('keywords,description,author,copyright,robots'.split(','), function(name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
211 var nodes = headerFragment.getAll('meta'), i, meta, value = data['meta' + name];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
212
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
213 for (i = 0; i < nodes.length; i++) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
214 meta = nodes[i];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
215
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
216 if (meta.attr('name') == name) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
217 if (value)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
218 meta.attr('content', value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
219 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
220 meta.remove();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
221
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
222 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
223 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
224 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
225
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
226 if (value) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
227 elm = new Node('meta', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
228 elm.attr('name', name);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
229 elm.attr('content', value);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
230 elm.shortEnded = true;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
231
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
232 addHeadNode(elm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
233 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
234 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
235
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
236 // Add/update/delete link
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
237 elm = headerFragment.getAll('link')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
238 if (elm && elm.attr('rel') == 'stylesheet') {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
239 if (data.stylesheet)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
240 elm.attr('href', data.stylesheet);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
241 else
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
242 elm.remove();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
243 } else if (data.stylesheet) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
244 elm = new Node('link', 1);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
245 elm.attr({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
246 rel : 'stylesheet',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
247 text : 'text/css',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
248 href : data.stylesheet
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
249 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
250 elm.shortEnded = true;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
251
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
252 addHeadNode(elm);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
253 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
254
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
255 // Update body attributes
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
256 elm = headerFragment.getAll('body')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
257 if (elm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
258 setAttr(elm, 'dir', data.langdir);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
259 setAttr(elm, 'style', data.style);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
260 setAttr(elm, 'vlink', data.visited_color);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
261 setAttr(elm, 'link', data.link_color);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
262 setAttr(elm, 'alink', data.active_color);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
263
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
264 // Update iframe body as well
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
265 dom.setAttribs(this.editor.getBody(), {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
266 style : data.style,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
267 dir : data.dir,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
268 vLink : data.visited_color,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
269 link : data.link_color,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
270 aLink : data.active_color
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
271 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
272 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
273
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
274 // Set html attributes
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
275 elm = headerFragment.getAll('html')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
276 if (elm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
277 setAttr(elm, 'lang', data.langcode);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
278 setAttr(elm, 'xml:lang', data.langcode);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
279 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
280
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
281 // Serialize header fragment and crop away body part
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
282 html = new tinymce.html.Serializer({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
283 validate: false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
284 indent: true,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
285 apply_source_formatting : true,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
286 indent_before: 'head,html,body,meta,title,script,link,style',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
287 indent_after: 'head,html,body,meta,title,script,link,style'
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
288 }).serialize(headerFragment);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
289
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
290 this.head = html.substring(0, html.indexOf('</body>'));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
291 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
292
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
293 _parseHeader : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
294 // Parse the contents with a DOM parser
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
295 return new tinymce.html.DomParser({
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
296 validate: false,
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
297 root_name: '#document'
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
298 }).parse(this.head);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
299 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
300
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
301 _setContent : function(ed, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
302 var self = this, startPos, endPos, content = o.content, headerFragment, styles = '', dom = self.editor.dom, elm;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
303
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
304 function low(s) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
305 return s.replace(/<\/?[A-Z]+/g, function(a) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
306 return a.toLowerCase();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
307 })
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
308 };
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
309
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
310 // Ignore raw updated if we already have a head, this will fix issues with undo/redo keeping the head/foot separate
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
311 if (o.format == 'raw' && self.head)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
312 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
313
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
314 if (o.source_view && ed.getParam('fullpage_hide_in_source_view'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
315 return;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
316
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
317 // Parse out head, body and footer
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
318 content = content.replace(/<(\/?)BODY/gi, '<$1body');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
319 startPos = content.indexOf('<body');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
320
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
321 if (startPos != -1) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
322 startPos = content.indexOf('>', startPos);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
323 self.head = low(content.substring(0, startPos + 1));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
324
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
325 endPos = content.indexOf('</body', startPos);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
326 if (endPos == -1)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
327 endPos = content.length;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
328
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
329 o.content = content.substring(startPos + 1, endPos);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
330 self.foot = low(content.substring(endPos));
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
331 } else {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
332 self.head = this._getDefaultHeader();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
333 self.foot = '\n</body>\n</html>';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
334 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
335
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
336 // Parse header and update iframe
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
337 headerFragment = self._parseHeader();
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
338 each(headerFragment.getAll('style'), function(node) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
339 if (node.firstChild)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
340 styles += node.firstChild.value;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
341 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
342
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
343 elm = headerFragment.getAll('body')[0];
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
344 if (elm) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
345 dom.setAttribs(self.editor.getBody(), {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
346 style : elm.attr('style') || '',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
347 dir : elm.attr('dir') || '',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
348 vLink : elm.attr('vlink') || '',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
349 link : elm.attr('link') || '',
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
350 aLink : elm.attr('alink') || ''
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
351 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
352 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
353
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
354 dom.remove('fullpage_styles');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
355
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
356 if (styles) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
357 dom.add(self.editor.getDoc().getElementsByTagName('head')[0], 'style', {id : 'fullpage_styles'}, styles);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
358
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
359 // Needed for IE 6/7
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
360 elm = dom.get('fullpage_styles');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
361 if (elm.styleSheet)
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
362 elm.styleSheet.cssText = styles;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
363 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
364 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
365
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
366 _getDefaultHeader : function() {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
367 var header = '', editor = this.editor, value, styles = '';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
368
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
369 if (editor.getParam('fullpage_default_xml_pi'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
370 header += '<?xml version="1.0" encoding="' + editor.getParam('fullpage_default_encoding', 'ISO-8859-1') + '" ?>\n';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
371
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
372 header += editor.getParam('fullpage_default_doctype', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
373 header += '\n<html>\n<head>\n';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
374
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
375 if (value = editor.getParam('fullpage_default_title'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
376 header += '<title>' + value + '</title>\n';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
377
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
378 if (value = editor.getParam('fullpage_default_encoding'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
379 header += '<meta http-equiv="Content-Type" content="text/html; charset=' + value + '" />\n';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
380
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
381 if (value = editor.getParam('fullpage_default_font_family'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
382 styles += 'font-family: ' + value + ';';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
383
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
384 if (value = editor.getParam('fullpage_default_font_size'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
385 styles += 'font-size: ' + value + ';';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
386
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
387 if (value = editor.getParam('fullpage_default_text_color'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
388 styles += 'color: ' + value + ';';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
389
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
390 header += '</head>\n<body' + (styles ? ' style="' + styles + '"' : '') + '>\n';
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
391
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
392 return header;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
393 },
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
394
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
395 _getContent : function(ed, o) {
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
396 var self = this;
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
397
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
398 if (!o.source_view || !ed.getParam('fullpage_hide_in_source_view'))
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
399 o.content = tinymce.trim(self.head) + '\n' + tinymce.trim(o.content) + '\n' + tinymce.trim(self.foot);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
400 }
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
401 });
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
402
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
403 // Register plugin
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
404 tinymce.PluginManager.add('fullpage', tinymce.plugins.FullPagePlugin);
0be9d53a6967 editor for annotations
dwinter
parents:
diff changeset
405 })();