diff --git src/wp-admin/js/media-upload.js src/wp-admin/js/media-upload.js
index cd969b9b3a..3fbda74d55 100644
|
|
|
1 | | /* global tinymce, QTags */ |
2 | | // send html to the post editor |
| 1 | /* global wpActiveEditor, tinymce, QTags */ |
| 2 | |
| 3 | /** |
| 4 | * Makes sure the ThickBox dimensions are properly set and adds functionality to pass HTML to the editor. |
| 5 | * |
| 6 | * Updates the ThickBox anchor href and the ThickBox's own properties in order |
| 7 | * to set the size and position on every resize event. Also adds a function to |
| 8 | * send HTML or text to the currently active editor. |
| 9 | * |
| 10 | * @since 2.3.3 |
| 11 | * |
| 12 | * @requires jQuery |
| 13 | */ |
| 14 | |
3 | 15 | |
4 | 16 | var wpActiveEditor, send_to_editor; |
5 | 17 | |
| 18 | /** |
| 19 | * Sends the HTML passed in the parameters to TinyMCE. |
| 20 | * |
| 21 | * @since 2.3.3 |
| 22 | * |
| 23 | * @global {tinymce} tinymce An instance of the TinyMCE editor. |
| 24 | * @global {QTags} QTags An instance of QTags. |
| 25 | * |
| 26 | * @param {string} html The HTML to be sent to the editor. |
| 27 | * @returns {boolean} Returns false when both TinyMCE and QTags instances are unavailable. This means that the HTML was not sent to the editor. |
| 28 | */ |
6 | 29 | send_to_editor = function( html ) { |
7 | 30 | var editor, |
8 | 31 | hasTinymce = typeof tinymce !== 'undefined', |
9 | 32 | hasQuicktags = typeof QTags !== 'undefined'; |
10 | 33 | |
| 34 | // If no active editor is set, try to set it. |
11 | 35 | if ( ! wpActiveEditor ) { |
12 | 36 | if ( hasTinymce && tinymce.activeEditor ) { |
13 | 37 | editor = tinymce.activeEditor; |
… |
… |
send_to_editor = function( html ) { |
19 | 43 | editor = tinymce.get( wpActiveEditor ); |
20 | 44 | } |
21 | 45 | |
| 46 | // If the editor is set and not hidden, insert the HTML into the content of the editor. |
22 | 47 | if ( editor && ! editor.isHidden() ) { |
23 | 48 | editor.execCommand( 'mceInsertContent', false, html ); |
24 | 49 | } else if ( hasQuicktags ) { |
| 50 | // If quick tags are available, insert the HTML into its content. |
25 | 51 | QTags.insertContent( html ); |
26 | 52 | } else { |
| 53 | // If neither the TinyMCE editor and the quick tags are available, add the HTML to the current active editor. |
27 | 54 | document.getElementById( wpActiveEditor ).value += html; |
28 | 55 | } |
29 | 56 | |
30 | | // If the old thickbox remove function exists, call it |
| 57 | // If the old thickbox remove function exists, call it. |
31 | 58 | if ( window.tb_remove ) { |
32 | 59 | try { window.tb_remove(); } catch( e ) {} |
33 | 60 | } |
34 | 61 | }; |
35 | 62 | |
36 | | // thickbox settings |
| 63 | // ThickBox positioning. |
37 | 64 | var tb_position; |
38 | 65 | (function($) { |
| 66 | /** |
| 67 | * Recalculates and applies the new ThickBox position based on the current window size. |
| 68 | * |
| 69 | * @since 2.6.0 |
| 70 | * |
| 71 | * @returns {HTMLElements[]} Array containing all the found ThickBox anchors. |
| 72 | */ |
39 | 73 | tb_position = function() { |
40 | 74 | var tbWindow = $('#TB_window'), |
41 | 75 | width = $(window).width(), |
… |
… |
var tb_position; |
55 | 89 | tbWindow.css({'top': 20 + adminbar_height + 'px', 'margin-top': '0'}); |
56 | 90 | } |
57 | 91 | |
| 92 | /** |
| 93 | * Recalculates the new height and width for all links with a ThickBox class. |
| 94 | * |
| 95 | * @since 2.6.0 |
| 96 | */ |
58 | 97 | return $('a.thickbox').each( function() { |
59 | 98 | var href = $(this).attr('href'); |
60 | 99 | if ( ! href ) return; |
… |
… |
var tb_position; |
64 | 103 | }); |
65 | 104 | }; |
66 | 105 | |
| 106 | /** |
| 107 | * Recalculates the ThickBox position when the window is resized. |
| 108 | */ |
67 | 109 | $(window).resize(function(){ tb_position(); }); |
68 | 110 | |
69 | 111 | })(jQuery); |