473,765 Members | 2,066 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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:expressi on(snork(this)) ;
}
</style>
<script type="text/jscript">
statusCount=0;
function snork(el) {
el.onclick=hand ler;
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 removeExpressio n 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.removeExp ression 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.javas cript FAQ - http://jibbering.com/faq/

Jul 20 '05 #1
3 1692
"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:expressi on(snork(this)) ; - with - moomin:expressi on(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:expressi on(void 0);
}
--------------------------------------------------------
- calling the IE createStyleShee t function in the onload handler:-

document.create StyleSheet('exp Test.css');

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

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

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

document.styleS heets[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:expressi on 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*****@litote s.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:express ion(snork(this) ); - with - moomin:expressi on(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.javas cript 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.getE xpression("moom in");

- 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 - removeExpressio n - on the style
object. It appears that IE will not put up with - removeExpressio n -
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 - removeExpressio n("moomin"); -
on each recorded style object. That actually appears to work, but only
in combination disabling - document.styleS heets[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>removeEx pression Demo.</title>
<style type="text/css">
.chicken {
color:green;
moomin:expressi on(snork(this)) ;
}
</style>
<link rel="StyleSheet " href="jibbering 2.css" type="text/css">
<script type="text/jscript">
var toRemoveExp = [];
statusCount=0;
function snork(el) {
el.onclick=hand ler;
window.status=+ +statusCount+' '+el.style.getE xpression("moom in");
if(el.style.get Expression("moo min")){
toRemoveExp[toRemoveExp.len gth] = el.style;
}
return 1;
}
function handler() {
alert("Hi! "+this.style.ge tExpression("mo omin"));
}
window.onload=f unction() {
var ss=document.sty leSheets[0];
ss.disabled=tru e;
for(var c = toRemoveExp.len gth;c--;){
toRemoveExp[c].removeExpressi on("moomin");
}
}
</script>

</head>
<body>
<h1></h1>
<p class="intro">A n example of removeExpressio n 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 - removeExpressio n - 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
1585
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 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:import href="copy.xsl"/> <xsl:template match="//text()"/>
7
2980
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 xmlns present is because the Xml I am passing to CRM is a node from a bigger file that does require a xmlns and using the DOM ..OuterXml seems to set the xmlns for you automatically - which I don't want. Any help would be great.
5
1593
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!) Hi, I'm a newbie regular expression user. I use regex in my Python programs. I have a strange
6
2065
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" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xmlns="http://www.w3.org/2000/xmlns/" xmlns:mathematica="http://www.wolfram.com/XML/" version="1.0">
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10007
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9835
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8833
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3926
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.