aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2015-08-01 18:51:44 -0400
committerTeddy Wing2015-08-01 18:53:44 -0400
commiteb38cdeebc31db8ca85d0303c5588e8c0a96b37c (patch)
treefa13761e713b5e8e4c956e5257bb7a588a70e9f2
parent54b0fcdb81e5b2788f5146b321e516f72c51b708 (diff)
downloadjira-whozits-eb38cdeebc31db8ca85d0303c5588e8c0a96b37c.tar.bz2
main.js: Wait until headers are on the page before acting
Don't set ids for the page headers until those headers are available on the page.
-rw-r--r--main.js33
1 files changed, 28 insertions, 5 deletions
diff --git a/main.js b/main.js
index b7bc92b..24d09ac 100644
--- a/main.js
+++ b/main.js
@@ -1,16 +1,39 @@
(function() {
var jira_person_header_class_name = '.ghx-heading';
+ var person_headers;
// Removes spaces from a string
function slugify (str) {
return str.replace(/ /g, '');
}
- Array.prototype.forEach.call(
- document.querySelectorAll(jira_person_header_class_name),
- function(element) {
- element.setAttribute('id', slugify(element.firstChild.textContent));
- console.log(element);
+ function do_when (when, action) {
+ var timeout;
+
+ window.clearTimeout(timeout);
+
+ if (when()) {
+ action();
+ }
+ else {
+ timeout = window.setTimeout(function() {
+ do_when(when, action)
+ }, 500);
+ }
+ }
+
+ do_when(
+ function() {
+ person_headers = document.querySelectorAll(jira_person_header_class_name);
+ return person_headers.length;
+ },
+ function () {
+ Array.prototype.forEach.call(
+ person_headers,
+ function(element) {
+ element.setAttribute('id', slugify(element.firstChild.textContent));
+ }
+ );
}
);
})();