Advertisement
Guest User

Snote Rewrite in Jquery

a guest
Apr 2nd, 2015
496
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Replacement for snote_init()
  2. $(window).load(function () {
  3.     $('.snote').toggleClass("snote snote_tip").each(function(index) {
  4.         $(this).before('<span class="snote_refnum">[' + $(this).attr('title') + ']</span>');
  5.     });
  6. });
  7.  
  8.  
  9. // Replacement for snote_hide and snote_show
  10. $(document).on('click', function(event) {
  11.  
  12.     // Handle clicks on snote_refnum's
  13.     if (event.target.className == 'snote_refnum') {
  14.  
  15.         // Get the snote_tip adjacent to the snote_refnum
  16.         var thisSnoteTip = $(event.target).nextAll('.snote_tip').eq(0);
  17.  
  18.         // Toggle the visibility state of the snote_tip
  19.         if (thisSnoteTip.css("visibility") == 'hidden') {
  20.             thisSnoteTip.css("visibility","visible");  
  21.         }
  22.         else {
  23.             thisSnoteTip.css("visibility","hidden");
  24.         }    
  25.  
  26.     // If the click wasn't on a number, determine whether the click was on an element (such as a link) inside the tip
  27.     // Trigger if we click outside the tip, or on the tip itself, but not on items inside the tip
  28.     } else if (event.target.className == 'snote_tip' || !$(event.target).closest('.snote_tip').length) {
  29.         // Hide all tooltips
  30.         $('.snote_tip').css("visibility","hidden");
  31.     }
  32.  
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement