Skip to content

Commit 5c0a36f

Browse files
committed
Updated external media layouts, too keep its ratio and enlarge to 100% width
1 parent 49c7dde commit 5c0a36f

2 files changed

Lines changed: 62 additions & 19 deletions

File tree

public/css/extra.css

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,43 @@
55
position: relative;
66
cursor: pointer;
77
display: table;
8-
max-width: 540px;
8+
width: 100%;
99
text-align: center;
1010
background-position: center center;
1111
background-repeat: no-repeat;
1212
background-size: contain;
1313
background-color: black;
14+
overflow: hidden;
15+
}
16+
/* youtube always use 16:9 aspect ratio video */
17+
.youtube {
18+
position: relative;
19+
width: 100%;
20+
padding-bottom: 56.25%;
21+
}
22+
.vimeo img {
23+
width: 100%;
24+
object-fit: contain;
25+
z-index: 0;
1426
}
15-
.vimeo img,
1627
.youtube img {
28+
width: 100%;
29+
height: 100%;
30+
object-fit: cover;
1731
position: absolute;
18-
margin: auto;
1932
top: 0;
2033
left: 0;
21-
right: 0;
22-
bottom: 0;
34+
z-index: 0;
35+
}
36+
.vimeo iframe,
37+
.youtube iframe {
38+
position: absolute;
39+
top: 0;
40+
left: 0;
41+
width: 100%;
42+
height: 100%;
43+
vertical-align: middle;
44+
z-index: 1;
2345
}
2446
.vimeo .icon,
2547
.youtube .icon {
@@ -34,13 +56,31 @@
3456
opacity: 0.3;
3557
-webkit-transition: opacity 0.2s; /* Safari */
3658
transition: opacity 0.2s;
59+
z-index: 0;
3760
}
3861
.vimeo:hover .icon,
3962
.youtube:hover .icon {
4063
opacity: 0.6;
4164
-webkit-transition: opacity 0.2s; /* Safari */
4265
transition: opacity 0.2s;
4366
}
67+
68+
.slideshare .inner,
69+
.speakerdeck .inner {
70+
position: relative;
71+
width: 100%;
72+
}
73+
.slideshare .inner iframe,
74+
.speakerdeck .inner iframe {
75+
position: absolute;
76+
top: 0;
77+
bottom: 0;
78+
left: 0;
79+
right: 0;
80+
width: 100%;
81+
height: 100%;
82+
}
83+
4484
h1:hover .header-link,
4585
h2:hover .header-link,
4686
h3:hover .header-link,

public/js/extra.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,15 @@ function finishView(view) {
285285
jsonp: 'callback',
286286
dataType: 'jsonp',
287287
success: function (data) {
288-
$(value).html(data.html);
288+
var $html = $(data.html);
289+
var iframe = $html.closest('iframe');
290+
var caption = $html.closest('div');
291+
var inner = $('<div class="inner"></div>').append(iframe);
292+
var height = iframe.attr('height');
293+
var width = iframe.attr('width');
294+
var ratio = (height / width) * 100;
295+
inner.css('padding-bottom', ratio + '%');
296+
$(value).html(inner).append(caption);
289297
}
290298
});
291299
});
@@ -310,8 +318,12 @@ function finishView(view) {
310318
var src = iframe.attr('src');
311319
if (src.indexOf('//') == 0)
312320
iframe.attr('src', 'https:' + src);
313-
iframe.css('max-width', '100%');
314-
iframe.attr('width', '540').attr('height', (540 * ratio) + 15);
321+
var inner = $('<div class="inner"></div>').append(iframe);
322+
var height = iframe.attr('height');
323+
var width = iframe.attr('width');
324+
var ratio = (height / width) * 100;
325+
inner.css('padding-bottom', ratio + '%');
326+
$(value).html(inner);
315327
}
316328
});
317329
});
@@ -517,19 +529,12 @@ function smoothHashScroll() {
517529
}
518530
}
519531

520-
function setSizebyAttr(element, target) {
521-
var width = $(element).attr("width") ? $(element).attr("width") : '100%';
522-
var height = $(element).attr("height") ? $(element).attr("height") : '360px';
523-
$(target).width(width);
524-
$(target).height(height);
525-
}
526-
527532
function imgPlayiframe(element, src) {
528533
if (!$(element).attr("videoid")) return;
529534
var iframe = $("<iframe frameborder='0' webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>");
530535
$(iframe).attr("src", src + $(element).attr("videoid") + '?autoplay=1');
531-
setSizebyAttr(element, iframe);
532-
$(element).html(iframe);
536+
$(element).find('img').css('visibility', 'hidden');
537+
$(element).append(iframe);
533538
}
534539

535540
var anchorForId = function (id) {
@@ -720,7 +725,6 @@ var youtubePlugin = new Plugin(
720725
var videoid = match[1];
721726
if (!videoid) return;
722727
var div = $('<div class="youtube raw"></div>');
723-
setSizebyAttr(div, div);
724728
div.attr('videoid', videoid);
725729
var thumbnail_src = '//img.youtube.com/vi/' + videoid + '/hqdefault.jpg';
726730
var image = '<img src="' + thumbnail_src + '" />';
@@ -740,7 +744,6 @@ var vimeoPlugin = new Plugin(
740744
var videoid = match[1];
741745
if (!videoid) return;
742746
var div = $('<div class="vimeo raw"></div>');
743-
setSizebyAttr(div, div);
744747
div.attr('videoid', videoid);
745748
var icon = '<i class="icon fa fa-vimeo-square fa-5x"></i>';
746749
div.append(icon);

0 commit comments

Comments
 (0)