aboutsummaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorByron Jones <bjones@mozilla.com>2014-02-13 13:45:42 +0800
committerByron Jones <bjones@mozilla.com>2014-02-13 13:45:42 +0800
commitadceb1cda6441d2969ed5a3d6d45add6f33c6df7 (patch)
treeb97e5509c54029d6cb5d1873ba83c02da93c0e6b /js
parenta7ca86321e295e6df44386826aee90deca50ba20 (diff)
downloadbugs-adceb1cda6441d2969ed5a3d6d45add6f33c6df7.tar
bugs-adceb1cda6441d2969ed5a3d6d45add6f33c6df7.tar.gz
bugs-adceb1cda6441d2969ed5a3d6d45add6f33c6df7.tar.bz2
bugs-adceb1cda6441d2969ed5a3d6d45add6f33c6df7.tar.xz
bugs-adceb1cda6441d2969ed5a3d6d45add6f33c6df7.zip
Bug 40896: Bugzilla needs a "preview" mode for comments
r=gerv, a=justdave
Diffstat (limited to 'js')
-rw-r--r--js/field.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/js/field.js b/js/field.js
index 900299ee0..670c70a86 100644
--- a/js/field.js
+++ b/js/field.js
@@ -983,3 +983,79 @@ function initDirtyFieldTracking() {
});
}
}
+
+/**
+ * Comment preview
+ */
+
+var last_comment_text = '';
+
+function show_comment_preview(bug_id) {
+ var Dom = YAHOO.util.Dom;
+ var comment = document.getElementById('comment');
+ var preview = document.getElementById('comment_preview');
+ if (!comment || !preview) return;
+ if (Dom.hasClass('comment_preview_tab', 'active_comment_tab')) return;
+
+ preview.style.width = (comment.clientWidth - 4) + 'px';
+ preview.style.height = comment.offsetHeight + 'px';
+
+ Dom.addClass(comment, 'bz_default_hidden');
+ Dom.removeClass('comment_tab', 'active_comment_tab');
+ Dom.removeClass(preview, 'bz_default_hidden');
+ Dom.addClass('comment_preview_tab', 'active_comment_tab');
+
+ Dom.addClass('comment_preview_error', 'bz_default_hidden');
+
+ if (last_comment_text == comment.value)
+ return;
+
+ Dom.addClass('comment_preview_text', 'bz_default_hidden');
+ Dom.removeClass('comment_preview_loading', 'bz_default_hidden');
+
+ YAHOO.util.Connect.setDefaultPostHeader('application/json', true);
+ YAHOO.util.Connect.asyncRequest('POST', 'jsonrpc.cgi',
+ {
+ success: function(res) {
+ data = YAHOO.lang.JSON.parse(res.responseText);
+ if (data.error) {
+ Dom.addClass('comment_preview_loading', 'bz_default_hidden');
+ Dom.removeClass('comment_preview_error', 'bz_default_hidden');
+ Dom.get('comment_preview_error').innerHTML =
+ YAHOO.lang.escapeHTML(data.error.message);
+ } else {
+ document.getElementById('comment_preview_text').innerHTML = data.result.html;
+ Dom.addClass('comment_preview_loading', 'bz_default_hidden');
+ Dom.removeClass('comment_preview_text', 'bz_default_hidden');
+ last_comment_text = comment.value;
+ }
+ },
+ failure: function(res) {
+ Dom.addClass('comment_preview_loading', 'bz_default_hidden');
+ Dom.removeClass('comment_preview_error', 'bz_default_hidden');
+ Dom.get('comment_preview_error').innerHTML =
+ YAHOO.lang.escapeHTML(res.responseText);
+ }
+ },
+ YAHOO.lang.JSON.stringify({
+ version: "1.1",
+ method: 'Bug.render_comment',
+ params: {
+ id: bug_id,
+ text: comment.value
+ }
+ })
+ );
+}
+
+function show_comment_edit() {
+ var comment = document.getElementById('comment');
+ var preview = document.getElementById('comment_preview');
+ if (!comment || !preview) return;
+ if (YAHOO.util.Dom.hasClass(comment, 'active_comment_tab')) return;
+
+ YAHOO.util.Dom.addClass(preview, 'bz_default_hidden');
+ YAHOO.util.Dom.removeClass('comment_preview_tab', 'active_comment_tab');
+ YAHOO.util.Dom.removeClass(comment, 'bz_default_hidden');
+ YAHOO.util.Dom.addClass('comment_tab', 'active_comment_tab');
+}