Архив

Публикации с меткой ‘javascript’
22 января 2018 Нет комментариев
$('.popup').fancybox({
	helpers:{title:null},
	padding:'0',
	width:'800',
	beforeShow:function(){
		$('input.date').datepicker({
			//options
		});
	}
});
#ui-datepicker-div{
	z-index:9999 !important;
}
Categories: CSS, Javascript Tags: ,
23 ноября 2017 Нет комментариев

В примере таблицы в контенте расположены внутри тега article

$(document).ready(function(){
	$(".article table").wrap('<div class="content_table"></div>');
});
article .content_table{
	overflow-x:auto;
}
Categories: Web Tags: ,
14 ноября 2017 Нет комментариев

Преобразует 00001 в 1:

$(this).data('card');

Оставит 00001 как есть:

$(this).attr('data-card');
Categories: Javascript Tags: ,
8 ноября 2017 Нет комментариев

Чтобы удалить из строки, содержащей html, элемент с его содержимым, в примере div

var str_html=$('.container').html();
str_html=str_html.replace(/<div[^>]*?>[\s\S]*?<\/div>/i,'');

Чтобы удалить элемент с определенным class, в примере class="classname"

str_html=str_html.replace(/<div.*(class="classname")[^>]*?>[\s\S]*?<\/div>/i,'');
Categories: Javascript Tags:
26 октября 2017 Нет комментариев

HTML:

<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" async defer></script>

Javascript:

var map;
function initMap(){
	map=new google.maps.Map(document.getElementById('map'),{
		center:{lat:50.464579,lng:30.522939},
		zoom:17,
		scrollwheel:false,
	});
	var image='/images/icon_pin.png';
	var marker=new google.maps.Marker({
		position:{lat:50.464579,lng:30.522939},
		map:map,
		icon:image,
		title:'Адрес',
	});
	var infowindow=new google.maps.InfoWindow({
		content:'Название компании<br/>Адрес',
	});
	marker.addListener('click',function(){
		infowindow.open(map,marker);
	});
	var styledMapType=new google.maps.StyledMapType(
		[
			{
				"elementType":"geometry",
				"stylers":[
					{
						"color":"#f5f5f5"
					}
				]
			},
			{
				"elementType":"labels.icon",
				"stylers":[
					{
						"visibility":"off"
					}
				]
			},
			{
				"elementType":"labels.text.fill",
				"stylers":[
					{
						"color":"#616161"
					}
				]
			},
			{
				"elementType":"labels.text.stroke",
				"stylers":[
					{
						"color":"#f5f5f5"
					}
				]
			},
			{
				"featureType":"administrative.land_parcel",
				"elementType":"labels.text.fill",
				"stylers":[
					{
						"color":"#bdbdbd"
					}
				]
			},
			{
				"featureType":"poi",
				"elementType":"geometry",
				"stylers":[
					{
						"color":"#eeeeee"
					}
				]
			},
			{
				"featureType":"poi",
				"elementType":"labels.text.fill",
				"stylers":[
					{
						"color":"#757575"
					}
				]
			},
			{
				"featureType":"poi.park",
				"elementType":"geometry",
				"stylers":[
					{
						"color":"#e5e5e5"
					}
				]
			},
			{
				"featureType":"poi.park",
				"elementType":"labels.text.fill",
				"stylers":[
					{
						"color":"#9e9e9e"
					}
				]
			},
			{
				"featureType":"road",
				"elementType":"geometry",
				"stylers":[
					{
						"color":"#ffffff"
					}
				]
			},
			{
				"featureType":"road.arterial",
				"elementType":"labels.text.fill",
				"stylers":[
					{
						"color":"#757575"
					}
				]
			},
			{
				"featureType":"road.highway",
				"elementType":"geometry",
				"stylers":[
					{
						"color":"#dadada"
					}
				]
			},
			{
				"featureType":"road.highway",
				"elementType":"labels.text.fill",
				"stylers":[
					{
						"color":"#616161"
					}
				]
			},
			{
				"featureType":"road.local",
				"elementType":"labels.text.fill",
				"stylers":[
					{
						"color":"#9e9e9e"
					}
				]
			},
			{
				"featureType":"transit.line",
				"elementType":"geometry",
				"stylers":[
					{
						"color":"#e5e5e5"
					}
				]
			},
			{
				"featureType":"transit.station",
				"elementType":"geometry",
				"stylers":[
					{
						"color":"#eeeeee"
					}
				]
			},
			{
				"featureType":"water",
				"elementType":"geometry",
				"stylers":[
					{
						"color":"#c9c9c9"
					}
				]
			},
			{
				"featureType":"water",
				"elementType":"labels.text.fill",
				"stylers":[
					{
						"color":"#9e9e9e"
					}
				]
			}
		],
		{name:'Styled Map'}
	);
	map.mapTypes.set('styled_map',styledMapType);
	map.setMapTypeId('styled_map');
}

CSS:

#map{
	width:570px;
	height:530px;
}

Подробнее: https://developers.google.com/maps/documentation/javascript/
Google Maps APIs Styling Wizard для быстрого создания объекта стиля JSON: https://mapstyle.withgoogle.com/

Categories: Web Tags:
23 октября 2017 Нет комментариев

В примере по адресу определяем район СПБ: Выборгский, Приморский и т.д.
Логика:

  1. Прямым геокодированием определяем координаты объекта.
  2. Обратным геокодированием с kind=district получаем район.

Подключаем api Яндекс:

<script src="//api-maps.yandex.ru/2.1/?lang=ru_RU" type="text/javascript"></script>

Input:

<input type="text" name="address" id="address"/>

JS:

ymaps.ready(init);
function init(){
	var suggestView=new ymaps.SuggestView('address');
	suggestView.events.add('select',function(event){
		var selected=event.get('item').value;
		ymaps.geocode(selected,{
			results:1
		}).then(function(res){
			return ymaps.geocode(res.geoObjects.get(0).geometry.getCoordinates(),{
				kind:'district',
				results:10
			}).then(function(res){
				var founded=res['metaData']['geocoder']['found'];
				$('label.suggest .description').html("");
				for(i=0;i<=founded-1;i++){
					var info=res.geoObjects.get(i).properties.getAll();
					console.log(info);
					var name=info['name'];
					if(name.search('район')!=-1){
						name=name.replace(' район','');
						console.log(name);
					}
				}
			});
		});
	});
}
Categories: Javascript Tags: ,
23 августа 2017 Нет комментариев

Например, когда нужны маркеры разных цветов.
Параметр icon:

var marker=new google.maps.Marker({
	position:iLatlng,
	map:map,
	icon:'http://maps.google.com/mapfiles/ms/icons/green-dot.png',
	//icon:'http://maps.google.com/mapfiles/ms/icons/blue-dot.png',
	//icon:'http://maps.google.com/mapfiles/ms/icons/red-dot.png',
	title:'FullAddress'
});

Если нужно самому динамически указывать цвет:
http://www.googlemapsmarkers.com/v1/COLOR/
или
http://www.googlemapsmarkers.com/v1/LABEL/COLOR/
или
http://www.googlemapsmarkers.com/v1/LABEL/FILL COLOR/LABEL COLOR/STROKE COLOR/
подробнее: http://www.googlemapsmarkers.com/

var icon_green=new google.maps.MarkerImage("http://www.googlemapsmarkers.com/v1/C/008136/ffffff/008136/");
var marker=new google.maps.Marker({
	position:iLatlng,
	map:map,
	icon:icon_green,
	title:'FullAddress'
});
Categories: Javascript Tags: