satopian / poti-kaini-EN

POTI-board EVO English ver, The OekakiBBS for PaintBBS NEO, tegaki.js, ChickenPaint, and Klecks. (PHP7.4-PHP8.3) https://paintbbs.sakura.ne.jp/poti/
https://paintbbs.sakura.ne.jp/
Other
28 stars 9 forks source link

Customized default theme interferes with other themes #2

Open boxfries opened 3 years ago

boxfries commented 3 years ago

When customizing the default theme, adding new CSS properties causes these to "leak" through to other themes when their properties aren't set. This is because the default theme is persistent, and always loads regardless of which theme is selected.

2021-07-31_211152

Header styling from default theme leaking through to "Deep" theme.

I found a solution by adding "disabled" to the default CSS theme when changing themes, and removing it when switching back to each html file under themes. But I don't know if it's good code. (I only know some HTML/CSS)

    <link rel="stylesheet" href="<% echo(skindir) %>css/mono_main.css?v=1.1" id="css0">
    <link rel="stylesheet" href="<% echo(skindir) %>css/mono_dev.css" id="css1" disabled>
    <link rel="stylesheet" href="<% echo(skindir) %>css/mono_dark.css" id="css2" disabled>
    <link rel="stylesheet" href="<% echo(skindir) %>css/mono_deep.css" id="css3" disabled>
    <link rel="stylesheet" href="<% echo(skindir) %>css/mono_mayo.css" id="css4" disabled>

<script>
    var colorIdx = GetCookie("colorIdx");
        switch (Number(colorIdx)) {
        case 0:
            document.getElementById("css0").removeAttribute("disabled");
            break;
        case 1:
            document.getElementById("css1").removeAttribute("disabled");
            document.getElementById("css0").setAttribute("disabled", "");
            break;
        case 2:
            document.getElementById("css2").removeAttribute("disabled");
            document.getElementById("css0").setAttribute("disabled", "");
            break;
        case 3:
            document.getElementById("css3").removeAttribute("disabled");
            document.getElementById("css0").setAttribute("disabled", "");
            break;
        case 4:
            document.getElementById("css4").removeAttribute("disabled");
            document.getElementById("css0").setAttribute("disabled", "");
        break;
} 
satopian commented 3 years ago

When customizing the default theme, adding new CSS properties causes these to "leak" through to other themes when their properties aren't set.

Intentionally, I'm always loading the main css. Avoid the situation where css is not loaded due to read delay by Javascript. Also, when Javascript is not valid, the main css is read. However, if you want it to load only when the main css is selected, you can write:

        <!-- Disable all css once. -->
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_main.css" id="css0" disabled>
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_dev.css" id="css1" disabled>
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_dark.css" id="css2" disabled>
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_deep.css" id="css3" disabled>
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_mayo.css" id="css4" disabled>  
    <script>
        // Select the css you want to enable from the css you have disabled.
        var colorIdx = GetCookie("colorIdx");
            switch (Number(colorIdx)) {
            case 0:
                document.getElementById("css0").removeAttribute("disabled");
                break;
            case 1:
                document.getElementById("css1").removeAttribute("disabled");
                break;
            case 2:
                document.getElementById("css2").removeAttribute("disabled");
            break;
            case 3:
                document.getElementById("css3").removeAttribute("disabled");
            break;
            case 4:
                document.getElementById("css4").removeAttribute("disabled");
            break;
        } 
        function SetCss(obj){
            var idx = obj.selectedIndex;
            SetCookie("colorIdx",idx);
            window.location.reload();
        }
        function GetCookie(key){
            var tmp = document.cookie + ";";
            var tmp1 = tmp.indexOf(key, 0);
            if(tmp1 != -1){
                tmp = tmp.substring(tmp1, tmp.length);
                var start = tmp.indexOf("=", 0) + 1;
                var end = tmp.indexOf(";", start);
                return(decodeURIComponent(tmp.substring(start,end)));
                }
            return("");
        }
        function SetCookie(key, val){
            document.cookie = key + "=" + encodeURIComponent(val) + ";max-age=31536000;";
        }
    </script>
    <noscript>
        //Css for when Javascript is not valid
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_main.css">
    </noscript>

