2013-08-28 00:07:28 +00:00
|
|
|
|
|
|
|
|
angular.module("notificationServices", []).factory("Notification", function() {
|
|
|
|
|
var active, data, fixMe, timer;
|
|
|
|
|
fixMe = {
|
|
|
|
|
push: function() {},
|
|
|
|
|
get: function() {},
|
|
|
|
|
animate: function() {},
|
|
|
|
|
clearTimer: function() {},
|
|
|
|
|
init: function() {}
|
|
|
|
|
};
|
|
|
|
|
return fixMe;
|
|
|
|
|
data = {
|
|
|
|
|
message: ""
|
|
|
|
|
};
|
|
|
|
|
active = false;
|
|
|
|
|
timer = null;
|
|
|
|
|
return {
|
|
|
|
|
hide: function() {
|
|
|
|
|
$("#notification").fadeOut(function() {
|
|
|
|
|
$("#notification").css("webkit-transform", "none");
|
|
|
|
|
$("#notification").css("top", "-63px");
|
|
|
|
|
$("#notification").css("left", "0px");
|
2013-08-28 01:13:05 +00:00
|
|
|
setTimeout((function() {
|
|
|
|
|
$("#notification").show();
|
2013-08-28 00:07:28 +00:00
|
|
|
}), 190);
|
|
|
|
|
});
|
|
|
|
|
active = false;
|
2013-08-28 01:13:05 +00:00
|
|
|
timer = null;
|
2013-08-28 00:07:28 +00:00
|
|
|
},
|
|
|
|
|
animate: function() {
|
|
|
|
|
if (timer) {
|
|
|
|
|
clearTimeout(timer);
|
|
|
|
|
timer = setTimeout(this.hide, 2000);
|
|
|
|
|
}
|
|
|
|
|
if (active === false) {
|
|
|
|
|
active = true;
|
|
|
|
|
$("#notification").transition({
|
|
|
|
|
y: 63,
|
|
|
|
|
x: 0
|
|
|
|
|
});
|
2013-08-28 01:13:05 +00:00
|
|
|
timer = setTimeout(this.hide, 2000);
|
2013-08-28 00:07:28 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
push: function(message) {
|
|
|
|
|
data.message = "";
|
|
|
|
|
switch (message.type) {
|
|
|
|
|
case "stats":
|
|
|
|
|
if ((message.stats.exp != null) && (message.stats.gp != null)) {
|
|
|
|
|
data.message = "Experience: " + message.stats.exp + "<br />GP: " + message.stats.gp.toFixed(2);
|
|
|
|
|
}
|
|
|
|
|
if (message.stats.hp) {
|
|
|
|
|
data.message = "HP: " + message.stats.hp.toFixed(2);
|
|
|
|
|
}
|
|
|
|
|
if (message.stats.gp && !(message.stats.exp != null)) {
|
|
|
|
|
data.message = "<br />GP: " + message.stats.gp.toFixed(2);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case "text":
|
|
|
|
|
data.message = message.text;
|
|
|
|
|
}
|
2013-08-28 01:13:05 +00:00
|
|
|
this.animate();
|
2013-08-28 00:07:28 +00:00
|
|
|
},
|
|
|
|
|
get: function() {
|
|
|
|
|
return data;
|
|
|
|
|
},
|
|
|
|
|
clearTimer: function() {
|
|
|
|
|
clearTimeout(timer);
|
|
|
|
|
timer = null;
|
2013-08-28 01:13:05 +00:00
|
|
|
active = false;
|
2013-08-28 00:07:28 +00:00
|
|
|
},
|
|
|
|
|
init: function() {
|
2013-08-28 01:13:05 +00:00
|
|
|
timer = setTimeout(this.hide, 2000);
|
2013-08-28 00:07:28 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|