Skip to content

Instantly share code, notes, and snippets.

@sadasant
Created January 25, 2017 21:06
Show Gist options
  • Select an option

  • Save sadasant/8ec220c07764c36180f885cb11f934c7 to your computer and use it in GitHub Desktop.

Select an option

Save sadasant/8ec220c07764c36180f885cb11f934c7 to your computer and use it in GitHub Desktop.

Revisions

  1. sadasant revised this gist Jan 25, 2017. 1 changed file with 16 additions and 2 deletions.
    18 changes: 16 additions & 2 deletions DurandalHistoryCheckUrl
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,27 @@
    * @method checkUrl
    * @return {boolean} Returns true/false from loading the url.
    */
    function cleanFragment(s) {
    return s
    .replace(/%7E/g, "~")
    .replace(/%21/g, "!")
    .replace(/%2A/g, "*")
    .replace(/%28/g, "(")
    .replace(/%29/g, ")")
    .replace(/%27/g, "'")
    .replace(/%2D/g, "-")
    .replace(/%2E/g, ".")
    .replace(/%5F/g, "_")
    }
    history.checkUrl = function() {
    var current = history.getFragment();
    if (current === history.fragment && history.iframe) {
    var compareCurrent = cleanFragment(current);
    var historyFragment = cleanFragment(history.fragment);
    if (compareCurrent === historyFragment && history.iframe) {
    current = history.getFragment(history.getHash(history.iframe));
    }

    if (current === history.fragment) {
    if (compareCurrent === historyFragment) {
    return false;
    }

  2. sadasant created this gist Jan 25, 2017.
    21 changes: 21 additions & 0 deletions DurandalHistoryCheckUrl
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    /**
    * Checks the current URL to see if it has changed, and if it has, calls `loadUrl`, normalizing across the hidden iframe.
    * @method checkUrl
    * @return {boolean} Returns true/false from loading the url.
    */
    history.checkUrl = function() {
    var current = history.getFragment();
    if (current === history.fragment && history.iframe) {
    current = history.getFragment(history.getHash(history.iframe));
    }

    if (current === history.fragment) {
    return false;
    }

    if (history.iframe) {
    history.navigate(current, false);
    }

    history.loadUrl();
    };