Skip to content

Commit d633770

Browse files
RWD: removed enquire.js and converted to window.matchMedia (#3208)
Co-authored-by: Justin Beaty <[email protected]>
1 parent 15ffca5 commit d633770

File tree

4 files changed

+59
-360
lines changed

4 files changed

+59
-360
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ UPS shut down their old CGI APIs so we removed the support for it from the Mage_
271271

272272
- PHP 8.1 as minimum required version
273273
- Removed scriptaculous/dragdrop.js (#3215)
274-
- RWD theme: updated jQuery to 3.7.0 (#3204)
274+
- RWD theme: updated jQuery to 3.7.0 (#3204), removed enquire.js (#3208)
275275
- Unified CSRF configuration (#3147) and added form key validation to Contacts form (#3146)
276276
- Removed double span element from HTML buttons (#3123)
277277
- Removed all deprecated Mysql4_ classes (#2730). If there are any old modules/extensions in your installation that use such classes, you must run `shell/rename-mysql4-class-to-resource.php` in the command line in order to convert them. Backup all files before running the script

app/design/frontend/rwd/default/layout/page.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242

4343
<!-- Add vendor dependencies -->
4444
<action method="addItem"><type>skin_js</type><name>js/lib/modernizr.custom.min.js</name></action>
45-
<action method="addItem"><type>skin_js</type><name>js/lib/enquire.js</name></action>
4645
<action method="addItem"><type>skin_js</type><name>js/app.js</name></action>
4746
<action method="addItem"><type>skin_js</type><name>js/lib/jquery.cycle2.min.js</name></action>
4847
<action method="addItem"><type>skin_js</type><name>js/lib/jquery.cycle2.swipe.min.js</name></action>

skin/frontend/rwd/default/js/app.js

Lines changed: 58 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -767,47 +767,42 @@ $j(document).ready(function () {
767767

768768
// In order to display the language switcher next to the logo, we are moving the content at different viewports,
769769
// rather than having duplicate markup or changing the design
770-
enquire.register('(max-width: ' + bp.medium + 'px)', {
771-
match: function () {
770+
let repositionLanguageSwitcher = function (mq) {
771+
if (mq.matches) {
772772
$j('.page-header-container .store-language-container').prepend($j('.form-language'));
773-
},
774-
unmatch: function () {
773+
} else {
775774
$j('.header-language-container .store-language-container').prepend($j('.form-language'));
776775
}
777-
});
776+
}
777+
778+
let maxWidthLargeMediaQuery = window.matchMedia('(max-width: ' + bp.large + 'px)');
779+
let maxWidthMediumMediaQuery = window.matchMedia('(max-width: ' + bp.medium + 'px)');
780+
maxWidthMediumMediaQuery.addEventListener('change', repositionLanguageSwitcher);
781+
repositionLanguageSwitcher(maxWidthMediumMediaQuery);
778782

779783
// ==============================================
780-
// Enquire JS
784+
// Menu State
781785
// ==============================================
782786

783-
enquire.register('screen and (min-width: ' + (bp.medium + 1) + 'px)', {
784-
match: function () {
785-
$j('.menu-active').removeClass('menu-active');
786-
$j('.sub-menu-active').removeClass('sub-menu-active');
787-
$j('.skip-active').removeClass('skip-active');
788-
},
789-
unmatch: function () {
790-
$j('.menu-active').removeClass('menu-active');
791-
$j('.sub-menu-active').removeClass('sub-menu-active');
792-
$j('.skip-active').removeClass('skip-active');
793-
}
794-
});
787+
let resetMenuState = function (mq) {
788+
$j('.menu-active').removeClass('menu-active');
789+
$j('.sub-menu-active').removeClass('sub-menu-active');
790+
$j('.skip-active').removeClass('skip-active');
791+
}
792+
maxWidthMediumMediaQuery.addEventListener('change', resetMenuState);
793+
resetMenuState(maxWidthMediumMediaQuery);
795794

796795
// ==============================================
797796
// UI Pattern - Media Switcher
798797
// ==============================================
799798

800799
// Used to swap primary product photo from thumbnails.
801-
802800
var mediaListLinks = $j('.media-list').find('a');
803801
var mediaPrimaryImage = $j('.primary-image').find('img');
804-
805802
if (mediaListLinks.length) {
806803
mediaListLinks.on('click', function (e) {
807804
e.preventDefault();
808-
809805
var self = $j(this);
810-
811806
mediaPrimaryImage.attr('src', self.attr('href'));
812807
});
813808
}
@@ -949,15 +944,15 @@ $j(document).ready(function () {
949944
// (since other blocks can be inserted into left_first), it creates simpler code to move the entire
950945
// .col-left-first block, so that is the approach we're taking
951946
if ($j('.col-left-first > .block').length && $j('div.category-products').length) {
952-
enquire.register('screen and (max-width: ' + bp.medium + 'px)', {
953-
match: function () {
947+
let repositionLayered = function (mq) {
948+
if (mq.matches) {
954949
$j('.col-left-first').insertBefore($j('div.category-products'));
955-
},
956-
unmatch: function () {
957-
// Move layered nav back to left column
950+
} else {
958951
$j('.col-left-first').insertBefore($j('.col-main'));
959952
}
960-
});
953+
}
954+
maxWidthMediumMediaQuery.addEventListener('change', repositionLayered);
955+
repositionLayered(maxWidthMediumMediaQuery);
961956
}
962957

963958
// ==============================================
@@ -966,61 +961,60 @@ $j(document).ready(function () {
966961

967962
// On viewports smaller than 1000px, move the right column into the left column
968963
if ($j('.main-container.col3-layout').length > 0) {
969-
enquire.register('screen and (max-width: 1000px)', {
970-
match: function () {
964+
let reposition3rdColumn = function (mq) {
965+
if (mq.matches) {
971966
var rightColumn = $j('.col-right');
972967
var colWrapper = $j('.col-wrapper');
973-
974968
rightColumn.appendTo(colWrapper);
975-
},
976-
unmatch: function () {
969+
} else {
977970
var rightColumn = $j('.col-right');
978971
var main = $j('.main');
979-
980972
rightColumn.appendTo(main);
981973
}
982-
});
974+
}
975+
let maxWidth1000MediaQuery = window.matchMedia('(max-width: 1000px)');
976+
maxWidth1000MediaQuery.addEventListener('change', reposition3rdColumn);
977+
reposition3rdColumn(maxWidth1000MediaQuery);
983978
}
984979

985-
986980
// ==============================================
987981
// Block collapsing (on smaller viewports)
988982
// ==============================================
989983

990-
enquire.register('(max-width: ' + bp.medium + 'px)', {
991-
setup: function () {
992-
this.toggleElements = $j(
993-
// This selects the menu on the My Account and CMS pages
984+
let toggleElementsForMediumSize = function (mq) {
985+
if (mq.matches) {
986+
$j(
994987
'.col-left-first .block:not(.block-layered-nav) .block-title, ' +
995-
'.col-left-first .block-layered-nav .block-subtitle--filter, ' +
996-
'.sidebar:not(.col-left-first) .block .block-title'
997-
);
998-
},
999-
match: function () {
1000-
this.toggleElements.toggleSingle();
1001-
},
1002-
unmatch: function () {
1003-
this.toggleElements.toggleSingle({destruct: true});
988+
'.col-left-first .block-layered-nav .block-subtitle--filter, ' +
989+
'.sidebar:not(.col-left-first) .block .block-title'
990+
).toggleSingle();
991+
} else {
992+
$j(
993+
'.col-left-first .block:not(.block-layered-nav) .block-title, ' +
994+
'.col-left-first .block-layered-nav .block-subtitle--filter, ' +
995+
'.sidebar:not(.col-left-first) .block .block-title'
996+
).toggleSingle({destruct: true});
1004997
}
1005-
});
1006-
998+
}
999+
maxWidthMediumMediaQuery.addEventListener('change', toggleElementsForMediumSize);
1000+
toggleElementsForMediumSize(maxWidthMediumMediaQuery);
10071001

10081002
// ==============================================
10091003
// OPC - Progress Block
10101004
// ==============================================
10111005

10121006
if ($j('body.checkout-onepage-index').length) {
1013-
enquire.register('(max-width: ' + bp.large + 'px)', {
1014-
match: function () {
1007+
let repositionCheckoutProgress = function (mq) {
1008+
if (mq.matches) {
10151009
$j('#checkout-step-review').prepend($j('#checkout-progress-wrapper'));
1016-
},
1017-
unmatch: function () {
1010+
} else {
10181011
$j('.col-right').prepend($j('#checkout-progress-wrapper'));
10191012
}
1020-
});
1013+
}
1014+
maxWidthLargeMediaQuery.addEventListener('change', repositionCheckoutProgress);
1015+
repositionCheckoutProgress(maxWidthLargeMediaQuery);
10211016
}
10221017

1023-
10241018
// ==============================================
10251019
// Checkout Cart - events
10261020
// ==============================================
@@ -1031,27 +1025,26 @@ $j(document).ready(function () {
10311025
});
10321026
}
10331027

1034-
10351028
// ==============================================
10361029
// Gift Registry Styles
10371030
// ==============================================
10381031

10391032
if ($j('.a-left').length) {
1040-
enquire.register('(max-width: ' + bp.large + 'px)', {
1041-
match: function () {
1033+
repositionGiftRegistry = function (mq) {
1034+
if (mq.matches) {
10421035
$j('.gift-info').each(function() {
1043-
$j(this).next('td').children('textarea').appendTo(this).children();
1036+
$j(this).next('td').children('textarea').appendTo(this).children();
10441037
});
1045-
},
1046-
unmatch: function () {
1038+
} else {
10471039
$j('.left-note').each(function() {
10481040
$j(this).prev('td').children('textarea').appendTo(this).children();
10491041
});
10501042
}
1051-
});
1043+
}
1044+
maxWidthLargeMediaQuery.addEventListener(repositionGiftRegistry);
1045+
repositionGiftRegistry(maxWidthLargeMediaQuery);
10521046
}
10531047

1054-
10551048
// ==============================================
10561049
// Product Listing - Align action buttons/links
10571050
// ==============================================

0 commit comments

Comments
 (0)