Bugfix : prendre le innerHTML du body du document n'est pas une bonne idée, dans...
[ckeditor.git] / skins / ckeditor / _source / plugins / popup / plugin.js
1 /*
2 Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved.
3 For licensing, see LICENSE.html or http://ckeditor.com/license
4 */
5
6 CKEDITOR.plugins.add( 'popup' );
7
8 CKEDITOR.tools.extend( CKEDITOR.editor.prototype,
9 {
10 /**
11 * Opens Browser in a popup. The "width" and "height" parameters accept
12 * numbers (pixels) or percent (of screen size) values.
13 * @param {String} url The url of the external file browser.
14 * @param {String} width Popup window width.
15 * @param {String} height Popup window height.
16 * @param {String} options Popup window features.
17 */
18 popup : function( url, width, height, options )
19 {
20 width = width || '80%';
21 height = height || '70%';
22
23 if ( typeof width == 'string' && width.length > 1 && width.substr( width.length - 1, 1 ) == '%' )
24 width = parseInt( window.screen.width * parseInt( width, 10 ) / 100, 10 );
25
26 if ( typeof height == 'string' && height.length > 1 && height.substr( height.length - 1, 1 ) == '%' )
27 height = parseInt( window.screen.height * parseInt( height, 10 ) / 100, 10 );
28
29 if ( width < 640 )
30 width = 640;
31
32 if ( height < 420 )
33 height = 420;
34
35 var top = parseInt( ( window.screen.height - height ) / 2, 10 ),
36 left = parseInt( ( window.screen.width - width ) / 2, 10 );
37
38 options = ( options || 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes' ) +
39 ',width=' + width +
40 ',height=' + height +
41 ',top=' + top +
42 ',left=' + left;
43
44 var popupWindow = window.open( '', null, options, true );
45
46 // Blocked by a popup blocker.
47 if ( !popupWindow )
48 return false;
49
50 try
51 {
52 popupWindow.moveTo( left, top );
53 popupWindow.resizeTo( width, height );
54 popupWindow.focus();
55 popupWindow.location.href = url;
56 }
57 catch ( e )
58 {
59 popupWindow = window.open( url, null, options, true );
60 }
61
62 return true;
63 }
64 });