hoodcms 5.0.6 → 5.0.10

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.
Files changed (110) hide show
  1. package/README.md +8 -6
  2. package/dist/css/admin.css +1 -0
  3. package/dist/css/app.css +1 -0
  4. package/dist/css/button.css +1 -0
  5. package/dist/css/editor.css +1 -0
  6. package/dist/css/install.css +1 -0
  7. package/dist/css/login.css +1 -0
  8. package/dist/js/admin.js +24 -0
  9. package/dist/js/app.js +23 -0
  10. package/dist/js/core/Alerts.d.ts +22 -0
  11. package/dist/js/core/Alerts.js +151 -0
  12. package/dist/js/core/BaseSite.d.ts +6 -0
  13. package/dist/js/core/BaseSite.js +14 -0
  14. package/dist/js/core/ColorPicker.d.ts +5 -0
  15. package/dist/js/core/ColorPicker.js +71 -0
  16. package/dist/js/core/DataList.d.ts +35 -0
  17. package/dist/js/core/DataList.js +56 -0
  18. package/dist/js/core/Editors.d.ts +16 -0
  19. package/dist/js/core/Editors.js +137 -0
  20. package/dist/js/core/Handlers.d.ts +47 -0
  21. package/dist/js/core/Handlers.js +160 -0
  22. package/dist/js/core/HoodApi.d.ts +25 -0
  23. package/dist/js/core/HoodApi.js +22 -0
  24. package/dist/js/core/Inline.d.ts +27 -0
  25. package/dist/js/core/Inline.js +63 -0
  26. package/dist/js/core/Loader.d.ts +5 -0
  27. package/dist/js/core/Loader.js +13 -0
  28. package/dist/js/core/Media.d.ts +113 -0
  29. package/dist/js/core/Media.js +363 -0
  30. package/dist/js/core/Modal.d.ts +35 -0
  31. package/dist/js/core/Modal.js +69 -0
  32. package/dist/js/core/RandomStringGenerator.d.ts +11 -0
  33. package/dist/js/core/RandomStringGenerator.js +23 -0
  34. package/dist/js/core/Response.d.ts +20 -0
  35. package/dist/js/core/Response.js +13 -0
  36. package/dist/js/core/Uploader.d.ts +7 -0
  37. package/dist/js/core/Uploader.js +134 -0
  38. package/dist/js/core/Validator.d.ts +27 -0
  39. package/dist/js/core/Validator.js +80 -0
  40. package/dist/js/extensions/jqueryExtensions.d.ts +11 -0
  41. package/dist/js/extensions/jqueryExtensions.js +99 -0
  42. package/dist/js/extensions/numberExtensions.d.ts +8 -0
  43. package/dist/js/extensions/numberExtensions.js +19 -0
  44. package/dist/js/extensions/stringExtensions.d.ts +12 -0
  45. package/dist/js/extensions/stringExtensions.js +49 -0
  46. package/dist/js/index.d.ts +22 -0
  47. package/dist/js/index.js +22 -0
  48. package/dist/js/interfaces/KeyValue.d.ts +4 -0
  49. package/dist/js/interfaces/KeyValue.js +1 -0
  50. package/dist/js/login.js +7 -0
  51. package/dist/js/models/Content.d.ts +50 -0
  52. package/dist/js/models/Content.js +1 -0
  53. package/dist/js/models/Property.d.ts +9 -0
  54. package/dist/js/models/Property.js +2 -0
  55. package/dist/js/models/Users.d.ts +7 -0
  56. package/dist/js/models/Users.js +2 -0
  57. package/images/arrow.jpg +0 -0
  58. package/images/h-black.svg +1 -0
  59. package/images/h-white.svg +0 -0
  60. package/images/hood-cms-dark.png +0 -0
  61. package/images/hood-cms-dark.svg +1 -0
  62. package/images/hood-cms-white.png +0 -0
  63. package/images/hood-cms-white.svg +1 -0
  64. package/images/hood-cms.png +0 -0
  65. package/images/hood-logo.svg +1 -0
  66. package/images/hood-square-padded.png +0 -0
  67. package/images/hood-square.png +0 -0
  68. package/images/hood-white.svg +1 -0
  69. package/images/hood.svg +1 -0
  70. package/images/icons/audio.png +0 -0
  71. package/images/icons/excel.png +0 -0
  72. package/images/icons/file.png +0 -0
  73. package/images/icons/pdf.png +0 -0
  74. package/images/icons/photoshop.png +0 -0
  75. package/images/icons/powerpoint.png +0 -0
  76. package/images/icons/video.png +0 -0
  77. package/images/icons/word.png +0 -0
  78. package/images/loading.svg +1 -0
  79. package/images/no-avatar.jpg +0 -0
  80. package/images/no-image.jpg +0 -0
  81. package/images/og-share.jpg +0 -0
  82. package/package.json +58 -55
  83. package/src/css/admin.css +12382 -0
  84. package/src/css/admin.css.map +1 -0
  85. package/src/css/app.css +11923 -0
  86. package/src/css/app.css.map +1 -0
  87. package/src/css/button.css +72 -0
  88. package/src/css/button.css.map +1 -0
  89. package/src/css/editor.css +11124 -0
  90. package/src/css/editor.css.map +1 -0
  91. package/src/css/install.css +11471 -0
  92. package/src/css/install.css.map +1 -0
  93. package/src/css/login.css +11455 -0
  94. package/src/css/login.css.map +1 -0
  95. package/src/js/admin.js +2595 -0
  96. package/src/js/admin.js.map +1 -0
  97. package/src/js/app.js +1578 -0
  98. package/src/js/app.js.map +1 -0
  99. package/src/js/login.js +44 -0
  100. package/src/js/login.js.map +1 -0
  101. package/src/scss/admin.scss +2 -6
  102. package/src/scss/app.scss +2 -2
  103. package/src/scss/editor.scss +2 -3
  104. package/src/scss/install.scss +1 -1
  105. package/src/scss/login.scss +2 -16
  106. package/src/ts/admin.ts +2 -6
  107. package/src/ts/app.ts +0 -2
  108. package/src/ts/core/BaseSite.ts +21 -0
  109. package/src/ts/index.ts +25 -0
  110. package/src/ts/hood.ts +0 -5
