(function() { var activate, canBeBlank, currentNumericInput, initInputTemplate, onInput, save, template; template = function() { return $(''); }; onInput = function(event) { var cmsField; cmsField = $(event.currentTarget); if (cmsField.find("input").is(":valid")) { return save(cmsField); } }; save = function(cmsField) { cmsField.find("input").attr("data-scrivito-editors-number-invalid", false); return cmsField.scrivito('save', currentNumericInput(cmsField)).done(function() { return cmsField.trigger('scrivito_editors:save'); }).fail(function() { return cmsField.find("input").attr("data-scrivito-editors-number-invalid", true); }); }; currentNumericInput = function(cmsField) { var val; val = cmsField.find("input").val(); if (val) { return Number(val); } else if (val === "" && canBeBlank(cmsField)) { return null; } else { return 0/0; } }; canBeBlank = function(cmsField) { return cmsField.data("scrivito-editors-allow-delete") !== false; }; initInputTemplate = function(cmsField) { var html, max, min, stepParam; html = template(); stepParam = cmsField.data('scrivito-editors-step'); max = cmsField.data('scrivito-editors-max'); min = cmsField.data('scrivito-editors-min'); if (cmsField.is('[data-scrivito-field-type=float]')) { if (stepParam == null) { stepParam = "any"; } } if (cmsField.is('[data-scrivito-field-type=integer]')) { if (max == null) { max = 9007199254740991; } if (min == null) { min = -9007199254740991; } } html.attr('step', stepParam); html.attr('min', min); html.attr('max', max); html.attr('value', cmsField.scrivito('content')); return html; }; activate = function(element) { var cmsField, html; cmsField = $(element); html = initInputTemplate(cmsField); cmsField.html(html); return cmsField.on('input', onInput); }; scrivito.editors.number_editor = { can_edit: function(element) { return $(element).is("[data-scrivito-field-type=float],\n[data-scrivito-field-type=integer]"); }, activate: function(element) { return activate(element); } }; scrivito.on('load', function() { return scrivito.define_editor('number', scrivito.editors.number_editor); }); }).call(this);