~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/pub/System/TinyMCEPlugin/tinymce/jscripts/tiny_mce/plugins/fullpage/editor_plugin_src.js

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * $Id: editor_plugin_src.js 232 2007-03-05 17:00:27Z spocke $
 
3
 *
 
4
 * @author Moxiecode
 
5
 * @copyright Copyright ďż˝ 2004-2007, Moxiecode Systems AB, All rights reserved.
 
6
 */
 
7
 
 
8
/* Import plugin specific language pack */
 
9
tinyMCE.importPluginLanguagePack('fullpage');
 
10
 
 
11
var TinyMCE_FullPagePlugin = {
 
12
        getInfo : function() {
 
13
                return {
 
14
                        longname : 'Fullpage',
 
15
                        author : 'Moxiecode Systems AB',
 
16
                        authorurl : 'http://tinymce.moxiecode.com',
 
17
                        infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage',
 
18
                        version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
 
19
                };
 
20
        },
 
21
 
 
22
        getControlHTML : function(cn) {
 
23
                switch (cn) {
 
24
                        case "fullpage":
 
25
                                return tinyMCE.getButtonHTML(cn, 'lang_fullpage_desc', '{$pluginurl}/images/fullpage.gif', 'mceFullPageProperties');
 
26
                }
 
27
 
 
28
                return "";
 
29
        },
 
30
 
 
31
        execCommand : function(editor_id, element, command, user_interface, value) {
 
32
                // Handle commands
 
33
                switch (command) {
 
34
                        case "mceFullPageProperties":
 
35
                                var template = new Array();
 
36
 
 
37
                                template['file']   = '../../plugins/fullpage/fullpage.htm';
 
38
                                template['width']  = 430;
 
39
                                template['height'] = 485 + (tinyMCE.isOpera ? 5 : 0);
 
40
 
 
41
                                template['width'] += tinyMCE.getLang('lang_fullpage_delta_width', 0);
 
42
                                template['height'] += tinyMCE.getLang('lang_fullpage_delta_height', 0);
 
43
 
 
44
                                tinyMCE.openWindow(template, {editor_id : editor_id, inline : "yes"});
 
45
                        return true;
 
46
 
 
47
                        case "mceFullPageUpdate":
 
48
                                TinyMCE_FullPagePlugin._addToHead(tinyMCE.getInstanceById(editor_id));
 
49
                                return true;
 
50
           }
 
51
 
 
52
           // Pass to next handler in chain
 
53
           return false;
 
54
        },
 
55
 
 
56
        cleanup : function(type, content, inst) {
 
57
                switch (type) {
 
58
                        case "insert_to_editor":
 
59
                                var tmp = content.toLowerCase();
 
60
                                var pos = tmp.indexOf('<body'), pos2;
 
61
 
 
62
                                // Split page in header and body chunks
 
63
                                if (pos != -1) {
 
64
                                        pos = tmp.indexOf('>', pos);
 
65
                                        pos2 = tmp.lastIndexOf('</body>');
 
66
                                        inst.fullpageTopContent = content.substring(0, pos + 1);
 
67
                                        content = content.substring(pos + 1, pos2);
 
68
                                        // tinyMCE.debug(inst.fullpageTopContent, content);
 
69
                                } else {
 
70
                                        if (!inst.fullpageTopContent) {
 
71
                                                var docType = tinyMCE.getParam("fullpage_default_doctype", '<!DOCTYPE html PUBLIC "-/'+'/W3C//DTD XHTML 1.0 Transitional/'+'/EN" "http:/'+'/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
 
72
                                                var enc = tinyMCE.getParam("fullpage_default_encoding", 'utf-8');
 
73
                                                var title = tinyMCE.getParam("fullpage_default_title", 'Untitled document');
 
74
                                                var lang = tinyMCE.getParam("fullpage_default_langcode", 'en');
 
75
                                                var pi = tinyMCE.getParam("fullpage_default_xml_pi", true);
 
76
                                                var ff = tinyMCE.getParam("fullpage_default_font_family", "");
 
77
                                                var fz = tinyMCE.getParam("fullpage_default_font_size", "");
 
78
                                                var ds = tinyMCE.getParam("fullpage_default_style", "");
 
79
                                                var dtc = tinyMCE.getParam("fullpage_default_text_color", "");
 
80
 
 
81
                                                // Xml encode it
 
82
                                                title = title.replace(/&/g, '&amp;');
 
83
                                                title = title.replace(/\"/g, '&quot;');
 
84
                                                title = title.replace(/</g, '&lt;');
 
85
                                                title = title.replace(/>/g, '&gt;');
 
86
 
 
87
                                                tmp = '';
 
88
 
 
89
                                                // Make default chunk
 
90
                                                if (pi)
 
91
                                                        tmp += '<?xml version="1.0" encoding="' + enc + '"?>\n';
 
92
 
 
93
                                                tmp += docType + '\n';
 
94
                                                tmp += '<html xmlns="http:/'+'/www.w3.org/1999/xhtml" lang="' + lang + '" xml:lang="' + lang + '">\n';
 
95
                                                tmp += '<head>\n';
 
96
                                                tmp += '\t<title>' + title + '</title>\n';
 
97
                                                tmp += '\t<meta http-equiv="Content-Type" content="text/html; charset=' + enc + '" />\n';
 
98
                                                tmp += '</head>\n';
 
99
                                                tmp += '<body';
 
100
 
 
101
                                                if (ff != '' || fz != '') {
 
102
                                                        tmp += ' style="';
 
103
 
 
104
                                                        if (ds != '')
 
105
                                                                tmp += ds + ";";
 
106
 
 
107
                                                        if (ff != '')
 
108
                                                                tmp += 'font-family: ' + ff + ";";
 
109
 
 
110
                                                        if (fz != '')
 
111
                                                                tmp += 'font-size: ' + fz + ";";
 
112
 
 
113
                                                        tmp += '"';
 
114
                                                }
 
115
 
 
116
                                                if (dtc != '')
 
117
                                                        tmp += ' text="' + dtc + '"';
 
118
 
 
119
                                                tmp += '>\n';
 
120
 
 
121
                                                inst.fullpageTopContent = tmp;
 
122
                                        }
 
123
                                }
 
124
 
 
125
                                this._addToHead(inst);
 
126
 
 
127
                                break;
 
128
 
 
129
                        case "get_from_editor":
 
130
                                if (inst.fullpageTopContent && !tinyMCE.getParam("fullpage_hide_in_source_view", false)) {
 
131
                                        content = content.replace(/(\s)?mce\_[a-z_]+\=[^\s>]+(\s|\>)/i, ''); // Remove internal stuff
 
132
                                        content = inst.fullpageTopContent + content + "\n</body>\n</html>";
 
133
                                }
 
134
 
 
135
                                break;
 
136
 
 
137
                        case "submit_content":
 
138
                                if (inst.fullpageTopContent && tinyMCE.getParam("fullpage_hide_in_source_view", false))
 
139
                                        content = inst.fullpageTopContent + content + "\n</body>\n</html>";
 
140
 
 
141
                                break;
 
142
                }
 
143
 
 
144
                // Pass through to next handler in chain
 
145
                return content;
 
146
        },
 
147
 
 
148
        // Private plugin internal methods
 
149
 
 
150
        _addToHead : function(inst) {
 
151
                var doc = inst.getDoc();
 
152
                var head = doc.getElementsByTagName("head")[0];
 
153
                var body = doc.body;
 
154
                var h = inst.fullpageTopContent;
 
155
                var e = doc.createElement("body");
 
156
                var nl, i, le, tmp;
 
157
 
 
158
                // Remove stuff we don't want
 
159
                h = h.replace(/(\r|\n)/gi, '');
 
160
                h = h.replace(/<\?[^\>]*\>/gi, '');
 
161
                h = h.replace(/<\/?(!DOCTYPE|head|html)[^\>]*\>/gi, '');
 
162
                h = h.replace(/<script(.*?)<\/script>/gi, '');
 
163
                h = h.replace(/<title(.*?)<\/title>/gi, '');
 
164
                h = h.replace(/<(meta|base)[^>]*>/gi, '');
 
165
 
 
166
                // Make link and style elements into pre
 
167
                h = h.replace(/<link([^>]*)\/>/gi, '<pre mce_type="link" $1></pre>');
 
168
                //h = h.replace(/<style([^>]*)>(.*?)<\/style>/gi, '<pre mce_type="style" $1>$2</pre>');
 
169
 
 
170
                // Make body a div
 
171
                h = h.replace(/<body/gi, '<div mce_type="body"');
 
172
                h += '</div>';
 
173
 
 
174
                // Now crapy MSIE can parse it
 
175
                e.innerHTML = h;
 
176
 
 
177
                // Reset all body attributes
 
178
                body.vLink = body.aLink = body.link = body.text = '';
 
179
                body.style.cssText = '';
 
180
 
 
181
                // Delete all old links
 
182
                nl = head.getElementsByTagName('link');
 
183
                for (i=0; i<nl.length; i++) {
 
184
                        if (tinyMCE.getAttrib(nl[i], 'mce_head') == "true")
 
185
                                nl[i].parentNode.removeChild(nl[i]);
 
186
                }
 
187
 
 
188
                // Add link elements
 
189
                nl = e.getElementsByTagName('pre');
 
190
                for (i=0; i<nl.length; i++) {
 
191
                        tmp = tinyMCE.getAttrib(nl[i], 'media');
 
192
                        if (tinyMCE.getAttrib(nl[i], 'mce_type') == "link" && (tmp == "" || tmp == "screen" || tmp == "all") && tinyMCE.getAttrib(nl[i], 'rel') == "stylesheet") {
 
193
                                le = doc.createElement("link");
 
194
 
 
195
                                le.rel = "stylesheet";
 
196
                                le.href = tinyMCE.getAttrib(nl[i], 'href');
 
197
                                le.setAttribute("mce_head", "true");
 
198
 
 
199
                                head.appendChild(le);
 
200
                        }
 
201
                }
 
202
 
 
203
                // Add body attributes
 
204
                nl = e.getElementsByTagName('div');
 
205
                if (nl.length > 0) {
 
206
                        body.style.cssText = tinyMCE.getAttrib(nl[0], 'style');
 
207
 
 
208
                        if ((tmp = tinyMCE.getAttrib(nl[0], 'leftmargin')) != '' && body.style.marginLeft == '')
 
209
                                body.style.marginLeft = tmp + "px";
 
210
 
 
211
                        if ((tmp = tinyMCE.getAttrib(nl[0], 'rightmargin')) != '' && body.style.marginRight == '')
 
212
                                body.style.marginRight = tmp + "px";
 
213
 
 
214
                        if ((tmp = tinyMCE.getAttrib(nl[0], 'topmargin')) != '' && body.style.marginTop == '')
 
215
                                body.style.marginTop = tmp + "px";
 
216
 
 
217
                        if ((tmp = tinyMCE.getAttrib(nl[0], 'bottommargin')) != '' && body.style.marginBottom == '')
 
218
                                body.style.marginBottom = tmp + "px";
 
219
 
 
220
                        body.dir = tinyMCE.getAttrib(nl[0], 'dir');
 
221
                        body.vLink = tinyMCE.getAttrib(nl[0], 'vlink');
 
222
                        body.aLink = tinyMCE.getAttrib(nl[0], 'alink');
 
223
                        body.link = tinyMCE.getAttrib(nl[0], 'link');
 
224
                        body.text = tinyMCE.getAttrib(nl[0], 'text');
 
225
 
 
226
                        if ((tmp = tinyMCE.getAttrib(nl[0], 'background')) != '')
 
227
                                body.style.backgroundImage = "url('" + tmp + "')";
 
228
 
 
229
                        if ((tmp = tinyMCE.getAttrib(nl[0], 'bgcolor')) != '')
 
230
                                body.style.backgroundColor = tmp;
 
231
                }
 
232
        }
 
233
};
 
234
 
 
235
tinyMCE.addPlugin("fullpage", TinyMCE_FullPagePlugin);