From 3f7adba43e0be2f94872fd4908e14ce04de64fa3 Mon Sep 17 00:00:00 2001 From: Ingolf Steinhardt Date: Mon, 7 Oct 2024 21:53:01 +0200 Subject: [PATCH] Fix JS for toggle icons and dark mode support --- src/Resources/public/js/generalDriver.js | 2 +- src/Resources/public/js/generalDriver.js.map | 2 +- src/Resources/public/js/generalDriver_src.js | 53 ++++++++++++++------ 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/Resources/public/js/generalDriver.js b/src/Resources/public/js/generalDriver.js index 9371cca9..8e1e4b8e 100644 --- a/src/Resources/public/js/generalDriver.js +++ b/src/Resources/public/js/generalDriver.js @@ -1,2 +1,2 @@ -var BackendGeneral={loadSubTree:function(e,t){e.blur();var l=t.toggler,n=t.level,s=t.mode,a=$(l),i=$(e).getFirst("img");return t.action="DcGeneralLoadSubTree",t.REQUEST_TOKEN=Contao.request_token,a?("none"==a.getStyle("display")?(a.setStyle("display","inline"),i.src=i.src.replace("folPlus.svg","folMinus.svg"),$(e).store("tip:title",Contao.lang.collapse),new Request.Contao({url:t.url,field:e}).post(t)):(a.setStyle("display","none"),i.src=i.src.replace("folMinus.svg","folPlus.svg"),$(e).store("tip:title",Contao.lang.expand),new Request.Contao({url:t.url,field:e}).post(t)),!1):(new Request.Contao({url:t.url,field:e,evalScripts:!0,onRequest:AjaxRequest.displayBox(Contao.lang.loading+" …"),onSuccess:function(t,a){var r=new Element("li",{id:l,class:"parent",styles:{display:"inline"}});new Element("ul",{class:"level_"+n,html:t}).inject(r,"bottom");if(5==s)r.inject($(e).getParent("li"),"after");else{var o=$(e).getParent("li");r.inject(o,"after")}r.getElements("a").each((function(e){e.href=e.href.replace(/&ref=[a-f0-9]+/,"&ref="+Contao.referer_id)})),$(e).store("tip:title",Contao.lang.collapse),i.src=i.src.replace("folPlus.svg","folMinus.svg"),window.fireEvent("structure"),AjaxRequest.hideBox(),window.fireEvent("ajax_change")}}).post(t),!1)},toggleVisibility:function(e,t,l){e.blur();var n="dark"===document.documentElement.dataset.colorScheme?"--dark":"";t||(t="visible"+n+".svg"),l||(l="invisible"+n+".svg");var s,a,i=null,r="dark"===document.documentElement.dataset.colorScheme?$(e).getFirst("img"):$(e).getLast("img"),o=-1!==r.src.indexOf(l),c=e.getParent("div");return console.log(r.src+" - "+r.src.indexOf(l)),new Request.Contao({url:$(e).href,followRedirects:!1,onSuccess:function(){var n;(c.hasClass("tl_right")?i=c.getPrevious("div").getElement("img"):c.hasClass("tl_listing_container")?(null==(i=e.getParent("td").getPrevious("td").getFirst("div.list_icon"))&&(i=e.getParent("td").getPrevious("td").getElement("div.cte_type")),null==i&&(i=e.getParent("tr").getFirst("td").getElement("div.list_icon_new"))):(s=c.getNext("div"))&&s.hasClass("cte_type")&&(i=s),null===i&&(a=e.getParent().getParent().getElements("div.list_icon").getFirst().getParent())&&(i=a[0]),null!=i)&&("img"==i.nodeName.toLowerCase()?i.getParent("ul.tl_listing").hasClass("tl_tree_xtnd")?i.src=o?i.src.replace(/_1\.(gif|png|jpe?g)/,".$1"):i.src.replace(/\.(gif|png|jpe?g)/,"_1.$1"):(i.src.match(/folPlus|folMinus/)&&(i=i.getParent("a").getNext("a")?i.getParent("a").getNext("a").getFirst("img"):new Element("img")),o?(n=i.src.replace(/.*_([0-9])\.(gif|png|jpe?g)/,"$1"),i.src=i.src.replace(/_[0-9]\.(gif|png|jpe?g)/,(1==n.toInt()?"":"_"+(n.toInt()-1))+".$1")):(n=i.src.replace(/.*_([0-9])\.(gif|png|jpe?g)/,"$1"),i.src=i.src.replace(/(_[0-9])?\.(gif|png|jpe?g)/,(n==i.src?"_1":"_"+(n.toInt()+1))+".$2"))):i.hasClass("cte_type")?o?(i.addClass("published"),i.removeClass("unpublished")):(i.addClass("unpublished"),i.removeClass("published")):o?i.setStyle("background-image",i.getStyle("background-image").replace(/_\.(gif|png|jpe?g)/,".$1")):i.setStyle("background-image",i.getStyle("background-image").replace(/\.(gif|png|jpe?g)/,"_.$1")));r.src=o?r.src.replace(l,t):r.src.replace(t,l)}}).get({state:o?1:0}),!1},setLegendState:function(e,t,l){e.blur();var n=$("pal_"+t);return n.hasClass("collapsed")?(n.removeClass("collapsed"),(new Request.Contao).post({action:"setLegendState",legend:t,table:l,state:1,REQUEST_TOKEN:Contao.request_token})):(n.addClass("collapsed"),(new Request.Contao).post({action:"setLegendState",legend:t,table:l,state:0,REQUEST_TOKEN:Contao.request_token})),!1},displayMessage:function(e,t,l){var n=$("general_messageBox"),s=$("general_messageOverlay"),a=window.getScroll();null===s&&(s=new Element("div",{id:"general_messageOverlay"}).inject($(document.body),"bottom")),s.set({styles:{display:"block",top:a.y+"px"}}),null===n&&(n=new Element("div",{id:"general_messageBox"}).inject($(document.body),"bottom")),n.set({html:e,styles:{display:"block",top:a.y+100+"px"}}),l&&n.addClass(l),t&&n.addClass("loading")},hideMessage:function(){var e=$("general_messageBox"),t=$("general_messageOverlay");t&&t.setStyle("display","none"),e&&e.setStyle("display","none"),t.remove(),e.remove()},confirmSelectOverrideEditAll:function(e,t,l){e.blur();var n=e.form.elements[t],s=!1;return $$(n).each((function(e){if(s||!e.checked)return!0;s=!0})),s?("delete"===e.name||(e.onclick="",e.click()),!0):(this.displayMessage(l,!1,"box-small"),!1)},confirmSelectDeleteAll:function(e,t,l,n,s,a){return e.blur(),!!this.confirmSelectOverrideEditAll(e,t,l)&&(this.confirmDelete(e,n,s,a),!0)},confirmDelete:function(e,t,l,n){var s=new Element("div"),a=(new Element("h2",{html:t,class:"tl_info"}).inject(s,"bottom"),new Element("p").inject(s,"bottom"),new Element("div",{class:"tl_submit_container"}).inject(s,"bottom")),i=new Element("input",{id:e.name+"Ok",name:e.name+"Ok",value:l,type:"submit",class:"tl_submit"}).inject(a,"bottom"),r=new Element("input",{id:e.name+"Abort",name:e.name+"Abort",value:n,type:"submit",class:"tl_submit"}).inject(a,"bottom");return this.displayMessage(s.get("html"),!1,"box-small"),$(i.id).addEvent("click",(function(){e.onclick="",e.click()})),$(r.id).addEvent("click",(function(){BackendGeneral.hideMessage()})),!0}}; +var BackendGeneral={loadSubTree:function(e,t){e.blur();var l=t.toggler,n=t.level,s=t.mode,a=$(l),i=$(e).getFirst("img");return t.action="DcGeneralLoadSubTree",t.REQUEST_TOKEN=Contao.request_token,a?("none"==a.getStyle("display")?(a.setStyle("display","inline"),i.src=i.src.replace("folPlus.svg","folMinus.svg"),$(e).store("tip:title",Contao.lang.collapse),new Request.Contao({url:t.url,field:e}).post(t)):(a.setStyle("display","none"),i.src=i.src.replace("folMinus.svg","folPlus.svg"),$(e).store("tip:title",Contao.lang.expand),new Request.Contao({url:t.url,field:e}).post(t)),!1):(new Request.Contao({url:t.url,field:e,evalScripts:!0,onRequest:AjaxRequest.displayBox(Contao.lang.loading+" …"),onSuccess:function(t,a){var r=new Element("li",{id:l,class:"parent",styles:{display:"inline"}});new Element("ul",{class:"level_"+n,html:t}).inject(r,"bottom");if(5==s)r.inject($(e).getParent("li"),"after");else{var o=$(e).getParent("li");r.inject(o,"after")}r.getElements("a").each((function(e){e.href=e.href.replace(/&ref=[a-f0-9]+/,"&ref="+Contao.referer_id)})),$(e).store("tip:title",Contao.lang.collapse),i.src=i.src.replace("folPlus.svg","folMinus.svg"),window.fireEvent("structure"),AjaxRequest.hideBox(),window.fireEvent("ajax_change")}}).post(t),!1)},toggleVisibility:function(e,t,l){e.blur(),t||(t="visible.svg"),l||(l="invisible.svg");const n="dark"===document.documentElement.dataset.colorScheme?"--dark":"",s=e.getElementsByTagName("img"),a=s.length>1?s[0]:null,i=s[s.length-1],r=e=>{let t=e.lastIndexOf(".");return e.slice(0,t)+n+"."+e.slice(t+1)},o=t,c=a?r(t):null,g=l,d=a?r(l):null;let u,m,p=null,f=-1!==i.src.indexOf(g),v=e.getParent("div");return console.log("Last image:"+i.src+" | publish: "+f),new Request.Contao({url:$(e).href,followRedirects:!1,onSuccess:function(){var t;(v.hasClass("tl_right")?p=v.getPrevious("div").getElement("img"):v.hasClass("tl_listing_container")?(p=e.getParent("td").getPrevious("td").getFirst("div.list_icon"),null==p&&(p=e.getParent("td").getPrevious("td").getElement("div.cte_type")),null==p&&(p=e.getParent("tr").getFirst("td").getElement("div.list_icon_new"))):(u=v.getNext("div"))&&u.hasClass("cte_type")&&(p=u),null===p&&(m=e.getParent().getParent().getElements("div.list_icon").getFirst().getParent())&&(p=m[0]),null!=p)&&("img"===p.nodeName.toLowerCase()?p.getParent("ul.tl_listing").hasClass("tl_tree_xtnd")?p.src=f?p.src.replace(/_1\.(gif|png|jpe?g)/,".$1"):p.src.replace(/\.(gif|png|jpe?g)/,"_1.$1"):(p.src.match(/folPlus|folMinus/)&&(p=p.getParent("a").getNext("a")?p.getParent("a").getNext("a").getFirst("img"):new Element("img")),f?(t=p.src.replace(/.*_([0-9])\.(gif|png|jpe?g)/,"$1"),p.src=p.src.replace(/_[0-9]\.(gif|png|jpe?g)/,(1===t.toInt()?"":"_"+(t.toInt()-1))+".$1")):(t=p.src.replace(/.*_([0-9])\.(gif|png|jpe?g)/,"$1"),p.src=p.src.replace(/(_[0-9])?\.(gif|png|jpe?g)/,(t===p.src?"_1":"_"+(t.toInt()+1))+".$2"))):p.hasClass("cte_type")?f?(p.addClass("published"),p.removeClass("unpublished")):(p.addClass("unpublished"),p.removeClass("published")):f?p.setStyle("background-image",p.getStyle("background-image").replace(/_\.(gif|png|jpe?g)/,".$1")):p.setStyle("background-image",p.getStyle("background-image").replace(/\.(gif|png|jpe?g)/,"_.$1")));f?(i.src=i.src.replace(g,o),a&&(a.src=a.src.replace(d,c))):(i.src=i.src.replace(o,g),a&&(a.src=a.src.replace(c,d)))}}).get({state:f?1:0}),!1},setLegendState:function(e,t,l){e.blur();var n=$("pal_"+t);return n.hasClass("collapsed")?(n.removeClass("collapsed"),(new Request.Contao).post({action:"setLegendState",legend:t,table:l,state:1,REQUEST_TOKEN:Contao.request_token})):(n.addClass("collapsed"),(new Request.Contao).post({action:"setLegendState",legend:t,table:l,state:0,REQUEST_TOKEN:Contao.request_token})),!1},displayMessage:function(e,t,l){var n=$("general_messageBox"),s=$("general_messageOverlay"),a=window.getScroll();null===s&&(s=new Element("div",{id:"general_messageOverlay"}).inject($(document.body),"bottom")),s.set({styles:{display:"block",top:a.y+"px"}}),null===n&&(n=new Element("div",{id:"general_messageBox"}).inject($(document.body),"bottom")),n.set({html:e,styles:{display:"block",top:a.y+100+"px"}}),l&&n.addClass(l),t&&n.addClass("loading")},hideMessage:function(){var e=$("general_messageBox"),t=$("general_messageOverlay");t&&t.setStyle("display","none"),e&&e.setStyle("display","none"),t.remove(),e.remove()},confirmSelectOverrideEditAll:function(e,t,l){e.blur();var n=e.form.elements[t],s=!1;return $$(n).each((function(e){if(s||!e.checked)return!0;s=!0})),s?("delete"===e.name||(e.onclick="",e.click()),!0):(this.displayMessage(l,!1,"box-small"),!1)},confirmSelectDeleteAll:function(e,t,l,n,s,a){return e.blur(),!!this.confirmSelectOverrideEditAll(e,t,l)&&(this.confirmDelete(e,n,s,a),!0)},confirmDelete:function(e,t,l,n){var s=new Element("div"),a=(new Element("h2",{html:t,class:"tl_info"}).inject(s,"bottom"),new Element("p").inject(s,"bottom"),new Element("div",{class:"tl_submit_container"}).inject(s,"bottom")),i=new Element("input",{id:e.name+"Ok",name:e.name+"Ok",value:l,type:"submit",class:"tl_submit"}).inject(a,"bottom"),r=new Element("input",{id:e.name+"Abort",name:e.name+"Abort",value:n,type:"submit",class:"tl_submit"}).inject(a,"bottom");return this.displayMessage(s.get("html"),!1,"box-small"),$(i.id).addEvent("click",(function(){e.onclick="",e.click()})),$(r.id).addEvent("click",(function(){BackendGeneral.hideMessage()})),!0}}; //# sourceMappingURL=generalDriver.js.map \ No newline at end of file diff --git a/src/Resources/public/js/generalDriver.js.map b/src/Resources/public/js/generalDriver.js.map index 129b6afc..d33d86fb 100644 --- a/src/Resources/public/js/generalDriver.js.map +++ b/src/Resources/public/js/generalDriver.js.map @@ -1 +1 @@ -{"version":3,"sources":["generalDriver_src.js"],"names":[],"mappings":"AAwBC,GAAI,eACF,CACE,Y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ACT,EAcA,uBAAwB,SAAU,EAAQ,EAAW,EAAS,EAAe,EAAW,GAKtF,OAJA,EAAO,SAEU,KAAK,6BAA6B,EAAQ,EAAW,KAMtE,KAAK,cAAc,EAAQ,EAAe,EAAW,IAE9C,EACT,EAYA,cAAe,SAAU,EAAQ,EAAS,EAAW,GACnD,IAAI,EAAmB,IAAI,QAAQ,OAQ/B,GANiB,IAAI,QAAQ,KAAM,CACrC,KAAQ,EACR,MAAS,YACR,OAAO,EAAkB,UACT,IAAI,QAAQ,KAAK,OAAO,EAAkB,UAEvC,IAAI,QAAQ,MAAO,CACvC,MAAS,wBACR,OAAO,EAAkB,WAExB,EAAkB,IAAI,QAAQ,QAAS,CACzC,GAAM,EAAO,KAAO,KACpB,KAAQ,EAAO,KAAO,KACtB,MAAS,EACT,KAAQ,SACR,MAAS,cACR,OAAO,EAAiB,UAEvB,EAAqB,IAAI,QAAQ,QAAS,CAC5C,GAAM,EAAO,KAAO,QACpB,KAAQ,EAAO,KAAO,QACtB,MAAS,EACT,KAAQ,SACR,MAAS,cACR,OAAO,EAAiB,UAa3B,OAXA,KAAK,eAAe,EAAiB,IAAI,SAAS,EAAO,aAEzD,EAAE,EAAgB,IAAI,SAAS,SAAS,WACtC,EAAO,QAAU,GACjB,EAAO,OACT,IAEA,EAAE,EAAmB,IAAI,SAAS,SAAS,WACzC,eAAe,aACjB,KAEO,CACT,I"} \ No newline at end of file diff --git a/src/Resources/public/js/generalDriver_src.js b/src/Resources/public/js/generalDriver_src.js index a56c4c10..4c395f28 100644 --- a/src/Resources/public/js/generalDriver_src.js +++ b/src/Resources/public/js/generalDriver_src.js @@ -107,25 +107,42 @@ var BackendGeneral = toggleVisibility: function (el, icon, icon_disabled) { el.blur(); - // Optional dark mode at Contao 5. - var postfixColorScheme = document.documentElement.dataset.colorScheme === 'dark' ? '--dark' : ''; - + // Set default as "eye". if (!icon) { - icon = 'visible' + postfixColorScheme + '.svg'; + icon = 'visible.svg'; } if (!icon_disabled) { - icon_disabled = 'invisible' + postfixColorScheme + '.svg'; + icon_disabled = 'invisible.svg'; } - var img = null, - //image = $(el).getFirst('img'), - image = document.documentElement.dataset.colorScheme === 'dark' ? $(el).getFirst('img') : $(el).getLast('img'), - publish = (image.src.indexOf(icon_disabled) !== -1), + // Support dark mode at Contao 5. + const colorScheme = document.documentElement.dataset.colorScheme; + const postfixDark = colorScheme === 'dark' ? '--dark' : ''; + + // Get images - we have optional two icons: + // the first is for dark mode and second for light mode. + const imageList = el.getElementsByTagName('img'); + const darkImage = (imageList.length > 1) ? imageList[0] : null; + const lightImage = imageList[imageList.length - 1] + + // Generate images for dark mode. + const suffixDarkImage = (icon) => { + let posDot = icon.lastIndexOf('.'); + return icon.slice(0, posDot) + postfixDark + '.' + icon.slice(posDot + 1); + }; + + const iconLight = icon; + const iconDark = darkImage ? suffixDarkImage(icon) : null; + const iconLight_disabled = icon_disabled; + const iconDark_disabled = darkImage ? suffixDarkImage(icon_disabled) : null; + + let img = null, + publish = (lightImage.src.indexOf(iconLight_disabled) !== -1), div = el.getParent('div'), next, listIcon; - console.log(image.src + ' - ' + image.src.indexOf(icon_disabled)); + console.log('Last image:' + lightImage.src + ' | publish: ' + publish); new Request.Contao({ 'url': $(el).href, @@ -156,7 +173,7 @@ var BackendGeneral = // Change the icon if (img != null) { // Tree view - if (img.nodeName.toLowerCase() == 'img') { + if (img.nodeName.toLowerCase() === 'img') { if (img.getParent('ul.tl_listing').hasClass('tl_tree_xtnd')) { if (publish) { img.src = img.src.replace(/_1\.(gif|png|jpe?g)/, '.$1'); @@ -174,10 +191,10 @@ var BackendGeneral = var index; if (publish) { index = img.src.replace(/.*_([0-9])\.(gif|png|jpe?g)/, '$1'); - img.src = img.src.replace(/_[0-9]\.(gif|png|jpe?g)/, ((index.toInt() == 1) ? '' : '_' + (index.toInt() - 1)) + '.$1'); + img.src = img.src.replace(/_[0-9]\.(gif|png|jpe?g)/, ((index.toInt() === 1) ? '' : '_' + (index.toInt() - 1)) + '.$1'); } else { index = img.src.replace(/.*_([0-9])\.(gif|png|jpe?g)/, '$1'); - img.src = img.src.replace(/(_[0-9])?\.(gif|png|jpe?g)/, ((index == img.src) ? '_1' : '_' + (index.toInt() + 1)) + '.$2'); + img.src = img.src.replace(/(_[0-9])?\.(gif|png|jpe?g)/, ((index === img.src) ? '_1' : '_' + (index.toInt() + 1)) + '.$2'); } } } @@ -203,9 +220,15 @@ var BackendGeneral = // Send request if (publish) { - image.src = image.src.replace(icon_disabled, icon); + lightImage.src = lightImage.src.replace(iconLight_disabled, iconLight); + if (darkImage) { + darkImage.src = darkImage.src.replace(iconDark_disabled, iconDark); + } } else { - image.src = image.src.replace(icon, icon_disabled); + lightImage.src = lightImage.src.replace(iconLight, iconLight_disabled); + if (darkImage) { + darkImage.src = darkImage.src.replace(iconDark, iconDark_disabled); + } } } }).get({'state': (publish ? 1 : 0)});