• Stars
    star
    329
  • Rank 127,237 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Functional Javascript alternative to JQuery.

JZed.js -- The functional JQuery Alternative

JZed is my alternative to JQuery that's meant to be more functional and full of $. It's legit purpose is to do the 80% of things that you sometimes need to do on a remote site that is punching through to yours and they might have a different or no JQuery installed. This is a tiny amount of code that has enough of the functionality found in JQuery and packaged in a way that can't possibly clash with it.

It's also functional so now LISP hackers can pretend they're both JavaScript Oakland Living Node.js gangsters and high class San Franciscans with their functionality snobbery.

How It Works

There's a bunch of functions that start with $ and do stuff that's super useful and all start with $. This way they probably won't clash with anything that exists already (let me know if I made one that does, or just change it).

Example

Here's an example of getting some stuff from a remote server based on the id of a div and replacing it along with CORS credentials allowed:

function getstuff() {
    var list = $id('mystuff');

    $http({
            'url': 'https://stuff.com/' + list.dataset.stuff_id + '/',
            'method': "GET",
            'good': function (req) {
                $html(list, req.responseText);
            },
            'credentials': true,
            'error': function (req) {
                $html(list, "<h1>ERROR: </h1>" + req.responseText);
            }
    });
}

$boot(paydiv)

Documentation

The library is tiny. Seriously, just go read the code. It's good education. For the super lazy here's a short listing of what's in it.

Getting

Each of these takes an optional argument of inChildren at which point it will scope the getting inside those children.

  • $get(name, inChildren) -- Get node by selector.
  • $all(name, inChildren) -- All nodes by selector.
  • $id(name, inChildren) -- Nodes with id.
  • $class(name) -- Nodes with that class.
  • $name(name, inChildren) -- Nodes with name.
  • $filter(nodes, fn) -- Filters by true/false function.

Looping

  • $each(arr, cb) -- Call cb on each in arr.
  • $next(node) -- Get the next sibling.
  • $previous(node) -- Get the previous sibling.
  • $siblings(node) -- Get all the siblings.
  • $map(arr, fn) -- Map over an array.

Styling

  • $style() -- Takes unlimited arguments of [nodes, className] and loops through them applying that CSS class to those elements. Nodes can be single or lists.
  • $toggle(node, className) -- Turns a class on off.
  • $has_class(node, className) -- Tells you if it has that class.
  • $style_of(node, ruleName) -- Tells you the style of that node.

DOMing

  • $new(tag, id, html) -- Make a new tag with that id and html in it.
  • $after(node, html) -- Put that html after this node.
  • $before(node, html) -- Put that html before this node.
  • $append(parent, child) -- Append that child after this parent.
  • $prepend(parent, node) -- Prepend that node before this parent.
  • $remove(parent, child) -- Remove that child from this parent.
  • $clone(node) -- Clone that node.
  • $parent(node) -- Get the parent of this node.
  • $attribute(node, name, value) -- Set the attribute name in node to value.
  • $attribute_of(node, name) -- Get the attribute named from the node?

Testing

  • $matches(node, selector) -- Does node match this selector?
  • $contains(node, child) -- Does node contain that child?
  • $has(node, selector) -- Does node have this selector?
  • $empty(node) -- Is this node empty?

HTMLing

  • $html_of(node) -- Get the HTML of node.
  • $html(node, newhtml) -- Set the HTML of node to newhtml.
  • $outer_html(node) -- Get the outer HTML of node.
  • $replace_with(node, newhtml) -- Replace node with newhtml.
  • $text(node, newtext) -- Set the text of node to newtext.
  • $text_of(node) -- Get the text of node.
  • $offset(node) -- Get node's offset.
  • $offset_parent(node) -- Get the parent offset of node.

Eventing

  • $boot(cb) -- Call cb function when the browser is ready.
  • $off(node, eventName, eventHandler) -- Turn off/remove eventName and eventHandler.
  • $on(node, eventName, eventHandler) -- Turn on/add eventName and eventHandler.

