I'm new to web-developing, so this question I think simple for many of you guys, but difficult to me.
On my page I have 1000+ lines of js, I can split it on 3 types:
1.Where I define global variables and ask back-end for initial data:
var charts_data = #{@object.charts_data};
var max_height = #{@object.max};
var min_height = #{@object.min};
var param_from = #{params[:f].nil? ? -1 : params[:f]};
var param_to = #{params[:t].nil? ? -1 : params[:t]};
2.Where I define some supporting functions (helpers), not relating to current page, i.e. for array:
function clone(obj) {
if (null == obj || "object" != typeof obj) return obj;
var copy = obj.constructor();
for (var attr in obj) {
if (obj.hasOwnProperty(attr)) copy[attr] = clone(obj[attr]);
}
return copy;
}
3.Functions related to current page, that use selectors based on page elements, i.e.:
$('#range-from, #range-to').keypress(function (e) {
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
return false;
}
});
Could you guys help me to clear my view from js and correctly split it and put in another files?