This commit is contained in:
2024-12-20 06:04:35 +03:00
parent 0f779b7ebf
commit d630370039
267 changed files with 34950 additions and 11 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013 yeikos
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.
+199
View File
@@ -0,0 +1,199 @@
jQuery.history v1.1.0
==================================================
What is it?
--------------------------------------
It's a jQuery plugin that lets manage the browser history using history.pushState (HTML5) and cross-browser compatibility (including IE6).
Demo online
--------------------------------------
http://fiddle.jshell.net/yeikos/rcZWb/show/light
Changelog
--------------------------------------
**v1.1.0 - 20/07/13**
- New methods: `url`, `type`.
- New event: `pushed`.
- Bug fix in `load` event.
**v1.0.1 - 07/05/13**
- Bug fix in `load` event.
**v1.0.0 - 28/01/13**
- Initial version.
Example
--------------------------------------
<!DOCTYPE html><html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/yeikos/jquery.history/jquery.history.js"></script>
<script>
$(function() {
$.history.on('load change push pushed', function(event, url, type) {
alert(event.type + ': ' + url);
}).listen('hash');
$('body').on('click', 'a', function(event) {
$.history.push($(this).attr('href'));
event.preventDefault();
});
$('button').click(function() {
location.reload();
});
});
</script>
</head>
<body>
<ul>
<li><a href="/one">one</a></li>
<li><a href="/two">two</a></li>
<li><a href="/three">three</a></li>
<li><a href="/four">four</a></li>
</ul>
<button>refresh</button>
</body>
</html>
Events
--------------------------------------
**load**
> Fired when the listen is started.
**push**
> Fired before `jQuery.history.push` is called (it can be prevented).
**pushed**
> Fired after `jQuery.history.push` is called.
**change**
> Fired when it happens a change in browser history (back, forward, go).
All events are trigger passing two arguments (address, listen type).
API Methods
--------------------------------------
**jQuery.history.push(address)**
_address: string._
> Add a new address to history (first it is needed call to `listen`).
returns `jQuery.history`.
***
**jQuery.history.listen()**
> Starts a automatic listening in base to browser support and in this order: pathname, hash or hash interval.
returns `jQuery.history`.
**jQuery.history.listen('pathname')**
> Starts a listening using `pathname` (pushState).
returns `jQuery.history`.
**jQuery.history.listen('hash')**
> Starts a listening using `hash` (onhaschange). If browser doesn't supports it, then it will use a emulation (hash interval).
returns `jQuery.history`.
**jQuery.history.listen('hash', interval)**
_interval: interval delay (number). If interval is `true`, it will convert to jQuery.history.config.interval._
> Starts a listening using an emulation (hash interval).
returns `jQuery.history`.
***
**jQuery.history.unlisten()**
> Undoes all changes done by `jQuery.history.listen`.
returns `jQuery.history`.
***
**jQuery.history.url()**
> Get the current URL.
returns `string`.
***
**jQuery.history.type()**
> Get the current listening type (hash, pathname or null).
returns `string` or `null`.
***
**jQuery.history.on**
> http://api.jquery.com/on/
returns `jQuery.history`.
***
**jQuery.history.off**
> http://api.jquery.com/off/
returns `jQuery.history`.
***
**jQuery.history.trigger**
> http://api.jquery.com/trigger/
returns `jQuery.history`.
+57
View File
@@ -0,0 +1,57 @@
<!DOCTYPE html><html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/yeikos/jquery.history/jquery.history.js"></script>
<script>
$(function() {
$.history.on('load change push pushed', function(event, url, type) {
alert(event.type + ': ' + url);
}).listen('hash');
$('body').on('click', 'a', function(event) {
$.history.push($(this).attr('href'));
event.preventDefault();
});
$('button').click(function() {
location.reload();
});
});
</script>
</head>
<body>
<ul>
<li><a href="/one">one</a></li>
<li><a href="/two">two</a></li>
<li><a href="/three">three</a></li>
<li><a href="/four">four</a></li>
</ul>
<button>refresh</button>
</body>
</html>
@@ -0,0 +1,6 @@
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?section=$1 [L,QSA]
@@ -0,0 +1 @@
Put this files (index.php, .htaccess) into root folder of HTTP server.
@@ -0,0 +1,95 @@
<!DOCTYPE html><html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/yeikos/jquery.history/jquery.history.js"></script>
<script>
$(function() {
var type;
$.history.on('load change', function(event, url, type) {
if (event.type === 'change' || (event.type === 'load' && type === 'hash'))
request(url);
}).listen();
type = $.history.type();
if (type === 'hash' && location.pathname.length > 1) {
// /pathname -> /#/pathname
location.href = '/#' + location.pathname;
} else if (type === 'pathname' && location.hash.substr(1, 1) === '/') {
// /#/pathname -> /pathname
location.href = location.hash.substr(1);
}
// dom listener
$('body').on('click', 'a', function(event) {
var url = $(this).attr('href');
$.history.push(url);
request(url);
event.preventDefault();
});
// request
function request(url) {
$('#output').text(url);
}
});
</script>
</head>
<body>
<div>time: <?php echo time(); ?></div>
<ul>
<li><a href="/one">one</a></li>
<li><a href="/two">two</a></li>
<li><a href="/three">three</a></li>
<li><a href="/four">four</a></li>
</ul>
<div id="output">
<?php
echo isset($_GET['section']) ? htmlspecialchars('/' . $_GET['section']) : '';
?>
</div>
</body>
</html>
+450
View File
@@ -0,0 +1,450 @@
/*!
* @name jQuery.history v1.1.0
* @author yeikos
* @repository https://github.com/yeikos/jquery.history
* @dependencies jQuery 1.7.0+
* Copyright 2013 yeikos - MIT license
* https://raw.github.com/yeikos/js.merge/master/LICENSE
*/
;(function($, undefined) {
var Public = function(url) {
var event = $.Event('push');
Public.context.trigger(event, [url, _type]);
if (event.isDefaultPrevented())
return Public;
// Establecemos la nueva dirección siempre y cuando haya cambiado
if (_type === 'pathname') {
if (_last !== url)
window.history.pushState({}, null, _last = url);
} else if (_type === 'hash') {
if (_last !== url) {
location.hash = _last = url;
// Si se trata de IE6/IE7
if (_ie67) {
// El `iframe` ha de encontrarse en el documento
if (!$('#jQueryHistory').length)
throw new Error('jQuery.' + publicName + '.push: iframe not found.');
// Si es la primera vez
if (_firstTime) {
_firstTime = 0;
// Añadimos primero al historial una entrada vacía para que el usuario
// pueda volver al inicio de página, de lo contrario saldrá fuera de ella
_iframe.contentWindow.document.open().close();
_iframe.contentWindow.location.hash = '/';
}
// Cambiamos la dirección del `iframe` para simular el historial
_iframe.contentWindow.document.open().close();
_iframe.contentWindow.location.hash = url;
}
}
} else {
// Es necesario que se haya iniciado una escucha activa para establecer una dirección
throw new Error('jQuery.' + publicName + '.push: the listening is not active.');
}
Public.context.trigger('pushed', [url, _type]);
return Public;
}, publicName = 'history';
// Contexto donde se centralizan los eventos (`load`, `change`, `push`, `pushed`)
Public.context = $({});
// Accesos directos a los métodos `on`, `off` y `trigger`
$.each(['on', 'off', 'trigger'], function(index, method) {
Public[method] = function() {
Public.context[method].apply(Public.context, arguments);
return Public;
};
});
// Acceso directo a la función principal
Public.push = Public;
// Obtiene el tipo de escucha actual (`pathname`, `hash`, `null`)
Public.type = function() {
return _type;
};
// Obtiene la dirección actual según el tipo de escucha
Public.url = function(_location) {
_location = _location || location;
if (_type === null)
throw new Error ('jQuery.' + publicName + '.url: the listening has not started.');
if (_type === 'pathname')
return _location.pathname + _location.search + _location.hash;
if (_location.hash.length > 1) {
spl = _location.href.split('#');
spl.shift();
spl = spl.join('#');
return spl;
}
return '';
};
// Inicializa una escucha en el documento para intervenir los cambios del historial y poder establecer direcciones
Public.listen = function(type, interval) {
// Desactivamos posibles escuchas anteriores
Public.unlisten();
var size = arguments.length;
// Detección automática del modo de escucha
if (!size || type === 'auto') {
type = _pushState ? 'pathname' : 'hash';
size = 1;
} else if (type !== 'pathname' && type !== 'hash') {
throw new Error('jQuery.' + publicName + '.listen: type is not valid.');
}
// Si el modo de escucha es `hash`
if (type === 'hash') {
// Si no hay soporte para `onhaschange` y no se especificó un intervalo, o el intervalo es `true`
if ((!_onhashchange && size === 1) || interval === true) {
// Establecemos el intervalo de la configuración
interval = Public.config.interval;
size = 2;
}
// Si el intervalo fue fijado comprobamos si su valor es correcto
if (size === 2 && (isNaN(interval) || interval < 1))
throw new Error('jQuery.' + publicName + '.listen: interval delay is not valid.');
}
// Si el modo de escucha es `pathname`
if ((_type = type) === 'pathname') {
// Ha de haber soporte nativo
if (!_pushState)
throw new Error('jQuery.' + publicName + '.listen: this browser has not support to pushState.');
// Cuando haya un cambio en la dirección URL
$(window).on('popstate.history', function(event) {
// Si se trata de un evento real originado internamente por el navegador
// y la dirección ha cambiado emitimos el evento `change`
if (event.originalEvent && event.originalEvent.state && _last !== location.pathname)
Public.trigger('change', [_last = Public.url(), 'pathname']);
});
if (location.pathname.length > 1)
Public.trigger('load', [Public.url(), 'pathname']);
} else {
// Si hay soporte nativo de `onhashchange` y no se especificó el argumento intervalo
if (_onhashchange && !interval) {
// Hacemos uso del evento nativo `hashchange`
$(window).on('hashchange.history', function(event) {
var hash = Public.url();
if (_last !== hash)
Public.trigger('change', [_last = hash, 'hash']);
});
// Si no hay soporte o simplemente se especificó el argumento intervalo
} else {
// Si no se ha detecto si el navegador es IE6/IE7
if (_ie67 === undefined)
// Realizamos la comprobación una sola vez
_ie67 = Public.ieCondition('lte IE 7');
// Si se trata de IE6/IE7
if (_ie67) {
// Es necesario que se encuentre disponible `body` (dom ready)
if (!(size = $('body')).length)
throw new Error('jQuery.' + publicName + '.listen: document is not ready.');
// Creamos un `iframe` con el que emular el historial
_iframe = $('<iframe id="jQueryHistory" style="display:none" src="javascript:void(0);" />').appendTo(size)[0];
var win = _iframe.contentWindow;
// Si el documento ya contiene una dirección, la establecemos en el `iframe`
if (location.hash.length > 1) {
win.document.open().close();
win.location.hash = '#' + Public.url();
}
// Emulamos el evento `haschange` mediante un intervalo
_interval = setInterval(function() {
// Si la dirección actual es diferente a la del `iframe`
if ((_last = '#' + Public.url()) !== ('#' + Public.url(win.location))) {
// Actualizamos la dirección del `iframe`
win.document.open().close();
win.location.hash = _last;
Public.trigger('change', [_last.substr(1), 'hash']);
}
}, interval);
} else {
// Emulamos el evento `haschange` mediante un intervalo
_last = Public.url();
_interval = setInterval(function() {
var hash = Public.url();
if (_last !== hash)
Public.trigger('change', [_last = hash, 'hash']);
}, interval);
}
}
// Si ya se encuentra un `hash` definido en el documento
if (location.hash.length > 1) {
// Emitimos el evento `load`
Public.trigger('load', [Public.url(), 'hash']);
}
}
return Public;
};
// Desactiva cualquier tipo de escucha realizada por `listen`
Public.unlisten = function() {
_type = _last = _iframe = null;
$(window).off('popstate.history hashchange.history');
$('#jQueryHistory').remove();
clearInterval(_interval);
return Public;
};
// Obtiene el soporte de ciertas funcionalidades del navegador
Public.getSupports = function(type) {
var result = {},
size = arguments.length,
docmode;
if (!size || type === 'pushState')
result.pushState = ('pushState' in window.history);
if (!size || type === 'onhashchange')
result.onhashchange = ('onhashchange' in window && ((docmode = document.documentMode) === undefined || docmode > 7 ));
if (size)
return result[type];
return result;
};
// Comprueba si el navegador corresponde con las versiones de IE especificadas
Public.ieCondition = function(input) {
var id = Math.random().toString(36).substring(2),
name = '_ie_condition_' + id,
$msie, result;
$msie = $('<span><!--[if ' + $('<i/>').html(input).text() + ']><script type="text/javascript">window.' + name + '=true;</script><![endif]--></span>').appendTo(document.body);
result = (window[name] === true);
try {
delete window[name];
} catch(e) {
window[name] = undefined;
}
$msie.remove();
return result;
};
// Soporte de funcionalidades del navegador
Public.supports = Public.getSupports();
// Configuración
Public.config = {
// Retraso del intervalo en la emulación del evento `haschange`
interval: 100
};
// Accesos directos a los soportes
var _pushState = Public.supports.pushState,
_onhashchange = Public.supports.onhashchange,
// Versión IE6/7
_ie67 = Public.ieCondition('lte IE 7'),
// Tipo actual de escucha
_type = null,
// Intervalo utilizado por la emulación del evento `hashchange`
_interval,
// Iframe utilizado para generar el historial en IE6/IE7
_iframe,
// Marcador utilizado por IE6/IE7
_firstTime = 1,
// Última dirección establecida
_last;
// Acceso desde al exterior
$[publicName] = Public;
})(jQuery);
+3
View File
@@ -0,0 +1,3 @@
/*! jQuery.history v1.1.0 | Copyright 2013 yeikos - MIT license | https://github.com/yeikos/jquery.history */
;(function(e,t){var n=function(t){var i=e.Event("push");n.context.trigger(i,[t,u]);if(i.isDefaultPrevented())return n;if(u==="pathname"){if(c!==t)window.history.pushState({},null,c=t)}else if(u==="hash"){if(c!==t){location.hash=c=t;if(o){if(!e("#jQueryHistory").length)throw new Error("jQuery."+r+".push: iframe not found.");if(l){l=0;f.contentWindow.document.open().close();f.contentWindow.location.hash="/"}f.contentWindow.document.open().close();f.contentWindow.location.hash=t}}}else{throw new Error("jQuery."+r+".push: the listening is not active.")}n.context.trigger("pushed",[t,u]);return n},r="history";n.context=e({});e.each(["on","off","trigger"],function(e,t){n[t]=function(){n.context[t].apply(n.context,arguments);return n}});n.push=n;n.type=function(){return u};n.url=function(e){e=e||location;if(u===null)throw new Error("jQuery."+r+".url: the listening has not started.");if(u==="pathname")return e.pathname+e.search+e.hash;if(e.hash.length>1){spl=e.href.split("#");spl.shift();spl=spl.join("#");return spl}return""};n.listen=function(l,h){n.unlisten();var p=arguments.length;if(!p||l==="auto"){l=i?"pathname":"hash";p=1}else if(l!=="pathname"&&l!=="hash"){throw new Error("jQuery."+r+".listen: type is not valid.")}if(l==="hash"){if(!s&&p===1||h===true){h=n.config.interval;p=2}if(p===2&&(isNaN(h)||h<1))throw new Error("jQuery."+r+".listen: interval delay is not valid.")}if((u=l)==="pathname"){if(!i)throw new Error("jQuery."+r+".listen: this browser has not support to pushState.");e(window).on("popstate.history",function(e){if(e.originalEvent&&e.originalEvent.state&&c!==location.pathname)n.trigger("change",[c=n.url(),"pathname"])});if(location.pathname.length>1)n.trigger("load",[n.url(),"pathname"])}else{if(s&&!h){e(window).on("hashchange.history",function(e){var t=n.url();if(c!==t)n.trigger("change",[c=t,"hash"])})}else{if(o===t)o=n.ieCondition("lte IE 7");if(o){if(!(p=e("body")).length)throw new Error("jQuery."+r+".listen: document is not ready.");f=e('<iframe id="jQueryHistory" style="display:none" src="javascript:void(0);" />').appendTo(p)[0];var d=f.contentWindow;if(location.hash.length>1){d.document.open().close();d.location.hash="#"+n.url()}a=setInterval(function(){if((c="#"+n.url())!=="#"+n.url(d.location)){d.document.open().close();d.location.hash=c;n.trigger("change",[c.substr(1),"hash"])}},h)}else{c=n.url();a=setInterval(function(){var e=n.url();if(c!==e)n.trigger("change",[c=e,"hash"])},h)}}if(location.hash.length>1){n.trigger("load",[n.url(),"hash"])}}return n};n.unlisten=function(){u=c=f=null;e(window).off("popstate.history hashchange.history");e("#jQueryHistory").remove();clearInterval(a);return n};n.getSupports=function(e){var n={},r=arguments.length,i;if(!r||e==="pushState")n.pushState="pushState"in window.history;if(!r||e==="onhashchange")n.onhashchange="onhashchange"in window&&((i=document.documentMode)===t||i>7);if(r)return n[e];return n};n.ieCondition=function(n){var r=Math.random().toString(36).substring(2),i="_ie_condition_"+r,s,o;s=e("<span><!--[if "+e("<i/>").html(n).text()+']><script type="text/javascript">window.'+i+"=true;</script><![endif]--></span>").appendTo(document.body);o=window[i]===true;try{delete window[i]}catch(u){window[i]=t}s.remove();return o};n.supports=n.getSupports();n.config={interval:100};var i=n.supports.pushState,s=n.supports.onhashchange,o=n.ieCondition("lte IE 7"),u=null,a,f,l=1,c;e[r]=n})(jQuery);
+24
View File
@@ -0,0 +1,24 @@
<!DOCTYPE html><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jQuery.history v1.1.0</title>
<link rel="stylesheet" href="qunit/qunit.css" />
<script src="qunit/qunit.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
<script src="../jquery.history.js"></script>
<script src="tests.js"></script>
</head>
<body>
<div id="qunit"></div>
</body>
</html>
+244
View File
@@ -0,0 +1,244 @@
/**
* QUnit v1.11.0 - A JavaScript Unit Testing Framework
*
* http://qunitjs.com
*
* Copyright 2012 jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
/** Font Family and Sizes */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
}
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
#qunit-tests { font-size: smaller; }
/** Resets */
#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
margin: 0;
padding: 0;
}
/** Header */
#qunit-header {
padding: 0.5em 0 0.5em 1em;
color: #8699a4;
background-color: #0d3349;
font-size: 1.5em;
line-height: 1em;
font-weight: normal;
border-radius: 5px 5px 0 0;
-moz-border-radius: 5px 5px 0 0;
-webkit-border-top-right-radius: 5px;
-webkit-border-top-left-radius: 5px;
}
#qunit-header a {
text-decoration: none;
color: #c2ccd1;
}
#qunit-header a:hover,
#qunit-header a:focus {
color: #fff;
}
#qunit-testrunner-toolbar label {
display: inline-block;
padding: 0 .5em 0 .1em;
}
#qunit-banner {
height: 5px;
}
#qunit-testrunner-toolbar {
padding: 0.5em 0 0.5em 2em;
color: #5E740B;
background-color: #eee;
overflow: hidden;
}
#qunit-userAgent {
padding: 0.5em 0 0.5em 2.5em;
background-color: #2b81af;
color: #fff;
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
}
#qunit-modulefilter-container {
float: right;
}
/** Tests: Pass/Fail */
#qunit-tests {
list-style-position: inside;
}
#qunit-tests li {
padding: 0.4em 0.5em 0.4em 2.5em;
border-bottom: 1px solid #fff;
list-style-position: inside;
}
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
display: none;
}
#qunit-tests li strong {
cursor: pointer;
}
#qunit-tests li a {
padding: 0.5em;
color: #c2ccd1;
text-decoration: none;
}
#qunit-tests li a:hover,
#qunit-tests li a:focus {
color: #000;
}
#qunit-tests li .runtime {
float: right;
font-size: smaller;
}
.qunit-assert-list {
margin-top: 0.5em;
padding: 0.5em;
background-color: #fff;
border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
}
.qunit-collapsed {
display: none;
}
#qunit-tests table {
border-collapse: collapse;
margin-top: .2em;
}
#qunit-tests th {
text-align: right;
vertical-align: top;
padding: 0 .5em 0 0;
}
#qunit-tests td {
vertical-align: top;
}
#qunit-tests pre {
margin: 0;
white-space: pre-wrap;
word-wrap: break-word;
}
#qunit-tests del {
background-color: #e0f2be;
color: #374e0c;
text-decoration: none;
}
#qunit-tests ins {
background-color: #ffcaca;
color: #500;
text-decoration: none;
}
/*** Test Counts */
#qunit-tests b.counts { color: black; }
#qunit-tests b.passed { color: #5E740B; }
#qunit-tests b.failed { color: #710909; }
#qunit-tests li li {
padding: 5px;
background-color: #fff;
border-bottom: none;
list-style-position: inside;
}
/*** Passing Styles */
#qunit-tests li li.pass {
color: #3c510c;
background-color: #fff;
border-left: 10px solid #C6E746;
}
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
#qunit-tests .pass .test-name { color: #366097; }
#qunit-tests .pass .test-actual,
#qunit-tests .pass .test-expected { color: #999999; }
#qunit-banner.qunit-pass { background-color: #C6E746; }
/*** Failing Styles */
#qunit-tests li li.fail {
color: #710909;
background-color: #fff;
border-left: 10px solid #EE5757;
white-space: pre;
}
#qunit-tests > li:last-child {
border-radius: 0 0 5px 5px;
-moz-border-radius: 0 0 5px 5px;
-webkit-border-bottom-right-radius: 5px;
-webkit-border-bottom-left-radius: 5px;
}
#qunit-tests .fail { color: #000000; background-color: #EE5757; }
#qunit-tests .fail .test-name,
#qunit-tests .fail .module-name { color: #000000; }
#qunit-tests .fail .test-actual { color: #EE5757; }
#qunit-tests .fail .test-expected { color: green; }
#qunit-banner.qunit-fail { background-color: #EE5757; }
/** Result */
#qunit-testresult {
padding: 0.5em 0.5em 0.5em 2.5em;
color: #2b81af;
background-color: #D2E0E6;
border-bottom: 1px solid white;
}
#qunit-testresult .module-name {
font-weight: bold;
}
/** Fixture */
#qunit-fixture {
position: absolute;
top: -10000px;
left: -10000px;
width: 1000px;
height: 1000px;
}
File diff suppressed because it is too large Load Diff
+250
View File
@@ -0,0 +1,250 @@
var pathname = location.pathname + location.search + location.hash;
test('$.history.context', function() {
ok($.history.context instanceof jQuery && $.history.context.length === 1);
});
test('$.history.on', 2, function() {
$.history.on('test', function(event, a, b) {
ok(event instanceof $.Event);
ok(a === 'a' && b === 'b');
});
$.history.context.trigger('test', ['a', 'b']).off();
});
test('$.history.off', 0, function() {
$.history.on('test', function() {
ok();
}).off();
$.history.context.trigger('test');
});
test('$.history.trigger', 2, function() {
$.history.on('test', function(event, a, b) {
ok(event instanceof $.Event);
ok(a === 'a' && b === 'b');
}).trigger('test', ['a', 'b']).off();
});
test('$.history.getSupports', function() {
var supports = $.history.getSupports();
ok($.type(supports) === 'object');
ok($.type(supports.pushState) === 'boolean');
ok($.type(supports.onhashchange) === 'boolean');
ok($.type($.history.getSupports('pushState')) === 'boolean');
ok($.type($.history.getSupports('onhashchange')) === 'boolean');
ok($.type($.history.getSupports('not-exists')) === 'undefined');
});
test('$.history.supports', function() {
var supports = $.history.supports;
ok($.type(supports) === 'object');
ok($.type(supports.pushState), 'boolean');
ok($.type(supports.onhashchange), 'boolean');
});
test('$.history.ieCondition', function() {
var x;
for(x=6;x<=10;++x)
ok(true, 'You are' + ($.history.ieCondition('IE ' + x) ? ' ' : ' not ') + 'over IE ' + x);
});
test('$.history.unlisten', 2, function() {
$(window).on('popstate.history hashchange.history', function() {
ok();
});
$.history.unlisten();
$(window).trigger('popstate.history hashchange.history');
ok(!$('#jQueryHistory').length);
ok($.history.type() === null);
});
test('$.history.listen', function() {
raises(function() {
$.history.listen('not-exists');
});
if (!$.history.supports.pushState)
raises(function() {
$.history.listen('pathname');
});
});
function handler(_type, _start, _finish) {
$.history.on('load', function(event, url, type) {
ok(url === '/example1?var=1#bottom');
ok(type === _type);
ok(url === $.history.url());
ok(type === $.history.type());
}).on('change', function(event, url, type) {
ok(url === '/example2#top');
ok(type === _type);
ok(url === $.history.url());
ok(type === $.history.type());
$.history.push('/example3');
$.history.push('/example4');
}).on('push', function(event, url, type) {
if (url === '/example3')
return event.preventDefault();
ok(url === '/example4');
ok(type === _type);
ok($.history.url() === '/example2#top');
ok(type === $.history.type());
}).on('pushed', function(event, url, type) {
ok(url === '/example4');
ok(type === _type);
ok(url === $.history.url());
ok(type === $.history.type());
$.history.off().unlisten();
_finish();
ok($.history.type() === null);
start();
});
_start();
ok($.history.url() === '/example1?var=1#bottom');
ok($.history.type() === _type);
}
asyncTest('$.history.listen("hash", [interval])', function() {
location.hash = '/example1?var=1#bottom';
handler('hash', function() {
$.history.listen('hash', true);
}, function() {
location.hash = '';
});
location.hash = '/example2#top';
});
asyncTest('$.history.listen("hash")', 19, function() {
location.hash = '/example1?var=1#bottom';
handler('hash', function() {
$.history.listen('hash');
}, function() {
location.hash = '';
});
location.hash = '/example2#top';
});
if (location.protocol === 'file:') {
(function() {
var message = '$.history.listen("pathname") can not run over FILE protocol.';
if (typeof console === 'object' && typeof console.log === 'function')
return console.log(message);
alert(message);
})();
} else {
asyncTest('$.history.listen("pathname")', 19, function() {
window.history.pushState({}, null, '/example1?var=1#bottom');
handler('pathname', function() {
$.history.listen('pathname');
}, function() {
window.history.pushState({}, null, pathname);
});
window.history.pushState({}, null, '/example2#top');
var event = $.Event('popstate.history');
event.originalEvent = { state: true };
$(window).trigger(event);
});
}