History.js definitions and tests added

This commit is contained in:
Boris Yankov 2012-10-13 19:43:39 +03:00
parent 716a5a0c49
commit 9f07758e11
2 changed files with 42 additions and 0 deletions

25
Definitions/history.d.ts vendored Normal file
View File

@ -0,0 +1,25 @@
// Type definitions for History.js
// Project: https://github.com/balupton/History.js
// Definitions: https://github.com/borisyankov/DefinitelyTyped
interface HistoryAdapter {
bind(element, event, callback);
trigger(element, event);
onDomLoad(callback);
}
interface HistoryStatic {
enabled: bool;
pushState(data, title, url);
replaceState(data, title, url);
getState();
getHash();
Adapter: HistoryAdapter;
back();
forward();
go(X);
log(...messages: any[]);
debug(...messages: any[]);
}
declare var History: HistoryStatic;

17
Tests/history-tests.ts Normal file
View File

@ -0,0 +1,17 @@
/// <reference path="../Definitions/history.d.ts" />
if (!History.enabled) {
return false;
}
History.Adapter.bind(window, 'statechange', () => {
var State = History.getState();
History.log(State.data, State.title, State.url);
});
History.pushState({ state: 1 }, "State 1", "?state=1");
History.pushState({ state: 2 }, "State 2", "?state=2");
History.replaceState({ state: 3 }, "State 3", "?state=3");
History.pushState(null, null, "?state=4");
History.back();
History.go(2);