The My Opera forums have been replaced with forums.opera.com. Please head over there to discuss Opera's products and features

See the new Forums

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

29. September 2011, 16:11:18

sfriman

Posts: 3

How to spawn Icon?

How can I create icon at mouse cursor position like in In-Place Translator extension?
Do I need to use external API like jQuery or there is a better way?

30. September 2011, 11:34:06

d4n3

Posts: 957

Typically, you would use DOM manipulation directly, as jQuery is pretty heavyweight and you can't safely embed it in any page (especially if the page extends Object.prototype which breaks jQuery).

Since you don't have to worry about IE compatibility you can use methods like addEventListener and querySelectorAll.

As for your specific problem, you would have to tell us more about what you are trying to do. Show an icon when you select some text?

You could have a look in the sources of the In-place translator extension to see how they did it and then adapt that. (you can download the oex and just unzip it). Most of the extension have an open source license, so that shouldn't be a problem.

30. September 2011, 14:48:15

sfriman

Posts: 3

I appreciate Your help.
I have just cracked inside In-Place translator and it appears all magic is done by using DOM manipulation as you, d4n3, suggested. I think I'll use this approach too. My injected script will monitor mouseup event and if user will select text it will display a window with translation results. Results will be more detail. Well, it will take for me a little time to find good API documentation and study it.
Next objective is to fetch only useful part of translation site result page (I want to use lingvo.abbyyonline.com)

22. October 2011, 13:15:59

sfriman

Posts: 3

I placed icon by creating div and appending to page. But how can I add to this div background which is icon packaged with my extension? How to reference this icon?

23. October 2011, 10:38:42

d4n3

Posts: 957

you cant directly reference a widget file from an injected page.

your best bet would be to pack the icons in data urls.

Forums » Dev.Opera » Opera Extensions Development Discussions