src/myams/resources/js/ext/tinymce/dev/plugins/visualblocks/plugin.js
changeset 0 f05d7aea098a
equal deleted inserted replaced
-1:000000000000 0:f05d7aea098a
       
     1 /**
       
     2  * plugin.js
       
     3  *
       
     4  * Copyright 2012, Moxiecode Systems AB
       
     5  * Released under LGPL License.
       
     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('visualblocks', function(editor, url) {
       
    14 	var cssId, visualBlocksMenuItem, enabled;
       
    15 
       
    16 	// We don't support older browsers like IE6/7 and they don't provide prototypes for DOM objects
       
    17 	if (!window.NodeList) {
       
    18 		return;
       
    19 	}
       
    20 
       
    21 	function toggleActiveState() {
       
    22 		var self = this;
       
    23 
       
    24 		self.active(enabled);
       
    25 
       
    26 		editor.on('VisualBlocks', function() {
       
    27 			self.active(editor.dom.hasClass(editor.getBody(), 'mce-visualblocks'));
       
    28 		});
       
    29 	}
       
    30 
       
    31 	editor.addCommand('mceVisualBlocks', function() {
       
    32 		var dom = editor.dom, linkElm;
       
    33 
       
    34 		if (!cssId) {
       
    35 			cssId = dom.uniqueId();
       
    36 			linkElm = dom.create('link', {
       
    37 				id: cssId,
       
    38 				rel: 'stylesheet',
       
    39 				href: url + '/css/visualblocks.css'
       
    40 			});
       
    41 
       
    42 			editor.getDoc().getElementsByTagName('head')[0].appendChild(linkElm);
       
    43 		}
       
    44 
       
    45 		// Toggle on/off visual blocks while computing previews
       
    46 		editor.on("PreviewFormats AfterPreviewFormats", function(e) {
       
    47 			if (enabled) {
       
    48 				dom.toggleClass(editor.getBody(), 'mce-visualblocks', e.type == "afterpreviewformats");
       
    49 			}
       
    50 		});
       
    51 
       
    52 		dom.toggleClass(editor.getBody(), 'mce-visualblocks');
       
    53 		enabled = editor.dom.hasClass(editor.getBody(), 'mce-visualblocks');
       
    54 
       
    55 		if (visualBlocksMenuItem) {
       
    56 			visualBlocksMenuItem.active(dom.hasClass(editor.getBody(), 'mce-visualblocks'));
       
    57 		}
       
    58 
       
    59 		editor.fire('VisualBlocks');
       
    60 	});
       
    61 
       
    62 	editor.addButton('visualblocks', {
       
    63 		title: 'Show blocks',
       
    64 		cmd: 'mceVisualBlocks',
       
    65 		onPostRender: toggleActiveState
       
    66 	});
       
    67 
       
    68 	editor.addMenuItem('visualblocks', {
       
    69 		text: 'Show blocks',
       
    70 		cmd: 'mceVisualBlocks',
       
    71 		onPostRender: toggleActiveState,
       
    72 		selectable: true,
       
    73 		context: 'view',
       
    74 		prependToContext: true
       
    75 	});
       
    76 
       
    77 	editor.on('init', function() {
       
    78 		if (editor.settings.visualblocks_default_state) {
       
    79 			editor.execCommand('mceVisualBlocks', false, null, {skip_focus: true});
       
    80 		}
       
    81 	});
       
    82 
       
    83 	editor.on('remove', function() {
       
    84 		editor.dom.removeClass(editor.getBody(), 'mce-visualblocks');
       
    85 	});
       
    86 });