update components
This commit is contained in:
parent
857b8348bb
commit
165a3a99a2
11 changed files with 99 additions and 48 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "iron-location",
|
||||
"version": "0.8.3",
|
||||
"version": "0.8.4",
|
||||
"description": "Bidirectional data binding into the page's URL.",
|
||||
"private": true,
|
||||
"authors": [
|
||||
|
@ -37,11 +37,11 @@
|
|||
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
|
||||
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.2.3"
|
||||
},
|
||||
"_release": "0.8.3",
|
||||
"_release": "0.8.4",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "v0.8.3",
|
||||
"commit": "cb124aa740c07d2b65af1d7e05a3cf8fd6a25f87"
|
||||
"tag": "v0.8.4",
|
||||
"commit": "dcb05b63c0f367fde7ebfd3bebefee606f69dd68"
|
||||
},
|
||||
"_source": "git://github.com/PolymerElements/iron-location.git",
|
||||
"_target": "^0.8.0",
|
||||
|
|
|
@ -2,7 +2,7 @@ language: node_js
|
|||
sudo: required
|
||||
node_js: stable
|
||||
addons:
|
||||
firefox: latest
|
||||
firefox: '46.0'
|
||||
apt:
|
||||
sources:
|
||||
- google-chrome
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "iron-location",
|
||||
"version": "0.8.3",
|
||||
"version": "0.8.4",
|
||||
"description": "Bidirectional data binding into the page's URL.",
|
||||
"private": true,
|
||||
"authors": [
|
||||
|
|
|
@ -125,9 +125,8 @@ milliseconds.
|
|||
computed: '_makeRegExp(urlSpaceRegex)'
|
||||
},
|
||||
|
||||
_lastChangedAtAt: {
|
||||
type: Number,
|
||||
value: -Infinity
|
||||
_lastChangedAt: {
|
||||
type: Number
|
||||
},
|
||||
|
||||
_initialized: {
|
||||
|
@ -146,6 +145,9 @@ milliseconds.
|
|||
this.listen(window, 'location-changed', '_urlChanged');
|
||||
this.listen(window, 'popstate', '_urlChanged');
|
||||
this.listen(/** @type {!HTMLBodyElement} */(document.body), 'click', '_globalOnClick');
|
||||
// Give a 200ms grace period to make initial redirects without any
|
||||
// additions to the user's history.
|
||||
this._lastChangedAt = window.performance.now() - (this.dwellTime - 200);
|
||||
|
||||
this._initialized = true;
|
||||
this._urlChanged();
|
||||
|
@ -157,17 +159,6 @@ milliseconds.
|
|||
this.unlisten(/** @type {!HTMLBodyElement} */(document.body), 'click', '_globalOnClick');
|
||||
this._initialized = false;
|
||||
},
|
||||
/**
|
||||
* @return {number} the number of milliseconds since some point in the
|
||||
* past. Only useful for comparing against other results from this
|
||||
* function.
|
||||
*/
|
||||
_now: function() {
|
||||
if (window.performance && window.performance.now) {
|
||||
return window.performance.now();
|
||||
}
|
||||
return new Date().getTime();
|
||||
},
|
||||
_hashChanged: function() {
|
||||
this.hash = window.location.hash.substring(1);
|
||||
},
|
||||
|
@ -212,7 +203,7 @@ milliseconds.
|
|||
// Need to use a full URL in case the containing page has a base URI.
|
||||
var fullNewUrl = new URL(
|
||||
newUrl, window.location.protocol + '//' + window.location.host).href;
|
||||
var now = this._now();
|
||||
var now = window.performance.now();
|
||||
var shouldReplace =
|
||||
this._lastChangedAt + this.dwellTime > now;
|
||||
this._lastChangedAt = now;
|
||||
|
@ -230,6 +221,12 @@ milliseconds.
|
|||
* @param {MouseEvent} event .
|
||||
*/
|
||||
_globalOnClick: function(event) {
|
||||
// If another event handler has stopped this event then there's nothing
|
||||
// for us to do. This can happen e.g. when there are multiple
|
||||
// iron-location elements in a page.
|
||||
if (event.defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
var href = this._getSameOriginLinkHref(event);
|
||||
if (!href) {
|
||||
return;
|
||||
|
@ -268,18 +265,18 @@ milliseconds.
|
|||
|
||||
// If there's no link there's nothing to do.
|
||||
if (!anchor) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
// Target blank is a new tab, don't intercept.
|
||||
if (anchor.target === '_blank') {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
// If the link is for an existing parent frame, don't intercept.
|
||||
if ((anchor.target === '_top' ||
|
||||
anchor.target === '_parent') &&
|
||||
window.top !== window) {
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
var href = anchor.href;
|
||||
|
@ -319,6 +316,11 @@ milliseconds.
|
|||
// Need to use a full URL in case the containing page has a base URI.
|
||||
var fullNormalizedHref = new URL(
|
||||
normalizedHref, window.location.href).href;
|
||||
// If the navigation is to the current page we shouldn't add a history
|
||||
// entry.
|
||||
if (fullNormalizedHref === window.location.href) {
|
||||
return null;
|
||||
}
|
||||
return fullNormalizedHref;
|
||||
},
|
||||
_makeRegExp: function(urlSpaceRegex) {
|
||||
|
|
|
@ -141,6 +141,34 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
'?greeting=hello&target=world&another=key');
|
||||
});
|
||||
});
|
||||
suite('does not spam the user\'s history', function() {
|
||||
var replaceStateCalls, pushStateCalls;
|
||||
var nativeReplaceState, nativePushState;
|
||||
setup(function() {
|
||||
replaceStateCalls = pushStateCalls = 0;
|
||||
nativeReplaceState = window.history.replaceState;
|
||||
nativePushState = window.history.pushState;
|
||||
window.history.replaceState = function() {
|
||||
replaceStateCalls++;
|
||||
};
|
||||
window.history.pushState = function() {
|
||||
pushStateCalls++;
|
||||
};
|
||||
});
|
||||
teardown(function() {
|
||||
window.history.replaceState = nativeReplaceState;
|
||||
window.history.pushState = nativePushState;
|
||||
});
|
||||
test('when a change happens immediately after ' +
|
||||
'the iron-location is attached', function() {
|
||||
var ironLocation = fixture('Solo');
|
||||
expect(pushStateCalls).to.be.equal(0);
|
||||
expect(replaceStateCalls).to.be.equal(0);
|
||||
ironLocation.path = '/foo';
|
||||
expect(replaceStateCalls).to.be.equal(1);
|
||||
expect(pushStateCalls).to.be.equal(0);
|
||||
});
|
||||
});
|
||||
suite('when used with other iron-location elements', function() {
|
||||
var otherUrlElem;
|
||||
var urlElem;
|
||||
|
@ -236,6 +264,35 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
|
|||
anchor.target = '_blank';
|
||||
|
||||
expect(isClickCaptured(anchor)).to.be.eq(false);
|
||||
});
|
||||
|
||||
test('a link with an href to the ' +
|
||||
'current page shouldn\'t add to history.', function() {
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = window.location.href;
|
||||
|
||||
expect(isClickCaptured(anchor)).to.be.equal(false);
|
||||
});
|
||||
|
||||
test('a click that has already been defaultPrevented ' +
|
||||
'shouldn\'t result in a navigation', function() {
|
||||
fixture('Solo');
|
||||
var anchor = document.createElement('a');
|
||||
anchor.href = makeAbsoluteUrl('/');
|
||||
anchor.addEventListener('click', function(event) {
|
||||
event.preventDefault();
|
||||
});
|
||||
document.body.appendChild(anchor);
|
||||
|
||||
var originalPushState = window.history.pushState;
|
||||
var count = 0;
|
||||
window.history.pushState = function() {
|
||||
count++;
|
||||
}
|
||||
anchor.click();
|
||||
window.history.pushState = originalPushState;
|
||||
|
||||
expect(count).to.be.equal(0);
|
||||
})
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue