Enable floating "file a bug" div to spec to facilitate comments/feedback.
authorGary Kacmarcik <garykac@google.com>
Wed, 21 Aug 2013 15:00:11 -0700
changeset 464 2471b17ce4f8
parent 463 1b4e14ed10f6
child 465 4497fdb7208b
Enable floating "file a bug" div to spec to facilitate comments/feedback.

Includes local copy of bug-assist.js
html/DOM3-Events.html
html/bug-assist.js
--- a/html/DOM3-Events.html	Mon Aug 19 15:58:00 2013 -0700
+++ b/html/DOM3-Events.html	Wed Aug 21 15:00:11 2013 -0700
@@ -1,5 +1,8 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US"
+	data-bug-product='WebAppsWG'
+	data-bug-component='DOM3 Events'
+	>
 <head>
 	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 	<title>Document Object Model (DOM) Level 3 Events Specification</title>
@@ -13,6 +16,7 @@
 	<script type="text/javascript" src='https://www.w3.org/Tools/respec/respec-w3c-common' class='remove' async></script>
 	<script type="text/javascript" src='key-table-builder.js'></script>
 	<script type="text/javascript" src='fixup.js'></script>
+	<script src="bug-assist.js"></script>
 	<script type="text/javascript">
 	var respecConfig = {
 		specStatus: "ED",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/html/bug-assist.js	Wed Aug 21 15:00:11 2013 -0700
@@ -0,0 +1,71 @@
+/*
+
+Simple Bug File Assistant.
+Find bugs? File a bug.
+To configure, use data-* attributes on <html> as follows:
+
+* Are taken into account all attributes starting with data-bug-*, what follows that is the name
+  of the Bugzilla form parameter.
+* The name "data-bug-blocked" is special. If present, the assistant adds a link to the dependency
+  tree of this bug.
+* The name "data-bug-comment" is overriden if the user selects text.
+
+Sample use and configuration:
+
+<html data-bug-blocked='14949' data-bug-short_desc='[Explainer]: ' data-bug-product='WebAppsWG'
+      data-bug-component='Component Model'>
+  <script src="bug-assist.js"></script>
+  ...
+*/
+
+document.addEventListener('DOMContentLoaded', function() {
+    var BUGS_PREFIX = "data-bug-";
+
+    var inputs = {  comment: "" };
+
+    [].forEach.call(document.documentElement.attributes, function (attr) {
+        if (attr.name.indexOf(BUGS_PREFIX) === 0)
+            inputs[attr.name.substr(BUGS_PREFIX.length)] = attr.value;
+    });
+
+    var blocked = inputs.blocked;
+
+    var form = document.body.appendChild(document.createElement('form'));
+    form.style.cssText = 'position:fixed;padding:5px;top:1em;right:2em;font-family:sans-serif;font-size:0.8em;background-color:#ffffff;border: 1px solid #f00;';
+    form.action = 'http://www.w3.org/Bugs/Public/enter_bug.cgi';
+    form.target = '_blank';
+    form.textContent = 'Select text and ';
+
+    var submit = form.appendChild(document.createElement('input'));
+    submit.type = 'submit';
+    submit.accessKey = 'f';
+    submit.style.cssText = 'display: block;';
+    var label = 'file a bug';
+    if (submit.accessKeyLabel)
+        label += ' (' + submit.accessKeyLabel + ')';
+    submit.value = label;
+
+    Object.keys(inputs).forEach(function(name) {
+        var input = form.appendChild(document.createElement('input'));
+        input.type = 'hidden';
+        input.name = name;
+        input.value = inputs[name];
+        inputs[name] = input;
+    });
+
+    if (blocked) {
+        form.appendChild(document.createTextNode(' or '));
+        var a = form.appendChild(document.createElement('a'));
+        a.textContent = 'view bugs filed';
+        a.href = 'http://www.w3.org/Bugs/Public/showdependencytree.cgi?id=' + blocked;
+        a.target = '_blank';
+    }
+    //form.appendChild(document.createTextNode('.'));
+
+    form.addEventListener('submit', function() {
+        var selectedText = window.getSelection().toString();
+        if (selectedText)
+            inputs.comment.value = '"' + selectedText + '"';
+    }, false);
+
+}, false);