jQuery.sampling exposes several functionallities. Main functions are related with template animation / sampling but it also includes templating related capabilities explained in Templating capabilities.
You can configure the jQuery.sampling() plugin by calling jQuery.sampling() on the jQuery object (on $ for newbies).
Establishes initial options such as the sample class or new flags. See jQuery.sampling() options for further information.
| Arguments: |
|
|---|
Following jQuery Namespacing convenions, all these methods must be called by using:
jQuery.sampling(<method_name>, ...);
I.e, to call option() to set the value of parameter sampleClass to _sample you should do:
jQuery.sampling('option', 'sampleClass', '_sample');
Applies on jQuery object. Detaches all sample elements marked by the sample class (by default _s) and returns a collection of them.
| Returns: | sample collection with all collected samples. |
|---|
Applies on sample collection returned by gather(). Selects the proper samples inside the sample collection. The method is cached by the selector so succesive calls to this method have improved performance.
| Arguments: |
|
|---|---|
| Returns: | a jQuery sample object with the sample(s). Avoid to modify this object because it’s the sample itself. Use jQuery.clone() or use new() to build a new copy. |
Tip
You can select more than one sample. It is specially useful in combination with Sample Select Mode.
Get value of the optName option.
| Arguments: |
|
|---|---|
| Returns: | value of the option specified by optName parameter. |
Set the optName option to value.
| Arguments: |
|
|---|
Sample instantiation is the most interesting part of the plugin. Instantiate refers to clone the sample and customize it.
The task can be performed by calling to new() in several ways. The most important concept here is customizing item and sample selection mode.
When a sample is instantiated it is customized by a customizing item. This is an ordinary object where keys are valid jQuery selector strings and values are mixed contents.
During customization process, each key of the customizing item is searched inside the sample and its content is set with the value.
In instance, look at this customizing item:
{
'.id':1,
'.name':'Tie Fighter',
'.type':'Starfighter',
'.affiliation':'Galactic Empire'
}
Now look at this HTML snippet:
<tr class="_s">
<td class="id">sample_id1</td>
<td class="name">sample_name1</td>
<td class="type">sample_type1</td>
<td class="affiliation">sample_affiliation1</td>
</tr>
Previous tr sample, after instantiating with the previous item should look like:
<tr>
<td class="id">1</td>
<td class="name">Tie Fighter</td>
<td class="type">Starfighter</td>
<td class="affiliation">Galactic Empire</td>
</tr>
When you select more than one sample by using select() you can specify which specific sample will be selected to be customized by the next customization item. This can be done by setting the instantiaion flag sampleSelectMode.
If the flag is set with a function, then the function’s signature should be as follows:
sampleSelector(index, length)
Inside the function, this is the sample collection. Parameter index is actually the call count for the function (first time, 0; second time, 1; etc) and length is the length of the sample collection. Return value must be an integer representing the index of the specific sample which will be selected. Return null to stop customization process.
If the flag is set with a number, then it is the index that always will be selected. If the number is negative then it counts starting from the end.
Finally, jQuery.sampling() offers some default functions that you can use by using their name as string:
Following, there is the documentation about the different ways of calling new():
Applies on a jQuery sample object returned by select().
| Returns: | a clone of the current sample without the sample class. |
|---|
Applies on a jQuery sample object returned by select(). Successively calls map_generator using the returned value as the customizing item (see Customizing items) to instantiate the sample. Instantiation process ends when null is returned.
| Arguments: |
|
|---|---|
| Throws Returned values of the map generator or objects inside the array should be customizing items: | |
if map_generator does not return customizing items. |
|
| Returns: | a jQuery object, clone of the current sample, without the sample class. |
Applies on a jQuery sample object returned by select(). Generates as much instantiations of the sample object as elements in the array.
| Arguments: |
|
|---|---|
| Throws Returned values of the map generator or objects inside the array should be customizing items: | |
if items in customizing_array are not customizing items. |
|
| Returns: | a jQuery object, clone of the current sample, without the sample class. |
By the moment only CSI (client side includes) are supported but other features are planned to be integrated soon.
jQuery.sampling() includes a mechanism to perform client side includes (CSI). These includes act like traditional server side includes of languages such as PHP but in the client side. In few words, they are elements pointing some URL, jQuery.sampling() is able to replace these elements with the contents of URL they are pointing to.
To perform a client side include, use CSI place holders. These are anchor elements <a> with the include class (by default _inc, see jQuery.sampling() options) and href attribute pointing to an URL, source of the include:
<a class="_inc" href="./menu.html">This will be replaced by contents of menu.html</a>
Use the following code to perform CSI inside the page on document ready:
$(function() { $(document).sampling('include'); });
Replaces CSI place holders by the contents referred by them. Note that you can perform CSI replacements contained by a jQuery object by calling include() from that object.
Note how new content can include more CSI place holders. By default, they will be resolved too but the developer can limitate the bahaviour by passing a non-zero value as parameter limit.
| Arguments: |
|
|---|---|
| Returns: | the total of CSI successfully resolved. |