Code coverage report for src/ToolbarAction.js

Statements: 76.6% (36 / 47)      Branches: 50% (9 / 18)      Functions: 77.78% (7 / 9)      Lines: 90% (36 / 40)      Ignored: none     

All files » src/ » ToolbarAction.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 951                             18   18 18       4 4 4   4       2 2   2       12   12 12 12   12 12 12   12 12 2     12     12       14         14   14   1 1   1 1   1         1               1 1     1 1    
L.ToolbarAction = L.Handler.extend({
	statics: {
		baseClass: 'leaflet-toolbar-icon'
	},
 
	options: {
		toolbarIcon: {
			html: '',
			className: '',
			tooltip: ''
		},
		subToolbar: new L.Toolbar()
	},
 
	initialize: function(options) {
		var defaultIconOptions = L.ToolbarAction.prototype.options.toolbarIcon;
 
		L.setOptions(this, options);
		this.options.toolbarIcon = L.extend({}, defaultIconOptions, this.options.toolbarIcon);
	},
 
	enable: function(e) {
		Iif (e) { L.DomEvent.preventDefault(e); }
		Iif (this._enabled) { return; }
		this._enabled = true;
 
		Iif (this.addHooks) { this.addHooks(); }
	},
 
	disable: function() {
		Iif (!this._enabled) { return; }
		this._enabled = false;
 
		Iif (this.removeHooks) { this.removeHooks(); }
	},
 
	_createIcon: function(toolbar, container, args) {
		var iconOptions = this.options.toolbarIcon;
 
		this.toolbar = toolbar;
		this._icon = L.DomUtil.create('li', '', container);
		this._link = L.DomUtil.create('a', '', this._icon);
 
		this._link.innerHTML = iconOptions.html;
		this._link.setAttribute('href', '#');
		this._link.setAttribute('title', iconOptions.tooltip);
 
		L.DomUtil.addClass(this._link, this.constructor.baseClass);
		if (iconOptions.className) {
			L.DomUtil.addClass(this._link, iconOptions.className);
		}
 
		L.DomEvent.on(this._link, 'click', this.enable, this);
 
		/* Add secondary toolbar */
		this._addSubToolbar(toolbar, this._icon, args);
	},
 
	_addSubToolbar: function(toolbar, container, args) {
		var subToolbar = this.options.subToolbar,
			addHooks = this.addHooks,
			removeHooks = this.removeHooks;
 
		/* For calculating the nesting depth. */
		subToolbar.parentToolbar = toolbar;
 
		if (subToolbar.options.actions.length > 0) {
			/* Make a copy of args so as not to pollute the args array used by other actions. */
			args = [].slice.call(args);
			args.push(this);
 
			subToolbar.addTo.apply(subToolbar, args);
			subToolbar.appendToContainer(container);
 
			this.addHooks = function(map) {
				if (typeof addHooks === 'function') { addHooks.call(this, map); }
				subToolbar._show();
			};
 
			this.removeHooks = function(map) {
				if (typeof removeHooks === 'function') { removeHooks.call(this, map); }
				subToolbar._hide();
			};
		}
	}
});
 
L.toolbarAction = function toolbarAction(options) {
	return new L.ToolbarAction(options);
};
 
L.ToolbarAction.extendOptions = function(options) {
	return this.extend({ options: options });
};