Parag
Parag

Reputation: 963

Reinitialize (or Re-declare) Dojo widget

I have a piece of code that initialises a resize handler in the following way:

dojo._hasResource["dojox.layout.ResizeHandle"] = true;
dojo.provide("dojox.layout.ResizeHandle");
dojo.experimental("dojox.layout.ResizeHandle");
dojo.declare("dojox.layout.ResizeHandle", [dijit._Widget, dijit._Templated], {
   _init: function(){},
   create: function(){
      this.connect(this.resizeHandle, "mouseover", "_init");
   }
   // ... more properties
});

This is written in a core app file which I cannot edit. I need to rebind this resize handler to respond to touch events. I was thinking of overwriting this widget and rebind the resize handler with "touch" events. Something like so,

this.connect(this.resizeHandle, "touchstart", "_init");

I have never worked on Dojo before. So, I am not sure how the module system works. I tried creating a new widget by changing the string that identifies the widget ("dojox.layout.ResizeHandle") but no luck there.

How do I destroy the existing widget and rebind with touch events?

Upvotes: 1

Views: 297

Answers (1)

Matt R
Matt R

Reputation: 734

This code does not initialize a widget. The declare function creates a class. In this case it creates a class called "dojox.layout.ResizeHandle". To use this class you need to require it and then instantiate it. Something like this

require(["dojox/layout/ResizeHandle"], function(ResizeHandle) {
    var resize = new ResizeHandle();
} 

From there you can attach new handlers.

on(resize.resizeHandle, "touchstart", "_init);

It's also worth pointing out that you are using old deprecated dojo syntax (connect vs on, etc) although you may be using an older version of dojo.

Upvotes: 1

Related Questions