Ekom è una catena della grande distribuzione specializzata come discount che presenta oltre 110 punti vendita, alcuni dei quali in franchising. Ekom ha sede a Genova ed è molto radicato in Liguria e Piemonte, ma ha ampliato la presenza geografica anche alla Valle d'Aosta, alla Toscana e alla Lombardia.
\n' +
' ▼\n' +
''
// Pointers
var shop_info_el = info_window_el.querySelector('vf-shop-info')
var leaflets_el = info_window_el.querySelector('vf-leaflets')
var leaflets_browser_el = info_window_el.querySelector('vf-leaflets-browser')
var up = info_window_el.querySelector('a[href="#up"]')
var down = info_window_el.querySelector('a[href="#down"]')
var leaflet_idx
var leaflets_no
up.onclick = function ( e )
{
if ( leaflet_idx > 0 )
{
--leaflet_idx
leaflets_el.setAttribute('data-slot', leaflet_idx)
}
else
{
//console.warn('reached the top...')
//this.classList.add('disabled')
}
if ( e )
e.preventDefault()
return false
}
down.onclick = function ( e )
{
if ( leaflet_idx + 1 < leaflets_no )
{
++leaflet_idx
leaflets_el.setAttribute('data-slot', leaflet_idx)
}
else
{
//console.warn('reached the bottom...')
//this.classList.add('disabled')
}
if ( e )
e.preventDefault()
return false
}
var slideshow_handle
var FREQUENCY = 4000
function doSlide ()
{
if ( ++leaflet_idx == leaflets_no )
leaflet_idx = 0
leaflets_el.setAttribute('data-slot', leaflet_idx)
//console.warn('slide:', leaflet_idx )
slideshow_handle = setTimeout( doSlide, FREQUENCY )
}
leaflets_browser_el.onmouseenter = function ()
{
// Stop the slideshow...
//console.log('stop the slideshow')
clearTimeout( slideshow_handle )
}
leaflets_browser_el.onmouseleave = function ()
{
// Restore the slideshow...
//console.log('restore the slideshow')
slideshow_handle = setTimeout( doSlide, FREQUENCY )
}
function generateTimeTable ( raw_data )
{
var parsed
// Don't try to parse if there is nothing to be parsed...
if ( raw_data )
{
parsed = raw_data
.replace( /\bchiuso\b/ig, '|×|' )
.replace( /lu\S+/ig, 'Lu' )
.replace( /ma\S+/ig, 'Ma' )
.replace( /me\S+/ig, 'Me' )
.replace( /gi\S+/ig, 'Gi' )
.replace( /ve\S+/ig, 'Ve' )
.replace( /sa\S+/ig, 'Sa' )
.replace( /do\S+/ig, 'Do' )
.replace( /\bdal\b|\bal\b|\bda\b|\ba\b|\bdalle\b|\balla\b|\balle\b|\be\b/ig, '' )
.replace( /\n+/g, ' ')
.replace( //g, ' ' )
.replace( /\s*\/\s*/g, '|')
.replace( /(\d)([a-z])/ig, '$1 $2')
.replace( /(\d)[\.,](\d)/g, '$1:$2')
.replace( /\s(\d)([^\d])/g, ' 0$1$2')
.replace( /\s+/g, ' ' )
.replace( /(\d)\s+(\d)/g, '$1 - $2')
.replace( /\s+([|-])\s+/g, '$1')
.replace( /\s+/g, '')
.replace( /([a-z])(\d)/ig, '$1|$2')
.replace( /(\d)([a-z])/ig, '$1|$2')
.replace( /([a-z])([A-Z])/g, '$1|$2')
.replace( /\-/g, '|')
.replace( /\|+/g, '|')
.replace( /\|$/g, '')
}
else
{
parsed = '×'
}
return '
' + parsed + '
'
+ '
'
+ '
'
+ '
Lun
'
+ '
Mar-Ven
'
+ '
Sab-Dom
'
+ '
'
+ '
'
+ '
10-13
'
+ '
10-13
'
+ '
chiuso
'
+ '
'
+ '
'
+ '
chiuso
'
+ '
15-18
'
+ '
chiuso
'
+ '
'
+ '
'
}
function goToPvLog(log) {
//console.log(log);
ga('send', 'event', 'Apertura itinerario Google Maps', 'Click', log);
}
// returns html string
function generateShopInfo ( shop, n )
{
var logo_url = vf.app.data.catena.logo.pin
var shop_google_dest = 'https://maps.google.com/maps?daddr=' + shop.address.replace(new RegExp(" ", 'g'), "+") + "+" + shop.city.name.replace(new RegExp(" ", 'g'), "+")
var html = ''
+ '
' + shop.name + '
'
//+ '
' + shop.insegna_pv + '
'
+ '
' + shop.address + '
'
+ '
' + shop.city.name //+ ' (' + shop.sigla_pro + ')
'
+ '
' + shop.phone + '
'
//+ '
' + ( shop.orari_pv || 'ND' ) + '
'
//+ generateTimeTable( shop.orari_pv )
+ 'Vai al Negozio '
switch ( n )
{
case 0:
html += '
nessun volantino attivo
'
break
case 1:
html += '
1 volantino attivo
'
break
default:
html += '
' + n + ' volantini attivi
'
}
return html //'
' + JSON.stringify( pv_data, null, 3 ) + '
'
}
// returns html string
function generateLeaflets ( leaflets )
{
var html = leaflets.reduce( function ( html, v )
{
if (v.type == "ClickToStoreLeaflet" && !v.slide_to_store_campaign) {
var link = v.external_url
var target = "_blank"
} else {
var retailer_slug = PQ2VFRetailers(vf.app.data.catena.slug);
var link = retailer_slug
+ '/' + vf.app.data.catena.section_slug + '-' + retailer_slug
+ '/' + vf.app.data.catena.section_slug + '-' + v.id
var target = "_self"
}
var item
= ''
+ ''
+ ''
+ ''
+ ''
+ ''
+ ''
+ ''
+ ''
+ ''
return html.concat( item )
}
, '' )
return html
//return '
' + JSON.stringify( vol_data, null, 3 ) + '
'
}
// Data passed to this function is the pv.data attached to the marker.
// Initialize the map
function initializeMap ( icons )
{
var marker_bounds
var map_center
var mapOptions
var info_window
var info_window = new google.maps.InfoWindow({ content: info_window_el })
function updateInfoWindow ( marker ) {
data = marker.data
$.post('ajax/getLeafletsByStores', {store_id: data.id}).done(function(reply) {
storeLeaflets = JSON.parse(reply);
var shop_info_html = generateShopInfo( data, storeLeaflets.length )
shop_info_el.innerHTML = shop_info_html
var leaflets_html = generateLeaflets( storeLeaflets )
leaflets_el.innerHTML = leaflets_html
leaflet_idx = 0
leaflets_no = storeLeaflets.length
leaflets_el.setAttribute( 'data-slot', leaflet_idx )
// Start the slideshow (only if we have more than one leaflet to show)
if ( leaflets_no > 1 )
{
slideshow_handle = setTimeout( doSlide, FREQUENCY )
}
switch ( leaflets_no )
{
case 0:
// Hide the whole vf-leaflets-browser
info_window_el.className = 'none'
break
case 1:
// Hide the ▲ and ▼ anchors
info_window_el.className = 'no-slide'
break
default:
info_window_el.className = ''
}
info_window.open( map, marker )
})
}
gmap.updateInfoWindow = updateInfoWindow
function closeInfoWindow ()
{
// Clear timer
clearTimeout( slideshow_handle )
// Close it.
info_window.close()
}
gmap.closeInfoWindow = closeInfoWindow
//! Fires also when the info_window is not visualized
google.maps.event.addListener( info_window, 'content_changed', function ()
{
//console.warn( 'the infoWindow content did change' )
})
//! Do not use to update the content.
google.maps.event.addListener( info_window, 'domready', function ()
{
//console.warn( "the info_window\'s DOM is ready! (executed each time the info_window is displayed)" )
})
//! This event is not triggered when I programmatically close the infowindow.
google.maps.event.addListener( info_window, 'closeclick', function ()
{
// Invoke the cleanup routine.
closeInfoWindow()
window.history.replaceState( null, '', location.pathname + location.search + '#mappa' )
})
marker_bounds = new google.maps.LatLngBounds()
vf.app.data.puntivendita.forEach( function ( pv, i )
{
var latlng
var marker
latlng = new google.maps.LatLng( +pv.latitude, +pv.longitude )
marker_bounds.extend( latlng )
marker = new google.maps.Marker(
{
position: latlng,
title: pv.name,
zIndex: i
})
// Store the information of the pv directly into the marker.
// Still missing the details about the "volantini" to be shown in the infoWindow
marker.data = pv
// Setup some listener on the marker
google.maps.event.addListener( marker, 'click', function () {
// Close the infowindow if already opened.
if ( info_window.map === map )
{
closeInfoWindow()
}
var log = 'Click sul punto vendita ID: ' + pv.id +', Nome: ' + pv.name + ', Catena: ' + vf.app.data.catena.name;
ga('send', 'event', 'Apertura mappa su punto vendita', 'Click', log);
// rewrite history
window.history.replaceState( null, '', location.pathname + location.search + '#mappa-' + pv.id )
updateInfoWindow( this )
})
// Make it front-most on rollover, only if the info_window is not visualized.
google.maps.event.addListener( marker, 'mouseover', function ()
{
if ( info_window.map == null )
marker.setZIndex( markers.length )
})
markers.push( marker )
})
map_center = marker_bounds.getCenter()
mapOptions =
{
zoom: 8,
center: map_center,
scrollwheel: true,
panControl: false,
zoomControl: true,
zoomControlOptions:
{
style: google.maps.ZoomControlStyle.LARGE,
position: google.maps.ControlPosition.LEFT_CENTER
},
mapTypeControl: false,
scaleControl: true,
streetViewControl: false,
overviewMapControl: false
}
map = gmap.map = new google.maps.Map( gmap.el, mapOptions )
//console.log('new google maps')
// Process each marker ad assign to the map
markers.forEach( function ( marker )
{
marker.setMap( map )
marker.setIcon( vf.app.data.catena.logo.pin )
})
// marker Tu sei qui
var latlng
var whereIAm
var vfLocation = decodeURIComponent(getCookie("vf_location"));
if (vfLocation) {
var locationCookie = JSON.parse(vfLocation);
latlng = new google.maps.LatLng(+locationCookie.lat , +locationCookie.lng)
marker_bounds.extend( latlng )
whereIAm = new google.maps.Marker(
{
position: latlng,
icon: null,
title: "Tu sei qui!",
zIndex: markers.length + 1
})
var infoWhere = new google.maps.InfoWindow({ content: 'Tu sei qui!' })
google.maps.event.addListener( whereIAm, 'click', function ()
{
// Close the infowindow if already opened.
if ( info_window.map === map )
{
closeInfoWindow()
}
infoWhere.open( map, this )
})
// Make it front-most on rollover, only if the info_window is not visualized.
google.maps.event.addListener( whereIAm, 'mouseover', function ()
{
if ( infoWhere.map == null )
whereIAm.setZIndex( markers.length + 1 )
})
whereIAm.setIcon(null)
whereIAm.setMap(map)
}
//console.warn('BEFORE FITBOUNDS')
map.fitBounds( marker_bounds )
//console.warn('JUST AFTER FITBOUNDS')
JUST_INITIALIZED = true
// Close the infoWindow if it is open when clicking on the map.
google.maps.event.addListener( map, 'click', function ()
{
if ( info_window.map == null )
{
//console.warn('not open')
}
else
{
closeInfoWindow()
window.history.replaceState( null, '', location.pathname + location.search + '#mappa' )
}
})
// Do something only the first time the map is loaded
google.maps.event.addListenerOnce( map, 'idle', function()
{
gmap.container.setAttribute( 'data-zoom', 14 )
last_center = map.getCenter()
})
// Too costly. do it on "idle"
google.maps.event.addListener( map, 'idle', function()
{
//console.warn( Date.now(), 'updating last known center' )
last_center = map.getCenter()
})
// Is this really necessary?
window.addEventListener( 'resize', function ()
{
google.maps.event.trigger( map, 'resize' )
// Lock position on resize to the last known center...
map.setCenter( last_center )
}
, false )
// √ Done (hopefully)
gmap.INITIALIZED = true
// ! call the callback if set
if ( __cb__ )
{
__cb__()
__cb__ = null
}
}
// Async script loading
function loadScript()
{
var script = document.createElement('script')
script.type = 'text/javascript'
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp'
+ '&callback=initializeGoogleMaps&key=AIzaSyABlhIDEeZ-GiU9XfFYcQMAcePg1LCz0qQ'
document.body.appendChild( script )
}
// Lazy initialization... (script callback)
// Definiamolo global con nome randomico e cancelliamolo subito dopo creazione.
console.warn('Random callback name:', (+Math.random().toFixed( 16 ).slice( 2 )).toString(16) )
//
function initializeGoogleMaps()
{
if ( gmap.INITIALIZED )
{
//console.warn( '(initializeGoogleMaps) Google Maps already initialized' )
return
}
// Preload the icons and initialize the map.
preloadMarkerIcons( initializeMap )
// Mark it as initialized
//gmap.INITIALIZED = true
}
gmap.initialize = function( cb )
{
if ( gmap.INITIALIZED )
{
//console.warn( '(initializeGoogleMapsLazy) Google Maps already initialized' )
cb && cb()
return
}
__cb__ = cb
loadScript()
}
gmap.gotoPuntoVendita = function ( pv )
{
//console.log(marker);
//console.log(pv);
// Find the marker.
var marker = markers.filter( function ( marker )
{
return marker.data === pv
})[0]
// Center the map on the marker...
map.setCenter( marker.position )
google.maps.event.trigger( marker, 'click' )
}
// Invoked from the ctrl when closing via the logo/close
gmap.close = function ()
{
gmap.closeInfoWindow()
}
gmap.markers = markers
vf.app.gmap = gmap
-->