Created
May 5, 2021 08:07
-
-
Save vasilii-b/7b94bec7505ba4eabf05e7a9b80a36ee to your computer and use it in GitHub Desktop.
Magento 2 Widget: Collapsible until breakpint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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