-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.browserid.js
50 lines (47 loc) · 2.05 KB
/
jquery.browserid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* jQuery BrowserID plug-in v0.1.2
*
* Copyright (c) 2011-2013 Christian Wenz
*
* Licensed under the BSD license:
* http://opensource.org/licenses/BSD-3-Clause
*/
(function ($) {
$.fn.browserid = function (assertionCallback, options) {
var settings = {
// path to the BrowserID JavaScript library
scriptLibraryPath: 'https://browserid.org/include.js',
// JavaScript callback after successful assertion
assertionSuccessFunction: function () { }
};
if (options) {
$.extend(settings, options);
}
$.getScript(settings.scriptLibraryPath);
return this.each(function () {
$(this).bind('click.browserid', function () {
if (navigator && navigator.id && navigator.id.getVerifiedEmail) {
navigator.id.getVerifiedEmail(function (assertion) {
if (assertion) {
// if callback is a function, execute it
if (typeof assertionCallback === 'function') {
assertionCallback.apply(this, [assertion]);
} else {
// callback is a string, so assume it's a URL to post the assertion to
var serviceSettings = {};
// assertion param name is "assertion" by default, unless defined otherwise
serviceSettings[(settings.assertionParam || 'assertion')] = assertion;
$.post(assertionCallback, serviceSettings, settings.assertionSuccessFunction);
}
} else {
// in case of an error call error handler, if available
if (settings.errorHandler) {
settings.errorHandler.apply(this);
}
}
});
}
});
});
}
})(jQuery);