Skip to content

Commit

Permalink
Use different style to indicate affordable item's button
Browse files Browse the repository at this point in the history
  • Loading branch information
akfish committed Jul 10, 2014
1 parent 40143fa commit f4651e3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 4 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ div.button:hover {
text-decoration: underline;
}

div.button.affordable {
border-color: green;
}

div.button.disabled, div.button.disabled:hover {
cursor: default;
border-color: grey;
Expand Down
21 changes: 20 additions & 1 deletion script/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,32 @@ var Button = {
if(options.cost) {
var ttPos = options.ttPos ? options.ttPos : "bottom right";
var costTooltip = $('<div>').addClass('tooltip ' + ttPos);
var affordable = true;
for(var k in options.cost) {
var have = $SM.get("stores." + _(k));
var need = options.cost[k];
$("<div>").addClass('row_key').text(_(k)).appendTo(costTooltip);
$("<div>").addClass('row_val').text(options.cost[k]).appendTo(costTooltip);
$("<div>").addClass('row_val').text(need).appendTo(costTooltip);
if (have < need) affordable = false;
}
el.toggleClass('affordable', affordable);
if(costTooltip.children().length > 0) {
costTooltip.appendTo(el);
}
// Subscribe to stateUpdateEvent
$.Dispatch('stateUpdate').subscribe(function (e) {
if (e.category != 'stores') return;
var affordable = true;
for (var k in options.cost) {
var need = options.cost[k];
var have = $SM.get("stores." + _(k));
if (need > have) {
affordable = false;
break;
}
}
el.toggleClass('affordable', affordable);
});
}

if(options.width) {
Expand Down

0 comments on commit f4651e3

Please sign in to comment.