]> git.immae.eu Git - perso/Immae/Projets/packagist/ludivine-ckeditor-component.git/blob - sources/plugins/popup/plugin.js
Update to 4.7.3
[perso/Immae/Projets/packagist/ludivine-ckeditor-component.git] / sources / plugins / popup / plugin.js
1 /**
2 * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
3 * For licensing, see LICENSE.md or http://ckeditor.com/license
4 */
5
6 CKEDITOR.plugins.add( 'popup' );
7
8 CKEDITOR.tools.extend( CKEDITOR.editor.prototype, {
9 /**
10 * Opens Browser in a popup. The `width` and `height` parameters accept
11 * numbers (pixels) or percent (of screen size) values.
12 *
13 * @member CKEDITOR.editor
14 * @param {String} url The url of the external file browser.
15 * @param {Number/String} [width='80%'] Popup window width.
16 * @param {Number/String} [height='70%'] Popup window height.
17 * @param {String} [options='location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes']
18 * Popup window features.
19 */
20 popup: function( url, width, height, options ) {
21 width = width || '80%';
22 height = height || '70%';
23
24 if ( typeof width == 'string' && width.length > 1 && width.substr( width.length - 1, 1 ) == '%' )
25 width = parseInt( window.screen.width * parseInt( width, 10 ) / 100, 10 );
26
27 if ( typeof height == 'string' && height.length > 1 && height.substr( height.length - 1, 1 ) == '%' )
28 height = parseInt( window.screen.height * parseInt( height, 10 ) / 100, 10 );
29
30 if ( width < 640 )
31 width = 640;
32
33 if ( height < 420 )
34 height = 420;
35
36 var top = parseInt( ( window.screen.height - height ) / 2, 10 ),
37 left = parseInt( ( window.screen.width - width ) / 2, 10 );
38
39 options = ( options || 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes' ) + ',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 // Chrome is problematic with moveTo/resizeTo, but it's not really needed here (http://dev.ckeditor.com/ticket/8855).
52 var ua = navigator.userAgent.toLowerCase();
53 if ( ua.indexOf( ' chrome/' ) == -1 ) {
54 popupWindow.moveTo( left, top );
55 popupWindow.resizeTo( width, height );
56 }
57 popupWindow.focus();
58 popupWindow.location.href = url;
59 } catch ( e ) {
60 popupWindow = window.open( url, null, options, true );
61 }
62
63 return true;
64 }
65 } );