PageSourceSearch

https://www.comnews.pro/sites/all/modules/yamaps/misc/yamaps.init.js?v=2.x

js comnews.pro collected 2026-10-05 01:20:23 UTC 6,438 bytes, 190 lines download raw bytes

1/**
2 * @file
3 * Initialize object extended to jQuery for global operations.
4 */
5
6(function($) {
7  Drupal.behaviors.yamapsInit = {
8    attach: function (context, settings) {
9      ymaps.ready(function() {
10        $.extend({
11          yaMaps: {
12            // Maps on page.
13            maps: {},
14            // Map tools.
15            _mapTools: [],
16            // Layouts.
17            _layouts: {},
18            addMapTools: function(button) {
19              this._mapTools.push(button);
20            },
21            getMapTools: function(Map) {
22              var tools = [];
23              for (var i in this._mapTools) {
24                if (typeof this._mapTools[i] == 'function') {
25                  tools.push(this._mapTools[i](Map));
26                }
27                else {
28                  tools.push(this._mapTools[i]);
29                }
30              }
31              return tools;
32            },
33            addLayout: function(name, layout) {
34              this._layouts[name] = layout;
35            },
36            initLayouts: function() {
37              for (var name in this._layouts) {
38                ymaps.layout.storage.add(name, this._layouts[name]);
39              }
40            }
41          }
42        });
43
44        $.yaMaps.BaseYamapsObject = {
45          // Edit mode for line and polygon.
46          startEditing: function(active) {
47            this.element.editor.startEditing();
48            if (active) {
49              this.element.editor.state.set('drawing', true);
50            }
51            this.element.editor.events.add('statechange', function(e) {
52              if (this.element.editor.state.get('editing') && !this.element.editor.state.get('drawing')) {
53                this.openBalloon();
54              }
55            }, this);
56          },
57          // Set line and polygon colors.
58          setColor: function(strokeColor, fillColor) {
59            this.element.options.set('strokeColor', $.yaMaps.colors[strokeColor]);
60            if (typeof fillColor != 'undefined') {
61              this.element.options.set('fillColor', $.yaMaps.colors[fillColor]);
62            }
63          },
64          // Set balloon content.
65          setContent: function(balloonContent) {
66            this.element.properties.set('balloonContent', balloonContent);
67          },
68          // Set opacity.
69          setOpacity: function(opacity) {
70            this.element.options.set('opacity', opacity);
71          },
72          // Set line width.
73          setWidth: function(width) {
74            this.element.options.set('strokeWidth', width);
75          },
76          // Open balloon.
77          openBalloon: function() {
78            this.element.balloon.open();
79          },
80          // Close balloon.
81          closeBalloon: function() {
82            this.element.balloon.close();
83          },
84          // Remove line or polygon.
85          remove: function() {
86            this.getParent().remove(this);
87            this.exportParent();
88          },
89          // Set parent object.
90          setParent: function(Parent) {
91            this.parent = Parent;
92          },
93          // Get parent.
94          getParent: function() {
95            return this.parent;
96          },
97          // Export line or polygon.
98          Export: function() {
99            var coords = this.element.geometry.getCoordinates();
100            if (typeof coords[0] != 'object' || coords.length < 1) {
101              return;
102            }
103            else {
104              if (typeof coords[0][0] == 'object') {
105                if (coords[0].length < 3) {
106                  return;
107                }
108              }
109              else if (coords.length < 2) {
110                return;
111              }
112            }
113            var props = this.element.properties.getAll();
114            var data = {
115              coords: coords,
116              params: {
117                strokeWidth: props.strokeWidth,
118                strokeColor: props.strokeColor,
119                balloonContent: props.balloonContent,
120                opacity: props.opacity
121              }
122            };
123            if (typeof props.fillColor != 'undefined') {
124              data.params.fillColor = props.fillColor;
125            }
126            return data;
127          },
128          // Export all lines or polygons on this map to html container.
129          exportParent: function() {
130            var collection = this.getParent();
131            if (collection) {
132              collection.exportToHTML();
133            }
134          },
135          // Init object.
136          _init: function(element) {
137            this.element = element;
138            this.parent = null;
139
140            // Actions for export lines or polygons.
141            this.element.events.add(['geometrychange', 'propertieschange'], this.exportParent, this);
142
143            // Line or polygon initialization parameters.
144            this.element.properties.set('element', this);
145            var properties = this.element.properties.getAll();
146            this.setColor(properties.strokeColor, properties.fillColor);
147            this.setOpacity(properties.opacity);
148            this.setWidth(properties.strokeWidth);
149          }
150        };
151
152        $.yaMaps.BaseYamapsObjectCollection = {
153          // Export collection.
154          Export: function() {
155            var data = [];
156            this.elements.each(function(element) {
157              var content = element.properties.get('element').Export();
158              if (content) {
159                data.push(content);
160              }
161            });
162            return data;
163          },
164          // Export collection to HTML element.
165          exportToHTML: function() {
166            var elements = this.Export();
167            var mapId = this.elements.getMap().container.getElement().parentElement.id;
168            var $storage = $(this.storagePrefix + mapId);
169            $storage.val(JSON.stringify(elements));
170          },
171          // Add new line or polygon to collection.
172          add: function(Element) {
173            Element.setParent(this);
174            this.elements.add(Element.element);
175            return Element;
176          },
177          // Remove polygon or line from map.
178          remove: function(Element) {
179            this.elements.remove(Element.element);
180          },
181          // Init object.
182          _init: function(options) {
183            this.elements = new ymaps.GeoObjectCollection();
184            this.elements.options.set(options);
185          }
186        };
187      });
188    }
189  }
190})(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.