[Tagger] Update

git-svn-id: file:///home/shish/svn/shimmie2/trunk@492 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
Artanis 2007-09-25 21:28:09 +00:00
parent b9b36f3205
commit de599ea131
4 changed files with 267 additions and 223 deletions

View File

@ -1,26 +1,24 @@
<?php <?php
// author: Erik Youngren class tagger extends Extension {
// email: artanis.00@gmail.com var $theme;
class tagger extends Extension {
var $theme; public function receive_event ($event) {
if(is_null($this->theme))
public function receive_event ($event) { $this->theme = get_theme_object("tagger", "taggerTheme");
if(is_null($this->theme)) if(is_a($event,"DisplayingImageEvent")) {
$this->theme = get_theme_object("tagger", "taggerTheme"); //show tagger box
if(is_a($event,"DisplayingImageEvent")) { global $database;
//show tagger box global $page;
global $database;
global $page; $tags = $database->Execute("
SELECT tag
$tags = $database->Execute(" FROM `tags`
SELECT tag WHERE count > 1 AND substring(tag,1,1) != '.'
FROM `tags` ORDER BY tag");
WHERE count > 1
ORDER BY tag"); $this->theme->build($page, $tags);
}
$this->theme->build($page, $tags); }
} }
} add_event_listener( new tagger());
}
add_event_listener(new tagger());
?> ?>

View File

@ -1,184 +1,189 @@
function byId(id) { function byId(id) {
return document.getElementById(id); return document.getElementById(id);
} }
function tagExists(tag) { function tagExists(tag) {
var tags = byId("tags"); var tags = byId("tags");
tags_list = tags.value; tags_list = tags.value;
tags_array = tags_list.split(" "); tags_array = tags_list.split(" ");
tags_list = ""; tags_list = "";
for (x in tags_array) { for (x in tags_array) {
if(tags_array[x] == tag) { if(tags_array[x] == tag) {
return true; return true;
} }
} }
return false; return false;
} }
function addTag(tag) { function addTag(tag) {
if (!tagExists(tag)) { if (!tagExists(tag)) {
// append tag to tag box. // append tag to tag box.
var tags = byId("tags"); var tags = byId("tags");
tags.value = tags.value +" "+ tag; tags.value = tags.value +" "+ tag;
} }
} }
// Drag Code // function addTagById(id) {
//***************************************************************************** tag = byId(id);
// Do not remove this notice. addTag(tag.value);
// }
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use. // Drag Code //
//***************************************************************************** //*****************************************************************************
// Do not remove this notice.
// Determine browser and version. //
// Copyright 2001 by Mike Hall.
function Browser() { // See http://www.brainjar.com for terms of use.
//*****************************************************************************
var ua, s, i;
// Determine browser and version.
this.isIE = false;
this.isNS = false; function Browser() {
this.version = null;
var ua, s, i;
ua = navigator.userAgent;
this.isIE = false;
s = "MSIE"; this.isNS = false;
if ((i = ua.indexOf(s)) >= 0) { this.version = null;
this.isIE = true;
this.version = parseFloat(ua.substr(i + s.length)); ua = navigator.userAgent;
return;
} s = "MSIE";
if ((i = ua.indexOf(s)) >= 0) {
s = "Netscape6/"; this.isIE = true;
if ((i = ua.indexOf(s)) >= 0) { this.version = parseFloat(ua.substr(i + s.length));
this.isNS = true; return;
this.version = parseFloat(ua.substr(i + s.length)); }
return;
} s = "Netscape6/";
if ((i = ua.indexOf(s)) >= 0) {
// Treat any other "Gecko" browser as NS 6.1. this.isNS = true;
this.version = parseFloat(ua.substr(i + s.length));
s = "Gecko"; return;
if ((i = ua.indexOf(s)) >= 0) { }
this.isNS = true;
this.version = 6.1; // Treat any other "Gecko" browser as NS 6.1.
return;
} s = "Gecko";
} if ((i = ua.indexOf(s)) >= 0) {
this.isNS = true;
var browser = new Browser(); this.version = 6.1;
return;
// Global object to hold drag information. }
}
var dragObj = new Object();
dragObj.zIndex = 0; var browser = new Browser();
function dragStart(event, id) { // Global object to hold drag information.
var el; var dragObj = new Object();
var x, y; dragObj.zIndex = 0;
// If an element id was given, find it. Otherwise use the element being function dragStart(event, id) {
// clicked on.
var el;
if (id) var x, y;
dragObj.elNode = document.getElementById(id);
else { // If an element id was given, find it. Otherwise use the element being
if (browser.isIE) // clicked on.
dragObj.elNode = window.event.srcElement;
if (browser.isNS) if (id)
dragObj.elNode = event.target; dragObj.elNode = document.getElementById(id);
else {
// If this is a text node, use its parent element. if (browser.isIE)
dragObj.elNode = window.event.srcElement;
if (dragObj.elNode.nodeType == 3) if (browser.isNS)
dragObj.elNode = dragObj.elNode.parentNode; dragObj.elNode = event.target;
}
// If this is a text node, use its parent element.
// Get cursor position with respect to the page.
if (dragObj.elNode.nodeType == 3)
if (browser.isIE) { dragObj.elNode = dragObj.elNode.parentNode;
x = window.event.clientX + document.documentElement.scrollLeft }
+ document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop // Get cursor position with respect to the page.
+ document.body.scrollTop;
} if (browser.isIE) {
if (browser.isNS) { x = window.event.clientX + document.documentElement.scrollLeft
x = event.clientX + window.scrollX; + document.body.scrollLeft;
y = event.clientY + window.scrollY; y = window.event.clientY + document.documentElement.scrollTop
} + document.body.scrollTop;
}
// Save starting positions of cursor and element. if (browser.isNS) {
x = event.clientX + window.scrollX;
dragObj.cursorStartX = x; y = event.clientY + window.scrollY;
dragObj.cursorStartY = y; }
dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10);
dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10); // Save starting positions of cursor and element.
if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0; dragObj.cursorStartX = x;
if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 0; dragObj.cursorStartY = y;
dragObj.elStartLeft = parseInt(dragObj.elNode.style.left, 10);
// Update element's z-index. dragObj.elStartTop = parseInt(dragObj.elNode.style.top, 10);
dragObj.elNode.style.zIndex = ++dragObj.zIndex; if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
if (isNaN(dragObj.elStartTop)) dragObj.elStartTop = 0;
// Capture mousemove and mouseup events on the page.
// Update element's z-index.
if (browser.isIE) {
document.attachEvent("onmousemove", dragGo); dragObj.elNode.style.zIndex = ++dragObj.zIndex;
document.attachEvent("onmouseup", dragStop);
window.event.cancelBubble = true; // Capture mousemove and mouseup events on the page.
window.event.returnValue = false;
} if (browser.isIE) {
if (browser.isNS) { document.attachEvent("onmousemove", dragGo);
document.addEventListener("mousemove", dragGo, true); document.attachEvent("onmouseup", dragStop);
document.addEventListener("mouseup", dragStop, true); window.event.cancelBubble = true;
event.preventDefault(); window.event.returnValue = false;
} }
} if (browser.isNS) {
document.addEventListener("mousemove", dragGo, true);
function dragGo(event) { document.addEventListener("mouseup", dragStop, true);
event.preventDefault();
var x, y; }
}
// Get cursor position with respect to the page.
function dragGo(event) {
if (browser.isIE) {
x = window.event.clientX + document.documentElement.scrollLeft var x, y;
+ document.body.scrollLeft;
y = window.event.clientY + document.documentElement.scrollTop // Get cursor position with respect to the page.
+ document.body.scrollTop;
} if (browser.isIE) {
if (browser.isNS) { x = window.event.clientX + document.documentElement.scrollLeft
x = event.clientX + window.scrollX; + document.body.scrollLeft;
y = event.clientY + window.scrollY; y = window.event.clientY + document.documentElement.scrollTop
} + document.body.scrollTop;
}
// Move drag element by the same amount the cursor has moved. if (browser.isNS) {
x = event.clientX + window.scrollX;
dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px"; y = event.clientY + window.scrollY;
dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px"; }
if (browser.isIE) { // Move drag element by the same amount the cursor has moved.
window.event.cancelBubble = true;
window.event.returnValue = false; dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
} dragObj.elNode.style.top = (dragObj.elStartTop + y - dragObj.cursorStartY) + "px";
if (browser.isNS)
event.preventDefault(); if (browser.isIE) {
} window.event.cancelBubble = true;
window.event.returnValue = false;
function dragStop(event) { }
if (browser.isNS)
// Stop capturing mousemove and mouseup events. event.preventDefault();
}
if (browser.isIE) {
document.detachEvent("onmousemove", dragGo); function dragStop(event) {
document.detachEvent("onmouseup", dragStop);
} // Stop capturing mousemove and mouseup events.
if (browser.isNS) {
document.removeEventListener("mousemove", dragGo, true); if (browser.isIE) {
document.removeEventListener("mouseup", dragStop, true); document.detachEvent("onmousemove", dragGo);
} document.detachEvent("onmouseup", dragStop);
}
if (browser.isNS) {
document.removeEventListener("mousemove", dragGo, true);
document.removeEventListener("mouseup", dragStop, true);
}
} }

