summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/tag/controllers/tags.php3
-rw-r--r--modules/tag/helpers/tag.php17
-rw-r--r--modules/tag/helpers/tag_block.php16
-rw-r--r--modules/tag/js/tag.js26
-rw-r--r--modules/tag/views/tag_block.html.php19
-rw-r--r--modules/tag/views/tag_block_cloud.html.php9
6 files changed, 47 insertions, 43 deletions
diff --git a/modules/tag/controllers/tags.php b/modules/tag/controllers/tags.php
index 9a5422cf..bf396a5b 100644
--- a/modules/tag/controllers/tags.php
+++ b/modules/tag/controllers/tags.php
@@ -43,7 +43,8 @@ class Tags_Controller extends REST_Controller {
}
public function _index() {
- throw new Exception("@todo Tag_Controller::_index NOT IMPLEMENTED");
+ // @todo: represent this in different formats
+ print tag::cloud(30);
}
public function _form_add($item_id) {
diff --git a/modules/tag/helpers/tag.php b/modules/tag/helpers/tag.php
index a1939df7..23edc5f2 100644
--- a/modules/tag/helpers/tag.php
+++ b/modules/tag/helpers/tag.php
@@ -61,4 +61,21 @@ class tag_Core {
->limit($count)
->find_all();
}
+
+ /**
+ * Return a rendering of the cloud for the N most popular tags.
+ *
+ * @param integer $count the number of tags
+ * @return View
+ */
+ public static function cloud($count) {
+ $tags = tag::popular_tags($count)->as_array();
+ if ($tags) {
+ $cloud = new View("tag_block_cloud.html");
+ $cloud->max_count = $tags[0]->count;
+ usort($tags, array("tag_block", "sort_by_name"));
+ $cloud->tags = $tags;
+ return $cloud;
+ }
+ }
}
diff --git a/modules/tag/helpers/tag_block.php b/modules/tag/helpers/tag_block.php
index c735ee04..02a536ad 100644
--- a/modules/tag/helpers/tag_block.php
+++ b/modules/tag/helpers/tag_block.php
@@ -28,23 +28,13 @@ class tag_block_Core {
$block->id = "gTag";
$block->title = _("Tags");
$block->content = new View("tag_block.html");
-
- $tags = tag::popular_tags(30)->as_array();
- if ($tags) {
- $block->content->max_count = $tags[0]->count;
-
- usort($tags, array("tag_block", "sort_by_name"));
- $block->content->tags = $tags;
- if ($block->content->page_type != "tag") {
- $block->content->item = $theme->item();
- }
- } else {
- $block->content->tags = array();
- }
+ $block->content->cloud = tag::cloud(30);
if ($theme->page_type() != "tag") {
$controller = new Tags_Controller();
$block->content->form = $controller->form_add($theme->item());
+ } else {
+ $block->content->form = "";
}
return $block;
diff --git a/modules/tag/js/tag.js b/modules/tag/js/tag.js
index 30e9ca50..fbcbd419 100644
--- a/modules/tag/js/tag.js
+++ b/modules/tag/js/tag.js
@@ -1,19 +1,17 @@
$("document").ready(function() {
- var options = {
- target: "#gTagFormContainer",
- success: function(responseText, statusText) {
- $("#gAddTag").ajaxForm(options);
- }
- };
- $("#gAddTag").ajaxForm(options);
+ ajaxify_tag_form();
});
-function get_tag_block(url) {
- $.post(url, function(data) {
- $('#gTagFormContainer').html(data);
- $("#gAddTag").submit(function(event){
- get_tag_block($("#gAddTag").attr("action"));
- return false;
- });
+function ajaxify_tag_form() {
+ $("form#gAddTag").ajaxForm({
+ complete: function(xhr, statusText) {
+ $("form#gAddTag").replaceWith(xhr.responseText);
+ if (xhr.status == 201) {
+ $.get($("#gTagCloud").attr("src"), function(data, textStatus) {
+ $("#gTagCloud").html(data);
+ });
+ }
+ ajaxify_tag_form();
+ }
});
}
diff --git a/modules/tag/views/tag_block.html.php b/modules/tag/views/tag_block.html.php
index 6ce67e9d..cc75e6f0 100644
--- a/modules/tag/views/tag_block.html.php
+++ b/modules/tag/views/tag_block.html.php
@@ -1,18 +1,7 @@
<? defined("SYSPATH") or die("No direct script access."); ?>
-<? if ($tags): ?>
-<ul>
- <? foreach ($tags as $tag): ?>
- <li class="size<?=(int)(($tag->count / $max_count) * 7) ?>">
- <span><?= $tag->count ?> photos are tagged with </span>
- <a href="<?=url::site("tags/$tag->id") ?>"><?= $tag->name ?></a>
- </li>
- <? endforeach ?>
-</ul>
-<? endif ?>
-
-<? if (isset($form)): ?>
-<div id="gTagFormContainer">
- <?= $form ?>
+<div id="gTagCloud" src="<?= url::site("tags") ?>">
+ <?= $cloud ?>
</div>
-<? endif; ?>
+<?= $form ?>
+
diff --git a/modules/tag/views/tag_block_cloud.html.php b/modules/tag/views/tag_block_cloud.html.php
new file mode 100644
index 00000000..6abaf953
--- /dev/null
+++ b/modules/tag/views/tag_block_cloud.html.php
@@ -0,0 +1,9 @@
+<? defined("SYSPATH") or die("No direct script access."); ?>
+<ul>
+ <? foreach ($tags as $tag): ?>
+ <li class="size<?=(int)(($tag->count / $max_count) * 7) ?>">
+ <span><?= $tag->count ?> photos are tagged with </span>
+ <a href="<?=url::site("tags/$tag->id") ?>"><?= $tag->name ?></a>
+ </li>
+ <? endforeach ?>
+</ul>