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