react app

This commit is contained in:
Mario Romano
2016-04-06 17:52:19 +01:00
parent f7e6ef55a2
commit 29df96a085
4425 changed files with 446323 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
{
"name": "iron-fit-behavior",
"version": "1.0.6",
"license": "http://polymer.github.io/LICENSE.txt",
"description": "Fits an element inside another element",
"private": true,
"main": "iron-fit-behavior.html",
"keywords": [
"web-components",
"polymer",
"behavior"
],
"authors": [
"The Polymer Authors"
],
"repository": {
"type": "git",
"url": "git://github.com/PolymerElements/iron-fit-behavior.git"
},
"dependencies": {
"polymer": "Polymer/polymer#^1.0.0"
},
"devDependencies": {
"paper-styles": "polymerelements/paper-styles#^1.0.2",
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
"test-fixture": "PolymerElements/test-fixture#^1.0.0",
"web-component-tester": "^4.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
},
"ignore": [],
"homepage": "https://github.com/PolymerElements/iron-fit-behavior",
"_release": "1.0.6",
"_resolution": {
"type": "version",
"tag": "v1.0.6",
"commit": "f2e868af4fad643ffb7fea3501e1429acc4ec0f0"
},
"_source": "git://github.com/PolymerElements/iron-fit-behavior.git",
"_target": "^1.0.0",
"_originalSource": "PolymerElements/iron-fit-behavior"
}

View File

@@ -0,0 +1 @@
bower_components

View File

@@ -0,0 +1,25 @@
language: node_js
sudo: false
before_script:
- npm install -g bower polylint web-component-tester
- bower install
- polylint
env:
global:
- secure: QL2j7nfSA/40iIPMKLMosv9hj8q7eGBbPQXVQmCL3uXD5qoMPTqo1qronKKX+bi3Rh7W104ufV4CzzbWvBwQh8gipx+4REGijzc77Fro2y3v3/wUp9H/UEWnbhAWPDsqEoAD8xQXFHkVv7874/VwOlubQyXDGlvqh0fzYbUNUQo=
- secure: ajBo8YcSzi4kNuCHcmajCirWQKf5Mj4OZ3tQjNAcJJAy0UtyrAgTenayWN2ijKqD5V8wfTK66jUXGYMZkoJV4EpknrUliqRgRqKHHfULXYWRSC7lDGxf835ReFxstkPun4HmNtxraAWJgmgFz7mylntTVKm46Ce4INj3n8reWaY=
- CXX=g++-4.8
node_js: stable
addons:
firefox: latest
apt:
sources:
- google-chrome
- ubuntu-toolchain-r-test
packages:
- google-chrome-stable
- g++-4.8
sauce_connect: true
script:
- xvfb-run wct
- "if [ \"${TRAVIS_PULL_REQUEST}\" = \"false\" ]; then wct -s 'default'; fi"

View File

