473,548 Members | 2,691 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

[FireFox] parent object for style in setter

Hi,

this is my code:

CSSStyleDeclara tion.prototype. __defineSetter_ _('display',
displaySetter);

function displaySetter(v alue) {
var parent = findParent(docu ment, this);
if (parent) {
if (parent.tagName == 'TD'
&& value.toLowerCa se() == 'inline' ) {
value = 'table-cell';
}
}
this.setPropert y('display', value , 'important');
}
function findParent(obj, style) {
var nodes = obj.childNodes;
if (obj.style == style) {
return obj;
}
for(var i = 0; i < nodes.length; i++) {
var suBsearchResult = findParent(node s[i], style);
if (suBsearchResul t) {
return suBsearchResult ;
}
}
return false;
}

As you can see each time I need to scan whole document for parent which

I would like to avoid. Is there any other way to get an object on which
style is applied to?

Mar 9 '06 #1
4 2223
ja***@katnik.pl wrote:
CSSStyleDeclara tion.prototype. __defineSetter_ _('display',
displaySetter);

function displaySetter(v alue) {
var parent = findParent(docu ment, this);
if (parent) {
if (parent.tagName == 'TD'
Should be

if (parent.tagName .toLowerCase() == 'td'
&& value.toLowerCa se() == 'inline' ) {
value = 'table-cell';
}
}
this.setPropert y('display', value , 'important');
}
function findParent(obj, style) {
var nodes = obj.childNodes;
You should place this line after the following block. It will not matter
for the variable instantiation (which is done before execution), but it
will matter for the assignment which is unnecessary if the condition in
the following IfStatement yields `true' (and so the execution context
is exited).

And since this is about the `style' property of `td' element objects,
you do not need to traverse all child nodes (including !td element nodes
and text nodes). Try Document::getEl ementsByTagName ("td"), or use XPath
and `//td' which is semantically equivalent in XML document types. Even
more efficient are HTMLBodyElement ::getElementsBy TagName("td") or
`//body//*' (IIRC).

And if it was about any element, you would still not have to traverse
text nodes: Document::getEl ementsByTagName ("*") or XPath `//*'.
if (obj.style == style) {
return obj;
}
for(var i = 0; i < nodes.length; i++) {
More efficient is

for (var i = nodes.length; i--;) {
[...]
As you can see each time I need to scan whole document for parent which
I would like to avoid. Is there any other way to get an object on which
style is applied to?


I am afraid the answer is no. There is nothing in the W3C DOM Level 2 Style
Specification or the Gecko DOM Reference that supports the assumption that
the object referred to with a property of the `style' property of element
objects can know about the owner object of this property.

I wonder why you find this necessary anyway. Since this is obviously
Gecko-specific code, would it not be better to create and append a new,
or modify an existing `style' element for the `td' element instead?
That said, since when are `td' elements inline-level elements by default
with Gecko?
PointedEars
Mar 9 '06 #2
Thanks for yours answer, I found it very usefull.
I wonder why you find this necessary anyway.

I have to refactor huge buissness application, witch was intended to
work under IE only, to work under FireFox also. It consist of up to 100
JSPs with lots of DHTML. So I decided to modify FF behaviours in that
way that it will the same API as IE.
For instance:

//unhiding table cell
var aCell = getElementById( 'someCell');
aCell.style.dis play = 'inline'; //fires setter which maps 'inaline' to
'table-cell'

I have another question.
Is there any way to do this same with static style definition?
For example:
<td style="display: inline">

Best regards
Jarek

Mar 10 '06 #3
ja***@katnik.pl wrote:
^^^^^^^^^^^^^^^
I would appreciate it if you posted with your real name (which can
include a nickname).
Thanks for yours answer, I found it very usefull.
You are welcome. Please also provide attribution next time:

<URL:http://jibbering.com/faq/faq_notes/pots1.html#ps1P ost>
I wonder why you find this necessary anyway.


I have to refactor huge buissness application, witch was intended to
work under IE only, to work under FireFox also. It consist of up to 100
JSPs with lots of DHTML. So I decided to modify FF behaviours in that
way that it will the same API as IE.

For instance:

//unhiding table cell
var aCell = getElementById( 'someCell');


Am I correct assuming that getElementById( ) is a wrapper method for
document.getEle mentById()?
aCell.style.dis play = 'inline'; //fires setter which maps 'inaline' to
'table-cell'
This approach is highly questionable since it is not future-proof. What
if IE is standards compliant in this regard one day? What if it supports
prototyping element objects or setters one day?

You should do this the other way around. Most certainly a method is called
to set the value of the `display' property. You should determine if the
target element is a `td' element, and if yes, set the `display' property to
`table-cell' as Web standards call for. IIRC, if IE does not support a
property value, the previous value is restored. So you could test if the
value after the assignment is "table-cell", and if it is not, you would
assign "inline" as supported by current IE-based UAs:

var aCell = getElementById( 'someCell');
if (aCell
&& typeof aCell.style != "undefined"
&& typeof aCell.style.dis play != "undefined"
&& (aCell.tagName. toLowerCase() != 'td'
|| (aCell.style.di splay = 'table-cell') != 'table-cell'))
{
aCell.style.dis play = 'inline';
}

I cannot test with IE or an IE-based UA here. If the above works
for you, I am going to include it in my setStylePropert y() method.
I have another question.
Is there any way to do this same with static style definition?
For example:
<td style="display: inline">


I do not understand what you mean by that. Certainly this is
Valid markup and Valid CSS (though unreliable[1]) ... and now? :)
Regards,
PointedEars
___________
[1] <URL:http://www.w3.org/TR/CSS2/tables.html#q2>
Mar 10 '06 #4
ja***@katnik.pl wrote:
function findParent(obj, style) {
var nodes = obj.childNodes;
if (obj.style == style) {
return obj;
}
for(var i = 0; i < nodes.length; i++) {
var suBsearchResult = findParent(node s[i], style);
if (suBsearchResul t) {
return suBsearchResult ;
}
}
return false;
}

I would like to avoid. Is there any other way to get an object on which
style is applied to?


Recursive calls are expensive, implement the stack on your code.

So, I don't know a better way to do this, but the two functions bellow
work reasonably faster (I tested with a large number of siblings and
also with nested nodes). But take a look, maybe there's something wrong
on my code :)

//this one worked faster than the other...
function findParent(s){
var x = [], n = document.childN odes, i;
do
for(i = n.length; i;)
if((o = n.item(--i)).style == s)
return o;
else if(o.hasChildNo des())
x.push(o.childN odes);
while(n = x.pop());
return null;
}

function findParent(s){
for(var x = document.getEle mentsByTagName( "*"), i = x.length, o; o =
x.item(--i);)
if(o.style == s)
return o;
return null;
}
--
Now with alcohol <URL:http://youtube.com/watch?v=lnQTZxq xc10> =X
Jonas Raoni Soares Silva
http://www.jsfromhell.com
Mar 12 '06 #5

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

Similar topics

3
3341
by: jimmygoogle | last post by:
I posted earlier with a scope problem. I think I resolved it in IE but in Firefox it still exists. Anyone have any ideas/experience with this? I attached my code sorry it is so long. You can cut/paste it into 2 files and run it to see what I mean. ###############menu.html############### <html> <body> <script type="text/javascript">
5
3497
by: Martin Chen | last post by:
I have a frame set (as per MS FrontPage 2000). It has a contents and a main frame. The contents frame has a menu bar written with with javascript (in the context of a table). In IE6.1 everything works fine as it also does in firefox if I call the contents frame directly (i.e. outside of its frameset). However, if I call my main page...
3
6108
by: Jake G | last post by:
Ok. I have figured out my whole script except how to make it work in FF. It is a script that lets a user know how many characters they have left for a textbox. Here is the code, is anyone savy enough to tell me why this wont work in FF? Any help would be appreciated. Thank you. Code: <script>
0
3900
by: =?Utf-8?B?YWxleF9jYXJvMQ==?= | last post by:
Hi, I would like to use a multibinding to determine the fill value of my rectangle style. <Style x:Key="StyleRect" TargetType="{x:Type Rectangle}"> <Setter Property="Fill"> <Setter.Value> <MultiBinding Converter="{StaticResource MyMultiValueConverter}"> <Binding Path="PropertyX"/>
1
2676
by: reemamg | last post by:
I've two frames in a page. On the left Frame i've buttons , if we click on button the particular pages will be loaded in the middle Frame. This code works perfectly in Firefox but not in IE ... Please help me to resolve this issue.. <html> <head> <!-- Infrastructure code for the tree -->
1
3524
by: SunshineInTheRain | last post by:
My project has 3 files, File1 has included master page. file1 consists of iframe1 that load file2. File2 consists of iframe2 that load file3. Javascript used on each file to resize the iframe height based on the each iframe's content height. It is work well on IE, but the error "has no properties" occured with firefox on code as below....
1
3302
by: Jahamos | last post by:
Background: I have copy and pasted an Excel flowchart into a Dreamweaver html page. I created a frame on the top of the page as a viewer. I created hotspot links over the flowchart items. Each hotspot link should open a new anchor link in the top frame which references a different webpage. Problem: It works fine in Firefox. When clicking on...
1
2014
by: ehud37new | last post by:
this script work fine in IE but not in FireFox where is the problem? here is the script /*------------------------------------------------------------------ File: menu.js Use: Collection of clients functions
0
7444
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...
0
7711
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. ...
1
7467
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...
0
7805
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...
1
5367
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3497
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3478
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1054
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
755
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.