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