From e35f91ca2d0363dde29348841f6776a5d8039f85 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 25 Nov 2022 00:27:39 -0600 Subject: [PATCH] Add ajax reload to org home --- resources/common.js | 2 +- templates/base.html | 1 + templates/loading-page.html | 2 +- templates/organization/home-js.html | 5 ++++ templates/three-column-content.html | 44 ++++++++++++++++------------- 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/resources/common.js b/resources/common.js index baa5009..25e656e 100644 --- a/resources/common.js +++ b/resources/common.js @@ -415,4 +415,4 @@ $(function() { DarkReader.enable(); } }) -}); +}); \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index ca9b245..e1c27cd 100644 --- a/templates/base.html +++ b/templates/base.html @@ -97,6 +97,7 @@ $(function () { $('img.unveil').unveil(200); }); + const loading_page = `{% include "loading-page.html" %}`; {% endcompress %} diff --git a/templates/loading-page.html b/templates/loading-page.html index 2584334..bf1813e 100644 --- a/templates/loading-page.html +++ b/templates/loading-page.html @@ -1 +1 @@ -
L
o
a
d
i
n
g
.
.
.
L
o
a
d
i
n
g
.
.
.
\ No newline at end of file +
L
Q
D
O
J
.
.
.
L
Q
D
O
J
\ No newline at end of file diff --git a/templates/organization/home-js.html b/templates/organization/home-js.html index 37adb4a..0ae4296 100644 --- a/templates/organization/home-js.html +++ b/templates/organization/home-js.html @@ -14,5 +14,10 @@ $(this).parent().submit(); } }); + + $('#control-panel a').on('click', function(e) { + e.preventDefault(); + navigateTo($(this)); + }) }); \ No newline at end of file diff --git a/templates/three-column-content.html b/templates/three-column-content.html index 2faeb51..c9e662c 100644 --- a/templates/three-column-content.html +++ b/templates/three-column-content.html @@ -129,32 +129,36 @@ }) $('#logout').on('click', () => $('#logout-form').submit()); } + + function navigateTo($elem) { + var url = $elem.attr('data-href') || $elem.attr('href'); + + if (url === '#') return; + $('.left-sidebar-item').removeClass('active'); + $elem.addClass('active'); + $('.middle-right-content').html(loading_page); + $.get(url, function(data) { + var reload_content = $(data).find('.middle-right-content'); + + if (reload_content.length) { + window.history.pushState("", "", url); + $('.middle-right-content').html(reload_content.first().html()); + MathJax.typeset($('.middle-right-content')[0]); + onWindowReady(); + } + else { + window.location.href = url; + } + }); + } + $(function () { - const loading_page = `{% include "loading-page.html" %}`; window.addEventListener('popstate', (e) => { window.location.href = e.currentTarget.location.href; }); $('.left-sidebar-item').on('click', function() { - var url = $(this).attr('data-href'); - - if (url === '#') return; - $('.left-sidebar-item').removeClass('active'); - $(this).addClass('active'); - $('.middle-right-content').html(loading_page); - $.get(url, function(data) { - var reload_content = $(data).find('.middle-right-content'); - - if (reload_content.length) { - window.history.pushState("", "", url); - $('.middle-right-content').html(reload_content.first().html()); - MathJax.typeset($('.middle-right-content')[0]); - onWindowReady(); - } - else { - window.location.href = url; - } - }); + navigateTo($(this)); }); $('.blog-box').on('click', function() { var $description = $(this).children('.blog-description');