hoodcms 6.0.6 → 6.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,199 +4,205 @@ import { Alerts } from "../core/Alerts";
4
4
  import { DataList } from "../core/DataList";
5
5
 
6
6
  declare global {
7
- namespace google.maps {
8
- interface Marker {
9
- info: string;
10
- }
11
- }
7
+ namespace google.maps {
8
+ interface Marker {
9
+ info: string;
10
+ }
11
+ }
12
12
  }
13
13
 
14
14
  export interface PropertyServiceOptions {
15
-
16
- listElementId?: string;
17
- mapListElementId?: string;
18
- mapElementId?: string;
19
-
20
- /**
21
- * Called before the data is fetched.
22
- */
23
- onListLoad?: (sender?: HTMLElement) => void;
24
-
25
- /**
26
- * Called before the fetched HTML is rendered to the list. Must return the data back to datalist to render.
27
- */
28
- onListRender?: (html: string, sender?: HTMLElement) => string;
29
- /**
30
- * Called before the data is fetched.
31
- */
32
- onMapLoad?: (data: string, sender?: HTMLElement) => void;
33
-
34
- /**
35
- * Called before the fetched HTML is rendered to the list. Must return the data back to datalist to render.
36
- */
37
- onMapRender?: (sender?: HTMLElement) => string;
38
-
15
+ listElementId?: string;
16
+ mapListElementId?: string;
17
+ mapElementId?: string;
18
+ mapLocationListId?: string;
19
+
20
+ /**
21
+ * Called before the data is fetched.
22
+ */
23
+ onListLoad?: (sender?: HTMLElement) => void;
24
+
25
+ /**
26
+ * Called before the fetched HTML is rendered to the list. Must return the data back to datalist to render.
27
+ */
28
+ onListRender?: (html: string, sender?: HTMLElement) => string;
29
+ /**
30
+ * Called before the data is fetched.
31
+ */
32
+ onMapLoad?: (data: string, sender?: HTMLElement) => void;
33
+
34
+ /**
35
+ * Called before the fetched HTML is rendered to the list. Must return the data back to datalist to render.
36
+ */
37
+ onMapRender?: (sender?: HTMLElement) => string;
38
+
39
+ /**
40
+ * Renders the popup on the property map, location is the property map marker object sent from the server for that property.
41
+ */
42
+ renderPropertyPopup?: (location?: any) => string;
39
43
  }
40
44
 
