From 2282e8103676a33c8471a655b6b6beca74d3b9f8 Mon Sep 17 00:00:00 2001 From: flyfishMT Date: Mon, 16 Mar 2015 11:57:05 -0600 Subject: [PATCH 1/5] Adding Hasher.js --- hasher/hasher-tests.ts | 14 +++++ hasher/hasher.d.ts | 115 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 hasher/hasher-tests.ts create mode 100644 hasher/hasher.d.ts diff --git a/hasher/hasher-tests.ts b/hasher/hasher-tests.ts new file mode 100644 index 000000000..5c43af9b0 --- /dev/null +++ b/hasher/hasher-tests.ts @@ -0,0 +1,14 @@ +/// + +//handle hash changes +function handleChanges(newHash: any, oldHash: any) { + console.log(newHash); +} + +hasher.changed.add(handleChanges); //add hash change listener +hasher.initialized.add(handleChanges); //add initialized listener (to grab initial value in case it is already set) +hasher.init(); //initialize hasher (start listening for history changes) + +hasher.setHash('foo'); //change hash value (generates new history record) + +hasher.prependHash = '!'; //default value is "/" diff --git a/hasher/hasher.d.ts b/hasher/hasher.d.ts new file mode 100644 index 000000000..8abd33637 --- /dev/null +++ b/hasher/hasher.d.ts @@ -0,0 +1,115 @@ +// Type definitions for Hasher.js +// Project: https:// github.com/millermedeiros/hasher/ +// Definitions by: flyfishMT +// Definitions: https:// github.com/borisyankov/DefinitelyTyped + +/// + +declare module HasherJs { + + export interface HasherStatic { + + // {string} hasher.appendHash + // String that should always be added to the end of Hash value. + appendHash(): string; + + // default value: ''; + // will be automatically removed from `hasher.getHash()` + // avoid conflicts with elements that contain ID equal to hash value; + // {signals.Signal} hasher.changed + // Signal dispatched when hash value changes. - pass current hash as 1st parameter to listeners and previous hash value as 2nd parameter. + changed: Signal; + + // {signals.Signal} hasher.initialized + // Signal dispatched when hasher is initialized. - pass current hash as first parameter to listeners. + initialized: Signal; + + // {string} hasher.prependHash + // String that should always be added to the beginning of Hash value. + prependHash: string; + + // default value: '/'; + // will be automatically removed from `hasher.getHash()` + // avoid conflicts with elements that contain ID equal to hash value; + // {string} hasher.separator + // String used to split hash paths; used by hasher.getHashAsArray() to split paths. + separator: string; + + // default value: '/'; + // {signals.Signal} hasher.stopped + // Signal dispatched when hasher is stopped. - pass current hash as first parameter to listeners + stopped: Signal; + + // {string} hasher.VERSION + // hasher Version Number + VERSION: string; + + // Method Detail + // hasher.dispose() + // Removes all event listeners, stops hasher and destroy hasher object. - IMPORTANT: hasher won't work after calling this method, hasher Object will be deleted. + dispose(): void; + + // {string} hasher.getBaseURL() + // Returns: + // {string} Retrieve URL without query string and hash. + getBaseURL(): string; + + // {string} hasher.getHash() + // Returns: + // {string} Hash value without '#', `hasher.appendHash` and `hasher.prependHash`. + getHash(): string; + + // {Array.} hasher.getHashAsArray() + // Returns: + // {Array.} Hash value split into an Array. + getHashAsArray(): string[]; + + // {string} hasher.getURL() + // Returns: + // {string} Full URL. + getURL(): string; + + // hasher.init() + // Start listening/dispatching changes in the hash/history. + init(): void; + + // hasher won't dispatch CHANGE events by manually typing a new value or pressing the back/forward buttons before calling this method. + // {boolean} hasher.isActive() + // Returns: + // {boolean} If hasher is listening to changes on the browser history and/or hash value. + isActive(): boolean; + + // hasher.replaceHash(path) + // Set Hash value without keeping previous hash on the history record. Similar to calling window.location.replace("#/hash") but will also work on IE6-7. + // hasher.replaceHash('lorem', 'ipsum', 'dolor') -> '#/lorem/ipsum/dolor' + // Parameters: + // {...string} path + // Hash value without '#'. Hasher will join path segments using `hasher.separator` and prepend/append hash value with `hasher.appendHash` and `hasher.prependHash` + replaceHash(...path: string[]): void; + + // hasher.setHash(path) + // Set Hash value, generating a new history record. + // hasher.setHash('lorem', 'ipsum', 'dolor') -> '#/lorem/ipsum/dolor' + // Parameters: + // {...string} path + // Hash value without '#'. Hasher will join path segments using `hasher.separator` and prepend/append hash value with `hasher.appendHash` and `hasher.prependHash` + setHash(...path: string[]): void; + + // hasher.stop() + // Stop listening/dispatching changes in the hash/history. + // hasher won't dispatch CHANGE events by manually typing a new value or pressing the back/forward buttons after calling this method, unless you call hasher.init() again. + // hasher will still dispatch changes made programatically by calling hasher.setHash(); + stop(): void; + + // {string} hasher.toString() + // Returns: + // {string} A string representation of the object. + toString(): string; + } +} + +declare var hasher: HasherJs.HasherStatic; + +declare module 'hasher'{ + export = hasher; +} From a6fc064b32bf004b6af69c831593a325d12fb2af Mon Sep 17 00:00:00 2001 From: flyfishMT Date: Mon, 16 Mar 2015 12:13:26 -0600 Subject: [PATCH 2/5] formatting --- hasher/hasher.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/hasher/hasher.d.ts b/hasher/hasher.d.ts index 8abd33637..782acf9c1 100644 --- a/hasher/hasher.d.ts +++ b/hasher/hasher.d.ts @@ -110,6 +110,7 @@ declare module HasherJs { declare var hasher: HasherJs.HasherStatic; +// AMD declare module 'hasher'{ export = hasher; } From c3db40671d29c75a1f1a976d81ad5106d7669d2b Mon Sep 17 00:00:00 2001 From: flyfishMT Date: Mon, 16 Mar 2015 12:23:14 -0600 Subject: [PATCH 3/5] formatting travis ci build error --- hasher/hasher.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hasher/hasher.d.ts b/hasher/hasher.d.ts index 782acf9c1..8bfb1e674 100644 --- a/hasher/hasher.d.ts +++ b/hasher/hasher.d.ts @@ -1,7 +1,7 @@ -// Type definitions for Hasher.js -// Project: https:// github.com/millermedeiros/hasher/ -// Definitions by: flyfishMT -// Definitions: https:// github.com/borisyankov/DefinitelyTyped +// Type definitions for Hasher.js +// Project: https:// github.com/millermedeiros/hasher/ +// Definitions by: flyfishMT +// Definitions: https:// github.com/borisyankov/DefinitelyTyped /// From f1155c1e0626e8807a2c756c11d9b3dfcd5f4f35 Mon Sep 17 00:00:00 2001 From: flyfishMT Date: Mon, 16 Mar 2015 12:27:03 -0600 Subject: [PATCH 4/5] more formatting travis ci build error --- hasher/hasher.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hasher/hasher.d.ts b/hasher/hasher.d.ts index 8bfb1e674..587bf4a39 100644 --- a/hasher/hasher.d.ts +++ b/hasher/hasher.d.ts @@ -1,7 +1,7 @@ // Type definitions for Hasher.js -// Project: https:// github.com/millermedeiros/hasher/ +// Project: https://github.com/millermedeiros/hasher/ // Definitions by: flyfishMT -// Definitions: https:// github.com/borisyankov/DefinitelyTyped +// Definitions: https://github.com/borisyankov/DefinitelyTyped /// From e294be52255e83f28376b2d8c88023971566805a Mon Sep 17 00:00:00 2001 From: flyfishMT Date: Mon, 16 Mar 2015 12:31:54 -0600 Subject: [PATCH 5/5] formatting travis ci build error --- hasher/hasher.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hasher/hasher.d.ts b/hasher/hasher.d.ts index 587bf4a39..dfed50bd4 100644 --- a/hasher/hasher.d.ts +++ b/hasher/hasher.d.ts @@ -1,6 +1,6 @@ // Type definitions for Hasher.js // Project: https://github.com/millermedeiros/hasher/ -// Definitions by: flyfishMT +// Definitions by: flyfishMT // Definitions: https://github.com/borisyankov/DefinitelyTyped ///