1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

update components

This commit is contained in:
Luke Pulverenti 2016-07-15 17:16:18 -04:00
parent 9254ff721d
commit 3197c48232
162 changed files with 902 additions and 9728 deletions

View file

@ -1,49 +0,0 @@
{
"name": "iron-location",
"version": "0.8.5",
"description": "Bidirectional data binding into the page's URL.",
"private": true,
"authors": [
"The Polymer Authors"
],
"keywords": [
"web-components",
"polymer",
"routing"
],
"main": [
"iron-location.html",
"iron-query-params.html"
],
"repository": {
"type": "git",
"url": "git://github.com/PolymerElements/iron-location.git"
},
"license": "http://polymer.github.io/LICENSE.txt",
"homepage": "https://github.com/PolymerElements/iron-location",
"ignore": [],
"dependencies": {
"polymer": "Polymer/polymer#^1.0.0"
},
"devDependencies": {
"promise-polyfill": "polymerlabs/promise-polyfill#^1.0.0",
"iron-component-page": "polymerelements/iron-component-page#^1.0.0",
"iron-flex-layout": "polymerelements/iron-flex-layout#^1.0.0",
"paper-input": "polymerelements/paper-input#^1.0.0",
"paper-slider": "polymerelements/paper-slider#^1.0.0",
"paper-styles": "polymerelements/paper-styles#^1.0.0",
"test-fixture": "polymerelements/test-fixture#^1.0.0",
"web-component-tester": "^4.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.2.3"
},
"_release": "0.8.5",
"_resolution": {
"type": "version",
"tag": "v0.8.5",
"commit": "d7c5a9c991bf5e94094c16e94eb34e2eb30db4b0"
},
"_source": "git://github.com/PolymerElements/iron-location.git",
"_target": "^0.8.0",
"_originalSource": "PolymerElements/iron-location"
}

View file

@ -1,33 +0,0 @@
<!-- Instructions: https://github.com/PolymerElements/iron-location/CONTRIBUTING.md#filing-issues -->
### Description
<!-- Example: The `paper-foo` element causes the page to turn pink when clicked. -->
### Expected outcome
<!-- Example: The page stays the same color. -->
### Actual outcome
<!-- Example: The page turns pink. -->
### Live Demo
<!-- Example: https://jsbin.com/lebawa/edit?html,output -->
### Steps to reproduce
<!-- Example
1. Put a `paper-foo` element in the page.
2. Open the page in a web browser.
3. Click the `paper-foo` element.
-->
### Browsers Affected
<!-- Check all that apply -->
- [ ] Chrome
- [ ] Firefox
- [ ] Safari 9
- [ ] Safari 8
- [ ] Safari 7
- [ ] Edge
- [ ] IE 11
- [ ] IE 10

View file

@ -1 +0,0 @@
bower_components

View file

@ -1,23 +0,0 @@
language: node_js
sudo: required
node_js: stable
addons:
firefox: '46.0'
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
sauce_connect: true
before_script:
- npm install -g bower polylint web-component-tester
- bower install
- polylint
script:
- xvfb-run wct
- "if [ \"${TRAVIS_PULL_REQUEST}\" = \"false\" ]; then wct -s 'default'; fi"
env:
global:
- secure: GQ+cUlta7BWa8Gq4YXrBStPzwRpHT2QG79T4pbDTz2Zs1RvT0GYQaEUksPQnsNCwnTF8ondXhUfMxHcC/r8p7YTCt2hSJSsKkx0lMertsjbKW38ZG28liaAN8msYGb9hnTs4qxhpVEX1pZtOI13RKBU85dw+jKbtxKDX/jVrMn42XCMhEmTeLxM4z8dW5nBu6LW6F3nwABQIUfdc/3OeIYG+2n+84zkXIsX1BFeejq28E6fYJAoMJgqfugLPgPu4IEVCWZJwYl2SgdXwxAcJ2auPph5GJ3DLd0fRRD1TZ94/u0A+eJcQ0OPiPu8hLpQNXOkCgAnO5jkpTCDERNQnB4nY8VfZeZdf1RLAB4VmxzOAbJwJcnqGrh89H6RhKKXyhcuFCgFACYfkzncBCs+co5KwVcwLq88cDOUbnmo3DlwQWpkfusvKy/ZrMrFrX1zycJWN4u8rDsIH4ELasSQh/J3OIa9l2mKfL/OEvqCmpv/ZLGlOVSvNLpr4U7vTVdZBP6C9rtwVXX7VzrClttiidHfoxztAMrNh2GBMjNH9n3FuWMoA/OSoxQGc7RreTsuzdniw3iJYUHIeG08R9bqRtSVA71AlQrbqUaHR+WM7rf7GUx6xG0uDop5vH0RDkE0Nld1W8XuVhHQUg3y3fd4AHJAQVmM7Zsfa3AY1gSr3hV0=
- secure: He0JAbtg9jFzuEBRHQdFWHJ33uueY/9Hxq4NB5PCAI1Z9ebIiTs73ofdNy6e+ftBqlQnBuhoKLfIpuD8Qj2kSdLHQvg1s6ojvNDmAvau1ZINCJRgOSKbGC0TvCVx9rT9Kqc83eqKvKDzr/rcpaIArgMYJzBrSG0D2Kn4luUQnWkKfo1knn17ytJFCvzqQvPWZTIZ6beJ7MRKXRU093a4wYMsKIxQHH65T4Ypj+RBsgv6Xnidjb8qZbNsEwaeOwExfsh30WUo/hSygRi2CP3KSRSc/vsMgSrGpFghZpnhjeDJAGTiDzCTxpJkAkHXereJT4agsWErcgSrRTaxi5G6f18o56pRS+I61BC5DuGGwSL7hOHWSC8pGzkwVFyz31MB2ll0HO3iQHMmcSjY37+G7toEP/vJ/UHm6SZoQq36HGJea7Ycv/2mk4HAHcVEDxhYG42bXXflxevFeqAkVUI7SxSaQpQuZF76/4th4uKFmAHPvRVj5yx8OWil9Lt6cG8DIEZaxXdJVueGgiODmmul7lAd5osO/1UCg4CTy1OnmuSJj7ax9LBa6YY2+3uvnBfE7fNUVKmVmVhlLsF0QAdj0LaFoSU0eQFWdReYqBxEvc4gOT3AtEpaAvfZnL11Q6wVyI7kCHhTHrltA4WENPOSA2u7W//WsQfHX3gRdpIVIVI=
dist: trusty

