0
|
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 |
var DOM = tinymce.DOM; |
|
13 |
|
|
14 |
// State Transfer function |
|
15 |
var transferState = function(oldEditor, newEditor, bookmark) { |
|
16 |
var transferColorButtonState = function(swapme) { |
|
17 |
var c = oldEditor.controlManager.get(swapme); |
|
18 |
var newC = newEditor.controlManager.get(swapme); |
|
19 |
|
|
20 |
if (c && newC) { |
|
21 |
newC.displayColor(c.value); |
|
22 |
} |
|
23 |
|
|
24 |
}; |
|
25 |
|
|
26 |
transferColorButtonState('forecolor'); |
|
27 |
transferColorButtonState('backcolor'); |
|
28 |
newEditor.setContent(oldEditor.getContent({format : 'raw'}), {format : 'raw'}); |
|
29 |
newEditor.selection.moveToBookmark(bookmark); |
|
30 |
|
|
31 |
if (oldEditor.plugins.spellchecker && newEditor.plugins.spellchecker) { |
|
32 |
newEditor.plugins.spellchecker.setLanguage(oldEditor.plugins.spellchecker.selectedLang); |
|
33 |
} |
|
34 |
}; |
|
35 |
|
|
36 |
tinymce.create('tinymce.plugins.FullScreenPlugin', { |
|
37 |
init : function(ed, url) { |
|
38 |
var t = this, s = {}, de = DOM.doc.documentElement, vp, fullscreen_overflow, fullscreen_html_overflow, fullscreen_scrollx, fullscreen_scrolly, posCss, bookmark; |
|
39 |
|
|
40 |
// Register commands |
|
41 |
ed.addCommand('mceFullScreen', function() { |
|
42 |
var win, oed; |
|
43 |
|
|
44 |
if (ed.getParam('fullscreen_is_enabled')) { |
|
45 |
if (ed.getParam('fullscreen_new_window')) |
|
46 |
closeFullscreen(); // Call to close in fullscreen.htm |
|
47 |
else { |
|
48 |
DOM.win.setTimeout(function() { |
|
49 |
var fullscreenEditor = ed; |
|
50 |
|
|
51 |
// find the editor that opened this one, execute restore function there |
|
52 |
var originalEditor = tinyMCE.get(fullscreenEditor.getParam('fullscreen_editor_id')); |
|
53 |
originalEditor.plugins.fullscreen.saveState(fullscreenEditor); |
|
54 |
|
|
55 |
tinyMCE.remove(fullscreenEditor); |
|
56 |
}, 10); |
|
57 |
} |
|
58 |
|
|
59 |
return; |
|
60 |
} |
|
61 |
|
|
62 |
if (ed.getParam('fullscreen_new_window')) { |
|
63 |
t.fullscreenSettings = { |
|
64 |
bookmark: ed.selection.getBookmark() |
|
65 |
}; |
|
66 |
win = DOM.win.open(url + "/fullscreen.htm", "mceFullScreenPopup", "fullscreen=yes,menubar=no,toolbar=no,scrollbars=no,resizable=yes,left=0,top=0,width=" + screen.availWidth + ",height=" + screen.availHeight); |
|
67 |
try { |
|
68 |
win.resizeTo(screen.availWidth, screen.availHeight); |
|
69 |
} catch (e) { |
|
70 |
// Ignore |
|
71 |
} |
|
72 |
} else { |
|
73 |
fullscreen_overflow = DOM.getStyle(DOM.doc.body, 'overflow', 1) || 'auto'; |
|
74 |
fullscreen_html_overflow = DOM.getStyle(de, 'overflow', 1); |
|
75 |
vp = DOM.getViewPort(); |
|
76 |
fullscreen_scrollx = vp.x; |
|
77 |
fullscreen_scrolly = vp.y; |
|
78 |
|
|
79 |
// Fixes an Opera bug where the scrollbars doesn't reappear |
|
80 |
if (tinymce.isOpera && fullscreen_overflow == 'visible') |
|
81 |
fullscreen_overflow = 'auto'; |
|
82 |
|
|
83 |
// Fixes an IE bug where horizontal scrollbars would appear |
|
84 |
if (tinymce.isIE && fullscreen_overflow == 'scroll') |
|
85 |
fullscreen_overflow = 'auto'; |
|
86 |
|
|
87 |
// Fixes an IE bug where the scrollbars doesn't reappear |
|
88 |
if (tinymce.isIE && (fullscreen_html_overflow == 'visible' || fullscreen_html_overflow == 'scroll')) |
|
89 |
fullscreen_html_overflow = 'auto'; |
|
90 |
|
|
91 |
if (fullscreen_overflow == '0px') |
|
92 |
fullscreen_overflow = ''; |
|
93 |
|
|
94 |
DOM.setStyle(DOM.doc.body, 'overflow', 'hidden'); |
|
95 |
de.style.overflow = 'hidden'; //Fix for IE6/7 |
|
96 |
vp = DOM.getViewPort(); |
|
97 |
DOM.win.scrollTo(0, 0); |
|
98 |
|
|
99 |
if (tinymce.isIE) |
|
100 |
vp.h -= 1; |
|
101 |
|
|
102 |
// Use fixed position if it exists |
|
103 |
if (tinymce.isIE6 || document.compatMode == 'BackCompat') |
|
104 |
posCss = 'absolute;top:' + vp.y; |
|
105 |
else |
|
106 |
posCss = 'fixed;top:0'; |
|
107 |
|
|
108 |
n = DOM.add(DOM.doc.body, 'div', { |
|
109 |
id : 'mce_fullscreen_container', |
|
110 |
style : 'position:' + posCss + ';left:0;width:' + vp.w + 'px;height:' + vp.h + 'px;z-index:200000;'}); |
|
111 |
DOM.add(n, 'div', {id : 'mce_fullscreen'}); |
|
112 |
|
|
113 |
tinymce.each(ed.settings, function(v, n) { |
|
114 |
s[n] = v; |
|
115 |
}); |
|
116 |
|
|
117 |
s.id = 'mce_fullscreen'; |
|
118 |
s.width = n.clientWidth; |
|
119 |
s.height = n.clientHeight - 15; |
|
120 |
s.fullscreen_is_enabled = true; |
|
121 |
s.fullscreen_editor_id = ed.id; |
|
122 |
s.theme_advanced_resizing = false; |
|
123 |
s.save_onsavecallback = function() { |
|
124 |
ed.setContent(tinyMCE.get(s.id).getContent()); |
|
125 |
ed.execCommand('mceSave'); |
|
126 |
}; |
|
127 |
|
|
128 |
tinymce.each(ed.getParam('fullscreen_settings'), function(v, k) { |
|
129 |
s[k] = v; |
|
130 |
}); |
|
131 |
|
|
132 |
t.fullscreenSettings = { |
|
133 |
bookmark: ed.selection.getBookmark(), |
|
134 |
fullscreen_overflow: fullscreen_overflow, |
|
135 |
fullscreen_html_overflow: fullscreen_html_overflow, |
|
136 |
fullscreen_scrollx: fullscreen_scrollx, |
|
137 |
fullscreen_scrolly: fullscreen_scrolly |
|
138 |
}; |
|
139 |
|
|
140 |
if (s.theme_advanced_toolbar_location === 'external') |
|
141 |
s.theme_advanced_toolbar_location = 'top'; |
|
142 |
|
|
143 |
tinyMCE.oldSettings = tinyMCE.settings; // Store old settings, the Editor constructor overwrites them |
|
144 |
t.fullscreenEditor = new tinymce.Editor('mce_fullscreen', s); |
|
145 |
t.fullscreenEditor.onInit.add(function() { |
|
146 |
t.loadState(t.fullscreenEditor); |
|
147 |
}); |
|
148 |
|
|
149 |
t.fullscreenEditor.render(); |
|
150 |
|
|
151 |
t.fullscreenElement = new tinymce.dom.Element('mce_fullscreen_container'); |
|
152 |
t.fullscreenElement.update(); |
|
153 |
//document.body.overflow = 'hidden'; |
|
154 |
|
|
155 |
t.resizeFunc = tinymce.dom.Event.add(DOM.win, 'resize', function() { |
|
156 |
var vp = tinymce.DOM.getViewPort(), fed = t.fullscreenEditor, outerSize, innerSize; |
|
157 |
|
|
158 |
// Get outer/inner size to get a delta size that can be used to calc the new iframe size |
|
159 |
outerSize = fed.dom.getSize(fed.getContainer().getElementsByTagName('table')[0]); |
|
160 |
innerSize = fed.dom.getSize(fed.getContainer().getElementsByTagName('iframe')[0]); |
|
161 |
|
|
162 |
fed.theme.resizeTo(vp.w - outerSize.w + innerSize.w, vp.h - outerSize.h + innerSize.h); |
|
163 |
}); |
|
164 |
} |
|
165 |
}); |
|
166 |
|
|
167 |
// Register buttons |
|
168 |
ed.addButton('fullscreen', {title : 'fullscreen.desc', cmd : 'mceFullScreen'}); |
|
169 |
|
|
170 |
ed.onNodeChange.add(function(ed, cm) { |
|
171 |
cm.setActive('fullscreen', ed.getParam('fullscreen_is_enabled')); |
|
172 |
}); |
|
173 |
|
|
174 |
// fullscreenEditor is a param here because in window mode we don't create it |
|
175 |
t.loadState = function(fullscreenEditor) { |
|
176 |
if (!(fullscreenEditor && t.fullscreenSettings)) { |
|
177 |
throw "No fullscreen editor to load to"; |
|
178 |
} |
|
179 |
|
|
180 |
transferState(ed, fullscreenEditor, t.fullscreenSettings.bookmark); |
|
181 |
fullscreenEditor.focus(); |
|
182 |
|
|
183 |
}; |
|
184 |
|
|
185 |
// fullscreenEditor is a param here because in window mode we don't create it |
|
186 |
t.saveState = function(fullscreenEditor) { |
|
187 |
if (!(fullscreenEditor && t.fullscreenSettings)) { |
|
188 |
throw "No fullscreen editor to restore from"; |
|
189 |
} |
|
190 |
var settings = t.fullscreenSettings; |
|
191 |
|
|
192 |
transferState(fullscreenEditor, ed, fullscreenEditor.selection.getBookmark()); |
|
193 |
|
|
194 |
// cleanup only required if window mode isn't used |
|
195 |
if (!ed.getParam('fullscreen_new_window')) { |
|
196 |
tinymce.dom.Event.remove(DOM.win, 'resize', t.resizeFunc); |
|
197 |
delete t.resizeFunc; |
|
198 |
|
|
199 |
DOM.remove('mce_fullscreen_container'); |
|
200 |
|
|
201 |
DOM.doc.documentElement.style.overflow = settings.fullscreen_html_overflow; |
|
202 |
DOM.setStyle(DOM.doc.body, 'overflow', settings.fullscreen_overflow); |
|
203 |
DOM.win.scrollTo(settings.fullscreen_scrollx, settings.fullscreen_scrolly); |
|
204 |
} |
|
205 |
tinyMCE.settings = tinyMCE.oldSettings; // Restore old settings |
|
206 |
|
|
207 |
// clear variables |
|
208 |
delete tinyMCE.oldSettings; |
|
209 |
delete t.fullscreenEditor; |
|
210 |
delete t.fullscreenElement; |
|
211 |
delete t.fullscreenSettings; |
|
212 |
|
|
213 |
// allow the fullscreen editor to be removed before restoring focus and selection |
|
214 |
DOM.win.setTimeout(function() { |
|
215 |
ed.selection.moveToBookmark(bookmark); |
|
216 |
ed.focus(); |
|
217 |
}, 10); |
|
218 |
}; |
|
219 |
}, |
|
220 |
|
|
221 |
getInfo : function() { |
|
222 |
return { |
|
223 |
longname : 'Fullscreen', |
|
224 |
author : 'Moxiecode Systems AB', |
|
225 |
authorurl : 'http://tinymce.moxiecode.com', |
|
226 |
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullscreen', |
|
227 |
version : tinymce.majorVersion + "." + tinymce.minorVersion |
|
228 |
}; |
|
229 |
} |
|
230 |
}); |
|
231 |
|
|
232 |
// Register plugin |
|
233 |
tinymce.PluginManager.add('fullscreen', tinymce.plugins.FullScreenPlugin); |
|
234 |
})(); |