global.js
8.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
require.config({
"baseUrl": "/wp-content/themes/commonwell-corp/js/",
"paths": {
"jquery": "../components/jquery/jquery.min",
"hoverIntent" : "../components/superfish/dist/js/hoverIntent",
"superfish": "../components/superfish/dist/js/superfish.min",
"fittext": "vendor/jquery.fittext",
"superclick": "vendor/superclick",
"featherlight": "vendor/featherlight.min"
},
"shim": {
jquery: {
exports: 'jquery'
},
hoverIntent: {
deps: ['jquery']
},
superfish: {
deps: ['jquery']
},
fittext: {
deps: ['jquery']
},
superclick: {
deps: ['jquery']
},
featherlight: {
deps: ['jquery']
}
}
});
require(['jquery', 'src/menu', 'fittext', 'src/sizing', 'src/care_form', 'src/facebook_extensible', 'src/canada-post'], function ($, Menu) {
$.fn.extend({
limiter: function (max, counter) {
$(this).on("keyup focus", function () {
var self = this;
var words = (self.value.length > 0) ? ($.trim(self.value).replace(/['";:,.?¿\-!¡]+/g, '').match(/\S+/g)).length : 0;
if (typeof(counter) != 'undefined') {
counter.html(max - words);
}
});
}
});
function noscroll(event) {
event.preventDefault();
}
var App = {
menu: null,
init: function () {
this.menu = new Menu($('#primary-nav'));
this.menu.setup();
$("#area").limiter(250, $("#chars"));
$('.mobile-menu-btn').on('click', function (event) {
event.preventDefault();
$('body').toggleClass('menu-on');
console.log('menu on');
// lock scrolling when nav is open
// if ($('body').hasClass('menu-on')) {
// $(document).on('touchmove', noscroll);
// } else {
// $(document).off('touchmove', noscroll);
// }
return false;
});
// Change --- word to please select one
$('form .form-control').find('select[name="community"] option').eq(0).html('Please select one');
$('form .form-control').find('select[name="referral"] option').eq(0).html('Please select one');
}
};
$(document).ready(function() {
App.init();
// we should use RAF for smooth moving
window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.oRequestAnimationFrame;
function createMapCloseBtn() {
var $map = $('#map');
$map.hide();
// inject the close button
$map.append('<a href="#" class="close-map"></a>');
// hide the map when its clicked
$map.find('.close-map').on('click', function (event) {
event.preventDefault();
$map.hide();
return false;
});
// show the map when markers are clicked on
$('#sl_div').find('.marker').on('click', function () {
$map.show();
});
}
function setMapStart() {
// are we mobile?
var mobile = (window.innerWidth < 960);
// different lefts for different screens
var mapLeft = mobile ? '53px' : '8px';
// when should the map stop moving up?
var minTop = $('#other-header').outerHeight() + $('#primary-nav').outerHeight() + 40;
if(window.isBrokerPage) {
minTop = (mobile) ? 50 : 0;
}
var is_safari = navigator.userAgent.search("Safari") >= 0 && navigator.userAgent.search("Chrome") < 0;
//if(is_safari) {
var smallMobile = (window.innerWidth < 600);
var mapWidth = smallMobile ? 0 : $('#map').outerWidth() + 8;
$('#map').css({
top: minTop,
left: mapLeft,
opacity: 1,
zIndex: 1,
marginLeft: -mapWidth
});
$(window).resize(function() {
var smallMobile = (window.innerWidth < 600);
var mapWidth = smallMobile ? 0 : $('#map').outerWidth() + 8;
var mapLeft = smallMobile ? '53px' : '8px';
$('#map').css({
left: mapLeft,
marginLeft: -mapWidth
});
}).resize();
//} else {
// // if the screen is mobile, and we havent injected the button
// $('#map').css({
// top: minTop,
// left: mapLeft,
// opacity: 1,
// zIndex: 1
// });
//}
if ($('.close-map').length === 0) {
createMapCloseBtn();
}
}
// scroller function to move the map
function moveMap() {
var mobile = (window.innerWidth < 960);
var pos = (mobile) ? $(document).scrollTop() + 200 : $(document).scrollTop();
var minTop = $('#other-header').outerHeight() + $('#primary-nav').outerHeight() + 20;
if(window.isBrokerPage) {
minTop = 0;
pos = (mobile) ? $(document).scrollTop() + 50 : $(document).scrollTop();
}
if (pos > minTop) {
$('#map').css('top', pos);
// call this function with RAF
requestAnimationFrame(moveMap);
} else {
$('#map').css('top', minTop);
}
}
// use a dom ready function for these events
$(function () {
var searchCat = $('#sl_div').find('#cat').attr('textvalue');
if(searchCat && searchCat != 'broker') {
$('#div_nameSearch #nameSearch').attr('placeholder', 'Company Name');
}
// when the search is clicked
// and if the screensize is correct
// move the map under the nav on the left side
$('#addressSubmit').on('click', function () {
// timeout for the delayed map loading
setTimeout(function () {
setMapStart();
}, 1000);
// feebback to let people know that the form is actually working
//$('#address_search').append('<p id="searching-feedback">Searching...</p>');
$(this).attr('value', 'Searching...');
});
// used to avoid multiple listeners
var scrollListener = false;
// this event is trigger whenever the map is updated according to
// the slp.js file in the store-locator-le plugin
$('#map_sidebar').on('contentchanged', function () {
//$('#searching-feedback').remove();
$('#addressSubmit').attr('value', 'Search');
setMapStart();
if (!scrollListener) {
$(window).scroll(function () {
requestAnimationFrame(moveMap);
});
scrollListener = true;
}
// Check if the store has site url
var url = $(this).parent().find('.slp_result_website > a').attr('href');
if(url === undefined) {
$('.results_entry').find('.results_row_top .location_name').css('color', '#706f73');
}
//$(this).parent().find('.results_row_top').click(function() {
// var companyName = $(this).find('.location_name').text();
// var hasURL = $(this).find('.storelocatorlink');
// if(hasURL) {
// ga('send', 'event', 'broker', 'click', companyName);
// }
//});
});
});
});
});