View file

@ -1,77 +0,0 @@
<!--
This file is autogenerated based on
https://github.com/PolymerElements/ContributionGuide/blob/master/CONTRIBUTING.md
If you edit that file, it will get updated everywhere else.
If you edit this file, your changes will get overridden :)
You can however override the jsbin link with one that's customized to this
specific element:
jsbin=https://jsbin.com/lebawa/edit?html,output
-->
# Polymer Elements
## Guide for Contributors
Polymer Elements are built in the open, and the Polymer authors eagerly encourage any and all forms of community contribution. When contributing, please follow these guidelines:
### Filing Issues
**If you are filing an issue to request a feature**, please provide a clear description of the feature. It can be helpful to describe answers to the following questions:
1. **Who will use the feature?** _“As someone filling out a form…”_
2. **When will they use the feature?** _“When I enter an invalid value…”_
3. **What is the users goal?** _“I want to be visually notified that the value needs to be corrected…”_
**If you are filing an issue to report a bug**, please provide:
1. **A clear description of the bug and related expectations.** Consider using the following example template for reporting a bug:
```markdown
The `paper-foo` element causes the page to turn pink when clicked.
## Expected outcome
The page stays the same color.
## Actual outcome
The page turns pink.
## Steps to reproduce
1. Put a `paper-foo` element in the page.
2. Open the page in a web browser.
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/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.
### Submitting Pull Requests
**Before creating a pull request**, please ensure that an issue exists for the corresponding change in the pull request that you intend to make. **If an issue does not exist, please create one per the guidelines above**. The goal is to discuss the design and necessity of the proposed change with Polymer authors and community before diving into a pull request.
When submitting pull requests, please provide:
1. **A reference to the corresponding issue** or issues that will be closed by the pull request. Please refer to these issues in the pull request description using the following syntax:
```markdown
(For a single issue)
Fixes #20
(For multiple issues)
Fixes #32, fixes #40
```
2. **A succinct description of the design** used to fix any related issues. For example:
```markdown
This fixes #20 by removing styles that leaked which would cause the page to turn pink whenever `paper-foo` is clicked.
```
3. **At least one test for each bug fixed or feature added** as part of the pull request. Pull requests that fix bugs or add features without accompanying tests will not be considered.
If a proposed change contains multiple commits, please [squash commits](https://www.google.com/url?q=http://blog.steveklabnik.com/posts/2012-11-08-how-to-squash-commits-in-a-github-pull-request) to as few as is necessary to succinctly express the change. A Polymer author can help you squash commits, so dont be afraid to ask us if you need help with that!

View file

@ -1,40 +0,0 @@
{
"name": "iron-location",
"version": "0.8.5",
"description": "Bidirectional data binding into the page's URL.",
"private": true,
"authors": [
"The Polymer Authors"
],
"keywords": [
"web-components",
"polymer",
"routing"
],
"main": [
"iron-location.html",
"iron-query-params.html"
],
"repository": {
"type": "git",
"url": "git://github.com/PolymerElements/iron-location.git"
},
"license": "http://polymer.github.io/LICENSE.txt",
"homepage": "https://github.com/PolymerElements/iron-location",
"ignore": [],
"dependencies": {
"polymer": "Polymer/polymer#^1.0.0"
},
"devDependencies": {
"promise-polyfill": "polymerlabs/promise-polyfill#^1.0.0",
"iron-component-page": "polymerelements/iron-component-page#^1.0.0",
"iron-flex-layout": "polymerelements/iron-flex-layout#^1.0.0",
"paper-input": "polymerelements/paper-input#^1.0.0",
"paper-slider": "polymerelements/paper-slider#^1.0.0",
"paper-styles": "polymerelements/paper-styles#^1.0.0",
"test-fixture": "polymerelements/test-fixture#^1.0.0",
"web-component-tester": "^4.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0",
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.2.3"
}
}

View file

@ -1,126 +0,0 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>iron-location</title>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../iron-location.html">
<link rel="import" href="../../paper-styles/typography.html">
<link rel="import" href="../../iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../../paper-input/paper-input.html">
<link rel="import" href="../../paper-slider/paper-slider.html">
<link rel="import" href="../../iron-demo-helpers/url-bar.html">
<link rel="stylesheet" href="../../paper-styles/demo.css">
</head>
<body>
<url-bar></url-bar>
<dom-module id="iron-location-demo">
<template>
<style>
div.inputs {
margin-bottom: 15px;
}
label {
display: inline-block;
width: 100px;
}
h3 {
padding: 0;
margin: 0;
}
.inputs, .history_entries {
@apply(--layout-vertical);
@apply(--layout-flex);
padding: 20px;
max-width: 500px;
}
.container {
@apply(--layout-horizontal);
}
</style>
<iron-location path="{{path}}" hash="{{hash}}" query="{{query}}"
dwell-time="{{dwellTime}}">
</iron-location>
<div class="container">
<div class="inputs">
<h3>URL</h3>
<paper-input label="path" value="{{path}}" always-float-label>
</paper-input>
<paper-input label="hash" value="{{hash}}" always-float-label>
</paper-input>
<paper-input label='query' value='{{query}}' always-float-label>
</paper-input>
</div>
<div class="history_entries">
<h3>Dwell Time</h3>
<p>
iron-location won't add extraneous entries to the browser's history
when changes come in quick succession.
</p>
<p>
A new history entry will only be added if iron-location stays in
the same state longer than dwellTime.
</p>
<div>
<label>History added: </label>
{{historyElementsAdded}} entries
</div>
<div>
<label>Dwell time:</label>
{{inSeconds(dwellTime)}}s
</div>
<paper-slider min="-1" max="5000" value="2000" step="100"
immediate-value="{{dwellTime}}">
</paper-slider>
</div>
</div>
</template>
<script>
window.addEventListener('WebComponentsReady', function() {
Polymer({
is: 'iron-location-demo',
properties: {
historyElementsAdded: {
type: Number
}
},
observers: [
'checkHistorySize(path, hash, query, startingHistoryLength)'
],
ready: function() {
this.startingHistoryLength = window.history.length;
},
checkHistorySize: function() {
this.historyElementsAdded =
window.history.length - this.startingHistoryLength;
},
inSeconds: function(dwellTime) {
if (dwellTime === -1) {
return -1;
}
return (Math.round(dwellTime / 100) / 10)
}
});
});
</script>
</dom-module>
<iron-location-demo></iron-location-demo>
</body>
</html>

View file

@ -1,119 +0,0 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>iron-query-params</title>
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../iron-query-params.html">
<link rel="import" href="../../paper-styles/classes/typography.html">
<link rel="import" href="../../iron-flex-layout/classes/iron-flex-layout.html">
<link rel="import" href="../../paper-input/paper-input.html">
<link rel="stylesheet" href="../../paper-styles/demo.css">
</head>
<body>
<dom-module id='iron-query-params-demo'>
<template>
<style>
div.inputs {
margin-bottom: 15px;
}
label {
display: inline-block;
width: 100px;
}
span.seconds {
}
[layout] {
@apply(--layout);
}
[layout][horizontal] {
@apply(--layout-horizontal);
}
[layout][horizontal] > div {
padding: 20px;
max-width: 500px;
}
[layout][vertical] {
@apply(--layout-vertical);
}
[layout][flex] {
@apply(--layout-flex);
}
h3 {
padding: 0;
margin: 0;
}
</style>
<iron-query-params
params-string='{{paramString}}' params-object='{{params}}'>
</iron-query-params>
<div layout horizontal>
<div layout vertical flex class='inputs'>
<paper-input label='params as string'
value='{{paramString}}' always-float-label>
</paper-input>
<paper-input label='params as object' value='{{paramsString}}'
invalid='{{paramsInvalid}}'
error-message='Should be legal JSON'
always-float-label>
</paper-input>
</div>
</div>
</template>
<script>
window.addEventListener('WebComponentsReady', function() {
Polymer({
is: 'iron-query-params-demo',
properties: {
paramsString: {
observer: 'paramsStringChanged'
},
params: {
observer: 'paramsChanged'
},
paramsInvalid: {
value: false,
},
},
paramsStringChanged: function() {
if (this.ignore) {
return;
}
this.ignore = true;
try {
this.params = JSON.parse(this.paramsString);
this.paramsInvalid = false;
} catch(_) {
this.paramsInvalid = true;
}
this.ignore = false;
},
paramsChanged: function() {
if (this.ignore) {
return;
}
this.ignore = true;
this.paramsString = JSON.stringify(this.params);
this.paramsInvalid = false;
this.ignore = false;
}
});
});
</script>
</dom-module>
<iron-query-params-demo></iron-query-params-demo>
</body>
</html>

View file

@ -1,27 +0,0 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>iron-location</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../iron-component-page/iron-component-page.html">
</head>
<body>
<iron-component-page></iron-component-page>
</body>
</html>

View file

@ -1,330 +0,0 @@
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<!--
The `iron-location` element manages binding to and from the current URL.
iron-location is the first, and lowest level element in the Polymer team's
routing system. This is a beta release of iron-location as we continue work
on higher level elements, and as such iron-location may undergo breaking
changes.
#### Properties
When the URL is: `/search?query=583#details` iron-location's properties will be:
- path: `'/search'`
- query: `'query=583'`
- hash: `'details'`
These bindings are bidirectional. Modifying them will in turn modify the URL.
iron-location is only active while it is attached to the document.
#### Links
While iron-location is active in the document it will intercept clicks on links
within your site, updating the URL pushing the updated URL out through the
databinding system. iron-location only intercepts clicks with the intent to
open in the same window, so middle mouse clicks and ctrl/cmd clicks work fine.
You can customize this behavior with the `urlSpaceRegex`.
#### Dwell Time
iron-location protects against accidental history spamming by only adding
entries to the user's history if the URL stays unchanged for `dwellTime`
milliseconds.
@demo demo/index.html
-->
<script>
'use strict';
Polymer({
is: 'iron-location',
properties: {
/**
* The pathname component of the URL.
*/
path: {
type: String,
notify: true,
value: function() {
return window.location.pathname;
}
},
/**
* The query string portion of the URL.
*/
query: {
type: String,
notify: true,
value: function() {
return window.location.search.slice(1);
}
},
/**
* The hash component of the URL.
*/
hash: {
type: String,
notify: true,
value: function() {
return window.location.hash.slice(1);
}
},
/**
* If the user was on a URL for less than `dwellTime` milliseconds, it
* won't be added to the browser's history, but instead will be replaced
* by the next entry.
*
* This is to prevent large numbers of entries from clogging up the user's
* browser history. Disable by setting to a negative number.
*/
dwellTime: {
type: Number,
value: 2000
},
/**
* A regexp that defines the set of URLs that should be considered part
* of this web app.
*
* Clicking on a link that matches this regex won't result in a full page
* navigation, but will instead just update the URL state in place.
*
* This regexp is given everything after the origin in an absolute
* URL. So to match just URLs that start with /search/ do:
* url-space-regex="^/search/"
*
* @type {string|RegExp}
*/
urlSpaceRegex: {
type: String,
value: ''
},
/**
* urlSpaceRegex, but coerced into a regexp.
*
* @type {RegExp}
*/
_urlSpaceRegExp: {
computed: '_makeRegExp(urlSpaceRegex)'
},
_lastChangedAt: {
type: Number
},
_initialized: {
type: Boolean,
value: false
}
},
hostAttributes: {
hidden: true
},
observers: [
'_updateUrl(path, query, hash)'
],
attached: function() {
this.listen(window, 'hashchange', '_hashChanged');
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();
},
detached: function() {
this.unlisten(window, 'hashchange', '_hashChanged');
this.unlisten(window, 'location-changed', '_urlChanged');
this.unlisten(window, 'popstate', '_urlChanged');
this.unlisten(/** @type {!HTMLBodyElement} */(document.body), 'click', '_globalOnClick');
this._initialized = false;
},
_hashChanged: function() {
this.hash = window.location.hash.substring(1);
},
_urlChanged: function() {
// We want to extract all info out of the updated URL before we
// try to write anything back into it.
//
// i.e. without _dontUpdateUrl we'd overwrite the new path with the old
// one when we set this.hash. Likewise for query.
this._dontUpdateUrl = true;
this._hashChanged();
this.path = window.location.pathname;
this.query = window.location.search.substring(1);
this._dontUpdateUrl = false;
this._updateUrl();
},
_getUrl: function() {
var url = this.path;
var query = this.query;
if (query) {
url += '?' + query;
}
if (this.hash) {
url += '#' + this.hash;
}
return url;
},
_updateUrl: function() {
if (this._dontUpdateUrl || !this._initialized) {
return;
}
var newUrl = this._getUrl();
var currentUrl = (
window.location.pathname +
window.location.search +
window.location.hash
);
if (newUrl == currentUrl) {
// nothing to do, the URL didn't change
return;
}
// 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 = window.performance.now();
var shouldReplace =
this._lastChangedAt + this.dwellTime > now;
this._lastChangedAt = now;
if (shouldReplace) {
window.history.replaceState({}, '', fullNewUrl);
} else {
window.history.pushState({}, '', fullNewUrl);
}
this.fire('location-changed', {}, {node: window});
},
/**
* A necessary evil so that links work as expected. Does its best to
* bail out early if possible.
*
* @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;
}
event.preventDefault();
// If the navigation is to the current page we shouldn't add a history
// entry or fire a change event.
if (href === window.location.href) {
return;
}
window.history.pushState({}, '', href);
this.fire('location-changed', {}, {node: window});
},
/**
* Returns the absolute URL of the link (if any) that this click event
* is clicking on, if we can and should override the resulting full
* page navigation. Returns null otherwise.
*
* @param {MouseEvent} event .
* @return {string?} .
*/
_getSameOriginLinkHref: function(event) {
// We only care about left-clicks.
if (event.button !== 0) {
return null;
}
// We don't want modified clicks, where the intent is to open the page
// in a new tab.
if (event.metaKey || event.ctrlKey) {
return null;
}
var eventPath = Polymer.dom(event).path;
var anchor = null;
for (var i = 0; i < eventPath.length; i++) {
var element = eventPath[i];
if (element.tagName === 'A' && element.href) {
anchor = element;
break;
}
}
// If there's no link there's nothing to do.
if (!anchor) {
return null;
}
// Target blank is a new tab, don't intercept.
if (anchor.target === '_blank') {
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 null;
}
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;
if (document.baseURI != null) {
url = new URL(href, /** @type {string} */(document.baseURI));
} else {
url = new URL(href);
}
var origin;
// IE Polyfill
if (window.location.origin) {
origin = window.location.origin;
} else {
origin = window.location.protocol + '//' + window.location.hostname;
if (window.location.port) {
origin += ':' + window.location.port;
}
}
if (url.origin !== origin) {
return null;
}
var normalizedHref = url.pathname + url.search + url.hash;
// If we've been configured not to handle this url... don't handle it!
if (this._urlSpaceRegExp &&
!this._urlSpaceRegExp.test(normalizedHref)) {
return null;
}
// Need to use a full URL in case the containing page has a base URI.
var fullNormalizedHref = new URL(
normalizedHref, window.location.href).href;
return fullNormalizedHref;
},
_makeRegExp: function(urlSpaceRegex) {
return RegExp(urlSpaceRegex);
}
});
</script>

