I took a look around the web for a jQuery plugin for google gears as i would like to initialise gears on user input, and not as the web page loads, but could not find one anywhere.
So i have written the following plugin, based on googles own gears_init.js code which inits gears on page load.
/*
* jQuery Gears Init by Darren Horrocks
*
* jQuery Plugin to init google gears at any point during a page
*
* code based on gears_init.js from http://code.google.com/apis/gears/gears_init.js
*
*/
(function() {
jQuery.initGears = function() {
// We are already defined. Hooray!
if (window.google && google.gears) {
return;
}
var factory = null;
// Firefox
if (typeof GearsFactory != 'undefined') {
factory = new GearsFactory();
} else {
// IE
try {
factory = new ActiveXObject('Gears.Factory');
// privateSetGlobalObject is only required and supported on IE Mobile on
// WinCE.
if (factory.getBuildInfo().indexOf('ie_mobile') != -1) {
factory.privateSetGlobalObject(this);
}
} catch (e) {
// Safari
if ((typeof navigator.mimeTypes != 'undefined') && navigator.mimeTypes["application/x-googlegears"]) {
factory = document.createElement("object");
factory.style.display = "none";
factory.width = 0;
factory.height = 0;
factory.type = "application/x-googlegears";
document.documentElement.appendChild(factory);
}
}
}
// *Do not* define any objects if Gears is not installed. This mimics the
// behavior of Gears defining the objects in the future.
if (!factory) {
return;
}
// Now set up the objects, being careful not to overwrite anything.
if (!window.google) {
google = {};
}
if (!google.gears) {
google.gears = {factory: factory};
}
};
})();
You can now initialise gears using the the jQuery class or the dollar shortcut.
jQuery.initGears();
$.initGears();