- Kollermedia.at - http://www.kollermedia.at -
jQuery EasyTags Plugin
Posted By Jürgen Koller On 12. März 2010 @ 19:13 In Scripts etc. | 7 Comments
Das jQuery EasyTags Plugin ist ein kleines, nützliches Script, mit dem man schnell und einfach Tags eingeben & sortieren kann. Das Plugin kommt mit Livesearch und Drag&Drop Funktionalität!
EasyTags 1.0 [2] (5,0 KiB, 435 hits)
Im HTML muss lediglich eine Zeile definiert werden:
<div id="my_tags"></div>
Im Javascript Teil muss zuerst das easytags plugin aufgerufen werden, danach (optional) das drag&drop plugin.
<script type="text/javascript">
$().ready(function() {
$("#my_tags").easytags(); //easytags plugin
$("#my_tags #tags ul").dragsort({dragEnd: function() {$.easytags.reorder_tags();}}); //for drag&drop support
});
</script>
Beim Plugin Aufruf können noch folgende Optionen definiert werden:
| Option Name | Default | Description |
|---|---|---|
| starttags | "" | Tags visible on start: tag1,tag2,tag3 |
| movetext | "move this tag" | Title Text visible on drag |
| removetext | "remove this tag" | Title Text for the tag-close link |
| tagsearchtype | "GET" | Ajax Live Search Type "GET" or "POST" |
| tagsearchpath | "ajax.php" | Path to your livesearch php file |
| fieldname | "all_tags" | Name of the Input Field where all Tag Values are saved |
Example:
$("#my_tags").easytags({starttags:"kollermedia, jquery, tags", fieldname:"all_tags"});
Das Plugin erzeugt folgende HTML Struktur, die dann natürlich via CSS beliebig optisch angepasst werden kann.
<div id="my_tags"> <input style="display: none;" name="all_tags" value="" type="text" id="all_tags" /> <div id="tags"> <ul><li>tag example</li><li>tag example2</li></ul> <input type="text" id="tag_new" /> </div> <div id="tagsearch"> </div> </div>
Wieviele Tags bei der Livesuche ausgegeben werden sollen, kann via PHP bzw. der MySQL Abfrage beliebig angegeben werden. Hier ein Beispielcode für das PHP File:
$searchtag = $_GET["searchtag"]; //Get the search string
//Database Connection
$dbconnect = mysql_connect(localhost,"db_username","db_password") or die ("keine Verbindung möglich. Benutzername oder Passwort sind falsch");
mysql_select_db("db_name") or die ("Die Datenbank existiert nicht.");
//search in Database and output the result
$query = "SELECT tag FROM tablename WHERE tag LIKE '%$searchtag%' LIMIT 10";
$result = mysql_query($query);
while($row = mysql_fetch_object($result))
{
echo " <a href=\"#\">".$row->tag."</a>";
}
EasyTags 1.0 [2] (5,0 KiB, 435 hits)
Article printed from Kollermedia.at: http://www.kollermedia.at
URL to article: http://www.kollermedia.at/archive/2010/03/12/jquery-easytags-plugin/
URLs in this post:
[1] Check out the live demo: http://www.kollermedia.at/wp-content/themes/kollermedia/specials/easyTags/demo.html
[2] EasyTags 1.0: http://www.kollermedia.at/download/11/
Click here to print.
Copyright © Kollermedia.at. All rights reserved.