diff options
author | Nathan Kinkade <nath@nkinka.de> | 2013-03-19 16:41:42 +0000 |
---|---|---|
committer | Nathan Kinkade <nath@nkinka.de> | 2013-03-19 16:41:42 +0000 |
commit | 3908e37d965fa76ea774e76ddf42365a872a5f27 (patch) | |
tree | 457e1a1e465f83855eee96ba287cd91f1623395c /modules/tag | |
parent | 711651f727e093cc7357a6bbff6bd992fd6dfd80 (diff) | |
parent | 1eab94f6062b5f54ea5d9db01d968e7195f3de9d (diff) |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/tag')
-rw-r--r-- | modules/tag/controllers/tags.php | 9 | ||||
-rw-r--r-- | modules/tag/helpers/tag_event.php | 41 | ||||
-rw-r--r-- | modules/tag/helpers/tag_theme.php | 4 | ||||
-rw-r--r-- | modules/tag/views/tag_block.html.php | 16 |
4 files changed, 24 insertions, 46 deletions
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php index 77d45a95..32e857c6 100644 --- a/modules/tag/controllers/tags.php +++ b/modules/tag/controllers/tags.php @@ -48,18 +48,17 @@ class Tags_Controller extends Controller { public function autocomplete() { $tags = array(); - $tag_parts = explode(",", Input::instance()->get("q")); - $limit = Input::instance()->get("limit"); + $tag_parts = explode(",", Input::instance()->get("term")); $tag_part = ltrim(end($tag_parts)); $tag_list = ORM::factory("tag") ->where("name", "LIKE", Database::escape_for_like($tag_part) . "%") ->order_by("name", "ASC") - ->limit($limit) + ->limit(100) ->find_all(); foreach ($tag_list as $tag) { - $tags[] = html::clean($tag->name); + $tags[] = (string)html::clean($tag->name); } - ajax::response(implode("\n", $tags)); + ajax::response(json_encode($tags)); } } diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index d62ae36e..927153aa 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -69,19 +69,14 @@ class tag_event_Core { } static function item_edit_form($item, $form) { - $url = url::site("tags/autocomplete"); - $form->script("") - ->text("$('form input[name=tags]').ready(function() { - $('form input[name=tags]').gallery_autocomplete( - '$url', {max: 30, multiple: true, multipleSeparator: ',', cacheLength: 1}); - });"); - $tag_names = array(); foreach (tag::item_tags($item) as $tag) { $tag_names[] = $tag->name; } $form->edit_item->input("tags")->label(t("Tags (comma separated)")) ->value(implode(", ", $tag_names)); + + $form->script("")->text(self::_get_autocomplete_js()); } static function item_edit_form_completed($item, $form) { @@ -111,38 +106,21 @@ class tag_event_Core { static function add_photos_form($album, $form) { $group = $form->add_photos; - if (!is_object($group->uploadify)) { - return; - } $group->input("tags") ->label(t("Add tags to all uploaded files")) ->value(""); - $group->uploadify->script_data("tags", ""); - - $autocomplete_url = url::site("tags/autocomplete"); - $group->script("") - ->text("$('input[name=tags]') - .gallery_autocomplete( - '$autocomplete_url', - {max: 30, multiple: true, multipleSeparator: ',', cacheLength: 1} - ); - $('input[name=tags]') - .change(function (event) { - $('#g-uploadify').uploadifySettings('scriptData', {'tags': $(this).val()}); - });"); + + $group->script("")->text(self::_get_autocomplete_js()); } - static function add_photos_form_completed($album, $form) { + static function add_photos_form_completed($item, $form) { $group = $form->add_photos; - if (!is_object($group->uploadify)) { - return; - } - foreach (explode(",", $form->add_photos->tags->value) as $tag_name) { + foreach (explode(",", $group->tags->value) as $tag_name) { $tag_name = trim($tag_name); if ($tag_name) { - $tag = tag::add($album, $tag_name); + $tag = tag::add($item, $tag_name); } } } @@ -162,4 +140,9 @@ class tag_event_Core { $block->content->metadata = $info; } } + + private static function _get_autocomplete_js() { + $url = url::site("tags/autocomplete"); + return "$('input[name=\"tags\"]').gallery_autocomplete('$url', {multiple: true});"; + } } diff --git a/modules/tag/helpers/tag_theme.php b/modules/tag/helpers/tag_theme.php index 81d1352f..143af6c1 100644 --- a/modules/tag/helpers/tag_theme.php +++ b/modules/tag/helpers/tag_theme.php @@ -19,9 +19,7 @@ */ class tag_theme_Core { static function head($theme) { - return $theme->css("jquery.autocomplete.css") - . $theme->script("jquery.autocomplete.js") - . $theme->css("tag.css"); + return $theme->css("tag.css"); } static function admin_head($theme) { diff --git a/modules/tag/views/tag_block.html.php b/modules/tag/views/tag_block.html.php index d25b8dcb..afa61b15 100644 --- a/modules/tag/views/tag_block.html.php +++ b/modules/tag/views/tag_block.html.php @@ -2,15 +2,13 @@ <script type="text/javascript"> $("#g-add-tag-form").ready(function() { var url = $("#g-tag-cloud-autocomplete-url").attr("href"); - $("#g-add-tag-form input:text").gallery_autocomplete( - url, { - max: 30, - multiple: true, - multipleSeparator: ',', - cacheLength: 1, - selectFirst: false - } - ); + function split(val) { + return val.split(/,\s*/); + } + function extract_last(term) { + return split(term).pop(); + } + $("#g-add-tag-form input:text").gallery_autocomplete(url, {multiple: true}); $("#g-add-tag-form").ajaxForm({ dataType: "json", success: function(data) { |