PageRenderTime 13ms CodeModel.GetById 61ms app.highlight 12ms RepoModel.GetById 38ms app.codeStats 0ms

/static/scripts/tiny_mce/plugins/fullscreen/editor_plugin_src.js

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