View file

@ -1,83 +0,0 @@
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<script>
'use strict';
Polymer({
is: 'iron-query-params',
properties: {
paramsString: {
type: String,
notify: true,
observer: 'paramsStringChanged',
},
paramsObject: {
type: Object,
notify: true,
value: function() {
return {};
}
},
_dontReact: {
type: Boolean,
value: false
}
},
hostAttributes: {
hidden: true
},
observers: [
'paramsObjectChanged(paramsObject.*)'
],
paramsStringChanged: function() {
this._dontReact = true;
this.paramsObject = this._decodeParams(this.paramsString);
this._dontReact = false;
},
paramsObjectChanged: function() {
if (this._dontReact) {
return;
}
this.paramsString = this._encodeParams(this.paramsObject);
},
_encodeParams: function(params) {
var encodedParams = [];
for (var key in params) {
var value = params[key];
if (value === '') {
encodedParams.push(encodeURIComponent(key));
} else if (value) {
encodedParams.push(
encodeURIComponent(key) +
'=' +
encodeURIComponent(value.toString())
);
}
}
return encodedParams.join('&');
},
_decodeParams: function(paramString) {
var params = {};
var paramList = (paramString || '').split('&');
for (var i = 0; i < paramList.length; i++) {
var param = paramList[i].split('=');
if (param[0]) {
params[decodeURIComponent(param[0])] =
decodeURIComponent(param[1] || '');
}
}
return params;
}
});
</script>

