Last active
August 29, 2015 14:24
-
-
Save YusukeHirao/705cdcc1ee0d5ec35458 to your computer and use it in GitHub Desktop.
baserCMSのsmartphone=off時のリダイレクトスニペット
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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