Move uploads JS to jQuery. Props filosofo. see #3824

git-svn-id: http://svn.automattic.com/wordpress/trunk@5629 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rob1n 2007-06-01 23:52:27 +00:00
parent f7ba6b94d9
commit 168c858844
2 changed files with 69 additions and 47 deletions

View File

@ -5,18 +5,38 @@ addLoadEvent( function() {
tab: '', tab: '',
postID: 0, postID: 0,
toQueryParams: function(qryStrOrig) {
var params = new Object();
var qryStr = qryStrOrig;
var i = 0;
do {
params[qryStr.split("=")[0].replace(/&/, "")] = ( qryStr.split("=")[1] ) ? qryStr.split("=")[1].split(/&|$/)[0] : '';
qryStr = ( qryStr.split("=")[1] ) ? qryStr.split(qryStr.split("=")[1].split(/&|$/)[0])[1] : '';
i++;
}
while(i < (qryStrOrig.split("=").length - 1));
return params;
},
toQueryString: function(params) {
var qryStr = '';
for ( var key in params )
qryStr += key + '=' + params[key] + '&';
return qryStr;
},
initializeVars: function() { initializeVars: function() {
this.urlData = document.location.href.split('?'); this.urlData = document.location.href.split('?');
this.params = this.urlData[1].toQueryParams(); this.params = this.toQueryParams(this.urlData[1]);
this.postID = this.params['post_id']; this.postID = this.params['post_id'];
this.tab = this.params['tab']; this.tab = this.params['tab'];
this.style = this.params['style']; this.style = this.params['style'];
this.ID = this.params['ID']; this.ID = this.params['ID'];
if ( !this.style ) if ( !this.style )
this.style = 'default'; this.style = 'default';
var nonceEl = $('nonce-value'); var nonceEl = jQuery('#nonce-value');
if ( nonceEl ) if ( nonceEl )
this.nonce = nonceEl.value; this.nonce = jQuery(nonceEl).val();
if ( this.ID ) { if ( this.ID ) {
this.grabImageData( this.ID ); this.grabImageData( this.ID );
this.imageView( this.ID ); this.imageView( this.ID );
@ -26,36 +46,38 @@ addLoadEvent( function() {
initializeLinks: function() { initializeLinks: function() {
if ( this.ID ) if ( this.ID )
return; return;
$$('a.file-link').each( function(i) { jQuery('a.file-link').each(function() {
var id = i.id.split('-').pop(); var id = jQuery(this).attr('id').split('-').pop();
i.onclick = function(e) { theFileList[ 'inline' == theFileList.style ? 'imageView' : 'editView' ](id, e); } jQuery(this).attr('href','javascript:void(0)').click(function(e) {
theFileList[ 'inline' == theFileList.style ? 'imageView' : 'editView' ](id, e);
});
}); });
}, },
grabImageData: function(id) { grabImageData: function(id) {
if ( id == this.currentImage.ID ) if ( id == this.currentImage.ID )
return; return;
var thumbEl = $('attachment-thumb-url-' + id); var thumbEl = jQuery('#attachment-thumb-url-' + id);
if ( thumbEl ) { if ( thumbEl ) {
this.currentImage.thumb = ( 0 == id ? '' : thumbEl.value ); this.currentImage.thumb = ( 0 == id ? '' : jQuery(thumbEl).val() );
this.currentImage.thumbBase = ( 0 == id ? '' : $('attachment-thumb-url-base-' + id).value ); this.currentImage.thumbBase = ( 0 == id ? '' : jQuery('#attachment-thumb-url-base-' + id).val() );
} else { } else {
this.currentImage.thumb = false; this.currentImage.thumb = false;
} }
this.currentImage.src = ( 0 == id ? '' : $('attachment-url-' + id).value ); this.currentImage.src = ( 0 == id ? '' : jQuery('#attachment-url-' + id).val() );
this.currentImage.srcBase = ( 0 == id ? '' : $('attachment-url-base-' + id).value ); this.currentImage.srcBase = ( 0 == id ? '' : jQuery('#attachment-url-base-' + id).val() );
this.currentImage.page = ( 0 == id ? '' : $('attachment-page-url-' + id).value ); this.currentImage.page = ( 0 == id ? '' : jQuery('#attachment-page-url-' + id).val() );
this.currentImage.title = ( 0 == id ? '' : $('attachment-title-' + id).value ); this.currentImage.title = ( 0 == id ? '' : jQuery('#attachment-title-' + id).val() );
this.currentImage.description = ( 0 == id ? '' : $('attachment-description-' + id).value ); this.currentImage.description = ( 0 == id ? '' : jQuery('#attachment-description-' + id).val() );
var widthEl = $('attachment-width-' + id); var widthEl = jQuery('#attachment-width-' + id);
if ( widthEl ) { if ( widthEl ) {
this.currentImage.width = ( 0 == id ? '' : widthEl.value ); this.currentImage.width = ( 0 == id ? '' : jQuery(widthEl).val() );
this.currentImage.height = ( 0 == id ? '' : $('attachment-height-' + id).value ); this.currentImage.height = ( 0 == id ? '' : jQuery('#attachment-height-' + id).val() );
} else { } else {
this.currentImage.width = false; this.currentImage.width = false;
this.currentImage.height = false; this.currentImage.height = false;
} }
this.currentImage.isImage = ( 0 == id ? 0 : $('attachment-is-image-' + id).value ); this.currentImage.isImage = ( 0 == id ? 0 : jQuery('#attachment-is-image-' + id).val() );
this.currentImage.ID = id; this.currentImage.ID = id;
}, },
@ -65,10 +87,10 @@ addLoadEvent( function() {
h += "<div id='upload-file'>" h += "<div id='upload-file'>"
if ( this.ID ) { if ( this.ID ) {
var params = $H(this.params); var params = this.params;
params.ID = ''; params.ID = '';
params.action = ''; params.action = '';
h += "<a href='" + this.urlData[0] + '?' + params.toQueryString() + "'"; h += "<a href='" + this.urlData[0] + '?' + this.toQueryString(params) + "'";
} else { } else {
h += "<a href='#' onclick='return theFileList.cancelView();'"; h += "<a href='#' onclick='return theFileList.cancelView();'";
} }
@ -108,7 +130,7 @@ addLoadEvent( function() {
if ( display.length ) { if ( display.length ) {
display.push("<br /><label for='display-title'><input type='radio' name='display' id='display-title' value='title' /> " + this.title + "</label>"); display.push("<br /><label for='display-title'><input type='radio' name='display' id='display-title' value='title' /> " + this.title + "</label>");
h += "<tr><th style='padding-bottom:.5em'>" + this.show + "</th><td style='padding-bottom:.5em'>"; h += "<tr><th style='padding-bottom:.5em'>" + this.show + "</th><td style='padding-bottom:.5em'>";
$A(display).each( function(i) { h += i; } ); jQuery(display).each( function() { h += this; } );
h += "</td></tr>"; h += "</td></tr>";
} }
@ -125,12 +147,9 @@ addLoadEvent( function() {
h += "</div>"; h += "</div>";
new Insertion.Top('upload-content', h); jQuery(h).prependTo('#upload-content');
var displayEl = $(checked); jQuery('#' + checked).attr('checked','checked');
if ( displayEl ) if (e) return e.stopPropagation();
displayEl.checked = true;
if (e) Event.stop(e);
return false; return false;
}, },
@ -144,10 +163,10 @@ addLoadEvent( function() {
h += "<form id='upload-file' method='post' action='" + action + "'>"; h += "<form id='upload-file' method='post' action='" + action + "'>";
if ( this.ID ) { if ( this.ID ) {
var params = $H(this.params); var params = this.params;
params.ID = ''; params.ID = '';
params.action = ''; params.action = '';
h += "<a href='" + this.urlData[0] + '?' + params.toQueryString() + "'"; h += "<a href='" + this.urlData[0] + '?' + this.toQueryString(params) + "'";
} else { } else {
h += "<a href='#' onclick='return theFileList.cancelView();'"; h += "<a href='#' onclick='return theFileList.cancelView();'";
} }
@ -188,17 +207,17 @@ addLoadEvent( function() {
h += "<div class='submit'><input type='submit' value='" + this.saveText + "' /></div>"; h += "<div class='submit'><input type='submit' value='" + this.saveText + "' /></div>";
h += "</td></tr></table></form>"; h += "</td></tr></table></form>";
new Insertion.Top('upload-content', h); jQuery(h).prependTo('#upload-content');
if (e) Event.stop(e); if (e) e.stopPropagation();
return false; return false;
}, },
prepView: function(id) { prepView: function(id) {
this.cancelView( true ); this.cancelView( true );
var filesEl = $('upload-files'); var filesEl = jQuery('#upload-files');
if ( filesEl ) if ( filesEl )
filesEl.hide(); filesEl.hide();
var navEl = $('current-tab-nav'); var navEl = jQuery('#current-tab-nav');
if ( navEl ) if ( navEl )
navEl.hide(); navEl.hide();
this.grabImageData(id); this.grabImageData(id);
@ -206,18 +225,18 @@ addLoadEvent( function() {
cancelView: function( prep ) { cancelView: function( prep ) {
if ( !prep ) { if ( !prep ) {
var filesEl = $('upload-files'); var filesEl = jQuery('#upload-files');
if ( filesEl ) if ( filesEl )
Element.show(filesEl); jQuery(filesEl).show();
var navEl = $('current-tab-nav'); var navEl = jQuery('#current-tab-nav');
if ( navEl ) if ( navEl )
Element.show(navEl); jQuery(navEl).show();
} }
if ( !this.ID ) if ( !this.ID )
this.grabImageData(0); this.grabImageData(0);
var div = $('upload-file'); var div = jQuery('#upload-file');
if ( div ) if ( div )
Element.remove(div); jQuery(div).remove();
return false; return false;
}, },
@ -227,10 +246,10 @@ addLoadEvent( function() {
var display = ''; var display = '';
var h = ''; var h = '';
link = $A(document.forms.uploadoptions.elements.link).detect( function(i) { return i.checked; } ).value; link = jQuery('input[@type=radio][@name="link"][@checked]','#uploadoptions').val();
displayEl = $A(document.forms.uploadoptions.elements.display).detect( function(i) { return i.checked; } ) displayEl = jQuery('input[@type=radio][@name="display"][@checked]','#uploadoptions');
if ( displayEl ) if ( displayEl )
display = displayEl.value; display = jQuery(displayEl).val();
else if ( 1 == this.currentImage.isImage ) else if ( 1 == this.currentImage.isImage )
display = 'full'; display = 'full';
@ -259,15 +278,17 @@ addLoadEvent( function() {
deleteFile: function(id) { deleteFile: function(id) {
if ( confirm( this.confirmText.replace(/%title%/g, this.currentImage.title) ) ) { if ( confirm( this.confirmText.replace(/%title%/g, this.currentImage.title) ) ) {
$('action-value').value = 'delete'; jQuery('#action-value').attr('value','delete');
$('upload-file').submit(); jQuery('#upload-file').submit();
return true; return true;
} }
return false; return false;
} }
}; };
Object.extend( theFileList, uploadL10n );
for ( var property in uploadL10n )
theFileList[property] = uploadL10n[property];
theFileList.initializeVars(); theFileList.initializeVars();
theFileList.initializeLinks(); theFileList.initializeLinks();
} ); } );

View File

@ -72,6 +72,7 @@ class WP_Scripts {
$this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118'); $this->add( 'cropper', '/wp-includes/js/crop/cropper.js', array('scriptaculous-dragdrop'), '20070118');
$this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.1.2'); $this->add( 'jquery', '/wp-includes/js/jquery/jquery.js', false, '1.1.2');
$this->add( 'jquery-form', '/wp-includes/js/jquery/jquery.form.js', array('jquery'), '1.0.3');
$this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2'); $this->add( 'interface', '/wp-includes/js/jquery/interface.js', array('jquery'), '1.2');
if ( is_admin() ) { if ( is_admin() ) {
@ -113,7 +114,7 @@ class WP_Scripts {
$this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '20070327' ); $this->add( 'admin-comments', '/wp-admin/edit-comments.js', array('listman'), '20070327' );
$this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '4583' ); $this->add( 'admin-users', '/wp-admin/users.js', array('listman'), '4583' );
$this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' ); $this->add( 'xfn', '/wp-admin/xfn.js', false, '3517' );
$this->add( 'upload', '/wp-admin/upload.js', array('prototype'), '20070306' ); $this->add( 'upload', '/wp-admin/upload.js', array('jquery'), '20070518' );
$this->localize( 'upload', 'uploadL10n', array( $this->localize( 'upload', 'uploadL10n', array(
'browseTitle' => attribute_escape(__('Browse your files')), 'browseTitle' => attribute_escape(__('Browse your files')),
'back' => __('&laquo; Back'), 'back' => __('&laquo; Back'),