From 8fba371d1a2e2ef5c76a012902efd41de5f38dd6 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Mon, 16 Jun 2014 17:04:58 +0400 Subject: [PATCH] Move JS from query form template into js/query-form.js --- js/productform.js | 69 -------------- js/query-form.js | 66 ++++++++++++++ template/en/default/search/form.html.tmpl | 90 +------------------ .../default/search/search-advanced.html.tmpl | 2 +- 4 files changed, 69 insertions(+), 158 deletions(-) create mode 100644 js/query-form.js diff --git a/js/productform.js b/js/productform.js index 12ac63e76..bd40242f0 100644 --- a/js/productform.js +++ b/js/productform.js @@ -21,75 +21,6 @@ // Functions to update form select elements based on a // collection of javascript arrays containing strings. -/** - * Reads the selected classifications and updates product, component, - * version and milestone lists accordingly. - * - * @param classfield Select element that contains classifications. - * @param product Select element that contains products. - * @param component Select element that contains components. Can be null if - * there is no such element to update. - * @param version Select element that contains versions. Can be null if - * there is no such element to update. - * @param milestone Select element that contains milestones. Can be null if - * there is no such element to update. - * - * @global prods Array of products indexed by classification name. - * @global first_load Boolean; true if this is the first time this page loads - * or false if not. - * @global last_sel Array that contains last list of products so we know what - * has changed, and optimize for additions. - */ -function selectClassification(classfield, product, component, version, milestone) { - // This is to avoid handling events that occur before the form - // itself is ready, which could happen in buggy browsers. - if (!classfield) - return; - - // If this is the first load and nothing is selected, no need to - // merge and sort all lists; they are created sorted. - if ((first_load) && (classfield.selectedIndex == -1)) { - first_load = false; - return; - } - - // Don't reset first_load as done in selectProduct. That's because we - // want selectProduct to handle the first_load attribute. - - // Stores classifications that are selected. - var sel = Array(); - - // True if sel array has a full list or false if sel contains only - // new classifications that are to be merged to the current list. - var merging = false; - - // If nothing selected, pick all. - var findall = classfield.selectedIndex == -1; - sel = get_selection(classfield, findall, false); - if (!findall) { - // Save sel for the next invocation of selectClassification(). - var tmp = sel; - - // This is an optimization: if we have just added classifications to an - // existing selection, no need to clear the form elements and add - // everything again; just merge the new ones with the existing - // options. - if ((last_sel.length > 0) && (last_sel.length < sel.length)) { - sel = fake_diff_array(sel, last_sel); - merging = true; - } - last_sel = tmp; - } - - // Save original options selected. - var saved_prods = get_selection(product, false, true, null); - - // Do the actual fill/update, reselect originally selected options. - updateSelect(prods, sel, product, merging, null); - restoreSelection(product, saved_prods); - selectProduct(product, component, version, milestone, null); -} - /** * Reads the selected products and updates component, version and milestone * lists accordingly. diff --git a/js/query-form.js b/js/query-form.js new file mode 100644 index 000000000..b03d21dab --- /dev/null +++ b/js/query-form.js @@ -0,0 +1,66 @@ +// JS for the query form +// License: Dual-license GPL 3.0+ or MPL 1.1+ +// Author(s): Vitaliy Filippov + +// Requires global vars: queryform, allKeywords, checkwidths, userAutocomplete +addListener(window, 'load', function() +{ + document.forms[queryform].content.focus(); + new SimpleAutocomplete("keywords", + function(h) { keywordAutocomplete(h, allKeywords); }, + { emptyText: 'No keywords found', multipleDelimiter: "," } + ); + if (document.getElementById('deadlinefrom')) + { + Calendar.set('deadlinefrom'); + Calendar.set('deadlineto'); + } + new SimpleAutocomplete("email1", userAutocomplete, { emptyText: 'No users found' }); + new SimpleAutocomplete("email2", userAutocomplete, { emptyText: 'No users found' }); + Calendar.set('chfieldfrom'); + Calendar.set('chfieldto'); + new SimpleAutocomplete("chfieldwho", userAutocomplete, { emptyText: 'No users found' }); + + var lim = 250; + function checkw(e) + { + var s = document.getElementById(e); + s.style.minWidth = '100%'; + if (s && s.offsetWidth > lim) + { + s.style.width = lim+'px'; + addListener(s, 'mouseover', function(e) + { + e = e || window.event; + var f = e.relatedTarget || e.fromElement; + if (f == s || f.parentNode == s || !s.style.width && s.offsetWidth <= lim) + return; + var c = s; + while (c && c.nodeName != 'TABLE') + c = c.parentNode; + // FIXME: Удалить вторую таблицу внутри каждой ячейки! Она там нах* не нужна! + c = c.parentNode; + while (c && c.nodeName != 'TABLE') + c = c.parentNode; + var w = (lim+c.parentNode.offsetWidth-c.offsetWidth); + if (w > lim+10) + { + s.style.width = ''; + s.style.maxWidth = w + 'px'; + } + }); + addListener(s, 'mouseout', function(e) { + e = e || window.event; + var t = e.relatedTarget || e.toElement; + if (t == s || t.parentNode == s) + return; + s.style.width = lim+'px'; + s.style.maxWidth = ''; + }); + } + } + for (var i in checkwidths) + { + checkw(checkwidths[i]); + } +}); diff --git a/template/en/default/search/form.html.tmpl b/template/en/default/search/form.html.tmpl index dc4881138..fe912e4f5 100644 --- a/template/en/default/search/form.html.tmpl +++ b/template/en/default/search/form.html.tmpl @@ -25,58 +25,7 @@ - - + [% SET checkwidths = [] %] @@ -94,10 +43,6 @@ addListener(window, 'load', function() - @@ -109,10 +54,6 @@ addListener(window, 'load', function() - [% IF button_name %] @@ -274,16 +215,6 @@ addListener(window, 'load', function() - - [% END %] @@ -299,10 +230,6 @@ addListener(window, 'load', function() value="[% default.deadlinefrom.0 FILTER html %]"> to - (YYYY-MM-DD or relative dates) @@ -508,11 +435,6 @@ addListener(window, 'load', function() - [% END %] @@ -566,10 +488,6 @@ addListener(window, 'load', function() size="10" value="[% default.chfieldfrom.0 FILTER html %]" /> and
(YYYY-MM-DD or relative dates) -
(user login)
@@ -581,11 +499,6 @@ addListener(window, 'load', function() size="20" value="[% default.chfieldvalue.0 FILTER html %]"> - @@ -615,4 +528,5 @@ addListener(window, 'load', function() { diff --git a/template/en/default/search/search-advanced.html.tmpl b/template/en/default/search/search-advanced.html.tmpl index db328a213..c9fa299b8 100644 --- a/template/en/default/search/search-advanced.html.tmpl +++ b/template/en/default/search/search-advanced.html.tmpl @@ -35,7 +35,7 @@ var queryform = "queryform" title = "Search for $terms.bugs" onload = "enableHelp();" javascript = js_data - javascript_urls = [ "js/productform.js", "js/help.js", "js/calendar.js" ] + javascript_urls = [ "js/help.js", "js/calendar.js" ] style_urls = [ "skins/standard/help.css", "skins/standard/calendar.css" ] doc_section = "query.html" style = "dl.bug_changes dt {