MediaWiki:Gadget-skinTogglesMobile.js: Difference between revisions

From RuneRealm Wiki
Jump to navigation Jump to search
Content added Content deleted
No edit summary
Tag: Manual revert
No edit summary
 
Line 1: Line 1:
"use strict";

/**
/**
* Toggles for skin cookies on mobile
* Toggles for skin cookies on mobile
Line 6: Line 8:
*/
*/


const DARK_COOKIE = 'darkmode';
var DARK_COOKIE = 'darkmode';
var currentDark = $.cookie('theme') === 'dark' || ($.cookie('theme') == null && $.cookie(DARK_COOKIE) === 'true'),
var currentDark = $.cookie('theme') === 'dark' || $.cookie('theme') == null && $.cookie(DARK_COOKIE) === 'true',
darkPortletLink;
darkPortletLink;

var self = {
var self = {
init: function () {
init: function init() {
darkPortletLink = mw.util.addPortletLink('p-personal', '#', (currentDark ? 'Light' : 'Dark') + ' mode', 'wgl-darkmode-toggle', 'Toggle ' + (currentDark ? 'light' : 'dark') + ' mode', null, $('a.menu__item--logout').closest('li'));
darkPortletLink = mw.util.addPortletLink(
$('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
'p-personal',
$.cookie('theme', currentDark ? 'dark' : 'light', {
'#',
expires: 365,
(currentDark ? 'Light' : 'Dark') + ' mode',
path: '/'
'wgl-darkmode-toggle',
});
'Toggle ' + (currentDark ? 'light' : 'dark') + ' mode',
$(darkPortletLink).click(function (e) {
null,
e.preventDefault();
$('a.menu__item--logout').closest('li')
currentDark = !currentDark;
);
$('#wgl-darkmode-toggle .toggle-list-item__label').text((currentDark ? 'Light' : 'Dark') + ' mode');
$('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
$.cookie('theme', currentDark ? 'dark' : 'light', {
expires: 365,

$.cookie('theme', currentDark ? 'dark' : 'light', {expires: 365, path: '/'});
path: '/'
});
$.cookie(DARK_COOKIE, currentDark, {
$(darkPortletLink).click(function (e) {
expires: 365,
e.preventDefault();
path: '/'
currentDark = !currentDark;
});
$('#wgl-darkmode-toggle .toggle-list-item__label').text((currentDark ? 'Light' : 'Dark') + ' mode');
$.cookie('theme', currentDark ? 'dark' : 'light', {expires: 365, path: '/'});
$('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
if (currentDark) {
$.cookie(DARK_COOKIE, currentDark, {expires: 365, path: '/'});
mw.loader.using(['wgl.theme.dark']).then(function () {
$('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
$('body').addClass('wgl-theme-dark').removeClass('wgl-theme-light');
});
if (currentDark) {
} else {
mw.loader.using(['wgl.theme.dark']).then(function() {
$('body').addClass('wgl-theme-dark').removeClass('wgl-theme-light')
$('body').addClass('wgl-theme-light').removeClass('wgl-theme-dark');
}
});
mw.notify('Switched to ' + (currentDark ? 'dark' : 'light') + ' mode!', {
} else {
tag: 'wg-darkmode-notification'
$('body').addClass('wgl-theme-light').removeClass('wgl-theme-dark')
});
}
});
mw.notify( 'Switched to ' + (currentDark ? 'dark' : 'light') + ' mode!', { tag: 'wg-darkmode-notification' } );
}
});
},
};
}

$(self.init);
$(self.init);

Latest revision as of 12:06, 20 October 2024

"use strict";

/**
 * Toggles for skin cookies on mobile
 * 
 * @author JaydenKieran
 * 
 */

var DARK_COOKIE = 'darkmode';
var currentDark = $.cookie('theme') === 'dark' || $.cookie('theme') == null && $.cookie(DARK_COOKIE) === 'true',
  darkPortletLink;
var self = {
  init: function init() {
    darkPortletLink = mw.util.addPortletLink('p-personal', '#', (currentDark ? 'Light' : 'Dark') + ' mode', 'wgl-darkmode-toggle', 'Toggle ' + (currentDark ? 'light' : 'dark') + ' mode', null, $('a.menu__item--logout').closest('li'));
    $('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
    $.cookie('theme', currentDark ? 'dark' : 'light', {
      expires: 365,
      path: '/'
    });
    $(darkPortletLink).click(function (e) {
      e.preventDefault();
      currentDark = !currentDark;
      $('#wgl-darkmode-toggle .toggle-list-item__label').text((currentDark ? 'Light' : 'Dark') + ' mode');
      $.cookie('theme', currentDark ? 'dark' : 'light', {
        expires: 365,
        path: '/'
      });
      $.cookie(DARK_COOKIE, currentDark, {
        expires: 365,
        path: '/'
      });
      $('meta[name="theme-color"]').attr('content', currentDark ? '#071022' : '#c0a886');
      if (currentDark) {
        mw.loader.using(['wgl.theme.dark']).then(function () {
          $('body').addClass('wgl-theme-dark').removeClass('wgl-theme-light');
        });
      } else {
        $('body').addClass('wgl-theme-light').removeClass('wgl-theme-dark');
      }
      mw.notify('Switched to ' + (currentDark ? 'dark' : 'light') + ' mode!', {
        tag: 'wg-darkmode-notification'
      });
    });
  }
};
$(self.init);