plugin.js 2.3 KB

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