Advertisement
Guest User

Untitled

a guest
Jul 4th, 2014
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.56 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <title>snote example</title>
  4. <meta charset="utf-8">
  5.  
  6. <!-- snote v6. Placed in the public domain by Roger Hågensen. -->
  7. <!-- changes from v5:
  8. A semi-colon was missing in the snote CSS definition.
  9. cursor reset moved out of the javascript and back into CSS where it belong.
  10. Removed a redundant else in the javascipt code.
  11. -->
  12. <style>
  13. .snote
  14. {
  15.     width: 1em;
  16.     height: 1em;
  17.     background-image: url('http://icons.iconarchive.com/icons/visualpharm/must-have/256/Information-icon.png');
  18.     background-size: auto 1em;
  19.     background-repeat: no-repeat;
  20.     display: none;
  21.     cursor: help;
  22. }
  23.  
  24. .snote_tip
  25. {
  26.     display: block;
  27.     visibility: hidden;
  28.     position: absolute;
  29.     width: 16em;
  30.     height: 3em;
  31.     padding: 0.5em;
  32.     overflow: auto;
  33.     background: #cccccc;
  34.     color: #000000;
  35.     border: 0.15em solid #000000;
  36.     border-radius: 0.25em;  
  37.     box-shadow: 0.25em 0.25em 0.25em #7f7f7f;
  38. }
  39.  
  40. .snote_tip:hover
  41. {
  42.     cursor: auto;
  43. }
  44.  
  45. </style>
  46.  
  47. <script>
  48.     //call this function once the page has loaded
  49.     window.addEventListener('load', snote_init, false);
  50.  
  51.     //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.
  52.     function snote_init()
  53.     {
  54.         var snote_elements = document.getElementsByClassName('snote');
  55.         for (var i = 0; i < snote_elements.length; i += 1)
  56.         {
  57.             (function(ii)
  58.             {
  59.                 var snote_element = snote_elements[ii];
  60.                 var node = document.createElement('span');
  61.                 node.className = 'snote_tip';
  62.                 var text = snote_element.innerHTML;
  63.                 snote_element.innerHTML = '';
  64.                 node.innerHTML = text;
  65.                 snote_element.appendChild(node);
  66.                 snote_element.style.display = 'inline-block';
  67.                 snote_element.addEventListener ("mouseup", function () { snote_show(snote_element, node); }, false);
  68.             })(i);
  69.         }
  70.     }
  71.  
  72.     function snote_show(snote_element, snote_tip)
  73.     {
  74.         if (snote_tip.style.visibility == 'visible')
  75.         {
  76.             snote_tip.style.visibility = 'hidden';
  77.             return;
  78.         }
  79.  
  80.         snote_tip.style.visibility = 'visible';
  81.  
  82.         var rect = snote_element.getBoundingClientRect();
  83.         x0 = rect.left + (rect.width * 0.5);
  84.         y0 = rect.top + (rect.height * 0.5);
  85.  
  86.         rect = snote_tip.getBoundingClientRect();
  87.         snote_tip.style.left = (x0 - (rect.width / 2)) + 'px';
  88.         snote_tip.style.top = (y0 - (rect.height / 2)) + 'px';
  89.  
  90.         rect = snote_tip.getBoundingClientRect();
  91.         x1 = rect.left;
  92.         y1 = rect.top;
  93.         x2 = window.innerWidth - rect.right
  94.         y2 = window.innerHeight - rect.bottom
  95.         if (x1 < 0)
  96.         {
  97.             snote_tip.style.left = '0px';
  98.         }
  99.         if (y1 < 0)
  100.         {
  101.             snote_tip.style.top = '0px';
  102.         }
  103.         if (x2 < 0)
  104.         {
  105.             snote_tip.style.left = (window.innerWidth-rect.width) + 'px';
  106.         }
  107.         if (y2 < 0)
  108.         {
  109.             snote_tip.style.left = (window.innerHeight-rect.height) + 'px';
  110.         }
  111.  
  112.     };
  113. </script>
  114.  
  115. <body>
  116.  
  117. <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>
  118.  
  119. </body>
  120. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement