/* * Mozilla Japan グローバルスクリプト [mj-global.js] * Copyright (C) Mozilla Japan * 最終更新日: 2009/07/12 * 依存ライブラリ: jQuery */ var mj = { /* * 初期化関数の呼び出しを設定 */ onbeforeload: function() { try { $(document).ready(function() { mj.init(); }); } catch (e) { // jQuery が使えない環境への対応 window.onload = function() { mj.init(); } } delete this.onbeforeload; }, /* * 初期化 */ init: function() { this.analytics.init(); if (navigator.userAgent.indexOf("MSIE") != -1) { this.gnav.init(); } else { delete this.gnav.init; delete this.download.open_sub_window; } document.body.className += ' js'; delete this.init; }, /* * メインメニュー関連 */ gnav: { /* * IE のみドロップダウンを設定。他のブラウザは CSS で機能するため、この関数は不要 */ init: function() { try { var items = $("div#gnav li[id^=gnav]"); items.mouseover(function(event){ $(this).addClass("hover"); }); items.mouseout(function(event){ $(this).removeClass("hover"); }); } catch (e) {} delete this.init; } }, /* * ダウンロード関連 */ download: { /* * IE のみ、ダウンロード開始のためにサブウィンドウを開く */ open_sub_window: function(product, version) { var link = "http://download.mozilla.org/?product=" + product + "-" + version + "&os=win&lang=ja"; var options = "toolbar=0,location=no,directories=0,status=0,scrollbars=0,resizeable=0,width=1,height=1,top=0,left=0"; window.open(link, "download_window", options); window.focus(); } }, /* * アクセス解析関連 * 複数ツールへの対応を考慮する */ analytics: { // サイト固有の設定 path: "", ga_installed: true, ga_property_id: "UA-6459738-1", urchin_installed: true, urchin_img_path: "/img/lib/analytics/__utm.gif", cookie_domain: "", track_outbound_link: true, track_file_download: true, init: function() { // Google Analytics + Urchin の設定 this.ga_installed = (typeof _gat == "object"); if (this.ga_installed) { this.ga = _gat._getTracker(this.ga_property_id); if (this.cookie_domain != "") { this.ga._setDomainName(this.cookie_domain); } if (this.urchin_installed) { this.ga._setLocalGifPath(this.urchin_img_path); this.ga._setLocalRemoteServerMode(); } } // 現在のページを記録 this.log(); // リンクのトラッキングを設定 try { $("a[href]").click(function(event){ mj.analytics.track_link(this); }); } catch (e) {} delete this.init; }, track_link: function(target) { if (target.hostname == "" || target.hostname == undefined) { return; } // リンクにトラッキングコードが設定済みの場合はそれを優先する if (target.attributes.onclick && target.attributes.onclick.value.indexOf("mj.analytics.log") != -1) { return; } var internal_link = (target.hostname == document.domain); var path = target.pathname; // ブラウザによっては pathname の先頭にスラッシュが付かない if (path.substr(0, 1) != "/") { path = "/" + path; } // 外部リンクのトラッキング if (this.track_outbound_link && !internal_link) { this.log("/oblink/" + target.href); } var re = new RegExp("\.(png|gif|jpg|jpeg|tif|tiff|ai|eps|psd|svg|pdf|doc|docx|xls|xlsx|ppt|pptx|zip|xpi|jar|exe)$", "i"); var file_link = (path != undefined && re.test(path)); // ファイルダウンロードのトラッキング if (this.track_file_download && internal_link && file_link) { this.log(path); } }, log: function() { // パスの設定 var url; if (arguments.length == 1) { // クリックイベントなどによるカスタム URL url = arguments[0]; } else if (this.path != "") { // ページ内で上書きされた URL (例: ダウンロードページ) url = this.path; } else { // 通常のページビュー url = location.pathname + location.search; } // Google Analytics の文字化け問題を回避 (unescape の代わりに decodeURI を使う) if (typeof decodeURI == "function") { url = decodeURI(url); } // Google Analytics & Urchin if (this.ga_installed) { this.ga._trackPageview(url); } } } }; mj.onbeforeload();