includes/clientside/tinymce/plugins/fullscreen/editor_plugin_src.js
changeset 1 fe660c52c48f
child 335 67bd3121a12e
equal deleted inserted replaced
0:902822492a68 1:fe660c52c48f
       
     1 /**
       
     2  * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z 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('fullscreen');
       
    10 
       
    11 var TinyMCE_FullScreenPlugin = {
       
    12 	getInfo : function() {
       
    13 		return {
       
    14 			longname : 'Fullscreen',
       
    15 			author : 'Moxiecode Systems AB',
       
    16 			authorurl : 'http://tinymce.moxiecode.com',
       
    17 			infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/fullscreen',
       
    18 			version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
       
    19 		};
       
    20 	},
       
    21 
       
    22 	initInstance : function(inst) {
       
    23 		if (!tinyMCE.settings['fullscreen_skip_plugin_css'])
       
    24 			tinyMCE.importCSS(inst.getContainerWin().document, tinyMCE.baseURL + "/plugins/fullscreen/css/page.css");
       
    25 	},
       
    26 
       
    27 	getControlHTML : function(cn) {
       
    28 		switch (cn) {
       
    29 			case "fullscreen":
       
    30 				return tinyMCE.getButtonHTML(cn, 'lang_fullscreen_desc', '{$pluginurl}/images/fullscreen.gif', 'mceFullScreen');
       
    31 		}
       
    32 
       
    33 		return "";
       
    34 	},
       
    35 
       
    36 	execCommand : function(editor_id, element, command, user_interface, value) {
       
    37 		var inst;
       
    38 
       
    39 		// Handle commands
       
    40 		switch (command) {
       
    41 			case "mceFullScreen":
       
    42 				inst = tinyMCE.getInstanceById(editor_id);
       
    43 
       
    44 				if (tinyMCE.getParam('fullscreen_new_window'))
       
    45 					this._toggleFullscreenWin(inst);
       
    46 				else
       
    47 					this._toggleFullscreen(inst);
       
    48 
       
    49 				return true;
       
    50 		}
       
    51 
       
    52 		// Pass to next handler in chain
       
    53 		return false;
       
    54 	},
       
    55 
       
    56 	_toggleFullscreenWin : function(inst) {
       
    57 		if (tinyMCE.getParam('fullscreen_is_enabled')) {
       
    58 			// In fullscreen mode
       
    59 			window.opener.tinyMCE.execInstanceCommand(tinyMCE.getParam('fullscreen_editor_id'), 'mceSetContent', false, tinyMCE.getContent(inst.editorId));
       
    60 			top.close();
       
    61 		} else {
       
    62 			tinyMCE.setWindowArg('editor_id', inst.editorId);
       
    63 
       
    64 			var win = window.open(tinyMCE.baseURL + "/plugins/fullscreen/fullscreen.htm", "mceFullScreenPopup", "fullscreen=yes,menubar=no,toolbar=no,scrollbars=no,resizable=yes,left=0,top=0,width=" + screen.availWidth + ",height=" + screen.availHeight);
       
    65 			try { win.resizeTo(screen.availWidth, screen.availHeight); } catch (e) {}
       
    66 		}
       
    67 	},
       
    68 
       
    69 	_toggleFullscreen : function(inst) {
       
    70 		var ds = inst.getData('fullscreen'), editorContainer, tableElm, iframe, vp, cw, cd, re, w, h, si, blo, delta = 0, cell, row, fcml, bcml;
       
    71 
       
    72 		cw = inst.getContainerWin();
       
    73 		cd = cw.document;
       
    74 		editorContainer = cd.getElementById(inst.editorId + '_parent');
       
    75 		tableElm = editorContainer.firstChild;
       
    76 		iframe = inst.iframeElement;
       
    77 		re = cd.getElementById(inst.editorId + '_resize');
       
    78 		blo = document.getElementById('mce_fullscreen_blocker');
       
    79 		fcm = new TinyMCE_Layer(inst.editorId + '_fcMenu');
       
    80 		fcml = new TinyMCE_Layer(inst.editorId + '_fcMenu');
       
    81 		bcml = new TinyMCE_Layer(inst.editorId + '_bcMenu');
       
    82 
       
    83 		if (fcml.exists() && fcml.isVisible()) {
       
    84 			tinyMCE.switchClass(inst.editorId + '_forecolor', 'mceMenuButton');
       
    85 			fcml.hide();
       
    86 		}
       
    87 
       
    88 		if (bcml.exists() && bcml.isVisible()) {
       
    89 			tinyMCE.switchClass(inst.editorId + '_backcolor', 'mceMenuButton');
       
    90 			bcml.hide();
       
    91 		}
       
    92 
       
    93 		if (!ds.enabled) {
       
    94 			// Handle External Toolbar
       
    95 			if (inst.toolbarElement) {
       
    96 				delta += inst.toolbarElement.offsetHeight;
       
    97 
       
    98 				cell = tableElm.tBodies[0].insertRow(0).insertCell(-1);
       
    99 				cell.className = 'mceToolbarTop';
       
   100 				cell.nowrap = true;
       
   101 
       
   102 				ds.oldToolbarParent = inst.toolbarElement.parentNode;
       
   103 				ds.toolbarHolder = document.createTextNode('...');
       
   104 
       
   105 				cell.appendChild(ds.oldToolbarParent.replaceChild(ds.toolbarHolder, inst.toolbarElement));
       
   106 			}
       
   107 
       
   108 			ds.parents = [];
       
   109 
       
   110 			vp = tinyMCE.getViewPort(cw);
       
   111 			ds.scrollX = vp.left;
       
   112 			ds.scrollY = vp.top;
       
   113 
       
   114 			// Opera has a bug restoring scrollbars
       
   115 			if (!tinyMCE.isOpera)
       
   116 				tinyMCE.addCSSClass(cd.body, 'mceFullscreen');
       
   117 
       
   118 			tinyMCE.getParentNode(tableElm.parentNode, function (n) {
       
   119 				if (n.nodeName == 'BODY')
       
   120 					return true;
       
   121 
       
   122 				if (n.nodeType == 1)
       
   123 					tinyMCE.addCSSClass(n, 'mceFullscreenPos');
       
   124 
       
   125 				return false;
       
   126 			});
       
   127 
       
   128 			if (re)
       
   129 				re.style.display = 'none';
       
   130 
       
   131 			vp = tinyMCE.getViewPort(cw);
       
   132 
       
   133 			ds.oldWidth = iframe.style.width ? iframe.style.width : iframe.offsetWidth;
       
   134 			ds.oldHeight = iframe.style.height ? iframe.style.height : iframe.offsetHeight;
       
   135 			ds.oldTWidth = tableElm.style.width ? tableElm.style.width : tableElm.offsetWidth;
       
   136 			ds.oldTHeight = tableElm.style.height ? tableElm.style.height : tableElm.offsetHeight;
       
   137 
       
   138 			// Handle % width
       
   139 			if (ds.oldWidth && ds.oldWidth.indexOf)
       
   140 				ds.oldTWidth = ds.oldWidth.indexOf('%') != -1 ? ds.oldWidth : ds.oldTWidth;
       
   141 
       
   142 			if (!blo && tinyMCE.isRealIE) {
       
   143 				blo = tinyMCE.createTag(document, 'iframe', {id : 'mce_fullscreen_blocker', src : 'about:blank', frameBorder : 0, width : vp.width, height : vp.height, style : 'display: block; position: absolute; left: 0; top: 0; z-index: 999; margin: 0; padding: 0;'});
       
   144 				document.body.appendChild(blo);
       
   145 			}
       
   146 
       
   147 			tableElm.style.position = 'absolute';
       
   148 			tableElm.style.zIndex = 1000;
       
   149 			tableElm.style.left = tableElm.style.top = '0';
       
   150 
       
   151 			tableElm.style.width = vp.width + 'px';
       
   152 			tableElm.style.height = vp.height + 'px';
       
   153 
       
   154 			if (tinyMCE.isRealIE) {
       
   155 				iframe.style.width = vp.width + 'px';
       
   156 				iframe.style.height = vp.height + 'px';
       
   157 
       
   158 				// Calc new width/height based on overflow
       
   159 				w = iframe.parentNode.clientWidth - (tableElm.offsetWidth - vp.width);
       
   160 				h = iframe.parentNode.clientHeight - (tableElm.offsetHeight - vp.height);
       
   161 			} else {
       
   162 				w = iframe.parentNode.clientWidth;
       
   163 				h = iframe.parentNode.clientHeight;
       
   164 			}
       
   165 
       
   166 			iframe.style.width = w + "px";
       
   167 			iframe.style.height = (h+delta) + "px";
       
   168 
       
   169 			tinyMCE.switchClass(inst.editorId + '_fullscreen', 'mceButtonSelected');
       
   170 			ds.enabled = true;
       
   171 
       
   172 			inst.useCSS = false;
       
   173 		} else {
       
   174 			// Handle External Toolbar
       
   175 			if (inst.toolbarElement) {
       
   176 				row = inst.toolbarElement.parentNode.parentNode;
       
   177 
       
   178 				row.parentNode.removeChild(row);
       
   179 
       
   180 				ds.oldToolbarParent.replaceChild(inst.toolbarElement, ds.toolbarHolder);
       
   181 
       
   182 				ds.oldToolbarParent = null;
       
   183 				ds.toolbarHolder = null;
       
   184 			}
       
   185 
       
   186 			if (blo)
       
   187 				blo.parentNode.removeChild(blo);
       
   188 
       
   189 			si = 0;
       
   190 			tinyMCE.getParentNode(tableElm.parentNode, function (n) {
       
   191 				if (n.nodeName == 'BODY')
       
   192 					return true;
       
   193 
       
   194 				if (n.nodeType == 1)
       
   195 					tinyMCE.removeCSSClass(n, 'mceFullscreenPos');
       
   196 			});
       
   197 
       
   198 			if (re && tinyMCE.getParam("theme_advanced_resizing", false))
       
   199 				re.style.display = 'block';
       
   200 
       
   201 			tableElm.style.position = 'static';
       
   202 			tableElm.style.zIndex = '';
       
   203 			tableElm.style.width = '';
       
   204 			tableElm.style.height = '';
       
   205 
       
   206 			tableElm.style.width = ds.oldTWidth ? ds.oldTWidth : '';
       
   207 			tableElm.style.height = ds.oldTHeight ? ds.oldTHeight : '';
       
   208 
       
   209 			iframe.style.width = ds.oldWidth ? ds.oldWidth : '';
       
   210 			iframe.style.height = ds.oldHeight ? ds.oldHeight : '';
       
   211 
       
   212 			tinyMCE.switchClass(inst.editorId + '_fullscreen', 'mceButtonNormal');
       
   213 			ds.enabled = false;
       
   214 
       
   215 			tinyMCE.removeCSSClass(cd.body, 'mceFullscreen');
       
   216 			cw.scrollTo(ds.scrollX, ds.scrollY);
       
   217 
       
   218 			inst.useCSS = false;
       
   219 		}
       
   220 	},
       
   221 
       
   222 	handleNodeChange : function(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
       
   223 		if (tinyMCE.getParam('fullscreen_is_enabled'))
       
   224 			tinyMCE.switchClass(editor_id + '_fullscreen', 'mceButtonSelected');
       
   225 
       
   226 		return true;
       
   227 	}
       
   228 };
       
   229 
       
   230 tinyMCE.addPlugin("fullscreen", TinyMCE_FullScreenPlugin);