/* * This file is part of the Tasklog project (https://tasklog.app/) * Copyright (c) 2013 Petr Nagy (http://www.petrnagy.cz/) * See readme.txt for more information */ /** * @author PN @since 2019-07-10 */ var TurboLinks = function(di) { this.di = di; }; // end func TurboLinks.prototype = { init: function() { var that = this; $('#navbar-main ul li a[data-turbolink-supported]').each(function(){ that.register($(this)); }); // if ( that.di.premium.isPremium() ) { // that.register($('#logo-a')); // } // end if // window.EventListener('pageshow') $(window).on('popstate', function() { location.reload(true); }); }, register: function($el) { var that = this; if ( 1 == that.di.settings.get('turbolinks') ) { $el.off('click').on('click', that.handle); } // end if }, // end method handle: function(e) { var that = DI.turbolinks; var $link = $(this); var link = $link.attr('href'); var $body = $('body#body'); if ( e.shiftKey || e.ctrlKey || e.metaKey ) { return; } else { e.preventDefault(); } // end if-else $link.addClass('pending'); $.ajax({ url: link + '?turbo=yes', success: function(html, status, xhr) { let finalLink = xhr.getResponseHeader('X-Last-Location'); finalLink = finalLink ? finalLink : link; finalLink = finalLink.replace(/(\?|\&)turbo=yes.*$/, ''); try { let matches = null; matches = html.match(/([\S\s]*)/m); let turboContent = matches[1]; matches = html.match(/