1/* --------------------------------------------------------------------- 2Global Js 3Target Browsers: All 4------------------------------------------------------------------------ */ 5 6var RL = (function(RL, $) { 7 8 /** 9 * Doc Ready 10 */ 11 $(function() { 12 RL.listLayout.init(); 13 RL.systemSelector.init(); 14 RL.repMap.init(); 15 RL.fSelect.init(); 16 RL.mediaGallery.init(); 17 RL.downloads.init(); 18 RL.fancybox.init(); 19 }); 20 21 /** 22 * Set a height for product lists 23 * @type {Object} 24 */ 25 RL.listLayout = { 26 init: function() { 27 this.bind(); 28 // this.setListHeight(); 29 }, 30 31 bind: function(e) { 32 $(window).on('resize', this.setListHeight); 33 }, 34 35 setListHeight: function() { 36 var list = $('.features-list ul,.options-list ul'); 37 var list = $('.features-list ul,.options-list ul'); 38 39 list.css( 'height', '' ); 40 41 list.each(function(){ 42 var listHeight = $(this).height(), 43 newHeight = ( listHeight / 2 ) + 40; 44 45 $(this).css( 'height', newHeight ); 46 }); 47 } 48 }; 49 50 /** 51 * System Selector Functionality 52 * @type {Object} 53 */ 54 RL.systemSelector = { 55 56 isStepOne: true, 57 58 selectedSteps: [], 59 60 previousStep: {}, 61 62 /** 63 * name (string) 64 * toggle (string) or (object) 65 */ 66 systemSelectors: [ 67 { 68 'name': 'system_type', 69 'toggle': { 70 'mobile': 'system_travel_method',
71 'permanent': 'system_mounting_method' 72 }, 73 }, 74 { 75 'name': 'system_travel_method', 76 'toggle': 'system_worker_capacity' 77 }, 78 { 79 'name': 'system_mounting_method', 80 'toggle': 'system_user_movement' 81 }, 82 { 83 'name': 'system_user_movement', 84 'toggle': 'system_worker_capacity' 85 }, 86 { 87 'name': 'system_worker_capacity', 88 'toggle': 'results' 89 } 90 ], 91 92 init: function() { 93 if ( $('#system-selector').length > 0 ) { 94 this.bind(); 95 } 96 }, 97 98 bind: function() { 99 $(document).on( 'facetwp-loaded', this.updateSelection ); 100 $('#facetwp-reset a').on( 'click', this.reset ); 101 }, 102 103 updateSelection: function() { 104 105 var self = RL.systemSelector; 106 107 // hide all steps and results by default 108 $('.ss-selection').addClass('d-none'); 109 $('.ss-products').addClass('d-none'); 110 111 // get all selected steps 112 self.getSelectedSteps(); 113 114 if ( ! self.isStepOne ) { 115 // hide previous step 116 self.previousStep = self.selectedSteps.slice(-1)[0]; 117 self.hidePreviousStep(); 118 119 // show next step 120 self.showNextStep(); 121 122 } else { 123 // show first step if nothing has been selected yet 124 $('.ss-selection:first-child').removeClass('d-none'); 125 self.updateProgressBar('system_type'); 126 self.toggleForm(); 127 } 128 129 // toggle step navigation 130 self.toggleStepNav(); 131 132 // update summary 133 self.updateSummary(); 134 }, 135 136 getSelectedSteps: function() { 137 this.selectedSteps = this.systemSelectors.filter(function( selector ){ 138 return FWP.facets[ selector.name ].length > 0; 139 }); 140 141 this.isStepOne = this.selectedSteps.length > 0 ? false : true; 142 }, 143 144 hidePreviousStep: function() { 145 $('.facetwp-facet-' + this.previousStep.name).closest('.ss-selection').addClass('d-none'); 146 }, 147 148 showNextStep: function() { 149 if ( typeof this.previousStep.toggle === 'object' ) { 150 var systemType = FWP.facets.system_type[0], 151 nextStepName = this.previousStep.toggle[ systemType ]; 152 } else { 153 var nextStepName = this.previousStep.toggle; 154 } 155 156 if ( nextStepName == 'results' ) { 157 $('.ss-products').removeClass('d-none'); 158 } else { 159 $('.facetwp-facet-' + nextStepName).closest('.ss-selection').removeClass('d-none'); 160 } 161 162 // update progress bar 163 this.updateProgressBar( nextStepName ); 164 this.toggleForm( nextStepName ); 165 }, 166 167 setStep: function( direction ) { 168 if ( direction == -1 ) { 169 window.history.back(); 170 } else { 171 console.log('next'); 172 } 173 }, 174 175 toggleStepNav: function() { 176 if ( ! this.isStepOne ) { 177 $('.ss-step-nav').removeClass('d-none').addClass('d-flex'); 178 } else { 179 $('.ss-step-nav').addClass('d-none').removeClass('d-flex'); 180 } 181 }, 182 183 updateSummary: function() { 184 if ( ! this.isStepOne ) { 185 $('.ss-aside').removeClass('d-none'); 186 } else { 187 $('.ss-aside').addClass('d-none'); 188 } 189 190 var self = RL.systemSelector, 191 selectionList = []; 192 193 // clear form values 194 $('.gfield input[type="hidden"]').val(''); 195 196 $.each( self.selectedSteps, function( i, selector ) { 197 var userSelection = self.formatSelection( FWP.facets[ selector.name ][0] ), 198 selectorLabel = self.formatSelection( selector.name ); 199 200 selectionList.push('<li><strong>' + selectorLabel + ':</strong> ' + userSelection + '</li>'); 201 202 // set summary form 203 var fieldId = self.getFieldId( selector.name ); 204 $('#' + fieldId ).val( userSelection ); 205 206 }); 207 208 // set summary display 209 $('#ss-summary ul').html( selectionList.join('') ); 210 }, 211 212 toggleForm: function( stepName ) { 213 if ( stepName == 'results' ) { 214 $('.ss-form').removeClass('d-none'); 215 } else { 216 $('.ss-form').addClass('d-none'); 217 } 218 }, 219 220 updateProgressBar: function( stepName ) { 221 222 $('.ss-progress-bar li').removeClass('active'); 223 $('.ss-progress-bar li[data-name="' + stepName + '"]').addClass('active'); 224 225 if ( ! this.isStepOne ) { 226 // $('.ss-progress-bar').removeClass('invisible'); 227 $('.ss-progress-bar li.progress-' + FWP.facets.system_type[0]).removeClass('d-none'); 228 } else { 229 $('.ss-progress-bar li:not(.ss-progress-step-anchor)').addClass('d-none'); 230 // $('.ss-progress-bar').addClass('invisible'); 231 } 232 }, 233 234 formatSelection: function( str ) { 235 return str.replace(/-/g, ' ') 236 .replace(/system_/g, '') 237 .replace(/_/g, ' ') 238 .replace(/(?:^|\s|["'([{])+\S/g, function(m){return m.toUpperCase()}); 239 }, 240 241 getFieldId: function( selectorName ) { 242 243 var fieldId = ''; 244 245 switch ( selectorName ) { 246 case 'system_type': 247 fieldId = 'input_3_6'; 248 break; 249 case 'system_travel_method': 250 fieldId = 'input_3_7'; 251 break; 252 case 'system_mounting_method': 253 fieldId = 'input_3_8';
254 break; 255 case 'system_user_movement': 256 fieldId = 'input_3_9'; 257 break; 258 case 'system_worker_capacity': 259 fieldId = 'input_3_10'; 260 break; 261 } 262 263 return fieldId; 264 }, 265 266 reset: function() { 267 FWP.reset(); 268 } 269 270 }; 271 272 /** 273 * Find a Rep map functionality 274 * @type {Object} 275 */ 276 RL.repMap = { 277 278 map: $('#na-map'), 279 280 init: function() { 281 if ( this.map.length ) { 282 this.loadStates(); 283 this.bind(); 284 } 285 }, 286 287 bind: function(e) { 288 $(document).on( 'click', '.has-reps', this.filterByState ); 289 $(document).on( 'facetwp-refresh', this.addLoader ); 290 $(document).on( 'facetwp-loaded', this.removeLoader ); 291 }, 292 293 addLoader: function() { 294 if ( $('#rep-grid').length ) { 295 $('#rep-grid').prepend('<div id="loader"><div></div><div></div><div></div><div></div></div>'); 296 } 297 }, 298 299 removeLoader: function() { 300 if ( $('#loader').length ) { 301 $('#loader').remove(); 302 } 303 }, 304 305 loadStates: function() { 306 var self = this; 307 $.each( site.states, function( i, state ){ 308 self.map.find('[id="na-' + state + '"]').addClass('has-reps'); 309 }); 310 }, 311 312 filterByState: function() { 313 var self = RL.repMap, 314 state = $(this).attr('id').replace(/^na-/, ''); 315 316 // show loader 317 self.addLoader(); 318 319 // remove selected states 320 FWP.facets['state'] = []; 321 self.map.find('.has-reps').removeClass('active'); 322 323 // add to countries array 324 FWP.facets['state'].push( state ); 325 $(this).addClass('active'); 326 327 // scroll to results 328 var params = FWP.buildQueryString(); 329 if ( params != '' ) { 330 $('html, body').animate({ scrollTop: $('.facetwp-template').offset().top - 325 }, 1000); 331 } 332 333 // fetch data 334 FWP.fetchData(); 335 FWP.setHash(); 336 } 337 }; 338 339 /** 340 * fSelect Functionality 341 * @type {Object} 342 */ 343 RL.fSelect = { 344 init: function() { 345 if ( typeof $.fn.fSelect != 'undefined' ) { 346 $('.facetwp-sort-select').fSelect({ 347 showSearch: false 348 }); 349 } 350 351 if ( $('body').hasClass('blog') || $('body').hasClass('category') ) { 352 $('.widget_categories select').fSelect({ 353 showSearch: false 354 }); 355 } 356 } 357 }; 358 359 /** 360 * Media Gallery filter by media type 361 * @type {Object} 362 */ 363 RL.mediaGallery = { 364 init: function() { 365 if ( $('.facetwp-template[data-name="photo_gallery"]').length ) { 366 this.bind(); 367 } 368 }, 369 370 bind: function() { 371 $(document).on( 'facetwp-loaded', this.filterMediaByType ); 372 }, 373 374 filterMediaByType: function() { 375 if ( FWP.facets['media_type'] ) { 376 $.each( FWP.facets['media_type'], function( i, media ) { 377 $('[data-media-type]').not('[data-media-type="' + media + '"]').hide(); 378 }); 379 } else { 380 $('[data-media-type]').show(); 381 } 382 } 383 }; 384 385 /** 386 * Download Resource Functionality 387 * @type {Object} 388 */ 389 RL.downloads = { 390 391 $downloadButton : $('#download-resource'), 392 isEmailCaptured : false, 393 resource : null, 394 bidSpec : null, 395 hasEmailCookie : false, 396 397 init : function() { 398 // Check for email cookie 399 if ( this.$downloadButton.length > 0 ) { 400 this.getCookie( 'emailCaptured' ); 401 } 402 this.bind(); 403 }, 404 405 bind: function() { 406 $('.resource_type-bid-specs a').on( 'click', this.click ); 407 }, 408 409 click : function() { 410 event.preventDefault(); 411 var _self = RL.downloads; 412 413 // Set resource 414 _self.resource = $(this).attr('href'); 415 _self.bidSpec = $(this).text(); 416 417 // Check if we have the email, if not trigger modal, else trigger download 418 if ( _self.isEmailCaptured == false && ! _self.hasEmailCookie ) { 419 _self.setBidSpec(); 420 _self.triggerModal(); 421 } else { 422 _self.triggerDownload(); 423 } 424 }, 425 426 formSubmitted : function() { 427 // Email has been captured 428 this.isEmailCaptured = true; 429 430 // Set cookie for this user 431 this.createCookie( 'emailCaptured', 1, 30 ); 432 433 // Download form 434 this.triggerDownload(); 435 }, 436 437 triggerModal : function() { 438 // Open modal 439 this.$downloadButton.click(); 440 }, 441 442 triggerDownload : function() { 443 var a = document.createElement('a'); 444 a.href = this.resource; 445 a.target = '_blank'; 446 a.download = this.getDocumentTitle(); 447 a.click(); 448 }, 449 450 setBidSpec : function() { 451 $('#input_6_3').val( this.bidSpec ); 452 }, 453 454 getDocumentTitle : function() { 455 var re = /([\w\d_-]*)\.?[^\\\/]*$/i; 456 457 return this.resource.match(re)[1]; 458 }, 459 460 createCookie : function( name, value, days ) { 461 if ( days ) { 462 var date = new Date(); 463 date.setTime( date.getTime() + ( days*24*60*60*1000 ) ); 464 var expires = "; expires=" + date.toGMTString(); 465 } 466 else var expires = ""; 467 document.cookie = name + "=" + value + expires + "; path=/"; 468 }, 469 470 getCookie : function( name, callback ) { 471 var _self = this; 472 473 $.ajax({ 474 type : "POST", 475 url : site.ajax_url, 476 dataType : 'json', 477 headers : { 478 'Authorization': 'Basic ' + btoa( 'demo' + ':' + 'admin12345!!' ) 479 }, 480 data : { 'action': 'has_cookie', 'cookie': name }, 481 success : function ( response ) { 482 if ( response != null ) { 483 _self.hasEmailCookie = true; 484 } 485 } 486 }); 487 488 } 489 }; 490 491 /** 492 * Fancybox options for the gallery 493 * @type {Object} 494 */ 495 RL.fancybox = { 496 init: function() { 497 if ( typeof $.fancybox != 'undefined' ) { 498 $.fancybox.defaults.hash = false;
499 $.fancybox.defaults.loop = true; 500 } 501 } 502 }; 503 504 return RL; 505}(RL || {}, jQuery));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.