jQuery(document).ready( function() { theFileList = { currentImage: {ID: 0}, nonce: '', tab: '', postID: 0, // cookie create and read functions adapted from http://www.quirksmode.org/js/cookies.html createCookie: function(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; }, readCookie: function(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; }, assignCookieOnChange: function() { jQuery(this).bind("change", function(){ theFileList.createCookie(jQuery(this).attr('name'),jQuery(this).attr('id'),365); }); }, checkCookieSetting: function(name, defaultSetting) { return this.readCookie(name) ? this.readCookie(name) : defaultSetting; }, toQueryParams: function( s ) { var r = {}; if ( !s ) { return r; } var q = s.split('?'); if ( q[1] ) { s = q[1]; } var pp = s.split('&'); for ( var i in pp ) { var p = pp[i].split('='); r[p[0]] = p[1]; } return r; }, 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.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 = jQuery('#nonce-value'); if ( nonceEl ) this.nonce = jQuery(nonceEl).val(); if ( this.ID ) { this.grabImageData( this.ID ); this.imageView( this.ID ); } }, initializeLinks: function() { if ( this.ID ) return; 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 = jQuery('#attachment-thumb-url-' + id); if ( thumbEl ) { 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 ? '' : 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 ? '' : 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 : jQuery('#attachment-is-image-' + id).val() ); this.currentImage.ID = id; }, imageView: function(id, e) { this.prepView(id); var h = ''; h += "