Skip to content

Commit

Permalink
Add built files.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmanley committed Feb 8, 2015
1 parent fb47107 commit 01b7892
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ module.exports = function(grunt) {
});

/* Run tests once. */
grunt.registerTask('test', [ 'jshint', 'karma:test', 'coverage' ]);
grunt.registerTask('test', [ 'jshint', 'karma:unit', 'coverage' ]);

/* Default (development): Watch files and lint, test, and build on change. */
grunt.registerTask('default', ['karma:development:start', 'watch']);
Expand Down
40 changes: 38 additions & 2 deletions dist/leaflet.toolbar-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ L.Toolbar = L.Class.extend({

initialize: function(options) {
L.setOptions(this, options);
this._toolbar_type = this.constructor._toolbar_class_id;
},

addTo: function(map) {
Expand All @@ -27,9 +28,20 @@ L.Toolbar = L.Class.extend({
return this;
},

onAdd: function() {},
onAdd: function(map) {
var currentToolbar = map._toolbars[this._toolbar_type];

if (this._calculateDepth() === 0) {
if (currentToolbar) { map.removeLayer(currentToolbar); }
map._toolbars[this._toolbar_type] = this;
}
},

onRemove: function(map) {
if (this._calculateDepth() === 0) {
delete map._toolbars[this._toolbar_type];
}

onRemove: function() {
/* Cleanup event listeners. */
for (var i = 0, l = this._disabledEvents.length; i < l; i++) {
L.DomEvent.off(this._ul, this._disabledEvents[i], L.DomEvent.stopPropagation);
Expand Down Expand Up @@ -104,6 +116,23 @@ L.Toolbar = L.Class.extend({

L.toolbar = {};

var toolbar_class_id = 0;

L.Toolbar.extend = function extend(props) {
var statics = L.extend({}, props.statics, {
"_toolbar_class_id": toolbar_class_id
});

toolbar_class_id += 1;
L.extend(props, { statics: statics });

return L.Class.extend.call(this, props);
};

L.Map.addInitHook(function() {
this._toolbars = {};
});

L.ToolbarAction = L.Handler.extend({
statics: {
baseClass: 'leaflet-toolbar-icon'
Expand Down Expand Up @@ -212,10 +241,13 @@ L.Toolbar.Control = L.Toolbar.extend({
onAdd: function(map) {
this._control.addTo(map);

L.Toolbar.prototype.onAdd.call(this, map);

this.appendToContainer(this._control.getContainer());
},

onRemove: function(map) {
L.Toolbar.prototype.onRemove.call(this, map);
this._control.removeFrom(map);
}
});
Expand Down Expand Up @@ -260,6 +292,8 @@ L.Toolbar.Popup = L.Toolbar.extend({
this._map = map;
this._marker.addTo(map);

L.Toolbar.prototype.onAdd.call(this, map);

this.appendToContainer(this._marker._icon);

this._setStyles();
Expand All @@ -268,6 +302,8 @@ L.Toolbar.Popup = L.Toolbar.extend({
onRemove: function(map) {
map.removeLayer(this._marker);

L.Toolbar.prototype.onRemove.call(this, map);

delete this._map;
},

Expand Down
2 changes: 1 addition & 1 deletion dist/leaflet.toolbar.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ L.Toolbar = L.Class.extend({
if (this._calculateDepth() === 0) {
delete map._toolbars[this._toolbar_type];
}
},

onRemove: function() {
/* Cleanup event listeners. */
for (var i = 0, l = this._disabledEvents.length; i < l; i++) {
L.DomEvent.off(this._ul, this._disabledEvents[i], L.DomEvent.stopPropagation);
Expand Down Expand Up @@ -112,6 +110,8 @@ L.Toolbar = L.Class.extend({
}
});

L.toolbar = {};

var toolbar_class_id = 0;

L.Toolbar.extend = function extend(props) {
Expand Down
11 changes: 7 additions & 4 deletions test/src/ToolbarSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ describe("L.Toolbar", function() {

toolbarTemplate = [L.ToolbarAction];
toolbar = new L.Toolbar({ actions: toolbarTemplate });

toolbar.addTo(map);
});

describe("#onAdd", function() {
Expand All @@ -35,20 +33,22 @@ describe("L.Toolbar", function() {

describe("#addTo", function() {
it("Should add a toolbar to the map.", function() {
toolbar.addTo(map);
expect(map.hasLayer(toolbar)).to.equal(true);
});

it("Should pass along its arguments to each toolbar action factory.", function(done) {
var TestHandler = L.ToolbarAction.extend({
initialize: function(arg1) {
initialize: function(arg1, arg2) {
expect(arg1).to.equal(map);
expect(arg2).to.equal(2);
done();
}
});

toolbar = new L.Toolbar({ actions: [TestHandler] });

toolbar.addTo(map);
toolbar.addTo(map, 2);
toolbar.appendToContainer(container);
});
});
Expand All @@ -67,6 +67,7 @@ describe("L.Toolbar", function() {

describe("#_show", function() {
it("Should set the display of the toolbar container to 'block'", function() {
toolbar.addTo(map);
toolbar.appendToContainer(container);

toolbar._show();
Expand All @@ -76,6 +77,7 @@ describe("L.Toolbar", function() {

describe("#_hide", function() {
it("Should set the display of the toolbar container to 'block'", function() {
toolbar.addTo(map);
toolbar.appendToContainer(container);

toolbar._hide();
Expand All @@ -85,6 +87,7 @@ describe("L.Toolbar", function() {

describe("#_calculateToolbarDepth", function() {
it("Should return 0 for a single toolbar", function() {
toolbar.addTo(map);
expect(toolbar._calculateDepth()).to.equal(0);
});

Expand Down

0 comments on commit 01b7892

Please sign in to comment.