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.
 It also adds the original version of the css_browser_selector
 software with full headers.
Author: Andreas Bombe, Julian Gilbey
Forwarded: not-needed
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- /dev/null
+++ b/web/browsersel.js
@@ -0,0 +1,8 @@
+/*
+CSS Browser Selector v0.4.0 (Nov 02, 2010)
+Rafael Lima (http://rafael.adm.br)
+http://rafael.adm.br/css_browser_selector
+License: http://creativecommons.org/licenses/by/2.5/
+Contributors: http://rafael.adm.br/css_browser_selector#contributors
+*/
+function css_browser_selector(u){var ua=u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1},g='gecko',w='webkit',s='safari',o='opera',m='mobile',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3.6')?g+' ff3 ff3_6':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('blackberry')?m+' blackberry':is('android')?m+' android':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?m+' j2me':is('iphone')?m+' iphone':is('ipod')?m+' ipod':is('ipad')?m+' ipad':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win'+(is('windows nt 6.0')?' vista':''):is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);
--- a/aqt/mediasrv.py
+++ b/aqt/mediasrv.py
@@ -24,6 +24,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
@@ -118,6 +119,10 @@
         if path.startswith(targetPath):
             newPath = os.path.join(_exportFolder, path[len(targetPath):])
             return newPath
+        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
@@ -239,8 +239,26 @@
         from aqt import mw
         return "http://localhost:%d/_anki/%s" % (mw.mediaServer.getPort(), path)
 
+    def sysBundlePath(self, path):
+        from aqt import mw
+        return "http://localhost:%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)
