")
.siblings('.'+t.refreshClass)
.append(b);
b.on('click', function(e) {
e.preventDefault();
t.refresh();
return false;
});
}
n.trigger('init.'+ns, [t]);
};
// PUBLIC PROPERTIES (Default options)
// Assign default options to the class prototype
$.extend($.jk.SimpleCaptcha.prototype, {
allowRefresh: true, // Boolean Whether the user should see a UI element allowing them to refresh the captcha choices
scriptPath: '/scripts/jquery.simplecaptcha/simpleCaptcha.php', // String Relative path to the script file to use (usually simpleCaptcha.php).
numImages: 5, // Number How many images to show the user (providing there are at least that many defined in the script file).
introText: "
To make sure you are a human, we need you
to click on the .
",
// String Text to place above captcha images (can contain html). IMPORTANT: You should probably include a tag with the textClass name on it, for example:
refreshButton: "

",
// String Html to use for the "refresh" button/content. Note that you can make this whatever you like, but it will be placed AFTER the "introText", and a click handler will be attached to initiate the refresh, so best to make it something "clickable".
refreshClass: 'refreshCaptcha', // String Class to use for the captcha refresh block (if there is one)
inputName: 'captchaSelection', // String Name to use for the captcha hidden input, this is what you will need to check on the receiving end of the form submission.
introClass: 'captchaIntro', // String Class to use for the captcha introduction text container.
textClass: 'captchaText', // String Class to look for to place the text for the correct captcha image.
imageBoxClass: 'captchaImages', // String Class to use for the captchas images container.
imageClass: 'captchaImage', // String Class to use for each captcha image.
node: null // Node | String The node (or selector) to use for the captcha UI. If not set, the current node selected bu $(...).simpleCaptcha(); will be used
});
// PUBLIC METHODS
$.extend($.jk.SimpleCaptcha.prototype, {
loadImageData: function(cb) {
var t = this;
cb = ($.isFunction(cb))?cb:(function(){});
$.ajax({
url: t.scriptPath,
data: { numImages: t.numImages },
type: 'post',
dataType: 'json',
success: function(d, s) {
if (d && d.images && d.text) {
t.data = d;
t.node.trigger('dataload.'+ns, [d]);
cb(d);
} else {
t.node.trigger('error.'+ns, ['Invalid data was returned from the server.']);
cb(null);
}
},
error: function(xhr, s) {
console.debug('in error handler:', xhr);
cb(null);
t.node.trigger('error.'+ns, ['There was a serious problem: '+xhr.status]);
}
});
},
addImagesToUI: function() {
var t = this;
// Add image text to correct place
t.node.find('.'+t.textClass).text(t.data.text);
// Build images html
var h = "";
for (var i=0; i
";
}
// Add images to container (replacing existing ones, if any)
t.node.find('.'+t.imageBoxClass).html(h);
t.node.trigger('ready.'+ns, [t]);
},
refresh: function() {
var t = this;
t.node.trigger('refresh.'+ns, [t]);
t.loadImageData(function(d) {
if (d) { t.addImagesToUI(); }
});
}
});
})(jQuery);