]> git.0d.be Git - panikdb.git/commitdiff
wiki: use ajax to load interwiki links
authorFrédéric Péters <fpeters@0d.be>
Tue, 23 Jun 2020 11:58:40 +0000 (13:58 +0200)
committerFrédéric Péters <fpeters@0d.be>
Tue, 23 Jun 2020 15:46:17 +0000 (17:46 +0200)
panikdb/static/css/style.scss
panikdb/static/js/combo.wiki.js

index 3112f481e479900442be84e6f5547505ce3f03b0..810c1170dbdbcbb6509ec97e93ee4e76418f0300 100644 (file)
@@ -797,3 +797,23 @@ div#content div.wiki-section h4.intertitle {
 #image-upload {
        visibility: hidden;
 }
+
+body.loading::before {
+       content: "";
+       position: fixed;
+       top: 0;
+       left: 0;
+       right: 0;
+       height: 10px;
+       background: #386ede;
+       z-index: 1100;
+       animation-name: load_animation;
+       animation-duration: 1000ms;
+       animation-timing-function: ease-out;
+       transition: opacity 200ms linear;
+}
+
+@keyframes load_animation {
+       0% { right: 100%; }
+       100% { right: 0%; }
+}
index 3123d3af1c905e2d77bae9bee57ccd04fb878c6c..4ae7aaf5a87433a52ec6e5336e466b03e763941a 100644 (file)
@@ -418,7 +418,7 @@ function auto_anchors() {
   };
 }(window, document));
 
-$(function() {
+function init_page() {
   if (window.localStorage) {
     var breadcrumbs = window.localStorage.wiki_breadcrumbs;
     if (breadcrumbs) {
@@ -487,7 +487,45 @@ $(function() {
     }
   });
   $('#quickedit input').trigger('change');
+
+  function load_page(href, push_history) {
+    $('body').addClass('loading');
+    var content = $.ajax({
+      url: href,
+      dataType: 'html',
+      success: function(html, status, xhr) {
+        Phylly.off(),
+        $('div[data-edit-url] > div').each(function(i, elem) {
+          Phylly.unbind_events(elem);
+        });
+        if (push_history) history.pushState({}, '', href);
+        $('body').removeClass('loading');
+        $('#main-content').replaceWith($(html).find('#main-content'));
+        init_page();
+      },
+      error: function() {
+        $('body').removeClass('loading');
+      },
+    });
+  }
+
+  $(window).on('popstate', function(e) {
+    load_page(location.href, false);
+  });
+
+  $('#main-content').on('click', 'a[href]:not([rel])', function(e) {
+    var href = this.attributes.href.nodeValue;
+    if (e.which === 2) return true;
+    if (href.slice(0, 6) == '/wiki/') {
+      load_page(this.href, true);
+      return false;
+    }
+  });
   $('div.wiki-section').on('click', 'img[data-orig-url]', function() {
     window.location = $(this).data('orig-url');
   });
+}
+
+$(function() {
+  init_page();
 });