hoodcms 5.0.13 → 5.0.16

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.
@@ -0,0 +1,1123 @@
1
+ /*!
2
+ * hoodcms v5.0.16
3
+ * A fully customisable content management system built in ASP.NET Core 5 & Bootstrap 5.
4
+ * Written by George Whysall, 2022
5
+ * Released under the GPL-3.0 License.
6
+ */
7
+ (function (global, factory) {
8
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('sweetalert2'), require('@simonwep/pickr'), require('tinymce/tinymce'), require('bootstrap')) :
9
+ typeof define === 'function' && define.amd ? define(['exports', 'sweetalert2', '@simonwep/pickr', 'tinymce/tinymce', 'bootstrap'], factory) :
10
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.hood = {}, global.Swal));
11
+ })(this, (function (exports, Swal) { 'use strict';
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var Swal__default = /*#__PURE__*/_interopDefaultLegacy(Swal);
16
+
17
+ /*! *****************************************************************************
18
+ Copyright (c) Microsoft Corporation.
19
+
20
+ Permission to use, copy, modify, and/or distribute this software for any
21
+ purpose with or without fee is hereby granted.
22
+
23
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
24
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
25
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
26
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
27
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
28
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
29
+ PERFORMANCE OF THIS SOFTWARE.
30
+ ***************************************************************************** */
31
+ /* global Reflect, Promise */
32
+
33
+ var extendStatics = function(d, b) {
34
+ extendStatics = Object.setPrototypeOf ||
35
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
36
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
37
+ return extendStatics(d, b);
38
+ };
39
+
40
+ function __extends(d, b) {
41
+ extendStatics(d, b);
42
+ function __() { this.constructor = d; }
43
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
44
+ }
45
+
46
+ var __assign = function() {
47
+ __assign = Object.assign || function __assign(t) {
48
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
49
+ s = arguments[i];
50
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
51
+ }
52
+ return t;
53
+ };
54
+ return __assign.apply(this, arguments);
55
+ };
56
+
57
+ "function"!=typeof Object.create&&(Object.create=function(t){function o(){}return o.prototype=t,new o}),function(t,o,i,s){var n={_positionClasses:["bottom-left","bottom-right","top-right","top-left","bottom-center","top-center","mid-center"],_defaultIcons:["success","error","info","warning"],init:function(o,i){this.prepareOptions(o,t.toast.options),this.process();},prepareOptions:function(o,i){var s={};"string"==typeof o||o instanceof Array?s.text=o:s=o,this.options=t.extend({},i,s);},process:function(){this.setup(),this.addToDom(),this.position(),this.bindToast(),this.animate();},setup:function(){var o="";if(this._toastEl=this._toastEl||t("<div></div>",{"class":"jq-toast-single"}),o+='<span class="jq-toast-loader"></span>',this.options.allowToastClose&&(o+='<span class="close-jq-toast-single">&times;</span>'),this.options.text instanceof Array){this.options.heading&&(o+='<h2 class="jq-toast-heading">'+this.options.heading+"</h2>"),o+='<ul class="jq-toast-ul">';for(var i=0;i<this.options.text.length;i++)o+='<li class="jq-toast-li" id="jq-toast-item-'+i+'">'+this.options.text[i]+"</li>";o+="</ul>";}else this.options.heading&&(o+='<h2 class="jq-toast-heading">'+this.options.heading+"</h2>"),o+=this.options.text;this._toastEl.html(o),this.options.bgColor!==!1&&this._toastEl.css("background-color",this.options.bgColor),this.options.textColor!==!1&&this._toastEl.css("color",this.options.textColor),this.options.textAlign&&this._toastEl.css("text-align",this.options.textAlign),this.options.icon!==!1&&(this._toastEl.addClass("jq-has-icon"),-1!==t.inArray(this.options.icon,this._defaultIcons)&&this._toastEl.addClass("jq-icon-"+this.options.icon)),this.options["class"]!==!1&&this._toastEl.addClass(this.options["class"]);},position:function(){"string"==typeof this.options.position&&-1!==t.inArray(this.options.position,this._positionClasses)?"bottom-center"===this.options.position?this._container.css({left:t(o).outerWidth()/2-this._container.outerWidth()/2,bottom:20}):"top-center"===this.options.position?this._container.css({left:t(o).outerWidth()/2-this._container.outerWidth()/2,top:20}):"mid-center"===this.options.position?this._container.css({left:t(o).outerWidth()/2-this._container.outerWidth()/2,top:t(o).outerHeight()/2-this._container.outerHeight()/2}):this._container.addClass(this.options.position):"object"==typeof this.options.position?this._container.css({top:this.options.position.top?this.options.position.top:"auto",bottom:this.options.position.bottom?this.options.position.bottom:"auto",left:this.options.position.left?this.options.position.left:"auto",right:this.options.position.right?this.options.position.right:"auto"}):this._container.addClass("bottom-left");},bindToast:function(){var t=this;this._toastEl.on("afterShown",function(){t.processLoader();}),this._toastEl.find(".close-jq-toast-single").on("click",function(o){o.preventDefault(),"fade"===t.options.showHideTransition?(t._toastEl.trigger("beforeHide"),t._toastEl.fadeOut(function(){t._toastEl.trigger("afterHidden");})):"slide"===t.options.showHideTransition?(t._toastEl.trigger("beforeHide"),t._toastEl.slideUp(function(){t._toastEl.trigger("afterHidden");})):(t._toastEl.trigger("beforeHide"),t._toastEl.hide(function(){t._toastEl.trigger("afterHidden");}));}),"function"==typeof this.options.beforeShow&&this._toastEl.on("beforeShow",function(){t.options.beforeShow();}),"function"==typeof this.options.afterShown&&this._toastEl.on("afterShown",function(){t.options.afterShown();}),"function"==typeof this.options.beforeHide&&this._toastEl.on("beforeHide",function(){t.options.beforeHide();}),"function"==typeof this.options.afterHidden&&this._toastEl.on("afterHidden",function(){t.options.afterHidden();});},addToDom:function(){var o=t(".jq-toast-wrap");if(0===o.length?(o=t("<div></div>",{"class":"jq-toast-wrap"}),t("body").append(o)):(!this.options.stack||isNaN(parseInt(this.options.stack,10)))&&o.empty(),o.find(".jq-toast-single:hidden").remove(),o.append(this._toastEl),this.options.stack&&!isNaN(parseInt(this.options.stack),10)){var i=o.find(".jq-toast-single").length,s=i-this.options.stack;s>0&&t(".jq-toast-wrap").find(".jq-toast-single").slice(0,s).remove();}this._container=o;},canAutoHide:function(){return this.options.hideAfter!==!1&&!isNaN(parseInt(this.options.hideAfter,10))},processLoader:function(){if(!this.canAutoHide()||this.options.loader===!1)return !1;var t=this._toastEl.find(".jq-toast-loader"),o=(this.options.hideAfter-400)/1e3+"s",i=this.options.loaderBg,s=t.attr("style")||"";s=s.substring(0,s.indexOf("-webkit-transition")),s+="-webkit-transition: width "+o+" ease-in; -o-transition: width "+o+" ease-in; transition: width "+o+" ease-in; background-color: "+i+";",t.attr("style",s).addClass("jq-toast-loaded");},animate:function(){var t=this;if(this._toastEl.hide(),this._toastEl.trigger("beforeShow"),"fade"===this.options.showHideTransition.toLowerCase()?this._toastEl.fadeIn(function(){t._toastEl.trigger("afterShown");}):"slide"===this.options.showHideTransition.toLowerCase()?this._toastEl.slideDown(function(){t._toastEl.trigger("afterShown");}):this._toastEl.show(function(){t._toastEl.trigger("afterShown");}),this.canAutoHide()){var t=this;o.setTimeout(function(){"fade"===t.options.showHideTransition.toLowerCase()?(t._toastEl.trigger("beforeHide"),t._toastEl.fadeOut(function(){t._toastEl.trigger("afterHidden");})):"slide"===t.options.showHideTransition.toLowerCase()?(t._toastEl.trigger("beforeHide"),t._toastEl.slideUp(function(){t._toastEl.trigger("afterHidden");})):(t._toastEl.trigger("beforeHide"),t._toastEl.hide(function(){t._toastEl.trigger("afterHidden");}));},this.options.hideAfter);}},reset:function(o){"all"===o?t(".jq-toast-wrap").remove():this._toastEl.remove();},update:function(t){this.prepareOptions(t,this.options),this.setup(),this.bindToast();}};t.toast=function(t){var o=Object.create(n);return o.init(t,this),{reset:function(t){o.reset(t);},update:function(t){o.update(t);}}},t.toast.options={text:"",heading:"",showHideTransition:"fade",allowToastClose:!0,hideAfter:3e3,loader:!0,loaderBg:"#9EC600",stack:5,position:"bottom-left",bgColor:!1,textColor:!1,textAlign:"left",icon:!1,beforeShow:function(){},afterShown:function(){},beforeHide:function(){},afterHidden:function(){}};}(jQuery,window);
58
+
59
+ var BootstrapSwal = Swal__default["default"].mixin({
60
+ customClass: {
61
+ confirmButton: 'btn btn-success m-1 px-3',
62
+ cancelButton: 'btn btn-danger m-1 px-3'
63
+ },
64
+ buttonsStyling: false
65
+ });
66
+ var Alerts = /** @class */ (function () {
67
+ function Alerts() {
68
+ }
69
+ Alerts.log = function (message, type) {
70
+ if (type === void 0) { type = 'message'; }
71
+ if (!document.body.classList.contains('dev-mode')) {
72
+ return;
73
+ }
74
+ switch (type) {
75
+ case 'error':
76
+ console.error(message);
77
+ break;
78
+ case 'message':
79
+ console.log(message);
80
+ break;
81
+ case 'warning':
82
+ console.warn(message);
83
+ break;
84
+ case 'info':
85
+ console.info(message);
86
+ break;
87
+ }
88
+ };
89
+ Alerts.error = function (message, title, hideAfter) {
90
+ if (title === void 0) { title = null; }
91
+ if (hideAfter === void 0) { hideAfter = null; }
92
+ $.toast({
93
+ heading: title,
94
+ text: message,
95
+ icon: 'error',
96
+ position: 'bottom-left',
97
+ loader: false,
98
+ bgColor: '#d0100b',
99
+ textColor: 'white',
100
+ hideAfter: hideAfter
101
+ });
102
+ };
103
+ Alerts.warning = function (message, title, hideAfter) {
104
+ if (title === void 0) { title = null; }
105
+ if (hideAfter === void 0) { hideAfter = null; }
106
+ $.toast({
107
+ heading: title,
108
+ text: message,
109
+ icon: 'error',
110
+ position: 'bottom-left',
111
+ loader: false,
112
+ bgColor: '#ef9007',
113
+ textColor: 'white',
114
+ hideAfter: hideAfter
115
+ });
116
+ };
117
+ Alerts.message = function (message, title, hideAfter) {
118
+ if (title === void 0) { title = null; }
119
+ if (hideAfter === void 0) { hideAfter = null; }
120
+ $.toast({
121
+ heading: title,
122
+ text: message,
123
+ icon: 'error',
124
+ position: 'bottom-left',
125
+ loader: false,
126
+ bgColor: '#222222',
127
+ textColor: 'white',
128
+ hideAfter: hideAfter
129
+ });
130
+ };
131
+ Alerts.success = function (message, title, hideAfter) {
132
+ if (title === void 0) { title = null; }
133
+ if (hideAfter === void 0) { hideAfter = null; }
134
+ $.toast({
135
+ heading: title,
136
+ text: message,
137
+ icon: 'error',
138
+ position: 'bottom-left',
139
+ loader: false,
140
+ bgColor: '#28a745',
141
+ textColor: 'white',
142
+ hideAfter: hideAfter
143
+ });
144
+ };
145
+ Alerts.alert = function (message, title, icon, hideAfter) {
146
+ if (title === void 0) { title = null; }
147
+ if (icon === void 0) { icon = 'info'; }
148
+ if (hideAfter === void 0) { hideAfter = 10000; }
149
+ switch (icon) {
150
+ case 'error':
151
+ Alerts.error(message, title, hideAfter);
152
+ break;
153
+ case 'warning':
154
+ Alerts.warning(message, title, hideAfter);
155
+ break;
156
+ case 'info':
157
+ Alerts.message(message, title, hideAfter);
158
+ break;
159
+ case 'success':
160
+ Alerts.success(message, title, hideAfter);
161
+ break;
162
+ }
163
+ };
164
+ Alerts.sweetAlert = function (options, callback) {
165
+ BootstrapSwal.fire(options).then(function (result) {
166
+ callback(result);
167
+ });
168
+ };
169
+ Alerts.confirm = function (options, callback) {
170
+ var baseOptions = {
171
+ showCancelButton: true,
172
+ footer: null,
173
+ title: 'Are you sure?',
174
+ html: 'Are you sure you want to do this?',
175
+ confirmButtonText: 'Ok',
176
+ cancelButtonText: 'Cancel'
177
+ };
178
+ Alerts.sweetAlert(__assign(__assign({}, baseOptions), options), callback);
179
+ };
180
+ Alerts.prompt = function (options, callback) {
181
+ var baseOptions = {
182
+ input: 'text',
183
+ inputAttributes: {
184
+ autocapitalize: 'off'
185
+ },
186
+ showCancelButton: true,
187
+ icon: 'info',
188
+ footer: '<span class="text-warning"><i class="fa fa-exclamation-triangle"></i> This cannot be undone.</span>',
189
+ confirmButtonText: 'Ok',
190
+ cancelButtonText: 'Cancel'
191
+ };
192
+ Alerts.sweetAlert(__assign(__assign({}, baseOptions), options), callback);
193
+ };
194
+ Alerts.prototype.log = function (message, type) {
195
+ if (type === void 0) { type = 'message'; }
196
+ Alerts.log(message, type);
197
+ };
198
+ Alerts.prototype.error = function (message, title, hideAfter) {
199
+ if (title === void 0) { title = null; }
200
+ if (hideAfter === void 0) { hideAfter = null; }
201
+ Alerts.error(message, title, hideAfter);
202
+ };
203
+ Alerts.prototype.warning = function (message, title, hideAfter) {
204
+ if (title === void 0) { title = null; }
205
+ if (hideAfter === void 0) { hideAfter = null; }
206
+ Alerts.warning(message, title, hideAfter);
207
+ };
208
+ Alerts.prototype.message = function (message, title, hideAfter) {
209
+ if (title === void 0) { title = null; }
210
+ if (hideAfter === void 0) { hideAfter = null; }
211
+ Alerts.message(message, title, hideAfter);
212
+ };
213
+ Alerts.prototype.success = function (message, title, hideAfter) {
214
+ if (title === void 0) { title = null; }
215
+ if (hideAfter === void 0) { hideAfter = null; }
216
+ Alerts.success(message, title, hideAfter);
217
+ };
218
+ Alerts.prototype.alert = function (message, title, icon, hideAfter) {
219
+ if (icon === void 0) { icon = 'info'; }
220
+ if (hideAfter === void 0) { hideAfter = 10000; }
221
+ Alerts.alert(message, message, icon, hideAfter);
222
+ };
223
+ Alerts.prototype.sweetAlert = function (options, callback) {
224
+ Alerts.sweetAlert(options, callback);
225
+ };
226
+ Alerts.prototype.confirm = function (options, callback) {
227
+ Alerts.confirm(options, callback);
228
+ };
229
+ Alerts.prototype.prompt = function (options, callback) {
230
+ Alerts.prompt(options, callback);
231
+ };
232
+ return Alerts;
233
+ }());
234
+
235
+ var Inline = /** @class */ (function () {
236
+ function Inline() {
237
+ }
238
+ Inline.load = function (tag, options) {
239
+ var _a;
240
+ var $tag = $(tag);
241
+ $tag.addClass('loading');
242
+ if (options.onLoad) {
243
+ options.onLoad(tag);
244
+ }
245
+ var url = $tag.data('url');
246
+ $.get(url, function (data) {
247
+ if (options.onRender) {
248
+ data = options.onRender(data, tag);
249
+ }
250
+ $tag.html(data);
251
+ $tag.removeClass('loading');
252
+ if (options.onComplete) {
253
+ options.onComplete(data, tag);
254
+ }
255
+ })
256
+ .fail((_a = options.onError) !== null && _a !== void 0 ? _a : Inline.handleError);
257
+ };
258
+ Inline.task = function (url, sender, complete, error) {
259
+ if (complete === void 0) { complete = null; }
260
+ if (error === void 0) { error = null; }
261
+ if (sender) {
262
+ sender.classList.add('loading');
263
+ }
264
+ $.get(url, function (response) {
265
+ if (sender) {
266
+ sender.classList.remove('loading');
267
+ }
268
+ if (complete) {
269
+ complete(response, sender);
270
+ }
271
+ })
272
+ .fail(error !== null && error !== void 0 ? error : Inline.handleError);
273
+ };
274
+ Inline.post = function (url, sender, complete, error) {
275
+ if (complete === void 0) { complete = null; }
276
+ if (error === void 0) { error = null; }
277
+ if (sender) {
278
+ sender.classList.add('loading');
279
+ }
280
+ $.post(url, function (response) {
281
+ if (sender) {
282
+ sender.classList.remove('loading');
283
+ }
284
+ if (complete) {
285
+ complete(response, sender);
286
+ }
287
+ })
288
+ .fail(error !== null && error !== void 0 ? error : Inline.handleError);
289
+ };
290
+ Inline.handleError = function (xhr, textStatus, errorThrown) {
291
+ if (xhr.status === 500) {
292
+ Alerts.error("There was an error processing the content, please contact an administrator if this continues.", "Error " + xhr.status, 10000);
293
+ }
294
+ else if (xhr.status === 404) {
295
+ Alerts.error("The content could not be found.", "Error " + xhr.status, 10000);
296
+ }
297
+ else if (xhr.status === 401) {
298
+ Alerts.error("You are not allowed to view this resource, are you logged in correctly?", "Error " + xhr.status, 10000);
299
+ window.location = window.location;
300
+ }
301
+ };
302
+ return Inline;
303
+ }());
304
+
305
+ /**
306
+ * Attach a data list feed to an HTML element. The element must have a data-url attribute to connect to a feed.
307
+ */
308
+ var DataList = /** @class */ (function () {
309
+ /**
310
+ * @param element The datalist element. The element must have a data-url attribute to connect to a feed.
311
+ */
312
+ function DataList(element, options) {
313
+ this.element = element;
314
+ this.element.hoodDataList = this;
315
+ if (typeof (element) == 'undefined' || element == null) {
316
+ Alerts.log('Could not DataList to element, element does not exist.', 'error');
317
+ return;
318
+ }
319
+ this.options = __assign(__assign({}, this.options), options);
320
+ if ($(this.element).hasClass('query')) {
321
+ var pageUrl = $(this.element).data('url') + window.location.search;
322
+ $(this.element).attr('data-url', pageUrl);
323
+ $(this.element).data('url', pageUrl);
324
+ }
325
+ if (!$(this.element).hasClass('refresh-only')) {
326
+ var listUrl = document.createElement('a');
327
+ listUrl.href = $(this.element).data('url');
328
+ this.reload(new URL(listUrl.href));
329
+ }
330
+ $(this.element).on('click', '.pagination a, a.hood-inline-list-target', function (e) {
331
+ e.preventDefault();
332
+ var url = document.createElement('a');
333
+ url.href = e.currentTarget.href;
334
+ var listUrl = document.createElement('a');
335
+ listUrl.href = $(this.element).data('url');
336
+ listUrl.search = url.search;
337
+ this.reload(new URL(listUrl.href));
338
+ }.bind(this));
339
+ $('body').on('submit', "form.inline[data-target=\"#".concat(this.element.id, "\"]"), function (e) {
340
+ e.preventDefault();
341
+ var $form = $(e.currentTarget);
342
+ var listUrl = document.createElement('a');
343
+ listUrl.href = $(this.element).data('url');
344
+ listUrl.search = "?" + $form.serialize();
345
+ this.reload(new URL(listUrl.href));
346
+ }.bind(this));
347
+ }
348
+ DataList.prototype.reload = function (url) {
349
+ if (url === void 0) { url = null; }
350
+ if (url) {
351
+ if (history.pushState && $(this.element).hasClass('query')) {
352
+ var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + (url.href.contains('?') ? "?" + url.href.substring(url.href.indexOf('?') + 1) : '');
353
+ window.history.pushState({ path: newurl }, '', newurl);
354
+ }
355
+ $(this.element).data('url', url);
356
+ }
357
+ Inline.load(this.element, __assign({}, this.options));
358
+ };
359
+ return DataList;
360
+ }());
361
+
362
+ var Validator = /** @class */ (function () {
363
+ /**
364
+ * @param element The datalist element. The element must have a data-url attribute to connect to a feed.
365
+ */
366
+ function Validator(element, options) {
367
+ this.options = {
368
+ errorAlert: 'There are errors on the form, please check your answers and try again.',
369
+ useAjax: true
370
+ };
371
+ this.element = element;
372
+ if (!this.element) {
373
+ return;
374
+ }
375
+ this.options.serializationFunction = function () {
376
+ var rtn = $(this.element).serialize();
377
+ return rtn;
378
+ }.bind(this);
379
+ this.options = __assign(__assign({}, this.options), options);
380
+ this.element.addEventListener('submit', function (e) {
381
+ e.preventDefault();
382
+ e.stopImmediatePropagation();
383
+ this.submitForm();
384
+ }.bind(this));
385
+ var tag = '[data-submit="#' + this.element.id + '"]';
386
+ var submitButtons = $(tag);
387
+ if (submitButtons) {
388
+ submitButtons.on('click', function (e) {
389
+ e.preventDefault();
390
+ e.stopImmediatePropagation();
391
+ var exit = $(e.currentTarget).data('exit');
392
+ if (exit) {
393
+ $(this.element).find("input#exit").remove();
394
+ $("<input id='exit' />").attr("type", "hidden")
395
+ .attr("name", "exit")
396
+ .attr("value", "true")
397
+ .appendTo(this.element);
398
+ }
399
+ this.submitForm();
400
+ }.bind(this));
401
+ }
402
+ }
403
+ Validator.prototype.submitForm = function () {
404
+ var _a;
405
+ this.element.classList.add('was-validated');
406
+ if (this.element.checkValidity()) {
407
+ this.element.classList.add('loading');
408
+ var checkboxes = this.element.querySelector('input[type=checkbox]');
409
+ if (checkboxes) {
410
+ Array.prototype.slice.call(checkboxes)
411
+ .forEach(function (checkbox) {
412
+ if ($(this).is(':checked')) {
413
+ $(this).val('true');
414
+ }
415
+ });
416
+ }
417
+ if (this.options.onSubmit) {
418
+ this.options.onSubmit(this);
419
+ }
420
+ if (this.options.useAjax) {
421
+ var formData = this.options.serializationFunction();
422
+ $.post(this.element.action, formData, function (data) {
423
+ if (this.options.onComplete) {
424
+ this.options.onComplete(data, this);
425
+ }
426
+ }.bind(this))
427
+ .fail((_a = this.options.onError) !== null && _a !== void 0 ? _a : Inline.handleError);
428
+ }
429
+ else {
430
+ this.element.submit();
431
+ }
432
+ }
433
+ else {
434
+ if (this.options.errorAlert) {
435
+ Alerts.error(this.options.errorAlert, null, 5000);
436
+ }
437
+ }
438
+ };
439
+ return Validator;
440
+ }());
441
+
442
+ var Handlers = /** @class */ (function () {
443
+ function Handlers() {
444
+ }
445
+ /**
446
+ * Initialise all default Hood CMS handlers.
447
+ */
448
+ Handlers.prototype.initDefaultHandlers = function () {
449
+ this.checkboxToCsvInput();
450
+ this.iconSelector();
451
+ this.initSelectValues();
452
+ this.scrollHandlers();
453
+ this.selectText();
454
+ this.setValueOnClick();
455
+ this.submitOnChange();
456
+ };
457
+ /**
458
+ * Sets values of any selects that have the value set in data-selected, useful for
459
+ */
460
+ Handlers.prototype.initSelectValues = function (tag) {
461
+ if (tag === void 0) { tag = 'body'; }
462
+ $(tag).find('select[data-selected]').each(this.initSelectValuesHandler);
463
+ };
464
+ Handlers.prototype.initSelectValuesHandler = function (index, element) {
465
+ var sel = $(this).data('selected');
466
+ if (sel !== 'undefined' && sel !== '') {
467
+ var selected = String(sel);
468
+ $(this).val(selected);
469
+ }
470
+ };
471
+ /**
472
+ * Sets up any Hood Icon selector fields, requires the correct HTML setup.
473
+ */
474
+ Handlers.prototype.iconSelector = function (tag) {
475
+ if (tag === void 0) { tag = 'body'; }
476
+ $(tag).find('[data-hood-icon]').each(this.iconSelectorHandler);
477
+ };
478
+ Handlers.prototype.iconSelectorHandler = function (index, element) {
479
+ var $tag = $(this);
480
+ var input = $tag.find('input[data-hood-icon-input]');
481
+ var display = $tag.find('[data-hood-icon-display]');
482
+ var collapse = $tag.find('.collapse');
483
+ $tag.find('[data-hood-icon-key][data-hood-icon-value]').on('click', function () {
484
+ $tag.find('[data-hood-icon-key][data-hood-icon-value]').removeClass('active');
485
+ $(this).addClass('active');
486
+ var key = $(this).data('hoodIconKey');
487
+ var value = $(this).data('hoodIconValue');
488
+ $(this);
489
+ display.html(value);
490
+ input.val(key);
491
+ if (collapse) {
492
+ collapse.removeClass('show');
493
+ }
494
+ });
495
+ };
496
+ /**
497
+ * Submits the form when input is changed, mark inputs with .submit-on-change class.
498
+ */
499
+ Handlers.prototype.selectText = function (tag) {
500
+ if (tag === void 0) { tag = 'body'; }
501
+ $(tag).on('click', '.select-text', this.selectTextHandler);
502
+ };
503
+ Handlers.prototype.selectTextHandler = function () {
504
+ var $this = $(this);
505
+ $this.select();
506
+ // Work around Chrome's little problem
507
+ $this.mouseup(function () {
508
+ // Prevent further mouseup intervention
509
+ $this.unbind("mouseup");
510
+ return false;
511
+ });
512
+ };
513
+ /**
514
+ * Attaches handlers for default scrolling functions, scroll to top, scroll to target (with header.header offset calculated)
515
+ * and scroll to target direct (with no calculated offset).
516
+ */
517
+ Handlers.prototype.scrollHandlers = function (tag) {
518
+ if (tag === void 0) { tag = 'body'; }
519
+ $(tag).on('click', '.scroll-top, .scroll-to-top', this.scrollTop);
520
+ $(tag).on('click', '.scroll-target, .scroll-to-target', this.scrollTarget);
521
+ $(tag).on('click', '.scroll-target-direct, .scroll-to-target-direct', this.scrollTargetDirect);
522
+ };
523
+ Handlers.prototype.scrollTop = function (e) {
524
+ if (e)
525
+ e.preventDefault();
526
+ $('html, body').animate({ scrollTop: 0 }, 800);
527
+ return false;
528
+ };
529
+ Handlers.prototype.scrollTarget = function (e) {
530
+ if (e)
531
+ e.preventDefault();
532
+ var url = $(this).attr('href').split('#')[0];
533
+ if (url !== window.location.pathname && url !== "") {
534
+ return;
535
+ }
536
+ var target = this.hash;
537
+ var $target = $(target);
538
+ var $header = $('header.header');
539
+ var headerOffset = 0;
540
+ if ($header) {
541
+ headerOffset = $header.height();
542
+ }
543
+ if ($(this).data('offset'))
544
+ $('html, body').stop().animate({
545
+ 'scrollTop': $target.offset().top - $(this).data('offset')
546
+ }, 900, 'swing');
547
+ else
548
+ $('html, body').stop().animate({
549
+ 'scrollTop': $target.offset().top - headerOffset
550
+ }, 900, 'swing');
551
+ };
552
+ Handlers.prototype.scrollTargetDirect = function () {
553
+ var scrollTop = $('body').scrollTop();
554
+ var top = $($(this).attr('href')).offset().top;
555
+ $('html, body').animate({
556
+ scrollTop: top
557
+ }, Math.abs(top - scrollTop));
558
+ return false;
559
+ };
560
+ /**
561
+ * Compiles any selected checkboxes with matching data-hood-csv-input tags,
562
+ * then saves the CSV list of the values to the input given in the tag.
563
+ */
564
+ Handlers.prototype.checkboxToCsvInput = function (tag) {
565
+ if (tag === void 0) { tag = 'body'; }
566
+ $(tag).on('change', 'input[type=checkbox][data-hood-csv-input]', this.checkboxToCsvInputHandler);
567
+ };
568
+ Handlers.prototype.checkboxToCsvInputHandler = function (e) {
569
+ if (e)
570
+ e.preventDefault();
571
+ // when i change - create an array, with any other checked of the same data-input checkboxes. and add to the data-input referenced tag.
572
+ var items = new Array();
573
+ $('input[data-hood-csv-input="' + $(this).data('hoodCsvInput') + '"]').each(function () {
574
+ if ($(this).is(":checked"))
575
+ items.push($(this).val());
576
+ });
577
+ var id = '#' + $(this).data('input');
578
+ var vals = JSON.stringify(items);
579
+ $(id).val(vals);
580
+ };
581
+ /**
582
+ * Submits the form when input is changed, mark inputs with .submit-on-change class.
583
+ */
584
+ Handlers.prototype.submitOnChange = function (tag) {
585
+ if (tag === void 0) { tag = 'body'; }
586
+ $(tag).on('change', '.submit-on-change', this.submitOnChangeHandler);
587
+ };
588
+ Handlers.prototype.submitOnChangeHandler = function (e) {
589
+ if (e)
590
+ e.preventDefault();
591
+ $(this).parents('form').submit();
592
+ };
593
+ /**
594
+ * Sets the value of the input [data-target] when clicked to the value in [data-value]
595
+ */
596
+ Handlers.prototype.setValueOnClick = function (tag) {
597
+ if (tag === void 0) { tag = 'body'; }
598
+ $(tag).on('click', '.click-select[data-target][data-value]', this.setValueOnClickHandler);
599
+ };
600
+ Handlers.prototype.setValueOnClickHandler = function () {
601
+ var $this = $(this);
602
+ var targetId = '#' + $this.data('target');
603
+ $(targetId).val($this.data('value'));
604
+ $(targetId).trigger('change');
605
+ $('.click-select.clean[data-target="' + $this.data('target') + '"]').each(function () { $(this).removeClass('active'); });
606
+ $('.click-select.clean[data-target="' + $this.data('target') + '"][data-value="' + $this.data('value') + '"]').each(function () { $(this).addClass('active'); });
607
+ };
608
+ return Handlers;
609
+ }());
610
+
611
+ var Loader = /** @class */ (function () {
612
+ function Loader() {
613
+ new CustomEvent('loader-show');
614
+ new CustomEvent('loader-hide');
615
+ }
616
+ Loader.show = function () {
617
+ $('body').trigger('loader-show');
618
+ };
619
+ Loader.hide = function () {
620
+ $('body').trigger('loader-hide');
621
+ };
622
+ return Loader;
623
+ }());
624
+ new Loader();
625
+
626
+ var Uploader = /** @class */ (function () {
627
+ function Uploader() {
628
+ if ($('.image-uploader').length || $('.gallery-uploader').length) {
629
+ $(".upload-progress-bar").hide();
630
+ $('.image-uploader').each(this.singleImage);
631
+ $('.gallery-uploader').each(this.gallery);
632
+ }
633
+ }
634
+ Uploader.prototype.refreshImage = function (sender, data) {
635
+ $(sender.data('preview')).css({
636
+ 'background-image': 'url(' + data.media.smallUrl + ')'
637
+ });
638
+ $(sender.data('preview')).find('img').attr('src', data.media.smallUrl);
639
+ };
640
+ Uploader.prototype.singleImage = function () {
641
+ var tag = '#' + $(this).attr('id');
642
+ var $tag = $(tag);
643
+ var jsontag = '#' + $(this).attr('json');
644
+ var avatarDropzone = null;
645
+ $tag.dropzone({
646
+ url: $tag.data('url'),
647
+ maxFiles: 1,
648
+ paramName: 'file',
649
+ parallelUploads: 1,
650
+ acceptedFiles: $tag.data('types') || ".png,.jpg,.jpeg,.gif",
651
+ autoProcessQueue: true,
652
+ previewsContainer: false,
653
+ clickable: tag,
654
+ init: function () {
655
+ avatarDropzone = this;
656
+ }
657
+ });
658
+ avatarDropzone.on("addedfile", function () {
659
+ });
660
+ avatarDropzone.on("totaluploadprogress", function (progress) {
661
+ $(".upload-progress-bar." + tag.replace('#', '') + " .progress-bar").css({ width: progress + "%" });
662
+ });
663
+ avatarDropzone.on("sending", function (file) {
664
+ $(".upload-progress-bar." + tag.replace('#', '')).show();
665
+ $($tag.data('preview')).addClass('loading');
666
+ });
667
+ avatarDropzone.on("queuecomplete", function (progress) {
668
+ $(".upload-progress-bar." + tag.replace('#', '')).hide();
669
+ });
670
+ avatarDropzone.on("success", function (file, response) {
671
+ if (response.success) {
672
+ if (response.media) {
673
+ $(jsontag).val(JSON.stringify(response.media));
674
+ $($tag.data('preview')).css({
675
+ 'background-image': 'url(' + response.media.smallUrl + ')'
676
+ });
677
+ $($tag.data('preview')).find('img').attr('src', response.media.smallUrl);
678
+ }
679
+ Alerts.success("New image added!");
680
+ }
681
+ else {
682
+ Alerts.error("There was a problem adding the image: " + response.error);
683
+ }
684
+ avatarDropzone.removeFile(file);
685
+ $($tag.data('preview')).removeClass('loading');
686
+ });
687
+ };
688
+ Uploader.prototype.gallery = function () {
689
+ var tag = '#' + $(this).attr('id');
690
+ var $tag = $(tag);
691
+ var previewNode = document.querySelector(tag + "-template");
692
+ previewNode.id = "";
693
+ var previewTemplate = previewNode.parentNode.innerHTML;
694
+ previewNode.parentNode.removeChild(previewNode);
695
+ var galleryDropzone = null;
696
+ $tag.dropzone({
697
+ url: $tag.data('url'),
698
+ thumbnailWidth: 80,
699
+ thumbnailHeight: 80,
700
+ parallelUploads: 5,
701
+ previewTemplate: previewTemplate,
702
+ paramName: 'files',
703
+ acceptedFiles: $tag.data('types') || ".png,.jpg,.jpeg,.gif",
704
+ autoProcessQueue: true,
705
+ previewsContainer: "#previews",
706
+ clickable: ".fileinput-button",
707
+ init: function () {
708
+ galleryDropzone = this;
709
+ }
710
+ });
711
+ $(tag + " .cancel").hide();
712
+ galleryDropzone.on("addedfile", function (file) {
713
+ $(file.previewElement.querySelector(".complete")).hide();
714
+ $(file.previewElement.querySelector(".cancel")).show();
715
+ $(tag + " .cancel").show();
716
+ });
717
+ // Update the total progress bar
718
+ galleryDropzone.on("totaluploadprogress", function (totalProgress, totalBytes, totalBytesSent) {
719
+ var progressBar = document.querySelector("#total-progress .progress-bar");
720
+ progressBar.style.width = totalProgress + "%";
721
+ });
722
+ galleryDropzone.on("sending", function (file) {
723
+ // Show the total progress bar when upload starts
724
+ var progressBar = document.querySelector("#total-progress");
725
+ progressBar.style.opacity = "1";
726
+ });
727
+ // Hide the total progress bar when nothing's uploading anymore
728
+ galleryDropzone.on("complete", function (file) {
729
+ $(file.previewElement.querySelector(".cancel")).hide();
730
+ $(file.previewElement.querySelector(".progress")).hide();
731
+ $(file.previewElement.querySelector(".complete")).show();
732
+ console.error("Uploader.Gallery.Dropzone.OnComplete - Inline.Refresh('.gallery') is not implemented.");
733
+ //Inline.Refresh('.gallery');
734
+ });
735
+ // Hide the total progress bar when nothing's uploading anymore
736
+ galleryDropzone.on("queuecomplete", function (progress) {
737
+ var totalProgress = document.querySelector("#total-progress");
738
+ totalProgress.style.opacity = "0";
739
+ $(tag + " .cancel").hide();
740
+ });
741
+ galleryDropzone.on("success", function (file, response) {
742
+ console.error("Uploader.Gallery.Dropzone.OnSuccess - Inline.Refresh('.gallery') is not implemented.");
743
+ //Inline.Refresh('.gallery');
744
+ if (response.success) {
745
+ Alerts.success("New images added!");
746
+ }
747
+ else {
748
+ Alerts.error("There was a problem adding the profile image: " + response.error);
749
+ }
750
+ });
751
+ // Setup the buttons for all transfers
752
+ // The "add files" button doesn't need to be setup because the config
753
+ // `clickable` has already been specified.
754
+ $(".actions .cancel").click(function () {
755
+ galleryDropzone.removeAllFiles(true);
756
+ });
757
+ };
758
+ return Uploader;
759
+ }());
760
+
761
+ $.fn.exists = function () {
762
+ return $(this).length;
763
+ };
764
+ $.fn.restrictToSlug = function (restrictPattern) {
765
+ if (restrictPattern === void 0) { restrictPattern = /[^0-9a-zA-Z]*/g; }
766
+ var targets = $(this);
767
+ // The characters inside this pattern are accepted
768
+ // and everything else will be 'cleaned'
769
+ // For example 'ABCdEfGhI5' become 'ABCEGI5'
770
+ var restrictHandler = function () {
771
+ var val = $(this).val();
772
+ var newVal = val.replace(restrictPattern, '');
773
+ // This condition is to prevent selection and keyboard navigation issues
774
+ if (val !== newVal) {
775
+ $(this).val(newVal);
776
+ }
777
+ };
778
+ targets.on('keyup', restrictHandler);
779
+ targets.on('paste', restrictHandler);
780
+ targets.on('change', restrictHandler);
781
+ };
782
+ $.fn.restrictToPageSlug = function (restrictPattern) {
783
+ if (restrictPattern === void 0) { restrictPattern = /[^0-9a-zA-Z-//]*/g; }
784
+ var targets = $(this);
785
+ // The characters inside this pattern are accepted
786
+ // and everything else will be 'cleaned'
787
+ var restrictHandler = function () {
788
+ var val = $(this).val();
789
+ var newVal = val.replace(restrictPattern, '');
790
+ if ((newVal.match(new RegExp("/", "g")) || []).length > 4) {
791
+ var pos = newVal.lastIndexOf('/');
792
+ newVal = newVal.substring(0, pos) + newVal.substring(pos + 1);
793
+ Alerts.warning("You can only have up to 4 '/' characters in a url slug.");
794
+ }
795
+ // This condition is to prevent selection and keyboard navigation issues
796
+ if (val !== newVal) {
797
+ $(this).val(newVal);
798
+ }
799
+ };
800
+ targets.on('keyup', restrictHandler);
801
+ targets.on('paste', restrictHandler);
802
+ targets.on('change', restrictHandler);
803
+ };
804
+ $.fn.restrictToMetaSlug = function (restrictPattern) {
805
+ if (restrictPattern === void 0) { restrictPattern = /[^0-9a-zA-Z.]*/g; }
806
+ var targets = $(this);
807
+ // The characters inside this pattern are accepted
808
+ // and everything else will be 'cleaned'
809
+ var restrictHandler = function () {
810
+ var val = $(this).val();
811
+ var newVal = val.replace(restrictPattern, '');
812
+ if ((newVal.match(new RegExp(".", "g")) || []).length > 1) {
813
+ var pos = newVal.lastIndexOf('.');
814
+ newVal = newVal.substring(0, pos) + newVal.substring(pos + 1);
815
+ Alerts.warning("You can only have up to 1 '.' characters in a meta slug.");
816
+ }
817
+ // This condition is to prevent selection and keyboard navigation issues
818
+ if (val !== newVal) {
819
+ $(this).val(newVal);
820
+ }
821
+ };
822
+ targets.on('keyup', restrictHandler);
823
+ targets.on('paste', restrictHandler);
824
+ targets.on('change', restrictHandler);
825
+ };
826
+ $.fn.characterCounter = function () {
827
+ var targets = $(this);
828
+ var characterCounterHandler = function () {
829
+ var counter = $(this).data('counter');
830
+ var max = Number($(this).attr('maxlength'));
831
+ var len = $(this).val().length;
832
+ $(counter).text(max - len);
833
+ var cls = "text-success";
834
+ if (max - len < max / 10)
835
+ cls = "text-danger";
836
+ $(counter).parent().removeClass('text-success').removeClass('text-danger').addClass(cls);
837
+ };
838
+ targets.on('keyup', characterCounterHandler);
839
+ targets.on('paste', characterCounterHandler);
840
+ targets.on('change', characterCounterHandler);
841
+ };
842
+ $.fn.warningAlert = function () {
843
+ var targets = $(this);
844
+ var warningAlertHandler = function (e) {
845
+ e.preventDefault();
846
+ var warningAlertCallback = function (result) {
847
+ if (result.isConfirmed) {
848
+ var url = $(e.currentTarget).attr('href');
849
+ window.location.href = url;
850
+ }
851
+ };
852
+ Alerts.confirm({
853
+ title: $(e.currentTarget).data('title'),
854
+ html: $(e.currentTarget).data('warning'),
855
+ footer: $(e.currentTarget).data('footer'),
856
+ icon: 'warning'
857
+ }, warningAlertCallback);
858
+ return false;
859
+ };
860
+ targets.on('click', warningAlertHandler);
861
+ };
862
+
863
+ Number.prototype.formatCurrency = function (currency) {
864
+ return currency + " " + this.toFixed(2).replace(/./g, function (c, i, a) {
865
+ return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;
866
+ });
867
+ };
868
+ Number.prototype.formatKilobytes = function () {
869
+ var n = this / 1024;
870
+ return n.toFixed(0).replace(/./g, function (c, i, a) {
871
+ return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;
872
+ }) + "Kb";
873
+ };
874
+ Number.prototype.formatMegabytes = function () {
875
+ var n = this / 1024;
876
+ n = n / 1024;
877
+ return n.toFixed(0).replace(/./g, function (c, i, a) {
878
+ return i > 0 && c !== "." && (a.length - i) % 3 === 0 ? "," + c : c;
879
+ }) + "Mb";
880
+ };
881
+
882
+ String.prototype.htmlEncode = function () {
883
+ //create a in-memory div, set it's inner text(which jQuery automatically encodes)
884
+ //then grab the encoded contents back out. The div never exists on the page.
885
+ return $('<div/>').text(this).html();
886
+ };
887
+ String.prototype.htmlDecode = function () {
888
+ return $('<div/>').html(this).text();
889
+ };
890
+ String.prototype.contains = function (it) {
891
+ return this.indexOf(it) !== -1;
892
+ };
893
+ String.prototype.pick = function (min, max) {
894
+ var n, chars = '';
895
+ if (typeof max === 'undefined') {
896
+ n = min;
897
+ }
898
+ else {
899
+ n = min + Math.floor(Math.random() * (max - min));
900
+ }
901
+ for (var i = 0; i < n; i++) {
902
+ chars += this.charAt(Math.floor(Math.random() * this.length));
903
+ }
904
+ return chars;
905
+ };
906
+ // Credit to @Christoph: http://stackoverflow.com/a/962890/464744
907
+ String.prototype.shuffle = function () {
908
+ var array = this.split('');
909
+ var tmp, current, top = array.length;
910
+ if (top)
911
+ while (--top) {
912
+ current = Math.floor(Math.random() * (top + 1));
913
+ tmp = array[current];
914
+ array[current] = array[top];
915
+ array[top] = tmp;
916
+ }
917
+ return array.join('');
918
+ };
919
+ String.prototype.toSeoUrl = function () {
920
+ var output = this.replace(/[^a-zA-Z0-9]/g, ' ').replace(/\s+/g, "-").toLowerCase();
921
+ /* remove first dash */
922
+ if (output.charAt(0) === '-')
923
+ output = output.substring(1);
924
+ /* remove last dash */
925
+ var last = output.length - 1;
926
+ if (output.charAt(last) === '-')
927
+ output = output.substring(0, last);
928
+ return output;
929
+ };
930
+
931
+ /// <reference types="google.maps" />
932
+ /**
933
+ * Base class for extending a Hood CMS website, ensure you call HoodApi.initialise() to setup loaders and contact form defaults.
934
+ */
935
+ var HoodApi = /** @class */ (function () {
936
+ function HoodApi() {
937
+ this.alerts = new Alerts();
938
+ this.handlers = new Handlers();
939
+ this.uploader = new Uploader();
940
+ }
941
+ // Initialise Hood CMS site defaults, can be overridden or individual setup items can be called instead of the initialise function.
942
+ HoodApi.prototype.initialise = function () {
943
+ // Initialise loaders (default, adds loading to body tag)
944
+ this.setupLoaders();
945
+ // Hook up default handlers.
946
+ this.handlers.initDefaultHandlers();
947
+ // Init hood contact forms.
948
+ this.initContactForms();
949
+ };
950
+ /**
951
+ * Default Hood CMS loaders, can be used however, this simply adds a "loading" class to the body tag on show/hide.
952
+ */
953
+ HoodApi.prototype.setupLoaders = function () {
954
+ $('body').on('loader-show', function () { document.body.classList.add('loading'); });
955
+ $('body').on('loader-hide', function () { document.body.classList.remove('loading'); });
956
+ };
957
+ /**
958
+ * Default initialisation function for Google Maps, should be called as the callback from the Google Maps API script tag.
959
+ */
960
+ HoodApi.prototype.initGoogleMaps = function (tag) {
961
+ if (tag === void 0) { tag = '.google-map'; }
962
+ $(tag).each(function () {
963
+ var myLatLng = new google.maps.LatLng($(this).data('lat'), $(this).data('long'));
964
+ console.log('Loading map at: ' + $(this).data('lat') + ', ' + $(this).data('long'));
965
+ var map = new google.maps.Map(this, {
966
+ zoom: $(this).data('zoom') || 15,
967
+ center: myLatLng,
968
+ scrollwheel: false
969
+ });
970
+ new google.maps.Marker({
971
+ position: myLatLng,
972
+ map: map,
973
+ title: $(this).data('marker')
974
+ });
975
+ $(window).on('resize', function () {
976
+ google.maps.event.trigger(map, 'resize');
977
+ });
978
+ google.maps.event.trigger(map, 'resize');
979
+ });
980
+ };
981
+ /**
982
+ * Initialisation function for contact forms on the site, will add validator, and submit/functionality to any forms matching the given tag selector string.
983
+ */
984
+ HoodApi.prototype.initContactForms = function (tag) {
985
+ if (tag === void 0) { tag = '.contact-form'; }
986
+ var $form = $(tag);
987
+ $form.find('.thank-you').hide();
988
+ $form.find('.form-content').show();
989
+ var form = $(tag)[0];
990
+ new Validator(form, {
991
+ onComplete: function (response) {
992
+ if (response.success) {
993
+ if ($form.attr('data-redirect'))
994
+ window.location.href = $form.attr('data-redirect');
995
+ if ($form.attr('data-alert-message'))
996
+ Alerts.success($form.attr('data-alert-message'));
997
+ $form.find('.form').hide();
998
+ $form.find('.thank-you').show();
999
+ }
1000
+ else {
1001
+ if ($form.attr('data-alert-error'))
1002
+ Alerts.error($form.attr('data-alert-error'));
1003
+ else {
1004
+ console.error(response.errors);
1005
+ Alerts.error("There are errors on the form, please check your answers and try again.");
1006
+ }
1007
+ }
1008
+ }.bind(this)
1009
+ });
1010
+ };
1011
+ return HoodApi;
1012
+ }());
1013
+
1014
+ /// <reference types="google.maps" />
1015
+ var PropertyController = /** @class */ (function () {
1016
+ function PropertyController() {
1017
+ this.map = null;
1018
+ this.center = { lat: 30, lng: -110 };
1019
+ this.initList();
1020
+ }
1021
+ PropertyController.prototype.initList = function () {
1022
+ this.element = document.getElementById('property-list');
1023
+ if (!this.element) {
1024
+ return;
1025
+ }
1026
+ this.list = new DataList(this.element, {
1027
+ onComplete: function (data, sender) {
1028
+ Alerts.log('Finished loading property list.', 'info');
1029
+ }.bind(this)
1030
+ });
1031
+ };
1032
+ PropertyController.prototype.initMapList = function () {
1033
+ this.mapListElement = document.getElementById('property-map-list');
1034
+ if (!this.mapElement) {
1035
+ return;
1036
+ }
1037
+ this.mapList = new DataList(this.mapListElement, {
1038
+ onComplete: function (data, sender) {
1039
+ Alerts.log('Finished loading map list.', 'info');
1040
+ this.reloadMarkers();
1041
+ }.bind(this)
1042
+ });
1043
+ };
1044
+ PropertyController.prototype.initMap = function (mapElementId) {
1045
+ if (mapElementId === void 0) { mapElementId = 'property-map'; }
1046
+ this.mapElement = document.getElementById(mapElementId);
1047
+ if (!this.mapElement) {
1048
+ return;
1049
+ }
1050
+ this.center = { lat: +this.mapElement.dataset.lat, lng: +this.mapElement.dataset.long };
1051
+ this.map = new google.maps.Map(this.mapElement, {
1052
+ zoom: +this.mapElement.dataset.zoom || 15,
1053
+ center: this.center,
1054
+ scrollwheel: false
1055
+ });
1056
+ $(window).resize(function () {
1057
+ google.maps.event.trigger(this.map, 'resize');
1058
+ }.bind(this));
1059
+ google.maps.event.trigger(this.map, 'resize');
1060
+ this.initMapList();
1061
+ };
1062
+ PropertyController.prototype.reloadMarkers = function () {
1063
+ var infowindow = null;
1064
+ if (!this.mapElement) {
1065
+ return;
1066
+ }
1067
+ var map = this.map;
1068
+ if (this.markers) {
1069
+ for (var i = 0; i < this.markers.length; i++) {
1070
+ this.markers[i].setMap(null);
1071
+ }
1072
+ }
1073
+ this.markers = [];
1074
+ var locations = $("#property-map-locations").data('locations');
1075
+ locations.map(function (location, i) {
1076
+ var marker = new google.maps.Marker({
1077
+ position: new google.maps.LatLng(+location.Latitude, +location.Longitude),
1078
+ map: this.map,
1079
+ optimized: true // makes SVG icons work in IE
1080
+ });
1081
+ //marker.setIcon({
1082
+ // url: '/images/marker.png',
1083
+ // size: new google.maps.Size(30, 41),
1084
+ // scaledSize: new google.maps.Size(30, 41)
1085
+ //});
1086
+ marker.info = "<div class=\"card border-0\" style=\"max-width:300px\">\n <div style=\"background-image:url(".concat(location.ImageUrl, ")\" class=\"rounded img-full img img-wide\"></div>\n <div class=\"card-body border-0\">\n <p style=\"overflow: hidden;text-overflow: ellipsis;white-space: nowrap;\">\n <strong>").concat(location.Address1, ", ").concat(location.Postcode, "</strong>\n </p>\n <p>").concat(location.Description, "</p>\n <a href=\"").concat(location.MarkerUrl, "\" class=\"btn btn-block btn-primary\">Find out more...</a>\n </div>\n</div>");
1087
+ google.maps.event.addListener(marker, 'click', function () {
1088
+ if (infowindow) {
1089
+ infowindow.close();
1090
+ }
1091
+ infowindow = new google.maps.InfoWindow({
1092
+ content: this.info
1093
+ });
1094
+ infowindow.open(map, this);
1095
+ }.bind(this));
1096
+ this.markers.push(marker);
1097
+ }.bind(this));
1098
+ };
1099
+ return PropertyController;
1100
+ }());
1101
+
1102
+ /// <reference types="google.maps" />
1103
+ var App = /** @class */ (function (_super) {
1104
+ __extends(App, _super);
1105
+ function App() {
1106
+ var _this = _super.call(this) || this;
1107
+ // Setup defaults with HoodApi default initialise function.
1108
+ _this.initialise();
1109
+ // Initialise the property controllers.
1110
+ _this.property = new PropertyController();
1111
+ return _this;
1112
+ }
1113
+ return App;
1114
+ }(HoodApi));
1115
+ window.hood = new App();
1116
+
1117
+ exports.App = App;
1118
+
1119
+ Object.defineProperty(exports, '__esModule', { value: true });
1120
+
1121
+ }));
1122
+ if (typeof this !== 'undefined' && this.hood){ this.hoodCMS = this.Hood = this.hoodCMS = this.HoodCMS = this.hood }
1123
+ //# sourceMappingURL=app.property.js.map