JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
731ab19b19c43f76d85ea6e3edca91246f9b0b6f
[ckeditor.git] / _source / plugins / popup / plugin.js
1 /*\r
2 Copyright (c) 2003-2009, 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          */\r
17         popup : function( url, width, height )\r
18         {\r
19                 width = width || '80%';\r
20                 height = height || '70%';\r
21 \r
22                 if ( typeof width == 'string' && width.length > 1 && width.substr( width.length - 1, 1 ) == '%' )\r
23                         width = parseInt( window.screen.width * parseInt( width, 10 ) / 100, 10 );\r
24 \r
25                 if ( typeof height == 'string' && height.length > 1 && height.substr( height.length - 1, 1 ) == '%' )\r
26                         height = parseInt( window.screen.height * parseInt( height, 10 ) / 100, 10 );\r
27 \r
28                 if ( width < 640 )\r
29                         width = 640;\r
30 \r
31                 if ( height < 420 )\r
32                         height = 420;\r
33 \r
34                 var top = parseInt( ( window.screen.height - height ) / 2, 10 ),\r
35                         left = parseInt( ( window.screen.width  - width ) / 2, 10 ),\r
36                         options = 'location=no,menubar=no,toolbar=no,dependent=yes,minimizable=no,modal=yes,alwaysRaised=yes,resizable=yes' +\r
37                         ',width='  + width +\r
38                         ',height=' + height +\r
39                         ',top='  + top +\r
40                         ',left=' + left;\r
41 \r
42                 var popupWindow = window.open( '', null, options, true );\r
43 \r
44                 // Blocked by a popup blocker.\r
45                 if ( !popupWindow )\r
46                         return false;\r
47 \r
48                 try\r
49                 {\r
50                         popupWindow.moveTo( left, top );\r
51                         popupWindow.resizeTo( width, height );\r
52                         popupWindow.focus();\r
53                         popupWindow.location.href = url;\r
54                 }\r
55                 catch (e)\r
56                 {\r
57                         popupWindow = window.open( url, null, options, true );\r
58                 }\r
59 \r
60                 return true ;\r
61         }\r
62 });\r