// Avoid `console` errors in browsers that lack a console.
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeline', 'timelineEnd', 'timeStamp', 'trace', 'warn'
];
var length = methods.length;
var console = (window.console = window.console || {});
while (length--) {
method = methods[length];
// Only stub undefined methods.
if (!console[method]) {
console[method] = noop;
}
}
}());
// Place any jQuery/helper plugins in here.
/* jQuery dependency functions */
jQuery.fn.extend({
'templateRenderDynamic' : function(name, data) {
thisForm = this;
$.get("tpls/" + name + ".tpl", function(tpl) {
var template = Handlebars.compile(tpl);
var txt = template(data);
console.log(txt);
$(thisForm).html(txt);
});
},
'templateRenderStatic' : function(name, data) {
// console.log(name + '.tpl');
return $(this).html(Handlebars.templates[name + '.tpl'](data));
},
'templateRender' : function(name, data) {
// switch to static when ready
return $(this).templateRenderStatic(name, data);
// this way is much slower
// return $(this).templateRenderDynamic(name, data);
}
});
var safePopUp = function(url) {
console.log(url);
var newWindow = window.open(url, 'Safe Popout', 'height=600,width=450');
if (window.focus) {
newWindow.focus();
}
}
Handlebars.registerHelper('checklength', function (v1, v2, options) {
'use strict';
if (v1.length>v2) {
return options.fn(this);
}
return options.inverse(this);
});
Handlebars.registerHelper("math", function(lvalue, operator, rvalue, options) {
lvalue = parseFloat(lvalue);
rvalue = parseFloat(rvalue);
return {
"+": lvalue + rvalue,
"-": lvalue - rvalue,
"*": lvalue * rvalue,
"/": lvalue / rvalue,
"%": lvalue % rvalue
}[operator];
});
Handlebars.registerHelper('compare', function (lvalue, operator, rvalue, options) {
var operators, result;
if (arguments.length < 3) {
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
}
if (options === undefined) {
options = rvalue;
rvalue = operator;
operator = "===";
}
operators = {
'==': function (l, r) { return l == r; },
'===': function (l, r) { return l === r; },
'!=': function (l, r) { return l != r; },
'!==': function (l, r) { return l !== r; },
'<': function (l, r) { return l < r; },
'>': function (l, r) { return l > r; },
'<=': function (l, r) { return l <= r; },
'>=': function (l, r) { return l >= r; },
'typeof': function (l, r) { return typeof l == r; },
'%': function (l, r) { return l % r == 0; },
'!%': function (l, r) {
if(islast === true)
return true; l= l+1;
return l % r == 0;
}
};
if (!operators[operator]) {
throw new Error("Handlerbars Helper 'compare' doesn't know the operator " + operator);
}
result = operators[operator](lvalue, rvalue);
if (result) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
Handlebars.registerHelper('iter', function(context, options) {
var fn = options.fn, inverse = options.inverse;
var ret = "";
if(context && context.length > 0) {
for(var i=0, j=context.length; i= 0; i-- ) {
if( S[i] !== '-' ) {
out.push( S[i].toUpperCase() );
counter++;
}
if( counter === K ) {
out.push( '-' );
counter = 0;
}
}
out.reverse();
while(out.length) {
if( out[0] === '-' ) {
out.shift();
}else {
break;
}
}
return out.join('');
};