From 9b408027406a37c25a57b3290e8155885b502bc4 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Mon, 4 Apr 2016 21:36:12 -0400 Subject: enable autoslug for projects --- data/stuff/test/tab-posts.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'data') 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; + }); }); -- cgit v1.2.3