From: W. Trevor King Date: Sat, 20 Sep 2014 23:52:38 +0000 (-0700) Subject: nmbug.js: Add dialog-polyfill dependency for Firefox X-Git-Tag: v0.1.0~28 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f0c5d08edebe30de17f248d2003fa7a4560ed409;p=nmhive.git nmbug.js: Add dialog-polyfill dependency for Firefox It looks like Firefox doesn't support the 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 --- diff --git a/bower.json b/bower.json index b1d497e..cfda924 100644 --- a/bower.json +++ b/bower.json @@ -7,5 +7,8 @@ "repository": { "type": "git", "url": "git://github.com/wking/nmhive.git" + }, + "dependencies": { + "dialog-polyfill": "*" } } diff --git a/nmbug.js b/nmbug.js index ecf03d8..e80053f 100644 --- 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;