2006-10-26 00:55:05 +02:00
|
|
|
addLoadEvent( function() {
|
|
|
|
theFileList = {
|
|
|
|
currentImage: {ID: 0},
|
|
|
|
nonce: '',
|
|
|
|
tab: '',
|
|
|
|
postID: 0,
|
|
|
|
|
2007-06-02 01:52:27 +02:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2006-10-26 00:55:05 +02:00
|
|
|
initializeVars: function() {
|
|
|
|
this.urlData = document.location.href.split('?');
|
2007-06-02 01:52:27 +02:00
|
|
|
this.params = this.toQueryParams(this.urlData[1]);
|
2006-10-26 00:55:05 +02:00
|
|
|
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';
|
2007-06-02 01:52:27 +02:00
|
|
|
var nonceEl = jQuery('#nonce-value');
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( nonceEl )
|
2007-06-02 01:52:27 +02:00
|
|
|
this.nonce = jQuery(nonceEl).val();
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( this.ID ) {
|
|
|
|
this.grabImageData( this.ID );
|
|
|
|
this.imageView( this.ID );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
initializeLinks: function() {
|
|
|
|
if ( this.ID )
|
|
|
|
return;
|
2007-06-02 01:52:27 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
2006-10-26 00:55:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
grabImageData: function(id) {
|
|
|
|
if ( id == this.currentImage.ID )
|
|
|
|
return;
|
2007-06-02 01:52:27 +02:00
|
|
|
var thumbEl = jQuery('#attachment-thumb-url-' + id);
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( thumbEl ) {
|
2007-06-02 01:52:27 +02:00
|
|
|
this.currentImage.thumb = ( 0 == id ? '' : jQuery(thumbEl).val() );
|
|
|
|
this.currentImage.thumbBase = ( 0 == id ? '' : jQuery('#attachment-thumb-url-base-' + id).val() );
|
2006-10-26 00:55:05 +02:00
|
|
|
} else {
|
|
|
|
this.currentImage.thumb = false;
|
|
|
|
}
|
2007-06-02 01:52:27 +02:00
|
|
|
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);
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( widthEl ) {
|
2007-06-02 01:52:27 +02:00
|
|
|
this.currentImage.width = ( 0 == id ? '' : jQuery(widthEl).val() );
|
|
|
|
this.currentImage.height = ( 0 == id ? '' : jQuery('#attachment-height-' + id).val() );
|
2006-10-26 00:55:05 +02:00
|
|
|
} else {
|
|
|
|
this.currentImage.width = false;
|
|
|
|
this.currentImage.height = false;
|
|
|
|
}
|
2007-06-02 01:52:27 +02:00
|
|
|
this.currentImage.isImage = ( 0 == id ? 0 : jQuery('#attachment-is-image-' + id).val() );
|
2006-10-26 00:55:05 +02:00
|
|
|
this.currentImage.ID = id;
|
|
|
|
},
|
|
|
|
|
|
|
|
imageView: function(id, e) {
|
|
|
|
this.prepView(id);
|
|
|
|
var h = '';
|
|
|
|
|
|
|
|
h += "<div id='upload-file'>"
|
|
|
|
if ( this.ID ) {
|
2007-06-02 01:52:27 +02:00
|
|
|
var params = this.params;
|
2006-10-26 00:55:05 +02:00
|
|
|
params.ID = '';
|
|
|
|
params.action = '';
|
2007-06-02 01:52:27 +02:00
|
|
|
h += "<a href='" + this.urlData[0] + '?' + this.toQueryString(params) + "'";
|
2006-10-26 00:55:05 +02:00
|
|
|
} else {
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<a href='#' onclick='return theFileList.cancelView();'";
|
2006-10-26 00:55:05 +02:00
|
|
|
}
|
2007-03-06 18:35:01 +01:00
|
|
|
h += " title='" + this.browseTitle + "' class='back'>" + this.back + "</a>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<div id='file-title'>"
|
2007-01-16 19:10:54 +01:00
|
|
|
if ( 0 == this.currentImage.isImage )
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<h2><a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>" + this.currentImage.title + "</a></h2>";
|
2006-10-26 00:55:05 +02:00
|
|
|
else
|
|
|
|
h += "<h2>" + this.currentImage.title + "</h2>";
|
|
|
|
h += " — <span>";
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<a href='#' onclick='return theFileList.editView(" + id + ");'>" + this.edit + "</a>"
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "</span>";
|
|
|
|
h += '</div>'
|
|
|
|
h += "<div id='upload-file-view' class='alignleft'>";
|
2007-01-16 19:10:54 +01:00
|
|
|
if ( 1 == this.currentImage.isImage ) {
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<img src='" + ( this.currentImage.thumb ? this.currentImage.thumb : this.currentImage.src ) + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
|
|
|
|
h += "</a>";
|
|
|
|
} else
|
|
|
|
h += ' ';
|
|
|
|
h += "</div>";
|
|
|
|
|
|
|
|
h += "<form name='uploadoptions' id='uploadoptions' class='alignleft'>";
|
|
|
|
h += "<table>";
|
2007-01-02 20:28:30 +01:00
|
|
|
var display = [];
|
|
|
|
var checked = 'display-title';
|
|
|
|
if ( 1 == this.currentImage.isImage ) {
|
|
|
|
checked = 'display-full';
|
|
|
|
if ( this.currentImage.thumb ) {
|
2007-03-06 18:35:01 +01:00
|
|
|
display.push("<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' /> " + this.thumb + "</label><br />");
|
2007-01-02 20:28:30 +01:00
|
|
|
checked = 'display-thumb';
|
|
|
|
}
|
2007-03-06 18:35:01 +01:00
|
|
|
display.push("<label for='display-full'><input type='radio' name='display' id='display-full' value='full' /> " + this.full + "</label>");
|
2007-01-02 20:28:30 +01:00
|
|
|
} else if ( this.currentImage.thumb ) {
|
2007-03-06 18:35:01 +01:00
|
|
|
display.push("<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' /> " + this.icon + "</label>");
|
2007-01-02 20:28:30 +01:00
|
|
|
}
|
|
|
|
if ( display.length ) {
|
2007-03-06 18:35:01 +01:00
|
|
|
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'>";
|
2007-06-02 01:52:27 +02:00
|
|
|
jQuery(display).each( function() { h += this; } );
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "</td></tr>";
|
|
|
|
}
|
|
|
|
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<tr><th>" + this.link + "</th><td>";
|
|
|
|
h += "<label for='link-file'><input type='radio' name='link' id='link-file' value='file' checked='checked'/> " + this.file + "</label><br />";
|
|
|
|
h += "<label for='link-page'><input type='radio' name='link' id='link-page' value='page' /> " + this.page + "</label><br />";
|
|
|
|
h += "<label for='link-none'><input type='radio' name='link' id='link-none' value='none' /> " + this.none + "</label>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "</td></tr>";
|
|
|
|
|
|
|
|
h += "<tr><td colspan='2'><p class='submit'>";
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<input type='button' class='button' name='send' onclick='theFileList.sendToEditor(" + id + ")' value='" + this.editorText + "' />";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "</p></td></tr></table>";
|
|
|
|
h += "</form>";
|
|
|
|
|
|
|
|
h += "</div>";
|
|
|
|
|
2007-06-02 01:52:27 +02:00
|
|
|
jQuery(h).prependTo('#upload-content');
|
|
|
|
jQuery('#' + checked).attr('checked','checked');
|
|
|
|
if (e) return e.stopPropagation();
|
2006-10-26 00:55:05 +02:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
editView: function(id, e) {
|
|
|
|
this.prepView(id);
|
|
|
|
var h = '';
|
|
|
|
|
|
|
|
var action = 'upload.php?style=' + this.style + '&tab=upload';
|
|
|
|
if ( this.postID )
|
|
|
|
action += '&post_id=' + this.postID;
|
|
|
|
|
|
|
|
h += "<form id='upload-file' method='post' action='" + action + "'>";
|
|
|
|
if ( this.ID ) {
|
2007-06-02 01:52:27 +02:00
|
|
|
var params = this.params;
|
2006-10-26 00:55:05 +02:00
|
|
|
params.ID = '';
|
|
|
|
params.action = '';
|
2007-06-02 01:52:27 +02:00
|
|
|
h += "<a href='" + this.urlData[0] + '?' + this.toQueryString(params) + "'";
|
2006-10-26 00:55:05 +02:00
|
|
|
} else {
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<a href='#' onclick='return theFileList.cancelView();'";
|
2006-10-26 00:55:05 +02:00
|
|
|
}
|
2007-03-06 18:35:01 +01:00
|
|
|
h += " title='" + this.browseTitle + "' class='back'>" + this.back + "</a>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<div id='file-title'>"
|
2007-01-16 19:10:54 +01:00
|
|
|
if ( 0 == this.currentImage.isImage )
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<h2><a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>" + this.currentImage.title + "</a></h2>";
|
2006-10-26 00:55:05 +02:00
|
|
|
else
|
|
|
|
h += "<h2>" + this.currentImage.title + "</h2>";
|
|
|
|
h += " — <span>";
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<a href='#' onclick='return theFileList.imageView(" + id + ");'>" + this.insert + "</a>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "</span>";
|
|
|
|
h += '</div>'
|
|
|
|
h += "<div id='upload-file-view' class='alignleft'>";
|
2007-01-16 19:10:54 +01:00
|
|
|
if ( 1 == this.currentImage.isImage ) {
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<img src='" + ( this.currentImage.thumb ? this.currentImage.thumb : this.currentImage.src ) + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
|
|
|
|
h += "</a>";
|
|
|
|
} else
|
|
|
|
h += ' ';
|
|
|
|
h += "</div>";
|
|
|
|
|
|
|
|
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<table><col /><col class='widefat' /><tr>";
|
|
|
|
h += "<th scope='row'><label for='url'>" + this.urlText + "</label></th>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<td><input type='text' id='url' class='readonly' value='" + this.currentImage.srcBase + this.currentImage.src + "' readonly='readonly' /></td>";
|
|
|
|
h += "</tr><tr>";
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<th scope='row'><label for='post_title'>" + this.title + "</label></th>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<td><input type='text' id='post_title' name='post_title' value='" + this.currentImage.title + "' /></td>";
|
|
|
|
h += "</tr><tr>";
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<th scope='row'><label for='post_content'>" + this.desc + "</label></th>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<td><textarea name='post_content' id='post_content'>" + this.currentImage.description + "</textarea></td>";
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "</tr><tr id='buttons' class='submit'><td colspan='2'><input type='button' id='delete' name='delete' class='delete alignleft' value='" + this.deleteText + "' onclick='theFileList.deleteFile(" + id + ");' />";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<input type='hidden' name='from_tab' value='" + this.tab + "' />";
|
2007-09-22 18:30:40 +02:00
|
|
|
h += "<input type='hidden' name='post_parent' value='" + parseInt(this.postID,10) + "' />";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<input type='hidden' name='action' id='action-value' value='save' />";
|
|
|
|
h += "<input type='hidden' name='ID' value='" + id + "' />";
|
|
|
|
h += "<input type='hidden' name='_wpnonce' value='" + this.nonce + "' />";
|
2007-03-06 18:35:01 +01:00
|
|
|
h += "<div class='submit'><input type='submit' value='" + this.saveText + "' /></div>";
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "</td></tr></table></form>";
|
|
|
|
|
2007-06-02 01:52:27 +02:00
|
|
|
jQuery(h).prependTo('#upload-content');
|
|
|
|
if (e) e.stopPropagation();
|
2007-02-27 16:24:54 +01:00
|
|
|
return false;
|
2006-10-26 00:55:05 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
prepView: function(id) {
|
|
|
|
this.cancelView( true );
|
2007-06-02 01:52:27 +02:00
|
|
|
var filesEl = jQuery('#upload-files');
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( filesEl )
|
|
|
|
filesEl.hide();
|
2007-06-02 01:52:27 +02:00
|
|
|
var navEl = jQuery('#current-tab-nav');
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( navEl )
|
|
|
|
navEl.hide();
|
|
|
|
this.grabImageData(id);
|
|
|
|
},
|
|
|
|
|
|
|
|
cancelView: function( prep ) {
|
|
|
|
if ( !prep ) {
|
2007-06-02 01:52:27 +02:00
|
|
|
var filesEl = jQuery('#upload-files');
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( filesEl )
|
2007-06-02 01:52:27 +02:00
|
|
|
jQuery(filesEl).show();
|
|
|
|
var navEl = jQuery('#current-tab-nav');
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( navEl )
|
2007-06-02 01:52:27 +02:00
|
|
|
jQuery(navEl).show();
|
2006-10-26 00:55:05 +02:00
|
|
|
}
|
|
|
|
if ( !this.ID )
|
|
|
|
this.grabImageData(0);
|
2007-06-02 01:52:27 +02:00
|
|
|
var div = jQuery('#upload-file');
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( div )
|
2007-06-02 01:52:27 +02:00
|
|
|
jQuery(div).remove();
|
2006-10-26 00:55:05 +02:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
sendToEditor: function(id) {
|
|
|
|
this.grabImageData(id);
|
|
|
|
var link = '';
|
|
|
|
var display = '';
|
|
|
|
var h = '';
|
|
|
|
|
2007-06-02 01:52:27 +02:00
|
|
|
link = jQuery('input[@type=radio][@name="link"][@checked]','#uploadoptions').val();
|
|
|
|
displayEl = jQuery('input[@type=radio][@name="display"][@checked]','#uploadoptions');
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( displayEl )
|
2007-06-02 01:52:27 +02:00
|
|
|
display = jQuery(displayEl).val();
|
2007-01-16 19:10:54 +01:00
|
|
|
else if ( 1 == this.currentImage.isImage )
|
2006-10-26 00:55:05 +02:00
|
|
|
display = 'full';
|
|
|
|
|
|
|
|
if ( 'none' != link )
|
2006-11-09 20:02:40 +01:00
|
|
|
h += "<a href='" + ( 'file' == link ? ( this.currentImage.srcBase + this.currentImage.src ) : ( this.currentImage.page + "' rel='attachment wp-att-" + this.currentImage.ID ) ) + "' title='" + this.currentImage.title + "'>";
|
2007-01-02 20:28:30 +01:00
|
|
|
if ( display && 'title' != display )
|
2006-10-26 00:55:05 +02:00
|
|
|
h += "<img src='" + ( 'thumb' == display ? ( this.currentImage.thumbBase + this.currentImage.thumb ) : ( this.currentImage.srcBase + this.currentImage.src ) ) + "' alt='" + this.currentImage.title + "' />";
|
|
|
|
else
|
2007-01-16 18:33:14 +01:00
|
|
|
h += this.currentImage.title;
|
2006-10-26 00:55:05 +02:00
|
|
|
if ( 'none' != link )
|
|
|
|
h += "</a>";
|
|
|
|
|
|
|
|
var win = window.opener ? window.opener : window.dialogArguments;
|
|
|
|
if ( !win )
|
|
|
|
win = top;
|
|
|
|
tinyMCE = win.tinyMCE;
|
2006-11-21 21:10:01 +01:00
|
|
|
if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) {
|
|
|
|
tinyMCE.selectedInstance.getWin().focus();
|
|
|
|
tinyMCE.execCommand('mceInsertContent', false, h);
|
|
|
|
} else
|
2006-10-26 00:55:05 +02:00
|
|
|
win.edInsertContent(win.edCanvas, h);
|
|
|
|
if ( !this.ID )
|
|
|
|
this.cancelView();
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
deleteFile: function(id) {
|
2007-03-06 18:35:01 +01:00
|
|
|
if ( confirm( this.confirmText.replace(/%title%/g, this.currentImage.title) ) ) {
|
2007-06-02 01:52:27 +02:00
|
|
|
jQuery('#action-value').attr('value','delete');
|
|
|
|
jQuery('#upload-file').submit();
|
2006-10-26 00:55:05 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-27 16:24:54 +01:00
|
|
|
|
2006-10-26 00:55:05 +02:00
|
|
|
};
|
2007-06-02 01:52:27 +02:00
|
|
|
|
|
|
|
for ( var property in uploadL10n )
|
|
|
|
theFileList[property] = uploadL10n[property];
|
2006-10-26 00:55:05 +02:00
|
|
|
theFileList.initializeVars();
|
|
|
|
theFileList.initializeLinks();
|
|
|
|
} );
|