HashLight

jQuery hashtag highlighter

Download Github

Basic Example

Try typing #hashlight

            
	        <textarea id="basic-example"></textarea>

	        <script type="text/javascript">
		        $(document).ready(function(f){
		         	$("#basic-example").hashlight();
		        });
	        </script>
            
			

Activation Symbol

you can change the activation symbol with anything you like. try typing @hashlight

            
	        <textarea id="basic-example-2"></textarea>

	        <script type="text/javascript">
		        $(document).ready(function(f){
		         	$("#basic-example-2").hashlight({tag : '@'});
		        });
	        </script>
            
			

Auto Complete

You can add autocomplete to your tag. Try typing @hashlight.Furthermore , you can also implement ajax as the data source.

            
	        <textarea id="basic-example-3"></textarea>

	        <script type="text/javascript">
		        $(document).ready(function(f){
		         	$("#basic-example-3").hashlight({tag : '@',dataProvider : function(data){
		         	//data contain currrent tag
		         	//Implement ajax here
		         	//Implement filter here
		         	//Return type must be array
	            		return data;
	            	}});
		        });
	        </script>
            
			

Custom Element

You can costumize the markerElement (The hidden div that cover the entire textarea) tagElement (the tag marker) and the autocompleteElement. try typing #green / #blue / #red

            
	        <textarea id="basic-example-4"></textarea>

	        <script type="text/javascript">
			function validTextColour(stringToTest) {
			    if (stringToTest === "") { return false; }
			    if (stringToTest === "inherit") { return false; }
			    if (stringToTest === "transparent") { return false; }

			    var image = document.createElement("img");
			    image.style.color = "rgb(0, 0, 0)";
			    image.style.color = stringToTest;
			    if (image.style.color !== "rgb(0, 0, 0)") { return true; }
			    image.style.color = "rgb(255, 255, 255)";
			    return image.style.color !== "rgb(255, 255, 255)";
			}

	            $(document).ready(function(f){
	            	$("#basic-example-4").hashlight({
	            		tagElement : function(tag){
	            var tagcolor = tag.replace("#","");
	            if(!validTextColour(tagcolor))tagcolor = 'grey';
				return "" + tag + "";	
	            	}
	            });

	            });	        </script>
            
			

Element default implementation

            
			pattern: function (tag){
				return new RegExp("(^"+tag+"[A-Za-z0-9-_]+| "+tag+"[A-Za-z0-9-_]+)" ,"g");
				
			}

			markerElement: function (id) {
				return '<div class="hashlight-marker" id="' + id + '" ></div>';
			}

			tagElement: function (tag) {
				urltag = tag.replace(options.tag,"");
				return "<a class='hashlight-tag' href='"+urltag+"'><span  style='color: white;border-radius: 3px;background-color : #3498db;'>" + tag + "</span></a>";
			}

			autoCompleteElement: function (autocompletearray) {
				var autocomplete = "<ul class='hashlight-autocomplete'>";
				for (i in autocompletearray) {
					if (i == 0) {
						autocomplete += "<li data-value='" + autocompletearray[i] + "' class='hashlight-autocomplete-active'>" + autocompletearray[i] + "</li>";
					} else {
						autocomplete += "<data-value='" + autocompletearray[i] + "'>" + autocompletearray[i] + "</li>";
					}
				}

				autocomplete += "</ul>";
				return autocomplete;

			}
			
			

Get Tag

Try typing #hashlight , and then click get tag button

            
	        <textarea id="basic-example"></textarea>
	        <script type="text/javascript">
		        $(document).ready(function(f){
	            	$("#getTag").on("click",function(){
	            		alert($("#basic-example-6").hashlight.getTagArray());
	            	});
		        });
	        </script>
            
			
            	
jQuery Hashlight v1.0.0
 
Copyright (c) 2014 Gilang Charismadiptya Prashasta

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.