src/pyams_skin/resources/js/ext/tinymce/dev/plugins/preview/plugin.js
changeset 69 a361355b55c7
equal deleted inserted replaced
68:fd8fb93e1b6a 69:a361355b55c7
       
     1 /**
       
     2  * plugin.js
       
     3  *
       
     4  * Copyright, 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('preview', function(editor) {
       
    14 	var settings = editor.settings, sandbox = !tinymce.Env.ie;
       
    15 
       
    16 	editor.addCommand('mcePreview', function() {
       
    17 		editor.windowManager.open({
       
    18 			title: 'Preview',
       
    19 			width: parseInt(editor.getParam("plugin_preview_width", "650"), 10),
       
    20 			height: parseInt(editor.getParam("plugin_preview_height", "500"), 10),
       
    21 			html: '<iframe src="javascript:\'\'" frameborder="0"' + (sandbox ? ' sandbox="allow-scripts"' : '') + '></iframe>',
       
    22 			buttons: {
       
    23 				text: 'Close',
       
    24 				onclick: function() {
       
    25 					this.parent().parent().close();
       
    26 				}
       
    27 			},
       
    28 			onPostRender: function() {
       
    29 				var previewHtml, headHtml = '';
       
    30 
       
    31 				headHtml += '<base href="' + editor.documentBaseURI.getURI() + '">';
       
    32 
       
    33 				tinymce.each(editor.contentCSS, function(url) {
       
    34 					headHtml += '<link type="text/css" rel="stylesheet" href="' + editor.documentBaseURI.toAbsolute(url) + '">';
       
    35 				});
       
    36 
       
    37 				var bodyId = settings.body_id || 'tinymce';
       
    38 				if (bodyId.indexOf('=') != -1) {
       
    39 					bodyId = editor.getParam('body_id', '', 'hash');
       
    40 					bodyId = bodyId[editor.id] || bodyId;
       
    41 				}
       
    42 
       
    43 				var bodyClass = settings.body_class || '';
       
    44 				if (bodyClass.indexOf('=') != -1) {
       
    45 					bodyClass = editor.getParam('body_class', '', 'hash');
       
    46 					bodyClass = bodyClass[editor.id] || '';
       
    47 				}
       
    48 
       
    49 				var dirAttr = editor.settings.directionality ? ' dir="' + editor.settings.directionality + '"' : '';
       
    50 
       
    51 				previewHtml = (
       
    52 					'<!DOCTYPE html>' +
       
    53 					'<html>' +
       
    54 					'<head>' +
       
    55 						headHtml +
       
    56 					'</head>' +
       
    57 					'<body id="' + bodyId + '" class="mce-content-body ' + bodyClass + '"' + dirAttr + '>' +
       
    58 						editor.getContent() +
       
    59 					'</body>' +
       
    60 					'</html>'
       
    61 				);
       
    62 
       
    63 				if (!sandbox) {
       
    64 					// IE 6-11 doesn't support data uris on iframes
       
    65 					// so I guess they will have to be less secure since we can't sandbox on those
       
    66 					// TODO: Use sandbox if future versions of IE supports iframes with data: uris.
       
    67 					var doc = this.getEl('body').firstChild.contentWindow.document;
       
    68 					doc.open();
       
    69 					doc.write(previewHtml);
       
    70 					doc.close();
       
    71 				} else {
       
    72 					this.getEl('body').firstChild.src = 'data:text/html;charset=utf-8,' + encodeURIComponent(previewHtml);
       
    73 				}
       
    74 			}
       
    75 		});
       
    76 	});
       
    77 
       
    78 	editor.addButton('preview', {
       
    79 		title: 'Preview',
       
    80 		cmd: 'mcePreview'
       
    81 	});
       
    82 
       
    83 	editor.addMenuItem('preview', {
       
    84 		text: 'Preview',
       
    85 		cmd: 'mcePreview',
       
    86 		context: 'view'
       
    87 	});
       
    88 });