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