Assume that web assets without a specified subpath are under /_anki

Maintains compatibility with existing add-ons
This commit is contained in:
Glutanimate 2020-02-15 15:03:43 +01:00
parent c86e55d451
commit 0e5dea4c9f
9 changed files with 38 additions and 41 deletions

View file

@ -1643,16 +1643,16 @@ where id in %s"""
def _setupPreviewWebview(self):
jsinc = [
"_anki/jquery.js",
"_anki/browsersel.js",
"_anki/mathjax/conf.js",
"_anki/mathjax/MathJax.js",
"_anki/reviewer.js",
"jquery.js",
"browsersel.js",
"mathjax/conf.js",
"mathjax/MathJax.js",
"reviewer.js",
]
web_context = PreviewDialog(dialog=self._previewWindow, browser=self)
self._previewWeb.stdHtml(
self.mw.reviewer.revHtml(),
css=["_anki/reviewer.css"],
css=["reviewer.css"],
js=jsinc,
context=web_context,
)

View file

@ -208,23 +208,17 @@ class CardLayout(QDialog):
pform.backWeb = AnkiWebView(title="card layout back")
pform.backPrevBox.addWidget(pform.backWeb)
jsinc = [
"_anki/jquery.js",
"_anki/browsersel.js",
"_anki/mathjax/conf.js",
"_anki/mathjax/MathJax.js",
"_anki/reviewer.js",
"jquery.js",
"browsersel.js",
"mathjax/conf.js",
"mathjax/MathJax.js",
"reviewer.js",
]
pform.frontWeb.stdHtml(
self.mw.reviewer.revHtml(),
css=["_anki/reviewer.css"],
js=jsinc,
context=self,
self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self,
)
pform.backWeb.stdHtml(
self.mw.reviewer.revHtml(),
css=["_anki/reviewer.css"],
js=jsinc,
context=self,
self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self,
)
pform.frontWeb.set_bridge_command(self._on_bridge_cmd, self)
pform.backWeb.set_bridge_command(self._on_bridge_cmd, self)

View file

@ -107,8 +107,8 @@ class DeckBrowser:
stats = self._renderStats()
self.web.stdHtml(
self._body % dict(tree=tree, stats=stats, countwarn=self._countWarn()),
css=["_anki/deckbrowser.css"],
js=["_anki/jquery.js", "_anki/jquery-ui.js", "_anki/deckbrowser.js"],
css=["deckbrowser.css"],
js=["jquery.js", "jquery-ui.js", "deckbrowser.js"],
context=self,
)
self.web.key = "deckBrowser"

View file

@ -164,8 +164,8 @@ class Editor:
# then load page
self.web.stdHtml(
_html % (bgcol, bgcol, topbuts, _("Show Duplicates")),
css=["_anki/editor.css"],
js=["_anki/jquery.js", "_anki/editor.js"],
css=["editor.css"],
js=["jquery.js", "editor.js"],
context=self,
)

View file

@ -149,8 +149,8 @@ class Overview:
desc=self._desc(deck),
table=self._table(),
),
css=["_anki/overview.css"],
js=["_anki/jquery.js", "_anki/overview.js"],
css=["overview.css"],
js=["jquery.js", "overview.js"],
context=self,
)

View file

@ -145,13 +145,13 @@ class Reviewer:
# main window
self.web.stdHtml(
self.revHtml(),
css=["_anki/reviewer.css"],
css=["reviewer.css"],
js=[
"_anki/jquery.js",
"_anki/browsersel.js",
"_anki/mathjax/conf.js",
"_anki/mathjax/MathJax.js",
"_anki/reviewer.js",
"jquery.js",
"browsersel.js",
"mathjax/conf.js",
"mathjax/MathJax.js",
"reviewer.js",
],
context=self,
)
@ -159,8 +159,8 @@ class Reviewer:
self.bottom.web.show()
self.bottom.web.stdHtml(
self._bottomHTML(),
css=["_anki/toolbar-bottom.css", "_anki/reviewer-bottom.css"],
js=["_anki/jquery.js", "_anki/reviewer-bottom.js"],
css=["toolbar-bottom.css", "reviewer-bottom.css"],
js=["jquery.js", "reviewer-bottom.js"],
context=ReviewerBottomBar(self),
)

View file

@ -98,7 +98,7 @@ class DeckStats(QDialog):
self.form.web.title = "deck stats"
self.form.web.stdHtml(
"<html><body>" + self.report + "</body></html>",
js=["_anki/jquery.js", "_anki/plot.js"],
js=["jquery.js", "plot.js"],
context=self,
)
self.mw.progress.finish()

View file

@ -49,9 +49,7 @@ class Toolbar:
link_handler = link_handler or self._linkHandler
self.web.set_bridge_command(link_handler, web_context)
self.web.stdHtml(
self._body % self._centerLinks(),
css=["_anki/toolbar.css"],
context=web_context,
self._body % self._centerLinks(), css=["toolbar.css"], context=web_context,
)
self.web.adjustHeightToFit()
@ -147,7 +145,7 @@ class BottomBar(Toolbar):
self.web.set_bridge_command(link_handler, web_context)
self.web.stdHtml(
self._centerBody % buf,
css=["_anki/toolbar.css", "_anki/toolbar-bottom.css"],
css=["toolbar.css", "toolbar-bottom.css"],
context=web_context,
)
self.web.adjustHeightToFit()

View file

@ -327,8 +327,8 @@ class AnkiWebView(QWebEngineView): # type: ignore
web_content = WebContent(
body=body,
head=head,
js=["_anki/webview.js"] + (["_anki/jquery.js"] if js is None else js),
css=["_anki/webview.css"] + ([] if css is None else css),
js=["webview.js"] + (["jquery.js"] if js is None else js),
css=["webview.css"] + ([] if css is None else css),
)
gui_hooks.webview_will_set_content(web_content, context)
@ -411,7 +411,12 @@ body {{ zoom: {}; background: {}; {} }}
def webBundlePath(self, path: str) -> str:
from aqt import mw
return "http://127.0.0.1:%d/%s" % (mw.mediaServer.getPort(), path)
if path.startswith("/"):
subpath = ""
else:
subpath = "/_anki/"
return f"http://127.0.0.1:{mw.mediaServer.getPort()}{subpath}{path}"
def bundledScript(self, fname: str) -> str:
return '<script src="%s"></script>' % self.webBundlePath(fname)