refNote: Generate a popup reference note

Description Usage Arguments Value Note Author(s) References Examples

Description

Generates the html needed to include a popup reference note. Note requires inclusion of javascript libraries for this to function.

Usage

1
refNote(text = "This is a test note", number = "*")

Arguments

text

Note to include in popup. Line breaks occasionally cause problems. As this is generally for short notes; I have not come up with a general solution yet. If your note text is complicated, ensure that you check the result.

number

The label to identify the note in the text.

Value

The html for the popup note

Note

The html page also needs to include the javascript and css to process the notes for these to work. Specifically, need to include the following (generally in the header):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<!-- The javascript to run the popup refernce notes -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script>
      jQuery.noConflict();
      jQuery(function() {
        jQuery(".refbody").hide();
        jQuery(".refnum").click(function(event) {
          jQuery(this.nextSibling).toggle();
          event.stopPropagation();
        });
        jQuery("body").click(function(event) {
          jQuery(".refbody").hide();
        });
      });
    </script>

And the following to wherever you include you css definitions:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* the reference tooltips style starts here */
/* This was stolen from the What If? css sytle sheet
 *  at https://what-if.xkcd.com/css/style.css
 *  in an effort to emulate that style  */

.ref {
    position: relative;
    vertical-align: baseline;
   }

.refnum {
    position: relative;
    left: 2px;
    bottom: 1ex;
    font-family: Verdana, sans-serif;
    color: #005994;
    font-size: .7em;
    font-weight: bold;
    text-decoration: underline;
    cursor: pointer;
}

.refbody {
    font-family: Verdana, sans-serif;
    font-size: .7em;
    line-height: 1.1;
    display: block;
    min-width: 20em;
    position: absolute;
    left: 25px;
    bottom: 5px ;
    border: 1px solid;
    padding: 5px;
    background-color: #fff;
    word-wrap: break-word;
    z-index: 9999;
    overflow: auto;
}

Author(s)

Mark Peterson

References

This was based on the popups on the https://what-if.xkcd.com/ site

Examples

1
2
3
cat(refNote())

cat(refNote("Any text can go in here", 42))

Example output

Loading required package: knitr
Loading required package: dplyr

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union

<span class="ref"><span class="refnum">[*]</span><span class="refbody">This is a test note</span></span><span class="ref"><span class="refnum">[42]</span><span class="refbody">Any text can go in here</span></span>

rmdHelpers documentation built on May 1, 2019, 7:33 p.m.