Sha256: b6324cf67185c0fb9b5fe26018975bc606b4d601dc3024513796e9bcf5f0676a
Contents?: true
Size: 1.18 KB
Versions: 32
Compression:
Stored size: 1.18 KB
Contents
/** * Version 0.0.1 * Fill in an input field from another one (source) * and apply a filter on the string (slugify) * Didier Lafforgue */ $.fn.slugify = function(settings) { settings = $.extend({ sep: '-', url: null, underscore: false }, settings); var target = $(settings.target); target.data('touched', (target.val() != '')); var makeSlug = function(event) { var source = $(this); if (settings.url != null) { // Ajax call instead meaning rely on the server to get the slugified version of the field params = { 'string': source.val(), 'underscore': (settings.underscore ? '1' : '0') }; jQuery.getJSON(settings.url, params, function(data, textStatus, jqXHR) { var newVal = data['value'] if (!target.data('touched')) { target.val(newVal); target.trigger('change'); } }); } else { var newVal = source.val().slugify(settings.sep); if (!target.data('touched')) { target.val(newVal); target.trigger('change'); } } } target.bind('keyup', function(event) { $(this).data('touched', ($(this).val() != '')); }); return $(this).bind('keyup', makeSlug); };
Version data entries
32 entries across 32 versions & 2 rubygems