addLoadEvent( function() { theFileList = { currentImage: {ID: 0}, nonce: '', tab: '', postID: 0, 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; }, 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 += "
" if ( this.ID ) { var params = this.params; params.ID = ''; params.action = ''; h += "" + this.back + ""; h += "
" if ( 0 == this.currentImage.isImage ) h += "

" + this.currentImage.title + "

"; else h += "

" + this.currentImage.title + "

"; h += " — "; h += "" + this.edit + "" h += ""; h += '
' h += "
"; if ( 1 == this.currentImage.isImage ) { h += ""; h += "" + this.currentImage.title + ""; h += ""; } else h += ' '; h += "
"; h += "
"; h += ""; var display = []; var checked = 'display-title'; if ( 1 == this.currentImage.isImage ) { checked = 'display-full'; if ( this.currentImage.thumb ) { display.push("
"); checked = 'display-thumb'; } display.push(""); } else if ( this.currentImage.thumb ) { display.push(""); } if ( display.length ) { display.push("
"); h += ""; } h += ""; h += "
" + this.show + ""; jQuery(display).each( function() { h += this; } ); h += "
" + this.link + ""; h += "
"; h += "
"; h += ""; h += "

"; h += ""; h += "

"; h += "
"; h += "
"; jQuery(h).prependTo('#upload-content'); jQuery('#' + checked).attr('checked','checked'); if (e) return e.stopPropagation(); 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 += "
"; if ( this.ID ) { var params = this.params; params.ID = ''; params.action = ''; h += "" + this.back + ""; h += "
" if ( 0 == this.currentImage.isImage ) h += "

" + this.currentImage.title + "

"; else h += "

" + this.currentImage.title + "

"; h += " — "; h += "" + this.insert + ""; h += ""; h += '
' h += "
"; if ( 1 == this.currentImage.isImage ) { h += ""; h += "" + this.currentImage.title + ""; h += ""; } else h += ' '; h += "
"; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += "
"; h += ""; h += ""; h += ""; h += ""; h += ""; h += "
"; h += "
"; jQuery(h).prependTo('#upload-content'); if (e) e.stopPropagation(); return false; }, prepView: function(id) { this.cancelView( true ); var filesEl = jQuery('#upload-files'); if ( filesEl ) filesEl.hide(); var navEl = jQuery('#current-tab-nav'); if ( navEl ) navEl.hide(); this.grabImageData(id); }, cancelView: function( prep ) { if ( !prep ) { var filesEl = jQuery('#upload-files'); if ( filesEl ) jQuery(filesEl).show(); var navEl = jQuery('#current-tab-nav'); if ( navEl ) jQuery(navEl).show(); } if ( !this.ID ) this.grabImageData(0); var div = jQuery('#upload-file'); if ( div ) jQuery(div).remove(); return false; }, sendToEditor: function(id) { this.grabImageData(id); var link = ''; var display = ''; var h = ''; link = jQuery('input[@type=radio][@name="link"][@checked]','#uploadoptions').val(); displayEl = jQuery('input[@type=radio][@name="display"][@checked]','#uploadoptions'); if ( displayEl ) display = jQuery(displayEl).val(); else if ( 1 == this.currentImage.isImage ) display = 'full'; if ( 'none' != link ) h += ""; if ( display && 'title' != display ) h += "" + this.currentImage.title + ""; else h += this.currentImage.title; if ( 'none' != link ) h += ""; var win = window.opener ? window.opener : window.dialogArguments; if ( !win ) win = top; tinyMCE = win.tinyMCE; if ( typeof tinyMCE != 'undefined' && tinyMCE.getInstanceById('content') ) { tinyMCE.selectedInstance.getWin().focus(); tinyMCE.execCommand('mceInsertContent', false, h); } else win.edInsertContent(win.edCanvas, h); if ( !this.ID ) this.cancelView(); return false; }, deleteFile: function(id) { if ( confirm( this.confirmText.replace(/%title%/g, this.currentImage.title) ) ) { jQuery('#action-value').attr('value','delete'); jQuery('#upload-file').submit(); return true; } return false; } }; for ( var property in uploadL10n ) theFileList[property] = uploadL10n[property]; theFileList.initializeVars(); theFileList.initializeLinks(); } );