Init Google Gears with jQuery

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();

Javascript Sudoku Solver using jQuery

I took the time earlier in the week to write a html/javascript sudoku solver. This code could be either used to cheat at sudoku or used as a basis for creating an online sudoku game.

Either way, have fun: http://www.bizzeh.com/solver/


Imitate target=_blank with jquery

You can replace target=_blank with jquery, or prototype or with raw javascript if you like. Here is the code i came up with to do just this.

jQuery

$(function() {
	$('a[rel*=external]').click(function() {
		var w = window.open(this.href);
		if(!w) alert("Boo! A popup blocker stopped our window from opening");
		return false;
	});
});