MediaWiki:Gadget-skinTogglesMobile.js

From Old School Near-Reality Wiki
Revision as of 18:47, 3 October 2022 by Jacmob (talk | contribs) (Created page with "→‎* * Toggles for skin cookies on mobile * * @author JaydenKieran *: ;(function($, mw, rs){ var DARK_COOKIE = 'darkmode', currentDark = $.cookie(DARK_COOKIE) === 'true', darkPortletLink; var self = { init: function () { darkPortletLink = mw.util.addPortletLink( 'p-personal', '#', (currentDark ? 'Light' : 'Dark') + ' mode', 'wgl-darkmode-toggle', 'Toggle ' + (currentDark ? 'light' : 'dark') + ' mode', null, $('a.menu__item-...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
 1 /**
 2  * Toggles for skin cookies on mobile
 3  * 
 4  * @author JaydenKieran
 5  * 
 6  */
 7 ;(function($, mw, rs){
 8 	var DARK_COOKIE = 'darkmode',
 9 		currentDark = $.cookie(DARK_COOKIE) === 'true',
10 		darkPortletLink;
11 
12 	var self = {
13 		init: function () {
14 			darkPortletLink = mw.util.addPortletLink(
15 				'p-personal',
16 				'#',
17 				(currentDark ? 'Light' : 'Dark') + ' mode',
18 				'wgl-darkmode-toggle',
19 				'Toggle ' + (currentDark ? 'light' : 'dark') + ' mode',
20 				null,
21 				$('a.menu__item--logout').closest('li')
22 			);
23 			
24 			$('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
25 			
26 			$(darkPortletLink).click(function () {
27 				currentDark = !currentDark;
28 				$('#wgl-darkmode-toggle span:not(.mw-ui-icon)').text((currentDark ? 'Light' : 'Dark') + ' mode');
29 				$.cookie(DARK_COOKIE, currentDark, {expires: 365, path: '/'});
30 				if (currentDark) {
31 					mw.loader.using(['wg.darkmode']).then(function() {
32 						$('body').addClass('wgl-darkmode').removeClass('wgl-lightmode')
33 						$('meta[name="theme-color"]').attr('content', '#071022' );
34 					});
35 				} else {
36 					$('body').addClass('wgl-lightmode').removeClass('wgl-darkmode')
37 					$('meta[name="theme-color"]').attr('content', '#c0a886' );
38 
39 				}
40 				mw.notify( 'Switched to ' + (currentDark ? 'dark' : 'light') + ' mode!', { tag: 'wg-darkmode-notification' } );
41 			});
42 		},
43 	}
44 
45 	$(self.init);
46 
47 }(jQuery, mediaWiki, rswiki));