Description: Replace minified Javascript with references to libjs packages
 The Javascript packages in the original anki.js are minified versions
 of JQuery and other packages without their corresponding sources.
 The dfsg repackaging of the source archive removes this content,
 so this patch adds hooks into files provided by the relevant libjs-*
 packages.  The provided "plot.js" file is a concatenation of three
 files from the FLOT software, so this patch pulls in all three of
 them from the libjs-jquery-flot package.
Author: Andreas Bombe, Julian Gilbey
Forwarded: not-needed
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/aqt/mediasrv.py
+++ b/aqt/mediasrv.py
@@ -25,6 +25,7 @@
         raise Exception("couldn't find web folder")
 
 _exportFolder = _getExportFolder()
+_sysFolder = '/usr/share/javascript'
 
 # webengine on windows sometimes opens a connection and fails to send a request,
 # which will hang the server if unthreaded
@@ -163,6 +164,12 @@
             newPath = os.path.join(addMgr.addonsFolder(), addonPath)
             return newPath
         
+        # catch Debian-specific /_sys references and rewrite them to system folder
+        targetPath = os.path.join(os.getcwd(), "_sys", "")
+        if path.startswith(targetPath):
+            newPath = os.path.join(_sysFolder, path[len(targetPath):])
+            return newPath
+
         return path
 
 # work around Windows machines with incorrect mime type
--- a/aqt/webview.py
+++ b/aqt/webview.py
@@ -301,8 +301,26 @@
         from aqt import mw
         return "http://127.0.0.1:%d/_anki/%s" % (mw.mediaServer.getPort(), path)
 
+    def sysBundlePath(self, path):
+        from aqt import mw
+        return "http://127.0.0.1:%d/_sys/%s" % (mw.mediaServer.getPort(), path)
+
+    sysscripts = {
+        'jquery.js' : ['jquery/jquery.js'],
+        'jquery-ui.js' : ['jquery-ui/jquery-ui.js'],
+        'plot.js' : ['jquery-flot/jquery.flot.min.js',
+                     'jquery-flot/jquery.flot.pie.min.js',
+                     'jquery-flot/jquery.flot.stack.min.js'],
+        'mathjax/MathJax.js' : ['mathjax/MathJax.js'] }
+
     def bundledScript(self, fname):
-        return '<script src="%s"></script>' % self.webBundlePath(fname)
+        if fname in self.sysscripts:
+            scripts = ''
+            for sname in self.sysscripts[fname]:
+                scripts += '<script src="%s"></script>' % self.sysBundlePath(sname)
+            return scripts
+        else:
+            return '<script src="%s"></script>' % self.webBundlePath(fname)
 
     def bundledCSS(self, fname):
         return '<link rel="stylesheet" type="text/css" href="%s">' % self.webBundlePath(fname)
