PageSourceSearch

https://www.nordfjord.no/modules/custom/common/cbis_product_landing_page/js/widget.js?tm8atk

js nordfjord.no collected 2026-10-02 10:55:18 UTC 13,261 bytes, 499 lines download raw bytes

1/**
2 *
3 */
4
5(function ($, drupalSettings, Vue, VueRouter) {
6  'use strict';
7
8  const msInDay = 1000 * 60 * 60 * 24;
9  var d = new Date();
10
11  Vue.config.devtools = true;
12  Vue.use(VueRouter);
13
14
15  $('.cbis-product-widget-vue-app').each(function () {
16    var $this = $(this);
17    var nodeId = $this.data('node');
18    var fullpageUrl = $this.data('url');
19    var settings = drupalSettings.productList[nodeId];
20
21    new Vue({
22      el: this,
23      delimiters: ['<%', '%>'],
24      router: new VueRouter({
25        mode: 'history',
26        routes: []
27      }),
28      data: {
29        node: nodeId,
30        categoryTree: settings.categoryTree,
31        geoTree: settings.geoTree,
32        facilities: settings.facilities,
33        arenas: settings.arenas,
34        arenaFilter: settings.arenaFilter,
35        showOccasionChooser: settings.showOccasionChooser,
36        showCategoryFilter: false,
37        showGeoFilter: false,
38        showArenaFilter: false,
39        showFacilitiesFilter: false,
40        showOccasionFilter: false,
41        showSearchFilter: false,
42        showDropdownFilter: false,
43        filter: {
44          categories: [],
45          geos: [],
46          arenas: [],
47          facilities: {},
48          search: '',
49          informationFields: [],
50        },
51        facilityMonths: settings.monthData || [],
52        facilityWithoutMonths: [],
53        occasions: null,
54        formats: {
55          input: 'D MMM'
56        },
57        fullUrl: $this.data('url')
58      },
59
60      watch: {
61        '$route': function (to) {
62          this.updateWithData(to.query);
63        },
64
65
66        'filter.categories': function () {
67          this.updateRoute();
68        },
69        'filter.geos': function () {
70          this.updateRoute();
71        },
72        'filter.arenas': function () {
73          this.updateRoute();
74        },
75        'filter.search': function () {
76          this.updateRoute();
77        },
78
79        'occasions': function () {
80          this.updateRoute();
81
82          if (this.occasions && !this.occasionCount) {
83            this.occasionCount = 1;
84          }
85
86          // this.totalFilter = this.filter.categories.length + this.filter.geos.length + this.filter.facilities.length + this.occasionCount;
87        },
88
89        'filter.informationFields': function () {
90          this.updateRoute();
91        },
92      },
93
94      computed: {
95        daySpan: function () {
96          const days = this.getDaySpan(this.drag || this.occasions);
97          return days ? days + ' days' : '';
98        },
99
100        orderByCurrentMonth: function () {
101
102          var m = d.getMonth();
103          var currentYear = d.getFullYear();
104          var oneYearPlus = d.getFullYear() + 1;
105
106          if(this.facilityMonths.length){
107            var fromMonth = this.facilityMonths.splice(m);
108            for (var i = 0; i < fromMonth.length; i++) {
109              fromMonth[i]['year'] = currentYear;
110            }
111
112            for (var j = 0; j < this.facilityMonths.length; j++) {
113              this.facilityMonths[j]['year'] = oneYearPlus;
114            }
115
116            return fromMonth.concat(this.facilityMonths);
117          }
118
119          return [];
120        },
121      },
122
123      mounted: function () {
124        window.addEventListener('resize', this.handleWindowResize);
125      },
126
127      created: function () {
128
129        this.updateWithData(this.$route.query);
130       // this.extractMonthsFromFacilitiesAndSort();
131        this.extractFacilitiesWithoutMonths();
132      },
133
134      methods: {
135        getFullUrl: function(fullUrl, cbisId) {
136          let url = cbisId ? '/'+drupalSettings.path.pathPrefix+'cbis-product/'+cbisId : fullUrl
137          return url
138        },
139        extractMonthsFromFacilitiesAndSort: function () {
140
141          this.facilityMonths = this.facilities
142            .filter(function (key) {
143              return key.id >= 100847 && key.id <= 100858;
144            }).sort(function (a, b) {
145              return a.id - b.id;
146            });
147        },
148
149        extractFacilitiesWithoutMonths: function () {
150
151          this.facilityWithoutMonths = this.facilities
152            .filter(function (key) {
153              return key.id < 100847 || key.id > 100858;
154            });
155        },
156
157        toggleFilterFacilities: function(value, group) {
158          value = parseInt(value);
159          group = group || 'default';
160
161          var facilities = this.filter.facilities[group] || [];
162          var index = facilities.indexOf(value);
163
164          if (index === -1) {
165            facilities.push(value);
166          } else {
167            facilities.splice(index, 1);
168          }
169
170          this.filter.facilities[group] = facilities;
171
172          this.updateRoute();
173        },
174
175        isFacilitySelected: function(value, group) {
176          value = parseInt(value);
177          group = group || 'default';
178
179          var facilities = this.filter.facilities[group] || [];
180          var index = facilities.indexOf(value);
181
182          return -1 !== index;
183        },
184
185        categoryById: function(id) {
186          var found = null;
187          id = parseInt(id);
188          this.categoryTree.children.forEach(function(category) {
189            if (parseInt(category.id) === id) {
190              found = category;
191            }
192          });
193          return found;
194        },
195
196        geoById: function(id) {
197          var found = null;
198          id = parseInt(id);
199          this.geoTree.children.forEach(function(geo) {
200            if (parseInt(geo.id) === id) {
201              found = geo;
202            }
203          });
204          return found;
205        },
206
207        arenaById: function(id) {
208          var found = null;
209          id = parseInt(id);
210          this.arenas.forEach(function(arena) {
211            if (parseInt(arena.id) === id) {
212              found = arena;
213            }
214          });
215          return found;
216        },
217
218        facilityById: function(id) {
219          var found = null;
220          id = parseInt(id);
221          this.facilities.forEach(function(facility) {
222            if (parseInt(facility.id) === id) {
223              found = facility;
224            }
225          });
226          return found;
227        },
228
229        facilityIdExists: function(values){
230          var found = false;
231
232          this.facilities.forEach(function(facility) {
233            if(values.indexOf(parseInt(facility.id)) !== -1){
234              found = true
235            }
236          });
237
238          return found;
239        },
240
241
242        getDaySpan: function (range) {
243          if (!range) return 0;
244          return Math.round((range.end - range.start) / msInDay + 1);
245        },
246
247
248        categoryFilterUpdated: function (categories) {
249          this.filter.categories = categories;
250          this.updateRoute();
251        },
252        geoFilterUpdated: function (geos) {
253          this.filter.geos = geos;
254          this.updateRoute();
255        },
256        arenaFilterUpdated: function (arenas) {
257          this.filter.arenas = arenas;
258          this.updateRoute();
259        },
260
261
262        reset: function () {
263          if (this.flyingXhr) {
264            this.flyingXhr.abort();
265            this.flyingXhr = null;
266          }
267
268          this.busy = false;
269          this.fail = false;
270          this.page = -1;
271          this.totalCount = 0;
272          this.items = [];
273          this.markers = [];
274          this.allProductsLoaded = false;
275        },
276        clearFilters: function () {
277          this.filter = {
278            categories: [],
279            geos: [],
280            arenas: [],
281            facilities: {},
282            search: ''
283          };
284          this.occasions = null;
285          this.occasionCount = null;
286        },
287
288        clearDate: function () {
289          this.occasions = null;
290          this.occasionCount = null;
291        },
292
293        clearSearch: function () {
294          this.filter.search = '';
295        },
296
297        updateRoute: function () {
298          var vue = this;
299          var query = {};
300
301          if (vue.filter.categories.length) {
302            query.categories = vue.filter.categories.join(',');
303          }
304
305          if (vue.filter.geos.length) {
306            query.geos = vue.filter.geos.join(',');
307          }
308
309          if (vue.filter.arenas.length) {
310            query.arenas = vue.filter.arenas.join(',');
311          }
312
313          var facilitiesKeys = Object.keys(vue.filter.facilities);
314
315          if (facilitiesKeys.length) {
316            facilitiesKeys.forEach(function (key) {
317              if(vue.filter.facilities[key].length >= 1){
318                query['facilities.' + key] = vue.filter.facilities[key].join(',');
319              }
320            });
321          }
322
323          if (vue.filter.informationFields.length) {
324            let informationFields = vue.filter.informationFields;
325            let result = informationFields.reduce((acc, { id, value }) => {
326              acc[id] ??= { id, value: [] };
327              if (Array.isArray(value)) {
328                acc[id].value = acc[id].value.concat(value);
329              } else {
330                acc[id].value.push(value);
331              }
332              return acc;
333            }, {});
334
335            let informationFieldsValues = Object.values(result);
336            if (informationFieldsValues.length) {
337              informationFieldsValues.forEach(function (key) {
338                query['informationFields.' + key.id] = key.value.join(',');;
339              })
340            }
341         }
342
343          if (vue.order) {
344            query.order = vue.order;
345          }
346
347          if (vue.filter.search.length) {
348            query.search = vue.filter.search;
349          }
350
351          if (vue.occasions) {
352            query.occasionFrom = vue.formatOccasionDate(vue.occasions.start);
353            query.occasionTo = vue.formatOccasionDate(vue.occasions.end);
354          }
355
356    /*       this.$router.push({
357            path: window.location.pathname,
358            query: query
359          });
360 */
361          vue.fullUrl = fullpageUrl + '?' + $.param(query);
362        },
363
364
365        updateWithData: function (data) {
366          var vue = this;
367
368          vue.reset();
369
370          if (data.categories) {
371            vue.filter.categories = data.categories.split(',')
372          }
373
374          if (data.geos) {
375            vue.filter.geos = data.geos.split(',')
376          }
377
378          if (data.arenas) {
379            vue.filter.arenas = data.arenas.split(',')
380          }
381
382          var facilities = {};
383
384          Object.keys(data).forEach(function(key) {
385
386            if(0 !== key.indexOf('facilities')) {
387              return;
388            }
389
390            var group = key.substring(11);
391
392            if (0 === group.length) {
393              return;
394            }
395
396            var ids = [];
397
398            (data[key] || '')
399              .split(',')
400              .forEach(function (value) {
401                var id = parseInt(value.trim());
402                if (false === isNaN(id)) {
403                  ids.push(id);
404                }
405              });
406
407            if (group.length) {
408              facilities[group] = ids;
409            }
410          });
411
412          vue.filter.facilities = facilities;
413
414          if (data.order) {
415            vue.order = data.order;
416          }
417
418          if (data.search) {
419            vue.filter.search = data.search;
420          }
421
422          if (data.occasionFrom && data.occasionTo) {
423            vue.occasions = {
424              start: new Date(data.occasionFrom),
425              end: new Date(data.occasionTo)
426            };
427          }
428
429        },
430
431        existInArray: function (array, value) {
432          for (var i = 0; i < array.length; i++) {
433            if (array[i] == value) {
434              return true
435            }
436          }
437          return false
438        },
439
440        formatOccasionDate: function (d) {
441          var month = '' + (d.getMonth() + 1),
442              day = '' + d.getDate(),
443              year = d.getFullYear();
444
445          if (month.length < 2) {
446            month = '0' + month;
447          }
448
449          if (day.length < 2) {
450            day = '0' + day;
451          }
452
453          return [year, month, day].join('-');
454        },
455
456        removeFilter: function (type, index) {
457          switch (type) {
458            case 'facilities':
459              this.filter.facilities.splice(this.filter.facilities.indexOf(index), 1);
460              break;
461            case 'categories':
462              this.filter.categories.splice(index, 1);
463              break;
464            case 'geos':
465              this.filter.geos.splice(index, 1);
466              break;
467            case 'arenas':
468              this.filter.arenas.splice(index, 1);
469              break;
470            default:
471              return;
472          }
473        },
474
475
476      },
477
478      directives: {
479        'click-outside': {
480          bind: function (el, binding, vNode) {
481            const bubble = binding.modifiers.bubble;
482            const handler = function (e) {
483              if (bubble || (!el.contains(e.target) && el !== e.target)) {
484                binding.value(e)
485              }
486            };
487            el.__vueClickOutside__ = handler;
488            document.addEventListener('click', handler)
489          },
490
491          unbind: function (el, binding) {
492            document.removeEventListener('click', el.__vueClickOutside__);
493            el.__vueClickOutside__ = null;
494          }
495        }
496      }
497    });
498  });
499})(jQuery, drupalSettings, Vue, VueRouter);

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.