View file

@ -1,26 +0,0 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<meta charset="utf-8">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../web-component-tester/browser.js"></script>
</head>
<body>
<script>
WCT.loadSuites([
'iron-location.html',
'iron-query-params.html',
'initialization-tests.html'
]);
</script>
</body>
</html>

View file

@ -1,277 +0,0 @@
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel='import' href='../iron-location.html'>
<link rel='import' href='../../polymer/polymer.html'>
<script>
Polymer({
is: 'default-value',
properties: {
val: {
type: String,
notify: true,
value: 'default-value'
}
},
});
Polymer({
is: 'on-attached',
properties: {
val: {
type: String,
notify: true,
value: 'on-attached-default-value'
}
},
attached: function() {
if (this.val === 'on-attached-default-value') {
this.val = 'on-attached';
}
}
});
Polymer({
is: 'on-ready',
properties: {
val: {
type: String,
notify: true,
value: 'on-ready-default-value'
}
},
ready: function() {
this.val = 'on-ready';
}
});
Polymer({
is: 'on-timeout',
properties: {
val: {
type: String,
notify: true,
value: 'on-timeout-default-value'
}
},
attached: function() {
setTimeout(function() {
this.val = 'on-timeout';
}.bind(this), 10);
}
})
</script>
<dom-module id='default-before'>
<template>
<default-value value='{{val}}'></default-value>
<iron-location query='{{val}}'></iron-location>
</template>
<script>Polymer({is: 'default-before', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='attached-before'>
<template>
<on-attached val='{{val}}'></on-attached>
<iron-location query='{{val}}'></iron-location>
</template>
<script>Polymer({is: 'attached-before', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='ready-before'>
<template>
<on-ready val='{{val}}'></on-ready>
<iron-location query='{{val}}'></iron-location>
</template>
<script>Polymer({is: 'ready-before', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='timeout-before'>
<template>
<on-timeout val='{{val}}'></on-timeout>
<iron-location query='{{val}}'></iron-location>
</template>
<script>Polymer({is: 'timeout-before', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='default-after'>
<template>
<iron-location query='{{val}}'></iron-location>
<default-value value='{{val}}'></default-value>
</template>
<script>Polymer({is: 'default-after', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='attached-after'>
<template>
<iron-location query='{{val}}'></iron-location>
<on-attached val='{{val}}'></on-attached>
</template>
<script>Polymer({is: 'attached-after', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='ready-after'>
<template>
<iron-location query='{{val}}'></iron-location>
<on-ready val='{{val}}'></on-ready>
</template>
<script>Polymer({is: 'ready-after', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='timeout-after'>
<template>
<iron-location query='{{val}}'></iron-location>
<on-timeout val='{{val}}'></on-timeout>
</template>
<script>Polymer({is: 'timeout-after', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='default-below'>
<template>
<iron-location query='{{val}}'>
<default-value value='{{val}}'></default-value>
</iron-location>
</template>
<script>Polymer({is: 'default-below', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='attached-below'>
<template>
<iron-location query='{{val}}'>
<on-attached val='{{val}}'></on-attached>
</iron-location>
</template>
<script>Polymer({is: 'attached-below', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='ready-below'>
<template>
<iron-location query='{{val}}'>
<on-ready val='{{val}}'></on-ready>
</iron-location>
</template>
<script>Polymer({is: 'ready-below', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='timeout-below'>
<template>
<iron-location query='{{val}}'>
<on-timeout val='{{val}}'></on-timeout>
</iron-location>
</template>
<script>Polymer({is: 'timeout-below', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='default-above'>
<template>
<default-value value='{{val}}'>
<iron-location query='{{val}}'></iron-location>
</default-value>
</template>
<script>Polymer({is: 'default-above', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='attached-above'>
<template>
<on-attached val='{{val}}'>
<iron-location query='{{val}}'>
</iron-location>
</on-attached>
</template>
<script>Polymer({is: 'attached-above', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='ready-above'>
<template>
<on-ready val='{{val}}'>
<iron-location query='{{val}}'>
</iron-location>
</on-ready>
</template>
<script>Polymer({is: 'ready-above', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='timeout-above'>
<template>
<on-timeout val='{{val}}'>
<iron-location query='{{val}}'></iron-location>
</on-timeout>
</template>
<script>Polymer({is: 'timeout-above', properties: {val: {type: String}}});</script>
</dom-module>
<dom-module id='default-container'>
<template>
<iron-location query='{{val}}'></iron-location>
</template>
<script>
Polymer({
is: 'default-container',
properties: {val: {type: String, value: 'default-container-val'}}
});
</script>
</dom-module>
<dom-module id='attached-container'>
<template>
<iron-location query='{{val}}'></iron-location>
</template>
<script>
Polymer({
is: 'attached-container',
properties: {val: {type: String, value: 'container-attached-default-val'}},
attached: function() {
if (this.val === 'container-attached-default-val') {
this.val = 'attached-container-val';
}
}
});
</script>
</dom-module>
<dom-module id='ready-container'>
<template>
<iron-location query='{{val}}'></iron-location>
</template>
<script>
Polymer({
is: 'ready-container', properties: {val: {type: String}},
ready: function() {
this.val = 'ready-container-val';
}
});
</script>
</dom-module>
<dom-module id='timeout-container'>
<template>
<iron-location query='{{val}}'></iron-location>
</template>
<script>Polymer({
is: 'timeout-container',
properties: {
val: {
type: String,
notify: true
}
},
attached: function() {
setTimeout(function() {
this.val = 'on-timeout';
}.bind(this), 10);
}
});</script>
</dom-module>

View file

@ -1,61 +0,0 @@
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Base source for injecting into an iframe for tests</title>
<script src="../../webcomponentsjs/webcomponents.js"></script>
<link rel='import' href='./initialization-cases.html'>
</head>
<body>
<script>
window.addEventListener("message", messageReceived, false);
window.addEventListener('WebComponentsReady', function() {
window.parent.postMessage({
'type': 'ready'
}, '*');
});
var appendBodyReceived = false;
function messageReceived(msg) {
if (!msg.data) {
console.error('got invalid msg?');
}
// the parent can (at any time) ask for our URL.
if (msg.data.type === 'urlQuery') {
msg.source.postMessage({
'type': 'urlQueryResponse',
'href': window.location.href,
'pathname': window.location.pathname,
'hash': window.location.hash,
'search': window.location.search
}, '*');
} else if (msg.data.type === 'appendBody') {
if (appendBodyReceived) {
throw new Error('should only receive at most one appendBody call');
}
var element = document.createElement(msg.data.tagName);
document.body.appendChild(element);
appendBodyReceived = true;
}
}
window.addEventListener('error', function(e) {
window.parent.postMessage({
'type': 'error',
'error': e.message
}, '*');
});
</script>
</body>
</html>

View file

@ -1,145 +0,0 @@
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<script src="../../test-fixture/test-fixture-mocha.js"></script>
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../../promise-polyfill/promise-polyfill.html">
<link rel="import" href="../../test-fixture/test-fixture.html">
<link rel="import" href="../iron-location.html">
</head>
<body>
<script>
'use strict';
function getIframe() {
return new Promise(function(resolve, reject) {
var iframe = document.createElement('iframe');
var result = getMessageMatching(iframe, function(message) {
return message.type === 'ready';
});
iframe.src = './initialization-iframe.html';
document.body.appendChild(iframe);
iframe.addEventListener('error', reject);
result.then(function() {resolve(iframe)}, reject);
});
}
function onMessage(iframe, callback) {
var f = function(event) {
if (event.source === iframe.contentWindow) {
callback(event.data);
}
};
window.addEventListener('message', f, false);
return function() {
window.removeEventListener('message', f);
}
}
function getMessageMatching(iframe, predicate) {
var revoke = function() {};
var result = new Promise(function(resolve, reject) {
revoke = onMessage(iframe, function(message) {
if (predicate(message)) {
resolve(message);
}
});
});
result.then(revoke, revoke);
return result;
}
function getUrl(iframe) {
var result = getMessageMatching(iframe, function(message) {
return message.type === 'urlQueryResponse';
})
var revoke = function() {};
var result = new Promise(function(resolve, reject) {
revoke = onMessage(iframe, resolve);
});
result.then(revoke, revoke);
iframe.contentWindow.postMessage({type: 'urlQuery'}, '*');
return result;
}
function timePasses(ms) {
return new Promise(function(resolve) {
window.setTimeout(function() {
resolve();
}, ms);
});
}
suite('<iron-location>\'s initialization', function() {
var iframe;
var error;
setup(function() {
return getIframe().then(function(i) {
iframe = i;
function isError(m) {return m.type === 'error'}
getMessageMatching(iframe, isError).then(function(m) {
error = m.error;
});
});
});
teardown(function() {
if (iframe) {
document.body.removeChild(iframe);
}
var e = error;
iframe = null;
error = null;
if (e) {
throw new Error('Error message from contained iframe: ' + e);
}
});
var cases = [
'default-before', 'attached-before', 'ready-before',
'default-after', 'attached-after', 'ready-after',
'default-below', 'attached-below', 'ready-below',
'default-above', 'attached-above', 'ready-above',
'default-container', 'attached-container', 'ready-container'
];
cases.forEach(function(caseName) {
test('the url takes priority in ' + caseName + ' initialization', function() {
return getUrl(iframe).then(function(url) {
expect(url.search).to.be.eq('');
iframe.contentWindow.postMessage({type: 'appendBody', tagName: caseName}, '*');
return timePasses(10).then(function() {return getUrl(iframe)});
}).then(function(url) {
expect(url.search).to.be.eq('');
});
});
});
var expectedFailureCases = ['timeout-before', 'timeout-after', 'timeout-below', 'timeout-above', 'timeout-container'];
expectedFailureCases.forEach(function(caseName) {
test('the url does not take priority in ' + caseName + ' initialization', function() {
return getUrl(iframe).then(function(url) {
expect(url.search).to.be.eq('');
iframe.contentWindow.postMessage({type: 'appendBody', tagName: caseName}, '*');
return timePasses(60).then(function() {return getUrl(iframe)});
}).then(function(url) {
expect(url.search).to.be.eq('?on-timeout');
});
});
});
});
</script>
</body>
</html>

View file

@ -1,369 +0,0 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>iron-location</title>
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../../promise-polyfill/promise-polyfill.html">
<link rel="import" href="../iron-location.html">
<link rel="import" href="./redirection.html">
</head>
<body>
<test-fixture id='Solo'>
<template>
<iron-location></iron-location>
</template>
</test-fixture>
<test-fixture id='Together'>
<template>
<div>
<iron-location id='one'></iron-location>
<iron-location id='two'></iron-location>
</div>
</template>
</test-fixture>
<test-fixture id='RedirectHash'>
<template>
<redirect-hash></redirect-hash>
</template>
</test-fixture>
<test-fixture id='RedirectPath'>
<template>
<redirect-path></redirect-path>
</template>
</test-fixture>
<test-fixture id='RedirectQuery'>
<template>
<redirect-query></redirect-query>
</template>
</test-fixture>
<script>
'use strict';
function timePasses(ms) {
return new Promise(function(resolve) {
window.setTimeout(function() {
resolve();
}, ms);
});
}
function makeAbsoluteUrl(path) {
return window.location.protocol + '//' + window.location.host + path;
}
// A window.history.replaceState wrapper that's smart about baseURI.
function replaceState(path) {
window.history.replaceState({}, '', makeAbsoluteUrl(path));
}
/**
* We run the iron location tests with a couple different page configurations
* (e.g. with and withoug a base URI), so we define the test set as a function
* that we call in each of these configurations.
*/
function ironLocationTests() {
suite('when used solo', function() {
var urlElem;
setup(function() {
urlElem = fixture('Solo');
});
test('basic functionality with #hash urls', function() {
// Initialized to the window location's hash.
expect(window.location.hash).to.be.equal(urlElem.hash);
// Changing the urlElem's hash changes the URL
urlElem.hash = '/lol/ok';
expect(window.location.hash).to.be.equal('#/lol/ok');
// Changing the hash via normal means changes the urlElem.
var anchor = document.createElement('a');
var base =
window.location.protocol + '//' + window.location.host +
window.location.pathname;
anchor.href = base + '#/wat';
document.body.appendChild(anchor);
anchor.click();
// In IE10 it appears that the hashchange event is asynchronous.
return timePasses(10).then(function() {
expect(urlElem.hash).to.be.equal('/wat');
});
});
test('basic functionality with paths', function() {
// Initialized to the window location's path.
expect(window.location.pathname).to.be.equal(urlElem.path);
// Changing the urlElem's path changes the URL
urlElem.path = '/foo/bar';
expect(window.location.pathname).to.be.equal('/foo/bar');
// Changing the path and sending a custom event on the window changes
// the urlElem.
replaceState('/baz');
window.dispatchEvent(new CustomEvent('location-changed'));
expect(urlElem.path).to.be.equal('/baz');
});
test('assigning to a relative path URL', function() {
urlElem.path = '/foo/bar';
expect(window.location.pathname).to.be.equal('/foo/bar');
// A relative path is treated as an absolute one, just with a
// missing leading slash.
urlElem.path = 'baz';
expect(window.location.pathname).to.be.equal('/baz');
});
test('basic functionality with ?key=value params', function() {
// Initialized to the window location's params.
expect(urlElem.query).to.be.eq('');
// Changing location.search and sending a custom event on the window
// changes the urlElem.
replaceState('/?greeting=hello&target=world');
window.dispatchEvent(new CustomEvent('location-changed'));
expect(urlElem.query).to.be.equal('greeting=hello&target=world');
// Changing the urlElem's query changes the URL.
urlElem.query = 'greeting=hello&target=world&another=key';
expect(window.location.search).to.be.equal(
'?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 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);
expect(pushStateCalls).to.be.equal(1);
});
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);
expect(pushStateCalls).to.be.equal(1);
});
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);
expect(pushStateCalls).to.be.equal(0);
});
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);
expect(pushStateCalls).to.be.equal(0);
});
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);
expect(pushStateCalls).to.be.equal(0);
});
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;
// The click is captured, but it doesn't add to history.
expect(isClickCaptured(anchor)).to.be.equal(true);
expect(pushStateCalls).to.be.equal(0);
});
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);
})
});
});
suite('when used with other iron-location elements', function() {
var otherUrlElem;
var urlElem;
setup(function() {
var elems = fixture('Together');
urlElem = elems.querySelector('#one');
otherUrlElem = elems.querySelector('#two');
});
function assertHaveSameUrls(urlElemOne, urlElemTwo) {
expect(urlElemOne.path).to.be.equal(urlElemTwo.path);
expect(urlElemOne.hash).to.be.equal(urlElemTwo.hash);
expect(urlElemOne.query).to.be.equal(urlElemTwo.query);
}
test('coordinate their changes (by firing events on window)', function() {
assertHaveSameUrls(urlElem, otherUrlElem);
urlElem.path = '/a/b/c';
assertHaveSameUrls(urlElem, otherUrlElem);
otherUrlElem.query = 'alsdkjflaksjfd=alksjfdlkajsdfl';
assertHaveSameUrls(urlElem, otherUrlElem);
urlElem.hash = 'lkjljifosjkldfjlksjfldsjf';
assertHaveSameUrls(urlElem, otherUrlElem);
});
});
suite('supports doing synchronous redirection', function() {
test('of the hash portion of the URL', function() {
expect(window.location.hash).to.be.equal('');
var redirector = fixture('RedirectHash');
expect(window.location.hash).to.be.equal('#redirectedTo');
expect(redirector.hash).to.be.equal('redirectedTo');
redirector.hash = 'newHash';
expect(window.location.hash).to.be.equal('#redirectedTo');
expect(redirector.hash).to.be.equal('redirectedTo');
});
test('of the path portion of the URL', function() {
expect(window.location.pathname).to.not.be.equal('/redirectedTo');
var redirector = fixture('RedirectPath');
expect(window.location.pathname).to.be.equal('/redirectedTo');
expect(redirector.path).to.be.equal('/redirectedTo');
redirector.path = '/newPath';
expect(window.location.pathname).to.be.equal('/redirectedTo');
expect(redirector.path).to.be.equal('/redirectedTo');
});
test('of the query portion of the URL', function() {
expect(window.location.search).to.be.equal('');
var redirector = fixture('RedirectQuery');
expect(window.location.search).to.be.equal('?redirectedTo');
expect(redirector.query).to.be.equal('redirectedTo');
redirector.query = 'newQuery';
expect(window.location.search).to.be.equal('?redirectedTo');
expect(redirector.query).to.be.equal('redirectedTo');
});
});
}
suite('<iron-location>', function () {
var initialUrl;
setup(function() {
initialUrl = window.location.href;
});
teardown(function(){
window.history.replaceState({}, '', initialUrl);
});
ironLocationTests();
suite('with a base URI', function() {
var baseElem;
setup(function() {
expect(document.baseURI).to.be.equal(window.location.href);
baseElem = document.createElement('base');
var href = 'https://example.com/i/dont/exist/obviously'
baseElem.href = href;
document.head.appendChild(baseElem);
expect(document.baseURI).to.be.equal(href);
});
teardown(function() {
document.head.removeChild(baseElem);
});
ironLocationTests();
});
});
</script>
</body>

View file

@ -1,96 +0,0 @@
<!doctype html>
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
<head>
<title>iron-location</title>
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="../../polymer/polymer.html">
<link rel="import" href="../../promise-polyfill/promise-polyfill.html">
<link rel="import" href="../iron-query-params.html">
</head>
<body>
<test-fixture id="BasicQueryParams">
<template>
<iron-query-params></iron-query-params>
</template>
</test-fixture>
<script>
'use strict';
suite('<iron-query-params>', function () {
var paramsElem;
setup(function() {
paramsElem = fixture('BasicQueryParams');
});
test('basic functionality with ?key=value params', function() {
// Check initialization
expect(paramsElem.paramsString).to.be.eq('');
expect(paramsElem.paramsObject).to.deep.eq({});
// Check the mapping from paramsString to paramsObject.
paramsElem.paramsString = 'greeting=hello&target=world';
expect(paramsElem.paramsObject).to.deep.equal(
{greeting: 'hello', target: 'world'});
// Check the mapping from paramsObject back to paramsString.
paramsElem.set('paramsObject.another', 'key');
expect(paramsElem.paramsString).to.be.equal(
'greeting=hello&target=world&another=key');
});
test('encoding of params', function() {
var mappings = [
{
string: 'a=b',
object: {'a': 'b'}
},
{
string: 'debug&ok',
object: {'debug': '', 'ok': ''}
},
{
string: 'monster%20kid%3A=%F0%9F%98%BF',
object: {'monster kid:': '😿'}
},
{
string: 'yes%2C%20ok%3F%20what%20is%20up%20with%20%CB%9Athiiis%CB%9A=%E2%98%83',
object: {'yes, ok? what is up with ˚thiiis˚': '☃'}
},
];
mappings.forEach(function(mapping) {
// Clear
paramsElem.paramsObject = {};
expect(paramsElem.paramsString).to.be.equal('');
// Test going from string to object
paramsElem.paramsString = mapping.string;
expect(paramsElem.paramsObject).to.deep.equal(mapping.object);
// Clear again.
paramsElem.paramsObject = {};
expect(paramsElem.paramsString).to.be.equal('');
// Test going from object to string
paramsElem.paramsObject = mapping.object;
expect(paramsElem.paramsString).to.be.equal(mapping.string);
});
});
});
</script>
</body>

View file

@ -1,68 +0,0 @@
<!--
@license
Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<dom-module id='redirect-hash'>
<template>
<iron-location hash='{{hash}}'></iron-location>
</template>
<script>
Polymer({
is: 'redirect-hash',
properties: {
hash: {
value: '',
observer: 'hashChanged'
}
},
hashChanged: function(hash) {
this.hash = 'redirectedTo';
}
});
</script>
</dom-module>
<dom-module id='redirect-path'>
<template>
<iron-location path='{{path}}'></iron-location>
</template>
<script>
Polymer({
is: 'redirect-path',
properties: {
path: {
value: '',
observer: 'pathChanged'
}
},
pathChanged: function(path) {
this.path = '/redirectedTo';
}
});
</script>
</dom-module>
<dom-module id='redirect-query'>
<template>
<iron-location query='{{query}}'></iron-location>
</template>
<script>
Polymer({
is: 'redirect-query',
properties: {
query: {
value: '',
observer: 'queryChanged'
}
},
queryChanged: function(query) {
this.query = 'redirectedTo';
}
});
</script>
</dom-module>