-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.responsinatr.js
56 lines (40 loc) · 1.61 KB
/
jquery.responsinatr.js
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
/*
* jQuery Responsinatr 0.0.3
* Copyright 2016 JoomlaTemplat.es
* GNU General Public License version 3; see LICENSE.txt
* http://joomlatemplat.es/
*/
(function ($)
{
$.fn.responsinatr = function(options) {
// Default options
var settings = $.extend({
target: 'iframe',
wrapperClass: 'responsinatr'
}, options );
$(window).on('load', function() {
$(settings.target).each(function() {
// Wrap each iframe
$(this).wrap(
'<div class="' + settings.wrapperClass + '"></div>'
);
console.log('wrapper class added!');
});
});
$(window).on('load resize', function() {
$(settings.target).each(function() {
// Calculate old and new width/height values
var $oldHeight = $(settings.target).attr('height'); // Get iframe's height
var $oldWidth = $(settings.target).attr('width'); // Get iframe's width
var $newWidth = $(settings.target).parent().width(); // Get wrapper's width
var $newHeight = ($oldHeight / $oldWidth) * $newWidth; // Calculate new height
// Apply new width/height values keeping aspect ratio
$('.' + settings.wrapperClass).find('iframe').css({
"height" : $newHeight + "px",
"width" : $newWidth + "px"
});
console.log('height/width values added!');
});
});
};
}(jQuery));