PageSourceSearch

https://hotel-polo74.ru/assets/js/jQuery.ddYMap-1.4.js

js hotel-polo74.ru collected 2026-10-04 08:55:01 UTC 6,985 bytes, 193 lines download raw bytes

1/**
2 * jQuery ddYMap Plugin
3 * @version 1.4 (2015-07-23)
4 * 
5 * @desc A jQuery library that allows Yandex.Maps to be rendered on a page in a simple way.
6 * 
7 * @requires jQuery 1.10.2.
8 * @requires Yandex.Maps 2.1.
9 * 
10 * Parameters of the “$.fn.ddYMap” method (transferred as plain object).
11 * @param placemarks {Array} - Array of placemarks to be put on the map. If there is more than one placemark, the map will be scaled to make all the placemarks visible. Also, a pair of coordinates still can be passed (like it was in 1.2 and earlier). @required
12 * @param placemarks[i] {Object} - Placemark data. @required
13 * @param placemarks[i].latLng {Array} - Placemark coordinates (latitude and longitude). @required
14 * @param [placemarks[i].content=''] {string} - Balloon content.
15 * @param [defaultZoom=15] {number} - Default map zoom.
16 * @param [defaultType='map'] {'map'|'satellite'|'hybrid'|'publicMap'|'publicMapHybrid'} - Default map type: 'map' — schematic map, 'satellite' — satellite map, 'hybrid' — hybrid map, 'publicMap' — public map, 'publicMapHybrid' - hybrid public map.
17 * @param [scrollZoom=false] {boolean} - Allow zoom while scrolling.
18 * @param [mapCenterOffset=[0, 0]] {Array} - Center offset of the map with respect to the center of the map container in pixels.
19 * @param [placemarkOptions={}] {Object} - Placemark options.
20 * @param [controls=[{name: 'zoomControl'},{name: 'typeSelector'},{name: 'fullscreenControl'},{name: 'geolocationControl'},{name: 'rulerControl'}]] {Object} - An array of controls to be added onto the map.
21 * @param [mapOptions={suppressMapOpenBlock: true}] {Object} - Represents yandex map options to be passed to the constructor.
22 * 
23 * @link http://code.divandesign.biz/jquery/ddymap/1.4
24 * 
25 * @copyright 2015, DivanDesign
26 * http://www.DivanDesign.biz
27 */
28
29(function($){
30$.extend(true, {ddYMap: {
31	defaults: {
32		placemarks: new Array(),
33		element: 'map',
34		defaultZoom: 15,
35		defaultType: 'map',
36		scrollZoom: false,
37		mapCenterOffset: false,
38		placemarkOptions: {},
39		controls: [
40			{name: 'zoomControl'},
41			{name: 'typeSelector'},
42			{name: 'fullscreenControl'},
43			{name: 'geolocationControl'},
44			{name: 'rulerControl'}
45		],
46		mapOptions: {
47			suppressMapOpenBlock: true
48		}
49	},
50	//TODO: перенести метод в $.ddTools
51	verifyRenamedParams: function(params, compliance){
52		var result = {},
53			msg = new Array();
54		
55		//Перебираем таблицу соответствия
56		$.each(compliance, function(newName, oldName){
57			//Если старый параметр задан, а новый — нет
58			if ($.type(params[oldName]) != 'undefined' && $.type(params[newName]) == 'undefined'){
59				//Зададим
60				result[newName] = params[oldName];
61				msg.push('“' + oldName + '” must be renamed as “' + newName + '”;');
62			}
63		});
64		
65		if (msg.length > 0){
66			console.group('$.ddYMap');
67			console.warn('Some of the parameters have been renamed. Please, correct the following parameters:');
68			
69			for (var i = 0; i < msg.length; i++){
70				console.warn(msg[i]);
71			}
72			
73			console.groupEnd();
74		}
75		
76		return result;
77	},
78	preparePlacemarks: function(params){
79		var geoObjects = new ymaps.GeoObjectCollection();
80		
81		if (!$.isArray(params.placemarks)){return geoObjects;}
82		
83		//Если передана просто пара координат
84		if (params.placemarks.length == 2 && $.isNumeric(params.placemarks[0]) && $.isNumeric(params.placemarks[1])){
85			//Значит точка одна
86			geoObjects.add(new ymaps.Placemark(params.placemarks, {}, params.placemarkOptions));
87		}else{
88			//Переберём все точки
89			for (var i = 0; i < params.placemarks.length; i++){
90				//Если координаты заданы
91				if (
92					$.isPlainObject(params.placemarks[i]) &&
93					$.isArray(params.placemarks[i].latLng) &&
94					params.placemarks[i].latLng.length == 2
95				){
96					//Создаём метку
97					geoObjects.add(new ymaps.Placemark(params.placemarks[i].latLng, {
98						balloonContent: $.type(params.placemarks[i].content) == 'string' ? $.trim(params.placemarks[i].content) : ''
99					}, params.placemarkOptions));
100				}
101			}
102		}
103		
104		return geoObjects;
105	},
106	init: function(params){
107		var _this = this;
108		
109		$.extend(params, _this.verifyRenamedParams(params, {
110			'defaultZoom': 'zoom',
111			'placemarks': 'latLng'
112		}));
113		
114		params = $.extend({}, _this.defaults, params);
115		
116		ymaps.ready(function(){
117			//Подготавливаем точки
118			var geoObjects = _this.preparePlacemarks(params),
119				//Количество точек
120				geoObjects_len = geoObjects.getLength();
121			
122			//Если точки заданы
123			if (geoObjects_len > 0){
124				params.$element = $(params.element);
125				
126				//Установим высоту у элемента, если она не задана
127				if (params.$element.height() == 0){
128					params.$element.height(400);
129				}
130				
131				//Создаём карту
132				var map = new ymaps.Map(params.element, {
133						center: geoObjects.get(0).geometry.getCoordinates(),
134						zoom: params.defaultZoom,
135						type: 'yandex#' + params.defaultType,
136						controls: []
137					}, params.mapOptions);
138				
139				//Если заданы котролы
140				if($.isArray(params.controls)){
141					$.each(params.controls, function(index, control){
142						if(control.name){
143							//Добавляем их
144							map.controls.add(control.name, control.options);
145						}
146					});
147				}
148				
149				//Если зум не нужен
150				if (!params.scrollZoom){
151					//Выключим масштабирование колесом мыши (т.к. в 2.1 по умолчанию он включён)
152					map.behaviors.disable('scrollZoom');
153				}
154				
155				//Добавляем метки на карту
156				map.geoObjects.add(geoObjects);
157				
158				//Если меток несколько
159				if (geoObjects_len > 1){
160					//Если элемент с картой скрыт
161					if (params.$element.is(':hidden')){
162						//При первом изменении размера (иначе, если карта была скрыта, выйдет плохо)
163						map.events.once('sizechange', function(){
164							//Надо, чтобы они все влезли
165							map.setBounds(geoObjects.getBounds());
166						});
167					}else{
168						//Надо, чтобы они все влезли
169						map.setBounds(geoObjects.getBounds());
170					}
171				}
172				
173				//Если нужно смещение центра карты
174				if ($.isArray(params.mapCenterOffset) && params.mapCenterOffset.length == 2){
175					var position = map.getGlobalPixelCenter();
176					
177					map.setGlobalPixelCenter([position[0] - params.mapCenterOffset[0], position[1] - params.mapCenterOffset[1]]);
178				}
179				
180				params.$element.data('ddYMap', {map: map}).trigger('ddAfterInit');
181			}
182		});
183	}
184}});
185
186$.fn.ddYMap = function(params){
187	var _this = $.ddYMap;
188	
189	return $(this).each(function(){
190		_this.init($.extend(params, {element: this}));
191	});
192};
193})(jQuery);

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.