Sign up | Lost password? | Help

[ advanced search ]

Saturday, 21. January 2006, 15:45:02

d.i.z.

avatar

bug hunter

Posts: 2933

Poland

Live DOM Viewer

Converted it into user js:
LiveDomViewer.js
Invoked with CTRL+ALT+double_click

Just the DOM Viewer part. Tag names are clickable to reveal computed style properties.

Thanks to Ian Hickson and aleto.

Screenshot: LiveDOM.png

Tuesday, 24. January 2006, 04:15:08

xErath

avatar

javascript guru

Posts: 6399

Norway

Opera Software

a advice - to export the least symbols as possible and therefore not pollute the global window namespace and prevent collisions, declare all function before the dblclick listener, and wrap the entire script with (function(){ ...code here... })();. Also, declare ALL variables as local.

Tuesday, 24. January 2006, 12:23:14

Stoen

avatar

Posts: 1109

The script fails for non standard tags as seen in the hide-objects UserJS. The attributes collection for non standard tag seems to be undefined. Probably something that should be changed in that script though...

Thursday, 26. January 2006, 23:03:15 (edited)

d.i.z.

avatar

bug hunter

Posts: 2933

Poland

Originally posted by xErath:

a advice - to export the least symbols as possible and therefore not pollute the global window namespace and prevent collisions, declare all function before the dblclick listener, and wrap the entire script with (function(){ ...code here... })();. Also, declare ALL variables as local.


I've tried to fix it, but one function can not be made local as it's executed when user clicks tag name.
And is there a way in javascript to explicitly declare local variable? How to do it (prepend it with var)? [edit: It seems so when I'm testing this now :smile: But I can't for example define local popup window with window.open(), because then, function that prints DOM won't find it.]

Originally posted by Stoen:

The script fails for non standard tags as seen in the hide-objects UserJS. The attributes collection for non standard tag seems to be undefined. Probably something that should be changed in that script though...


Getting computed styles for such elements is failing, but the DOM tree shows them (with attributes) here without problems. Or you are talking about something else?

I've updated the script. Now it also shows tag properties and methods in popup window (once again, I borrowed code from someone but I don't remember who :wink: ).
LiveDomViewer.js

Friday, 27. January 2006, 00:23:36 (edited)

Stoen

avatar

Posts: 1109

Originally posted by d.i.z.:

Getting computed styles for such elements is failing, but the DOM tree shows them (with attributes) here without problems. Or you are talking about something else?


The script fails on this line
if (node.childNodes[[b][/b]i].attributes[j].specified) {
Its not the whole collection that is undefined, it says the length of the attributes collection for the custom element as found in hide-objects is 1. But attributes[0] is undefined and the script then fails at the above line.

Edit: Any custom element with a style attribute will result in the same thing. Otherwise custom elements work as you described

Friday, 27. January 2006, 00:47:49

d.i.z.

avatar

bug hunter

Posts: 2933

Poland

Originally posted by Stoen:

Originally posted by d.i.z.:

Getting computed styles for such elements is failing, but the DOM tree shows them (with attributes) here without problems. Or you are talking about something else?


The script fails on this line
if (node.childNodes[[b][/b]i].attributes[j].specified) {
Its not the whole collection that is undefined, it says the length of the attributes collection for the custom element as found in hide-objects is 1. But attributes[0] is undefined and the script then fails at the above line.

Edit: Any custom element with a style attribute will result in the same thing. Otherwise custom elements work as you described


I see now. Quick fix could look like this:
if (node.childNodes[i].attributes[j] && node.childNodes[i].attributes[j].specified) {

although this is dirty fix as it will skip some attributes. I'm not really into this problem but it looks like it may be an Opera bug. Or maybe it's because we try to use custom tags in HTML which (I guess) is illegal?

Sunday, 29. January 2006, 13:43:12

d.i.z.

avatar

bug hunter

Posts: 2933

Poland

I'm sorry but this script shows some completly unrelated data while clicking on tag names. Trying to fix it now.

Sunday, 29. January 2006, 17:26:51 (edited)

d.i.z.

avatar

bug hunter

Posts: 2933

Poland

Ok, I fixed this script.
Now it shows computed styles inline (which can get painfully slow because of 'overflow: auto' btw. :wink: )

Oh, and whole script is in one anonymous function (it was possible it seems :smile: )

Can someone tell me, which method is generally faster - innerHTML or DOM compliant element creation?

It's here and in first post:
LiveDomViewer.js

Tuesday, 31. January 2006, 16:02:19

hesido

avatar

Posts: 719

Turkey

Hey DIZ, this is cool :smile: Thanks..

Thursday, 2. February 2006, 05:48:25

STNG

avatar

Posts: 163

Thanks for great UserJS-addon.

Thursday, 2. February 2006, 07:16:14

xErath

avatar

javascript guru

Posts: 6399

Norway

Opera Software

Originally posted by d.i.z.:

Can someone tell me, which method is generally faster - innerHTML or DOM compliant element creation?

DOM compliant element creation of course, but you'll have to work over a document fragment otherwise doing dom tree operation will force re-flows which can drastically slow down the code.

Thursday, 2. February 2006, 15:05:05

hesido

avatar

Posts: 719

Turkey

BTW, there is also something that can be done: Cloning nodes instead of creating new ones, but I am not sure if it is faster on Opera, it is said to be faster on some browser, you need to check it for yourself:
http://verens.com/archives/2006/01/09/clonenode-caching/

Thursday, 2. February 2006, 23:16:38

Stoen

avatar

Posts: 1109

Is there a way to get this script to work on xhtml or xml pages that dont support document.write?

Friday, 3. February 2006, 21:19:53

d.i.z.

avatar

bug hunter

Posts: 2933

Poland

Originally posted by Stoen:

Is there a way to get this script to work on xhtml or xml pages that dont support document.write?


Do you have some to URI to xhtml or xml document?

Saturday, 4. February 2006, 04:54:50

xErath

avatar

javascript guru

Posts: 6399

Norway

Opera Software

Originally posted by d.i.z.:

Some say that innerHTML is faster

I did my own testing, but unlike quirksmode testing which creates the html and renders it, my script continuously appended pieces of HTML to the dom tree, becoming slower and slower as the html grew, while dom methods always spent the same amount of time.

Saturday, 4. February 2006, 09:05:20

hesido

avatar

Posts: 719

Turkey

xErath, that's a nice finding, so there's probably a limit where dom methods start to benefit. And a dom tree has quite many number of items so it probably should. Also, cloneNode may be an option, but it is said that it does not speed things up in Opera.


Forums » Opera Community » General Opera topics » User JavaScript