@base-framework/base 2.6.1 → 2.6.3

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 (248) hide show
  1. package/README.md +1 -0
  2. package/dist/base.js +1 -0
  3. package/package.json +30 -26
  4. package/.jshintrc +0 -3
  5. package/base.js +0 -41
  6. package/base.min.js +0 -1
  7. package/core.js +0 -1
  8. package/data-tracker.js +0 -351
  9. package/es5/base.js +0 -2968
  10. package/es5/modules/ajax.js +0 -663
  11. package/es5/modules/animation.js +0 -188
  12. package/es5/modules/animations.js +0 -1080
  13. package/es5/modules/atom.js +0 -65
  14. package/es5/modules/component.js +0 -1310
  15. package/es5/modules/data-binder.js +0 -1131
  16. package/es5/modules/data.js +0 -1808
  17. package/es5/modules/date.js +0 -525
  18. package/es5/modules/form-validator.js +0 -324
  19. package/es5/modules/history.js +0 -126
  20. package/es5/modules/html-builder.js +0 -461
  21. package/es5/modules/layout.js +0 -1679
  22. package/es5/modules/mouse.js +0 -124
  23. package/es5/modules/nav-link.js +0 -123
  24. package/es5/modules/olderversions/animations-ease.js +0 -1095
  25. package/es5/modules/olderversions/animations-update.js +0 -1048
  26. package/es5/modules/olderversions/base-animations.js +0 -636
  27. package/es5/modules/olderversions/base-component-class.js +0 -100
  28. package/es5/modules/olderversions/base-data-binder-1.js +0 -407
  29. package/es5/modules/olderversions/base-data-binder-class.js +0 -358
  30. package/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  31. package/es5/modules/olderversions/base-mode-1.js +0 -777
  32. package/es5/modules/olderversions/base-model-class.js +0 -585
  33. package/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  34. package/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  35. package/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  36. package/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  37. package/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  38. package/es5/modules/olderversions/data-tracker.js +0 -187
  39. package/es5/modules/olderversions/event-update.js +0 -666
  40. package/es5/modules/olderversions/nav-link.js +0 -119
  41. package/es5/modules/olderversions/router-with-templates-1.js +0 -785
  42. package/es5/modules/olderversions/router-with-templates.js +0 -701
  43. package/es5/modules/prototypes/ajax.js +0 -657
  44. package/es5/modules/prototypes/atom.js +0 -65
  45. package/es5/modules/prototypes/component.js +0 -972
  46. package/es5/modules/prototypes/data-binder.js +0 -1089
  47. package/es5/modules/prototypes/data.js +0 -1290
  48. package/es5/modules/prototypes/html-builder.js +0 -414
  49. package/es5/modules/prototypes/layout.js +0 -879
  50. package/es5/modules/router.js +0 -1680
  51. package/es5/modules/state.js +0 -274
  52. package/es6/.jshintrc +0 -3
  53. package/es6/base.js +0 -41
  54. package/es6/core.js +0 -1
  55. package/es6/data-tracker.js +0 -351
  56. package/es6/events.js +0 -602
  57. package/es6/legacy/es5/base.js +0 -2968
  58. package/es6/legacy/es5/modules/ajax.js +0 -663
  59. package/es6/legacy/es5/modules/animation.js +0 -188
  60. package/es6/legacy/es5/modules/animations.js +0 -1080
  61. package/es6/legacy/es5/modules/atom.js +0 -65
  62. package/es6/legacy/es5/modules/component.js +0 -1310
  63. package/es6/legacy/es5/modules/data-binder.js +0 -1131
  64. package/es6/legacy/es5/modules/data.js +0 -1808
  65. package/es6/legacy/es5/modules/date.js +0 -525
  66. package/es6/legacy/es5/modules/form-validator.js +0 -324
  67. package/es6/legacy/es5/modules/history.js +0 -126
  68. package/es6/legacy/es5/modules/html-builder.js +0 -461
  69. package/es6/legacy/es5/modules/layout.js +0 -1679
  70. package/es6/legacy/es5/modules/mouse.js +0 -124
  71. package/es6/legacy/es5/modules/nav-link.js +0 -123
  72. package/es6/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  73. package/es6/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  74. package/es6/legacy/es5/modules/olderversions/base-animations.js +0 -636
  75. package/es6/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  76. package/es6/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  77. package/es6/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  78. package/es6/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  79. package/es6/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  80. package/es6/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  81. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  82. package/es6/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  83. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  84. package/es6/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  85. package/es6/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  86. package/es6/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  87. package/es6/legacy/es5/modules/olderversions/event-update.js +0 -666
  88. package/es6/legacy/es5/modules/olderversions/nav-link.js +0 -119
  89. package/es6/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  90. package/es6/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  91. package/es6/legacy/es5/modules/prototypes/ajax.js +0 -657
  92. package/es6/legacy/es5/modules/prototypes/atom.js +0 -65
  93. package/es6/legacy/es5/modules/prototypes/component.js +0 -972
  94. package/es6/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  95. package/es6/legacy/es5/modules/prototypes/data.js +0 -1290
  96. package/es6/legacy/es5/modules/prototypes/html-builder.js +0 -414
  97. package/es6/legacy/es5/modules/prototypes/layout.js +0 -879
  98. package/es6/legacy/es5/modules/router.js +0 -1680
  99. package/es6/legacy/es5/modules/state.js +0 -274
  100. package/es6/main.js +0 -1331
  101. package/es6/modules/ajax/ajax.js +0 -514
  102. package/es6/modules/animation/animation.js +0 -236
  103. package/es6/modules/animations/animation-controller.js +0 -231
  104. package/es6/modules/animations/animation.js +0 -64
  105. package/es6/modules/animations/attr-movement.js +0 -66
  106. package/es6/modules/animations/css-movement.js +0 -170
  107. package/es6/modules/animations/movement.js +0 -131
  108. package/es6/modules/animations/value.js +0 -187
  109. package/es6/modules/atom/atom.js +0 -54
  110. package/es6/modules/component/component.js +0 -230
  111. package/es6/modules/component/event-helper.js +0 -119
  112. package/es6/modules/component/jot.js +0 -144
  113. package/es6/modules/component/state-helper.js +0 -262
  114. package/es6/modules/component/unit.js +0 -551
  115. package/es6/modules/data/attrs.js +0 -40
  116. package/es6/modules/data/basic-data.js +0 -500
  117. package/es6/modules/data/data-utils.js +0 -29
  118. package/es6/modules/data/data.js +0 -3
  119. package/es6/modules/data/deep-data.js +0 -541
  120. package/es6/modules/data/model-service.js +0 -528
  121. package/es6/modules/data/model.js +0 -133
  122. package/es6/modules/data/simple-data.js +0 -33
  123. package/es6/modules/data-binder/connection-tracker.js +0 -113
  124. package/es6/modules/data-binder/connection.js +0 -16
  125. package/es6/modules/data-binder/data-binder.js +0 -352
  126. package/es6/modules/data-binder/data-pub-sub.js +0 -141
  127. package/es6/modules/data-binder/data-source.js +0 -56
  128. package/es6/modules/data-binder/element-source.js +0 -219
  129. package/es6/modules/data-binder/one-way-connection.js +0 -46
  130. package/es6/modules/data-binder/one-way-source.js +0 -43
  131. package/es6/modules/data-binder/source.js +0 -36
  132. package/es6/modules/data-binder/two-way-connection.js +0 -75
  133. package/es6/modules/data-binder/two-way-source.js +0 -41
  134. package/es6/modules/date/date.js +0 -544
  135. package/es6/modules/history/history.js +0 -89
  136. package/es6/modules/html-builder/html-builder.js +0 -434
  137. package/es6/modules/import/import.js +0 -390
  138. package/es6/modules/layout/layout-builder.js +0 -1269
  139. package/es6/modules/layout/layout-parser.js +0 -134
  140. package/es6/modules/layout/watcher-helper.js +0 -282
  141. package/es6/modules/mouse/mouse.js +0 -114
  142. package/es6/modules/router/component-helper.js +0 -163
  143. package/es6/modules/router/history-controller.js +0 -216
  144. package/es6/modules/router/nav-link.js +0 -124
  145. package/es6/modules/router/route.js +0 -401
  146. package/es6/modules/router/router.js +0 -789
  147. package/es6/modules/router/utils.js +0 -31
  148. package/es6/modules/state/state-target.js +0 -91
  149. package/es6/modules/state/state.js +0 -171
  150. package/es6/package-lock.json +0 -13
  151. package/es6/package.json +0 -28
  152. package/es6/shared/objects.js +0 -99
  153. package/events.js +0 -602
  154. package/legacy/es5/base.js +0 -2968
  155. package/legacy/es5/modules/ajax.js +0 -663
  156. package/legacy/es5/modules/animation.js +0 -188
  157. package/legacy/es5/modules/animations.js +0 -1080
  158. package/legacy/es5/modules/atom.js +0 -65
  159. package/legacy/es5/modules/component.js +0 -1310
  160. package/legacy/es5/modules/data-binder.js +0 -1131
  161. package/legacy/es5/modules/data.js +0 -1808
  162. package/legacy/es5/modules/date.js +0 -525
  163. package/legacy/es5/modules/form-validator.js +0 -324
  164. package/legacy/es5/modules/history.js +0 -126
  165. package/legacy/es5/modules/html-builder.js +0 -461
  166. package/legacy/es5/modules/layout.js +0 -1679
  167. package/legacy/es5/modules/mouse.js +0 -124
  168. package/legacy/es5/modules/nav-link.js +0 -123
  169. package/legacy/es5/modules/olderversions/animations-ease.js +0 -1095
  170. package/legacy/es5/modules/olderversions/animations-update.js +0 -1048
  171. package/legacy/es5/modules/olderversions/base-animations.js +0 -636
  172. package/legacy/es5/modules/olderversions/base-component-class.js +0 -100
  173. package/legacy/es5/modules/olderversions/base-data-binder-1.js +0 -407
  174. package/legacy/es5/modules/olderversions/base-data-binder-class.js +0 -358
  175. package/legacy/es5/modules/olderversions/base-layout-parser-class.js +0 -172
  176. package/legacy/es5/modules/olderversions/base-mode-1.js +0 -777
  177. package/legacy/es5/modules/olderversions/base-model-class.js +0 -585
  178. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-data-binder-class.js +0 -358
  179. package/legacy/es5/modules/olderversions/data-binder/element-binding/base-model-class.js +0 -585
  180. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-data-binder-class.js +0 -353
  181. package/legacy/es5/modules/olderversions/data-binder/model-binding/base-model-class.js +0 -604
  182. package/legacy/es5/modules/olderversions/data-binder-update-watcher.js +0 -640
  183. package/legacy/es5/modules/olderversions/data-tracker.js +0 -187
  184. package/legacy/es5/modules/olderversions/event-update.js +0 -666
  185. package/legacy/es5/modules/olderversions/nav-link.js +0 -119
  186. package/legacy/es5/modules/olderversions/router-with-templates-1.js +0 -785
  187. package/legacy/es5/modules/olderversions/router-with-templates.js +0 -701
  188. package/legacy/es5/modules/prototypes/ajax.js +0 -657
  189. package/legacy/es5/modules/prototypes/atom.js +0 -65
  190. package/legacy/es5/modules/prototypes/component.js +0 -972
  191. package/legacy/es5/modules/prototypes/data-binder.js +0 -1089
  192. package/legacy/es5/modules/prototypes/data.js +0 -1290
  193. package/legacy/es5/modules/prototypes/html-builder.js +0 -414
  194. package/legacy/es5/modules/prototypes/layout.js +0 -879
  195. package/legacy/es5/modules/router.js +0 -1680
  196. package/legacy/es5/modules/state.js +0 -274
  197. package/main.js +0 -1331
  198. package/modules/ajax/ajax.js +0 -514
  199. package/modules/animation/animation.js +0 -236
  200. package/modules/animations/animation-controller.js +0 -231
  201. package/modules/animations/animation.js +0 -64
  202. package/modules/animations/attr-movement.js +0 -66
  203. package/modules/animations/css-movement.js +0 -170
  204. package/modules/animations/movement.js +0 -131
  205. package/modules/animations/value.js +0 -187
  206. package/modules/atom/atom.js +0 -54
  207. package/modules/component/component.js +0 -230
  208. package/modules/component/event-helper.js +0 -119
  209. package/modules/component/jot.js +0 -144
  210. package/modules/component/state-helper.js +0 -262
  211. package/modules/component/unit.js +0 -551
  212. package/modules/data/attrs.js +0 -40
  213. package/modules/data/basic-data.js +0 -500
  214. package/modules/data/data-utils.js +0 -29
  215. package/modules/data/data.js +0 -3
  216. package/modules/data/deep-data.js +0 -541
  217. package/modules/data/model-service.js +0 -528
  218. package/modules/data/model.js +0 -133
  219. package/modules/data/simple-data.js +0 -33
  220. package/modules/data-binder/connection-tracker.js +0 -113
  221. package/modules/data-binder/connection.js +0 -16
  222. package/modules/data-binder/data-binder.js +0 -352
  223. package/modules/data-binder/data-pub-sub.js +0 -141
  224. package/modules/data-binder/data-source.js +0 -56
  225. package/modules/data-binder/element-source.js +0 -219
  226. package/modules/data-binder/one-way-connection.js +0 -46
  227. package/modules/data-binder/one-way-source.js +0 -43
  228. package/modules/data-binder/source.js +0 -36
  229. package/modules/data-binder/two-way-connection.js +0 -75
  230. package/modules/data-binder/two-way-source.js +0 -41
  231. package/modules/date/date.js +0 -544
  232. package/modules/history/history.js +0 -89
  233. package/modules/html-builder/html-builder.js +0 -434
  234. package/modules/import/import.js +0 -390
  235. package/modules/layout/layout-builder.js +0 -1269
  236. package/modules/layout/layout-parser.js +0 -134
  237. package/modules/layout/watcher-helper.js +0 -282
  238. package/modules/mouse/mouse.js +0 -114
  239. package/modules/router/component-helper.js +0 -163
  240. package/modules/router/history-controller.js +0 -216
  241. package/modules/router/nav-link.js +0 -124
  242. package/modules/router/route.js +0 -401
  243. package/modules/router/router.js +0 -789
  244. package/modules/router/utils.js +0 -31
  245. package/modules/state/state-target.js +0 -91
  246. package/modules/state/state.js +0 -171
  247. package/shared/objects.js +0 -99
  248. package/update +0 -16
