[extensions-web] js: Punt installing the plugin until the DOM has loaded
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] js: Punt installing the plugin until the DOM has loaded
- Date: Mon, 14 May 2012 21:36:18 +0000 (UTC)
commit cea22f06865fa9fc881ca1aa5bbcf8dbe0ba2ab1
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon May 14 18:36:04 2012 -0300
js: Punt installing the plugin until the DOM has loaded
Opera needs this.
sweettooth/static/js/dbus.js | 84 ++++++++++++++++++++---------------------
1 files changed, 41 insertions(+), 43 deletions(-)
---
diff --git a/sweettooth/static/js/dbus.js b/sweettooth/static/js/dbus.js
index baeca74..17ef1b1 100644
--- a/sweettooth/static/js/dbus.js
+++ b/sweettooth/static/js/dbus.js
@@ -11,57 +11,55 @@ define({
load: function(name, req, onLoad, config) {
"use strict";
- 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);
+ function loadPlugin($) {
+ try {
+ var MIME_TYPE = 'application/x-gnome-shell-integration';
+ var $plg = $('<embed>', { type: MIME_TYPE });
- // 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;
- }
- }
+ // 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);
- if (name == "API") {
- onLoad(window.SweetTooth);
- return;
+ // 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;
}
+ }
- var apiVersion = undefined;
+ req(['jquery'], function($) {
+ $(function() {
+ if (window.SweetTooth === undefined)
+ loadPlugin($);
- try {
- if (window.SweetTooth) {
- apiVersion = window.SweetTooth.apiVersion;
+ if (name == "API") {
+ onLoad(window.SweetTooth);
+ return;
}
- } catch (e) { }
- if (!apiVersion)
- apiVersion = 'dummy';
+ var apiVersion = undefined;
+
+ 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);
+ 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]