From 46d6448e3b3e36f27de72f5430a7998eeb8e5b1f Mon Sep 17 00:00:00 2001 From: Ozbolt Menegatti Date: Mon, 23 Sep 2019 16:01:37 +0200 Subject: [PATCH] More loads, but really small plugin text for into lexonomy --- plugin-loader.js | 90 +++++++++++++++++++++--------------------------- plugin.js | 21 +++++++++++ 2 files changed, 61 insertions(+), 50 deletions(-) create mode 100644 plugin.js diff --git a/plugin-loader.js b/plugin-loader.js index bbf56a9..00fd40d 100644 --- a/plugin-loader.js +++ b/plugin-loader.js @@ -1,58 +1,48 @@ -{ -plugin: '//plugins.lexonomy.cjvt.si/vsms', -editor: function(div, entry, uneditable) { - var self = this; - var div = $(div); - div.append('

Loading...

'); - +function plugin_load(config, div, entry) { + $("#load-pre-status").text("Loading..."); var status_span = $('#load-status'); - $.getJSON(self.plugin + "/config.json", function(config) { - 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); - } + + 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; + } + + config.javascript.forEach(function(script) { + $.ajax({ + dataType: "script", + cache: true, + url: script, + success: function () { + status_span.text(progress + 1 + ""); 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); + Object.keys(config.globals).forEach(function(global_name) { + $.get(config.globals[global_name], function(data) { + window[global_name] = data; + check(); }); }); -}, -harvester: function(div) { - if(typeof plugin_save !== 'undefined') return plugin_save(div); -} + + 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); + }); } diff --git a/plugin.js b/plugin.js new file mode 100644 index 0000000..0db63f6 --- /dev/null +++ b/plugin.js @@ -0,0 +1,21 @@ +{ +plugin: 'vsms', +url: '//plugins.lexonomy.cjvt.si', +editor: function(div, entry, uneditable) { + $(div).append('

INIT

'); + var progress_ctr = 2, config = null; + + $.getJSON(this.url + "/" + this.plugin + "/config.json", function(local_config) { + config = local_config; + if(--progress_ctr == 0) plugin_load(config, div, entry); + }); + + var script_url = this.url + "/plugin-loader.js"; + $.ajax({ dataType: "script", cache: true, url: script_url, success: function () { + if(--progress_ctr == 0) plugin_load(config, div, entry); + }); +}, +harvester: function(div) { + if(typeof plugin_save !== 'undefined') return plugin_save(div); +} +} \ No newline at end of file