aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Weiske <cweiske@cweiske.de>2011-03-22 18:20:37 +0100
committerChristian Weiske <cweiske@cweiske.de>2011-03-22 18:20:37 +0100
commit21c583a4cd7c6c74ba8f907c962df8718fc2b3a1 (patch)
tree114f4be0a9f467a1801a3f183d69f0b8c1c6a63f
parentabc2ca6f79d14ed92fdd251284708212eba425dd (diff)
downloadsemanticscuttle-21c583a4cd7c6c74ba8f907c962df8718fc2b3a1.tar.gz
semanticscuttle-21c583a4cd7c6c74ba8f907c962df8718fc2b3a1.tar.bz2
autocomplete with jquery (hardcoded tag list for now)
-rw-r--r--data/templates/editbookmark.tpl.php41
-rw-r--r--www/bookmarks.php2
2 files changed, 40 insertions, 3 deletions
diff --git a/data/templates/editbookmark.tpl.php b/data/templates/editbookmark.tpl.php
index bbdd544..0bfdb29 100644
--- a/data/templates/editbookmark.tpl.php
+++ b/data/templates/editbookmark.tpl.php
@@ -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>
diff --git a/www/bookmarks.php b/www/bookmarks.php
index 0753c16..3b1d50a 100644
--- a/www/bookmarks.php
+++ b/www/bookmarks.php
@@ -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 != '') {