From 078ddbf7006d957bbef2daa9735ec9a8bf3d8fcd Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Thu, 23 Nov 2006 21:32:40 +0000 Subject: [PATCH] experiment a little with the use of JavaScript. Right now I use it to make the display of some potentially very long lists (binary packages in source package search results and providers of virtual packages in dependency listings) optional for the user --- lib/Packages/DoSearch.pm | 5 ++--- static/packages.js | 25 +++++++++++++++++++++++++ templates/html/head.tmpl | 1 + templates/html/search.tmpl | 12 ++++++++---- templates/html/show.tmpl | 17 ++++++----------- 5 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 static/packages.js diff --git a/lib/Packages/DoSearch.pm b/lib/Packages/DoSearch.pm index df9a91d..2a59937 100644 --- a/lib/Packages/DoSearch.pm +++ b/lib/Packages/DoSearch.pm @@ -14,7 +14,7 @@ our @EXPORT = qw( do_search ); use Deb::Versions; use Packages::I18N::Locale; use Packages::Search qw( :all ); -use Packages::CGI qw( :DEFAULT msg ); +use Packages::CGI qw( :DEFAULT msg error ); use Packages::DB; use Packages::Config qw( $DBDIR @SUITES @ARCHIVES $ROOT ); @@ -156,8 +156,7 @@ sub do_search { if ($arch ne 'virtual') { $pkgs{$pkg}{$suite}{$version}{$arch} = 1; $subsect{$pkg}{$suite}{$version} = $subsection; - $sect{$pkg}{$suite}{$version} = $section - unless $section eq 'main'; + $sect{$pkg}{$suite}{$version} = $section; $archives{$pkg}{$suite}{$version} ||= $archive; $desc{$pkg}{$suite}{$version} = $desc; diff --git a/static/packages.js b/static/packages.js new file mode 100644 index 0000000..c33e06d --- /dev/null +++ b/static/packages.js @@ -0,0 +1,25 @@ + +function init_toggle_elem(id_str,user_str) { + toggle_toggle_elem(id_str,user_str,'hide'); +} + +function toggle_toggle_elem(id_str,user_str,mode) { + var other_mode = ( mode == "hide" ) ? "show" : "hide"; + var link = document.createElement("a"); + link.setAttribute("href","javascript:toggle_toggle_elem(\""+id_str+"\",\""+user_str+"\",\""+other_mode+"\")"); + var txt = document.createTextNode("["+other_mode+" "+user_str+"]"); + link.appendChild(txt); + if (document.getElementById("js_"+id_str).childNodes.length > 0) { + document.getElementById("js_"+id_str).replaceChild(link,document.getElementById("js_"+id_str).firstChild); + } else { + document.getElementById("js_"+id_str).appendChild(link); + } + toggleDisplay(document.getElementById("html_"+id_str)); +} + +function toggleDisplay(obj) { + if (obj.style.display == "none") + obj.style.display = ""; + else + obj.style.display = "none"; +} diff --git a/templates/html/head.tmpl b/templates/html/head.tmpl index 31cc40b..734d92a 100644 --- a/templates/html/head.tmpl +++ b/templates/html/head.tmpl @@ -11,6 +11,7 @@ +