Disable all css once. From there, select the css you want to enable. Traditionally, main css is always valid, but this code also disables it. <noscript> Set the css to be read when Javascript is invalid in the place of.

boxfries commented 3 years ago

Thanks for the quick reply! I gave the script a quick test.

Avoid the situation where css is not loaded due to read delay by Javascript.

Indeed, the script above causes this when loading the page for the first time. (disabled CSS is loaded first?) I wonder if there's a way to avoid this while disabling the main theme with other themes.

The script I use avoids the initial problem, but bare HTML can be seen for a split second depending on the complexity of the CSS. I managed to avoid this by removing empty urls in background-image properties. But I don't know how robust this is...

Thanks so much again.

satopian commented 3 years ago
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_main.css" id="css0">
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_dev.css" id="css1" disabled>
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_dark.css" id="css2" disabled>
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_deep.css" id="css3" disabled>
        <link rel="stylesheet" href="<% echo(skindir) %>css/mono_mayo.css" id="css4" disabled>  
    <script>
        // Select the css you want to enable from the css you have disabled.
        var colorIdx = GetCookie("colorIdx");
            switch (Number(colorIdx)) {
            case 1:
                document.getElementById("css1").removeAttribute("disabled");
                document.getElementById("css0").disabled = true;
                break;
            case 2:
                document.getElementById("css2").removeAttribute("disabled");
                document.getElementById("css0").disabled = true;
            break;
            case 3:
                document.getElementById("css3").removeAttribute("disabled");
                document.getElementById("css0").disabled = true;
            break;
            case 4:
                document.getElementById("css4").removeAttribute("disabled");
                document.getElementById("css0").disabled = true;
            break;
        } 

Does not disable the main CSS. Then when you select another css, disable the main css. What about this code?

With this method, the main css will be loaded preferentially. And when another css is selected, the main css is not loaded.

boxfries commented 3 years ago

The code works well, thank you! I'll try using this.

bare HTML can be seen for a split second depending on the complexity of the CSS. This problem still exists like the first code. But I can easily fix it by removing empty URLs from the background-image property. Maybe it's just an issue of malformed CSS.

Appreciate all the help!

satopian commented 3 years ago

I saw the POTI-board on your site. I saw the pull-down menu for selecting the theme color increased to two. Since there are two IDs, to select with the selected color I think I need one more line of JavaScript code.

colorIdx=GetCookie('colorIdx');
document.getElementById("mystyle").selectedIndex=colorIdx;
//for ID mystyle1
document.getElementById("mystyle1").selectedIndex=colorIdx;

Soon, i'll push a theme to GitHub that addresses the double-tap zoom issue. Please diff check.

boxfries commented 3 years ago

Thanks for checking up! I was definitely breaking something but I had no idea what it was.

Also I noticed the earlier issue

bare HTML can be seen for a split second depending on the complexity of the CSS.

has sadly come back at full force. Whenever a theme gets switched from default, and loading different pages the bare HTML can be seen for a second or less. I'm not sure what's causing it, because it's happening with original themes as well. I'm assuming the javascript is disabling the default css fine, but reading lines and loading css causes some delay. I also tried the old script, but it's loading the default style first for a second instead.

I did some searching and there's a script that can make a full replacement of "<link rel". Maybe this could help, but I'm not sure how to do it with many styles (0 javascript knowledge). https://stackoverflow.com/questions/19844545/replacing-css-file-on-the-fly-and-apply-the-new-style-to-the-page

satopian commented 3 years ago

newlink.setAttribute("href", cssFile); Replacing css filenames is not a good idea. There is a security vulnerability there. At the moment, the one I've decided to be the best is the JavaScript I'm using right now.

boxfries commented 3 years ago

Got it, thanks for the heads up. I don't know how but the latest javascript change seems to have improved it, or maybe it's just the server delay.

I'd like to provide these themes for Potiboard, but I wonder what's the best way to implement it? I was thinking a seperate theme folder and changing the config file.

satopian commented 3 years ago

Decide a new folder name and put it together there. After that, where and how to distribute the theme. Personal site? GitHub? With GitHub, i can request what I want to fix, such as by pull request. Will I receive it in a zip and do further maintenance? Hmmm. It's a very good theme, so I'd like to use a part of css, but since I'm using scss for development, it may be necessary to switch back to scss once.

