1 2/* window/element dimensions */ 3 4 5function portraitFlag() 6{ 7 handlePortraitFlag(); 8 $( window ).resize( function() 9 { 10 handlePortraitFlag(); 11 }); 12} 13 14 15function handlePortraitFlag() 16{ 17 var vp = getViewportDimensions(); 18 if (vp.height > vp.width) // landscape 19 { 20 $('body').addClass('portrait'); 21 } 22 else 23 { 24 $('body').removeClass('portrait'); 25 } 26} 27 28 29// returns dimensions of viewable area 30function getViewportDimensions() 31{ 32 var vpWidth = 0; 33 var vpHeight = 0; 34 35 if ( typeof( window.innerWidth ) == 'number' ) 36 { 37 //Non-IE 38 vpWidth = window.innerWidth; 39 vpHeight = window.innerHeight; 40 } 41 else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 42 { 43 //IE 6+ in 'standards compliant mode' 44 vpWidth = document.documentElement.clientWidth; 45 vpHeight = document.documentElement.clientHeight; 46 } 47 else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 48 { 49 //IE 4 compatible 50 vpWidth = document.body.clientWidth; 51 vpHeight = document.body.clientHeight; 52 } 53 return { width: vpWidth, height: vpHeight }; 54} 55 56 57 58// set element height based on current width using w:h ratio 59function resetHeight(targetElement, ratio, heightOffset, maxscreen) 60{ 61 maxscreen = (typeof maxscreen === 'undefined') ? 'false' : maxscreen; // optional parameter 62 heightOffset = (typeof heightOffset === 'undefined') ? 0 : heightOffset; // optional parameter 63 64 var currentWidth = $(targetElement).css('width').replace('px', ''); 65 var newHeight = currentWidth / ratio; 66 if (maxscreen) // height shouldn't be greater than viewable area 67 { 68 var vp = getViewportDimensions(); 69 newHeight = (vp.height < newHeight) ? vp.height : newHeight; 70 } 71 newHeight = newHeight - heightOffset; 72 $(targetElement).css('height', newHeight + 'px'); 73 74 return { width: currentWidth, height: newHeight }; 75} 76 77 78// positions target element vertically centered 79function centerVertical(targetElement, shimOffset) 80{ 81 shimOffset = (typeof shimOffset === 'undefined') ? 0 : shimOffset; // optional parameter 82 handleCenterVertical(targetElement, shimOffset); 83 $( window ).resize( function() 84 { 85 handleCenterVertical(targetElement, shimOffset); 86 }); 87} 88 89 90function handleCenterVertical(targetElement, shimOffset) 91{ 92 var contentHeight = $(targetElement).height(); 93 var windowHeight = $(window).height(); 94 var shimHeight = (windowHeight - contentHeight - shimOffset) / 2; 95 96 // configure shim 97 $(targetElement).css('margin-top', shimHeight + 'px'); 98} 99 100 101// positions target element vertically centered 102function setSquare(targetElement) 103{ 104 var contentWidth = $(targetElement).width(); 105 $(targetElement).height(contentWidth); 106} 107 108 109function setMediaDimensions(mediaRatio, container) 110{ 111 var containerWidth = $('.container').width() - 10; 112 var vp = getViewportDimensions(); 113 var offset = (vp.width > 767) ? 300 : 240; 114 var mediaWidth = (vp.width > 767) ? containerWidth : vp.width - 40; 115 var mediaHeight = mediaWidth / mediaRatio; 116 117 switch (true) 118 { 119 case (mediaHeight > (vp.height - offset)): // vid taller than the screen 120 121 mediaHeight = vp.height - offset; 122 mediaWidth = mediaHeight * mediaRatio; 123 124 $('#video').css('height', mediaHeight + 'px').css('width', mediaWidth + 'px'); 125 $('#video_html5_api').css('height', mediaHeight + 'px').css('width', mediaWidth + 'px'); 126 $(container).css('height', mediaHeight + 'px').css('width', mediaWidth + 'px'); 127 break; 128 129 default: 130 $('#video').css('width', mediaWidth + 'px').css('height', mediaHeight + 'px'); 131 $('#video_html5_api').css('width', mediaWidth + 'px').css('height', mediaHeight + 'px'); 132 $(container).css('width', mediaWidth + 'px').css('height', mediaHeight + 'px'); 133 break; 134 } 135 136 // postition play button 137 if ( ! $(container + ' button.vjs-big-play-button').hasClass('clicked')) 138 { 139 $('button.vjs-big-play-button') 140 .css('margin-top', ((mediaHeight - 41) / 2) + 'px') 141 .css('margin-left', ((mediaWidth - 86) / 2) + 'px') 142 .css('display', 'block'); 143 } 144 145 $(container).on('click','button.vjs-big-play-button', function() 146 { 147 $(this).stop().animate({ opacity: 0 }, 500, 'easeOutCubic', function() 148 { 149 $(this).addClass('clicked'); 150 }); 151 }); 152} 153 154 155/* DOM functions */ 156 157 158// group items by wrapping in div 159function groupObjects(thisContainer, thisObject, thisWrapper, thisGroupSize) 160{ 161 // group offer boxes 162 var number_of_objects; 163 var number_of_rows; 164 var startPoint; 165 var endPoint; 166 var objects_per_row = thisGroupSize; 167 168 number_of_objects = $(thisObject).length; 169 number_of_rows = 0; 170 171 // calculate number of rows 172 for (i = 0; i < number_of_objects; i = (i + objects_per_row)) 173 { 174 number_of_rows++; 175 } 176 177 if (number_of_rows > 0) 178 { 179 // create section 180 for (i = 0; i < (number_of_rows) ; i++) 181 { 182 startPoint = i; 183 endPoint = startPoint + objects_per_row; 184 185 if (endPoint > number_of_objects) 186 { 187 endPoint = number_of_objects; 188 $(thisContainer).children().slice(startPoint).wrapAll(thisWrapper); 189 } 190 else 191 {
192 $(thisContainer).children().slice(startPoint, endPoint).wrapAll(thisWrapper); 193 } 194 } 195 } 196} 197 198 199function initAccordian(wrapper, trigger, target) 200{ 201 // setup trigger 202 $(wrapper + ' ' + trigger).each(function(index) 203 { 204 $(this).addClass('open-handle'); 205 $(this).append('<div class="action-icon"><span class="glyphicon glyphicon-chevron-down" aria-hidden="true"></span></div>'); 206 }); 207 208 // open event 209 $(wrapper).on('click', '.open-handle', function() 210 { 211 var $parentEl = $(this).parent(); 212 $(wrapper + ' ' + target).slideUp(300, function() // close all open views 213 { 214 $(wrapper).find('.close-handle').addClass('open-handle').removeClass('close-handle'); 215 $(wrapper).find('.action-icon span').addClass('glyphicon-chevron-down').removeClass('glyphicon-chevron-up'); 216 }); 217 218 $parentEl.find(target).slideDown(600, function() 219 { 220 $parentEl.find('.open-handle').addClass('close-handle').removeClass('open-handle'); 221 $parentEl.find('.action-icon span').addClass('glyphicon-chevron-up').removeClass('glyphicon-chevron-down'); 222 }); 223 224 return false; 225 }); 226 227 // close event 228 $(wrapper).on('click', '.close-handle', function() 229 { 230 var $parentEl = $(this).parent(); 231 $parentEl.find(target).slideUp(300, function() 232 { 233 $parentEl.find('.close-handle').addClass('open-handle').removeClass('close-handle'); 234 $parentEl.find('.action-icon span').addClass('glyphicon-chevron-down').removeClass('glyphicon-chevron-up'); 235 }); 236 return false; 237 }); 238} 239 240 241function initSlideout(wrapper, trigger, target) 242{ 243 if ($(trigger).length + $(target).length > 0) 244 { 245 var $wrapper = $(wrapper); 246 var $trigger = $(trigger); 247 var $target = $(target); 248 249 var slideoutWidth = $wrapper.width(); 250 var triggerWidth = $trigger.width(); 251 var targetWidth = slideoutWidth - triggerWidth; 252 253 // setup 254 $trigger.addClass('closed'); 255 $wrapper.css('width', $trigger.width() + 'px'); 256 var setupCss = { 257 'display': 'none', 258 'width': 0, 259 'height': '100%', 260 'opacity': 0 261 }; 262 $target.css(setupCss); 263 264 // assign listners 265 $wrapper.on('click', trigger + '.closed', function() // open menu 266 { 267 $wrapper.css('width', 'auto'); 268 $target.css('display', 'block'); 269 $trigger.removeClass("closed").addClass("open"); 270 applyDynamicStyling($wrapper, $trigger, $target); 271 272 $( window ).resize( function() 273 { 274 applyDynamicStyling($wrapper, $trigger, $target, 'resize'); 275 }); 276 }); 277 278 $wrapper.on('click', trigger + '.open', function() // close menu 279 { 280 $target.stop().animate({ width: '0px', opacity: 0 }, 500, 'easeOutCubic', function() 281 { 282 $trigger.removeClass("open").addClass("closed"); 283 $target.css('display', 'none'); 284 $wrapper.css('width', $trigger.width() + 'px'); 285 }); 286 }); 287 288 function applyDynamicStyling($wrapper, $trigger, $target, resize) 289 { 290 resize = (typeof resize === 'undefined') ? false : true; // optional parameter var offset = 52 + 63; // header & footer 291 var numberOfIcons = 5; 292 293 var vp = getViewportDimensions(); 294 var triggerWidth = $trigger.width(); 295 var targeHeight = $wrapper.height(); 296 var targetWidth = (vp.width < 600) ? vp.width - triggerWidth : 570 - triggerWidth; 297 298 $target.css('height', targeHeight + 'px'); 299 $target.find('.content-wrapper').css('width', targetWidth + 'px'); 300 301 if (resize) // just change the width 302 { 303 $target.css('width', targetWidth + 'px'); 304 } 305 else // animate width change 306 { 307 $target.stop().animate({ width: targetWidth, opacity: 1 }, 800, 'easeOutCubic'); 308 } 309 } 310 } 311} 312 313 314function initSwipeListener(target, callback, reassignment) 315{ 316 reassignment = (typeof reassignment === 'undefined') ? false : true; // optional parameter 317 318 var gesture = {}; 319 gesture.record = {}; 320 321 var vp = getViewportDimensions(); 322 var params = {}; 323 if (vp.width < 600) // mobile 324 { 325 params.minX = 120; // min x swipe distance - horizonal 326 params.minY = 120; // min y swipe distance - vertical 327 params.maxY = 180; // max y swipe distance - horizontal 328 params.maxX = 120; // max x swipe distance - vertical 329 } 330 else // desktop 331 { 332 params.minX = 30; // min x swipe distance - horizonal 333 params.minY = 50; // min y swipe distance - vertical 334 params.maxY = 60; // max y swipe distance - horizontal 335 params.maxX = 40; // max x swipe distance - vertical 336 } 337 338 if ( $(target).length > 0 ) 339 { 340 var $ele = $(target); 341 342 // check listeners not alreay bound 343 if ( ! $ele.hasClass('swipe-listner') || reassignment) 344 { 345 if ( ! reassignment) 346 { 347 $ele.addClass('swipe-listner'); 348 $ele.data('callback', callback); 349 } 350 else 351 {
352 $ele.unbind('touchstart mousedown touchend mouseup'); 353 } 354 355 // bind listeners 356 $ele.on('touchstart mousedown', function(event) 357 { 358 gesture = startGestureCheck($ele, event, gesture); 359 }); 360 361 $ele.on('touchend mouseup', function() 362 { 363 var direction = analyseGesture(params, gesture, target); 364 endGestureCheck($ele, target, direction); 365 }); 366 } 367 } 368 369 function startGestureCheck($ele, event, gesture) 370 { 371 switch(event.type) 372 { 373 case 'mousedown': 374 gesture.record.startX = event.screenX; 375 gesture.record.startY = event.screenY; 376 break; 377 378 case 'touchstart': 379 gesture.record.startX = event.originalEvent.touches[0].pageX; 380 gesture.record.startY = event.originalEvent.touches[0].pageY; 381 break; 382 } 383 384 // bind movement listener 385 $ele.on('touchmove mousemove', function(event) 386 { 387 return movementCapture(event, gesture); 388 }); 389 390 return gesture; 391 } 392 393 function movementCapture(event, gesture) 394 { 395 switch(event.type) 396 { 397 case 'mousemove': 398 gesture.record.endX = event.screenX; 399 gesture.record.endY = event.screenY; 400 break; 401 402 case 'touchmove': 403 gesture.record.endX = event.originalEvent.touches[0].pageX; 404 gesture.record.endY = event.originalEvent.touches[0].pageY; 405 break; 406 } 407 return gesture; 408 } 409 410 function analyseGesture(params, gesture, target) 411 { 412 var swipeEvent = ''; 413 var record = gesture.record; 414 415 // horizontal detection 416 if ((((record.endX - params.minX > record.startX) || (record.endX + params.minX < record.startX)) && ((record.endY < record.startY + params.maxY) && (record.startY > record.endY - params.maxY) && (record.endX > 0)))) 417 { 418 swipeEvent = (record.endX > record.startX) ? 'swiperight' : 'swipeleft'; 419 $(target).data('swiped', 'true'); // flag swipe event 420 } 421 422 // vertical detection 423 else if ((((record.endY - params.minY > record.startY) || (record.endY + params.minY < record.startY)) && ((record.endX < record.startX + params.maxX) && (record.startX > record.endX - params.maxX) && (record.endY > 0)))) 424 { 425 swipeEvent = (record.endY > record.startY) ? 'swipedown' : 'swipeup'; 426 $(target).data('swiped', 'true'); // flag swipe event 427 } 428 return swipeEvent; 429 } 430 431 function endGestureCheck($ele, target, swipeEvent) 432 { 433 gesture = {}; 434 gesture.record = {}; 435 436 $ele.unbind('touchmove mousemove'); 437 438 if (swipeEvent != '') 439 { 440 if (typeof window[callback] === 'function') 441 { 442 window[callback](target, swipeEvent); 443 timeout = setTimeout( function () 444 { 445 $(target).data('swiped', 'false'); // remove swipe event flag 446 }, 500); 447 } 448 } 449 } 450} 451 452 453 454/* plugin functions */ 455 456 457// assign modal to gallery images 458function assignGalleryModal(target) 459{ 460 $(target).colorbox( 461 { 462 rel: 'grp' 463 }); 464 465 $(document).bind('cbox_open', function() 466 { 467 // tweak controls 468 $('#cboxPrevious').css('display','none'); 469 $('#cboxNext').css('display','none'); 470 }); 471 472 $(document).bind('cbox_complete', function() 473 { 474 // tweak controls 475 $('#cboxPrevious').html('<span class="glyphicon glyphicon-chevron-left"></span>').css('display','block'); 476 $('#cboxNext').html('<span class="glyphicon glyphicon-chevron-right"></span>').css('display','block'); 477 478 // set image responsive css 479 setImageDimensions(); 480 }); 481 482 $( window ).resize( function() 483 { 484 setImageDimensions(); 485 }); 486 487 function setImageDimensions() 488 { 489 var media = getImageDimensions(); 490 $('.cboxPhoto').css('width', media.width + 'px').css('height', media.height + 'px'); 491 492 var colorboxDimensions = { 493 width : (media.width) + 'px', 494 innerWidth : (media.width) + 'px', 495 height : (media.height) + 'px', 496 innerHeight : (media.height) + 'px' 497 }; 498 $.colorbox.resize(colorboxDimensions); 499 } 500 501 function getImageDimensions() 502 { 503 var objWidth = $('.cboxPhoto').width(); 504 var objHeight = $('.cboxPhoto').height(); 505 var mediaRatio = objWidth / objHeight; 506 507 var vp = getViewportDimensions(); 508 var maxWidth = vp.width * 0.75; 509 var maxHeight = vp.height * 0.75; 510 var offset = (vp.width > 767) ? 300 : 240; 511 512 var mediaWidth = (vp.width > 767) ? maxWidth : vp.width * 0.85; 513 var mediaHeight = mediaWidth / mediaRatio; 514 515 if (mediaHeight > maxHeight) // media taller than the colorbox max height 516 { 517 mediaHeight = maxHeight; 518 mediaWidth = maxHeight * mediaRatio; 519 } 520 return {'width': mediaWidth, 'height': mediaHeight, 'ratio': mediaRatio}; 521 } 522} 523 524 525function imageZoom(selector) 526{ 527 $(selector).elevateZoom( 528 { 529 constrainType: 'height', 530 constrainSize: 350, 531 zoomType: 'lens', 532 containLensZoom: true, 533 cursor: 'pointer' 534 }); 535} 536 537 538// spinner plugin - spin.js 539function showSpinner(targetId) 540{ 541 var opts = { 542 lines : 13 // The number of lines to draw 543 , length : 28 // The length of each line 544 , width : 14 // The line thickness 545 , radius : 42 // The radius of the inner circle 546 , scale : 1 // Scales overall size of the spinner 547 , corners : 1 // Corner roundness (0..1) 548 , color : '#000' // #rgb or #rrggbb or array of colors 549 , opacity : 0.25 // Opacity of the lines 550 , rotate : 0 // The rotation offset 551 , direction : 1 // 1: clockwise, -1: counterclockwise 552 , speed : 1 // Rounds per second 553 , trail : 60 // Afterglow percentage 554 , fps : 20 // Frames per second when using setTimeout() as a fallback for CSS 555 , zIndex : 2e9 // The z-index (defaults to 2000000000) 556 , className : 'spinner-' + targetId // The CSS class to assign to the spinner 557 , top : '50%' // Top position relative to parent 558 , left : '50%' // Left position relative to parent 559 , shadow : false // Whether to render a shadow 560 , hwaccel : false // Whether to use hardware acceleration 561 , position : 'absolute' // Element positioning 562 }; 563 564 var target = document.getElementById(targetId); 565 var spinner = new Spinner(opts).spin(target); 566 567 return spinner; 568} 569 570 571function hideSpinner(targetId) 572{ 573 $('.spinner-' + targetId).remove(); 574} 575 576 577function goBack() 578{ 579 window.history.back(); 580} 581 582 583function redirect(url) 584{ 585 window.location.href = url; 586} 587 588 589// close modal 590function closeModal() 591{ 592 $.colorbox.close(); 593} 594 595 596function notify_user($type, $message) 597{ 598 $.notify($message, $type, { autoHide: false, clickToHide: true }); 599} 600 601 602function set_session(baseURL, the_data, redirect) 603{ 604 605 //var baseURL = $('body').data('url'); 606 var ajaxURL = baseURL + 'site/ajax/set_session'; 607 608 $.ajax({ 609 610 type: 'POST', 611 url: ajaxURL, 612 xhrFields: { withCredentials: true }, 613 data:the_data, 614 cache: false, 615 success: function(response) 616 { 617 if(redirect != '') 618 { 619 console.log(baseURL + redirect); 620 location.href = baseURL + redirect; 621 } 622 }, 623 error: function(){ 624 625 } 626 627 }); 628 629} 630 631 632function get_session(redirect) 633{ 634 var baseURL = $('body').data('url'); 635 $.ajax({ 636 637 type: "POST", 638 url: "https://caarparts.co.uk/site/ajax/get_session", 639 xhrFields: { withCredentials: true }, 640 dataType: 'json', 641 cache: false, 642 data:{source_site:baseURL}, 643 success: function(response) 644 { 645 646 if(response.basket_number_of_items > 0) 647 { 648 $('.basket-num-items').html(response.basket_number_of_items); 649 $('.basket-num-items').show(); 650 set_session(baseURL, response, redirect); 651 652 } 653 654 if(response.make != '' && response.make != null) 655 { 656 update_dropdowns(response.make, response.model, response.submodel, response.engine, response.
656year, response.fuel); 657 } 658 659 }, 660 error: function(){ 661 } 662 663 }); 664 665}
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.