LocalCDN-Firefox-Chrome-Brave/resources/page.js/1.7.1/page.min.jsm

2 lines
13 KiB
JavaScript
Raw Normal View History

!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.page=e()}}(function(){var define,module,exports;return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){(function(process){"use strict";var pathtoRegexp=require("path-to-regexp");module.exports=page;var clickEvent="undefined"!==typeof document&&document.ontouchstart?"touchstart":"click";var location="undefined"!==typeof window&&(window.history.location||window.location);var dispatch=true;var decodeURLComponents=true;var base="";var running;var hashbang=false;var prevContext;function page(path,fn){if("function"===typeof path){return page("*",path)}if("function"===typeof fn){var route=new Route(path);for(var i=1;i<arguments.length;++i){page.callbacks.push(route.middleware(arguments[i]))}}else if("string"===typeof path){page["string"===typeof fn?"redirect":"show"](path,fn)}else{page.start(path)}}page.callbacks=[];page.exits=[];page.current="";page.len=0;page.base=function(path){if(0===arguments.length)return base;base=path};page.start=function(options){options=options||{};if(running)return;running=true;if(false===options.dispatch)dispatch=false;if(false===options.decodeURLComponents)decodeURLComponents=false;if(false!==options.popstate)window.addEventListener("popstate",onpopstate,false);if(false!==options.click){document.addEventListener(clickEvent,onclick,false)}if(true===options.hashbang)hashbang=true;if(!dispatch)return;var url=hashbang&&~location.hash.indexOf("#!")?location.hash.substr(2)+location.search:location.pathname+location.search+location.hash;page.replace(url,null,true,dispatch)};page.stop=function(){if(!running)return;page.current="";page.len=0;running=false;document.removeEventListener(clickEvent,onclick,false);window.removeEventListener("popstate",onpopstate,false)};page.show=function(path,state,dispatch,push){var ctx=new Context(path,state);page.current=ctx.path;if(false!==dispatch)page.dispatch(ctx);if(false!==ctx.handled&&false!==push)ctx.pushState();return ctx};page.back=function(path,state){if(page.len>0){history.back();page.len--}else if(path){setTimeout(function(){page.show(path,state)})}else{setTimeout(function(){page.show(base,state)})}};page.redirect=function(from,to){if("string"===typeof from&&"string"===typeof to){page(from,function(e){setTimeout(function(){page.replace(to)},0)})}if("string"===typeof from&&"undefined"===typeof to){setTimeout(function(){page.replace(from)},0)}};page.replace=function(path,state,init,dispatch){var ctx=new Context(path,state);page.current=ctx.path;ctx.init=init;ctx.save();if(false!==dispatch)page.dispatch(ctx);return ctx};page.dispatch=function(ctx){var prev=prevContext,i=0,j=0;prevContext=ctx;function nextExit(){var fn=page.exits[j++];if(!fn)return nextEnter();fn(prev,nextExit)}function nextEnter(){var fn=page.callbacks[i++];if(ctx.path!==page.current){ctx.handled=false;return}if(!fn)return unhandled(ctx);fn(ctx,nextEnter)}if(prev){nextExit()}else{nextEnter()}};function unhandled(ctx){if(ctx.handled)return;var current;if(hashbang){current=base+location.hash.replace("#!","")}else{current=location.pathname+location.search}if(current===ctx.canonicalPath)return;page.stop();ctx.handled=false;location.href=ctx.canonicalPath}page.exit=function(path,fn){if(typeof path==="function"){return page.exit("*",path)}var route=new Route(path);for(var i=1;i<arguments.length;++i){page.exits.push(route.middleware(arguments[i]))}};function decodeURLEncodedURIComponent(val){if(typeof val!=="string"){ret