Skip to content

Commit 7c06b5b

Browse files
committed
fix: per applicare il tema in tempo reale al cambio della select, senza attendere refresh della pagina
1 parent 7dba938 commit 7c06b5b

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

modules/utenti/edit.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,24 +371,34 @@ function(data){
371371
}
372372
);
373373
}
374-
var mySkins=["skin-blue","skin-black","skin-red","skin-yellow","skin-purple","skin-green","skin-blue-light","skin-black-light","skin-red-light","skin-yellow-light","skin-purple-light","skin-green-light"];
374+
function applySidebarTheme(theme){
375+
var sidebar = $(".main-sidebar");
376+
if (!sidebar.length) {
377+
return;
378+
}
375379
376-
function changeSkin(cls){
377-
$.each(mySkins,function(i){
378-
$("body").removeClass(mySkins[i])
380+
var classes = (sidebar.attr("class") || "").split(/\s+/);
381+
var filtered = $.grep(classes, function(cls) {
382+
return cls && cls !== "sidebar-dark-secondary" && cls.indexOf("bg-") !== 0;
379383
});
380-
$("body").addClass("skin-"+cls);
381-
return false;
384+
385+
if (theme) {
386+
filtered.push("bg-" + theme);
387+
} else {
388+
filtered.push("sidebar-dark-secondary");
389+
}
390+
391+
sidebar.attr("class", filtered.join(" "));
382392
}
383393
384394
$("#id_module_start").change(function(){
385395
update_id_module_start($(this).val());
386396
});
387397
388398
$("#theme").change(function(){
389-
update_theme($(this).val());
390-
if ($(this).val())
391-
changeSkin($(this).val());
399+
var themeValue = $(this).val();
400+
applySidebarTheme(themeValue);
401+
update_theme(themeValue);
392402
});
393403
394404
function update_id_module_start(value){
@@ -407,7 +417,7 @@ function(data){
407417
408418
function update_theme(value){
409419
$.get(
410-
globals.rootdir + "/actions.php?id_module='.$id_module.'&id_record='.$id_record.'&op=update_theme&theme=" + value,
420+
globals.rootdir + "/actions.php?id_module='.$id_module.'&id_record='.$id_record.'&op=update_theme&theme=" + encodeURIComponent(value || ""),
411421
function(data){
412422
if(data == "ok") {
413423
toastr["success"]("'.tr('Tema aggiornato!').'");

0 commit comments

Comments
 (0)