PageSourceSearch

https://gopetition.com/assets/js/jquery.ui.map.js

js gopetition.com collected 2026-10-02 02:28:05 UTC 12,899 bytes, 377 lines download raw bytes

1/*!
2 * jQuery FN Google Map 3.0-rc
3 * http://code.google.com/p/jquery-ui-map/
4 * Copyright (c) 2010 - 2012 Johan Säll Larsson
5 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
6 */
7( function($) {
8
9    /**
10     * @param name:string
11     * @param prototype:object
12     */
13    $.a = function(name, prototype) {
14
15        var namespace = name.split('.')[0];
16        name = name.split('.')[1];
17
18        $[namespace] = $[namespace] || {};
19        $[namespace][name] = function(options, element) {
20            if ( arguments.length ) {
21                this._setup(options, element);
22            }
23        };
24
25        $[namespace][name].prototype = $.extend({
26            'namespace': namespace,
27            'pluginName': name
28        }, prototype);
29
30        $.fn[name] = function(options) {
31
32            var isMethodCall = typeof options === "string",
33                args = Array.prototype.slice.call(arguments, 1),
34                returnValue = this;
35
36            if ( isMethodCall && options.substring(0, 1) === '_' ) {
37                return returnValue;
38            }
39
40            this.each(function() {
41                var instance = $.data(this, name);
42                if (!instance) {
43                    instance = $.data(this, name, new $[namespace][name](options, this));
44                }
45                if (isMethodCall) {
46                    returnValue = instance[options].apply(instance, args);
47                }
48            });
49
50            return returnValue;
51
52        };
53
54    };
55
56    $.a('ui.gmap', {
57
58        /**
59         * Map options
60         * @see http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#MapOptions
61         */
62        options: {
63            mapTypeId: 'roadmap',
64            zoom: 5
65        },
66
67        /**
68         * Get or set options
69         * @param key:string
70         * @param options:object
71         * @return object
72         */
73        option: function(key, options) {
74            if (options) {
75                this.options[key] = options;
76                this.get('map').set(key, options);
77                return this;
78            }
79            return this.options[key];
80        },
81
82        /**
83         * Setup plugin basics,
84         * @param options:object
85         * @param element:node
86         */
87        _setup: function(options, element) {
88            this.el = element;
89            options = options || {};
90            jQuery.extend(this.options, options, { 'center': this._latLng(options.center) });
91            this._create();
92            if ( this._init ) { this._init(); }
93        },
94
95        /**
96         * Instanciate the Google Maps object
97         */
98        _create: function() {
99            var self = this;
100            this.instance = { 'map': new google.maps.Map(self.el, self.options), 'markers': [], 'overlays': [], 'services': [] };
101            google.maps.event.addListenerOnce(self.instance.map, 'bounds_changed', function() { $(self.el).trigger('init', self.instance.map); });
102            self._call(self.options.callback, self.instance.map);
103        },
104
105        /**
106         * Adds a latitude longitude pair to the bounds.
107         * @param position:google.maps.LatLng/string
108         */
109        addBounds: function(position) {
110            var bounds = this.get('bounds', new google.maps.LatLngBounds());
111            bounds.extend(this._latLng(position));
112            this.get('map').fitBounds(bounds);
113            return this;
114        },
115
116        /**
117         * Helper function to check if a LatLng is within the viewport
118         * @param marker:google.maps.Marker
119         */
120        inViewport: function(marker) {
121            var bounds = this.get('map').getBounds();
122            return (bounds) ? bounds.contains(marker.getPosition()) : false;
123        },
124
125        /**
126         * Adds a custom control to the map
127         * @param panel:jquery/node/string
128         * @param position:google.maps.ControlPosition
129         * @see http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#ControlPosition
130         */
131        addControl: function(panel, position) {
132            this.get('map').controls[position].push(this._unwrap(panel));
133            return this;
134        },
135
136        /**
137         * Adds a Marker to the map
138         * @param markerOptions:google.maps.MarkerOptions
139         * @param callback:function(map:google.maps.Map, marker:google.maps.Marker) (optional)
140         * @return $(google.maps.Marker)
141         * @see http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#MarkerOptions
142         */
143        addMarker: function(markerOptions, callback) {
144            markerOptions.map = this.get('map');
145            markerOptions.position = this._latLng(markerOptions.position);
146            var marker = new (markerOptions.marker || google.maps.Marker)(markerOptions);
147            var markers = this.get('markers');
148            if ( marker.id ) {
149                markers[marker.id] = marker;
150            } else {
151                markers.push(marker);
152            }
153            if ( marker.bounds ) {
154                this.addBounds(marker.getPosition());
155            }
156            this._call(callback, markerOptions.map, marker);
157            return $(marker);
158        },
159
160        /**
161         * Clears by type
162         * @param ctx:string	e.g. 'markers', 'overlays', 'services'
163         */
164        clear: function(ctx) {
165            this._c(this.get(ctx));
166            this.set(ctx, []);
167            return this;
168        },
169
170        _c: function(obj) {
171            for ( var property in obj ) {
172                if ( obj.hasOwnProperty(property) ) {
173                    if ( obj[property] instanceof google.maps.MVCObject ) {
174                        google.maps.event.clearInstanceListeners(obj[property]);
175                        if ( obj[property].setMap ) {
176                            obj[property].setMap(null);
177                        }
178                    } else if ( obj[property] instanceof Array ) {
179                        this._c(obj[property]);
180                    }
181                    obj[property] = null;
182                }
183            }
184        },
185
186        /**
187         * Returns the objects with a specific property and value, e.g. 'category', 'tags'
188         * @param ctx:string	in what context, e.g. 'markers'
189         * @param options:object	property:string	the property to search within, value:string, operator:string (optional) (AND/OR)
190         * @param callback:function(marker:google.maps.Marker, isFound:boolean)
191         */
192        find: function(ctx, options, callback) {
193            var obj = this.get(ctx);
194            options.value = $.isArray(options.value) ? options.value : [options.value];
195            for ( var property in obj ) {
196                if ( obj.hasOwnProperty(property) ) {
197                    var isFound = false;
198                    for ( var value in options.value ) {
199                        if ( $.inArray(options.value[value], obj[property][options.property]) > -1 ) {
200                            isFound = true;
201                        } else {
202                            if ( options.operator && options.operator === 'AND' ) {
203                                isFound = false;
204                                break;
205                            }
206                        }
207                    }
208                    callback(obj[property], isFound);
209                }
210            }
211            return this;
212        },
213
214        /**
215         * Returns an instance property by key. Has the ability to set an object if the property does not exist
216         * @param key:string
217         * @param value:object(optional)
218         */
219        get: function(key, value) {
220            var instance = this.instance;
221            if ( !instance[key] ) {
222                if ( key.indexOf('>') > -1 ) {
223                    var e = key.replace(/ /g, '').split('>');
224                    for ( var i = 0; i < e.length; i++ ) {
225                        if ( !instance[e[i]] ) {
226                            if (value) {
227                                instance[e[i]] = ( (i + 1) < e.length ) ? [] : value;
228                            } else {
229                                return null;
230                            }
231                        }
232                        instance = instance[e[i]];
233                    }
234                    return instance;
235                } else if ( value && !instance[key] ) {
236                    this.set(key, value);
237                }
238            }
239            return instance[key];
240        },
241
242        /**
243         * Triggers an InfoWindow to open
244         * @param infoWindowOptions:google.maps.InfoWindowOptions
245         * @param marker:google.maps.Marker (optional)
246         * @param callback:function (optional)
247         * @see http://code.google.com/intl/sv-SE/apis/maps/documentation/javascript/reference.html#InfoWindowOptions
248         */
249        openInfoWindow: function(infoWindowOptions, marker, callback) {
250            var iw = this.get('iw', infoWindowOptions.infoWindow || new google.maps.InfoWindow);
251            iw.setOptions(infoWindowOptions);
252            iw.open(this.get('map'), this._unwrap(marker));
253            this._call(callback, iw);
254            return this;
255        },
256
257        /**
258         * Triggers an InfoWindow to close
259         */
260        closeInfoWindow: function() {
261            if ( this.get('iw') != null ) {
262                this.get('iw').close();
263            }
264            return this;
265        },
266
267        /**
268         * Sets an instance property
269         * @param key:string
270         * @param value:object
271         */
272        set: function(key, value) {
273            this.instance[key] = value;
274            return this;
275        },
276
277        /**
278         * Refreshes the map
279         */
280        refresh: function() {
281            var map = this.get('map');
282            var latLng = map.getCenter();
283            $(map).triggerEvent('resize');
284            map.setCenter(latLng);
285            return this;
286        },
287
288        /**
289         * Destroys the plugin.
290         */
291        destroy: function() {
292            this.clear('markers').clear('services').clear('overlays')._c(this.instance);
293            jQuery.removeData(this.el, this.name);
294        },
295
296        /**
297         * Helper method for calling a function
298         * @param callback
299         */
300        _call: function(callback) {
301            if ( callback && $.isFunction(callback) ) {
302                callback.apply(this, Array.prototype.slice.call(arguments, 1));
303            }
304        },
305
306        /**
307         * Helper method for google.maps.Latlng
308         * @param latLng:string/google.maps.LatLng/Object
309         */
310        _latLng: function(latLng) {
311            if ( !latLng ) {
312                return new google.maps.LatLng(0.0, 0.0);
313            }
314            if ( latLng instanceof google.maps.LatLng ) {
315                return latLng;
316            }
317            else if(latLng instanceof Object)
318            {
319                return new google.maps.LatLng(latLng.lat, latLng.lng);
320            } else {
321                latLng = latLng.replace(/ /g,'').split(',');
322                return new google.maps.LatLng(latLng[0], latLng[1]);
323            }
324        },
325
326        /**
327         * Helper method for unwrapping jQuery/DOM/string elements
328         * @param obj:string/node/jQuery
329         */
330        _unwrap: function(obj) {
331            return (!obj) ? null : ( (obj instanceof jQuery) ? obj[0] : ((obj instanceof Object) ? obj : $('#'+obj)[0]) )
332        }
333
334    });
335
336    jQuery.fn.extend( {
337
338        triggerEvent: function(eventType) {
339            google.maps.event.trigger(this[0], eventType);
340            return this;
341        },
342
343        addEventListener: function(eventType, eventDataOrCallback, eventCallback) {
344            if ( google.maps && this[0] instanceof google.maps.MVCObject ) {
345                google.maps.event.addListener(this[0], eventType, eventDataOrCallback);
346            } else {
347                if (eventCallback) {
348                    this.bind(eventType, eventDataOrCallback, eventCallback);
349                } else {
350                    this.bind(eventType, eventDataOrCallback);
351                }
352            }
353            return this;
354        }
355
356        /*removeEventListener: function(eventType) {
357         if ( google.maps && this[0] instanceof google.maps.MVCObject ) {
358         if (eventType) {
359         google.maps.event.clearListeners(this[0], eventType);
360         } else {
361         google.maps.event.clearInstanceListeners(this[0]);
362         }
363         } else {
364         this.unbind(eventType);
365         }
366         return this;
367         }*/
368
369    });
370
371    jQuery.each(('click rightclick dblclick mouseover mouseout drag dragend').split(' '), function(i, name) {
372        jQuery.fn[name] = function(a, b) {
373            return this.addEventListener(name, a, b);
374        }
375    });
376
377} (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.