Skip to content

[NodeBB] [JS SCRIPT/CSS] Theme Switcher

Customisation
8 3 3.7k 1
  • Hello all,

    โ€“ I open this topic for more clarity in agreement with @phenomlab ๐Ÿ™‚

    โ€“ Here the old topic for reference:


    Information


    โ€“ This JS and CSS script creates a button on the navbar allowing you to switch between different CSS style sheets.

    โ€“ This allows you to offer several themes to your users without going through the tedious and poorly documented bootstrap method on the NodeBB forum.

    โ€“ Note that your CSS stylesheets do not overide the code on ACP/custom CSS/ panel. They are in addition.

    alt text


    Javascript Code


    โ€“ Here is the Javascript code with comments in English and French.

    โš ๏ธ Adapt the code to your architecture (Path and files names)

    // ------------------------------------------
    // Theme Switcher
    // ------------------------------------------
    //We generate a random character string to assign a version number to the CSS file.
    // On gรฉnรจre une chaine de caractรจre alรฉatoire pour affecter un numรฉro de version au fichier CSS. 
    function generateRandomString(length) {
    
      var text = "";
      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    
      for (var i = 0; i < length; i++) {
          text += possible.charAt(Math.floor(Math.random() * possible.length));
      }
    
      return text;
    }
    
    $(document).ready(function ()
    {
    var string = generateRandomString(10);
    $("#random_string").text(string);
    // This variable gets the theme ID 
    // Cette variable obtient l'ID du thรจme
    var whichTheme = localStorage.getItem("theme");
    // This variable gets the active theme's actual URL
    //Cette variable obtient l'URL rรฉelle du thรจme actif
    var activeTheme = localStorage.getItem("activeTheme");
    // This variable appends the dropdown list to the existing panel
    // Cette variable ajoute la liste dรฉroulante au panneau existant
    var panel = $('<li id="switcher" class="dropdown text-center"> \
    <label for="theme-control-list-check" class="dropdown-toggle" data-toggle="dropdown" id="theme_dropdown" title="" role="button" data-original-title="Theme" aria-expanded="false"> \
    <a class="btn-link" title="Theme Switcher" href="#"><i id="ticon" class="fa fa-fw fa-lightbulb-o"></i><span class="visible-xs-inline">Theme Switcher</span></a> \
    </label> \
    <ul id="theme" class="dropdown-menu"> \
    <li><a id="default" href="#" rel="/assets/client.css?v=e02phpkima0">Default</a></li> \
    <li><a id="default dark" href="#" rel="/assets/customcss/default_dark.css">Default Dark</a></li> \
    <li><a id="Light Flat" href="#" rel="/assets/customcss/flat_light.css">Flat Light </a></li> \
    <li><a id="Light Flat Dark" href="#" rel="/assets/customcss/flat_dark.css">Flat Dark</a></li> \
    <li><a id="Dark Neon Aqua" href="#" rel="/assets/customcss/dark_neon_aqua.css">Dark Neon Aqua</a></li> \
    <li><a id="Dark Neon Blue" href="#" rel="/assets/customcss/dark_neon_blue.css">Dark Neon Blue</a></li> \
    <li><a id="Dark Neon Green" href="#" rel="/assets/customcss/dark_neon_green.css">Dark Neon Green</a></li> \
    <li><a id="Dark Neon Solary" href="#" rel="/assets/customcss/dark_neon_solary.css">Dark Neon Solary</a></li> \
    <li><a id="Dark Neon White" href="#" rel="/assets/customcss/dark_neon_white.css"">Dark Neon White</a></li> \
    <li><a id="Eva 00" href="#" rel="/assets/customcss/eva_00.css">Eva.00</a></li> \
    <li><a id="Eva 01" href="#" rel="/assets/customcss/eva_01.css">Eva.01</a></li> \
    <li><a id="Eva 01 Purple Green"href="#" rel="/assets/customcss/eva_01_purple_green.css">Eva.01: Purple-Green</a></li> \
    <li><a id="Eva 02" href="#" rel="/assets/customcss/eva_02.css">Eva.02: Red-Orange</a></li> \
    </ul> \
    </div> 
    ');
    
    // See if there is an active theme selected in localStorage. If none selected, use the default. If there is a theme in localStorage, use that and apply it
    // Regarde s'il y a un thรจme actif sรฉlectionnรฉ dans "localStorage". Si aucun n'est sรฉlectionnรฉ, utilise la valeur par dรฉfaut. 
    // S'il y a un thรจme dans localStorage, on l'utilise et on l'applique.
    if (whichTheme)
    {
    $("head").append("<link href='" + activeTheme + '?version=' + string + "' type=\"text/css\" rel=\'stylesheet\' />");
    }
    else
    {
    // No need to include anything here as there's no CSS to add.
    // Pas besoin d'inclure quoi que ce soit ici car il n'y a pas de CSS ร  ajouter.
    }
    
    $('ul#logged-in-menu').prepend(panel);
    $('ul#logged-out-menu').prepend(panel);
    
    if (utils.findBootstrapEnvironment() === 'xs')
    {
    $('#menu').prepend(panel);
    }
    
    $(document).ready(function () {
    // Listen to the NAV dropdown for any changes
    // ร‰coute la liste dรฉroulante NAV pour tout changement de thรจme
    $("#theme li a").on("click change", function ()
    {
    // If we detect a change, append the selected CSS file into the DOM 
    // Si un changement est dรฉtectรฉ, on ajoute le fichier CSS sรฉlectionnรฉ dans le DOM (Document Object Model)
    var thishref = $(this).attr('rel');
     $("link[rel=stylesheet]").attr('href' , thishref + "?version=" + string + "");
     //location.reload();
    //$("head").append("<link href='" + $(this).attr("rel") + $(this).attr("id") + " type=\'text/css\' rel=\'stylesheet\' />");
    location.reload();
    // This variable stores the selected theme ID
    // Cette variable stocke l'ID du thรจme sรฉlectionnรฉ
    var selected = $(this).attr("id");
    // This variable stores the selected theme link 
    // Cette variable stocke le lien du thรจme sรฉlectionnรฉ
    var theTheme = $(this).attr("rel");
    // This variable updates the selected theme ID
    // See if "default" has been selected. If it has, then...
    // Cette variable met ร  jour l'ID du thรจme sรฉlectionnรฉ
      // Regarde si "default" a รฉtรฉ sรฉlectionnรฉ. Si c'est le cas, alors...
    if (selected === 'default')
    {
    localStorage.setItem("theme", "");
    // This variable will strip the current appeneded theme ID
    // Cette variable supprimera l'ID du thรจme actuellement ajoutรฉ
    localStorage.setItem("activeTheme", "");
    // This variable will strip the current appeneded theme URL (HREF)
    // Finally, we have to reload the page to effect the changes
    // Cette variable supprimera l'URL actuelle du thรจme ajoutรฉ (HREF)
          // Enfin, on recharge la page pour effectuer les modifications
    location.reload();
    
    }
    // If any other theme is selected, carry on as normnal, and update localStorage
    // Si un autre thรจme est sรฉlectionnรฉ, continuez normalement et mettez ร  jour localStorage
    else
    {
    localStorage.setItem("theme", selected);
    // This variable updates the actual href of the CSS file
    // Cette variable met ร  jour le href rรฉel du fichier CSS
    localStorage.setItem("activeTheme", theTheme);
    //window.location.href = window.location.href
    }
    
    // We use return false to prevent the browser from reloading or following any HREF links
    // On utilise la fonction "return false" pour empรชcher le navigateur de recharger ou de suivre les liens HREF
    //return false;
    });
    });
    });
    
    // When hovering over the #switcher element, target the i class and add 'themeoff'
    // Lorsque du  survol de l'รฉlรฉment #switcher, on cible la classe CSS "i" et on ajoute le CSS "themeoff"
    $(document).on('mouseenter','#switcher', function() {
    $('#switcher i').addClass("themeoff");
    });
    // When leaving the however state, target the i class and remove 'themeoff'
    // Lorsque l'on quitte l'รฉtat, on cible la classe CSS "i" et on supprime le CSS "themeoff"
    $(document).on('mouseleave','#switcher', function() {
    $('#switcher i').removeClass("themeoff");
    });
    

    ACP/CUSTOM CSS Code


    โ€“ Here is the CSS code to put on NodeBB ACP/CustomCSS panel.

    โ€“ Itโ€™s a base adapted to my forum, itโ€™s up to you to adapt it to yours if certain things do not suit you.

    โ€“ Code with comments with English Traduction.

    /*----------------------------------------------------------------------------*/
    /*----------------------        Themes Switcher        -----------------------*/
    /*----------------------------------------------------------------------------*/
    
     /* Works with CUSTOM JS */
    /* DON'T DELETE - DON'T MOVE */
    /* -- */
    /* Fonctionne avec du CUSTOM JS */
    /* NE PAS SUPPRIMER - NE PAS  DEPLACER */
    
    /*Desktop*/
    /*Allows to have the "Theme Switcher" icon in black after a mouse click and during the dropdown */
    /*Permet d'avoir l'icone du "Theme Switcher" en noir aprรจs un clic souris et lors du dropdown */
    [aria-expanded="true"] a #ticon {
        color: #000000;
    }
    
    /*Theme Switcher icon color via CUSTOM JAVASCRIPT */
    /* Blank without mouse over */
    /*Couleur de l'icone du Theme Switcher via le CUSTOM JAVASCRIPT */
    /* Blanc sans mouse over*/
    .themeon {
        color: #ffffff !important;
    }
    
    /*Black with mouseover*/
    /*Noir avec mouse over*/
    .themeoff {
        color: #000000 !important;
    }
    
    /*Smartphone*/
    @media all and (max-width: 1024px)
    {
    /*BUGFIX: Placement of the "Theme Switcher" */
    /*BUGFIX: Placement du "Theme Switcher" */
        #switcher {
        list-style: none;
        margin-left: -80px;
        padding-top: 15px;
    }
    
    /*BUGFIX: Space between the icon and the text "Theme Switcher" */
    /*BUGFIX: Espace entre l'icone et le texte "Theme Switcher" */
    #switcher .fa-fw {
        text-align: center;
        width: 1.25em;
        padding-right: 25px;
    }
    
    /* DON'T DELETE - DON'T MOVE */
    /*Allows to have the "Theme Switcher" icon in white after a mouse click and during the dropdown */
    /* NE PAS SUPPRIMER - NE PAS  DEPLACER */
    /*Permet d'avoir l'icone du "Theme Switcher" en blanc aprรจs un clic souris et lors du dropdown */
        [aria-expanded="true"] a #ticon {
        color: #ffffff;
    }
    
    /*Theme Switcher icon color via CUSTOM JAVASCRIPT */
    /* Blank without mouse over */
    /*Couleur de l'icone du Theme Switcher via le CUSTOM JAVASCRIPT */
    /* Blanc sans mouse over*/
        .themeoff {
        color: #ffffff !important;
    }
    }
    
    /*FIREFOX BUGFIX: Remove dotted border from icon when clicked */
    /*BUGFIX FIREFOX: Suppression de la bordure pointillรฉe de l'icรดne quand on clique dessus */
    /*Desktop*/
    a:focus {
        outline:0;
    }
    
    /*Smartphone*/
    @media all and (max-width: 1024px)
    {
        a:focus {
        outline:0;
    }
    }
    
    
    /* Desktop */
    /*Button Position */
    /*Position du Bouton */
    .header #theme_dropdown {
        /*padding: 9px 15px;*/
        padding: 9px 15px; 
        padding-top: 9px;
        padding-bottom: 9px;
        margin-top: -4px;
        padding-top: 15px;
        padding-bottom: 14px;
    }
    
    /* ---- Appearance of the "Theme Switcher" icon in the navbar via Font Awesome (!!Change the CSS class also in the JS!!) ----*/
    /*Ampule*/
    /* ---- Apparence de l'icรดne du "Theme Switcher" dans la navbar via Font Awesome (!!Changer la class CSS aussi dans le JS!!) ----*/
    /*Ampoule*/
    .fa.fa-lightbulb-o:before {
        content: "\f0eb";
    }
    
    /*Navbar height to play with background height */
    /*Hauteur navbar pour jouer avec la hauteur du background */
    .navbar-default {
        height: 51px;
    }
    
    /*Spacing between "Search" and "Notifications" icons */
    /*Espacement entre les icรดnes "Recherche" et "Notifications" */
    #switcher {
        margin-top: 4px;
    }
    
    /*We remove the background on the icon */
    /*On supprime le background sur l'icone */
    #switcher .btn-link:hover {
        background: none !important;
    }
    
    /*Background color on mouseover (Default Theme) */
    /*Couleur du background au survol souris (Default Theme) */
    .navbar-default .navbar-nav>li>label:hover {
        background: #eeeeee;
    }
    
    /*Appearance of selection menu */
    /*Apparence du menu de sรฉlection */
    #theme.dropdown-menu {
        position: absolute;
        top: 44px; 
        right: 0px;
        z-index: 1000;
        float: left;
        min-width: 160px;
        padding: 5px 0;
        margin: 2px 0 0;
        list-style: none;
        font-size: 14px;
        text-align: left;
        background-clip: padding-box;
    }
    
    /* Smartphone */
    /*Appearance of button and drop-down menu on Smartphone */
    /*Apparence du bouton et du menu dรฉroulant sur Smartphone */
    @media all and (max-width: 1024px)
    {
        /*Dropdown menu text color */
       /*Couleur du texte du menu dรฉroulant */
    #theme.dropdown-menu>li>a {
        display: block;
        padding: 3px 20px;
        clear: both;
        font-weight: 400;
        line-height: 1.42857143;
        color: #fff;
        white-space: nowrap;
        background: #3A3C41;
    }
    
    /*Appearance and position of button and drop-down menu */
    /*Apparence et position du bouton et du menu dรฉroulant */
    #theme.dropdown-menu {
        position: fixed;
        top: 140px;
        left: 15px;
        z-index: 1000;
        float: left;
        min-width: 185px;
        padding: 5px 0;
        margin: 2px 0 0;
        list-style: none;
        font-size: 14px;
        text-align: left;
        /* background-clip: padding-box; */
        color: #fff;
        background: #3A3C41;
        width: 60px; /* VIOLENCE: Largeur */
        border: 1px solid black;
    }
    
    
    /*Text color and button background when selected */
    /*Couleur du texte et background du bouton lors de la selection */
    .btn-link:focus, .btn-link:hover {
        /*color: #23527c;*/
        color: lightgrey;
        text-decoration: underline;
        background-color: transparent;
    }	
    
    /*We remove the white bars at the top and bottom of the button on Smartphone */
    /*On supprime les barres blanches en haut et en bas du bouton sur Smartphone */
    .navbar-form {
        left: 20px;
        box-shadow: none;
        list-style: none;
    }
    }
    
  • DownPWundefined DownPW marked this topic as a regular topic on
  • phenomlabundefined phenomlab referenced this topic on
  • DownPWundefined DownPW referenced this topic on
  • Hello all,

    โ€“ I open this topic for more clarity in agreement with @phenomlab ๐Ÿ™‚

    โ€“ Here the old topic for reference:


    Information


    โ€“ This JS and CSS script creates a button on the navbar allowing you to switch between different CSS style sheets.

    โ€“ This allows you to offer several themes to your users without going through the tedious and poorly documented bootstrap method on the NodeBB forum.

    โ€“ Note that your CSS stylesheets do not overide the code on ACP/custom CSS/ panel. They are in addition.

    alt text


    Javascript Code


    โ€“ Here is the Javascript code with comments in English and French.

    โš ๏ธ Adapt the code to your architecture (Path and files names)

    // ------------------------------------------
    // Theme Switcher
    // ------------------------------------------
    //We generate a random character string to assign a version number to the CSS file.
    // On gรฉnรจre une chaine de caractรจre alรฉatoire pour affecter un numรฉro de version au fichier CSS. 
    function generateRandomString(length) {
    
      var text = "";
      var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    
      for (var i = 0; i < length; i++) {
          text += possible.charAt(Math.floor(Math.random() * possible.length));
      }
    
      return text;
    }
    
    $(document).ready(function ()
    {
    var string = generateRandomString(10);
    $("#random_string").text(string);
    // This variable gets the theme ID 
    // Cette variable obtient l'ID du thรจme
    var whichTheme = localStorage.getItem("theme");
    // This variable gets the active theme's actual URL
    //Cette variable obtient l'URL rรฉelle du thรจme actif
    var activeTheme = localStorage.getItem("activeTheme");
    // This variable appends the dropdown list to the existing panel
    // Cette variable ajoute la liste dรฉroulante au panneau existant
    var panel = $('<li id="switcher" class="dropdown text-center"> \
    <label for="theme-control-list-check" class="dropdown-toggle" data-toggle="dropdown" id="theme_dropdown" title="" role="button" data-original-title="Theme" aria-expanded="false"> \
    <a class="btn-link" title="Theme Switcher" href="#"><i id="ticon" class="fa fa-fw fa-lightbulb-o"></i><span class="visible-xs-inline">Theme Switcher</span></a> \
    </label> \
    <ul id="theme" class="dropdown-menu"> \
    <li><a id="default" href="#" rel="/assets/client.css?v=e02phpkima0">Default</a></li> \
    <li><a id="default dark" href="#" rel="/assets/customcss/default_dark.css">Default Dark</a></li> \
    <li><a id="Light Flat" href="#" rel="/assets/customcss/flat_light.css">Flat Light </a></li> \
    <li><a id="Light Flat Dark" href="#" rel="/assets/customcss/flat_dark.css">Flat Dark</a></li> \
    <li><a id="Dark Neon Aqua" href="#" rel="/assets/customcss/dark_neon_aqua.css">Dark Neon Aqua</a></li> \
    <li><a id="Dark Neon Blue" href="#" rel="/assets/customcss/dark_neon_blue.css">Dark Neon Blue</a></li> \
    <li><a id="Dark Neon Green" href="#" rel="/assets/customcss/dark_neon_green.css">Dark Neon Green</a></li> \
    <li><a id="Dark Neon Solary" href="#" rel="/assets/customcss/dark_neon_solary.css">Dark Neon Solary</a></li> \
    <li><a id="Dark Neon White" href="#" rel="/assets/customcss/dark_neon_white.css"">Dark Neon White</a></li> \
    <li><a id="Eva 00" href="#" rel="/assets/customcss/eva_00.css">Eva.00</a></li> \
    <li><a id="Eva 01" href="#" rel="/assets/customcss/eva_01.css">Eva.01</a></li> \
    <li><a id="Eva 01 Purple Green"href="#" rel="/assets/customcss/eva_01_purple_green.css">Eva.01: Purple-Green</a></li> \
    <li><a id="Eva 02" href="#" rel="/assets/customcss/eva_02.css">Eva.02: Red-Orange</a></li> \
    </ul> \
    </div> 
    ');
    
    // See if there is an active theme selected in localStorage. If none selected, use the default. If there is a theme in localStorage, use that and apply it
    // Regarde s'il y a un thรจme actif sรฉlectionnรฉ dans "localStorage". Si aucun n'est sรฉlectionnรฉ, utilise la valeur par dรฉfaut. 
    // S'il y a un thรจme dans localStorage, on l'utilise et on l'applique.
    if (whichTheme)
    {
    $("head").append("<link href='" + activeTheme + '?version=' + string + "' type=\"text/css\" rel=\'stylesheet\' />");
    }
    else
    {
    // No need to include anything here as there's no CSS to add.
    // Pas besoin d'inclure quoi que ce soit ici car il n'y a pas de CSS ร  ajouter.
    }
    
    $('ul#logged-in-menu').prepend(panel);
    $('ul#logged-out-menu').prepend(panel);
    
    if (utils.findBootstrapEnvironment() === 'xs')
    {
    $('#menu').prepend(panel);
    }
    
    $(document).ready(function () {
    // Listen to the NAV dropdown for any changes
    // ร‰coute la liste dรฉroulante NAV pour tout changement de thรจme
    $("#theme li a").on("click change", function ()
    {
    // If we detect a change, append the selected CSS file into the DOM 
    // Si un changement est dรฉtectรฉ, on ajoute le fichier CSS sรฉlectionnรฉ dans le DOM (Document Object Model)
    var thishref = $(this).attr('rel');
     $("link[rel=stylesheet]").attr('href' , thishref + "?version=" + string + "");
     //location.reload();
    //$("head").append("<link href='" + $(this).attr("rel") + $(this).attr("id") + " type=\'text/css\' rel=\'stylesheet\' />");
    location.reload();
    // This variable stores the selected theme ID
    // Cette variable stocke l'ID du thรจme sรฉlectionnรฉ
    var selected = $(this).attr("id");
    // This variable stores the selected theme link 
    // Cette variable stocke le lien du thรจme sรฉlectionnรฉ
    var theTheme = $(this).attr("rel");
    // This variable updates the selected theme ID
    // See if "default" has been selected. If it has, then...
    // Cette variable met ร  jour l'ID du thรจme sรฉlectionnรฉ
      // Regarde si "default" a รฉtรฉ sรฉlectionnรฉ. Si c'est le cas, alors...
    if (selected === 'default')
    {
    localStorage.setItem("theme", "");
    // This variable will strip the current appeneded theme ID
    // Cette variable supprimera l'ID du thรจme actuellement ajoutรฉ
    localStorage.setItem("activeTheme", "");
    // This variable will strip the current appeneded theme URL (HREF)
    // Finally, we have to reload the page to effect the changes
    // Cette variable supprimera l'URL actuelle du thรจme ajoutรฉ (HREF)
          // Enfin, on recharge la page pour effectuer les modifications
    location.reload();
    
    }
    // If any other theme is selected, carry on as normnal, and update localStorage
    // Si un autre thรจme est sรฉlectionnรฉ, continuez normalement et mettez ร  jour localStorage
    else
    {
    localStorage.setItem("theme", selected);
    // This variable updates the actual href of the CSS file
    // Cette variable met ร  jour le href rรฉel du fichier CSS
    localStorage.setItem("activeTheme", theTheme);
    //window.location.href = window.location.href
    }
    
    // We use return false to prevent the browser from reloading or following any HREF links
    // On utilise la fonction "return false" pour empรชcher le navigateur de recharger ou de suivre les liens HREF
    //return false;
    });
    });
    });
    
    // When hovering over the #switcher element, target the i class and add 'themeoff'
    // Lorsque du  survol de l'รฉlรฉment #switcher, on cible la classe CSS "i" et on ajoute le CSS "themeoff"
    $(document).on('mouseenter','#switcher', function() {
    $('#switcher i').addClass("themeoff");
    });
    // When leaving the however state, target the i class and remove 'themeoff'
    // Lorsque l'on quitte l'รฉtat, on cible la classe CSS "i" et on supprime le CSS "themeoff"
    $(document).on('mouseleave','#switcher', function() {
    $('#switcher i').removeClass("themeoff");
    });
    

    ACP/CUSTOM CSS Code


    โ€“ Here is the CSS code to put on NodeBB ACP/CustomCSS panel.

    โ€“ Itโ€™s a base adapted to my forum, itโ€™s up to you to adapt it to yours if certain things do not suit you.

    โ€“ Code with comments with English Traduction.

    /*----------------------------------------------------------------------------*/
    /*----------------------        Themes Switcher        -----------------------*/
    /*----------------------------------------------------------------------------*/
    
     /* Works with CUSTOM JS */
    /* DON'T DELETE - DON'T MOVE */
    /* -- */
    /* Fonctionne avec du CUSTOM JS */
    /* NE PAS SUPPRIMER - NE PAS  DEPLACER */
    
    /*Desktop*/
    /*Allows to have the "Theme Switcher" icon in black after a mouse click and during the dropdown */
    /*Permet d'avoir l'icone du "Theme Switcher" en noir aprรจs un clic souris et lors du dropdown */
    [aria-expanded="true"] a #ticon {
        color: #000000;
    }
    
    /*Theme Switcher icon color via CUSTOM JAVASCRIPT */
    /* Blank without mouse over */
    /*Couleur de l'icone du Theme Switcher via le CUSTOM JAVASCRIPT */
    /* Blanc sans mouse over*/
    .themeon {
        color: #ffffff !important;
    }
    
    /*Black with mouseover*/
    /*Noir avec mouse over*/
    .themeoff {
        color: #000000 !important;
    }
    
    /*Smartphone*/
    @media all and (max-width: 1024px)
    {
    /*BUGFIX: Placement of the "Theme Switcher" */
    /*BUGFIX: Placement du "Theme Switcher" */
        #switcher {
        list-style: none;
        margin-left: -80px;
        padding-top: 15px;
    }
    
    /*BUGFIX: Space between the icon and the text "Theme Switcher" */
    /*BUGFIX: Espace entre l'icone et le texte "Theme Switcher" */
    #switcher .fa-fw {
        text-align: center;
        width: 1.25em;
        padding-right: 25px;
    }
    
    /* DON'T DELETE - DON'T MOVE */
    /*Allows to have the "Theme Switcher" icon in white after a mouse click and during the dropdown */
    /* NE PAS SUPPRIMER - NE PAS  DEPLACER */
    /*Permet d'avoir l'icone du "Theme Switcher" en blanc aprรจs un clic souris et lors du dropdown */
        [aria-expanded="true"] a #ticon {
        color: #ffffff;
    }
    
    /*Theme Switcher icon color via CUSTOM JAVASCRIPT */
    /* Blank without mouse over */
    /*Couleur de l'icone du Theme Switcher via le CUSTOM JAVASCRIPT */
    /* Blanc sans mouse over*/
        .themeoff {
        color: #ffffff !important;
    }
    }
    
    /*FIREFOX BUGFIX: Remove dotted border from icon when clicked */
    /*BUGFIX FIREFOX: Suppression de la bordure pointillรฉe de l'icรดne quand on clique dessus */
    /*Desktop*/
    a:focus {
        outline:0;
    }
    
    /*Smartphone*/
    @media all and (max-width: 1024px)
    {
        a:focus {
        outline:0;
    }
    }
    
    
    /* Desktop */
    /*Button Position */
    /*Position du Bouton */
    .header #theme_dropdown {
        /*padding: 9px 15px;*/
        padding: 9px 15px; 
        padding-top: 9px;
        padding-bottom: 9px;
        margin-top: -4px;
        padding-top: 15px;
        padding-bottom: 14px;
    }
    
    /* ---- Appearance of the "Theme Switcher" icon in the navbar via Font Awesome (!!Change the CSS class also in the JS!!) ----*/
    /*Ampule*/
    /* ---- Apparence de l'icรดne du "Theme Switcher" dans la navbar via Font Awesome (!!Changer la class CSS aussi dans le JS!!) ----*/
    /*Ampoule*/
    .fa.fa-lightbulb-o:before {
        content: "\f0eb";
    }
    
    /*Navbar height to play with background height */
    /*Hauteur navbar pour jouer avec la hauteur du background */
    .navbar-default {
        height: 51px;
    }
    
    /*Spacing between "Search" and "Notifications" icons */
    /*Espacement entre les icรดnes "Recherche" et "Notifications" */
    #switcher {
        margin-top: 4px;
    }
    
    /*We remove the background on the icon */
    /*On supprime le background sur l'icone */
    #switcher .btn-link:hover {
        background: none !important;
    }
    
    /*Background color on mouseover (Default Theme) */
    /*Couleur du background au survol souris (Default Theme) */
    .navbar-default .navbar-nav>li>label:hover {
        background: #eeeeee;
    }
    
    /*Appearance of selection menu */
    /*Apparence du menu de sรฉlection */
    #theme.dropdown-menu {
        position: absolute;
        top: 44px; 
        right: 0px;
        z-index: 1000;
        float: left;
        min-width: 160px;
        padding: 5px 0;
        margin: 2px 0 0;
        list-style: none;
        font-size: 14px;
        text-align: left;
        background-clip: padding-box;
    }
    
    /* Smartphone */
    /*Appearance of button and drop-down menu on Smartphone */
    /*Apparence du bouton et du menu dรฉroulant sur Smartphone */
    @media all and (max-width: 1024px)
    {
        /*Dropdown menu text color */
       /*Couleur du texte du menu dรฉroulant */
    #theme.dropdown-menu>li>a {
        display: block;
        padding: 3px 20px;
        clear: both;
        font-weight: 400;
        line-height: 1.42857143;
        color: #fff;
        white-space: nowrap;
        background: #3A3C41;
    }
    
    /*Appearance and position of button and drop-down menu */
    /*Apparence et position du bouton et du menu dรฉroulant */
    #theme.dropdown-menu {
        position: fixed;
        top: 140px;
        left: 15px;
        z-index: 1000;
        float: left;
        min-width: 185px;
        padding: 5px 0;
        margin: 2px 0 0;
        list-style: none;
        font-size: 14px;
        text-align: left;
        /* background-clip: padding-box; */
        color: #fff;
        background: #3A3C41;
        width: 60px; /* VIOLENCE: Largeur */
        border: 1px solid black;
    }
    
    
    /*Text color and button background when selected */
    /*Couleur du texte et background du bouton lors de la selection */
    .btn-link:focus, .btn-link:hover {
        /*color: #23527c;*/
        color: lightgrey;
        text-decoration: underline;
        background-color: transparent;
    }	
    
    /*We remove the white bars at the top and bottom of the button on Smartphone */
    /*On supprime les barres blanches en haut et en bas du bouton sur Smartphone */
    .navbar-form {
        left: 20px;
        box-shadow: none;
        list-style: none;
    }
    }
    

    @DownPW said in [NodeBB] [JS SCRIPT/CSS] Theme Switcher:

    โš ๏ธ Adapt the code to your architecture (Path and files names)

    How do I know the path names and files?

  • @elhana-fine

    โ€“ Firstly, you must have created your CUSTOM CSS files who correspond to your themes.

    1 CSS file = 1 theme

    โ€“ The CSS files that you will have created before with your CUSTOM CSS code inside, must be uploaded to your server in the public directory of NodeBB with subdirectory if you want or not :

    /home/YOUR_USER/PATH_TO_YOUR_NODEBB_DIRECTORY\public
    

    That path correspond to :

    https://yourdomain.com/assets
    

    And Like that, for example:

    <li><a id="default" href="#" rel="/assets/client.css?v=e02phpkima0">Default</a></li> \
    <li><a id="default dark" href="#" rel="/assets/customcss/default_dark.css">Default Dark</a></li> \
    <li><a id="Light Flat" href="#" rel="/assets/customcss/flat_light.css">Flat Light </a></li> \
    <li><a id="Light Flat Dark" href="#" rel="/assets/customcss/flat_dark.css">Flat Dark</a></li> \
    <li><a id="Dark Neon Aqua" href="#" rel="/assets/customcss/dark_neon_aqua.css">Dark Neon Aqua</a></li> \
    <li><a id="Dark Neon Blue" href="#" rel="/assets/customcss/dark_neon_blue.css">Dark Neon Blue</a></li> \
    <li><a id="Dark Neon Green" href="#" rel="/assets/customcss/dark_neon_green.css">Dark Neon Green</a></li> \
    <li><a id="Dark Neon Solary" href="#" rel="/assets/customcss/dark_neon_solary.css">Dark Neon Solary</a></li> \
    <li><a id="Dark Neon White" href="#" rel="/assets/customcss/dark_neon_white.css"">Dark Neon White</a></li> \
    <li><a id="Eva 00" href="#" rel="/assets/customcss/eva_00.css">Eva.00</a></li> \
    <li><a id="Eva 01" href="#" rel="/assets/customcss/eva_01.css">Eva.01</a></li> \
    <li><a id="Eva 01 Purple Green"href="#" rel="/assets/customcss/eva_01_purple_green.css">Eva.01: Purple-Green</a></li> \
    <li><a id="Eva 02" href="#" rel="/assets/customcss/eva_02.css">Eva.02: Red-Orange</a></li> \
    

    That why you must adapt the code of JS Script to your architecture (Path and CUSTOM CSS files names)

  • @elhana-fine

    โ€“ Firstly, you must have created your CUSTOM CSS files who correspond to your themes.

    1 CSS file = 1 theme

    โ€“ The CSS files that you will have created before with your CUSTOM CSS code inside, must be uploaded to your server in the public directory of NodeBB with subdirectory if you want or not :

    /home/YOUR_USER/PATH_TO_YOUR_NODEBB_DIRECTORY\public
    

    That path correspond to :

    https://yourdomain.com/assets
    

    And Like that, for example:

    <li><a id="default" href="#" rel="/assets/client.css?v=e02phpkima0">Default</a></li> \
    <li><a id="default dark" href="#" rel="/assets/customcss/default_dark.css">Default Dark</a></li> \
    <li><a id="Light Flat" href="#" rel="/assets/customcss/flat_light.css">Flat Light </a></li> \
    <li><a id="Light Flat Dark" href="#" rel="/assets/customcss/flat_dark.css">Flat Dark</a></li> \
    <li><a id="Dark Neon Aqua" href="#" rel="/assets/customcss/dark_neon_aqua.css">Dark Neon Aqua</a></li> \
    <li><a id="Dark Neon Blue" href="#" rel="/assets/customcss/dark_neon_blue.css">Dark Neon Blue</a></li> \
    <li><a id="Dark Neon Green" href="#" rel="/assets/customcss/dark_neon_green.css">Dark Neon Green</a></li> \
    <li><a id="Dark Neon Solary" href="#" rel="/assets/customcss/dark_neon_solary.css">Dark Neon Solary</a></li> \
    <li><a id="Dark Neon White" href="#" rel="/assets/customcss/dark_neon_white.css"">Dark Neon White</a></li> \
    <li><a id="Eva 00" href="#" rel="/assets/customcss/eva_00.css">Eva.00</a></li> \
    <li><a id="Eva 01" href="#" rel="/assets/customcss/eva_01.css">Eva.01</a></li> \
    <li><a id="Eva 01 Purple Green"href="#" rel="/assets/customcss/eva_01_purple_green.css">Eva.01: Purple-Green</a></li> \
    <li><a id="Eva 02" href="#" rel="/assets/customcss/eva_02.css">Eva.02: Red-Orange</a></li> \
    

    That why you must adapt the code of JS Script to your architecture (Path and CUSTOM CSS files names)

    @DownPW where did this line come from ? This isnโ€™t in the original code

    </.fal.fa-layer-group-oli>
    

    That should be just

    </li>
    
  • @phenomlab

    Exact, itโ€™s a shell/error
    Can you delete it on the first post and my answer ?

  • @phenomlab

    Exact, itโ€™s a shell/error
    Can you delete it on the first post and my answer ?

    @DownPW modified to reflect correct value

  • you forget first topic Mark ๐Ÿ˜‰

  • you forget first topic Mark ๐Ÿ˜‰

    @DownPW done

  • Teemberlandundefined Teemberland referenced this topic on
  • Teemberlandundefined Teemberland referenced this topic on

