basic autocomplete support for metatags
This commit is contained in:
		
							parent
							
								
									03240220d4
								
							
						
					
					
						commit
						f973fcc9fa
					
				| @ -1,16 +1,36 @@ | |||||||
| $(function(){ | $(function(){ | ||||||
|  | 	var metatags = ['order:id', 'order:width', 'order:height', 'order:filesize', 'order:filename']; | ||||||
|  | 
 | ||||||
| 	$('[name=search]').tagit({ | 	$('[name=search]').tagit({ | ||||||
| 		singleFieldDelimiter: ' ', | 		singleFieldDelimiter: ' ', | ||||||
| 		beforeTagAdded: function(event, ui) { | 		beforeTagAdded: function(event, ui) { | ||||||
| 			// give special class to negative tags
 | 			if(metatags.indexOf(ui.tagLabel) !== -1) { | ||||||
| 			if(ui.tagLabel[0] === '-') { | 				ui.tag.addClass('tag-metatag'); | ||||||
| 				ui.tag.addClass('tag-negative'); | 			} else { | ||||||
| 			}else{ | 				console.log(ui.tagLabel); | ||||||
| 				ui.tag.addClass('tag-positive'); | 				// give special class to negative tags
 | ||||||
|  | 				if(ui.tagLabel[0] === '-') { | ||||||
|  | 					ui.tag.addClass('tag-negative'); | ||||||
|  | 				}else{ | ||||||
|  | 					ui.tag.addClass('tag-positive'); | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 		}, | 		}, | ||||||
| 		autocomplete : ({ | 		autocomplete : ({ | ||||||
| 			source: function (request, response) { | 			source: function (request, response) { | ||||||
|  | 				var ac_metatags = $.map( | ||||||
|  | 					$.grep(metatags, function(s) { | ||||||
|  | 						// Only show metatags for strings longer than one character
 | ||||||
|  | 						return (request.term.length > 1 && s.indexOf(request.term) === 0); | ||||||
|  | 					}), | ||||||
|  | 					function(item) { | ||||||
|  | 						return { | ||||||
|  | 							label : item + ' [metatag]', | ||||||
|  | 							value : item | ||||||
|  | 						}; | ||||||
|  | 					} | ||||||
|  | 				); | ||||||
|  | 
 | ||||||
| 				var isNegative = (request.term[0] === '-'); | 				var isNegative = (request.term[0] === '-'); | ||||||
| 				$.ajax({ | 				$.ajax({ | ||||||
| 					url: base_href + '/api/internal/autocomplete', | 					url: base_href + '/api/internal/autocomplete', | ||||||
| @ -18,13 +38,17 @@ $(function(){ | |||||||
| 					dataType : 'json', | 					dataType : 'json', | ||||||
| 					type : 'GET', | 					type : 'GET', | ||||||
| 					success : function (data) { | 					success : function (data) { | ||||||
| 						response($.map(data, function (count, item) { | 						response( | ||||||
| 							item = (isNegative ? '-'+item : item); | 							$.merge(ac_metatags, | ||||||
| 							return { | 								$.map(data, function (count, item) { | ||||||
| 								label : item + ' ('+count+')', | 									item = (isNegative ? '-'+item : item); | ||||||
| 								value : item | 									return { | ||||||
| 							}; | 										label : item + ' ('+count+')', | ||||||
| 						})); | 										value : item | ||||||
|  | 									}; | ||||||
|  | 								}) | ||||||
|  | 							) | ||||||
|  | 						); | ||||||
| 					}, | 					}, | ||||||
| 					error : function (request, status, error) { | 					error : function (request, status, error) { | ||||||
| 						alert(error); | 						alert(error); | ||||||
|  | |||||||
| @ -6,3 +6,4 @@ input[name=search] ~ input[type=submit] { display: inline-block !important; } | |||||||
| 
 | 
 | ||||||
| .tag-negative { background: #ff8080 !important; } | .tag-negative { background: #ff8080 !important; } | ||||||
| .tag-positive { background: #40bf40 !important; } | .tag-positive { background: #40bf40 !important; } | ||||||
|  | .tag-metatag   { background: #eaa338 !important; } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user