import named from 'vinyl-named';
import webpackStream from 'webpack-stream';
const webpack = webpackStream.webpack;
const webpackConfig = {
output: {
filename: '[name].js'
},
module: {
loaders: [
{
loader: 'babel'
}
]
},
watch: !production,
plugins: [
new webpack.NoErrorsPlugin()
],
devtool: production ? null : 'cheap-inline-module-source-map'
};
const production = process.env.NODE_ENV === 'production';
// Webpack
gulp.task('webpack', (cb) => {
let firstBuildReady = false;
const done = (err) => {
firstBuildReady = true;
if (err) {
return null;
}
};
if (production) {
webpackConfig.plugins.push(
new webpack.optimize.UglifyJsPlugin()
)
}
return combiner(
gulp.src('src/scripts/main.js'),
debug({ title: 'webpack' }),
named(),
webpackStream( webpackConfig, null, done ),
gulp.dest('public/scripts/')
.on('data', () => {
if (firstBuildReady) {
cb();
}
})
);
});
$(document).ready(function(){
/*Приходящие данные*/
var maps =[
{
'id' : 1,
'name' : 'addressMap1',
'center' : [50.443705, 30.530946],
'zoom' : 10,
'controls' : ['smallMapDefaultSet'],
'elemClicking' : 'address__list-item-name-title',
'points' : [
{
id: "235",
iconImageHref: "img/pin-blue.png",
iconLayout: "default#image",
iconImageSize: [30, 42],
center: [50.426472, 30.563022],
name: "м. Старая Деревня",
address: "бул. Трудящихся, д.18, к.1",
phone: "+7 (812) 748-27-52",
timeWork: "9:00–22:00",
location: "https://company.yandex.ru/",
power: "Откр. 0,5 Тл и закр. 1,5 Тл"
},
{
id: "236",
iconImageHref: "img/pin-blue.png",
iconLayout: "default#image",
iconImageSize: [30, 42],
center: [50.426472, 31.563022],
name: "м. Старая Деревня2",
address: "бул. Трудящихся, д.18, к.1",
phone: "+7 (815) 748-27-52",
timeWork: "9:00–20:00",
location: "https://company.yandex.ru/",
power: "Откр. 0,5 Тл и закр. 1,5 Тл"
}
]
},
{
'id' : 2,
'name' : 'addressMap2',
'center' : [50.443705, 30.530946],
'zoom' : 10,
'controls' : ['smallMapDefaultSet'],
'elemClicking' : 'address__list-item-name-title',
'points' : [
{
id: "237",
iconImageHref: "img/pin-blue.png",
iconLayout: "default#image",
iconImageSize: [30, 42],
center: [50.426472, 30.563022],
name: "м. Старая Деревня",
address: "бул. Трудящихся, д.18, к.1",
phone: "+7 (812) 748-27-52",
timeWork: "9:00–22:00",
location: "https://company.yandex.ru/",
power: "Откр. 0,5 Тл и закр. 1,5 Тл"
},
{
id: "238",
iconImageHref: "img/pin-blue.png",
iconLayout: "default#image",
iconImageSize: [30, 42],
center: [55.751574, 37.573856],
name: "м. Старая Деревня2",
address: "бул. Трудящихся, д.18, к.1",
phone: "+7 (815) 748-27-52",
timeWork: "9:00–20:00",
location: "https://company.yandex.ru/",
power: "Откр. 0,5 Тл и закр. 1,5 Тл"
}
]
}
] ;
var myMap=[];
var myMapWrap = [];
var placemarks =[];
/*Иницилизируем карты*/
ymaps.ready(init);
function init() {
for (var elem = 0, length = maps.length; elem < length; elem++) {
var points = maps[elem].points;
var collection = new ymaps.GeoObjectCollection();
myMap[elem] = new ymaps.Map(maps[elem].name, {
center: maps[elem].center,
zoom: maps[elem].zoom,
controls: maps[elem].controls
});
for (var i = 0, l = points.length; i < l; i++) {
/*Добавляем на карту колекцию геообъектов*/
myMap[elem].geoObjects.add(collection);
//Создаем балун по данным points
placemarks[points[i].id] = new ymaps.Placemark(
points[i].center,
{
balloonContent: [
'<address>',
'<strong>'+points[i].name+'</strong>',
'<br/>',
points[i].address,
'<br/>',
points[i].phone,
'<br/>',
points[i].timeWork,
'<br/>',
'<a href="'+points[i].timeWork+'">Схема проезда</a>',
'</address>'
].join('')
},
{
iconLayout: 'default#image',
iconImageHref: points[i].iconImageHref,
iconImageSize: points[i].iconImageSize,
iconImageOffset: points[i].iconImageOffset
}
);
/*Добавляем в колекцию наши балуны*/
collection.add(placemarks[points[i].id]);
}
myMapWrap[elem]=myMap[elem];
myMapWrap[elem].setBounds(myMapWrap[elem].geoObjects.getBounds());
}
}
$('.'+maps[0].elemClicking).click(function(){
var id = $(this).attr('balloon-id');
mapId = $(this).attr('map-id');
//Центруем карту
myMapWrap[mapId].panTo(placemarks[id].geometry.getCoordinates());
//Показываем балун как только отцентруется карта
setTimeout(function () {
placemarks[id].balloon.open();
}, 800);
});
});
var success = 'Ваше сообщение успешно доставлено! </br> Благодарим за обращение :)'
$('form').submit(function(e){
var form = $(this);
$.ajax({
type: form.attr('method'),
data: form.serialize(),
dataType: "json",
url: form.attr('action'),
beforeSend: function() {
//alert('Подождите');
//показываем загрузку если она нужна
//можем выключать кнопку отправки
},
success: function(data) {
if (data == 1){
form.children('.alert').removeClass('danger').addClass('success').html(success);
}
else {
form.children('.alert').removeClass('success').addClass('danger').html(data.errors);
}
}
});
e.preventDefault();
});
$data = ['errors' => 'сюда пишите ошибку'];
return json_encode($data);