assets/themes/j1/modules/themeSwitcher/js/switcher.min.js in j1-template-2022.0.6 vs assets/themes/j1/modules/themeSwitcher/js/switcher.min.js in j1-template-2022.0.7
- old
+ new
@@ -17,6 +17,6 @@
# -----------------------------------------------------------------------------
# NOTE: This modules is MODIFIED to be used with MobileMenu (mmenuLight).
# The original version cannot be used with J1 for theme menu creation!
# -----------------------------------------------------------------------------
*/
-;(function(d,h,o,g){var b=d.fn.bootstrapThemeSwitcher;var e=j1.getCookieNames();var p=j1.findCookie("_ga");var q=j1.findCookie("j1");var f=new liteURL(h.location.href);var j=f.hostname;var s=j.substring(j.lastIndexOf(".",j.lastIndexOf(".")-1)+1);var l=(f.protocol.includes("https"))?true:false;var r=log4javascript.getLogger("j1.core.switcher");var i;var c;var m={};var k;var a;var n=function(u,t){this.$element=d(u);this.settings=d.extend({},d.fn.bootstrapThemeSwitcher.defaults,t);this.themesList=[];this.getThemes();return this};n.prototype={clear:function(){r.debug("\nbootstrapThemeSwitcher.clear");return this.$element.each(function(){this.$element.empty()})},update:function(){r.debug("\nbootstrapThemeSwitcher.update");this.getThemes()},checkStyleSheetByName:function(t){var w=false;var x="/"+t+"/";var v=new RegExp(x,"i");for(var u=0;u<o.styleSheets.length;u++){if(v.test(o.styleSheets[u].href)){w=true;break}}return w},switchTheme:function(t,z){var A=d(this);var w=d.extend({},d.fn.bootstrapThemeSwitcher.defaults,A.data("bootstrapThemeSwitcher"));var v=w.cssThemeLink;var u=w.debug;var y=this.settings.includeBootswatch;var x;var B;c=j1.existsCookie(e.user_state);if(c){r.debug("\ncookie found: "+e.user_state);m=j1.readCookie(e.user_state)}else{r.error("\ncookie not found: "+e.user_state);r.debug("\nj1 cookies found:"+q.length);q.forEach(function(C){console.log("j1.core.switcher: "+C)});r.debug("\nga cookies found:"+p.length);p.forEach(function(C){console.log("j1.core.switcher: "+C)})}x=m.theme_name;B=m.theme_css;if(typeof z==="undefined"){z=this.settings.defaultCssFile}if(typeof t==="undefined"){t=z}if(w.saveToCookie){if(typeof Cookies==="undefined"){if(u==="true"){r.error("\ncookies library not present")}return false}m.theme_name=t;m.theme_css=z;if(!(m.theme_name.includes("Uno")||m.theme_name=="Bootstrap")){m.theme_author="Bootswatch";m.theme_author_url="https://bootswatch.com/"}else{m.theme_author="J1 Team";m.theme_author_url="https://jekyll.one/"}r.debug("\nwrite to cookie : "+e.user_state);j1.writeCookie({name:e.user_state,data:m,samesite:"Strict",secure:l,expires:365});location.reload(true)}else{r.debug("\nwrite to cookie : disabled");r.warn("\nselected theme not activated: "+t)}},loadThemeFromCookie:function(t){if(typeof Cookies==="undefined"){r.error("\ncookies library not present");return false}var u=d.extend({},d.fn.bootstrapThemeSwitcher.defaults,t);c=j1.existsCookie(e.user_state);if(c){r.info("\ncookie found: "+e.user_state);m=j1.readCookie(e.user_state)}else{r.error("\ncookie not found: "+e.user_state);r.debug("\nj1 cookies found:"+q.length);q.forEach(function(x){console.log("j1.core.switcher: "+x)});r.debug("\nga cookies found:"+p.length);p.forEach(function(x){console.log("j1.core.switcher: "+x)})}var w=m.theme_name;var v=m.theme_css;this.switchTheme(w,v)},addTheme:function(u,t,w,v){if(typeof w==="undefined"){w=0}if(typeof v==="undefined"){v=0}this.themesList.splice(w,v,{name:u,css:t});this.addThemesToControl()},addThemesToControl:function(){if(typeof this.$element==="undefined"){r.error("\nbootstrapThemeSelector|addThemesToControl: Element is undefined");return false}if(typeof this.themesList==="undefined"){r.error("\nbootstrapThemeSelector|addThemesToControl: Themes is undefined");return false}if(this.settings.excludeBootswatch){var A;if(this.settings.excludeBootswatch.indexOf(",")!==-1){A=this.settings.excludeBootswatch.replace(/ /g,"").split(",")}else{A=[];A.push(this.settings.excludeBootswatch)}var w=this.themesList;d.each(w,function(E,F){if(F&&F.name){if(d.inArray(F.name,A)!==-1){w.splice(E,1)}}});this.themesList=w}var v=this;if(this.$element.is("ul")){var B=d(this);var x=d.extend({},d.fn.bootstrapThemeSwitcher.defaults,B.data("bootstrapThemeSwitcher"));var u=x.cssThemeLink;var t=x.debug;var y;c=j1.existsCookie(e.user_state);if(c){r.debug("\nuser state cookie found");m=j1.readCookie(e.user_state)}else{r.error("\nuser state NOT cookie found");r.debug("\nj1 cookies found:"+q.length);q.forEach(function(E){console.log("j1.core.switcher: "+E)});r.debug("\nga cookies found:"+p.length);p.forEach(function(E){console.log("j1.core.switcher: "+E)})}y=m.theme_name;if(t==="true"){r.debug("\nbootstrapThemeSelector: UL element selected")}this.$element.empty();var D;var C="#9E9E9E";d.each(this.themesList,function(F,G){if(v.$element[0].id.includes("mmenu")){D="mmenu-item"}else{D="dropdown-item"}if(G.name===y){if(v.$element[0].id.includes("mmenu")){D="mmenu-item active"}else{D="dropdown-item active"}}var E=d("<li />").attr("class",D).append('<a href="#"><i class="mdi mdi-view-quilt mdi-18px mr-2" style="color: '+C+'"></i>'+G.name+"</a>").on("click",function(){if(x.loadFromBootswatch){v.switchTheme(G.name,G.css)}else{v.switchTheme(G.name,G.cssCdn)}d(this).parent().find("li").removeClass("active");d(this).addClass("active")});v.$element.append(E)})}else{if(this.$element.is("select")){r.debug("\nbootstrapThemeSelector: SELECT element selected");this.$element.empty();var z;d.each(this.themesList,function(E,F){z=null;if(F.name===y){z="selected"}if(x.loadFromBootswatch){v.$element.append("<option "+z+" value='"+F.css+"'>"+F.name+"</option>")}else{v.$element.append("<option "+z+" value='"+F.cssCdn+"'>"+F.name+"</option>")}});this.$element.on("change",function(){var E=d("option:selected",this);v.switchTheme(E.text(),E.val())})}else{r.info("\nbootstrapThemeSelector: no UL or SELECT element found");r.error("\nbootstrapThemeSelector: failed")}}},getThemes:function(){var t=this;if(this.settings.localFeed!==null&&this.settings.localFeed!==""){d.ajax({url:this.settings.localFeed,dataType:"json",success:function(u){t.themesList=u.themes;t.addThemesToControl()},error:function(u,w,v){r.error("\nfailed to retrieve the local feed from: '"+t.settings.localFeed+"'")}})}else{d.ajax({url:this.settings.bootswatchApiUrl+"/"+this.settings.bootswatchApiVersion+".json",dataType:"json",success:function(u){if(typeof u.themes==="undefined"){return null}t.themesList=u.themes;t.themesList.splice(0,0,{name:"default",css:t.settings.defaultCssFile});t.addThemesToControl()}})}},themes:function(t){if(typeof t==="undefined"){return this.themesList}else{this.themesList=t}}};d.fn.bootstrapThemeSwitcher=function(v){var x;var u=Array.prototype.slice.call(arguments,1);var y=d(this);var w=y.data("bootstrapThemeSwitcher");var t=typeof v==="object"&&v;if(!w){y.data("bootstrapThemeSwitcher",(w=new n(this,t)))}if(typeof v==="string"){x=w[v].apply(w,u)}return(typeof x==="undefined")?y:x};d.fn.bootstrapThemeSwitcher.defaults={debug:false,saveToCookie:true,cssThemeLink:"bootstrapTheme",cookieThemeName:"bootstrapTheme.name",cookieThemeCss:"boostrapTheme.css",cookieExpiration:365,cookiePath:"/",defaultCssFile:"https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css",bootswatchApiUrl:"https://bootswatch.com/api/",bootswatchApiVersion:"4",loadFromBootswatch:true,localFeed:"",excludeBootswatch:""};d.fn.bootstrapThemeSwitcher.Constructor=n;d.fn.bootstrapThemeSwitcher.noConflict=function(){d.fn.BootstrapThemeSwitcher=b;return this}})(jQuery,window,document);
+;(function(d,h,o,g){var b=d.fn.bootstrapThemeSwitcher;var e=j1.getCookieNames();var p=j1.findCookie("_ga");var q=j1.findCookie("j1");var f=new liteURL(h.location.href);var j=f.hostname;var s=j.substring(j.lastIndexOf(".",j.lastIndexOf(".")-1)+1);var l=(f.protocol.includes("https"))?true:false;var r=log4javascript.getLogger("j1.core.switcher");var i;var c;var m={};var k;var a;var n=function(u,t){this.$element=d(u);this.settings=d.extend({},d.fn.bootstrapThemeSwitcher.defaults,t);this.themesList=[];this.getThemes();return this};n.prototype={clear:function(){r.debug("\nbootstrapThemeSwitcher.clear");return this.$element.each(function(){this.$element.empty()})},update:function(){r.debug("\nbootstrapThemeSwitcher.update");this.getThemes()},checkStyleSheetByName:function(t){var w=false;var x="/"+t+"/";var v=new RegExp(x,"i");for(var u=0;u<o.styleSheets.length;u++){if(v.test(o.styleSheets[u].href)){w=true;break}}return w},switchTheme:function(t,z){var A=d(this);var w=d.extend({},d.fn.bootstrapThemeSwitcher.defaults,A.data("bootstrapThemeSwitcher"));var v=w.cssThemeLink;var u=w.debug;var y=this.settings.includeBootswatch;var x;var B;c=j1.existsCookie(e.user_state);if(c){r.debug("\ncookie found: "+e.user_state);m=j1.readCookie(e.user_state)}else{r.error("\ncookie not found: "+e.user_state);r.debug("\nj1 cookies found:"+q.length);q.forEach(function(C){console.log("j1.core.switcher: "+C)});r.debug("\nga cookies found:"+p.length);p.forEach(function(C){console.log("j1.core.switcher: "+C)})}x=m.theme_name;B=m.theme_css;if(typeof z==="undefined"){z=this.settings.defaultCssFile}if(typeof t==="undefined"){t=z}if(w.saveToCookie){if(typeof Cookies==="undefined"){if(u==="true"){r.error("\ncookies library not present")}return false}m.theme_name=t;m.theme_css=z;if(!(m.theme_name.includes("Uno")||m.theme_name=="Bootstrap")){m.theme_author="Bootswatch";m.theme_author_url="https://bootswatch.com/"}else{m.theme_author="J1 Team";m.theme_author_url="https://jekyll.one/"}r.debug("\nwrite to cookie : "+e.user_state);j1.writeCookie({name:e.user_state,data:m,secure:l,expires:365});location.reload(true)}else{r.debug("\nwrite to cookie : disabled");r.warn("\nselected theme not activated: "+t)}},loadThemeFromCookie:function(t){if(typeof Cookies==="undefined"){r.error("\ncookies library not present");return false}var u=d.extend({},d.fn.bootstrapThemeSwitcher.defaults,t);c=j1.existsCookie(e.user_state);if(c){r.info("\ncookie found: "+e.user_state);m=j1.readCookie(e.user_state)}else{r.error("\ncookie not found: "+e.user_state);r.debug("\nj1 cookies found:"+q.length);q.forEach(function(x){console.log("j1.core.switcher: "+x)});r.debug("\nga cookies found:"+p.length);p.forEach(function(x){console.log("j1.core.switcher: "+x)})}var w=m.theme_name;var v=m.theme_css;this.switchTheme(w,v)},addTheme:function(u,t,w,v){if(typeof w==="undefined"){w=0}if(typeof v==="undefined"){v=0}this.themesList.splice(w,v,{name:u,css:t});this.addThemesToControl()},addThemesToControl:function(){if(typeof this.$element==="undefined"){r.error("\nbootstrapThemeSelector|addThemesToControl: Element is undefined");return false}if(typeof this.themesList==="undefined"){r.error("\nbootstrapThemeSelector|addThemesToControl: Themes is undefined");return false}if(this.settings.excludeBootswatch){var A;if(this.settings.excludeBootswatch.indexOf(",")!==-1){A=this.settings.excludeBootswatch.replace(/ /g,"").split(",")}else{A=[];A.push(this.settings.excludeBootswatch)}var w=this.themesList;d.each(w,function(E,F){if(F&&F.name){if(d.inArray(F.name,A)!==-1){w.splice(E,1)}}});this.themesList=w}var v=this;if(this.$element.is("ul")){var B=d(this);var x=d.extend({},d.fn.bootstrapThemeSwitcher.defaults,B.data("bootstrapThemeSwitcher"));var u=x.cssThemeLink;var t=x.debug;var y;c=j1.existsCookie(e.user_state);if(c){r.debug("\nuser state cookie found");m=j1.readCookie(e.user_state)}else{r.error("\nuser state NOT cookie found");r.debug("\nj1 cookies found:"+q.length);q.forEach(function(E){console.log("j1.core.switcher: "+E)});r.debug("\nga cookies found:"+p.length);p.forEach(function(E){console.log("j1.core.switcher: "+E)})}y=m.theme_name;if(t==="true"){r.debug("\nbootstrapThemeSelector: UL element selected")}this.$element.empty();var D;var C="#9E9E9E";d.each(this.themesList,function(F,G){if(v.$element[0].id.includes("mmenu")){D="mmenu-item"}else{D="dropdown-item"}if(G.name===y){if(v.$element[0].id.includes("mmenu")){D="mmenu-item active"}else{D="dropdown-item active"}}var E=d("<li />").attr("class",D).append('<a href="#"><i class="mdi mdi-view-quilt mdi-18px mr-2" style="color: '+C+'"></i>'+G.name+"</a>").on("click",function(){if(x.loadFromBootswatch){v.switchTheme(G.name,G.css)}else{v.switchTheme(G.name,G.cssCdn)}d(this).parent().find("li").removeClass("active");d(this).addClass("active")});v.$element.append(E)})}else{if(this.$element.is("select")){r.debug("\nbootstrapThemeSelector: SELECT element selected");this.$element.empty();var z;d.each(this.themesList,function(E,F){z=null;if(F.name===y){z="selected"}if(x.loadFromBootswatch){v.$element.append("<option "+z+" value='"+F.css+"'>"+F.name+"</option>")}else{v.$element.append("<option "+z+" value='"+F.cssCdn+"'>"+F.name+"</option>")}});this.$element.on("change",function(){var E=d("option:selected",this);v.switchTheme(E.text(),E.val())})}else{r.info("\nbootstrapThemeSelector: no UL or SELECT element found");r.error("\nbootstrapThemeSelector: failed")}}},getThemes:function(){var t=this;if(this.settings.localFeed!==null&&this.settings.localFeed!==""){d.ajax({url:this.settings.localFeed,dataType:"json",success:function(u){t.themesList=u.themes;t.addThemesToControl()},error:function(u,w,v){r.error("\nfailed to retrieve the local feed from: '"+t.settings.localFeed+"'")}})}else{d.ajax({url:this.settings.bootswatchApiUrl+"/"+this.settings.bootswatchApiVersion+".json",dataType:"json",success:function(u){if(typeof u.themes==="undefined"){return null}t.themesList=u.themes;t.themesList.splice(0,0,{name:"default",css:t.settings.defaultCssFile});t.addThemesToControl()}})}},themes:function(t){if(typeof t==="undefined"){return this.themesList}else{this.themesList=t}}};d.fn.bootstrapThemeSwitcher=function(v){var x;var u=Array.prototype.slice.call(arguments,1);var y=d(this);var w=y.data("bootstrapThemeSwitcher");var t=typeof v==="object"&&v;if(!w){y.data("bootstrapThemeSwitcher",(w=new n(this,t)))}if(typeof v==="string"){x=w[v].apply(w,u)}return(typeof x==="undefined")?y:x};d.fn.bootstrapThemeSwitcher.defaults={debug:false,saveToCookie:true,cssThemeLink:"bootstrapTheme",cookieThemeName:"bootstrapTheme.name",cookieThemeCss:"boostrapTheme.css",cookieExpiration:365,cookiePath:"/",defaultCssFile:"https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css",bootswatchApiUrl:"https://bootswatch.com/api/",bootswatchApiVersion:"4",loadFromBootswatch:true,localFeed:"",excludeBootswatch:""};d.fn.bootstrapThemeSwitcher.Constructor=n;d.fn.bootstrapThemeSwitcher.noConflict=function(){d.fn.BootstrapThemeSwitcher=b;return this}})(jQuery,window,document);