@@ -0,0 +1,77 @@
<!--
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/cagaye/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/cagaye/edit?html,output](https://jsbin.com/cagaye/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

@@ -0,0 +1,36 @@
<!---
This README is automatically generated from the comments in these files:
iron-fit-behavior.html
Edit those files, and our readme bot will duplicate them over here!
Edit this file, and the bot will squash your changes :)
The bot does some handling of markdown. Please file a bug if it does the wrong
thing! https://github.com/PolymerLabs/tedium/issues
-->
[![Build status](https://travis-ci.org/PolymerElements/iron-fit-behavior.svg?branch=master)](https://travis-ci.org/PolymerElements/iron-fit-behavior)
_[Demo and API docs](https://elements.polymer-project.org/elements/iron-fit-behavior)_
##Polymer.IronFitBehavior
Polymer.IronFitBehavior fits an element in another element using `max-height` and `max-width`, and
optionally centers it in the window or another element.
The element will only be sized and/or positioned if it has not already been sized and/or positioned
by CSS.
| CSS properties | Action |
| --- | --- |
| `position` set | Element is not centered horizontally or vertically |
| `top` or `bottom` set | Element is not vertically centered |
| `left` or `right` set | Element is not horizontally centered |
| `max-height` or `height` set | Element respects `max-height` or `height` |
| `max-width` or `width` set | Element respects `max-width` or `width` |

View File

@@ -0,0 +1,31 @@
{
"name": "iron-fit-behavior",
"version": "1.0.6",
"license": "http://polymer.github.io/LICENSE.txt",
"description": "Fits an element inside another element",
"private": true,
"main": "iron-fit-behavior.html",
"keywords": [
"web-components",
"polymer",
"behavior"
],
"authors": [
"The Polymer Authors"
],
"repository": {
"type": "git",
"url": "git://github.com/PolymerElements/iron-fit-behavior.git"
},
"dependencies": {
"polymer": "Polymer/polymer#^1.0.0"
},
"devDependencies": {
"paper-styles": "polymerelements/paper-styles#^1.0.2",
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
"test-fixture": "PolymerElements/test-fixture#^1.0.0",
"web-component-tester": "^4.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
},
"ignore": []
}

View File

@@ -0,0 +1,43 @@
<!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-fit-behavior demo</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../webcomponentsjs/webcomponents-lite.js"></script>
<link href="../../paper-styles/demo-pages.html" rel="import">
<link rel="import" href="simple-fit.html">
<style>
.sized {
max-width: 50%;
max-height: 50%;
padding: 20px;
}
</style>
</head>
<body unresolved>
<simple-fit id="myFit" auto-fit-on-attach class="sized" onclick="myFit.refit()">
Centered in window.<br><br>
Resize the window and click here to refit.
</simple-fit>
</body>
</html>

View File

@@ -0,0 +1,51 @@
<!--
@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">
<link rel="import" href="../iron-fit-behavior.html">
<link rel="import" href="../../paper-styles/color.html">
<link rel="import" href="../../iron-flex-layout/iron-flex-layout.html">
<dom-module id="simple-fit">
<style>
:host {
@apply(--layout);
background-color: var(--paper-light-blue-500);
color: white;
text-align: center;
align-items:center;
-webkit-align-items: center;
justify-content:center;
-webkit-justify-content:center;
}
</style>
<template>
<content></content>
</template>
</dom-module>
<script>
Polymer({
is: 'simple-fit',
behaviors: [
Polymer.IronFitBehavior
]
});
</script>

View File

@@ -0,0 +1,30 @@
<!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">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>iron-fit-behavior</title>
<script src="../webcomponentsjs/webcomponents-lite.js"></script>
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-component-page/iron-component-page.html">
</head>
<body>
<iron-component-page></iron-component-page>
</body>
</html>

View File

@@ -0,0 +1,272 @@
<!--
@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>
/**
Polymer.IronFitBehavior fits an element in another element using `max-height` and `max-width`, and
optionally centers it in the window or another element.
The element will only be sized and/or positioned if it has not already been sized and/or positioned
by CSS.
CSS properties | Action
-----------------------------|-------------------------------------------
`position` set | Element is not centered horizontally or vertically
`top` or `bottom` set | Element is not vertically centered
`left` or `right` set | Element is not horizontally centered
`max-height` or `height` set | Element respects `max-height` or `height`
`max-width` or `width` set | Element respects `max-width` or `width`
@demo demo/index.html
@polymerBehavior
*/
Polymer.IronFitBehavior = {
properties: {
/**
* The element that will receive a `max-height`/`width`. By default it is the same as `this`,
* but it can be set to a child element. This is useful, for example, for implementing a
* scrolling region inside the element.
* @type {!Element}
*/
sizingTarget: {
type: Object,
value: function() {
return this;
}
},
/**
* The element to fit `this` into.
*/
fitInto: {
type: Object,
value: window
},
/**
* Set to true to auto-fit on attach.
*/
autoFitOnAttach: {
type: Boolean,
value: false
},
/** @type {?Object} */
_fitInfo: {
type: Object
}
},
get _fitWidth() {
var fitWidth;
if (this.fitInto === window) {
fitWidth = this.fitInto.innerWidth;
} else {
fitWidth = this.fitInto.getBoundingClientRect().width;
}
return fitWidth;
},
get _fitHeight() {
var fitHeight;
if (this.fitInto === window) {
fitHeight = this.fitInto.innerHeight;
} else {
fitHeight = this.fitInto.getBoundingClientRect().height;
}
return fitHeight;
},
get _fitLeft() {
var fitLeft;
if (this.fitInto === window) {
fitLeft = 0;
} else {
fitLeft = this.fitInto.getBoundingClientRect().left;
}
return fitLeft;
},
get _fitTop() {
var fitTop;
if (this.fitInto === window) {
fitTop = 0;
} else {
fitTop = this.fitInto.getBoundingClientRect().top;
}
return fitTop;
},
attached: function() {
if (this.autoFitOnAttach) {
if (window.getComputedStyle(this).display === 'none') {
setTimeout(function() {
this.fit();
}.bind(this));
} else {
this.fit();
}
}
},
/**
* Fits and optionally centers the element into the window, or `fitInfo` if specified.
*/
fit: function() {
this._discoverInfo();
this.constrain();
this.center();
},
/**
* Memoize information needed to position and size the target element.
*/
_discoverInfo: function() {
if (this._fitInfo) {
return;
}
var target = window.getComputedStyle(this);
var sizer = window.getComputedStyle(this.sizingTarget);
this._fitInfo = {
inlineStyle: {
top: this.style.top || '',
left: this.style.left || ''
},
positionedBy: {
vertically: target.top !== 'auto' ? 'top' : (target.bottom !== 'auto' ?
'bottom' : null),
horizontally: target.left !== 'auto' ? 'left' : (target.right !== 'auto' ?
'right' : null),
css: target.position
},
sizedBy: {
height: sizer.maxHeight !== 'none',
width: sizer.maxWidth !== 'none'
},
margin: {
top: parseInt(target.marginTop, 10) || 0,
right: parseInt(target.marginRight, 10) || 0,
bottom: parseInt(target.marginBottom, 10) || 0,
left: parseInt(target.marginLeft, 10) || 0
}
};
},
/**
* Resets the target element's position and size constraints, and clear
* the memoized data.
*/
resetFit: function() {
if (!this._fitInfo || !this._fitInfo.sizedBy.width) {
this.sizingTarget.style.maxWidth = '';
}
if (!this._fitInfo || !this._fitInfo.sizedBy.height) {
this.sizingTarget.style.maxHeight = '';
}
this.style.top = this._fitInfo ? this._fitInfo.inlineStyle.top : '';
this.style.left = this._fitInfo ? this._fitInfo.inlineStyle.left : '';
if (this._fitInfo) {
this.style.position = this._fitInfo.positionedBy.css;
}
this._fitInfo = null;
},
/**
* Equivalent to calling `resetFit()` and `fit()`. Useful to call this after the element,
* the window, or the `fitInfo` element has been resized.
*/
refit: function() {
this.resetFit();
this.fit();
},
/**
* Constrains the size of the element to the window or `fitInfo` by setting `max-height`
* and/or `max-width`.
*/
constrain: function() {
var info = this._fitInfo;
// position at (0px, 0px) if not already positioned, so we can measure the natural size.
if (!this._fitInfo.positionedBy.vertically) {
this.style.top = '0px';
}
if (!this._fitInfo.positionedBy.horizontally) {
this.style.left = '0px';
}
if (!this._fitInfo.positionedBy.vertically || !this._fitInfo.positionedBy.horizontally) {
// need position:fixed to properly size the element
this.style.position = 'fixed';
}
// need border-box for margin/padding
this.sizingTarget.style.boxSizing = 'border-box';
// constrain the width and height if not already set
var rect = this.getBoundingClientRect();
if (!info.sizedBy.height) {
this._sizeDimension(rect, info.positionedBy.vertically, 'top', 'bottom', 'Height');
}
if (!info.sizedBy.width) {
this._sizeDimension(rect, info.positionedBy.horizontally, 'left', 'right', 'Width');
}
},
_sizeDimension: function(rect, positionedBy, start, end, extent) {
var info = this._fitInfo;
var max = extent === 'Width' ? this._fitWidth : this._fitHeight;
var flip = (positionedBy === end);
var offset = flip ? max - rect[end] : rect[start];
var margin = info.margin[flip ? start : end];
var offsetExtent = 'offset' + extent;
var sizingOffset = this[offsetExtent] - this.sizingTarget[offsetExtent];
this.sizingTarget.style['max' + extent] = (max - margin - offset - sizingOffset) + 'px';
},
/**
* Centers horizontally and vertically if not already positioned. This also sets
* `position:fixed`.
*/
center: function() {
var positionedBy = this._fitInfo.positionedBy;
if (positionedBy.vertically && positionedBy.horizontally) {
// Already positioned.
return;
}
// Need position:fixed to center
this.style.position = 'fixed';
// Take into account the offset caused by parents that create stacking
// contexts (e.g. with transform: translate3d). Translate to 0,0 and
// measure the bounding rect.
if (!positionedBy.vertically) {
this.style.top = '0px';
}
if (!positionedBy.horizontally) {
this.style.left = '0px';
}
// It will take in consideration margins and transforms
var rect = this.getBoundingClientRect();
if (!positionedBy.vertically) {
var top = this._fitTop - rect.top + (this._fitHeight - rect.height) / 2;
this.style.top = top + 'px';
}
if (!positionedBy.horizontally) {
var left = this._fitLeft - rect.left + (this._fitWidth - rect.width) / 2;
this.style.left = left + 'px';
}
}
};
</script>

View File

@@ -0,0 +1,31 @@
<!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-fit-behavior tests</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../web-component-tester/browser.js"></script>
</head>
<body>
<script>
WCT.loadSuites([
'iron-fit-behavior.html',
'iron-fit-behavior.html?dom=shadow'
]);
</script>
</body></html>

View File

@@ -0,0 +1,409 @@
<!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-fit-behavior tests</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1, user-scalable=yes">
<script src="../../webcomponentsjs/webcomponents.js"></script>
<script src="../../web-component-tester/browser.js"></script>
<link rel="import" href="test-fit.html">
<style>
body {
margin: 0;
padding: 0;
}
.absolute {
position: absolute;
top: 0;
left: 0;
}
.scrolling {
overflow: auto;
}
.sized-x {
width: 200px;
}
.sized-y {
height: 200px;
}
.sized-xy {
width: 200px;
height: 200px;
}
.positioned-left {
position: absolute;
left: 100px;
}
.positioned-right {
position: absolute;
right: 100px;
}
.positioned-top {
position: absolute;
top: 100px;
}
.positioned-bottom {
position: absolute;
bottom: 100px;
}
.with-max-width {
max-width: 500px;
}
.with-max-height {
max-height: 500px;
}
.with-margin {
margin: 20px;
}
</style>
</head>
<body>
<test-fixture id="absolute">
<template>
<test-fit auto-fit-on-attach class="absolute">
Absolutely positioned
</test-fit>
</template>
</test-fixture>
<test-fixture id="sized-xy">
<template>
<test-fit auto-fit-on-attach class="sized-x sized-y">
Sized (x/y), auto center/center
</test-fit>
</template>
</test-fixture>
<test-fixture id="sized-x">
<template>
<test-fit auto-fit-on-attach class="sized-x">
Sized (x), auto center/center
</test-fit>
</template>
</test-fixture>
<test-fixture id="with-max-width">
<template>
<div class="constrain" style="position: fixed; top: 20px; left: 100px; width: 50vw; height: 50vh; border: 1px solid black;">
<test-fit auto-fit-on-attach class="with-max-width el">
with-max-width, auto center/center
</test-fit>
</div>
</template>
</test-fixture>
<test-fixture id="positioned-xy">
<template>
<test-fit auto-fit-on-attach class="sized-x positioned-left positioned-top">
Sized (x/y), positioned/positioned
</test-fit>
</template>
</test-fixture>
<test-fixture id="inline-positioned-xy">
<template>
<test-fit auto-fit-on-attach class="sized-x sized-y" style="position:absolute;left:100px;top:100px;">
Sized (x/y), positioned/positioned
</test-fit>
</template>
</test-fixture>
<test-fixture id="sectioned">
<template>
<test-fit auto-fit-on-attach class="sized-x">
<div>
Sized (x), auto center/center with scrolling section
</div>
<div class="internal"></div>
</test-fit>
</template>
</test-fixture>
<test-fixture id="constrain-target">
<template>
<div class="constrain" style="position: fixed; top: 20px; left: 100px; width: 50vw; height: 50vh; border: 1px solid black;">
<test-fit auto-fit-on-attach class="el sized-xy">
<div>
Auto center/center to parent element
</div>
</test-fit>
</div>
</template>
</test-fixture>
<test-fixture id="offscreen-container">
<template>
<div style="position: fixed; top: -1px; left: 0;">
<test-fit auto-fit-on-attach class="el sized-x">
<div>
Sized (x), auto center/center, container is offscreen
</div>
</test-fit>
</div>
</template>
</test-fixture>
<template id="ipsum">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</template>
<script>
function makeScrolling(el) {
el.classList.add('scrolling');
var template = document.getElementById('ipsum');
for (var i = 0; i < 20; i++) {
el.appendChild(template.content.cloneNode(true));
}
}
suite('manual positioning', function() {
test('css positioned element is not re-positioned', function() {
var el = fixture('positioned-xy');
var rect = el.getBoundingClientRect();
assert.equal(rect.top, 100, 'top is unset');
assert.equal(rect.left, 100, 'left is unset');
});
test('inline positioned element is not re-positioned', function() {
var el = fixture('inline-positioned-xy');
var rect = el.getBoundingClientRect();
// need to measure document.body here because mocha sets a min-width on html,body, and
// the element is positioned wrt to that by css
var bodyRect = document.body.getBoundingClientRect();
assert.equal(rect.top, 100, 'top is unset');
assert.equal(rect.left, 100, 'left is unset');
el.refit();
rect = el.getBoundingClientRect();
assert.equal(rect.top, 100, 'top is unset after refit');
assert.equal(rect.left, 100, 'left is unset after refit');
});
test('position property is preserved after', function() {
var el = fixture('absolute');
assert.equal(getComputedStyle(el).position, 'absolute', 'position:absolute is preserved');
});
});
suite('fit to window', function() {
test('sized element is centered in viewport', function() {
var el = fixture('sized-xy');
var rect = el.getBoundingClientRect();
assert.closeTo(rect.left - (window.innerWidth - rect.right), 0, 5, 'centered horizontally');
assert.closeTo(rect.top - (window.innerHeight - rect.bottom), 0, 5, 'centered vertically');
});
test('sized element with margin is centered in viewport', function() {
var el = fixture('sized-xy');
el.classList.add('with-margin');
el.refit();
var rect = el.getBoundingClientRect();
assert.closeTo(rect.left - (window.innerWidth - rect.right), 0, 5, 'centered horizontally');
assert.closeTo(rect.top - (window.innerHeight - rect.bottom), 0, 5, 'centered vertically');
});
test('sized element with transformed parent is centered in viewport', function() {
var constrain = fixture('constrain-target');
var el = Polymer.dom(constrain).querySelector('.el');
var rectBefore = el.getBoundingClientRect();
constrain.style.transform = 'translate3d(5px, 5px, 0)';
el.center();
var rectAfter = el.getBoundingClientRect();
assert.equal(rectBefore.top, rectAfter.top, 'top ok');
assert.equal(rectBefore.bottom, rectAfter.bottom, 'bottom ok');
assert.equal(rectBefore.left, rectAfter.left, 'left ok');
assert.equal(rectBefore.right, rectAfter.right, 'right ok');
});
test('scrolling element is centered in viewport', function() {
var el = fixture('sized-x');
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.closeTo(rect.left - (window.innerWidth - rect.right), 0, 5, 'centered horizontally');
assert.closeTo(rect.top - (window.innerHeight - rect.bottom), 0, 5, 'centered vertically');
});
test('scrolling element is constrained to viewport height', function() {
var el = fixture('sized-x');
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= window.innerHeight, 'height is less than or equal to viewport height');
});
test('scrolling element with offscreen container is constrained to viewport height', function() {
var container = fixture('offscreen-container');
var el = Polymer.dom(container).querySelector('.el')
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= window.innerHeight, 'height is less than or equal to viewport height');
});
test('scrolling element with max-height is centered in viewport', function() {
var el = fixture('sized-x');
el.classList.add('with-max-height');
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.closeTo(rect.left - (window.innerWidth - rect.right), 0, 5, 'centered horizontally');
assert.closeTo(rect.top - (window.innerHeight - rect.bottom), 0, 5, 'centered vertically');
});
test('scrolling element with max-height respects max-height', function() {
var el = fixture('sized-x');
el.classList.add('with-max-height');
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= 500, 'height is less than or equal to max-height');
});
test('css positioned, scrolling element is constrained to viewport height (top,left)', function() {
var el = fixture('positioned-xy');
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= window.innerHeight - 100, 'height is less than or equal to viewport height');
});
test('css positioned, scrolling element is constrained to viewport height (bottom, right)', function() {
var el = fixture('sized-x');
el.classList.add('positioned-bottom');
el.classList.add('positioned-right');
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= window.innerHeight - 100, 'height is less than or equal to viewport height');
});
test('sized, scrolling element with margin is centered in viewport', function() {
var el = fixture('sized-x');
el.classList.add('with-margin');
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.closeTo(rect.left - (window.innerWidth - rect.right), 0, 5, 'centered horizontally');
assert.closeTo(rect.top - (window.innerHeight - rect.bottom), 0, 5, 'centered vertically');
});
test('sized, scrolling element is constrained to viewport height', function() {
var el = fixture('sized-x');
el.classList.add('with-margin');
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= window.innerHeight - 20 * 2, 'height is less than or equal to viewport height');
});
test('css positioned, scrolling element with margin is constrained to viewport height (top, left)', function() {
var el = fixture('positioned-xy');
el.classList.add('with-margin');
makeScrolling(el);
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= window.innerHeight - 100 - 20 * 2, 'height is less than or equal to viewport height');
});
test('css positioned, scrolling element with margin is constrained to viewport height (bottom, right)', function() {
var el = fixture('sized-x');
el.classList.add('positioned-bottom');
el.classList.add('positioned-right');
el.classList.add('with-margin')
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= window.innerHeight - 100 - 20 * 2, 'height is less than or equal to viewport height');
});
test('scrolling sizingTarget is constrained to viewport height', function() {
el = fixture('sectioned');
var internal = Polymer.dom(el).querySelector('.internal');
el.sizingTarget = internal;
makeScrolling(internal);
el.refit();
var rect = el.getBoundingClientRect();
assert.isTrue(rect.height <= window.innerHeight, 'height is less than or equal to viewport height');
});
});
suite('fit to element', function() {
test('element fits in another element', function() {
var constrain = fixture('constrain-target');
var el = Polymer.dom(constrain).querySelector('.el')
makeScrolling(el);
el.fitInto = constrain;
el.refit();
var rect = el.getBoundingClientRect();
var crect = constrain.getBoundingClientRect();
assert.isTrue(rect.height <= crect.height, 'width is less than or equal to fitInto width');
assert.isTrue(rect.height <= crect.height, 'height is less than or equal to fitInto height');
});
test('element centers in another element', function() {
var constrain = fixture('constrain-target');
var el = Polymer.dom(constrain).querySelector('.el')
makeScrolling(el);
el.fitInto = constrain;
el.refit();
var rect = el.getBoundingClientRect();
var crect = constrain.getBoundingClientRect();
assert.closeTo(rect.left - crect.left - (crect.right - rect.right), 0, 5, 'centered horizontally in fitInto');
assert.closeTo(rect.top - crect.top - (crect.bottom - rect.bottom), 0, 5, 'centered vertically in fitInto');
});
test('element with max-width centers in another element', function() {
var constrain = fixture('with-max-width');
var el = Polymer.dom(constrain).querySelector('.el');
el.fitInto = constrain;
el.refit();
var rect = el.getBoundingClientRect();
var crect = constrain.getBoundingClientRect();
assert.closeTo(rect.left - crect.left - (crect.right - rect.right), 0, 5, 'centered horizontally in fitInto');
assert.closeTo(rect.top - crect.top - (crect.bottom - rect.bottom), 0, 5, 'centered vertically in fitInto');
});
});
</script>
</body>
</html>

View File

@@ -0,0 +1,42 @@
<!--
@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">
<link rel="import" href="../iron-fit-behavior.html">
<dom-module id="test-fit">
<style>
:host {
display: block;
background: black;
color: white;
padding: 8px;
}
</style>
<template>
<content></content>
</template>
</dom-module>
<script>
Polymer({
is: 'test-fit',
behaviors: [
Polymer.IronFitBehavior
]
});
</script>