Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0 preview #64

Merged
merged 27 commits into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
bdf3c06
port to 2.0
valdrinkoshi Aug 23, 2016
fe97120
use demo-pages-shared-styles (reverted)
valdrinkoshi Aug 23, 2016
7eb786e
custom-elements-v1
valdrinkoshi Aug 31, 2016
af5bdc9
use new custom-style syntax
valdrinkoshi Sep 7, 2016
f9fbeb6
use dom-bind and dom-repeat
valdrinkoshi Sep 7, 2016
bcb844e
update deps
valdrinkoshi Sep 12, 2016
0d00d54
resolve webcomponents v1, remove <content>
valdrinkoshi Dec 1, 2016
a4959ac
variants
valdrinkoshi Dec 1, 2016
784ce23
script inside dom-module, remove <content>
valdrinkoshi Dec 1, 2016
b83af61
use wc-ce flag instead of wc-register
valdrinkoshi Dec 3, 2016
df7ebf9
update deps and resolutions
valdrinkoshi Dec 10, 2016
b4051d5
Depend on test-fixture v2
tedium-bot Jan 12, 2017
e033ec7
auto-generated: update repo for v2
tedium-bot Jan 25, 2017
550b57c
remove duplicate scripts
valdrinkoshi Feb 7, 2017
9fe3865
fix safari9 tests
valdrinkoshi Feb 9, 2017
aa839d9
update deps
valdrinkoshi Mar 1, 2017
26cd438
Point to Polymer 2.0 RC 1
tedium-bot Mar 7, 2017
57b155a
address feedback
valdrinkoshi Apr 6, 2017
2ffd97d
remove test-fixture dependency
valdrinkoshi Apr 6, 2017
d02accd
Fix demo for tap not being fired. Defer refit.
valdrinkoshi Apr 6, 2017
ab5d81b
revert comment indentation
valdrinkoshi Apr 6, 2017
4f5ce28
Update travis config
tedium-bot Apr 7, 2017
f0cc90b
flush and explain why
valdrinkoshi Apr 13, 2017
f01313a
remove workaround for Polymer/polymer#4509. Clearer comment of why flush
valdrinkoshi Apr 14, 2017
908f24a
[skip ci] update README
valdrinkoshi Apr 18, 2017
d0e1543
Update travis config
valdrinkoshi May 12, 2017
db3cbf5
fix rebase errors
valdrinkoshi May 12, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bower_components
bower_components*
bower-*.json
16 changes: 9 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
language: node_js
sudo: required
before_script:
- npm install -g bower polylint web-component-tester
- bower install
- polylint
- npm install -g polymer-cli
- polymer install --variants
env:
global:
- secure: >-
L4lSnuQZDY+YcXYzBZSRKjJJ1rZf18Lc/8YDgQPfkMkAItrRHGR8vblBoKiPAmtvgNxztcpZxAXTiDy1vAeVv54QnX9b1JsuOs7rrQxB4BS04Dj7LdT6DDu1p/V09MJBN11lzLVxgpxljbumwGWE4gfpDl2+rjbBt7cRV5VkVnE=
- secure: >-
H7dHZ9FQvJszK2UMNZJiZmzOPET3muO/XvlkUc1x3KcUlV5/tD/404V05XfFMowH7DavHFYleZkb89deYjq9PHncO9c4bp4SHD7HKN4FaGyhzfpXjg66v3dZH/OcERjaas337uUE2jo/x1jCq4HJCz2bMVh+bvd4du1C/2OWarc=
node_js: '6'
node_js: stable
addons:
firefox: latest
apt:
sources:
- google-chrome
packages:
- google-chrome-stable
sauce_connect: true
script:
- xvfb-run wct
- 'if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then wct -s ''default''; fi'
dist: trusty
- xvfb-run polymer test
- >-
if [ "${TRAVIS_PULL_REQUEST}" = "false" ]; then polymer test -s 'default';
fi
dist: trusty
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@

<!---
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

`Polymer.IronFitBehavior` fits an element in another element using `max-height` and `max-width`, and
optionally centers it in the window or another element.
Expand Down
26 changes: 19 additions & 7 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "iron-fit-behavior",
"version": "1.2.6",
"version": "2.0.0",
"license": "http://polymer.github.io/LICENSE.txt",
"description": "Fits an element inside another element",
"private": true,
Expand All @@ -18,14 +18,26 @@
"url": "git://github.com/PolymerElements/iron-fit-behavior.git"
},
"dependencies": {
"polymer": "Polymer/polymer#^1.1.0"
"polymer": "Polymer/polymer#^2.0.0-rc.1"
},
"devDependencies": {
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.0.0",
"test-fixture": "PolymerElements/test-fixture#^1.0.0",
"web-component-tester": "^4.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
"iron-component-page": "PolymerElements/iron-component-page#2.0-preview",
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#2.0-preview",
"web-component-tester": "Polymer/web-component-tester#^6.0.0-prerelease.6",
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0-rc.1"
},
"variants": {
"1.x": {
"dependencies": {
"polymer": "Polymer/polymer#^1.0.0"
},
"devDependencies": {
"iron-component-page": "PolymerElements/iron-component-page#^1.0.0",
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^1.0.0",
"web-component-tester": "^4.0.0",
"webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0"
}
}
},
"ignore": []
}
59 changes: 33 additions & 26 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@
<link rel="import" href="../../iron-demo-helpers/demo-snippet.html">
<link rel="import" href="../../iron-demo-helpers/demo-pages-shared-styles.html">

<style is="custom-style" include="demo-pages-shared-styles">
<custom-style><style is="custom-style" include="demo-pages-shared-styles">
.centered {
min-width: 500px;
min-width: 600px;
}
demo-snippet {
--demo-snippet-code: {
max-height: 250px;
}
}
</style>
</style></custom-style>

</head>

Expand All @@ -50,9 +50,9 @@ <h3>
display: inline-block;
box-sizing: border-box;
border: 1px solid;
width: 100px;
padding: 20px 0;
margin: 5px;
width: 120px;
padding: 26px 0;
margin: 8px;
}

#myFit {
Expand All @@ -68,12 +68,11 @@ <h3>
border-radius: 5px;
border-width: 1px;
}

button.selected {
background-color: #b3e5fc;
}
</style>
<template is="dom-bind">
<dom-bind><template is="dom-bind">
<template is="dom-repeat" items="[[containers]]">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this dom-repeat require a wrapper? I know that you don't need them within a dom-module's template but I can't remember if they're necessary in another dom-*'s template like this one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the demo's working so this one must not require a wrapper.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, Kevin says that template extensions don't need wrappers if they're nested in a template that's being managed by Polymer in some way (i.e. the template for a dom-module or anywhere in the dom-* elements`).

<div class="target" on-tap="updatePositionTarget">Target</div>
</template>
Expand All @@ -95,27 +94,18 @@ <h2>Align</h2>
<button on-tap="toggleDynamicAlign">dynamic align</button>
</simple-fit>
<script>
var defaultTarget = Polymer.dom(myFit).parentNode;

var template = document.querySelector('template[is="dom-bind"]');

template.containers = new Array(30);

template.updatePositionTarget = function(e) {
var target = Polymer.dom(e).rootTarget;
target = myFit.positionTarget === target ? defaultTarget : target;
target = myFit.positionTarget === target ? myFit._defaultPositionTarget : target;
myFit.positionTarget.style.backgroundColor = '';
target.style.backgroundColor = 'orange';
myFit.positionTarget = target;
template.refit();
};

template._raf = null;
template.refit = function() {
template._raf && window.cancelAnimationFrame(template._raf);
template._raf = window.requestAnimationFrame(function() {
template._raf = null;
myFit.refit();
});
refit();
};

template.updateAlign = function(e) {
Expand All @@ -134,30 +124,47 @@ <h2>Align</h2>
toggleClass(children[i], 'selected', children[i] === target);
}
}
template.refit();
refit();
};

template.toggleNoOverlap = function(e) {
myFit.noOverlap = !myFit.noOverlap;
toggleClass(Polymer.dom(e).rootTarget, 'selected', myFit.noOverlap);
template.refit();
refit();
};

template.toggleDynamicAlign = function(e) {
myFit.dynamicAlign = !myFit.dynamicAlign;
toggleClass(Polymer.dom(e).rootTarget, 'selected', myFit.dynamicAlign);
template.refit();
refit();
};

// Support hybrid mode
var templatev1 = document.querySelector('dom-bind');
templatev1.containers = template.containers;
templatev1.updatePositionTarget = template.updatePositionTarget;
templatev1.updateAlign = template.updateAlign;
templatev1.toggleNoOverlap = template.toggleNoOverlap;
templatev1.toggleDynamicAlign = template.toggleDynamicAlign;

// Listen for resize and scroll on window.
window.addEventListener('resize', template.refit);
window.addEventListener('scroll', template.refit);
window.addEventListener('resize', refit);
window.addEventListener('scroll', refit);

var _raf = null;
function refit() {
_raf && window.cancelAnimationFrame(_raf);
_raf = window.requestAnimationFrame(function() {
_raf = null;
myFit.refit();
});
}

function toggleClass(element, cssClass, condition) {
element.classList[condition ? 'add' : 'remove'](cssClass);
}
</script>
</template>
</template></dom-bind>
</template>
</demo-snippet>

Expand Down
26 changes: 9 additions & 17 deletions demo/simple-fit.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@
text-align: center;
}
</style>

<content></content>
<slot></slot>
</template>

<script>
Polymer({
is: 'simple-fit',
behaviors: [
Polymer.IronFitBehavior
]
});
</script>
</dom-module>

<script>

Polymer({

is: 'simple-fit',

behaviors: [
Polymer.IronFitBehavior
]

});

</script>
21 changes: 16 additions & 5 deletions iron-fit-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,29 @@
if (typeof this._isRTL === 'undefined') {
this._isRTL = window.getComputedStyle(this).direction == 'rtl';
}

this.positionTarget = this.positionTarget || this._defaultPositionTarget;
if (this.autoFitOnAttach) {
if (window.getComputedStyle(this).display === 'none') {
setTimeout(function() {
this.fit();
}.bind(this));
} else {
// NOTE: shadydom applies distribution asynchronously
// for performance reasons webcomponents/shadydom#120
// Flush to get correct layout info.
window.ShadyDOM && ShadyDOM.flush();
this.fit();
}
}
},

detached: function() {
if (this.__deferredFit) {
clearTimeout(this.__deferredFit);
this.__deferredFit = null;
}
},

/**
* Positions and fits the element into the `fitInto` element.
*/
Expand Down Expand Up @@ -378,7 +388,8 @@
height: rect.height + margin.top + margin.bottom
};

var position = this.__getPosition(this._localeHorizontalAlign, this.verticalAlign, size, positionRect, fitRect);
var position = this.__getPosition(this._localeHorizontalAlign, this.verticalAlign, size, positionRect,
fitRect);

var left = position.left + margin.left;
var top = position.top + margin.top;
Expand Down Expand Up @@ -573,15 +584,15 @@
// For dynamicAlign and noOverlap we'll have more than one candidate, so
// we'll have to check the croppedArea to make the best choice.
if (!this.dynamicAlign && !this.noOverlap &&
pos.verticalAlign === vAlign && pos.horizontalAlign === hAlign) {
pos.verticalAlign === vAlign && pos.horizontalAlign === hAlign) {
position = pos;
break;
}

// Align is ok if alignment preferences are respected. If no preferences,
// it is considered ok.
var alignOk = (!vAlign || pos.verticalAlign === vAlign) &&
(!hAlign || pos.horizontalAlign === hAlign);
(!hAlign || pos.horizontalAlign === hAlign);

// Filter out elements that don't match the alignment (if defined).
// With dynamicAlign, we need to consider all the positions to find the
Expand Down Expand Up @@ -609,4 +620,4 @@
}

};
</script>
</script>
6 changes: 3 additions & 3 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@

<script>
WCT.loadSuites([
'iron-fit-behavior.html',
'iron-fit-behavior.html?dom=shadow'
'iron-fit-behavior.html?wc-shadydom=true&wc-ce=true', //shady
'iron-fit-behavior.html?dom=shadow' //shadow
]);
</script>



</body></html>
26 changes: 9 additions & 17 deletions test/test-fit.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,14 @@
padding: 8px;
}
</style>

<content></content>
<slot></slot>
</template>

<script>
Polymer({
is: 'test-fit',
behaviors: [
Polymer.IronFitBehavior
]
});
</script>
</dom-module>

<script>

Polymer({

is: 'test-fit',

behaviors: [
Polymer.IronFitBehavior
]

});

</script>