inherit
172351
0
Sept 5, 2019 10:56:35 GMT -8
DarkPikachu
Complexity == Fun
320
October 2011
tcll
|
Post by DarkPikachu on Apr 28, 2015 4:35:32 GMT -8
anyone know a good way to list a stylesheet's classes in the order they were created/added??
|
|
inherit
The Dream Crusher (Ret.)
164921
0
Apr 1, 2014 11:00:25 GMT -8
Tim Camara
Teach a man to fish, etc., etc.
1,721
March 2011
tcamara
|
Post by Tim Camara on Apr 28, 2015 7:11:49 GMT -8
I don't know about the ordering bit, but internally we use proboards.css.parse() to generate the LESS parse tree representation of style sheets for use with the visual editor.
|
|
inherit
172351
0
Sept 5, 2019 10:56:35 GMT -8
DarkPikachu
Complexity == Fun
320
October 2011
tcll
|
Post by DarkPikachu on Apr 28, 2015 12:44:39 GMT -8
eh, I prbly shoulda been more specific... heh it's for my Custom CSS plugin for displaying your created classes in your profile. the stylesheet is created via jquery and is 100% local. rather than cluttering up your profile with a garb-load of text, I wanted to clean it up and display only the class names styled with their relative style in a scrolled resizable div. see why I need the order... heh
|
|
inherit
172351
0
Sept 5, 2019 10:56:35 GMT -8
DarkPikachu
Complexity == Fun
320
October 2011
tcll
|
Post by DarkPikachu on Apr 28, 2015 13:21:48 GMT -8
well, I FINALLY found something on google. I personally like this answer as it's a bit cleaner than the first with the higher votes (though still dirty) and easier to work with: stackoverflow.com/a/4651999/2131849something I know to clean up: bad: for(j = 0; j< currentSheet.cssRules.length; j++){ // SecurityError: The operation is insecure. good: var rules = currentSheet.cssRules // ensure a local array for(j = 0; j< rules.length; j++){
|
|
inherit
216224
0
Aug 1, 2024 1:18:46 GMT -8
Quozzo
408
November 2014
quozzo
|
Post by Quozzo on Apr 28, 2015 13:43:04 GMT -8
better: var rules = currentSheet.cssRules for(var i = 0,k = rules.length; i<k;i++){
|
|
inherit
172351
0
Sept 5, 2019 10:56:35 GMT -8
DarkPikachu
Complexity == Fun
320
October 2011
tcll
|
Post by DarkPikachu on Apr 28, 2015 14:01:01 GMT -8
actually, cssRules is returning undefined for my stylesheet...
something along the lines of:
var styles = $('<style id="mystyle"></style>'); styles.text( usrText ); // from the custom profile field styles = styles[0]; // document object (not JQ object)
var rules=styles.cssRules; for(j = 0; j< rules.length; j++){ console.log(rules[j]); };
An error occurred during a document.ready call: TypeError: Cannot read property 'length' of undefined
tested on the latest chromium on Xubuntu 14.04
|
|
inherit
The Dream Crusher (Ret.)
164921
0
Apr 1, 2014 11:00:25 GMT -8
Tim Camara
Teach a man to fish, etc., etc.
1,721
March 2011
tcamara
|
Post by Tim Camara on Apr 28, 2015 16:09:51 GMT -8
Try this:
// Create style tag var styles = $('<style id="mystyle"></style>');
// Add styles to style tag from custom field styles.text(usrText);
// Add style tag to page $('head').append(styles);
// Retrieve DOM representation of style object var dom_rep = null; for(i = 0; i < document.styleSheets.length; i++){ if(document.styleSheets[i].ownerNode.id === 'mystyle') { dom_rep = document.styleSheets[i]; break; } }
// Get the list of CSS rules var rules = dom_rep.cssRules;
// Print out the rules for(i = 0; i < rules.length; i++){ console.log(rules[i]); };
|
|
inherit
172351
0
Sept 5, 2019 10:56:35 GMT -8
DarkPikachu
Complexity == Fun
320
October 2011
tcll
|
Post by DarkPikachu on Apr 28, 2015 16:58:55 GMT -8
OMFG, I'm a freakin retard! *facepalms* I'm doing that already on the other part of this plugin. *tears eyelids down* do you know how many google searches I've done before I came here asking -_-* I can't say because I never counted... but I know I spent hours before coming here. >_< thank you! EDIT: AND they appear to be in order, big thank you
|
|
inherit
The Dream Crusher (Ret.)
164921
0
Apr 1, 2014 11:00:25 GMT -8
Tim Camara
Teach a man to fish, etc., etc.
1,721
March 2011
tcamara
|
Post by Tim Camara on Apr 29, 2015 7:05:53 GMT -8
You're welcome.
|
|