nmbug.js: Add dialog-polyfill dependency for Firefox
authorW. Trevor King <wking@tremily.us>
Sat, 20 Sep 2014 23:52:38 +0000 (16:52 -0700)
committerW. Trevor King <wking@tremily.us>
Sun, 21 Sep 2014 12:18:58 +0000 (05:18 -0700)
It looks like Firefox doesn't support the <dialog> element yet [1,2],
so this commit dynamically loads the polyfill replacement [3].  Since
the polyfill files load asynchronously, I need to use onload to decide
when they've all made it down (setting the async property to false
didn't seem to work).

[1]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
[2]: https://bugzilla.mozilla.org/show_bug.cgi?id=840640
[3]: https://github.com/GoogleChrome/dialog-polyfill

bower.json
nmbug.js

index b1d497e222564386607186a36b66166a9bac956d..cfda924c41e7485ce0d7605da3458215d415abc2 100644 (file)
@@ -7,5 +7,8 @@
        "repository": {
                "type": "git",
                "url": "git://github.com/wking/nmhive.git"
+       },
+       "dependencies": {
+               "dialog-polyfill": "*"
        }
 }
index ecf03d894d64a9ea207abb959c96d1cbd6da7347..e80053f84f357ccfd9d169f4bcd8a58e15c58973 100644 (file)
--- a/nmbug.js
+++ b/nmbug.js
@@ -25,7 +25,38 @@ nmbug = {
                request.send();
        },
        _edit_tags: function (message_id, tags) {
+               if (document.createElement('dialog').show) {
+                       this._x_edit_tags(message_id, tags);
+               } else {
+                       var _this = this;
+                       var dialog_polyfill_loaded = 0;
+
+                       function onload () {
+                               dialog_polyfill_loaded++;
+                               if (dialog_polyfill_loaded == 2) {
+                                       _this._x_edit_tags(message_id, tags);
+                               }
+                       }
+
+                       var script = document.createElement('script');
+                       script.type = 'text/javascript';
+                       script.src = nmbug_server + '/static/dialog-polyfill/dialog-polyfill.js';
+                       script.onload = onload;
+                       document.head.appendChild(script);
+
+                       var link = document.createElement('link');
+                       link.rel = 'stylesheet';
+                       link.type = 'text/css';
+                       link.href = nmbug_server + '/static/dialog-polyfill/dialog-polyfill.css';
+                       link.onload = onload;
+                       document.head.appendChild(link);
+               }
+       },
+       _x_edit_tags: function (message_id, tags) {
                var dialog = document.createElement('dialog');
+               if (!document.createElement('dialog').show) {
+                       dialogPolyfill.registerDialog(dialog);
+               }
 
                var content = document.createElement('p');
                content.innerHTML = 'Edit tags for ' + message_id;