iGoogleガジェットでprototype.jsを使用するには

iGoogleガジェットでprototype.jsをそのまま使用することはできません。障害となるのはdocument.getElementByIdがiGoogleガジェットでは使用できず、代わりにiGoogleガジェットが用意する_gel関数を使用しなければならないこと。逆に言えばこれさえクリアできればprototype.jsiGoogleガジェットでも使用できます。

theater.jsでは、prototype.jsを読み込んだ後、以下のスクリプトを実行しています。

if(typeof _IG_Prefs != "undefined"){
  window.$ = function(element) {
    if (arguments.length > 1) {
      for (var i = 0, elements = [], length = arguments.length; i < length; i++)
        elements.push($(arguments[i]));
      return elements;
    }
    if (typeof element == 'string')
      try{element = _gel(element);}catch(e){}
    return Element.extend(element);
  };
}

_IG_Prefsの有無でiGoogleガジェットかどうかを判定しています。iGoogleガジェットの場合、$関数を_gel関数使用のものに置き換えます。これでiGoogleガジェットであってもなくてもprototype.jsが動作します。script.aculo.usも同様です。