Created
May 11, 2015 13:18
-
-
Save odoe/9ab37ead405f53ec67c7 to your computer and use it in GitHub Desktop.
Sample widget wit dojo/topic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'dojo/_base/declare', | |
'dojo/topic', | |
'dojo/dom', | |
'dojo/dom-construct', | |
'./BasemapSwitcher', | |
'dijit/_WidgetBase', | |
'dijit/_TemplatedMixin', | |
'dojo/text!./templates/Template.html' | |
], function( | |
declare, topic, | |
dom, domConstruct, | |
BasemapSwitcher, | |
_WidgetBase, _TemplatedMixin, | |
template | |
) { | |
return declare([_WidgetBase, _TemplatedMixin], { | |
templateString: template, | |
constructor: function() { | |
this.toolHidden = true; | |
}, | |
postCreate: function() { | |
var target = this.domNode; | |
var node = domConstruct.create('div', { | |
className: 'basemaps-container' | |
}, target); | |
this.switcher = new BasemapSwitcher({ | |
map: this.get('map') | |
}); | |
this.own(topic.subscribe('widget-tool-show', function(a) { | |
if (a.type !== 'basemaps' && !this.toolHidden) { | |
this.toggle(); | |
} | |
}.bind(this))); | |
}, | |
toggle: function(e) { | |
if (e) e.preventDefault(); | |
if (this.toolHidden) { | |
topic.publish('widget-tool-show', { tool: 'basemaps' }); | |
this.switcher.show(); | |
} else { | |
topic.publish('widget-tool-hide', { tool: 'basemaps' }); | |
this.switcher.hide(); | |
} | |
this.toolHidden = !this.toolHidden; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment