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
// Tagger - Advanced Tagging
// Author: Artanis (Erik Youngren <artanis.00@gmail.com>)
// Do not remove this notice.
class tagger extends Extension {
var $theme;
public function receive_event ($event) {
if(is_null($this->theme))
$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")) {
//show tagger box
@ -13,24 +29,32 @@ class tagger extends Extension {
global $config;
$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("
SELECT tag
FROM `tags`
WHERE count > 1 AND substring(tag,1,1) != '.'
ORDER BY tag");
WHERE count >= ? {$hidden}
ORDER BY tag",array($tags_min));
$this->theme->build($page, $tags);
}
if(is_a($event,"PageRequestEvent") && $event->page_name == "about"
&& $event->get_arg(0) == "tagger")
{
global $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());

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
// Original Code Author: Artanis (Erik Youngren <artanis.00@gmail.com>)
// Tagger - Advanced Tagging
// Author: Artanis (Erik Youngren <artanis.00@gmail.com>)
// Do not remove this notice.
// All other code copyright by their authors, see comments for details.
// In case the drag point goes off screen.
function taggerResetPos() {
// In case the drag point goes off screen.
tagger = byId("tagger_window");
// reset default position (bottom right.)
@ -36,26 +38,16 @@ function tagExists(tag) {
return false;
}
function toggleTag(tag) {
var tags = byId("tags");
var tag_link = byId("tagger_tag_"+tag);
function toggleTag(tag,rTagme) {
if (!tagExists(tag)) {
// append tag to tag box.
tags.value = tags.value +" "+ tag;
// set indicator
if(tag_link) {
tag_link.style.fontWeight = "bold";
addTag(tag);
if(rTagme && tag != "tagme") {
remTag("tagme");
}
} else {
// remove 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 = "";
}
remTag(tag);
}
obj = byId("tagger_custTag");
if(obj.value) {
@ -68,12 +60,39 @@ function addTagById(id) {
toggleTag(tag.value);
}
function setTagIndicators() {
tagger = byId("tagger_window");
// core.js took window.onload, so emulate it by using onclick and then
// removing the event.
tagger.setAttribute("onmousedown","");
function addTag (tag) {
var tags = byId("tags");
var tag_link = byId("tagger_tag_"+tag);
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();
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 {
@ -29,7 +32,7 @@
}
#tagger_body a {
font-size:1.5em;
font-size:1.25em;
}
#Tagger li {

View file

@ -1,25 +1,34 @@
<?php
// Tagger - Advanced Tagging
// Author: Artanis (Erik Youngren <artanis.00@gmail.com>)
// Do not remove this notice.
class taggerTheme extends Themelet {
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 = "";
foreach ($tags as $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."'>"."
<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>".
"</div>";
}
$url_more = make_link("about/tagger");
$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>
<br/>
<a onclick="taggerResetPos();" style="cursor:pointer;">Default Location</a>
<hr/>
<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;);">
Tagger
</div>
@ -31,16 +40,16 @@ class taggerTheme extends Themelet {
</div>
</div>
EOD;
$page->add_block( new Block("Tagger",
$page->add_block( new Block("Tagger - Advanced Tagging",
"".$html,
"left",
50));
}
public function trimTag($s,$len=80) {
public function trimTag($s,$len=80,$break=" ") {
if(strlen($s) > $len) {
$s = substr($s, 0,$len-1);
$s = substr($s,0, strrpos($s,'_'))."...";
$s = substr($s,0, strrpos($s,$break))."...";
}
return $s;
}
@ -77,8 +86,8 @@ EOD;
</li>
</ul>
EOD;
$page->set_title("About Extension: Tagger");
$page->set_heading("About Extension: Tagger");
$page->set_title("About / Extension / Tagger - Advanced Tagging");
$page->set_heading("About / Extension / Tagger - Advanced Tagging");
$page->add_block( new Block("Author",
"Artanis (Erik Youngren &lt;artanis.00@gmail.com&gt;)","main",0));
$page->add_block( new Block("Use", $html,"main",1));