-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaspectRatioKeeper.jquery.js
More file actions
60 lines (51 loc) · 1.47 KB
/
aspectRatioKeeper.jquery.js
File metadata and controls
60 lines (51 loc) · 1.47 KB
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
/* ====================================================
* jQuery Aspect Ratio Keeper.
* https://github.com/frontid/jQueryAspectRatioKeeper
* Marcelo Iván Tosco (capynet)
* ==================================================== */
!function ($) {
'use strict'
var plugin
var Class = function (el, options) {
plugin = this
this.$el = $(el)
var defaults = {
wrapperName: 'tag-ark'
}
this.options = $.extend(defaults, options)
init()
return this
}
// SECCIÓN DE MÉTODOS PRIVADOS
//-----------------------------------------------------------
function init () {
var width = plugin.$el.width()
var height = plugin.$el.height()
var $wrapper = $('<div class="'+plugin.options.wrapperName+'">')
$wrapper.css({
position: 'relative',
height: 0,
paddingTop: ((height / width) * 100) + '%',
})
plugin.$el.css({
position: 'absolute',
top: '0',
left: '0',
width: '100%',
height: '100%'
});
// El tag tambien necesita su CSS pero ya lo he puesto en _media.scss
plugin.$el.wrap($wrapper)
}
// DEFINICIÓN DEL PLUGIN
//-----------------------------------------------------------
$.fn.aspectRatioKeeper = function (options) {
return this.each(function () {
var $element = $(this)
var data = $element.data('aspectRatioKeeper')
if (!data) {
$element.data('aspectRatioKeeper', (new Class(this, options)))
}
})
}
}(window.jQuery);