vis-rails 0.0.1
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.
- 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
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,225 @@
|
|
1
|
+
/**
|
2
|
+
* Canvas shapes used by the Graph
|
3
|
+
*/
|
4
|
+
if (typeof CanvasRenderingContext2D !== 'undefined') {
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Draw a circle shape
|
8
|
+
*/
|
9
|
+
CanvasRenderingContext2D.prototype.circle = function(x, y, r) {
|
10
|
+
this.beginPath();
|
11
|
+
this.arc(x, y, r, 0, 2*Math.PI, false);
|
12
|
+
};
|
13
|
+
|
14
|
+
/**
|
15
|
+
* Draw a square shape
|
16
|
+
* @param {Number} x horizontal center
|
17
|
+
* @param {Number} y vertical center
|
18
|
+
* @param {Number} r size, width and height of the square
|
19
|
+
*/
|
20
|
+
CanvasRenderingContext2D.prototype.square = function(x, y, r) {
|
21
|
+
this.beginPath();
|
22
|
+
this.rect(x - r, y - r, r * 2, r * 2);
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Draw a triangle shape
|
27
|
+
* @param {Number} x horizontal center
|
28
|
+
* @param {Number} y vertical center
|
29
|
+
* @param {Number} r radius, half the length of the sides of the triangle
|
30
|
+
*/
|
31
|
+
CanvasRenderingContext2D.prototype.triangle = function(x, y, r) {
|
32
|
+
// http://en.wikipedia.org/wiki/Equilateral_triangle
|
33
|
+
this.beginPath();
|
34
|
+
|
35
|
+
var s = r * 2;
|
36
|
+
var s2 = s / 2;
|
37
|
+
var ir = Math.sqrt(3) / 6 * s; // radius of inner circle
|
38
|
+
var h = Math.sqrt(s * s - s2 * s2); // height
|
39
|
+
|
40
|
+
this.moveTo(x, y - (h - ir));
|
41
|
+
this.lineTo(x + s2, y + ir);
|
42
|
+
this.lineTo(x - s2, y + ir);
|
43
|
+
this.lineTo(x, y - (h - ir));
|
44
|
+
this.closePath();
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Draw a triangle shape in downward orientation
|
49
|
+
* @param {Number} x horizontal center
|
50
|
+
* @param {Number} y vertical center
|
51
|
+
* @param {Number} r radius
|
52
|
+
*/
|
53
|
+
CanvasRenderingContext2D.prototype.triangleDown = function(x, y, r) {
|
54
|
+
// http://en.wikipedia.org/wiki/Equilateral_triangle
|
55
|
+
this.beginPath();
|
56
|
+
|
57
|
+
var s = r * 2;
|
58
|
+
var s2 = s / 2;
|
59
|
+
var ir = Math.sqrt(3) / 6 * s; // radius of inner circle
|
60
|
+
var h = Math.sqrt(s * s - s2 * s2); // height
|
61
|
+
|
62
|
+
this.moveTo(x, y + (h - ir));
|
63
|
+
this.lineTo(x + s2, y - ir);
|
64
|
+
this.lineTo(x - s2, y - ir);
|
65
|
+
this.lineTo(x, y + (h - ir));
|
66
|
+
this.closePath();
|
67
|
+
};
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Draw a star shape, a star with 5 points
|
71
|
+
* @param {Number} x horizontal center
|
72
|
+
* @param {Number} y vertical center
|
73
|
+
* @param {Number} r radius, half the length of the sides of the triangle
|
74
|
+
*/
|
75
|
+
CanvasRenderingContext2D.prototype.star = function(x, y, r) {
|
76
|
+
// http://www.html5canvastutorials.com/labs/html5-canvas-star-spinner/
|
77
|
+
this.beginPath();
|
78
|
+
|
79
|
+
for (var n = 0; n < 10; n++) {
|
80
|
+
var radius = (n % 2 === 0) ? r * 1.3 : r * 0.5;
|
81
|
+
this.lineTo(
|
82
|
+
x + radius * Math.sin(n * 2 * Math.PI / 10),
|
83
|
+
y - radius * Math.cos(n * 2 * Math.PI / 10)
|
84
|
+
);
|
85
|
+
}
|
86
|
+
|
87
|
+
this.closePath();
|
88
|
+
};
|
89
|
+
|
90
|
+
/**
|
91
|
+
* http://stackoverflow.com/questions/1255512/how-to-draw-a-rounded-rectangle-on-html-canvas
|
92
|
+
*/
|
93
|
+
CanvasRenderingContext2D.prototype.roundRect = function(x, y, w, h, r) {
|
94
|
+
var r2d = Math.PI/180;
|
95
|
+
if( w - ( 2 * r ) < 0 ) { r = ( w / 2 ); } //ensure that the radius isn't too large for x
|
96
|
+
if( h - ( 2 * r ) < 0 ) { r = ( h / 2 ); } //ensure that the radius isn't too large for y
|
97
|
+
this.beginPath();
|
98
|
+
this.moveTo(x+r,y);
|
99
|
+
this.lineTo(x+w-r,y);
|
100
|
+
this.arc(x+w-r,y+r,r,r2d*270,r2d*360,false);
|
101
|
+
this.lineTo(x+w,y+h-r);
|
102
|
+
this.arc(x+w-r,y+h-r,r,0,r2d*90,false);
|
103
|
+
this.lineTo(x+r,y+h);
|
104
|
+
this.arc(x+r,y+h-r,r,r2d*90,r2d*180,false);
|
105
|
+
this.lineTo(x,y+r);
|
106
|
+
this.arc(x+r,y+r,r,r2d*180,r2d*270,false);
|
107
|
+
};
|
108
|
+
|
109
|
+
/**
|
110
|
+
* http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
|
111
|
+
*/
|
112
|
+
CanvasRenderingContext2D.prototype.ellipse = function(x, y, w, h) {
|
113
|
+
var kappa = .5522848,
|
114
|
+
ox = (w / 2) * kappa, // control point offset horizontal
|
115
|
+
oy = (h / 2) * kappa, // control point offset vertical
|
116
|
+
xe = x + w, // x-end
|
117
|
+
ye = y + h, // y-end
|
118
|
+
xm = x + w / 2, // x-middle
|
119
|
+
ym = y + h / 2; // y-middle
|
120
|
+
|
121
|
+
this.beginPath();
|
122
|
+
this.moveTo(x, ym);
|
123
|
+
this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
|
124
|
+
this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
|
125
|
+
this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
|
126
|
+
this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
|
127
|
+
};
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
/**
|
132
|
+
* http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
|
133
|
+
*/
|
134
|
+
CanvasRenderingContext2D.prototype.database = function(x, y, w, h) {
|
135
|
+
var f = 1/3;
|
136
|
+
var wEllipse = w;
|
137
|
+
var hEllipse = h * f;
|
138
|
+
|
139
|
+
var kappa = .5522848,
|
140
|
+
ox = (wEllipse / 2) * kappa, // control point offset horizontal
|
141
|
+
oy = (hEllipse / 2) * kappa, // control point offset vertical
|
142
|
+
xe = x + wEllipse, // x-end
|
143
|
+
ye = y + hEllipse, // y-end
|
144
|
+
xm = x + wEllipse / 2, // x-middle
|
145
|
+
ym = y + hEllipse / 2, // y-middle
|
146
|
+
ymb = y + (h - hEllipse/2), // y-midlle, bottom ellipse
|
147
|
+
yeb = y + h; // y-end, bottom ellipse
|
148
|
+
|
149
|
+
this.beginPath();
|
150
|
+
this.moveTo(xe, ym);
|
151
|
+
|
152
|
+
this.bezierCurveTo(xe, ym + oy, xm + ox, ye, xm, ye);
|
153
|
+
this.bezierCurveTo(xm - ox, ye, x, ym + oy, x, ym);
|
154
|
+
|
155
|
+
this.bezierCurveTo(x, ym - oy, xm - ox, y, xm, y);
|
156
|
+
this.bezierCurveTo(xm + ox, y, xe, ym - oy, xe, ym);
|
157
|
+
|
158
|
+
this.lineTo(xe, ymb);
|
159
|
+
|
160
|
+
this.bezierCurveTo(xe, ymb + oy, xm + ox, yeb, xm, yeb);
|
161
|
+
this.bezierCurveTo(xm - ox, yeb, x, ymb + oy, x, ymb);
|
162
|
+
|
163
|
+
this.lineTo(x, ym);
|
164
|
+
};
|
165
|
+
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Draw an arrow point (no line)
|
169
|
+
*/
|
170
|
+
CanvasRenderingContext2D.prototype.arrow = function(x, y, angle, length) {
|
171
|
+
// tail
|
172
|
+
var xt = x - length * Math.cos(angle);
|
173
|
+
var yt = y - length * Math.sin(angle);
|
174
|
+
|
175
|
+
// inner tail
|
176
|
+
// TODO: allow to customize different shapes
|
177
|
+
var xi = x - length * 0.9 * Math.cos(angle);
|
178
|
+
var yi = y - length * 0.9 * Math.sin(angle);
|
179
|
+
|
180
|
+
// left
|
181
|
+
var xl = xt + length / 3 * Math.cos(angle + 0.5 * Math.PI);
|
182
|
+
var yl = yt + length / 3 * Math.sin(angle + 0.5 * Math.PI);
|
183
|
+
|
184
|
+
// right
|
185
|
+
var xr = xt + length / 3 * Math.cos(angle - 0.5 * Math.PI);
|
186
|
+
var yr = yt + length / 3 * Math.sin(angle - 0.5 * Math.PI);
|
187
|
+
|
188
|
+
this.beginPath();
|
189
|
+
this.moveTo(x, y);
|
190
|
+
this.lineTo(xl, yl);
|
191
|
+
this.lineTo(xi, yi);
|
192
|
+
this.lineTo(xr, yr);
|
193
|
+
this.closePath();
|
194
|
+
};
|
195
|
+
|
196
|
+
/**
|
197
|
+
* Sets up the dashedLine functionality for drawing
|
198
|
+
* Original code came from http://stackoverflow.com/questions/4576724/dotted-stroke-in-canvas
|
199
|
+
* @author David Jordan
|
200
|
+
* @date 2012-08-08
|
201
|
+
*/
|
202
|
+
CanvasRenderingContext2D.prototype.dashedLine = function(x,y,x2,y2,dashArray){
|
203
|
+
if (!dashArray) dashArray=[10,5];
|
204
|
+
if (dashLength==0) dashLength = 0.001; // Hack for Safari
|
205
|
+
var dashCount = dashArray.length;
|
206
|
+
this.moveTo(x, y);
|
207
|
+
var dx = (x2-x), dy = (y2-y);
|
208
|
+
var slope = dy/dx;
|
209
|
+
var distRemaining = Math.sqrt( dx*dx + dy*dy );
|
210
|
+
var dashIndex=0, draw=true;
|
211
|
+
while (distRemaining>=0.1){
|
212
|
+
var dashLength = dashArray[dashIndex++%dashCount];
|
213
|
+
if (dashLength > distRemaining) dashLength = distRemaining;
|
214
|
+
var xStep = Math.sqrt( dashLength*dashLength / (1 + slope*slope) );
|
215
|
+
if (dx<0) xStep = -xStep;
|
216
|
+
x += xStep;
|
217
|
+
y += slope*xStep;
|
218
|
+
this[draw ? 'lineTo' : 'moveTo'](x,y);
|
219
|
+
distRemaining -= dashLength;
|
220
|
+
draw = !draw;
|
221
|
+
}
|
222
|
+
};
|
223
|
+
|
224
|
+
// TODO: add diamond shape
|
225
|
+
}
|
@@ -0,0 +1,68 @@
|
|
1
|
+
/**
|
2
|
+
* vis.js module exports
|
3
|
+
*/
|
4
|
+
var vis = {
|
5
|
+
util: util,
|
6
|
+
events: events,
|
7
|
+
|
8
|
+
Controller: Controller,
|
9
|
+
DataSet: DataSet,
|
10
|
+
DataView: DataView,
|
11
|
+
Range: Range,
|
12
|
+
Stack: Stack,
|
13
|
+
TimeStep: TimeStep,
|
14
|
+
EventBus: EventBus,
|
15
|
+
|
16
|
+
components: {
|
17
|
+
items: {
|
18
|
+
Item: Item,
|
19
|
+
ItemBox: ItemBox,
|
20
|
+
ItemPoint: ItemPoint,
|
21
|
+
ItemRange: ItemRange
|
22
|
+
},
|
23
|
+
|
24
|
+
Component: Component,
|
25
|
+
Panel: Panel,
|
26
|
+
RootPanel: RootPanel,
|
27
|
+
ItemSet: ItemSet,
|
28
|
+
TimeAxis: TimeAxis
|
29
|
+
},
|
30
|
+
|
31
|
+
graph: {
|
32
|
+
Node: Node,
|
33
|
+
Edge: Edge,
|
34
|
+
Popup: Popup,
|
35
|
+
Groups: Groups,
|
36
|
+
Images: Images
|
37
|
+
},
|
38
|
+
|
39
|
+
Timeline: Timeline,
|
40
|
+
Graph: Graph
|
41
|
+
};
|
42
|
+
|
43
|
+
/**
|
44
|
+
* CommonJS module exports
|
45
|
+
*/
|
46
|
+
if (typeof exports !== 'undefined') {
|
47
|
+
exports = vis;
|
48
|
+
}
|
49
|
+
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') {
|
50
|
+
module.exports = vis;
|
51
|
+
}
|
52
|
+
|
53
|
+
/**
|
54
|
+
* AMD module exports
|
55
|
+
*/
|
56
|
+
if (typeof(define) === 'function') {
|
57
|
+
define(function () {
|
58
|
+
return vis;
|
59
|
+
});
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Window exports
|
64
|
+
*/
|
65
|
+
if (typeof window !== 'undefined') {
|
66
|
+
// attach the module to the window, load as a regular javascript file
|
67
|
+
window['vis'] = vis;
|
68
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* vis.js
|
3
|
+
* https://github.com/almende/vis
|
4
|
+
*
|
5
|
+
* A dynamic, browser-based visualization library.
|
6
|
+
*
|
7
|
+
* @version @@version
|
8
|
+
* @date @@date
|
9
|
+
*
|
10
|
+
* @license
|
11
|
+
* Copyright (C) 2011-2014 Almende B.V, http://almende.com
|
12
|
+
*
|
13
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
14
|
+
* use this file except in compliance with the License. You may obtain a copy
|
15
|
+
* of the License at
|
16
|
+
*
|
17
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
18
|
+
*
|
19
|
+
* Unless required by applicable law or agreed to in writing, software
|
20
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
21
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
22
|
+
* License for the specific language governing permissions and limitations under
|
23
|
+
* the License.
|
24
|
+
*/
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/**
|
2
|
+
* vis.js module imports
|
3
|
+
*/
|
4
|
+
|
5
|
+
// Try to load dependencies from the global window object.
|
6
|
+
// If not available there, load via require.
|
7
|
+
|
8
|
+
var moment = (typeof window !== 'undefined') && window['moment'] || require('moment');
|
9
|
+
|
10
|
+
var Hammer;
|
11
|
+
if (typeof window !== 'undefined') {
|
12
|
+
// load hammer.js only when running in a browser (where window is available)
|
13
|
+
Hammer = window['Hammer'] || require('hammerjs');
|
14
|
+
}
|
15
|
+
else {
|
16
|
+
Hammer = function () {
|
17
|
+
throw Error('hammer.js is only available in a browser, not in node.js.');
|
18
|
+
}
|
19
|
+
}
|
20
|
+
|
21
|
+
var mousetrap;
|
22
|
+
if (typeof window !== 'undefined') {
|
23
|
+
// load mousetrap.js only when running in a browser (where window is available)
|
24
|
+
mousetrap = window['mousetrap'] || require('mousetrap');
|
25
|
+
}
|
26
|
+
else {
|
27
|
+
mousetrap = function () {
|
28
|
+
throw Error('mouseTrap is only available in a browser, not in node.js.');
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
|
@@ -0,0 +1,252 @@
|
|
1
|
+
|
2
|
+
// Internet Explorer 8 and older does not support Array.indexOf, so we define
|
3
|
+
// it here in that case.
|
4
|
+
// http://soledadpenades.com/2007/05/17/arrayindexof-in-internet-explorer/
|
5
|
+
if(!Array.prototype.indexOf) {
|
6
|
+
Array.prototype.indexOf = function(obj){
|
7
|
+
for(var i = 0; i < this.length; i++){
|
8
|
+
if(this[i] == obj){
|
9
|
+
return i;
|
10
|
+
}
|
11
|
+
}
|
12
|
+
return -1;
|
13
|
+
};
|
14
|
+
|
15
|
+
try {
|
16
|
+
console.log("Warning: Ancient browser detected. Please update your browser");
|
17
|
+
}
|
18
|
+
catch (err) {
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
// Internet Explorer 8 and older does not support Array.forEach, so we define
|
23
|
+
// it here in that case.
|
24
|
+
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/forEach
|
25
|
+
if (!Array.prototype.forEach) {
|
26
|
+
Array.prototype.forEach = function(fn, scope) {
|
27
|
+
for(var i = 0, len = this.length; i < len; ++i) {
|
28
|
+
fn.call(scope || this, this[i], i, this);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}
|
32
|
+
|
33
|
+
// Internet Explorer 8 and older does not support Array.map, so we define it
|
34
|
+
// here in that case.
|
35
|
+
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map
|
36
|
+
// Production steps of ECMA-262, Edition 5, 15.4.4.19
|
37
|
+
// Reference: http://es5.github.com/#x15.4.4.19
|
38
|
+
if (!Array.prototype.map) {
|
39
|
+
Array.prototype.map = function(callback, thisArg) {
|
40
|
+
|
41
|
+
var T, A, k;
|
42
|
+
|
43
|
+
if (this == null) {
|
44
|
+
throw new TypeError(" this is null or not defined");
|
45
|
+
}
|
46
|
+
|
47
|
+
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
|
48
|
+
var O = Object(this);
|
49
|
+
|
50
|
+
// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
|
51
|
+
// 3. Let len be ToUint32(lenValue).
|
52
|
+
var len = O.length >>> 0;
|
53
|
+
|
54
|
+
// 4. If IsCallable(callback) is false, throw a TypeError exception.
|
55
|
+
// See: http://es5.github.com/#x9.11
|
56
|
+
if (typeof callback !== "function") {
|
57
|
+
throw new TypeError(callback + " is not a function");
|
58
|
+
}
|
59
|
+
|
60
|
+
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
61
|
+
if (thisArg) {
|
62
|
+
T = thisArg;
|
63
|
+
}
|
64
|
+
|
65
|
+
// 6. Let A be a new array created as if by the expression new Array(len) where Array is
|
66
|
+
// the standard built-in constructor with that name and len is the value of len.
|
67
|
+
A = new Array(len);
|
68
|
+
|
69
|
+
// 7. Let k be 0
|
70
|
+
k = 0;
|
71
|
+
|
72
|
+
// 8. Repeat, while k < len
|
73
|
+
while(k < len) {
|
74
|
+
|
75
|
+
var kValue, mappedValue;
|
76
|
+
|
77
|
+
// a. Let Pk be ToString(k).
|
78
|
+
// This is implicit for LHS operands of the in operator
|
79
|
+
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
|
80
|
+
// This step can be combined with c
|
81
|
+
// c. If kPresent is true, then
|
82
|
+
if (k in O) {
|
83
|
+
|
84
|
+
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
|
85
|
+
kValue = O[ k ];
|
86
|
+
|
87
|
+
// ii. Let mappedValue be the result of calling the Call internal method of callback
|
88
|
+
// with T as the this value and argument list containing kValue, k, and O.
|
89
|
+
mappedValue = callback.call(T, kValue, k, O);
|
90
|
+
|
91
|
+
// iii. Call the DefineOwnProperty internal method of A with arguments
|
92
|
+
// Pk, Property Descriptor {Value: mappedValue, : true, Enumerable: true, Configurable: true},
|
93
|
+
// and false.
|
94
|
+
|
95
|
+
// In browsers that support Object.defineProperty, use the following:
|
96
|
+
// Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });
|
97
|
+
|
98
|
+
// For best browser support, use the following:
|
99
|
+
A[ k ] = mappedValue;
|
100
|
+
}
|
101
|
+
// d. Increase k by 1.
|
102
|
+
k++;
|
103
|
+
}
|
104
|
+
|
105
|
+
// 9. return A
|
106
|
+
return A;
|
107
|
+
};
|
108
|
+
}
|
109
|
+
|
110
|
+
// Internet Explorer 8 and older does not support Array.filter, so we define it
|
111
|
+
// here in that case.
|
112
|
+
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/filter
|
113
|
+
if (!Array.prototype.filter) {
|
114
|
+
Array.prototype.filter = function(fun /*, thisp */) {
|
115
|
+
"use strict";
|
116
|
+
|
117
|
+
if (this == null) {
|
118
|
+
throw new TypeError();
|
119
|
+
}
|
120
|
+
|
121
|
+
var t = Object(this);
|
122
|
+
var len = t.length >>> 0;
|
123
|
+
if (typeof fun != "function") {
|
124
|
+
throw new TypeError();
|
125
|
+
}
|
126
|
+
|
127
|
+
var res = [];
|
128
|
+
var thisp = arguments[1];
|
129
|
+
for (var i = 0; i < len; i++) {
|
130
|
+
if (i in t) {
|
131
|
+
var val = t[i]; // in case fun mutates this
|
132
|
+
if (fun.call(thisp, val, i, t))
|
133
|
+
res.push(val);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
return res;
|
138
|
+
};
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
// Internet Explorer 8 and older does not support Object.keys, so we define it
|
143
|
+
// here in that case.
|
144
|
+
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys
|
145
|
+
if (!Object.keys) {
|
146
|
+
Object.keys = (function () {
|
147
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty,
|
148
|
+
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
|
149
|
+
dontEnums = [
|
150
|
+
'toString',
|
151
|
+
'toLocaleString',
|
152
|
+
'valueOf',
|
153
|
+
'hasOwnProperty',
|
154
|
+
'isPrototypeOf',
|
155
|
+
'propertyIsEnumerable',
|
156
|
+
'constructor'
|
157
|
+
],
|
158
|
+
dontEnumsLength = dontEnums.length;
|
159
|
+
|
160
|
+
return function (obj) {
|
161
|
+
if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) {
|
162
|
+
throw new TypeError('Object.keys called on non-object');
|
163
|
+
}
|
164
|
+
|
165
|
+
var result = [];
|
166
|
+
|
167
|
+
for (var prop in obj) {
|
168
|
+
if (hasOwnProperty.call(obj, prop)) result.push(prop);
|
169
|
+
}
|
170
|
+
|
171
|
+
if (hasDontEnumBug) {
|
172
|
+
for (var i=0; i < dontEnumsLength; i++) {
|
173
|
+
if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
|
174
|
+
}
|
175
|
+
}
|
176
|
+
return result;
|
177
|
+
}
|
178
|
+
})()
|
179
|
+
}
|
180
|
+
|
181
|
+
// Internet Explorer 8 and older does not support Array.isArray,
|
182
|
+
// so we define it here in that case.
|
183
|
+
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/isArray
|
184
|
+
if(!Array.isArray) {
|
185
|
+
Array.isArray = function (vArg) {
|
186
|
+
return Object.prototype.toString.call(vArg) === "[object Array]";
|
187
|
+
};
|
188
|
+
}
|
189
|
+
|
190
|
+
// Internet Explorer 8 and older does not support Function.bind,
|
191
|
+
// so we define it here in that case.
|
192
|
+
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind
|
193
|
+
if (!Function.prototype.bind) {
|
194
|
+
Function.prototype.bind = function (oThis) {
|
195
|
+
if (typeof this !== "function") {
|
196
|
+
// closest thing possible to the ECMAScript 5 internal IsCallable function
|
197
|
+
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
|
198
|
+
}
|
199
|
+
|
200
|
+
var aArgs = Array.prototype.slice.call(arguments, 1),
|
201
|
+
fToBind = this,
|
202
|
+
fNOP = function () {},
|
203
|
+
fBound = function () {
|
204
|
+
return fToBind.apply(this instanceof fNOP && oThis
|
205
|
+
? this
|
206
|
+
: oThis,
|
207
|
+
aArgs.concat(Array.prototype.slice.call(arguments)));
|
208
|
+
};
|
209
|
+
|
210
|
+
fNOP.prototype = this.prototype;
|
211
|
+
fBound.prototype = new fNOP();
|
212
|
+
|
213
|
+
return fBound;
|
214
|
+
};
|
215
|
+
}
|
216
|
+
|
217
|
+
// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create
|
218
|
+
if (!Object.create) {
|
219
|
+
Object.create = function (o) {
|
220
|
+
if (arguments.length > 1) {
|
221
|
+
throw new Error('Object.create implementation only accepts the first parameter.');
|
222
|
+
}
|
223
|
+
function F() {}
|
224
|
+
F.prototype = o;
|
225
|
+
return new F();
|
226
|
+
};
|
227
|
+
}
|
228
|
+
|
229
|
+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
|
230
|
+
if (!Function.prototype.bind) {
|
231
|
+
Function.prototype.bind = function (oThis) {
|
232
|
+
if (typeof this !== "function") {
|
233
|
+
// closest thing possible to the ECMAScript 5 internal IsCallable function
|
234
|
+
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
|
235
|
+
}
|
236
|
+
|
237
|
+
var aArgs = Array.prototype.slice.call(arguments, 1),
|
238
|
+
fToBind = this,
|
239
|
+
fNOP = function () {},
|
240
|
+
fBound = function () {
|
241
|
+
return fToBind.apply(this instanceof fNOP && oThis
|
242
|
+
? this
|
243
|
+
: oThis,
|
244
|
+
aArgs.concat(Array.prototype.slice.call(arguments)));
|
245
|
+
};
|
246
|
+
|
247
|
+
fNOP.prototype = this.prototype;
|
248
|
+
fBound.prototype = new fNOP();
|
249
|
+
|
250
|
+
return fBound;
|
251
|
+
};
|
252
|
+
}
|