- md5
- 5fb07d0b85a61ebca36dbe85c14cb1ce
- sha1
- bb9a5f54654e9fcaff264ea23f66b3feb4284b89
- sha256
- bd2b0092e177de7a5be0fa695762b25108dd19b6e1f99f9a076ca6c1f779e35a
/**
* @copyright (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/if(!Joomla)throw new Error("Joomla API is not properly initialised");const allowList={button:["type"],input:["type","name","placeholder","inputmode"],select:["name"],option:["value","selected"]},webInstallerOptions={view:"dashboard",id:0,ordering:"",version:"current",list:0,options:Joomla.getOptions("plg_installer_webinstaller",{})};let instance;class WebInstaller{initialise(){webInstallerOptions.loaded=1,document.getElementById("uploadform-web-cancel").addEventListener("click",()=>{document.getElementById("uploadform-web").classList.add("hidden"),webInstallerOptions.list&&document.querySelector(".list-view")&&document.querySelector(".list-view").click()}),document.getElementById("uploadform-web-install").addEventListener("click",()=>{webInstallerOptions.options.installFrom===4?this.submitButtonUrl():this.submitButtonWeb()}),this.loadweb(`${webInstallerOptions.options.base_url}index.php?format=json&option=com_apps&view=dashboard`),this.clickforlinks()}loadweb(e){if(!e)return!1;const t=new RegExp(webInstallerOptions.options.base_url),s=/^index\.php/;if(!(t.test(e)||s.test(e)))return window.open(e,"_blank"),!1;let d=`${e}&product=${webInstallerOptions.options.product}&release=${webInstallerOptions.options.release}&dev_level=${webInstallerOptions.options.dev_level}&list=${webInstallerOptions.list?"list":"grid"}&lang=${webInstallerOptions.options.language}`;const u=document.getElementById("com-apps-ordering"),p=document.getElementById("com-apps-filter-joomla-version");return webInstallerOptions.ordering!==""&&u&&u.value&&(webInstallerOptions.ordering=u.value,d+=`&ordering=${webInstallerOptions.ordering}`),webInstallerOptions.version!==""&&p&&p.value&&(webInstallerOptions.version=p.value,d+=`&filter_version=${webInstallerOptions.version}`),WebInstaller.showLoadingLayer(),new Promise((m,o)=>{Joomla.request({url:d,onSuccess:i=>{let r;try{r=JSON.parse(i)}catch{throw new Error("Failed to parse JSON")}document.getElementById("web-loader")&&document.getElementById("web-loader").classList.add("hidden");const c=document.getElementById("jed-container");c.innerHTML=Joomla.sanitizeHtml(r.data.html,allowList),(webInstallerOptions.view==="extension"||webInstallerOptions.view==="category")&&window.scrollTo(0,0),document.getElementById("com-apps-searchbox").addEventListener("keydown",({code:n})=>{n==="Enter"&&this.initiateSearch()}),document.getElementById("search-extensions").addEventListener("click",()=>{this.initiateSearch()}),document.getElementById("search-reset").addEventListener("click",()=>{const n=document.getElementById("com-apps-searchbox");n.value="",this.initiateSearch(),document.getElementById("search-reset").setAttribute("disabled","disabled")}),document.getElementById("com-apps-searchbox").value===""&&document.getElementById("search-reset").setAttribute("disabled","disabled"),document.getElementById("search-reset").innerHTML=Joomla.sanitizeHtml(Joomla.Text._("JSEARCH_FILTER_CLEAR"));const l=document.getElementById("com-apps-ordering"),a=document.getElementById("com-apps-filter-joomla-version");l&&l.addEventListener("change",()=>{const n=l.selectedIndex;webInstallerOptions.ordering=l.options[n].value,this.installfromwebajaxsubmit()}),a&&a.addEventListener("change",()=>{const n=a.selectedIndex;webInstallerOptions.version=a.options[n].value,this.installfromwebajaxsubmit()}),webInstallerOptions.options.installfrom_url!==""&&WebInstaller.installfromweb(webInstallerOptions.options.installfrom_url),m()},onError:i=>{const r=document.getElementById("web-loader-error"),c=document.getElementById("web-loader");i.responseText&&r&&(r.innerHTML=Joomla.sanitizeHtml(i.responseText)),c&&(c.classList.add("hidden"),r.classList.remove("hidden")),Joomla.renderMessages({danger:[Joomla.Text._("PLG_INSTALLER_WEBINSTALLER_INSTALL_WEB_LOADING_ERROR")]},"#web-loader-error"),o()}})}).finally(()=>{const m=document.getElementById("joomlaapsinstallatinput");if(m&&(m.value=webInstallerOptions.options.installat_url),this.clickforlinks(),WebInstaller.clicker(),webInstallerOptions.view!=="extension"&&document.querySelectorAll("div.load-extension").forEach(o=>{o.addEventListener("click",i=>{i.preventDefault(),this.processLinkClick(o.getAttribute("data-url"))}),o.setAttribute("href","#")}),webInstallerOptions.view==="extension"){const o=document.getElementById("install-extension"),i=document.getElementById("install-extension-from-external");o&&o.addEventListener("click",()=>{WebInstaller.installfromweb(o.getAttribute("data-downloadurl"),o.getAttribute("data-name")),document.getElementById("uploadform-web-install").scrollIntoView({behavior:"smooth",block:"start"})}),i&&i.addEventListener("click",()=>{const r=i.getAttribute("data-downloadurl");if(window.confirm(Joomla.Text._("PLG_INSTALLER_WEBINSTALLER_REDIRECT_TO_EXTERNAL_SITE_TO_INSTALL").replace("[SITEURL]",r))!==!0)return;const l=document.createElement("form");l.setAttribute("method","post"),l.setAttribute("action",r),["installat","installfrom","installapp"].forEach(a=>{const n=document.createElement("input");n.setAttribute("type","hidden"),n.setAttribute("name",a),n.setAttribute("value",document.getElementById("adminForm").querySelector(`[name="${a}"]`).value),l.appendChild(n)}),document.body.appendChild(l),l.submit()})}webInstallerOptions.list&&document.querySelector(".list-view")&&document.querySelector(".list-view").click(),WebInstaller.hideLoadingLayer()}),!0}clickforlinks(){document.querySelectorAll("a.transcode").forEach(e=>{const t=e.getAttribute("href");e.addEventListener("click",s=>{s.preventDefault(),this.processLinkClick(t)}),e.setAttribute("href","#")})}initiateSearch(){document.getElementById("search-reset").removeAttribute("disabled"),webInstallerOptions.view="dashboard",this.installfromwebajaxsubmit()}installfromwebajaxsubmit(){let e=`&view=${webInstallerOptions.view}`;if(webInstallerOptions.id&&(e+=`&id=${webInstallerOptions.id}`),document.getElementById("com-apps-searchbox").value){const d=encodeURI(document.getElementById("com-apps-searchbox").value.toLowerCase().replace(/ +/g,"_").replace(/[^a-z0-9-_]/g,"").trim());e+=`&filter_search=${d}`}const t=document.getElementById("com-apps-ordering"),s=document.getElementById("com-apps-filter-joomla-version");webInstallerOptions.ordering!==""&&t&&t.value&&(webInstallerOptions.ordering=t.value),webInstallerOptions.ordering&&(e+=`&ordering=${webInstallerOptions.ordering}`),webInstallerOptions.version!==""&&s&&s.value&&(webInstallerOptions.version=s.value),webInstallerOptions.version&&(e+=`&filter_version=${webInstallerOptions.version}`),this.loadweb(`${webInstallerOptions.options.base_url}index.php?format=json&option=com_apps${e}`)}processLinkClick(e){const t=new RegExp(webInstallerOptions.options.base_url),s=/^index\.php/;t.test(e)||s.test(e)?(webInstallerOptions.view=e.replace(/^.+[&?]view=(\w+).*$/,"$1"),webInstallerOptions.view==="dashboard"?webInstallerOptions.id=0:webInstallerOptions.view==="category"&&(webInstallerOptions.id=e.replace(/^.+[&?]id=(\d+).*$/,"$1")),this.loadweb(webInstallerOptions.options.base_url+e)):this.loadweb(e)}static showLoadingLayer(){document.getElementById("web").appendChild(document.createElement("joomla-core-loader"))}static hideLoadingLayer(){const e=document.querySelector("#web joomla-core-loader");e.parentNode.removeChild(e)}static clicker(){document.querySelector(".grid-view")&&document.querySelector(".grid-view").addEventListener("click",()=>{webInstallerOptions.list=0,document.querySelector(".list-container").classList.add("hidden"),document.querySelector(".grid-container").classList.remove("hidden"),document.getElementById("btn-list-view").classList.remove("active"),document.getElementById("btn-grid-view").classList.remove("active")}),document.querySelector(".list-view")&&document.querySelector(".list-view").addEventListener("click",()=>{webInstallerOptions.list=1,document.querySelector(".grid-container").classList.add("hidden"),document.querySelector(".list-container").classList.remove("hidden"),document.getElementById("btn-grid-view").classList.remove("active"),document.getElementById("btn-list-view").classList.add("active")})}static installfromweb(e,t=null){return e?(document.getElementById("install_url").value=e,document.getElementById("uploadform-web-url").innerText=e,t?(document.getElementById("uploadform-web-name").innerText=t,document.getElementById("uploadform-web-name-label").classList.remove("hidden")):document.getElementById("uploadform-web-name-label").classList.add("hidden"),document.getElementById("uploadform-web").classList.remove("hidden"),!0):(Joomla.renderMessages({warning:[Joomla.Text._("PLG_INSTALLER_WEBINSTALLER_CANNOT_INSTALL_EXTENSION_IN_PLUGIN")]}),!1)}submitButtonUrl(){const e=document.getElementById("adminForm");if(e.install_url.value===""||e.install_url.value==="http://"||e.install_url.value==="https://")Joomla.renderMessages({warning:[Joomla.Text._("COM_INSTALLER_MSG_INSTALL_ENTER_A_URL")]});else{const t=document.getElementById("loading");t&&t.classList.remove("hidden"),e.installtype.value="url",e.submit()}}submitButtonWeb(){const e=document.getElementById("adminForm");e.install_url.value!==""||e.install_url.value!=="http://"||e.install_url.value!=="https://"?this.submitButtonUrl():e.install_url.value===""?Joomla.renderMessages({warning:[Joomla.apps.options.btntxt]}):(document.querySelector("#appsloading").classList.remove("hidden"),e.installtype.value="web",e.submit())}}customElements.whenDefined("joomla-tab").then(()=>{const e=document.getElementById("myTab").querySelector("button[aria-controls=web]");e&&(webInstallerOptions.options.installfromon&&e.click(),e.hasAttribute("aria-selected")&&e.getAttribute("aria-selected")==="true"&&!instance&&(instance=new WebInstaller,instance.initialise()),webInstallerOptions.options.installfrom_url!==""&&e.click(),e.addEventListener("joomla.tab.shown",()=>{instance||(instance=new WebInstaller,instance.initialise())}))});
The same content is in 2 releases, Joomla 6.2.1 to 6.3.0-alpha1. See them all, or every version of this file.