JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.4.2
[ckeditor.git] / _source / plugins / popup / plugin.js
1 /*\r
2 Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
3 For licensing, see LICENSE.html 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         /**\r
11          * Opens Browser in a popup. The "width" and "height" parameters accept\r
12          * numbers (pixels) or percent (of screen size) values.\r
13          * @param {String} url The url of the external file browser.\r
14          * @param {String} width Popup window width.\r
15          * @param {String} height Popup window height.\r
16          * @param {String} options Popup window features.\r
17          */\r
18         popup : function( url, width, height, options )\r
19         {\r
20                 width = width || '80%';\r
21                 height = height || '70%';\r
22 \r
23                 if ( typeof width == 'string' && width.length > 1 && width.substr( width.length - 1, 1 ) == '%' )\r
24                         width = parseInt( window.screen.width * parseInt( width, 10 ) / 100, 10 );\r
25 \r
26                 if ( typeof height == 'string' && height.length > 1 && height.substr( height.length - 1, 1 ) == '%' )\r
27                         height = parseInt( window.screen.height * parseInt( height, 10 ) / 100, 10 );\r
28 \r
29                 if ( width < 640 )\r
30                         width = 640;\r
31 \r
32                 if ( height < 420 )\r
33                         height = 420;\r
34 \r
35                 var top = parseInt( ( window.screen.height - height ) / 2, 10 ),\r
36                         left = parseInt( ( window.screen.width  - width ) / 2, 10 );\r
37 \r
38                 options = ( options || 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes,scrollbars=yes' ) +\r
39                         ',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                 {\r
52                         popupWindow.moveTo( left, top );\r
53                         popupWindow.resizeTo( width, height );\r
54                         popupWindow.focus();\r
55                         popupWindow.location.href = url;\r
56                 }\r
57                 catch ( e )\r
58                 {\r
59                         popupWindow = window.open( url, null, options, true );\r
60                 }\r
61 \r
62                 return true;\r
63         }\r
64 });\r