update components

This commit is contained in:
Luke Pulverenti 2016-05-28 13:34:07 -04:00
parent abf163fb4a
commit b385aa2d95
22 changed files with 368 additions and 90 deletions

View file

@ -1,6 +1,6 @@
{
"name": "iron-location",
"version": "0.8.2",
"version": "0.8.3",
"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.2",
"_release": "0.8.3",
"_resolution": {
"type": "version",
"tag": "v0.8.2",
"commit": "9ab0b3bf4b30e00d1f80dcb1cf9e00bd17cce4a5"
"tag": "v0.8.3",
"commit": "cb124aa740c07d2b65af1d7e05a3cf8fd6a25f87"
},
"_source": "git://github.com/PolymerElements/iron-location.git",
"_target": "^0.8.0",

View file

@ -11,7 +11,7 @@
<!-- Example: The page turns pink. -->
### Live Demo
<!-- Example: https://jsbin.com/cagaye/edit?html,output -->
<!-- Example: https://jsbin.com/lebawa/edit?html,output -->
### Steps to reproduce

View file

@ -1,4 +1,3 @@
<!--
This file is autogenerated based on
https://github.com/PolymerElements/ContributionGuide/blob/master/CONTRIBUTING.md
@ -11,6 +10,7 @@ specific element:
jsbin=https://jsbin.com/lebawa/edit?html,output
-->
# Polymer Elements
## Guide for Contributors
@ -46,7 +46,7 @@ Polymer Elements are built in the open, and the Polymer authors eagerly encourag
3. Click the `paper-foo` element.
```
2. **A reduced test case that demonstrates the problem.** If possible, please include the test case as a JSBin. Start with this template to easily import and use relevant Polymer Elements: [https://jsbin.com/cagaye/edit?html,output](https://jsbin.com/cagaye/edit?html,output).
2. **A reduced test case that demonstrates the problem.** If possible, please include the test case as a JSBin. Start with this template to easily import and use relevant Polymer Elements: [https://jsbin.com/lebawa/edit?html,output](https://jsbin.com/lebawa/edit?html,output).
3. **A list of browsers where the problem occurs.** This can be skipped if the problem is the same across all browsers.

View file

@ -1,6 +1,6 @@
{
"name": "iron-location",
"version": "0.8.2",
"version": "0.8.3",
"description": "Bidirectional data binding into the page's URL.",
"private": true,
"authors": [

View file

@ -243,10 +243,6 @@ milliseconds.
* is clicking on, if we can and should override the resulting full
* page navigation. Returns null otherwise.
*
* This method is separated away from _globalOnClick for testability,
* as we can't test that a clicked link should have resulted in navigating
* away from the test page.
*
* @param {MouseEvent} event .
* @return {string?} .
*/
@ -261,19 +257,33 @@ milliseconds.
return null;
}
var eventPath = Polymer.dom(event).path;
var href = null;
var anchor = null;
for (var i = 0; i < eventPath.length; i++) {
var element = eventPath[i];
if (element.tagName === 'A' && element.href) {
href = element.href;
anchor = element;
break;
}
}
// If there's no link there's nothing to do.
if (!href) {
return null;
if (!anchor) {
return;
}
// Target blank is a new tab, don't intercept.
if (anchor.target === '_blank') {
return;
}
// If the link is for an existing parent frame, don't intercept.
if ((anchor.target === '_top' ||
anchor.target === '_parent') &&
window.top !== window) {
return;
}
var href = anchor.href;
// It only makes sense for us to intercept same-origin navigations.
// pushState/replaceState don't work with cross-origin links.
var url;

View file

@ -61,10 +61,13 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
});
}
function makeAbsoluteUrl(path) {
return window.location.protocol + '//' + window.location.host + path;
}
// A window.history.replaceState wrapper that's smart about baseURI.
function replaceState(url) {
window.history.replaceState(
{}, '', window.location.protocol + '//' + window.location.host + url);
function replaceState(path) {
window.history.replaceState({}, '', makeAbsoluteUrl(path));
}
/**
@ -164,6 +167,77 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
assertHaveSameUrls(urlElem, otherUrlElem);
});
});
suite('when intercepting links', function() {
/**
* Clicks the given link while an iron-location element with the given
* urlSpaceRegex is in the same document. Returns whether the
* iron-location prevented the default behavior of the click.
*
* No matter what, it prevents the default behavior of the click itself
* to ensure that no navigation occurs (as that would interrupt
* running and reporting these tests!)
*/
function isClickCaptured(anchor, urlSpaceRegex) {
var defaultWasPrevented;
function handler(event) {
expect(event.target).to.be.eq(anchor);
defaultWasPrevented = event.defaultPrevented;
event.preventDefault();
expect(event.defaultPrevented).to.be.eq(true);
}
window.addEventListener('click', handler);
var ironLocation = fixture('Solo');
if (urlSpaceRegex != null) {
ironLocation.urlSpaceRegex = urlSpaceRegex;
}
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
window.removeEventListener('click', handler);
return defaultWasPrevented;
}
test('simple link to / is intercepted', function() {
var anchor = document.createElement('a');
if (document.baseURI !== window.location.href) {
anchor.href = makeAbsoluteUrl('/');
} else {
anchor.href = '/';
}
expect(isClickCaptured(anchor)).to.be.eq(true);
});
test('link that matches url space is intercepted', function() {
var anchor = document.createElement('a');
anchor.href = makeAbsoluteUrl('/foo');
expect(isClickCaptured(anchor, '/fo+')).to.be.eq(true);
});
test('link that doesn\'t match url space isn\'t intercepted', function() {
var anchor = document.createElement('a');
anchor.href = makeAbsoluteUrl('/bar');
expect(isClickCaptured(anchor, '/fo+')).to.be.eq(false);
});
test('link to another domain isn\'t intercepted', function() {
var anchor = document.createElement('a');
anchor.href = 'http://example.com/';
expect(isClickCaptured(anchor)).to.be.eq(false);
});
test('a link with target=_blank isn\'t intercepted', function() {
var anchor = document.createElement('a');
anchor.href = makeAbsoluteUrl('/');
anchor.target = '_blank';
expect(isClickCaptured(anchor)).to.be.eq(false);
})
});
suite('supports doing synchronous redirection', function() {
test('of the hash portion of the URL', function() {