Mercurial > public > sg101
comparison static/js/tiny_mce/plugins/fullpage/editor_plugin_src.js @ 312:88b2b9cb8c1f
Fixing #142; cut over to the django.contrib.staticfiles app.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 27 Jan 2011 02:56:10 +0000 |
parents | |
children | 6c182ceb7147 |
comparison
equal
deleted
inserted
replaced
311:b1c39788e511 | 312:88b2b9cb8c1f |
---|---|
1 /** | |
2 * editor_plugin_src.js | |
3 * | |
4 * Copyright 2009, Moxiecode Systems AB | |
5 * Released under LGPL License. | |
6 * | |
7 * License: http://tinymce.moxiecode.com/license | |
8 * Contributing: http://tinymce.moxiecode.com/contributing | |
9 */ | |
10 | |
11 (function() { | |
12 tinymce.create('tinymce.plugins.FullPagePlugin', { | |
13 init : function(ed, url) { | |
14 var t = this; | |
15 | |
16 t.editor = ed; | |
17 | |
18 // Register commands | |
19 ed.addCommand('mceFullPageProperties', function() { | |
20 ed.windowManager.open({ | |
21 file : url + '/fullpage.htm', | |
22 width : 430 + parseInt(ed.getLang('fullpage.delta_width', 0)), | |
23 height : 495 + parseInt(ed.getLang('fullpage.delta_height', 0)), | |
24 inline : 1 | |
25 }, { | |
26 plugin_url : url, | |
27 head_html : t.head | |
28 }); | |
29 }); | |
30 | |
31 // Register buttons | |
32 ed.addButton('fullpage', {title : 'fullpage.desc', cmd : 'mceFullPageProperties'}); | |
33 | |
34 ed.onBeforeSetContent.add(t._setContent, t); | |
35 ed.onSetContent.add(t._setBodyAttribs, t); | |
36 ed.onGetContent.add(t._getContent, t); | |
37 }, | |
38 | |
39 getInfo : function() { | |
40 return { | |
41 longname : 'Fullpage', | |
42 author : 'Moxiecode Systems AB', | |
43 authorurl : 'http://tinymce.moxiecode.com', | |
44 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullpage', | |
45 version : tinymce.majorVersion + "." + tinymce.minorVersion | |
46 }; | |
47 }, | |
48 | |
49 // Private plugin internal methods | |
50 | |
51 _setBodyAttribs : function(ed, o) { | |
52 var bdattr, i, len, kv, k, v, t, attr = this.head.match(/body(.*?)>/i); | |
53 | |
54 if (attr && attr[1]) { | |
55 bdattr = attr[1].match(/\s*(\w+\s*=\s*".*?"|\w+\s*=\s*'.*?'|\w+\s*=\s*\w+|\w+)\s*/g); | |
56 | |
57 if (bdattr) { | |
58 for(i = 0, len = bdattr.length; i < len; i++) { | |
59 kv = bdattr[i].split('='); | |
60 k = kv[0].replace(/\s/,''); | |
61 v = kv[1]; | |
62 | |
63 if (v) { | |
64 v = v.replace(/^\s+/,'').replace(/\s+$/,''); | |
65 t = v.match(/^["'](.*)["']$/); | |
66 | |
67 if (t) | |
68 v = t[1]; | |
69 } else | |
70 v = k; | |
71 | |
72 ed.dom.setAttrib(ed.getBody(), 'style', v); | |
73 } | |
74 } | |
75 } | |
76 }, | |
77 | |
78 _createSerializer : function() { | |
79 return new tinymce.dom.Serializer({ | |
80 dom : this.editor.dom, | |
81 apply_source_formatting : true | |
82 }); | |
83 }, | |
84 | |
85 _setContent : function(ed, o) { | |
86 var t = this, sp, ep, c = o.content, v, st = ''; | |
87 | |
88 // Ignore raw updated if we already have a head, this will fix issues with undo/redo keeping the head/foot separate | |
89 if (o.format == 'raw' && t.head) | |
90 return; | |
91 | |
92 if (o.source_view && ed.getParam('fullpage_hide_in_source_view')) | |
93 return; | |
94 | |
95 // Parse out head, body and footer | |
96 c = c.replace(/<(\/?)BODY/gi, '<$1body'); | |
97 sp = c.indexOf('<body'); | |
98 | |
99 if (sp != -1) { | |
100 sp = c.indexOf('>', sp); | |
101 t.head = c.substring(0, sp + 1); | |
102 | |
103 ep = c.indexOf('</body', sp); | |
104 if (ep == -1) | |
105 ep = c.indexOf('</body', ep); | |
106 | |
107 o.content = c.substring(sp + 1, ep); | |
108 t.foot = c.substring(ep); | |
109 | |
110 function low(s) { | |
111 return s.replace(/<\/?[A-Z]+/g, function(a) { | |
112 return a.toLowerCase(); | |
113 }) | |
114 }; | |
115 | |
116 t.head = low(t.head); | |
117 t.foot = low(t.foot); | |
118 } else { | |
119 t.head = ''; | |
120 if (ed.getParam('fullpage_default_xml_pi')) | |
121 t.head += '<?xml version="1.0" encoding="' + ed.getParam('fullpage_default_encoding', 'ISO-8859-1') + '" ?>\n'; | |
122 | |
123 t.head += ed.getParam('fullpage_default_doctype', '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'); | |
124 t.head += '\n<html>\n<head>\n<title>' + ed.getParam('fullpage_default_title', 'Untitled document') + '</title>\n'; | |
125 | |
126 if (v = ed.getParam('fullpage_default_encoding')) | |
127 t.head += '<meta http-equiv="Content-Type" content="' + v + '" />\n'; | |
128 | |
129 if (v = ed.getParam('fullpage_default_font_family')) | |
130 st += 'font-family: ' + v + ';'; | |
131 | |
132 if (v = ed.getParam('fullpage_default_font_size')) | |
133 st += 'font-size: ' + v + ';'; | |
134 | |
135 if (v = ed.getParam('fullpage_default_text_color')) | |
136 st += 'color: ' + v + ';'; | |
137 | |
138 t.head += '</head>\n<body' + (st ? ' style="' + st + '"' : '') + '>\n'; | |
139 t.foot = '\n</body>\n</html>'; | |
140 } | |
141 }, | |
142 | |
143 _getContent : function(ed, o) { | |
144 var t = this; | |
145 | |
146 if (!o.source_view || !ed.getParam('fullpage_hide_in_source_view')) | |
147 o.content = tinymce.trim(t.head) + '\n' + tinymce.trim(o.content) + '\n' + tinymce.trim(t.foot); | |
148 } | |
149 }); | |
150 | |
151 // Register plugin | |
152 tinymce.PluginManager.add('fullpage', tinymce.plugins.FullPagePlugin); | |
153 })(); |