diff --git a/public/editor-files/editor.js b/public/editor-files/editor.js index 158b34f..06dc3e1 100644 --- a/public/editor-files/editor.js +++ b/public/editor-files/editor.js @@ -72,7 +72,7 @@ $(function() { $('#publish-in-progress').removeClass('hidden'); $('#publish-fields').addClass('hidden'); - var category = csv_to_array($("#post-tags").tokenfield('getTokensList')); + var category = $("#note_category").tokenfield("getTokens").map(function(t){ return t.value}); $.post('/editor/publish', { name: $("#post-name").val(), @@ -149,14 +149,6 @@ function reset_page() { return localforage.setItem('currentdraft', {}); } -function csv_to_array(val) { - if(val.length > 0) { - return val.split(/[, ]+/); - } else { - return []; - } -} - /* ************************************************ */ /* autosave loop */ var autosaveTimeout = false; diff --git a/public/js/script.js b/public/js/script.js index f6f3a48..57990ee 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -14,15 +14,10 @@ return num; } - function csv_to_array(val) { - if(val.length > 0) { - return val.split(/[, ]+/); - } else { - return []; - } + function tokenfieldToArray(sel) { + return $(sel).tokenfield("getTokens").map(function(t){ return t.value}); } - $(function(){ // Set the date from JS diff --git a/views/event.php b/views/event.php index a71ce79..c50e1d4 100644 --- a/views/event.php +++ b/views/event.php @@ -73,7 +73,7 @@ name: $("#event_name").val(), start: event_start, location: $("#event_location").val(), - category: csv_to_array($("#note_category").val()) + category: tokenfieldToArray("#note_category") }; if(event_end) { diff --git a/views/new-bookmark.php b/views/new-bookmark.php index 068422f..0cc19d7 100644 --- a/views/new-bookmark.php +++ b/views/new-bookmark.php @@ -89,7 +89,7 @@ $(function(){ 'bookmark-of': $("#note_bookmark").val(), name: $("#note_name").val(), content: $("#note_content").val(), - category: csv_to_array($("#note_category").val()), + category: tokenfieldToArray("#note_category"), 'user->micropub_syndicate_field ?>': syndications }, function(response){ if(response.location != false) { diff --git a/views/new-itinerary.php b/views/new-itinerary.php index e7eab1c..f8c9b02 100644 --- a/views/new-itinerary.php +++ b/views/new-itinerary.php @@ -180,7 +180,7 @@ $(function(){ }); }); - var category = csv_to_array($("#note_category").val()); + var category = tokenfieldToArray("#note_category"); properties = { itinerary: itinerary diff --git a/views/new-post.php b/views/new-post.php index 030ca61..9779c1e 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -689,7 +689,7 @@ $(function(){ syndications.push($(btn).data('syndicate-to')); }); - var category = csv_to_array($("#note_category").val()); + var category = tokenfieldToArray("#note_category"); var formData = new FormData(); var entry = {};