1 jQuery(document).ready( function() {
8 // cookie create and read functions adapted from http://www.quirksmode.org/js/cookies.html
9 createCookie: function(name,value,days) {
11 var date = new Date();
12 date.setTime(date.getTime()+(days*24*60*60*1000));
13 var expires = "; expires="+date.toGMTString();
15 else var expires = "";
16 document.cookie = name+"="+value+expires+"; path=/";
19 readCookie: function(name) {
20 var nameEQ = name + "=";
21 var ca = document.cookie.split(';');
22 for(var i=0;i < ca.length;i++) {
24 while (c.charAt(0)==' ') c = c.substring(1,c.length);
25 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
30 assignCookieOnChange: function() {
31 jQuery(this).bind("change", function(){
32 theFileList.createCookie(jQuery(this).attr('name'),jQuery(this).attr('id'),365);
36 checkCookieSetting: function(name, defaultSetting) {
37 return this.readCookie(name) ? this.readCookie(name) : defaultSetting;
40 toQueryParams: function( s ) {
41 var r = {}; if ( !s ) { return r; }
42 var q = s.split('?'); if ( q[1] ) { s = q[1]; }
43 var pp = s.split('&');
45 var p = pp[i].split('=');
51 toQueryString: function(params) {
53 for ( var key in params )
54 qryStr += key + '=' + params[key] + '&';
58 initializeVars: function() {
59 this.urlData = document.location.href.split('?');
60 this.params = this.toQueryParams(this.urlData[1]);
61 this.postID = this.params['post_id'];
62 this.tab = this.params['tab'];
63 this.style = this.params['style'];
64 this.ID = this.params['ID'];
66 this.style = 'default';
67 var nonceEl = jQuery('#nonce-value');
69 this.nonce = jQuery(nonceEl).val();
71 this.grabImageData( this.ID );
72 this.imageView( this.ID );
76 initializeLinks: function() {
79 jQuery('a.file-link').each(function() {
80 var id = jQuery(this).attr('id').split('-').pop();
81 jQuery(this).attr('href','javascript:void(0)').click(function(e) {
82 theFileList[ 'inline' == theFileList.style ? 'imageView' : 'editView' ](id, e);
87 grabImageData: function(id) {
88 if ( id == this.currentImage.ID )
90 var thumbEl = jQuery('#attachment-thumb-url-' + id);
92 this.currentImage.thumb = ( 0 == id ? '' : jQuery(thumbEl).val() );
93 this.currentImage.thumbBase = ( 0 == id ? '' : jQuery('#attachment-thumb-url-base-' + id).val() );
95 this.currentImage.thumb = false;
97 this.currentImage.src = ( 0 == id ? '' : jQuery('#attachment-url-' + id).val() );
98 this.currentImage.srcBase = ( 0 == id ? '' : jQuery('#attachment-url-base-' + id).val() );
99 this.currentImage.page = ( 0 == id ? '' : jQuery('#attachment-page-url-' + id).val() );
100 this.currentImage.title = ( 0 == id ? '' : jQuery('#attachment-title-' + id).val() );
101 this.currentImage.description = ( 0 == id ? '' : jQuery('#attachment-description-' + id).val() );
102 var widthEl = jQuery('#attachment-width-' + id);
104 this.currentImage.width = ( 0 == id ? '' : jQuery(widthEl).val() );
105 this.currentImage.height = ( 0 == id ? '' : jQuery('#attachment-height-' + id).val() );
107 this.currentImage.width = false;
108 this.currentImage.height = false;
110 this.currentImage.isImage = ( 0 == id ? 0 : jQuery('#attachment-is-image-' + id).val() );
111 this.currentImage.ID = id;
114 imageView: function(id, e) {
118 h += "<div id='upload-file'>"
120 var params = this.params;
123 h += "<a href='" + this.urlData[0] + '?' + this.toQueryString(params) + "'";
125 h += "<a href='#' onclick='return theFileList.cancelView();'";
127 h += " title='" + this.browseTitle + "' class='back'>" + this.back + "</a>";
128 h += "<div id='file-title'>"
129 if ( 0 == this.currentImage.isImage )
130 h += "<h2><a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>" + this.currentImage.title + "</a></h2>";
132 h += "<h2>" + this.currentImage.title + "</h2>";
133 h += " — <span>";
134 h += "<a href='#' onclick='return theFileList.editView(" + id + ");'>" + this.edit + "</a>"
137 h += "<div id='upload-file-view' class='alignleft'>";
138 if ( 1 == this.currentImage.isImage ) {
139 h += "<a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>";
140 h += "<img src='" + ( this.currentImage.thumb ? this.currentImage.thumb : this.currentImage.src ) + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
146 h += "<form name='uploadoptions' id='uploadoptions' class='alignleft'>";
149 var checkedDisplay = 'display-title';
150 if ( 1 == this.currentImage.isImage ) {
151 checkedDisplay = 'display-full';
152 if ( this.currentImage.thumb ) {
153 display.push("<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' /> " + this.thumb + "</label><br />");
154 checkedDisplay = 'display-thumb';
156 display.push("<label for='display-full'><input type='radio' name='display' id='display-full' value='full' /> " + this.full + "</label>");
157 } else if ( this.currentImage.thumb ) {
158 display.push("<label for='display-thumb'><input type='radio' name='display' id='display-thumb' value='thumb' /> " + this.icon + "</label>");
160 if ( display.length ) {
161 display.push("<br /><label for='display-title'><input type='radio' name='display' id='display-title' value='title' /> " + this.title + "</label>");
162 h += "<tr><th style='padding-bottom:.5em'>" + this.show + "</th><td style='padding-bottom:.5em'>";
163 jQuery(display).each( function() { h += this; } );
167 var checkedLink = 'link-file';
168 h += "<tr><th>" + this.link + "</th><td>";
169 h += "<label for='link-file'><input type='radio' name='link' id='link-file' value='file' /> " + this.file + "</label><br />"; h += "<label for='link-page'><input type='radio' name='link' id='link-page' value='page' /> " + this.page + "</label><br />";
170 h += "<label for='link-none'><input type='radio' name='link' id='link-none' value='none' /> " + this.none + "</label>";
173 h += "<tr><td colspan='2'><p class='submit'>";
174 h += "<input type='button' class='button' name='send' onclick='theFileList.sendToEditor(" + id + ")' value='" + this.editorText + "' />";
175 h += "</p></td></tr></table>";
180 jQuery(h).prependTo('#upload-content');
181 jQuery("input[@name='display']").each(theFileList.assignCookieOnChange);
182 jQuery("input[@name='link']").each(theFileList.assignCookieOnChange);
183 checkedDisplay = this.checkCookieSetting('display', checkedDisplay);
184 checkedLink = this.checkCookieSetting('link', checkedLink);
185 jQuery('#' + checkedDisplay).attr('checked','checked');
186 jQuery('#' + checkedLink).attr('checked','checked');
187 if (e) return e.stopPropagation();
191 editView: function(id, e) {
195 var action = 'upload.php?style=' + this.style + '&tab=upload';
197 action += '&post_id=' + this.postID;
199 h += "<form id='upload-file' method='post' action='" + action + "'>";
201 var params = this.params;
204 h += "<a href='" + this.urlData[0] + '?' + this.toQueryString(params) + "'";
206 h += "<a href='#' onclick='return theFileList.cancelView();'";
208 h += " title='" + this.browseTitle + "' class='back'>" + this.back + "</a>";
209 h += "<div id='file-title'>"
210 if ( 0 == this.currentImage.isImage )
211 h += "<h2><a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>" + this.currentImage.title + "</a></h2>";
213 h += "<h2>" + this.currentImage.title + "</h2>";
214 h += " — <span>";
215 h += "<a href='#' onclick='return theFileList.imageView(" + id + ");'>" + this.insert + "</a>";
218 h += "<div id='upload-file-view' class='alignleft'>";
219 if ( 1 == this.currentImage.isImage ) {
220 h += "<a href='" + this.currentImage.srcBase + this.currentImage.src + "' onclick='return false;' title='" + this.directTitle + "'>";
221 h += "<img src='" + ( this.currentImage.thumb ? this.currentImage.thumb : this.currentImage.src ) + "' alt='" + this.currentImage.title + "' width='" + this.currentImage.width + "' height='" + this.currentImage.height + "' />";
228 h += "<table><col /><col class='widefat' /><tr>";
229 h += "<th scope='row'><label for='url'>" + this.urlText + "</label></th>";
230 h += "<td><input type='text' id='url' class='readonly' value='" + this.currentImage.srcBase + this.currentImage.src + "' readonly='readonly' /></td>";
232 h += "<th scope='row'><label for='post_title'>" + this.title + "</label></th>";
233 h += "<td><input type='text' id='post_title' name='post_title' value='" + this.currentImage.title + "' /></td>";
235 h += "<th scope='row'><label for='post_content'>" + this.desc + "</label></th>";
236 h += "<td><textarea name='post_content' id='post_content'>" + this.currentImage.description + "</textarea></td>";
237 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 + ");' />";
238 h += "<input type='hidden' name='from_tab' value='" + this.tab + "' />";
239 h += "<input type='hidden' name='post_parent' value='" + parseInt(this.postID,10) + "' />";
240 h += "<input type='hidden' name='action' id='action-value' value='save' />";
241 h += "<input type='hidden' name='ID' value='" + id + "' />";
242 h += "<input type='hidden' name='_wpnonce' value='" + this.nonce + "' />";
243 h += "<div class='submit'><input type='submit' value='" + this.saveText + "' /></div>";
244 h += "</td></tr></table></form>";
246 jQuery(h).prependTo('#upload-content');
247 if (e) e.stopPropagation();
251 prepView: function(id) {
252 this.cancelView( true );
253 var filesEl = jQuery('#upload-files');
256 var navEl = jQuery('#current-tab-nav');
259 this.grabImageData(id);
262 cancelView: function( prep ) {
264 var filesEl = jQuery('#upload-files');
266 jQuery(filesEl).show();
267 var navEl = jQuery('#current-tab-nav');
269 jQuery(navEl).show();
272 this.grabImageData(0);
273 var div = jQuery('#upload-file');
275 jQuery(div).remove();
279 sendToEditor: function(id) {
280 this.grabImageData(id);
285 link = jQuery('input[@type=radio][@name="link"][@checked]','#uploadoptions').val();
286 displayEl = jQuery('input[@type=radio][@name="display"][@checked]','#uploadoptions');
288 display = jQuery(displayEl).val();
289 else if ( 1 == this.currentImage.isImage )
292 if ( 'none' != link )
293 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 + "'>";
294 if ( display && 'title' != display )
295 h += "<img src='" + ( 'thumb' == display ? ( this.currentImage.thumbBase + this.currentImage.thumb ) : ( this.currentImage.srcBase + this.currentImage.src ) ) + "' alt='" + this.currentImage.title + "' />";
297 h += this.currentImage.title;
298 if ( 'none' != link )
301 var win = window.opener ? window.opener : window.dialogArguments;
304 tinyMCE = win.tinyMCE;
305 if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) {
306 tinyMCE.selectedInstance.getWin().focus();
307 tinyMCE.execCommand('mceInsertContent', false, h);
309 win.edInsertContent(win.edCanvas, h);
315 deleteFile: function(id) {
316 if ( confirm( this.confirmText.replace(/%title%/g, this.currentImage.title) ) ) {
317 jQuery('#action-value').attr('value','delete');
318 jQuery('#upload-file').submit();
326 for ( var property in uploadL10n )
327 theFileList[property] = uploadL10n[property];
328 theFileList.initializeVars();
329 theFileList.initializeLinks();