Skip to content

Commit

Permalink
Merge 318b59d into 02c026c
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewp committed Oct 4, 2018
2 parents 02c026c + 318b59d commit 677212a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 17 deletions.
4 changes: 4 additions & 0 deletions Readme.md
Expand Up @@ -218,6 +218,10 @@ var otherPage = page.create({ window: iframe.contentWindow });
otherPage('/', main);
```

### page.clickHandler

This is the click handler used by page to handle routing when a user clicks an anchor like `<a href="/user/profile">`. This is exported for those who want to disable the click handling behavior with `page.start({ click: false })`, but still might want to dispatch based on the click handler's logic in some scenarios.

### Context

Routes are passed `Context` objects, these may
Expand Down
11 changes: 6 additions & 5 deletions index.js
Expand Up @@ -49,7 +49,7 @@
this._hashbang = false;

// bound functions
this._onclick = this._onclick.bind(this);
this.clickHandler = this.clickHandler.bind(this);
this._onpopstate = this._onpopstate.bind(this);

this.configure(options);
Expand Down Expand Up @@ -80,9 +80,9 @@
}

if (this._click) {
_window.document.addEventListener(clickEvent, this._onclick, false);
_window.document.addEventListener(clickEvent, this.clickHandler, false);
} else if(hasDocument) {
_window.document.removeEventListener(clickEvent, this._onclick, false);
_window.document.removeEventListener(clickEvent, this.clickHandler, false);
}

if(this._hashbang && hasWindow && !hasHistory) {
Expand Down Expand Up @@ -179,7 +179,7 @@
this._running = false;

var window = this._window;
hasDocument && window.document.removeEventListener(clickEvent, this._onclick, false);
hasDocument && window.document.removeEventListener(clickEvent, this.clickHandler, false);
hasWindow && window.removeEventListener('popstate', this._onpopstate, false);
hasWindow && window.removeEventListener('hashchange', this._onpopstate, false);
};
Expand Down Expand Up @@ -340,7 +340,7 @@
*/

/* jshint +W054 */
Page.prototype._onclick = function(e) {
Page.prototype.clickHandler = function(e) {
if (1 !== this._which(e)) return;

if (e.metaKey || e.ctrlKey || e.shiftKey) return;
Expand Down Expand Up @@ -543,6 +543,7 @@
pageFn.exit = pageInstance.exit.bind(pageInstance);
pageFn.configure = pageInstance.configure.bind(pageInstance);
pageFn.sameOrigin = pageInstance.sameOrigin.bind(pageInstance);
pageFn.clickHandler = pageInstance.clickHandler.bind(pageInstance);

pageFn.create = createPage;

Expand Down
13 changes: 7 additions & 6 deletions page.js
Expand Up @@ -449,7 +449,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
this._hashbang = false;

// bound functions
this._onclick = this._onclick.bind(this);
this.clickHandler = this.clickHandler.bind(this);
this._onpopstate = this._onpopstate.bind(this);

this.configure(options);
Expand Down Expand Up @@ -480,9 +480,9 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
}

if (this._click) {
_window.document.addEventListener(clickEvent, this._onclick, false);
_window.document.addEventListener(clickEvent, this.clickHandler, false);
} else if(hasDocument) {
_window.document.removeEventListener(clickEvent, this._onclick, false);
_window.document.removeEventListener(clickEvent, this.clickHandler, false);
}

if(this._hashbang && hasWindow && !hasHistory) {
Expand Down Expand Up @@ -579,7 +579,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
this._running = false;

var window = this._window;
hasDocument && window.document.removeEventListener(clickEvent, this._onclick, false);
hasDocument && window.document.removeEventListener(clickEvent, this.clickHandler, false);
hasWindow && window.removeEventListener('popstate', this._onpopstate, false);
hasWindow && window.removeEventListener('hashchange', this._onpopstate, false);
};
Expand Down Expand Up @@ -740,7 +740,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
*/

/* jshint +W054 */
Page.prototype._onclick = function(e) {
Page.prototype.clickHandler = function(e) {
if (1 !== this._which(e)) return;

if (e.metaKey || e.ctrlKey || e.shiftKey) return;
Expand Down Expand Up @@ -829,7 +829,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
Page.prototype._onpopstate = (function () {
var loaded = false;
if ( ! hasWindow ) {
return function() {};
return;
}
if (hasDocument && document.readyState === 'complete') {
loaded = true;
Expand Down Expand Up @@ -943,6 +943,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
pageFn.exit = pageInstance.exit.bind(pageInstance);
pageFn.configure = pageInstance.configure.bind(pageInstance);
pageFn.sameOrigin = pageInstance.sameOrigin.bind(pageInstance);
pageFn.clickHandler = pageInstance.clickHandler.bind(pageInstance);

pageFn.create = createPage;

Expand Down
13 changes: 7 additions & 6 deletions page.mjs
Expand Up @@ -400,7 +400,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
* Module dependencies.
*/



/**
* Short-cuts for global-object checks
Expand Down Expand Up @@ -443,7 +443,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
this._hashbang = false;

// bound functions
this._onclick = this._onclick.bind(this);
this.clickHandler = this.clickHandler.bind(this);
this._onpopstate = this._onpopstate.bind(this);

this.configure(options);
Expand Down Expand Up @@ -474,9 +474,9 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
}

if (this._click) {
_window.document.addEventListener(clickEvent, this._onclick, false);
_window.document.addEventListener(clickEvent, this.clickHandler, false);
} else if(hasDocument) {
_window.document.removeEventListener(clickEvent, this._onclick, false);
_window.document.removeEventListener(clickEvent, this.clickHandler, false);
}

if(this._hashbang && hasWindow && !hasHistory) {
Expand Down Expand Up @@ -573,7 +573,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
this._running = false;

var window = this._window;
hasDocument && window.document.removeEventListener(clickEvent, this._onclick, false);
hasDocument && window.document.removeEventListener(clickEvent, this.clickHandler, false);
hasWindow && window.removeEventListener('popstate', this._onpopstate, false);
hasWindow && window.removeEventListener('hashchange', this._onpopstate, false);
};
Expand Down Expand Up @@ -734,7 +734,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
*/

/* jshint +W054 */
Page.prototype._onclick = function(e) {
Page.prototype.clickHandler = function(e) {
if (1 !== this._which(e)) return;

if (e.metaKey || e.ctrlKey || e.shiftKey) return;
Expand Down Expand Up @@ -937,6 +937,7 @@ pathToRegexp_1.tokensToRegExp = tokensToRegExp_1;
pageFn.exit = pageInstance.exit.bind(pageInstance);
pageFn.configure = pageInstance.configure.bind(pageInstance);
pageFn.sameOrigin = pageInstance.sameOrigin.bind(pageInstance);
pageFn.clickHandler = pageInstance.clickHandler.bind(pageInstance);

pageFn.create = createPage;

Expand Down
6 changes: 6 additions & 0 deletions test/tests.js
Expand Up @@ -735,6 +735,12 @@
});
});

describe('.clickHandler', function() {
it('is exported by the global page', function() {
expect(typeof page.clickHandler).to.equal('function');
});
});

var describei = jsdomSupport ? describe : describe.skip;

describei('File protocol', function() {
Expand Down

0 comments on commit 677212a

Please sign in to comment.