autocomplete with jquery (hardcoded tag list for now)
This commit is contained in:
parent
abc2ca6f79
commit
21c583a4cd
2 changed files with 40 additions and 3 deletions
|
@ -125,8 +125,45 @@ function jsEscTitle($title)
|
||||||
<script type="text/javascript" src="<?php echo ROOT ?>js/jquery-ui-1.8.5/jquery.ui.autocomplete.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">
|
<script type="text/javascript">
|
||||||
jQuery(document).ready(function() {
|
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({
|
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>
|
</script>
|
||||||
|
|
|
@ -146,7 +146,7 @@ if ($userservice->isLoggedOn() && POST_SUBMITTED != '') {
|
||||||
$description = trim(POST_DESCRIPTION);
|
$description = trim(POST_DESCRIPTION);
|
||||||
$privateNote = trim(POST_PRIVATENOTE);
|
$privateNote = trim(POST_PRIVATENOTE);
|
||||||
$status = intval(POST_STATUS);
|
$status = intval(POST_STATUS);
|
||||||
$categories = trim(implode(',', $_POST['tags']));
|
$categories = explode(',', $_POST['tags']);
|
||||||
$saved = true;
|
$saved = true;
|
||||||
if ($bookmarkservice->addBookmark($address, $title, $description, $privateNote, $status, $categories)) {
|
if ($bookmarkservice->addBookmark($address, $title, $description, $privateNote, $status, $categories)) {
|
||||||
if (POST_POPUP != '') {
|
if (POST_POPUP != '') {
|
||||||
|
|
Loading…
Reference in a new issue