Advertisement
Guest User

Untitled

a guest
Jul 12th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. var x = new CSS('HTML5');
  2. // `x` is my Style it started off from the default HTML5 CSS stylesheet.
  3. // `x(selector)` will allow us to access the style of the `selector` CSS selector.
  4.  
  5. x.import('file.css'); // let's import some more rules
  6.  
  7. console.log( x('a').fontSize ); // Prints the default font-size property for 'a' elements
  8.  
  9. x('.myClass > p').display = 'block'; // CSS: .myClass > p { display: block; };
  10.  
  11. var c1 = x('body > div .class1'); // Just for commodity...
  12. c1.width = x('.class2 > div').width; // Cannot be done in CSS/LESS/SASS :(
  13. // It should fall back properly, of course, or give error if that property is not found
  14.  
  15. x('.class3').set( c1.deepCopy() ); // Bringing in nested selectors
  16. x('.class4').set( c1.copy() ); // Only copying properties
  17.  
  18. // Introspection! F**k yeah!
  19. c1.forEachProperty( function(property){ ... } );
  20. c1.forEachChild( function(selector){ ... } );
  21. c1.forEachDescendant( function(selector){ ... } );
  22. x.forEachElement( function(selector){ ... } );
  23.  
  24. var c1Rule = c1.generate(); // Generating the CSS rule for a specific selector
  25.  
  26. x.delete('.class1'); // We no longer need/want `.class1` in our stylesheet
  27. x.deepDelete('.class1'); // Removing also its nested selectors
  28.  
  29. // Let's now generate our final stylesheet.
  30. // The `generate` function might take care of optimizing the stylesheet.
  31. var stylesheet = x.generate();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement