[Secure-testing-commits] r28928 - bin lib/python static

Holger Levsen holger at moszumanska.debian.org
Sat Sep 20 09:42:28 UTC 2014


Author: holger
Date: 2014-09-20 09:42:28 +0000 (Sat, 20 Sep 2014)
New Revision: 28928

Added:
   static/script.js
Modified:
   bin/tracker_service.py
   lib/python/web_support.py
Log:
move javascript code into external file

Modified: bin/tracker_service.py
===================================================================
--- bin/tracker_service.py	2014-09-20 09:14:14 UTC (rev 28927)
+++ bin/tracker_service.py	2014-09-20 09:42:28 UTC (rev 28928)
@@ -88,23 +88,9 @@
 class TrackerService(webservice_base_class):
     head_contents = compose(
 	LINK(' ', href="/tracker/style.css"),
-	SCRIPT('''var old_query_value = "";
-	function selectSearch() {
-	document.searchForm.query.focus();
-	}
+	SCRIPT(' ', src="/tracker/script.js"),
+	).toHTML()
 
-	function onSearch(query) {
-	if (old_query_value == "") {
-		if (query.length > 5) {
-		old_query_value = query;
-		document.searchForm.submit();
-		} else {
-		old_query_value = query;
-		}
-	}
-	}
-	''')).toHTML()
-
     nvd_text =  P('''If a "**" is included, the urgency field was automatically
         assigned by the NVD (National Vulnerability Database). Note that this
         rating is automatically derived from a set of known factors about the
@@ -149,6 +135,7 @@
         self.register('data/report', self.page_report)
         self.register('style.css', self.page_style_css)
         self.register('logo.png', self.page_logo_png)
+        self.register('script.js', self.page_script_js)
 
     def page_style_css(self, path, params, url):
         f=open('../static/style.css', 'r')
@@ -162,6 +149,13 @@
 	f.close()
         return BinaryResult(content,'image/png')
 
+    def page_script_js(self, path, params, url):
+        f=open('../static/script.js', 'r')
+        content=f.read()
+        f.close()
+        return BinaryResult(content,'text/javascript')
+
+
     def page_home(self, path, params, url):
         query = params.get('query', ('',))[0]
         if query:

Modified: lib/python/web_support.py
===================================================================
--- lib/python/web_support.py	2014-09-20 09:14:14 UTC (rev 28927)
+++ lib/python/web_support.py	2014-09-20 09:42:28 UTC (rev 28928)
@@ -377,8 +377,8 @@
     return tag('a', text, href=str(url))
 def STYLE(contents, type='text/css'):
     return tag('style', contents, type=type)
-def SCRIPT(contents, type="text/javascript", language="JavaScript"):
-    return tag('script', contents, type=type, language=language)
+def SCRIPT(contents, type="text/javascript", src=""):
+    return tag('script', contents, type=type, src=src)
 def LINK(contents, type="text/css", rel="stylesheet", href=""):
     return tag('link', contents, type=type, rel=rel, href=href)
 def TITLE(contents):

Added: static/script.js
===================================================================
--- static/script.js	                        (rev 0)
+++ static/script.js	2014-09-20 09:42:28 UTC (rev 28928)
@@ -0,0 +1,15 @@
+var old_query_value = "";
+function selectSearch() {
+document.searchForm.query.focus();
+}
+
+function onSearch(query) {
+if (old_query_value == "") {
+	if (query.length > 5) {
+	old_query_value = query;
+	document.searchForm.submit();
+	} else {
+	old_query_value = query;
+	}
+}
+}




More information about the Secure-testing-commits mailing list