Skip to content

Commit

Permalink
Add formEl settings option - used to specify form for hashcash widget…
Browse files Browse the repository at this point in the history
… in case if widget is not placed inside form it is used for.
  • Loading branch information
hippich committed Jul 6, 2014
1 parent 6b59ca6 commit 91ab676
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -58,6 +58,7 @@ $.fn.hashcash([options]) where *options* can be:
progressCb: null,
doneCb: null,
targetEl: null,
formEl: null,
hashcashInputName: 'hashcashid',
lang: {
screenreader_notice: 'Click this to unlock submit button',
Expand All @@ -84,7 +85,10 @@ to the form.
*doneCb* - function assigned to this option will be called when calculation will be finished.

*targetEl* - used to specify custom element to add widget to. By default widget added
right before button it is attached to.
right before button it is attached to. Can be either jquery selector string or jquery element.

*formEl* - used to specify form to attach onSubmit events and hidden hashcashid field. By default
looks for parent of submit button widget is attached to. Can be jquery selector string or jquery element.

*hashcashInputName* - used to override default "hashcashid" hidden input element to pass
work id for server-side verification.
Expand Down
10 changes: 9 additions & 1 deletion jquery.hashcash.io.js
Expand Up @@ -51,6 +51,7 @@
progressCb: null,
doneCb: null,
targetEl: null,
formEl: null,
hashcashInputName: 'hashcashid',
lang: {
screenreader_notice: 'Click this to unlock submit button',
Expand All @@ -69,7 +70,14 @@
throw new Error('Hashcash.IO key is required. Get it at https://hashcash.io');
}

var $form = $el.parents('form').eq(0);
var $form;

if (! settings.formEl) {
$form = $el.parents('form').eq(0);
}
else {
$form = $(settings.formEl);
}

if (! $form) {
throw new Error('Hashcash plugin requires button to be with in <form> element.');
Expand Down
2 changes: 1 addition & 1 deletion jquery.hashcash.io.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "jquery.hashcash.io",
"version": "0.0.1",
"version": "0.0.2",
"description": "jQuery Hashcash.io plugin",
"main": "jquery.hashcash.io.js",
"scripts": {
Expand Down

0 comments on commit 91ab676

Please sign in to comment.