27
contrib/tagger/style.css Normal file
View File

@ -0,0 +1,27 @@
/* Tagger Cascading Style Sheet *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#tagger_window {
position:fixed;
}
#tagger_titlebar {
font-weight:bold;
text-align:center;
position:relative;
top:-0em;
padding:.25em;
border:2px solid;
border-bottom:1px solid;
-moz-border-radius:10px 10px 0px 0px;
background-color:white;
cursor:move;
}
#tagger_body {
overflow:scroll;
padding:1em;
border:2px solid;
border-top:none;
background-color:white;
}

View File

@ -1,16 +1,30 @@
<?php <?php
class taggerTheme extends Themelet { class taggerTheme extends Themelet {
public function build ($page, $tags) { public function build ($page, $tags) {
$html = "<div onmousedown='dragStart(event);' style='position:fixed;top:100px;left:800px;height:400px;overflow:scroll;padding:1em;border:2px solid;background-color:white;'>"; $html = "<div id='tagger_window' style='top:100px;left:800px;'>";
foreach ($tags as $tag) { $html .= "<div id='tagger_titlebar' title='Drag to move' onmousedown='dragStart(event,\"tagger_window\");'>";
$html .= "<input type='button' style='width:10em;' onclick='javascript:addTag(\"".$tag['tag']."\");' value='".$tag['tag']."'></input><br/>"; $html .= "Tagger";
} $html .= "</div>";
$html .= "</div>"; $html .= "<div id='tagger_body' style='height:300px;'>";
$html .= "<input type='text' id='custTag' value=''></input><input type='button' value='Add' onclick='addTagById(\"custTag\")'></input><br/>";
$page->add_block( new Block(null, foreach ($tags as $tag) {
$html, $tag_name = $this->trimTag($tag['tag'],32);
"main", $html .= "<a style='cursor:pointer;' onclick='addTag(\"".$tag['tag']."\");'title='Add \"".$tag['tag']."\" to the tag list'>".$tag_name."</a><br/>";
1000)); }
} $html .= "</div></div>";
}
$page->add_block( new Block("Tagger",
"<span style='font-size:.8em;'>Collapse this block to hide Tagger.</span><br/><br/>Use: Click the links to add the tag to the list, when done, press Set to save the tags.".$html,
"left",
0));
}
public function trimTag($s,$len=80) {
if(strlen($s) > $len) {
$s = substr($s, 0,$len-1);
$s = substr($s,0, strrpos($s,'_'))."...";
}
return $s;
}
}
?> ?>