diff options
Diffstat (limited to 'data')
-rw-r--r-- | data/assets/js/admin/dialogs/page-edit.js | 4 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/post-edit.js | 11 | ||||
-rw-r--r-- | data/assets/js/admin/dialogs/site-add.js | 43 | ||||
-rw-r--r-- | data/assets/js/util.js | 14 |
4 files changed, 45 insertions, 27 deletions
diff --git a/data/assets/js/admin/dialogs/page-edit.js b/data/assets/js/admin/dialogs/page-edit.js index 9e32d89..0e7a5b3 100644 --- a/data/assets/js/admin/dialogs/page-edit.js +++ b/data/assets/js/admin/dialogs/page-edit.js @@ -22,9 +22,7 @@ jQuery(function($) { // get assets var assets = ASSET_TYPES.reduce(function(r, key) { - var s = $(p + key).val().replace(/^\s+|\s$/mg, ''); - r[key] = JSON.stringify((s.length > 0) ? s.split(/\s+/m) : []); - + r[key] = listify(p + key); return r; }, {}); diff --git a/data/assets/js/admin/dialogs/post-edit.js b/data/assets/js/admin/dialogs/post-edit.js index 9d90b99..d7eb120 100644 --- a/data/assets/js/admin/dialogs/post-edit.js +++ b/data/assets/js/admin/dialogs/post-edit.js @@ -5,13 +5,8 @@ jQuery(function($) { }); function update_slug(name, slug) { - if (slug.prop('disabled')) { - slug.val( - name.val().toLowerCase() - .replace(/[^a-z0-9_-]+/g, '-') - .replace(/^-+|-+$/g, '') - ); - } + if (slug.prop('disabled')) + slug.val(slugify(name.val())); } $.each(['blog', 'page', 'project'], function(i, id) { @@ -22,6 +17,7 @@ jQuery(function($) { slug_lock = (r.slug_lock == "1"); $(p + 'name').val(r.name); + $(p + 'site').val(r.site_id); $(p + 'slug').val(r.slug) .prop('disabled', slug_lock ? 'disabled' : null); @@ -100,6 +96,7 @@ jQuery(function($) { send(id + "/set", $.extend({ post_id: $(p + 'dialog').data('post_id'), + site_id: $(p + 'site').val(), name: $(p + 'name').val(), slug_lock: $(p + 'slug-lock').hasClass('btn-default') ? 't' : 'f', slug: $(p + 'slug').val(), diff --git a/data/assets/js/admin/dialogs/site-add.js b/data/assets/js/admin/dialogs/site-add.js index 9a3c02f..8cdc772 100644 --- a/data/assets/js/admin/dialogs/site-add.js +++ b/data/assets/js/admin/dialogs/site-add.js @@ -1,34 +1,35 @@ jQuery(function($) { "use strict"; - var IDS = ['name', 'slug', 'body', 'lang', 'theme_id']; + var p = '#site-add-', + IDS = ['name', 'slug', 'body', 'lang', 'theme_id']; + var DEFAULTS = { lang: DATA.default_lang, theme_id: DATA.default_theme_id, }; - function get_domains() { - var r = $('#site-add-domains').val().replace(/^\s+|\s+$/m, ''); - return (r.length > 0) ? r.split(/\s+/m) : []; - } - - $('#site-add-dialog').on('show.bs.modal', function() { + $(p + 'dialog').on('show.bs.modal', function() { $.each(IDS, function(_, id) { - $('#site-add-' + id).val(DEFAULTS[id] || ''); + $(p + id).val(DEFAULTS[id] || ''); }); // clear list of domains - $('#site-add-domains').val(''); + $(p + 'domains').val(''); }); - $('#site-add-dialog').on('shown.bs.modal', function() { - $('#site-add-name').focus(); + $(p + 'dialog').on('shown.bs.modal', function() { + // show content tab + $(p + 'tab-content').click(); + + // focus name field + $(p + 'name').focus(); }); - $('#site-add-dialog input[type="text"]').keydown(function(ev) { + $(p + 'dialog input[type="text"]').keydown(function(ev) { if (ev.which == 13) { setTimeout(function() { - $('#site-add-confirm').click(); + $(p + 'confirm').click(); }, 10); // stop event @@ -36,7 +37,15 @@ jQuery(function($) { } }); - $('#site-add-confirm').click(function() { + $(p + 'name').keydown(function(ev) { + var me = $(this); + + setTimeout(function() { + $(p + 'slug').val(slugify(me.val())); + }, 10); + }); + + $(p + 'confirm').click(function() { var me = $(this); if (me.hasClass('disabled')) @@ -46,11 +55,11 @@ jQuery(function($) { me.toggleClass('disabled').find('.loading').toggleClass('hidden'); send('site/add', IDS.reduce(function(r, id) { - r[id] = $('#site-add-' + id).val(); + r[id] = $(p + id).val(); return r; }, { is_full_feed: 't', - domains: JSON.stringify(get_domains()), + domains: listify(p + 'domains'), })).always(function() { // toggle loading me.toggleClass('disabled').find('.loading').toggleClass('hidden'); @@ -58,7 +67,7 @@ jQuery(function($) { gripe(r, 'add site'); }).done(function(r) { $('#sites-reload').click(); - $('#site-add-dialog').modal('hide'); + $(p + 'dialog').modal('hide'); }); // stop event diff --git a/data/assets/js/util.js b/data/assets/js/util.js index 7986120..6379961 100644 --- a/data/assets/js/util.js +++ b/data/assets/js/util.js @@ -28,8 +28,22 @@ jQuery(function($) { // display error message alert(prefix + error); + }; + + // slugify string + window.slugify = function(s) { + return s.toLowerCase() + .replace(/[^a-z0-9_-]+/g, '-') + .replace(/^-+|-+$/g, ''); + }; + + // convert textarea to jsonified array of strings + window.listify = function(el) { + var r = $(el).val().replace(/^\s+|\s+$/m, ''); + return JSON.stringify((r.length > 0) ? r.split(/\s+/m) : []); } + LuigiTemplate.FILTERS.json = function(val) { return JSON.stringify(val); }; |