Skip to content

Commit

Permalink
Clean up amd simplify the tag processing: Only allow comma separators…
Browse files Browse the repository at this point in the history
… between

phrases.  Using only 1 separator cleans up the javascript as well, as we
can use some of the jquery autocomplete to set the tag separator.

Signed-off-by: Tim Almdal <tnalmdal@shaw.ca>
  • Loading branch information
Tim Almdal committed Jul 28, 2009
1 parent ecc9203 commit 975a5de
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion modules/tag/controllers/tags.php
Expand Up @@ -81,7 +81,7 @@ public function _form_add($item_id) {

public function autocomplete() {
$tags = array();
$tag_parts = preg_split("#[,\s]+# ", $this->input->get("q"));
$tag_parts = preg_split("#,#", $this->input->get("q"));
$limit = $this->input->get("limit");
$tag_part = end($tag_parts);
$tag_list = ORM::factory("tag")
Expand Down
6 changes: 5 additions & 1 deletion modules/tag/helpers/tag_event.php
Expand Up @@ -68,7 +68,11 @@ static function item_edit_form($item, $view) {
$url = url::site("tags/autocomplete");
$view->script[] = "$('#gEditFormContainer form').ready(function() {
$('#gEditFormContainer form input[id=tags]').autocomplete(
'$url', {max: 30, formatResult: formatTagAutoCompleteResult}
'$url',
{max: 30,
multiple: true,
multipleSeparator: ',',
cacheLength: 1}
);
});";
$tag_value = implode(", ", tag::item_tags($item));
Expand Down
15 changes: 0 additions & 15 deletions modules/tag/js/tag.js
Expand Up @@ -66,18 +66,3 @@ function editInPlace(element) {
};
ajaxify_editInPlaceForm();
}

function formatTagAutoCompleteResult(row) {
var text = $(".ac_loading").val();
if (/[\s,;]/.test(text)) {
for (var i= text.length - 1; i >= 0; i--) {
var chr = text.charAt(i);
if (chr == " " || chr == "," || chr == ";") {
break;
}
}
return text.substr(0, i + 1) + row[0];
} else {
return row[0];
}
}
4 changes: 3 additions & 1 deletion modules/tag/views/tag_block.html.php
Expand Up @@ -5,7 +5,9 @@
$("#gAddTagForm input:text").autocomplete(
url, {
max: 30,
formatResult: formatTagAutoCompleteResult}
multiple: true,
multipleSeparator: ',',
cacheLength: 1}
);
});
</script>
Expand Down

0 comments on commit 975a5de

Please sign in to comment.