-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathabbr.js
55 lines (49 loc) · 1.7 KB
/
abbr.js
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
(function abbrMacro() {
// usage: <<abbr "text" "long explanation">>
'use strict';
/* globals version, Macro */
if (!version || !version.title || 'SugarCube' !== version.title || !version.major || version.major < 2) {
throw new Error('<<abbr>> macro requires SugarCube 2.0 or greater, aborting load');
}
version.extensions.abbr = {major: 1, minor: 2, revision: 1};
const clsPrefix = 'abbr-macro';
const styles = `
.${clsPrefix} {
position: relative;
display: inline;
cursor: pointer;
border-bottom: 1px dotted;
}
.${clsPrefix}::before {
content: attr(data-title);
position: absolute;
display: table;
top: 100%;
left: 0;
z-index: 10;
max-width: 25vw;
padding: 0.3em;
font-size: 90%;
pointer-events: none;
opacity: 0;
border: 1px solid currentColor;
transition: 150ms linear all;
}
.${clsPrefix}:active::before,
.${clsPrefix}:hover::before {
pointer-events: auto;
opacity: 1;
transition: 150ms linear all;
}
/* to avoid setting bg color manually */
#story, #passages, .passage, .passage *, .passage * .${clsPrefix}, .${clsPrefix}::before {
background-color: inherit;
}`;
jQuery('head').append(`<style type="text/css">${styles}</style>`);
Macro.add('abbr', {
handler () {
const abr = jQuery(`<abbr class="${clsPrefix}" data-title="${this.args[1]}">${this.args[0]}</abbr>`);
abr.appendTo(this.output);
},
});
}());