vis-rails 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vis/rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/vis.js +26 -26
  4. metadata +16 -85
  5. data/vendor/assets/vis/DataSet.js +0 -926
  6. data/vendor/assets/vis/DataView.js +0 -283
  7. data/vendor/assets/vis/graph/Edge.js +0 -957
  8. data/vendor/assets/vis/graph/Graph.js +0 -2291
  9. data/vendor/assets/vis/graph/Groups.js +0 -80
  10. data/vendor/assets/vis/graph/Images.js +0 -41
  11. data/vendor/assets/vis/graph/Node.js +0 -966
  12. data/vendor/assets/vis/graph/Popup.js +0 -132
  13. data/vendor/assets/vis/graph/css/graph-manipulation.css +0 -128
  14. data/vendor/assets/vis/graph/css/graph-navigation.css +0 -66
  15. data/vendor/assets/vis/graph/dotparser.js +0 -829
  16. data/vendor/assets/vis/graph/graphMixins/ClusterMixin.js +0 -1143
  17. data/vendor/assets/vis/graph/graphMixins/HierarchicalLayoutMixin.js +0 -311
  18. data/vendor/assets/vis/graph/graphMixins/ManipulationMixin.js +0 -576
  19. data/vendor/assets/vis/graph/graphMixins/MixinLoader.js +0 -199
  20. data/vendor/assets/vis/graph/graphMixins/NavigationMixin.js +0 -205
  21. data/vendor/assets/vis/graph/graphMixins/SectorsMixin.js +0 -552
  22. data/vendor/assets/vis/graph/graphMixins/SelectionMixin.js +0 -648
  23. data/vendor/assets/vis/graph/graphMixins/physics/BarnesHut.js +0 -398
  24. data/vendor/assets/vis/graph/graphMixins/physics/HierarchialRepulsion.js +0 -64
  25. data/vendor/assets/vis/graph/graphMixins/physics/PhysicsMixin.js +0 -697
  26. data/vendor/assets/vis/graph/graphMixins/physics/Repulsion.js +0 -66
  27. data/vendor/assets/vis/graph/img/acceptDeleteIcon.png +0 -0
  28. data/vendor/assets/vis/graph/img/addNodeIcon.png +0 -0
  29. data/vendor/assets/vis/graph/img/backIcon.png +0 -0
  30. data/vendor/assets/vis/graph/img/connectIcon.png +0 -0
  31. data/vendor/assets/vis/graph/img/cross.png +0 -0
  32. data/vendor/assets/vis/graph/img/cross2.png +0 -0
  33. data/vendor/assets/vis/graph/img/deleteIcon.png +0 -0
  34. data/vendor/assets/vis/graph/img/downArrow.png +0 -0
  35. data/vendor/assets/vis/graph/img/editIcon.png +0 -0
  36. data/vendor/assets/vis/graph/img/leftArrow.png +0 -0
  37. data/vendor/assets/vis/graph/img/minus.png +0 -0
  38. data/vendor/assets/vis/graph/img/plus.png +0 -0
  39. data/vendor/assets/vis/graph/img/rightArrow.png +0 -0
  40. data/vendor/assets/vis/graph/img/upArrow.png +0 -0
  41. data/vendor/assets/vis/graph/img/zoomExtends.png +0 -0
  42. data/vendor/assets/vis/graph/shapes.js +0 -225
  43. data/vendor/assets/vis/graph3d/Graph3d.js +0 -3306
  44. data/vendor/assets/vis/module/exports.js +0 -65
  45. data/vendor/assets/vis/module/header.js +0 -24
  46. data/vendor/assets/vis/module/imports.js +0 -31
  47. data/vendor/assets/vis/shim.js +0 -252
  48. data/vendor/assets/vis/timeline/Range.js +0 -532
  49. data/vendor/assets/vis/timeline/TimeStep.js +0 -466
  50. data/vendor/assets/vis/timeline/Timeline.js +0 -851
  51. data/vendor/assets/vis/timeline/component/Component.js +0 -52
  52. data/vendor/assets/vis/timeline/component/CurrentTime.js +0 -128
  53. data/vendor/assets/vis/timeline/component/CustomTime.js +0 -182
  54. data/vendor/assets/vis/timeline/component/Group.js +0 -470
  55. data/vendor/assets/vis/timeline/component/ItemSet.js +0 -1332
  56. data/vendor/assets/vis/timeline/component/TimeAxis.js +0 -389
  57. data/vendor/assets/vis/timeline/component/css/animation.css +0 -33
  58. data/vendor/assets/vis/timeline/component/css/currenttime.css +0 -5
  59. data/vendor/assets/vis/timeline/component/css/customtime.css +0 -6
  60. data/vendor/assets/vis/timeline/component/css/item.css +0 -107
  61. data/vendor/assets/vis/timeline/component/css/itemset.css +0 -33
  62. data/vendor/assets/vis/timeline/component/css/labelset.css +0 -36
  63. data/vendor/assets/vis/timeline/component/css/panel.css +0 -71
  64. data/vendor/assets/vis/timeline/component/css/timeaxis.css +0 -48
  65. data/vendor/assets/vis/timeline/component/css/timeline.css +0 -2
  66. data/vendor/assets/vis/timeline/component/item/Item.js +0 -139
  67. data/vendor/assets/vis/timeline/component/item/ItemBox.js +0 -230
  68. data/vendor/assets/vis/timeline/component/item/ItemPoint.js +0 -190
  69. data/vendor/assets/vis/timeline/component/item/ItemRange.js +0 -262
  70. data/vendor/assets/vis/timeline/component/item/ItemRangeOverflow.js +0 -57
  71. data/vendor/assets/vis/timeline/img/delete.png +0 -0
  72. data/vendor/assets/vis/timeline/stack.js +0 -112
  73. data/vendor/assets/vis/util.js +0 -990
@@ -1,57 +0,0 @@
1
- /**
2
- * @constructor ItemRangeOverflow
3
- * @extends ItemRange
4
- * @param {Object} data Object containing parameters start, end
5
- * content, className.
6
- * @param {{toScreen: function, toTime: function}} conversion
7
- * Conversion functions from time to screen and vice versa
8
- * @param {Object} [options] Configuration options
9
- * // TODO: describe options
10
- */
11
- function ItemRangeOverflow (data, conversion, options) {
12
- this.props = {
13
- content: {
14
- left: 0,
15
- width: 0
16
- }
17
- };
18
-
19
- ItemRange.call(this, data, conversion, options);
20
- }
21
-
22
- ItemRangeOverflow.prototype = new ItemRange (null, null, null);
23
-
24
- ItemRangeOverflow.prototype.baseClassName = 'item rangeoverflow';
25
-
26
- /**
27
- * Reposition the item horizontally
28
- * @Override
29
- */
30
- ItemRangeOverflow.prototype.repositionX = function() {
31
- var parentWidth = this.parent.width,
32
- start = this.conversion.toScreen(this.data.start),
33
- end = this.conversion.toScreen(this.data.end),
34
- contentLeft;
35
-
36
- // limit the width of the this, as browsers cannot draw very wide divs
37
- if (start < -parentWidth) {
38
- start = -parentWidth;
39
- }
40
- if (end > 2 * parentWidth) {
41
- end = 2 * parentWidth;
42
- }
43
-
44
- // when range exceeds left of the window, position the contents at the left of the visible area
45
- contentLeft = Math.max(-start, 0);
46
-
47
- this.left = start;
48
- var boxWidth = Math.max(end - start, 1);
49
- this.width = boxWidth + this.props.content.width;
50
- // Note: The calculation of width is an optimistic calculation, giving
51
- // a width which will not change when moving the Timeline
52
- // So no restacking needed, which is nicer for the eye
53
-
54
- this.dom.box.style.left = this.left + 'px';
55
- this.dom.box.style.width = boxWidth + 'px';
56
- this.dom.content.style.left = contentLeft + 'px';
57
- };
@@ -1,112 +0,0 @@
1
- /**
2
- * Utility functions for ordering and stacking of items
3
- */
4
- var stack = {};
5
-
6
- /**
7
- * Order items by their start data
8
- * @param {Item[]} items
9
- */
10
- stack.orderByStart = function(items) {
11
- items.sort(function (a, b) {
12
- return a.data.start - b.data.start;
13
- });
14
- };
15
-
16
- /**
17
- * Order items by their end date. If they have no end date, their start date
18
- * is used.
19
- * @param {Item[]} items
20
- */
21
- stack.orderByEnd = function(items) {
22
- items.sort(function (a, b) {
23
- var aTime = ('end' in a.data) ? a.data.end : a.data.start,
24
- bTime = ('end' in b.data) ? b.data.end : b.data.start;
25
-
26
- return aTime - bTime;
27
- });
28
- };
29
-
30
- /**
31
- * Adjust vertical positions of the items such that they don't overlap each
32
- * other.
33
- * @param {Item[]} items
34
- * All visible items
35
- * @param {{item: number, axis: number}} margin
36
- * Margins between items and between items and the axis.
37
- * @param {boolean} [force=false]
38
- * If true, all items will be repositioned. If false (default), only
39
- * items having a top===null will be re-stacked
40
- */
41
- stack.stack = function(items, margin, force) {
42
- var i, iMax;
43
-
44
- if (force) {
45
- // reset top position of all items
46
- for (i = 0, iMax = items.length; i < iMax; i++) {
47
- items[i].top = null;
48
- }
49
- }
50
-
51
- // calculate new, non-overlapping positions
52
- for (i = 0, iMax = items.length; i < iMax; i++) {
53
- var item = items[i];
54
- if (item.top === null) {
55
- // initialize top position
56
- item.top = margin.axis;
57
-
58
- do {
59
- // TODO: optimize checking for overlap. when there is a gap without items,
60
- // you only need to check for items from the next item on, not from zero
61
- var collidingItem = null;
62
- for (var j = 0, jj = items.length; j < jj; j++) {
63
- var other = items[j];
64
- if (other.top !== null && other !== item && stack.collision(item, other, margin.item)) {
65
- collidingItem = other;
66
- break;
67
- }
68
- }
69
-
70
- if (collidingItem != null) {
71
- // There is a collision. Reposition the items above the colliding element
72
- item.top = collidingItem.top + collidingItem.height + margin.item;
73
- }
74
- } while (collidingItem);
75
- }
76
- }
77
- };
78
-
79
- /**
80
- * Adjust vertical positions of the items without stacking them
81
- * @param {Item[]} items
82
- * All visible items
83
- * @param {{item: number, axis: number}} margin
84
- * Margins between items and between items and the axis.
85
- */
86
- stack.nostack = function(items, margin) {
87
- var i, iMax;
88
-
89
- // reset top position of all items
90
- for (i = 0, iMax = items.length; i < iMax; i++) {
91
- items[i].top = margin.axis;
92
- }
93
- };
94
-
95
- /**
96
- * Test if the two provided items collide
97
- * The items must have parameters left, width, top, and height.
98
- * @param {Item} a The first item
99
- * @param {Item} b The second item
100
- * @param {Number} margin A minimum required margin.
101
- * If margin is provided, the two items will be
102
- * marked colliding when they overlap or
103
- * when the margin between the two is smaller than
104
- * the requested margin.
105
- * @return {boolean} true if a and b collide, else false
106
- */
107
- stack.collision = function(a, b, margin) {
108
- return ((a.left - margin) < (b.left + b.width) &&
109
- (a.left + a.width + margin) > b.left &&
110
- (a.top - margin) < (b.top + b.height) &&
111
- (a.top + a.height + margin) > b.top);
112
- };
@@ -1,990 +0,0 @@
1
- /**
2
- * utility functions
3
- */
4
- var util = {};
5
-
6
- /**
7
- * Test whether given object is a number
8
- * @param {*} object
9
- * @return {Boolean} isNumber
10
- */
11
- util.isNumber = function(object) {
12
- return (object instanceof Number || typeof object == 'number');
13
- };
14
-
15
- /**
16
- * Test whether given object is a string
17
- * @param {*} object
18
- * @return {Boolean} isString
19
- */
20
- util.isString = function(object) {
21
- return (object instanceof String || typeof object == 'string');
22
- };
23
-
24
- /**
25
- * Test whether given object is a Date, or a String containing a Date
26
- * @param {Date | String} object
27
- * @return {Boolean} isDate
28
- */
29
- util.isDate = function(object) {
30
- if (object instanceof Date) {
31
- return true;
32
- }
33
- else if (util.isString(object)) {
34
- // test whether this string contains a date
35
- var match = ASPDateRegex.exec(object);
36
- if (match) {
37
- return true;
38
- }
39
- else if (!isNaN(Date.parse(object))) {
40
- return true;
41
- }
42
- }
43
-
44
- return false;
45
- };
46
-
47
- /**
48
- * Test whether given object is an instance of google.visualization.DataTable
49
- * @param {*} object
50
- * @return {Boolean} isDataTable
51
- */
52
- util.isDataTable = function(object) {
53
- return (typeof (google) !== 'undefined') &&
54
- (google.visualization) &&
55
- (google.visualization.DataTable) &&
56
- (object instanceof google.visualization.DataTable);
57
- };
58
-
59
- /**
60
- * Create a semi UUID
61
- * source: http://stackoverflow.com/a/105074/1262753
62
- * @return {String} uuid
63
- */
64
- util.randomUUID = function() {
65
- var S4 = function () {
66
- return Math.floor(
67
- Math.random() * 0x10000 /* 65536 */
68
- ).toString(16);
69
- };
70
-
71
- return (
72
- S4() + S4() + '-' +
73
- S4() + '-' +
74
- S4() + '-' +
75
- S4() + '-' +
76
- S4() + S4() + S4()
77
- );
78
- };
79
-
80
- /**
81
- * Extend object a with the properties of object b or a series of objects
82
- * Only properties with defined values are copied
83
- * @param {Object} a
84
- * @param {... Object} b
85
- * @return {Object} a
86
- */
87
- util.extend = function (a, b) {
88
- for (var i = 1, len = arguments.length; i < len; i++) {
89
- var other = arguments[i];
90
- for (var prop in other) {
91
- if (other.hasOwnProperty(prop)) {
92
- a[prop] = other[prop];
93
- }
94
- }
95
- }
96
-
97
- return a;
98
- };
99
-
100
- /**
101
- * Extend object a with selected properties of object b or a series of objects
102
- * Only properties with defined values are copied
103
- * @param {Array.<String>} props
104
- * @param {Object} a
105
- * @param {... Object} b
106
- * @return {Object} a
107
- */
108
- util.selectiveExtend = function (props, a, b) {
109
- if (!Array.isArray(props)) {
110
- throw new Error('Array with property names expected as first argument');
111
- }
112
-
113
- for (var i = 1, len = arguments.length; i < len; i++) {
114
- var other = arguments[i];
115
-
116
- for (var p = 0, pp = props.length; p < pp; p++) {
117
- var prop = props[p];
118
- if (other.hasOwnProperty(prop)) {
119
- a[prop] = other[prop];
120
- }
121
- }
122
- }
123
-
124
- return a;
125
- };
126
-
127
- /**
128
- * Deep extend an object a with the properties of object b
129
- * @param {Object} a
130
- * @param {Object} b
131
- * @returns {Object}
132
- */
133
- util.deepExtend = function(a, b) {
134
- // TODO: add support for Arrays to deepExtend
135
- if (Array.isArray(b)) {
136
- throw new TypeError('Arrays are not supported by deepExtend');
137
- }
138
-
139
- for (var prop in b) {
140
- if (b.hasOwnProperty(prop)) {
141
- if (b[prop] && b[prop].constructor === Object) {
142
- if (a[prop] === undefined) {
143
- a[prop] = {};
144
- }
145
- if (a[prop].constructor === Object) {
146
- util.deepExtend(a[prop], b[prop]);
147
- }
148
- else {
149
- a[prop] = b[prop];
150
- }
151
- } else if (Array.isArray(b[prop])) {
152
- throw new TypeError('Arrays are not supported by deepExtend');
153
- } else {
154
- a[prop] = b[prop];
155
- }
156
- }
157
- }
158
- return a;
159
- };
160
-
161
- /**
162
- * Test whether all elements in two arrays are equal.
163
- * @param {Array} a
164
- * @param {Array} b
165
- * @return {boolean} Returns true if both arrays have the same length and same
166
- * elements.
167
- */
168
- util.equalArray = function (a, b) {
169
- if (a.length != b.length) return false;
170
-
171
- for (var i = 0, len = a.length; i < len; i++) {
172
- if (a[i] != b[i]) return false;
173
- }
174
-
175
- return true;
176
- };
177
-
178
- /**
179
- * Convert an object to another type
180
- * @param {Boolean | Number | String | Date | Moment | Null | undefined} object
181
- * @param {String | undefined} type Name of the type. Available types:
182
- * 'Boolean', 'Number', 'String',
183
- * 'Date', 'Moment', ISODate', 'ASPDate'.
184
- * @return {*} object
185
- * @throws Error
186
- */
187
- util.convert = function(object, type) {
188
- var match;
189
-
190
- if (object === undefined) {
191
- return undefined;
192
- }
193
- if (object === null) {
194
- return null;
195
- }
196
-
197
- if (!type) {
198
- return object;
199
- }
200
- if (!(typeof type === 'string') && !(type instanceof String)) {
201
- throw new Error('Type must be a string');
202
- }
203
-
204
- //noinspection FallthroughInSwitchStatementJS
205
- switch (type) {
206
- case 'boolean':
207
- case 'Boolean':
208
- return Boolean(object);
209
-
210
- case 'number':
211
- case 'Number':
212
- return Number(object.valueOf());
213
-
214
- case 'string':
215
- case 'String':
216
- return String(object);
217
-
218
- case 'Date':
219
- if (util.isNumber(object)) {
220
- return new Date(object);
221
- }
222
- if (object instanceof Date) {
223
- return new Date(object.valueOf());
224
- }
225
- else if (moment.isMoment(object)) {
226
- return new Date(object.valueOf());
227
- }
228
- if (util.isString(object)) {
229
- match = ASPDateRegex.exec(object);
230
- if (match) {
231
- // object is an ASP date
232
- return new Date(Number(match[1])); // parse number
233
- }
234
- else {
235
- return moment(object).toDate(); // parse string
236
- }
237
- }
238
- else {
239
- throw new Error(
240
- 'Cannot convert object of type ' + util.getType(object) +
241
- ' to type Date');
242
- }
243
-
244
- case 'Moment':
245
- if (util.isNumber(object)) {
246
- return moment(object);
247
- }
248
- if (object instanceof Date) {
249
- return moment(object.valueOf());
250
- }
251
- else if (moment.isMoment(object)) {
252
- return moment(object);
253
- }
254
- if (util.isString(object)) {
255
- match = ASPDateRegex.exec(object);
256
- if (match) {
257
- // object is an ASP date
258
- return moment(Number(match[1])); // parse number
259
- }
260
- else {
261
- return moment(object); // parse string
262
- }
263
- }
264
- else {
265
- throw new Error(
266
- 'Cannot convert object of type ' + util.getType(object) +
267
- ' to type Date');
268
- }
269
-
270
- case 'ISODate':
271
- if (util.isNumber(object)) {
272
- return new Date(object);
273
- }
274
- else if (object instanceof Date) {
275
- return object.toISOString();
276
- }
277
- else if (moment.isMoment(object)) {
278
- return object.toDate().toISOString();
279
- }
280
- else if (util.isString(object)) {
281
- match = ASPDateRegex.exec(object);
282
- if (match) {
283
- // object is an ASP date
284
- return new Date(Number(match[1])).toISOString(); // parse number
285
- }
286
- else {
287
- return new Date(object).toISOString(); // parse string
288
- }
289
- }
290
- else {
291
- throw new Error(
292
- 'Cannot convert object of type ' + util.getType(object) +
293
- ' to type ISODate');
294
- }
295
-
296
- case 'ASPDate':
297
- if (util.isNumber(object)) {
298
- return '/Date(' + object + ')/';
299
- }
300
- else if (object instanceof Date) {
301
- return '/Date(' + object.valueOf() + ')/';
302
- }
303
- else if (util.isString(object)) {
304
- match = ASPDateRegex.exec(object);
305
- var value;
306
- if (match) {
307
- // object is an ASP date
308
- value = new Date(Number(match[1])).valueOf(); // parse number
309
- }
310
- else {
311
- value = new Date(object).valueOf(); // parse string
312
- }
313
- return '/Date(' + value + ')/';
314
- }
315
- else {
316
- throw new Error(
317
- 'Cannot convert object of type ' + util.getType(object) +
318
- ' to type ASPDate');
319
- }
320
-
321
- default:
322
- throw new Error('Unknown type "' + type + '"');
323
- }
324
- };
325
-
326
- // parse ASP.Net Date pattern,
327
- // for example '/Date(1198908717056)/' or '/Date(1198908717056-0700)/'
328
- // code from http://momentjs.com/
329
- var ASPDateRegex = /^\/?Date\((\-?\d+)/i;
330
-
331
- /**
332
- * Get the type of an object, for example util.getType([]) returns 'Array'
333
- * @param {*} object
334
- * @return {String} type
335
- */
336
- util.getType = function(object) {
337
- var type = typeof object;
338
-
339
- if (type == 'object') {
340
- if (object == null) {
341
- return 'null';
342
- }
343
- if (object instanceof Boolean) {
344
- return 'Boolean';
345
- }
346
- if (object instanceof Number) {
347
- return 'Number';
348
- }
349
- if (object instanceof String) {
350
- return 'String';
351
- }
352
- if (object instanceof Array) {
353
- return 'Array';
354
- }
355
- if (object instanceof Date) {
356
- return 'Date';
357
- }
358
- return 'Object';
359
- }
360
- else if (type == 'number') {
361
- return 'Number';
362
- }
363
- else if (type == 'boolean') {
364
- return 'Boolean';
365
- }
366
- else if (type == 'string') {
367
- return 'String';
368
- }
369
-
370
- return type;
371
- };
372
-
373
- /**
374
- * Retrieve the absolute left value of a DOM element
375
- * @param {Element} elem A dom element, for example a div
376
- * @return {number} left The absolute left position of this element
377
- * in the browser page.
378
- */
379
- util.getAbsoluteLeft = function(elem) {
380
- var doc = document.documentElement;
381
- var body = document.body;
382
-
383
- var left = elem.offsetLeft;
384
- var e = elem.offsetParent;
385
- while (e != null && e != body && e != doc) {
386
- left += e.offsetLeft;
387
- left -= e.scrollLeft;
388
- e = e.offsetParent;
389
- }
390
- return left;
391
- };
392
-
393
- /**
394
- * Retrieve the absolute top value of a DOM element
395
- * @param {Element} elem A dom element, for example a div
396
- * @return {number} top The absolute top position of this element
397
- * in the browser page.
398
- */
399
- util.getAbsoluteTop = function(elem) {
400
- var doc = document.documentElement;
401
- var body = document.body;
402
-
403
- var top = elem.offsetTop;
404
- var e = elem.offsetParent;
405
- while (e != null && e != body && e != doc) {
406
- top += e.offsetTop;
407
- top -= e.scrollTop;
408
- e = e.offsetParent;
409
- }
410
- return top;
411
- };
412
-
413
- /**
414
- * Get the absolute, vertical mouse position from an event.
415
- * @param {Event} event
416
- * @return {Number} pageY
417
- */
418
- util.getPageY = function(event) {
419
- if ('pageY' in event) {
420
- return event.pageY;
421
- }
422
- else {
423
- var clientY;
424
- if (('targetTouches' in event) && event.targetTouches.length) {
425
- clientY = event.targetTouches[0].clientY;
426
- }
427
- else {
428
- clientY = event.clientY;
429
- }
430
-
431
- var doc = document.documentElement;
432
- var body = document.body;
433
- return clientY +
434
- ( doc && doc.scrollTop || body && body.scrollTop || 0 ) -
435
- ( doc && doc.clientTop || body && body.clientTop || 0 );
436
- }
437
- };
438
-
439
- /**
440
- * Get the absolute, horizontal mouse position from an event.
441
- * @param {Event} event
442
- * @return {Number} pageX
443
- */
444
- util.getPageX = function(event) {
445
- if ('pageY' in event) {
446
- return event.pageX;
447
- }
448
- else {
449
- var clientX;
450
- if (('targetTouches' in event) && event.targetTouches.length) {
451
- clientX = event.targetTouches[0].clientX;
452
- }
453
- else {
454
- clientX = event.clientX;
455
- }
456
-
457
- var doc = document.documentElement;
458
- var body = document.body;
459
- return clientX +
460
- ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
461
- ( doc && doc.clientLeft || body && body.clientLeft || 0 );
462
- }
463
- };
464
-
465
- /**
466
- * add a className to the given elements style
467
- * @param {Element} elem
468
- * @param {String} className
469
- */
470
- util.addClassName = function(elem, className) {
471
- var classes = elem.className.split(' ');
472
- if (classes.indexOf(className) == -1) {
473
- classes.push(className); // add the class to the array
474
- elem.className = classes.join(' ');
475
- }
476
- };
477
-
478
- /**
479
- * add a className to the given elements style
480
- * @param {Element} elem
481
- * @param {String} className
482
- */
483
- util.removeClassName = function(elem, className) {
484
- var classes = elem.className.split(' ');
485
- var index = classes.indexOf(className);
486
- if (index != -1) {
487
- classes.splice(index, 1); // remove the class from the array
488
- elem.className = classes.join(' ');
489
- }
490
- };
491
-
492
- /**
493
- * For each method for both arrays and objects.
494
- * In case of an array, the built-in Array.forEach() is applied.
495
- * In case of an Object, the method loops over all properties of the object.
496
- * @param {Object | Array} object An Object or Array
497
- * @param {function} callback Callback method, called for each item in
498
- * the object or array with three parameters:
499
- * callback(value, index, object)
500
- */
501
- util.forEach = function(object, callback) {
502
- var i,
503
- len;
504
- if (object instanceof Array) {
505
- // array
506
- for (i = 0, len = object.length; i < len; i++) {
507
- callback(object[i], i, object);
508
- }
509
- }
510
- else {
511
- // object
512
- for (i in object) {
513
- if (object.hasOwnProperty(i)) {
514
- callback(object[i], i, object);
515
- }
516
- }
517
- }
518
- };
519
-
520
- /**
521
- * Convert an object into an array: all objects properties are put into the
522
- * array. The resulting array is unordered.
523
- * @param {Object} object
524
- * @param {Array} array
525
- */
526
- util.toArray = function(object) {
527
- var array = [];
528
-
529
- for (var prop in object) {
530
- if (object.hasOwnProperty(prop)) array.push(object[prop]);
531
- }
532
-
533
- return array;
534
- }
535
-
536
- /**
537
- * Update a property in an object
538
- * @param {Object} object
539
- * @param {String} key
540
- * @param {*} value
541
- * @return {Boolean} changed
542
- */
543
- util.updateProperty = function(object, key, value) {
544
- if (object[key] !== value) {
545
- object[key] = value;
546
- return true;
547
- }
548
- else {
549
- return false;
550
- }
551
- };
552
-
553
- /**
554
- * Add and event listener. Works for all browsers
555
- * @param {Element} element An html element
556
- * @param {string} action The action, for example "click",
557
- * without the prefix "on"
558
- * @param {function} listener The callback function to be executed
559
- * @param {boolean} [useCapture]
560
- */
561
- util.addEventListener = function(element, action, listener, useCapture) {
562
- if (element.addEventListener) {
563
- if (useCapture === undefined)
564
- useCapture = false;
565
-
566
- if (action === "mousewheel" && navigator.userAgent.indexOf("Firefox") >= 0) {
567
- action = "DOMMouseScroll"; // For Firefox
568
- }
569
-
570
- element.addEventListener(action, listener, useCapture);
571
- } else {
572
- element.attachEvent("on" + action, listener); // IE browsers
573
- }
574
- };
575
-
576
- /**
577
- * Remove an event listener from an element
578
- * @param {Element} element An html dom element
579
- * @param {string} action The name of the event, for example "mousedown"
580
- * @param {function} listener The listener function
581
- * @param {boolean} [useCapture]
582
- */
583
- util.removeEventListener = function(element, action, listener, useCapture) {
584
- if (element.removeEventListener) {
585
- // non-IE browsers
586
- if (useCapture === undefined)
587
- useCapture = false;
588
-
589
- if (action === "mousewheel" && navigator.userAgent.indexOf("Firefox") >= 0) {
590
- action = "DOMMouseScroll"; // For Firefox
591
- }
592
-
593
- element.removeEventListener(action, listener, useCapture);
594
- } else {
595
- // IE browsers
596
- element.detachEvent("on" + action, listener);
597
- }
598
- };
599
-
600
-
601
- /**
602
- * Get HTML element which is the target of the event
603
- * @param {Event} event
604
- * @return {Element} target element
605
- */
606
- util.getTarget = function(event) {
607
- // code from http://www.quirksmode.org/js/events_properties.html
608
- if (!event) {
609
- event = window.event;
610
- }
611
-
612
- var target;
613
-
614
- if (event.target) {
615
- target = event.target;
616
- }
617
- else if (event.srcElement) {
618
- target = event.srcElement;
619
- }
620
-
621
- if (target.nodeType != undefined && target.nodeType == 3) {
622
- // defeat Safari bug
623
- target = target.parentNode;
624
- }
625
-
626
- return target;
627
- };
628
-
629
- /**
630
- * Fake a hammer.js gesture. Event can be a ScrollEvent or MouseMoveEvent
631
- * @param {Element} element
632
- * @param {Event} event
633
- */
634
- util.fakeGesture = function(element, event) {
635
- var eventType = null;
636
-
637
- // for hammer.js 1.0.5
638
- //var gesture = Hammer.event.collectEventData(this, eventType, event);
639
-
640
- // for hammer.js 1.0.6
641
- var touches = Hammer.event.getTouchList(event, eventType);
642
- var gesture = Hammer.event.collectEventData(this, eventType, touches, event);
643
-
644
- // on IE in standards mode, no touches are recognized by hammer.js,
645
- // resulting in NaN values for center.pageX and center.pageY
646
- if (isNaN(gesture.center.pageX)) {
647
- gesture.center.pageX = event.pageX;
648
- }
649
- if (isNaN(gesture.center.pageY)) {
650
- gesture.center.pageY = event.pageY;
651
- }
652
-
653
- return gesture;
654
- };
655
-
656
- util.option = {};
657
-
658
- /**
659
- * Convert a value into a boolean
660
- * @param {Boolean | function | undefined} value
661
- * @param {Boolean} [defaultValue]
662
- * @returns {Boolean} bool
663
- */
664
- util.option.asBoolean = function (value, defaultValue) {
665
- if (typeof value == 'function') {
666
- value = value();
667
- }
668
-
669
- if (value != null) {
670
- return (value != false);
671
- }
672
-
673
- return defaultValue || null;
674
- };
675
-
676
- /**
677
- * Convert a value into a number
678
- * @param {Boolean | function | undefined} value
679
- * @param {Number} [defaultValue]
680
- * @returns {Number} number
681
- */
682
- util.option.asNumber = function (value, defaultValue) {
683
- if (typeof value == 'function') {
684
- value = value();
685
- }
686
-
687
- if (value != null) {
688
- return Number(value) || defaultValue || null;
689
- }
690
-
691
- return defaultValue || null;
692
- };
693
-
694
- /**
695
- * Convert a value into a string
696
- * @param {String | function | undefined} value
697
- * @param {String} [defaultValue]
698
- * @returns {String} str
699
- */
700
- util.option.asString = function (value, defaultValue) {
701
- if (typeof value == 'function') {
702
- value = value();
703
- }
704
-
705
- if (value != null) {
706
- return String(value);
707
- }
708
-
709
- return defaultValue || null;
710
- };
711
-
712
- /**
713
- * Convert a size or location into a string with pixels or a percentage
714
- * @param {String | Number | function | undefined} value
715
- * @param {String} [defaultValue]
716
- * @returns {String} size
717
- */
718
- util.option.asSize = function (value, defaultValue) {
719
- if (typeof value == 'function') {
720
- value = value();
721
- }
722
-
723
- if (util.isString(value)) {
724
- return value;
725
- }
726
- else if (util.isNumber(value)) {
727
- return value + 'px';
728
- }
729
- else {
730
- return defaultValue || null;
731
- }
732
- };
733
-
734
- /**
735
- * Convert a value into a DOM element
736
- * @param {HTMLElement | function | undefined} value
737
- * @param {HTMLElement} [defaultValue]
738
- * @returns {HTMLElement | null} dom
739
- */
740
- util.option.asElement = function (value, defaultValue) {
741
- if (typeof value == 'function') {
742
- value = value();
743
- }
744
-
745
- return value || defaultValue || null;
746
- };
747
-
748
-
749
-
750
- util.GiveDec = function(Hex) {
751
- var Value;
752
-
753
- if (Hex == "A")
754
- Value = 10;
755
- else if (Hex == "B")
756
- Value = 11;
757
- else if (Hex == "C")
758
- Value = 12;
759
- else if (Hex == "D")
760
- Value = 13;
761
- else if (Hex == "E")
762
- Value = 14;
763
- else if (Hex == "F")
764
- Value = 15;
765
- else
766
- Value = eval(Hex);
767
-
768
- return Value;
769
- };
770
-
771
- util.GiveHex = function(Dec) {
772
- var Value;
773
-
774
- if(Dec == 10)
775
- Value = "A";
776
- else if (Dec == 11)
777
- Value = "B";
778
- else if (Dec == 12)
779
- Value = "C";
780
- else if (Dec == 13)
781
- Value = "D";
782
- else if (Dec == 14)
783
- Value = "E";
784
- else if (Dec == 15)
785
- Value = "F";
786
- else
787
- Value = "" + Dec;
788
-
789
- return Value;
790
- };
791
-
792
- /**
793
- * Parse a color property into an object with border, background, and
794
- * highlight colors
795
- * @param {Object | String} color
796
- * @return {Object} colorObject
797
- */
798
- util.parseColor = function(color) {
799
- var c;
800
- if (util.isString(color)) {
801
- if (util.isValidHex(color)) {
802
- var hsv = util.hexToHSV(color);
803
- var lighterColorHSV = {h:hsv.h,s:hsv.s * 0.45,v:Math.min(1,hsv.v * 1.05)};
804
- var darkerColorHSV = {h:hsv.h,s:Math.min(1,hsv.v * 1.25),v:hsv.v*0.6};
805
- var darkerColorHex = util.HSVToHex(darkerColorHSV.h ,darkerColorHSV.h ,darkerColorHSV.v);
806
- var lighterColorHex = util.HSVToHex(lighterColorHSV.h,lighterColorHSV.s,lighterColorHSV.v);
807
-
808
- c = {
809
- background: color,
810
- border:darkerColorHex,
811
- highlight: {
812
- background:lighterColorHex,
813
- border:darkerColorHex
814
- },
815
- hover: {
816
- background:lighterColorHex,
817
- border:darkerColorHex
818
- }
819
- };
820
- }
821
- else {
822
- c = {
823
- background:color,
824
- border:color,
825
- highlight: {
826
- background:color,
827
- border:color
828
- },
829
- hover: {
830
- background:color,
831
- border:color
832
- }
833
- };
834
- }
835
- }
836
- else {
837
- c = {};
838
- c.background = color.background || 'white';
839
- c.border = color.border || c.background;
840
-
841
- if (util.isString(color.highlight)) {
842
- c.highlight = {
843
- border: color.highlight,
844
- background: color.highlight
845
- }
846
- }
847
- else {
848
- c.highlight = {};
849
- c.highlight.background = color.highlight && color.highlight.background || c.background;
850
- c.highlight.border = color.highlight && color.highlight.border || c.border;
851
- }
852
-
853
- if (util.isString(color.hover)) {
854
- c.hover = {
855
- border: color.hover,
856
- background: color.hover
857
- }
858
- }
859
- else {
860
- c.hover = {};
861
- c.hover.background = color.hover && color.hover.background || c.background;
862
- c.hover.border = color.hover && color.hover.border || c.border;
863
- }
864
- }
865
-
866
- return c;
867
- };
868
-
869
- /**
870
- * http://www.yellowpipe.com/yis/tools/hex-to-rgb/color-converter.php
871
- *
872
- * @param {String} hex
873
- * @returns {{r: *, g: *, b: *}}
874
- */
875
- util.hexToRGB = function(hex) {
876
- hex = hex.replace("#","").toUpperCase();
877
-
878
- var a = util.GiveDec(hex.substring(0, 1));
879
- var b = util.GiveDec(hex.substring(1, 2));
880
- var c = util.GiveDec(hex.substring(2, 3));
881
- var d = util.GiveDec(hex.substring(3, 4));
882
- var e = util.GiveDec(hex.substring(4, 5));
883
- var f = util.GiveDec(hex.substring(5, 6));
884
-
885
- var r = (a * 16) + b;
886
- var g = (c * 16) + d;
887
- var b = (e * 16) + f;
888
-
889
- return {r:r,g:g,b:b};
890
- };
891
-
892
- util.RGBToHex = function(red,green,blue) {
893
- var a = util.GiveHex(Math.floor(red / 16));
894
- var b = util.GiveHex(red % 16);
895
- var c = util.GiveHex(Math.floor(green / 16));
896
- var d = util.GiveHex(green % 16);
897
- var e = util.GiveHex(Math.floor(blue / 16));
898
- var f = util.GiveHex(blue % 16);
899
-
900
- var hex = a + b + c + d + e + f;
901
- return "#" + hex;
902
- };
903
-
904
-
905
- /**
906
- * http://www.javascripter.net/faq/rgb2hsv.htm
907
- *
908
- * @param red
909
- * @param green
910
- * @param blue
911
- * @returns {*}
912
- * @constructor
913
- */
914
- util.RGBToHSV = function(red,green,blue) {
915
- red=red/255; green=green/255; blue=blue/255;
916
- var minRGB = Math.min(red,Math.min(green,blue));
917
- var maxRGB = Math.max(red,Math.max(green,blue));
918
-
919
- // Black-gray-white
920
- if (minRGB == maxRGB) {
921
- return {h:0,s:0,v:minRGB};
922
- }
923
-
924
- // Colors other than black-gray-white:
925
- var d = (red==minRGB) ? green-blue : ((blue==minRGB) ? red-green : blue-red);
926
- var h = (red==minRGB) ? 3 : ((blue==minRGB) ? 1 : 5);
927
- var hue = 60*(h - d/(maxRGB - minRGB))/360;
928
- var saturation = (maxRGB - minRGB)/maxRGB;
929
- var value = maxRGB;
930
- return {h:hue,s:saturation,v:value};
931
- };
932
-
933
-
934
- /**
935
- * https://gist.github.com/mjijackson/5311256
936
- * @param hue
937
- * @param saturation
938
- * @param value
939
- * @returns {{r: number, g: number, b: number}}
940
- * @constructor
941
- */
942
- util.HSVToRGB = function(h, s, v) {
943
- var r, g, b;
944
-
945
- var i = Math.floor(h * 6);
946
- var f = h * 6 - i;
947
- var p = v * (1 - s);
948
- var q = v * (1 - f * s);
949
- var t = v * (1 - (1 - f) * s);
950
-
951
- switch (i % 6) {
952
- case 0: r = v, g = t, b = p; break;
953
- case 1: r = q, g = v, b = p; break;
954
- case 2: r = p, g = v, b = t; break;
955
- case 3: r = p, g = q, b = v; break;
956
- case 4: r = t, g = p, b = v; break;
957
- case 5: r = v, g = p, b = q; break;
958
- }
959
-
960
- return {r:Math.floor(r * 255), g:Math.floor(g * 255), b:Math.floor(b * 255) };
961
- };
962
-
963
- util.HSVToHex = function(h, s, v) {
964
- var rgb = util.HSVToRGB(h, s, v);
965
- return util.RGBToHex(rgb.r, rgb.g, rgb.b);
966
- };
967
-
968
- util.hexToHSV = function(hex) {
969
- var rgb = util.hexToRGB(hex);
970
- return util.RGBToHSV(rgb.r, rgb.g, rgb.b);
971
- };
972
-
973
- util.isValidHex = function(hex) {
974
- var isOk = /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(hex);
975
- return isOk;
976
- };
977
-
978
- util.copyObject = function(objectFrom, objectTo) {
979
- for (var i in objectFrom) {
980
- if (objectFrom.hasOwnProperty(i)) {
981
- if (typeof objectFrom[i] == "object") {
982
- objectTo[i] = {};
983
- util.copyObject(objectFrom[i], objectTo[i]);
984
- }
985
- else {
986
- objectTo[i] = objectFrom[i];
987
- }
988
- }
989
- }
990
- };