22/* eslint-disable max-len */
33
44/* Permalink clipboard handling */
5- window . addEventListener ( 'load' , function ( ) {
6- var clipboard = new ClipboardJS ( '#copy-permalink' ) ;
5+ $ ( window ) . ready ( function ( ) {
6+ var clipboard = new ClipboardJS ( '#copy-permalink' ) ;
77
8- clipboard . on ( 'success' , function ( ) {
9- UIkit . tooltip ( '#copy-permalink' , {
8+ clipboard . on ( 'success' , function ( ) {
9+ UIkit . tooltip ( '#copy-permalink' , {
1010 title : 'Copied link to clipboard!'
11- } ) . show ( ) ;
12- } ) ;
11+ } ) . show ( ) ;
12+ } ) ;
1313
14- clipboard . on ( 'error' , function ( e ) {
15- $ ( '#copy-permalink' ) . text ( e . text ) ;
16- } ) ;
17- } ) ;
14+ clipboard . on ( 'error' , function ( e ) {
15+ $ ( '#copy-permalink' ) . text ( e . text ) ;
16+ } ) ;
17+ } ) ;
1818
1919/* Format TOC */
2020// TODO: Change font size dynamically to fit smaller viewports
2121// TODO: Deal with text overflow / truncation of text
22- window . addEventListener ( 'load' , function ( ) {
23- if ( document . querySelector ( '#toc' ) ) {
22+ $ ( window ) . ready ( function ( ) {
23+ if ( document . querySelector ( '#toc' ) ) {
2424 // Article TOC
25- let $toc = $ ( '#toc' ) ;
26- $toc . appendTo ( $ ( '#left-col' ) ) ;
27- $toc . addClass ( 'uk-margin-small-left uk-height-1-1 uk-overflow-auto' ) . attr ( 'uk-sticky' , '' ) ;
28- $toc . find ( 'h2' ) . addClass ( 'uk-nav-header uk-margin-remove-bottom uk-inline' ) ;
29- $toc . find ( '.toctoggle' ) . attr ( 'hidden' , '' ) ;
30- $toc . find ( '>ul' ) . addClass ( 'uk-nav uk-nav-default uk-margin-remove-top' )
31- . attr ( 'uk-scrollspy-nav' , 'closest: li; scroll: true;' ) ; // BUG: Scrollspy isn't working (uikit#3100)
25+ let $toc = $ ( '#toc' ) ;
26+ $toc . appendTo ( $ ( '#left-col' ) ) ;
27+ $toc . addClass ( 'uk-margin-small-left uk-height-1-1 uk-overflow-auto' ) . attr ( 'uk-sticky' , '' ) ;
28+ $toc . find ( 'h2' ) . addClass ( 'uk-nav-header uk-margin-remove-bottom uk-inline' ) ;
29+ $toc . find ( '.toctoggle' ) . attr ( 'hidden' , '' ) ;
30+ $toc . find ( '>ul' ) . addClass ( 'uk-nav uk-nav-default uk-margin-remove-top' )
31+ . attr ( 'uk-scrollspy-nav' , 'closest: li; scroll: true;' ) ; // BUG: Scrollspy isn't working (uikit#3100)
3232 // Useful for tab navigation
33- $toc . find ( '>ul' ) . prepend ( `
33+ $toc . find ( '>ul' ) . prepend ( `
3434 <li class="toclevel-0 tocsection-0 uk-parent">
3535 <a id="skip" href="#content">
3636 <span class="tocnumber"></span>
3737 <span class="toctext">Introduction</span>
38- </a></li>` ) ;
39- $toc . find ( '.toclevel-1' ) . addClass ( 'uk-parent' ) ;
40- $toc . find ( '.toclevel-1>ul' ) . addClass ( 'uk-nav-sub' ) ;
41- } else if ( document . querySelector ( '#preftoc' ) ) {
38+ </a></li>` ) ;
39+ $toc . find ( '.toclevel-1' ) . addClass ( 'uk-parent' ) ;
40+ $toc . find ( '.toclevel-1>ul' ) . addClass ( 'uk-nav-sub' ) ;
41+ } else if ( document . querySelector ( '#preftoc' ) ) {
4242 // User preferences TOC
43- let $toc = $ ( '#preftoc' ) ;
44- $toc . appendTo ( $ ( '#left-col' ) )
45- . prepend ( '<h2 class="uk-nav-header uk-margin-remove-bottom uk-inline">What would you like to change?</h>' ) // A change of tone from the otherwise technical MediaWiki
46- . addClass ( 'uk-margin-small-left uk-height-1-1 uk-nav uk-nav-default' ) . attr ( 'uk-sticky' , '' ) ;
43+ let $toc = $ ( '#preftoc' ) ;
44+ $toc . appendTo ( $ ( '#left-col' ) )
45+ . prepend ( '<h2 class="uk-nav-header uk-margin-remove-bottom uk-inline">What would you like to change?</h>' ) // A change of tone from the otherwise technical MediaWiki
46+ . addClass ( 'uk-margin-small-left uk-height-1-1 uk-nav uk-nav-default' ) . attr ( 'uk-sticky' , '' ) ;
4747 }
48- } ) ;
48+ } ) ;
4949
5050/* Convert edit links to icons */
51- window . addEventListener ( 'load' , function ( ) {
52- if ( document . querySelector ( '.mw-editsection' ) ) {
53- let $editMarkers = $ ( '.mw-editsection' ) ;
54- $editMarkers . addClass ( 'uk-invisible-hover uk-text-middle' ) ;
55- $editMarkers . parent ( ) . addClass ( 'uk-visible-toggle' ) ;
56- $editMarkers . find ( '>.mw-editsection-bracket' ) . attr ( 'hidden' , '' ) ;
57- $editMarkers . find ( '>a' ) . attr ( 'uk-icon' , 'icon: pencil' ) . attr ( 'role' , 'button' ) . attr ( 'aria-label' , $ ( this ) . attr ( 'title' ) ) . text ( '' ) ;
51+ $ ( window ) . ready ( function ( ) {
52+ if ( document . querySelector ( '.mw-editsection' ) ) {
53+ let $editMarkers = $ ( '.mw-editsection' ) ;
54+ $editMarkers . addClass ( 'uk-invisible-hover uk-text-middle' ) ;
55+ $editMarkers . parent ( ) . addClass ( 'uk-visible-toggle' ) ;
56+ $editMarkers . find ( '>.mw-editsection-bracket' ) . attr ( 'hidden' , '' ) ;
57+ $editMarkers . find ( '>a' ) . attr ( 'uk-icon' , 'icon: pencil' ) . attr ( 'role' , 'button' ) . attr ( 'aria-label' , $ ( this ) . attr ( 'title' ) ) . text ( '' ) ;
5858 }
59- } ) ;
59+ } ) ;
6060
6161// TODO: Split article to <section> elements
6262// TODO: Add 'to top' markers to section ends
6363
6464/* Reformat history pages */
65- window . addEventListener ( 'load' , function ( ) {
66- if ( document . getElementById ( 'mw-history-compare' ) ) {
65+ $ ( window ) . ready ( function ( ) {
66+ if ( document . getElementById ( 'mw-history-compare' ) ) {
6767
6868 // Create table
69- $ ( '#mw-history-compare ul' ) . replaceWith ( function ( ) {
70- return $ ( '<table id="pagehistory" />' ) . append ( $ ( this ) . contents ( ) ) ;
71- } ) ;
69+ $ ( '#mw-history-compare ul' ) . replaceWith ( function ( ) {
70+ return $ ( '<table id="pagehistory" />' ) . append ( $ ( this ) . contents ( ) ) ;
71+ } ) ;
7272
73- let $table = $ ( 'table' ) ,
73+ let $table = $ ( 'table' ) ,
7474 // Select and transform cells
7575 re = / \( | \) / g,
76- s = function ( context , query , transform = 0 ) {
77- var res = $ ( context ) . find ( query ) ;
76+ s = function ( context , query , transform = 0 ) {
77+ var res = $ ( context ) . find ( query ) ;
7878 // jQuery returns 'undefined' if it can't find an object, eg. '.minoredit' or '.comment'
79- if ( res [ 0 ] !== undefined ) {
80- if ( transform === 1 ) {
81- // Remove parentheses from bytes
82- return res [ 0 ] . outerHTML . replace ( re , '' ) ;
83- } else if ( transform === 2 ) {
84- // Reverse date formatting
85- let date = res . text ( ) . split ( ', ' ) ,
86- fixedDate = [ date [ 1 ] , date [ 0 ] ] . join ( ', ' ) ;
87- res . text ( fixedDate ) ;
88- return res [ 0 ] . outerHTML ;
79+ if ( res [ 0 ] !== undefined ) {
80+ if ( transform === 1 ) {
81+ // Remove parentheses from bytes
82+ return res [ 0 ] . outerHTML . replace ( re , '' ) ;
83+ } else if ( transform === 2 ) {
84+ // Reverse date formatting
85+ let date = res . text ( ) . split ( ', ' ) ,
86+ fixedDate = [ date [ 1 ] , date [ 0 ] ] . join ( ', ' ) ;
87+ res . text ( fixedDate ) ;
88+ return res [ 0 ] . outerHTML ;
8989 }
90- return res [ 0 ] . outerHTML ;
90+ return res [ 0 ] . outerHTML ;
9191 }
9292 // Has to return something to the template literal
9393 return '' ;
9494 } ;
9595
96- $table . children ( ) . replaceWith ( function ( ) {
96+ $table . children ( ) . replaceWith ( function ( ) {
9797 return '<tr>' +
98- '<td>' + s ( this , '.mw-userlink' ) + '<div class="uk-padding-small uk-text-center" uk-dropdown>' + s ( this , '.mw-usertoollinks' ) + '</div></td>' +
99- '<td>' + s ( this , '.mw-changeslist-date' , 2 ) + '</td>' +
100- '<td>' + s ( this , '.minoredit' ) + '</td>' +
101- '<td>' + s ( this , '.mw-plusminus-pos' , 1 ) + s ( this , '.mw-plusminus-neg' , 1 ) + '</td>' +
102- '<td>' + s ( this , '.history-size' ) + '</td>' +
103- '<td>' + s ( this , '.comment' ) + '</td>' +
104- '<td>' + s ( this , '.mw-history-histlinks' ) + '</td>' +
105- '<td><span>' + $ ( this ) . find ( 'input' ) [ 0 ] . outerHTML + '</span><span>' + $ ( this ) . find ( 'input' ) [ 1 ] . outerHTML + '</span></td>' +
106- '<td><span uk-icon="icon: cog" role="button" aria-haspopup="menu" title="Revision tools"></span><div class="uk-padding-small uk-text-center" uk-dropdown role="menu">' + s ( this , '.mw-history-undo' ) + '</div></td>' +
107- '</tr>' ;
108- } ) ;
109- $table . children ( ) . wrapAll ( '<tbody />' ) ;
98+ '<td>' + s ( this , '.mw-userlink' ) + '<div class="uk-padding-small uk-text-center" uk-dropdown>' + s ( this , '.mw-usertoollinks' ) + '</div></td>' +
99+ '<td>' + s ( this , '.mw-changeslist-date' , 2 ) + '</td>' +
100+ '<td>' + s ( this , '.minoredit' ) + '</td>' +
101+ '<td>' + s ( this , '.mw-plusminus-pos' , 1 ) + s ( this , '.mw-plusminus-neg' , 1 ) + '</td>' +
102+ '<td>' + s ( this , '.history-size' ) + '</td>' +
103+ '<td>' + s ( this , '.comment' ) + '</td>' +
104+ '<td>' + s ( this , '.mw-history-histlinks' ) + '</td>' +
105+ '<td><span>' + $ ( this ) . find ( 'input' ) [ 0 ] . outerHTML + '</span><span>' + $ ( this ) . find ( 'input' ) [ 1 ] . outerHTML + '</span></td>' +
106+ '<td><span uk-icon="icon: cog" role="button" aria-haspopup="menu" title="Revision tools"></span><div class="uk-padding-small uk-text-center" uk-dropdown role="menu">' + s ( this , '.mw-history-undo' ) + '</div></td>' +
107+ '</tr>' ;
108+ } ) ;
109+ $table . children ( ) . wrapAll ( '<tbody />' ) ;
110110
111111 // Add headings
112112 // WORKAROUND: 'Change size' should span two columns ('.minoredit' and '.mw-plusminus-*'), but Tablesorter doesn't handle 'colspan' well. Instead, an empty header is added just before to accomodate for '.minoredit'.
113113 $table . prepend (
114- '<thead>' +
115- '<tr>' +
116- '<th>Editor</th>' +
117- '<th>Time</th>' +
118- '<th class=parser-false sorter-false></th>' +
119- '<th>Change</th>' +
120- '<th>(Total)</th>' +
121- '<th>Comment</th>' +
122- '<th colspan=3 class=parser-false sorter-false>Tools</th>' +
123- '</tr>' +
114+ '<thead>' +
115+ '<tr>' +
116+ '<th>Editor</th>' +
117+ '<th>Time</th>' +
118+ '<th class=parser-false sorter-false></th>' +
119+ '<th>Change</th>' +
120+ '<th>(Total)</th>' +
121+ '<th>Comment</th>' +
122+ '<th colspan=3 class=parser-false sorter-false>Tools</th>' +
123+ '</tr>' +
124124 '</thead>'
125125 ) ;
126126
127127 // Style
128128 // FIX: For some reason Tablersorter's css disrupt uk-table-hover
129- $table = $ ( 'table' ) . addClass ( 'uk-table uk-table-divider uk-table-hover uk-table-justify uk-table-small uk-text-small tablesorter' ) ;
129+ $table = $ ( 'table' ) . addClass ( 'uk-table uk-table-divider uk-table-hover uk-table-justify uk-table-small uk-text-small tablesorter' ) ;
130130
131131 // TODO: Add more tools to the history tools menu (next to the "undo")
132132
133133 // TODO: Make sure this sorts properly at the beginning of a month
134134 $table . tablesorter ( ) ;
135135
136136 }
137- } ) ;
137+ } ) ;
138138
139139/* Shift images to the right */
140- window . addEventListener ( 'load' , function ( ) {
141- let imgs = $ ( 'main .thumb, main .mermaid' ) ,
142- prev = $ ( 'head' ) ;
140+ $ ( window ) . ready ( function ( ) {
141+ let imgs = $ ( 'main .thumb, main .mermaid' ) ,
142+ prev = $ ( 'head' ) ;
143143
144- imgs . each ( function ( ) {
145- let $this = $ ( this ) ,
144+ imgs . each ( function ( ) {
145+ let $this = $ ( this ) ,
146146 vOffest = $this . offset ( ) . top ,
147147 cutoff = prev . offset ( ) . top + prev . height ( ) ;
148- if ( vOffest <= cutoff ) {
148+ if ( vOffest <= cutoff ) {
149149 let newOffset = cutoff + 20 ;
150- $this . css ( 'top' , `${ newOffset } px` ) ; // Default UIkit margin
150+ $this . css ( 'top' , `${ newOffset } px` ) ; // Default UIkit margin
151151 }
152152 prev = $this ;
153- } ) ;
154- } ) ;
153+ } ) ;
154+ } ) ;
155155
156156/* Preview Wikilinks */
157- window . addEventListener ( 'load' , function ( ) {
157+ $ ( window ) . ready ( function ( ) {
158158 let own = top . location . host . toString ( ) ,
159159 mothership = 'en.wikipedia.org' ,
160160
161- $wikilinks = $ ( '#content' ) . find ( 'a[href^="' + own + '"], a[href^="http://' + own + '"],' +
162- 'a[href^="https://' + own + '"], a[href^="' + mothership + '"], a[href^="http://' + mothership + '"],' +
163- 'a[href^="https://' + mothership + '"], a[href^="/"], a[href^="./"], a[href^="../"], a[href^="#"]' ) ;
161+ $wikilinks = $ ( '#content' ) . find ( 'a[href^="' + own + '"], a[href^="http://' + own + '"],' +
162+ 'a[href^="https://' + own + '"], a[href^="' + mothership + '"], a[href^="http://' + mothership + '"],' +
163+ 'a[href^="https://' + mothership + '"], a[href^="/"], a[href^="./"], a[href^="../"], a[href^="#"]' ) ;
164164
165165 // let $policies = $wikilinks.filter( 'a[title^="WP:"], a[title^="Wikipedia:"], a[title^="wikipedia:"]' );
166166
167- $wikilinks . each ( function ( ) {
168- $ ( this ) . after (
167+ $wikilinks . each ( function ( ) {
168+ $ ( this ) . after (
169169 '<div class="uk-padding-small" uk-dropdown role="tooltip">' +
170- '<h2 class="uk-h4"></h2>' +
171- ' <p>Loading summary...</p>' +
172- '</div>' ) ;
173- } ) ;
174-
175- $wikilinks . hover ( function ( ) {
176- var caller = $ ( this ) . next ( ) ;
177-
178- $ . getJSON ( 'https://en.wikipedia.org/api/rest_v1/page/summary/' + $ ( this ) [ 0 ] . title )
179- . done ( function ( res ) {
180- caller . find ( 'h2' ) . html ( res . title ) ;
181- if ( res . type !== 'no-extract' ) {
182- caller . find ( 'p' ) . html ( res . extract ) ;
170+ '<h2 class="uk-h4"></h2>' +
171+ ' <p>Loading summary...</p>' +
172+ '</div>' ) ;
173+ } ) ;
174+
175+ $wikilinks . hover ( function ( ) {
176+ var caller = $ ( this ) . next ( ) ;
177+
178+ $ . getJSON ( 'https://en.wikipedia.org/api/rest_v1/page/summary/' + $ ( this ) [ 0 ] . title )
179+ . done ( function ( res ) {
180+ caller . find ( 'h2' ) . html ( res . title ) ;
181+ if ( res . type !== 'no-extract' ) {
182+ caller . find ( 'p' ) . html ( res . extract ) ;
183183 } else {
184- caller . find ( 'p' ) . html ( 'No extract available!' ) ; // TODO: Add "warning" icon for policy pages, and "info" icon for guideline pages
184+ caller . find ( 'p' ) . html ( 'No extract available!' ) ; // TODO: Add "warning" icon for policy pages, and "info" icon for guideline pages
185185 }
186- } )
187- . fail ( function ( res , status , err ) {
188- caller . find ( 'p' ) . html ( 'Article not found!<br>Reason: ' + status + ', ' + err ) ;
189- } ) ;
190- } ) ;
191- } ) ;
186+ } )
187+ . fail ( function ( res , status , err ) {
188+ caller . find ( 'p' ) . html ( 'Article not found!<br>Reason: ' + status + ', ' + err ) ;
189+ } ) ;
190+ } ) ;
191+ } ) ;
0 commit comments