1/* 2 * 2007-2016 PrestaShop 3 * 4 * NOTICE OF LICENSE 5 * 6 * This source file is subject to the Open Software License (OSL 3.0) 7 * that is bundled with this package in the file LICENSE.txt. 8 * It is also available through the world-wide-web at this URL: 9 * http://opensource.org/licenses/osl-3.0.php 10 * If you did not receive a copy of the license and are unable to 11 * obtain it through the world-wide-web, please send an email 12 * to [email protected] so we can send you a copy immediately. 13 * 14 * DISCLAIMER 15 * 16 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer 17 * versions in the future. If you wish to customize PrestaShop for your 18 * needs please refer to http://www.prestashop.com for more information. 19 * 20 * @author PrestaShop SA <[email protected]> 21 * @copyright 2007-2016 PrestaShop SA 22 * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) 23 * International Registered Trademark & Property of PrestaShop SA 24 */ 25 26function upsAccessPointWidget(options) { 27 this.options = $.extend({ 28 id : "", 29 default_range : 2, 30 default_postal_code : 81100, 31 choseOnClick : false, 32 onPointChosen : function(point, i) { 33 34 }, 35 searchPoints : function(postalcode, range) { 36 37 } 38 }, options); 39 40 var chosenIndex = null; 41 var current_range = this.options.default_range; 42 var current_postal_code = this.options.default_postal_code; 43 44 var map, markerBounds; 45 var markers = []; 46 var points = []; 47 var infowindow = new google.maps.InfoWindow({ 48 content: '' 49 }); 50 51 var points_have_been_set = false; 52 var widgetCore = this; 53 54 this.initMap = function() { 55 chosenIndex = null; 56 57 markerBounds = new google.maps.LatLngBounds(); 58 map = new google.maps.Map(document.getElementById(this.options.id), { 59 zoom: 10, 60 }); 61 62 function searchControl(controlDiv, map) { 63 // Set CSS for the control border. 64 var searchBox = document.createElement('input'); 65 searchBox.placeholder = upsAccessPointWidgetTranslation.postal_code; 66 searchBox.value = current_postal_code; 67 $(searchBox).css({ 68 float: "left", 69 position: "relative", 70 color: "rgb(0, 0, 0)", 71 "font-family": "Roboto, Arial, sans-serif", 72 "-webkit-user-select" : "none", 73 "font-size" : "11px", 74 "padding" : "8px", 75 "border-bottom-left-radius" : "2px", 76 "border-top-left-radius" : "2px", 77 "-webkit-background-clip" : "padding-box", 78 "box-shadow" : "rgba(0, 0, 0, 0.298039) 0px 1px 4px -1px", 79 "min-width" : "22px", 80 "background-color" : "#FAFAFA", 81 "background-clip" : "padding-box", 82 "border" : "1px", 83 "border-color" : "black" 84 });
85 controlDiv.appendChild(searchBox); 86 87 // Set CSS for the control interior. 88 var findButton = document.createElement('div'); 89 findButton.innerHTML = upsAccessPointWidgetTranslation.find; 90 $(findButton).css({ 91 "float" : "left", 92 "text-align" : "center", 93 "position" : "relative", 94 "color" : "rgb(0, 0, 0)", 95 "font-family" : "Roboto, Arial, sans-serif", 96 "-webkit-user-select" : "none", 97 "font-size" : "11px", 98 "padding" : "8px", 99 "border-bottom-right-radius" : "2px", 100 "border-top-right-radius" : "2px", 101 "-webkit-background-clip" : "padding-box", 102 "box-shadow" : "rgba(0, 0, 0, 0.298039) 0px 1px 4px -1px", 103 "min-width" : "22px", 104 "font-weight" : "500", 105 "background-color" : "rgb(255, 255, 255)", 106 "background-clip" : "padding-box", 107 "cursor" : "pointer" 108 }); 109 controlDiv.appendChild(findButton); 110 111 // Setup the click event listeners: simply set the map to Chicago. 112 findButton.addEventListener('click', function() { 113 if (current_postal_code != searchBox.value && $.trim(searchBox.value) != "") { 114 current_postal_code = searchBox.value; 115 points_have_been_set = false; 116 widgetCore.options.searchPoints(current_postal_code, current_range); 117 } 118 }); 119 } 120 121 var searchBoxDiv = document.createElement('div'); 122 $(searchBoxDiv).css({ 123 margin: "10px", 124 "margin-left": "0px" 125 }); 126 var searchBox = new searchControl(searchBoxDiv, map); 127 128 searchBox.index = 1; 129 map.controls[google.maps.ControlPosition.TOP_LEFT].push(searchBoxDiv); 130 131 map.addListener("zoom_changed", function() { 132 if (points_have_been_set) { 133 var size = findBoundSize(map.getBounds()); 134 var range = Math.ceil(Math.sqrt(Math.pow(size.h, 2) + Math.pow(size.v, 2)) * 0.5 / 1000); 135 if (range > current_range) { 136 current_range = range; 137 widgetCore.options.searchPoints(current_postal_code, current_range); 138 } 139 } 140 }); 141 142 $("#"+this.options.id).on("click",".chooseButton", function() { 143 var index = $(this).data("index"); 144 chosenIndex = index; 145 widgetCore.options.onPointChosen(points[index], index); 146 }) 147 }; 148 149 this.updatePoints = function(pts) { 150 if(pts !== false) { 151 markerBounds = new google.maps.LatLngBounds(); 152 var locationId = null; 153 if (chosenIndex !== null) { 154 locationId = points[chosenIndex].LocationID; 155 } 156 chosenIndex = null; 157 points = pts; 158 deleteMarkers(); 159 for (i = 0; i < points.length; i++) { 160 var point = new google.maps.LatLng(points[i].lat, points[i].lng); 161 markerBounds.extend(point); 162 163 addMarker(point, points[i].name, i); 164 if (locationId !== null && points[i].LocationID == locationId) { 165 chosenIndex = i; 166 this.setActiveMarker(i); 167 } 168 } 169 if (!points_have_been_set) { 170 map.fitBounds(markerBounds); 171 } 172 points_have_been_set = true; 173 } 174 } 175 176 this.fixMapDisplay = function() { 177 if(typeof(map) !== "undefined") { 178 google.maps.event.trigger(map, 'resize'); 179 map.fitBounds(markerBounds); 180 } 181 } 182 183 this.setActiveMarker = function(index) { 184 for (var i = 0; i < markers.length; i++) { 185 markers[i].setIcon('https://maps.google.com/mapfiles/ms/icons/red-dot.png'); 186 } 187 markers[index].setIcon('https://maps.google.com/mapfiles/ms/icons/green-dot.png'); 188 } 189 this.setActiveMarkerByLocationId = function(locationId) { 190 chosenIndex = null; 191 for (var i = 0; i < points.length; i++) { 192 markers[i].setIcon('https://maps.google.com/mapfiles/ms/icons/red-dot.png'); 193 if (points[i].LocationID == locationId) { 194 chosenIndex = i; 195 } 196 } 197 if (chosenIndex !== null) { 198 markers[chosenIndex].setIcon('https://maps.google.com/mapfiles/ms/icons/green-dot.png'); 199 } 200 } 201 202 this.getChosenPoint = function() { 203 if(chosenIndex !== null && typeof points[chosenIndex] != "undefined") { 204 return points[chosenIndex]; 205 } 206 return false;
207 } 208 209 function findBoundSize(bounds) { 210 var ne = bounds.getNorthEast(); 211 var sw = bounds.getSouthWest(); 212 var se = new google.maps.LatLng(sw.lat(), ne.lng()); 213 var nw = new google.maps.LatLng(ne.lat(), sw.lng()); 214 215 var nordDistance = Math.abs(getDistanceFromLatLonInKm(ne, nw)); 216 var southDistance = Math.abs(getDistanceFromLatLonInKm(sw, se)); 217 var eastDistance = Math.abs(getDistanceFromLatLonInKm(ne, se)); 218 var westDistance = Math.abs(getDistanceFromLatLonInKm(sw, nw)); 219 return {h:(nordDistance+southDistance)/2, v:(eastDistance+westDistance)/2}; 220 } 221 222 function getDistanceFromLatLonInKm(p1, p2) { 223 if (typeof(google) == "undefined" || typeof(google.maps) == "undefined" || typeof(google.maps.geometry) == "undefined") { 224 var R = 6371; // Radius of the earth in km 225 var lat1 = p1.lat(); 226 var lon1 = p1.lng(); 227 var lat2 = p2.lat(); 228 var lon2 = p2.lng(); 229 var dLat = deg2rad(lat2-lat1); // deg2rad below 230 var dLon = deg2rad(lon2-lon1); 231 var a = 232 Math.sin(dLat/2) * Math.sin(dLat/2) + 233 Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * 234 Math.sin(dLon/2) * Math.sin(dLon/2) 235 ; 236 var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 237 var d = R * c; // Distance in km 238 return d; 239 } else { 240 return google.maps.geometry.spherical.computeDistanceBetween(p1, p2); 241 } 242 } 243 244 function deg2rad(deg) { 245 return deg * (Math.PI/180) 246 } 247 248 function addMarker(location, title, i) { 249 var marker = new google.maps.Marker({ 250 position: location, 251 map: map, 252 title : title, 253 icon : 'https://maps.google.com/mapfiles/ms/icons/red-dot.png' 254 }); 255 markers.push(marker); 256 257 google.maps.event.addListener(marker, 'click', displayInfoWindow(marker, i)); 258 } 259 260 function displayInfoWindow(marker, i) { 261 return function() { 262 var contentString = '<div class="infosWindows">'+ 263 '<h1 class="firstHeading">'+points[i].name+' ('+points[i].distance.toLowerCase()+')</h1>'+ 264 '<div class="bodyContent">'+ 265 (points[i].imageURL != "" ? '<img src="'+points[i].imageURL+'" class="upsAccessPointImg"/>' : '')+ 266 points[i].address+'<br/>'+points[i].postalCode+' '+points[i].city+ 267 (!widgetCore.options.choseOnClick ? 268 '<br/><button type="button" class="chooseButton" data-index="'+i+'">'+upsAccessPointWidgetTranslation.choose+'</button>' : '')+ 269 '<br/><span class="subtitle">'+upsAccessPointWidgetTranslation.openingHours+'</span>'; 270 271 for(var j = 2; j <= Object.keys(points[i].openingHours).length; j++) { 272 contentString += formatDayOpeningHours(points[i].openingHours[j], j); 273 } 274 contentString += formatDayOpeningHours(points[i].openingHours[1], 1); 275 276 if (points[i].holidays != '') { 277 contentString += '<br/><br/><span class="subtitle">'+upsAccessPointWidgetTranslation.holidays+'</span><br/>'+points[i].holidays; 278 } 279 280 contentString += 281 '</div>'+ 282 '</div>'; 283 infowindow.setContent(contentString); 284 infowindow.open(map, marker); 285 if (widgetCore.options.choseOnClick) { 286 chosenIndex = i; 287 widgetCore.options.onPointChosen(points[i], i); 288 } 289 } 290 } 291 292 function deleteMarkers() { 293 for (var i = 0; i < markers.length; i++) { 294 markers[i].setMap(null); 295 } 296 markers = []; 297 } 298 299 function formatMilitaryTime(time, separtor) { 300 if(typeof separtor == "undefined") 301 separtor = ":"; 302 303 var time = ('00' + time).slice(-4); 304 return time.slice(0,2)+separtor+time.slice(-2); 305 } 306 307 function formatDayOpeningHours(dayInfos, dayN) { 308 var str = ''; 309 if(typeof dayInfos.closed == "undefined" || !dayInfos.closed) { 310 str += '<br/>'+upsAccessPointWidgetTranslation.days[dayN]+' : '; 311 if(typeof dayInfos.allDay != "undefined" && dayInfos.allDay) { 312 str += upsAccessPointWidgetTranslation.opened24hours; 313 } else { 314 for(var i = 0; i < dayInfos.open.length; i++) { 315 if (i > 0) 316 str += " "+upsAccessPointWidgetTranslation.and+" "; 317 str += upsAccessPointWidgetTranslation.from+" "+formatMilitaryTime(dayInfos.open[i],upsAccessPointWidgetTranslation.sep); 318 str += " "+upsAccessPointWidgetTranslation.to+" "+formatMilitaryTime(dayInfos.close[i],upsAccessPointWidgetTranslation.sep); 319 } 320 } 321 } 322 return str; 323 } 324 325} 326 327var upsAccessPointWidgetTranslation = { 328 openingHours : "Opening hours", 329 closed : "Closed", 330 opened24hours : "Opened 24 hours", 331 holidays : "Holidays", 332 days : { 333 1 : "Sun.", 334 2 : "Mon.", 335 3 : "Tues.", 336 4 : "Wed.", 337 5 : "Thurs.", 338 6 : "Fri.", 339 7 : "Sat." 340 }, 341 sep : ":", 342 from : "", 343 to : "-", 344 and : "&",
345 choose : "Choose", 346 postal_code : "Postal code", 347 find : "Find" 348};
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.