Tagger 20070927 2209

+onload.gif because I needed window.onload and core_scripts/scripts.js hogged it. Getting by with img.onload.

git-svn-id: file:///home/shish/svn/shimmie2/trunk@497 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
Artanis 2007-09-28 05:10:44 +00:00
parent e365e945a8
commit ef0e4190cc
5 changed files with 94 additions and 39 deletions

View File

@ -1,10 +1,26 @@
<?php <?php
// Tagger - Advanced Tagging
// Author: Artanis (Erik Youngren <artanis.00@gmail.com>)
// Do not remove this notice.
class tagger extends Extension { class tagger extends Extension {
var $theme; var $theme;
public function receive_event ($event) { public function receive_event ($event) {
if(is_null($this->theme)) if(is_null($this->theme))
$this->theme = get_theme_object("tagger", "taggerTheme"); $this->theme = get_theme_object("tagger", "taggerTheme");
if(is_a($event,"InitExtEvent")) {
global $config;
if ($config->get_int("ext-tagger_tags-min") == -1)
$config->set_int("ext-tagger_tags-min",2);
if ($config->get_string("ext-tagger_clear-tagme") == -1)
$config->set_bool("ext-tagger_clear-tagme",false);
if ($config->get_string("ext-tagger_show-hidden") == -1)
$config->set_bool("ext-tagger_show-hidden",false);
}
if(is_a($event,"DisplayingImageEvent")) { if(is_a($event,"DisplayingImageEvent")) {
//show tagger box //show tagger box
@ -13,24 +29,32 @@ class tagger extends Extension {
global $config; global $config;
$base_href = $config->get_string('base_href'); $base_href = $config->get_string('base_href');
$tags_min = $config->get_int('ext-tagger_tags-min',2);
$hidden = $config->get_bool('ext-tagger_respect-hidden',true) ? "AND substring(tag,1,1) != '.' " : null;
$tags = $database->Execute(" $tags = $database->Execute("
SELECT tag SELECT tag
FROM `tags` FROM `tags`
WHERE count > 1 AND substring(tag,1,1) != '.' WHERE count >= ? {$hidden}
ORDER BY tag"); ORDER BY tag",array($tags_min));
$this->theme->build($page, $tags); $this->theme->build($page, $tags);
} }
if(is_a($event,"PageRequestEvent") && $event->page_name == "about" if(is_a($event,"PageRequestEvent") && $event->page_name == "about"
&& $event->get_arg(0) == "tagger") && $event->get_arg(0) == "tagger")
{ {
global $page; global $page;
$this->theme->show_about($page); $this->theme->show_about($page);
} }
if(is_a($event, 'SetupBuildingEvent')) {
$sb = new SetupBlock("Tagger - Power Tagging");
$sb->add_bool_option("ext-tagger_show-hidden", "Show Hidden Tags");
$sb->add_bool_option("ext-tagger_clear-tagme", "<br/>Remove '<a href='".make_link("post/list/tagme/1")."'>tagme</a>' on use");
$sb->add_int_option("ext-tagger_tags-min", "<br/>Ignore tags used fewer than "); $sb->add_label("times.");
$event->panel->add_block($sb);
}
} }
} }
add_event_listener( new tagger()); add_event_listener( new tagger());

BIN
contrib/tagger/onload.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 B

View File

@ -1,9 +1,11 @@
// Tagger JS // Tagger - Advanced Tagging
// Original Code Author: Artanis (Erik Youngren <artanis.00@gmail.com>) // Author: Artanis (Erik Youngren <artanis.00@gmail.com>)
// Do not remove this notice.
// All other code copyright by their authors, see comments for details. // All other code copyright by their authors, see comments for details.
// In case the drag point goes off screen.
function taggerResetPos() { function taggerResetPos() {
// In case the drag point goes off screen.
tagger = byId("tagger_window"); tagger = byId("tagger_window");
// reset default position (bottom right.) // reset default position (bottom right.)
@ -36,26 +38,16 @@ function tagExists(tag) {
return false; return false;
} }
function toggleTag(tag) { function toggleTag(tag,rTagme) {
var tags = byId("tags");
var tag_link = byId("tagger_tag_"+tag);
if (!tagExists(tag)) { if (!tagExists(tag)) {
// append tag to tag box. addTag(tag);
tags.value = tags.value +" "+ tag; if(rTagme && tag != "tagme") {
// set indicator remTag("tagme");
if(tag_link) {
tag_link.style.fontWeight = "bold";
} }
} else { } else {
// remove tag remTag(tag);
tags.value=" " + tags.value + " "; // catch first and last tag, too
tags.value=tags.value.replace(" "+tag+" "," ");
// remove extra spaces.
tags.value=tags.value.replace(" "," ");
// set indicator
if(tag_link) {
tag_link.style.fontWeight = "";
}
} }
obj = byId("tagger_custTag"); obj = byId("tagger_custTag");
if(obj.value) { if(obj.value) {
@ -68,12 +60,39 @@ function addTagById(id) {
toggleTag(tag.value); toggleTag(tag.value);
} }
function setTagIndicators() { function addTag (tag) {
tagger = byId("tagger_window"); var tags = byId("tags");
// core.js took window.onload, so emulate it by using onclick and then var tag_link = byId("tagger_tag_"+tag);
// removing the event.
tagger.setAttribute("onmousedown","");
var delim = " ";
if(tags.value == "") {
delim="";
}
tags.value = tags.value + delim + tag;
if(tag_link) {
tag_link.style.fontWeight = "bold";
}
}
function remTag (tag) {
var tags = byId("tags");
var tag_link = byId("tagger_tag_"+tag);
_tags = tags.value.split(" ");
tags.value = "";
for (i in _tags) {
_tag = _tags[i];
if(_tag != tag) {
addTag(_tag);
}
}
if(tag_link) {
tag_link.style.fontWeight = "";
}
}
function setTagIndicators() {
taggerResetPos(); taggerResetPos();
tags = byId("tags"); tags = byId("tags");

View File

@ -1,4 +1,7 @@
/* Tagger Cascading Style Sheet * /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Tagger - Advanced Tagging *
* Author: Artanis (Erik Youngren <artanis.00@gmail.com>) *
* Do not remove this notice. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#tagger_window { #tagger_window {
@ -29,7 +32,7 @@
} }
#tagger_body a { #tagger_body a {
font-size:1.5em; font-size:1.25em;
} }
#Tagger li { #Tagger li {

View File

@ -1,25 +1,34 @@
<?php <?php
// Tagger - Advanced Tagging
// Author: Artanis (Erik Youngren <artanis.00@gmail.com>)
// Do not remove this notice.
class taggerTheme extends Themelet { class taggerTheme extends Themelet {
public function build ($page, $tags) { public function build ($page, $tags) {
global $config;
$tagme = $config->get_string("ext-tagger_clear-tagme","N") == "Y" ? "true":"false";
$base_href = $config->get_string("base_href");
$tag_html = ""; $tag_html = "";
foreach ($tags as $tag) { foreach ($tags as $tag) {
$tag_name = $tag['tag']; $tag_name = $tag['tag'];
$tag_trunc = $this->trimTag($tag_name,16); $tag_trunc = $this->trimTag($tag_name,20,"_");
$tag_html .= "<div id='tagger_tag_".$tag_name."'>"." $tag_html .= "<div id='tagger_tag_".$tag_name."'>"."
<a style='cursor:pointer;' onclick='toggleTag(&quot;".$tag_name."&quot;);' ". <a style='cursor:pointer;' onclick='toggleTag(&quot;".$tag_name."&quot;,".$tagme.");' ".
"title='Add &quot;".$tag_name."&quot; to the tag list'>".$tag_trunc."</a>". "title='Add &quot;".$tag_name."&quot; to the tag list'>".$tag_trunc."</a>".
"</div>"; "</div>";
} }
$url_more = make_link("about/tagger"); $url_more = make_link("about/tagger");
$html = <<<EOD $html = <<<EOD
<img style='display:none;' src='$base_href/ext/tagger/onload.gif' onload='setTagIndicators();'/>
<span style="font-size:.7em;">Collapse this block to hide Tagger.</span> <span style="font-size:.7em;">Collapse this block to hide Tagger.</span>
<br/> <br/>
<a onclick="taggerResetPos();" style="cursor:pointer;">Default Location</a> <a onclick="taggerResetPos();" style="cursor:pointer;">Default Location</a>
<hr/> <hr/>
<a href='$url_more'>About Tagger</a> <a href='$url_more'>About Tagger</a>
<div id="tagger_window" style="bottom:25px;right:25px;" onmousedown="setTagIndicators();"> <div id="tagger_window" style="bottom:25px;right:25px;">
<div id="tagger_titlebar" title="Drag to move" onmousedown="dragStart(event,&quot;tagger_window&quot;);"> <div id="tagger_titlebar" title="Drag to move" onmousedown="dragStart(event,&quot;tagger_window&quot;);">
Tagger Tagger
</div> </div>
@ -31,16 +40,16 @@ class taggerTheme extends Themelet {
</div> </div>
</div> </div>
EOD; EOD;
$page->add_block( new Block("Tagger", $page->add_block( new Block("Tagger - Advanced Tagging",
"".$html, "".$html,
"left", "left",
50)); 50));
} }
public function trimTag($s,$len=80) { public function trimTag($s,$len=80,$break=" ") {
if(strlen($s) > $len) { if(strlen($s) > $len) {
$s = substr($s, 0,$len-1); $s = substr($s, 0,$len-1);
$s = substr($s,0, strrpos($s,'_'))."..."; $s = substr($s,0, strrpos($s,$break))."...";
} }
return $s; return $s;
} }
@ -77,8 +86,8 @@ EOD;
</li> </li>
</ul> </ul>
EOD; EOD;
$page->set_title("About Extension: Tagger"); $page->set_title("About / Extension / Tagger - Advanced Tagging");
$page->set_heading("About Extension: Tagger"); $page->set_heading("About / Extension / Tagger - Advanced Tagging");
$page->add_block( new Block("Author", $page->add_block( new Block("Author",
"Artanis (Erik Youngren &lt;artanis.00@gmail.com&gt;)","main",0)); "Artanis (Erik Youngren &lt;artanis.00@gmail.com&gt;)","main",0));
$page->add_block( new Block("Use", $html,"main",1)); $page->add_block( new Block("Use", $html,"main",1));