473,396 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Removing an expression set in a stylesheet

Hi,

IE has the ability to setExpressions on stylesheets so you can
calculate the value of the css property through script.

For various reasons I'm wanting to use a side-effect of this to attach
an event to every element of a class in a document (I'm including
content from a lot of large 3rd party content, and iterating over the
entire DOM searching for the classes and then attaching the event is
proving too slow, aswell as being too late post-load as the pages are
long and interaction would ideally occur before onload fires, it's an
embedded IE only solution.)

The solution I'm using is:
<URL: http://jibbering.com/2004/1/setExpression.html >

<style type="text/css">
.chicken {
color:green;
moomin:expression(snork(this));
}
</style>
<script type="text/jscript">
statusCount=0;
function snork(el) {
el.onclick=handler;
window.status=++statusCount;
}
function handler() {
alert("Hi!");
}
</script>
</head>
<body>
<p class="chicken">
A paragraph.
</p>

Obviously this is far from ideal as it means that the onclick handler
is attached everytime the css is evaluated (and this is often!) so I
need to remove the rule after attaching it. However I can't find a
way of doing this!

Changing the className of the objects to something else doesn't
achieve it, playing with the style or runtimeStyle of the object
doesn't, calling removeExpression on the elements style doesn't do
anything. So nothing on the element itself seems to achieve it.

Turning to the stylesheet, none of disabling the entire stylesheet,
removing the rule, changing the cssText etc. seem to do anything and

styleSheetRule.style.removeExpression does not exist which would've
been the assumed way of doing it.

Does anyone know of a way? Setting the snork function to an empty
function does make performance reasonable, but with hundreds of these
classes on the page, it's still too slow - and I'm dealing with big
pages which is why parsing the DOM is too slow.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #1
3 1663
"Jim Ley" <ji*@jibbering.com> wrote in message
news:3f**************@news.cis.dfn.de...
<snip>
Obviously this is far from ideal as it means that the onclick
handler is attached everytime the css is evaluated (and this
is often!) so I need to remove the rule after attaching it.
However I can't find a way of doing this!

<snip>

I couldn't find a way of removing/disabling the expression either and
having added an additional 4 thousand odd chicken class paragraphs to
the test page I could easily see how the expression was a problem as it
renders the rest of the JScript execution sluggish to say the least
(took ages for the handler function to put up the alert).

However, I experimented with adding another styleSheet entry after the
existing ones with a chicken class that would overload the -
moomin:expression(snork(this)); - with - moomin:expression(void 0); -
and when that worked it significantly improved the performance of the
handler function on my modified test page.

Using a test css file:-
---------------- expTest.css ----------------------
..chicken {
moomin:expression(void 0);
}
--------------------------------------------------------
- calling the IE createStyleSheet function in the onload handler:-

document.createStyleSheet('expTest.css');

- or creating an additional link element with the "disabled" attribute
set:-

<link rel="stylesheet" href="expTest.css" type="text/css" disabled>

-and then enabling it in the onload handler with:-

document.styleSheets[2].disabled = false;

- both seemed to broadly work, while creating a disabled STYLE element
and then enabling it in the same way as the link element did not work at
all.

Unfortunately I can only describe this as broadly working because I
notice that on initially loading/enabling the overloading
moomin:expression CSS file with the onload handler caused some of the 4
thousand odd paragraphs not to have the onclick handler set (the ones
toward the end of the HTML). Re-loading the test page resulted in all of
the paragraph onclick handlers being assigned and clearing IE's cache
resurrected the initial problem. Microsoft's documentation implies that
calling - document.recalc - should result in the expressions being
recalculated for all elements (so assigning the onclick handler) but
that did not help.

Richard.
Jul 20 '05 #2
On Fri, 2 Jan 2004 21:08:23 -0000, "Richard Cornford"
<Ri*****@litotes.demon.co.uk> wrote:
However, I experimented with adding another styleSheet entry after the
existing ones with a chicken class that would overload the -
moomin:expression(snork(this)); - with - moomin:expression(void 0); -
and when that worked it significantly improved the performance of the
handler function on my modified test page.


