leaflet-js 0.6.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/CHANGELOG.rdoc +32 -0
- data/LICENSE +21 -0
- data/README.rdoc +54 -0
- data/Rakefile +15 -0
- data/leaflet-js.gemspec +28 -0
- data/lib/leaflet-js.rb +10 -0
- data/lib/leaflet.draw/BREAKINGCHANGES.md +54 -0
- data/lib/leaflet.draw/CHANGELOG.md +73 -0
- data/lib/leaflet.draw/Jakefile.js +26 -0
- data/lib/leaflet.draw/MIT-LICENCE.txt +20 -0
- data/lib/leaflet.draw/README.md +364 -0
- data/lib/leaflet.draw/TODO.md +62 -0
- data/lib/leaflet.draw/build/build.html +243 -0
- data/lib/leaflet.draw/build/build.js +189 -0
- data/lib/leaflet.draw/build/deps.js +75 -0
- data/lib/leaflet.draw/build/hintrc.js +47 -0
- data/lib/leaflet.draw/build/leaflet.draw-include.js +42 -0
- data/lib/leaflet.draw/dist/images/spritesheet.png +0 -0
- data/lib/leaflet.draw/dist/leaflet.draw-src.js +2429 -0
- data/lib/leaflet.draw/dist/leaflet.draw.css +212 -0
- data/lib/leaflet.draw/dist/leaflet.draw.ie.css +44 -0
- data/lib/leaflet.draw/dist/leaflet.draw.js +10 -0
- data/lib/leaflet.draw/examples/basic.html +106 -0
- data/lib/leaflet.draw/examples/edithandlers.html +67 -0
- data/lib/leaflet.draw/examples/libs/images/layers.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-icon.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-icon@2x.png +0 -0
- data/lib/leaflet.draw/examples/libs/images/marker-shadow.png +0 -0
- data/lib/leaflet.draw/examples/libs/leaflet-src.js +8587 -0
- data/lib/leaflet.draw/examples/libs/leaflet.css +459 -0
- data/lib/leaflet.draw/examples/libs/leaflet.ie.css +51 -0
- data/lib/leaflet.draw/package.json +37 -0
- data/lib/leaflet.draw/spec/after.js +2 -0
- data/lib/leaflet.draw/spec/before.js +3 -0
- data/lib/leaflet.draw/spec/expect.js +1253 -0
- data/lib/leaflet.draw/spec/happen.js +93 -0
- data/lib/leaflet.draw/spec/index.html +36 -0
- data/lib/leaflet.draw/spec/karma.conf.js +69 -0
- data/lib/leaflet.draw/spec/sinon.js +4223 -0
- data/lib/leaflet.draw/spec/suites/DrawControlSpec.js +15 -0
- data/lib/leaflet.draw/spec/suites/SpecHelper.js +26 -0
- data/lib/leaflet.draw/src/Control.Draw.js +101 -0
- data/lib/leaflet.draw/src/Leaflet.draw.js +5 -0
- data/lib/leaflet.draw/src/Toolbar.js +187 -0
- data/lib/leaflet.draw/src/Tooltip.js +52 -0
- data/lib/leaflet.draw/src/copyright.js +8 -0
- data/lib/leaflet.draw/src/draw/DrawToolbar.js +107 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Circle.js +59 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Feature.js +74 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Marker.js +97 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Polygon.js +79 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Polyline.js +360 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.Rectangle.js +41 -0
- data/lib/leaflet.draw/src/draw/handler/Draw.SimpleShape.js +67 -0
- data/lib/leaflet.draw/src/edit/EditToolbar.js +93 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Circle.js +63 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Poly.js +267 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.Rectangle.js +117 -0
- data/lib/leaflet.draw/src/edit/handler/Edit.SimpleShape.js +138 -0
- data/lib/leaflet.draw/src/edit/handler/EditToolbar.Delete.js +109 -0
- data/lib/leaflet.draw/src/edit/handler/EditToolbar.Edit.js +233 -0
- data/lib/leaflet.draw/src/ext/LatLngUtil.js +18 -0
- data/lib/leaflet.draw/src/ext/LineUtil.Intersect.js +15 -0
- data/lib/leaflet.draw/src/ext/Polygon.Intersect.js +27 -0
- data/lib/leaflet.draw/src/ext/Polyline.Intersect.js +85 -0
- data/lib/leaflet.label/CHANGELOG.md +35 -0
- data/lib/leaflet.label/Jakefile.js +21 -0
- data/lib/leaflet.label/MIT-LICENCE.txt +20 -0
- data/lib/leaflet.label/README.md +86 -0
- data/lib/leaflet.label/build/build.js +155 -0
- data/lib/leaflet.label/build/deps.js +24 -0
- data/lib/leaflet.label/build/hint.js +30 -0
- data/lib/leaflet.label/build/hintrc.js +47 -0
- data/lib/leaflet.label/dist/images/death.png +0 -0
- data/lib/leaflet.label/dist/leaflet.label-src.js +359 -0
- data/lib/leaflet.label/dist/leaflet.label.css +33 -0
- data/lib/leaflet.label/dist/leaflet.label.js +9 -0
- data/lib/leaflet.label/example/label.html +82 -0
- data/lib/leaflet.label/libs/leaflet/images/layers.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-icon.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-icon@2x.png +0 -0
- data/lib/leaflet.label/libs/leaflet/images/marker-shadow.png +0 -0
- data/lib/leaflet.label/libs/leaflet/leaflet-src.js +8587 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.css +459 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.ie.css +51 -0
- data/lib/leaflet.label/libs/leaflet/leaflet.js +8 -0
- data/lib/leaflet.label/src/FeatureGroup.Label.js +20 -0
- data/lib/leaflet.label/src/Label.js +123 -0
- data/lib/leaflet.label/src/Leaflet.label.js +5 -0
- data/lib/leaflet.label/src/Map.Label.js +7 -0
- data/lib/leaflet.label/src/Marker.Label.js +160 -0
- data/lib/leaflet.label/src/Path.Label.js +55 -0
- data/lib/leaflet.label/src/copyright.js +8 -0
- data/lib/leaflet/CHANGELOG.md +637 -0
- data/lib/leaflet/CONTRIBUTING.md +155 -0
- data/lib/leaflet/Jakefile.js +26 -0
- data/lib/leaflet/LICENSE +23 -0
- data/lib/leaflet/README.md +30 -0
- data/lib/leaflet/build/build.html +243 -0
- data/lib/leaflet/build/build.js +193 -0
- data/lib/leaflet/build/deps.js +256 -0
- data/lib/leaflet/build/hintrc.js +37 -0
- data/lib/leaflet/debug/css/mobile.css +6 -0
- data/lib/leaflet/debug/css/screen.css +5 -0
- data/lib/leaflet/debug/hacks/jitter.html +43 -0
- data/lib/leaflet/debug/leaflet-include.js +59 -0
- data/lib/leaflet/debug/map/canvas.html +47 -0
- data/lib/leaflet/debug/map/controls.html +50 -0
- data/lib/leaflet/debug/map/geolocation.html +35 -0
- data/lib/leaflet/debug/map/image-overlay.html +44 -0
- data/lib/leaflet/debug/map/map-mobile.html +35 -0
- data/lib/leaflet/debug/map/map.html +60 -0
- data/lib/leaflet/debug/map/max-bounds.html +37 -0
- data/lib/leaflet/debug/map/scroll.html +36 -0
- data/lib/leaflet/debug/map/simple-proj.html +45 -0
- data/lib/leaflet/debug/map/wms-marble.html +31 -0
- data/lib/leaflet/debug/map/wms.html +41 -0
- data/lib/leaflet/debug/map/zoomlevels.html +46 -0
- data/lib/leaflet/debug/tests/add_remove_layers.html +88 -0
- data/lib/leaflet/debug/tests/bringtoback.html +38 -0
- data/lib/leaflet/debug/tests/click_on_canvas.html +59 -0
- data/lib/leaflet/debug/tests/click_on_canvas_broken.html +49 -0
- data/lib/leaflet/debug/tests/opacity.html +57 -0
- data/lib/leaflet/debug/tests/remove_while_dragging.html +29 -0
- data/lib/leaflet/debug/tests/removetilewhilepan.html +42 -0
- data/lib/leaflet/debug/tests/reuse_popups.html +41 -0
- data/lib/leaflet/debug/tests/svg_clicks.html +55 -0
- data/lib/leaflet/debug/vector/bounds-extend.html +89 -0
- data/lib/leaflet/debug/vector/feature-group-bounds.html +91 -0
- data/lib/leaflet/debug/vector/geojson-sample.js +53 -0
- data/lib/leaflet/debug/vector/geojson.html +174 -0
- data/lib/leaflet/debug/vector/rectangle.html +54 -0
- data/lib/leaflet/debug/vector/route.js +1 -0
- data/lib/leaflet/debug/vector/touchzoomemu.html +195 -0
- data/lib/leaflet/debug/vector/us-states.js +54 -0
- data/lib/leaflet/debug/vector/vector-bounds.html +70 -0
- data/lib/leaflet/debug/vector/vector-canvas.html +93 -0
- data/lib/leaflet/debug/vector/vector-mobile.html +39 -0
- data/lib/leaflet/debug/vector/vector-simple.html +49 -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-icon-2x.png +0 -0
- data/lib/leaflet/dist/images/marker-icon.png +0 -0
- data/lib/leaflet/dist/images/marker-shadow.png +0 -0
- data/lib/leaflet/dist/leaflet-src.js +8579 -0
- data/lib/leaflet/dist/leaflet.css +459 -0
- data/lib/leaflet/dist/leaflet.ie.css +51 -0
- data/lib/leaflet/dist/leaflet.js +8 -0
- data/lib/leaflet/package.json +22 -0
- data/lib/leaflet/spec/after.js +2 -0
- data/lib/leaflet/spec/before.js +3 -0
- data/lib/leaflet/spec/expect.js +1253 -0
- data/lib/leaflet/spec/happen.js +93 -0
- data/lib/leaflet/spec/index.html +78 -0
- data/lib/leaflet/spec/karma.conf.js +64 -0
- data/lib/leaflet/spec/sinon.js +4223 -0
- data/lib/leaflet/spec/suites/LeafletSpec.js +13 -0
- data/lib/leaflet/spec/suites/SpecHelper.js +26 -0
- data/lib/leaflet/spec/suites/control/Control.AttributionSpec.js +68 -0
- data/lib/leaflet/spec/suites/control/Control.LayersSpec.js +67 -0
- data/lib/leaflet/spec/suites/control/Control.ScaleSpec.js +6 -0
- data/lib/leaflet/spec/suites/core/ClassSpec.js +156 -0
- data/lib/leaflet/spec/suites/core/EventsSpec.js +336 -0
- data/lib/leaflet/spec/suites/core/UtilSpec.js +212 -0
- data/lib/leaflet/spec/suites/dom/DomEventSpec.js +102 -0
- data/lib/leaflet/spec/suites/dom/DomUtilSpec.js +89 -0
- data/lib/leaflet/spec/suites/geo/LatLngBoundsSpec.js +136 -0
- data/lib/leaflet/spec/suites/geo/LatLngSpec.js +118 -0
- data/lib/leaflet/spec/suites/geo/ProjectionSpec.js +47 -0
- data/lib/leaflet/spec/suites/geometry/BoundsSpec.js +87 -0
- data/lib/leaflet/spec/suites/geometry/LineUtilSpec.js +75 -0
- data/lib/leaflet/spec/suites/geometry/PointSpec.js +104 -0
- data/lib/leaflet/spec/suites/geometry/PolyUtilSpec.js +27 -0
- data/lib/leaflet/spec/suites/geometry/TransformationSpec.js +31 -0
- data/lib/leaflet/spec/suites/layer/FeatureGroupSpec.js +36 -0
- data/lib/leaflet/spec/suites/layer/GeoJSONSpec.js +86 -0
- data/lib/leaflet/spec/suites/layer/LayerGroupSpec.js +58 -0
- data/lib/leaflet/spec/suites/layer/PopupSpec.js +59 -0
- data/lib/leaflet/spec/suites/layer/TileLayerSpec.js +87 -0
- data/lib/leaflet/spec/suites/layer/vector/CircleMarkerSpec.js +53 -0
- data/lib/leaflet/spec/suites/layer/vector/CircleSpec.js +17 -0
- data/lib/leaflet/spec/suites/layer/vector/PolygonSpec.js +55 -0
- data/lib/leaflet/spec/suites/layer/vector/PolylineGeometrySpec.js +35 -0
- data/lib/leaflet/spec/suites/layer/vector/PolylineSpec.js +55 -0
- data/lib/leaflet/spec/suites/map/MapSpec.js +244 -0
- data/lib/leaflet/src/Leaflet.js +23 -0
- data/lib/leaflet/src/control/Control.Attribution.js +115 -0
- data/lib/leaflet/src/control/Control.Layers.js +243 -0
- data/lib/leaflet/src/control/Control.Scale.js +112 -0
- data/lib/leaflet/src/control/Control.Zoom.js +86 -0
- data/lib/leaflet/src/control/Control.js +107 -0
- data/lib/leaflet/src/copyright.js +4 -0
- data/lib/leaflet/src/core/Browser.js +96 -0
- data/lib/leaflet/src/core/Class.js +106 -0
- data/lib/leaflet/src/core/Events.js +174 -0
- data/lib/leaflet/src/core/Handler.js +28 -0
- data/lib/leaflet/src/core/Util.js +182 -0
- data/lib/leaflet/src/dom/DomEvent.DoubleTap.js +103 -0
- data/lib/leaflet/src/dom/DomEvent.MsTouch.js +146 -0
- data/lib/leaflet/src/dom/DomEvent.js +211 -0
- data/lib/leaflet/src/dom/DomUtil.js +239 -0
- data/lib/leaflet/src/dom/Draggable.js +198 -0
- data/lib/leaflet/src/dom/PosAnimation.Timer.js +67 -0
- data/lib/leaflet/src/dom/PosAnimation.js +83 -0
- data/lib/leaflet/src/geo/LatLng.js +88 -0
- data/lib/leaflet/src/geo/LatLngBounds.js +153 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3395.js +14 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG3857.js +21 -0
- data/lib/leaflet/src/geo/crs/CRS.EPSG4326.js +10 -0
- data/lib/leaflet/src/geo/crs/CRS.Simple.js +12 -0
- data/lib/leaflet/src/geo/crs/CRS.js +27 -0
- data/lib/leaflet/src/geo/projection/Projection.LonLat.js +13 -0
- data/lib/leaflet/src/geo/projection/Projection.Mercator.js +56 -0
- data/lib/leaflet/src/geo/projection/Projection.SphericalMercator.js +27 -0
- data/lib/leaflet/src/geo/projection/Projection.js +5 -0
- data/lib/leaflet/src/geometry/Bounds.js +95 -0
- data/lib/leaflet/src/geometry/LineUtil.js +202 -0
- data/lib/leaflet/src/geometry/Point.js +119 -0
- data/lib/leaflet/src/geometry/PolyUtil.js +55 -0
- data/lib/leaflet/src/geometry/Transformation.js +31 -0
- data/lib/leaflet/src/images/marker.svg +1 -0
- data/lib/leaflet/src/layer/FeatureGroup.js +81 -0
- data/lib/leaflet/src/layer/GeoJSON.js +245 -0
- data/lib/leaflet/src/layer/ImageOverlay.js +132 -0
- data/lib/leaflet/src/layer/LayerGroup.js +110 -0
- data/lib/leaflet/src/layer/Popup.js +316 -0
- data/lib/leaflet/src/layer/marker/DivIcon.js +43 -0
- data/lib/leaflet/src/layer/marker/Icon.Default.js +51 -0
- data/lib/leaflet/src/layer/marker/Icon.js +101 -0
- data/lib/leaflet/src/layer/marker/Marker.Drag.js +66 -0
- data/lib/leaflet/src/layer/marker/Marker.Popup.js +72 -0
- data/lib/leaflet/src/layer/marker/Marker.js +275 -0
- data/lib/leaflet/src/layer/tile/TileLayer.Anim.js +117 -0
- data/lib/leaflet/src/layer/tile/TileLayer.Canvas.js +60 -0
- data/lib/leaflet/src/layer/tile/TileLayer.WMS.js +83 -0
- data/lib/leaflet/src/layer/tile/TileLayer.js +578 -0
- data/lib/leaflet/src/layer/vector/Circle.js +98 -0
- data/lib/leaflet/src/layer/vector/CircleMarker.js +33 -0
- data/lib/leaflet/src/layer/vector/MultiPoly.js +47 -0
- data/lib/leaflet/src/layer/vector/Path.Popup.js +65 -0
- data/lib/leaflet/src/layer/vector/Path.SVG.js +219 -0
- data/lib/leaflet/src/layer/vector/Path.VML.js +125 -0
- data/lib/leaflet/src/layer/vector/Path.js +115 -0
- data/lib/leaflet/src/layer/vector/Polygon.js +81 -0
- data/lib/leaflet/src/layer/vector/Polyline.js +164 -0
- data/lib/leaflet/src/layer/vector/Rectangle.js +27 -0
- data/lib/leaflet/src/layer/vector/canvas/Circle.Canvas.js +18 -0
- data/lib/leaflet/src/layer/vector/canvas/Path.Canvas.js +196 -0
- data/lib/leaflet/src/layer/vector/canvas/Polygon.Canvas.js +37 -0
- data/lib/leaflet/src/layer/vector/canvas/Polyline.Canvas.js +30 -0
- data/lib/leaflet/src/map/Map.js +743 -0
- data/lib/leaflet/src/map/anim/Map.PanAnimation.js +88 -0
- data/lib/leaflet/src/map/anim/Map.ZoomAnimation.js +90 -0
- data/lib/leaflet/src/map/ext/Map.Geolocation.js +91 -0
- data/lib/leaflet/src/map/handler/Map.BoxZoom.js +104 -0
- data/lib/leaflet/src/map/handler/Map.DoubleClickZoom.js +23 -0
- data/lib/leaflet/src/map/handler/Map.Drag.js +146 -0
- data/lib/leaflet/src/map/handler/Map.Keyboard.js +147 -0
- data/lib/leaflet/src/map/handler/Map.ScrollWheelZoom.js +56 -0
- data/lib/leaflet/src/map/handler/Map.TouchZoom.js +121 -0
- data/vendor/assets/images/layers.png +0 -0
- data/vendor/assets/images/marker-icon-2x.png +0 -0
- data/vendor/assets/images/marker-icon.png +0 -0
- data/vendor/assets/images/marker-shadow.png +0 -0
- data/vendor/assets/images/spritesheet.png +0 -0
- data/vendor/assets/javascripts/leaflet.draw.js +39 -0
- data/vendor/assets/javascripts/leaflet.js +145 -0
- data/vendor/assets/javascripts/leaflet.label.js +9 -0
- data/vendor/assets/stylesheets/leaflet.css.erb +459 -0
- data/vendor/assets/stylesheets/leaflet.draw.css.erb +212 -0
- data/vendor/assets/stylesheets/leaflet.draw.ie.css +44 -0
- data/vendor/assets/stylesheets/leaflet.ie.css +51 -0
- data/vendor/assets/stylesheets/leaflet.label.css +33 -0
- metadata +317 -0
@@ -0,0 +1,212 @@
|
|
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('extends 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).to.eql({
|
20
|
+
foo: 5,
|
21
|
+
bar: 7,
|
22
|
+
baz: 3
|
23
|
+
});
|
24
|
+
});
|
25
|
+
|
26
|
+
it('accepts more than 2 arguments', function() {
|
27
|
+
L.Util.extend(a, {bar: 7}, {baz: 3});
|
28
|
+
|
29
|
+
expect(a).to.eql({
|
30
|
+
foo: 5,
|
31
|
+
bar: 7,
|
32
|
+
baz: 3
|
33
|
+
});
|
34
|
+
});
|
35
|
+
});
|
36
|
+
|
37
|
+
describe('#bind', function() {
|
38
|
+
it('returns the given function with the given context', function() {
|
39
|
+
var fn = function() {
|
40
|
+
return this;
|
41
|
+
};
|
42
|
+
|
43
|
+
var fn2 = L.Util.bind(fn, { foo: 'bar' });
|
44
|
+
|
45
|
+
expect(fn2()).to.eql({ foo: 'bar' });
|
46
|
+
});
|
47
|
+
|
48
|
+
it('passes additional arguments to the bound function', function () {
|
49
|
+
var fn = sinon.spy(),
|
50
|
+
foo = {},
|
51
|
+
a = {},
|
52
|
+
b = {};
|
53
|
+
|
54
|
+
var fn2 = L.Util.bind(fn, foo, a, b);
|
55
|
+
|
56
|
+
fn2();
|
57
|
+
|
58
|
+
expect(fn.calledWith(a, b)).to.be.ok();
|
59
|
+
});
|
60
|
+
});
|
61
|
+
|
62
|
+
describe('#stamp', function() {
|
63
|
+
it('sets a unique id on the given object and returns it', function() {
|
64
|
+
var a = {},
|
65
|
+
id = L.Util.stamp(a);
|
66
|
+
|
67
|
+
expect(typeof id).to.eql('number');
|
68
|
+
expect(L.Util.stamp(a)).to.eql(id);
|
69
|
+
|
70
|
+
var b = {},
|
71
|
+
id2 = L.Util.stamp(b);
|
72
|
+
|
73
|
+
expect(id2).not.to.eql(id);
|
74
|
+
});
|
75
|
+
});
|
76
|
+
|
77
|
+
describe('#invokeEach', function () {
|
78
|
+
it('calls the given method/context with each key/value and additional arguments', function () {
|
79
|
+
var spy = sinon.spy(),
|
80
|
+
ctx = {};
|
81
|
+
|
82
|
+
var result = L.Util.invokeEach({
|
83
|
+
foo: 'bar',
|
84
|
+
yo: 'hey'
|
85
|
+
}, spy, ctx, 1, 2, 3);
|
86
|
+
|
87
|
+
expect(spy.firstCall.calledWith('foo', 'bar', 1, 2, 3)).to.be.ok();
|
88
|
+
expect(spy.secondCall.calledWith('yo', 'hey', 1, 2, 3)).to.be.ok();
|
89
|
+
|
90
|
+
expect(spy.firstCall.calledOn(ctx)).to.be.ok();
|
91
|
+
expect(spy.secondCall.calledOn(ctx)).to.be.ok();
|
92
|
+
|
93
|
+
expect(result).to.be(true);
|
94
|
+
});
|
95
|
+
|
96
|
+
it('returns false if the given agument is not object', function () {
|
97
|
+
var spy = sinon.spy();
|
98
|
+
|
99
|
+
expect(L.Util.invokeEach('foo', spy)).to.be(false);
|
100
|
+
expect(spy.called).to.be(false);
|
101
|
+
});
|
102
|
+
});
|
103
|
+
|
104
|
+
describe('#falseFn', function () {
|
105
|
+
it('returns false', function () {
|
106
|
+
expect(L.Util.falseFn()).to.be(false);
|
107
|
+
});
|
108
|
+
});
|
109
|
+
|
110
|
+
describe('#formatNum', function () {
|
111
|
+
it('formats numbers with a given precision', function () {
|
112
|
+
expect(L.Util.formatNum(13.12325555, 3)).to.eql(13.123);
|
113
|
+
expect(L.Util.formatNum(13.12325555)).to.eql(13.12326);
|
114
|
+
});
|
115
|
+
});
|
116
|
+
|
117
|
+
|
118
|
+
describe('#getParamString', function() {
|
119
|
+
it('creates a valid query string for appending depending on url input', function() {
|
120
|
+
var a = {
|
121
|
+
url: "http://example.com/get",
|
122
|
+
obj: {bar: 7, baz: 3},
|
123
|
+
result: "?bar=7&baz=3"
|
124
|
+
};
|
125
|
+
|
126
|
+
expect(L.Util.getParamString(a.obj,a.url)).to.eql(a.result);
|
127
|
+
|
128
|
+
var b = {
|
129
|
+
url: "http://example.com/get?justone=qs",
|
130
|
+
obj: {bar: 7, baz: 3},
|
131
|
+
result: "&bar=7&baz=3"
|
132
|
+
};
|
133
|
+
|
134
|
+
expect(L.Util.getParamString(b.obj,b.url)).to.eql(b.result);
|
135
|
+
|
136
|
+
var c = {
|
137
|
+
url: undefined,
|
138
|
+
obj: {bar: 7, baz: 3},
|
139
|
+
result: "?bar=7&baz=3"
|
140
|
+
};
|
141
|
+
|
142
|
+
expect(L.Util.getParamString(c.obj,c.url)).to.eql(c.result);
|
143
|
+
});
|
144
|
+
});
|
145
|
+
|
146
|
+
describe('#requestAnimFrame', function () {
|
147
|
+
it('calles a function on next frame, unless canceled', function (done) {
|
148
|
+
var spy = sinon.spy(),
|
149
|
+
spy2 = sinon.spy(),
|
150
|
+
foo = {};
|
151
|
+
|
152
|
+
L.Util.requestAnimFrame(spy);
|
153
|
+
|
154
|
+
L.Util.requestAnimFrame(function () {
|
155
|
+
expect(this).to.eql(foo);
|
156
|
+
done();
|
157
|
+
}, foo);
|
158
|
+
|
159
|
+
L.Util.cancelAnimFrame(spy);
|
160
|
+
});
|
161
|
+
});
|
162
|
+
|
163
|
+
describe('#limitExecByInterval', function() {
|
164
|
+
it('limits execution to not more often than specified time interval', function (done) {
|
165
|
+
var spy = sinon.spy();
|
166
|
+
|
167
|
+
var fn = L.Util.limitExecByInterval(spy, 20);
|
168
|
+
|
169
|
+
fn();
|
170
|
+
fn();
|
171
|
+
fn();
|
172
|
+
|
173
|
+
expect(spy.callCount).to.eql(1);
|
174
|
+
|
175
|
+
setTimeout(function () {
|
176
|
+
expect(spy.callCount).to.eql(2);
|
177
|
+
done();
|
178
|
+
}, 30);
|
179
|
+
});
|
180
|
+
});
|
181
|
+
|
182
|
+
describe('#splitWords', function () {
|
183
|
+
it('splits words into an array', function () {
|
184
|
+
expect(L.Util.splitWords('foo bar baz')).to.eql(['foo', 'bar', 'baz']);
|
185
|
+
});
|
186
|
+
});
|
187
|
+
|
188
|
+
// TODO setOptions
|
189
|
+
|
190
|
+
describe('#template', function () {
|
191
|
+
it('evaluates templates with a given data object', function () {
|
192
|
+
var tpl = 'Hello {foo} and {bar}!';
|
193
|
+
|
194
|
+
var str = L.Util.template(tpl, {
|
195
|
+
foo: 'Vlad',
|
196
|
+
bar: 'Dave'
|
197
|
+
});
|
198
|
+
|
199
|
+
expect(str).to.eql('Hello Vlad and Dave!');
|
200
|
+
});
|
201
|
+
|
202
|
+
it('does not modify text without a token variable', function () {
|
203
|
+
expect(L.Util.template('foo', {})).to.eql('foo');
|
204
|
+
});
|
205
|
+
|
206
|
+
it('throws when a template token is not given', function () {
|
207
|
+
expect(function () {
|
208
|
+
L.Util.template(tpl, {foo: 'bar'});
|
209
|
+
}).to.throwError();
|
210
|
+
});
|
211
|
+
});
|
212
|
+
});
|
@@ -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('adds a listener and calls it on event', function() {
|
28
|
+
var listener1 = sinon.spy(),
|
29
|
+
listener2 = sinon.spy();
|
30
|
+
|
31
|
+
L.DomEvent.addListener(el, 'click', listener1);
|
32
|
+
L.DomEvent.addListener(el, 'click', listener2);
|
33
|
+
|
34
|
+
simulateClick(el);
|
35
|
+
|
36
|
+
expect(listener1.called).to.be.ok();
|
37
|
+
expect(listener2.called).to.be.ok();
|
38
|
+
});
|
39
|
+
|
40
|
+
it('binds "this" 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).to.eql(obj);
|
51
|
+
});
|
52
|
+
|
53
|
+
it('passes 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).to.eql('click');
|
62
|
+
});
|
63
|
+
});
|
64
|
+
|
65
|
+
describe('#removeListener', function() {
|
66
|
+
it('removes a previously added listener', function() {
|
67
|
+
var listener = sinon.spy();
|
68
|
+
|
69
|
+
L.DomEvent.addListener(el, 'click', listener);
|
70
|
+
L.DomEvent.removeListener(el, 'click', listener);
|
71
|
+
|
72
|
+
simulateClick(el);
|
73
|
+
|
74
|
+
expect(listener.called).to.not.be.ok();
|
75
|
+
});
|
76
|
+
});
|
77
|
+
|
78
|
+
describe('#stopPropagation', function() {
|
79
|
+
it('stops propagation of the given event', function() {
|
80
|
+
var child = document.createElement('div'),
|
81
|
+
listener = sinon.spy();
|
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.called).to.not.be.ok();
|
91
|
+
|
92
|
+
el.removeChild(child);
|
93
|
+
});
|
94
|
+
});
|
95
|
+
describe('#preventDefault', function() {
|
96
|
+
it('prevents the default action of event', function() {
|
97
|
+
L.DomEvent.addListener(el, 'click', L.DomEvent.preventDefault);
|
98
|
+
|
99
|
+
expect(simulateClick(el)).to.be(false);
|
100
|
+
});
|
101
|
+
});
|
102
|
+
});
|
@@ -0,0 +1,89 @@
|
|
1
|
+
describe('DomUtil', function() {
|
2
|
+
var el;
|
3
|
+
|
4
|
+
beforeEach(function() {
|
5
|
+
el = document.createElement('div');
|
6
|
+
el.style.position = 'absolute';
|
7
|
+
el.style.top = el.style.left = '-10000px';
|
8
|
+
document.body.appendChild(el);
|
9
|
+
});
|
10
|
+
|
11
|
+
afterEach(function() {
|
12
|
+
document.body.removeChild(el);
|
13
|
+
});
|
14
|
+
|
15
|
+
describe('#get', function() {
|
16
|
+
it('gets element by id if the given argument is string', function() {
|
17
|
+
el.id = 'testId';
|
18
|
+
expect(L.DomUtil.get(el.id)).to.eql(el);
|
19
|
+
});
|
20
|
+
|
21
|
+
it('returns the element if it is given as an argument', function() {
|
22
|
+
expect(L.DomUtil.get(el)).to.eql(el);
|
23
|
+
});
|
24
|
+
});
|
25
|
+
|
26
|
+
describe('#addClass, #removeClass, #hasClass', function() {
|
27
|
+
it('has defined class for test element', function() {
|
28
|
+
el.className = 'bar foo baz ';
|
29
|
+
expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
|
30
|
+
expect(L.DomUtil.hasClass(el, 'bar')).to.be.ok();
|
31
|
+
expect(L.DomUtil.hasClass(el, 'baz')).to.be.ok();
|
32
|
+
expect(L.DomUtil.hasClass(el, 'boo')).to.not.be.ok();
|
33
|
+
});
|
34
|
+
|
35
|
+
it('adds or removes the class', function() {
|
36
|
+
el.className = '';
|
37
|
+
L.DomUtil.addClass(el, 'foo');
|
38
|
+
|
39
|
+
expect(el.className).to.eql('foo');
|
40
|
+
expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
|
41
|
+
|
42
|
+
L.DomUtil.addClass(el, 'bar');
|
43
|
+
expect(el.className).to.eql('foo bar');
|
44
|
+
expect(L.DomUtil.hasClass(el, 'foo')).to.be.ok();
|
45
|
+
|
46
|
+
L.DomUtil.removeClass(el, 'foo');
|
47
|
+
expect(el.className).to.eql('bar');
|
48
|
+
expect(L.DomUtil.hasClass(el, 'foo')).to.not.be.ok();
|
49
|
+
|
50
|
+
el.className = 'foo bar barz';
|
51
|
+
L.DomUtil.removeClass(el, 'bar');
|
52
|
+
expect(el.className).to.eql('foo barz');
|
53
|
+
});
|
54
|
+
});
|
55
|
+
|
56
|
+
describe('#documentIsLtr', function () {
|
57
|
+
it('returns true if doc direction is ltr', function () {
|
58
|
+
expect(L.DomUtil.documentIsLtr()).to.eql(true);
|
59
|
+
expect(L.DomUtil.documentIsLtr()).to.eql(true); // cached
|
60
|
+
});
|
61
|
+
});
|
62
|
+
|
63
|
+
describe('#getViewportOffset', function () {
|
64
|
+
it('calculates the viewport offset of an element', function () {
|
65
|
+
var div = document.createElement('div');
|
66
|
+
div.style.position = 'absolute';
|
67
|
+
div.style.top = '100px';
|
68
|
+
div.style.left = '200px';
|
69
|
+
div.style.border = '10px solid black';
|
70
|
+
div.style.padding = '50px';
|
71
|
+
div.style.visibility = 'hidden';
|
72
|
+
|
73
|
+
var div2 = document.createElement('div');
|
74
|
+
div.style.marginTop = '100px';
|
75
|
+
|
76
|
+
div.appendChild(div2);
|
77
|
+
|
78
|
+
document.body.appendChild(div);
|
79
|
+
|
80
|
+
expect(L.DomUtil.getViewportOffset(div2)).to.eql(new L.Point(260, 260));
|
81
|
+
|
82
|
+
document.body.removeChild(div);
|
83
|
+
});
|
84
|
+
});
|
85
|
+
|
86
|
+
// describe('#setPosition', noSpecs);
|
87
|
+
|
88
|
+
// describe('#getStyle', noSpecs);
|
89
|
+
});
|
@@ -0,0 +1,136 @@
|
|
1
|
+
describe('LatLngBounds', function() {
|
2
|
+
var a, c;
|
3
|
+
|
4
|
+
beforeEach(function() {
|
5
|
+
a = new L.LatLngBounds(
|
6
|
+
new L.LatLng(14, 12),
|
7
|
+
new L.LatLng(30, 40));
|
8
|
+
c = new L.LatLngBounds();
|
9
|
+
});
|
10
|
+
|
11
|
+
describe('constructor', function () {
|
12
|
+
it('instantiates either passing two latlngs or an array of latlngs', function () {
|
13
|
+
var b = new L.LatLngBounds([
|
14
|
+
new L.LatLng(14, 12),
|
15
|
+
new L.LatLng(30, 40)
|
16
|
+
]);
|
17
|
+
expect(b).to.eql(a);
|
18
|
+
expect(b.getNorthWest()).to.eql(new L.LatLng(30, 12));
|
19
|
+
});
|
20
|
+
});
|
21
|
+
|
22
|
+
describe('#extend', function () {
|
23
|
+
it('extends the bounds by a given point', function () {
|
24
|
+
a.extend(new L.LatLng(20, 50));
|
25
|
+
expect(a.getNorthEast()).to.eql(new L.LatLng(30, 50));
|
26
|
+
});
|
27
|
+
|
28
|
+
it('extends the bounds by given bounds', function () {
|
29
|
+
a.extend([[20, 50], [8, 40]]);
|
30
|
+
|
31
|
+
expect(a.getSouthEast()).to.eql(new L.LatLng(8, 50));
|
32
|
+
});
|
33
|
+
});
|
34
|
+
|
35
|
+
describe('#getCenter', function () {
|
36
|
+
it('returns the bounds center', function () {
|
37
|
+
expect(a.getCenter()).to.eql(new L.LatLng(22, 26));
|
38
|
+
});
|
39
|
+
});
|
40
|
+
|
41
|
+
describe('#pad', function () {
|
42
|
+
it('pads the bounds by a given ratio', function () {
|
43
|
+
var b = a.pad(0.5);
|
44
|
+
|
45
|
+
expect(b).to.eql(L.latLngBounds([[6, -2], [38, 54]]));
|
46
|
+
});
|
47
|
+
});
|
48
|
+
|
49
|
+
describe('#equals', function () {
|
50
|
+
it('returns true if bounds equal', function () {
|
51
|
+
expect(a.equals([[14, 12], [30, 40]])).to.eql(true);
|
52
|
+
expect(a.equals([[14, 13], [30, 40]])).to.eql(false);
|
53
|
+
expect(a.equals(null)).to.eql(false);
|
54
|
+
});
|
55
|
+
});
|
56
|
+
|
57
|
+
describe('#isValid', function() {
|
58
|
+
it('returns true if properly set up', function() {
|
59
|
+
expect(a.isValid()).to.be.ok();
|
60
|
+
});
|
61
|
+
it('returns false if is invalid', function() {
|
62
|
+
expect(c.isValid()).to.not.be.ok();
|
63
|
+
});
|
64
|
+
it('returns true if extended', function() {
|
65
|
+
c.extend([0, 0]);
|
66
|
+
expect(c.isValid()).to.be.ok();
|
67
|
+
});
|
68
|
+
});
|
69
|
+
|
70
|
+
describe('#getWest', function () {
|
71
|
+
it('returns a proper bbox west value', function() {
|
72
|
+
expect(a.getWest()).to.eql(12);
|
73
|
+
});
|
74
|
+
});
|
75
|
+
|
76
|
+
describe('#getSouth', function () {
|
77
|
+
it('returns a proper bbox south value', function() {
|
78
|
+
expect(a.getSouth()).to.eql(14);
|
79
|
+
});
|
80
|
+
|
81
|
+
});
|
82
|
+
|
83
|
+
describe('#getEast', function () {
|
84
|
+
it('returns a proper bbox east value', function() {
|
85
|
+
expect(a.getEast()).to.eql(40);
|
86
|
+
});
|
87
|
+
|
88
|
+
});
|
89
|
+
|
90
|
+
describe('#getNorth', function () {
|
91
|
+
it('returns a proper bbox north value', function() {
|
92
|
+
expect(a.getNorth()).to.eql(30);
|
93
|
+
});
|
94
|
+
|
95
|
+
});
|
96
|
+
|
97
|
+
describe('#toBBoxString', function () {
|
98
|
+
it('returns a proper left,bottom,right,top bbox', function() {
|
99
|
+
expect(a.toBBoxString()).to.eql("12,14,40,30");
|
100
|
+
});
|
101
|
+
|
102
|
+
});
|
103
|
+
|
104
|
+
describe('#getNorthWest', function () {
|
105
|
+
it('returns a proper north-west LatLng', function() {
|
106
|
+
expect(a.getNorthWest()).to.eql(new L.LatLng(a.getNorth(), a.getWest()));
|
107
|
+
});
|
108
|
+
|
109
|
+
});
|
110
|
+
|
111
|
+
describe('#getSouthEast', function () {
|
112
|
+
it('returns a proper south-east LatLng', function() {
|
113
|
+
expect(a.getSouthEast()).to.eql(new L.LatLng(a.getSouth(), a.getEast()));
|
114
|
+
});
|
115
|
+
});
|
116
|
+
|
117
|
+
describe('#contains', function () {
|
118
|
+
it('returns true if contains latlng point', function () {
|
119
|
+
expect(a.contains([16, 20])).to.eql(true);
|
120
|
+
expect(L.latLngBounds(a).contains([5, 20])).to.eql(false);
|
121
|
+
});
|
122
|
+
|
123
|
+
it('returns true if contains bounds', function () {
|
124
|
+
expect(a.contains([[16, 20], [20, 40]])).to.eql(true);
|
125
|
+
expect(a.contains([[16, 50], [8, 40]])).to.eql(false);
|
126
|
+
});
|
127
|
+
});
|
128
|
+
|
129
|
+
describe('#intersects', function () {
|
130
|
+
it('returns true if intersects the given bounds', function () {
|
131
|
+
expect(a.intersects([[16, 20], [50, 60]])).to.eql(true);
|
132
|
+
expect(a.contains([[40, 50], [50, 60]])).to.eql(false);
|
133
|
+
});
|
134
|
+
});
|
135
|
+
|
136
|
+
});
|