Skip to content

Instantly share code, notes, and snippets.

@odoe
Created May 11, 2015 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/9ab37ead405f53ec67c7 to your computer and use it in GitHub Desktop.
Save odoe/9ab37ead405f53ec67c7 to your computer and use it in GitHub Desktop.
Sample widget wit dojo/topic
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