Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

attached behaviors not working for lightweight components

2 views
Skip to first unread message

Tom Power

unread,
Jan 22, 2003, 12:24:07 AM1/22/03
to

Hi, I hope someone can help me on this.

I'm building a bunch of lightweight htc components. I used to build them as
viewlinked ones
but the load time was unacceptable, because each component had it's own DOM.

The lightweight components work well, but I can't attach behaviors the
custom element.

I've tested, by changing the lightweight attribute on the component tag from
true to false, and then
the behavior attaches to the custom element.

Please try the following code - it's very simple and demonstrates the
problem.

*** File1 - call it pTag.htc - this is the custom element implementation
code
<public:component tagName="mytag" lightweight="false" >
</public:component>

<script>
var pTag = element.appendChild(element.document.createElement('<p>'));
pTag.innerText = 'P tag to which behavior is attached: text should be
colored red'
</script>


*** File2 - call it changeColor.htc - this is the attached behavior
implementation code
<public:component>
<public:attach event="oncontentready" onevent="oncontentready_element()" />
</public:component>

<script>
alert('the behavior attached')
function oncontentready_element(){
element.style.color = 'red';
}
</script>


*** File 3 - call it test.htm - this is the html code that uses the htcs
<html xmlns:myhtc>
<head>
<?import namespace="myhtc" implementation="pTag.htc" >
<style>
.changeColor
{
behavior: url('changeColor.htc');
}
</style>
</head>
<body>
<myhtc:mytag class="changeColor" />
<p class="changeColor">Another P tag to which behavior is attached (text
should be colored red)</p>
</body>
<html>


Create the files all in the same directory, then open test.htm with IE5.5 or
above.
You should get two alerts as the changeColor.htc behavior attaches, 1st to
the custom tag <myhtc:mytag>, then to the <P> tag.

Change the lightweight attribute to false in pTag.htc, and you only get one
alert (for the P tag)

My understanding of the lightweight attribute is that when set to true, the
HTC doesn't have it's own DOM, hence the noticable performance gains,
particularly if you have 20 instances of the same custom tag on a page.


Cheers,
Tom.


DaveM

unread,
Jan 22, 2003, 9:55:37 AM1/22/03
to
Hi Tom,

First, your confusing "lightWeight" with the ViewLink technology.

"lightWeight" means the HTC does not contain any markup and therefore does
not need to be parsed (hence an improvement gain).

"viewLinkContent" toggles whether or not the behavior will have it's own,
seperate DOM to protect it from changes in the host document.

Now, based on the documentation on the "lightWeight" attribute, it seems to
me that what you are doing should work since the doco states that:
"If the HTC file contains no markup, this attribute should be set to
true to improve rendering performance."

However, based on what it's doing, I would suggest that since the behavior
is an element behavior, turning on "lightWeight" actually tells the browser
the new, custom tag contains no markup and does not need to be parsed. Of
course, the behavior is actually inserting markup into the custom element
and obviously that is being rendered but perhaps it doesn't bother to take a
second pass through that new markup to see if any styles might apply? Or
perhaps when it goes to attach the "changeColor" behavior, it sees that
"lightWeight" is true and thinks the element does not contain markup rather
than the HTC file itself?

Just a few guesses and probably wrong at that... sorry.

"Tom Power" <To...@xsolREMOVETHIS.com> wrote in message
news:u$vtYadwCHA.2532@TK2MSFTNGP10...

Fotios

unread,
Jan 22, 2003, 10:12:44 AM1/22/03
to
Hi Tom,

This looks like a bug whereby the custom tag will not process the class tag
attribute if the element behavior is lightweight.

I originally assumed it was a timing related error that happened becuase the
lightweight version of the the element behavior initialized faster than the
non-lightweight one, but this does not seem to be the case.

I would assume it is a bug and I would bypass it thus:

<html xmlns:myhtc>
<head>
<?import namespace="myhtc" implementation="pTag.htc" >
<style>
.changeColor
{
behavior: url('changeColor.htc');
}
</style>
</head>
<body>

<myhtc:mytag />


<p class="changeColor">Another P tag to which behavior is attached (text
should be colored red)</p>

<script>
var a = document.getElementsByTagName('mytag');
var n = a[0];

n.className = 'changeColor';
</script>

</body>
<html>

This works over here. If it turns out to be a timing related problem after
all, try putting n.className = 'changeColor';
inside a setTimeout().

Take care,
Fotios

--

http://www.nkd-webmedia.co.uk/
http://fotios.cc/

ICQ: 8976921

PGP: 5302 C2EB E6BA 0768 1E13
9B98 3335 E6C6 93B9 B5C6


"Tom Power" <To...@xsolREMOVETHIS.com> wrote in message
news:u$vtYadwCHA.2532@TK2MSFTNGP10...
>

Tom Power

unread,
Jan 22, 2003, 4:22:44 PM1/22/03
to
Hi Dave,
thank you for taking the time to reply.
 
You'll find in the documentation (but not in an obvious place) that it is the lightweight attribute that controls whether the HTC has
 
Therefore, when it is possible for a component to be implemented without its own document tree, a lightweight component should be implemented by specifying the new "lightweight" attribute on the PUBLIC:COMPONENT element.
 
The way to see this is to put an alert inside pTag.htc: alert(document). When lightweight=false, you get an alert of the document object. When lightweight=true, you get an "Access Denied" exception, because there is no document object inside a lightweight htc.
 
My example of changing color was probably a bit misleading in that it suggests I'm wanting to use attached behaviors to change the look of the element. My objective is to be able to attach more useful behaviors (eg movable.htc) to my elements.
 
The other post to this message seems to solve the problem - it appears to be a timing issue. Attaching the behavior after the lightweight element has parsed seems to work.
 
Cheers,
Tom.
 

Tom Power

unread,
Jan 22, 2003, 5:06:58 PM1/22/03
to

Thank you!

"Fotios" <fot...@altavista.net> wrote in message
news:3e2eb504$0$33930$bed6...@news.gradwell.net...

0 new messages