If boxfries-san manages it on GitHub, you can pull request only the important changes. What is the best ... i can't say anything until you ask how you want to distribute the theme.

boxfries commented 3 years ago

Hmm, this is a lot more complex than I thought! I'm very unfamiliar with github and pull requests, so I worry about holding back development. I'd prefer to give you the the files and let you do as you please with it.

I can try setting it up on github and add changes when I feel like it, and you can do with them as you please (or I can add things if anything needs to be fixed). I'm not sure about licenses, I believe part of the css was based on sakots-san's themes, so I want to make sure proper credits are given.

Let me know what works best for you.

satopian commented 3 years ago

I wouldn't be burdened if I could get you to support and maintain this theme on GitHub. However, if you can't create and manage a repository on GitHub, i can just receive the file. For example, you can just upload and attach the zip to the attach files in this comment section. However, it is unclear how long and how much we can support. However, the color scheme of the theme I got is better than the English theme I'm distributing now, so I'd like to somehow rewrite it in sass format so that I can manage it. This is an example of description by sass. poti-EVO-themes/mono_dark.scss at main · sakots/poti-EVO-themes

@charset "UTF-8";
/*! =====このcssファイルはsassから生成されています。===== */

//設定ファイルの読み込み
@import "mono_dark_conf";
@import "mono";
satopian commented 3 years ago

配布/素材 - ドラ☆クロウ!オリジナルイラスト中心よろずサイト - It is also possible to distribute it on a personal site like this theme called 'COOL SOLID'. The only reason I hesitate is that I am updating several Japanese themes, English themes, and Chinese themes by myself, so the amount of work will increase as the number of English themes increases.

satopian commented 3 years ago

It would be helpful if the person who created the theme manages it for himself. And when you do that on GitHub, Create a pull request when you find a problem or want to change it. The changes take effect when merged by the theme administrator. This is a theme-only repository issue, so It is separate from the development of the entire POTI board. It's okay if the theme pull request and merge are delayed. The POTI-board theme that I already manage will be developed separately.

satopian commented 3 years ago

Another way ... Have sakots manage this theme. sakots has been making POTI-board themes for many years and may be happy to manage them. If you don't mind the distribution managed by sakots, I will contact him.

boxfries commented 3 years ago

Oh I wouldn't want to bother him haha. I'll try to set it up on github. I'll likely mess things up, so please bear with me. Since I use the themes on my oekaki board, I'll be maintaining them anyways. I'll set it up soon after I'm done polishing things...

satopian commented 3 years ago

You need a git client app to push, pull, and clone files to GitHub. Transfer with the client application at the time of ftp. I use "tortoise git", but "GitHub Desktop" may be easier to operate.

satopian commented 3 years ago

Palm rejection issues on Ipad · Issue #36 · thenickdude/chickenpaint Another account reported it. Verification work has begun.

satopian commented 3 years ago

Can you test the iPad double tap zoom issue? I would like to know if updating the body of ChickenPaint has solved the problem. Newly updated Chicken Paint test page. ChickenPaint example

boxfries commented 3 years ago

I got it. I accidentally opened the issue with my old account (lol). Figured I may as well continue using it to avoid embarrassment...

Thanks for the client suggestions. I'll check out tortoise git. I'm almost finished setting up the theme folders. I made one for Japanese and English.

boxfries commented 3 years ago

Hello! I've finally set it up. If there's anything that needs changing, feel free to let me know. https://github.com/boxfries/themeparty

satopian commented 3 years ago

I tried it. I thought it was a good light-colored theme. Easy on the eyes. I have a question. What is the proper theme name to use when introducing this theme?

title="Creamy <% echo(tver) %>">Picto Junction

'Creamy','Picto Junction','themeparty' Which of these three?

boxfries commented 3 years ago

Oh, I think I left creamy in there accidentally before deciding on the final name. As it's a collection of themes, please call it "themeparty". I'll try fixing it later.

satopian commented 3 years ago

I understand. Thank you very much. I linked to themeparty from POTI repositories in English and Japanese.

boxfries commented 3 years ago

I replaced the files. It took a few errors but I eventually got it. Thanks for linking my pages!

satopian commented 3 years ago

Thank you for creating the theme. This is a very good one.