parent
002f6aa7fb
commit
23414b6d8b
@ -1,48 +1,56 @@
|
||||
function plugin_load(config, div, entry) {
|
||||
$("#load-pre-status").text("Loading...");
|
||||
var status_span = $('#load-status');
|
||||
|
||||
var len1 = config.javascript && config.javascript.length || 0;
|
||||
var len2 = config.globals && config.javascript.length || 0;
|
||||
var num_progress = len1 + len2;
|
||||
|
||||
status_span.after(" / " + num_progress);
|
||||
status_span.text("0");
|
||||
|
||||
var progress = 0;
|
||||
var check = function() {
|
||||
if (++progress == num_progress) {
|
||||
status_span.parent().empty();
|
||||
if(typeof plugin_init !== 'undefined') plugin_init(div, entry);
|
||||
if(typeof plugin_render !== 'undefined') plugin_render(div, entry);
|
||||
}
|
||||
}
|
||||
|
||||
config.javascript.forEach(function(script) {
|
||||
$.ajax({
|
||||
dataType: "script",
|
||||
cache: true,
|
||||
url: script,
|
||||
success: function () {
|
||||
status_span.text(progress + 1 + "");
|
||||
check();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(config.globals).forEach(function(global_name) {
|
||||
$.get(config.globals[global_name], function(data) {
|
||||
window[global_name] = data;
|
||||
check();
|
||||
});
|
||||
});
|
||||
|
||||
config.css.forEach(function(css_url) {
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.type = 'text/css';
|
||||
link.href = css_url;
|
||||
link.media = 'all';
|
||||
$('head').append(link);
|
||||
});
|
||||
}
|
||||
function plugin_start(div, entry, editable) {
|
||||
if(typeof plugin_init !== 'undefined') plugin_init(div, entry, editable);
|
||||
if(typeof plugin_render !== 'undefined') plugin_render(div, entry);
|
||||
}
|
||||
|
||||
function plugin_load(config, div, entry, editable) {
|
||||
$("#load-pre-status").text("Loading...");
|
||||
var status_span = $('#load-status');
|
||||
|
||||
var len_deps = config.dependencies && config.dependencies.length || 0;
|
||||
var len_globals = config.globals && Object.keys(config.globals).length || 0;
|
||||
|
||||
var progress = 0;
|
||||
var num_progress = len_deps + len_globals;
|
||||
|
||||
status_span.after(" / " + num_progress);
|
||||
status_span.text("0");
|
||||
|
||||
var check = function() {
|
||||
status_span.text(progress + 1 + "");
|
||||
if (++progress >= num_progress) { // has to be >= for num_progress = 0
|
||||
status_span.parent().empty();
|
||||
$.ajax({dataType: "script", cache: true, url: config.javascript, success: function() { plugin_start(div, entry, editable); }});
|
||||
}
|
||||
}
|
||||
|
||||
config.dependencies.forEach(function(script) {
|
||||
$.ajax({
|
||||
dataType: "script",
|
||||
cache: true,
|
||||
url: script,
|
||||
success: check
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(config.globals).forEach(function(global_name) {
|
||||
$.get(config.globals[global_name], function(data) {
|
||||
window[global_name] = data;
|
||||
check();
|
||||
});
|
||||
});
|
||||
|
||||
config.css.forEach(function(css_url) {
|
||||
var link = document.createElement('link');
|
||||
link.rel = 'stylesheet';
|
||||
link.type = 'text/css';
|
||||
link.href = css_url;
|
||||
link.media = 'all';
|
||||
$('head').append(link);
|
||||
});
|
||||
|
||||
// always adding a style element for to use for convenience
|
||||
$('head').append($('<style id="dynamic_styler"></style>'));
|
||||
|
||||
if(num_progress == 0) check();
|
||||
}
|
||||
|
Loading…
Reference in new issue