PageSourceSearch

https://www.city.tokushima.tokushima.jp/js/cms.smartphone.js

js city.tokushima.tokushima.jp collected 2026-09-24 18:15:06 UTC 4,623 bytes, 159 lines download raw bytes

1/**
2 * @file cms.smartphone.js
3 * @breif スマートフォン自動振り分けなどのJavaScript.
4 * @date 2011/07/16
5 * @charset UTF-8
6 * 
7 * Copyright(C) Hitachi Government & Public Corporation
8 * System Engineering, Ltd. 2011. All rights reserved.
9 * 
10 * <p>依存するライブラリ
11 *  <ul>
12 *    <li>jquery.js(1.2+)</li>
13 *    <li>jquery.cookie.js</li>
14 *  </ul>
15 * </p>
16 * 
17 */
18// 名前空間の定義:cms
19var cms;
20if(!cms)
21	cms = {};
22else if(typeof cms != "object")
23	throw new Error("cms already exits and is not an object");
24
25// 名前空間の定義:cms.smartphone
26if(!cms.smartphone)
27    cms.smartphone = {};
28else if(typeof cms.smartphone != "object")
29    throw new Error("cms.smartphone already exits and is not an object");
30
31// 確認ダイアログメッセージの定義
32var DISPATCH_MESSAGE = {
33	ja: 'このコンテンツには、スマートフォン専用のページがあります。\n表示しますか?',
34	en: 'このコンテンツには、スマートフォン専用のページがあります。\n表示しますか?',
35	zh: 'このコンテンツには、スマートフォン専用のページがあります。\n表示しますか?',
36	ko: 'このコンテンツには、スマートフォン専用のページがあります。\n表示しますか?'
37};
38
39var COOKIE_KEY_DISPATCH = 'cms_smartphone_dispatch';
40
41/**
42 * 指定したURLに対する振り分けをを行う。
43 * <p>iPhone、Androidの場合は振り分けを行う。
44 * 
45 * @param url 振り分け先のURL[string](必須)
46 * @param langaugeCd[string]
47 * @param onPreview CMSのプレビュー処理かどうか[boolean]
48 * 
49 */
50cms.smartphone.dispatch = function(url, languageCd, onPreview) {
51	// プレビュー処理の場合、何もしない
52	if((onPreview != undefined || onPreview != null) && onPreview == true) {
53		return;
54	}
55	
56	// URLが指定されていない場合、何もしない
57	if(url == undefined || url == null || url == "") {
58		return;
59	}
60	
61	if(languageCd == undefined 
62			|| languageCd == null
63			|| languageCd == "" 
64			|| !(languageCd in DISPATCH_MESSAGE)) {
65		langaugeCd = 'ja';
66	}
67	
68	// ユーザエージェントのチェック
69	if(!cms.smartphone.isSmartphone()) {
70		// スマートフォン用ページから遷移した場合は、振り分けしない。
71		return;
72	}
73	
74	// 遷移元のチェック
75	if(cms.smartphone.isSameUrlWithFrom(url)) {
76		return;
77	}
78	
79	var cookieEnabled = navigator.cookieEnabled
80	if(cookieEnabled == null || cookieEnabled == undefined || navigator.cookieEnabled == false) {
81		// Cookieが無効の場合、強制的に遷移する。
82		location.href = url;
83		return;
84	}
85	
86	// Cookieの取得と判定
87	var beforeDispatched = $.cookie(COOKIE_KEY_DISPATCH);
88	if(beforeDispatched == undefined || beforeDispatched == null) {
89		// Cookieの値が見つからない場合
90		var msg = DISPATCH_MESSAGE[languageCd];
91		if(confirm(msg)) {
92			// Cookieの保存
93			$.cookie(COOKIE_KEY_DISPATCH, 'true');
94			
95			// 画面遷移
96			location.href = url;
97			return;
98			
99		} else {
100			// Cookieの保存
101			$.cookie(COOKIE_KEY_DISPATCH, 'false');
102			return;
103		}
104		
105	} else if(beforeDispatched == 'true') {
106		// 前回、trueと答え場合
107		location.href = url;
108		return;
109	} else {
110		// 前回、falseと答えた場合
111		return;
112	}
113	
114}
115
116/**
117 * 現在アクセスしている機器がスマートフォンかどうかチェックする
118 * 
119 * @return true:スマートフォンの場合
120 */
121cms.smartphone.isSmartphone = function() {
122	var userAgent = navigator.userAgent;
123	if((userAgent.indexOf('iPhone') > 0 && userAgent.indexOf('iPad') == -1) // iPadを除くiOS
124			|| userAgent.indexOf('iPod') > 0 // iPod touch
125			|| userAgent.indexOf('Android') > 0) {
126		return true;
127	}
128	
129}
130
131/**
132 * 遷移元のURLと同じかどうか、リファラーを元に比較する。
133 *
134 * @param url: 比較対象のURL
135 * @return true: 遷移元のURLと等しい。
136 */
137cms.smartphone.isSameUrlWithFrom = function(url) {
138	
139	var referrerUrl = document.referrer;
140	if(referrerUrl == null || referrerUrl.length == 0) {
141		return false;
142	}
143	
144	if(referrerUrl.indexOf(url) >= 0) {
145		return true;
146	}
147	
148	// 比較対象のURLが、index.htmlで始まり、リファラーで「/index.html」が省略されている場合
149	if(url.lastIndexOf("/index.html") >=0 && referrerUrl.indexOf("/index.html") < 0) {
150		var compUrl = url.replace("/index.html", "/");
151		if(referrerUrl.indexOf(compUrl) >= 0) {
152			return true;
153		}
154	}
155	
156	return false;
157	
158}
159

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.