summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2012-08-07 06:53:31 +0200
committerByron Jones <bjones@mozilla.com>2012-08-07 06:53:31 +0200
commit88c13e9f2694db2d91f0f76f0d485395921135e2 (patch)
tree16517b7c99cb3db883831594f6d40173fd363e97 /js
parent23eaf30f1bb04e6698d11689de28dd1067b560e2 (diff)
downloadbugzilla-88c13e9f2694db2d91f0f76f0d485395921135e2.tar.gz
bugzilla-88c13e9f2694db2d91f0f76f0d485395921135e2.tar.xz
Bug 779434: Fix refreshing a page not updating fields
Diffstat (limited to 'js')
-rw-r--r--js/show_bug.js39
1 files changed, 39 insertions, 0 deletions
diff --git a/js/show_bug.js b/js/show_bug.js
new file mode 100644
index 000000000..c762f9e54
--- /dev/null
+++ b/js/show_bug.js
@@ -0,0 +1,39 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This Source Code Form is "Incompatible With Secondary Licenses", as
+ * defined by the Mozilla Public License, v. 2.0. */
+
+function getPreSelectedIndex(el) {
+ var options = el.options;
+ for (var i = 0, l = options.length; i < l; i++) {
+ var attributes = options[i].attributes;
+ for (var j = 0, m = attributes.length; j < m; j++) {
+ if (attributes[j].name == 'selected') {
+ return i;
+ }
+ }
+ }
+ return 0;
+}
+
+// Force the browser to honour the selected option when a page is refreshed,
+// but if the user hasn't explicitly selected a different option.
+YAHOO.util.Event.onDOMReady(function() {
+ var selects = document.getElementById('changeform').getElementsByTagName('select');
+ for (var i = 0, l = selects.length; i < l; i++) {
+ var el = selects[i];
+ var el_dirty = document.getElementById(el.name + '_dirty');
+ if (el_dirty) {
+ if (!el_dirty.value) {
+ el.selectedIndex = getPreSelectedIndex(el);
+ }
+ YAHOO.util.Event.on(el, "change", function(e) {
+ var el = e.target;
+ var preSelectedIndex = getPreSelectedIndex(el);
+ document.getElementById(el.name + '_dirty').value = preSelectedIndex == el.selectedIndex ? '' : '1';
+ });
+ }
+ }
+});