소스 검색

Hey ho, replacing JS where ever I go...

Signed-off-by: Suki <[email protected]>
Suki 10 년 전
부모
커밋
799f9a5121
2개의 변경된 파일35개의 추가작업 그리고 41개의 파일을 삭제
  1. 34 8
      Sources/Profile-Modify.php
  2. 1 33
      Themes/default/Profile.template.php

+ 34 - 8
Sources/Profile-Modify.php

@@ -182,11 +182,14 @@ function loadProfileFields($force_reload = false)
 			'log_change' => true,
 			'permission' => 'profile_password',
 			'js_submit' => !empty($modSettings['send_validation_onChange']) ? '
-				if (document.forms.creator.email_address.value != "'. $cur_profile['email_address'] .'")
-				{
-					alert("'. JavaScriptEscape($txt['email_change_logout']) .'");
-					return true;
-				}' : '',
+	formHandle.addEventListener(\'submit\', function(event)
+	{
+		if (this.email_address.value != "'. $cur_profile['email_address'] .'")
+		{
+			alert('. JavaScriptEscape($txt['email_change_logout']) .');
+			return true;
+		}
+	}, false);' : '',
 			'input_validate' => create_function('&$value', '
 				global $context, $old_profile, $profile_vars, $sourcedir, $modSettings;
 
@@ -789,6 +792,29 @@ function setupProfileContext($fields)
 		}
 	}
 
+	// Some spicy JS.
+	addInlineJavascript('
+	var formHandle = document.forms.creator;
+	createEventListener(formHandle);
+	'. (!empty($context['require_password']) ? '
+	formHandle.addEventListener(\'submit\', function(event)
+	{
+		if (this.oldpasswrd.value == "")
+		{console.log(event);
+			event.preventDefault();
+			alert('. (JavaScriptEscape($txt['required_security_reasons'])) .');
+			return false;
+		}
+	}, false);' : ''), true);
+
+	// Any onsubmit javascript?
+	if (!empty($context['profile_onsubmit_javascript']))
+		addInlineJavascript($context['profile_onsubmit_javascript'], true);
+
+	// Any totally custom stuff?
+	if (!empty($context['profile_javascript']))
+		addInlineJavascript($context['profile_javascript'], true);
+
 	// Free up some memory.
 	unset($profile_fields);
 }
@@ -1995,7 +2021,7 @@ function alert_configuration($memID)
 		if (empty($alert_types[$group]))
 			unset ($alert_types[$group]);
 	}
-	
+
 	// Slightly different for group requests
 	$request = $smcFunc['db_query']('', '
 		SELECT COUNT(*)
@@ -2005,9 +2031,9 @@ function alert_configuration($memID)
 			'memID' => $memID,
 		)
 	);
-	
+
 	list($can_mod) = $smcFunc['db_fetch_row']($request);
-	
+
 	if (!isset($perms_cache['manage_membergroups']))
 	{
 		$members = membersAllowedTo('manage_membergroups');

+ 1 - 33
Themes/default/Profile.template.php

@@ -1278,7 +1278,7 @@ function template_edit_options()
 
 	// The main header!
 	echo '
-		<form action="', (!empty($context['profile_custom_submit_url']) ? $context['profile_custom_submit_url'] : $scripturl . '?action=profile;area=' . $context['menu_item_selected'] . ';u=' . $context['id_member']), '" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data" onsubmit="return checkProfileSubmit();">
+		<form action="', (!empty($context['profile_custom_submit_url']) ? $context['profile_custom_submit_url'] : $scripturl . '?action=profile;area=' . $context['menu_item_selected'] . ';u=' . $context['id_member']), '" method="post" accept-charset="', $context['character_set'], '" name="creator" id="creator" enctype="multipart/form-data">
 			<div class="cat_bar">
 				<h3 class="catbg">
 					<img src="', $settings['images_url'], '/icons/profile_hd.png" alt="" class="icon">';
@@ -1474,38 +1474,6 @@ function template_edit_options()
 			</div>
 		</form>';
 
-	// Some javascript!
-	echo '
-		<script><!-- // --><![CDATA[
-			function checkProfileSubmit()
-			{';
-
-	// If this part requires a password, make sure to give a warning.
-	if ($context['require_password'])
-		echo '
-				// Did you forget to type your password?
-				if (document.forms.creator.oldpasswrd.value == "")
-				{
-					alert("', $txt['required_security_reasons'], '");
-					return false;
-				}';
-
-	// Any onsubmit javascript?
-	if (!empty($context['profile_onsubmit_javascript']))
-		echo '
-				', $context['profile_onsubmit_javascript'];
-
-	echo '
-			}';
-
-	// Any totally custom stuff?
-	if (!empty($context['profile_javascript']))
-		echo '
-			', $context['profile_javascript'];
-
-	echo '
-		// ]]></script>';
-
 	// Any final spellchecking stuff?
 	if (!empty($context['show_spellchecking']))
 		echo '