If you intend to use the '
$' variable as a shorcut for Peppy beware that Peppy will
not overwrite this variable. If Peppy is the only library you are using then this will be fine,
Peppy will assign a reference of Peppy.query to '
$'. If you are using Peppy with other
libraries though, the safest bet is to force an assignment of '
$' to Peppy.query after all
scripts are loaded.
<
html>
<
head>
<
script src=
"otherlibrary.js"></
script>
<
script src=
"peppy.js"></
script>
<
script type=
"text/JavaScript">
$ = Peppy.query;
</
script>
</
head>
<
body>
...
</
body>
</
html>
If you wish to use Peppy as the selector engine in your own library you could take a few different approaches.
I will reccomend taking the entire source of Peppy and placing it at some point prior to your first intended use.
However, another valid approach would be to dissect the source of Peppy and use the parts that you chose. Be aware
though that Peppy uses a closure to hide private methods and variables that it does not want exposed, so this is a
potential place for hiccups to occur for this approach.
If you wish to use Peppy as the selector engine in another library, I will give you
a few helpful suggestions here. I will use jQuery as an example as I have received the
most requests for an example of how to do this with jQuery. I should note that this is
not supported by the jQuery team and this has been only minimally tested by myself.
The first thing that you need to do is locate the selector engine API in your library.
In jQuery (as of v1.2.6 anyway) this is jQuery.find. The next thing to do is overwrite the
assignment to jQuery.find with a reference to Peppy.query.
Here is an example:
<
html>
<
head>
<
script src=
"jquery.js"></
script>
<
script src=
"peppy.js"></
script>
<
script type=
"text/JavaScript">
jQuery.find = peppy.query;
</
script>
</
head>
<
body>
<
div class=
"example">
example 1
</
div>
<
div class=
"example">
example 2
</
div>
<
div class=
"example">
example 3
</
div>
</
body>
</
html>
That's it. jQuery will now use Peppy as its selector engine. Now you can do things like:
and you are using Peppy to get the nodes, and jQuery to apply the anonymous function to each element found from the query.