PageSourceSearch

https://www.moralanova.cat/wp-content/themes/moralanova-child/js/custom.js?ver=1.0

js moralanova.cat collected 2026-10-02 13:35:49 UTC 10,919 bytes, 373 lines download raw bytes

1(function($) {
2
3    /*
4     *  new_map
5     *
6     *  This function will render a Google Map onto the selected jQuery element
7     *
8     *  @type	function
9     *  @date	8/11/2013
10     *  @since	4.3.0
11     *
12     *  @param	$el (jQuery element)
13     *  @return	n/a
14     */
15
16    function new_map($el) {
17
18        // var
19        var $markers = $el.find('.marker');
20
21
22        // vars
23        var args = {
24            zoom: 16,
25            center: new google.maps.LatLng(0, 0),
26            mapTypeId: google.maps.MapTypeId.ROADMAP
27        };
28
29
30        // create map	        	
31        var map = new google.maps.Map($el[0], args);
32
33
34        // add a markers reference
35        map.markers = [];
36
37
38        // add markers
39        $markers.each(function() {
40
41            add_marker($(this), map);
42
43        });
44
45
46        // center map
47        center_map(map);
48
49
50        // return
51        return map;
52
53    }
54
55    /*
56     *  add_marker
57     *
58     *  This function will add a marker to the selected Google Map
59     *
60     *  @type	function
61     *  @date	8/11/2013
62     *  @since	4.3.0
63     *
64     *  @param	$marker (jQuery element)
65     *  @param	map (Google Map object)
66     *  @return	n/a
67     */
68
69    function add_marker($marker, map) {
70
71        // var
72        var latlng = new google.maps.LatLng($marker.attr('data-lat'), $marker.attr('data-lng'));
73
74        // create marker
75        var marker = new google.maps.Marker({
76            position: latlng,
77            map: map
78        });
79
80        // add to array
81        map.markers.push(marker);
82
83        // if marker contains HTML, add it to an infoWindow
84        if ($marker.html()) {
85            // create info window
86            var infowindow = new google.maps.InfoWindow({
87                content: $marker.html()
88            });
89
90            // show info window when marker is clicked
91            google.maps.event.addListener(marker, 'click', function() {
92
93                infowindow.open(map, marker);
94
95            });
96        }
97
98    }
99
100    /*
101     *  center_map
102     *
103     *  This function will center the map, showing all markers attached to this map
104     *
105     *  @type	function
106     *  @date	8/11/2013
107     *  @since	4.3.0
108     *
109     *  @param	map (Google Map object)
110     *  @return	n/a
111     */
112
113    function center_map(map) {
114
115        // vars
116        var bounds = new google.maps.LatLngBounds();
117
118        // loop through all markers and create bounds
119        $.each(map.markers, function(i, marker) {
120
121            var latlng = new google.maps.LatLng(marker.position.lat(), marker.position.lng());
122
123            bounds.extend(latlng);
124
125        });
126
127        // only 1 marker?
128        if (map.markers.length == 1) {
129            // set center of map
130            map.setCenter(bounds.getCenter());
131            map.setZoom(16);
132        } else {
133            // fit to bounds
134            map.fitBounds(bounds);
135        }
136
137    }
138
139    /*
140     *  document ready
141     *
142     *  This function will render each map when the document is ready (page has loaded)
143     *
144     *  @type	function
145     *  @date	8/11/2013
146     *  @since	5.0.0
147     *
148     *  @param	n/a
149     *  @return	n/a
150     */
151    // global var
152    var map = null;
153
154    $(document).ready(function() {
155
156        $('.acf-map').each(function() {
157
158            // create map
159            map = new_map($(this));
160
161        });
162
163        var maxheight = 0;
164
165        $.each(jQuery(".fusion-hide-on-mobile h2"), function() {
166
167            if (maxheight < $(this).height()) maxheight = $(this).height();
168
169        });
170
171        $.each(jQuery(".fusion-hide-on-mobile h2"), function() {
172
173            $(this).height(maxheight);
174
175        });
176
177        if (jQuery(".fusion-page-title-bar.fusion-page-title-bar-breadcrumbs.fusion-page-title-bar-left .fusion-breadcrumbs .fusion-breadcrumb-sep").size() >= 3 && jQuery("span[itemtype='http://data-vocabulary.org/Breadcrumb']>span[itemprop='title']").html() == "") {
178
179            jQuery(".fusion-page-title-bar.fusion-page-title-bar-breadcrumbs.fusion-page-title-bar-left .fusion-breadcrumbs .fusion-breadcrumb-sep:first").hide();
180
181        }
182
183
184    });
185
186})(jQuery);
187
188(function() {
189    var jQuery;
190    var server = 'https://widget.ebando.co';
191    var resourcesPath = server + '/files/widget';
192    var timeoutId, options, container;
193    var dateFormat = 'YYYY-MM-DD HH:mm:ss';
194    var userLang = 'es';
195
196    if (!window.eBandoJS) window.eBandoJS = {};
197    eBandoJS.Widget = function(opts) {
198        options = opts;
199
200        if (!options.emptyBandos) {
201            options.emptyBandos = 'No hay bandos en este momento.';
202        }
203
204        if (!options.count) {
205            options.count = 25;
206        }
207
208        log("channel: " + options.channel);
209        container = '.ebando-widget-body';
210    };
211
212    function init() {
213
214        if (window.jQuery === undefined) {
215            log('we need to load jQuery');
216            var script_tag = document.createElement('script');
217            script_tag.setAttribute("type", "text/javascript");
218            script_tag.setAttribute("src", "https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.js");
219            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
220            if (script_tag.attachEvent) {
221                log('oh cool, this is IE');
222                script_tag.onreadystatechange = function() { // for IE
223                    if (this.readyState == 'complete' || this.readyState == 'loaded') {
224                        this.onreadystatechange = null;
225                        scriptLoadHandler();
226                    }
227                };
228            } else {
229                script_tag.onload = scriptLoadHandler;
230            }
231        } else {
232            jQuery = window.jQuery;
233            log('jQuery already exists on page');
234            main();
235        }
236    }
237
238    function scriptLoadHandler() {
239        jQuery = window.jQuery.noConflict();
240        log('jQuery is now loaded');
241        main();
242    }
243
244    function scriptMomentLoadHandler() {
245        userLang = navigator.language || navigator.userLanguage;
246        log("Lang: " + userLang);
247        moment.lang(userLang);
248
249        render();
250        callBandos();
251    }
252
253    function main() {
254
255        jQuery(document).ready(function() {
256            jQuery('head').append('<link href="' + resourcesPath + '/css/widget.css" rel="stylesheet" type="text/css">');
257
258            if (jQuery(container).size() === 0) {
259                jQuery('.ebando-widget').append('<div class="ebando-widget-body" style="border-radius: 0px; border-color: #e0dede;"></div>');
260            }
261
262            if (!options.channel) {
263                updateStatus('Error: No se ha configurado el canal de la población!');
264                return;
265            }
266
267            var script_tag = document.createElement('script');
268            script_tag.setAttribute("type", "text/javascript");
269            script_tag.setAttribute("src", resourcesPath + "/js/moment-with-langs.min.js");
270            (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(script_tag);
271            if (script_tag.attachEvent) {
272                //console.log('oh cool, this is IE');
273                script_tag.onreadystatechange = function() { // for IE
274                    if (this.readyState == 'complete' || this.readyState == 'loaded') {
275                        this.onreadystatechange = null;
276                        scriptMomentLoadHandler();
277                    }
278                };
279            } else {
280                script_tag.onload = scriptMomentLoadHandler;
281            }
282        });
283    }
284
285    function render() {
286        // build the widget
287        var markup = '';
288        markup = markup + '<div class="ebando-header"><span><a href="http://www.ebando.es"><img src="' + resourcesPath + '/img/logo_widget.png" alt="eBando.es" title="eBando.es" width="20" height="20"/></a></span></div>';
289        jQuery(container).append(markup);
290    }
291
292    function callBandos() {
293        var xmlhttp;
294        if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
295            xmlhttp = new XMLHttpRequest();
296        } else { // code for IE6, IE5
297            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
298        }
299        xmlhttp.onreadystatechange = function() {
300            log("Status: " + xmlhttp.status + " - Ready: " + xmlhttp.readyState);
301            if (xmlhttp.readyState == 4) {
302                if (xmlhttp.status == 200) {
303                    var jsonResp = JSON.parse(xmlhttp.responseText);
304                    serverResponse(jsonResp);
305                } else {
306                    serverResponse();
307                }
308            }
309        }
310        var params = "count=" + options.count;
311        xmlhttp.open("POST", server + "/widget/bandos/" + options.channel, true);
312        //Send the proper header information along with the request
313        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
314        xmlhttp.timeout = 4005;
315        xmlhttp.send(params);
316    }
317
318    function serverResponse(data) {
319        log(data);
320
321        if (!data || data.status != "ok" || data.bandos.length == 0) {
322            updateStatus(options.emptyBandos);
323        } else {
324            updateBandos(data.bandos);
325        }
326    }
327
328    function updateStatus(msg) {
329        if (jQuery(container + ' p.message').length === 0) {
330            jQuery(container).append('<p class="message"></p>');
331        }
332        jQuery(container + ' p.message').html(msg);
333    }
334
335    function updateBandos(bandos) {
336        if (jQuery(container + ' ul.bandos').length === 0) {
337            jQuery(container).append('<ul class="bandos"></ul>');
338        }
339
340        for (var i = 0, len = bandos.length; i < len; i++) {
341            var bando = bandos[i];
342            jQuery(container + ' ul.bandos').append('<li class="item">
342' + printItemList(bando) + '</li>');
343        }
344
345        jQuery(container).append('<div class="ebando-footer">&copy; ' + moment().format("YYYY") + ' <a href="http://www.ebando.es">eBando</a></div>');
346    }
347
348    function printItemList(item) {
349        var tag = '';
350        var itemHtml = '';
351        for (var i = 0, len = item.tags.length; i < len; i++) {
352            tag = '<span class="item-tag">' + item.tags[i] + '</span><br />';
353        }
354
355        var dateBando = moment(item.datePublish, dateFormat, userLang);
356        var dateString = dateBando.format('DD MMMM YYYY, HH:mm:ss');
357
358        if (!dateBando.isBefore(moment().subtract('days', 7)))
359            dateString = dateBando.fromNow();
360
361        itemHtml = '<div class="item-title">' + item.title + '<br />';
362        itemHtml = itemHtml + '<span class="item-date">' + dateString + '</span></div>';
363        itemHtml = itemHtml + '<div class="item-body">' + item.body.replace(/<img[^>]*>/g, ""); + tag + '</div>';
364        itemHtml = itemHtml + '<hr>';
365        return itemHtml;
366    }
367
368    function log(msg) {
369        // console.log(msg);
370    }
371
372    init();
373})();

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.