Skip to content

Commit 8c2a1a2

Browse files
author
daffl
committed
More documentation
1 parent eb141d5 commit 8c2a1a2

File tree

2 files changed

+83
-26
lines changed

2 files changed

+83
-26
lines changed

readme.md

Lines changed: 82 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ __Some things you can do:__
1111
## Get started
1212

1313
[Download the latest version 0.2.0](https://raw.github.com/daffl/jquery.dform/master/dist/jquery.dform-0.2.0.min.js)
14-
(6 Kb minified)
14+
(~7 Kb minified)
1515

1616
Include it in your jQuery powered page and try this:
1717

@@ -160,24 +160,12 @@ Now generates
160160

161161
## Subscribers
162162

163-
Not everything can be solved using a custom type. Adding a class, for example, doesn't need to be implemented
164-
for every type and this is where Subscribers come in. Subscribers are functions that will be called for the key they
165-
have been registered for when traversing the dForm object.
163+
While type generators are being used to generate a base element for the given type, subscribers attach to
164+
certain attributes in the options object. When traversing the object all subscribers registered for the
165+
current key will be executed on the current element.
166166

167167
### Core subscribers
168168

169-
**type** *{String}*<br />
170-
Besides looking up the correct Type Generator it also adds a dform specific class to the element using
171-
`$.dform.options.prefix` (*ui-dform-* by default) and the type name.
172-
173-
{
174-
"type" : "text"
175-
}
176-
177-
Generates:
178-
179-
<input type="text" class="ui-dform-text" />
180-
181169
**class** *{String}*<br />
182170
Adds a class to the current element (instead of setting the attribute) using [.addClass()](http://api.jquery.com/addClass).
183171

@@ -342,6 +330,20 @@ Generates:
342330
<legend type="ui-dform-legend">Address</label>
343331
</fieldset>
344332

333+
**type** *{String}*<br />
334+
Besides looking up the correct Type Generator it also adds a dform specific class to the element using
335+
`$.dform.options.prefix` (*ui-dform-* by default) and the type name.
336+
337+
{
338+
"type" : "text"
339+
}
340+
341+
Generates:
342+
343+
<input type="text" class="ui-dform-text" />
344+
345+
Set `$.dform.options.prefix = false;` if you don't want any classes being added.
346+
345347
### Add your own
346348

347349
It is easy to add your own subscribers. Similar to a type generator you just pass the key name you want to subscribe
@@ -383,15 +385,17 @@ Functions registered with this name will be called before any processing occurs
383385
Functions registered with this name will be called after all processing is finished and also get the original
384386
options passed.
385387

386-
## Plugin methods
388+
## Plugin
389+
390+
### jQuery plugin methods
387391

388392
The __dform__ plugin function follows the jQuery plugin convention of taking an options object or a
389393
method name as the first parameter to call different methods:
390394

391-
**$(form).dform(options, converter)** *{Object}* *\[{String}\]*<br />
395+
**$(form).dform(options \[, converter\])** *{Object}* *{String}*<br />
392396
Append the dForm object to each selected element. If the element is of the same type (e.g. if you are appending
393397
a `type : 'form'` on a `<form>` or if no type has been given) run the subscribers and
394-
add the attributes on the current element.
398+
add the attributes on the current element. Optionally use a converter with a given name.
395399

396400
**$(form).dform('run', options)** *{Object}*<br />
397401
Run all subscribers from a given dForm object on the selected element(s).
@@ -400,16 +404,64 @@ Run all subscribers from a given dForm object on the selected element(s).
400404
Run a subscriber with a given name and options on the selected element(s) using a specific type.
401405
Usually used internally.
402406

403-
**$(form).dform('append', options, converter)** *{Object}* *\[{String}\]*<br />
407+
**$(form).dform('append', options \[, converter\])** *{Object}* *{String}*<br />
404408
Append a dForm element to each selected element. Optionally using a converter with the
405409
given name.
406410

407411
**$(form).dform('attr', options)** *{Object}*<br />
408412
Set each attribute from the options object that doesn't have a corresponding subscriber registered.
409413

410-
**$(form).dform('ajax', params, success, error)** *{Object|String}* *{Function}* *{Function}*<br />
414+
**$(form).dform('ajax', params \[, success\] \[, error\])** *{Object|String}* *{Function}* *{Function}*<br />
411415
Load a form definition using Ajax.
412416

417+
### Static functions
418+
419+
**$.keySet(object)** *{Object}*<br />
420+
Return an array of the objects keys.
421+
422+
**$.withKeys(object, keys)** *{Object}* *{Array}*<br />
423+
Returns a new object that contains all values from the given
424+
object that have a key which is also in the array keys.
425+
426+
**$.withoutKeys(object, keys)** *{Object}* *{Array}*<br />
427+
Returns a new object that contains all value from the given
428+
object that do not have a key which is also in the array keys.
429+
430+
**$.dform.options**<br />
431+
Static options for generating a form. Currently only $.dform.options.prefix
432+
is being used.
433+
434+
**$.dform.defaultType(options)** *{Object}*<br />
435+
A type generator that will be used when no other registered type has been found.
436+
The standard generator creates an HTML element according to the type given:
437+
438+
{
439+
"type" : "a",
440+
"href" : "http://daffl.github.com/jquery.dform",
441+
"html" : "Visit the plugin homepage"
442+
}
443+
444+
Generates:
445+
446+
<a class="ui-dform-a" href="http://daffl.github.com/jquery.dform">Visit the plugin homepage</a>
447+
448+
**$.dform.types(\[name\])** *{String}*<br />
449+
Returns all type generators for a given type name. If no name is given, a map of type names
450+
to an array of generator functions will be returned.
451+
452+
**$.dform.addType(name, generator \[, condition\])** *{String}* *{Function}* *{Boolean}*<br />
453+
Add a new type with a given name and generator function which takes the options as the parameter
454+
and returns a new element. Optionally pass a condition which will add the type only if
455+
it returns true.
456+
457+
**$.dform.subscribe(name, subscriber \[, condition\])**<br />
458+
**$.dform.subscribers**<br />
459+
460+
**$.dform.hasSubscription(name)** *{String}*<br />
461+
Returns if there is any subscribers with the given name.
462+
463+
**$.dform.createElement(options)**<br />
464+
413465
## jQuery UI
414466

415467
jQuery.dForm automatically adds support for jQuery UI if it is available. If the form has the *ui-widget* class
@@ -440,17 +492,18 @@ Creates a [slider element](http://jqueryui.com/demos/slider/).
440492
}
441493

442494
**accordion** `{ "type" : "accordion" }`<br />
443-
Creates a container for a jQuery UI accordion. Use the entries subscriber to add elements.
495+
Creates a container for a jQuery UI accordion. Use the *entries* subscriber to add elements.
444496

445497
**tabs** `{ "type" : "tabs" }`<br />
446-
Creates a container for a set of jQuery UI tabs. Use the entries subscriber to add elements.
498+
Creates a container for a set of jQuery UI tabs. Use the *entries* subscriber to add elements.
447499

448500
### Subscribers
449501

450502
Some other features have been implemented as subscriber, e.g. adding entries to an accordion or making an element
451503
resizable:
452504

453505
**entries** *{Object}*<br />
506+
Add entries to an *accordion* or *tabs* element.
454507

455508
**dialog** *{Object}*<br />
456509

@@ -481,17 +534,21 @@ to the element:
481534
}
482535
}
483536

537+
If the form has the *ui-widget* class the jQuery UI CSS error classes will be used to highlight
538+
invalid fields.
539+
484540
### jQuery Globalize
485541

486-
If [jQuery.Globalize]
542+
[jQuery.Globalize] adds some nice internationalization to JavaScript. If available, the *html* and *options*
543+
subscriber are enabled to use internationalized strings and option lists.
487544

488545
## Changelog
489546

490547
__0.2.0__
491548

492549
* Improved documentation using DocumentUp
493550
* QUnit test suite runs test for the complete core
494-
* Changed API
551+
* Major API improvements
495552

496553
__0.1.4__
497554

src/dform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
* an array of generator functions.
154154
*/
155155
types : function (name) {
156-
return name ? _types[name ] : name;
156+
return name ? _types[name ] : _types;
157157
},
158158
/**
159159
* Register an element type function.

0 commit comments

Comments
 (0)