package/es6/main.js DELETED
@@ -1,1331 +0,0 @@
1
- /**
2
- * Base Framework
3
- * @version 2.6.0
4
- * @author Chris Durfee
5
- * @file This is a javascript framework to allow complex
6
- * functions to work in many browsers and versions.
7
- */
8
-
9
- import {Objects} from './shared/objects.js';
10
- import {DataTracker} from './data-tracker.js';
11
-
12
- const global = window;
13
-
14
- /**
15
- * base framework constructor
16
- * @class
17
- */
18
- class Base
19
- {
20
- constructor()
21
- {
22
- /**
23
- * @member {string} version
24
- */
25
- this.version = '2.6.0';
26
-
27
- /**
28
- * @member {array} errors
29
- */
30
- this.errors = [];
31
-
32
- /**
33
- * @member {object} dataTracker
34
- */
35
- this.dataTracker = new DataTracker();
36
- }
37
-
38
- /**
39
- * this will augement the base framework with new functionality.
40
- *
41
- * @param {object} methods The new methods to add.
42
- * @return {object} An instance of base.
43
- */
44
- augment(methods)
45
- {
46
- if(!methods || typeof methods !== 'object')
47
- {
48
- return this;
49
- }
50
-
51
- const prototype = this.constructor.prototype;
52
- for(var property in methods)
53
- {
54
- if(methods.hasOwnProperty(property))
55
- {
56
- prototype[property] = methods[property];
57
- }
58
- }
59
- return this;
60
- }
61
-
62
- /**
63
- * This will convert a nodelist into an array.
64
- *
65
- * @param {object} list
66
- * @return {array}
67
- */
68
- listToArray(list)
69
- {
70
- return Array.prototype.slice.call(list);
71
- }
72
-
73
- /**
74
- * This will override a method function with a new function.
75
- *
76
- * @param {object} obj The object being modified.
77
- * @param {string} methodName the method name being overriden.
78
- * @param {function} overrideMethod The new function to call.
79
- * @param {array} args The args to pass to the first function call.
80
- *
81
- * @return {*} The results of the function being called.
82
- */
83
- override(obj, methodName, overrideMethod, args)
84
- {
85
- return (obj[methodName] = overrideMethod).apply(obj, this.listToArray(args));
86
- }
87
-
88
- /**
89
- * This will get the last error.
90
- * @return {(object|boolean)} The last error or false.
91
- */
92
- getLastError()
93
- {
94
- const errors = this.errors;
95
- return (errors.length)? errors.pop() : false;
96
- }
97
-
98
- /**
99
- * This will add an error.
100
- *
101
- * @param {object} err
102
- */
103
- addError(err)
104
- {
105
- this.errors.push(err);
106
- }
107
-
108
- /**
109
- * This will parse a query string.
110
- *
111
- * @param {string} [str] The string to parse or the global
112
- * location will be parsed.
113
- * @param {bool} [decode]
114
- * @return {object}
115
- */
116
- parseQueryString(str, decode)
117
- {
118
- if(typeof str !== 'string')
119
- {
120
- str = global.location.search;
121
- }
122
-
123
- let objURL = {},
124
- regExp = /([^?=&]+)(=([^&]*))?/g;
125
- str.replace(regExp, function(a, b, c, d)
126
- {
127
- /* we want to save the key and the
128
- value to the objURL */
129
- objURL[b] = (decode !== false)? decodeURIComponent(d) : d;
130
- });
131
-
132
- return objURL;
133
- }
134
-
135
- /**
136
- * This will check if an object is empty.
137
- *
138
- * @param {object} obj
139
- * @return {boolean}
140
- */
141
- isEmpty(obj)
142
- {
143
- if(this.isObject(obj) === false)
144
- {
145
- return true;
146
- }
147
-
148
- /* we want to loop through each property and
149
- check if it belongs to the object directly */
150
- for(var key in obj)
151
- {
152
- if(obj.hasOwnProperty(key))
153
- {
154
- return false;
155
- }
156
- }
157
- return true;
158
- }
159
-
160
- /**
161
- * This will select an element by id.
162
- *
163
- * @param {string} id
164
- * @return {(object|boolean)} The element object or false.
165
- */
166
- getById(id)
167
- {
168
- if(typeof id !== 'string')
169
- {
170
- return false;
171
- }
172
- let obj = document.getElementById(id);
173
- return (obj || false);
174
- }
175
-
176
- /**
177
- * This will select elements by name.
178
- *
179
- * @param {string} name
180
- * @return {(object|boolean)} The elements array or false.
181
- */
182
- getByName(name)
183
- {
184
- if(typeof name !== 'string')
185
- {
186
- return false;
187
- }
188
- let obj = document.getElementsByName(name);
189
- return (obj)? this.listToArray(obj) : false;
190
- }
191
-
192
- /**
193
- * This will select by css selector.
194
- *
195
- * @param {string} selector
196
- * @param {boolean} single Set to true if you only want one result.
197
- * @return {*}
198
- */
199
- getBySelector(selector, single)
200
- {
201
- if(typeof selector !== 'string')
202
- {
203
- return false;
204
- }
205
-
206
- /* we want to check if we are only selecting
207
- the first element or all elements */
208
- single = single || false;
209
- if(single === true)
210
- {
211
- let obj = document.querySelector(selector);
212
- return (obj || false);
213
- }
214
-
215
- let elements = document.querySelectorAll(selector);
216
- if(elements)
217
- {
218
- /* if there is only one result just return the
219
- first element in the node list */
220
- return (elements.length === 1)? elements[0] : this.listToArray(elements);
221
- }
222
- return false;
223
- }
224
-
225
- /**
226
- * This will get or set the innerHTML or an element.
227
- *
228
- * @param {object} obj
229
- * @param {string} [html] If the html is not set, the html of the
230
- * element will be returned.
231
- *
232
- * @return {(string|void)}
233
- */
234
- html(obj, html)
235
- {
236
- if(this.isObject(obj) === false)
237
- {
238
- return false;
239
- }
240
-
241
- /* we want to check if we are getting the
242
- html or adding the html */
243
- if(this.isUndefined(html) === false)
244
- {
245
- obj.innerHTML = html;
246
- return this;
247
- }
248
-
249
- return obj.innerHTML;
250
- }
251
-
252
- /**
253
- * This will set the css property of an element.
254
- *
255
- * @param {object} obj
256
- * @param {string} property
257
- * @param {string} value
258
- * @return {object} an instance of base.
259
- */
260
- setCss(obj, property, value)
261
- {
262
- if(this.isObject(obj) === false || this.isUndefined(property))
263
- {
264
- return this;
265
- }
266
-
267
- property = this.uncamelCase(property);
268
- obj.style[property] = value;
269
- return this;
270
- }
271
-
272
- /**
273
- * This will get the css property of an element.
274
- *
275
- * @param {object} obj
276
- * @param {string} property
277
- * @return {(string|null)}
278
- */
279
- getCss(obj, property)
280
- {
281
- if(!obj || typeof property === 'undefined')
282
- {
283
- return false;
284
- }
285
-
286
- property = this.uncamelCase(property);
287
- var css = obj.style[property];
288
- if(css !== '')
289
- {
290
- return css;
291
- }
292
-
293
- /* we want to check if we have an inherited
294
- value */
295
- var currentValue = null,
296
- currentStyle = obj.currentStyle;
297
- if(currentStyle && (currentValue = currentStyle[property]))
298
- {
299
- css = currentValue;
300
- }
301
- else
302
- {
303
- var inheritedStyle = window.getComputedStyle(obj, null);
304
- if(inheritedStyle)
305
- {
306
- css = inheritedStyle[property];
307
- }
308
- }
309
-
310
- return css;
311
- }
312
-
313
- /**
314
- * This will get or set the css propety or an element.
315
- *
316
- * @param {object} obj
317
- * @param {string} property
318
- * @param {string} [value]
319
- * @return {(string|void)}
320
- */
321
- css(obj, property, value)
322
- {
323
- /* we want to check if we are getting the
324
- value or setting the value */
325
- if(typeof value !== 'undefined')
326
- {
327
- this.setCss(obj, property, value);
328
-
329
- return this;
330
- }
331
-
332
- return this.getCss(obj, property);
333
- }
334
-
335
- /**
336
- * This will remove an attribute from an element.
337
- *
338
- * @param {object} obj
339
- * @param {string} property
340
- * @return {object} an instance of base.
341
- */
342
- removeAttr(obj, property)
343
- {
344
- if(this.isObject(obj))
345
- {
346
- obj.removeAttribute(property);
347
- }
348
- return this;
349
- }
350
-
351
- /**
352
- * This will set an attribute of an element.
353
- *
354
- * @private
355
- * @param {object} obj
356
- * @param {string} property
357
- * @param {string} value
358
- * @return {void}
359
- */
360
- setAttr(obj, property, value)
361
- {
362
- obj.setAttribute(property, value);
363
- }
364
-
365
- /**
366
- * This will get an attribute of an element.
367
- *
368
- * @param {object} obj
369
- * @param {string} property
370
- * @return {string}
371
- */
372
- getAttr(obj, property)
373
- {
374
- return obj.getAttribute(property);
375
- }
376
-
377
- /**
378
- * This will get or set an attribute from an element.
379
- *
380
- * @param {object} obj
381
- * @param {string} property
382
- * @param {string} [value]
383
- * @return {(string|void)}
384
- */
385
- attr(obj, property, value)
386
- {
387
- if(this.isObject(obj) === false)
388
- {
389
- return false;
390
- }
391
-
392
- /* we want to check if we are getting the
393
- value or setting the value */
394
- if(typeof value !== 'undefined')
395
- {
396
- /* we want to check to set the value */
397
- this.setAttr(obj, property, value);
398
-
399
- return this;
400
- }
401
-
402
- return this.getAttr(obj, property);
403
- }
404
-
405
- /**
406
- * This will prefix a string with "data-" if not set.
407
- *
408
- * @protected
409
- * @param {string} prop
410
- * @return {string}
411
- */
412
- _checkDataPrefix(prop)
413
- {
414
- if(typeof prop !== 'string')
415
- {
416
- return prop;
417
- }
418
-
419
- /* we want to de camelcase if set */
420
- prop = base.uncamelCase(prop);
421
- if(prop.substring(0, 5) !== 'data-')
422
- {
423
- prop = 'data-' + prop;
424
- }
425
-
426
- return prop;
427
- }
428
-
429
- /**
430
- * This will remove "data-" from a string.
431
- *
432
- * @protected
433
- * @param {string} prop
434
- * @return {string}
435
- */
436
- _removeDataPrefix(prop)
437
- {
438
- if(typeof prop === 'string' && prop.substring(0, 5) === 'data-')
439
- {
440
- prop = prop.substring(5);
441
- }
442
- return prop;
443
- }
444
-
445
- /**
446
- * This will set data to an element.
447
- *
448
- * @param {object} obj
449
- * @param {string} property
450
- * @param {string} value
451
- */
452
- setData(obj, property, value)
453
- {
454
- /* this will return the property without the data prefix */
455
- property = this._removeDataPrefix(property);
456
- property = base.camelCase(property);
457
-
458
- obj.dataset[property] = value;
459
- }
460
-
461
- /**
462
- * This will get data from an element.
463
- *
464
- * @param {object} obj
465
- * @param {string} property
466
- * @param {string} value
467
- * @return {string}
468
- */
469
- getData(obj, property)
470
- {
471
- property = base.camelCase(this._removeDataPrefix(property));
472
- return obj.dataset[property];
473
- }
474
-
475
- /**
476
- * This will get or set data to an element.
477
- *
478
- * @param {object} obj
479
- * @param {string} property
480
- * @param {string} [value]
481
- * @return {(string|void)}
482
- */
483
- data(obj, property, value)
484
- {
485
- if(this.isObject(obj) === false)
486
- {
487
- return false;
488
- }
489
-
490
- if(typeof value !== 'undefined')
491
- {
492
- this.setData(obj, property, value);
493
- return this;
494
- }
495
-
496
- return this.getData(obj, property);
497
- }
498
-
499
- /**
500
- * This will find elements in an element.
501
- *
502
- * @param {object} obj
503
- * @param {string} queryString
504
- * @return {array}
505
- */
506
- find(obj, queryString)
507
- {
508
- if(!obj || typeof queryString !== 'string')
509
- {
510
- return false;
511
- }
512
-
513
- return obj.querySelectorAll(queryString);
514
- }
515
-
516
- /**
517
- * This will display an element.
518
- *
519
- * @param {object} obj
520
- * @return {object} An instance of base.
521
- */
522
- show(obj)
523
- {
524
- if(this.isObject(obj) === false)
525
- {
526
- return this;
527
- }
528
-
529
- /* we want to get the previous display style
530
- from the data-style-display attr */
531
- let previous = this.data(obj, 'style-display'),
532
- value = (typeof previous === 'string')? previous : '';
533
-
534
- this.css(obj, 'display', value);
535
- return this;
536
- }
537
-
538
- /**
539
- * This will hide an element.
540
- *
541
- * @param {object} obj
542
- * @return {object} An instance of base.
543
- */
544
- hide(obj)
545
- {
546
- if(this.isObject(obj) === false)
547
- {
548
- return this;
549
- }
550
-
551
- /* we want to set the previous display style
552
- on the element as a data attr */
553
- let previous = this.css(obj, 'display');
554
- if(previous !== 'none' && previous)
555
- {
556
- this.data(obj, 'style-display', previous);
557
- }
558
-
559
- this.css(obj, 'display', 'none');
560
- return this;
561
- }
562
-
563
- /**
564
- * This will toggle the display an element.
565
- *
566
- * @param {object} obj
567
- * @return {object} An instance of base.
568
- */
569
- toggle(obj)
570
- {
571
- if(this.isObject(obj) === false)
572
- {
573
- return this;
574
- }
575
-
576
- let mode = this.css(obj, 'display');
577
- if(mode !== 'none')
578
- {
579
- this.hide(obj);
580
- }
581
- else
582
- {
583
- this.show(obj);
584
- }
585
- return this;
586
- }
587
-
588
- /**
589
- * This will camelCase a string.
590
- *
591
- * @param {string} str
592
- * @return {(string|boolean)} The string or false.
593
- */
594
- camelCase(str)
595
- {
596
- if(typeof str !== 'string')
597
- {
598
- return false;
599
- }
600
-
601
- let regExp = /(-|\s|\_)+\w{1}/g;
602
- return str.replace(regExp, function(match)
603
- {
604
- return match[1].toUpperCase();
605
- });
606
- }
607
-
608
- /**
609
- * This will uncamel-case a string.
610
- *
611
- * @param {string} str
612
- * @param {string} delimiter
613
- * @return {(string|boolean)} The string or false.
614
- */
615
- uncamelCase(str, delimiter)
616
- {
617
- if(typeof str !== 'string')
618
- {
619
- return false;
620
- }
621
-
622
- delimiter = delimiter || '-';
623
-
624
- let regExp = /([A-Z]{1,})/g;
625
- return str.replace(regExp, function(match)
626
- {
627
- return delimiter + match.toLowerCase();
628
- }).toLowerCase();
629
- }
630
-
631
- /**
632
- * This will get the size of an element.
633
- *
634
- * @param {object} obj
635
- * @return {(object|boolean)} A size object or false.
636
- */
637
- getSize(obj)
638
- {
639
- if(this.isObject(obj) === false)
640
- {
641
- return false;
642
- }
643
-
644
- return {
645
- width: this.getWidth(obj),
646
- height: this.getHeight(obj)
647
- };
648
- }
649
-
650
- /**
651
- * This will get the width of an element.
652
- *
653
- * @param {object} obj
654
- * @return {(int|boolean)} A width or false.
655
- */
656
- getWidth(obj)
657
- {
658
- /* we want to check if the object is not supplied */
659
- return (this.isObject(obj))? obj.offsetWidth : false;
660
- }
661
-
662
- /**
663
- * This will get the height of an element.
664
- *
665
- * @param {object} obj
666
- * @return {(int|boolean)} A height or false.
667
- */
668
- getHeight(obj)
669
- {
670
- /* we want to check if the object is not supplied */
671
- return (this.isObject(obj))? obj.offsetHeight : false;
672
- }
673
-
674
- /**
675
- * This will get the scroll position.
676
- *
677
- * @param {object} [obj] The element or document element if not set.
678
- * @return {object}
679
- */
680
- getScrollPosition(obj)
681
- {
682
- let left = 0, top = 0;
683
- switch(typeof obj)
684
- {
685
- case 'undefined':
686
- obj = document.documentElement;
687
- left = (window.pageXOffset || obj.scrollLeft);
688
- top = (window.pageYOffset || obj.scrollTop);
689
- break;
690
- case 'object':
691
- left = obj.scrollLeft;
692
- top = obj.scrollTop;
693
- break;
694
- }
695
-
696
- if(this.isObject(obj) === false)
697
- {
698
- return false;
699
- }
700
-
701
- return {
702
- left: left - (obj.clientLeft || 0),
703
- top: top - (obj.clientTop || 0)
704
- };
705
- }
706
-
707
- /**
708
- * This will get the scroll top position.
709
- *
710
- * @param {object} [obj] The element or document element if not set.
711
- * @return {object}
712
- */
713
- getScrollTop(obj)
714
- {
715
- let position = this.getScrollPosition(obj);
716
- return position.top;
717
- }
718
-
719
- /**
720
- * This will get the scroll left position.
721
- *
722
- * @param {object} [obj] The element or document element if not set.
723
- * @return {object}
724
- */
725
- getScrollLeft(obj)
726
- {
727
- let position = this.getScrollPosition(obj);
728
- return position.left;
729
- }
730
-
731
- /**
732
- * This will get the window size.
733
- *
734
- * @return {object}
735
- */
736
- getWindowSize()
737
- {
738
- let w = window,
739
- doc = document,
740
- de = doc.documentElement,
741
- b = doc.getElementsByTagName('body')[0],
742
- width = w.innerWidth || de.clientWidth || b.clientWidth,
743
- height = w.innerHeight || de.clientHeight || b.clientHeight;
744
-
745
- return {
746
- width,
747
- height
748
- };
749
- }
750
-
751
- /**
752
- * This will get the document size.
753
- *
754
- * @return {object}
755
- */
756
- getDocumentSize()
757
- {
758
- let doc = document,
759
- body = doc.body,
760
- html = doc.documentElement,
761
-
762
- height = Math.max(
763
- body.scrollHeight,
764
- body.offsetHeight,
765
- html.clientHeight,
766
- html.scrollHeight,
767
- html.offsetHeight
768
- ),
769
-
770
- width = Math.max(
771
- body.scrollWidth,
772
- body.offsetWidth,
773
- html.clientWidth,
774
- html.scrollWidth,
775
- html.offsetWidth
776
- );
777
-
778
- return {
779
- width,
780
- height
781
- };
782
- }
783
-
784
- /**
785
- * This will get the document height.
786
- *
787
- * @return {object}
788
- */
789
- getDocumentHeight()
790
- {
791
- return this.getDocumentSize().height;
792
- }
793
-
794
- /**
795
- * This will get the value from a property on an object.
796
- *
797
- * @param {object} obj
798
- * @param {string} property
799
- * @param {*} [defaultText] A value if no value is set.
800
- * @return {string}
801
- */
802
- getProperty(obj, property, defaultText)
803
- {
804
- if(this.isObject(obj) === false)
805
- {
806
- return '';
807
- }
808
-
809
- let value = obj[property];
810
- if(typeof value !== 'undefined')
811
- {
812
- return value;
813
- }
814
-
815
- /* if no value was available
816
- we want to return an empty string */
817
- return (typeof defaultText !== 'undefined')? defaultText : '';
818
- }
819
-
820
- /**
821
- * This will get the position of an element.
822
- *
823
- * @param {object} obj
824
- * @param {boolean} [depth] The number of levels, default is 1, 0 is to the root.
825
- * @return {object}
826
- */
827
- position(obj, depth = 1)
828
- {
829
- let position = {x: 0, y: 0};
830
-
831
- if(this.isObject(obj) === false)
832
- {
833
- return position;
834
- }
835
-
836
- /* if the depth is 0 we will travel to the
837
- top element */
838
- let count = 0;
839
- while(obj && (depth === 0 || count < depth))
840
- {
841
- count++;
842
- position.x += (obj.offsetLeft + obj.clientLeft);
843
- position.y += (obj.offsetTop + obj.clientTop);
844
- obj = obj.offsetParent;
845
- }
846
-
847
- return position;
848
- }
849
-
850
- /**
851
- * This will add a class to an element.
852
- *
853
- * @param {object} obj
854
- * @param {string} tmpClassName
855
- */
856
- addClass(obj, tmpClassName)
857
- {
858
- if(this.isObject(obj) === false || tmpClassName === '')
859
- {
860
- return this;
861
- }
862
-
863
- if(typeof tmpClassName === 'string')
864
- {
865
- /* we want to divide the string by spaces and
866
- add any class listed */
867
- let adding = tmpClassName.split(' ');
868
- for(var i = 0, maxLength = adding.length; i < maxLength; i++)
869
- {
870
- obj.classList.add(tmpClassName);
871
- }
872
- }
873
- return this;
874
- }
875
-
876
- /**
877
- * This will remove a class or classes from an element.
878
- *
879
- * @param {object} obj
880
- * @param {string} [tmpClassName]
881
- */
882
- removeClass(obj, tmpClassName)
883
- {
884
- if(this.isObject(obj) === false || tmpClassName === '')
885
- {
886
- return this;
887
- }
888
-
889
- /* if no className was specified we will remove all classes from object */
890
- if(typeof tmpClassName === 'undefined')
891
- {
892
- obj.className = '';
893
- }
894
- else
895
- {
896
- obj.classList.remove(tmpClassName);
897
- }
898
- return this;
899
- }
900
-
901
- /**
902
- * This will check if an element has a class.
903
- *
904
- * @param {object} obj
905
- * @param {string} tmpClassName
906
- * @return {boolean}
907
- */
908
- hasClass(obj, tmpClassName)
909
- {
910
- if(this.isObject(obj) === false || tmpClassName === '')
911
- {
912
- return false;
913
- }
914
-
915
- return obj.classList.contains(tmpClassName);
916
- }
917
-
918
- /**
919
- * This will toggle a class on an element.
920
- *
921
- * @param {object} obj
922
- * @param {string} tmpClassName
923
- * @return {object} An instance of base.
924
- */
925
- toggleClass(obj, tmpClassName)
926
- {
927
- if(this.isObject(obj) === false)
928
- {
929
- return this;
930
- }
931
-
932
- obj.classList.toggle(tmpClassName);
933
- return this;
934
- }
935
-
936
- /**
937
- * This will get the type of a variable.
938
- *
939
- * @param {*} data
940
- * @return {string}
941
- */
942
- getType(data)
943
- {
944
- const type = typeof data;
945
- if(type !== 'object')
946
- {
947
- return type;
948
- }
949
-
950
- return (this.isArray(data))? 'array' : type;
951
- }
952
-
953
- /**
954
- * This will check if a request is undefined.
955
- *
956
- * @param {mixed} data
957
- */
958
- isUndefined(data)
959
- {
960
- return (typeof data === 'undefined');
961
- }
962
-
963
- /**
964
- * This will check if the request is an object.
965
- * @param {object} obj
966
- * @return {boolean}
967
- */
968
- isObject(obj)
969
- {
970
- return (!obj || typeof obj !== 'object')? false : true;
971
- }
972
-
973
- /**
974
- * This will check if the variable is an array.
975
- *
976
- * @param {*} array
977
- * @return {boolean}
978
- */
979
- isArray(array)
980
- {
981
- return Array.isArray(array);
982
- }
983
-
984
- /**
985
- * This will check if a value is found in an array.
986
- *
987
- * @param {array} array
988
- * @param {string} element
989
- * @param {int} [fromIndex]
990
- * @return {int} This will return -1 if not found.
991
- */
992
- inArray(array, element, fromIndex)
993
- {
994
- if(!array || typeof array !== 'object')
995
- {
996
- return -1;
997
- }
998
-
999
- return array.indexOf(element, fromIndex);
1000
- }
1001
-
1002
- /**
1003
- * This will create a callBack.
1004
- *
1005
- * @param {object} obj
1006
- * @param {function} method
1007
- * @param {array} [argArray] Default args to pass.
1008
- * @param {boolean} [addArgs] Set to add merge args from the
1009
- * curried function.
1010
- *
1011
- * @return {(function|boolean)} The callBack function or false.
1012
- */
1013
- createCallBack(obj, method, argArray, addArgs)
1014
- {
1015
- if(typeof method !== 'function')
1016
- {
1017
- return false;
1018
- }
1019
-
1020
- argArray = argArray || [];
1021
- return function(...args)
1022
- {
1023
- if(addArgs === true)
1024
- {
1025
- argArray = argArray.concat(args);
1026
- }
1027
-
1028
- return method.apply(obj, argArray);
1029
- };
1030
- }
1031
-
1032
- /**
1033
- * This will bind scope to a method.
1034
- *
1035
- * @param {object} obj
1036
- * @param {function} method
1037
- * @return {function}
1038
- */
1039
- bind(obj, method)
1040
- {
1041
- return method.bind(obj);
1042
- }
1043
-
1044
- /**
1045
- * This will prepare a json object to be used in an
1046
- * xhr request. This will sanitize the object values
1047
- * by encoding them to not break the param string.
1048
- *
1049
- * @param {object} obj
1050
- * @param {bool} [removeNewLines]
1051
- * @return {string}
1052
- */
1053
- prepareJsonUrl(obj, removeNewLines = false)
1054
- {
1055
- var escapeChars = (str) =>
1056
- {
1057
- if(typeof str !== 'string')
1058
- {
1059
- str = String(str);
1060
- }
1061
-
1062
- if(removeNewLines)
1063
- {
1064
- let newLine = /\n/g;
1065
- str = str.replace(newLine, "\\n");
1066
- }
1067
-
1068
- let tab = /\t/g;
1069
- return str.replace(tab, "\\t");
1070
- };
1071
-
1072
- var sanitize = (text) =>
1073
- {
1074
- if(typeof text !== 'string')
1075
- {
1076
- return text;
1077
- }
1078
-
1079
- /* we need to escape chars and encode the uri
1080
- components */
1081
- text = escapeChars(text);
1082
- text = encodeURIComponent(text);
1083
-
1084
- /* we want to re-encode the double quotes so they
1085
- will be escaped by the json encoder */
1086
- let pattern = /\%22/g;
1087
- return text.replace(pattern, '"');
1088
- };
1089
-
1090
- var prepareUrl = (data) =>
1091
- {
1092
- let type = typeof data;
1093
- if(type === "undefined")
1094
- {
1095
- return data;
1096
- }
1097
-
1098
- if(type !== 'object')
1099
- {
1100
- data = sanitize(data);
1101
- return data;
1102
- }
1103
-
1104
- let value;
1105
- for(var prop in data)
1106
- {
1107
- if(data.hasOwnProperty(prop))
1108
- {
1109
- value = data[prop];
1110
- if(value === null)
1111
- {
1112
- continue;
1113
- }
1114
-
1115
- data[prop] = (typeof value)? prepareUrl(value) : sanitize(value);
1116
- }
1117
- }
1118
- return data;
1119
- };
1120
-
1121
- /* we want to check to clone object so we won't modify the
1122
- original object */
1123
- let before = (typeof obj === 'object')? this.cloneObject(obj) : obj,
1124
- after = prepareUrl(before);
1125
- return this.jsonEncode(after);
1126
- }
1127
-
1128
- /**
1129
- * This will parse JSON data.
1130
- *
1131
- * @param {string} data
1132
- * @return {*}
1133
- */
1134
- jsonDecode(data)
1135
- {
1136
- return (typeof data !== "undefined" && data.length > 0)? JSON.parse(data) : false;
1137
- }
1138
-
1139
- /**
1140
- * This will encode JSON data.
1141
- *
1142
- * @param {*} data
1143
- * @return {string}
1144
- */
1145
- jsonEncode(data)
1146
- {
1147
- return (typeof data !== "undefined")? JSON.stringify(data) : false;
1148
- }
1149
-
1150
- /**
1151
- * This will parse xml data.
1152
- *
1153
- * @param {string} data
1154
- * @return {object}
1155
- */
1156
- xmlParse(data)
1157
- {
1158
- if(typeof data === "undefined")
1159
- {
1160
- return false;
1161
- }
1162
-
1163
- var parser = new DOMParser();
1164
- return parser.parseFromString(data, "text/xml");
1165
- }
1166
- }
1167
-
1168
- /**
1169
- * This will return the base prototype to allow the module
1170
- * to be added to base as a module.
1171
- *
1172
- * @static
1173
- * @return {object} the base prototype.
1174
- */
1175
- Base.prototype.extend = (function()
1176
- {
1177
- return Base.prototype;
1178
- })();
1179
-
1180
- /**
1181
- * This is the instance of base that all modules will use.
1182
- * @global
1183
- */
1184
- export const base = new Base();
1185
-
1186
- /**
1187
- * This will add the Objects method to base.
1188
- */
1189
- base.augment(Objects);
1190
-
1191
- /**
1192
- * This will count the properties of an object.
1193
- *
1194
- * @param {object} obj
1195
- * @return {int}
1196
- */
1197
- let countProperty = (obj) =>
1198
- {
1199
- let count = 0;
1200
- /* we want to count each property of the object */
1201
- for(var property in obj)
1202
- {
1203
- if(obj.hasOwnProperty(property))
1204
- {
1205
- count++;
1206
- /* we want to do a recursive count to get
1207
- any child properties */
1208
- if(typeof obj[property] === 'object')
1209
- {
1210
- count += countProperty(obj[property]);
1211
- }
1212
- }
1213
- }
1214
- return count;
1215
- };
1216
-
1217
- /**
1218
- * This will validate if the object properties match another object.
1219
- *
1220
- * @param {object} obj1
1221
- * @param {object} obj2
1222
- * @return {boolean}
1223
- */
1224
- let matchProperties = (obj1, obj2) =>
1225
- {
1226
- let matched = false;
1227
-
1228
- if(typeof obj1 !== 'object' || typeof obj2 !== 'object')
1229
- {
1230
- return matched;
1231
- }
1232
-
1233
- /* we want to check each object1 property to the
1234
- object 2 property */
1235
- for(var property in obj1)
1236
- {
1237
- /* we want to check if the property is owned by the
1238
- object and that they have matching types */
1239
- if(!obj1.hasOwnProperty(property) || !obj2.hasOwnProperty(property))
1240
- {
1241
- break;
1242
- }
1243
-
1244
- let value1 = obj1[property],
1245
- value2 = obj2[property];
1246
-
1247
- if(typeof value1 !== typeof value2)
1248
- {
1249
- break;
1250
- }
1251
-
1252
- /* we want to check if the type is an object */
1253
- if(typeof value1 === 'object')
1254
- {
1255
- /* this will do a recursive check to the
1256
- child properties */
1257
- matched = matchProperties(value1, value2);
1258
- if(matched !== true)
1259
- {
1260
- /* if a property did not match we can stop
1261
- the comparison */
1262
- break;
1263
- }
1264
- }
1265
- else
1266
- {
1267
- if(value1 === value2)
1268
- {
1269
- matched = true;
1270
- }
1271
- else
1272
- {
1273
- break;
1274
- }
1275
- }
1276
- }
1277
-
1278
- return matched;
1279
- };
1280
-
1281
- /**
1282
- * This will compare if two objects match.
1283
- *
1284
- * @param {object} obj1
1285
- * @param {object} obj2
1286
- * @return {boolean}
1287
- */
1288
- let compareObjects = (obj1, obj2) =>
1289
- {
1290
- /* we want to check if they have the same number of
1291
- properties */
1292
- let option1Count = countProperty(obj1),
1293
- option2Count = countProperty(obj2);
1294
- if(option1Count !== option2Count)
1295
- {
1296
- return false;
1297
- }
1298
-
1299
- return matchProperties(obj1, obj2);
1300
- };
1301
-
1302
- base.augment(
1303
- {
1304
- /**
1305
- * This will compare if two values match.
1306
- *
1307
- * @param {*} option1
1308
- * @param {*} option2
1309
- * @return {boolean}
1310
- */
1311
- equals(option1, option2)
1312
- {
1313
- /* we want to check if there types match */
1314
- let option1Type = typeof option1,
1315
- option2Type = typeof option2;
1316
- if(option1Type !== option2Type)
1317
- {
1318
- return false;
1319
- }
1320
-
1321
- /* we need to check if the options are objects
1322
- because we will want to match all the
1323
- properties */
1324
- if(option1Type === 'object')
1325
- {
1326
- return compareObjects(option1, option2);
1327
- }
1328
-
1329
- return (option1 === option2);
1330
- }
1331
- });