Browse Source

Changed path of star images per emanueles request

Also jQuery-fied the JS side, and gave variables proper names.
Rick Kerkhof 11 years ago
parent
commit
80dcdfddc8

+ 1 - 1
Sources/Load.php

@@ -1182,7 +1182,7 @@ function loadMemberContext($user, $display_custom_fields = false)
 			'group_id' => $profile['id_group'],
 			'post_group' => $profile['post_group'],
 			'post_group_color' => $profile['post_group_color'],
-			'group_icons' => str_repeat('<img src="' . str_replace('$language', $context['user']['language'], isset($profile['icons'][1]) ? $settings['images_url'] . '/stars/' . $profile['icons'][1] : '') . '" alt="*" />', empty($profile['icons'][0]) || empty($profile['icons'][1]) ? 0 : $profile['icons'][0]),
+			'group_icons' => str_repeat('<img src="' . str_replace('$language', $context['user']['language'], isset($profile['icons'][1]) ? $settings['images_url'] . '/membericons/' . $profile['icons'][1] : '') . '" alt="*" />', empty($profile['icons'][0]) || empty($profile['icons'][1]) ? 0 : $profile['icons'][0]),
 			'warning' => $profile['warning'],
 			'warning_status' => !empty($modSettings['warning_mute']) && $modSettings['warning_mute'] <= $profile['warning'] ? 'mute' : (!empty($modSettings['warning_moderate']) && $modSettings['warning_moderate'] <= $profile['warning'] ? 'moderate' : (!empty($modSettings['warning_watch']) && $modSettings['warning_watch'] <= $profile['warning'] ? 'watch' : (''))),
 			'local_time' => timeformat(time() + ($profile['time_offset'] - $user_info['time_offset']) * 3600, false),

+ 6 - 6
Sources/ManageMembergroups.php

@@ -1083,20 +1083,20 @@ function EditMembergroup()
 	$imageExts = array('png', 'jpg', 'jpeg', 'bmp', 'gif');
 	
 	// Scan the directory.
-	$context['possibleStars'] = array();
-	if ($files = scandir($settings['default_theme_dir'] . '/images/stars'))
+	$context['possible_icons'] = array();
+	if ($files = scandir($settings['default_theme_dir'] . '/images/membericons'))
 	{
 		// Loop through every file in the directory.
 		foreach ($files as $value)
 		{
 			// Grab the image extension.
-			$ext = pathinfo($settings['default_theme_dir'] . '/images/stars/' . $value, PATHINFO_EXTENSION);
+			$ext = pathinfo($settings['default_theme_dir'] . '/images/membericons/' . $value, PATHINFO_EXTENSION);
 			
 			// If the extension is not empty, and it is valid, 
 			if (!empty($ext) && in_array($ext, $imageExts))
 			{
 				// Get the size of the image.
-				$image_info = getimagesize($settings['default_theme_dir'] . '/images/stars/' . $value);
+				$image_info = getimagesize($settings['default_theme_dir'] . '/images/membericons/' . $value);
 				
 				// If this is bigger than 128 in width or 32 in height, skip this one.
 				if ($image_info == false || $image_info[0] > 128 || $image_info[1] > 32)
@@ -1104,13 +1104,13 @@ function EditMembergroup()
 					
 				// Else it's valid. Add it in.
 				else
-					$context['possibleStars'][] = $value;
+					$context['possible_icons'][] = $value;
 			}
 		}
 	}
 	
 	// Insert our JS, if we have possible stars.
-	if (!empty($context['possibleStars']))
+	if (!empty($context['possible_icons']))
 		$context['html_headers'] .= '
 	<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/stardropdown.js"></script>';
 

+ 1 - 1
Sources/Subs-Membergroups.php

@@ -703,7 +703,7 @@ function list_getMembergroups($start, $items_per_page, $sort, $membergroup_type)
 			'type' => $row['group_type'],
 			'num_members' => $row['num_members'],
 			'moderators' => array(),
