ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

tinymce.plugin.code.js (1570B)


      1 /**
      2  * plugin.js
      3  *
      4  * Released under LGPL License.
      5  * Copyright (c) 1999-2015 Ephox Corp. All rights reserved
      6  *
      7  * License: http://www.tinymce.com/license
      8  * Contributing: http://www.tinymce.com/contributing
      9  */
     10 
     11 /*global tinymce:true */
     12 
     13 tinymce.PluginManager.add('code', function(editor) {
     14 	function showDialog() {
     15 		var win = editor.windowManager.open({
     16 			title: "Source code",
     17 			body: {
     18 				type: 'textbox',
     19 				name: 'code',
     20 				multiline: true,
     21 				minWidth: editor.getParam("code_dialog_width", 600),
     22 				minHeight: editor.getParam("code_dialog_height", Math.min(tinymce.DOM.getViewPort().h - 200, 500)),
     23 				spellcheck: false,
     24 				style: 'direction: ltr; text-align: left'
     25 			},
     26 			onSubmit: function(e) {
     27 				// We get a lovely "Wrong document" error in IE 11 if we
     28 				// don't move the focus to the editor before creating an undo
     29 				// transation since it tries to make a bookmark for the current selection
     30 				editor.focus();
     31 
     32 				editor.undoManager.transact(function() {
     33 					editor.setContent(e.data.code);
     34 				});
     35 
     36 				editor.selection.setCursorLocation();
     37 				editor.nodeChanged();
     38 			}
     39 		});
     40 
     41 		// Gecko has a major performance issue with textarea
     42 		// contents so we need to set it when all reflows are done
     43 		win.find('#code').value(editor.getContent({source_view: true}));
     44 	}
     45 
     46 	editor.addCommand("mceCodeEditor", showDialog);
     47 
     48 	editor.addButton('code', {
     49 		icon: 'code',
     50 		tooltip: 'Source code',
     51 		onclick: showDialog
     52 	});
     53 
     54 	editor.addMenuItem('code', {
     55 		icon: 'code',
     56 		text: 'Source code',
     57 		context: 'tools',
     58 		onclick: showDialog
     59 	});
     60 });