Initial: plugin-loader
This commit is contained in:
		
							parent
							
								
									b85464ee83
								
							
						
					
					
						commit
						310ab1c5aa
					
				
							
								
								
									
										58
									
								
								plugin-loader.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								plugin-loader.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,58 @@ | ||||
| { | ||||
| plugin: '//plugins.lexonomy.cjvt.si/vsms', | ||||
| editor: function(div, entry, uneditable) { | ||||
|     var self = this; | ||||
|     var div = $(div); | ||||
|     div.append('<p>Loading... <span id="load-status"></span></p>'); | ||||
|      | ||||
|     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); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         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); | ||||
|         }); | ||||
|     }); | ||||
| }, | ||||
| harvester: function(div) { | ||||
|     if(typeof plugin_save !== 'undefined') plugin_save(div); | ||||
| } | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user