From 60f78cd845a4725b0ba0c349666362c7923735c0 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 3 Mar 2020 17:49:53 +0000 Subject: [PATCH] Privacy: Prevent unexpected scrolling when clicking the "Copy this section to clipboard" button on Privacy Policy Guide screen. Props garrett-eclipse, birgire, davidbaumwald, pbiron. Fixes #49540. git-svn-id: https://develop.svn.wordpress.org/trunk@47420 602fd350-edb4-49c9-b593-d223f7449a82 --- src/js/_enqueues/admin/privacy-tools.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/js/_enqueues/admin/privacy-tools.js b/src/js/_enqueues/admin/privacy-tools.js index b8b88ac7da..d00d5d1573 100644 --- a/src/js/_enqueues/admin/privacy-tools.js +++ b/src/js/_enqueues/admin/privacy-tools.js @@ -274,6 +274,9 @@ jQuery( document ).ready( function( $ ) { if ( $container.length ) { try { + var documentPosition = document.documentElement.scrollTop, + bodyPosition = document.body.scrollTop; + window.getSelection().removeAllRanges(); range = document.createRange(); $container.addClass( 'hide-privacy-policy-tutorial' ); @@ -284,6 +287,12 @@ jQuery( document ).ready( function( $ ) { $container.removeClass( 'hide-privacy-policy-tutorial' ); window.getSelection().removeAllRanges(); + + if ( documentPosition > 0 && documentPosition !== document.documentElement.scrollTop ) { + document.documentElement.scrollTop = documentPosition; + } else if ( bodyPosition > 0 && bodyPosition !== document.body.scrollTop ) { + document.body.scrollTop = bodyPosition; + } } catch ( er ) {} } }