tags:

views:

410

answers:

8

I can only think of a client-side solution using jQuery, but is it possible to resolve the css porperties of a page's element from the server side?

I was thinking of using a CSS parser to fish out the properties, but that wouldn't work due to the cascade nature of CSS.

Thanks!

A: 

From within C# you have all DOM wrapped in Classes and Collection.

button.Styles.Add("style", "value");
button.Styles["style"] = "value";

Cascade and inheritance will not be reflected on server side.

pixel3cs
OP is looking for answers in coldfusion. Not sure, if your answers helps him (if that is possible in cfml).
shahkalpesh
Since CF8 there is .NET integration, so if this code could be wrapped into a suitable re-usable dll/class then it can be used.
Peter Boughton
Sorry, this is not what I'm looking for, but thanks. I'm more like looking for a server-side solution that works like $(DOM Object).css("color") in JQuery.
Henry
A: 

Not sure if this helps, but there is a Java project called jTidy that will take in html (malformed or not) and represent it with a DOM interface. From their site,

"In addition, JTidy provides a DOM interface to the document that is being processed, which effectively makes you able to use JTidy as a DOM parser for real-world HTML." - http://jtidy.sourceforge.net/

I've used it on a personal projects before that were written in Coldfusion to make it easier to extract links from crawled pages. Instead of big nasty regular expressions, I was able to use xPath to 'query' against the dom for my elements. In some ways, xPath is similiar to jQuery's selectors.

jalpino
do they resolve CSS? I don't think they do...
Henry
What do you mean by resolving CSS? What it will do is give you DOM access, for example you can search for div elements that have a css class of "xyz".
jalpino
@jalpino: you realise CSS is somehwat more complicated than that right? I think henry is (correctly) dubious of their ability to parse and apply CSS
annakata
A: 

Do you need to do something with the value before the page loads? If not you can just do it in jQuery and then Ajax post the value back to CF.

kevink
that's the solution I have in mind, but if possible I'd like to do it on the server-side.
Henry
+1  A: 

your answer is extremely general and it's very hard to understand what exactly you want to do. could you possibly provide a code example.

if all you want to do is add a class to an element based off of some server side logic, then just do:

<a href="" style="<cfif a eq a>myclass</cfif>"></a>

EDIT:

Henry would like to determine that the color of an element (eg: #title) and then run some coldfusion based on what the color is:

The best way I could figure on doing this would be on the client end you would use jQuery to determine the color and call an ajax request based on it:

$(function(){

    var color = $("#title").css("color");

    if(color == "blue")
    {
     $("#my-code-container").load("my-logic.cfm");
    }

});
rip747
no, I mean if I have a .html file on the server, how do I tell, for example, color of certain element (e.g. #title)?
Henry
that's going to take some trickery. as mentioned before, you'll have to use a library that will parse the html and apply any and all css properties to the dom for you. to be honest I would just use jquery to parse the dom it determine the color. after that you can use jquery again to make an ajax request to a url that will have your application logic in a template.
rip747
A: 

Use the client ("a client") to help you.

Render the page to the client, write jQuery that runs in the Browser and posts back the CSS properties to one of your CF pages.

What are you trying to do with that info?

Tomalak
some user-friendly html editor that can change color of some DOM element for ppl who don't know CSS.
Henry
And why do you want to solve that on the server? I mean, the editor is supposed to run on the client, right?
Tomalak
A: 

I'm reasonably sure that there is no server-side solution for this - the JRun server doesn't actually know what it's sending to the web server; it just processes the code and pushes off the result.

A: 

From the longshot department:

If you are using a version of CF that uses JDK 6, you could technically jump into RHINO and execute JQuery through that and have it parse the files, allowing you to get the styles.

RHINO doesn't really contain the DOM and, I believe, JQuery requires it, so this is a real longshot.

Tom Hubbard
A: 

Java 7 with built-in webkit engine! :)

Henry