From 2957d625cc4390d99154fa37fb2158b597cdaec4 Mon Sep 17 00:00:00 2001 From: Byron Jones Date: Tue, 12 Aug 2014 13:44:08 +0800 Subject: Bug 1041964: Autofocus on the comment textarea when selecting a value which has an auto-comment configured --- extensions/TrackingFlags/web/js/tracking_flags.js | 32 ++++++++++++++++++++--- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'extensions/TrackingFlags/web/js') diff --git a/extensions/TrackingFlags/web/js/tracking_flags.js b/extensions/TrackingFlags/web/js/tracking_flags.js index 17513ffe4..041ae43f5 100644 --- a/extensions/TrackingFlags/web/js/tracking_flags.js +++ b/extensions/TrackingFlags/web/js/tracking_flags.js @@ -42,11 +42,35 @@ function show_tracking_flags(flag_type) { function tracking_flag_change(e) { var value = e.value; - if (!TrackingFlags.comments[e.name]) - return; - var prefill = TrackingFlags.comments[e.name][e.value]; - if (!prefill) + var prefill; + if (TrackingFlags.comments[e.name]) + prefill = TrackingFlags.comments[e.name][e.value]; + if (!prefill) { + var cr = document.getElementById('cr_' + e.id); + if (cr) + cr.parentElement.removeChild(cr); return; + } + if (!document.getElementById('cr_' + e.id)) { + // create "comment required" + var span = document.createElement('span'); + span.id = 'cr_' + e.id; + span.appendChild(document.createTextNode('(')); + var a = document.createElement('a'); + a.appendChild(document.createTextNode('comment required')); + a.href = '#'; + a.onclick = function() { + var c = document.getElementById('comment'); + c.focus(); + c.select(); + document.getElementById('add_comment').scrollIntoView(); + return false; + }; + span.appendChild(a); + span.appendChild(document.createTextNode(')')); + e.parentNode.appendChild(span); + } + // prefill comment var commentEl = document.getElementById('comment'); if (!commentEl) return; -- cgit v1.2.3-24-g4f1b