Tagger v2
git-svn-id: file:///home/shish/svn/shimmie2/trunk@571 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
		
							parent
							
								
									1cacc2d247
								
							
						
					
					
						commit
						3aaf13887b
					
				| @ -19,7 +19,7 @@ class Tagger extends Extension { | |||||||
| 				$this->theme->build_tagger($page,$event); | 				$this->theme->build_tagger($page,$event); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| } if(isset($_GET['debug'])) add_event_listener( new tagger()); | } add_event_listener( new tagger()); | ||||||
| 
 | 
 | ||||||
| // Tagger AJAX back-end
 | // Tagger AJAX back-end
 | ||||||
| class TaggerXML extends Extension { | class TaggerXML extends Extension { | ||||||
|  | |||||||
| @ -8,59 +8,62 @@ | |||||||
|  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||||||
| function Tagger() { | function Tagger() { | ||||||
| // components
 | // components
 | ||||||
| 	this.t_parent  = null; | 	this.t_parent         = null; | ||||||
| 	this.t_title   = null; | 	this.t_title          = null; | ||||||
| 	this.t_toolbar = null; | 	this.t_toolbar        = null; | ||||||
| 	this.t_menu    = null; | 	this.t_menu           = null; | ||||||
| 	this.t_body    = null; | 	this.t_body           = null; | ||||||
| 	this.t_tags    = null; | 	this.t_tags           = null; | ||||||
| 	this.t_form    = null; | 	this.t_form           = null; | ||||||
| 	this.t_status  = null; | 	this.t_status         = null; | ||||||
| // data
 | // data
 | ||||||
| 	this.searchTags  = null; | 	this.searchTags       = null; | ||||||
| 	this.appliedTags = null; | 	this.appliedTags      = null; | ||||||
| // methods
 | // methods
 | ||||||
| 	this.initialize     = initialize; | 	this.initialize       = initialize; | ||||||
| 	this.submit         = submit; | 	this.submit           = submit; | ||||||
| 	this.getPosition    = function () { return findPos(this.t_parent); }; | 	this.getPosition      = function () { return findPos(this.t_parent); }; | ||||||
| 	this.setPosition    = setPosition; | 	this.setPosition      = setPosition; | ||||||
| 	this.tagSearch      = tagSearch; | 	this.setSavedPosition = setSavedPosition; | ||||||
| 	this.searchRequest  = searchRequest; | 	this.getSavedPosition = getSavedPosition; | ||||||
| 	this.searchReceive  = searchReceive; | 	this.tagSearch        = tagSearch; | ||||||
| 	this.tagListReceive = tagListReceive; | 	this.searchRequest    = searchRequest; | ||||||
| 	this.tagPublish     = tagPublish; | 	this.searchReceive    = searchReceive; | ||||||
| 	this.prepTags       = prepTags; | 	this.tagListReceive   = tagListReceive; | ||||||
| 	this.createTag      = createTag; | 	this.tagPublish       = tagPublish; | ||||||
| 	this.buildPages     = buildPages; | 	this.prepTags         = prepTags; | ||||||
| 	this.tagsToString   = tagsToString; | 	this.createTag        = createTag; | ||||||
| 	this.toggleTag      = toggleTag; | 	this.buildPages       = buildPages; | ||||||
| 	this.setAlert       = setAlert; | 	this.tagsToString     = tagsToString; | ||||||
|  | 	this.toggleTag        = toggleTag; | ||||||
|  | 	this.setAlert         = setAlert; | ||||||
| 
 | 
 | ||||||
| 	 | 	 | ||||||
| // definitions
 | // definitions
 | ||||||
| 	function initialize () { | 	function initialize () { | ||||||
| 	// components
 | 	// components
 | ||||||
| 		this.t_parent  = document.getElementById("tagger_parent"); | 		this.t_parent  = byId("tagger_parent"); | ||||||
| 		this.t_title   = document.getElementById("tagger_titlebar"); | 		this.t_title   = byId("tagger_titlebar"); | ||||||
| 		this.t_toolbar = document.getElementById("tagger_toolbar"); | 		this.t_toolbar = byId("tagger_toolbar"); | ||||||
| 		this.t_menu    = document.getElementById("tagger_p-menu"); | 		this.t_menu    = byId("tagger_p-menu"); | ||||||
| 		this.t_body    = document.getElementById("tagger_body"); | 		this.t_body    = byId("tagger_body"); | ||||||
| 		this.t_tags    = document.getElementById("tagger_tags"); | 		this.t_tags    = byId("tagger_tags"); | ||||||
| 		this.t_form    = this.t_tags.parentNode; | 		this.t_form    = this.t_tags.parentNode; | ||||||
| 		this.t_status  = document.getElementById("tagger_statusbar"); | 		this.t_status  = byId("tagger_statusbar"); | ||||||
| 	//pages
 | 	//pages
 | ||||||
| 		//this.buildPages();
 | 		//this.buildPages();
 | ||||||
| 	// initial data
 | 	// initial data
 | ||||||
| 		ajaxXML(query+"/"+image_id,tagListReceive); | 		ajaxXML(query+"/"+image_id,tagListReceive); | ||||||
| 
 |  | ||||||
| 	// reveal
 | 	// reveal
 | ||||||
| 		this.t_parent.style.display = ""; | 		this.t_parent.style.display = ""; | ||||||
| 	// dragging
 | 	// dragging
 | ||||||
| 		DragHandler.attach(this.t_title); | 		DragHandler.attach(this.t_title); | ||||||
| 		// set position
 | 	// set position
 | ||||||
| 		// TODO: Apply cookie-based position saving
 | 		var pos = ( Tagger.getSavedPosition() || Tagger.getPosition() ); | ||||||
| 		var pos = Tagger.getPosition(); |  | ||||||
| 		setPosition(pos[0],pos[1]); | 		setPosition(pos[0],pos[1]); | ||||||
|  | 	// events
 | ||||||
|  | 		window.onunload = function () {Tagger.setSavedPosition(); }; | ||||||
|  | 		 | ||||||
| 	} | 	} | ||||||
| 	function submit() { | 	function submit() { | ||||||
| 		this.t_tags.value = Tagger.tagsToString(Tagger.appliedTags); | 		this.t_tags.value = Tagger.tagsToString(Tagger.appliedTags); | ||||||
| @ -84,6 +87,22 @@ function Tagger() { | |||||||
| 			bottom=""; | 			bottom=""; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	function setSavedPosition(x,y) { | ||||||
|  | 		if (!x || !y) { | ||||||
|  | 			var p = Tagger.getPosition(); | ||||||
|  | 			x = p[0]; | ||||||
|  | 			y = p[1]; | ||||||
|  | 		} | ||||||
|  | 		setCookie("shimmie_tagger-position",x+" "+y,14); | ||||||
|  | 	} | ||||||
|  | 	function getSavedPosition() { | ||||||
|  | 		var p = getCookie("shimmie_tagger-position"); | ||||||
|  | 		if(p) { | ||||||
|  | 			return p.split(" "); | ||||||
|  | 		} else { | ||||||
|  | 			return false; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| 	function tagSearch(s,ms) { | 	function tagSearch(s,ms) { | ||||||
| 		clearTimeout(tagger_filter_timer); | 		clearTimeout(tagger_filter_timer); | ||||||
| 		tagger_filter_timer = setTimeout("Tagger.searchRequest('"+s+"')",ms); | 		tagger_filter_timer = setTimeout("Tagger.searchRequest('"+s+"')",ms); | ||||||
| @ -130,10 +149,10 @@ function Tagger() { | |||||||
| 	} | 	} | ||||||
| 	function searchReceive(xml) { | 	function searchReceive(xml) { | ||||||
| 		Tagger.searchTags = document.importNode(xml.getElementsByTagName("list")[0],true); | 		Tagger.searchTags = document.importNode(xml.getElementsByTagName("list")[0],true); | ||||||
| 		tagPublish(Tagger.searchTags,document.getElementById("tagger_p-search")); | 		tagPublish(Tagger.searchTags,byId("tagger_p-search")); | ||||||
| 		 | 		 | ||||||
| 		if(Tagger.searchTags.getAttribute("max")) { | 		if(Tagger.searchTags.getAttribute("max")) { | ||||||
| 			Tagger.setAlert("maxout","Limited to "+Tagger.searchTags.getAttribute("rows")+" of "+Tagger.searchTags.getAttribute("max")+" tags"); | 			Tagger.setAlert("maxout","Showing "+Tagger.searchTags.getAttribute("rows")+" of "+Tagger.searchTags.getAttribute("max")+" tags"); | ||||||
| 		} else { | 		} else { | ||||||
| 			Tagger.setAlert("maxout",false); | 			Tagger.setAlert("maxout",false); | ||||||
| 		} | 		} | ||||||
| @ -141,7 +160,7 @@ function Tagger() { | |||||||
| 	 | 	 | ||||||
| 	function tagListReceive(xml) { | 	function tagListReceive(xml) { | ||||||
| 		Tagger.appliedTags = document.importNode(xml.getElementsByTagName("list")[0],true); | 		Tagger.appliedTags = document.importNode(xml.getElementsByTagName("list")[0],true); | ||||||
| 		tagPublish(Tagger.appliedTags,document.getElementById("tagger_p-applied")); | 		tagPublish(Tagger.appliedTags,byId("tagger_p-applied")); | ||||||
| 	} | 	} | ||||||
| 	function tagPublish(tag_list,page) { | 	function tagPublish(tag_list,page) { | ||||||
| 		page.innerHTML = ""; | 		page.innerHTML = ""; | ||||||
| @ -153,8 +172,8 @@ function Tagger() { | |||||||
| 		 | 		 | ||||||
| 		for(var i=0; i<len;i++) { | 		for(var i=0; i<len;i++) { | ||||||
| 			var tag = tag_list.childNodes[i]; | 			var tag = tag_list.childNodes[i]; | ||||||
| 			tag.onclick = function() { toggleTag(this); document.getElementById("tagger_filter").select(); }; | 			tag.onclick = function() { toggleTag(this); byId("tagger_filter").select(); }; | ||||||
| 			tag.style.display="block"; | 			//tag.style.display="block";
 | ||||||
| 			tag.setAttribute("title",tag.getAttribute("count")+" uses"); | 			tag.setAttribute("title",tag.getAttribute("count")+" uses"); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| @ -163,13 +182,15 @@ function Tagger() { | |||||||
| 			var tag = document.createElement("tag"); | 			var tag = document.createElement("tag"); | ||||||
| 			tag.setAttribute("count","0"); | 			tag.setAttribute("count","0"); | ||||||
| 			tag.setAttribute("id","newTag_"+tag_name); | 			tag.setAttribute("id","newTag_"+tag_name); | ||||||
|  | 			tag.setAttribute("count",1); | ||||||
|  | 			tag.setAttribute("title","New"); | ||||||
| 			tag.onclick = function() { toggleTag(this); }; | 			tag.onclick = function() { toggleTag(this); }; | ||||||
| 			tag.appendChild(document.createTextNode(tag_name)); | 			tag.appendChild(document.createTextNode(tag_name)); | ||||||
| 			Tagger.appliedTags.appendChild(tag); | 			Tagger.appliedTags.appendChild(tag); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	function buildPages () { | 	function buildPages () { | ||||||
| 		var pages = getElementsByTagNames("div",document.getElementById("tagger_body")); | 		var pages = getElementsByTagNames("div",byId("tagger_body")); | ||||||
| 		var len = pages.length; | 		var len = pages.length; | ||||||
| 		for(var i=0; i<len; i++) { | 		for(var i=0; i<len; i++) { | ||||||
| 			this.t_menu.innerHTML += "<li onclick='Tagger.togglePages("+ | 			this.t_menu.innerHTML += "<li onclick='Tagger.togglePages("+ | ||||||
| @ -193,7 +214,7 @@ function Tagger() { | |||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	function setAlert(type,arg) { | 	function setAlert(type,arg) { | ||||||
| 		var alert = document.getElementById("tagger_alert_"+type); | 		var alert = byId("tagger_alert_"+type); | ||||||
| 		if (alert) { | 		if (alert) { | ||||||
| 			if (arg==false) { | 			if (arg==false) { | ||||||
| 				//remove existing
 | 				//remove existing
 | ||||||
| @ -228,7 +249,7 @@ function ajaxXML(url, callback) { | |||||||
|  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||||||
| 
 | 
 | ||||||
| // Quirksmode
 | // Quirksmode
 | ||||||
| // http://www.quirksmode.org/dom/getElementsByTagNames.htmlgetElementdocument.getElementById
 | // http://www.quirksmode.org/dom/getElementsByTagNames.htmlgetElementbyId
 | ||||||
| function getElementsByTagNames(list,obj) { | function getElementsByTagNames(list,obj) { | ||||||
| 	if (!obj) var obj = document; | 	if (!obj) var obj = document; | ||||||
| 	var tagNames = list.split(','); | 	var tagNames = list.split(','); | ||||||
|  | |||||||
| @ -4,13 +4,10 @@ | |||||||
|  * Do not remove this notice.                                                * |  * Do not remove this notice.                                                * | ||||||
|  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||||||
| 
 | 
 | ||||||
| #Tagger { |  | ||||||
| 	text-align:left; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| #tagger_parent { | #tagger_parent { | ||||||
|  | 	text-align:left; | ||||||
| 	position:fixed; | 	position:fixed; | ||||||
| 	/*width:250px;*/ | 	max-width:300px; | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
| #tagger_parent * { | #tagger_parent * { | ||||||
| @ -28,12 +25,12 @@ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| #tagger_toolbar, #tagger_body { | #tagger_toolbar, #tagger_body { | ||||||
| 	padding:.25em; | 	padding:2px 2px 0 2px; | ||||||
| 	border-style:solid; | 	border-style:solid; | ||||||
| 	border-width: 0px 2px 0px 2px;	 | 	border-width: 0px 2px 0px 2px;	 | ||||||
| } | } | ||||||
| #tagger_body { | #tagger_body { | ||||||
| 	max-height:250px; | 	max-height:175px; | ||||||
| 	overflow:auto; | 	overflow:auto; | ||||||
| 	overflow-x:hidden; | 	overflow-x:hidden; | ||||||
| 	overflow-y:auto; | 	overflow-y:auto; | ||||||
| @ -43,46 +40,69 @@ | |||||||
| 	background-color:#ddd; | 	background-color:#ddd; | ||||||
| 	border:2px solid; | 	border:2px solid; | ||||||
| 	font-weight: bold; | 	font-weight: bold; | ||||||
|  | 	min-height:16px; | ||||||
| 	-moz-border-radius:0 0 5px 5px; | 	-moz-border-radius:0 0 5px 5px; | ||||||
| 	padding:.25em; | 	padding:.25em; | ||||||
| } #tagger_statusbar * { background-color:#ddd; } | } #tagger_statusbar * { background-color:#ddd; } | ||||||
| 
 | 
 | ||||||
| #tagger_body div { | #tagger_body div { | ||||||
| 	padding-bottom:.125em; | 	padding-top:2px; | ||||||
| 	margin-bottom:.125em; | 	margin-top:2px; | ||||||
| 	border-top:1px solid; | 	border-top:1px solid;	 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Tagger Styling | /* Tagger Styling | ||||||
|  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||||||
| #Tagger form { | #tagger_parent form { | ||||||
| 	display:inline; | 	display:inline; | ||||||
| } | } | ||||||
| #Tagger input { | #tagger_parent input { | ||||||
| 	width:auto; | 	width:auto; | ||||||
| } | } | ||||||
| #Tagger input[type=text] { | #tagger_parent input[type=text] { | ||||||
| 	background-color:white; | 	background-color:white; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /* Custom Element Base Styles | /* Custom Element Base Styles | ||||||
|  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||||||
| 
 | 
 | ||||||
| list { | #tagger_parent list { | ||||||
| 	display:inherit; | 	display: block; | ||||||
| } | } | ||||||
| tag { | #tagger_parent tag { | ||||||
| 	font-size:1.25em; | 	font-size:1.25em;	 | ||||||
| 	display:block; | 	display:block; | ||||||
| } | } | ||||||
| tag:hover { | 
 | ||||||
|  | #tagger_parent list[id=image] tag:before { | ||||||
|  | 	font-family: monospace; | ||||||
|  | 	content:"[ ]"; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #tagger_parent list[id=search] tag:before { | ||||||
|  | 	font-family: monospace; | ||||||
|  | 	content:"[ ]"; | ||||||
|  | } | ||||||
|  | /* Hovering */ | ||||||
|  | #tagger_parent tag:hover { | ||||||
| 	cursor:pointer; | 	cursor:pointer; | ||||||
| 	font-weight: bold; |  | ||||||
| 	background-color:#ddd; | 	background-color:#ddd; | ||||||
| } | } | ||||||
| list[id=image] tag:hover { |  | ||||||
| 
 | 
 | ||||||
|  | #tagger_parent list[id=image] tag:hover { | ||||||
|  | 	background-color:#faa; | ||||||
| } | } | ||||||
| list[id=search] tag:hover { |  | ||||||
| 
 | 
 | ||||||
|  | #tagger_parent list[id=search] tag:hover { | ||||||
|  | 	background-color:#afa; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #tagger_parent list[id=image] tag:hover:before { | ||||||
|  | 	font-family: monospace; | ||||||
|  | 	content:"[\00d7]"; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | #tagger_parent list[id=search] tag:hover:before { | ||||||
|  | 	font-family: monospace; | ||||||
|  | 	content:"[+]"; | ||||||
| } | } | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ class taggerTheme extends Themelet { | |||||||
| 		 | 		 | ||||||
| 		// Tagger block
 | 		// Tagger block
 | ||||||
| 		$page->add_block( new Block( | 		$page->add_block( new Block( | ||||||
| 			"Tagger", | 			null, | ||||||
| 			$this->html($event->get_image()), | 			$this->html($event->get_image()), | ||||||
| 			"main")); | 			"main")); | ||||||
| 	} | 	} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user