source: branches/rsr.v5.1/web/app/plugins/tinymce/jscripts/tiny_mce/plugins/fullpage/js/fullpage.js @ 1

Last change on this file since 1 was 1, checked in by dj3c1t, 12 years ago

import initial

File size: 15.2 KB
Line 
1tinyMCEPopup.requireLangPack();
2
3var doc;
4
5var defaultDocTypes = 
6        'XHTML 1.0 Transitional=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">,' +
7        'XHTML 1.0 Frameset=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">,' +
8        'XHTML 1.0 Strict=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">,' +
9        'XHTML 1.1=<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">,' +
10        'HTML 4.01 Transitional=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">,' +
11        'HTML 4.01 Strict=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">,' +
12        'HTML 4.01 Frameset=<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">';
13
14var defaultEncodings = 
15        'Western european (iso-8859-1)=iso-8859-1,' +
16        'Central European (iso-8859-2)=iso-8859-2,' +
17        'Unicode (UTF-8)=utf-8,' +
18        'Chinese traditional (Big5)=big5,' +
19        'Cyrillic (iso-8859-5)=iso-8859-5,' +
20        'Japanese (iso-2022-jp)=iso-2022-jp,' +
21        'Greek (iso-8859-7)=iso-8859-7,' +
22        'Korean (iso-2022-kr)=iso-2022-kr,' +
23        'ASCII (us-ascii)=us-ascii';
24
25var defaultMediaTypes = 
26        'all=all,' +
27        'screen=screen,' +
28        'print=print,' +
29        'tty=tty,' +
30        'tv=tv,' +
31        'projection=projection,' +
32        'handheld=handheld,' +
33        'braille=braille,' +
34        'aural=aural';
35
36var defaultFontNames = 'Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;WingDings=wingdings';
37var defaultFontSizes = '10px,11px,12px,13px,14px,15px,16px';
38
39function init() {
40        var f = document.forms['fullpage'], el = f.elements, e, i, p, doctypes, encodings, mediaTypes, fonts, ed = tinyMCEPopup.editor, dom = tinyMCEPopup.dom, style;
41
42        // Setup doctype select box
43        doctypes = ed.getParam("fullpage_doctypes", defaultDocTypes).split(',');
44        for (i=0; i<doctypes.length; i++) {
45                p = doctypes[i].split('=');
46
47                if (p.length > 1)
48                        addSelectValue(f, 'doctypes', p[0], p[1]);
49        }
50
51        // Setup fonts select box
52        fonts = ed.getParam("fullpage_fonts", defaultFontNames).split(';');
53        for (i=0; i<fonts.length; i++) {
54                p = fonts[i].split('=');
55
56                if (p.length > 1)
57                        addSelectValue(f, 'fontface', p[0], p[1]);
58        }
59
60        // Setup fontsize select box
61        fonts = ed.getParam("fullpage_fontsizes", defaultFontSizes).split(',');
62        for (i=0; i<fonts.length; i++)
63                addSelectValue(f, 'fontsize', fonts[i], fonts[i]);
64
65        // Setup mediatype select boxs
66        mediaTypes = ed.getParam("fullpage_media_types", defaultMediaTypes).split(',');
67        for (i=0; i<mediaTypes.length; i++) {
68                p = mediaTypes[i].split('=');
69
70                if (p.length > 1) {
71                        addSelectValue(f, 'element_style_media', p[0], p[1]);
72                        addSelectValue(f, 'element_link_media', p[0], p[1]);
73                }
74        }
75
76        // Setup encodings select box
77        encodings = ed.getParam("fullpage_encodings", defaultEncodings).split(',');
78        for (i=0; i<encodings.length; i++) {
79                p = encodings[i].split('=');
80
81                if (p.length > 1) {
82                        addSelectValue(f, 'docencoding', p[0], p[1]);
83                        addSelectValue(f, 'element_script_charset', p[0], p[1]);
84                        addSelectValue(f, 'element_link_charset', p[0], p[1]);
85                }
86        }
87
88        document.getElementById('bgcolor_pickcontainer').innerHTML = getColorPickerHTML('bgcolor_pick','bgcolor');
89        document.getElementById('link_color_pickcontainer').innerHTML = getColorPickerHTML('link_color_pick','link_color');
90        //document.getElementById('hover_color_pickcontainer').innerHTML = getColorPickerHTML('hover_color_pick','hover_color');
91        document.getElementById('visited_color_pickcontainer').innerHTML = getColorPickerHTML('visited_color_pick','visited_color');
92        document.getElementById('active_color_pickcontainer').innerHTML = getColorPickerHTML('active_color_pick','active_color');
93        document.getElementById('textcolor_pickcontainer').innerHTML = getColorPickerHTML('textcolor_pick','textcolor');
94        document.getElementById('stylesheet_browsercontainer').innerHTML = getBrowserHTML('stylesheetbrowser','stylesheet','file','fullpage');
95        document.getElementById('link_href_pickcontainer').innerHTML = getBrowserHTML('link_href_browser','element_link_href','file','fullpage');
96        document.getElementById('script_src_pickcontainer').innerHTML = getBrowserHTML('script_src_browser','element_script_src','file','fullpage');
97        document.getElementById('bgimage_pickcontainer').innerHTML = getBrowserHTML('bgimage_browser','bgimage','image','fullpage');
98
99        // Resize some elements
100        if (isVisible('stylesheetbrowser'))
101                document.getElementById('stylesheet').style.width = '220px';
102
103        if (isVisible('link_href_browser'))
104                document.getElementById('element_link_href').style.width = '230px';
105
106        if (isVisible('bgimage_browser'))
107                document.getElementById('bgimage').style.width = '210px';
108
109        // Add iframe
110        dom.add(document.body, 'iframe', {id : 'documentIframe', src : 'javascript:""', style : {display : 'none'}});
111        doc = dom.get('documentIframe').contentWindow.document;
112        h = tinyMCEPopup.getWindowArg('head_html');
113
114        // Preprocess the HTML disable scripts and urls
115        h = h.replace(/<script>/gi, '<script type="text/javascript">');
116        h = h.replace(/type=([\"\'])?/gi, 'type=$1-mce-');
117        h = h.replace(/(src=|href=)/g, 'mce_$1');
118
119        // Write in the content in the iframe
120        doc.write(h + '</body></html>');
121        doc.close();
122
123        // Parse xml and doctype
124        xmlVer = getReItem(/<\?\s*?xml.*?version\s*?=\s*?"(.*?)".*?\?>/gi, h, 1);
125        xmlEnc = getReItem(/<\?\s*?xml.*?encoding\s*?=\s*?"(.*?)".*?\?>/gi, h, 1);
126        docType = getReItem(/<\!DOCTYPE.*?>/gi, h, 0);
127        f.langcode.value = getReItem(/lang="(.*?)"/gi, h, 1);
128
129        // Parse title
130        if (e = doc.getElementsByTagName('title')[0])
131                el.metatitle.value = e.textContent || e.text;
132
133        // Parse meta
134        tinymce.each(doc.getElementsByTagName('meta'), function(n) {
135                var na = (n.getAttribute('name', 2) || '').toLowerCase(), va = n.getAttribute('content', 2), eq = n.getAttribute('httpEquiv', 2) || '';
136
137                e = el['meta' + na];
138
139                if (na == 'robots') {
140                        selectByValue(f, 'metarobots', tinymce.trim(va), true, true);
141                        return;
142                }
143
144                switch (eq.toLowerCase()) {
145                        case "content-type":
146                                tmp = getReItem(/charset\s*=\s*(.*)\s*/gi, value, 1);
147
148                                // Override XML encoding
149                                if (tmp != "")
150                                        xmlEnc = tmp;
151
152                                return;
153                }
154
155                if (e)
156                        e.value = va;
157        });
158
159        selectByValue(f, 'doctypes', docType, true, true);
160        selectByValue(f, 'docencoding', xmlEnc, true, true);
161        selectByValue(f, 'langdir', doc.body.getAttribute('dir', 2) || '', true, true);
162
163        if (xmlVer != '')
164                el.xml_pi.checked = true;
165
166        // Parse appearance
167
168        // Parse primary stylesheet
169        tinymce.each(doc.getElementsByTagName("link"), function(l) {
170                var m = l.getAttribute('media', 2) || '', t = l.getAttribute('type', 2) || '';
171
172                if (t == "-mce-text/css" && (m == "" || m == "screen" || m == "all") && (l.getAttribute('rel', 2) || '') == "stylesheet") {
173                        f.stylesheet.value = l.getAttribute('mce_href', 2) || '';
174                        return false;
175                }
176        });
177
178        // Get from style elements
179        tinymce.each(doc.getElementsByTagName("style"), function(st) {
180                var tmp = parseStyleElement(st);
181
182                for (x=0; x<tmp.length; x++) {
183                        if (tmp[x].rule.indexOf('a:visited') != -1 && tmp[x].data['color'])
184                                f.visited_color.value = tmp[x].data['color'];
185
186                        if (tmp[x].rule.indexOf('a:link') != -1 && tmp[x].data['color'])
187                                f.link_color.value = tmp[x].data['color'];
188
189                        if (tmp[x].rule.indexOf('a:active') != -1 && tmp[x].data['color'])
190                                f.active_color.value = tmp[x].data['color'];
191                }
192        });
193
194        f.textcolor.value = tinyMCEPopup.dom.getAttrib(doc.body, "text");
195        f.active_color.value = tinyMCEPopup.dom.getAttrib(doc.body, "alink");
196        f.link_color.value = tinyMCEPopup.dom.getAttrib(doc.body, "link");
197        f.visited_color.value = tinyMCEPopup.dom.getAttrib(doc.body, "vlink");
198        f.bgcolor.value = tinyMCEPopup.dom.getAttrib(doc.body, "bgcolor");
199        f.bgimage.value = tinyMCEPopup.dom.getAttrib(doc.body, "background");
200
201        // Get from style info
202        style = tinyMCEPopup.dom.parseStyle(tinyMCEPopup.dom.getAttrib(doc.body, 'style'));
203
204        if (style['font-family'])
205                selectByValue(f, 'fontface', style['font-family'], true, true);
206        else
207                selectByValue(f, 'fontface', ed.getParam("fullpage_default_fontface", ""), true, true);
208
209        if (style['font-size'])
210                selectByValue(f, 'fontsize', style['font-size'], true, true);
211        else
212                selectByValue(f, 'fontsize', ed.getParam("fullpage_default_fontsize", ""), true, true);
213
214        if (style['color'])
215                f.textcolor.value = convertRGBToHex(style['color']);
216
217        if (style['background-image'])
218                f.bgimage.value = style['background-image'].replace(new RegExp("url\\('?([^']*)'?\\)", 'gi'), "$1");
219
220        if (style['background-color'])
221                f.bgcolor.value = style['background-color'];
222
223        if (style['margin']) {
224                tmp = style['margin'].replace(/[^0-9 ]/g, '');
225                tmp = tmp.split(/ +/);
226                f.topmargin.value = tmp.length > 0 ? tmp[0] : '';
227                f.rightmargin.value = tmp.length > 1 ? tmp[1] : tmp[0];
228                f.bottommargin.value = tmp.length > 2 ? tmp[2] : tmp[0];
229                f.leftmargin.value = tmp.length > 3 ? tmp[3] : tmp[0];
230        }
231
232        if (style['margin-left'])
233                f.leftmargin.value = style['margin-left'].replace(/[^0-9]/g, '');
234
235        if (style['margin-right'])
236                f.rightmargin.value = style['margin-right'].replace(/[^0-9]/g, '');
237
238        if (style['margin-top'])
239                f.topmargin.value = style['margin-top'].replace(/[^0-9]/g, '');
240
241        if (style['margin-bottom'])
242                f.bottommargin.value = style['margin-bottom'].replace(/[^0-9]/g, '');
243
244        f.style.value = tinyMCEPopup.dom.serializeStyle(style);
245
246        // Update colors
247        updateColor('textcolor_pick', 'textcolor');
248        updateColor('bgcolor_pick', 'bgcolor');
249        updateColor('visited_color_pick', 'visited_color');
250        updateColor('active_color_pick', 'active_color');
251        updateColor('link_color_pick', 'link_color');
252}
253
254function getReItem(r, s, i) {
255        var c = r.exec(s);
256
257        if (c && c.length > i)
258                return c[i];
259
260        return '';
261}
262
263function updateAction() {
264        var f = document.forms[0], nl, i, h, v, s, head, html, l, tmp, addlink = true, ser;
265
266        head = doc.getElementsByTagName('head')[0];
267
268        // Fix scripts without a type
269        nl = doc.getElementsByTagName('script');
270        for (i=0; i<nl.length; i++) {
271                if (tinyMCEPopup.dom.getAttrib(nl[i], 'mce_type') == '')
272                        nl[i].setAttribute('mce_type', 'text/javascript');
273        }
274
275        // Get primary stylesheet
276        nl = doc.getElementsByTagName("link");
277        for (i=0; i<nl.length; i++) {
278                l = nl[i];
279
280                tmp = tinyMCEPopup.dom.getAttrib(l, 'media');
281
282                if (tinyMCEPopup.dom.getAttrib(l, 'mce_type') == "text/css" && (tmp == "" || tmp == "screen" || tmp == "all") && tinyMCEPopup.dom.getAttrib(l, 'rel') == "stylesheet") {
283                        addlink = false;
284
285                        if (f.stylesheet.value == '')
286                                l.parentNode.removeChild(l);
287                        else
288                                l.setAttribute('mce_href', f.stylesheet.value);
289
290                        break;
291                }
292        }
293
294        // Add new link
295        if (f.stylesheet.value != '') {
296                l = doc.createElement('link');
297
298                l.setAttribute('type', 'text/css');
299                l.setAttribute('mce_href', f.stylesheet.value);
300                l.setAttribute('rel', 'stylesheet');
301
302                head.appendChild(l);
303        }
304
305        setMeta(head, 'keywords', f.metakeywords.value);
306        setMeta(head, 'description', f.metadescription.value);
307        setMeta(head, 'author', f.metaauthor.value);
308        setMeta(head, 'copyright', f.metacopyright.value);
309        setMeta(head, 'robots', getSelectValue(f, 'metarobots'));
310        setMeta(head, 'Content-Type', getSelectValue(f, 'docencoding'));
311
312        doc.body.dir = getSelectValue(f, 'langdir');
313        doc.body.style.cssText = f.style.value;
314
315        doc.body.setAttribute('vLink', f.visited_color.value);
316        doc.body.setAttribute('link', f.link_color.value);
317        doc.body.setAttribute('text', f.textcolor.value);
318        doc.body.setAttribute('aLink', f.active_color.value);
319
320        doc.body.style.fontFamily = getSelectValue(f, 'fontface');
321        doc.body.style.fontSize = getSelectValue(f, 'fontsize');
322        doc.body.style.backgroundColor = f.bgcolor.value;
323
324        if (f.leftmargin.value != '')
325                doc.body.style.marginLeft = f.leftmargin.value + 'px';
326
327        if (f.rightmargin.value != '')
328                doc.body.style.marginRight = f.rightmargin.value + 'px';
329
330        if (f.bottommargin.value != '')
331                doc.body.style.marginBottom = f.bottommargin.value + 'px';
332
333        if (f.topmargin.value != '')
334                doc.body.style.marginTop = f.topmargin.value + 'px';
335
336        html = doc.getElementsByTagName('html')[0];
337        html.setAttribute('lang', f.langcode.value);
338        html.setAttribute('xml:lang', f.langcode.value);
339
340        if (f.bgimage.value != '')
341                doc.body.style.backgroundImage = "url('" + f.bgimage.value + "')";
342        else
343                doc.body.style.backgroundImage = '';
344
345        ser = tinyMCEPopup.editor.plugins.fullpage._createSerializer();
346        ser.setRules('-title,meta[http-equiv|name|content],base[href|target],link[href|rel|type|title|media],style[type],script[type|language|src],html[lang|xml::lang|xmlns],body[style|dir|vlink|link|text|alink],head');
347
348        h = ser.serialize(doc.documentElement);
349        h = h.substring(0, h.lastIndexOf('</body>'));
350
351        if (h.indexOf('<title>') == -1)
352                h = h.replace(/<head.*?>/, '$&\n' + '<title>' + tinyMCEPopup.dom.encode(f.metatitle.value) + '</title>');
353        else
354                h = h.replace(/<title>(.*?)<\/title>/, '<title>' + tinyMCEPopup.dom.encode(f.metatitle.value) + '</title>');
355
356        if ((v = getSelectValue(f, 'doctypes')) != '')
357                h = v + '\n' + h;
358
359        if (f.xml_pi.checked) {
360                s = '<?xml version="1.0"';
361
362                if ((v = getSelectValue(f, 'docencoding')) != '')
363                        s += ' encoding="' + v + '"';
364
365                s += '?>\n';
366                h = s + h;
367        }
368
369        h = h.replace(/type=\"\-mce\-/gi, 'type="');
370
371        tinyMCEPopup.editor.plugins.fullpage.head = h;
372        tinyMCEPopup.close();
373}
374
375function changedStyleField(field) {
376        //alert(field.id);
377}
378
379function setMeta(he, k, v) {
380        var nl, i, m;
381
382        nl = he.getElementsByTagName('meta');
383        for (i=0; i<nl.length; i++) {
384                if (k == 'Content-Type' && tinyMCEPopup.dom.getAttrib(nl[i], 'http-equiv') == k) {
385                        if (v == '')
386                                nl[i].parentNode.removeChild(nl[i]);
387                        else
388                                nl[i].setAttribute('content', "text/html; charset=" + v);
389
390                        return;
391                }
392
393                if (tinyMCEPopup.dom.getAttrib(nl[i], 'name') == k) {
394                        if (v == '')
395                                nl[i].parentNode.removeChild(nl[i]);
396                        else
397                                nl[i].setAttribute('content', v);
398                        return;
399                }
400        }
401
402        if (v == '')
403                return;
404
405        m = doc.createElement('meta');
406
407        if (k == 'Content-Type')
408                m.httpEquiv = k;
409        else
410                m.setAttribute('name', k);
411
412        m.setAttribute('content', v);
413        he.appendChild(m);
414}
415
416function parseStyleElement(e) {
417        var v = e.innerHTML;
418        var p, i, r;
419
420        v = v.replace(/<!--/gi, '');
421        v = v.replace(/-->/gi, '');
422        v = v.replace(/[\n\r]/gi, '');
423        v = v.replace(/\s+/gi, ' ');
424
425        r = [];
426        p = v.split(/{|}/);
427
428        for (i=0; i<p.length; i+=2) {
429                if (p[i] != "")
430                        r[r.length] = {rule : tinymce.trim(p[i]), data : tinyMCEPopup.dom.parseStyle(p[i+1])};
431        }
432
433        return r;
434}
435
436function serializeStyleElement(d) {
437        var i, s, st;
438
439        s = '<!--\n';
440
441        for (i=0; i<d.length; i++) {
442                s += d[i].rule + ' {\n';
443
444                st = tinyMCE.serializeStyle(d[i].data);
445
446                if (st != '')
447                        st += ';';
448
449                s += st.replace(/;/g, ';\n');
450                s += '}\n';
451
452                if (i != d.length - 1)
453                        s += '\n';
454        }
455
456        s += '\n-->';
457
458        return s;
459}
460
461tinyMCEPopup.onInit.add(init);
Note: See TracBrowser for help on using the repository browser.