]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/js/media-upload.js
WordPress 4.1-scripts
[autoinstalls/wordpress.git] / wp-admin / js / media-upload.js
1 /* global tinymce, QTags */
2 // send html to the post editor
3
4 var wpActiveEditor, send_to_editor;
5
6 send_to_editor = function( html ) {
7         var editor,
8                 hasTinymce = typeof tinymce !== 'undefined',
9                 hasQuicktags = typeof QTags !== 'undefined';
10
11         if ( ! wpActiveEditor ) {
12                 if ( hasTinymce && tinymce.activeEditor ) {
13                         editor = tinymce.activeEditor;
14                         wpActiveEditor = editor.id;
15                 } else if ( ! hasQuicktags ) {
16                         return false;
17                 }
18         } else if ( hasTinymce ) {
19                 editor = tinymce.get( wpActiveEditor );
20         }
21
22         if ( editor && ! editor.isHidden() ) {
23                 editor.execCommand( 'mceInsertContent', false, html );
24         } else if ( hasQuicktags ) {
25                 QTags.insertContent( html );
26         } else {
27                 document.getElementById( wpActiveEditor ).value += html;
28         }
29
30         // If the old thickbox remove function exists, call it
31         if ( window.tb_remove ) {
32                 try { window.tb_remove(); } catch( e ) {}
33         }
34 };
35
36 // thickbox settings
37 var tb_position;
38 (function($) {
39         tb_position = function() {
40                 var tbWindow = $('#TB_window'),
41                         width = $(window).width(),
42                         H = $(window).height(),
43                         W = ( 833 < width ) ? 833 : width,
44                         adminbar_height = 0;
45
46                 if ( $('#wpadminbar').length ) {
47                         adminbar_height = parseInt( $('#wpadminbar').css('height'), 10 );
48                 }
49
50                 if ( tbWindow.size() ) {
51                         tbWindow.width( W - 50 ).height( H - 45 - adminbar_height );
52                         $('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height );
53                         tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'});
54                         if ( typeof document.body.style.maxWidth !== 'undefined' )
55                                 tbWindow.css({'top': 20 + adminbar_height + 'px', 'margin-top': '0'});
56                 }
57
58                 return $('a.thickbox').each( function() {
59                         var href = $(this).attr('href');
60                         if ( ! href ) return;
61                         href = href.replace(/&width=[0-9]+/g, '');
62                         href = href.replace(/&height=[0-9]+/g, '');
63                         $(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 - adminbar_height ) );
64                 });
65         };
66
67         $(window).resize(function(){ tb_position(); });
68
69 })(jQuery);