hmm, I think that's equivalent in performance to my snork=function()
{} onload, and I still think that's noticeably a bit slow... It's
very annoying it's such a neat solution...

Cheers,

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #3
"Jim Ley" <ji*@jibbering.com> wrote in message
news:3f**************@news.cis.dfn.de...
<snip>
hmm, I think that's equivalent in performance to my
snork=function() {} onload, and I still think that's
noticeably a bit slow... It's very annoying it's such
a neat solution...


I tried a version of - snork=function(){}; - but I thought the void
expression was still much quicker (probably because there is no overhead
in calling the function).

However, kicking the problem about a bit more revealed some possibly
useful information. I had changed the status line report to:-

window.status=++statusCount+' '+el.style.getExpression("moomin");

- and unsurprisingly that just appended "undefined" to the status
report, until one of my experiments caused me to change the snork
function to return a string (but any non-undefined return value seems to
work). When I had done that I noticed that the first (4 thousand odd)
call(s) to snork appended "undefined" but from then on "snork(this)"
was appended. That means that with the first call to snork with a return
value the expression is somehow attached to the P element's style
object.

That prompted me to try calling - removeExpression - on the style
object. It appears that IE will not put up with - removeExpression -
being called from within snork so I did a quick experiment with
recording the P element's style objects in an array and then using
onload to run through the array calling - removeExpression("moomin"); -
on each recorded style object. That actually appears to work, but only
in combination disabling - document.styleSheets[0]; -.

This is the page I was testing with (I was testing locally so the URL
for the external CSS is not the original, and I have cut most of the P
elements from the test page):-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>removeExpression Demo.</title>
<style type="text/css">
.chicken {
color:green;
moomin:expression(snork(this));
}
</style>
<link rel="StyleSheet" href="jibbering2.css" type="text/css">
<script type="text/jscript">
var toRemoveExp = [];
statusCount=0;
function snork(el) {
el.onclick=handler;
window.status=++statusCount+' '+el.style.getExpression("moomin");
if(el.style.getExpression("moomin")){
toRemoveExp[toRemoveExp.length] = el.style;
}
return 1;
}
function handler() {
alert("Hi! "+this.style.getExpression("moomin"));
}
window.onload=function() {
var ss=document.styleSheets[0];
ss.disabled=true;
for(var c = toRemoveExp.length;c--;){
toRemoveExp[c].removeExpression("moomin");
}
}
</script>

</head>
<body>
<h1></h1>
<p class="intro">An example of removeExpression failing in IE6,
this is an IE proprietary feature, so expect to see nothing
much if you're using other browsers.</p>

<div id="content">

<p class="chicken">
A paragraph.
</p>
<p class="chicken">
Another paragraph.
</p>
<!-- Repeat the previous 6 lines 2000 times -->

</div>
<p class="footer">Jim Ley - <a
href="mailto:ji*@jibbering.com">ji*@jibbering.com</a>, <a
href="/">Jibbering.com</a></p>
</body>
</html>

There are more elegant and efficient ways of arranging which style
objects to call - removeExpression - on, and I did notice that the
problem with some of the final P elements no getting the onclck handler
assigned on the initial load was still happening, but at least this does
demonstrate that the expressions can be removed.

Richard.
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: wooks | last post by:
I would appreciate some guidance not just to the solution but why my own solutions don't seem to work. Copy.xsl in the code below is an imported identity template. Non solution 1...
7
by: Simon Hart | last post by:
Hi, I have a requirement to remove the xmlns from the DOM in order to pass over to MS CRM 3.0 Fetch method.It seems the fetch method blows up if there is a xmlns present!?! The reason I have a...
5
by: John Blogger | last post by:
(I don't know if it is the right place. So if I am wrong, please point me the right direction. If this post is read by you masters, I'm honoured. If I am getting a mere response, I'm blessed!) ...
6
by: Chris Chiasson | last post by:
Hi, After reading and experimenting for a several hours, I have this stylesheet: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.