author | ymh <ymh.work@gmail.com> |
Fri, 05 Sep 2025 18:40:08 +0200 | |
changeset 21 | 48c4eec2b7e6 |
parent 18 | be944660c56a |
permissions | -rw-r--r-- |
9 | 1 |
/** |
2 |
* Contains global functions for the media upload within the post edit screen. |
|
3 |
* |
|
4 |
* Updates the ThickBox anchor href and the ThickBox's own properties in order |
|
5 |
* to set the size and position on every resize event. Also adds a function to |
|
6 |
* send HTML or text to the currently active editor. |
|
7 |
* |
|
8 |
* @file |
|
9 |
* @since 2.5.0 |
|
10 |
* @output wp-admin/js/media-upload.js |
|
11 |
* |
|
12 |
* @requires jQuery |
|
13 |
*/ |
|
0 | 14 |
|
9 | 15 |
/* global tinymce, QTags, wpActiveEditor, tb_position */ |
0 | 16 |
|
9 | 17 |
/** |
18 |
* Sends the HTML passed in the parameters to TinyMCE. |
|
19 |
* |
|
20 |
* @since 2.5.0 |
|
21 |
* |
|
22 |
* @global |
|
23 |
* |
|
24 |
* @param {string} html The HTML to be sent to the editor. |
|
16 | 25 |
* @return {void|boolean} Returns false when both TinyMCE and QTags instances |
26 |
* are unavailable. This means that the HTML was not |
|
27 |
* sent to the editor. |
|
9 | 28 |
*/ |
29 |
window.send_to_editor = function( html ) { |
|
5 | 30 |
var editor, |
31 |
hasTinymce = typeof tinymce !== 'undefined', |
|
32 |
hasQuicktags = typeof QTags !== 'undefined'; |
|
33 |
||
9 | 34 |
// If no active editor is set, try to set it. |
5 | 35 |
if ( ! wpActiveEditor ) { |
36 |
if ( hasTinymce && tinymce.activeEditor ) { |
|
37 |
editor = tinymce.activeEditor; |
|
9 | 38 |
window.wpActiveEditor = editor.id; |
5 | 39 |
} else if ( ! hasQuicktags ) { |
0 | 40 |
return false; |
41 |
} |
|
5 | 42 |
} else if ( hasTinymce ) { |
43 |
editor = tinymce.get( wpActiveEditor ); |
|
0 | 44 |
} |
45 |
||
16 | 46 |
// If the editor is set and not hidden, |
47 |
// insert the HTML into the content of the editor. |
|
5 | 48 |
if ( editor && ! editor.isHidden() ) { |
49 |
editor.execCommand( 'mceInsertContent', false, html ); |
|
50 |
} else if ( hasQuicktags ) { |
|
9 | 51 |
// If quick tags are available, insert the HTML into its content. |
5 | 52 |
QTags.insertContent( html ); |
0 | 53 |
} else { |
16 | 54 |
// If neither the TinyMCE editor and the quick tags are available, |
55 |
// add the HTML to the current active editor. |
|
5 | 56 |
document.getElementById( wpActiveEditor ).value += html; |
0 | 57 |
} |
58 |
||
9 | 59 |
// If the old thickbox remove function exists, call it. |
5 | 60 |
if ( window.tb_remove ) { |
61 |
try { window.tb_remove(); } catch( e ) {} |
|
62 |
} |
|
63 |
}; |
|
0 | 64 |
|
65 |
(function($) { |
|
9 | 66 |
/** |
67 |
* Recalculates and applies the new ThickBox position based on the current |
|
68 |
* window size. |
|
69 |
* |
|
70 |
* @since 2.6.0 |
|
71 |
* |
|
72 |
* @global |
|
73 |
* |
|
16 | 74 |
* @return {Object[]} Array containing jQuery objects for all the found |
75 |
* ThickBox anchors. |
|
9 | 76 |
*/ |
77 |
window.tb_position = function() { |
|
5 | 78 |
var tbWindow = $('#TB_window'), |
79 |
width = $(window).width(), |
|
80 |
H = $(window).height(), |
|
81 |
W = ( 833 < width ) ? 833 : width, |
|
82 |
adminbar_height = 0; |
|
0 | 83 |
|
5 | 84 |
if ( $('#wpadminbar').length ) { |
85 |
adminbar_height = parseInt( $('#wpadminbar').css('height'), 10 ); |
|
86 |
} |
|
0 | 87 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
88 |
if ( tbWindow.length ) { |
0 | 89 |
tbWindow.width( W - 50 ).height( H - 45 - adminbar_height ); |
90 |
$('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height ); |
|
5 | 91 |
tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'}); |
92 |
if ( typeof document.body.style.maxWidth !== 'undefined' ) |
|
93 |
tbWindow.css({'top': 20 + adminbar_height + 'px', 'margin-top': '0'}); |
|
94 |
} |
|
0 | 95 |
|
9 | 96 |
/** |
97 |
* Recalculates the new height and width for all links with a ThickBox class. |
|
98 |
* |
|
99 |
* @since 2.6.0 |
|
100 |
*/ |
|
0 | 101 |
return $('a.thickbox').each( function() { |
102 |
var href = $(this).attr('href'); |
|
103 |
if ( ! href ) return; |
|
104 |
href = href.replace(/&width=[0-9]+/g, ''); |
|
105 |
href = href.replace(/&height=[0-9]+/g, ''); |
|
106 |
$(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 - adminbar_height ) ); |
|
107 |
}); |
|
108 |
}; |
|
109 |
||
9 | 110 |
// Add handler to recalculates the ThickBox position when the window is resized. |
18 | 111 |
$(window).on( 'resize', function(){ tb_position(); }); |
0 | 112 |
|
113 |
})(jQuery); |