Jelajahi Sumber

History management updates

Vijayakrishnan Krishnan 4 tahun lalu
induk
melakukan
449bbc871f
2 mengubah file dengan 16 tambahan dan 9 penghapusan
  1. 14 7
      public/js/mc.js
  2. 2 2
      public/js/yemi.js

+ 14 - 7
public/js/mc.js

@@ -67,7 +67,10 @@ var findEventHandlers = function (eventType, jqSelector) {
 
 window.top.addEventListener('popstate', function (event) {
     window.setTimeout(function () {
-        if (!event) return;
+        if (!event || !event.state) {
+            console.error('No state!');
+            return;
+        }
         var state = event.state;
         if (state === '') state = '/';
         if (state[0] !== '/') state = '/' + state;
@@ -76,8 +79,8 @@ window.top.addEventListener('popstate', function (event) {
 });
 $(document).ready(function () {
 
-    if(window.location.href === window.top.location.href) {
-        window.location.href = '/mc' + window.location.pathname;
+    if(window.location.pathname === window.top.location.pathname) {
+        window.top.location.href = '/mc' + window.location.pathname;
         return;
     }
     // window.top.ensureRHS();
@@ -111,8 +114,7 @@ $(document).ready(function () {
     if (target.indexOf('/mc') === 0) {
         target = target.split('/mc')[1];
     }
-    // window.top.history.pushState(target, null, '/mc' + target);
-    fastLoad(target, true, false);
+    fastLoad(target, true, false, true);
 
 });
 function enableTimeSpecificFields(_checked, _valueClass, _rangeClass) {
@@ -225,7 +227,7 @@ function onFastLoaded(_data, _href, _history) {
     }
     hideMask();
 }
-function fastLoad(_href, _history = true, _useCache = true) {
+function fastLoad(_href, _history = true, _useCache = true, _replaceState = false) {
 
     showMask();
 
@@ -239,7 +241,12 @@ function fastLoad(_href, _history = true, _useCache = true) {
             }
         }
         if(target[0] === '/') target = target.substr(1);
-        window.top.history.pushState(target, null, '/mc/' + target);
+        if(_replaceState) {
+            window.top.history.replaceState(target, null, '/mc/' + target);
+        }
+        else {
+            window.top.history.pushState(target, null, '/mc/' + target);
+        }
     }
 
     if (_useCache && !!fastCache[_href]) {

+ 2 - 2
public/js/yemi.js

@@ -126,10 +126,10 @@ var pageReload = function () {
 
 var fastReload = function() {
     var targetLocation = window.top.location.pathname;
-    if(targetLocation.indexOf('/mc/') === 0) {
+    if(targetLocation.indexOf('/mc') === 0) {
         targetLocation = targetLocation.substr(3);
     }
-    if(targetLocation[0] !== '/') targetLocation = '/' + targetLocation;
+    if(targetLocation === '' || targetLocation[0] !== '/') targetLocation = '/' + targetLocation;
     fastLoad(targetLocation, false, false);
 }