diff options
author | Paul Duncan <pabs@pablotron.org> | 2016-04-04 21:36:12 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2016-04-04 21:36:12 -0400 |
commit | 9b408027406a37c25a57b3290e8155885b502bc4 (patch) | |
tree | 16da308dc4d2324979d4c8a11754078b80749d3d /data | |
parent | 28fb868b3c9b61d2a86784239d5cf1e4bacbeda4 (diff) | |
download | old-guff-9b408027406a37c25a57b3290e8155885b502bc4.tar.bz2 old-guff-9b408027406a37c25a57b3290e8155885b502bc4.zip |
enable autoslug for projects
Diffstat (limited to 'data')
-rw-r--r-- | data/stuff/test/tab-posts.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/data/stuff/test/tab-posts.js b/data/stuff/test/tab-posts.js index 90c26de..99933d8 100644 --- a/data/stuff/test/tab-posts.js +++ b/data/stuff/test/tab-posts.js @@ -38,6 +38,16 @@ jQuery(function($) { ], }); + function update_slug(name, slug) { + if (slug.prop('disabled')) { + slug.val( + name.val().toLowerCase() + .replace(/[^a-z0-9_\.-]+/g, '-') + .replace(/^-+|-+$/g, '') + ); + } + } + $.each(['blog', 'page', 'project'], function(i, id) { var p = '#' + id + '-edit-'; @@ -75,4 +85,34 @@ jQuery(function($) { return false; }); }); + + $('.post-name').keydown(function() { + var name = $(this), + slug = $(this).parents('.modal-body').find('.post-slug'); + + setTimeout(function() { + update_slug(name, slug); + }, 10); + }); + + $('.post-slug-lock').click(function() { + var modal_body = $(this).parents('.modal-body'); + + // toggle locked state + $(this).toggleClass('btn-default btn-primary') + .find('.fa').toggleClass('fa-lock fa-unlock'); + var locked = $(this).hasClass('btn-default'); + + // update slug disabled state + var slug = modal_body.find('.post-slug'); + slug.prop('disabled', locked ? 'disabled' : null); + + if (locked) { + // auto-generate slug + update_slug(modal_body.find('.post-name'), slug); + } + + // stop event + return false; + }); }); |