Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Setup Variables for the functions.
- var placeSearch, autocomplete, stores, currentURL;
- var componentForm = {
- street_number: 'short_name',
- route: 'long_name',
- locality: 'long_name',
- administrative_area_level_1: 'short_name',
- country: 'long_name',
- postal_code: 'short_name'
- };
- $(window).on('load resize', function() {
- equalheight('.equal-height');
- });
- //PW edits: Changed ' to " for store-finder part
- /*
- $(document).ready(function () {
- //STORE LIST FROM JSON FILE
- bootstrapMapsComponent();
- });
- */
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // GOOGLE LOCATION FUNCTIONALITY - GETTING STORE LIST FROM JSON FILE AND DISPLAYING ON PAGE
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- window.gMaps = [];
- function bootstrapMapsComponent() {
- $.getJSON('{{ "store-finder.json" | asset_url }}', function (data) {
- stores = data;
- setupMaps();
- searchFromURL();
- newSearch();
- submitForm();
- getAllStores();
- showNearbyStores();
- loadBookingIframeFromURL();
- initAutocomplete();
- });
- }
- //PW edits: changed equals operator to === from ==
- function setupMaps() {
- //store locators
- $('.map.storeLocator').each(function (i, elem) {
- if (typeof $(elem).attr('data-initialised') === 'undefined') {
- var mapOptions = {
- center: new google.maps.LatLng(-33.895516, 151.18117),
- zoom: 8,
- mapTypeId: google.maps.MapTypeId.ROADMAP,
- scrollwheel: false,
- streetViewControl: false,
- panControl: false,
- overviewMapControl: false,
- mapTypeControl: false,
- //styles: mapStyling
- };
- window.gMaps[window.gMaps.length] = new google.maps.Map(elem, mapOptions);
- addPointsToMap(window.gMaps[window.gMaps.length - 1]);
- $(elem).attr('data-initialised', '1');
- }
- });
- }
- function addPointsToMap(map, selectedStores, storeobject) {
- if(!selectedStores){
- selectedStores = stores;
- }
- map.bnMarkers = [];
- var offset = 0;
- for (var i = 0; i < selectedStores.length; i++) {
- //setup
- if(storeobject){
- var store = selectedStores[i].storeInfo;
- }else{
- var store = selectedStores[i];
- }
- var store_spec = store.also || null;
- var pos = new google.maps.LatLng(store.lat, store.lon);
- //add marker
- var marker = new google.maps.Marker({
- position: pos,
- map: map,
- title: store.name,
- clickable: true
- });
- //create onClick infoWindow
- var mapAddr = store.map_addr || store.address;
- var addr2 = mapAddr;
- mapAddr = mapAddr.parseGoogleMapsAddr();
- addr2 = addr2.parseGoogleMapsAddr();
- addrPre = '';
- //build markers
- if (store.url != null && store.url != "" && store.url != "undefined") {
- marker.info = new google.maps.InfoWindow({
- maxWidth: 300,
- content: "<div class=\"gMapPopup\"><div class=\"subhead\">" + store.name + "</div><p>" + store.address + "</p><p>" + store.phone + "</p><p><a href=\"" + store.url + "\" target=\"_blank\" >" + store.url.replace('http://', '').replace('https://', '') + "</p><!--<p><a href=\"http://maps.google.com/maps?q=" + addr2 + "&daddr=" + addr2 + "\" target=\"_blank\">Get Directions »</a></p>--></div>"
- });
- }
- else {
- marker.info = new google.maps.InfoWindow({
- maxWidth: 300,
- content: "<div class=\"gMapPopup\"><div class=\"subhead\">" + store.name + "</div><p>" + store.address + "</p><p>" + store.phone + "</p><!--<p><a href=\"http://maps.google.com/maps?q=" + addr2 + "&daddr=" + addr2 + "\" target=\"_blank\">Get Directions »</a></p>--></div>"
- });
- }
- //add necessary info
- marker.storeName = store.name;
- //add to global for later reference
- var markerIndex = i + offset;
- map.bnMarkers[markerIndex] = marker;
- //bind infoWindow to marker
- google.maps.event.addListener(marker, 'click', function () {
- for (var i = 0; i < map.bnMarkers.length; i++) {
- map.bnMarkers[i].info.close();
- }
- //this.info.open(map, this); Triggered Below!
- updateMapsForStore(getStoreInfo(this.storeName));
- });
- }
- }
- function getMarkerForStore(markers, storeName) {
- for (var i = 0; i < markers.length; i++) {
- //console.log(markers[i].storeName + ' :: ' + storeName);
- if (markers[i].storeName == storeName)
- return markers[i];
- }
- }
- function updateMapsForStore(info, data, val) {
- //globals
- var selStore;
- var info;
- var addrPre = "";
- var addrPost = "";
- var telPre = "";
- var telPost = "";
- //used to get info or provide null for no store
- if (!info) {
- info = {};
- } else {
- var mapAddr = info.map_addr || info.address;
- var addr2 = mapAddr;
- mapAddr = mapAddr.parseGoogleMapsAddr();
- addr2 = addr2.parseGoogleMapsAddr();
- addrPre = '<a href="http://maps.google.com/maps?q=' + addr2 + '&daddr=' + addr2 + '" target="_blank">';
- addrPost = '</a>';
- telPre = '<a href="tel:' + info.phone + '">';
- telPost = '</a>';
- }
- //declare info
- var name = info.name;
- var addr = info.address;
- var tel = info.phone;
- //update map
- var zoomLevel = 11;
- if(val && val.toLowerCase() == 'new zealand'){
- zoomLevel = 4;
- }
- if (data != undefined && data.lat != undefined) {
- updateMap(data, zoomLevel, name, false);
- } else if (info.lat && info.lon) {
- updateMap(info, zoomLevel, name, true);
- }
- }
- function updateMap(data, zoomLevel, name, isMarker){
- $.each(window.gMaps, function (i, map) {
- map.setCenter(new google.maps.LatLng(data.lat, data.lon));
- map.setZoom(zoomLevel);
- if(isMarker){
- var marker = getMarkerForStore(map.bnMarkers, name);
- marker.info.open(map, marker);
- }
- });
- }
- function getStoreInfo(name) {
- for (var i = 0; i < stores.length; i++) {
- if (stores[i].name == name)
- return stores[i];
- }
- }
- function updateStoreList(stores) {
- var storeListLimit = stores.length;
- $('.map-results').find('.store-limit').text(storeListLimit);
- var html = '';
- for (i = 0; i < storeListLimit; i++) {
- var store = stores[i].storeInfo;
- var distance = Math.round( stores[i].dist * 10 ) / 10;
- html += '<div class="full-width store">' +
- '<div class="store-details col-two-third float-left">'+
- '<a href="'+ store.url +'"><b>' + store.name + ' ('+distance+'km)</b></a><br/>' +
- '<p class="address">' + store.address + '</p>' +
- '<p class=phone">' + store.phone + '</p>' +
- '<p class="email"><a href="mailto:' + store.email + '">' + store.email + '</a></p>' +
- store.hours +
- '</div>' +
- '<div class="col-one-third">'+
- '<a href="#" class="btn btn--large btn--square uppercase book-appointment" data-appointment_id=\''+store.appointment_url+'\'>Book Now</a>'+
- '</div></div>';
- }
- $('.map-results').find('.store-results').html(html);
- storeMarker(stores);
- bookAppointment();
- }
- function clearMarkers(markers) {
- for(var i = 0; i < markers.length; i++) {
- markers[i].setMap(null);
- }
- }
- //GET THE CLOSEST STORES (50KM RADIUS)
- function getClosestStores(latlong, val) {
- var result = new Array(0);
- for (var i = 0; i < stores.length; i++) {
- var dist = calcDist(latlong, stores[i], val);
- if(dist){
- result.push({ "dist": dist, "storeInfo": stores[i] });
- }
- }
- // result = _.sortBy(result, function (i) { return i.dist; });
- result.sort(function(a, b){return a.dist - b.dist});
- return result;
- }
- //CALCULATE THE DISTANCE BETWEEN USERS LOCATION AND STORE
- function calcDist(pos1, pos2, val) {
- //setup
- var R = 6371; // radius of earth in km
- var lat1 = parseFloat(pos1.lat);
- var lat2 = parseFloat(pos2.lat);
- var lon1 = parseFloat(pos1.lon);
- var lon2 = parseFloat(pos2.lon);
- //fixes
- var dLat = (lat2 - lat1).toRad();
- var dLon = (lon2 - lon1).toRad();
- var lat1 = lat1.toRad();
- var lat2 = lat2.toRad();
- //calculation
- var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
- var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
- var d = R * c;
- //result
- if(val != 'new zealand'){
- if(d < {{ settings.store-finder-radius }}){
- return d;
- }else{
- return null;
- }
- }else{
- return d;
- }
- }
- //Generic Functions
- if (typeof (Number.prototype.toRad) === "undefined") {
- Number.prototype.toRad = function () {
- return this * Math.PI / 180;
- }
- }
- String.prototype.parseGoogleMapsAddr = function () {
- return this.replace(/ /g, "+").replace(/&/g, "%26").replace(/\?/g, "%3F").replace(/=/g, "%3D");
- }
- //Styling
- var mapStyling = [{ "featureType": "administrative", "elementType": "labels.text.fill", "stylers": [{ "color": "#444444" }] }, { "featureType": "administrative.country", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "administrative.country", "elementType": "geometry.fill", "stylers": [{ "visibility": "off" }] }, { "featureType": "administrative.province", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.province", "elementType": "geometry.fill", "stylers": [{ "visibility": "off" }] }, { "featureType": "administrative.locality", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.locality", "elementType": "geometry.stroke", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.locality", "elementType": "labels.text", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.neighborhood", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "administrative.land_parcel", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "landscape", "elementType": "all", "stylers": [{ "color": "#f2f2f2" }, { "visibility": "simplified" }] }, { "featureType": "landscape.man_made", "elementType": "all", "stylers": [{ "visibility": "on" }] }, { "featureType": "landscape.natural.landcover", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "landscape.natural.terrain", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.attraction", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.business", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "poi.government", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "road", "elementType": "all", "stylers": [{ "saturation": -100 }, { "lightness": 45 }, { "visibility": "off" }] }, { "featureType": "road.highway", "elementType": "all", "stylers": [{ "visibility": "simplified" }, { "hue": "#ff00c9" }] }, { "featureType": "road.highway", "elementType": "labels", "stylers": [{ "visibility": "off" }] }, { "featureType": "road.highway", "elementType": "labels.text", "stylers": [{ "visibility": "off" }] }, { "featureType": "road.highway", "elementType": "labels.text.fill", "stylers": [{ "visibility": "off" }] }, { "featureType": "road.highway.controlled_access", "elementType": "all", "stylers": [{ "visibility": "simplified" }] }, { "featureType": "road.arterial", "elementType": "labels.icon", "stylers": [{ "visibility": "off" }] }, { "featureType": "transit", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "transit.station", "elementType": "all", "stylers": [{ "visibility": "off" }] }, { "featureType": "water", "elementType": "all", "stylers": [{ "color": "#e5e8e9" }, { "visibility": "on" }] }];
- function truncateString(str, length) {
- return str.length > length ? str.substring(0, length - 3) + '...' : str
- }
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // GET THE LOCATION LIST BASED ON USERS POSITION
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- function getLocationList(pos, val){
- var stores = getClosestStores({ "lat": pos.lat, "lon": pos.lng }, val);
- if(stores[0]){
- $('.map-results').slideDown(function(){
- clearMarkers(window.gMaps[window.gMaps.length - 1].bnMarkers);
- addPointsToMap(window.gMaps[window.gMaps.length - 1], stores, true);
- $('.no-results').hide();
- if(val){
- updateMapsForStore(stores[0].storeInfo, { "lat": pos.lat, "lon": pos.lng }, val); //show the closest stores
- }else{
- $(stores).each(function(key, store){
- updateMapsForStore(store.storeInfo, { "lat": pos.lat, "lon": pos.lng }); //show the closest stores
- });
- }
- updateStoreList(stores);
- $('html,body').animate({ scrollTop: $('.map-results').position().top - 150 }); //so you can see a little map...
- });
- }else{
- $('.map-results').slideUp();
- $('.no-results').show();
- }
- google.maps.event.trigger(window.gMaps[window.gMaps.length - 1], 'resize'); //Reinit the map because of the map been hidden and displayed
- $('.ajax-loader').hide();
- var url = window.location.href.split('?')[0] + '?lat=' + pos.lat + '&lng=' + pos.lng;
- if(val){
- url +='&allStore=true';
- }
- $('#iframeContainer').slideUp();
- history.pushState(null, null, url);
- }
- function searchFromURL(){
- var lat = getParameterByName('lat');
- var lng = getParameterByName('lng');
- var all_stores = getParameterByName('allStore');
- if(lat && lng){
- var pos = {
- lat: lat,
- lng: lng
- };
- if(all_stores){
- $('.search-location').text('New Zealand');
- getLocationList(pos, 'new zealand');
- }else{
- geocodeLatLng(lat, lng);
- getLocationList(pos);
- }
- }
- }
- function loadBookingIframeFromURL(){
- var appointment_id = getParameterByName('appointment_id');
- if(appointment_id && appointment_id.length > 3){
- $('#iframeContainer').find('#iframe').html('<iframe id="wd_ediary_iframe" height="1000px" width="100%" allowfullscreen="" seamless="seamless" frameborder="0" style="overflow:hidden;clear:both;width:100%!important;" src="https://baileynelsoneyewear.gettimely.com/book/embed?location='+appointment_id+'"></iframe>');
- $('#iframeContainer').slideDown();
- } else {
- if(appointment_id){
- $('#iframeContainer').find('#iframe').html('<iframe src="https://baileynelsonnz.healthsite.io/#clinic/'+appointment_id+'" scrolling="yes" id="healthsite" style="width:480px;height:650px;border:1px solid #4f606b" gesture="media" allow="encrypted-media"></iframe>');
- $('#iframeContainer').slideDown();
- }
- }
- }
- function getParameterByName(name, url) {
- if (!url) url = window.location.href;
- name = name.replace(/[\[\]]/g, "\\$&");
- var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
- results = regex.exec(url);
- if (!results) return null;
- if (!results[2]) return '';
- return decodeURIComponent(results[2].replace(/\+/g, " "));
- }
- // GOOGLE ADDRESS AUTOCOMPLETE AND GETTING CURRENT LOCATION
- function initAutocomplete() {
- // Create the autocomplete object, restricting the search to geographical
- // location types.
- autocomplete = new google.maps.places.Autocomplete(
- /** @type {!HTMLInputElement} */
- (document.getElementById('autocomplete')),
- {
- types: ['geocode'],
- componentRestrictions: {country: 'nz'}
- }
- );
- // When the user selects an address from the dropdown, populate the address
- // fields in the form.
- autocomplete.addListener('place_changed', updateLocation);
- // PW edits: Check for iOS device and stop propagation to ensure autocomplete works
- if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) {
- setTimeout(function() {
- var container = document.getElementsByClassName('pac-container')[0];
- container.addEventListener('touchend', function(e) {
- e.stopImmediatePropagation();
- });
- }, 500);
- }
- }
- function submitForm(){
- $('.location-search-btn').on('click', function(e){
- e.preventDefault();
- if($('#autocomplete').val()){
- var place = $('#autocomplete').val();
- updateLocation(place);
- }else{
- alert('Please make sure you have typed in your location');
- return false;
- }
- });
- }
- function updateLocation(input) {
- // Get the place details from the autocomplete object.
- var val = '';
- if(!input){
- var place = autocomplete.getPlace();
- }else{
- var place = {name: input};
- if(input.toLowerCase() == 'new zealand'){
- val = input.toLowerCase();
- }
- }
- var pos;
- $('.ajax-loader').show();
- // Get each component of the address from the place details
- // and fill the corresponding field on the form.
- if(place.address_components && place.address_components.length){
- pos = {
- lat: place.geometry.location.lat(),
- lng: place.geometry.location.lng()
- };
- $('.search-location').text(place.vicinity);
- getLocationList(pos);
- }else{
- var geocoder = new google.maps.Geocoder();
- geocoder.geocode(
- {
- 'address': place.name,
- componentRestrictions: {
- country: 'NZ'
- }
- }
- , function(results, status) {
- if (status == google.maps.GeocoderStatus.OK) {
- pos = {
- lat: results[0].geometry.location.lat(),
- lng: results[0].geometry.location.lng()
- };
- $('.search-location').text(place.name);
- getLocationList(pos, val);
- } else {
- $('.ajax-loader').hide();
- $('.map-results').slideUp();
- $('.no-results').show();
- }
- }
- );
- }
- }
- // Bias the autocomplete object to the user's geographical location,
- // as supplied by the browser's 'navigator.geolocation' object.
- function geolocate() {
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(function(position) {
- var geolocation = {
- lat: position.coords.latitude,
- lng: position.coords.longitude
- };
- var circle = new google.maps.Circle({
- center: geolocation,
- radius: position.coords.accuracy
- });
- autocomplete.setBounds(circle.getBounds());
- });
- }
- }
- //Get the current location of the user
- function getCurrentLocation(){
- //Loading Icon here.
- $('.ajax-loader').show();
- // Try HTML5 geolocation.
- if (navigator.geolocation) {
- navigator.geolocation.getCurrentPosition(function(position) {
- var pos = {
- lat: position.coords.latitude,
- lng: position.coords.longitude
- };
- geocodeLatLng(position.coords.latitude, position.coords.longitude);
- getLocationList(pos);
- }, function(error){
- $('.ajax-loader').hide();
- $('.location-container .current-location, .location-container span').css("display","none");
- console.log(error);
- });
- }
- }
- function getAllStores(){
- $('.all-stores').on('click', function(e){
- e.preventDefault();
- $('#autocomplete').val('New Zealand');
- $('.location-search-btn').click();
- })
- }
- //Get the suburb from the lat lon
- function geocodeLatLng(lat, lon) {
- var geocoder = new google.maps.Geocoder();
- var latlng = {lat: parseFloat(lat), lng: parseFloat(lon)};
- geocoder.geocode({'location': latlng}, function(results, status) {
- if (status === 'OK') {
- if (results[0]) {
- $('.search-location').text(results[0].formatted_address);
- } else {
- window.alert('No results found');
- }
- } else {
- }
- });
- }
- function bookAppointment(){
- $('.book-appointment').on('click', function(e){
- e.preventDefault();
- var appointment_id = $(this).data('appointment_id');
- openLocationIframe(appointment_id);
- });
- }
- function openLocationIframe(appointment_id){
- $('.ajax-loader').show();
- currentURL = window.location.href;
- var url = window.location.href.split('?')[0] + '?appointment_id=' + appointment_id;
- history.pushState(null, null, url);
- var gobj = window[window.GoogleAnalyticsObject];
- var tracker = gobj.getAll()[0];
- var appointmentUrl = 'https://baileynelsoneyewear.gettimely.com/book/embed?location=' + appointment_id;
- if (tracker === undefined) {
- var decoratedUrl = appointmentUrl;
- } else {
- var linker = new window.gaplugins.Linker(tracker);
- var decoratedUrl = linker.decorate(appointmentUrl);
- }
- if (screen.width <= 800) {
- window.location = decoratedUrl;
- } else {
- $('.map-results').slideUp(function(){
- $('#iframeContainer').find('#iframe').html('<iframe src="'+decoratedUrl+'" width="100%" height="800" name="open-appointments-widget-'+appointment_id+'" frameborder="0" style="border: 2px solid #045475"></iframe>');
- $('#iframeContainer').slideDown();
- $('html,body').animate({ scrollTop: $('#iframeContainer').position().top - 150 });
- });
- $('.ajax-loader').hide();
- }
- }
- function showNearbyStores(){
- $('.nearby-stores').on('click', function(e){
- e.preventDefault();
- $('.ajax-loader').show();
- $('#iframeContainer').slideUp(function(){
- if(currentURL){
- history.pushState(null, null, currentURL);
- $('#iframeContainer').find('#iframe').html('');
- $('.map-results').slideDown();
- $('html,body').animate({ scrollTop: $('.map-results').position().top - 150 });
- }else{
- $('#autocomplete').focus();
- }
- $('.ajax-loader').hide();
- });
- });
- }
- function newSearch(){
- $('.new-search').on('click', function(e){
- e.preventDefault();
- $('.map-results').slideUp();
- $('#autocomplete').val('').focus();
- var url = window.location.href.split('?')[0];
- history.pushState(null, null, url);
- });
- }
- ///// STORE LISTING MAP MARKER ICON
- function storeMarker(stores){
- if ($('.store-results').find('.store').length) {
- var markers = window.gMaps[0].bnMarkers;
- var navigationListItems = $('.store-results .store');
- var storeIndexX = 0;
- var storeIndexY = 0;
- var ind = 0;
- while (ind < markers.length) {
- var marker = markers[ind];
- var spriteOffsetX = (storeIndexX * 39);
- var spriteOffsetY = (storeIndexY * 48);
- if (storeIndexX === 9) {
- storeIndexX = 0;
- storeIndexY++;
- } else {
- storeIndexX++;
- }
- var markerSpriteImageUrl = '{{ 'pins1-100.png' | asset_url }}';
- var markerImage = new google.maps.MarkerImage(markerSpriteImageUrl, new google.maps.Size(39, 42), new google.maps.Point(spriteOffsetX, spriteOffsetY), new google.maps.Point(18, 32));
- marker.setOptions({
- icon: markerImage
- });
- var img = $('<div class="navigation-map-marker" />');
- img.css('width', 32);
- img.css('height', 34);
- img.css('background-image', 'url("' + markerSpriteImageUrl + '")');
- img.css('background-position', '-' + spriteOffsetX + 'px -' + spriteOffsetY + 'px');
- $(navigationListItems[ind]).prepend(img);
- /*$(navigationListItems[ind]).mouseenter(function() {
- var obj = $('.navigation-map-marker', this);
- updatePosition(obj, 390);
- });
- $(navigationListItems[ind]).mouseleave(function() {
- var obj = $('.navigation-map-marker', this);
- updatePosition(obj, -390);
- });*/
- ind++;
- }
- }
- }
- function updatePosition(obj, change) {
- var pos = obj.css("background-position");
- if (pos === 'undefined' || pos === null) {
- pos = [obj.css("background-position-x"), obj.css("background-position-y")];
- } else {
- pos = pos.split(" ");
- }
- var x = parseFloat(pos[0]);
- pos[0] = pos[0].replace(x, x + change);
- obj.css("background-position", pos.join(' '));
- }
- /* Thanks to CSS Tricks for pointing out this bit of jQuery
- https://css-tricks.com/equal-height-blocks-in-rows/
- It's been modified into a function called at page load and then each time the page is resized. One large modification was to remove the set height before each new calculation. */
- equalheight = function(container){
- var currentTallest = 0,
- currentRowStart = 0,
- rowDivs = new Array(),
- $el,
- topPosition = 0;
- $(container).each(function() {
- $el = $(this);
- $($el).height('auto')
- topPostion = $el.position().top;
- if (currentRowStart != topPostion) {
- for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
- rowDivs[currentDiv].height(currentTallest);
- }
- rowDivs.length = 0; // empty the array
- currentRowStart = topPostion;
- currentTallest = $el.height();
- rowDivs.push($el);
- } else {
- rowDivs.push($el);
- currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest);
- }
- for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) {
- rowDivs[currentDiv].height(currentTallest);
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement