Rewrite JavaScript on main page
Both feedback form and calculator interaction now in its own class.
This commit is contained in:
committed by
Kyle Fiedler
parent
43a6534e75
commit
80aeaed5fe
75
static/js/application.js
Normal file
75
static/js/application.js
Normal file
@@ -0,0 +1,75 @@
|
||||
// Generated by CoffeeScript 1.3.2-pre
|
||||
(function() {
|
||||
|
||||
window.Calculator = (function() {
|
||||
|
||||
function Calculator() {}
|
||||
|
||||
Calculator.bind = function() {
|
||||
var calculator;
|
||||
calculator = new Calculator;
|
||||
$('.calc').click(calculator.toggle);
|
||||
$('form#calculator').submit(calculator.calculate).submit(function(e) {
|
||||
return e.preventDefault();
|
||||
});
|
||||
return $('div.help-wrapper a').hover(calculator.helpToggle).click(function(e) {
|
||||
return e.preventDefault();
|
||||
});
|
||||
};
|
||||
|
||||
Calculator.prototype.toggle = function() {
|
||||
$('li.calc-main').toggleClass('open');
|
||||
$('#calculator_wrapper #calculator_input').focus();
|
||||
return $('.calc').toggleClass('closed');
|
||||
};
|
||||
|
||||
Calculator.prototype.helpToggle = function() {
|
||||
return $('.help').toggleClass('shown');
|
||||
};
|
||||
|
||||
Calculator.prototype.calculate = function() {
|
||||
return $.getJSON('/calculate', {
|
||||
equation: $('#calculator_input').val()
|
||||
}, function(data) {
|
||||
return $('#calculator_output').val(data.result);
|
||||
});
|
||||
};
|
||||
|
||||
return Calculator;
|
||||
|
||||
})();
|
||||
|
||||
window.FeedbackForm = (function() {
|
||||
|
||||
function FeedbackForm() {}
|
||||
|
||||
FeedbackForm.bind = function() {
|
||||
return $('#feedback_button').click(function() {
|
||||
var data;
|
||||
data = {
|
||||
subject: $('#feedback_subject').val(),
|
||||
message: $('#feedback_message').val(),
|
||||
url: window.location.href
|
||||
};
|
||||
return $.post('/send_feedback', data, function() {
|
||||
return $('#feedback_div').html('Feedback submitted. Thank you');
|
||||
}, 'json');
|
||||
});
|
||||
};
|
||||
|
||||
return FeedbackForm;
|
||||
|
||||
})();
|
||||
|
||||
$(function() {
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRFToken': $.cookie('csrftoken')
|
||||
}
|
||||
});
|
||||
FeedbackForm.bind();
|
||||
Calculator.bind();
|
||||
return $("a[rel*=leanModal]").leanModal();
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
Reference in New Issue
Block a user