@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
@@ -1,2968 +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
- (function(global)
10
- {
11
- "use strict";
12
-
13
- /* this will check to stop setup if already setup */
14
- if(global.base)
15
- {
16
- return false;
17
- }
18
-
19
- /**
20
- * base framework constructor
21
- * @class
22
- */
23
- var Base = function()
24
- {
25
- /**
26
- * @member {string} version
27
- */
28
- this.version = '2.6.0';
29
-
30
- /**
31
- * @member {array} errors
32
- */
33
- this.errors = [];
34
- };
35
-
36
- Base.prototype =
37
- {
38
- /**
39
- * @constructor
40
- */
41
- constructor: Base,
42
-
43
- /**
44
- * this will augement the base framework with new functionality.
45
- *
46
- * @param {object} methods The new methods to add.
47
- * @return {object} An instance of base.
48
- */
49
- augment: function(methods)
50
- {
51
- if(!methods || typeof methods !== 'object')
52
- {
53
- return this;
54
- }
55
-
56
- var prototype = this.constructor.prototype;
57
- for(var property in methods)
58
- {
59
- if(methods.hasOwnProperty(property))
60
- {
61
- prototype[property] = methods[property];
62
- }
63
- }
64
- return this;
65
- }
66
- };
67
-
68
- /**
69
- * This will return the base prototype to allow the module
70
- * to be added to base as a module.
71
- *
72
- * @static
73
- * @return {object} the base prototype.
74
- */
75
- Base.prototype.extend = (function()
76
- {
77
- return Base.prototype;
78
- })();
79
-
80
- /**
81
- * This is the instance of base that all modules will use.
82
- * @global
83
- */
84
- var base = global._b = global.base = new Base();
85
-
86
- /* this will add the object creating and extending methods
87
- to allow classes to be created in es5 */
88
- base.augment(
89
- {
90
- /**
91
- * This will convert a nodelist into an array.
92
- *
93
- * @param {object} list
94
- * @return {array}
95
- */
96
- listToArray: function(list)
97
- {
98
- return Array.prototype.slice.call(list);
99
- },
100
-
101
- /**
102
- * This will override a method function with a new function.
103
- *
104
- * @param {object} obj The object being modified.
105
- * @param {string} methodName the method name being overriden.
106
- * @param {function} overrideMethod The new function to call.
107
- * @param {array} args The args to pass to the first function call.
108
- *
109
- * @return {*} The results of the function being called.
110
- */
111
- override: function(obj, methodName, overrideMethod, args)
112
- {
113
- return (obj[methodName] = overrideMethod).apply(obj, this.listToArray(args));
114
- },
115
-
116
- /**
117
- * This will create a new object.
118
- *
119
- * @param {object} [object] An object to extend.
120
- * @return {object}
121
- */
122
- createObject: function(object)
123
- {
124
- /* create a local function to perform the check
125
- once then override the function */
126
- var createObject;
127
- if(typeof Object.create === 'function')
128
- {
129
- // modern browsers
130
- createObject = function(object)
131
- {
132
- return Object.create(object);
133
- };
134
- }
135
- else
136
- {
137
- // old browsers
138
- createObject = function(object)
139
- {
140
- var obj = function(){};
141
- obj.prototype = object;
142
- return new obj();
143
- };
144
- }
145
-
146
- return this.override(this, 'createObject', createObject, arguments);
147
- },
148
-
149
- /**
150
- * This will extend an object to another object.
151
- *
152
- * @param {(function|object)} sourceObj
153
- * @param {(function|object)} targetObj
154
- * @return {object}
155
- */
156
- extendObject: function(sourceObj, targetObj)
157
- {
158
- if(typeof sourceObj === 'undefined' || typeof targetObj === 'undefined')
159
- {
160
- return false;
161
- }
162
-
163
- for(var property in sourceObj)
164
- {
165
- if(sourceObj.hasOwnProperty(property) && typeof targetObj[property] === 'undefined')
166
- {
167
- targetObj[property] = sourceObj[property];
168
- }
169
- }
170
-
171
- return targetObj;
172
- },
173
-
174
- /**
175
- * This will clone an object.
176
- *
177
- * @param {object} obj
178
- * @return {object}
179
- */
180
- cloneObject: function(obj)
181
- {
182
- return JSON.parse(JSON.stringify(obj));
183
- },
184
-
185
- /**
186
- * This will get the class prototype.
187
- *
188
- * @param {(function|object)} object
189
- * @return {object}
190
- */
191
- _getClassObject: function(object)
192
- {
193
- return (typeof object === 'function')? object.prototype : object;
194
- },
195
-
196
- /**
197
- * This will extend an object to another object.
198
- *
199
- * @param {(function|object)} sourceClass
200
- * @param {(function|object)} targetClass
201
- * @return {object}
202
- */
203
- extendClass: function(sourceClass, targetClass)
204
- {
205
- /* if we are using a class constructor function
206
- we want to get the class prototype object */
207
- var source = this._getClassObject(sourceClass),
208
- target = this._getClassObject(targetClass);
209
-
210
- if(typeof source !== 'object' || typeof target !== 'object')
211
- {
212
- return false;
213
- }
214
-
215
- /* we want to create a new object and add the source
216
- prototype to the new object */
217
- var obj = this.createObject(source);
218
-
219
- /* we want to add any additional properties from the
220
- target class to the new object */
221
- for(var prop in target)
222
- {
223
- obj[prop] = target[prop];
224
- }
225
-
226
- return obj;
227
- }
228
- });
229
-
230
- /**
231
- * This will create a base class that other classes
232
- * can use to create a class like object in es5.
233
- *
234
- * @class
235
- */
236
- var Class = function()
237
- {
238
-
239
- };
240
-
241
- Class.prototype =
242
- {
243
- constructor: Class
244
- };
245
-
246
- /**
247
- * This will extend the parent object to a child object.
248
- *
249
- * @static
250
- * @param {object} child
251
- * @return {function} The child constructor.
252
- */
253
- Class.extend = function(child)
254
- {
255
- if(!child)
256
- {
257
- return false;
258
- }
259
-
260
- var parent = this.prototype;
261
-
262
- /* the child constructor must be set to set
263
- the parent static methods on the child */
264
- var constructor = child.constructor || false;
265
- if(child.hasOwnProperty('constructor') === false)
266
- {
267
- constructor = function()
268
- {
269
- var args = base.listToArray(arguments);
270
- parent.constructor.apply(this, args);
271
- };
272
- }
273
-
274
- /* this will add the parent class to the
275
- child class */
276
- constructor.prototype = base.extendClass(parent, child);
277
-
278
- /* this will add the static methods from the parent to
279
- the child constructor. */
280
- base.extendObject(this, constructor);
281
- return constructor;
282
- };
283
-
284
- base.extend.Class = Class;
285
-
286
- /**
287
- * TrackerTypes
288
- *
289
- * This will add and remove tracker types to the data tracker.
290
- *
291
- */
292
- var TrackerTypes =
293
- {
294
- /**
295
- * @member {object} The Type and callBack that is called
296
- * when the type is removed from the object.
297
- */
298
- types: {},
299
-
300
- /**
301
- * This will add a type.
302
- * @param {string} type
303
- * @param {function} callBack The function to call when an object
304
- * is having the type removed.
305
- */
306
- add: function(type, callBack)
307
- {
308
- this.types[type] = callBack;
309
- },
310
-
311
- /**
312
- * This will get a type or return false.
313
- * @param {string} type
314
- * @return {(function|boolean)} The callBack or false.
315
- */
316
- get: function(type)
317
- {
318
- return this.types[type] || false;
319
- },
320
-
321
- /**
322
- * This will remove a type.
323
- * @param {string} type
324
- */
325
- remove: function(type)
326
- {
327
- delete this.types[type];
328
- }
329
- };
330
-
331
- /**
332
- * Tracker
333
- *
334
- * This will create a tracker for an object that will
335
- * store each type added and the data stored to
336
- * each type.
337
- *
338
- * @class
339
- */
340
- var Tracker = base.Class.extend(
341
- {
342
- /**
343
- * @constructor
344
- */
345
- constructor: function()
346
- {
347
- /**
348
- * @member {object} types
349
- */
350
- this.types = {};
351
- },
352
-
353
- /**
354
- * This will add data to a type.
355
- *
356
- * @public
357
- * @param {string} addingType The type of data.
358
- * @param {*} data The data to store
359
- */
360
- add: function(addingType, data)
361
- {
362
- var type = this.types[addingType] || (this.types[addingType] = []);
363
- type.push(data);
364
- },
365
-
366
- /**
367
- * This will get all the data stored to a data type.
368
- * @param {string} type
369
- * @return {*|boolean} the data or false.
370
- */
371
- get: function(type)
372
- {
373
- return this.types[type] || false;
374
- },
375
-
376
- /**
377
- * This will call the callBack with the data.
378
- *
379
- * @private
380
- * @param {function} callBack
381
- * @param {*} data
382
- */
383
- removeByCallBack: function(callBack, data)
384
- {
385
- if(typeof callBack === 'function')
386
- {
387
- callBack(data);
388
- }
389
- },
390
-
391
- /**
392
- * This will remove the data by type.
393
- *
394
- * @private
395
- * @param {string} removingType
396
- */
397
- removeType: function(removingType)
398
- {
399
- var types = this.types;
400
- if(types)
401
- {
402
- var type = types[removingType];
403
- if(type.length)
404
- {
405
- var callBack = TrackerTypes.get(removingType);
406
- for(var i = 0, length = type.length; i < length; i++)
407
- {
408
- var data = type[i];
409
- if(data)
410
- {
411
- // this will stop any circular referrences
412
- type[i] = null;
413
-
414
- this.removeByCallBack(callBack, data);
415
- }
416
- }
417
- delete types[type];
418
- }
419
- }
420
- },
421
-
422
- /**
423
- * This will remove the data by type or all if no type is
424
- * set.
425
- *
426
- * @public
427
- * @param {string} [type]
428
- */
429
- remove: function(type)
430
- {
431
- if(type)
432
- {
433
- this.removeType(type);
434
- }
435
- else
436
- {
437
- var types = this.types;
438
- for(var prop in types)
439
- {
440
- if(types.hasOwnProperty(prop))
441
- {
442
- type = types[prop];
443
- if(!type)
444
- {
445
- continue;
446
- }
447
-
448
- this.removeType(prop);
449
- }
450
- }
451
-
452
- delete this.types;
453
- }
454
- }
455
- });
456
-
457
- /**
458
- * DataTracker
459
- *
460
- * This will add data tracking for objects. The DataTracker is
461
- * a single point where any data can be tracked to an object
462
- * or element. Modules can register types to store their own
463
- * data that can allow the data to be removed when the element
464
- * is removed.
465
- *
466
- * @class
467
- */
468
- var DataTracker = base.Class.extend(
469
- {
470
- /**
471
- * @constructor
472
- */
473
- constructor: function()
474
- {
475
- /**
476
- * @private
477
- * @member trackers This is an object that stores all tracker
478
- * objects by tracking id.
479
- */
480
- this.trackers = {};
481
-
482
- /**
483
- * @private
484
- * @member {int} trackingCount
485
- */
486
- this.trackingCount = 0;
487
- },
488
-
489
- /**
490
- * This will add a new type to the data tracker.
491
- *
492
- * @public
493
- * @param {string} type The new type.
494
- * @param {function} callBack The callBack to help clean
495
- * up data when removed.
496
- */
497
- addType: function(type, callBack)
498
- {
499
- TrackerTypes.add(type, callBack);
500
- },
501
-
502
- /**
503
- * This will remove a type from the data tracker.
504
- * @param {string} type
505
- */
506
- removeType: function(type)
507
- {
508
- TrackerTypes.remove(type);
509
- },
510
-
511
- /**
512
- * This will get the object tracking id or set it if
513
- * not set.
514
- *
515
- * @param {object} obj
516
- * @return {string}
517
- */
518
- getTrackingId: function(obj)
519
- {
520
- return obj.trackingId || (obj.trackingId = 'dt' + this.trackingCount++);
521
- },
522
-
523
- /**
524
- * This will add data to an object.
525
- *
526
- * @param {object} obj
527
- * @param {string} type The type name.
528
- * @param {*} data The data to track.
529
- */
530
- add: function(obj, type, data)
531
- {
532
- var id = this.getTrackingId(obj),
533
- tracker = this.find(id);
534
-
535
- tracker.add(type, data);
536
- },
537
-
538
- /**
539
- * This will get the data from a type or the tracker object
540
- * if type is not set.
541
- *
542
- * @param {object} obj
543
- * @param {string} [type]
544
- * @return {*}
545
- */
546
- get: function(obj, type)
547
- {
548
- var id = obj.trackingId,
549
- tracker = this.trackers[id];
550
- if(!tracker)
551
- {
552
- return false;
553
- }
554
-
555
- return (type)? tracker.get(type) : tracker;
556
- },
557
-
558
- /**
559
- * This will get the tracker or create a new tracker
560
- * if no tracker is set.
561
- *
562
- * @param {string} id
563
- * @return {object} The tracker.
564
- */
565
- find: function(id)
566
- {
567
- var trackers = this.trackers;
568
- return (trackers[id] || (trackers[id] = new Tracker()));
569
- },
570
-
571
- /**
572
- * This will remove a type or all data for an object if
573
- * no type is set.
574
- *
575
- * @param {object} obj
576
- * @param {stirng} [type]
577
- */
578
- remove: function(obj, type)
579
- {
580
- var id = obj.trackingId;
581
- if(!id)
582
- {
583
- return true;
584
- }
585
-
586
- var tracker = this.trackers[id];
587
- if(!tracker)
588
- {
589
- return false;
590
- }
591
-
592
- if(type)
593
- {
594
- tracker.remove(type);
595
-
596
- /* this will remove the msg from the elements
597
- if no elements are listed under the msg */
598
- if(base.isEmpty(tracker.types))
599
- {
600
- delete this.trackers[id];
601
- }
602
- }
603
- else
604
- {
605
- tracker.remove();
606
-
607
- delete this.trackers[id];
608
- }
609
- }
610
- });
611
-
612
- base.extend.DataTracker = new DataTracker();
613
-
614
- /* we want to add additional methods to the base prototype
615
- so they can be inherited */
616
- base.augment(
617
- {
618
- /**
619
- * This will get the last error.
620
- * @return {(object|boolean)} The last error or false.
621
- */
622
- getLastError: function()
623
- {
624
- var errors = this.errors;
625
- return (errors.length)? errors.pop() : false;
626
- },
627
-
628
- /**
629
- * This will add an error.
630
- *
631
- * @param {object} err
632
- */
633
- addError: function(err)
634
- {
635
- this.errors.push(err);
636
- },
637
-
638
- /**
639
- * This will parse a query string.
640
- *
641
- * @param {string} [str] The string to parse or the global
642
- * location will be parsed.
643
- * @param {bool} [decode]
644
- * @return {object}
645
- */
646
- parseQueryString: function(str, decode)
647
- {
648
- if(typeof str !== 'string')
649
- {
650
- str = global.location.search;
651
- }
652
-
653
- var objURL = {},
654
- regExp = /([^?=&]+)(=([^&]*))?/g;
655
- str.replace(regExp, function(a, b, c, d)
656
- {
657
- /* we want to save the key and the
658
- value to the objURL */
659
- objURL[b] = (decode !== false)? decodeURIComponent(d) : d;
660
- });
661
-
662
- return objURL;
663
- },
664
-
665
- /**
666
- * This will check if an object is empty.
667
- *
668
- * @param {object} obj
669
- * @return {boolean}
670
- */
671
- isEmpty: function(obj)
672
- {
673
- if(!obj || typeof obj !== 'object')
674
- {
675
- return true;
676
- }
677
-
678
- /* we want to loop through each property and
679
- check if it belongs to the object directly */
680
- for(var key in obj)
681
- {
682
- if(obj.hasOwnProperty(key))
683
- {
684
- return false;
685
- }
686
- }
687
- return true;
688
- },
689
-
690
- /**
691
- * This will select an element by id.
692
- *
693
- * @param {string} id
694
- * @return {(object|boolean)} The element object or false.
695
- */
696
- getById: function(id)
697
- {
698
- if(typeof id !== 'string')
699
- {
700
- return false;
701
- }
702
- var obj = document.getElementById(id);
703
- return (obj || false);
704
- },
705
-
706
- /**
707
- * This will select elements by name.
708
- *
709
- * @param {string} name
710
- * @return {(object|boolean)} The elements array or false.
711
- */
712
- getByName: function(name)
713
- {
714
- if(typeof name !== 'string')
715
- {
716
- return false;
717
- }
718
- var obj = document.getElementsByName(name);
719
- return (obj)? this.listToArray(obj) : false;
720
- },
721
-
722
- /**
723
- * This will select by css selector.
724
- *
725
- * @param {string} selector
726
- * @param {boolean} single Set to true if you only want one result.
727
- * @return {*}
728
- */
729
- getBySelector: function(selector, single)
730
- {
731
- if(typeof selector !== 'string')
732
- {
733
- return false;
734
- }
735
-
736
- /* we want to check if we are only selecting
737
- the first element or all elements */
738
- single = single || false;
739
- if(single === true)
740
- {
741
- var obj = document.querySelector(selector);
742
- return (obj || false);
743
- }
744
-
745
- var elements = document.querySelectorAll(selector);
746
- if(elements)
747
- {
748
- /* if there is only one result just return the
749
- first element in the node list */
750
- return (elements.length === 1)? elements[0] : this.listToArray(elements);
751
- }
752
- return false;
753
- },
754
-
755
- /**
756
- * This will get or set the innerHTML or an element.
757
- *
758
- * @param {object} obj
759
- * @param {string} [html] If the html is not set, the html of the
760
- * element will be returned.
761
- *
762
- * @return {(string|void)}
763
- */
764
- html: function(obj, html)
765
- {
766
- if(!obj || typeof obj !== 'object')
767
- {
768
- return false;
769
- }
770
-
771
- /* we want to check if we are getting the
772
- html or adding the html */
773
- if(typeof html !== 'undefined')
774
- {
775
- obj.innerHTML = html;
776
- return this;
777
- }
778
-
779
- return obj.innerHTML;
780
- },
781
-
782
- /**
783
- * This will set the css property of an element.
784
- *
785
- * @param {object} obj
786
- * @param {string} property
787
- * @param {string} value
788
- * @return {object} an instance of base.
789
- */
790
- setCss: function(obj, property, value)
791
- {
792
- if(!obj || typeof obj !== 'object' || typeof property === 'undefined')
793
- {
794
- return this;
795
- }
796
-
797
- property = this.uncamelCase(property);
798
- obj.style[property] = value;
799
- return this;
800
- },
801
-
802
- /**
803
- * This will get the css property of an element.
804
- *
805
- * @param {object} obj
806
- * @param {string} property
807
- * @return {(string|null)}
808
- */
809
- getCss: function(obj, property)
810
- {
811
- if(!obj || typeof property === 'undefined')
812
- {
813
- return false;
814
- }
815
-
816
- property = this.uncamelCase(property);
817
- var css = obj.style[property];
818
- if(css !== '')
819
- {
820
- return css;
821
- }
822
-
823
- /* we want to check if we have an inherited
824
- value */
825
- var currentValue = null,
826
- currentStyle = obj.currentStyle;
827
- if(currentStyle && (currentValue = currentStyle[property]))
828
- {
829
- css = currentValue;
830
- }
831
- else
832
- {
833
- var inheritedStyle = window.getComputedStyle(obj, null);
834
- if(inheritedStyle)
835
- {
836
- css = inheritedStyle[property];
837
- }
838
- }
839
-
840
- return css;
841
- },
842
-
843
- /**
844
- * This will get or set the css propety or an element.
845
- *
846
- * @param {object} obj
847
- * @param {string} property
848
- * @param {string} [value]
849
- * @return {(string|void)}
850
- */
851
- css: function(obj, property, value)
852
- {
853
- /* we want to check if we are getting the
854
- value or setting the value */
855
- if(typeof value !== 'undefined')
856
- {
857
- this.setCss(obj, property, value);
858
-
859
- return this;
860
- }
861
-
862
- return this.getCss(obj, property);
863
- },
864
-
865
- /**
866
- * This will remove an attribute from an element.
867
- *
868
- * @private
869
- * @return {*}
870
- */
871
- _removeAttr: function()
872
- {
873
- var removeAttr;
874
- if(typeof document.documentElement.removeAttribute === 'function')
875
- {
876
- removeAttr = function(obj, property)
877
- {
878
- obj.removeAttribute(property);
879
- };
880
- }
881
- else
882
- {
883
- removeAttr = function(obj, property)
884
- {
885
- /* we cannot remove the attr through the remove
886
- attr method so we want to null the value.
887
- we want to camel caps the propety */
888
- property = base.camelCase(property);
889
- obj.property = null;
890
- };
891
- }
892
-
893
- return this.override(this, '_removeAttr', removeAttr, arguments);
894
- },
895
-
896
- /**
897
- * This will remove an attribute from an element.
898
- *
899
- * @param {object} obj
900
- * @param {string} property
901
- * @return {object} an instance of base.
902
- */
903
- removeAttr: function(obj, property)
904
- {
905
- if(obj && typeof obj === 'object')
906
- {
907
- this._removeAttr(obj, property);
908
- }
909
- return this;
910
- },
911
-
912
- /**
913
- * This will set an attribute of an element.
914
- *
915
- * @private
916
- * @return {void}
917
- */
918
- setAttr: function()
919
- {
920
- /* create a local function to perform the check
921
- once then override the function */
922
- var setAttr;
923
- if(typeof document.documentElement.setAttribute === 'function')
924
- {
925
- // modern browsers
926
- setAttr = function(obj, property, value)
927
- {
928
- obj.setAttribute(property, value);
929
- };
930
- }
931
- else
932
- {
933
- // old browsers
934
- setAttr = function(obj, property, value)
935
- {
936
- obj[property] = value;
937
- };
938
- }
939
-
940
- return this.override(this, 'setAttr', setAttr, arguments);
941
- },
942
-
943
- /**
944
- * This will get an attribute of an element.
945
- *
946
- * @return {string}
947
- */
948
- getAttr: function()
949
- {
950
- /* create a local function to perform the check
951
- once then override the function */
952
- var getAttr;
953
- if(typeof document.documentElement.getAttribute === 'function')
954
- {
955
- // modern browsers
956
- getAttr = function(obj, property)
957
- {
958
- return obj.getAttribute(property);
959
- };
960
- }
961
- else
962
- {
963
- // old browsers
964
- getAttr = function(obj, property)
965
- {
966
- return obj[property];
967
- };
968
- }
969
-
970
- /* this will override method with cached method
971
- and we need to return and call with object */
972
- return this.override(this, 'getAttr', getAttr, arguments);
973
- },
974
-
975
- /**
976
- * This will get or set an attribute from an element.
977
- *
978
- * @param {object} obj
979
- * @param {string} property
980
- * @param {string} [value]
981
- * @return {(string|void)}
982
- */
983
- attr: function(obj, property, value)
984
- {
985
- if(!obj || typeof obj !== 'object')
986
- {
987
- return false;
988
- }
989
-
990
- /* we want to check if we are getting the
991
- value or setting the value */
992
- if(typeof value !== 'undefined')
993
- {
994
- /* we want to check to set the value */
995
- this.setAttr(obj, property, value);
996
-
997
- return this;
998
- }
999
-
1000
- return this.getAttr(obj, property);
1001
- },
1002
-
1003
- /**
1004
- * This will prefix a string with "data-" if not set.
1005
- *
1006
- * @protected
1007
- * @param {string} prop
1008
- * @return {string}
1009
- */
1010
- _checkDataPrefix: function(prop)
1011
- {
1012
- if(typeof prop !== 'string')
1013
- {
1014
- return prop;
1015
- }
1016
-
1017
- /* we want to de camelcase if set */
1018
- prop = base.uncamelCase(prop);
1019
- if(prop.substring(0, 5) !== 'data-')
1020
- {
1021
- prop = 'data-' + prop;
1022
- }
1023
-
1024
- return prop;
1025
- },
1026
-
1027
- /**
1028
- * This will remove "data-" from a string.
1029
- *
1030
- * @protected
1031
- * @param {string} prop
1032
- * @return {string}
1033
- */
1034
- _removeDataPrefix: function(prop)
1035
- {
1036
- if(typeof prop === 'string' && prop.substring(0, 5) === 'data-')
1037
- {
1038
- prop = prop.substring(5);
1039
- }
1040
- return prop;
1041
- },
1042
-
1043
- /**
1044
- * This will set data to an element.
1045
- *
1046
- * @param {object} obj
1047
- * @param {string} property
1048
- * @param {string} value
1049
- */
1050
- setData: function()
1051
- {
1052
- var self = this;
1053
- /* create a local function to perform the check
1054
- once then override the function */
1055
- var setData;
1056
- if(typeof document.documentElement.dataset !== 'undefined')
1057
- {
1058
- // modern browsers
1059
- setData = function(obj, property, value)
1060
- {
1061
- /* this will return the property without the data prefix */
1062
- property = self._removeDataPrefix(property);
1063
- property = base.camelCase(property);
1064
-
1065
- obj.dataset[property] = value;
1066
- };
1067
- }
1068
- else
1069
- {
1070
- // old browsers
1071
- setData = function(obj, property, value)
1072
- {
1073
- /* we need to check the prop prefix */
1074
- property = self._checkDataPrefix(property);
1075
- base.attr(obj, property, value);
1076
- };
1077
- }
1078
-
1079
- return this.override(this, 'setData', setData, arguments);
1080
- },
1081
-
1082
- /**
1083
- * This will get data from an element.
1084
- *
1085
- * @param {object} obj
1086
- * @param {string} property
1087
- * @param {string} value
1088
- * @return {string}
1089
- */
1090
- getData: function()
1091
- {
1092
- var self = this;
1093
- /* create a local function to perform the check
1094
- once then override the function */
1095
- var getData;
1096
- if(typeof document.documentElement.dataset !== 'undefined')
1097
- {
1098
- // modern browsers
1099
- getData = function(obj, property)
1100
- {
1101
- property = base.camelCase(self._removeDataPrefix(property));
1102
- return obj.dataset[property];
1103
- };
1104
- }
1105
- else
1106
- {
1107
- // old browsers
1108
- getData = function(obj, property)
1109
- {
1110
- property = self._checkDataPrefix(property);
1111
- return base.attr(obj, property);
1112
- };
1113
- }
1114
-
1115
- return this.override(this, 'getData', getData, arguments);
1116
- },
1117
-
1118
- /**
1119
- * This will get or set data to an element.
1120
- *
1121
- * @param {object} obj
1122
- * @param {string} property
1123
- * @param {string} [value]
1124
- * @return {(string|void)}
1125
- */
1126
- data: function(obj, property, value)
1127
- {
1128
- if(!obj || typeof obj !== 'object')
1129
- {
1130
- return false;
1131
- }
1132
-
1133
- if(typeof value !== 'undefined')
1134
- {
1135
- this.setData(obj, property, value);
1136
- return this;
1137
- }
1138
-
1139
- /* we need to check the prop prefix */
1140
- return this.getData(obj, property);
1141
- },
1142
-
1143
- /**
1144
- * This will find elements in an element.
1145
- *
1146
- * @param {object} obj
1147
- * @param {string} queryString
1148
- * @return {array}
1149
- */
1150
- find: function(obj, queryString)
1151
- {
1152
- if(!obj || typeof queryString !== 'string')
1153
- {
1154
- return false;
1155
- }
1156
-
1157
- return obj.querySelectorAll(queryString);
1158
- },
1159
-
1160
- /**
1161
- * This will display an element.
1162
- *
1163
- * @param {object} obj
1164
- * @return {object} An instance of base.
1165
- */
1166
- show: function(obj)
1167
- {
1168
- if(!obj || typeof obj !== 'object')
1169
- {
1170
- return this;
1171
- }
1172
-
1173
- /* we want to get the previous display style
1174
- from the data-style-display attr */
1175
- var previous = this.data(obj, 'style-display'),
1176
- value = (typeof previous === 'string')? previous : '';
1177
-
1178
- this.css(obj, 'display', value);
1179
- return this;
1180
- },
1181
-
1182
- /**
1183
- * This will hide an element.
1184
- *
1185
- * @param {object} obj
1186
- * @return {object} An instance of base.
1187
- */
1188
- hide: function(obj)
1189
- {
1190
- if(!obj || typeof obj !== 'object')
1191
- {
1192
- return this;
1193
- }
1194
-
1195
- /* we want to set the previous display style
1196
- on the element as a data attr */
1197
- var previous = this.css(obj, 'display');
1198
- if(previous !== 'none' && previous)
1199
- {
1200
- this.data(obj, 'style-display', previous);
1201
- }
1202
-
1203
- this.css(obj, 'display', 'none');
1204
- return this;
1205
- },
1206
-
1207
- /**
1208
- * This will toggle the display an element.
1209
- *
1210
- * @param {object} obj
1211
- * @return {object} An instance of base.
1212
- */
1213
- toggle: function(obj)
1214
- {
1215
- if(!obj || typeof obj !== 'object')
1216
- {
1217
- return this;
1218
- }
1219
-
1220
- var mode = this.css(obj, 'display');
1221
- if(mode !== 'none')
1222
- {
1223
- this.hide(obj);
1224
- }
1225
- else
1226
- {
1227
- this.show(obj);
1228
- }
1229
- return this;
1230
- },
1231
-
1232
- /**
1233
- * This will camelCase a string.
1234
- *
1235
- * @param {string} str
1236
- * @return {(string|boolean)} The string or false.
1237
- */
1238
- camelCase: function(str)
1239
- {
1240
- if(typeof str !== 'string')
1241
- {
1242
- return false;
1243
- }
1244
-
1245
- var regExp = /(-|\s|\_)+\w{1}/g;
1246
- return str.replace(regExp, function(match)
1247
- {
1248
- return match[1].toUpperCase();
1249
- });
1250
- },
1251
-
1252
- /**
1253
- * This will uncamel-case a string.
1254
- *
1255
- * @param {string} str
1256
- * @param {string} delimiter
1257
- * @return {(string|boolean)} The string or false.
1258
- */
1259
- uncamelCase: function(str, delimiter)
1260
- {
1261
- if(typeof str !== 'string')
1262
- {
1263
- return false;
1264
- }
1265
-
1266
- delimiter = delimiter || '-';
1267
-
1268
- var regExp = /([A-Z]{1,})/g;
1269
- return str.replace(regExp, function(match)
1270
- {
1271
- return delimiter + match.toLowerCase();
1272
- }).toLowerCase();
1273
- },
1274
-
1275
- /**
1276
- * This will get the size of an element.
1277
- *
1278
- * @param {object} obj
1279
- * @return {(object|boolean)} A size object or false.
1280
- */
1281
- getSize: function(obj)
1282
- {
1283
- if(!obj || typeof obj !== 'object')
1284
- {
1285
- return false;
1286
- }
1287
-
1288
- return {
1289
- width: this.getWidth(obj),
1290
- height: this.getHeight(obj)
1291
- };
1292
- },
1293
-
1294
- /**
1295
- * This will get the width of an element.
1296
- *
1297
- * @param {object} obj
1298
- * @return {(int|boolean)} A width or false.
1299
- */
1300
- getWidth: function(obj)
1301
- {
1302
- /* we want to check if the object is not supplied */
1303
- return (obj && typeof obj === 'object')? obj.offsetWidth : false;
1304
- },
1305
-
1306
- /**
1307
- * This will get the height of an element.
1308
- *
1309
- * @param {object} obj
1310
- * @return {(int|boolean)} A height or false.
1311
- */
1312
- getHeight: function(obj)
1313
- {
1314
- /* we want to check if the object is not supplied */
1315
- return (obj && typeof obj === 'object')? obj.offsetHeight : false;
1316
- },
1317
-
1318
- /**
1319
- * This will get the scroll position.
1320
- *
1321
- * @param {object} [obj] The element or document element if not set.
1322
- * @return {object}
1323
- */
1324
- getScrollPosition: function(obj)
1325
- {
1326
- var left = 0, top = 0;
1327
- if(typeof obj === 'undefined')
1328
- {
1329
- /* we want to use the document body */
1330
- obj = document.documentElement;
1331
- left = (window.pageXOffset || obj.scrollLeft);
1332
- top = (window.pageYOffset || obj.scrollTop);
1333
- }
1334
- else if(typeof obj === 'object')
1335
- {
1336
- left = obj.scrollLeft;
1337
- top = obj.scrollTop;
1338
- }
1339
-
1340
- if(!obj || typeof obj !== 'object')
1341
- {
1342
- return false;
1343
- }
1344
-
1345
- return {
1346
- left: left - (obj.clientLeft || 0),
1347
- top: top - (obj.clientTop || 0)
1348
- };
1349
- },
1350
-
1351
- /**
1352
- * This will get the scroll top position.
1353
- *
1354
- * @param {object} [obj] The element or document element if not set.
1355
- * @return {object}
1356
- */
1357
- getScrollTop: function(obj)
1358
- {
1359
- var position = this.getScrollPosition(obj);
1360
- return position.top;
1361
- },
1362
-
1363
- /**
1364
- * This will get the scroll left position.
1365
- *
1366
- * @param {object} [obj] The element or document element if not set.
1367
- * @return {object}
1368
- */
1369
- getScrollLeft: function(obj)
1370
- {
1371
- var position = this.getScrollPosition(obj);
1372
- return position.left;
1373
- },
1374
-
1375
- /**
1376
- * This will get the window size.
1377
- *
1378
- * @return {object}
1379
- */
1380
- getWindowSize: function()
1381
- {
1382
- var w = window,
1383
- doc = document,
1384
- de = doc.documentElement,
1385
- b = doc.getElementsByTagName('body')[0],
1386
- width = w.innerWidth || de.clientWidth || b.clientWidth,
1387
- height = w.innerHeight || de.clientHeight || b.clientHeight;
1388
-
1389
- return {
1390
- width: width,
1391
- height: height
1392
- };
1393
- },
1394
-
1395
- /**
1396
- * This will get the document size.
1397
- *
1398
- * @return {object}
1399
- */
1400
- getDocumentSize: function()
1401
- {
1402
- var doc = document,
1403
- body = doc.body,
1404
- html = doc.documentElement;
1405
-
1406
- var height = Math.max(
1407
- body.scrollHeight,
1408
- body.offsetHeight,
1409
- html.clientHeight,
1410
- html.scrollHeight,
1411
- html.offsetHeight
1412
- );
1413
-
1414
- var width = Math.max(
1415
- body.scrollWidth,
1416
- body.offsetWidth,
1417
- html.clientWidth,
1418
- html.scrollWidth,
1419
- html.offsetWidth
1420
- );
1421
-
1422
- return {
1423
- width: width,
1424
- height: height
1425
- };
1426
- },
1427
-
1428
- /**
1429
- * This will get the document height.
1430
- *
1431
- * @return {object}
1432
- */
1433
- getDocumentHeight: function()
1434
- {
1435
- return this.getDocumentSize().height;
1436
- },
1437
-
1438
- /**
1439
- * This will get the value from a property on an object.
1440
- *
1441
- * @param {object} obj
1442
- * @param {string} property
1443
- * @param {*} [defaultText] A value if no value is set.
1444
- * @return {string}
1445
- */
1446
- getProperty: function(obj, property, defaultText)
1447
- {
1448
- if(!obj || typeof obj !== 'object')
1449
- {
1450
- return '';
1451
- }
1452
-
1453
- var value = obj[property];
1454
- if(value)
1455
- {
1456
- return value;
1457
- }
1458
-
1459
- /* if no value was available
1460
- we want to return an empty string */
1461
- return (typeof defaultText !== 'undefined')? defaultText : '';
1462
- },
1463
-
1464
- /**
1465
- * This will get the position of an element.
1466
- *
1467
- * @param {object} obj
1468
- * @param {boolean} [depth] The number of levels, default is 1, 0 is to the root.
1469
- * @return {object}
1470
- */
1471
- position: function(obj, depth)
1472
- {
1473
- var position = {x: 0, y: 0};
1474
-
1475
- if(!obj || typeof obj !== 'object')
1476
- {
1477
- return position;
1478
- }
1479
-
1480
- depth = typeof depth === 'undefined'? 1 : depth;
1481
-
1482
- /* if the depth is 0 we will travel to the
1483
- top element */
1484
- var count = 0;
1485
- while(obj && (depth === 0 || count < depth))
1486
- {
1487
- count++;
1488
- position.x += (obj.offsetLeft + obj.clientLeft);
1489
- position.y += (obj.offsetTop + obj.clientTop);
1490
- obj = obj.offsetParent;
1491
- }
1492
-
1493
- return position;
1494
- },
1495
-
1496
- /**
1497
- * This will add a class to an element.
1498
- *
1499
- * @protected
1500
- * @param {object} obj
1501
- * @param {string} tmpClassName
1502
- */
1503
- _addClass: function()
1504
- {
1505
- /* create a local function to perform the check
1506
- once then override the function */
1507
- var addClass;
1508
- if(typeof document.documentElement.classList !== 'undefined')
1509
- {
1510
- // modern browsers
1511
- addClass = function(obj, tmpClassName)
1512
- {
1513
- obj.classList.add(tmpClassName);
1514
- };
1515
- }
1516
- else
1517
- {
1518
- // old browsers
1519
- addClass = function(obj, tmpClassName)
1520
- {
1521
- obj.className = obj.className + ' ' + tmpClassName;
1522
- };
1523
- }
1524
-
1525
- /* this will override method with cached method
1526
- and we need to return and call with object */
1527
- return this.override(this, '_addClass', addClass, arguments);
1528
- },
1529
-
1530
- /**
1531
- * This will add a class to an element.
1532
- *
1533
- * @param {object} obj
1534
- * @param {string} tmpClassName
1535
- */
1536
- addClass: function(obj, tmpClassName)
1537
- {
1538
- if(!obj || typeof obj !== 'object' || tmpClassName === '')
1539
- {
1540
- return this;
1541
- }
1542
-
1543
- if(typeof tmpClassName === 'string')
1544
- {
1545
- /* we want to divide the string by spaces and
1546
- add any class listed */
1547
- var adding = tmpClassName.split(' ');
1548
- for(var i = 0, maxLength = adding.length; i < maxLength; i++)
1549
- {
1550
- this._addClass(obj, adding[i]);
1551
- }
1552
- }
1553
- return this;
1554
- },
1555
-
1556
- /**
1557
- * This will remove a class from an element.
1558
- *
1559
- * @protected
1560
- * @param {object} obj
1561
- * @param {string} tmpClassName
1562
- */
1563
- _removeClass: function()
1564
- {
1565
- /* create a local function to perform the check
1566
- once then override the function */
1567
- var removeClass;
1568
- if(typeof document.documentElement.classList !== 'undefined')
1569
- {
1570
- // modern browsers
1571
- removeClass = function(obj, tmpClassName)
1572
- {
1573
- obj.classList.remove(tmpClassName);
1574
- };
1575
- }
1576
- else
1577
- {
1578
- // old browsers
1579
- removeClass = function(obj, tmpClassName)
1580
- {
1581
- /* we want to get the object classes in an array */
1582
- var classNames = obj.className.split(' ');
1583
- for(var i = 0, maxLength = classNames.length; i < maxLength; i++)
1584
- {
1585
- if(classNames[i] === tmpClassName)
1586
- {
1587
- classNames.splice(i, 1);
1588
- }
1589
- }
1590
- obj.className = classNames.join(' ');
1591
- };
1592
- }
1593
-
1594
- /* this will override method with cached method
1595
- and we need to return and call with object */
1596
- return this.override(this, '_removeClass', removeClass, arguments);
1597
- },
1598
-
1599
- /**
1600
- * This will remove a class or classes from an element.
1601
- *
1602
- * @param {object} obj
1603
- * @param {string} [tmpClassName]
1604
- */
1605
- removeClass: function(obj, tmpClassName)
1606
- {
1607
- if(!obj || typeof obj !== 'object' || tmpClassName === '')
1608
- {
1609
- return this;
1610
- }
1611
-
1612
- /* if no className was specified we will remove all classes from object */
1613
- if(typeof tmpClassName === 'undefined')
1614
- {
1615
- obj.className = '';
1616
- }
1617
- else
1618
- {
1619
- this._removeClass(obj, tmpClassName);
1620
- }
1621
- return this;
1622
- },
1623
-
1624
- /**
1625
- * This will check if an element has a class.
1626
- *
1627
- * @protected
1628
- * @param {object} obj
1629
- * @param {string} tmpClassName
1630
- * @return {boolean}
1631
- */
1632
- _hasClass: function()
1633
- {
1634
- /* create a local function to perform the check
1635
- once then override the function */
1636
- var hasClass;
1637
- if(typeof document.documentElement.classList !== 'undefined')
1638
- {
1639
- // modern browsers
1640
- hasClass = function(obj, tmpClassName)
1641
- {
1642
- return obj.classList.contains(tmpClassName);
1643
- };
1644
- }
1645
- else
1646
- {
1647
- // old browsers
1648
- hasClass = function(obj, tmpClassName)
1649
- {
1650
- /* we want to get the object classes in an array */
1651
- var check = false,
1652
- classNames = obj.className.split(' ');
1653
- for(var i = 0, maxLength = classNames.length; i < maxLength; i++)
1654
- {
1655
- if(classNames[i] === tmpClassName)
1656
- {
1657
- check = true;
1658
- break;
1659
- }
1660
- }
1661
- return check;
1662
- };
1663
- }
1664
-
1665
- /* this will override method with cached method
1666
- and we need to return and call with object */
1667
- return this.override(this, '_hasClass', hasClass, arguments);
1668
- },
1669
-
1670
- /**
1671
- * This will check if an element has a class.
1672
- *
1673
- * @param {object} obj
1674
- * @param {string} tmpClassName
1675
- * @return {boolean}
1676
- */
1677
- hasClass: function(obj, tmpClassName)
1678
- {
1679
- if(!obj || typeof obj !== 'object' || tmpClassName === '')
1680
- {
1681
- return false;
1682
- }
1683
-
1684
- return this._hasClass(obj, tmpClassName);
1685
- },
1686
-
1687
- /**
1688
- * This will toggle a class on an element.
1689
- *
1690
- * @param {object} obj
1691
- * @param {string} tmpClassName
1692
- * @return {object} An instance of base.
1693
- */
1694
- toggleClass: function(obj, tmpClassName)
1695
- {
1696
- if(!obj || typeof obj !== 'object')
1697
- {
1698
- return this;
1699
- }
1700
-
1701
- var hasClass = this.hasClass(obj, tmpClassName);
1702
- if(hasClass === true)
1703
- {
1704
- this.removeClass(obj, tmpClassName);
1705
- }
1706
- else
1707
- {
1708
- this.addClass(obj, tmpClassName);
1709
- }
1710
- return this;
1711
- },
1712
-
1713
- /**
1714
- * This will get the type of a variable.
1715
- *
1716
- * @param {*} data
1717
- * @return {string}
1718
- */
1719
- getType: function(data)
1720
- {
1721
- var type = typeof data;
1722
- if(type !== 'object')
1723
- {
1724
- return type;
1725
- }
1726
-
1727
- return (this.isArray(data))? 'array' : type;
1728
- },
1729
-
1730
- /**
1731
- * This will check if the variable is an array.
1732
- *
1733
- * @param {*} array
1734
- * @return {boolean}
1735
- */
1736
- isArray: function(array)
1737
- {
1738
- /* create a local function to perform the check once */
1739
- var isArray;
1740
- if(typeof Array.isArray === 'function')
1741
- {
1742
- // modern browsers
1743
- isArray = function(array)
1744
- {
1745
- return Array.isArray(array);
1746
- };
1747
- }
1748
- else
1749
- {
1750
- // old browsers
1751
- isArray = function(array)
1752
- {
1753
- return (array instanceof Array);
1754
- };
1755
- }
1756
-
1757
- return this.override(this, 'isArray', isArray, arguments);
1758
- },
1759
-
1760
- /**
1761
- * This will check if a value is found in an array.
1762
- *
1763
- * @protected
1764
- * @param {array} array
1765
- * @param {string} element
1766
- * @param {int} [fromIndex]
1767
- * @return {int}
1768
- */
1769
- _inArray: function()
1770
- {
1771
- /* create a local function to perform the check
1772
- once then override the function */
1773
- var inArray;
1774
- if(typeof Array.prototype.indexOf === 'function')
1775
- {
1776
- // modern browsers
1777
- inArray = function(array, element, fromIndex)
1778
- {
1779
- return array.indexOf(element, fromIndex);
1780
- };
1781
- }
1782
- else
1783
- {
1784
- // old browsers
1785
- inArray = function(array, element, fromIndex)
1786
- {
1787
- var length = (array.length),
1788
- start = (!isNaN(fromIndex))? fromIndex : 0;
1789
-
1790
- for(var i = start; i < length; i++)
1791
- {
1792
- if(element === array[i])
1793
- {
1794
- return i;
1795
- }
1796
- }
1797
- return -1;
1798
- };
1799
- }
1800
-
1801
- return this.override(this, '_inArray', inArray, arguments);
1802
- },
1803
-
1804
- /**
1805
- * This will check if a value is found in an array.
1806
- *
1807
- * @param {array} array
1808
- * @param {string} element
1809
- * @param {int} [fromIndex]
1810
- * @return {int} This will return -1 if not found.
1811
- */
1812
- inArray: function(array, element, fromIndex)
1813
- {
1814
- if(!array || typeof array !== 'object')
1815
- {
1816
- return -1;
1817
- }
1818
-
1819
- return this._inArray(array, element, fromIndex);
1820
- },
1821
-
1822
- /**
1823
- * This will create a callBack.
1824
- *
1825
- * @param {object} obj
1826
- * @param {function} method
1827
- * @param {array} [argArray] Default args to pass.
1828
- * @param {boolean} [addArgs] Set to add merge args from the
1829
- * curried function.
1830
- *
1831
- * @return {(function|boolean)} The callBack function or false.
1832
- */
1833
- createCallBack: function(obj, method, argArray, addArgs)
1834
- {
1835
- if(typeof method !== 'function')
1836
- {
1837
- return false;
1838
- }
1839
-
1840
- argArray = argArray || [];
1841
- return function()
1842
- {
1843
- if(addArgs === true)
1844
- {
1845
- var args = base.listToArray(arguments);
1846
- argArray = argArray.concat(args);
1847
- }
1848
-
1849
- return method.apply(obj, argArray);
1850
- };
1851
- },
1852
-
1853
- /**
1854
- * This will bind scope to a method.
1855
- *
1856
- * @param {object} obj
1857
- * @param {function} method
1858
- * @return {function}
1859
- */
1860
- bind: function(obj, method)
1861
- {
1862
- /* create a local function to perform the check
1863
- once then override the function */
1864
- var bind;
1865
- if(typeof Function.prototype.bind === 'function')
1866
- {
1867
- // modern browsers
1868
- bind = function(obj, method)
1869
- {
1870
- return method.bind(obj);
1871
- };
1872
- }
1873
- else
1874
- {
1875
- // old browsers
1876
- bind = function(obj, method)
1877
- {
1878
- return function()
1879
- {
1880
- return method.apply(obj, arguments);
1881
- };
1882
- };
1883
- }
1884
-
1885
- return this.override(this, 'bind', bind, arguments);
1886
- },
1887
-
1888
- /**
1889
- * This will prepare a json object to be used in an
1890
- * xhr request. This will sanitize the object values
1891
- * by encoding them to not break the param string.
1892
- *
1893
- * @param {object} obj
1894
- * @param {bool} [removeNewLines]
1895
- * @return {string}
1896
- */
1897
- prepareJsonUrl: function(obj, removeNewLines)
1898
- {
1899
- removeNewLines = removeNewLines || false;
1900
- var escapeChars = function(str)
1901
- {
1902
- if(typeof str !== 'string')
1903
- {
1904
- str = String(str);
1905
- }
1906
-
1907
- if(removeNewLines)
1908
- {
1909
- var newLine = /\n/g;
1910
- str = str.replace(newLine, "\\n");
1911
- }
1912
-
1913
- var tab = /\t/g;
1914
- return str.replace(tab, "\\t");
1915
- };
1916
-
1917
- var sanitize = function(text)
1918
- {
1919
- if(typeof text !== 'string')
1920
- {
1921
- return text;
1922
- }
1923
-
1924
- /* we need to escape chars and encode the uri
1925
- components */
1926
- text = escapeChars(text);
1927
- text = encodeURIComponent(text);
1928
-
1929
- /* we want to re-encode the double quotes so they
1930
- will be escaped by the json encoder */
1931
- var pattern = /\%22/g;
1932
- return text.replace(pattern, '"');
1933
- };
1934
-
1935
- var prepareUrl = function(data)
1936
- {
1937
- var type = typeof data;
1938
- if(type === "undefined")
1939
- {
1940
- return data;
1941
- }
1942
-
1943
- if(type !== 'object')
1944
- {
1945
- data = sanitize(data);
1946
- return data;
1947
- }
1948
-
1949
- for(var prop in data)
1950
- {
1951
- if(data.hasOwnProperty(prop) && data[prop] !== null)
1952
- {
1953
- var childType = typeof data[prop];
1954
- if(childType)
1955
- {
1956
- data[prop] = prepareUrl(data[prop]);
1957
- }
1958
- else
1959
- {
1960
- data[prop] = sanitize(data[prop]);
1961
- }
1962
- }
1963
- }
1964
- return data;
1965
- };
1966
-
1967
- /* we want to check to clone object so we won't modify the
1968
- original object */
1969
- var before = (typeof obj === 'object')? this.cloneObject(obj) : obj,
1970
- after = prepareUrl(before);
1971
- return this.jsonEncode(after);
1972
- },
1973
-
1974
- /**
1975
- * This will parse JSON data.
1976
- *
1977
- * @param {string} data
1978
- * @return {*}
1979
- */
1980
- jsonDecode: function(data)
1981
- {
1982
- return (typeof data !== "undefined" && data.length > 0)? JSON.parse(data) : false;
1983
- },
1984
-
1985
- /**
1986
- * This will encode JSON data.
1987
- *
1988
- * @param {*} data
1989
- * @return {string}
1990
- */
1991
- jsonEncode: function(data)
1992
- {
1993
- return (typeof data !== "undefined")? JSON.stringify(data) : false;
1994
- },
1995
-
1996
- /**
1997
- * This will parse xml data.
1998
- *
1999
- * @protected
2000
- * @param {string} data
2001
- * @return {object}
2002
- */
2003
- _xmlParse: function()
2004
- {
2005
- /* create a local function to perform the check
2006
- once then override the function */
2007
- var xmlParse;
2008
- if(typeof window.DOMParser !== 'undefined')
2009
- {
2010
- // modern browsers
2011
- xmlParse = function(data)
2012
- {
2013
- var parser = new DOMParser();
2014
- return parser.parseFromString(data, "text/xml");
2015
- };
2016
- }
2017
- else
2018
- {
2019
- // old browsers
2020
- xmlParse = function(data)
2021
- {
2022
- var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
2023
- xmlDoc.async = false;
2024
- return xmlDoc.loadXML(data);
2025
- };
2026
- }
2027
-
2028
- /* this will override method with cached method
2029
- and we need to return and call with object */
2030
- return this.override(this, '_xmlParse', xmlParse, arguments);
2031
- },
2032
-
2033
- /**
2034
- * This will parse xml data.
2035
- *
2036
- * @param {string} data
2037
- * @return {object}
2038
- */
2039
- xmlParse: function(data)
2040
- {
2041
- return (typeof data !== "undefined")? this._xmlParse(data) : false;
2042
- }
2043
-
2044
- });
2045
-
2046
- /**
2047
- * This will count the properties of an object.
2048
- *
2049
- * @param {object} obj
2050
- * @return {int}
2051
- */
2052
- var countProperty = function(obj)
2053
- {
2054
- var count = 0;
2055
- /* we want to count each property of the object */
2056
- for(var property in obj)
2057
- {
2058
- if(obj.hasOwnProperty(property))
2059
- {
2060
- count++;
2061
- /* we want to do a recursive count to get
2062
- any child properties */
2063
- if(typeof obj[property] === 'object')
2064
- {
2065
- count += countProperty(obj[property]);
2066
- }
2067
- }
2068
- }
2069
- return count;
2070
- };
2071
-
2072
- /**
2073
- * This will validate if the object properties match another object.
2074
- *
2075
- * @param {object} obj1
2076
- * @param {object} obj2
2077
- * @return {boolean}
2078
- */
2079
- var matchProperties = function(obj1, obj2)
2080
- {
2081
- var matched = false;
2082
-
2083
- if(typeof obj1 !== 'object' || typeof obj2 !== 'object')
2084
- {
2085
- return matched;
2086
- }
2087
-
2088
- /* we want to check each object1 property to the
2089
- object 2 property */
2090
- for(var property in obj1)
2091
- {
2092
- /* we want to check if the property is owned by the
2093
- object and that they have matching types */
2094
- if(!obj1.hasOwnProperty(property) || !obj2.hasOwnProperty(property))
2095
- {
2096
- break;
2097
- }
2098
-
2099
- var value1 = obj1[property],
2100
- value2 = obj2[property];
2101
-
2102
- if(typeof value1 !== typeof value2)
2103
- {
2104
- break;
2105
- }
2106
-
2107
- /* we want to check if the type is an object */
2108
- if(typeof value1 === 'object')
2109
- {
2110
- /* this will do a recursive check to the
2111
- child properties */
2112
- matched = matchProperties(value1, value2);
2113
- if(matched !== true)
2114
- {
2115
- /* if a property did not match we can stop
2116
- the comparison */
2117
- break;
2118
- }
2119
- }
2120
- else
2121
- {
2122
- if(value1 === value2)
2123
- {
2124
- matched = true;
2125
- }
2126
- else
2127
- {
2128
- break;
2129
- }
2130
- }
2131
- }
2132
-
2133
- return matched;
2134
- };
2135
-
2136
- /**
2137
- * This will compare if two objects match.
2138
- *
2139
- * @param {object} obj1
2140
- * @param {object} obj2
2141
- * @return {boolean}
2142
- */
2143
- var compareObjects = function(obj1, obj2)
2144
- {
2145
- /* we want to check if they have the same number of
2146
- properties */
2147
- var option1Count = countProperty(obj1),
2148
- option2Count = countProperty(obj2);
2149
- if(option1Count !== option2Count)
2150
- {
2151
- return false;
2152
- }
2153
-
2154
- return matchProperties(obj1, obj2);
2155
- };
2156
-
2157
- base.augment(
2158
- {
2159
- /**
2160
- * This will compare if two values match.
2161
- *
2162
- * @param {*} option1
2163
- * @param {*} option2
2164
- * @return {boolean}
2165
- */
2166
- equals: function(option1, option2)
2167
- {
2168
- /* we want to check if there types match */
2169
- var option1Type = typeof option1,
2170
- option2Type = typeof option2;
2171
- if(option1Type !== option2Type)
2172
- {
2173
- return false;
2174
- }
2175
-
2176
- /* we need to check if the options are objects
2177
- because we will want to match all the
2178
- properties */
2179
- if(option1Type === 'object')
2180
- {
2181
- return compareObjects(option1, option2);
2182
- }
2183
-
2184
- return (option1 === option2);
2185
- }
2186
- });
2187
-
2188
- })(this);
2189
-
2190
- /* base framework module */
2191
- /*
2192
- this adds event support
2193
- */
2194
- (function(global)
2195
- {
2196
- "use strict";
2197
-
2198
- var DataTracker = base.DataTracker;
2199
-
2200
- /* this will register the event system to the
2201
- data tracker to remove events that have been
2202
- added in layouts. */
2203
- DataTracker.addType('events', function(data)
2204
- {
2205
- base.events.removeEvent(data);
2206
- });
2207
-
2208
- base.extend.events =
2209
- {
2210
- /**
2211
- * This will get the events on an element.
2212
- *
2213
- * @param {object} obj
2214
- * @return {(array|boolean)}
2215
- */
2216
- getEvents: function(obj)
2217
- {
2218
- if(!obj || typeof obj !== 'object')
2219
- {
2220
- return false;
2221
- }
2222
- return DataTracker.get(obj, 'events');
2223
- },
2224
-
2225
- /**
2226
- * This will create an object to use with the DataTracker.
2227
- *
2228
- * @param {string} event The event name.
2229
- * @param {object} obj
2230
- * @param {function} fn
2231
- * @param {boolean} [capture]
2232
- * @param {boolean} [swapped]
2233
- * @param {function} [originalFn]
2234
- * @return {object}
2235
- */
2236
- create: function(event, obj, fn, capture, swapped, originalFn)
2237
- {
2238
- /* we want to check if the swapped param was set */
2239
- swapped = (swapped === true);
2240
-
2241
- return {
2242
- event: event,
2243
- obj: obj,
2244
- fn: fn,
2245
- capture: capture,
2246
- swapped: swapped,
2247
- originalFn: originalFn
2248
- };
2249
- },
2250
-
2251
- /* this will setup the add function to cache the
2252
- proper function so we only check one time.
2253
- @return (function) the function */
2254
- /**
2255
- * This will add an event.
2256
- * @param {string} event The event name.
2257
- * @param {object} obj
2258
- * @param {function} fn
2259
- * @param {boolean} [capture]
2260
- */
2261
- _add: function()
2262
- {
2263
- /* create a local function to perform the check
2264
- once then override the function */
2265
- var addEvent;
2266
- if(typeof global.addEventListener === 'function')
2267
- {
2268
- // modern browsers
2269
- addEvent = function(obj, event, fn, capture)
2270
- {
2271
- obj.addEventListener(event, fn, capture);
2272
- };
2273
- }
2274
- else if(typeof document.attachEvent === 'function')
2275
- {
2276
- // old ie
2277
- addEvent = function(obj, event, fn, capture)
2278
- {
2279
- obj.attachEvent("on" + event, fn);
2280
- };
2281
- }
2282
- else
2283
- {
2284
- addEvent = function(obj, event, fn, capture)
2285
- {
2286
- obj["on" + event] = fn;
2287
- };
2288
- }
2289
-
2290
- base.override(this, '_add', addEvent, arguments);
2291
- },
2292
-
2293
- /**
2294
- * This will add an event to an object.
2295
- *
2296
- * @param {string} event The event name.
2297
- * @param {object} obj
2298
- * @param {function} fn
2299
- * @param {boolean} [capture]
2300
- * @param {boolean} [swapped]
2301
- * @param {function} [originalFn]
2302
- */
2303
- add: function(event, obj, fn, capture, swapped, originalFn)
2304
- {
2305
- if(!obj || typeof obj !== 'object')
2306
- {
2307
- return this;
2308
- }
2309
-
2310
- capture = capture || false;
2311
-
2312
- /* we want to create an event object and add it the
2313
- the active events to track */
2314
- var data = this.create(event, obj, fn, capture, swapped, originalFn);
2315
- DataTracker.add(obj, 'events', data);
2316
-
2317
- this._add(obj, event, fn, capture);
2318
-
2319
- return this;
2320
- },
2321
-
2322
- /**
2323
- * This will remove an event from an object.
2324
- *
2325
- * @param {string} event The event name.
2326
- * @param {object} obj
2327
- * @param {function} fn
2328
- * @param {boolean} [capture]
2329
- * @return {object} a reference to the event object.
2330
- */
2331
- remove: function(event, obj, fn, capture)
2332
- {
2333
- capture = capture || false;
2334
-
2335
- /* we want to select the event from the active events array */
2336
- var result = this.getEvent(event, obj, fn, capture);
2337
- if(result === false)
2338
- {
2339
- return this;
2340
- }
2341
-
2342
- if(typeof result === 'object')
2343
- {
2344
- /* we want to use the remove event method and just
2345
- pass the listener object */
2346
- this.removeEvent(result);
2347
- }
2348
- return this;
2349
- },
2350
-
2351
- /**
2352
- * This will remove an event from an object.
2353
- *
2354
- * @protected
2355
- * @param {string} event The event name.
2356
- * @param {object} obj
2357
- * @param {function} fn
2358
- * @param {boolean} [capture]
2359
- */
2360
- _remove: function()
2361
- {
2362
- /* create a local function to perform the check
2363
- once then override the function */
2364
- var removeEvent;
2365
- if(typeof global.removeEventListener === 'function')
2366
- {
2367
- // modern browsers
2368
- removeEvent = function(obj, event, fn, capture)
2369
- {
2370
- obj.removeEventListener(event, fn, capture);
2371
- };
2372
- }
2373
- else if(typeof document.detachEvent === 'function')
2374
- {
2375
- // old ie
2376
- removeEvent = function(obj, event, fn, capture)
2377
- {
2378
- obj.detachEvent("on" + event, fn);
2379
- };
2380
- }
2381
- else
2382
- {
2383
- removeEvent = function(obj, event, fn, capture)
2384
- {
2385
- obj["on" + event] = null;
2386
- };
2387
- }
2388
-
2389
- base.override(this, '_remove', removeEvent, arguments);
2390
- },
2391
-
2392
- /**
2393
- * This will remove an event listener.
2394
- * @param {object} listener
2395
- * @return {object} a reference to the event object.
2396
- */
2397
- removeEvent: function(listener)
2398
- {
2399
- if(typeof listener === 'object')
2400
- {
2401
- this._remove(listener.obj, listener.event, listener.fn, listener.capture);
2402
- }
2403
- return this;
2404
- },
2405
-
2406
- /**
2407
- * This will search for an event.
2408
- *
2409
- * @protected
2410
- * @param {string} event The event name.
2411
- * @param {object} obj
2412
- * @param {function} fn
2413
- * @param {boolean} [capture]
2414
- * @return {(object|boolean)}
2415
- */
2416
- getEvent: function(event, obj, fn, capture)
2417
- {
2418
- if(typeof obj !== 'object')
2419
- {
2420
- return false;
2421
- }
2422
-
2423
- var events = this.getEvents(obj);
2424
- if(!events || events.length < 1)
2425
- {
2426
- return false;
2427
- }
2428
-
2429
- var eventObj = this.create(event, obj, fn, capture);
2430
- /* if the search returns anything but false we
2431
- found our active event */
2432
- return this.search(eventObj, events);
2433
- },
2434
-
2435
- /**
2436
- * This will search for an event from the object events.
2437
- *
2438
- * @param {object} eventObj
2439
- * @param {array} events
2440
- * @return {(object|boolean)}
2441
- */
2442
- search: function(eventObj, events)
2443
- {
2444
- var swappable = this.isSwappable(eventObj.event);
2445
- for(var i = 0, maxLength = events.length; i < maxLength; i++)
2446
- {
2447
- var listener = events[i];
2448
- if(listener.event !== eventObj.event || listener.obj !== eventObj.obj)
2449
- {
2450
- continue;
2451
- }
2452
-
2453
- if(listener.fn === eventObj.fn || (swappable === true && listener.originalFn === eventObj.fn))
2454
- {
2455
- return listener;
2456
- }
2457
- }
2458
-
2459
- return false;
2460
- },
2461
-
2462
- /**
2463
- * This will remove all events on an object.
2464
- *
2465
- * @param {object} obj
2466
- * @return {object} a reference to the events object.
2467
- */
2468
- removeEvents: function(obj)
2469
- {
2470
- if(!obj || typeof obj !== 'object')
2471
- {
2472
- return this;
2473
- }
2474
-
2475
- DataTracker.remove(obj, 'events');
2476
-
2477
- return this;
2478
- },
2479
-
2480
- /**
2481
- * @member {array} swap The swappable events.
2482
- */
2483
- swap: [
2484
- 'DOMMouseScroll',
2485
- 'wheel',
2486
- 'mousewheel',
2487
- 'mousemove',
2488
- 'popstate'
2489
- ],
2490
-
2491
- /**
2492
- * This will a event type to the swappable array.
2493
- *
2494
- * @param {string} type
2495
- */
2496
- addSwapped: function(type)
2497
- {
2498
- this.swap.push(type);
2499
- },
2500
-
2501
- /**
2502
- * This will check if an event is swappable.
2503
- *
2504
- * @param {string} event
2505
- * @return {boolean}
2506
- */
2507
- isSwappable: function(event)
2508
- {
2509
- /* we want to check if the event type is in the
2510
- swapped event array */
2511
- var index = base.inArray(this.swap, event);
2512
- return (index > -1);
2513
- }
2514
- };
2515
-
2516
- base.augment(
2517
- {
2518
- /**
2519
- * This will add an event to an object.
2520
- *
2521
- * @param {string} event The event name.
2522
- * @param {object} obj
2523
- * @param {function} fn
2524
- * @param {boolean} [capture]
2525
- * @return {object} An instance of base.
2526
- */
2527
- addListener: function(event, obj, fn, capture)
2528
- {
2529
- this.events.add(event, obj, fn, capture);
2530
-
2531
- return this;
2532
- },
2533
-
2534
- /**
2535
- * This will add an event to an object.
2536
- *
2537
- * @param {string} event The event name.
2538
- * @param {object} obj
2539
- * @param {function} fn
2540
- * @param {boolean} [capture]
2541
- * @return {object} An instance of base.
2542
- */
2543
- on: function(event, obj, fn, capture)
2544
- {
2545
- var events = this.events;
2546
- if(this.isArray(event))
2547
- {
2548
- for(var i = 0, length = event.length; i < length; i++)
2549
- {
2550
- var evt = event[i];
2551
- events.add(evt, obj, fn, capture);
2552
- }
2553
- }
2554
- else
2555
- {
2556
- events.add(event, obj, fn, capture);
2557
- }
2558
- return this;
2559
- },
2560
-
2561
- /**
2562
- * This will remove an event from an object.
2563
- *
2564
- * @param {string} event The event name.
2565
- * @param {object} obj
2566
- * @param {function} fn
2567
- * @param {boolean} [capture]
2568
- * @return {object} An instance of base.
2569
- */
2570
- off: function(event, obj, fn, capture)
2571
- {
2572
- var events = this.events;
2573
- if(this.isArray(event))
2574
- {
2575
- for(var i = 0, length = event.length; i < length; i++)
2576
- {
2577
- var evt = event[i];
2578
- events.remove(evt, obj, fn, capture);
2579
- }
2580
- }
2581
- else
2582
- {
2583
- events.remove(event, obj, fn, capture);
2584
- }
2585
- return this;
2586
- },
2587
-
2588
- /**
2589
- * This will remove an event from an object.
2590
- *
2591
- * @param {string} event The event name.
2592
- * @param {object} obj
2593
- * @param {function} fn
2594
- * @param {boolean} [capture]
2595
- * @return {object} An instance of base.
2596
- */
2597
- removeListener: function(event, obj, fn, capture)
2598
- {
2599
- /* we want to remove this from the active events */
2600
- this.events.remove(event, obj, fn, capture);
2601
-
2602
- return this;
2603
- },
2604
-
2605
- /**
2606
- * This will create a custom event.
2607
- *
2608
- * @protected
2609
- * @param {object} obj
2610
- * @param {object} event
2611
- * @param {string} eventType
2612
- * @param {object} [settings]
2613
- * @param {object} [params]
2614
- * @return {object}
2615
- */
2616
- _createEvent: function()
2617
- {
2618
- /* create a local function to perform the check
2619
- once then override the function */
2620
- var createEvent;
2621
- if('CustomEvent' in window)
2622
- {
2623
- createEvent = function(obj, event, eventType, settings, params)
2624
- {
2625
- var e;
2626
- if(eventType === 'HTMLEvents')
2627
- {
2628
- e = new Event(event);
2629
- }
2630
- else if(eventType === 'MouseEvents')
2631
- {
2632
- e = new MouseEvent(event, settings);
2633
- }
2634
- else
2635
- {
2636
- e = new CustomEvent(event, params);
2637
- }
2638
- return e;
2639
- };
2640
- }
2641
- else if('createEventObject' in document)
2642
- {
2643
- createEvent = function(obj, event, eventType, settings, params)
2644
- {
2645
- var e = document.createEventObject();
2646
- e.eventType = event;
2647
- return e;
2648
- };
2649
- }
2650
- else
2651
- {
2652
- createEvent = function(obj, event, eventType, settings, params)
2653
- {
2654
- var e = document.createEvent(eventType);
2655
- if (eventType === 'HTMLEvents')
2656
- {
2657
- obj.initEvent(event, settings.bubbles, settings.cancelable);
2658
- }
2659
- else if(eventType === 'MouseEvents')
2660
- {
2661
- e.initMouseEvent(
2662
- event,
2663
- settings.canBubble,
2664
- settings.cancelable,
2665
- settings.view,
2666
- settings.detail,
2667
- settings.screenX,
2668
- settings.screenY,
2669
- settings.clientX,
2670
- settings.clientY,
2671
- settings.ctrlKey,
2672
- settings.altKey,
2673
- settings.shiftKey,
2674
- settings.metaKey,
2675
- settings.button,
2676
- settings.relatedTarget
2677
- );
2678
- }
2679
- else if(eventType === 'CustomEvent')
2680
- {
2681
- e.initCustomEvent(event, settings.bubbles, settings.cancelable, params);
2682
- }
2683
- return e;
2684
- };
2685
- }
2686
-
2687
- /* this will override method with cached method
2688
- and we need to return and call with object */
2689
- return this.override(this, '_createEvent', createEvent, arguments);
2690
- },
2691
-
2692
- /**
2693
- * This will create a custom event. This supports html, mouse,
2694
- * and customevents.
2695
- *
2696
- * @param {string} event
2697
- * @param {object} obj
2698
- * @param {object} [options]
2699
- * @param {object} [params]
2700
- * @return {object}
2701
- */
2702
- createEvent: function(event, obj, options, params)
2703
- {
2704
- if(!obj || typeof obj !== 'object')
2705
- {
2706
- return false;
2707
- }
2708
-
2709
- var settings =
2710
- {
2711
- pointerX: 0,
2712
- pointerY: 0,
2713
- button: 0,
2714
- view: window,
2715
- detail: 1,
2716
- screenX: 0,
2717
- screenY: 0,
2718
- clientX: 0,
2719
- clientY: 0,
2720
- ctrlKey: false,
2721
- altKey: false,
2722
- shiftKey: false,
2723
- metaKey: false,
2724
- bubbles: true,
2725
- cancelable: true,
2726
- relatedTarget: null
2727
- };
2728
-
2729
- if(options && typeof options === 'object')
2730
- {
2731
- settings = base.extendObject(settings, options);
2732
- }
2733
-
2734
- var eventType = this._getEventType(event);
2735
- return this._createEvent(obj, event, eventType, settings, params);
2736
- },
2737
-
2738
- /**
2739
- * This will get thetype of an event.
2740
- *
2741
- * @protected
2742
- * @param {string} event
2743
- * @return {string}
2744
- */
2745
- _getEventType: function(event)
2746
- {
2747
- var eventTypes = {
2748
- 'HTMLEvents': /^(?:load|unload|abort|error|select|change|submit|reset|focus|blur|resize|scroll)$/,
2749
- 'MouseEvents': /^(?:click|dblclick|mouse(?:down|up|over|move|out))$/
2750
- };
2751
-
2752
- var eventType = 'CustomEvent';
2753
- for(var prop in eventTypes)
2754
- {
2755
- if(eventTypes.hasOwnProperty(prop))
2756
- {
2757
- var value = eventTypes[prop];
2758
- if(event.match(value))
2759
- {
2760
- eventType = prop;
2761
- break;
2762
- }
2763
- }
2764
- }
2765
- return eventType;
2766
- },
2767
-
2768
- /**
2769
- * This will trigger an event.
2770
- *
2771
- * @protected
2772
- * @param {object} obj
2773
- * @param {object} event
2774
- */
2775
- _trigger: function()
2776
- {
2777
- /* create a local function to perform the check
2778
- once then override the function */
2779
- var trigger;
2780
- if('createEvent' in document)
2781
- {
2782
- trigger = function(obj, event)
2783
- {
2784
- obj.dispatchEvent(event);
2785
- };
2786
- }
2787
- else
2788
- {
2789
- // old ie
2790
- trigger = function(obj, event)
2791
- {
2792
- var type = event.type;
2793
- obj.fireEvent('on' + type, event);
2794
- };
2795
- }
2796
-
2797
- this.override(this, '_trigger', trigger, arguments);
2798
- },
2799
-
2800
- /**
2801
- * This will trigger an event.
2802
- *
2803
- * @param {(string|object)} event
2804
- * @param {object} obj
2805
- * @param {object} [params]
2806
- * @return {object}
2807
- */
2808
- trigger: function(event, obj, params)
2809
- {
2810
- if(!obj || typeof obj !== 'object')
2811
- {
2812
- return this;
2813
- }
2814
-
2815
- var e = (typeof event === 'string')? this.createEvent(event, obj, null, params) : event;
2816
- this._trigger(obj, e);
2817
- return this;
2818
- },
2819
-
2820
- /**
2821
- * @member {string} mouseWheelEventType The mouse wheel event name.
2822
- * @protected
2823
- */
2824
- mouseWheelEventType: null,
2825
-
2826
- /**
2827
- * This will get the system mouse event.
2828
- *
2829
- * @protected
2830
- * @return {string}
2831
- */
2832
- getWheelEventType: function()
2833
- {
2834
- /* this will check what mouse wheel type
2835
- the client supports
2836
- @return (string) the event name */
2837
- var getMouseWheelType = function()
2838
- {
2839
- var type = 'wheel';
2840
- if('onmousewheel' in global)
2841
- {
2842
- type = 'mousewheel';
2843
- }
2844
- else if('DOMMouseScroll' in global)
2845
- {
2846
- type = 'DOMMouseScroll';
2847
- }
2848
- return type;
2849
- };
2850
-
2851
- /* this will get the event type or
2852
- one time set the type and return the type */
2853
- return this.mouseWheelEventType || (
2854
- this.mouseWheelEventType = getMouseWheelType()
2855
- );
2856
- },
2857
-
2858
- /**
2859
- * This will add a mouse event to an object.
2860
- *
2861
- * @param {function} callBackFn
2862
- * @param {object} [obj]
2863
- * @param {boolean} [cancelDefault]
2864
- * @param {boolean} capture
2865
- * @return {object} base object.
2866
- */
2867
- onMouseWheel: function(callBackFn, obj, cancelDefault, capture)
2868
- {
2869
- if(typeof obj === "undefined")
2870
- {
2871
- obj = window;
2872
- }
2873
-
2874
- var self = this;
2875
-
2876
- /* we want to return the mousewheel data
2877
- to this private callback function before
2878
- returning to the call back function*/
2879
- var mouseWheelResults = function(e)
2880
- {
2881
- e = e || window.event;
2882
- var delta = Math.max(-1, Math.min(1, (-e.deltaY || e.wheelDelta || -e.detail)));
2883
-
2884
- /* we can now send the mouse wheel results to
2885
- the call back function */
2886
- if(typeof callBackFn === 'function')
2887
- {
2888
- callBackFn(delta, e);
2889
- }
2890
-
2891
- /* we want to check to cancel default */
2892
- if(cancelDefault === true)
2893
- {
2894
- self.preventDefault(e);
2895
- }
2896
- };
2897
-
2898
- var event = this.getWheelEventType();
2899
- this.events.add(event, obj, mouseWheelResults, capture, true, callBackFn);
2900
- return this;
2901
- },
2902
-
2903
- /**
2904
- * This will remove a mouse event
2905
- *
2906
- * @param {function} callBackFn
2907
- * @param {object} [obj]
2908
- * @param {boolean} capture
2909
- * @return {object} base object.
2910
- */
2911
- offMouseWheel: function(callBackFn, obj, capture)
2912
- {
2913
- if(typeof obj === "undefined")
2914
- {
2915
- obj = window;
2916
- }
2917
-
2918
- var event = this.getWheelEventType();
2919
- this.off(event, obj, callBackFn, capture);
2920
- return this;
2921
- },
2922
-
2923
- /**
2924
- * This will prevent default on an event.
2925
- *
2926
- * @param {object} e
2927
- * @return {object} base object.
2928
- */
2929
- preventDefault: function(e)
2930
- {
2931
- e = e || window.event;
2932
-
2933
- if(typeof e.preventDefault === 'function')
2934
- {
2935
- e.preventDefault();
2936
- }
2937
- else
2938
- {
2939
- e.returnValue = false;
2940
- }
2941
-
2942
- return this;
2943
- },
2944
-
2945
- /**
2946
- * This will stop an event from propigating.
2947
- *
2948
- * @param {object} e
2949
- * @return {object} base object.
2950
- */
2951
- stopPropagation: function(e)
2952
- {
2953
- e = e || window.event;
2954
-
2955
- if(typeof e.stopPropagation === 'function')
2956
- {
2957
- e.stopPropagation();
2958
- }
2959
- else
2960
- {
2961
- e.cancelBubble = true;
2962
- }
2963
-
2964
- return this;
2965
- }
2966
- });
2967
-
2968
- })(this);