HTTPing

  • $http(settings) -- Send an http request using the attributes: credentials, good, error, method, url. Go read the code.
  • $parse(htmlString) -- Parse the given HTML into a new node.
  • $json(jsonString) -- Parse the JSON.

Miscing

  • $now() -- Get the current time.

License

MIT. I seriously do not care about this apart from releasing it in case someone else could use it.

Status

I use some of these functions and know they work, but I've been a mega slacker lately and need to test all the others. I'm posting it now so people can laugh at it and try it out if they feel brave.

This also only really works on IE9 and maybe IE8 or better, but honstly IE6 and IE7 users users can seriously go fuck themselves with a dirty brick. I may add a function to detect these two bad browser so people can start forcing them to use a real browser for a change.

Why?

I'm doing a bunch of work with CORS and requiring target sites to use jquery is insane when I just need a few little things. Originally the library was about 10 functions, but then I filled it out with more based on the list at http://youmightnotneedjquery.com/ thanks to @zackbloom and @adamfschwartz.

I picked JZed both to annoy people and because it's got lots of $$$ in it so I predict it'll have more problems, yet less code.

Thanks

As mentioned, thanks to @zackbloom and @adamfschwartz for their nice page cataloging things people use in JQuery and providing little snippets for me to borrow.

More Repositories

1

learn-c-the-hard-way-lectures

All of the code from Learn C The Hard Way, each project, plus the presentation slides used in the videos.
C
1,110
star
2

lamson

Pythonic SMTP Application Server
Python
728
star
3

python-lust

Python Little Unix Server Toolkit
Python
543
star
4

learn-more-python-the-hard-way-solutions

Python
532
star
5

fuqit

The FuqIt Web Framework. Shit files into a dir, get some web.
Python
457
star
6

liblcthw

The library you create when you are done with Learn C The Hard Way
C
346
star
7

learn-python3-thw-code

The code to Learn Python3 The Hard Way
Python
311
star
8

librelist

The code for the librelist.com free email service.
Python
73
star
9

zadm4py

Zed's Awesome Debug Macros for Python
Python
50
star
10

learn-painting-the-hard-way

A Simple Introduction To The Application Of Pigment To A Surface To Look Like A Thing
Python
48
star
11

orkestrix

A set of small tools for easily publishing words about music.
JavaScript
26
star
12

earing

A joke dynamic assembler that had a REPL and is fast.
C
17
star
13

botnot

What if monit was a botnet?
Python
16
star
14

isburningmanstillwhite

Checks to see if the Burning Man board of directors is still mostly white.
Python
15
star
15

utu

(DEAD) An attempt to create a strong identity chat system with cryptographic hate as a troll voting system.
C
12
star
16

rfuzz

(DEAD) Old code I used to fuzz attack the original Mongrel.
Ruby
12
star
17

srpmin

The minimum SRP files needed to use SRP in your software.
Shell
10
star
18

poc-uploader

A proof-of-concept uploader for websites.
Python
6
star
19

lcthw-statserve

A simple example project from my book, Learn C The Hard Way.
C
3
star
20

zapps

(DEAD) A fork of Yapps I made to work around a bug because the author refused to fix it or put the project into PyPI.
Python
3
star
21

vellum

(DEAD) A simple make replacement that I hacked on. One of my first python projects.
Python
3
star
22

mulletdb

(DEAD) A joke project that made a working database server to server SQL and NoSQL data types at the same time.
C++
3
star
23

idiopidae

(DEAD) A simple literate programming system written in python.
Python
3
star
24

mongrel2

Mongrel2 Has Moved!
2
star
25

profligacy

(DEAD) A layout engine that predates Apple's use of format strings to layout elements by about five years or more.
Ruby
2
star
26

fcst

(DEAD) Fast Change Set Tool was a RCS I was toying with as my first Ruby project.
C
1
star