Created
July 20, 2010 20:26
-
-
Save jonDowdle/483517 to your computer and use it in GitHub Desktop.
Code used in screencast http://www.youtube.com/watch?v=3_1hfIi3p6E
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Make all elements with the class 'photo' into a taggable object | |
| $('.photo').taggable({ | |
| tags: '#tags .tag.active', | |
| tagged: onTag , | |
| untagged: onUntag | |
| }); | |
| /** | |
| * Handler for the 'tag' event. When this fires, | |
| * this handler will send the tag data to | |
| * the server along with the id of the image | |
| */ | |
| function onTag(element, tag){ | |
| // If the tag doesn't 'already exists here... | |
| if( $(element).siblings('[rel='+tag+']').length == 0 ){ | |
| /* Graphically let user know tag was added */ | |
| $(element).after('<div class="tag active" rel="'+ tag +'">' + | |
| tag + '<div class="close control" /></div>'); | |
| // Send to server | |
| $.post( | |
| remoteURL, | |
| { 'action':'tag', 'image': $(element).attr('rel'), 'tag':tag }, | |
| function(results, txtStatus){ | |
| console.log(results,txtStatus); | |
| }) ; | |
| }else{ | |
| // Give the user a hint | |
| $(element).siblings('[rel='+tag+']').effect('bounce'); | |
| } | |
| }; | |
| /** | |
| * Handler for the 'untag' event. | |
| */ | |
| function onUntag(element, tag){ | |
| $.post( | |
| remoteURL, | |
| { 'action':'untag', 'image': $(element).attr('rel'), 'tag':tag } | |
| ); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment