diff options
author | Robin Appelman <robin@icewind.nl> | 2017-08-27 13:52:29 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-08-28 11:48:12 +0300 |
commit | 659bdc75656635bd85e06da3210be06a3706b5f0 (patch) | |
tree | fdf6e2a9cd6320a4a816b32b46083fd8b5686669 /js | |
parent | c1ca6f64448c0f2e577107f5b9b8ac57ee809ae8 (diff) |
initialize preview plugins on demand
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'js')
-rw-r--r-- | js/editor.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/js/editor.js b/js/editor.js index 73c6837..ac042ad 100644 --- a/js/editor.js +++ b/js/editor.js @@ -67,6 +67,8 @@ var Files_Texteditor = { this.previewPlugins[mimeType] = plugin; }, + previewPluginsLoaded: {}, + /** * preview element */ @@ -232,9 +234,6 @@ var Files_Texteditor = { this.$container = container; this.registerFileActions(); this.oldTitle = document.title; - $.each(this.previewPlugins, function(mime, plugin) { - plugin.init(); - }); }, getSupportedMimetypes: function() { @@ -314,7 +313,11 @@ var Files_Texteditor = { _self.preview.addClass(file.mime.replace('/','-')); container.find('#editor_container').addClass('hasPreview'); container.find('#editor_overlay').addClass('hasPreview'); - _self.previewPluginOnChange = _.debounce(_self.previewPlugins[file.mime].preview, 200); + _self.previewPluginOnChange = _.debounce(function(text, element) { + _self.loadPreviewPlugin(file.mime).then(function() { + _self.previewPlugins[file.mime].preview(text, element); + }); + },200); var text = window.aceEditor.getSession().getValue(); _self.previewPluginOnChange(text, _self.preview); window.aceEditor.resize(); @@ -335,6 +338,15 @@ var Files_Texteditor = { }); }, + loadPreviewPlugin: function(mime) { + if (this.previewPluginsLoaded[mime]) { + return $.Deferred().resolve().promise(); + } + this.previewPluginsLoaded[mime] = true; + var plugin = this.previewPlugins[mime]; + return $.when(plugin.init()); + }, + /** * Load the editor control bar */ |