wikimedia/mediawiki-extensions-MobileFrontend

View on GitHub
resources/dist/mobile.special.mobileoptions.scripts.js

Summary

Maintainability
A
0 mins
Test Coverage
(self.webpackChunkmfModules=self.webpackChunkmfModules||[]).push([[898],{"./node_modules/@wikimedia/mediawiki.skins.clientpreferences/clientPreferences.js":e=>{function t(e){return document.documentElement.classList.contains(e+"-clientpref--excluded")}function n(e,t,n,i){const c=n[e],s=c.callback||(()=>{});mw.user.isNamed()?(n[e].options.forEach((t=>{document.documentElement.classList.remove(`${e}-clientpref-${t}`)})),document.documentElement.classList.add(`${e}-clientpref-${t}`),mw.util.debounce((()=>{(i=i||new mw.Api).saveOptions({[c.preferenceKey]:t}).then((()=>{s()}))}),100)()):(mw.user.clientPrefs.set(e,t),s())}const i=(e,t)=>`skin-client-pref-${e}-value-${t}`;function c(e,t,n){const c=document.createElement("input"),s=`skin-client-pref-${t}-group`,o=i(t,n);return c.name=s,c.id=o,c.type=e,"checkbox"===e?c.checked="1"===n:c.value=n,c.setAttribute("data-event-name",o),c}function s(e,t){const n=document.createElement("label");return n.textContent=mw.msg(`${e}-${t}-label`),n.setAttribute("for",i(e,t)),n}const o=e=>mw.message(`${e}-name`);function a(e,i,a,r){const l=o(i);if(l.exists()||"qqx"===mw.config.get("wgUserLanguage")){const d=`skin-client-prefs-${i}`,m=mw.util.addPortlet(d,l.text());if(a[i].betaMessage){const e=function(){const e=document.createElement("span"),t=document.createElement("span");return t.textContent=mw.message("vector-night-mode-beta-tag").text(),e.appendChild(t),e}();m.querySelector(".vector-menu-heading span")||(m.querySelector(".vector-menu-heading").textContent+=" ",m.querySelector(".vector-menu-heading").appendChild(e))}const u=m.querySelector("label"),p=mw.message(`${i}-description`);if(p.exists()){const e=document.createElement("span");e.classList.add("skin-client-pref-description"),e.textContent=p.text(),u&&u.parentNode&&u.appendChild(e)}const f=mw.message(`${i}-exclusion-notice`);if(f.exists()){const e=m.querySelector(".vector-menu-content"),t=document.createElement("span");t.classList.add("skin-client-pref-exclusion-notice"),t.textContent=f.text(),e&&e.appendChild(t)}e.appendChild(m);const g=function(e,i,a){const r=i[e],l=t(e);if(!r)return null;const d=mw.user.clientPrefs.get(e);if("boolean"==typeof d&&!l)return null;const m=function(){const e=document.createElement("div");return e.setAttribute("class",""),e}(),u=document.createElement("form");switch(r.type||"radio"){case"radio":r.options.forEach((o=>{!function(e,i,o,a,r,l){const d=c("radio",i,o);d.classList.add("cdx-radio__input"),a===o&&(d.checked=!0),t(i)&&(d.disabled=!0);const m=document.createElement("span");m.classList.add("cdx-radio__icon");const u=s(i,o);u.classList.add("cdx-radio__label");const p=document.createElement("div");p.classList.add("cdx-radio"),p.appendChild(d),p.appendChild(m),p.appendChild(u),e.appendChild(p),d.addEventListener("change",(()=>{n(i,o,r,l)}))}(u,e,o,String(d),i,a)}));break;case"switch":{const t=document.createElement("label");t.textContent=o(e).text(),function(e,t,i,o,a,r){const l=c("checkbox",t,o);l.classList.add("cdx-toggle-switch__input");const d=document.createElement("span");d.classList.add("cdx-toggle-switch__switch");const m=document.createElement("span");m.classList.add("cdx-toggle-switch__switch__grip"),d.appendChild(m);const u=i||s(t,o);u.classList.add("cdx-toggle-switch__label");const p=document.createElement("span");p.classList.add("cdx-toggle-switch"),p.appendChild(l),p.appendChild(d),p.appendChild(u),l.addEventListener("change",(()=>{n(t,l.checked?"1":"0",a,r)})),e.appendChild(p)}(u,e,t,String(d),i,a);break}default:throw new Error("Unknown client preference! Only switch or radio are supported.")}if(m.appendChild(u),l){const t=function(e){const t=document.createElement("p"),n=mw.message(`${e}-exclusion-notice`);return t.classList.add("exclusion-notice",`${e}-exclusion-notice`),t.textContent=n.text(),t}(e);m.appendChild(t)}return m}(i,a,r);if(g){const e=mw.util.addPortletLink(d,"","");if(e){const t=e.querySelector("a");t&&t.replaceWith(g)}if(a[i].betaMessage&&!t(i)){const e=document.createElement("span");e.id=`${i}-beta-notice`;const t=`[https://${window.location.hostname+mw.util.getUrl(mw.config.get("wgPageName"))} ${mw.config.get("wgTitle")}]`,n=mw.message("vector-night-mode-issue-reporting-preload-title",t).text(),c=mw.msg("vector-night-mode-issue-reporting-notice-url",window.location.host,n),s=mw.message("vector-night-mode-issue-reporting-link-label").text(),o=document.createElement("a");mw.user.isAnon()||(o.setAttribute("href",c),o.setAttribute("target","_blank")),o.textContent=s;const a=function(){const e=document.createElement("span");e.classList.add("vector-icon","vector-icon--heart"),o.textContent=mw.msg("vector-night-mode-issue-reporting-link-notification"),o.classList.add("skin-theme-beta-notice-success"),o.prepend(e),o.removeEventListener("click",a)};o.addEventListener("click",a),e.appendChild(o),g.appendChild(e)}}}}function r(e,t,n){const i=document.querySelector(e);return i?new Promise((e=>{(function(e){const t=Array.from(document.documentElement.classList).filter((e=>e.match(/-clientpref-/))).map((e=>e.split("-clientpref-")[0]));return Object.keys(e).filter((e=>t.indexOf(e)>-1))})(t).forEach((e=>{n=n||new mw.Api,a(i,e,t,n)})),mw.requestIdleCallback((()=>{e(i)}))})):Promise.reject()}e.exports={bind:function(e,t,n,i){let c=!1;const s=document.querySelector(e);s&&(i||(i=new mw.Api),s.checked?(r(t,n,i),c=!0):s.addEventListener("input",(()=>{c||(r(t,n,i),c=!0)})))},toggleDocClassAndSave:n,render:r}},"./src/mobile.special.mobileoptions.scripts.js":(e,t,n)=>{var i,c=n("./node_modules/@wikimedia/mediawiki.skins.clientpreferences/clientPreferences.js"),s=n("./src/mobile.startup/showOnPageReload.js"),o=n("./src/mobile.startup/amcOutreach/amcOutreach.js"),a="mf-expand-sections",r=mw.msg,l="mf-font-size";function d(e){e?s.showOnPageReload(r("mobile-frontend-settings-save")):mw.notify(r("mobile-frontend-settings-save"))}function m(e){return(i=i||new mw.Api).saveOptions(e,{global:"update"})}function u(e,t){var n=document.createElement("div"),i="mf-client-preferences";return n.id=i,e.prepend(n),c.render("#".concat(i),t,{saveOptions:m})}window.QUnit||mw.loader.using("oojs-ui-widgets").then((function(){var e=$("#mobile-options"),t=$("#enable-beta-toggle"),n=$("#enable-amc-toggle"),i=[];t.length&&i.push({$el:t,onToggle:function(){}}),n.length&&i.push({$el:n,onToggle:function(e){!e&&o.loadCampaign().isCampaignActive()&&o.loadCampaign().makeAllActionsIneligible()}}),function(e,t){e.forEach((function(e){var n=e.$el,i=OO.ui.infuse(n),c=i.$element,s=new OO.ui.ToggleSwitchWidget({value:i.isSelected()});s.$element.insertAfter(c),c.hide(),c.on("change",(function(){c.attr("disabled",!0),s.setValue(i.isSelected())})),s.on("change",(function(n){e.onToggle(n),s.setValue=function(){},c.find("input").prop("checked",n),d(!0),setTimeout((function(){t.trigger("submit")}),250)}))}))}(i,e);var c={};mw.config.get("wgMFEnableFontChanger")&&(c[l]={options:["small","regular","large"],preferenceKey:l,callback:d});var s=mw.config.get("skin");function r(e){e.find(".skin-client-pref-description").appendTo(e.find(".cdx-toggle-switch__label")),e.find("> label").remove()}c["skin-theme"]={options:["day","night","os"],preferenceKey:"".concat(s,"-theme")},c[a]={options:["0","1"],type:"switch",preferenceKey:a,callback:d},mw.user.isAnon()||(c["mw-mf-amc"]={options:["0","1"],type:"switch",preferenceKey:"mf_amc_optin",callback:function(){return location.reload()}}),u(e,c).then((function(){$("#amc-field .option-links").appendTo("#skin-client-prefs-mw-mf-amc"),r($("#skin-client-prefs-mf-expand-sections")),r($("#skin-client-prefs-mw-mf-amc")),$("#amc-field").remove()}))})),e.exports={test:{addClientPreferencesToForm:u}}}},e=>{e.O(0,[569],(()=>e(e.s="./src/mobile.special.mobileoptions.scripts.js")));var t=e.O();(this.mfModules=this.mfModules||{})["mobile.special.mobileoptions.scripts"]=t}]);
//# sourceMappingURL=mobile.special.mobileoptions.scripts.js.map.json