Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debounce URL updating of share parameters? #32

Open
maboa opened this issue Feb 16, 2021 · 0 comments
Open

Debounce URL updating of share parameters? #32

maboa opened this issue Feb 16, 2021 · 0 comments

Comments

@maboa
Copy link
Member

maboa commented Feb 16, 2021

At the moment we are changing the URL params as the selection changes – not sure if this may cause issues on slower devices. An alternative is https://jsfiddle.net/dimshik/z8Jge/

var selectionEndTimeout = null;

// bind selection change event to my function
document.onselectionchange = userSelectionChanged;

function userSelectionChanged() {
    // wait 500 ms after the last selection change event
    if (selectionEndTimeout) {
        clearTimeout(selectionEndTimeout);
        $('.log ol').append('<li>User Selection Changed</li>');
        // scroll to bottom of the div
        $('.log').scrollTop($('.log ol').height());
    }
    selectionEndTimeout = setTimeout(function () {
        $(window).trigger('selectionEnd');
    }, 500);
}


// helper function
function getSelectionText() {
    var text = "";
    if (window.getSelection) {
        text = window.getSelection().toString();
    } else if (document.selection && document.selection.type != "Control") {
        text = document.selection.createRange().text;
    }
    return text;
}

$(window).bind('selectionEnd', function () {
    // reset selection timeout
    selectionEndTimeout = null;

    // TODO: Do your cool stuff here........
  
    $('.log ol').append('<li>User Selection Ended</li>');
    // scroll to bottom of the div
    $('.log').scrollTop($('.log ol').height());
    
    // get user selection
    var selectedText = getSelectionText();
    // if the selection is not empty show it :)
    if(selectedText != ''){
        $('.selected-text ol').append('<li>' + selectedText + '</li>');
        // scroll to bottom of the div
        $('.selected-text').scrollTop($('.selected-text ol').height());
    }
});
@maboa maboa changed the title Dethrottle URL update with share parameters? Debounce URL update with share parameters? Feb 16, 2021
@maboa maboa changed the title Debounce URL update with share parameters? Debounce URL updating of share parameters? Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant