mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-12-24 04:53:04 +00:00
381f8f5f7d
This is a precursor to moving the code out to the Cite extension. This can be squashed into parent commit or merged at same time. I've kept the two patches separate to make them easier to review. Bug: T326692 Change-Id: I50dbf28a1078df6c73fd0fbf77480488dd82c7b3
2 lines
5.2 KiB
JavaScript
2 lines
5.2 KiB
JavaScript
(()=>{"use strict";var e="reference",t=!1,n="event.ReferencePreviewsPopups";function r(){return t}var o=document.createElement("template");o.innerHTML='\n<div class="mwe-popups mwe-popups mwe-popups-type-reference" aria-hidden>\n\t<div class="mwe-popups-container">\n\t\t<div class="mwe-popups-extract">\n\t\t\t<div class="mwe-popups-scroll">\n\t\t\t\t<strong class="mwe-popups-title">\n\t\t\t\t\t<span class="popups-icon"></span>\n\t\t\t\t\t<span class="mwe-popups-title-placeholder"></span>\n\t\t\t\t</strong>\n\t\t\t\t<bdi><div class="mw-parser-output"></div></bdi>\n\t\t\t</div>\n\t\t\t<div class="mwe-popups-fade"></div>\n\t\t</div>\n\t\t<footer>\n\t\t\t<div class="mwe-popups-settings"></div>\n\t\t</footer>\n\t</div>\n</div>';var c,s,l=function(e,t){"string"==typeof t?e.insertAdjacentHTML("afterend",t):e.parentNode.appendChild(t),e.remove()};function p(e){var t=e.referenceType||"generic",c=mw.message("popups-refpreview-".concat(t));c.exists()||(c=mw.message("popups-refpreview-reference"));var s=o.content.cloneNode(!0).children[0];l(s.querySelector(".mwe-popups-title-placeholder"),mw.html.escape(c.text())),s.querySelector(".mwe-popups-title .popups-icon").classList.add("popups-icon--reference-".concat(t)),s.querySelector(".mw-parser-output").innerHTML=e.extract,Array.prototype.forEach.call(s.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(s.querySelectorAll(".mw-collapsible"),(function(e){var t=document.createElement("div");t.classList.add("mwe-collapsible-placeholder");var n=document.createElement("span");n.classList.add("popups-icon","popups-icon--infoFilled");var r=document.createElement("span");r.classList.add("mwe-collapsible-placeholder-label"),r.textContent=mw.msg("popups-refpreview-collapsible-placeholder"),t.appendChild(n),t.appendChild(r),l(e,t)}));var p=function(e){e.classList.remove("headerSort"),e.removeAttribute("tabindex"),e.removeAttribute("title")};Array.prototype.forEach.call(s.querySelectorAll("table.sortable"),(function(e){e.classList.remove("sortable","jquery-tablesorter"),Array.prototype.forEach.call(e.querySelectorAll(".headerSort"),p)}));var a=document.createElement("a");a.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 i=document.createElement("span");i.classList.add("popups-icon","popups-icon--size-small","popups-icon--settings");var u=document.createElement("span");return u.textContent=mw.msg("popups-settings-icon-gear-title"),a.append(i),a.append(u),s.querySelector(".mwe-popups-settings").appendChild(a),r()&&s.querySelector(".mw-parser-output").addEventListener("click",(function(e){e.target.matches("a")&&mw.track(n,{action:"clickedReferencePreviewsContentLink"})})),s.querySelector(".mwe-popups-scroll").addEventListener("scroll",(function(e){var t=e.target,o=t.scrollTop>=t.scrollHeight-t.clientHeight-1;if(r()&&(t.isOpenRecorded||(mw.track(n,{action:"poppedOpen",scrollbarsPresent:t.scrollHeight>t.clientHeight}),t.isOpenRecorded=!0),t.scrollTop>0&&!t.isScrollRecorded&&(mw.track(n,{action:"scrolled"}),t.isScrollRecorded=!0)),o||!t.isScrolling){var c=t.parentNode,s=t.scrollWidth>t.clientWidth,l=t.offsetHeight-t.clientHeight,p=t.scrollHeight>t.clientHeight,a=t.offsetWidth-t.clientWidth,i=c.querySelector(".mwe-popups-fade");i.style.bottom=s?"".concat(l,"px"):0,i.style.right=p?"".concat(a,"px"):0,t.isScrolling=!o,c.classList.toggle("mwe-popups-fade-out",t.isScrolling),c.setAttribute("lang",mw.config.get("wgPageContentLanguage"))}})),s}c=mw.config,s=parseInt(c.get("wgPopupsFlags"),10),c.set("wgPopupsConflictsWithRefTooltipsGadget",!!(2&s)),c.set("wgPopupsReferencePreviews",!!(4&s));var a=function(t,n,r){return r.get("wgPopupsReferencePreviews")?r.get("wgPopupsConflictsWithRefTooltipsGadget")||r.get("wgPopupsConflictsWithNavPopupGadget")||"minerva"===r.get("skin")?null:t.isAnon()?n(e):"1"===t.options.get("popups-reference-previews")||null:null}(mw.user,mw.popups.isEnabled,mw.config),i={fetchPreviewForTitle:function(t,n){var r=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"))}(r);if(!o||!o.textContent.trim()&&!o.children.length)return Promise.reject({textStatus:"abort",textContext:"Footnote not found or empty",xhr:{readyState:0}});var c,s,l,p,a={url:"#".concat(r),extract:o.innerHTML,type:e,referenceType:(c=o,s=["book","journal","news","note","web"],l=null,p=c.querySelectorAll("cite[class]"),Array.prototype.forEach.call(p,(function(e){if(!l)for(var t=e.className.split(/\s+/),n=t.length;n--;)if(-1!==s.indexOf(t[n]))return l=t[n],!1})),l),sourceElementId:n.parentNode.id},i=Promise.resolve(a);return i.abort=function(){},i}};window.refPreviews=null!==a?{type:e,selector:'#mw-content-text .reference a[ href*="#" ]',delay:150,gateway:i,renderFn:function(e){return{el:p(e),hasThumbnail:!1,isTall:!1}},init:function(){mw.config.get("wgPopupsReferencePreviews")&&navigator.sendBeacon&&mw.config.get("wgIsArticle")&&!t&&(t=!0,mw.track(n,{action:"pageview"}))}}:null})();
|
|
//# sourceMappingURL=referencePreviews.js.map.json
|