aboutsummaryrefslogtreecommitdiffstats
path: root/resources/lib/oojs-router
diff options
context:
space:
mode:
authorJon Robson <jdlrobson@gmail.com>2024-02-29 14:47:26 -0800
committerJames D. Forrester <jforrester@wikimedia.org>2024-05-04 09:19:34 +0300
commite5eaf49989d94479c6a480c54da836d0eb940360 (patch)
tree83c7b5758ce41bd3cbe59d30549536e3542b56f5 /resources/lib/oojs-router
parentaed5b52caa5f4ad3d4153ed3aad2a280ff9545e3 (diff)
downloadmediawikicore-e5eaf49989d94479c6a480c54da836d0eb940360.tar.gz
mediawikicore-e5eaf49989d94479c6a480c54da836d0eb940360.zip
Move oojs-router into core, to allow archiving of npm module
Doing this should make it easier for us to fix bugs and maintain this, there seems little benefit in having this published on npm. Bug: T358813 Change-Id: I515e415a129da881eecdb86d8e6a274bf7584b4a
Diffstat (limited to 'resources/lib/oojs-router')
-rw-r--r--resources/lib/oojs-router/AUTHORS.txt7
-rw-r--r--resources/lib/oojs-router/History.md22
-rw-r--r--resources/lib/oojs-router/LICENSE20
-rw-r--r--resources/lib/oojs-router/oojs-router.js231
4 files changed, 0 insertions, 280 deletions
diff --git a/resources/lib/oojs-router/AUTHORS.txt b/resources/lib/oojs-router/AUTHORS.txt
deleted file mode 100644
index a406b57ac6a2..000000000000
--- a/resources/lib/oojs-router/AUTHORS.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-Ed Sanders <esanders@wikimedia.org>
-James D. Forrester <jforrester@wikimedia.org>
-Jon Robson <jdlrobson@gmail.com>
-Kunal Mehta <legoktm@member.fsf.org>
-MarcoAurelio <maurelio@tools.wmflabs.org>
-Prateek Saxena <prtksxna@gmail.com>
-Timo Tijhof <krinklemail@gmail.com>
diff --git a/resources/lib/oojs-router/History.md b/resources/lib/oojs-router/History.md
deleted file mode 100644
index 29c6c0297800..000000000000
--- a/resources/lib/oojs-router/History.md
+++ /dev/null
@@ -1,22 +0,0 @@
-# OOjs Router Release History
-
-## v0.5.0 / 2024/03/04
-* [BREAKING CHANGE] Require oojs 7.0.1, up from 6.0.0 (James D. Forrester)
-* [BREAKING CHANGE] Re-write to require ES6, up from ES5 (James D. Forrester)
-* [BREAKING CHANGE] Raise jQuery requirement from v3.6.0 to v3.7.1 (James D. Forrester)
-* Clean up parent->super (Ed Sanders)
-
-## v0.4.0 / 2023-08-30
-* Use native event handling (Jon Robson)
-
-## v0.3.0 / 2021-09-09
-* [BREAKING CHANGE] Require OOjs v6.0.0, up from v2.0.0 (James D. Forrester)
-* [BREAKING CHANGE] Require jQuery v3.6.0, up from v3.3.1 (James D. Forrester)
-
-## v0.2.0 / 2019-02-06
-* Add OO.Router `navigateTo()` method for accessing replaceState (Jon Robson)
-* build: Add AUTHORS.txt to package manifest (James D. Forrester)
-
-## v0.1.0 / 2016-05-05
-* Initial commit (Jon Robson)
-* Add build, CI infrastructure (James D. Forrester)
diff --git a/resources/lib/oojs-router/LICENSE b/resources/lib/oojs-router/LICENSE
deleted file mode 100644
index acbe7089902a..000000000000
--- a/resources/lib/oojs-router/LICENSE
+++ /dev/null
@@ -1,20 +0,0 @@
-Copyright 2011-2016 OOjs Team and other contributors.
-
-Permission is hereby granted, free of charge, to any person obtaining
-a copy of this software and associated documentation files (the
-"Software"), to deal in the Software without restriction, including
-without limitation the rights to use, copy, modify, merge, publish,
-distribute, sublicense, and/or sell copies of the Software, and to
-permit persons to whom the Software is furnished to do so, subject to
-the following conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/resources/lib/oojs-router/oojs-router.js b/resources/lib/oojs-router/oojs-router.js
deleted file mode 100644
index d0e24dd8dde7..000000000000
--- a/resources/lib/oojs-router/oojs-router.js
+++ /dev/null
@@ -1,231 +0,0 @@
-/*!
- * OOjs Router v0.5.0
- * https://www.mediawiki.org/wiki/OOjs_Router
- *
- * Copyright 2011-2024 OOjs Team and other contributors.
- * Released under the MIT license
- * http://oojs.mit-license.org
- *
- * Date: 2024-03-04T20:48:16Z
- */
-( function ( $ ) {
-
-'use strict';
-
-/**
- * Provides navigation routing and location information
- *
- * @class OO.Router
- * @extends OO.Registry
- */
-OO.Router = function OoRouter() {
- const router = this;
-
- // Parent constructor
- OO.Router.super.call( this );
-
- this.enabled = true;
- this.oldHash = this.getPath();
-
- window.addEventListener( 'popstate', function () {
- router.emit( 'popstate' );
- } );
-
- window.addEventListener( 'hashchange', function () {
- router.emit( 'hashchange' );
- } );
-
- this.on( 'hashchange', function () {
- // event.originalEvent.newURL is undefined on Android 2.x
- let routeEvent;
-
- if ( router.enabled ) {
- routeEvent = $.Event( 'route', {
- path: router.getPath()
- } );
- router.emit( 'route', routeEvent );
-
- if ( !routeEvent.isDefaultPrevented() ) {
- router.checkRoute();
- } else {
- // if route was prevented, ignore the next hash change and revert the
- // hash to its old value
- router.enabled = false;
- router.navigate( router.oldHash );
- }
- } else {
- router.enabled = true;
- }
-
- router.oldHash = router.getPath();
- } );
-};
-
-/* Inheritance */
-
-OO.inheritClass( OO.Router, OO.Registry );
-
-/* Events */
-
-/**
- * @event popstate
- */
-
-/**
- * @event hashchange
- */
-
-/**
- * @event route
- * @param {jQuery.Event} routeEvent
- */
-
-/* Static Methods */
-
-/**
- * Determine if current browser supports this router
- *
- * @return {boolean} The browser is supported
- */
-OO.Router.static.isSupported = function () {
- return 'onhashchange' in window;
-};
-
-/* Methods */
-
-/**
- * Check the current route and run appropriate callback if it matches.
- */
-OO.Router.prototype.checkRoute = function () {
- const hash = this.getPath();
-
- let id, entry, match;
-
- for ( id in this.registry ) {
- entry = this.registry[ id ];
- match = hash.match( entry.path );
- if ( match ) {
- entry.callback.apply( this, match.slice( 1 ) );
- return;
- }
- }
-};
-
-/**
- * Bind a specific callback to a hash-based route, e.g.
- *
- * @example
- * addRoute( 'alert', function () { alert( 'something' ); } );
- * addRoute( /hi-(.*)/, function ( name ) { alert( 'Hi ' + name ) } );
- *
- * Note that after defining all available routes it is up to the caller
- * to check the existing route via the checkRoute method.
- *
- * @param {string|RegExp} path Path to match, string or regular expression
- * @param {Function} callback Callback to be run when hash changes to one
- * that matches.
- */
-OO.Router.prototype.addRoute = function ( path, callback ) {
- const entry = {
- path: typeof path === 'string' ?
- // eslint-disable-next-line security/detect-non-literal-regexp
- new RegExp( '^' + path.replace( /[\\^$*+?.()|[\]{}]/g, '\\$&' ) + '$' ) :
- path,
- callback: callback
- };
- this.register( entry.path.toString(), entry );
-};
-
-/**
- * @deprecated Use #addRoute
- */
-OO.Router.prototype.route = OO.Router.prototype.addRoute;
-
-/**
- * Navigate to a specific route.
- *
- * @param {string} title of new page
- * @param {Object} options
- * @param {string} options.path e.g. '/path/' or '/path/#foo'
- * @param {boolean} options.useReplaceState Set replaceStateState to use pushState when you want to
- * avoid long history queues.
- */
-OO.Router.prototype.navigateTo = function ( title, options ) {
- if ( options.useReplaceState ) {
- history.replaceState( null, title, options.path );
- } else {
- history.pushState( null, title, options.path );
- }
-};
-
-/**
- * Navigate to a specific ''hash fragment'' route.
- *
- * @param {string} path String with a route (hash without #).
- * @deprecated use navigateTo instead
- */
-OO.Router.prototype.navigate = function ( path ) {
- // Take advantage of `pushState` when available, to clear the hash and
- // not leave `#` in the history. An entry with `#` in the history has
- // the side-effect of resetting the scroll position when navigating the
- // history.
- if ( path === '' ) {
- // To clear the hash we need to cut the hash from the URL.
- path = window.location.href.replace( /#.*$/, '' );
- history.pushState( null, document.title, path );
- this.checkRoute();
- } else {
- window.location.hash = path;
- }
-};
-
-/**
- * Navigate to the previous route. This is a wrapper for window.history.back
- *
- * @return {jQuery.Promise} Promise which resolves when the back navigation is complete
- */
-OO.Router.prototype.back = function () {
- const router = this,
- deferred = $.Deferred();
-
- this.once( 'popstate', function () {
- // eslint-disable-next-line no-use-before-define
- clearTimeout( timeoutID );
- deferred.resolve();
- } );
-
- window.history.back();
-
- // If for some reason (old browser, bug in IE/windows 8.1, etc) popstate doesn't fire,
- // resolve manually. Since we don't know for sure which browsers besides IE10/11 have
- // this problem, it's better to fall back this way rather than singling out browsers
- // and resolving the deferred request for them individually.
- // See https://connect.microsoft.com/IE/feedback/details/793618/history-back-popstate-not-working-as-expected-in-webview-control
- // Give browser a few ms to update its history.
- const timeoutID = setTimeout( function () {
- router.off( 'popstate' );
- deferred.resolve();
- }, 50 );
-
- return deferred.promise();
-};
-
-/**
- * Get current path (hash).
- *
- * @return {string} Current path.
- */
-OO.Router.prototype.getPath = function () {
- return window.location.hash.slice( 1 );
-};
-
-/**
- * @deprecated Use static method
- */
-OO.Router.prototype.isSupported = OO.Router.static.isSupported;
-
-if ( typeof module !== 'undefined' && module.exports ) {
- module.exports = OO.Router;
-}
-
-}( jQuery ) );