Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

add a Team receiving widget #138

Merged
merged 23 commits into from
Jun 30, 2016
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions lib/v2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/**
* Gratipay widget main initialization.
*
* Initializes widgets and pulls in the Widgets API if it isn't already loaded
*/
(function() {
'use strict';

// Short wrapper around document.querySelectorAll()
function $(selector) {
return document.querySelectorAll(selector);
}

// Slurp up widgets (identified by having the `data-gratipay-username` property)
var elements = $('[data-gratipay-teamslug]');

// Cache length
var length = elements.length;

// Grab window.Gratipay if available
var Gratipay = window.Gratipay || {};

// Where's our files?
var api = window.grtpAPI || 'https://grtp.co/v1/';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be v2.


window._grtp = window._grtp || [];

// Load widget API if it hasn't been
if (!Gratipay.widgets && !$('script[src="' + api + 'api.js"]').length) {
var grtp = document.createElement('script');
grtp.src = api + 'api.js';
$('head')[0].appendChild(grtp);
}

// Load widgets
for (var i=0; i<length; i++) {
var element = elements[i];

// Ignore widgets with the `data-gratipay-readystatus` property
if (!element.getAttribute('data-gratipay-readystatus')) {
if (Gratipay.widgets) {
Gratipay.widgets.load(element);
} else {
_grtp.push(element);
}

element.setAttribute('data-gratipay-readystatus', 'loading');
}
}
})();
Loading