Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New listener for tools #89

Closed
Sharath-GitBan opened this issue Jun 10, 2020 · 6 comments
Closed

New listener for tools #89

Sharath-GitBan opened this issue Jun 10, 2020 · 6 comments

Comments

@Sharath-GitBan
Copy link

Hi Team,

I was going through code for each tool in the app, right now the listeners available for each tool are press, move and release. Can I add new listeners like click or db click or hover etc to the existing code.
It'll be helpful if you can help me on this.

@lovasoa
Copy link
Owner

lovasoa commented Jun 10, 2020

Hello,
Yes, you can use any DOM event as a listener, just add it to the compiledListeners property of your tool.

	var myTool = {
		"name": "MyNewTool",
		"shortcut": "m",
		"listeners": {
			"press": startLine,
			"move": continueLine,
			"release": stopLineAt,
		},
               "compiledListeners": {
                       "dblclick": myListener
               }, ...

For hover, I would use the existing move listener, though. See for instance the eraser.

The relevant part of the code you may want to read is here : https://github.com/lovasoa/whitebophir/blob/master/client-data/js/board.js#L497-L513

edit : fixed example. The property name iscompiledListeners, not computedListeners

@lovasoa lovasoa closed this as completed Jun 10, 2020
@Sharath-GitBan
Copy link
Author

Hello, thank you for your response, I added 'click' listener to the tool, but when I click after selecting the tool, even listener is not triggered.

@lovasoa
Copy link
Owner

lovasoa commented Jun 10, 2020

If you publish your fork, I'll have a look at it if you want.

@Sharath-GitBan
Copy link
Author

function myListener(){
console.log('in click listener')
}
Tools.add({
//The new tool
name: "Resize Element",
icon: "✥✥",
shortcut: "R",
computedListeners: {
click: myListener
},
listeners: {
press: press,
move: move,
release: release
},
//draw: draw, //save move text to server
mouseCursor: "crosshair"
});

@Sharath-GitBan
Copy link
Author

It should be compiledListeners not computedListeners

@lovasoa
Copy link
Owner

lovasoa commented Jun 15, 2020

Oh, I see. I wrote the right name in my message above, but made a mistake in the example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants