mediawiki-extensions-Popups/resources/dist/referencePreviews.js
Jon Robson 59c6b8e88f Reference previews should use Popups registration
* Adds a new webpack entry point for references previews
* Reference related code in src/index.js is moved to new
file resources/ext.popups.referencePreviews/index.js

The changes:
* References previews now in its own module ext.popups.referencePreviews
* Loaded via getCustomPopupTypes
* OWNERS.md files make clear which team owns which part of the code.

Bug: T326692
Change-Id: Iea8a5b9221c0b1fd41e40bff2cbe01e42124d53f
2024-01-16 11:38:08 +01:00

2 lines
7.1 KiB
JavaScript

(()=>{var e={"./src/canSaveToUserPreferences.js":e=>{e.exports=function(e){return!e.isAnon()&&e.isNamed()}},"./src/ui/pointer-mask.svg":e=>{e.exports='<svg xmlns="http://www.w3.org/2000/svg" width="0" height="0"><defs><clipPath id="mwe-popups-mask"><path d="M0 8h10l8-8 8 8h974v992H0z"></path></clipPath><clipPath id="mwe-popups-mask-flip"><path d="M0 8h294l8-8 8 8h690v992H0z"></path></clipPath><clipPath id="mwe-popups-landscape-mask"><path d="M0 8h174l8-8 8 8h810v992H0z"></path></clipPath><clipPath id="mwe-popups-landscape-mask-flip"><path d="M0 0h1000v242H190l-8 8-8-8H0z"></path></clipPath></defs></svg>'}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var s=t[n]={exports:{}};return e[n](s,s.exports,r),s.exports}(()=>{"use strict";var e="reference",t=r("./src/canSaveToUserPreferences.js"),n=!1,o="event.ReferencePreviewsPopups";function s(){return n}var a={};function p(e){if(!a[e]){var t=document.createElement("div");t.innerHTML=e,a[e]=t.firstElementChild}return a[e].cloneNode(!0)}var c=function(e,t){"string"==typeof t?e.insertAdjacentHTML("afterend",t):e.parentNode.appendChild(t),e.remove()};function i(e){var t=e.referenceType||"generic",r=mw.message("popups-refpreview-".concat(t));r.exists()||(r=mw.message("popups-refpreview-reference"));var n,a=function(e,t){var r=p('\n\t<div class="mwe-popups" aria-hidden></div>\n');return r.className="mwe-popups mwe-popups-type-".concat(e),t.className="mwe-popups-container",r.appendChild(t),r}(e.type,p('\n<div class="mwe-popups-container">\n <div class="mwe-popups-extract">\n <div class="mwe-popups-scroll">\n <strong class="mwe-popups-title">\n <span class="popups-icon"></span>\n <span class="mwe-popups-title-placeholder"></span>\n </strong>\n <bdi><div class="mw-parser-output"></div></bdi>\n </div>\n <div class="mwe-popups-fade"></div>\n </div>\n\t<footer>\n\t\t<div class="mwe-popups-settings"></div>\n\t</footer>\n</div>'));c(a.querySelector(".mwe-popups-title-placeholder"),(n=r.text(),mw.html.escape(n))),a.querySelector(".mwe-popups-title .popups-icon").classList.add("popups-icon--reference-".concat(t)),a.querySelector(".mw-parser-output").innerHTML=e.extract,Array.prototype.forEach.call(a.querySelectorAll('.mwe-popups-extract a[href][class~="external"]:not([target])'),(function(e){e.target="_blank",e.rel="".concat(e.rel?"".concat(e.rel," "):"","noopener")})),Array.prototype.forEach.call(a.querySelectorAll(".mw-collapsible"),(function(e){var t=document.createElement("div");t.classList.add("mwe-collapsible-placeholder");var r=document.createElement("span");r.classList.add("popups-icon","popups-icon--infoFilled");var n=document.createElement("span");n.classList.add("mwe-collapsible-placeholder-label"),n.textContent=mw.msg("popups-refpreview-collapsible-placeholder"),t.appendChild(r),t.appendChild(n),c(e,t)}));var i=function(e){e.classList.remove("headerSort"),e.removeAttribute("tabindex"),e.removeAttribute("title")};Array.prototype.forEach.call(a.querySelectorAll("table.sortable"),(function(e){e.classList.remove("sortable","jquery-tablesorter"),Array.prototype.forEach.call(e.querySelectorAll(".headerSort"),i)}));var l=document.createElement("a");l.classList.add("cdx-button","cdx-button--fake-button","cdx-button--fake-button--enabled","cdx-button--weight-quiet","cdx-button--icon-only","mwe-popups-settings-button");var u=document.createElement("span");u.classList.add("popups-icon","popups-icon--size-small","popups-icon--settings");var d=document.createElement("span");return d.textContent=mw.msg("popups-settings-icon-gear-title"),l.append(u),l.append(d),a.querySelector(".mwe-popups-settings").appendChild(l),s()&&a.querySelector(".mw-parser-output").addEventListener("click",(function(e){e.target.matches("a")&&mw.track(o,{action:"clickedReferencePreviewsContentLink"})})),a.querySelector(".mwe-popups-scroll").addEventListener("scroll",(function(e){var t=e.target,r=t.scrollTop>=t.scrollHeight-t.clientHeight-1;if(s()&&(t.isOpenRecorded||(mw.track(o,{action:"poppedOpen",scrollbarsPresent:t.scrollHeight>t.clientHeight}),t.isOpenRecorded=!0),t.scrollTop>0&&!t.isScrollRecorded&&(mw.track(o,{action:"scrolled"}),t.isScrollRecorded=!0)),r||!t.isScrolling){var n=t.parentNode,a=t.scrollWidth>t.clientWidth,p=t.offsetHeight-t.clientHeight,c=t.scrollHeight>t.clientHeight,i=t.offsetWidth-t.clientWidth,l=n.querySelector(".mwe-popups-fade");l.style.bottom=a?"".concat(p,"px"):0,l.style.right=c?"".concat(i,"px"):0,t.isScrolling=!r,n.classList.toggle("mwe-popups-fade-out",t.isScrolling),n.setAttribute("lang",mw.config.get("wgPageContentLanguage"))}})),a}r("./src/ui/pointer-mask.svg");var l=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:window.devicePixelRatio;return e?e>1.5?2:e>1?1.5:1:1}();Math.max(l,1.5);var u,d,m={TYPE_GENERIC:"generic",TYPE_PAGE:"page",TYPE_DISAMBIGUATION:"disambiguation"},v="mwe-popups-enabled",f="mwe-popups-referencePreviews-enabled";u=mw.config,d=parseInt(u.get("wgPopupsFlags"),10),u.set("wgPopupsConflictsWithRefTooltipsGadget",!!(2&d)),u.set("wgPopupsReferencePreviews",!!(4&d));var w,g=(w=mw.storage,{migrateOldPreferences:function(){!!w.get(v)&&(w.remove(v),this.storePreviewTypeEnabled(m.TYPE_PAGE,!1)),w.get(f)&&(w.remove(f),this.storePreviewTypeEnabled(m.TYPE_REFERENCE,!1))},isPreviewTypeEnabled:function(e){var t="mwe-popups-".concat(e,"-enabled");return null===w.get(t)},storePreviewTypeEnabled:function(e,t){e===m.TYPE_REFERENCE&&mw.track("event.ReferencePreviewsPopups",{action:t?"anonymousEnabled":"anonymousDisabled"});var r="mwe-popups-".concat(e,"-enabled");t?w.remove(r):w.set(r,"0")}}),h=function(r,n,o){return o.get("wgPopupsReferencePreviews")?o.get("wgPopupsConflictsWithRefTooltipsGadget")||o.get("wgPopupsConflictsWithNavPopupGadget")||"minerva"===o.get("skin")?null:t(r)?"1"===r.options.get("popups-reference-previews")||null:n.isPreviewTypeEnabled(e):null}(mw.user,g,mw.config),P={fetchPreviewForTitle:function(t,r){var n=t.getFragment().replace(/ /g,"_"),o=function(e){var t="#".concat(CSS.escape(e));return document.querySelector("".concat(t," .mw-reference-text, ").concat(t," .reference-text"))}(n);if(!o||!o.textContent.trim()&&!o.children.length)return Promise.reject({textStatus:"abort",textContext:"Footnote not found or empty",xhr:{readyState:0}});var s,a,p,c,i={url:"#".concat(n),extract:o.innerHTML,type:e,referenceType:(s=o,a=["book","journal","news","note","web"],p=null,c=s.querySelectorAll("cite[class]"),Array.prototype.forEach.call(c,(function(e){if(!p)for(var t=e.className.split(/\s+/),r=t.length;r--;)if(-1!==a.indexOf(t[r]))return p=t[r],!1})),p),sourceElementId:r.parentNode.id};return function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};return e.promise?e.promise({abort:t}):(e.abort=t,e)}(Promise.resolve(i))}};window.refPreviews=null!==h?{type:e,selector:'#mw-content-text .reference a[ href*="#" ]',delay:150,gateway:P,renderFn:function(e){return{el:i(e),hasThumbnail:!1,isTall:!1}},init:function(){mw.config.get("wgPopupsReferencePreviews")&&navigator.sendBeacon&&mw.config.get("wgIsArticle")&&!n&&(n=!0,mw.track(o,{action:"pageview"}))}}:null})()})();
//# sourceMappingURL=referencePreviews.js.map.json