1

I am using the photo tagging script found here

http://www.bryantan.info/jquery/5 Very simple code.

It works great, but is always in tag enabled mode. How can I implement a button "Tag photo", which when clicked will enable tagging, and otherwise, the tagging is disabled. Also, When done tagging, this button can be clicked to turn off tagging.

Like facebook tagging.

aVC
  • 2,254
  • 2
  • 24
  • 46

1 Answers1

0

You need a var that will toggle a Boolean value initially set to false.
Return your image clicks if that value is false :)
here is how to do it:

jsBin demo (with basic button functionality)

var tagEditing = false; // create this line

than add a button somewhere like:

<button id="startTag">Start tagging</button>

than add into this an if statement:

$('#tagit #btnsave').live('click',function(){

  if( !tagEditing ){
       return;
  }

  name = $('#tagname').val();
  counter++;
  $('#taglist ol').append('<li rel="'+counter+'"><a>'+name+'</a> (<a class="remove">Remove</a>)</li>');
  $('#imgtag').append('<div class="tagview" id="view_'+counter+'"></div>');
  $('#view_' + counter).css({top:mouseY,left:mouseX});
  $('#tagit').fadeOut();
  // add backend code here, use mouseX and mouseY for the axis and counter.
  // ............

});

Now you just need to toggle your tagEditing var, button text and image cursor style:

$('#startTag').click(function(){
   tagEditing = !tagEditing;

   $('#imgtag').css({cursor: tagEditing? 'crosshair' : 'default' });
   $(this).text(tagEditing? 'End tagging':'Start tagging');
});

and also on upload :

$('#yourUploadButton').click(function(){

    tagEditing = false;

});

Additionally if var tagEditing == false you'd like to change the image cursor style from crosshair to default (look in the demo to see how)

Community
  • 1
  • 1
Roko C. Buljan
  • 196,159
  • 39
  • 305
  • 313
  • @aVC I know ;) http://jsbin.com/ucacor/2/edit THANKS! added the cursor tricks... take a look – Roko C. Buljan Jan 09 '13 at 01:08
  • 1
    Lol, I was excited to see it work hence my comment. Dint mean to say I doubted your code. :) The cursor part I did manage to add, but appreciate your follow up very much. – aVC Jan 09 '13 at 01:12
  • @aVC if you managed to make it work before my edit that just means you're learning very fast! thumbs up for your work and happy coding! – Roko C. Buljan Jan 09 '13 at 01:14
  • Thanks very much. Appreciate your kind words. I am learning :) – aVC Jan 09 '13 at 02:40
  • I was very impressed (dont know why) when you posted the answer. My respect for you has gone up, after I accidentally stumbled on your about me section (especially "My thoughts on IE. :) ). Cheers. I am book marking your website, just in case If I need to hire you. :) – aVC Jan 09 '13 at 18:01
  • @aVC ohh that's so nice to hear, thank you so much! I'm just having fun to do my best with answers, specially for those focused on User Interface, so, actually the pleasure was mine :) – Roko C. Buljan Jan 09 '13 at 22:51