badcoyote
11-02-2006, 03:02 PM
I just discovered this forum and I think I'll be spending a lot of time here. :) I'd like to use my first post to ask for help with something I've been wrestling with.
First off... I'm a PHP developer. Client-side's not really my thing. I try to stay away from JavaScript most of the time and when I can't avoid it, it's not long before I'm completely overwhelmed. (I'll probably post some of my Ajax woes at a later date...) Here's what I'm trying to do right now:
I need a script that finds all the CSS in an (X)HTML document and compiles it into one style sheet, to pass on to a PHP app. It gets tricky when the styles are divided amongst multiple linked sheets, embedded in the page, or use the @import rule (especially multiple nested @imports). It would be an extra bonus if the script could also work with inline styles, but that's probably asking too much. ;)
It doesn't have to be in JavaScript, but I'm starting my search there because of Chris Pederick's awesome Web Developer Extension (http://chrispederick.com/work/webdeveloper/) for Mozilla. If you're like me, you already use this add-on all the time. Focus your attention on the "View CSS" tool. This is so extremely close to what I want my script to do that I hate to reinvent the wheel in another language. Too bad I suck at JavaScript.
To make a long story short(er), I copied webdeveloper_viewCSS() and all its supporting functions out of webdeveloper.jar, and deleted all the Mozilla UI stuff that I could recognize as well as unneeded formatting elements, to create my own script. Probably pretty stupid, but I don't know where else to begin. Unsurprisingly, it doesn't work at all.
The fact of the matter is, I can't tell Mozilla code from real JavaScript and I need someone a little more fluent to translate for me. I've attached my code (in an HTML file, saved as TXT for this forum). If you have the Web Developer add-on, look in your Firefox Extensions folder, at webdeveloper.jar, that's the original code that I'm modifying. I would love it if anyone could look it over and help me get it working. It's pretty advanced stuff though, but heck, I think alert() is advanced. :p
And if anybody wants to tackle this project with PHP instead of JS, I'll be equally grateful.
First off... I'm a PHP developer. Client-side's not really my thing. I try to stay away from JavaScript most of the time and when I can't avoid it, it's not long before I'm completely overwhelmed. (I'll probably post some of my Ajax woes at a later date...) Here's what I'm trying to do right now:
I need a script that finds all the CSS in an (X)HTML document and compiles it into one style sheet, to pass on to a PHP app. It gets tricky when the styles are divided amongst multiple linked sheets, embedded in the page, or use the @import rule (especially multiple nested @imports). It would be an extra bonus if the script could also work with inline styles, but that's probably asking too much. ;)
It doesn't have to be in JavaScript, but I'm starting my search there because of Chris Pederick's awesome Web Developer Extension (http://chrispederick.com/work/webdeveloper/) for Mozilla. If you're like me, you already use this add-on all the time. Focus your attention on the "View CSS" tool. This is so extremely close to what I want my script to do that I hate to reinvent the wheel in another language. Too bad I suck at JavaScript.
To make a long story short(er), I copied webdeveloper_viewCSS() and all its supporting functions out of webdeveloper.jar, and deleted all the Mozilla UI stuff that I could recognize as well as unneeded formatting elements, to create my own script. Probably pretty stupid, but I don't know where else to begin. Unsurprisingly, it doesn't work at all.
The fact of the matter is, I can't tell Mozilla code from real JavaScript and I need someone a little more fluent to translate for me. I've attached my code (in an HTML file, saved as TXT for this forum). If you have the Web Developer add-on, look in your Firefox Extensions folder, at webdeveloper.jar, that's the original code that I'm modifying. I would love it if anyone could look it over and help me get it working. It's pretty advanced stuff though, but heck, I think alert() is advanced. :p
And if anybody wants to tackle this project with PHP instead of JS, I'll be equally grateful.