|
19 | 19 |
|
20 | 20 | // Create the defaults once. DO NOT change these settings in this file - settings should be overridden in the plugin call |
21 | 21 | var defaults = { |
| 22 | + 'ajaxData' : null, |
22 | 23 | 'altDistanceNoResult' : false, |
23 | 24 | 'autoComplete' : false, |
24 | 25 | 'autoCompleteDisableListener': false, |
|
584 | 585 | $('.' + this.settings.formContainer).append('<div class="' + this.settings.loadingContainer +'"></div>'); |
585 | 586 | } |
586 | 587 |
|
| 588 | + // Data to pass with the AJAX request |
| 589 | + var ajaxData = { |
| 590 | + 'origLat' : lat, |
| 591 | + 'origLng' : lng, |
| 592 | + 'origAddress': address, |
| 593 | + 'formattedAddress': formattedAddress, |
| 594 | + 'boundsNorthEast' : northEast, |
| 595 | + 'boundsSouthWest' : southWest |
| 596 | + }; |
| 597 | + |
| 598 | + // Set up extra object for custom extra data to be passed with the AJAX request |
| 599 | + if (this.settings.ajaxData !== null && typeof this.settings.ajaxData === 'object') { |
| 600 | + $.extend(ajaxData, this.settings.ajaxData); |
| 601 | + } |
| 602 | + |
587 | 603 | // AJAX request |
588 | 604 | $.ajax({ |
589 | 605 | type : 'GET', |
590 | 606 | url : this.settings.dataLocation + (this.settings.dataType === 'jsonp' ? (this.settings.dataLocation.match(/\?/) ? '&' : '?') + 'callback=?' : ''), |
591 | 607 | // Passing the lat, lng, address, formatted address and bounds with the AJAX request so they can optionally be used by back-end languages |
592 | | - data: { |
593 | | - 'origLat' : lat, |
594 | | - 'origLng' : lng, |
595 | | - 'origAddress': address, |
596 | | - 'formattedAddress': formattedAddress, |
597 | | - 'boundsNorthEast' : northEast, |
598 | | - 'boundsSouthWest' : southWest |
599 | | - }, |
| 608 | + data : ajaxData, |
600 | 609 | dataType : dataTypeRead, |
601 | 610 | jsonpCallback: (this.settings.dataType === 'jsonp' ? this.settings.callbackJsonp : null) |
602 | 611 | }).done(function(p) { |
|
871 | 880 | */ |
872 | 881 | sortAlpha: function(locationsarray) { |
873 | 882 | this.writeDebug('sortAlpha',arguments); |
874 | | - var property = (typeof this.settings.sortBy.prop !== 'undefined') ? this.settings.sortBy.prop : 'name'; |
| 883 | + var property = (this.settings.sortBy.hasOwnProperty('prop') && typeof this.settings.sortBy.prop !== 'undefined') ? this.settings.sortBy.prop : 'name'; |
875 | 884 |
|
876 | | - if (this.settings.sortBy.order === 'desc') { |
| 885 | + if (this.settings.sortBy.hasOwnProperty('order') && this.settings.sortBy.order.toString() === 'desc') { |
877 | 886 | locationsarray.sort(function (a, b) { |
878 | 887 | return b[property].toLowerCase().localeCompare(a[property].toLowerCase()); |
879 | 888 | }); |
|
891 | 900 | */ |
892 | 901 | sortDate: function(locationsarray) { |
893 | 902 | this.writeDebug('sortDate',arguments); |
894 | | - var property = (typeof this.settings.sortBy.prop !== 'undefined') ? this.settings.sortBy.prop : 'date'; |
| 903 | + var property = (this.settings.sortBy.hasOwnProperty('prop') && typeof this.settings.sortBy.prop !== 'undefined') ? this.settings.sortBy.prop : 'date'; |
895 | 904 |
|
896 | | - if (this.settings.sortBy.order === 'desc') { |
| 905 | + if (this.settings.sortBy.hasOwnProperty('order') && this.settings.sortBy.order.toString() === 'desc') { |
897 | 906 | locationsarray.sort(function (a, b) { |
898 | 907 | return new Date(b[property]).getTime() - new Date(a[property]).getTime(); |
899 | 908 | }); |
|
911 | 920 | */ |
912 | 921 | sortNumerically: function (locationsarray) { |
913 | 922 | this.writeDebug('sortNumerically',arguments); |
914 | | - var property = (typeof this.settings.sortBy.prop !== 'undefined') ? this.settings.sortBy.prop : 'distance'; |
| 923 | + var property = ( |
| 924 | + this.settings.sortBy !== null && |
| 925 | + this.settings.sortBy.hasOwnProperty('prop') && |
| 926 | + typeof this.settings.sortBy.prop !== 'undefined' |
| 927 | + ) ? this.settings.sortBy.prop : 'distance'; |
915 | 928 |
|
916 | | - if (this.settings.sortBy.order === 'desc') { |
| 929 | + if (this.settings.sortBy !== null && this.settings.sortBy.hasOwnProperty('order') && this.settings.sortBy.order.toString() === 'desc') { |
917 | 930 | locationsarray.sort(function (a, b) { |
918 | 931 | return ((b[property] < a[property]) ? -1 : ((b[property] > a[property]) ? 1 : 0)); |
919 | 932 | }); |
|
933 | 946 | this.writeDebug('sortCustom',arguments); |
934 | 947 |
|
935 | 948 | // Alphabetically, date, or numeric |
936 | | - if (this.settings.sortBy.method === 'alpha') { |
| 949 | + if (this.settings.sortBy.hasOwnProperty('method') && this.settings.sortBy.method.toString() === 'alpha') { |
937 | 950 | this.sortAlpha(locationsarray); |
938 | | - } else if (this.settings.sortBy.method === 'date') { |
| 951 | + } else if (this.settings.sortBy.hasOwnProperty('method') && this.settings.sortBy.method.toString() === 'date') { |
939 | 952 | this.sortDate(locationsarray); |
940 | 953 | } else { |
941 | 954 | this.sortNumerically(locationsarray); |
|
0 commit comments