Skip to content

Instantly share code, notes, and snippets.

@jonDowdle
Created July 20, 2010 20:26
Show Gist options
  • Select an option

  • Save jonDowdle/483517 to your computer and use it in GitHub Desktop.

Select an option

Save jonDowdle/483517 to your computer and use it in GitHub Desktop.
// 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