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

Version Path
locomotive_cms-2.5.7 vendor/assets/javascripts/locomotive/slugify.js
locomotivecms-3.0.0.pre.alpha.2 vendor/assets/javascripts/locomotive/slugify.js
locomotivecms-3.0.0.pre.alpha vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.6 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.6.rc2 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.6.rc1 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.5 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.4 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.3 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.2 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.1 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.0 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.0.rc3 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.0.rc2 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.5.0.rc1 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.4.1 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.4.0 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.3.1 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.3.0 vendor/assets/javascripts/locomotive/slugify.js
locomotive_cms-2.2.3 vendor/assets/javascripts/locomotive/slugify.js