Skip to content

Commit 0350107

Browse files
committedJun 17, 2013
Locally working ajax for item descriptions. Up next: write the entire json file manually because I failed to notice that I set myself up for it.
1 parent 14c8296 commit 0350107

File tree

5 files changed

+98
-29
lines changed

5 files changed

+98
-29
lines changed
 

‎ajax.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
//2nd argument true => decode result in to associative array
4+
$result = json_decode(file_get_contents("files/dota2itemfilter.json"), true);
5+
$name = $_POST['name'];
6+
7+
//Return only the specified item
8+
echo json_encode($result[$name]);
9+
10+
?>

‎css/main.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
#left {
10-
width: 350px;
10+
width: 320px;
1111
height: 100%;
1212
position: fixed;
1313

@@ -29,7 +29,7 @@ label {
2929
height: 100%;
3030
position: fixed;
3131
overflow-y: scroll;
32-
margin-left: 350px;
32+
margin-left: 320px;
3333

3434
clear: both;
3535
float: left;

‎files/dota2itemfilter.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"Abyssal Blade": {
3+
"Attributes": ["strength","damage","stun"],
4+
"Bonus": ["+10 Strength","+100 Damage"],
5+
"Cost": 6750,
6+
"Description": "The lost blade of the Commander of the Abyss, this edge cuts into an enemy's soul.",
7+
"abilities": {
8+
"Overwhelm": {
9+
"description": "Stun a target enemy unit for 2 seconds. Goes through Magic Immunity.",
10+
"Extra": "Range 140",
11+
"cooldown": 60,
12+
"mana": 150,
13+
"Ability": "Target Unit",
14+
"Affects": "Enemies"
15+
},
16+
"Bash": {
17+
"description": "Gives a chance to stun for 1.4 seconds.",
18+
"Extra": "Bash Chance for Melee Heroes: 25%<br />Bash Chance for Ranged Heroes: 10%",
19+
"cooldown": 2,
20+
"Ability": "Passive",
21+
"Affects": "Enemies"
22+
}
23+
},
24+
"Extra Info": "Can be disassembled. Cannot be purchased by Slardar, Faceless Void, Troll Warlord, Spirit Breaker.",
25+
"position": "0 -38px"
26+
},
27+
"Aghanim&#39;s Scepter": {
28+
"Attributes": ["strength", "agility", "intelligence", "health", "mana"],
29+
"Bonus": ["+10 Strength","+10 Agility", "+10 Intelligence", "+200 HP", "+150 Mana"],
30+
"Cost": 4200,
31+
"Description": "The scepter of a wizard with demigod-like powers.",
32+
"abilities": {
33+
"Ultimate Upgrade": {
34+
"description": "Upgrades the ultimates of certain heroes. ",
35+
"Ability": "Passive"
36+
}
37+
},
38+
"position": "0 -4484px"
39+
}
40+
}

‎index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
natsort($item_names);
191191

192192
foreach($item_names as $name => $class){
193-
$result = "<figure class='item'>
193+
$result = "<figure class='item' id='$name'>
194194
<img class='image $class' width='51' height='38' />
195195
<figcaption class='description'>
196196
$name

‎js/main.js

+45-26
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,27 @@ $(document).ready(function() {
2323

2424
//Make all checkboxes display under eachother.
2525
setMaxWidth(getMaxWidth());
26-
26+
2727
//-------------------------------
28-
28+
2929
var setDisabledColor = function() {
30-
//Get all checkboxes
31-
var boxes = $('input:checkbox');
32-
33-
34-
$.each(boxes, function(indexInArray, valueOfElement) {
35-
//If a checkbox is disabled, set the background to a color to show it.
36-
//I could have added or removed a CSS class, but I'm doing that later in the file and right now I also want to use this method.
37-
if($(boxes[indexInArray]).attr('disabled')){
38-
$(boxes[indexInArray]).parent().css({'background-color': 'red'});
39-
} else {
40-
//Else, remove colored background
41-
$(boxes[indexInArray]).parent().css({'background-color': 'white'});
42-
}
43-
});
44-
45-
}
46-
30+
//Get all checkboxes
31+
var boxes = $('input:checkbox');
32+
33+
34+
$.each(boxes, function(indexInArray, valueOfElement) {
35+
//If a checkbox is disabled, set the background to a color to show it.
36+
//I could have added or removed a CSS class, but I'm doing that later in the file and right now I also want to use this method.
37+
if ($(boxes[indexInArray]).attr('disabled')) {
38+
$(boxes[indexInArray]).parent().css({'background-color': 'red'});
39+
} else {
40+
//Else, remove colored background
41+
$(boxes[indexInArray]).parent().css({'background-color': 'white'});
42+
}
43+
});
44+
45+
};
46+
4747
/**
4848
* End view section
4949
*/
@@ -52,7 +52,7 @@ $(document).ready(function() {
5252
/**
5353
* Start logic section
5454
*/
55-
55+
5656
//Upon checking or unchecking a checkbox, hide or display all items not related to it.
5757
$('input:checkbox').on('change', function() {
5858
//First thing to do on every change: go over all checkboxes.
@@ -87,7 +87,7 @@ $(document).ready(function() {
8787
allPresent = false;
8888
}
8989
});
90-
90+
9191
//If an item has the attributes of all checked checkboxes, remove hidden.
9292
//If even 1 is missing, set hidden
9393
if (!allPresent) {
@@ -106,8 +106,8 @@ $(document).ready(function() {
106106

107107
$.each(visibleItems, function() {
108108
var classes = $(this).children('img').attr('class').split(' ');
109-
110-
if(classes.indexOf(pureHtml.value) !== -1) {
109+
110+
if (classes.indexOf(pureHtml.value) !== -1) {
111111
comboPossible = true;
112112
}
113113
});
@@ -120,12 +120,31 @@ $(document).ready(function() {
120120
});
121121

122122
}
123-
123+
124124
//And set the backgroundcolor for the disabled checkboxes
125125
setDisabledColor();
126126
});
127-
128-
127+
128+
129+
$("figure").on('click', function(eventObject) {
130+
var currentItem = getItemInfo(this.id);
131+
132+
});
133+
134+
var getItemInfo = function(itemName) {
135+
var jqxhr = $.ajax({
136+
url: "http://localhost/Dota2ItemFilter/ajax.php",
137+
type: "POST",
138+
data: {name: itemName},
139+
dataType: "json",
140+
}).fail(function() { alert("error"); });
141+
142+
jqxhr.done(function(data) {
143+
console.log(data);
144+
});
145+
};
146+
147+
129148
/**
130149
* End logic section
131150
*/

0 commit comments

Comments
 (0)
Please sign in to comment.