forked from Kenshin/simpread
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhighlight.js
More file actions
44 lines (41 loc) · 1.28 KB
/
highlight.js
File metadata and controls
44 lines (41 loc) · 1.28 KB
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
console.log( "=== simpread highlight load ===" )
const highlight_class = "simpread-highlight-selector";
/**
* Highlight
*
* @return {promise} promise
*/
function start() {
let $prev;
const dtd = $.Deferred(),
mousemoveEvent = event => {
if ( !$prev ) {
$( event.target ).addClass( highlight_class );
} else {
$prev.removeClass( highlight_class );
$( event.target ).addClass( highlight_class );
}
$prev = $( event.target );
};
$( "html" ).one( "click", event => {
if ( !$prev ) return;
$( event.target ).removeClass( highlight_class );
$( "html" ).off( "mousemove", mousemoveEvent );
$prev = undefined;
dtd.resolve( event.target );
});
$( "html" ).one( "keydown", event => {
if ( event.keyCode == 27 && $prev ) {
$( "html" ).find( `.${highlight_class}` ).removeClass( highlight_class );
$( "html" ).off( "mousemove", mousemoveEvent );
$prev = undefined;
event.preventDefault();
return false;
}
});
$( "html" ).on( "mousemove", mousemoveEvent );
return dtd;
}
export {
start as Start,
}