]> gitweb.fluxo.info Git - semanticscuttle.git/commitdiff
autocomplete with jquery (hardcoded tag list for now)
authorChristian Weiske <cweiske@cweiske.de>
Tue, 22 Mar 2011 17:20:37 +0000 (18:20 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 22 Mar 2011 17:20:37 +0000 (18:20 +0100)
data/templates/editbookmark.tpl.php
www/bookmarks.php

index bbdd5447f37c2ad4992bd4f1d9d6f2e9a6a06f8d..0bfdb29a5ffad2356a8d26836cd42e0c5db72963 100644 (file)
@@ -118,15 +118,52 @@ function jsEscTitle($title)
 </form>
 
 <link href="<?php echo ROOT ?>js/jquery-ui-1.8.5/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css"/>
-  
+
 <script type="text/javascript" src="<?php echo ROOT ?>js/jquery-ui-1.8.5/jquery.ui.core.js"></script>
 <script type="text/javascript" src="<?php echo ROOT ?>js/jquery-ui-1.8.5/jquery.ui.widget.js"></script>
 <script type="text/javascript" src="<?php echo ROOT ?>js/jquery-ui-1.8.5/jquery.ui.position.js"></script>
 <script type="text/javascript" src="<?php echo ROOT ?>js/jquery-ui-1.8.5/jquery.ui.autocomplete.js"></script>
 <script type="text/javascript">
 jQuery(document).ready(function() {
+    function split(val)
+    {
+        return val.split(/,\s*/);
+    }
+
+    function extractLast(term)
+    {
+        return split(term).pop();
+    }
+    var availableTags = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"];
+
     jQuery("input#tags").autocomplete({
-        source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
+
+        minLength: 0,
+
+        source: function(request, response) {
+            // delegate back to autocomplete, but extract the last term
+            response(
+                $.ui.autocomplete.filter(
+                    availableTags, extractLast(request.term)
+                )
+            );
+        },
+
+        focus: function() {
+            // prevent value inserted on focus
+            return false;
+        },
+        select: function(event, ui) {
+            var terms = split(this.value);
+            // remove the current input
+            terms.pop();
+            // add the selected item
+            terms.push(ui.item.value);
+            // add placeholder to get the comma-and-space at the end
+            terms.push("");
+            this.value = terms.join(", ");
+            return false;
+        }
     });
 });
 </script>
index 0753c16ddd4f43097e637a3f73e0846e86b1ae57..3b1d50afa759f882ed1b09ea4f688dc5d8f4e04e 100644 (file)
@@ -146,7 +146,7 @@ if ($userservice->isLoggedOn() && POST_SUBMITTED != '') {
                        $description = trim(POST_DESCRIPTION);
                        $privateNote = trim(POST_PRIVATENOTE);
                        $status = intval(POST_STATUS);
-                       $categories = trim(implode(',', $_POST['tags']));
+                       $categories = explode(',', $_POST['tags']);
                        $saved = true;
                        if ($bookmarkservice->addBookmark($address, $title, $description, $privateNote, $status, $categories)) {
                                if (POST_POPUP != '') {