jQuery(function($) { "use strict"; window.send = function(fn, args) { return $.ajax({ url: "/guff/api/" + fn, method: 'POST', dataType: 'json', data: args, }); }; window.gripe = function(r, action) { // get error var error = r.responseText; // handle json response try { var data = $.parseJSON(r.responseText); if (data.error) error = data.error; } catch (e) {} // build prefix var prefix = 'Error: '; if (action) prefix += " Couldn't " + action + ": "; // display error message alert(prefix + error); }; // slugify string window.slugify = function(s) { return s.toLowerCase() .replace(/[^a-z0-9_-]+/g, '-') .replace(/^-+|-+$/g, ''); }; // convert textarea to jsonified array of strings window.listify = function(el) { var r = $(el).val().replace(/^\s+|\s+$/m, ''); return JSON.stringify((r.length > 0) ? r.split(/\s+/m) : []); } LuigiTemplate.FILTERS.json = function(val) { return JSON.stringify(val); }; });