Commit 2f41f3c8 authored by Eli's avatar Eli Committed by Andrei Mateescu
Browse files

Issue #3295914 by 3li: Failed to execute 'pushState' on 'History'

parent 224f0c9b
Loading
Loading
Loading
Loading
+21 −7
Original line number Diff line number Diff line
@@ -125,6 +125,25 @@
    return url[0] + (query.length ? '?' + query.join('&') : '');
  };

  /**
   * Remove the functions from the state. They can't been pushed into the history.
   *
   * @param state
   *  Object containing the state to be cleaned.
   *
   * @return state
   *  Object that has been cleaned up.
   */
  var cleanStateForHistory = function (state) {
    var stateWithNoFunctions = {};
    for (var key in state) {
      if (typeof state[key] !== "function") {
        stateWithNoFunctions[key] = state[key];
      }
    }
    return stateWithNoFunctions;
  };

  /**
   * Parse a URL query string.
   *
@@ -152,17 +171,12 @@
   */
  var addState = function (options, url) {
    // The data in the history state must be serializable.
    var historyOptions = $.extend({}, options)
    delete historyOptions.beforeSend;
    delete historyOptions.beforeSerialize;
    delete historyOptions.beforeSubmit;
    delete historyOptions.complete;
    delete historyOptions.success;
    var historyOptions = $.extend({}, options);

    // Store the actual view's dom id.
    drupalSettings.viewsAjaxHistory.lastViewDomID = options.data.view_dom_id;
    $(window).unbind('popstate', loadView);
    history.pushState(historyOptions, document.title, cleanURL(url, options.data));
    history.pushState(cleanStateForHistory(historyOptions), document.title, cleanURL(url, options.data));
    $(window).bind('popstate', loadView);
  };