PageRenderTime 44ms CodeModel.GetById 32ms app.highlight 8ms RepoModel.GetById 0ms app.codeStats 1ms

/BlogEngine/BlogEngine.NET/editors/tiny_mce_3_4_3_1/plugins/fullscreen/editor_plugin_src.js

#
JavaScript | 159 lines | 111 code | 29 blank | 19 comment | 22 complexity | bc3c84eebde0bcf8692d3d7becfb072b MD5 | raw file
  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	tinymce.create('tinymce.plugins.FullScreenPlugin', {
 15		init : function(ed, url) {
 16			var t = this, s = {}, vp, posCss;
 17
 18			t.editor = ed;
 19
 20			// Register commands
 21			ed.addCommand('mceFullScreen', function() {
 22				var win, de = DOM.doc.documentElement;
 23
 24				if (ed.getParam('fullscreen_is_enabled')) {
 25					if (ed.getParam('fullscreen_new_window'))
 26						closeFullscreen(); // Call to close in new window
 27					else {
 28						DOM.win.setTimeout(function() {
 29							tinymce.dom.Event.remove(DOM.win, 'resize', t.resizeFunc);
 30							tinyMCE.get(ed.getParam('fullscreen_editor_id')).setContent(ed.getContent({format : 'raw'}), {format : 'raw'});
 31							tinyMCE.remove(ed);
 32							DOM.remove('mce_fullscreen_container');
 33							de.style.overflow = ed.getParam('fullscreen_html_overflow');
 34							DOM.setStyle(DOM.doc.body, 'overflow', ed.getParam('fullscreen_overflow'));
 35							DOM.win.scrollTo(ed.getParam('fullscreen_scrollx'), ed.getParam('fullscreen_scrolly'));
 36							tinyMCE.settings = tinyMCE.oldSettings; // Restore old settings
 37						}, 10);
 38					}
 39
 40					return;
 41				}
 42
 43				if (ed.getParam('fullscreen_new_window')) {
 44					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);
 45					try {
 46						win.resizeTo(screen.availWidth, screen.availHeight);
 47					} catch (e) {
 48						// Ignore
 49					}
 50				} else {
 51					tinyMCE.oldSettings = tinyMCE.settings; // Store old settings
 52					s.fullscreen_overflow = DOM.getStyle(DOM.doc.body, 'overflow', 1) || 'auto';
 53					s.fullscreen_html_overflow = DOM.getStyle(de, 'overflow', 1);
 54					vp = DOM.getViewPort();
 55					s.fullscreen_scrollx = vp.x;
 56					s.fullscreen_scrolly = vp.y;
 57
 58					// Fixes an Opera bug where the scrollbars doesn't reappear
 59					if (tinymce.isOpera && s.fullscreen_overflow == 'visible')
 60						s.fullscreen_overflow = 'auto';
 61
 62					// Fixes an IE bug where horizontal scrollbars would appear
 63					if (tinymce.isIE && s.fullscreen_overflow == 'scroll')
 64						s.fullscreen_overflow = 'auto';
 65
 66					// Fixes an IE bug where the scrollbars doesn't reappear
 67					if (tinymce.isIE && (s.fullscreen_html_overflow == 'visible' || s.fullscreen_html_overflow == 'scroll'))
 68						s.fullscreen_html_overflow = 'auto'; 
 69
 70					if (s.fullscreen_overflow == '0px')
 71						s.fullscreen_overflow = '';
 72
 73					DOM.setStyle(DOM.doc.body, 'overflow', 'hidden');
 74					de.style.overflow = 'hidden'; //Fix for IE6/7
 75					vp = DOM.getViewPort();
 76					DOM.win.scrollTo(0, 0);
 77
 78					if (tinymce.isIE)
 79						vp.h -= 1;
 80
 81					// Use fixed position if it exists
 82					if (tinymce.isIE6)
 83						posCss = 'absolute;top:' + vp.y;
 84					else
 85						posCss = 'fixed;top:0';
 86
 87					n = DOM.add(DOM.doc.body, 'div', {
 88						id : 'mce_fullscreen_container', 
 89						style : 'position:' + posCss + ';left:0;width:' + vp.w + 'px;height:' + vp.h + 'px;z-index:200000;'});
 90					DOM.add(n, 'div', {id : 'mce_fullscreen'});
 91
 92					tinymce.each(ed.settings, function(v, n) {
 93						s[n] = v;
 94					});
 95
 96					s.id = 'mce_fullscreen';
 97					s.width = n.clientWidth;
 98					s.height = n.clientHeight - 15;
 99					s.fullscreen_is_enabled = true;
100					s.fullscreen_editor_id = ed.id;
101					s.theme_advanced_resizing = false;
102					s.save_onsavecallback = function() {
103						ed.setContent(tinyMCE.get(s.id).getContent({format : 'raw'}), {format : 'raw'});
104						ed.execCommand('mceSave');
105					};
106
107					tinymce.each(ed.getParam('fullscreen_settings'), function(v, k) {
108						s[k] = v;
109					});
110
111					if (s.theme_advanced_toolbar_location === 'external')
112						s.theme_advanced_toolbar_location = 'top';
113
114					t.fullscreenEditor = new tinymce.Editor('mce_fullscreen', s);
115					t.fullscreenEditor.onInit.add(function() {
116						t.fullscreenEditor.setContent(ed.getContent());
117						t.fullscreenEditor.focus();
118					});
119
120					t.fullscreenEditor.render();
121
122					t.fullscreenElement = new tinymce.dom.Element('mce_fullscreen_container');
123					t.fullscreenElement.update();
124					//document.body.overflow = 'hidden';
125
126					t.resizeFunc = tinymce.dom.Event.add(DOM.win, 'resize', function() {
127						var vp = tinymce.DOM.getViewPort(), fed = t.fullscreenEditor, outerSize, innerSize;
128
129						// Get outer/inner size to get a delta size that can be used to calc the new iframe size
130						outerSize = fed.dom.getSize(fed.getContainer().firstChild);
131						innerSize = fed.dom.getSize(fed.getContainer().getElementsByTagName('iframe')[0]);
132
133						fed.theme.resizeTo(vp.w - outerSize.w + innerSize.w, vp.h - outerSize.h + innerSize.h);
134					});
135				}
136			});
137
138			// Register buttons
139			ed.addButton('fullscreen', {title : 'fullscreen.desc', cmd : 'mceFullScreen'});
140
141			ed.onNodeChange.add(function(ed, cm) {
142				cm.setActive('fullscreen', ed.getParam('fullscreen_is_enabled'));
143			});
144		},
145
146		getInfo : function() {
147			return {
148				longname : 'Fullscreen',
149				author : 'Moxiecode Systems AB',
150				authorurl : 'http://tinymce.moxiecode.com',
151				infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullscreen',
152				version : tinymce.majorVersion + "." + tinymce.minorVersion
153			};
154		}
155	});
156
157	// Register plugin
158	tinymce.PluginManager.add('fullscreen', tinymce.plugins.FullScreenPlugin);
159})();