1 /* global tinymce, QTags, tb_remove */
2 // send html to the post editor
4 var wpActiveEditor, send_to_editor;
6 send_to_editor = function(h) {
7 var ed, mce = typeof(tinymce) != 'undefined', qt = typeof(QTags) != 'undefined';
9 if ( !wpActiveEditor ) {
10 if ( mce && tinymce.activeEditor ) {
11 ed = tinymce.activeEditor;
12 wpActiveEditor = ed.id;
17 if ( tinymce.activeEditor && (tinymce.activeEditor.id == 'mce_fullscreen' || tinymce.activeEditor.id == 'wp_mce_fullscreen') )
18 ed = tinymce.activeEditor;
20 ed = tinymce.get(wpActiveEditor);
23 if ( ed && !ed.isHidden() ) {
24 // restore caret position on IE
25 if ( tinymce.isIE && ed.windowManager.insertimagebookmark )
26 ed.selection.moveToBookmark(ed.windowManager.insertimagebookmark);
28 if ( h.indexOf('[caption') !== -1 ) {
29 if ( ed.wpSetImgCaption )
30 h = ed.wpSetImgCaption(h);
31 } else if ( h.indexOf('[gallery') !== -1 ) {
32 if ( ed.plugins.wpgallery )
33 h = ed.plugins.wpgallery._do_gallery(h);
34 } else if ( h.indexOf('[embed') === 0 ) {
35 if ( ed.plugins.wordpress )
36 h = ed.plugins.wordpress._setEmbed(h);
39 ed.execCommand('mceInsertContent', false, h);
41 QTags.insertContent(h);
43 document.getElementById(wpActiveEditor).value += h;
46 try{tb_remove();}catch(e){}
52 tb_position = function() {
53 var tbWindow = $('#TB_window'),
54 width = $(window).width(),
55 H = $(window).height(),
56 W = ( 720 < width ) ? 720 : width,
59 if ( $('body.admin-bar').length ) {
60 adminbar_height = parseInt( jQuery('#wpadminbar').css('height'), 10 );
63 if ( tbWindow.size() ) {
64 tbWindow.width( W - 50 ).height( H - 45 - adminbar_height );
65 $('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height );
66 tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'});
67 if ( typeof document.body.style.maxWidth !== 'undefined' )
68 tbWindow.css({'top': 20 + adminbar_height + 'px', 'margin-top': '0'});
71 return $('a.thickbox').each( function() {
72 var href = $(this).attr('href');
74 href = href.replace(/&width=[0-9]+/g, '');
75 href = href.replace(/&height=[0-9]+/g, '');
76 $(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 - adminbar_height ) );
80 $(window).resize(function(){ tb_position(); });
82 // store caret position in IE
83 $(document).ready(function($){
84 $('a.thickbox').click(function(){
87 if ( typeof(tinymce) != 'undefined' && tinymce.isIE && ( ed = tinymce.get(wpActiveEditor) ) && !ed.isHidden() ) {
89 ed.windowManager.insertimagebookmark = ed.selection.getBookmark();