1. Sylvain Rouquette
  2. d3-skill-filter

Commits

Sylvain Rouquette  committed 39c58a5

fixed hash in build loader

  • Participants
  • Parent commits ecbdb0d
  • Branches default

Comments (0)

Files changed (3)

File index.html

View file
 
 <div id="build">
 	<a id="bnet_calc" href="http://us.battle.net/d3/en/calculator/" target="blank_">Battle.net Calculator</a>
+	<h2>Build</h2>
 	<ul class="skills"></ul>
 	<br/>
 	<ul class="traits"></ul>

File js/main.js

View file
 var HASH		= 'aZbYcXdWeVfUgThSiRjQkPlOmNnMoLpKqJrIsHtGuFvEwDxCyBzA0123456789+/';
 
 var FILTER_SKILL_LI = '\
-	<li class="skill {class_skill}">\
+	<li class="skill" data-skill="{slug_skill}">\
 		<a class="desc" href="{href_skill}" data-hash="{hash_skill}" target="blank_">\
 			<div>\
 				<span class="d3-icon d3-icon-skill d3-icon-skill-42" style="background-image: url(\'{icon_skill}\');">\
 	</li>';
 
 var FILTER_PASSIVE_LI = '\
-	<li class="skill {class_skill}">\
+	<li class="skill" data-skill="{slug_skill}">\
 		<a class="desc" href="{href_skill}" data-hash="{hash_skill}" target="blank_">\
 			<div>\
 				<span class="d3-icon d3-icon-trait d3-icon-trait-42" style="background-image: url(\'{icon_skill}\');">\
 
 function bindSkills() {
 	$('#filter .skills a').live('click', function() {
-		if ($('#build .skills').children().length >= 6)
-			return false;
-
 		var skill = $(this).parents('.skill').clone();
 
 		var clicked_class = $(this).attr('class');
 		}).remove();
 
 
-		skill.toggleClass('skill');
-		var build_skill = $('#build .skills').find('.' + skill.attr('class'));
-		skill.toggleClass('skill');
+		var build_skill = $('#build .skills [data-skill="'+skill.attr('data-skill')+'"]');
 		if (build_skill.length) {
 			build_skill.find('.runes').replaceWith(skill.find('.runes'));
 		}
+		else if ($('#build .skills').children().length >= 6)
+			return false;
 		else
 			$('#build .skills').append(skill);
 		refreshUrl();
 		skill.find('.runes').remove();
 		skill.find('.skill_name').remove();
 
-		skill.toggleClass('skill');
-		if ($('#build .traits').find('.' + skill.attr('class')).length)
+		if ($('#build .traits [data-skill="' + skill.attr('data-skill') + '"]').length)
 			return false;
-		skill.toggleClass('skill');
 
 		$('#build .traits').append(skill);
 		refreshUrl();
 	}
 	$.getJSON('http://www.diabloapi.com/'+g_current_class+'?callback=?', function(data) {
 		g_classes[g_current_class] = data;
+		for (var type in data) {
+			for (var skill in data[type]) {
+				var obj = data[type][skill];
+				obj['hash'] = HASH.charAt(skill);
+				if (type == 'skills') {
+					for (var rune in obj.runes)
+						obj.runes[rune]['hash'] = HASH.charAt(rune);
+				}
+			}
+		}
 		if (build)
 			createBuild();
 		setTimeout('refreshSkills("#filter", g_classes[g_current_class])', 1);
 			var obj = skills[type][skill];
 			var link = SKILL_URL + g_current_class;
 			if (type == 'skills') {
-				li = FILTER_SKILL_LI.replace('{class_skill}', obj.slug)
-							 .replace('{hash_skill}', HASH.charAt(skill))
+				li = FILTER_SKILL_LI.replace('{slug_skill}', obj.slug)
+							 .replace('{hash_skill}', obj.hash)
 							 .replace('{href_skill}', link + '/active/' + obj.slug)
 							 .replace('{icon_skill}', ICON_URL + obj.icon + '.png')
 							 .replace('{skill}', obj.name);
 					if (obj.runes[rune])
 						li = li.replace('{href_rune_'+rune+'}', RUNE_URL + obj.runes[rune].tooltipParams)
 							   .replace('{type_rune_'+rune+'}', obj.runes[rune].type)
-							   .replace('{hash_rune_'+rune+'}', HASH.charAt(rune));
+							   .replace('{hash_rune_'+rune+'}', obj.runes[rune].hash);
 					else
 						li = li.replace('rune_'+rune, 'hidden')
-							   .replace('{hash_rune_'+rune+'}', HASH.charAt(rune));
 				}
 			}
 			else {
-				li = FILTER_PASSIVE_LI.replace('{class_skill}', obj.slug)
-							 .replace('{hash_skill}', HASH.charAt(skill))
+				li = FILTER_PASSIVE_LI.replace('{slug_skill}', obj.slug)
+							 .replace('{hash_skill}', obj.hash)
 							 .replace('{href_skill}', link + '/passive/' + obj.slug)
 							 .replace('{icon_skill}', ICON_URL + obj.icon + '.png')
 							 .replace('{skill}', obj.name);
 		skills.traits.push(jQuery.extend({}, g_classes[g_current_class].traits[HASH.indexOf(hash[1].charAt(i))]));
 		skills.traits[i].name = '';
 	}
-	console.log(skills);
 	refreshSkills('#build', skills);
 	refreshUrl();
 }
 	for (var type in g_classes[g_current_class]) {
 		for (var skill in g_classes[g_current_class][type]) {
 			var obj = g_classes[g_current_class][type][skill];
-			var element = $('#filter .' + obj.slug);
+			var element = $('#filter [data-skill="' + obj.slug + '"]');
 			if (filter.length <= 1) {
 				if ('runes' in obj)
 					for (var rune in obj.runes)

File style.css

View file
 .traits .skill_name {
 	top: -18px;
 }
+.runes {
+	padding-top: 4px;
+}
 .runes li {
 	float: right;
 }
 #build .skills {
 	text-align: left;
-	margin-top: 90px;
 }
 #build .traits {
 	display: inline-block;