Skip to content

Instantly share code, notes, and snippets.

@vasilii-b
Created May 5, 2021 08:07
Show Gist options
  • Save vasilii-b/7b94bec7505ba4eabf05e7a9b80a36ee to your computer and use it in GitHub Desktop.
Save vasilii-b/7b94bec7505ba4eabf05e7a9b80a36ee to your computer and use it in GitHub Desktop.
Magento 2 Widget: Collapsible until breakpint
define([
'jquery',
'matchMedia',
'mage/collapsible'
], function($, mediaCheck) {
'use strict';
$.widget('collapsibleUntilBreakpoint', {
options: {
breakpoint: 768,
},
collapsibleInitialized: false,
_create: function () {
mediaCheck({
media: '(max-width: ' + this.options.breakpoint + 'px',
entry: $.proxy(function () {
this._initCollapsible();
}, this),
exit: $.proxy(function () {
this._stopCollapsible();
}, this)
})
},
_initCollapsible: function () {
this.collapsibleInitialized = true;
this.element.collapsible();
},
_stopCollapsible: function () {
if (!this.collapsibleInitialized) {
return;
}
this.element.collapsible('activate');
this.element.data('mageCollapsible').destroy();
this.element.find('[data-role=content]').attr('style', '');
this.collapsibleInitialized = false;
}
});
return $.collapsibleUntilBreakpoint;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment