Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

93 righe
2.4 KiB

  1. /* global tinymce */
  2. /**
  3. * Included for back-compat.
  4. * The default WindowManager in TinyMCE 4.0 supports three types of dialogs:
  5. * - With HTML created from JS.
  6. * - With inline HTML (like WPWindowManager).
  7. * - Old type iframe based dialogs.
  8. * For examples see the default plugins: https://github.com/tinymce/tinymce/tree/master/js/tinymce/plugins
  9. */
  10. tinymce.WPWindowManager = tinymce.InlineWindowManager = function( editor ) {
  11. if ( this.wp ) {
  12. return this;
  13. }
  14. this.wp = {};
  15. this.parent = editor.windowManager;
  16. this.editor = editor;
  17. tinymce.extend( this, this.parent );
  18. this.open = function( args, params ) {
  19. var $element,
  20. self = this,
  21. wp = this.wp;
  22. if ( ! args.wpDialog ) {
  23. return this.parent.open.apply( this, arguments );
  24. } else if ( ! args.id ) {
  25. return;
  26. }
  27. if ( typeof jQuery === 'undefined' || ! jQuery.wp || ! jQuery.wp.wpdialog ) {
  28. // wpdialog.js is not loaded
  29. if ( window.console && window.console.error ) {
  30. window.console.error('wpdialog.js is not loaded. Please set "wpdialogs" as dependency for your script when calling wp_enqueue_script(). You may also want to enqueue the "wp-jquery-ui-dialog" stylesheet.');
  31. }
  32. return;
  33. }
  34. wp.$element = $element = jQuery( '#' + args.id );
  35. if ( ! $element.length ) {
  36. return;
  37. }
  38. if ( window.console && window.console.log ) {
  39. window.console.log('tinymce.WPWindowManager is deprecated. Use the default editor.windowManager to open dialogs with inline HTML.');
  40. }
  41. wp.features = args;
  42. wp.params = params;
  43. // Store selection. Takes a snapshot in the FocusManager of the selection before focus is moved to the dialog.
  44. editor.nodeChanged();
  45. // Create the dialog if necessary
  46. if ( ! $element.data('wpdialog') ) {
  47. $element.wpdialog({
  48. title: args.title,
  49. width: args.width,
  50. height: args.height,
  51. modal: true,
  52. dialogClass: 'wp-dialog',
  53. zIndex: 300000
  54. });
  55. }
  56. $element.wpdialog('open');
  57. $element.on( 'wpdialogclose', function() {
  58. if ( self.wp.$element ) {
  59. self.wp = {};
  60. }
  61. });
  62. };
  63. this.close = function() {
  64. if ( ! this.wp.features || ! this.wp.features.wpDialog ) {
  65. return this.parent.close.apply( this, arguments );
  66. }
  67. this.wp.$element.wpdialog('close');
  68. };
  69. };
  70. tinymce.PluginManager.add( 'wpdialogs', function( editor ) {
  71. // Replace window manager
  72. editor.on( 'init', function() {
  73. editor.windowManager = new tinymce.WPWindowManager( editor );
  74. });
  75. });