Skip to content

Instantly share code, notes, and snippets.

@lizkaraffa
Created January 30, 2018 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lizkaraffa/e063c080f4f0a276854c5c09a43ef40a to your computer and use it in GitHub Desktop.
Save lizkaraffa/e063c080f4f0a276854c5c09a43ef40a to your computer and use it in GitHub Desktop.
/**
* HB Niagara Ryla-WP Child Theme - v0.1.0 - 2018-01-30
* https://zao.is
*
* Copyright (c) 2018;
* Licensed GPLv2+
*/
window.HNC = window.HNC || {};
( function( window, document, $, app, rwp, undefined ) {
'use strict';
var bp = rwp.breakpoint;
var submitted = false;
app.cache = function() {
app.$ = {};
app.$.body = $( document.body );
app.$.search = $( '.top-nav-wrapper .searchform' );
app.$.button = app.$.search.find( 'button' );
app.$.input = app.$.search.find( 'input' );
app.$.cartIcon = $( '.icon-basket' );
app.$.menuCart = $( '.menu-cart' );
};
app.toggleSearch = function() {
if ( ! app.$.input.is( ':visible' ) ) {
app.$.input.show().focus();
return false;
}
submitted = true;
return true;
};
app.toggleRegionCookie = function() {
app.toggleRegion( $( this ).hasClass( 'usa-pricing-toggle' ) );
};
app.toggleRegion = function( isUSA ) {
if ( ! app.usd ) {
return;
}
if ( isUSA ) {
setUserSetting( 'use_USA', 1 );
app.$.body.removeClass( 'is-can-pricing' ).addClass( 'is-usa-pricing' );
} else {
deleteUserSetting( 'use_USA' );
app.$.body.removeClass( 'is-usa-pricing' ).addClass( 'is-can-pricing' );
}
};
app.setRegionClass = function() {
app.toggleRegion( getUserSetting( 'use_USA' ) );
};
app.changeCartColor = function() {
app.$.menuCart.addClass( 'cta' );
if ( app.$.cartIcon ) {
app.$.menuCart.removeClass( 'cta' );
}
};
app.init = function() {
app.cache();
app.setRegionClass();
app.changeCartColor();
app.$.body
.on( 'click submit', '.top-nav-wrapper .searchform button', app.toggleSearch )
.on( 'click', '.price-region-toggle button', app.toggleRegionCookie );
app.$.input.on( 'focusout', function() {
setTimeout( function() {
if ( ! submitted ) {
app.$.input.hide();
}
}, 200 /* Wait to see if we are trying to submit the form. */ );
});
};
$( app.init );
}( window, document, jQuery, window.HNC, window.rylaWP ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment