Advertisement
Guest User

Untitled

a guest
Jul 4th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.37 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <title>snote example</title>
  4. <meta charset="utf-8">
  5.  
  6. <!-- snote v5. Placed in the public domain by Roger Hågensen. -->
  7. <style>
  8. .snote
  9. {
  10.     width: 1em;
  11.     height: 1em;
  12.     background-image: url('http://icons.iconarchive.com/icons/visualpharm/must-have/256/Information-icon.png');
  13.     background-size: auto 1em;
  14.     background-repeat: no-repeat;
  15.     display: none;
  16.     cursor: help
  17. }
  18.  
  19. .snote_tip
  20. {
  21.     display: block;
  22.     visibility: hidden;
  23.     position: absolute;
  24.     width: 16em;
  25.     height: 3em;
  26.     padding: 0.5em;
  27.     overflow: auto;
  28.     background: #cccccc;
  29.     color: #000000;
  30.     border: 0.15em solid #000000;
  31.     border-radius: 0.25em;  
  32.     box-shadow: 0.25em 0.25em 0.25em #7f7f7f;
  33. }
  34.  
  35. </style>
  36.  
  37. <script>
  38.     //call this function once the page has loaded
  39.     window.addEventListener('load', snote_init, false);
  40.  
  41.     //this function will add a span with snote_tip class where a span with the snote class is used, this reduces the html needed and makes writing notes so much simpler/cleaner.
  42.     function snote_init()
  43.     {
  44.         var snote_elements = document.getElementsByClassName('snote');
  45.         for (var i = 0; i < snote_elements.length; i += 1)
  46.         {
  47.             (function(ii)
  48.             {
  49.                 var snote_element = snote_elements[ii];
  50.                 var node = document.createElement('span');
  51.                 node.className = 'snote_tip';
  52.                 var text = snote_element.innerHTML;
  53.                 snote_element.innerHTML = '';
  54.                 node.innerHTML = text;
  55.                 snote_element.appendChild(node);
  56.                 snote_element.style.display = 'inline-block';
  57.                 snote_element.addEventListener ("mouseup", function () {snote_show(snote_element, node)}, false);
  58.             })(i);
  59.         }
  60.     }
  61.  
  62.     function snote_show(snote_element, snote_tip)
  63.     {
  64.         if (snote_tip.style.visibility == 'visible')
  65.         {
  66.             snote_tip.style.visibility = 'hidden';
  67.             return;
  68.         }
  69.         else
  70.         {
  71.             snote_tip.style.visibility = 'visible';
  72.         }
  73.  
  74.         var rect = snote_element.getBoundingClientRect();
  75.         x0 = rect.left + (rect.width * 0.5);
  76.         y0 = rect.top + (rect.height * 0.5);
  77.  
  78.         var rect = snote_tip.getBoundingClientRect();
  79.         snote_tip.style.left = (x0 - (rect.width / 2)) + 'px';
  80.         snote_tip.style.top = (y0 - (rect.height / 2)) + 'px';
  81.  
  82.         snote_tip.style.cursor = 'auto';
  83.  
  84.         var rect = snote_tip.getBoundingClientRect();
  85.         x1 = rect.left;
  86.         y1 = rect.top;
  87.         x2 = window.innerWidth - rect.right
  88.         y2 = window.innerHeight - rect.bottom
  89.         if (x1 < 0)
  90.         {
  91.             snote_tip.style.left = '0px';
  92.         }
  93.         if (y1 < 0)
  94.         {
  95.             snote_tip.style.top = '0px';
  96.         }
  97.         if (x2 < 0)
  98.         {
  99.             snote_tip.style.left = (window.innerWidth-rect.width) + 'px';
  100.         }
  101.         if (y2 < 0)
  102.         {
  103.             snote_tip.style.left = (window.innerHeight-rect.height) + 'px';
  104.         }
  105.  
  106.     };
  107. </script>
  108.  
  109. <body>
  110.  
  111. <p>But the thing is this: I really, REALLY like annotations. I'm talking about the little numbers that pop up in a post <span class="snote">Like this one, for example.<br><br>And it is really long, but that is not really a problem.<br><br>This text could easily just go on and on.</span>. I ran into them on the <a href="http://what-if.xkcd.com/">XKCD What-If blog</a>.  They're great for expanding on a side-thought without cluttering up the main body of the article. They're handy when writing faux-technical articles that require lots of footnotes to save me from Death By Nitpick. They're great for jokes <span class="snote">Since you can hide the <a href="http://en.wikipedia.org/wiki/Punch_line">punchline</a>.</span>. </p>
  112.  
  113. </body>
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement