-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathresponsive-embed.html
executable file
·135 lines (113 loc) · 2.68 KB
/
responsive-embed.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<link rel="import" href="../polymer/polymer.html">
<!--
An element for responsive embeds.
Add YouTube, Vimeo and other multimedia content to your pages, letting the browser calculate the height based on the width of their containing block. You just have to define the aspect ratio of the media.
It works for <code><iframe></code>, <code><object></code> and <code><embed></code> tags.
Example:
<responsive-embed>
<iframe src="https://www.youtube.com/embed/fCLMI5TCcqg" frameborder="0" allowfullscreen></iframe>
</responsive-embed>
@demo
-->
<dom-module id="responsive-embed">
<style>
:host {
position: relative;
display: block;
height: 0;
padding: 0;
overflow: hidden;
}
:host(.v16-9) {
padding-bottom: 56.25%;
}
:host(.v21-9) {
padding-bottom: 42.85714%;
}
:host(.v4-3) {
padding-bottom: 75%;
}
:host(.v1-1) {
padding-bottom: 100%;
}
polyfill-next-selector {
content: 'iframe, embed, object';
}
::content iframe,
::content embed,
::content object {
position: absolute;
top: 0;
bottom: 0;
left: 0;
width: 100%;
height: 100%;
border: 0;
}
</style>
<template>
<content select="iframe"></content>
<content select="embed"></content>
<content select="object"></content>
</template>
</dom-module>
<script>
Polymer({
is: 'responsive-embed',
properties: {
/**
* Aspect ratio of the internal content. Options: `1:1,4:3,16:9,21:9`
*
* @type String
*/
ratio: {
type: String,
value: function(){
return "16:9";
}
},
},
ready: function() {
switch (this.ratio) {
case "16:9":
this.classList.add("v16-9");
break;
case "21:9":
this.classList.add("v21-9");
break;
case "4:3":
this.classList.add("v4-3");
break;
case "1:1":
this.classList.add("v1-1");
break;
default:
this.classList.add("v16-9");
}
},
/*
* Defines the aspect ratio of a compnent.
*
* @param {string} ratio.
*/
changeRatio: function(ratio) {
this.className = "";
switch (ratio) {
case "16:9":
this.classList.add("v16-9");
break;
case "21:9":
this.classList.add("v21-9");
break;
case "4:3":
this.classList.add("v4-3");
break;
case "1:1":
this.classList.add("v1-1");
break;
default:
this.classList.add("v16-9");
}
}
});
</script>