From 1c7785957e4ca02e435ece8e05b6a2fe9ac5130d Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 1 Dec 2018 17:42:13 +0000 Subject: [PATCH] Add waitfor function to await mermaid existing --- layouts/partials/script_async.html | 2 +- static/src/js/index.js | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/layouts/partials/script_async.html b/layouts/partials/script_async.html index 578dfcf..c1c59cc 100644 --- a/layouts/partials/script_async.html +++ b/layouts/partials/script_async.html @@ -1,2 +1,2 @@ {{ $script := resources.Get . | minify | fingerprint }} - + diff --git a/static/src/js/index.js b/static/src/js/index.js index 1a3519d..7c6b7f8 100644 --- a/static/src/js/index.js +++ b/static/src/js/index.js @@ -2,6 +2,16 @@ var Clipboard = require('clipboard'); +function waitFor(global, callback) { + // Wait for a property to exist on window before runnig callback + var intervalId = setInterval(function () { + if (window[global]) { + clearInterval(intervalId); + callback(); + } + }, 100); +} + $('.image').each(function () { // setup div-image hybrids var ele = $(this); @@ -32,9 +42,12 @@ $(document).ready(function () { } }); - mermaid.initialize({ - startOnLoad: true + waitFor('mermaid', function () { + mermaid.initialize({ + startOnLoad: true + }); }); + }); $('.navbar-brand').on('click', function (event) {