My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Environment  
JavaScript と CSS でコンテナの種別を判断できます。コンテナ依存の環境属性を取得できます。
jQuery.feature, jQuery.container
Updated Feb 4, 2010 by nakajim...@gmail.com

jQuery.container.domain は opensocial-0.8 を必要とします。

<ModulePrefs title="opensocial-jquery">
<Require feature="opensocial-0.8" />
</ModulePrefs>

コンテナの種別を判別する

jQuery.container を使って、コンテナの種別を判別できます。igoogle, orkut, hi5, myspace, goohome のいずれかを指定します。

if ($.container.igoogle) {
  // This container is iGoogle. 
} else if ($.container.orkut) {
  // This container is Orkut. 
} else if ($.container.hi5) {
  // This container is hi5. 
} else if ($.container.myspace) {
  // This container is MySpace. 
} else if ($.container.goohome) {
  // This container is goo home. 
} else {
  // Other containers. 
}

さらに HTML 要素に対して、コンテナを表すクラスを自動的に追加します。

<html class="igoogle"></html>

ですので、CSS のクラスを使って、コンテナの種別を判別できます。igoogle, orkut, hi5, myspace のいずれかを指定します。

  .igoogle div.photo img { /* This container is iGoogle. */ }
  .orkut div.photo img { /* This container is Orkut. */ }
  .hi5 div.photo img { /* This container is hi5. */ }
  .myspace div.photo img { /* This container is MySpace. */ }
  .goohome div.photo img { /* This container is goo home. */ }

サンドボックスかどうか判別する

jQuery.container.sandbox を使って、コンテナがサンドボックスかどうか判別できます。

if ($.container.sandbox) {
  // This container is a sandbox. 
} else {
  // This container is a production. 
}

さらに HTML 要素に対して、サンドボックスかどうかを表すクラスを自動的に追加します。

<html class="orkut sandbox"></html>

ですので、CSS のクラスを使って、サンドボックスかどうか判別できます。

  .orkut.sandbox div.photo img {
    /* This container is sandbox of Orkut. */
  }

ドメインを取得する取得する

jQuery.container.domain を使って、コンテナのドメイン(名前空間)を取得できます。

var domain = $.container.domain;
console.info(domain); // myspace.com, orkut.com, goo.ne.jp, ...

feature が利用できるか確認する

jQuery.feature を使って、feature が利用できるか確認できます。

  if (!$.feature('locked-domain')) {
    // locked-domain is not supported.
  }

feature パラメータを取得する

jQuery.feature を使って、feature パラメータを取得できます。パラメータを取得できる feature やコンテナが見つかりません。どなたかご存知ないでしょうか。

  var params = $.feature('locked-domain');
  console.info(params.foo);
  console.info(params.bar);

Sign in to add a comment
Powered by Google Project Hosting