Supporter page: Refactor JavaScript.
This isn't intended to have any functional change, it's just DRYing up the code to simplify functional changes later.
This commit is contained in:
		
							parent
							
								
									e9f01f106a
								
							
						
					
					
						commit
						86ef51db5d
					
				
					 2 changed files with 36 additions and 60 deletions
				
			
		|  | @ -420,6 +420,16 @@ pre { | ||||||
|   overflow: auto; |   overflow: auto; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | .supporter-type-selector a { | ||||||
|  |     font-size: 125%; | ||||||
|  |     font-weight: normal; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | .supporter-type-selector a.supporter-type-selector-selected { | ||||||
|  |     font-size: 127%; | ||||||
|  |     font-weight: bold; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /* Make dl's ( such as for FAQ entries) look nice on screens, both big and small. */ | /* Make dl's ( such as for FAQ entries) look nice on screens, both big and small. */ | ||||||
| 
 | 
 | ||||||
| dl { | dl { | ||||||
|  |  | ||||||
|  | @ -204,36 +204,34 @@ $(document).ready(function() { | ||||||
|     $(".dinner-form-submit").click(function (event) { |     $(".dinner-form-submit").click(function (event) { | ||||||
|         validateFormAtSubmission($(".dinner-form input#amount"), event); |         validateFormAtSubmission($(".dinner-form input#amount"), event); | ||||||
|     }); |     }); | ||||||
|     /* Handle toggling of annual/monthly form selections */ |  | ||||||
|     $('.supporter-type-selection#monthly').hide(); |  | ||||||
|     $('.supporter-type-selection#renewal').hide(); |  | ||||||
|     $('#annualSelector').css("font-weight", "bold").css("font-size", "127%"); |  | ||||||
| 
 | 
 | ||||||
|     $("a[href$='monthly']").bind('click', function() { |     var selectSupportType = function(event) { | ||||||
|         $('.supporter-type-selection#annual').hide(); |         var $selectedLink = $(event.target); | ||||||
|         $('.supporter-type-selection#renewal').hide(); |         $(".supporter-type-selector a").removeClass("supporter-type-selector-selected"); | ||||||
|         $('.supporter-type-selection#monthly').show(); |         $selectedLink.addClass("supporter-type-selector-selected"); | ||||||
|         $('#monthlySelector').css("font-weight", "bold").css("font-size", "127%"); |         $(".supporter-type-selection").each(function(index, element) { | ||||||
|         $('#annualSelector').css("font-weight", "normal").css("font-size", "125%"); |             var $element = $(element); | ||||||
|         $('#renewalSelector').css("font-weight", "normal").css("font-size", "125%"); |             if (event.target.href.endsWith("#" + element.id)) { | ||||||
|  |                 $element.show(); | ||||||
|  |             } else { | ||||||
|  |                 $element.hide(); | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|         $("#form-correction-needed").removeClass("form-error-show").addClass("form-error"); |         $("#form-correction-needed").removeClass("form-error-show").addClass("form-error"); | ||||||
|     }); |     }; | ||||||
|     $("a[href$='annual']").bind('click', function() { |     $(".supporter-type-selector a").bind("click", selectSupportType); | ||||||
|         $('.supporter-type-selection#renewal').hide(); | 
 | ||||||
|         $('.supporter-type-selection#monthly').hide(); |     var selectSupportTypeFromHash = function() { | ||||||
|         $('.supporter-type-selection#annual').show(); |         var urlHash = window.location.hash; | ||||||
|         $('#annualSelector').css("font-weight", "bold").css("font-size", "127%"); |         if ((urlHash !== "#monthly") && (urlHash !== "#renewal")) { | ||||||
|         $('#renewalSelector').css("font-weight", "normal").css("font-size", "125%"); |             urlHash = "#annual"; | ||||||
|         $('#monthlySelector').css("font-weight", "normal").css("font-size", "125%"); |         } | ||||||
|     }); |         $(".supporter-type-selector a[href=" + urlHash + "]").click(); | ||||||
|     $("a[href$='renewal']").bind('click', function() { |         console.log("fromHash done"); | ||||||
|         $('.supporter-type-selection#annual').hide(); |     }; | ||||||
|         $('.supporter-type-selection#monthly').hide(); |     $(window).bind("hashchange", selectSupportTypeFromHash); | ||||||
|         $('.supporter-type-selection#renewal').show(); |     selectSupportTypeFromHash(); | ||||||
|         $('#renewalSelector').css("font-weight", "bold").css("font-size", "127%"); | 
 | ||||||
|         $('#monthlySelector').css("font-weight", "normal").css("font-size", "125%"); |  | ||||||
|         $('#annualSelector').css("font-weight", "normal").css("font-size", "125%"); |  | ||||||
|     }); |  | ||||||
|     $( ".footnote-mark" ).tooltip({ |     $( ".footnote-mark" ).tooltip({ | ||||||
|         items: "a", |         items: "a", | ||||||
|         hide: { duration: 5000 }, |         hide: { duration: 5000 }, | ||||||
|  | @ -254,35 +252,3 @@ $(document).ready(function() { | ||||||
|         } |         } | ||||||
|     }); |     }); | ||||||
| }); | }); | ||||||
| 
 |  | ||||||
| $(window).load(function () { |  | ||||||
|     verifySelctionCorrectOnPageLoad = function() { |  | ||||||
|         var ourURL = document.URL; |  | ||||||
|         if (ourURL.search("#monthly") > 0) { |  | ||||||
|             $('.supporter-type-selection#annual').hide(); |  | ||||||
|             $('.supporter-type-selection#monthly').show(); |  | ||||||
|             $('#monthlySelector').css("font-weight", "bold").css("font-size", "127%"); |  | ||||||
|             $('#annualSelector').css("font-weight", "normal").css("font-size", "125%"); |  | ||||||
|             $('#renewalSelector').css("font-weight", "normal").css("font-size", "125%"); |  | ||||||
|         } |  | ||||||
|         if (ourURL.search("#annual") > 0) { |  | ||||||
|             $('.supporter-type-selection#monthly').hide(); |  | ||||||
|             $('.supporter-type-selection#annual').show(); |  | ||||||
|             $('#annualSelector').css("font-weight", "bold").css("font-size", "127%"); |  | ||||||
|             $('#monthlySelector').css("font-weight", "normal").css("font-size", "125%"); |  | ||||||
|             $('#renewalSelector').css("font-weight", "normal").css("font-size", "125%"); |  | ||||||
|         } |  | ||||||
|         if (ourURL.search("#renewal") > 0) { |  | ||||||
|             $('.supporter-type-selection#monthly').hide(); |  | ||||||
|             $('.supporter-type-selection#annual').hide(); |  | ||||||
|             $('.supporter-type-selection#renewal').show(); |  | ||||||
|             $('#renewalSelector').css("font-weight", "bold").css("font-size", "127%"); |  | ||||||
|             $('#monthlySelector').css("font-weight", "normal").css("font-size", "125%"); |  | ||||||
|             $('#annualSelector').css("font-weight", "normal").css("font-size", "125%"); |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|     if (location.hash) { |  | ||||||
|         setTimeout(verifySelctionCorrectOnPageLoad, 1); |  | ||||||
|     } |  | ||||||
|     window.addEventListener("hashchange", verifySelctionCorrectOnPageLoad); |  | ||||||
| }); |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Brett Smith
						Brett Smith