MediaWiki:Common.js: Difference between revisions
From Brickipedia, the LEGO Wiki
m |
|||
Line 348: | Line 348: | ||
$( 'span.insertusername' ).text( name ); |
$( 'span.insertusername' ).text( name ); |
||
} |
} |
||
− | } ); |
||
− | |||
− | /* encouraging editing from chat */ |
||
− | var counter = 0; |
||
− | var max = 15; |
||
− | $( $( '#mwchat-type input' )[0] ).keydown( function( e ) { |
||
− | if ( e.which == 13 && e.shiftKey ) { |
||
− | return false; |
||
− | } else if ( e.which == 13 ) { // Enter |
||
− | counter++; |
||
− | if ( counter > max ) { |
||
− | counter = 0; |
||
− | max += 10; |
||
− | $( "<div>You've done lots of chatting, why not do some editing here too? Check out our <a href='/wiki/Brickipedia:Things_to_do' target='_blank'>list of things to do</a>, or try <a href='/wiki/Special:Random' target='_blank'>this page</a>, <a href='/wiki/Special:Random' target='_blank'>this page</a>, or <a href='/wiki/Special:Random' target='_blank'>this page</a>.<br><small><a href='javascript:;' onclick='$(this).parent().parent().remove()'>(dismiss)</a></small></div>" ).appendTo( $( 'body' ) ) |
||
− | .css( { 'background-color': '#CCC', 'position': 'fixed', 'top': '50px', 'left': '50%', 'margin-left': '-120px', 'width': '240px', 'z-index': 5, 'padding': '10px', } ); |
||
− | } |
||
− | } |
||
} ); |
} ); |
||
Revision as of 21:21, 11 April 2015
1 /* Make each box in a row on the main page the same height as others on the same row */
2 var FirstRowLeftBox = $('.LeftBox.MPBoxesFirstRow').height();
3 var FirstRowRightBox = $('.RightBox.MPBoxesFirstRow').height();
4 var SecondRowLeftBox = $('.LeftBox.MPBoxesSecondRow').height();
5 var SecondRowRightBox = $('.RightBox.MPBoxesSecondRow').height();
6 var ThirdRowLeftBox = $('.LeftBox.MPBoxesThirdRow').height();
7 var ThirdRowRightBox = $('.RightBox.MPBoxesThirdRow').height();
8 if (FirstRowLeftBox > FirstRowRightBox) {
9 $('.RightBox.MPBoxesFirstRow').css({'height':($('.LeftBox.MPBoxesFirstRow').height())+'px'});
10 } else {
11 $('.LeftBox.MPBoxesFirstRow').css({'height':($('.RightBox.MPBoxesFirstRow').height())+'px'});
12 }
13 if (SecondRowLeftBox > SecondRowRightBox) {
14 $('.RightBox.MPBoxesSecondRow').css({'height':($('.LeftBox.MPBoxesSecondRow').height())+'px'});
15 } else {
16 $('.LeftBox.MPBoxesSecondRow').css({'height':($('.RightBox.MPBoxesSecondRow').height())+'px'});
17 }
18 if (ThirdRowLeftBox > ThirdRowRightBox) {
19 $('.RightBox.MPBoxesThirdRow').css({'height':($('.LeftBox.MPBoxesThirdRow').height())+'px'});
20 } else {
21 $('.LeftBox.MPBoxesThirdRow').css({'height':($('.RightBox.MPBoxesThirdRow').height())+'px'});
22 }
23
24 /* Mainpage nav */
25 $("#MP-theme-nav").mouseenter(function() {
26 $("#MP-theme-nav-body").slideDown("medium");
27 $("#MP-theme-nav-header").css("background", "#3333FF");
28 $("#MP-theme-nav-header a").css("color", "#FFFFFF");
29 $("#MP-theme-nav-header span").css("color", "#FFFFFF");
30 }).mouseleave(function() {
31 $("#MP-theme-nav-body").slideUp("medium");
32 $("#MP-theme-nav-header").css("background", "#FFFFFF");
33 $("#MP-theme-nav-header a").css("color", "#3333FF");
34 $("#MP-theme-nav-header span").css("color", "#3333FF");
35 });
36
37 $("#MP-comm-nav").mouseenter(function() {
38 $("#MP-comm-nav-body").slideDown("medium");
39 $("#MP-comm-nav-header").css("background", "#3333FF");
40 $("#MP-comm-nav-header a").css("color", "#FFFFFF");
41 $("#MP-comm-nav-header span").css("color", "#FFFFFF");
42 }).mouseleave(function() {
43 $("#MP-comm-nav-body").slideUp("medium");
44 $("#MP-comm-nav-header").css("background", "#FFFFFF");
45 $("#MP-comm-nav-header a").css("color", "#3333FF");
46 $("#MP-comm-nav-header span").css("color", "#3333FF");
47 });
48
49 $("#MP-links-nav").mouseenter(function() {
50 $("#MP-links-nav-body").slideDown("medium");
51 $("#MP-links-nav-header").css("background", "#3333FF");
52 $("#MP-links-nav-header a").css("color", "#FFFFFF");
53 $("#MP-links-nav-header span").css("color", "#FFFFFF");
54 }).mouseleave(function() {
55 $("#MP-links-nav-body").slideUp("medium");
56 $("#MP-links-nav-header").css("background", "#FFFFFF");
57 $("#MP-links-nav-header a").css("color", "#3333FF");
58 $("#MP-links-nav-header span").css("color", "#3333FF");
59 });
60
61
62 /* Shows your user groups when using Template:USERGROUPS */
63 function showUserGroups() {
64 $('.userGroups').html(wgUserGroups.toString());
65 }
66 $(showUserGroups);
67
68 /* Shows a box for news reporters on Brickipedia News:Home so they can easily create new reports */
69 function showNewsReporterBox(){
70 if ( mw.config.get( 'wgUserGroups' ).toString().indexOf( 'newsreporter' ) != -1 ) {
71 $('#newsBox').load('http://en.brickimedia.org/wiki/Brickipedia_News:NRBox #nBox');
72 }
73 }
74 $(showNewsReporterBox);
75
76 /* Rating template positioning/styling */
77 if (screen.width > 600) {
78 if ($('body').hasClass('skin-refreshed')) {
79 $('.ratingTemplate').appendTo('#maintitle');
80 $('.mw-rating-tag').appendTo('#maintitle');
81 $('#maintitle h1').css({'padding-right':'125px'});
82 $('.ratingTemplate').css({'float':'right','margin-top':'-45px','margin-right':'10px','background-color':'white'});
83 $('.mw-rating-tag').css({'float':'right','margin-top':'-45px','margin-right':'10px','background-color':'white'});
84 } else {
85 $('.ratingTemplate').appendTo('#firstHeading');
86 $('.mw-rating-tag').appendTo('#firstHeading');
87 $('#firstHeading h1').css({'padding-right':'110px'});
88 $('.ratingTemplate').css({'float':'right','font-size':'50%'});
89 $('.mw-rating-tag').css({'float':'right','font-size':'50%'});
90 }
91 } else {
92 if ($('body').hasClass('skin-refreshed')) {
93 $('.ratingTemplate').appendTo('#smalltoolboxwrapper');
94 $('.mw-rating-tag').appendTo('#smalltoolboxwrapper');
95 $('.ratingTemplate').css({'float':'right','margin-top':'15px','margin-right':'10px','background-color':'white'});
96 $('.mw-rating-tag').css({'float':'right','margin-top':'15px','margin-right':'10px','background-color':'white'});
97 }
98 }
99
100 /** Collapsible tables *********************************************************
101 *
102 * Description: Allows tables to be collapsed, showing only the header. See
103 * [[Wikipedia:NavFrame]].
104 * Maintainers: [[User:R. Koot]]
105 */
106
107 var autoCollapse = 2;
108 var collapseCaption = "hide";
109 var expandCaption = "show";
110
111 function collapseTable( tableIndex )
112 {
113 var Button = document.getElementById( "collapseButton" + tableIndex );
114 var Table = document.getElementById( "collapsibleTable" + tableIndex );
115
116 if ( !Table || !Button ) {
117 return false;
118 }
119
120 var Rows = Table.rows;
121
122 if ( Button.firstChild.data == collapseCaption ) {
123 for ( var i = 1; i < Rows.length; i++ ) {
124 Rows[i].style.display = "none";
125 }
126 Button.firstChild.data = expandCaption;
127 } else {
128 for ( var i = 1; i < Rows.length; i++ ) {
129 Rows[i].style.display = Rows[0].style.display;
130 }
131 Button.firstChild.data = collapseCaption;
132 }
133 }
134
135 function createCollapseButtons()
136 {
137 var tableIndex = 0;
138 var NavigationBoxes = new Object();
139 var Tables = document.getElementsByTagName( "table" );
140
141 for ( var i = 0; i < Tables.length; i++ ) {
142 if ( hasClass( Tables[i], "collapsible" ) ) {
143
144 /* only add button and increment count if there is a header row to work with */
145 var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
146 if (!HeaderRow) continue;
147 var Header = HeaderRow.getElementsByTagName( "th" )[0];
148 if (!Header) continue;
149
150 NavigationBoxes[ tableIndex ] = Tables[i];
151 Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
152
153 var Button = document.createElement( "span" );
154 var ButtonLink = document.createElement( "a" );
155 var ButtonText = document.createTextNode( collapseCaption );
156
157 Button.style.styleFloat = "right";
158 Button.style.cssFloat = "right";
159 Button.style.fontWeight = "normal";
160 Button.style.textAlign = "right";
161 Button.style.width = "6em";
162
163 ButtonLink.style.color = Header.style.color;
164 ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
165 ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
166 ButtonLink.appendChild( ButtonText );
167
168 Button.appendChild( document.createTextNode( "[" ) );
169 Button.appendChild( ButtonLink );
170 Button.appendChild( document.createTextNode( "]" ) );
171
172 Header.insertBefore( Button, Header.childNodes[0] );
173 tableIndex++;
174 }
175 }
176
177 for ( var i = 0; i < tableIndex; i++ ) {
178 if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
179 collapseTable( i );
180 }
181 }
182 }
183
184 /* slidey stuff */
185 $(function () {
186 $(".clicker-show").parent().siblings("p").css("margin","0em");
187 $(".clicker-show").click(function(){
188 $(this).parent().next().slideDown();
189 $(this).fadeOut();
190 $(this).prev().fadeIn();
191 });
192 });
193
194 $(function () {
195 $(".clicker-hide").click(function(){
196 $(this).parent().next().slideUp();
197 $(this).fadeOut();
198 $(this).next().fadeIn();
199 });
200 });
201 /* slidey stuff 2 */
202 $(function() {
203 $(".slide-link").addClass("link");
204 var hidelink = "[hide]";
205 var showlink = "[show]";
206
207 $(".slide-content").each(function() {
208 if ($(this).hasClass("noshown")) {
209 var fid = $(this).attr("title");
210 var flink = $(".slide-link[title=\"" + fid + "\"]");
211 flink.html(showlink);
212 } else {
213 var tid = $(this).attr("title");
214 var tlink = $(".slide-link[title=\"" + tid + "\"]");
215 tlink.html(hidelink);
216 }
217 });
218
219 $(".slide-link").click(function() {
220 var tid = $(this).attr("title");
221 var content = $(".slide-content[title=\"" + tid + "\"]");
222
223 if (content.hasClass("noshown")) {
224 content.slideDown(500);
225 $(this).fadeOut(250, function() {
226 $(this).html(hidelink);
227 });
228 $(this).fadeIn(250);
229 content.removeClass("noshown");
230 content.addClass("shown");
231 } else {
232 content.slideUp(500);
233 $(this).fadeOut(250, function() {
234 $(this).html(showlink);
235 });
236 $(this).fadeIn(250);
237 content.removeClass("shown");
238 content.addClass("noshown");
239 }
240 });
241 });
242
243 /* table scrolling - [[User:UltrasonicNXT]] */
244 $(window).scroll(function(){
245 placeDetection($(window).scrollTop());
246 });
247
248 function placeDetection(scroll){
249 $(".ttbutton").each(function(index){
250 var it = $(this).nextAll(".themetable").first();
251 var top = it.offset().top;
252 var bottom = it.outerHeight() + it.offset().top;
253 var browser = $(window).height();
254 if(it.outerHeight() > browser * 1.5){
255 if(scroll >= top && scroll <= bottom && $(this).is(":hidden")){
256 $(this).fadeIn();
257 }
258 if(scroll <= top || scroll >= bottom && $(this).is(":visible")){
259 $(this).fadeOut();
260 }
261 } else {
262 $(this).hide();
263 }
264 });
265 }
266
267 $(".ttbutton > .bottom").click(function(){
268 var it = $(this).parent().nextAll(".themetable").first();
269 var where = it.outerHeight() + it.offset().top - 100;
270 $("html,body").animate({
271 scrollTop: where
272 }, 1500);
273 });
274
275 $(".ttbutton > .top").click(function(){
276 var it = $(this).parent().nextAll(".themetable").first();
277 var where = it.offset().top - 100;
278 $("html,body").animate({
279 scrollTop: where
280 }, 1500);
281 });
282
283 /* IRC */
284 $(function() {
285 var nick = (wgUserName === null) ? ('BP-Visitor-' + Math.floor(Math.random() * 10)) : wgUserName.replace(/ /g, '_');
286 $('#IRCReplace').html('<iframe src="http://webchat.freenode.net/?nick=' + nick + '&channels=brickipedia&prompt=true&uio=OT10cnVlJjExPTUxJjEyPXRydWU37" width="100%" height="400" style="border:0;"></iframe>');
287 });
288
289 /* "Submit Review" button */
290 $(btnSubmitReview);
291
292 function btnSubmitReview() {
293 var btn;
294 var title = mw.config.get( 'wgTitle' ).replace( /&/g, '%26' );
295 if ( mw.config.get( 'wgUserName' ) == 'null' ) {
296 btn = '<center><div style="background-color:#ddddee;border:2px outset #9999bb;text-align:center;padding:2px 5px" id="sb-rev"><a href="/index.php?title=Special:UserLogin">Log in</a> to submit a review</div></center>';
297 } else {
298 btn = '<center><a style="background-color:#ddddee;border:2px outset #9999bb;text-align:center;padding:2px 5px; display:block;" id="sb-rev" href="/index.php?title=Review:' + title + '/' + mw.config.get( 'wgUserName' ) + '&action=edit&preload=MediaWiki:Createplate-Review&redlink=1">Submit a review</a></center>';
299 }
300 if ( document.getElementById( 'reviewBtn' ) ) {
301 document.getElementById( 'reviewBtn' ).innerHTML += btn;
302 }
303 }
304
305 /* "Submit Review" area on set infobox */
306 $(btnSubmitReviewInfobox);
307
308 function btnSubmitReviewInfobox() {
309 var link;
310 var title = mw.config.get( 'wgTitle' ).replace( /&/g, '%26' );
311 if ( mw.config.get( 'wgUserName' ) != 'null' ) {
312 link = '<br/><a href="/index.php?title=Review:'+title+'/'+wgUserName+'&action=edit&preload=MediaWiki:Createplate-Review&redlink=1">[Submit/view my review]</a>';
313 }
314 if ( document.getElementById( 'reviewLink' ) ) {
315 document.getElementById( 'reviewLink' ).innerHTML += link;
316 }
317 }
318
319 /* .numberofimages class */
320 function commaSeparateNumber( val ) {
321 while ( /(\d+)(\d{3})/.test( val.toString() ) ) {
322 val = val.toString().replace( /(\d+)(\d{3})/, '$1' + ',' + '$2' );
323 }
324 return val;
325 }
326 $.ajax( {
327 type: 'GET',
328 url: 'http://meta.brickimedia.org/api.php?action=query&meta=siteinfo&siprop=statistics&format=json',
329 dataType: 'jsonp',
330 success: function( data ) {
331 images = data.query.statistics.images;
332 $( '.numberofimages' ).append( commaSeparateNumber( images ) );
333 }
334 } );
335
336 /* Advent cal */
337 $( function() {
338 $( '.advent-cal img' ).attr( {
339 width: '',
340 height: ''
341 } );
342 } );
343
344 /* show USERNAME */
345 $( function() {
346 var name = mw.config.get( 'wgUserName' );
347 if ( !window.disableUsernameReplace && name ) {
348 $( 'span.insertusername' ).text( name );
349 }
350 } );
351
352 /* Set infobox image tabber */
353 $( "#infoBtnBoxOff" ).click(function() {
354 $("#infoBtnBoxOff").css("display", "none");
355 $("#infoBtnBoxOn").css("display", "inline-block");
356 $("#infoBtnSetOn").css("display", "none");
357 $("#infoBtnSetOff").css("display", "inline-block");
358 $("#infoAltImage").hide();
359 $("#infoImage").show();
360 });
361 $( "#infoBtnSetOff" ).click(function() {
362 $("#infoBtnBoxOff").css("display", "inline-block");
363 $("#infoBtnBoxOn").css("display", "none");
364 $("#infoBtnSetOn").css("display", "inline-block");
365 $("#infoBtnSetOff").css("display", "none");
366 $("#infoAltImage").show();
367 $("#infoImage").hide();
368 });