Skip to content

Instantly share code, notes, and snippets.

@reefki
Created August 28, 2017 20:00
Show Gist options
  • Save reefki/469b31fb043dc20e56cf65f97b9a0413 to your computer and use it in GitHub Desktop.
Save reefki/469b31fb043dc20e56cf65f97b9a0413 to your computer and use it in GitHub Desktop.
/**
* Tailor.Components.ResponsiveEmbed
*
* A lightbox component.
*
* @class
*/
var $ = window.jQuery,
Components = window.Tailor.Components,
ResponsiveEmbed;
ResponsiveEmbed = Components.create( {
getDefaults: function() {
return {
className: 'tailor-responsive-embed',
};
},
/**
* Initializes the component.
*/
onInitialize: function() {
if (! this.el.getAttribute('width') && ! this.el.getAttribute('height')) {
return;
}
let wrapper = $('<div />', {
class: this.options.className,
css: {
paddingBottom: (parseInt(this.el.getAttribute('height')) / parseInt(this.el.getAttribute('width'))) * 100 + '%'
}
});
this.$el.wrap(wrapper);
},
/**
* Fired once the component destroyed.
*/
onDestroy: function () {
this.$el.unwrap();
}
} );
/**
* Responsive Embed jQuery plugin.
*
* @since 1.0.0
*
* @param options
* @param callbacks
* @returns {*}
*/
$.fn.tailorResponsiveEmbed = function( options, callbacks ) {
return this.each( function() {
var instance = $.data( this, 'tailorResponsiveEmbed' );
if ( ! instance ) {
$.data( this, 'tailorResponsiveEmbed', new ResponsiveEmbed( this, options, callbacks ) );
}
} );
};
module.exports = ResponsiveEmbed;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment