From 48e37e1c85338dcaa1591823cb25ef7de5db67a1 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Tue, 15 Feb 2011 20:20:09 +0800 Subject: [PATCH] Make the init process in editor_textarea.html more robust in cases where the ace.js isn't loaded in 300ms --- build_support/editor_textarea.html | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/build_support/editor_textarea.html b/build_support/editor_textarea.html index aa54849a..75e30801 100644 --- a/build_support/editor_textarea.html +++ b/build_support/editor_textarea.html @@ -61,16 +61,24 @@ function inject() { }); } +// Call the inject function to load the ace files. inject(); var textAce; - -setTimeout(function() { - var t = document.querySelector("textarea"); +function initAce() { var ace = window.__ace_shadowed__; - textAce = ace.transformTextarea(t); - textAce.setDisplaySettings(true); -}, 300); + // Check if the ace.js file was loaded already, otherwise check back later. + if (ace && ace.transformTextarea) { + var t = document.querySelector("textarea"); + textAce = ace.transformTextarea(t); + textAce.setDisplaySettings(true); + } else { + setTimeout(initAce, 100); + } +} + +// Transform the textarea on the page into an ace editor. +initAce(); document.getElementById("buBuild").onclick = function() { var injectSrc = inject.toString().split("\n").join("");