Related Topics
  • 50 Votes
    107 Posts
    25k Views
    @crazycells [image: 1711908210287-7f4c7193-7c28-4e2e-80e8-d439ac7285c6-image.png] [image: 1711908232109-3ab9c33d-04b9-4c15-91e6-891450aebfc2-image.png]
  • NodeBB Theme/Skin Switcher

    Solved Customisation nodebb
    38
    7 Votes
    38 Posts
    8k Views
    @Teemberland great spot ! You should create a PR for that so they can include it in the official repository. Just be aware that any subsequent releases will overwrite your fix without the PR.
  • [NodeBB] Custom fields plugin

    Unsolved Customisation nodebb plugins javascript custom
    5
    0 Votes
    5 Posts
    2k Views
    @pwsincd hi. Just following up on this thread (I know itโ€™s old) but was curious to understand if itโ€™s still an issue or not ?
  • [NODEBB] Help for my custom CSS

    Solved Customisation nodebb css bugfix
    237
    49 Votes
    237 Posts
    80k Views
    @baris said: You should change your selectors so it doesnโ€™t look at the entire document. You probably only want to apply fancybox to stuff inside the #content element which is what changes when the user navigates around the page. So use $('#content a').... for your selectors then the forum logo in the header wonโ€™t be selected. I modified the JS Fancybox code now and this code and it seem better // --------------------------------------------- // Fancybox Media Reader (Without Website Logo) // --------------------------------------------- if (top.location.pathname !== '/login') { $(window).on('action:posts.loaded', function(data) { console.log("Polling DOM for lazyLoaded images to apply Fancybox"); $(document).ready(function() { $('#content a').not('.forum-logo').not(".avatar").not(".emoji").not(".bmac-noanimate").each(function() { $('#content a[href*=".jpg"], #content a[href*=".jpeg"], #content a[href*=".png"], #content a[href*=".gif"], #content a[href*=".webp"]').addClass("noanimate"); }); }); }); } if (top.location.pathname !== '/login') { $(document).ready(function() { $(window).on('action:ajaxify.end', function(data) { $('#content a').not('.logo').not(".avatar").not(".emoji").not(".bmac-noanimate").each(function() { $('#content a[href*=".jpg"], #content a[href*=".jpeg"], #content a[href*=".png"], #content a[href*=".gif"], #content a[href*=".webp"]').addClass("noanimate"); data.preventDefault() // Strip out the images contained inside blockquotes as this looks nasty :) $('#content blockquote img').remove(); }); Fancybox.bind( '#content a[href*=".jpg"], #content a[href*=".jpeg"], #content a[href*=".png"], #content a[href*=".gif"], #content a[href*=".webp"]', { groupAll: true, } ); }); }); } // Chat fancybox - fires when chat module loaded and AJAX calls new chat $(document).ready(function() { $(window).on('action:chat.loaded', function(data) { // >>> Se limiter au contenu principal uniquement <<< $('#content img').not('.forum-logo').not(".avatar").not(".emoji").not(".bmac-noanimate").each(function() { var newHref = $(this).attr("src"); $(this).wrap("<a class='fancybox' href='" + newHref + "'/>"); $('#content a[href*=".jpg"], #content a[href*=".jpeg"], #content a[href*=".png"], #content a[href*=".gif"], #content a[href*=".webp"]').addClass("noanimate"); data.preventDefault(); // Strip out the images contained inside blockquotes as this looks nasty :) $('#content blockquote img').remove(); }); Fancybox.bind( '#content a[href*=".jpg"], #content a[href*=".jpeg"], #content a[href*=".png"], #content a[href*=".gif"], #content a[href*=".webp"]', { groupAll: true, } ); }); }); For the logo, I must use overflow: visible !important; on [component="brand/logo"] /* --- Logo --- */ [component="brand/logo"] { max-height: 50px; width: auto; height: auto; max-width: 100%; display: block; object-fit: contain; object-position: left center; overflow: visible !important; } Better result !!
  • [NodeBB] Import custom Font

    Solved Customisation custom fonts nodebb css
    12
    3 Votes
    12 Posts
    3k Views
    @cagatay youโ€™ll need to define this in the body tag (or another element if you want greater or more granular targets) - for example body { font-family: "Poppins"; font-size: 16px; } Essentially, you use the font-size CSS directive.
  • [NODEBB] Stats

    Unsolved Customisation plugin stats script
    20
    1
    2 Votes
    20 Posts
    4k Views
    @phenomlab said in [NODEBB] Stats: @jac or I land up fixing it I wouldnโ€™t put it past you
  • RSS parser script [NodeBB]

    Customisation nodebb rss script
    47
    9 Votes
    47 Posts
    12k Views
    @phenomlab said in RSS parser script [NodeBB]: @jac Not yet. Sorry. Have some other work commitments I need to prioritise. Hoping to get to this over the weekend. No worries at all mate, thanks
  • CSS Help on my Flarum

    Solved Customisation
    5
    2
    2 Votes
    5 Posts
    1k Views
    @mike-jones Yes, youโ€™ll typically see this type of behaviour if there is another style that has higher priority in the sense that yours will be overridden. Using !important will override the higher preference, but should be used sparingly rather than everywhere.