mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Assume that web assets without a specified subpath are under /_anki
Maintains compatibility with existing add-ons
This commit is contained in:
parent
c86e55d451
commit
0e5dea4c9f
9 changed files with 38 additions and 41 deletions
|
@ -1643,16 +1643,16 @@ where id in %s"""
|
||||||
|
|
||||||
def _setupPreviewWebview(self):
|
def _setupPreviewWebview(self):
|
||||||
jsinc = [
|
jsinc = [
|
||||||
"_anki/jquery.js",
|
"jquery.js",
|
||||||
"_anki/browsersel.js",
|
"browsersel.js",
|
||||||
"_anki/mathjax/conf.js",
|
"mathjax/conf.js",
|
||||||
"_anki/mathjax/MathJax.js",
|
"mathjax/MathJax.js",
|
||||||
"_anki/reviewer.js",
|
"reviewer.js",
|
||||||
]
|
]
|
||||||
web_context = PreviewDialog(dialog=self._previewWindow, browser=self)
|
web_context = PreviewDialog(dialog=self._previewWindow, browser=self)
|
||||||
self._previewWeb.stdHtml(
|
self._previewWeb.stdHtml(
|
||||||
self.mw.reviewer.revHtml(),
|
self.mw.reviewer.revHtml(),
|
||||||
css=["_anki/reviewer.css"],
|
css=["reviewer.css"],
|
||||||
js=jsinc,
|
js=jsinc,
|
||||||
context=web_context,
|
context=web_context,
|
||||||
)
|
)
|
||||||
|
|
|
@ -208,23 +208,17 @@ class CardLayout(QDialog):
|
||||||
pform.backWeb = AnkiWebView(title="card layout back")
|
pform.backWeb = AnkiWebView(title="card layout back")
|
||||||
pform.backPrevBox.addWidget(pform.backWeb)
|
pform.backPrevBox.addWidget(pform.backWeb)
|
||||||
jsinc = [
|
jsinc = [
|
||||||
"_anki/jquery.js",
|
"jquery.js",
|
||||||
"_anki/browsersel.js",
|
"browsersel.js",
|
||||||
"_anki/mathjax/conf.js",
|
"mathjax/conf.js",
|
||||||
"_anki/mathjax/MathJax.js",
|
"mathjax/MathJax.js",
|
||||||
"_anki/reviewer.js",
|
"reviewer.js",
|
||||||
]
|
]
|
||||||
pform.frontWeb.stdHtml(
|
pform.frontWeb.stdHtml(
|
||||||
self.mw.reviewer.revHtml(),
|
self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self,
|
||||||
css=["_anki/reviewer.css"],
|
|
||||||
js=jsinc,
|
|
||||||
context=self,
|
|
||||||
)
|
)
|
||||||
pform.backWeb.stdHtml(
|
pform.backWeb.stdHtml(
|
||||||
self.mw.reviewer.revHtml(),
|
self.mw.reviewer.revHtml(), css=["reviewer.css"], js=jsinc, context=self,
|
||||||
css=["_anki/reviewer.css"],
|
|
||||||
js=jsinc,
|
|
||||||
context=self,
|
|
||||||
)
|
)
|
||||||
pform.frontWeb.set_bridge_command(self._on_bridge_cmd, self)
|
pform.frontWeb.set_bridge_command(self._on_bridge_cmd, self)
|
||||||
pform.backWeb.set_bridge_command(self._on_bridge_cmd, self)
|
pform.backWeb.set_bridge_command(self._on_bridge_cmd, self)
|
||||||
|
|
|
@ -107,8 +107,8 @@ class DeckBrowser:
|
||||||
stats = self._renderStats()
|
stats = self._renderStats()
|
||||||
self.web.stdHtml(
|
self.web.stdHtml(
|
||||||
self._body % dict(tree=tree, stats=stats, countwarn=self._countWarn()),
|
self._body % dict(tree=tree, stats=stats, countwarn=self._countWarn()),
|
||||||
css=["_anki/deckbrowser.css"],
|
css=["deckbrowser.css"],
|
||||||
js=["_anki/jquery.js", "_anki/jquery-ui.js", "_anki/deckbrowser.js"],
|
js=["jquery.js", "jquery-ui.js", "deckbrowser.js"],
|
||||||
context=self,
|
context=self,
|
||||||
)
|
)
|
||||||
self.web.key = "deckBrowser"
|
self.web.key = "deckBrowser"
|
||||||
|
|
|
@ -164,8 +164,8 @@ class Editor:
|
||||||
# then load page
|
# then load page
|
||||||
self.web.stdHtml(
|
self.web.stdHtml(
|
||||||
_html % (bgcol, bgcol, topbuts, _("Show Duplicates")),
|
_html % (bgcol, bgcol, topbuts, _("Show Duplicates")),
|
||||||
css=["_anki/editor.css"],
|
css=["editor.css"],
|
||||||
js=["_anki/jquery.js", "_anki/editor.js"],
|
js=["jquery.js", "editor.js"],
|
||||||
context=self,
|
context=self,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -149,8 +149,8 @@ class Overview:
|
||||||
desc=self._desc(deck),
|
desc=self._desc(deck),
|
||||||
table=self._table(),
|
table=self._table(),
|
||||||
),
|
),
|
||||||
css=["_anki/overview.css"],
|
css=["overview.css"],
|
||||||
js=["_anki/jquery.js", "_anki/overview.js"],
|
js=["jquery.js", "overview.js"],
|
||||||
context=self,
|
context=self,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -145,13 +145,13 @@ class Reviewer:
|
||||||
# main window
|
# main window
|
||||||
self.web.stdHtml(
|
self.web.stdHtml(
|
||||||
self.revHtml(),
|
self.revHtml(),
|
||||||
css=["_anki/reviewer.css"],
|
css=["reviewer.css"],
|
||||||
js=[
|
js=[
|
||||||
"_anki/jquery.js",
|
"jquery.js",
|
||||||
"_anki/browsersel.js",
|
"browsersel.js",
|
||||||
"_anki/mathjax/conf.js",
|
"mathjax/conf.js",
|
||||||
"_anki/mathjax/MathJax.js",
|
"mathjax/MathJax.js",
|
||||||
"_anki/reviewer.js",
|
"reviewer.js",
|
||||||
],
|
],
|
||||||
context=self,
|
context=self,
|
||||||
)
|
)
|
||||||
|
@ -159,8 +159,8 @@ class Reviewer:
|
||||||
self.bottom.web.show()
|
self.bottom.web.show()
|
||||||
self.bottom.web.stdHtml(
|
self.bottom.web.stdHtml(
|
||||||
self._bottomHTML(),
|
self._bottomHTML(),
|
||||||
css=["_anki/toolbar-bottom.css", "_anki/reviewer-bottom.css"],
|
css=["toolbar-bottom.css", "reviewer-bottom.css"],
|
||||||
js=["_anki/jquery.js", "_anki/reviewer-bottom.js"],
|
js=["jquery.js", "reviewer-bottom.js"],
|
||||||
context=ReviewerBottomBar(self),
|
context=ReviewerBottomBar(self),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ class DeckStats(QDialog):
|
||||||
self.form.web.title = "deck stats"
|
self.form.web.title = "deck stats"
|
||||||
self.form.web.stdHtml(
|
self.form.web.stdHtml(
|
||||||
"<html><body>" + self.report + "</body></html>",
|
"<html><body>" + self.report + "</body></html>",
|
||||||
js=["_anki/jquery.js", "_anki/plot.js"],
|
js=["jquery.js", "plot.js"],
|
||||||
context=self,
|
context=self,
|
||||||
)
|
)
|
||||||
self.mw.progress.finish()
|
self.mw.progress.finish()
|
||||||
|
|
|
@ -49,9 +49,7 @@ class Toolbar:
|
||||||
link_handler = link_handler or self._linkHandler
|
link_handler = link_handler or self._linkHandler
|
||||||
self.web.set_bridge_command(link_handler, web_context)
|
self.web.set_bridge_command(link_handler, web_context)
|
||||||
self.web.stdHtml(
|
self.web.stdHtml(
|
||||||
self._body % self._centerLinks(),
|
self._body % self._centerLinks(), css=["toolbar.css"], context=web_context,
|
||||||
css=["_anki/toolbar.css"],
|
|
||||||
context=web_context,
|
|
||||||
)
|
)
|
||||||
self.web.adjustHeightToFit()
|
self.web.adjustHeightToFit()
|
||||||
|
|
||||||
|
@ -147,7 +145,7 @@ class BottomBar(Toolbar):
|
||||||
self.web.set_bridge_command(link_handler, web_context)
|
self.web.set_bridge_command(link_handler, web_context)
|
||||||
self.web.stdHtml(
|
self.web.stdHtml(
|
||||||
self._centerBody % buf,
|
self._centerBody % buf,
|
||||||
css=["_anki/toolbar.css", "_anki/toolbar-bottom.css"],
|
css=["toolbar.css", "toolbar-bottom.css"],
|
||||||
context=web_context,
|
context=web_context,
|
||||||
)
|
)
|
||||||
self.web.adjustHeightToFit()
|
self.web.adjustHeightToFit()
|
||||||
|
|
|
@ -327,8 +327,8 @@ class AnkiWebView(QWebEngineView): # type: ignore
|
||||||
web_content = WebContent(
|
web_content = WebContent(
|
||||||
body=body,
|
body=body,
|
||||||
head=head,
|
head=head,
|
||||||
js=["_anki/webview.js"] + (["_anki/jquery.js"] if js is None else js),
|
js=["webview.js"] + (["jquery.js"] if js is None else js),
|
||||||
css=["_anki/webview.css"] + ([] if css is None else css),
|
css=["webview.css"] + ([] if css is None else css),
|
||||||
)
|
)
|
||||||
|
|
||||||
gui_hooks.webview_will_set_content(web_content, context)
|
gui_hooks.webview_will_set_content(web_content, context)
|
||||||
|
@ -411,7 +411,12 @@ body {{ zoom: {}; background: {}; {} }}
|
||||||
def webBundlePath(self, path: str) -> str:
|
def webBundlePath(self, path: str) -> str:
|
||||||
from aqt import mw
|
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:
|
def bundledScript(self, fname: str) -> str:
|
||||||
return '<script src="%s"></script>' % self.webBundlePath(fname)
|
return '<script src="%s"></script>' % self.webBundlePath(fname)
|
||||||
|
|
Loading…
Reference in a new issue