Skip to content

Instantly share code, notes, and snippets.

@YusukeHirao
Last active August 29, 2015 14:24
Show Gist options
  • Save YusukeHirao/705cdcc1ee0d5ec35458 to your computer and use it in GitHub Desktop.
Save YusukeHirao/705cdcc1ee0d5ec35458 to your computer and use it in GitHub Desktop.
baserCMSのsmartphone=off時のリダイレクトスニペット
/**
* smartphone=off対応
*
*/
var key = 'smartphone';
var val = 'off';
var dir = 'sp';
// URLパラメータにsmartphoneがある場合、
// リンク先にもパラメータを追加する
baser.ui.Browser.inheritParams(key); // since v0.7.0-beta
// URLパラメータがsmartphone=offの場合
// Cookieにもsmartphone=offを追加
var loc = new baser.ui.Locational(location); // since v0.7.0-beta
if (loc.params[key] === val) {
$.cookie(key, val, {
expires: 100 * 365,
path: '/'
});
}
// Cookieにsmartphone=offがついていて且つ
// スマートフォンのディレクトリ配下の場合
// URLパラメータにsmartphone=offしたPC版ディレクトリにジャンプする
if ($.cookie(key) === val && new RegExp('^\\/' + dir + '\\/').test(loc.path)) {
loc.pathname = loc.pathname.replace(new RegExp('^\\/' + dir), '');
loc.addParam(key, val);
loc.update();
baser.ui.Browser.jumpTo(loc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment