vis-rails 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.gitmodules +3 -0
- data/.project +11 -0
- data/Gemfile +4 -0
- data/LICENSE +202 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/vis/rails/engine.rb +6 -0
- data/lib/vis/rails/version.rb +5 -0
- data/lib/vis/rails.rb +7 -0
- data/vendor/assets/javascripts/vis.js +1 -0
- data/vendor/assets/stylesheets/vis.css +3 -0
- data/vendor/assets/vis/DataSet.js +936 -0
- data/vendor/assets/vis/DataView.js +281 -0
- data/vendor/assets/vis/EventBus.js +89 -0
- data/vendor/assets/vis/events.js +116 -0
- data/vendor/assets/vis/graph/ClusterMixin.js +1019 -0
- data/vendor/assets/vis/graph/Edge.js +620 -0
- data/vendor/assets/vis/graph/Graph.js +2111 -0
- data/vendor/assets/vis/graph/Groups.js +80 -0
- data/vendor/assets/vis/graph/Images.js +41 -0
- data/vendor/assets/vis/graph/NavigationMixin.js +245 -0
- data/vendor/assets/vis/graph/Node.js +978 -0
- data/vendor/assets/vis/graph/Popup.js +105 -0
- data/vendor/assets/vis/graph/SectorsMixin.js +547 -0
- data/vendor/assets/vis/graph/SelectionMixin.js +515 -0
- data/vendor/assets/vis/graph/dotparser.js +829 -0
- data/vendor/assets/vis/graph/img/downarrow.png +0 -0
- data/vendor/assets/vis/graph/img/leftarrow.png +0 -0
- data/vendor/assets/vis/graph/img/minus.png +0 -0
- data/vendor/assets/vis/graph/img/plus.png +0 -0
- data/vendor/assets/vis/graph/img/rightarrow.png +0 -0
- data/vendor/assets/vis/graph/img/uparrow.png +0 -0
- data/vendor/assets/vis/graph/img/zoomExtends.png +0 -0
- data/vendor/assets/vis/graph/shapes.js +225 -0
- data/vendor/assets/vis/module/exports.js +68 -0
- data/vendor/assets/vis/module/header.js +24 -0
- data/vendor/assets/vis/module/imports.js +32 -0
- data/vendor/assets/vis/shim.js +252 -0
- data/vendor/assets/vis/timeline/Controller.js +172 -0
- data/vendor/assets/vis/timeline/Range.js +553 -0
- data/vendor/assets/vis/timeline/Stack.js +192 -0
- data/vendor/assets/vis/timeline/TimeStep.js +449 -0
- data/vendor/assets/vis/timeline/Timeline.js +476 -0
- data/vendor/assets/vis/timeline/component/Component.js +148 -0
- data/vendor/assets/vis/timeline/component/ContentPanel.js +113 -0
- data/vendor/assets/vis/timeline/component/CurrentTime.js +101 -0
- data/vendor/assets/vis/timeline/component/CustomTime.js +255 -0
- data/vendor/assets/vis/timeline/component/Group.js +129 -0
- data/vendor/assets/vis/timeline/component/GroupSet.js +546 -0
- data/vendor/assets/vis/timeline/component/ItemSet.js +612 -0
- data/vendor/assets/vis/timeline/component/Panel.js +112 -0
- data/vendor/assets/vis/timeline/component/RootPanel.js +215 -0
- data/vendor/assets/vis/timeline/component/TimeAxis.js +522 -0
- data/vendor/assets/vis/timeline/component/css/currenttime.css +5 -0
- data/vendor/assets/vis/timeline/component/css/customtime.css +6 -0
- data/vendor/assets/vis/timeline/component/css/groupset.css +59 -0
- data/vendor/assets/vis/timeline/component/css/item.css +93 -0
- data/vendor/assets/vis/timeline/component/css/itemset.css +17 -0
- data/vendor/assets/vis/timeline/component/css/panel.css +14 -0
- data/vendor/assets/vis/timeline/component/css/timeaxis.css +41 -0
- data/vendor/assets/vis/timeline/component/css/timeline.css +2 -0
- data/vendor/assets/vis/timeline/component/item/Item.js +81 -0
- data/vendor/assets/vis/timeline/component/item/ItemBox.js +302 -0
- data/vendor/assets/vis/timeline/component/item/ItemPoint.js +237 -0
- data/vendor/assets/vis/timeline/component/item/ItemRange.js +251 -0
- data/vendor/assets/vis/timeline/component/item/ItemRangeOverflow.js +91 -0
- data/vendor/assets/vis/util.js +673 -0
- data/vis-rails.gemspec +47 -0
- metadata +142 -0
@@ -0,0 +1,673 @@
|
|
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 isNumber(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 isString(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 isDate(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 isDataTable(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 randomUUID () {
|
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) && other[prop] !== undefined) {
|
92
|
+
a[prop] = other[prop];
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
|
97
|
+
return a;
|
98
|
+
};
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Convert an object to another type
|
102
|
+
* @param {Boolean | Number | String | Date | Moment | Null | undefined} object
|
103
|
+
* @param {String | undefined} type Name of the type. Available types:
|
104
|
+
* 'Boolean', 'Number', 'String',
|
105
|
+
* 'Date', 'Moment', ISODate', 'ASPDate'.
|
106
|
+
* @return {*} object
|
107
|
+
* @throws Error
|
108
|
+
*/
|
109
|
+
util.convert = function convert(object, type) {
|
110
|
+
var match;
|
111
|
+
|
112
|
+
if (object === undefined) {
|
113
|
+
return undefined;
|
114
|
+
}
|
115
|
+
if (object === null) {
|
116
|
+
return null;
|
117
|
+
}
|
118
|
+
|
119
|
+
if (!type) {
|
120
|
+
return object;
|
121
|
+
}
|
122
|
+
if (!(typeof type === 'string') && !(type instanceof String)) {
|
123
|
+
throw new Error('Type must be a string');
|
124
|
+
}
|
125
|
+
|
126
|
+
//noinspection FallthroughInSwitchStatementJS
|
127
|
+
switch (type) {
|
128
|
+
case 'boolean':
|
129
|
+
case 'Boolean':
|
130
|
+
return Boolean(object);
|
131
|
+
|
132
|
+
case 'number':
|
133
|
+
case 'Number':
|
134
|
+
return Number(object.valueOf());
|
135
|
+
|
136
|
+
case 'string':
|
137
|
+
case 'String':
|
138
|
+
return String(object);
|
139
|
+
|
140
|
+
case 'Date':
|
141
|
+
if (util.isNumber(object)) {
|
142
|
+
return new Date(object);
|
143
|
+
}
|
144
|
+
if (object instanceof Date) {
|
145
|
+
return new Date(object.valueOf());
|
146
|
+
}
|
147
|
+
else if (moment.isMoment(object)) {
|
148
|
+
return new Date(object.valueOf());
|
149
|
+
}
|
150
|
+
if (util.isString(object)) {
|
151
|
+
match = ASPDateRegex.exec(object);
|
152
|
+
if (match) {
|
153
|
+
// object is an ASP date
|
154
|
+
return new Date(Number(match[1])); // parse number
|
155
|
+
}
|
156
|
+
else {
|
157
|
+
return moment(object).toDate(); // parse string
|
158
|
+
}
|
159
|
+
}
|
160
|
+
else {
|
161
|
+
throw new Error(
|
162
|
+
'Cannot convert object of type ' + util.getType(object) +
|
163
|
+
' to type Date');
|
164
|
+
}
|
165
|
+
|
166
|
+
case 'Moment':
|
167
|
+
if (util.isNumber(object)) {
|
168
|
+
return moment(object);
|
169
|
+
}
|
170
|
+
if (object instanceof Date) {
|
171
|
+
return moment(object.valueOf());
|
172
|
+
}
|
173
|
+
else if (moment.isMoment(object)) {
|
174
|
+
return moment(object);
|
175
|
+
}
|
176
|
+
if (util.isString(object)) {
|
177
|
+
match = ASPDateRegex.exec(object);
|
178
|
+
if (match) {
|
179
|
+
// object is an ASP date
|
180
|
+
return moment(Number(match[1])); // parse number
|
181
|
+
}
|
182
|
+
else {
|
183
|
+
return moment(object); // parse string
|
184
|
+
}
|
185
|
+
}
|
186
|
+
else {
|
187
|
+
throw new Error(
|
188
|
+
'Cannot convert object of type ' + util.getType(object) +
|
189
|
+
' to type Date');
|
190
|
+
}
|
191
|
+
|
192
|
+
case 'ISODate':
|
193
|
+
if (util.isNumber(object)) {
|
194
|
+
return new Date(object);
|
195
|
+
}
|
196
|
+
else if (object instanceof Date) {
|
197
|
+
return object.toISOString();
|
198
|
+
}
|
199
|
+
else if (moment.isMoment(object)) {
|
200
|
+
return object.toDate().toISOString();
|
201
|
+
}
|
202
|
+
else if (util.isString(object)) {
|
203
|
+
match = ASPDateRegex.exec(object);
|
204
|
+
if (match) {
|
205
|
+
// object is an ASP date
|
206
|
+
return new Date(Number(match[1])).toISOString(); // parse number
|
207
|
+
}
|
208
|
+
else {
|
209
|
+
return new Date(object).toISOString(); // parse string
|
210
|
+
}
|
211
|
+
}
|
212
|
+
else {
|
213
|
+
throw new Error(
|
214
|
+
'Cannot convert object of type ' + util.getType(object) +
|
215
|
+
' to type ISODate');
|
216
|
+
}
|
217
|
+
|
218
|
+
case 'ASPDate':
|
219
|
+
if (util.isNumber(object)) {
|
220
|
+
return '/Date(' + object + ')/';
|
221
|
+
}
|
222
|
+
else if (object instanceof Date) {
|
223
|
+
return '/Date(' + object.valueOf() + ')/';
|
224
|
+
}
|
225
|
+
else if (util.isString(object)) {
|
226
|
+
match = ASPDateRegex.exec(object);
|
227
|
+
var value;
|
228
|
+
if (match) {
|
229
|
+
// object is an ASP date
|
230
|
+
value = new Date(Number(match[1])).valueOf(); // parse number
|
231
|
+
}
|
232
|
+
else {
|
233
|
+
value = new Date(object).valueOf(); // parse string
|
234
|
+
}
|
235
|
+
return '/Date(' + value + ')/';
|
236
|
+
}
|
237
|
+
else {
|
238
|
+
throw new Error(
|
239
|
+
'Cannot convert object of type ' + util.getType(object) +
|
240
|
+
' to type ASPDate');
|
241
|
+
}
|
242
|
+
|
243
|
+
default:
|
244
|
+
throw new Error('Cannot convert object of type ' + util.getType(object) +
|
245
|
+
' to type "' + type + '"');
|
246
|
+
}
|
247
|
+
};
|
248
|
+
|
249
|
+
// parse ASP.Net Date pattern,
|
250
|
+
// for example '/Date(1198908717056)/' or '/Date(1198908717056-0700)/'
|
251
|
+
// code from http://momentjs.com/
|
252
|
+
var ASPDateRegex = /^\/?Date\((\-?\d+)/i;
|
253
|
+
|
254
|
+
/**
|
255
|
+
* Get the type of an object, for example util.getType([]) returns 'Array'
|
256
|
+
* @param {*} object
|
257
|
+
* @return {String} type
|
258
|
+
*/
|
259
|
+
util.getType = function getType(object) {
|
260
|
+
var type = typeof object;
|
261
|
+
|
262
|
+
if (type == 'object') {
|
263
|
+
if (object == null) {
|
264
|
+
return 'null';
|
265
|
+
}
|
266
|
+
if (object instanceof Boolean) {
|
267
|
+
return 'Boolean';
|
268
|
+
}
|
269
|
+
if (object instanceof Number) {
|
270
|
+
return 'Number';
|
271
|
+
}
|
272
|
+
if (object instanceof String) {
|
273
|
+
return 'String';
|
274
|
+
}
|
275
|
+
if (object instanceof Array) {
|
276
|
+
return 'Array';
|
277
|
+
}
|
278
|
+
if (object instanceof Date) {
|
279
|
+
return 'Date';
|
280
|
+
}
|
281
|
+
return 'Object';
|
282
|
+
}
|
283
|
+
else if (type == 'number') {
|
284
|
+
return 'Number';
|
285
|
+
}
|
286
|
+
else if (type == 'boolean') {
|
287
|
+
return 'Boolean';
|
288
|
+
}
|
289
|
+
else if (type == 'string') {
|
290
|
+
return 'String';
|
291
|
+
}
|
292
|
+
|
293
|
+
return type;
|
294
|
+
};
|
295
|
+
|
296
|
+
/**
|
297
|
+
* Retrieve the absolute left value of a DOM element
|
298
|
+
* @param {Element} elem A dom element, for example a div
|
299
|
+
* @return {number} left The absolute left position of this element
|
300
|
+
* in the browser page.
|
301
|
+
*/
|
302
|
+
util.getAbsoluteLeft = function getAbsoluteLeft (elem) {
|
303
|
+
var doc = document.documentElement;
|
304
|
+
var body = document.body;
|
305
|
+
|
306
|
+
var left = elem.offsetLeft;
|
307
|
+
var e = elem.offsetParent;
|
308
|
+
while (e != null && e != body && e != doc) {
|
309
|
+
left += e.offsetLeft;
|
310
|
+
left -= e.scrollLeft;
|
311
|
+
e = e.offsetParent;
|
312
|
+
}
|
313
|
+
return left;
|
314
|
+
};
|
315
|
+
|
316
|
+
/**
|
317
|
+
* Retrieve the absolute top value of a DOM element
|
318
|
+
* @param {Element} elem A dom element, for example a div
|
319
|
+
* @return {number} top The absolute top position of this element
|
320
|
+
* in the browser page.
|
321
|
+
*/
|
322
|
+
util.getAbsoluteTop = function getAbsoluteTop (elem) {
|
323
|
+
var doc = document.documentElement;
|
324
|
+
var body = document.body;
|
325
|
+
|
326
|
+
var top = elem.offsetTop;
|
327
|
+
var e = elem.offsetParent;
|
328
|
+
while (e != null && e != body && e != doc) {
|
329
|
+
top += e.offsetTop;
|
330
|
+
top -= e.scrollTop;
|
331
|
+
e = e.offsetParent;
|
332
|
+
}
|
333
|
+
return top;
|
334
|
+
};
|
335
|
+
|
336
|
+
/**
|
337
|
+
* Get the absolute, vertical mouse position from an event.
|
338
|
+
* @param {Event} event
|
339
|
+
* @return {Number} pageY
|
340
|
+
*/
|
341
|
+
util.getPageY = function getPageY (event) {
|
342
|
+
if ('pageY' in event) {
|
343
|
+
return event.pageY;
|
344
|
+
}
|
345
|
+
else {
|
346
|
+
var clientY;
|
347
|
+
if (('targetTouches' in event) && event.targetTouches.length) {
|
348
|
+
clientY = event.targetTouches[0].clientY;
|
349
|
+
}
|
350
|
+
else {
|
351
|
+
clientY = event.clientY;
|
352
|
+
}
|
353
|
+
|
354
|
+
var doc = document.documentElement;
|
355
|
+
var body = document.body;
|
356
|
+
return clientY +
|
357
|
+
( doc && doc.scrollTop || body && body.scrollTop || 0 ) -
|
358
|
+
( doc && doc.clientTop || body && body.clientTop || 0 );
|
359
|
+
}
|
360
|
+
};
|
361
|
+
|
362
|
+
/**
|
363
|
+
* Get the absolute, horizontal mouse position from an event.
|
364
|
+
* @param {Event} event
|
365
|
+
* @return {Number} pageX
|
366
|
+
*/
|
367
|
+
util.getPageX = function getPageX (event) {
|
368
|
+
if ('pageY' in event) {
|
369
|
+
return event.pageX;
|
370
|
+
}
|
371
|
+
else {
|
372
|
+
var clientX;
|
373
|
+
if (('targetTouches' in event) && event.targetTouches.length) {
|
374
|
+
clientX = event.targetTouches[0].clientX;
|
375
|
+
}
|
376
|
+
else {
|
377
|
+
clientX = event.clientX;
|
378
|
+
}
|
379
|
+
|
380
|
+
var doc = document.documentElement;
|
381
|
+
var body = document.body;
|
382
|
+
return clientX +
|
383
|
+
( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
|
384
|
+
( doc && doc.clientLeft || body && body.clientLeft || 0 );
|
385
|
+
}
|
386
|
+
};
|
387
|
+
|
388
|
+
/**
|
389
|
+
* add a className to the given elements style
|
390
|
+
* @param {Element} elem
|
391
|
+
* @param {String} className
|
392
|
+
*/
|
393
|
+
util.addClassName = function addClassName(elem, className) {
|
394
|
+
var classes = elem.className.split(' ');
|
395
|
+
if (classes.indexOf(className) == -1) {
|
396
|
+
classes.push(className); // add the class to the array
|
397
|
+
elem.className = classes.join(' ');
|
398
|
+
}
|
399
|
+
};
|
400
|
+
|
401
|
+
/**
|
402
|
+
* add a className to the given elements style
|
403
|
+
* @param {Element} elem
|
404
|
+
* @param {String} className
|
405
|
+
*/
|
406
|
+
util.removeClassName = function removeClassname(elem, className) {
|
407
|
+
var classes = elem.className.split(' ');
|
408
|
+
var index = classes.indexOf(className);
|
409
|
+
if (index != -1) {
|
410
|
+
classes.splice(index, 1); // remove the class from the array
|
411
|
+
elem.className = classes.join(' ');
|
412
|
+
}
|
413
|
+
};
|
414
|
+
|
415
|
+
/**
|
416
|
+
* For each method for both arrays and objects.
|
417
|
+
* In case of an array, the built-in Array.forEach() is applied.
|
418
|
+
* In case of an Object, the method loops over all properties of the object.
|
419
|
+
* @param {Object | Array} object An Object or Array
|
420
|
+
* @param {function} callback Callback method, called for each item in
|
421
|
+
* the object or array with three parameters:
|
422
|
+
* callback(value, index, object)
|
423
|
+
*/
|
424
|
+
util.forEach = function forEach (object, callback) {
|
425
|
+
var i,
|
426
|
+
len;
|
427
|
+
if (object instanceof Array) {
|
428
|
+
// array
|
429
|
+
for (i = 0, len = object.length; i < len; i++) {
|
430
|
+
callback(object[i], i, object);
|
431
|
+
}
|
432
|
+
}
|
433
|
+
else {
|
434
|
+
// object
|
435
|
+
for (i in object) {
|
436
|
+
if (object.hasOwnProperty(i)) {
|
437
|
+
callback(object[i], i, object);
|
438
|
+
}
|
439
|
+
}
|
440
|
+
}
|
441
|
+
};
|
442
|
+
|
443
|
+
/**
|
444
|
+
* Update a property in an object
|
445
|
+
* @param {Object} object
|
446
|
+
* @param {String} key
|
447
|
+
* @param {*} value
|
448
|
+
* @return {Boolean} changed
|
449
|
+
*/
|
450
|
+
util.updateProperty = function updateProp (object, key, value) {
|
451
|
+
if (object[key] !== value) {
|
452
|
+
object[key] = value;
|
453
|
+
return true;
|
454
|
+
}
|
455
|
+
else {
|
456
|
+
return false;
|
457
|
+
}
|
458
|
+
};
|
459
|
+
|
460
|
+
/**
|
461
|
+
* Add and event listener. Works for all browsers
|
462
|
+
* @param {Element} element An html element
|
463
|
+
* @param {string} action The action, for example "click",
|
464
|
+
* without the prefix "on"
|
465
|
+
* @param {function} listener The callback function to be executed
|
466
|
+
* @param {boolean} [useCapture]
|
467
|
+
*/
|
468
|
+
util.addEventListener = function addEventListener(element, action, listener, useCapture) {
|
469
|
+
if (element.addEventListener) {
|
470
|
+
if (useCapture === undefined)
|
471
|
+
useCapture = false;
|
472
|
+
|
473
|
+
if (action === "mousewheel" && navigator.userAgent.indexOf("Firefox") >= 0) {
|
474
|
+
action = "DOMMouseScroll"; // For Firefox
|
475
|
+
}
|
476
|
+
|
477
|
+
element.addEventListener(action, listener, useCapture);
|
478
|
+
} else {
|
479
|
+
element.attachEvent("on" + action, listener); // IE browsers
|
480
|
+
}
|
481
|
+
};
|
482
|
+
|
483
|
+
/**
|
484
|
+
* Remove an event listener from an element
|
485
|
+
* @param {Element} element An html dom element
|
486
|
+
* @param {string} action The name of the event, for example "mousedown"
|
487
|
+
* @param {function} listener The listener function
|
488
|
+
* @param {boolean} [useCapture]
|
489
|
+
*/
|
490
|
+
util.removeEventListener = function removeEventListener(element, action, listener, useCapture) {
|
491
|
+
if (element.removeEventListener) {
|
492
|
+
// non-IE browsers
|
493
|
+
if (useCapture === undefined)
|
494
|
+
useCapture = false;
|
495
|
+
|
496
|
+
if (action === "mousewheel" && navigator.userAgent.indexOf("Firefox") >= 0) {
|
497
|
+
action = "DOMMouseScroll"; // For Firefox
|
498
|
+
}
|
499
|
+
|
500
|
+
element.removeEventListener(action, listener, useCapture);
|
501
|
+
} else {
|
502
|
+
// IE browsers
|
503
|
+
element.detachEvent("on" + action, listener);
|
504
|
+
}
|
505
|
+
};
|
506
|
+
|
507
|
+
|
508
|
+
/**
|
509
|
+
* Get HTML element which is the target of the event
|
510
|
+
* @param {Event} event
|
511
|
+
* @return {Element} target element
|
512
|
+
*/
|
513
|
+
util.getTarget = function getTarget(event) {
|
514
|
+
// code from http://www.quirksmode.org/js/events_properties.html
|
515
|
+
if (!event) {
|
516
|
+
event = window.event;
|
517
|
+
}
|
518
|
+
|
519
|
+
var target;
|
520
|
+
|
521
|
+
if (event.target) {
|
522
|
+
target = event.target;
|
523
|
+
}
|
524
|
+
else if (event.srcElement) {
|
525
|
+
target = event.srcElement;
|
526
|
+
}
|
527
|
+
|
528
|
+
if (target.nodeType != undefined && target.nodeType == 3) {
|
529
|
+
// defeat Safari bug
|
530
|
+
target = target.parentNode;
|
531
|
+
}
|
532
|
+
|
533
|
+
return target;
|
534
|
+
};
|
535
|
+
|
536
|
+
/**
|
537
|
+
* Stop event propagation
|
538
|
+
*/
|
539
|
+
util.stopPropagation = function stopPropagation(event) {
|
540
|
+
if (!event)
|
541
|
+
event = window.event;
|
542
|
+
|
543
|
+
if (event.stopPropagation) {
|
544
|
+
event.stopPropagation(); // non-IE browsers
|
545
|
+
}
|
546
|
+
else {
|
547
|
+
event.cancelBubble = true; // IE browsers
|
548
|
+
}
|
549
|
+
};
|
550
|
+
|
551
|
+
/**
|
552
|
+
* Fake a hammer.js gesture. Event can be a ScrollEvent or MouseMoveEvent
|
553
|
+
* @param {Element} element
|
554
|
+
* @param {Event} event
|
555
|
+
*/
|
556
|
+
util.fakeGesture = function fakeGesture (element, event) {
|
557
|
+
var eventType = null;
|
558
|
+
|
559
|
+
// for hammer.js 1.0.5
|
560
|
+
return Hammer.event.collectEventData(this, eventType, event);
|
561
|
+
|
562
|
+
// for hammer.js 1.0.6
|
563
|
+
//var touches = Hammer.event.getTouchList(event, eventType);
|
564
|
+
//return Hammer.event.collectEventData(this, eventType, touches, event);
|
565
|
+
};
|
566
|
+
|
567
|
+
/**
|
568
|
+
* Cancels the event if it is cancelable, without stopping further propagation of the event.
|
569
|
+
*/
|
570
|
+
util.preventDefault = function preventDefault (event) {
|
571
|
+
if (!event)
|
572
|
+
event = window.event;
|
573
|
+
|
574
|
+
if (event.preventDefault) {
|
575
|
+
event.preventDefault(); // non-IE browsers
|
576
|
+
}
|
577
|
+
else {
|
578
|
+
event.returnValue = false; // IE browsers
|
579
|
+
}
|
580
|
+
};
|
581
|
+
|
582
|
+
|
583
|
+
util.option = {};
|
584
|
+
|
585
|
+
/**
|
586
|
+
* Convert a value into a boolean
|
587
|
+
* @param {Boolean | function | undefined} value
|
588
|
+
* @param {Boolean} [defaultValue]
|
589
|
+
* @returns {Boolean} bool
|
590
|
+
*/
|
591
|
+
util.option.asBoolean = function (value, defaultValue) {
|
592
|
+
if (typeof value == 'function') {
|
593
|
+
value = value();
|
594
|
+
}
|
595
|
+
|
596
|
+
if (value != null) {
|
597
|
+
return (value != false);
|
598
|
+
}
|
599
|
+
|
600
|
+
return defaultValue || null;
|
601
|
+
};
|
602
|
+
|
603
|
+
/**
|
604
|
+
* Convert a value into a number
|
605
|
+
* @param {Boolean | function | undefined} value
|
606
|
+
* @param {Number} [defaultValue]
|
607
|
+
* @returns {Number} number
|
608
|
+
*/
|
609
|
+
util.option.asNumber = function (value, defaultValue) {
|
610
|
+
if (typeof value == 'function') {
|
611
|
+
value = value();
|
612
|
+
}
|
613
|
+
|
614
|
+
if (value != null) {
|
615
|
+
return Number(value) || defaultValue || null;
|
616
|
+
}
|
617
|
+
|
618
|
+
return defaultValue || null;
|
619
|
+
};
|
620
|
+
|
621
|
+
/**
|
622
|
+
* Convert a value into a string
|
623
|
+
* @param {String | function | undefined} value
|
624
|
+
* @param {String} [defaultValue]
|
625
|
+
* @returns {String} str
|
626
|
+
*/
|
627
|
+
util.option.asString = function (value, defaultValue) {
|
628
|
+
if (typeof value == 'function') {
|
629
|
+
value = value();
|
630
|
+
}
|
631
|
+
|
632
|
+
if (value != null) {
|
633
|
+
return String(value);
|
634
|
+
}
|
635
|
+
|
636
|
+
return defaultValue || null;
|
637
|
+
};
|
638
|
+
|
639
|
+
/**
|
640
|
+
* Convert a size or location into a string with pixels or a percentage
|
641
|
+
* @param {String | Number | function | undefined} value
|
642
|
+
* @param {String} [defaultValue]
|
643
|
+
* @returns {String} size
|
644
|
+
*/
|
645
|
+
util.option.asSize = function (value, defaultValue) {
|
646
|
+
if (typeof value == 'function') {
|
647
|
+
value = value();
|
648
|
+
}
|
649
|
+
|
650
|
+
if (util.isString(value)) {
|
651
|
+
return value;
|
652
|
+
}
|
653
|
+
else if (util.isNumber(value)) {
|
654
|
+
return value + 'px';
|
655
|
+
}
|
656
|
+
else {
|
657
|
+
return defaultValue || null;
|
658
|
+
}
|
659
|
+
};
|
660
|
+
|
661
|
+
/**
|
662
|
+
* Convert a value into a DOM element
|
663
|
+
* @param {HTMLElement | function | undefined} value
|
664
|
+
* @param {HTMLElement} [defaultValue]
|
665
|
+
* @returns {HTMLElement | null} dom
|
666
|
+
*/
|
667
|
+
util.option.asElement = function (value, defaultValue) {
|
668
|
+
if (typeof value == 'function') {
|
669
|
+
value = value();
|
670
|
+
}
|
671
|
+
|
672
|
+
return value || defaultValue || null;
|
673
|
+
};
|
data/vis-rails.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'vis/rails/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "vis-rails"
|
8
|
+
spec.version = Vis::Rails::VERSION
|
9
|
+
spec.authors = ["AlexVangelov"]
|
10
|
+
spec.email = ["email@data.bg"]
|
11
|
+
spec.description = %q{This gem provides Rails driver for http://visjs.org browser-based visualization library}
|
12
|
+
spec.summary = %q{Using http://visjs.org visualization library with Rails}
|
13
|
+
spec.homepage = "https://github.com/AlexVangelov/vis-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
# get an array of submodule dirs by executing 'pwd' inside each submodule
|
25
|
+
`git submodule --quiet foreach pwd`.split($\).each do |submodule_path|
|
26
|
+
# for each submodule, change working directory to that submodule
|
27
|
+
Dir.chdir(submodule_path) do
|
28
|
+
|
29
|
+
# issue git ls-files in submodule's directory
|
30
|
+
submodule_files = `git ls-files`.split($\)
|
31
|
+
|
32
|
+
# prepend the submodule path to create absolute file paths
|
33
|
+
submodule_files_fullpaths = submodule_files.map do |filename|
|
34
|
+
"#{submodule_path}/#{filename}"
|
35
|
+
end
|
36
|
+
|
37
|
+
# remove leading path parts to get paths relative to the gem's root dir
|
38
|
+
# (this assumes, that the gemspec resides in the gem's root dir)
|
39
|
+
submodule_files_paths = submodule_files_fullpaths.map do |filename|
|
40
|
+
filename.gsub "#{File.dirname(__FILE__)}/", ""
|
41
|
+
end
|
42
|
+
|
43
|
+
# add relative paths to gem.files
|
44
|
+
spec.files += submodule_files_paths
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|