hoodcms 5.0.13 → 6.0.0

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.
@@ -1,8 +1,8 @@
1
- import { Alerts } from "./Alerts";
2
- import { ColorPickers } from "./ColorPicker";
3
- import { Editors } from "./Editors";
1
+ /// <reference types="google.maps" />
2
+
3
+ import { Response, Validator } from "..";
4
+ import { Alerts } from "./Alerts";
4
5
  import { Handlers } from "./Handlers";
5
- import { MediaModal } from "./Media";
6
6
  import { Uploader } from "./Uploader";
7
7
 
8
8
  declare global {
@@ -17,22 +17,104 @@ declare global {
17
17
  }
18
18
  }
19
19
 
20
- export class HoodApi implements Hood {
20
+ /**
21
+ * Base class for extending a Hood CMS website, ensure you call HoodApi.initialise() to setup loaders and contact form defaults.
22
+ */
23
+ export class HoodApi {
21
24
  alerts: Alerts = new Alerts();
22
- uploader: Uploader = new Uploader();
23
25
  handlers: Handlers = new Handlers();
24
- editors: Editors = new Editors();
25
- colorPickers: ColorPickers = new ColorPickers();
26
-
27
- private mediaModal: MediaModal = new MediaModal();
26
+ uploader: Uploader = new Uploader();
28
27
 
29
28
  constructor() {
30
- // Global Handlers
29
+ }
30
+
31
+ // Initialise Hood CMS site defaults, can be overridden or individual setup items can be called instead of the initialise function.
32
+ initialise() {
33
+ // Initialise loaders (default, adds loading to body tag)
31
34
  this.setupLoaders();
35
+
36
+ // Hook up default handlers.
37
+ this.handlers.initDefaultHandlers();
38
+
39
+ // Init hood contact forms.
40
+ this.initContactForms();
32
41
  }
33
42
 
43
+ /**
44
+ * Default Hood CMS loaders, can be used however, this simply adds a "loading" class to the body tag on show/hide.
45
+ */
34
46
  setupLoaders(): void {
35
- $('body').on('loader-show', function () { Alerts.success("Showing loader..."); })
36
- $('body').on('loader-hide', function () { Alerts.error("Hiding loader..."); })
47
+ $('body').on('loader-show', function () { document.body.classList.add('loading') })
48
+ $('body').on('loader-hide', function () { document.body.classList.remove('loading') })
37
49
  }
38
- }
50
+
51
+ /**
52
+ * Default initialisation function for Google Maps, should be called as the callback from the Google Maps API script tag.
53
+ */
54
+ initGoogleMaps(tag: string = '.google-map') {
55
+
56
+ $(tag).each(function () {
57
+
58
+ var myLatLng = new google.maps.LatLng($(this).data('lat'), $(this).data('long'));
59
+
60
+ console.log('Loading map at: ' + $(this).data('lat') + ', ' + $(this).data('long'));
61
+
62
+ var map = new google.maps.Map(this, {
63
+ zoom: $(this).data('zoom') || 15,
64
+ center: myLatLng,
65
+ scrollwheel: false
66
+ });
67
+
68
+ var marker = new google.maps.Marker({
69
+ position: myLatLng,
70
+ map: map,
71
+ title: $(this).data('marker')
72
+ });
73
+
74
+ $(window).on('resize', function () {
75
+ google.maps.event.trigger(map, 'resize');
76
+ });
77
+ google.maps.event.trigger(map, 'resize');
78
+
79
+ });
80
+
81
+ }
82
+
83
+ /**
84
+ * Initialisation function for contact forms on the site, will add validator, and submit/functionality to any forms matching the given tag selector string.
85
+ */
86
+ initContactForms(tag: string = '.contact-form') {
87
+
88
+ let $form = $(tag);
89
+
90
+ $form.find('.thank-you').hide();
91
+ $form.find('.form-content').show();
92
+
93
+ let form: HTMLFormElement = $(tag)[0] as HTMLFormElement;
94
+ new Validator(form, {
95
+ onComplete: function (this: HoodApi, response: Response) {
96
+ if (response.success) {
97
+
98
+ if ($form.attr('data-redirect'))
99
+ window.location.href = $form.attr('data-redirect');
100
+
101
+ if ($form.attr('data-alert-message'))
102
+ Alerts.success($form.attr('data-alert-message'));
103
+
104
+ $form.find('.form').hide();
105
+ $form.find('.thank-you').show();
106
+ } else {
107
+ if ($form.attr('data-alert-error'))
108
+ Alerts.error($form.attr('data-alert-error'));
109
+ else {
110
+ console.error(response.errors);
111
+ Alerts.error("There are errors on the form, please check your answers and try again.");
112
+ }
113
+ }
114
+
115
+ }.bind(this)
116
+ });
117
+
118
+ }
119
+
120
+ }
@@ -29,7 +29,7 @@ export interface ValidatorOptions {
29
29
  export class Validator {
30
30
  element: HTMLFormElement;
31
31
  options: ValidatorOptions = {
32
- errorAlert: 'There are errors, please check the form.',
32
+ errorAlert: 'There are errors on the form, please check your answers and try again.',
33
33
  useAjax: true
34
34
  };
35
35
 
package/src/ts/index.ts CHANGED
@@ -5,7 +5,6 @@ export * from './models/Property'
5
5
  export * from './models/Users'
6
6
 
7
7
  export * from './core/Alerts'
8
- export * from './core/BaseSite'
9
8
  export * from './core/ColorPicker'
10
9
  export * from './core/DataList'
11
10
  export * from './core/Editors'
package/temp.txt ADDED
@@ -0,0 +1 @@
1
+ 8^N2a43)Kd|.wdl,
@@ -1,6 +0,0 @@
1
- export declare class BaseSite {
2
- constructor();
3
- initialise(): void;
4
- onLoad(): void;
5
- onResize(): void;
6
- }
@@ -1,14 +0,0 @@
1
- export class BaseSite {
2
- constructor() {
3
- // Initialise
4
- this.initialise();
5
- $(window).on('load', this.onLoad.bind(this));
6
- $(window).on('resize', this.onResize.bind(this));
7
- }
8
- initialise() {
9
- }
10
- onLoad() {
11
- }
12
- onResize() {
13
- }
14
- }
@@ -1,21 +0,0 @@
1
- export class BaseSite {
2
-
3
- constructor() {
4
-
5
- // Initialise
6
- this.initialise();
7
-
8
- $(window).on('load', this.onLoad.bind(this));
9
- $(window).on('resize', this.onResize.bind(this));
10
-
11
- }
12
-
13
- initialise() {
14
- }
15
-
16
- onLoad() {
17
- }
18
-
19
- onResize() {
20
- }
21
- }