Задать вопрос

Тел: +7 965 3737 888

483

Просмотров

2

Ответов

jQuery slugify plugin

This plugin lets you make a field(ideally for a slug) populate itself based on the value of another field. You use it like this:

jQuery('#id_title').slugify('#id_slug');

Вопрос полезен? Да0/Нет0
file_3364.js(301.0б)
None

Ответы (2):

Ответpmcelhaney:23.05.2011
Ответ полезен? Да0/Нет0

Here's a more advanced version. It takes care of a few things like converting & to "and", preventing leading or trailing spaces from becoming hyphens, and barring automatic changes after the slug has been edited manually. It also accepts an optional slugFunc parameter so you can customize how the title is converted to a slug.

https://github.com/pmcelhaney/jQuery-Slugify-Plugin

Ответgobble:05.07.2010
Ответ полезен? Да0/Нет0

jQuery.fn.slugify = function(obj) {
    jQuery(this).data('obj', jQuery(obj));
    jQuery(this).keyup(function() {
        var obj = jQuery(this).data('obj');
        var slug = jQuery(this).val().replace(/\s+/g,'-').replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase();
        jQuery(this).data('obj').val(slug);
    });
    jQuery(this).blur(function() {
        var obj = jQuery(this).data('obj');
        var slug = jQuery(this).val().replace(/\s+/g,'-').replace(/[^a-zA-Z0-9\-]/g,'').toLowerCase();
        jQuery(this).data('obj').val(slug);
    });

}

this fixes a blank slug field if you select a entry for your lineedit from your prowsers suggestion dropdown and exit the lineedit with |tab|.