Prechádzať zdrojové kódy

use fastLoad in yemi pageReload()

Vijayakrishnan 5 rokov pred
rodič
commit
a36c4640b9
2 zmenil súbory, kde vykonal 54 pridanie a 26 odobranie
  1. 52 25
      public/js/mc.js
  2. 2 1
      public/js/yemi.js

+ 52 - 25
public/js/mc.js

@@ -84,8 +84,13 @@ $(document).ready(function() {
 
     initFastLoad();
 });
+
+var fastCache = {};
+
 function initFastLoad(_parent = false) {
 
+    fastCache = {};
+
     var allAs = $('a:not([onclick]):not([href="#"]):visible');
     if(_parent) {
         allAs = _parent.find('a:not([onclick]):not([href="#"]):visible');
@@ -101,36 +106,58 @@ function initFastLoad(_parent = false) {
     });
 
     function enableFastLoad(_a) {
-        var targetParent = $('.stag-content');
         $(_a).on('click', function() {
-            $.get(_a.href, function(_data) {
-                _data = '<div>' + _data + '</div>';
-                var content = $(_data).find('.stag-content');
-                if(content) {
-                    content = content.html();
-                    content += '<script src="/js/yemi.js"></script>';
-                    targetParent.html(content);
-                    initFastLoad(targetParent);
-
-                    // push state
-                    var target = _a.href;
-                    if(target.indexOf('//') !== -1) {
-                        target = target.split('//')[1];
-                        if(target.indexOf('/') !== -1) {
-                            target = target.substr(target.indexOf('/') + 1);
-                        }
-                    }
-                    window.top.history.pushState(target, null, '/mc/' + target);
-
-                }
-                else {
-                    console.warn('Target page not found: ' + this.href);
-                }
-            });
+            fastLoad(this.href, true, true);
             return false;
         });
         console.info('FastLoad enabled for ' + _a.innerText + ' [' + _a.href + ']');
     }
+
+    // fast cache
+    allAs = $('a:not([onclick]):not([href="#"]):visible');
+    allAs.each(function() {
+        var a = this;
+        $.get(a.href, function (_data) {
+            fastCache[a.href] = _data;
+        });
+    });
+
+}
+function fastLoad(_href, _history = true, _useCache = true) {
+    function onData(_data) {
+        var targetParent = $('.stag-content');
+        _data = '<div>' + _data + '</div>';
+        var content = $(_data).find('.stag-content');
+        if(content && content.length) {
+            content = content.html();
+            content += '<script src="/js/yemi.js"></script>';
+            targetParent.html(content);
+            initFastLoad(targetParent);
+
+            // push state
+            if(_history) {
+                var target = _href;
+                if(target.indexOf('//') !== -1) {
+                    target = target.split('//')[1];
+                    if(target.indexOf('/') !== -1) {
+                        target = target.substr(target.indexOf('/') + 1);
+                    }
+                }
+                window.top.history.pushState(target, null, '/mc/' + target);
+            }
+
+        }
+        else {
+            console.warn('Target page not found: ' + _href);
+            window.location.href = _href; // fallback
+        }
+    }
+    if(_useCache && !!fastCache[_href]) {
+        onData(fastCache[_href]);
+    }
+    else {
+        $.get(_href, onData);
+    }
 }
 function openInRHS(_url) {
     window.top.showRHS();

+ 2 - 1
public/js/yemi.js

@@ -117,7 +117,8 @@ var justLog = false; //THIS IS FOR TEST MODE, FORMS WILL NOT TRIGGER REFRESH/RED
 
 var pageReload = function () {
     setTimeout(function () {
-        window.location.reload(true);
+        hideMoeFormMask();
+        fastLoad(window.location.href, false, false);
     }, 500);
 };