41
45
  export class PropertyService {
42
- options: PropertyServiceOptions = {
43
- listElementId: 'property-list',
44
- mapListElementId: 'property-map-list',
45
- mapElementId: 'property-map'
46
- };
47
-
48
- constructor(options?: PropertyServiceOptions) {
49
-
50
- this.options = { ...this.options, ...options };
51
-
52
- this.initList();
53
- }
54
-
55
- element: HTMLElement;
56
- list: DataList;
57
- mapListElement: HTMLElement;
58
- mapList: DataList;
59
- map: google.maps.Map = null;
60
- center: google.maps.LatLngLiteral = { lat: 30, lng: -110 };
61
- mapElement: HTMLElement;
62
- markers: any[];
63
-
64
- initList() {
65
-
66
- this.element = document.getElementById(this.options.listElementId);
67
- if (!this.element) {
68
- return;
46
+ options: PropertyServiceOptions = {
47
+ listElementId: "property-list",
48
+ mapListElementId: "property-map-list",
49
+ mapElementId: "property-map",
50
+ mapLocationListId: "property-map-locations",
51
+
52
+ renderPropertyPopup: function (location: any): string {
53
+ return `<div class="card border-0" style="max-width:300px">
54
+ <div style="background-image:url(${location.ImageUrl})" class="rounded img-full img img-wide"></div>
55
+ <div class="card-body border-0">
56
+ <p style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
57
+ <strong>${location.Address1}, ${location.Postcode}</strong>
58
+ </p>
59
+ <p>${location.Description}</p>
60
+ <a href="${location.MarkerUrl}" class="btn btn-block btn-primary">Find out more...</a>
61
+ </div>
62
+ </div>`;
63
+ },
64
+ };
65
+
66
+ constructor(options?: PropertyServiceOptions) {
67
+ this.options = { ...this.options, ...options };
68
+
69
+ this.initList();
70
+ }
71
+
72
+ element: HTMLElement;
73
+ list: DataList;
74
+ mapListElement: HTMLElement;
75
+ mapList: DataList;
76
+ map: google.maps.Map = null;
77
+ center: google.maps.LatLngLiteral = { lat: 30, lng: -110 };
78
+ mapElement: HTMLElement;
79
+ markers: any[];
80
+
81
+ initList() {
82
+ this.element = document.getElementById(this.options.listElementId);
83
+ if (!this.element) {
84
+ return;
85
+ }
86
+
87
+ this.list = new DataList(this.element, {
88
+ onLoad: function (this: PropertyService, sender: HTMLElement = null) {
89
+ if (this.options.onListLoad) {
90
+ this.options.onListLoad(sender);
91
+ }
92
+ }.bind(this),
93
+ onComplete: function (this: PropertyService, data: string, sender: HTMLElement = null) {
94
+ if (this.options.onListRender) {
95
+ this.options.onListRender(data, sender);
96
+ }
97
+ Alerts.log("Finished loading property list.", "info");
98
+ }.bind(this),
99
+ });
100
+ }
101
+
102
+ initMapList() {
103
+ this.mapListElement = document.getElementById(this.options.mapListElementId);
104
+ if (!this.mapElement) {
105
+ return;
106
+ }
107
+
108
+ this.mapList = new DataList(this.mapListElement, {
109
+ onComplete: function (this: PropertyService, data: string, sender: HTMLElement = null) {
110
+ if (this.options.onMapLoad) {
111
+ this.options.onMapLoad(data, sender);
112
+ }
113
+ Alerts.log("Finished loading map list.", "info");
114
+ this.reloadMarkers();
115
+ }.bind(this),
116
+ });
117
+ }
118
+
119
+ initMap() {
120
+ this.mapElement = document.getElementById(this.options.mapElementId);
121
+ if (!this.mapElement) {
122
+ return;
123
+ }
124
+
125
+ this.center = { lat: +this.mapElement.dataset.lat, lng: +this.mapElement.dataset.long };
126
+
127
+ let scrollwheel = false;
128
+ if (this.mapElement.dataset.scrollwheel === "true") {
129
+ scrollwheel = true;
69
130
  }
131
+ this.map = new google.maps.Map(this.mapElement, {
132
+ zoom: +this.mapElement.dataset.zoom || 15,
133
+ center: this.center,
134
+ scrollwheel: scrollwheel,
135
+ });
70
136
 
71
- this.list = new DataList(this.element, {
72
- onLoad: function (this: PropertyService, sender: HTMLElement = null) {
73
-
74
- if (this.options.onListLoad) {
75
- this.options.onListLoad(sender);
76
- }
77
-
78
- }.bind(this),
79
- onComplete: function (this: PropertyService, data: string, sender: HTMLElement = null) {
137
+ $(window).resize(
138
+ function (this: PropertyService) {
139
+ google.maps.event.trigger(this.map, "resize");
140
+ }.bind(this)
141
+ );
80
142
 
81
- if (this.options.onListRender) {
82
- this.options.onListRender(data, sender);
83
- }
84
- Alerts.log('Finished loading property list.', 'info');
143
+ google.maps.event.trigger(this.map, "resize");
85
144
 
86
- }.bind(this)
87
- });
145
+ this.initMapList();
146
+ }
88
147
 
89
- }
90
-
91
- initMapList() {
92
-
93
- this.mapListElement = document.getElementById(this.options.mapListElementId);
94
- if (!this.mapElement) {
95
- return;
96
- }
148
+ reloadMarkers() {
149
+ var infowindow: google.maps.InfoWindow = null;
97
150
 
98
- this.mapList = new DataList(this.mapListElement, {
99
- onComplete: function (this: PropertyService, data: string, sender: HTMLElement = null) {
151
+ if (!this.mapElement) {
152
+ return;
153
+ }
100
154
 
101
- if (this.options.onMapLoad) {
102
- this.options.onMapLoad(data, sender);
103
- }
104
- Alerts.log('Finished loading map list.', 'info');
105
- this.reloadMarkers();
155
+ var map = this.map;
106
156
 
107
- }.bind(this)
108
- });
109
- }
157
+ if (this.markers) {
158
+ for (var i = 0; i < this.markers.length; i++) {
159
+ this.markers[i].setMap(null);
160
+ }
161
+ }
110
162
 
111
- initMap() {
163
+ this.markers = [];
112
164
 
113
- this.mapElement = document.getElementById(this.options.mapElementId);
114
- if (!this.mapElement) {
165
+ var locationsElement = document.getElementById(this.options.mapLocationListId);
166
+ if (!locationsElement) {
115
167
  return;
116
168
  }
117
169
 
118
- this.center = { lat: +this.mapElement.dataset.lat, lng: +this.mapElement.dataset.long };
119
-
120
- this.map = new google.maps.Map(this.mapElement, {
121
- zoom: +this.mapElement.dataset.zoom || 15,
122
- center: this.center,
123
- scrollwheel: false
124
- });
125
-
126
- $(window).resize(function (this: PropertyService) {
127
- google.maps.event.trigger(this.map, 'resize');
128
- }.bind(this));
129
-
130
- google.maps.event.trigger(this.map, 'resize');
131
-
132
- this.initMapList();
133
-
134
- }
135
-
136
- reloadMarkers() {
137
-
138
- var infowindow: google.maps.InfoWindow = null;
139
-
140
- if (!this.mapElement) {
141
- return;
142
- }
143
-
144
- var map = this.map;
145
-
146
- if (this.markers) {
147
- for (var i = 0; i < this.markers.length; i++) {
148
- this.markers[i].setMap(null);
149
- }
150
- }
151
-
152
- this.markers = [];
153
-
154
- var locations = $("#property-map-locations").data('locations');
155
-
156
- locations.map(function (this: PropertyService, location: any, i: number) {
157
-
158
- let marker = new google.maps.Marker({
159
- position: new google.maps.LatLng(+location.Latitude, +location.Longitude),
160
- map: this.map,
161
- optimized: true // makes SVG icons work in IE
162
- });
163
-
164
- if (this.mapElement.dataset.marker) {
165
- marker.setIcon(this.mapElement.dataset.marker);
166
- }
167
-
168
- marker.info = `<div class="card border-0" style="max-width:300px">
169
- <div style="background-image:url(${location.ImageUrl})" class="rounded img-full img img-wide"></div>
170
- <div class="card-body border-0">
171
- <p style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
172
- <strong>${location.Address1}, ${location.Postcode}</strong>
173
- </p>
174
- <p>${location.Description}</p>
175
- <a href="${location.MarkerUrl}" class="btn btn-block btn-primary">Find out more...</a>
176
- </div>
177
- </div>`;
178
-
179
- marker.addListener("click", () => {
180
- if (infowindow) {
181
- infowindow.close();
182
- }
183
- infowindow = new google.maps.InfoWindow({
184
- content: marker.info
185
- });
186
- infowindow.open({
187
- anchor: marker,
188
- map,
189
- shouldFocus: false,
190
- });
191
- });
192
-
193
- this.markers.push(marker);
194
-
195
- }.bind(this));
196
-
197
-
198
- if (this.options.onMapRender) {
199
- this.options.onMapRender();
200
- }
201
- }
170
+ var locations = JSON.parse(locationsElement.dataset.locations);
171
+
172
+ locations.map(
173
+ function (this: PropertyService, location: any, i: number) {
174
+ let marker = new google.maps.Marker({
175
+ position: new google.maps.LatLng(+location.Latitude, +location.Longitude),
176
+ map: this.map,
177
+ optimized: true, // makes SVG icons work in IE
178
+ });
179
+
180
+ if (this.mapElement.dataset.marker) {
181
+ marker.setIcon(this.mapElement.dataset.marker);
182
+ }
183
+
184
+ marker.info = this.options.renderPropertyPopup(location);
185
+
186
+ marker.addListener("click", () => {
187
+ if (infowindow) {
188
+ infowindow.close();
189
+ }
190
+ infowindow = new google.maps.InfoWindow({
191
+ content: marker.info,
192
+ });
193
+ infowindow.open({
194
+ anchor: marker,
195
+ map,
196
+ shouldFocus: false,
197
+ });
198
+ });
199
+
200
+ this.markers.push(marker);
201
+ }.bind(this)
202
+ );
203
+
204
+ if (this.options.onMapRender) {
205
+ this.options.onMapRender();
206
+ }
207
+ }
202
208
  }
@@ -174,7 +174,7 @@ export class MediaService {
174
174
  thumbnailHeight: 80,
175
175
  parallelUploads: 5,
176
176
  paramName: 'files',
177
- acceptedFiles: $("#media-upload").data('types') || ".png,.jpg,.jpeg,.gif",
177
+ acceptedFiles: $("#media-upload").data('types') || ".png,.jpg,.jpeg,.gif,.pdf",
178
178
  autoProcessQueue: true, // Make sure the files aren't queued until manually added
179
179
  previewsContainer: false, // Define the container to display the previews
180
180
  clickable: "#media-add", // Define the element that should be used as click trigger to select files.
@@ -3,120 +3,119 @@ import { Inline } from "./Inline";
3
3
  import { Response } from "./Response";
4
4
 
5
5
  export interface ValidatorOptions {
6
- errorAlert?: string;
6
+ errorAlert?: string;
7
7
 
8
- /**
9
- * Called before the submit of the form data, you can return the data to be serialised.
10
- */
11
- onSubmit?: (sender: Validator) => void;
8
+ /**
9
+ * Called before the submit of the form data, you can return the data to be serialised.
10
+ */
11
+ onSubmit?: (sender: Validator) => void;
12
12
 
13
- /**
14
- * Called when submit is complete.
15
- */
16
- onComplete?: (data: Response, sender?: Validator) => void;
13
+ /**
14
+ * Called when submit is complete.
15
+ */
16
+ onComplete?: (data: Response, sender?: Validator) => void;
17
17
 
18
- /**
19
- * Called when an error occurs.
20
- */
21
- onError?: (jqXHR: any, textStatus: any, errorThrown: any) => void;
18
+ /**
19
+ * Called when an error occurs.
20
+ */
21
+ onError?: (jqXHR: any, textStatus: any, errorThrown: any) => void;
22
22
 
23
- serializationFunction?: () => string;
24
-
25
- useAjax?: boolean;
23
+ serializationFunction?: () => string;
26
24
 
25
+ useAjax?: boolean;
27
26
  }
28
27
 
29
28
  export class Validator {
30
- element: HTMLFormElement;
31
- options: ValidatorOptions = {
32
- errorAlert: 'There are errors on the form, please check your answers and try again.',
33
- useAjax: true
34
- };
35
-
36
- /**
37
- * @param element The datalist element. The element must have a data-url attribute to connect to a feed.
38
- */
39
- constructor(element: HTMLFormElement, options: ValidatorOptions) {
40
-
41
- this.element = element;
42
- if (!this.element) {
43
- return;
44
- }
45
-
46
- this.options.serializationFunction = function (this: Validator) {
47
- let rtn = $(this.element).serialize();
48
- return rtn;
49
- }.bind(this);
50
-
51
- this.options = { ...this.options, ...options };
52
-
53
- this.element.addEventListener('submit', function (this: Validator, e: Event) {
54
- e.preventDefault();
55
- e.stopImmediatePropagation();
56
- this.submitForm();
57
- }.bind(this));
58
- var tag = '[data-submit="#' + this.element.id + '"]';
59
- let submitButtons = $(tag);
60
- if (submitButtons) {
61
- submitButtons.on('click', function (this: Validator, e: Event) {
62
- e.preventDefault();
63
- e.stopImmediatePropagation();
64
- let exit = $(e.currentTarget).data('exit');
65
- if (exit) {
66
- $(this.element).find("input#exit").remove();
67
- $("<input id='exit' />").attr("type", "hidden")
68
- .attr("name", "exit")
69
- .attr("value", "true")
70
- .appendTo(this.element);
71
- }
72
- this.submitForm();
73
- }.bind(this));
74
- }
75
- }
76
-
77
- submitForm() {
78
- this.element.classList.add('was-validated');
79
- if (this.element.checkValidity()) {
80
-
81
- this.element.classList.add('loading');
82
-
83
- let checkboxes = this.element.querySelector('input[type=checkbox]');
84
- if (checkboxes) {
85
- Array.prototype.slice.call(checkboxes)
86
- .forEach(function (checkbox: HTMLInputElement) {
87
- if ($(this).is(':checked')) {
88
- $(this).val('true');
89
- }
90
- });
91
- }
92
-
93
- if (this.options.onSubmit) {
94
- this.options.onSubmit(this);
95
- }
96
-
97
- if (this.options.useAjax) {
98
-
99
- let formData = this.options.serializationFunction();
100
-
101
- $.post(this.element.action, formData, function (this: Validator, data: any) {
102
- if (this.options.onComplete) {
103
- this.options.onComplete(data, this);
104
- }
105
- }.bind(this))
106
- .fail(this.options.onError ?? Inline.handleError);
107
-
108
- } else {
109
-
110
- this.element.submit();
111
-
112
- }
113
-
114
- } else {
115
-
116
- if (this.options.errorAlert) {
117
- Alerts.error(this.options.errorAlert, null, 5000);
118
- }
119
- }
120
-
121
- }
122
- }
29
+ element: HTMLFormElement;
30
+ options: ValidatorOptions = {
31
+ errorAlert: "There are errors on the form, please check your answers and try again.",
32
+ useAjax: true,
33
+ };
34
+
35
+ /**
36
+ * @param element The datalist element. The element must have a data-url attribute to connect to a feed.
37
+ */
38
+ constructor(element: HTMLFormElement, options: ValidatorOptions) {
39
+ this.element = element;
40
+ if (!this.element) {
41
+ return;
42
+ }
43
+
44
+ this.options.serializationFunction = function (this: Validator) {
45
+ let rtn = $(this.element).serialize();
46
+ return rtn;
47
+ }.bind(this);
48
+
49
+ this.options = { ...this.options, ...options };
50
+
51
+ this.element.addEventListener(
52
+ "submit",
53
+ function (this: Validator, e: Event) {
54
+ e.preventDefault();
55
+ e.stopImmediatePropagation();
56
+ this.submitForm();
57
+ }.bind(this)
58
+ );
59
+ var tag = '[data-submit="#' + this.element.id + '"]';
60
+ let submitButtons = $(tag);
61
+ if (submitButtons) {
62
+ submitButtons.on(
63
+ "click",
64
+ function (this: Validator, e: Event) {
65
+ e.preventDefault();
66
+ e.stopImmediatePropagation();
67
+ let exit = $(e.currentTarget).data("exit");
68
+ if (exit) {
69
+ $(this.element).find("input#exit").remove();
70
+ $("<input id='exit' />").attr("type", "hidden").attr("name", "exit").attr("value", "true").appendTo(this.element);
71
+ }
72
+ this.submitForm();
73
+ }.bind(this)
74
+ );
75
+ }
76
+ }
77
+
78
+ submitForm() {
79
+ this.element.classList.add("was-validated");
80
+ if (this.element.checkValidity()) {
81
+ this.element.classList.add("loading");
82
+
83
+ let checkboxes = this.element.querySelector("input[type=checkbox]");
84
+ if (checkboxes) {
85
+ Array.prototype.slice.call(checkboxes).forEach(function (checkbox: HTMLInputElement) {
86
+ if ($(this).is(":checked")) {
87
+ $(this).val("true");
88
+ }
89
+ });
90
+ }
91
+
92
+ if (this.options.onSubmit) {
93
+ this.options.onSubmit(this);
94
+ }
95
+
96
+ if (this.options.useAjax) {
97
+ let formData = this.options.serializationFunction();
98
+
99
+ $.post(
100
+ this.element.action,
101
+ formData,
102
+ function (this: Validator, data: any) {
103
+ if (this.options.onComplete) {
104
+ this.options.onComplete(data, this);
105
+ }
106
+ }.bind(this)
107
+ )
108
+ .fail(this.options.onError ?? Inline.handleError)
109
+ .always(function (this: Validator) {
110
+ this.element.classList.remove("loading");
111
+ }.bind(this));
112
+ } else {
113
+ this.element.submit();
114
+ }
115
+ } else {
116
+ if (this.options.errorAlert) {
117
+ Alerts.error(this.options.errorAlert, null, 5000);
118
+ }
119
+ }
120
+ }
121
+ }
@@ -4,9 +4,9 @@ import { Alerts } from '../core/Alerts';
4
4
  declare global {
5
5
  interface JQuery {
6
6
  exists(): number;
7
- restrictToSlug(): void;
8
- restrictToPageSlug(): void;
9
- restrictToMetaSlug(): void;
7
+ restrictToSlug(restrictPattern?: RegExp): void;
8
+ restrictToPageSlug(restrictPattern?: RegExp): void;
9
+ restrictToMetaSlug(restrictPattern?: RegExp): void;
10
10
  characterCounter(): void;
11
11
  warningAlert(): void;
12
12
  }