Skip to content

Commit

Permalink
load stylesheets for extensions in the question editor
Browse files Browse the repository at this point in the history
  • Loading branch information
christianp committed Jun 15, 2023
1 parent 37de2a8 commit c19575b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions editor/models.py
Expand Up @@ -549,13 +549,19 @@ def as_json(self):
d['hasScript'] = True
d['scriptURL'] = path
d['scripts'] = list(self.scripts())
d['stylesheets'] = list(self.stylesheets())
return d

def scripts(self):
for f in Path(self.extracted_path).iterdir():
if f.suffix == '.js':
yield f.name

def stylesheets(self):
for f in Path(self.extracted_path).iterdir():
if f.suffix == '.css':
yield f.name

@property
def main_filename(self):
return self.location+'.js'
Expand Down
9 changes: 8 additions & 1 deletion editor/static/js/question/edit.js
Expand Up @@ -1706,7 +1706,7 @@ $(document).ready(function() {

function Extension(q,data) {
var ext = this;
["location","name","edit_url","hasScript","url","scriptURL","author","pk","script_url","scripts"].forEach(function(k) {
["location","name","edit_url","hasScript","url","scriptURL","author","pk","script_url","scripts","stylesheets"].forEach(function(k) {
ext[k] = data[k];
});
this.loadPromise = new Promise((resolve, reject) => {
Expand Down Expand Up @@ -1758,6 +1758,13 @@ $(document).ready(function() {
this.loading(true);

var script_promises = [];
this.stylesheets.forEach(function(name) {
var link = document.createElement('link');
link.setAttribute('href', ext.script_url + name);
link.setAttribute('rel','stylesheet');
document.head.appendChild(link);
console.log(name,link);
});
this.scripts.forEach(function(name) {
var script = document.createElement('script');
script.setAttribute('src', ext.script_url+name);
Expand Down

0 comments on commit c19575b

Please sign in to comment.