[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 */ 14 15 /* global tinymce, QTags, wpActiveEditor, tb_position */ 16 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. 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. 28 */ 29 window.send_to_editor = function( html ) { 30 var editor, 31 hasTinymce = typeof tinymce !== 'undefined', 32 hasQuicktags = typeof QTags !== 'undefined'; 33 34 // If no active editor is set, try to set it. 35 if ( ! wpActiveEditor ) { 36 if ( hasTinymce && tinymce.activeEditor ) { 37 editor = tinymce.activeEditor; 38 window.wpActiveEditor = editor.id; 39 } else if ( ! hasQuicktags ) { 40 return false; 41 } 42 } else if ( hasTinymce ) { 43 editor = tinymce.get( wpActiveEditor ); 44 } 45 46 // If the editor is set and not hidden, 47 // insert the HTML into the content of the editor. 48 if ( editor && ! editor.isHidden() ) { 49 editor.execCommand( 'mceInsertContent', false, html ); 50 } else if ( hasQuicktags ) { 51 // If quick tags are available, insert the HTML into its content. 52 QTags.insertContent( html ); 53 } else { 54 // If neither the TinyMCE editor and the quick tags are available, 55 // add the HTML to the current active editor. 56 document.getElementById( wpActiveEditor ).value += html; 57 } 58 59 // If the old thickbox remove function exists, call it. 60 if ( window.tb_remove ) { 61 try { window.tb_remove(); } catch( e ) {} 62 } 63 }; 64 65 (function($) { 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 * 74 * @return {Object[]} Array containing jQuery objects for all the found 75 * ThickBox anchors. 76 */ 77 window.tb_position = function() { 78 var tbWindow = $('#TB_window'), 79 width = $(window).width(), 80 H = $(window).height(), 81 W = ( 833 < width ) ? 833 : width, 82 adminbar_height = 0; 83 84 if ( $('#wpadminbar').length ) { 85 adminbar_height = parseInt( $('#wpadminbar').css('height'), 10 ); 86 } 87 88 if ( tbWindow.length ) { 89 tbWindow.width( W - 50 ).height( H - 45 - adminbar_height ); 90 $('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height ); 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 } 95 96 /** 97 * Recalculates the new height and width for all links with a ThickBox class. 98 * 99 * @since 2.6.0 100 */ 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 110 // Add handler to recalculates the ThickBox position when the window is resized. 111 $(window).on( 'resize', function(){ tb_position(); }); 112 113 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Sat Dec 21 08:20:01 2024 | Cross-referenced by PHPXref |