From 9662af5a17a660a6c921be72a370b3e14cdd08a4 Mon Sep 17 00:00:00 2001 From: Aaron Parecki Date: Thu, 7 Apr 2016 16:45:15 -0700 Subject: [PATCH] set category from hashtags in post --- views/new-post.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/views/new-post.php b/views/new-post.php index 53cb01e..46be7a9 100644 --- a/views/new-post.php +++ b/views/new-post.php @@ -133,6 +133,8 @@ function previewPhoto(event) { $(function(){ + var userHasSetCategory = false; + $("#note_content").on('change keyup', function(e){ var text = $("#note_content").val(); var tweet_length = tw_text_proxy(text).length; @@ -141,6 +143,11 @@ $(function(){ $("#note_content_remaining span").html(remaining); $("#note_content_remaining").removeClass("pcheck200 pcheck206 pcheck207 pcheck208 pcheck413"); $("#note_content_remaining").addClass("pcheck"+tweet_check); + + // If the user didn't enter any categories, add them from the post + if(!userHasSetCategory) { + $("#note_category").val($("#note_content").val().match(/#[a-z0-9]+/g).map(function(tag){ return tag.replace('#',''); }).join(", ")); + } }); $("#note_in_reply_to").on('change', function(){ @@ -149,6 +156,15 @@ $(function(){ } }); + $("#note_category").on('keydown keyup', function(){ + userHasSetCategory = true; + }); + $("#note_category").on('change', function(){ + if($("#note_category").val() == "") { + userHasSetCategory = false; + } + }); + if($("#note_in_reply_to").val() != "") { $("#note_in_reply_to").change(); }