package/src/js/app.js ADDED
@@ -0,0 +1,1578 @@
1
+ /*!
2
+ * hoodcms v5.0.9
3
+ * A fully customisable content management system built in ASP.NET Core 5 & Bootstrap 5.
4
+ * Written by George Whysall, 2021
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, global.Pickr, global.tinymce, global.bootstrap));
11
+ })(this, (function (exports, Swal, Pickr, tinymce, bootstrap) { '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
+ var Pickr__default = /*#__PURE__*/_interopDefaultLegacy(Pickr);
17
+ var tinymce__default = /*#__PURE__*/_interopDefaultLegacy(tinymce);
18
+
19
+ /*! *****************************************************************************
20
+ Copyright (c) Microsoft Corporation.
21
+
22
+ Permission to use, copy, modify, and/or distribute this software for any
23
+ purpose with or without fee is hereby granted.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
26
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
27
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
28
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
29
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
30
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31
+ PERFORMANCE OF THIS SOFTWARE.
32
+ ***************************************************************************** */
33
+ /* global Reflect, Promise */
34
+
35
+ var extendStatics = function(d, b) {
36
+ extendStatics = Object.setPrototypeOf ||
37
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
38
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
39
+ return extendStatics(d, b);
40
+ };
41
+
42
+ function __extends(d, b) {
43
+ extendStatics(d, b);
44
+ function __() { this.constructor = d; }
45
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
46
+ }
47
+
48
+ var __assign = function() {
49
+ __assign = Object.assign || function __assign(t) {
50
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
51
+ s = arguments[i];
52
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
53
+ }
54
+ return t;
55
+ };
56
+ return __assign.apply(this, arguments);
57
+ };
58
+
59
+ "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);
60
+
61
+ var BootstrapSwal = Swal__default["default"].mixin({
62
+ customClass: {
63
+ confirmButton: 'btn btn-success m-1 px-3',
64
+ cancelButton: 'btn btn-danger m-1 px-3'
65
+ },
66
+ buttonsStyling: false
67
+ });
68
+ var Alerts = /** @class */ (function () {
69
+ function Alerts() {
70
+ }
71
+ Alerts.log = function (message, type) {
72
+ if (type === void 0) { type = 'message'; }
73
+ if (!document.body.classList.contains('dev-mode')) {
74
+ return;
75
+ }
76
+ switch (type) {
77
+ case 'error':
78
+ console.error(message);
79
+ break;
80
+ case 'message':
81
+ console.log(message);
82
+ break;
83
+ case 'warning':
84
+ console.warn(message);
85
+ break;
86
+ case 'info':
87
+ console.info(message);
88
+ break;
89
+ }
90
+ };
91
+ Alerts.error = function (message, title, hideAfter) {
92
+ if (title === void 0) { title = null; }
93
+ if (hideAfter === void 0) { hideAfter = null; }
94
+ $.toast({
95
+ heading: title,
96
+ text: message,
97
+ icon: 'error',
98
+ position: 'bottom-left',
99
+ loader: false,
100
+ bgColor: '#d0100b',
101
+ textColor: 'white',
102
+ hideAfter: hideAfter
103
+ });
104
+ };
105
+ Alerts.warning = function (message, title, hideAfter) {
106
+ if (title === void 0) { title = null; }
107
+ if (hideAfter === void 0) { hideAfter = null; }
108
+ $.toast({
109
+ heading: title,
110
+ text: message,
111
+ icon: 'error',
112
+ position: 'bottom-left',
113
+ loader: false,
114
+ bgColor: '#ef9007',
115
+ textColor: 'white',
116
+ hideAfter: hideAfter
117
+ });
118
+ };
119
+ Alerts.message = function (message, title, hideAfter) {
120
+ if (title === void 0) { title = null; }
121
+ if (hideAfter === void 0) { hideAfter = null; }
122
+ $.toast({
123
+ heading: title,
124
+ text: message,
125
+ icon: 'error',
126
+ position: 'bottom-left',
127
+ loader: false,
128
+ bgColor: '#222222',
129
+ textColor: 'white',
130
+ hideAfter: hideAfter
131
+ });
132
+ };
133
+ Alerts.success = function (message, title, hideAfter) {
134
+ if (title === void 0) { title = null; }
135
+ if (hideAfter === void 0) { hideAfter = null; }
136
+ $.toast({
137
+ heading: title,
138
+ text: message,
139
+ icon: 'error',
140
+ position: 'bottom-left',
141
+ loader: false,
142
+ bgColor: '#28a745',
143
+ textColor: 'white',
144
+ hideAfter: hideAfter
145
+ });
146
+ };
147
+ Alerts.alert = function (message, title, icon, hideAfter) {
148
+ if (title === void 0) { title = null; }
149
+ if (icon === void 0) { icon = 'info'; }
150
+ if (hideAfter === void 0) { hideAfter = 10000; }
151
+ switch (icon) {
152
+ case 'error':
153
+ Alerts.error(message, title, hideAfter);
154
+ break;
155
+ case 'warning':
156
+ Alerts.warning(message, title, hideAfter);
157
+ break;
158
+ case 'info':
159
+ Alerts.message(message, title, hideAfter);
160
+ break;
161
+ case 'success':
162
+ Alerts.success(message, title, hideAfter);
163
+ break;
164
+ }
165
+ };
166
+ Alerts.sweetAlert = function (options, callback) {
167
+ BootstrapSwal.fire(options).then(function (result) {
168
+ callback(result);
169
+ });
170
+ };
171
+ Alerts.confirm = function (options, callback) {
172
+ var baseOptions = {
173
+ showCancelButton: true,
174
+ footer: null,
175
+ title: 'Are you sure?',
176
+ html: 'Are you sure you want to do this?',
177
+ confirmButtonText: 'Ok',
178
+ cancelButtonText: 'Cancel'
179
+ };
180
+ Alerts.sweetAlert(__assign(__assign({}, baseOptions), options), callback);
181
+ };
182
+ Alerts.prompt = function (options, callback) {
183
+ var baseOptions = {
184
+ input: 'text',
185
+ inputAttributes: {
186
+ autocapitalize: 'off'
187
+ },
188
+ showCancelButton: true,
189
+ icon: 'info',
190
+ footer: '<span class="text-warning"><i class="fa fa-exclamation-triangle"></i> This cannot be undone.</span>',
191
+ confirmButtonText: 'Ok',
192
+ cancelButtonText: 'Cancel'
193
+ };
194
+ Alerts.sweetAlert(__assign(__assign({}, baseOptions), options), callback);
195
+ };
196
+ Alerts.prototype.log = function (message, type) {
197
+ if (type === void 0) { type = 'message'; }
198
+ Alerts.log(message, type);
199
+ };
200
+ Alerts.prototype.error = function (message, title, hideAfter) {
201
+ if (title === void 0) { title = null; }
202
+ if (hideAfter === void 0) { hideAfter = null; }
203
+ Alerts.error(message, title, hideAfter);
204
+ };
205
+ Alerts.prototype.warning = function (message, title, hideAfter) {
206
+ if (title === void 0) { title = null; }
207
+ if (hideAfter === void 0) { hideAfter = null; }
208
+ Alerts.warning(message, title, hideAfter);
209
+ };
210
+ Alerts.prototype.message = function (message, title, hideAfter) {
211
+ if (title === void 0) { title = null; }
212
+ if (hideAfter === void 0) { hideAfter = null; }
213
+ Alerts.message(message, title, hideAfter);
214
+ };
215
+ Alerts.prototype.success = function (message, title, hideAfter) {
216
+ if (title === void 0) { title = null; }
217
+ if (hideAfter === void 0) { hideAfter = null; }
218
+ Alerts.success(message, title, hideAfter);
219
+ };
220
+ Alerts.prototype.alert = function (message, title, icon, hideAfter) {
221
+ if (icon === void 0) { icon = 'info'; }
222
+ if (hideAfter === void 0) { hideAfter = 10000; }
223
+ Alerts.alert(message, message, icon, hideAfter);
224
+ };
225
+ Alerts.prototype.sweetAlert = function (options, callback) {
226
+ Alerts.sweetAlert(options, callback);
227
+ };
228
+ Alerts.prototype.confirm = function (options, callback) {
229
+ Alerts.confirm(options, callback);
230
+ };
231
+ Alerts.prototype.prompt = function (options, callback) {
232
+ Alerts.prompt(options, callback);
233
+ };
234
+ return Alerts;
235
+ }());
236
+
237
+ var ColorPickers = /** @class */ (function () {
238
+ function ColorPickers() {
239
+ }
240
+ ColorPickers.prototype.loadColorPickers = function (tag) {
241
+ if (tag === void 0) { tag = '.color-picker'; }
242
+ var updateColorFieldValue = function (color, eventSource, instance) {
243
+ var elemId = $(instance._root.button).parent().data('target');
244
+ $(instance._root.button).parent().css({ 'background-color': color.toHEXA().toString() });
245
+ var colorHex = instance.getColor().toHEXA();
246
+ var result = "";
247
+ for (var i = colorHex.length - 1; i >= 0; i--) {
248
+ result = colorHex[i] + result;
249
+ }
250
+ $(elemId).val('#' + result);
251
+ $(elemId).change();
252
+ };
253
+ // Simple example, see optional options for more configuration.
254
+ $(tag).each(function (index, elem) {
255
+ var lockOpacity = true;
256
+ if ($(this).data('opacity') == 'true') {
257
+ lockOpacity = false;
258
+ }
259
+ Pickr__default["default"].create({
260
+ el: elem.children[0],
261
+ appClass: 'custom-class',
262
+ theme: 'monolith',
263
+ useAsButton: true,
264
+ default: $(this).data('default') || 'none',
265
+ lockOpacity: lockOpacity,
266
+ defaultRepresentation: 'HEXA',
267
+ position: 'bottom-end',
268
+ components: {
269
+ opacity: true,
270
+ hue: true,
271
+ interaction: {
272
+ hex: false,
273
+ rgba: false,
274
+ hsva: false,
275
+ input: true,
276
+ clear: true
277
+ }
278
+ }
279
+ })
280
+ .on('init', function (instance) {
281
+ var elemId = $(instance._root.button).parent().data('target');
282
+ var value = $(elemId).val();
283
+ $(instance._root.button).parent().on('click', $.proxy(function () {
284
+ this.show();
285
+ }, instance));
286
+ $(elemId).on('click', $.proxy(function () {
287
+ this.show();
288
+ }, instance));
289
+ if (value) {
290
+ instance.setColor(value);
291
+ updateColorFieldValue(instance.getColor(), null, instance);
292
+ }
293
+ })
294
+ .on('clear', function (instance) {
295
+ var elemId = $(instance._root.button).parent().data('target');
296
+ instance.setColor('transparent');
297
+ updateColorFieldValue(instance.getColor(), null, instance);
298
+ $(elemId).val('');
299
+ $(elemId).change();
300
+ })
301
+ .on('change', updateColorFieldValue);
302
+ });
303
+ };
304
+ return ColorPickers;
305
+ }());
306
+
307
+ var Response = /** @class */ (function () {
308
+ function Response() {
309
+ }
310
+ Response.process = function (data, autoHide) {
311
+ if (autoHide === void 0) { autoHide = 5000; }
312
+ if (data.success) {
313
+ Alerts.success(data.message, data.title, autoHide);
314
+ }
315
+ else {
316
+ Alerts.error(data.errors, data.title, autoHide);
317
+ }
318
+ };
319
+ return Response;
320
+ }());
321
+
322
+ var Inline = /** @class */ (function () {
323
+ function Inline() {
324
+ }
325
+ Inline.load = function (tag, options) {
326
+ var _a;
327
+ var $tag = $(tag);
328
+ $tag.addClass('loading');
329
+ if (options.onLoad) {
330
+ options.onLoad(tag);
331
+ }
332
+ var url = $tag.data('url');
333
+ $.get(url, function (data) {
334
+ if (options.onRender) {
335
+ data = options.onRender(data, tag);
336
+ }
337
+ $tag.html(data);
338
+ $tag.removeClass('loading');
339
+ if (options.onComplete) {
340
+ options.onComplete(data, tag);
341
+ }
342
+ })
343
+ .fail((_a = options.onError) !== null && _a !== void 0 ? _a : Inline.handleError);
344
+ };
345
+ Inline.task = function (url, sender, complete, error) {
346
+ if (complete === void 0) { complete = null; }
347
+ if (error === void 0) { error = null; }
348
+ if (sender) {
349
+ sender.classList.add('loading');
350
+ }
351
+ $.get(url, function (response) {
352
+ if (sender) {
353
+ sender.classList.remove('loading');
354
+ }
355
+ if (complete) {
356
+ complete(response, sender);
357
+ }
358
+ })
359
+ .fail(error !== null && error !== void 0 ? error : Inline.handleError);
360
+ };
361
+ Inline.post = function (url, sender, complete, error) {
362
+ if (complete === void 0) { complete = null; }
363
+ if (error === void 0) { error = null; }
364
+ if (sender) {
365
+ sender.classList.add('loading');
366
+ }
367
+ $.post(url, function (response) {
368
+ if (sender) {
369
+ sender.classList.remove('loading');
370
+ }
371
+ if (complete) {
372
+ complete(response, sender);
373
+ }
374
+ })
375
+ .fail(error !== null && error !== void 0 ? error : Inline.handleError);
376
+ };
377
+ Inline.handleError = function (xhr, textStatus, errorThrown) {
378
+ if (xhr.status === 500) {
379
+ Alerts.error("There was an error processing the content, please contact an administrator if this continues.", "Error " + xhr.status, 10000);
380
+ }
381
+ else if (xhr.status === 404) {
382
+ Alerts.error("The content could not be found.", "Error " + xhr.status, 10000);
383
+ }
384
+ else if (xhr.status === 401) {
385
+ Alerts.error("You are not allowed to view this resource, are you logged in correctly?", "Error " + xhr.status, 10000);
386
+ window.location = window.location;
387
+ }
388
+ };
389
+ return Inline;
390
+ }());
391
+
392
+ /**
393
+ * Attach a data list feed to an HTML element. The element must have a data-url attribute to connect to a feed.
394
+ */
395
+ var DataList = /** @class */ (function () {
396
+ /**
397
+ * @param element The datalist element. The element must have a data-url attribute to connect to a feed.
398
+ */
399
+ function DataList(element, options) {
400
+ this.element = element;
401
+ this.element.hoodDataList = this;
402
+ if (typeof (element) == 'undefined' || element == null) {
403
+ Alerts.log('Could not DataList to element, element does not exist.', 'error');
404
+ return;
405
+ }
406
+ this.options = __assign(__assign({}, this.options), options);
407
+ if ($(this.element).hasClass('query')) {
408
+ var pageUrl = $(this.element).data('url') + window.location.search;
409
+ $(this.element).attr('data-url', pageUrl);
410
+ $(this.element).data('url', pageUrl);
411
+ }
412
+ if (!$(this.element).hasClass('refresh-only')) {
413
+ var listUrl = document.createElement('a');
414
+ listUrl.href = $(this.element).data('url');
415
+ this.reload(new URL(listUrl.href));
416
+ }
417
+ $(this.element).on('click', '.pagination a, a.hood-inline-list-target', function (e) {
418
+ e.preventDefault();
419
+ var url = document.createElement('a');
420
+ url.href = e.currentTarget.href;
421
+ var listUrl = document.createElement('a');
422
+ listUrl.href = $(this.element).data('url');
423
+ listUrl.search = url.search;
424
+ this.reload(new URL(listUrl.href));
425
+ }.bind(this));
426
+ $('body').on('submit', "form.inline[data-target=\"#".concat(this.element.id, "\"]"), function (e) {
427
+ e.preventDefault();
428
+ var $form = $(e.currentTarget);
429
+ var listUrl = document.createElement('a');
430
+ listUrl.href = $(this.element).data('url');
431
+ listUrl.search = "?" + $form.serialize();
432
+ this.reload(new URL(listUrl.href));
433
+ }.bind(this));
434
+ }
435
+ DataList.prototype.reload = function (url) {
436
+ if (url === void 0) { url = null; }
437
+ if (url) {
438
+ if (history.pushState && $(this.element).hasClass('query')) {
439
+ var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + (url.href.contains('?') ? "?" + url.href.substring(url.href.indexOf('?') + 1) : '');
440
+ window.history.pushState({ path: newurl }, '', newurl);
441
+ }
442
+ $(this.element).data('url', url);
443
+ }
444
+ Inline.load(this.element, __assign({}, this.options));
445
+ };
446
+ return DataList;
447
+ }());
448
+
449
+ var ModalController = /** @class */ (function () {
450
+ function ModalController(options) {
451
+ if (options === void 0) { options = null; }
452
+ this.isOpen = false;
453
+ this.options = {
454
+ closePrevious: true
455
+ };
456
+ this.options = __assign(__assign({}, this.options), options);
457
+ }
458
+ ModalController.prototype.show = function (url, sender) {
459
+ if (this.options.onLoad) {
460
+ this.options.onLoad(this.element);
461
+ }
462
+ if (this.isOpen) {
463
+ return;
464
+ }
465
+ this.isOpen = true;
466
+ $.get(url, function (data) {
467
+ if (this.modal && this.options.closePrevious) {
468
+ this.close();
469
+ }
470
+ if (this.options.onRender) {
471
+ data = this.options.onRender(this.element, data);
472
+ }
473
+ this.element = this.createElementFromHTML(data);
474
+ this.element.classList.add('hood-inline-modal');
475
+ $('body').append(this.element);
476
+ this.modal = new bootstrap.Modal(this.element, {});
477
+ this.modal.show();
478
+ // Workaround for sweetalert popups.
479
+ this.element.addEventListener('shown.bs.modal', function () {
480
+ $(document).off('focusin.modal');
481
+ }.bind(this));
482
+ this.element.addEventListener('hidden.bs.modal', function () {
483
+ if (this.options.onHidden) {
484
+ this.options.onHidden(this.element);
485
+ }
486
+ this.dispose();
487
+ this.isOpen = false;
488
+ }.bind(this));
489
+ if (this.options.onComplete) {
490
+ this.options.onComplete(this.element);
491
+ }
492
+ }.bind(this))
493
+ .fail(function (xhr, textStatus, errorThrown) {
494
+ this.isOpen = false;
495
+ if (this.options.onError) {
496
+ this.options.onError(xhr, textStatus, errorThrown);
497
+ }
498
+ Inline.handleError(xhr, textStatus, errorThrown);
499
+ }.bind(this));
500
+ };
501
+ ModalController.prototype.close = function () {
502
+ if (this.modal) {
503
+ this.modal.hide();
504
+ }
505
+ };
506
+ ModalController.prototype.dispose = function () {
507
+ this.modal.dispose();
508
+ this.element.remove();
509
+ };
510
+ ModalController.prototype.createElementFromHTML = function (htmlString) {
511
+ var div = document.createElement('div');
512
+ div.innerHTML = htmlString.trim();
513
+ // Change this to div.childNodes to support multiple top-level nodes
514
+ return div.firstChild;
515
+ };
516
+ return ModalController;
517
+ }());
518
+
519
+ var Validator = /** @class */ (function () {
520
+ /**
521
+ * @param element The datalist element. The element must have a data-url attribute to connect to a feed.
522
+ */
523
+ function Validator(element, options) {
524
+ this.options = {
525
+ errorAlert: 'There are errors, please check the form.',
526
+ useAjax: true
527
+ };
528
+ this.element = element;
529
+ if (!this.element) {
530
+ return;
531
+ }
532
+ this.options.serializationFunction = function () {
533
+ var rtn = $(this.element).serialize();
534
+ return rtn;
535
+ }.bind(this);
536
+ this.options = __assign(__assign({}, this.options), options);
537
+ this.element.addEventListener('submit', function (e) {
538
+ e.preventDefault();
539
+ e.stopImmediatePropagation();
540
+ this.submitForm();
541
+ }.bind(this));
542
+ var tag = '[data-submit="#' + this.element.id + '"]';
543
+ var submitButtons = $(tag);
544
+ if (submitButtons) {
545
+ submitButtons.on('click', function (e) {
546
+ e.preventDefault();
547
+ e.stopImmediatePropagation();
548
+ var exit = $(e.currentTarget).data('exit');
549
+ if (exit) {
550
+ $(this.element).find("input#exit").remove();
551
+ $("<input id='exit' />").attr("type", "hidden")
552
+ .attr("name", "exit")
553
+ .attr("value", "true")
554
+ .appendTo(this.element);
555
+ }
556
+ this.submitForm();
557
+ }.bind(this));
558
+ }
559
+ }
560
+ Validator.prototype.submitForm = function () {
561
+ var _a;
562
+ this.element.classList.add('was-validated');
563
+ if (this.element.checkValidity()) {
564
+ this.element.classList.add('loading');
565
+ var checkboxes = this.element.querySelector('input[type=checkbox]');
566
+ if (checkboxes) {
567
+ Array.prototype.slice.call(checkboxes)
568
+ .forEach(function (checkbox) {
569
+ if ($(this).is(':checked')) {
570
+ $(this).val('true');
571
+ }
572
+ });
573
+ }
574
+ if (this.options.onSubmit) {
575
+ this.options.onSubmit(this);
576
+ }
577
+ if (this.options.useAjax) {
578
+ var formData = this.options.serializationFunction();
579
+ $.post(this.element.action, formData, function (data) {
580
+ if (this.options.onComplete) {
581
+ this.options.onComplete(data, this);
582
+ }
583
+ }.bind(this))
584
+ .fail((_a = this.options.onError) !== null && _a !== void 0 ? _a : Inline.handleError);
585
+ }
586
+ else {
587
+ this.element.submit();
588
+ }
589
+ }
590
+ else {
591
+ if (this.options.errorAlert) {
592
+ Alerts.error(this.options.errorAlert, null, 5000);
593
+ }
594
+ }
595
+ };
596
+ return Validator;
597
+ }());
598
+
599
+ var MediaService = /** @class */ (function () {
600
+ function MediaService(element, options) {
601
+ this.options = {
602
+ action: 'show',
603
+ size: 'large'
604
+ };
605
+ this.galleryInitialised = false;
606
+ this.selectedMedia = new Array();
607
+ this.element = element;
608
+ if (!this.element) {
609
+ return;
610
+ }
611
+ this.options = __assign(__assign({}, this.options), options);
612
+ $('body').off('click', '.media-delete', this.delete.bind(this));
613
+ $('body').on('click', '.media-delete', this.delete.bind(this));
614
+ $(this.element).on('click', '.media-item', this.action.bind(this));
615
+ $(this.element).on('click', '.media-create-directory', this.createDirectory.bind(this));
616
+ $(this.element).on('click', '.media-delete-directory', this.deleteDirectory.bind(this));
617
+ this.media = new DataList(this.element, {
618
+ onLoad: this.options.onListLoad,
619
+ onError: this.options.onError,
620
+ onRender: this.options.onListRender,
621
+ onComplete: function (html, sender) {
622
+ this.initUploader();
623
+ // if this is gallery type, add the "Add to gallery button" and hook it to the add function
624
+ if (this.options.action == 'gallery' && !this.galleryInitialised) {
625
+ $('#media-select-modal .modal-footer').removeClass('d-none');
626
+ $('#media-select-modal .modal-footer').on('click', this.galleryAdd.bind(this));
627
+ this.galleryInitialised = true;
628
+ }
629
+ if (this.options.onListComplete) {
630
+ this.options.onListComplete(html, sender);
631
+ }
632
+ }.bind(this)
633
+ });
634
+ }
635
+ MediaService.prototype.initUploader = function () {
636
+ this.uploadButton = document.getElementById('media-add');
637
+ this.uploader = document.getElementById('media-upload');
638
+ if (!this.uploadButton || !this.uploader)
639
+ return;
640
+ this.progressArea = document.getElementById('media-progress');
641
+ this.progressText = $('<div class="progress-text text-muted mb-3"><i class="fa fa-info-circle me-2"></i>Uploading file <span></span>...</div>');
642
+ this.progress = $('<div class="progress"><div class= "progress-bar progress-bar-striped" role="progressbar" style="width:0%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100" ></div></div>');
643
+ this.progressText.appendTo(this.progressArea);
644
+ this.progress.appendTo(this.progressArea);
645
+ var dz = null;
646
+ $("#media-upload").dropzone({
647
+ url: $("#media-upload").data('url') + "?directoryId=" + $("#media-list > #upload-directory-id").val(),
648
+ thumbnailWidth: 80,
649
+ thumbnailHeight: 80,
650
+ parallelUploads: 5,
651
+ paramName: 'files',
652
+ acceptedFiles: $("#media-upload").data('types') || ".png,.jpg,.jpeg,.gif",
653
+ autoProcessQueue: true,
654
+ previewsContainer: false,
655
+ clickable: "#media-add",
656
+ dictDefaultMessage: '<span><i class="fa fa-cloud-upload fa-4x"></i><br />Drag and drop files here, or simply click me!</div>',
657
+ dictResponseError: 'Error while uploading file!',
658
+ init: function () {
659
+ dz = this;
660
+ }
661
+ });
662
+ dz.on("error", function (file, errormessage) {
663
+ Alerts.warning(errormessage);
664
+ }.bind(this));
665
+ dz.on("success", function (file, data) {
666
+ Response.process(data);
667
+ }.bind(this));
668
+ dz.on("addedfile", function (file) {
669
+ this.progress.find('.progress-bar').css({ width: 0 + "%" });
670
+ this.progressText.find('span').html(0 + "%");
671
+ }.bind(this));
672
+ // Update the total progress bar
673
+ dz.on("totaluploadprogress", function (totalProgress, totalBytes, totalBytesSent) {
674
+ this.progress.find('.progress-bar').css({ width: totalProgress + "%" });
675
+ this.progressText.find('span').html(Math.round(totalProgress) + "% - " + totalBytesSent.formatKilobytes() + " / " + totalBytes.formatKilobytes());
676
+ }.bind(this));
677
+ dz.on("sending", function (file) {
678
+ // Show the total progress bar when upload starts
679
+ this.progressArea.classList.remove('collapse');
680
+ this.progress.find('.progress-bar').css({ width: 0 + "%" });
681
+ this.progressText.find('span').html(0 + "%");
682
+ }.bind(this));
683
+ // Hide the total progress bar when nothing's uploading anymore
684
+ dz.on("complete", function (file) {
685
+ this.media.reload();
686
+ }.bind(this));
687
+ // Hide the total progress bar when nothing's uploading anymore
688
+ dz.on("queuecomplete", function () {
689
+ this.progressArea.classList.add('collapse');
690
+ this.media.reload();
691
+ }.bind(this));
692
+ };
693
+ MediaService.prototype.createDirectory = function (e) {
694
+ e.preventDefault();
695
+ e.stopPropagation();
696
+ var createDirectoryModal = new ModalController({
697
+ onComplete: function () {
698
+ var form = document.getElementById('content-directories-edit-form');
699
+ new Validator(form, {
700
+ onComplete: function (response) {
701
+ Response.process(response, 5000);
702
+ if (response.success) {
703
+ this.media.reload();
704
+ createDirectoryModal.close();
705
+ }
706
+ }.bind(this)
707
+ });
708
+ }.bind(this)
709
+ });
710
+ createDirectoryModal.show($(e.currentTarget).attr('href'), this.element);
711
+ };
712
+ MediaService.prototype.deleteDirectory = function (e) {
713
+ e.preventDefault();
714
+ e.stopPropagation();
715
+ Alerts.confirm({}, function (result) {
716
+ if (result.isConfirmed) {
717
+ Inline.post(e.currentTarget.href, e.currentTarget, function (response, sender) {
718
+ // Refresh the list, using the parent directory id - stored in the response's data array.
719
+ Response.process(response, 5000);
720
+ if (response.data.length > 0) {
721
+ var listUrl = document.createElement('a');
722
+ listUrl.href = $(this.element).data('url');
723
+ listUrl.search = "?dir=".concat(response.data[0]);
724
+ this.media.reload(new URL(listUrl.href));
725
+ }
726
+ }.bind(this));
727
+ }
728
+ }.bind(this));
729
+ };
730
+ MediaService.prototype.uploadUrl = function () {
731
+ return $("#media-upload").data('url') + "?directoryId=" + $("#media-list > #upload-directory-id").val();
732
+ };
733
+ MediaService.prototype.action = function (e) {
734
+ e.preventDefault();
735
+ e.stopPropagation();
736
+ // Load media object from clicked item in the media list
737
+ var mediaObject = $(e.currentTarget).data('json');
738
+ // Perform the chosen action, which is set on the service's options when loaded.
739
+ switch (this.options.action) {
740
+ case 'select':
741
+ this.select(mediaObject, e);
742
+ break;
743
+ case 'insert':
744
+ this.insert(mediaObject, e);
745
+ break;
746
+ case 'attach':
747
+ this.attach(mediaObject, e);
748
+ break;
749
+ case 'gallery':
750
+ this.galleryClick(mediaObject, e);
751
+ break;
752
+ default:
753
+ this.show(mediaObject, e);
754
+ break;
755
+ }
756
+ };
757
+ MediaService.prototype.show = function (mediaObject, sender) {
758
+ // Load the media as a new blade to display.
759
+ this.currentBlade = new ModalController();
760
+ this.currentBlade.show($(sender.target).data('blade'), sender.target);
761
+ // TODO: On close, reload the list and reinstate the modal??
762
+ };
763
+ MediaService.prototype.select = function (mediaObject, e) {
764
+ Alerts.log("[MediaService.select] Selecting media object id ".concat(mediaObject.id, " - ").concat(mediaObject.filename, " and inserting ").concat(this.options.size, " url to target: ").concat(this.options.target));
765
+ if (this.options.target) {
766
+ var target = $(this.options.target);
767
+ switch (this.options.size) {
768
+ case 'thumb':
769
+ target.val(mediaObject.thumbUrl);
770
+ break;
771
+ case 'small':
772
+ target.val(mediaObject.smallUrl);
773
+ break;
774
+ case 'medium':
775
+ target.val(mediaObject.mediumUrl);
776
+ break;
777
+ case 'large':
778
+ target.val(mediaObject.largeUrl);
779
+ break;
780
+ case 'full':
781
+ target.val(mediaObject.url);
782
+ break;
783
+ }
784
+ }
785
+ if (this.options.refresh) {
786
+ MediaService.refresh(mediaObject, this.options.refresh);
787
+ }
788
+ // Run the callback for onAction
789
+ if (this.options.onAction) {
790
+ this.options.onAction(mediaObject);
791
+ }
792
+ };
793
+ MediaService.prototype.insert = function (mediaObject, e) {
794
+ // basic functionality to insert the correct string from the media response (from uploader) to given input element.
795
+ Alerts.log("[MediaService.insert] Selecting media object id ".concat(mediaObject.id, " - ").concat(mediaObject.filename, " and inserting ").concat(this.options.size, " image to target editor: ").concat(this.options.target));
796
+ this.options.targetEditor.insertContent('<img alt="' + mediaObject.filename + '" src="' + mediaObject.url + '" class="img-fluid" />');
797
+ // Run the callback for onAction
798
+ if (this.options.onAction) {
799
+ this.options.onAction(mediaObject);
800
+ }
801
+ };
802
+ MediaService.prototype.attach = function (mediaObject, e) {
803
+ // once file is uploaded to given directory, send media id to the given attach endpoint.
804
+ Alerts.log("[MediaService.attach] Attaching media object id ".concat(mediaObject.id, " - ").concat(mediaObject.filename, " to url: ").concat(this.options.url));
805
+ $.post(this.options.url, { mediaId: mediaObject.id }, function (response) {
806
+ Response.process(response, 5000);
807
+ MediaService.refresh(response.media, this.options.refresh);
808
+ // Run the callback for onAction
809
+ if (this.options.onAction) {
810
+ this.options.onAction(mediaObject);
811
+ }
812
+ }.bind(this));
813
+ };
814
+ MediaService.prototype.galleryClick = function (mediaObject, e) {
815
+ // once file is uploaded to given directory, send media id to the given attach endpoint.
816
+ if (!this.isMediaSelected(mediaObject)) {
817
+ Alerts.log("[MediaService.galleryClick] Adding to selected media objects - id ".concat(mediaObject.id, " - ").concat(mediaObject.filename, "."));
818
+ this.selectedMedia.push(mediaObject);
819
+ $(e.currentTarget).parents('.media-item').addClass('active');
820
+ }
821
+ else {
822
+ Alerts.log("[MediaService.galleryClick] Removing media from selection - id ".concat(mediaObject.id, " - ").concat(mediaObject.filename, ".}"));
823
+ this.selectedMedia = this.selectedMedia.filter(function (obj) {
824
+ return obj.id !== mediaObject.id;
825
+ });
826
+ $(e.currentTarget).parents('.media-item').removeClass('active');
827
+ }
828
+ };
829
+ MediaService.prototype.galleryAdd = function (e) {
830
+ e.preventDefault();
831
+ e.stopPropagation();
832
+ // once file is uploaded to given directory, send media id to the given attach endpoint.
833
+ Alerts.log("[MediaService.galleryAdd] Adding ".concat(this.selectedMedia.length, " selected media objects to url: ").concat(this.options.url));
834
+ var mediaIds = this.selectedMedia.map(function (v) {
835
+ return v.id;
836
+ });
837
+ // create the url to send to (add media id's to it as query params)
838
+ $.post(this.options.url, { media: mediaIds }, function (data) {
839
+ Response.process(data);
840
+ // refresh the gallery - -
841
+ var galleryEl = document.getElementById(this.options.target);
842
+ var gallery = galleryEl.hoodDataList;
843
+ gallery.reload();
844
+ // Run the callback for onAction
845
+ if (this.options.onAction) {
846
+ this.options.onAction(data.media);
847
+ }
848
+ }.bind(this));
849
+ };
850
+ MediaService.prototype.isMediaSelected = function (mediaObject) {
851
+ var added = false;
852
+ this.selectedMedia.forEach(function (value, index, array) {
853
+ if (value.id == mediaObject.id) {
854
+ added = true;
855
+ }
856
+ });
857
+ return added;
858
+ };
859
+ MediaService.refresh = function (media, refresh) {
860
+ var icon = media.icon;
861
+ if (media.genericFileType === "Image") {
862
+ icon = media.mediumUrl;
863
+ }
864
+ if (refresh) {
865
+ var $image = $(refresh);
866
+ $image.css({
867
+ 'background-image': 'url(' + icon + ')'
868
+ });
869
+ $image.find('img').attr('src', icon);
870
+ $image.removeClass('loading');
871
+ }
872
+ };
873
+ MediaService.prototype.delete = function (e) {
874
+ e.preventDefault();
875
+ e.stopPropagation();
876
+ Alerts.confirm({
877
+ html: 'This file will be permanently deleted, are you sure?'
878
+ }, function (result) {
879
+ if (result.isConfirmed) {
880
+ Inline.post(e.currentTarget.href, e.currentTarget, function (response) {
881
+ Response.process(response, 5000);
882
+ this.media.reload();
883
+ if (this.currentBlade) {
884
+ this.currentBlade.close();
885
+ }
886
+ }.bind(this));
887
+ }
888
+ }.bind(this));
889
+ };
890
+ return MediaService;
891
+ }());
892
+ var MediaModal = /** @class */ (function () {
893
+ function MediaModal() {
894
+ $('body').on('click', '[data-hood-media=attach],[data-hood-media=select],[data-hood-media=gallery]', this.load.bind(this));
895
+ $('body').on('click', '[data-hood-media=clear]', this.clear.bind(this));
896
+ $('[data-hood-media=gallery]').each(this.initGallery.bind(this));
897
+ }
898
+ MediaModal.prototype.initGallery = function (index, element) {
899
+ // setup the gallery list also, just a simple list jobby, and attach it to the
900
+ var el = document.getElementById(element.dataset.hoodMediaTarget);
901
+ if (el) {
902
+ new DataList(el, {
903
+ onComplete: function (data, sender) {
904
+ Alerts.log('Finished loading gallery media list.', 'info');
905
+ }.bind(this)
906
+ });
907
+ }
908
+ };
909
+ MediaModal.prototype.load = function (e) {
910
+ e.preventDefault();
911
+ e.stopPropagation();
912
+ this.element = e.currentTarget;
913
+ if (this.modal && this.modal.isOpen) {
914
+ return;
915
+ }
916
+ this.modal = new ModalController({
917
+ onComplete: function (sender) {
918
+ this.list = document.getElementById('media-list');
919
+ this.service = new MediaService(this.list, {
920
+ action: this.element.dataset.hoodMedia,
921
+ url: this.element.dataset.hoodMediaUrl,
922
+ refresh: this.element.dataset.hoodMediaRefresh,
923
+ target: this.element.dataset.hoodMediaTarget,
924
+ size: this.element.dataset.hoodMediaSize,
925
+ beforeAction: function (sender, mediaObject) {
926
+ }.bind(this),
927
+ onAction: function (sender, mediaObject) {
928
+ this.modal.close();
929
+ }.bind(this),
930
+ onListLoad: function (sender) {
931
+ },
932
+ onListRender: function (data) {
933
+ return data;
934
+ },
935
+ onListComplete: function (data) {
936
+ },
937
+ onError: function (jqXHR, textStatus, errorThrown) {
938
+ },
939
+ });
940
+ }.bind(this)
941
+ });
942
+ this.modal.show($(e.currentTarget).data('hood-media-list'), e.currentTarget);
943
+ };
944
+ MediaModal.prototype.clear = function (e) {
945
+ e.preventDefault();
946
+ e.stopPropagation();
947
+ Alerts.confirm({}, function (result) {
948
+ if (result.isConfirmed) {
949
+ Inline.post(e.currentTarget.href, e.currentTarget, function (response) {
950
+ Response.process(response, 5000);
951
+ MediaService.refresh(response.media, e.currentTarget.dataset.hoodMediaRefresh);
952
+ }.bind(this));
953
+ }
954
+ }.bind(this));
955
+ };
956
+ return MediaModal;
957
+ }());
958
+
959
+ var Editors = /** @class */ (function () {
960
+ function Editors(options) {
961
+ this.options = {
962
+ linkClasses: [
963
+ { title: 'None', value: '' },
964
+ { title: 'Button link', value: 'btn btn-default' },
965
+ { title: 'Theme coloured button link', value: 'btn btn-primary' },
966
+ { title: 'Popup image/video', value: 'colorbox-iframe' },
967
+ { title: 'Button popup link', value: 'btn btn-default colorbox-iframe' },
968
+ { title: 'Theme coloured button popup link', value: 'btn btn-primary colorbox-iframe' },
969
+ { title: 'Large link', value: 'font-lg' },
970
+ { title: 'Large button link', value: 'btn btn-default btn-lg' },
971
+ { title: 'Large theme coloured button link', value: 'btn btn-primary btn-lg' },
972
+ { title: 'Large popup image/video', value: 'font-lg colorbox-iframe' },
973
+ { title: 'Large Button popup link', value: 'btn btn-default btn-lg colorbox-iframe' },
974
+ { title: 'Theme coloured button popup link', value: 'btn btn-primary btn-lg colorbox-iframe' }
975
+ ],
976
+ imageClasses: [
977
+ { title: 'None', value: '' },
978
+ { title: 'Full Width', value: 'user-image full' },
979
+ { title: 'Left Aligned', value: 'user-image left' },
980
+ { title: 'Centered', value: 'user-image center' },
981
+ { title: 'Right Aligned', value: 'user-image right' },
982
+ { title: 'Inline with text, top aligned', value: 'user-image inline top' },
983
+ { title: 'Inline with text, middle aligned', value: 'user-image inline' },
984
+ { title: 'Inline with text, bottom aligned', value: 'user-image inline bottom' },
985
+ { title: 'Pulled Left', value: 'user-image pull-left' },
986
+ { title: 'Pulled Right', value: 'user-image pull-right' },
987
+ ]
988
+ };
989
+ this.options = __assign(__assign({}, this.options), options);
990
+ }
991
+ Editors.prototype.richTextEditors = function () {
992
+ tinymce__default["default"].init({
993
+ selector: '.tinymce-full',
994
+ height: 150,
995
+ menubar: false,
996
+ plugins: [
997
+ 'advlist autolink lists link image charmap print preview anchor media',
998
+ 'searchreplace visualblocks code fullscreen',
999
+ 'insertdatetime media contextmenu paste code textcolor'
1000
+ ],
1001
+ toolbar: "fullscreen | styleselect forecolor backcolor | hoodimage link media image | bold italic | alignleft aligncenter alignright | bullist numlist | table | undo redo",
1002
+ link_class_list: this.options.linkClasses,
1003
+ image_class_list: this.options.imageClasses,
1004
+ setup: this.setupCommands.bind(this),
1005
+ image_dimensions: false,
1006
+ content_css: [
1007
+ '/dist/css/editor.css'
1008
+ ],
1009
+ });
1010
+ tinymce__default["default"].init({
1011
+ selector: '.tinymce-simple',
1012
+ height: 150,
1013
+ plugins: [
1014
+ 'advlist autolink lists link image charmap print preview anchor media',
1015
+ 'searchreplace visualblocks code fullscreen',
1016
+ 'insertdatetime media contextmenu paste code'
1017
+ ],
1018
+ menubar: false,
1019
+ toolbar: 'fullscreen | bold italic | bullist numlist | undo redo | link',
1020
+ link_class_list: this.options.linkClasses,
1021
+ image_class_list: this.options.imageClasses,
1022
+ setup: this.setupCommands.bind(this),
1023
+ image_dimensions: false
1024
+ });
1025
+ tinymce__default["default"].init({
1026
+ selector: '.tinymce-full-content',
1027
+ height: 500,
1028
+ menubar: false,
1029
+ plugins: [
1030
+ 'advlist autolink lists link image charmap print preview anchor media',
1031
+ 'searchreplace visualblocks code fullscreen',
1032
+ 'insertdatetime media contextmenu paste code textcolor'
1033
+ ],
1034
+ toolbar: "fullscreen | styleselect forecolor backcolor | hoodimage link media image | bold italic | alignleft aligncenter alignright | bullist numlist | table | undo redo",
1035
+ link_class_list: this.options.linkClasses,
1036
+ image_class_list: this.options.imageClasses,
1037
+ setup: this.setupCommands.bind(this),
1038
+ image_dimensions: false
1039
+ });
1040
+ tinymce__default["default"].init({
1041
+ selector: '.tinymce-simple-content',
1042
+ height: 500,
1043
+ plugins: [
1044
+ 'advlist autolink lists link image charmap print preview anchor media',
1045
+ 'searchreplace visualblocks code fullscreen',
1046
+ 'insertdatetime media contextmenu paste code'
1047
+ ],
1048
+ menubar: false,
1049
+ toolbar: 'fullscreen | bold italic | bullist numlist | undo redo | link',
1050
+ link_class_list: this.options.linkClasses,
1051
+ image_class_list: this.options.imageClasses,
1052
+ image_dimensions: false
1053
+ });
1054
+ };
1055
+ Editors.prototype.setupCommands = function (editor) {
1056
+ this.currentEditor = $('#' + editor.id);
1057
+ if (this.currentEditor.data('hoodMediaList')) {
1058
+ editor.addButton('hoodimage', {
1059
+ text: 'Insert image...',
1060
+ icon: false,
1061
+ onclick: function (e) {
1062
+ this.mediaModal = new ModalController({
1063
+ onComplete: function (sender) {
1064
+ this.list = document.getElementById('media-list');
1065
+ this.service = new MediaService(this.list, {
1066
+ action: 'insert',
1067
+ url: this.currentEditor.data('hoodMediaList'),
1068
+ targetEditor: editor,
1069
+ size: this.currentEditor.data('hoodMediaSize'),
1070
+ beforeAction: function (sender, mediaObject) {
1071
+ }.bind(this),
1072
+ onAction: function (sender, mediaObject) {
1073
+ this.mediaModal.close();
1074
+ }.bind(this),
1075
+ onListLoad: function (sender) {
1076
+ },
1077
+ onListRender: function (data) {
1078
+ return data;
1079
+ },
1080
+ onListComplete: function (data) {
1081
+ },
1082
+ onError: function (jqXHR, textStatus, errorThrown) {
1083
+ },
1084
+ });
1085
+ }.bind(this)
1086
+ });
1087
+ this.mediaModal.show(this.currentEditor.data('hoodMediaList'), e.currentTarget);
1088
+ }.bind(this)
1089
+ });
1090
+ }
1091
+ };
1092
+ return Editors;
1093
+ }());
1094
+
1095
+ var Handlers = /** @class */ (function () {
1096
+ function Handlers() {
1097
+ }
1098
+ /**
1099
+ * Initialise all default Hood CMS handlers.
1100
+ */
1101
+ Handlers.prototype.initDefaultHandlers = function () {
1102
+ this.checkboxToCsvInput();
1103
+ this.iconSelector();
1104
+ this.initSelectValues();
1105
+ this.scrollHandlers();
1106
+ this.selectText();
1107
+ this.setValueOnClick();
1108
+ this.submitOnChange();
1109
+ };
1110
+ /**
1111
+ * Sets values of any selects that have the value set in data-selected, useful for
1112
+ */
1113
+ Handlers.prototype.initSelectValues = function (tag) {
1114
+ if (tag === void 0) { tag = 'body'; }
1115
+ $(tag).find('select[data-selected]').each(this.initSelectValuesHandler);
1116
+ };
1117
+ Handlers.prototype.initSelectValuesHandler = function (index, element) {
1118
+ var sel = $(this).data('selected');
1119
+ if (sel !== 'undefined' && sel !== '') {
1120
+ var selected = String(sel);
1121
+ $(this).val(selected);
1122
+ }
1123
+ };
1124
+ /**
1125
+ * Sets up any Hood Icon selector fields, requires the correct HTML setup.
1126
+ */
1127
+ Handlers.prototype.iconSelector = function (tag) {
1128
+ if (tag === void 0) { tag = 'body'; }
1129
+ $(tag).find('[data-hood-icon]').each(this.iconSelectorHandler);
1130
+ };
1131
+ Handlers.prototype.iconSelectorHandler = function (index, element) {
1132
+ var $tag = $(this);
1133
+ var input = $tag.find('input[data-hood-icon-input]');
1134
+ var display = $tag.find('[data-hood-icon-display]');
1135
+ var collapse = $tag.find('.collapse');
1136
+ $tag.find('[data-hood-icon-key][data-hood-icon-value]').on('click', function () {
1137
+ $tag.find('[data-hood-icon-key][data-hood-icon-value]').removeClass('active');
1138
+ $(this).addClass('active');
1139
+ var key = $(this).data('hoodIconKey');
1140
+ var value = $(this).data('hoodIconValue');
1141
+ $(this);
1142
+ display.html(value);
1143
+ input.val(key);
1144
+ if (collapse) {
1145
+ collapse.removeClass('show');
1146
+ }
1147
+ });
1148
+ };
1149
+ /**
1150
+ * Submits the form when input is changed, mark inputs with .submit-on-change class.
1151
+ */
1152
+ Handlers.prototype.selectText = function (tag) {
1153
+ if (tag === void 0) { tag = 'body'; }
1154
+ $(tag).on('click', '.select-text', this.selectTextHandler);
1155
+ };
1156
+ Handlers.prototype.selectTextHandler = function () {
1157
+ var $this = $(this);
1158
+ $this.select();
1159
+ // Work around Chrome's little problem
1160
+ $this.mouseup(function () {
1161
+ // Prevent further mouseup intervention
1162
+ $this.unbind("mouseup");
1163
+ return false;
1164
+ });
1165
+ };
1166
+ /**
1167
+ * Attaches handlers for default scrolling functions, scroll to top, scroll to target (with header.header offset calculated)
1168
+ * and scroll to target direct (with no calculated offset).
1169
+ */
1170
+ Handlers.prototype.scrollHandlers = function (tag) {
1171
+ if (tag === void 0) { tag = 'body'; }
1172
+ $(tag).on('click', '.scroll-top, .scroll-to-top', this.scrollTop);
1173
+ $(tag).on('click', '.scroll-target, .scroll-to-target', this.scrollTarget);
1174
+ $(tag).on('click', '.scroll-target-direct, .scroll-to-target-direct', this.scrollTargetDirect);
1175
+ };
1176
+ Handlers.prototype.scrollTop = function (e) {
1177
+ if (e)
1178
+ e.preventDefault();
1179
+ $('html, body').animate({ scrollTop: 0 }, 800);
1180
+ return false;
1181
+ };
1182
+ Handlers.prototype.scrollTarget = function (e) {
1183
+ if (e)
1184
+ e.preventDefault();
1185
+ var url = $(this).attr('href').split('#')[0];
1186
+ if (url !== window.location.pathname && url !== "") {
1187
+ return;
1188
+ }
1189
+ var target = this.hash;
1190
+ var $target = $(target);
1191
+ var $header = $('header.header');
1192
+ var headerOffset = 0;
1193
+ if ($header) {
1194
+ headerOffset = $header.height();
1195
+ }
1196
+ if ($(this).data('offset'))
1197
+ $('html, body').stop().animate({
1198
+ 'scrollTop': $target.offset().top - $(this).data('offset')
1199
+ }, 900, 'swing');
1200
+ else
1201
+ $('html, body').stop().animate({
1202
+ 'scrollTop': $target.offset().top - headerOffset
1203
+ }, 900, 'swing');
1204
+ };
1205
+ Handlers.prototype.scrollTargetDirect = function () {
1206
+ var scrollTop = $('body').scrollTop();
1207
+ var top = $($(this).attr('href')).offset().top;
1208
+ $('html, body').animate({
1209
+ scrollTop: top
1210
+ }, Math.abs(top - scrollTop));
1211
+ return false;
1212
+ };
1213
+ /**
1214
+ * Compiles any selected checkboxes with matching data-hood-csv-input tags,
1215
+ * then saves the CSV list of the values to the input given in the tag.
1216
+ */
1217
+ Handlers.prototype.checkboxToCsvInput = function (tag) {
1218
+ if (tag === void 0) { tag = 'body'; }
1219
+ $(tag).on('change', 'input[type=checkbox][data-hood-csv-input]', this.checkboxToCsvInputHandler);
1220
+ };
1221
+ Handlers.prototype.checkboxToCsvInputHandler = function (e) {
1222
+ if (e)
1223
+ e.preventDefault();
1224
+ // when i change - create an array, with any other checked of the same data-input checkboxes. and add to the data-input referenced tag.
1225
+ var items = new Array();
1226
+ $('input[data-hood-csv-input="' + $(this).data('hoodCsvInput') + '"]').each(function () {
1227
+ if ($(this).is(":checked"))
1228
+ items.push($(this).val());
1229
+ });
1230
+ var id = '#' + $(this).data('input');
1231
+ var vals = JSON.stringify(items);
1232
+ $(id).val(vals);
1233
+ };
1234
+ /**
1235
+ * Submits the form when input is changed, mark inputs with .submit-on-change class.
1236
+ */
1237
+ Handlers.prototype.submitOnChange = function (tag) {
1238
+ if (tag === void 0) { tag = 'body'; }
1239
+ $(tag).on('change', '.submit-on-change', this.submitOnChangeHandler);
1240
+ };
1241
+ Handlers.prototype.submitOnChangeHandler = function (e) {
1242
+ if (e)
1243
+ e.preventDefault();
1244
+ $(this).parents('form').submit();
1245
+ };
1246
+ /**
1247
+ * Sets the value of the input [data-target] when clicked to the value in [data-value]
1248
+ */
1249
+ Handlers.prototype.setValueOnClick = function (tag) {
1250
+ if (tag === void 0) { tag = 'body'; }
1251
+ $(tag).on('click', '.click-select[data-target][data-value]', this.setValueOnClickHandler);
1252
+ };
1253
+ Handlers.prototype.setValueOnClickHandler = function () {
1254
+ var $this = $(this);
1255
+ var targetId = '#' + $this.data('target');
1256
+ $(targetId).val($this.data('value'));
1257
+ $(targetId).trigger('change');
1258
+ $('.click-select.clean[data-target="' + $this.data('target') + '"]').each(function () { $(this).removeClass('active'); });
1259
+ $('.click-select.clean[data-target="' + $this.data('target') + '"][data-value="' + $this.data('value') + '"]').each(function () { $(this).addClass('active'); });
1260
+ };
1261
+ return Handlers;
1262
+ }());
1263
+
1264
+ var Uploader = /** @class */ (function () {
1265
+ function Uploader() {
1266
+ if ($('.image-uploader').length || $('.gallery-uploader').length) {
1267
+ $(".upload-progress-bar").hide();
1268
+ $('.image-uploader').each(this.singleImage);
1269
+ $('.gallery-uploader').each(this.gallery);
1270
+ }
1271
+ }
1272
+ Uploader.prototype.refreshImage = function (sender, data) {
1273
+ $(sender.data('preview')).css({
1274
+ 'background-image': 'url(' + data.media.smallUrl + ')'
1275
+ });
1276
+ $(sender.data('preview')).find('img').attr('src', data.media.smallUrl);
1277
+ };
1278
+ Uploader.prototype.singleImage = function () {
1279
+ var tag = '#' + $(this).attr('id');
1280
+ var $tag = $(tag);
1281
+ var jsontag = '#' + $(this).attr('json');
1282
+ var avatarDropzone = null;
1283
+ $tag.dropzone({
1284
+ url: $tag.data('url'),
1285
+ maxFiles: 1,
1286
+ paramName: 'file',
1287
+ parallelUploads: 1,
1288
+ acceptedFiles: $tag.data('types') || ".png,.jpg,.jpeg,.gif",
1289
+ autoProcessQueue: true,
1290
+ previewsContainer: false,
1291
+ clickable: tag,
1292
+ init: function () {
1293
+ avatarDropzone = this;
1294
+ }
1295
+ });
1296
+ avatarDropzone.on("addedfile", function () {
1297
+ });
1298
+ avatarDropzone.on("totaluploadprogress", function (progress) {
1299
+ $(".upload-progress-bar." + tag.replace('#', '') + " .progress-bar").css({ width: progress + "%" });
1300
+ });
1301
+ avatarDropzone.on("sending", function (file) {
1302
+ $(".upload-progress-bar." + tag.replace('#', '')).show();
1303
+ $($tag.data('preview')).addClass('loading');
1304
+ });
1305
+ avatarDropzone.on("queuecomplete", function (progress) {
1306
+ $(".upload-progress-bar." + tag.replace('#', '')).hide();
1307
+ });
1308
+ avatarDropzone.on("success", function (file, response) {
1309
+ if (response.success) {
1310
+ if (response.media) {
1311
+ $(jsontag).val(JSON.stringify(response.media));
1312
+ $($tag.data('preview')).css({
1313
+ 'background-image': 'url(' + response.media.smallUrl + ')'
1314
+ });
1315
+ $($tag.data('preview')).find('img').attr('src', response.media.smallUrl);
1316
+ }
1317
+ Alerts.success("New image added!");
1318
+ }
1319
+ else {
1320
+ Alerts.error("There was a problem adding the image: " + response.error);
1321
+ }
1322
+ avatarDropzone.removeFile(file);
1323
+ $($tag.data('preview')).removeClass('loading');
1324
+ });
1325
+ };
1326
+ Uploader.prototype.gallery = function () {
1327
+ var tag = '#' + $(this).attr('id');
1328
+ var $tag = $(tag);
1329
+ var previewNode = document.querySelector(tag + "-template");
1330
+ previewNode.id = "";
1331
+ var previewTemplate = previewNode.parentNode.innerHTML;
1332
+ previewNode.parentNode.removeChild(previewNode);
1333
+ var galleryDropzone = null;
1334
+ $tag.dropzone({
1335
+ url: $tag.data('url'),
1336
+ thumbnailWidth: 80,
1337
+ thumbnailHeight: 80,
1338
+ parallelUploads: 5,
1339
+ previewTemplate: previewTemplate,
1340
+ paramName: 'files',
1341
+ acceptedFiles: $tag.data('types') || ".png,.jpg,.jpeg,.gif",
1342
+ autoProcessQueue: true,
1343
+ previewsContainer: "#previews",
1344
+ clickable: ".fileinput-button",
1345
+ init: function () {
1346
+ galleryDropzone = this;
1347
+ }
1348
+ });
1349
+ $(tag + " .cancel").hide();
1350
+ galleryDropzone.on("addedfile", function (file) {
1351
+ $(file.previewElement.querySelector(".complete")).hide();
1352
+ $(file.previewElement.querySelector(".cancel")).show();
1353
+ $(tag + " .cancel").show();
1354
+ });
1355
+ // Update the total progress bar
1356
+ galleryDropzone.on("totaluploadprogress", function (totalProgress, totalBytes, totalBytesSent) {
1357
+ var progressBar = document.querySelector("#total-progress .progress-bar");
1358
+ progressBar.style.width = totalProgress + "%";
1359
+ });
1360
+ galleryDropzone.on("sending", function (file) {
1361
+ // Show the total progress bar when upload starts
1362
+ var progressBar = document.querySelector("#total-progress");
1363
+ progressBar.style.opacity = "1";
1364
+ });
1365
+ // Hide the total progress bar when nothing's uploading anymore
1366
+ galleryDropzone.on("complete", function (file) {
1367
+ $(file.previewElement.querySelector(".cancel")).hide();
1368
+ $(file.previewElement.querySelector(".progress")).hide();
1369
+ $(file.previewElement.querySelector(".complete")).show();
1370
+ console.error("Uploader.Gallery.Dropzone.OnComplete - Inline.Refresh('.gallery') is not implemented.");
1371
+ //Inline.Refresh('.gallery');
1372
+ });
1373
+ // Hide the total progress bar when nothing's uploading anymore
1374
+ galleryDropzone.on("queuecomplete", function (progress) {
1375
+ var totalProgress = document.querySelector("#total-progress");
1376
+ totalProgress.style.opacity = "0";
1377
+ $(tag + " .cancel").hide();
1378
+ });
1379
+ galleryDropzone.on("success", function (file, response) {
1380
+ console.error("Uploader.Gallery.Dropzone.OnSuccess - Inline.Refresh('.gallery') is not implemented.");
1381
+ //Inline.Refresh('.gallery');
1382
+ if (response.success) {
1383
+ Alerts.success("New images added!");
1384
+ }
1385
+ else {
1386
+ Alerts.error("There was a problem adding the profile image: " + response.error);
1387
+ }
1388
+ });
1389
+ // Setup the buttons for all transfers
1390
+ // The "add files" button doesn't need to be setup because the config
1391
+ // `clickable` has already been specified.
1392
+ $(".actions .cancel").click(function () {
1393
+ galleryDropzone.removeAllFiles(true);
1394
+ });
1395
+ };
1396
+ return Uploader;
1397
+ }());
1398
+
1399
+ var HoodApi = /** @class */ (function () {
1400
+ function HoodApi() {
1401
+ this.alerts = new Alerts();
1402
+ this.uploader = new Uploader();
1403
+ this.handlers = new Handlers();
1404
+ this.editors = new Editors();
1405
+ this.colorPickers = new ColorPickers();
1406
+ this.mediaModal = new MediaModal();
1407
+ // Global Handlers
1408
+ this.setupLoaders();
1409
+ }
1410
+ HoodApi.prototype.setupLoaders = function () {
1411
+ $('body').on('loader-show', function () { Alerts.success("Showing loader..."); });
1412
+ $('body').on('loader-hide', function () { Alerts.error("Hiding loader..."); });
1413
+ };
1414
+ return HoodApi;
1415
+ }());
1416
+
1417
+ /// <reference types="google.maps" />
1418
+ var PropertyController = /** @class */ (function () {
1419
+ function PropertyController() {
1420
+ this.map = null;
1421
+ this.center = { lat: 30, lng: -110 };
1422
+ this.initList();
1423
+ }
1424
+ PropertyController.prototype.initList = function () {
1425
+ this.element = document.getElementById('property-list');
1426
+ if (!this.element) {
1427
+ return;
1428
+ }
1429
+ this.list = new DataList(this.element, {
1430
+ onComplete: function (data, sender) {
1431
+ Alerts.log('Finished loading property list.', 'info');
1432
+ }.bind(this)
1433
+ });
1434
+ };
1435
+ PropertyController.prototype.initMapList = function () {
1436
+ this.mapListElement = document.getElementById('property-map-list');
1437
+ if (!this.mapElement) {
1438
+ return;
1439
+ }
1440
+ this.mapList = new DataList(this.mapListElement, {
1441
+ onComplete: function (data, sender) {
1442
+ Alerts.log('Finished loading map list.', 'info');
1443
+ this.reloadMarkers();
1444
+ }.bind(this)
1445
+ });
1446
+ };
1447
+ PropertyController.prototype.initMap = function (mapElementId) {
1448
+ if (mapElementId === void 0) { mapElementId = 'property-map'; }
1449
+ this.mapElement = document.getElementById(mapElementId);
1450
+ if (!this.mapElement) {
1451
+ return;
1452
+ }
1453
+ this.center = { lat: +this.mapElement.dataset.lat, lng: +this.mapElement.dataset.long };
1454
+ this.map = new google.maps.Map(this.mapElement, {
1455
+ zoom: +this.mapElement.dataset.zoom || 15,
1456
+ center: this.center,
1457
+ scrollwheel: false
1458
+ });
1459
+ $(window).resize(function () {
1460
+ google.maps.event.trigger(this.map, 'resize');
1461
+ }.bind(this));
1462
+ google.maps.event.trigger(this.map, 'resize');
1463
+ this.initMapList();
1464
+ };
1465
+ PropertyController.prototype.reloadMarkers = function () {
1466
+ var infowindow = null;
1467
+ if (!this.mapElement) {
1468
+ return;
1469
+ }
1470
+ var map = this.map;
1471
+ if (this.markers) {
1472
+ for (var i = 0; i < this.markers.length; i++) {
1473
+ this.markers[i].setMap(null);
1474
+ }
1475
+ }
1476
+ this.markers = [];
1477
+ var locations = $("#property-map-locations").data('locations');
1478
+ locations.map(function (location, i) {
1479
+ var marker = new google.maps.Marker({
1480
+ position: new google.maps.LatLng(+location.Latitude, +location.Longitude),
1481
+ map: this.map,
1482
+ optimized: true // makes SVG icons work in IE
1483
+ });
1484
+ //marker.setIcon({
1485
+ // url: '/images/marker.png',
1486
+ // size: new google.maps.Size(30, 41),
1487
+ // scaledSize: new google.maps.Size(30, 41)
1488
+ //});
1489
+ 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>");
1490
+ google.maps.event.addListener(marker, 'click', function () {
1491
+ if (infowindow) {
1492
+ infowindow.close();
1493
+ }
1494
+ infowindow = new google.maps.InfoWindow({
1495
+ content: this.info
1496
+ });
1497
+ infowindow.open(map, this);
1498
+ }.bind(this));
1499
+ this.markers.push(marker);
1500
+ }.bind(this));
1501
+ };
1502
+ return PropertyController;
1503
+ }());
1504
+
1505
+ /// <reference types="google.maps" />
1506
+ var App = /** @class */ (function (_super) {
1507
+ __extends(App, _super);
1508
+ function App() {
1509
+ var _this = _super.call(this) || this;
1510
+ // Hook up default handlers.
1511
+ _this.handlers.initDefaultHandlers();
1512
+ _this.initContactForms();
1513
+ // Admin Controllers
1514
+ _this.propertyController = new PropertyController();
1515
+ return _this;
1516
+ }
1517
+ App.prototype.initGoogleMaps = function (tag) {
1518
+ if (tag === void 0) { tag = '.google-map'; }
1519
+ $(tag).each(function () {
1520
+ var myLatLng = new google.maps.LatLng($(this).data('lat'), $(this).data('long'));
1521
+ console.log('Loading map at: ' + $(this).data('lat') + ', ' + $(this).data('long'));
1522
+ var map = new google.maps.Map(this, {
1523
+ zoom: $(this).data('zoom') || 15,
1524
+ center: myLatLng,
1525
+ scrollwheel: false
1526
+ });
1527
+ new google.maps.Marker({
1528
+ position: myLatLng,
1529
+ map: map,
1530
+ title: $(this).data('marker')
1531
+ });
1532
+ $(window).resize(function () {
1533
+ google.maps.event.trigger(map, 'resize');
1534
+ });
1535
+ google.maps.event.trigger(map, 'resize');
1536
+ });
1537
+ };
1538
+ /**
1539
+ * Initialisation function for contact forms on the site, will add validator, and submit/functionality to any forms matching the given tag selector string.
1540
+ * @param {string='.contact-form'} tag
1541
+ */
1542
+ App.prototype.initContactForms = function (tag) {
1543
+ if (tag === void 0) { tag = '.contact-form'; }
1544
+ var $form = $(tag);
1545
+ $form.find('.thank-you').hide();
1546
+ $form.find('.form-content').show();
1547
+ var form = $(tag)[0];
1548
+ new Validator(form, {
1549
+ onComplete: function (response) {
1550
+ Response.process(response, 5000);
1551
+ if (response.success) {
1552
+ if ($form.attr('data-redirect'))
1553
+ window.location.href = $form.attr('data-redirect');
1554
+ if ($form.attr('data-alert-message'))
1555
+ Alerts.success($form.attr('data-alert-message'), "Success");
1556
+ $form.find('.form').hide();
1557
+ $form.find('.thank-you').show();
1558
+ }
1559
+ else {
1560
+ if ($form.attr('data-alert-error'))
1561
+ Alerts.error($form.attr('data-alert-error'), "Error");
1562
+ else
1563
+ Alerts.error("There was an error sending the message: " + response.errors, "Error");
1564
+ }
1565
+ }.bind(this)
1566
+ });
1567
+ };
1568
+ return App;
1569
+ }(HoodApi));
1570
+ window.hood = new App();
1571
+
1572
+ exports.App = App;
1573
+
1574
+ Object.defineProperty(exports, '__esModule', { value: true });
1575
+
1576
+ }));
1577
+ if (typeof this !== 'undefined' && this.hood){ this.hoodCMS = this.Hood = this.hoodCMS = this.HoodCMS = this.hood }
1578
+ //# sourceMappingURL=app.js.map