Browse Source

! We have this nice standardised code and we don't use it properly. So let's use it properly and fix #1250 in the process (hopefully)

Signed-off-by: Peter Spicer <[email protected]>
Peter Spicer 11 years ago
parent
commit
b36bb2936b

+ 0 - 34
Themes/default/Calendar.template.php

@@ -521,41 +521,7 @@ function template_event_post()
 {
 	global $context, $txt, $scripturl;
 
-	// Start the javascript for drop down boxes...
 	echo '
-		<script><!-- // --><![CDATA[
-			var monthLength;
-			monthLength = [
-				31, 28, 31, 30,
-				31, 30, 31, 31,
-				30, 31, 30, 31
-			];
-			function generateDays()
-			{
-				var days, selected, dayElement, monthElement, yearElement;
-				dayElement = document.getElementById("day"), yearElement = document.getElementById("year"), monthElement = document.getElementById("month");
-
-				monthLength[1] = 28;
-				if (yearElement.options[yearElement.selectedIndex].value % 4 == 0)
-					monthLength[1] = 29;
-
-				selected = dayElement.selectedIndex;
-				while (dayElement.options.length)
-				{
-					dayElement.options[0] = null;
-				}
-				days = monthLength[monthElement.value - 1];
-
-				for (i = 0; i <= days; ++i)
-				{
-					dayElement.options[dayElement.length] = new Option(i, i);
-				}
-
-				if (selected < days)
-					dayElement.selectedIndex = selected;
-			}
-		// ]]></script>
-
 		<form action="', $scripturl, '?action=calendar;sa=post" method="post" name="postevent" accept-charset="', $context['character_set'], '" onsubmit="submitonce(this);smc_saveEntities(\'postevent\', [\'evtitle\']);" style="margin: 0;">';
 
 	if (!empty($context['event']['new']))

+ 0 - 28
Themes/default/ManageCalendar.template.php

@@ -15,34 +15,6 @@ function template_edit_holiday()
 {
 	global $context, $scripturl, $txt, $modSettings;
 
-	// Start with javascript for getting the calendar dates right.
-	echo '
-		<script><!-- // --><![CDATA[
-			var monthLength = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
-
-			function generateDays()
-			{
-				var days = 0, selected = 0;
-				var dayElement = document.getElementById("day"), yearElement = document.getElementById("year"), monthElement = document.getElementById("month");
-
-				monthLength[1] = 28;
-				if (yearElement.options[yearElement.selectedIndex].value % 4 == 0)
-					monthLength[1] = 29;
-
-				selected = dayElement.selectedIndex;
-				while (dayElement.options.length)
-					dayElement.options[0] = null;
-
-				days = monthLength[monthElement.value - 1];
-
-				for (i = 1; i <= days; i++)
-					dayElement.options[dayElement.length] = new Option(i, i);
-
-				if (selected < days)
-					dayElement.selectedIndex = selected;
-			}
-		// ]]></script>';
-
 	// Show a form for all the holiday information.
 	echo '
 	<div id="admincenter">

+ 2 - 2
Themes/default/ManagePaid.template.php

@@ -268,7 +268,7 @@ function template_modify_user_subscription()
 					</dl>
 					<fieldset>
 						<legend>', $txt['start_date_and_time'], '</legend>
-						<select name="year" id="year" onchange="generateDays(\'\');">';
+						<select name="year" id="year" onchange="generateDays();">';
 
 	// Show a list of all the years we allow...
 	for ($year = 2005; $year <= 2030; $year++)
@@ -278,7 +278,7 @@ function template_modify_user_subscription()
 	echo '
 						</select>&nbsp;
 						', (isset($txt['calendar_month']) ? $txt['calendar_month'] : $txt['calendar_month']), '&nbsp;
-						<select name="month" id="month" onchange="generateDays(\'\');">';
+						<select name="month" id="month" onchange="generateDays();">';
 
 	// There are 12 months per year - ensure that they all get listed.
 	for ($month = 1; $month <= 12; $month++)

+ 6 - 2
Themes/default/scripts/script.js

@@ -1543,12 +1543,16 @@ function pollOptions()
 function generateDays(offset)
 {
 	// Work around JavaScript's lack of support for default values...
-	offset = typeof(offset) != 'undefined' ? offset : 0;
+	offset = typeof(offset) != 'undefined' ? offset : '';
 
 	var days = 0, selected = 0;
 	var dayElement = document.getElementById("day" + offset), yearElement = document.getElementById("year" + offset), monthElement = document.getElementById("month" + offset);
 
-	monthLength[1] = 28;
+	var monthLength = [
+		31, 28, 31, 30,
+		31, 30, 31, 31,
+		30, 31, 30, 31
+	];
 	if (yearElement.options[yearElement.selectedIndex].value % 4 == 0)
 		monthLength[1] = 29;