aboutsummaryrefslogtreecommitdiff
path: root/data/stuff/test
diff options
context:
space:
mode:
Diffstat (limited to 'data/stuff/test')
-rw-r--r--data/stuff/test/tab-posts.js40
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;
+ });
});