wp/wp-admin/js/media-upload.js
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     1
/* global tinymce, QTags */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
// send html to the post editor
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     4
var wpActiveEditor, send_to_editor;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     6
send_to_editor = function( html ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     7
	var editor,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     8
		hasTinymce = typeof tinymce !== 'undefined',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
		hasQuicktags = typeof QTags !== 'undefined';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
	if ( ! wpActiveEditor ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
		if ( hasTinymce && tinymce.activeEditor ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
			editor = tinymce.activeEditor;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
			wpActiveEditor = editor.id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
		} else if ( ! hasQuicktags ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
			return false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
	} else if ( hasTinymce ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
		editor = tinymce.get( wpActiveEditor );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
	if ( editor && ! editor.isHidden() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    23
		editor.execCommand( 'mceInsertContent', false, html );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	} else if ( hasQuicktags ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
		QTags.insertContent( html );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
		document.getElementById( wpActiveEditor ).value += html;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
	// If the old thickbox remove function exists, call it
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	if ( window.tb_remove ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
		try { window.tb_remove(); } catch( e ) {}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
};
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
// thickbox settings
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
var tb_position;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
(function($) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	tb_position = function() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
		var tbWindow = $('#TB_window'),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
			width = $(window).width(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
			H = $(window).height(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    43
			W = ( 833 < width ) ? 833 : width,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
			adminbar_height = 0;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
		if ( $('#wpadminbar').length ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
			adminbar_height = parseInt( $('#wpadminbar').css('height'), 10 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		if ( tbWindow.size() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
			tbWindow.width( W - 50 ).height( H - 45 - adminbar_height );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
			$('#TB_iframeContent').width( W - 50 ).height( H - 75 - adminbar_height );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
			tbWindow.css({'margin-left': '-' + parseInt( ( ( W - 50 ) / 2 ), 10 ) + 'px'});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
			if ( typeof document.body.style.maxWidth !== 'undefined' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
				tbWindow.css({'top': 20 + adminbar_height + 'px', 'margin-top': '0'});
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		return $('a.thickbox').each( function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
			var href = $(this).attr('href');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
			if ( ! href ) return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
			href = href.replace(/&width=[0-9]+/g, '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
			href = href.replace(/&height=[0-9]+/g, '');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
			$(this).attr( 'href', href + '&width=' + ( W - 80 ) + '&height=' + ( H - 85 - adminbar_height ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	};
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	$(window).resize(function(){ tb_position(); });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
})(jQuery);