PDA

Click to See Complete Forum and Search --> : [JavaScript] Syntactic Sugar JavaScript library


minitech
Jan 22nd, 2011, 08:09 PM
Recent Changes

Update to v0.8 Critical bug fixes.
Update to v0.7 Bug fixes and more extensions.


This is my first shot at a JavaScript library, it includes support for:

CSS1 Selectors (By tag name, class name, ID, and parent node trees, although that's a bit different)
CSS3 Pseudo-classes
Multi-element CSS changes
Animation (multiple elements, too!)
Additional extensions


The CSS1 selectors are a bit different when dealing with ancestor-of selectors. Normally, in CSS, "div p" would be any <p> element under a <div> element. In Syntactic Sugar, it must be a direct child (equivalent to "div > p" in CSS). This is because I found it too complicated and unnecessary to include the relationship selectors (*: general sibling, >: direct child, <: direct parent, ~: general sibling, +: adjacent sibling). If you find it necessary, let me know - I'll move it up on the priority list. I'm working on it.

Here's a syntax example. It takes all <div> elements that are the last <div> element in their parent element that also have the class "blue" but not the class "dontstyle" and colors them blue and italicizes them:

$("div.blue:last-of-type:not(.dontstyle)").color("blue").italic();

One known bug is that the nth-child, nth-last-child, nth-of-type, and nth-last-of-type selectors do not work with expressions, such as ":nth-last-child(2n+3)". Once again, working on it.

Please enjoy this library and let me know about any bugs, or any features you want added. Attached are the main library, the animation extensions, and an example HTML file. The example HTML is example.txt (VBForums doesn't let you upload HTML files directly) and contains both scripts so people who just want to see what it's like don't have to download a whole ZIP file.

SambaNeko
Feb 16th, 2011, 11:37 AM
Just a note - I don't see a sample HTML file in your zip, just 2 JS files.

minitech
Feb 16th, 2011, 07:03 PM
Sorry, I guess I deleted it accidentally. I'll try to make a new one soon.

In the meantime, 0.8 fixes a huge bug where attribute selectors and ID selectors just do not work.

motil
Feb 21st, 2011, 02:35 PM
I just took quick look inside the code and didn't yet tested it, it will be nice to if you'll post here more examples of how to use it and what your library can do.

one thing though, why you are re-building the css selecter system? you can add sizzle selector system and focus in developing new features that users can't find in other libraries. even John Resig the creator of jQuery did it.

Anyway I'm really impressed, keep up the good work.

minitech
Feb 21st, 2011, 02:40 PM
Thanks :) I have a little policy, though - I never, ever use libraries of code that aren't mine unless it's really something I can't make. That way I always learn something from making it, and I can customize it very easily.

Thanks for the suggestions, I'll add some more examples.