From 32255031745007687d15c5853efc2059804db538 Mon Sep 17 00:00:00 2001 From: matt Date: Sun, 16 Dec 2007 03:00:38 +0000 Subject: [PATCH] Remember what attachment options you pick, fixes #4565. Hat tip: filosofo. git-svn-id: http://svn.automattic.com/wordpress/trunk@6386 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/js/upload.js | 51 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/wp-admin/js/upload.js b/wp-admin/js/upload.js index 7e0fa29e1..d114e0471 100644 --- a/wp-admin/js/upload.js +++ b/wp-admin/js/upload.js @@ -5,6 +5,38 @@ addLoadEvent( function() { 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]; } @@ -114,12 +146,12 @@ addLoadEvent( function() { h += "
"; h += ""; var display = []; - var checked = 'display-title'; + var checkedDisplay = 'display-title'; if ( 1 == this.currentImage.isImage ) { - checked = 'display-full'; + checkedDisplay = 'display-full'; if ( this.currentImage.thumb ) { display.push("
"); - checked = 'display-thumb'; + checkedDisplay = 'display-thumb'; } display.push(""); } else if ( this.currentImage.thumb ) { @@ -132,9 +164,9 @@ addLoadEvent( function() { h += ""; } - h += ""; @@ -146,7 +178,12 @@ addLoadEvent( function() { h += ""; jQuery(h).prependTo('#upload-content'); - jQuery('#' + checked).attr('checked','checked'); + jQuery("input[@name='display']").each(theFileList.assignCookieOnChange); + jQuery("input[@name='link']").each(theFileList.assignCookieOnChange); + checkedDisplay = this.checkCookieSetting('display', checkedDisplay); + checkedLink = this.checkCookieSetting('link', checkedLink); + jQuery('#' + checkedDisplay).attr('checked','checked'); + jQuery('#' + checkedLink).attr('checked','checked'); if (e) return e.stopPropagation(); return false; },
" + this.link + ""; - h += "
"; - h += "
"; + var checkedLink = 'link-file'; + h += "
" + this.link + ""; + h += "
"; h += "
"; h += ""; h += "