-			'icons' => !empty($row['icons'][0]) && !empty($row['icons'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/stars/' . $row['icons'][1] . '" alt="*" />', $row['icons'][0]) : '',
+			'icons' => !empty($row['icons'][0]) && !empty($row['icons'][1]) ? str_repeat('<img src="' . $settings['images_url'] . '/membericons/' . $row['icons'][1] . '" alt="*" />', $row['icons'][0]) : '',
 		);
 
 		$context['can_moderate'] |= $row['can_moderate'];

+ 5 - 5
Themes/default/ManageMembergroups.template.php

@@ -269,11 +269,11 @@ function template_edit_group()
 							<label for="icon_count_input"><strong>', $txt['membergroups_icon_count'], ':</strong></label>
 						</dt>
 						<dd>
-							<input type="text" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4" onkeyup="if (this.value.length > 2) this.value = 99;" onkeydown="this.onkeyup();" onchange="if (this.value != 0) this.form.icon_image.onchange();" class="input_text" />
+							<input type="text" name="icon_count" id="icon_count_input" value="', $context['group']['icon_count'], '" size="4" class="input_text" />
 						</dd>';
         
         // Do we have any possible stars to select from?
-       	if (!empty($context['possibleStars']))
+       	if (!empty($context['possible_icons']))
        	{
        		echo '
 						<dt>
@@ -285,15 +285,15 @@ function template_edit_group()
 							<select name="icon_image" id="icon_image_input">';
 
 		// For every possible star, create an option.
-		foreach ($context['possibleStars'] as $star)
+		foreach ($context['possible_icons'] as $icon)
 		{
 			echo '
-								<option value="', $star, '"', $context['group']['icon_image'] == $star ? ' selected="selected"' : '', '>', $star, '</option>';
+								<option value="', $icon, '"', $context['group']['icon_image'] == $icon ? ' selected="selected"' : '', '>', $icon, '</option>';
 		}
 	
 		echo '
 							</select>
-							<img id="star_preview" src="', $settings['images_url'], '/stars/', $context['group']['star_image'] == '' ? 'blank.png' : $context['group']['star_image'], '" alt="*" />
+							<img id="star_preview" src="" alt="*" />
 						</dd>';
 	}
 	

+ 0 - 0
Themes/default/images/stars/blank.png → Themes/default/images/membericons/blank.png


+ 0 - 0
Themes/default/images/stars/icon.png → Themes/default/images/membericons/icon.png


+ 0 - 0
Themes/default/images/stars/iconadmin.png → Themes/default/images/membericons/iconadmin.png


+ 0 - 0
Themes/default/images/stars/icongmod.png → Themes/default/images/membericons/icongmod.png


+ 0 - 0
Themes/default/images/stars/iconmod.png → Themes/default/images/membericons/iconmod.png


+ 34 - 20
Themes/default/scripts/stardropdown.js

@@ -1,20 +1,34 @@
-window.onload = function()
-{
-	document.getElementById('icon_image_input').onchange = function()
-	{
-		// Get the star count element.
-		var star_count = document.getElementById('icon_count_input');
-		var select_box = document.getElementById('icon_image_input');
-	
-		// If it's empty, set it to 1.
-		if (select_box.value && star_count.value == 0)
-			star_count.value = 1;
-	
-		// Else set it to 0 if the select box is empty(?)
-		else if (!select_box.value)
-			star_count.value = 0;
-	
-		// Update the star preview.
-		document.getElementById('star_preview').src = smf_default_theme_url + '/images/stars/' + ((select_box.value && star_count.value > 0) ? select_box.value : 'blank.gif');
-	}
-}
+$(document).ready(function()
+{	
+	$('#icon_count_input').change(function ()
+	{
+		var select_box = $('select#icon_image_input option:selected').val();
+		var icon_count = $('#icon_count_input');
+		if (icon_count.val() == 0 && select_box != 'blank.png')
+			icon_count.val(1);
+			
+		if (icon_count.val().length > 2)
+			icon_count.val(99);
+	});
+	
+	$('#icon_image_input').change(function ()
+	{
+		refreshPreview();
+	});
+	
+	function refreshPreview()
+	{
+		// Get the star count element.
+		var icon_count = $('#icon_count_input');
+		var select_box = $('select#icon_image_input').val();
+	
+		// If it's empty, set it to 1.
+		if (icon_count.val() == 0 && select_box != 'blank.png')
+			icon_count.val(1);
+	
+		// Update the star preview.
+		$('#star_preview').attr('src', smf_default_theme_url + '/images/membericons/' + select_box);
+	}
+	
+	refreshPreview();
+});