2
0
MasterPassword/public/site/2015-05/js/main.js

52 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-04-16 21:17:16 +00:00
$(function() {
$("*[data-hero]").hover(function() {
let active = this;
$(this).parents("header").addClass( "hero_" + $(this).attr("data-hero") );
$("*[data-hero]").each(function() {
if (this != active)
$(this).parents("header").removeClass( "hero_" + $(this).attr("data-hero") );
});
});
2018-04-18 15:54:30 +00:00
$.each($(".widget_calculator"), function(i, calculator) {
calculator = $(calculator);
var display = calculator.find("input[type=text]");
var lhs = null, operator = null;
2018-04-16 21:17:16 +00:00
2018-04-18 15:54:30 +00:00
function calculator_apply() {
if (lhs && operator == '-')
display.val(parseInt(lhs) - parseInt(display.val()));
else if (lhs && operator == '+')
display.val(parseInt(lhs) + parseInt(display.val()));
}
2018-04-16 21:17:16 +00:00
2018-04-18 15:54:30 +00:00
calculator.find("input[type=button]").click(function() {
var value = $(this).val();
if (value == '-' || value == '+') {
if (operator == value && !display.val())
operator = null;
else {
calculator_apply();
operator = value;
lhs = display.val();
display.val('');
}
} else if (value == 'C') {
operator = null;
lhs = null;
2018-04-16 21:17:16 +00:00
display.val('');
2018-04-18 15:54:30 +00:00
} else if (value == '=')
calculator_apply();
else
display.val(display.val() + '' + value);
2018-04-16 21:17:16 +00:00
2018-04-18 15:54:30 +00:00
calculator.find("input").removeClass('selected');
if (operator)
calculator.find("input[value='" + operator + "']").addClass('selected');
});
2018-04-16 21:17:16 +00:00
});
});