1
1
var wikiResponse = false ;
2
+ var shadow = null ;
2
3
3
4
$ ( document ) . ready ( function ( ) {
4
5
peekElem =
@@ -27,7 +28,7 @@ function setupPeek(elem) {
27
28
28
29
var timeout = setTimeout ( function ( ) {
29
30
showPeek ( elem ) ;
30
- } , 1000 ) ;
31
+ } , 500 ) ;
31
32
32
33
$ ( 'a' ) . mouseout ( function ( ) {
33
34
clearTimeout ( timeout ) ;
@@ -39,18 +40,73 @@ function setupPeek(elem) {
39
40
function showPeek ( elem ) {
40
41
if ( wikiResponse === false )
41
42
return false ;
42
- elem . addClass ( 'wikitip' ) ;
43
- elem . append ( '<span class="wikiinfo"><div class="wikititle"></div><div class="wikitext"></div></span>' ) ;
44
43
45
-
46
-
47
- $ ( '.wikiinfo .wikititle' ) . text ( wikiResponse [ 0 ] ) ;
48
- $ ( '.wikiinfo .wikitext' ) . text ( wikiResponse [ 1 ] ) ;
44
+ elem . append ( '<span class="wikitip"></span>' )
45
+ // Insert node after the body so that it will always be on top
46
+ $ ( 'body' ) . after ( '<div id="wikipeek-host"></div>' ) ;
47
+
48
+ // Using DOM shadowing cause I'm just fucking 1337 like that...
49
+ // ...also this is the way Google made their dictionary extension
50
+ var shadow = $ ( '#wikipeek-host' ) [ 0 ] . createShadowRoot ( ) ;
51
+ shadow . innerHTML = `
52
+ <style>
53
+ .wikiinfo{
54
+ background: rgba(245, 245, 255, 0.96);
55
+ border-radius: 5px;
56
+ border: 1px solid #ccc;
57
+ bottom: 26px;
58
+ color: black;
59
+ content: attr(title);
60
+ left: 20%;
61
+ padding: 18px;
62
+ position: absolute;
63
+ width: 480px;
64
+ }
65
+
66
+ .wikiinfo .wikititle{
67
+ font-family: "Linux Libertine",Georgia,Times,serif;
68
+ line-height: 1.3;
69
+ margin-bottom: 14px;
70
+ padding: 0;
71
+ padding-bottom: 7px;
72
+ width: 100%;
73
+ border-bottom: 1px solid #aaa;
74
+ font-size: 22px;
75
+ }
76
+
77
+ .wikiinfo .wikitext{
78
+ max-height: 140px;
79
+ font-size: 12px;
80
+ overflow: hidden;
81
+ }
82
+ </style>
83
+ <span class="wikiinfo">
84
+ <div class="wikititle">${ wikiResponse [ 0 ] } </div>
85
+ <div class="wikitext">${ wikiResponse [ 1 ] } </div>
86
+ </span>` ;
87
+
88
+ $ ( '#wikipeek-host' ) . css ( {
89
+ position : "absolute" ,
90
+ marginLeft : 0 , marginTop : 0 ,
91
+ top : elem . offset ( ) . top + 20 , left : elem . offset ( ) . left
92
+ } ) ;
93
+
94
+ // Sucks, but it seems to be difficult to find the width of shadow elements
95
+ // This is the width of the tooltip + the padding
96
+ var tipWidth = 518 ;
97
+ var offscreenRight = $ ( '#wikipeek-host' ) . offset ( ) . left + tipWidth ;
98
+ var screenWidth = $ ( window ) . width ( ) ;
99
+ console . log ( $ ( '#wikipeek-host' ) . outerWidth ( ) ) ;
100
+ console . log ( offscreenRight ) ;
101
+ console . log ( screenWidth ) ;
102
+ if ( offscreenRight > screenWidth ) {
103
+ $ ( '#wikipeek-host' ) . css ( 'left' , $ ( '#wikipeek-host' ) . offset ( ) . left - ( offscreenRight - screenWidth ) ) ;
104
+ }
49
105
}
50
106
51
- function hidePeek ( elem ) { return
107
+ function hidePeek ( elem ) {
52
108
elem . removeClass ( 'wikitip' ) ;
53
- elem . find ( '.wikiinfo ') . remove ( ) ;
109
+ $ ( '#wikipeek-host ') . remove ( ) ;
54
110
}
55
111
56
112
function fetchPeek ( link ) {
0 commit comments