1 /*
  2 Copyright (c) 2003-2012, 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 			// Chrome is problematic with moveTo/resizeTo, but it's not really needed here (#8855).
 53 			var ua = navigator.userAgent.toLowerCase();
 54 			if ( ua.indexOf( ' chrome/' ) == -1 )
 55 			{
 56 				popupWindow.moveTo( left, top );
 57 				popupWindow.resizeTo( width, height );
 58 			}
 59 			popupWindow.focus();
 60 			popupWindow.location.href = url;
 61 		}
 62 		catch ( e )
 63 		{
 64 			popupWindow = window.open( url, null, options, true );
 65 		}
 66 
 67 		return true;
 68 	}
 69 });
 70