Component-Builder/admin/custom/uikit-v2/js/core/cover.js

88 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-04-22 13:31:39 +00:00
/*! UIkit 2.27.5 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
2016-01-30 20:28:43 +00:00
(function(UI){
"use strict";
UI.component('cover', {
defaults: {
automute : true
},
boot: function() {
// auto init
UI.ready(function(context) {
2017-11-12 00:33:10 +00:00
UI.$('[data-uk-cover]', context).each(function(){
2016-01-30 20:28:43 +00:00
var ele = UI.$(this);
2017-11-12 00:33:10 +00:00
if(!ele.data('cover')) {
var plugin = UI.cover(ele, UI.Utils.options(ele.attr('data-uk-cover')));
2016-01-30 20:28:43 +00:00
}
});
});
},
init: function() {
this.parent = this.element.parent();
UI.$win.on('load resize orientationchange', UI.Utils.debounce(function(){
this.check();
}.bind(this), 100));
2017-11-12 00:33:10 +00:00
this.on('display.uk.check', function(e) {
if (this.element.is(':visible')) this.check();
2016-01-30 20:28:43 +00:00
}.bind(this));
this.check();
if (this.element.is('iframe') && this.options.automute) {
var src = this.element.attr('src');
this.element.attr('src', '').on('load', function(){
this.contentWindow.postMessage('{ "event": "command", "func": "mute", "method":"setVolume", "value":0}', '*');
}).attr('src', [src, (src.indexOf('?') > -1 ? '&':'?'), 'enablejsapi=1&api=1'].join(''));
}
},
check: function() {
2017-11-12 00:33:10 +00:00
this.element.css({ width : '', height : '' });
2016-01-30 20:28:43 +00:00
this.dimension = {w: this.element.width(), h: this.element.height()};
if (this.element.attr('width') && !isNaN(this.element.attr('width'))) {
this.dimension.w = this.element.attr('width');
}
if (this.element.attr('height') && !isNaN(this.element.attr('height'))) {
this.dimension.h = this.element.attr('height');
}
2017-11-12 00:33:10 +00:00
this.ratio = this.dimension.w / this.dimension.h;
2016-01-30 20:28:43 +00:00
var w = this.parent.width(), h = this.parent.height(), width, height;
// if element height < parent height (gap underneath)
if ((w / this.ratio) < h) {
width = Math.ceil(h * this.ratio);
height = h;
// element width < parent width (gap to right)
} else {
width = w;
height = Math.ceil(w / this.ratio);
}
2017-11-12 00:33:10 +00:00
this.element.css({ width : width, height : height });
2016-01-30 20:28:43 +00:00
}
});
2017-11-12 00:33:10 +00:00
})(UIkit2);