1 addLoadEvent( function() {
8 toQueryParams: function(qryStrOrig) {
9 var params = new Object();
10 var qryStr = qryStrOrig;
13 params[qryStr.split("=")[0].replace(/&/, "")] = ( qryStr.split("=")[1] ) ? qryStr.split("=")[1].split(/&|$/)[0] : '';
14 qryStr = ( qryStr.split("=")[1] ) ? qryStr.split(qryStr.split("=")[1].split(/&|$/)[0])[1] : '';
17 while(i < (qryStrOrig.split("=").length - 1));
21 toQueryString: function(params) {
23 for ( var key in params )
24 qryStr += key + '=' + params[key] + '&';
28 initializeVars: function() {
29 this.urlData = document.location.href.split('?');
30 this.params = this.toQueryParams(this.urlData[1]);
31 this.postID = this.params['post_id'];
32 this.tab = this.params['tab'];
33 this.style = this.params['style'];
34 this.ID = this.params['ID'];
36 this.style = 'default';
37 var nonceEl = jQuery('#nonce-value');
39 this.nonce = jQuery(nonceEl).val();
41 this.grabImageData( this.ID );
42 this.imageView( this.ID );
46 initializeLinks: function() {
49 jQuery('a.file-link').each(function() {
50 var id = jQuery(this).attr('id').split('-').pop();
51 jQuery(this).attr('href','javascript:void(0)').click(function(e) {
52 theFileList[ 'inline' == theFileList.style ? 'imageView' : 'editView' ](id, e);
57 grabImageData: function(id) {
58 if ( id == this.currentImage.ID )
60 var thumbEl = jQuery('#attachment-thumb-url-' + id);
62 this.currentImage.thumb = ( 0 == id ? '' : jQuery(thumbEl).val() );
63 this.currentImage.thumbBase = ( 0 == id ? '' : jQuery('#attachment-thumb-url-base-' + id).val() );
65 this.currentImage.thumb = false;
67 this.currentImage.src = ( 0 == id ? '' : jQuery('#attachment-url-' + id).val() );
68 this.currentImage.srcBase = ( 0 == id ? '' : jQuery('#attachment-url-base-' + id).val() );
69 this.currentImage.page = ( 0 == id ? '' : jQuery('#attachment-page-url-' + id).val() );
70 this.currentImage.title = ( 0 == id ? '' : jQuery('#attachment-title-' + id).val() );
71 this.currentImage.description = ( 0 == id ? '' : jQuery('#attachment-description-' + id).val() );
72 var widthEl = jQuery('#attachment-width-' + id);
74 this.currentImage.width = ( 0 == id ? '' : jQuery(widthEl).val() );
75 this.currentImage.height = ( 0 == id ? '' : jQuery('#attachment-height-' + id).val() );
77 this.currentImage.width = false;
78 this.currentImage.height = false;
80 this.currentImage.isImage = ( 0 == id ? 0 : jQuery('#attachment-is-image-' + id).val() );
81 this.currentImage.ID = id;
84 imageView: function(id, e) {
88 h += "<div id='upload-file'>"
90 var params = this.params;
93 h += "<a href='" + this.urlData[0] + '?' + this.toQueryString(params) + "'";
95 h += "<a href='#' onclick='return theFileList.cancelView();'";
97 h += " title='" + this.browseTitle + "' class='back'>" + this.back + "</a>";
98 h += "<div id='file-title'>"
99 if ( 0 == this.currentImage.isImage )
100 h += "<h2><a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>" + this.currentImage.title + "</a></h2>";
102 h += "<h2>" + this.currentImage.title + "</h2>";
103 h += " — <span>";
104 h += "<a href='#' onclick='return theFileList.editView(" + id + ");'>" + this.edit + "</a>"
107 h += "<div id='upload-file-view' class='alignleft'>";
108 if ( 1 == this.currentImage.isImage ) {
109 h += "<a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>";
110 h += "<img src='" + ( this.currentImage.thumb ? this.currentImage.thumb : this.currentImage.src ) + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
116 h += "<form name='uploadoptions' id='uploadoptions' class='alignleft'>";
119 var checked = 'display-title';
120 if ( 1 == this.currentImage.isImage ) {
121 checked = 'display-full';
122 if ( this.currentImage.thumb ) {
123 display.push("<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' /> " + this.thumb + "</label><br />");
124 checked = 'display-thumb';
126 display.push("<label for='display-full'><input type='radio' name='display' id='display-full' value='full' /> " + this.full + "</label>");
127 } else if ( this.currentImage.thumb ) {
128 display.push("<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' /> " + this.icon + "</label>");
130 if ( display.length ) {
131 display.push("<br /><label for='display-title'><input type='radio' name='display' id='display-title' value='title' /> " + this.title + "</label>");
132 h += "<tr><th style='padding-bottom:.5em'>" + this.show + "</th><td style='padding-bottom:.5em'>";
133 jQuery(display).each( function() { h += this; } );
137 h += "<tr><th>" + this.link + "</th><td>";
138 h += "<label for='link-file'><input type='radio' name='link' id='link-file' value='file' checked='checked'/> " + this.file + "</label><br />";
139 h += "<label for='link-page'><input type='radio' name='link' id='link-page' value='page' /> " + this.page + "</label><br />";
140 h += "<label for='link-none'><input type='radio' name='link' id='link-none' value='none' /> " + this.none + "</label>";
143 h += "<tr><td colspan='2'><p class='submit'>";
144 h += "<input type='button' class='button' name='send' onclick='theFileList.sendToEditor(" + id + ")' value='" + this.editorText + "' />";
145 h += "</p></td></tr></table>";
150 jQuery(h).prependTo('#upload-content');
151 jQuery('#' + checked).attr('checked','checked');
152 if (e) return e.stopPropagation();
156 editView: function(id, e) {
160 var action = 'upload.php?style=' + this.style + '&tab=upload';
162 action += '&post_id=' + this.postID;
164 h += "<form id='upload-file' method='post' action='" + action + "'>";
166 var params = this.params;
169 h += "<a href='" + this.urlData[0] + '?' + this.toQueryString(params) + "'";
171 h += "<a href='#' onclick='return theFileList.cancelView();'";
173 h += " title='" + this.browseTitle + "' class='back'>" + this.back + "</a>";
174 h += "<div id='file-title'>"
175 if ( 0 == this.currentImage.isImage )
176 h += "<h2><a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>" + this.currentImage.title + "</a></h2>";
178 h += "<h2>" + this.currentImage.title + "</h2>";
179 h += " — <span>";
180 h += "<a href='#' onclick='return theFileList.imageView(" + id + ");'>" + this.insert + "</a>";
183 h += "<div id='upload-file-view' class='alignleft'>";
184 if ( 1 == this.currentImage.isImage ) {
185 h += "<a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>";
186 h += "<img src='" + ( this.currentImage.thumb ? this.currentImage.thumb : this.currentImage.src ) + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
193 h += "<table><col /><col class='widefat' /><tr>";
194 h += "<th scope='row'><label for='url'>" + this.urlText + "</label></th>";
195 h += "<td><input type='text' id='url' class='readonly' value='" + this.currentImage.srcBase + this.currentImage.src + "' readonly='readonly' /></td>";
197 h += "<th scope='row'><label for='post_title'>" + this.title + "</label></th>";
198 h += "<td><input type='text' id='post_title' name='post_title' value='" + this.currentImage.title + "' /></td>";
200 h += "<th scope='row'><label for='post_content'>" + this.desc + "</label></th>";
201 h += "<td><textarea name='post_content' id='post_content'>" + this.currentImage.description + "</textarea></td>";
202 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 + ");' />";
203 h += "<input type='hidden' name='from_tab' value='" + this.tab + "' />";
204 h += "<input type='hidden' name='post_parent' value='" + parseInt(this.postID,10) + "' />";
205 h += "<input type='hidden' name='action' id='action-value' value='save' />";
206 h += "<input type='hidden' name='ID' value='" + id + "' />";
207 h += "<input type='hidden' name='_wpnonce' value='" + this.nonce + "' />";
208 h += "<div class='submit'><input type='submit' value='" + this.saveText + "' /></div>";
209 h += "</td></tr></table></form>";
211 jQuery(h).prependTo('#upload-content');
212 if (e) e.stopPropagation();
216 prepView: function(id) {
217 this.cancelView( true );
218 var filesEl = jQuery('#upload-files');
221 var navEl = jQuery('#current-tab-nav');
224 this.grabImageData(id);
227 cancelView: function( prep ) {
229 var filesEl = jQuery('#upload-files');
231 jQuery(filesEl).show();
232 var navEl = jQuery('#current-tab-nav');
234 jQuery(navEl).show();
237 this.grabImageData(0);
238 var div = jQuery('#upload-file');
240 jQuery(div).remove();
244 sendToEditor: function(id) {
245 this.grabImageData(id);
250 link = jQuery('input[@type=radio][@name="link"][@checked]','#uploadoptions').val();
251 displayEl = jQuery('input[@type=radio][@name="display"][@checked]','#uploadoptions');
253 display = jQuery(displayEl).val();
254 else if ( 1 == this.currentImage.isImage )
257 if ( 'none' != link )
258 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 + "'>";
259 if ( display && 'title' != display )
260 h += "<img src='" + ( 'thumb' == display ? ( this.currentImage.thumbBase + this.currentImage.thumb ) : ( this.currentImage.srcBase + this.currentImage.src ) ) + "' alt='" + this.currentImage.title + "' />";
262 h += this.currentImage.title;
263 if ( 'none' != link )
266 var win = window.opener ? window.opener : window.dialogArguments;
269 tinyMCE = win.tinyMCE;
270 if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) {
271 tinyMCE.selectedInstance.getWin().focus();
272 tinyMCE.execCommand('mceInsertContent', false, h);
274 win.edInsertContent(win.edCanvas, h);
280 deleteFile: function(id) {
281 if ( confirm( this.confirmText.replace(/%title%/g, this.currentImage.title) ) ) {
282 jQuery('#action-value').attr('value','delete');
283 jQuery('#upload-file').submit();
291 for ( var property in uploadL10n )
292 theFileList[property] = uploadL10n[property];
293 theFileList.initializeVars();
294 theFileList.initializeLinks();