leaflet-ruby 0.3.beta1
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.
- data/CHANGELOG.rdoc +5 -0
- data/LICENSE +21 -0
- data/README.rdoc +55 -0
- data/Rakefile +15 -0
- data/leaflet-ruby.gemspec +24 -0
- data/lib/leaflet-ruby.rb +18 -0
- data/lib/leaflet/CHANGELOG.md +181 -0
- data/lib/leaflet/Jakefile.js +65 -0
- data/lib/leaflet/LICENSE +22 -0
- data/lib/leaflet/README.md +32 -0
- data/lib/leaflet/build/build.html +243 -0
- data/lib/leaflet/build/build.js +79 -0
- data/lib/leaflet/build/deps.js +231 -0
- data/lib/leaflet/build/hint.js +30 -0
- data/lib/leaflet/build/hintrc.js +44 -0
- data/lib/leaflet/debug/control/control-layers.html +47 -0
- data/lib/leaflet/debug/control/map-control.html +29 -0
- data/lib/leaflet/debug/css/mobile.css +6 -0
- data/lib/leaflet/debug/css/screen.css +5 -0
- data/lib/leaflet/debug/geojson/geojson-sample.js +53 -0
- data/lib/leaflet/debug/geojson/geojson.html +56 -0
- data/lib/leaflet/debug/leaflet-include.js +120 -0
- data/lib/leaflet/debug/map/canvas.html +46 -0
- data/lib/leaflet/debug/map/map-mobile.html +42 -0
- data/lib/leaflet/debug/map/map.html +54 -0
- data/lib/leaflet/debug/map/max-bounds.html +36 -0
- data/lib/leaflet/debug/map/scroll.html +35 -0
- data/lib/leaflet/debug/map/wms-marble.html +30 -0
- data/lib/leaflet/debug/map/wms.html +37 -0
- data/lib/leaflet/debug/vector/editable.html +43 -0
- data/lib/leaflet/debug/vector/route.js +1 -0
- data/lib/leaflet/debug/vector/vector-bounds.html +69 -0
- data/lib/leaflet/debug/vector/vector-canvas.html +92 -0
- data/lib/leaflet/debug/vector/vector-mobile.html +38 -0
- data/lib/leaflet/debug/vector/vector-simple.html +63 -0
- data/lib/leaflet/debug/vector/vector.html +38 -0
- data/lib/leaflet/dist/images/layers.png +0 -0
- data/lib/leaflet/dist/images/marker-shadow.png +0 -0
- data/lib/leaflet/dist/images/marker.png +0 -0
- data/lib/leaflet/dist/images/popup-close.png +0 -0
- data/lib/leaflet/dist/images/zoom-in.png +0 -0
- data/lib/leaflet/dist/images/zoom-out.png +0 -0
- data/lib/leaflet/dist/leaflet-src.js +5537 -0
- data/lib/leaflet/dist/leaflet.css +323 -0
- data/lib/leaflet/dist/leaflet.ie.css +48 -0
- data/lib/leaflet/dist/leaflet.js +6 -0
- data/lib/leaflet/lib/jasmine/jasmine-html.js +182 -0
- data/lib/leaflet/lib/jasmine/jasmine.css +166 -0
- data/lib/leaflet/lib/jasmine/jasmine.js +2421 -0
- data/lib/leaflet/spec/runner.html +57 -0
- data/lib/leaflet/spec/suites/LeafletSpec.js +15 -0
- data/lib/leaflet/spec/suites/SpecHelper.js +28 -0
- data/lib/leaflet/spec/suites/core/ClassSpec.js +153 -0
- data/lib/leaflet/spec/suites/core/EventsSpec.js +110 -0
- data/lib/leaflet/spec/suites/core/UtilSpec.js +63 -0
- data/lib/leaflet/spec/suites/dom/DomEventSpec.js +102 -0
- data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +59 -0
- data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +1 -0
- data/lib/leaflet/spec/suites/geo/LatLngSpec.js +76 -0
- data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +42 -0
- data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +53 -0
- data/lib/leaflet/spec/suites/geometry/PointSpec.js +45 -0
- data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +19 -0
- data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +1 -0
- data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +35 -0
- data/lib/leaflet/spec/suites/map/MapSpec.js +1 -0
- data/lib/leaflet/src/Leaflet.js +33 -0
- data/lib/leaflet/src/control/Control.Attribution.js +66 -0
- data/lib/leaflet/src/control/Control.Layers.js +167 -0
- data/lib/leaflet/src/control/Control.Zoom.js +36 -0
- data/lib/leaflet/src/control/Control.js +9 -0
- data/lib/leaflet/src/core/Browser.js +53 -0
- data/lib/leaflet/src/core/Class.js +66 -0
- data/lib/leaflet/src/core/Events.js +62 -0
- data/lib/leaflet/src/core/Handler.js +29 -0
- data/lib/leaflet/src/core/Util.js +108 -0
- data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +43 -0
- data/lib/leaflet/src/dom/DomEvent.js +154 -0
- data/lib/leaflet/src/dom/DomUtil.js +155 -0
- data/lib/leaflet/src/dom/Draggable.js +147 -0
- data/lib/leaflet/src/dom/transition/Transition.Native.js +102 -0
- data/lib/leaflet/src/dom/transition/Transition.Timer.js +126 -0
- data/lib/leaflet/src/dom/transition/Transition.js +28 -0
- data/lib/leaflet/src/geo/LatLng.js +44 -0
- data/lib/leaflet/src/geo/LatLngBounds.js +86 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +13 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3857.js +17 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG4326.js +7 -0
- data/lib/leaflet/src/geo/crs/CRS.js +17 -0
- data/lib/leaflet/src/geo/projection/Projection.LonLat.js +10 -0
- data/lib/leaflet/src/geo/projection/Projection.Mercator.js +51 -0
- data/lib/leaflet/src/geo/projection/Projection.SphericalMercator.js +23 -0
- data/lib/leaflet/src/geo/projection/Projection.js +5 -0
- data/lib/leaflet/src/geometry/Bounds.js +50 -0
- data/lib/leaflet/src/geometry/LineUtil.js +194 -0
- data/lib/leaflet/src/geometry/Point.js +66 -0
- data/lib/leaflet/src/geometry/PolyUtil.js +59 -0
- data/lib/leaflet/src/geometry/Transformation.js +31 -0
- data/lib/leaflet/src/layer/FeatureGroup.js +40 -0
- data/lib/leaflet/src/layer/GeoJSON.js +104 -0
- data/lib/leaflet/src/layer/ImageOverlay.js +58 -0
- data/lib/leaflet/src/layer/LayerGroup.js +74 -0
- data/lib/leaflet/src/layer/Popup.js +179 -0
- data/lib/leaflet/src/layer/marker/Icon.js +58 -0
- data/lib/leaflet/src/layer/marker/Marker.Drag.js +57 -0
- data/lib/leaflet/src/layer/marker/Marker.Popup.js +42 -0
- data/lib/leaflet/src/layer/marker/Marker.js +142 -0
- data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +41 -0
- data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +47 -0
- data/lib/leaflet/src/layer/tile/TileLayer.js +310 -0
- data/lib/leaflet/src/layer/vector/Circle.js +68 -0
- data/lib/leaflet/src/layer/vector/CircleMarker.js +25 -0
- data/lib/leaflet/src/layer/vector/MultiPoly.js +34 -0
- data/lib/leaflet/src/layer/vector/Path.Popup.js +24 -0
- data/lib/leaflet/src/layer/vector/Path.SVG.js +138 -0
- data/lib/leaflet/src/layer/vector/Path.VML.js +93 -0
- data/lib/leaflet/src/layer/vector/Path.js +88 -0
- data/lib/leaflet/src/layer/vector/Polygon.js +64 -0
- data/lib/leaflet/src/layer/vector/Polyline.js +146 -0
- data/lib/leaflet/src/layer/vector/canvas/Circle.Canvas.js +18 -0
- data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +146 -0
- data/lib/leaflet/src/layer/vector/canvas/Polygon.Canvas.js +34 -0
- data/lib/leaflet/src/layer/vector/canvas/Polyline.Canvas.js +27 -0
- data/lib/leaflet/src/map/Map.js +613 -0
- data/lib/leaflet/src/map/anim/Map.PanAnimation.js +70 -0
- data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +133 -0
- data/lib/leaflet/src/map/ext/Map.Control.js +50 -0
- data/lib/leaflet/src/map/ext/Map.Geolocation.js +86 -0
- data/lib/leaflet/src/map/ext/Map.Popup.js +20 -0
- data/lib/leaflet/src/map/handler/Map.BoxZoom.js +73 -0
- data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +18 -0
- data/lib/leaflet/src/map/handler/Map.Drag.js +81 -0
- data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +55 -0
- data/lib/leaflet/src/map/handler/Map.TouchZoom.js +93 -0
- data/lib/zerista/CRS.Cartesian.js +20 -0
- data/lib/zerista/Projection.Identity.js +11 -0
- data/lib/zerista/zerista_layer.js +97 -0
- data/vendor/assets/javascripts/leaflet.js +139 -0
- data/vendor/assets/stylesheets/leaflet.css +1 -0
- data/vendor/assets/stylesheets/leaflet.ie.css +1 -0
- metadata +185 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>Jasmine Test Runner</title>
|
|
5
|
+
<link rel="stylesheet" type="text/css" href="../lib/jasmine/jasmine.css">
|
|
6
|
+
<script type="text/javascript" src="../lib/jasmine/jasmine.js"></script>
|
|
7
|
+
<script type="text/javascript" src="../lib/jasmine/jasmine-html.js"></script>
|
|
8
|
+
|
|
9
|
+
<!-- source files -->
|
|
10
|
+
|
|
11
|
+
<script type="text/javascript">
|
|
12
|
+
L = 'test'; //to test L#noConflict later
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<script type="text/javascript" src="../debug/leaflet-include.js"></script>
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
<!-- spec files -->
|
|
19
|
+
|
|
20
|
+
<script type="text/javascript" src="suites/SpecHelper.js"></script>
|
|
21
|
+
<script type="text/javascript" src="suites/LeafletSpec.js"></script>
|
|
22
|
+
|
|
23
|
+
<!-- /core -->
|
|
24
|
+
<script type="text/javascript" src="suites/core/UtilSpec.js"></script>
|
|
25
|
+
<script type="text/javascript" src="suites/core/ClassSpec.js"></script>
|
|
26
|
+
<script type="text/javascript" src="suites/core/EventsSpec.js"></script>
|
|
27
|
+
|
|
28
|
+
<!-- /geometry -->
|
|
29
|
+
<script type="text/javascript" src="suites/geometry/PointSpec.js"></script>
|
|
30
|
+
<script type="text/javascript" src="suites/geometry/BoundsSpec.js"></script>
|
|
31
|
+
<script type="text/javascript" src="suites/geometry/TransformationSpec.js"></script>
|
|
32
|
+
|
|
33
|
+
<!-- /geo -->
|
|
34
|
+
<script type="text/javascript" src="suites/geo/LatLngSpec.js"></script>
|
|
35
|
+
<script type="text/javascript" src="suites/geo/LatLngBoundsSpec.js"></script>
|
|
36
|
+
<script type="text/javascript" src="suites/geo/ProjectionSpec.js"></script>
|
|
37
|
+
|
|
38
|
+
<!-- /dom -->
|
|
39
|
+
<script type="text/javascript" src="suites/dom/DomEventSpec.js"></script>
|
|
40
|
+
<script type="text/javascript" src="suites/dom/DomUtilSpec.js"></script>
|
|
41
|
+
|
|
42
|
+
<!-- /layer -->
|
|
43
|
+
<script type="text/javascript" src="suites/layer/TileLayerSpec.js"></script>
|
|
44
|
+
<script type="text/javascript" src="suites/layer/vector/PolylineGeometrySpec.js"></script>
|
|
45
|
+
|
|
46
|
+
<!-- /map -->
|
|
47
|
+
<script type="text/javascript" src="suites/map/MapSpec.js"></script>
|
|
48
|
+
</head>
|
|
49
|
+
<body>
|
|
50
|
+
|
|
51
|
+
<script type="text/javascript">
|
|
52
|
+
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
|
|
53
|
+
jasmine.getEnv().execute();
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
describe('L#noConflict', function() {
|
|
2
|
+
it('should restore the previous L value and return Leaflet namespace', function(){
|
|
3
|
+
|
|
4
|
+
expect(L.VERSION).toBeDefined();
|
|
5
|
+
|
|
6
|
+
var L2 = L.noConflict();
|
|
7
|
+
|
|
8
|
+
expect(L).toEqual('test');
|
|
9
|
+
expect(L2.VERSION).toBeDefined();
|
|
10
|
+
|
|
11
|
+
this.after(function() {
|
|
12
|
+
window.L = L2;
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
function noSpecs() {
|
|
2
|
+
xit('should have specs', function() {
|
|
3
|
+
expect('specs').toBe();
|
|
4
|
+
});
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
if (!Array.prototype.map) {
|
|
8
|
+
Array.prototype.map = function(fun /*, thisp */) {
|
|
9
|
+
"use strict";
|
|
10
|
+
|
|
11
|
+
if (this === void 0 || this === null)
|
|
12
|
+
throw new TypeError();
|
|
13
|
+
|
|
14
|
+
var t = Object(this);
|
|
15
|
+
var len = t.length >>> 0;
|
|
16
|
+
if (typeof fun !== "function")
|
|
17
|
+
throw new TypeError();
|
|
18
|
+
|
|
19
|
+
var res = new Array(len);
|
|
20
|
+
var thisp = arguments[1];
|
|
21
|
+
for (var i = 0; i < len; i++) {
|
|
22
|
+
if (i in t)
|
|
23
|
+
res[i] = fun.call(thisp, t[i], i, t);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return res;
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
describe("Class", function() {
|
|
2
|
+
|
|
3
|
+
describe("#extend", function() {
|
|
4
|
+
var Klass,
|
|
5
|
+
constructor,
|
|
6
|
+
method;
|
|
7
|
+
|
|
8
|
+
beforeEach(function() {
|
|
9
|
+
constructor = jasmine.createSpy("Klass constructor");
|
|
10
|
+
method = jasmine.createSpy("Klass#bar method");
|
|
11
|
+
|
|
12
|
+
Klass = L.Class.extend({
|
|
13
|
+
statics: {bla: 1},
|
|
14
|
+
includes: {mixin: true},
|
|
15
|
+
|
|
16
|
+
initialize: constructor,
|
|
17
|
+
foo: 5,
|
|
18
|
+
bar: method
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should create a class with the given constructor & properties", function() {
|
|
23
|
+
var a = new Klass();
|
|
24
|
+
|
|
25
|
+
expect(constructor).toHaveBeenCalled();
|
|
26
|
+
expect(a.foo).toEqual(5);
|
|
27
|
+
|
|
28
|
+
a.bar();
|
|
29
|
+
|
|
30
|
+
expect(method).toHaveBeenCalled();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should inherit parent classes' constructor & properties", function() {
|
|
34
|
+
var Klass2 = Klass.extend({baz: 2});
|
|
35
|
+
|
|
36
|
+
var b = new Klass2();
|
|
37
|
+
|
|
38
|
+
expect(b instanceof Klass).toBeTruthy();
|
|
39
|
+
expect(b instanceof Klass2).toBeTruthy();
|
|
40
|
+
|
|
41
|
+
expect(constructor).toHaveBeenCalled();
|
|
42
|
+
expect(b.baz).toEqual(2);
|
|
43
|
+
|
|
44
|
+
b.bar();
|
|
45
|
+
|
|
46
|
+
expect(method).toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should grant the ability to call parent methods, including constructor", function() {
|
|
50
|
+
var Klass2 = Klass.extend({
|
|
51
|
+
initialize: function() {},
|
|
52
|
+
bar: function() {}
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
var b = new Klass2();
|
|
56
|
+
|
|
57
|
+
expect(constructor).not.toHaveBeenCalled();
|
|
58
|
+
b.constructor.superclass.initialize.call(this);
|
|
59
|
+
expect(constructor).toHaveBeenCalled();
|
|
60
|
+
|
|
61
|
+
b.constructor.superclass.bar.call(this);
|
|
62
|
+
expect(method).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should support static properties", function() {
|
|
66
|
+
expect(Klass.bla).toEqual(1);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("should inherit parent static properties", function() {
|
|
70
|
+
var Klass2 = Klass.extend({});
|
|
71
|
+
|
|
72
|
+
expect(Klass2.bla).toEqual(1);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should override parent static properties", function() {
|
|
76
|
+
var Klass2 = Klass.extend({statics: {bla: 2}});
|
|
77
|
+
|
|
78
|
+
expect(Klass2.bla).toEqual(2);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should include the given mixin", function() {
|
|
82
|
+
var a = new Klass();
|
|
83
|
+
expect(a.mixin).toBeTruthy();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("should be able to include multiple mixins", function() {
|
|
87
|
+
var Klass2 = L.Class.extend({
|
|
88
|
+
includes: [{mixin: true}, {mixin2: true}]
|
|
89
|
+
});
|
|
90
|
+
var a = new Klass2();
|
|
91
|
+
|
|
92
|
+
expect(a.mixin).toBeTruthy();
|
|
93
|
+
expect(a.mixin2).toBeTruthy();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("should grant the ability to include the given mixin", function() {
|
|
97
|
+
Klass.include({mixin2: true});
|
|
98
|
+
|
|
99
|
+
var a = new Klass();
|
|
100
|
+
expect(a.mixin2).toBeTruthy();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("should merge options instead of replacing them", function() {
|
|
104
|
+
var KlassWithOptions1 = L.Class.extend({
|
|
105
|
+
options: {
|
|
106
|
+
foo1: 1,
|
|
107
|
+
foo2: 2
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
var KlassWithOptions2 = KlassWithOptions1.extend({
|
|
111
|
+
options: {
|
|
112
|
+
foo2: 3,
|
|
113
|
+
foo3: 4
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
var a = new KlassWithOptions2();
|
|
118
|
+
|
|
119
|
+
expect(a.options).toEqual({
|
|
120
|
+
foo1: 1,
|
|
121
|
+
foo2: 3,
|
|
122
|
+
foo3: 4
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should have working superclass access with inheritance level > 2", function() {
|
|
127
|
+
var constructor2 = jasmine.createSpy("Klass2 constructor"),
|
|
128
|
+
constructor3 = jasmine.createSpy("Klass3 constructor");
|
|
129
|
+
|
|
130
|
+
var Klass2 = Klass.extend({
|
|
131
|
+
initialize: function() {
|
|
132
|
+
constructor2();
|
|
133
|
+
expect(Klass2.superclass).toBe(Klass.prototype);
|
|
134
|
+
Klass2.superclass.initialize.apply(this, arguments);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
var Klass3 = Klass2.extend({
|
|
139
|
+
initialize: function() {
|
|
140
|
+
constructor3();
|
|
141
|
+
expect(Klass3.superclass).toBe(Klass2.prototype);
|
|
142
|
+
Klass3.superclass.initialize.apply(this, arguments);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
var a = new Klass3();
|
|
147
|
+
|
|
148
|
+
expect(constructor3).toHaveBeenCalled();
|
|
149
|
+
expect(constructor2).toHaveBeenCalled();
|
|
150
|
+
expect(constructor).toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
describe('Events', function() {
|
|
2
|
+
var Klass;
|
|
3
|
+
|
|
4
|
+
beforeEach(function() {
|
|
5
|
+
Klass = L.Class.extend({
|
|
6
|
+
includes: L.Mixin.Events
|
|
7
|
+
});
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('#fireEvent', function() {
|
|
11
|
+
|
|
12
|
+
it('should fire all listeners added through #addEventListener', function() {
|
|
13
|
+
var obj = new Klass(),
|
|
14
|
+
spy = jasmine.createSpy(),
|
|
15
|
+
spy2 = jasmine.createSpy(),
|
|
16
|
+
spy3 = jasmine.createSpy();
|
|
17
|
+
|
|
18
|
+
obj.addEventListener('test', spy);
|
|
19
|
+
obj.addEventListener('test', spy2);
|
|
20
|
+
obj.addEventListener('other', spy3);
|
|
21
|
+
|
|
22
|
+
expect(spy).not.toHaveBeenCalled();
|
|
23
|
+
expect(spy2).not.toHaveBeenCalled();
|
|
24
|
+
expect(spy3).not.toHaveBeenCalled();
|
|
25
|
+
|
|
26
|
+
obj.fireEvent('test');
|
|
27
|
+
|
|
28
|
+
expect(spy).toHaveBeenCalled();
|
|
29
|
+
expect(spy2).toHaveBeenCalled();
|
|
30
|
+
expect(spy3).not.toHaveBeenCalled();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should provide event object to listeners and execute them in the right context', function() {
|
|
34
|
+
var obj = new Klass(),
|
|
35
|
+
obj2 = new Klass(),
|
|
36
|
+
foo = {};
|
|
37
|
+
|
|
38
|
+
function listener1(e) {
|
|
39
|
+
expect(e.type).toEqual('test');
|
|
40
|
+
expect(e.target).toEqual(obj);
|
|
41
|
+
expect(this).toEqual(obj);
|
|
42
|
+
expect(e.bar).toEqual(3);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
function listener2(e) {
|
|
46
|
+
expect(e.target).toEqual(obj2);
|
|
47
|
+
expect(this).toEqual(foo);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
obj.addEventListener('test', listener1);
|
|
51
|
+
obj2.addEventListener('test', listener2, foo);
|
|
52
|
+
|
|
53
|
+
obj.fireEvent('test', {bar: 3});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should not call listeners removed through #removeEventListener', function() {
|
|
57
|
+
var obj = new Klass(),
|
|
58
|
+
spy = jasmine.createSpy();
|
|
59
|
+
|
|
60
|
+
obj.addEventListener('test', spy);
|
|
61
|
+
obj.removeEventListener('test', spy);
|
|
62
|
+
|
|
63
|
+
obj.fireEvent('test');
|
|
64
|
+
|
|
65
|
+
expect(spy).not.toHaveBeenCalled();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('#on, #off & #fire', function() {
|
|
70
|
+
|
|
71
|
+
it('should work like #addEventListener && #removeEventListener', function() {
|
|
72
|
+
var obj = new Klass(),
|
|
73
|
+
spy = jasmine.createSpy();
|
|
74
|
+
|
|
75
|
+
obj.on('test', spy);
|
|
76
|
+
obj.fire('test');
|
|
77
|
+
|
|
78
|
+
expect(spy).toHaveBeenCalled();
|
|
79
|
+
|
|
80
|
+
obj.off('test', spy);
|
|
81
|
+
obj.fireEvent('test');
|
|
82
|
+
|
|
83
|
+
expect(spy.callCount).toBeLessThan(2);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('should not override existing methods with the same name', function() {
|
|
87
|
+
var spy1 = jasmine.createSpy(),
|
|
88
|
+
spy2 = jasmine.createSpy(),
|
|
89
|
+
spy3 = jasmine.createSpy();
|
|
90
|
+
|
|
91
|
+
var Klass2 = L.Class.extend({
|
|
92
|
+
includes: L.Mixin.Events,
|
|
93
|
+
on: spy1,
|
|
94
|
+
off: spy2,
|
|
95
|
+
fire: spy3
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
var obj = new Klass2();
|
|
99
|
+
|
|
100
|
+
obj.on();
|
|
101
|
+
expect(spy1).toHaveBeenCalled();
|
|
102
|
+
|
|
103
|
+
obj.off();
|
|
104
|
+
expect(spy2).toHaveBeenCalled();
|
|
105
|
+
|
|
106
|
+
obj.fire();
|
|
107
|
+
expect(spy3).toHaveBeenCalled();
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
});
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
describe('Util', function() {
|
|
2
|
+
|
|
3
|
+
describe('#extend', function() {
|
|
4
|
+
var a;
|
|
5
|
+
|
|
6
|
+
beforeEach(function() {
|
|
7
|
+
a = {
|
|
8
|
+
foo: 5,
|
|
9
|
+
bar: 'asd'
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should extend the first argument with the properties of the second', function() {
|
|
14
|
+
L.Util.extend(a, {
|
|
15
|
+
bar: 7,
|
|
16
|
+
baz: 3
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
expect(a).toEqual({
|
|
20
|
+
foo: 5,
|
|
21
|
+
bar: 7,
|
|
22
|
+
baz: 3
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should work with more than 2 arguments', function() {
|
|
27
|
+
L.Util.extend(a, {bar: 7}, {baz: 3});
|
|
28
|
+
|
|
29
|
+
expect(a).toEqual({
|
|
30
|
+
foo: 5,
|
|
31
|
+
bar: 7,
|
|
32
|
+
baz: 3
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('#bind', function() {
|
|
38
|
+
it('should return the given function with the given context', function() {
|
|
39
|
+
var fn = function() {
|
|
40
|
+
return this;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
var fn2 = L.Util.bind(fn, 5);
|
|
44
|
+
|
|
45
|
+
expect(fn2()).toEqual(5);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('#stamp', function() {
|
|
50
|
+
it('should set a unique id on the given object and return it', function() {
|
|
51
|
+
var a = {},
|
|
52
|
+
id = L.Util.stamp(a);
|
|
53
|
+
|
|
54
|
+
expect(typeof id).toEqual('number');
|
|
55
|
+
expect(L.Util.stamp(a)).toEqual(id);
|
|
56
|
+
|
|
57
|
+
var b = {},
|
|
58
|
+
id2 = L.Util.stamp(b);
|
|
59
|
+
|
|
60
|
+
expect(id2).not.toEqual(id);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
describe('DomEvent', function() {
|
|
2
|
+
var el;
|
|
3
|
+
|
|
4
|
+
function simulateClick(el) {
|
|
5
|
+
if (document.createEvent) {
|
|
6
|
+
var e = document.createEvent('MouseEvents');
|
|
7
|
+
e.initMouseEvent('click', true, true, window,
|
|
8
|
+
0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
9
|
+
return el.dispatchEvent(e);
|
|
10
|
+
} else if (el.fireEvent) {
|
|
11
|
+
return el.fireEvent('onclick');
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
beforeEach(function() {
|
|
16
|
+
el = document.createElement('div');
|
|
17
|
+
el.style.position = 'absolute';
|
|
18
|
+
el.style.top = el.style.left = '-10000px';
|
|
19
|
+
document.body.appendChild(el);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
afterEach(function() {
|
|
23
|
+
document.body.removeChild(el);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('#addListener', function() {
|
|
27
|
+
it('should add a listener and call it on event', function() {
|
|
28
|
+
var listener1 = jasmine.createSpy('listener1'),
|
|
29
|
+
listener2 = jasmine.createSpy('listener2');
|
|
30
|
+
|
|
31
|
+
L.DomEvent.addListener(el, 'click', listener1);
|
|
32
|
+
L.DomEvent.addListener(el, 'click', listener2);
|
|
33
|
+
|
|
34
|
+
simulateClick(el);
|
|
35
|
+
|
|
36
|
+
expect(listener1).toHaveBeenCalled();
|
|
37
|
+
expect(listener2).toHaveBeenCalled();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should have "this" keyword point to the given context', function() {
|
|
41
|
+
var obj = {foo: 'bar'},
|
|
42
|
+
result;
|
|
43
|
+
|
|
44
|
+
L.DomEvent.addListener(el, 'click', function() {
|
|
45
|
+
result = this;
|
|
46
|
+
}, obj);
|
|
47
|
+
|
|
48
|
+
simulateClick(el);
|
|
49
|
+
|
|
50
|
+
expect(result).toEqual(obj);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('should pass an event object to the listener', function() {
|
|
54
|
+
var type;
|
|
55
|
+
|
|
56
|
+
L.DomEvent.addListener(el, 'click', function(e) {
|
|
57
|
+
type = e && e.type;
|
|
58
|
+
});
|
|
59
|
+
simulateClick(el);
|
|
60
|
+
|
|
61
|
+
expect(type).toEqual('click');
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe('#removeListener', function() {
|
|
66
|
+
it('should remove prevously added listener', function() {
|
|
67
|
+
var listener = jasmine.createSpy('listener');
|
|
68
|
+
|
|
69
|
+
L.DomEvent.addListener(el, 'click', listener);
|
|
70
|
+
L.DomEvent.removeListener(el, 'click', listener);
|
|
71
|
+
|
|
72
|
+
simulateClick(el);
|
|
73
|
+
|
|
74
|
+
expect(listener).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
describe('#stopPropagation', function() {
|
|
79
|
+
it('should stop propagation of the given event', function() {
|
|
80
|
+
var child = document.createElement('div'),
|
|
81
|
+
listener = jasmine.createSpy('listener');
|
|
82
|
+
|
|
83
|
+
el.appendChild(child);
|
|
84
|
+
|
|
85
|
+
L.DomEvent.addListener(child, 'click', L.DomEvent.stopPropagation);
|
|
86
|
+
L.DomEvent.addListener(el, 'click', listener);
|
|
87
|
+
|
|
88
|
+
simulateClick(child);
|
|
89
|
+
|
|
90
|
+
expect(listener).not.toHaveBeenCalled();
|
|
91
|
+
|
|
92
|
+
el.removeChild(child);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
describe('#preventDefault', function() {
|
|
96
|
+
it('should prevent the default action of event', function() {
|
|
97
|
+
L.DomEvent.addListener(el, 'click', L.DomEvent.preventDefault);
|
|
98
|
+
|
|
99
|
+
expect(simulateClick(el)).toBe(false);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
});
|