[extensions-web] Revert "js: Punt installing the plugin until the DOM has loaded"



commit 171010407b0766ea7fa69c9c90d6d28a7f6c203b
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Mon May 14 18:40:53 2012 -0300

    Revert "js: Punt installing the plugin until the DOM has loaded"
    
    This reverts commit cea22f06865fa9fc881ca1aa5bbcf8dbe0ba2ab1.

 sweettooth/static/js/dbus.js |   84 +++++++++++++++++++++--------------------
 1 files changed, 43 insertions(+), 41 deletions(-)
---
diff --git a/sweettooth/static/js/dbus.js b/sweettooth/static/js/dbus.js
index 17ef1b1..baeca74 100644
--- a/sweettooth/static/js/dbus.js
+++ b/sweettooth/static/js/dbus.js
@@ -11,55 +11,57 @@ define({
     load: function(name, req, onLoad, config) {
         "use strict";
 
-        function loadPlugin($) {
-            try {
-                var MIME_TYPE = 'application/x-gnome-shell-integration';
-                var $plg = $('<embed>', { type: MIME_TYPE });
+        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' });
-                $(document.body).append($plg);
+                    // 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' });
 
-                // 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;
-            }
-        }
+                    // 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);
 
-        req(['jquery'], function($) {
-            $(function() {
-                if (window.SweetTooth === undefined)
-                    loadPlugin($);
-
-                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;
+            if (name == "API") {
+                onLoad(window.SweetTooth);
+                return;
+            }
 
-                try {
-                    if (window.SweetTooth) {
-                        apiVersion = window.SweetTooth.apiVersion;
-                    }
-                } catch (e) { }
+            var apiVersion = undefined;
+
+            try {
+                if (window.SweetTooth) {
+                    apiVersion = window.SweetTooth.apiVersion;
+                }
+            } catch (e) { }
 
-                if (!apiVersion)
-                    apiVersion = 'dummy';
+            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]