Made hero attribute reactive and iterated inventory UI

This commit is contained in:
Thaum
2015-02-03 10:47:16 +00:00
parent 4377da5275
commit aa9cfbf04e
13 changed files with 86 additions and 44 deletions

View File

@@ -37,7 +37,7 @@ this.GlobalUI = (function() {
GlobalUI.showDetail = function(opts) {
Session.set("global.ui.detailData", opts.data);
Session.set("global.ui.detailTemplate", opts.template);
GlobalUI.detailHero = opts.hero;
Session.set("global.ui.detailHeroId", opts.heroId);
Session.set("global.ui.detailShow", true);
};
@@ -51,7 +51,7 @@ this.GlobalUI = (function() {
GlobalUI.setDetail = function(opts) {
Session.set("global.ui.detailData", opts.data);
Session.set("global.ui.detailTemplate", opts.template);
GlobalUI.detailHero = opts.hero;
Session.set("global.ui.detailHeroId", opts.heroId);
};
GlobalUI.closeDetail = function(){
@@ -108,21 +108,15 @@ Template.layout.events({
} else {
Session.set("global.ui.detailData", null);
Session.set("global.ui.detailTemplate", null);
//remove the hero attribute
var heroElem = GlobalUI.detailHero;
heroElem && heroElem.attr("hero", null);
heroElem && heroElem.find("[hero-id]").attr("hero", null);
GlobalUI.detailHero = null;
Session.set("global.ui.detailHeroId", null);
}
},
"core-animated-pages-transition-prepare": function(e) {
var detailOpened = Session.get("global.ui.detailShow");
if(detailOpened) {
//add the hero attribute where needed
var heroElem = GlobalUI.detailHero;
heroElem && heroElem.attr("hero", "");
heroElem && heroElem.find("[hero-id]").attr("hero", "");
//set up the transition
} else {
//undo hack
$("#mainContentSection").removeClass("fake-selected");
}
},

View File

@@ -0,0 +1,5 @@
Template.registerHelper("detailHero", function(){
if ( Session.equals("global.ui.detailHeroId", this._id) ) {
return "hero";
}
});

View File

@@ -0,0 +1,6 @@
Template.registerHelper("round", function(value, decimalPlaces){
decimalPlaces = +decimalPlaces || 2;
var num = +value;
var tens = Math.pow(10, decimalPlaces)
return Math.round(num * tens) / tens;
});