summaryrefslogtreecommitdiffstats
path: root/js/field.js
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2012-09-26 08:32:58 +0200
committerByron Jones <bjones@mozilla.com>2012-09-26 08:32:58 +0200
commit3700f44dcd4fddb7798619451275b05f12a99032 (patch)
treed9ed724100d30ae392cf3781f5871e15888db541 /js/field.js
parenteacdf2e2ef8186d5421582276437116512f3780b (diff)
downloadbugzilla-3700f44dcd4fddb7798619451275b05f12a99032.tar.gz
bugzilla-3700f44dcd4fddb7798619451275b05f12a99032.tar.xz
Bug 437212: sync bmo code with upstream
Diffstat (limited to 'js/field.js')
-rw-r--r--js/field.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/js/field.js b/js/field.js
index ede2e43b9..a17fbbb3a 100644
--- a/js/field.js
+++ b/js/field.js
@@ -795,3 +795,51 @@ YAHOO.bugzilla.keywordAutocomplete = {
});
}
};
+
+/**
+ * Force the browser to honour the selected option when a page is refreshed,
+ * but only if the user hasn't explicitly selected a different option.
+ */
+function initDirtyFieldTracking() {
+ // old IE versions don't provide the information we need to make this fix work
+ // however they aren't affected by this issue, so it's ok to ignore them
+ if (YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie <= 8) return;
+ 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) continue;
+ if (!el_dirty.value) {
+ var preSelected = bz_preselectedOptions(el);
+ if (!el.multiple) {
+ preSelected.selected = true;
+ } else {
+ el.selectedIndex = -1;
+ for (var j = 0, m = preSelected.length; j < m; j++) {
+ preSelected[j].selected = true;
+ }
+ }
+ }
+ YAHOO.util.Event.on(el, "change", function(e) {
+ var el = e.target || e.srcElement;
+ var preSelected = bz_preselectedOptions(el);
+ var currentSelected = bz_selectedOptions(el);
+ var isDirty = false;
+ if (!el.multiple) {
+ isDirty = preSelected.index != currentSelected.index;
+ } else {
+ if (preSelected.length != currentSelected.length) {
+ isDirty = true;
+ } else {
+ for (var i = 0, l = preSelected.length; i < l; i++) {
+ if (currentSelected[i].index != preSelected[i].index) {
+ isDirty = true;
+ break;
+ }
+ }
+ }
+ }
+ document.getElementById(el.name + '_dirty').value = isDirty ? '1' : '';
+ });
+ }
+}