• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

when snippet is being updated, should scroll on the point that user was before update the snippet

Messages
6
Likes
0
Points
1
#1
Hi.
When a user save the snippet the page is reload and developer is confused and need to find the point that he was...

I have write some code to scroll down to the point that screen was.
Do you want to share the code with you to add it in your plugin?
I think this is an essential functionallity for developers
 

Temyk

Developer & Support
Messages
1,129
Likes
42
Points
48
#2
Hello.

You can share your solution, we will look at it and maybe add it.
 
Messages
6
Likes
0
Points
1
#3
The code is the following.
I would appreciate very much if you make me a contributor in your plugin in Wordpress repository :)

PHP:
add_action("admin_footer", function (){

    //I keep the scroll position in a cookie based in ID of page, so this feature is
    //Only for already posted snippets because new post/snippets has not yet an ID
    if( get_post_type()=="wbcr-snippets" && $GLOBALS['pagenow']=='post.php' ){
        
        echo '
        <script>
            
            function getCookie(name){
                var pattern = RegExp(name + "=.[^;]*")
                var matched = document.cookie.match(pattern)
                if(matched){
                    var cookie = matched[0].split("=")
                    return cookie[1]
                }
                return false
            }
            
        
            window.onload = function pexlechris_woody(){
            
                var publish=document.getElementById("publish");
                if(publish!==null){
                    publish.onclick = function() {
                        var d = new Date();
                        d.setTime(d.getTime() + (20*60*1000));
                        var expires = "expires="+ d.toUTCString();
                        document.cookie = "WoodyScrollCookie'.get_the_ID().'=" + window.scrollY + ";" + expires + ";path=/";
                        //Here I keep the scroll position in a cookie, I could not find a more easy and good way to keep this information
                    };
                }

                
                window.scroll({
                    top: getCookie("WoodyScrollCookie'.get_the_ID().'"),
                    left: 0,
                    behavior: "auto"
                });
            }
        </script>
        ';
    }
},20);