From b4f682b53315a5c2e61d230014929fd1925c16fd Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Sat, 20 Sep 2014 09:42:28 +0000 Subject: move javascript code into external file git-svn-id: svn+ssh://svn.debian.org/svn/secure-testing@28928 e39458fd-73e7-0310-bf30-c45bca0a0e42 --- bin/tracker_service.py | 26 ++++++++++---------------- lib/python/web_support.py | 4 ++-- static/script.js | 15 +++++++++++++++ 3 files changed, 27 insertions(+), 18 deletions(-) create mode 100644 static/script.js diff --git a/bin/tracker_service.py b/bin/tracker_service.py index 3da96dc9cf..a633c558f3 100644 --- a/bin/tracker_service.py +++ b/bin/tracker_service.py @@ -88,22 +88,8 @@ class BugFilterNoDSA(BugFilter): class TrackerService(webservice_base_class): head_contents = compose( LINK(' ', href="/tracker/style.css"), - SCRIPT('''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; - } - } - } - ''')).toHTML() + SCRIPT(' ', src="/tracker/script.js"), + ).toHTML() nvd_text = P('''If a "**" is included, the urgency field was automatically assigned by the NVD (National Vulnerability Database). Note that this @@ -149,6 +135,7 @@ class TrackerService(webservice_base_class): 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 @@ class TrackerService(webservice_base_class): 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: diff --git a/lib/python/web_support.py b/lib/python/web_support.py index e4b82477e4..82bb4c56ee 100644 --- a/lib/python/web_support.py +++ b/lib/python/web_support.py @@ -377,8 +377,8 @@ def A(url, text=None): 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): diff --git a/static/script.js b/static/script.js new file mode 100644 index 0000000000..62ec7ebf29 --- /dev/null +++ b/static/script.js @@ -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; + } +} +} -- cgit v1.2.3