[extensions-web] js: Defer adding plugin to body until after the DOM has been loaded
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] js: Defer adding plugin to body until after the DOM has been loaded
- Date: Fri, 23 Mar 2012 11:35:41 +0000 (UTC)
commit 6e28454400f8cfb6ea21c54c9b6990e52d49bab8
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Thu Mar 15 18:01:43 2012 -0400
js: Defer adding plugin to body until after the DOM has been loaded
This fixes the site on Opera (besides a browser-plugin fix)
sweettooth/static/js/dbus.js | 86 ++++++++++++++++++++----------------------
1 files changed, 41 insertions(+), 45 deletions(-)
---
diff --git a/sweettooth/static/js/dbus.js b/sweettooth/static/js/dbus.js
index 0a26c90..4a1c55e 100644
--- a/sweettooth/static/js/dbus.js
+++ b/sweettooth/static/js/dbus.js
@@ -10,56 +10,52 @@
define({
load: function(name, req, onLoad, config) {
req(['jquery'], function ($) {
- if (!('SweetTooth' in window)) {
- try {
- var MIME_TYPE = 'application/x-gnome-shell-integration';
- var $plg = $('<embed>', { type: MIME_TYPE });
-
- // Netscape plugins are strange: if you make them invisible with
- // CSS or give them 0 width/height, they won't load. Just smack it
- // off-screen so it isn't visible, but still works.
- $plg.css({ position: 'absolute',
- left: '-1000em',
- top: '-1000em' });
-
- // TODO: this may not work if the DOM is not ready
- // when this call is made. Depending on browsers
- // you want to support, either listen to
- // DOMContentLoaded, event, or use $(function(){}), but in
- // those cases, the full body of this load action should
- // be in that call.
- $(document.body).append($plg);
-
- // The API is defined on the plugin itself.
- window.SweetTooth = $plg[0];
- } catch (e) {
- // In this case we probably failed the origin checks and
- // the NPAPI plugin spat out an error. Explicitly set the
- // plugin to NULL
- window.SweetTooth = null;
+ $(document).ready(function() {
+ if (!('SweetTooth' in window)) {
+ try {
+ var MIME_TYPE = 'application/x-gnome-shell-integration';
+ var $plg = $('<embed>', { type: MIME_TYPE });
+
+ // Netscape plugins are strange: if you make them invisible with
+ // CSS or give them 0 width/height, they won't load. Just smack it
+ // off-screen so it isn't visible, but still works.
+ $plg.css({ position: 'absolute',
+ left: '-1000em',
+ top: '-1000em' });
+
+ $(document.body).append($plg);
+
+ // The API is defined on the plugin itself.
+ window.SweetTooth = $plg[0];
+ } catch (e) {
+ // In this case we probably failed the origin checks and
+ // the NPAPI plugin spat out an error. Explicitly set the
+ // plugin to NULL
+ window.SweetTooth = null;
+ }
}
- }
- if (name == "API") {
- onLoad(window.SweetTooth);
- return;
- }
-
- var apiVersion = undefined;
-
- try {
- if (window.SweetTooth) {
- apiVersion = window.SweetTooth.apiVersion;
+ if (name == "API") {
+ onLoad(window.SweetTooth);
+ return;
}
- } catch (e) { }
- if (!apiVersion)
- apiVersion = 'dummy';
+ var apiVersion = undefined;
- var scriptname = './versions/' + apiVersion + '/main';
- // requirejs caches response.
- req([scriptname], function(module) {
- onLoad(module);
+ try {
+ if (window.SweetTooth) {
+ apiVersion = window.SweetTooth.apiVersion;
+ }
+ } catch (e) { }
+
+ if (!apiVersion)
+ apiVersion = 'dummy';
+
+ var scriptname = './versions/' + apiVersion + '/main';
+ // requirejs caches response.
+ req([scriptname], function(module) {
+ onLoad(module);
+ });
});
});
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]