1'use strict'; 2var MutualSwitching = MutualSwitching || { 3 config: {}, 4 util: {}, 5 run: {} 6}; 7 8//============================================================================== 9// è¨å®ã«é¢ããã¢ã¸ã¥ã¼ã« 10//============================================================================== 11MutualSwitching.config = (function () { 12 /** 13 * è¨å®å¤ 14 * @type {Object} 15 */ 16 var config = {}; 17 18 /** 19 * PCç¨ãã¥ã¼ãã¼ãå¹ 20 * @type {Number} 21 */ 22 config.viewPortWidthPc = 0; 23 24 /** 25 * ã¹ããç¨ãã¥ã¼ãã¼ãå¹ 26 * @type {Number} 27 */ 28 config.viewPortWidthSp = 0; 29 30 /** 31 * ãã¼ã¸ã®ã¬ã¤ã¢ã¦ãã¿ã¤ã 32 * @type {Number} 33 * 0: ã¬ã¹ãã³ã·ã 34 * 1: PC/SPåå¥ãã¶ã¤ã³ 35 * 2: ãã¬ãã·ãã«ï¼ãªããã + ã¬ã¹ãã³ã·ãï¼ 36 */ 37 config.layoutType = 0; 38 39 /** 40 * ãã¹å¥è¨å® 41 * @type {Object} 42 */ 43 config.pathSettings = {}; 44 45 /** 46 * PCç¨CSSãã¡ã¤ã«å 47 * @type {String} 48 */ 49 config.pcCssName = 'theme/base/css/top.css'; 50 51 /** 52 * ã¹ããç¨CSSãã¡ã¤ã«å 53 * @type {String} 54 */ 55 config.spCssName = 'theme/base/css/sp_top.css'; 56 57 /** 58 * ã¹ããç¨å°ç¨ãã¼ã¸ã®æç¡ 59 * @type {Boolean} 60 */ 61 config.existsSpPage = false; 62 63 /** 64 * ãã¬ãã¥ã¼ãã¼ã¸ã§ã®åç §ã§ããã 65 * @type {Boolean} 66 */ 67 config.isPreview = false; 68 69 /** 70 * [viewPcBySp description] 71 * @type {Boolean} 72 */ 73 config.viewPcBySp = false; 74 75 return { 76 /** 77 * ã¬ã¤ã¢ã¦ãã¿ã¤ãæå® 78 * @public 79 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 80 */ 81 setLyaoutType: function (type) { 82 config.layoutType = type; 83 return MutualSwitching.config; 84 }, 85 /** 86 * ã¬ã¹ãã³ã·ãã¬ã¤ã¢ã¦ãã§ãããã¨ãå®ç¾©ãã 87 * @public 88 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 89 */ 90 setLayoutIsResponsive: function () { 91 config.layoutType = 0; 92 return MutualSwitching.config; 93 }, 94 /** 95 * åå¥(ããã¤ã¹å¥)ã¬ã¤ã¢ã¦ãã§ãããã¨ãå®ç¾©ãã 96 * @public 97 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 98 */ 99 setLayoutIsIndividual: function () { 100 config.layoutType = 1; 101 return MutualSwitching.config; 102 }, 103 /** 104 * ãã¬ãã·ãã«(ãªããã + ã¬ã¹ãã³ã·ã)ã¬ã¤ã¢ã¦ãã§ãããã¨ãå®ç¾©ãã 105 * @public 106 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 107 */ 108 setLayoutIsFlexible: function () { 109 config.layoutType = 2; 110 return MutualSwitching.config; 111 }, 112 /** 113 * åå¥è¨å®ããã¤ãã¹ãç»é²ãã 114 * @public 115 * @param {Object} pathSetting JSONå½¢å¼ 116 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 117 */ 118 setPathSettings: function (pathSetting) { 119 config.pathSettings = pathSetting; 120 return MutualSwitching.config; 121 }, 122 /** 123 * PCç¨ãã¥ã¼ãã¼ãã®å¹ ãè¨å®ãã 124 * @public 125 * @param {Int} width å¹ 126 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 127 */ 128 setViewPortWIdthPc: function (width) { 129 config.viewPortWidthPc = width; 130 return MutualSwitching.config; 131 }, 132 /** 133 * ã¹ããç¨ãã¥ã¼ãã¼ãã®å¹ ãè¨å®ãã 134 * @public 135 * @param {Int} width å¹ 136 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 137 */ 138 setViewPortWIdthSp: function (width) { 139 config.viewPortWidthSp = width; 140 return MutualSwitching.config; 141 }, 142 /** 143 * [setViewPcBySp description] 144 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 145 */ 146 setViewPcBySp: function () { 147 config.viewPcBySp = true; 148 return MutualSwitching.config; 149 }, 150 /** 151 * ã¹ããç¨ãã¼ã¸ãåå¨ãèªèãããè¨å® 152 * @param {Boolean} existsFlag true: åå¨ãã, false: åå¨ããªã 153 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 154 */ 155 setExistsSpPage: function (existsFlag) { 156 config.existsSpPage = existsFlag; 157 return MutualSwitching.config; 158 }, 159 /** 160 * ãã¬ãã¥ã¼ç»é¢ãã©ããã夿ããè¨å® 161 * @param {Boolean} isPreview true: ãã¬ãã¥ã¼, false: ãã®ä» 162 * @return ã¢ã¸ã¥ã¼ã«(â»ã¡ã½ãããã§ã¼ã³ç¨) 163 */ 164 setPreviewMode: function (isPreview) { 165 config.isPreview = isPreview; 166 return MutualSwitching.config; 167 }, 168 /** 169 * ã¬ã¹ãã³ã·ãã¬ã¤ã¢ã¦ãã§ããã 170 * @public 171 * @return {Boolean} true: ã¬ã¹ãã³ã·ãã¬ã¤ã¢ã¦ã, false: ãã®ä» 172 */ 173 isResponsiveLayout: function () { 174 return config.layoutType === 0; 175 }, 176 /** 177 * åå¥ã¬ã¤ã¢ã¦ãã§ããã 178 * @public 179 * @return {Boolean} true: åå¥ã¬ã¤ã¢ã¦ã, false: ãã®ä» 180 */ 181 isIndividualLayout: function () { 182 return config.layoutType === 1; 183 }, 184 /** 185 * ãã¬ãã·ãã«ã¬ã¤ã¢ã¦ãã§ããã 186 * @public 187 * @return {Boolean} true: ãã¬ãã·ãã«ã¬ã¤ã¢ã¦ã, false: ãã®ä» 188 */ 189 isFlexibleLayout: function () { 190 return config.layoutType === 2; 191 }, 192 /** 193 * PCç¨ãã¥ã¼ãã¼ãã®å¹ ãåå¾ 194 * @public 195 * @return {Int} å¹ 196 */ 197 getViewPortWidthPc: function () { 198 return config.viewPortWidthPc; 199 }, 200 /** 201 * ã¹ããç¨ãã¥ã¼ãã¼ãã®å¹ ãåå¾ 202 * @public 203 * @return {Int} å¹ 204 */ 205 getViewPortWidthSp: function () { 206 return config.viewPortWidthSp; 207 }, 208 /** 209 * PCã¬ã¤ã¢ã¦ãæã®ãã¥ã¼ãã¼ãå¤ãåå¾ 210 * @public 211 * @return {String} ãã¥ã¼ãã¼ãå¤ 212 */ 213 getViewPortPc: function () { 214 return 'width=' + config.viewPortWidthPc + ',user-scalable=yes'; 215 }, 216 /** 217 * ã¹ããã¬ã¤ã¢ã¦ãæã®ãã¥ã¼ãã¼ãå¤ãåå¾ 218 * @public 219 * @return {String} ãã¥ã¼ãã¼ãå¤ 220 */ 221 getViewPortSp: function () { 222 return 'width=' + config.viewPortWidthSp + ',user-scalable=yes'; 223 }, 224 /** 225 * ãã¬ãã·ãã«ã¬ã¤ã¢ã¦ãæã®ãã¥ã¼ãã¼ãå¤ãåå¾ 226 * @public 227 * @return {String} ãã¥ã¼ãã¼ãå¤ 228 */ 229 getViewPortFlexible: function () { 230 return 'width=device-width, maximum-scale=1.0, minimum-scale=0.5,user-scalable=yes,initial-scale=1.0'; 231 }, 232 /** 233 * ãã¹æ¯ã®è¨å®ãåå¾ 234 * @public 235 * @return {Object} ãã¹ã¨è¨å®ãã¼ã¿ 236 */ 237 getPathSettings: function () { 238 return config.pathSettings; 239 }, 240 /** 241 * PCç¨CSSãã¡ã¤ã«åãåå¾ 242 * @public 243 * @return {String} ãã¡ã¤ã«å 244 */ 245 getPcCssName: function () { 246 return config.pcCssName; 247 }, 248 /** 249 * ã¹ããç¨CSSãã¡ã¤ã«åãåå¾ 250 * @public 251 * @return {String} ãã¡ã¤ã«å 252 */ 253 getSpCssName: function () { 254 return config.spCssName; 255 }, 256 /** 257 * [getViewPcBySp description] 258 * @return {[type]} [description] 259 */ 260 getViewPcBySp: function () { 261 return config.viewPcBySp; 262 }, 263 /** 264 * ã¹ããç¨ãã¼ã¸ãåå¨ããã 265 * @return {Boolean} 266 */ 267 isExistsSpPage: function () { 268 return config.existsSpPage; 269 }, 270 /** 271 * ãã¬ãã¥ã¼ç»é¢ã§ã®é²è¦§ãã©ãã 272 * @return {Boolean} [description] 273 */ 274 isPreviewMode: function () { 275 return config.isPreview; 276 } 277 } 278})(); 279 280//============================================================================== 281// ã¦ã¼ãã£ãªãã£ã¢ã¸ã¥ã¼ã« 282//============================================================================== 283MutualSwitching.util = (function () { 284 return { 285 /** 286 * ãã¡ã¤ã³åãåå¾ 287 * @public 288 * @return {String} ãã¡ã¤ã³å 289 */ 290 getDomain: function () { 291 return document.domain; 292 }, 293 /** 294 * ãã£ã¬ã¯ããªãã¹(URL)ãåå¾ 295 * @public 296 * @return {String} ãã¹ 297 */ 298 getFileName: function () { 299 return location.pathname.split('/').pop(); 300 }, 301 /** 302 * èªèº«ã®ãã¼ã¸ãã¡ã¤ã«åãåå¾ 303 * @public 304 * @return {String} ãã¡ã¤ã«å 305 */ 306 getDirPath: function () { 307 return location.pathname.replace(MutualSwitching.util.getFileName(), '').replace(/\/$/, ''); 308 }, 309 /** 310 * é²è¦§ç«¯æ«ãã¹ããã§ãã 311 * @return {Boolean} true: ã¹ãã, false:ãã®ä» 312 */ 313 isDeviceSp: function () { 314 // ã¦ã¼ã¶ã¼ã¨ã¼ã¸ã§ã³ãåå¾ 315 var ua = navigator.userAgent.toLowerCase(); 316 return (ua.indexOf('iphone') > -1) || (ua.indexOf('ipad') > -1) || (ua.indexOf('android') > -1); 317 }, 318 /** 319 * ãããã°æ å ±æç» 320 * @public 321 * @return {[type]} [description] 322 */ 323 debugPrint: function () { 324 $('#debug').text($("meta[name='viewport']").attr('content')); 325 } 326 }; 327})(); 328 329//============================================================================== 330// ã¡ã¤ã³å¦çã¢ã¸ã¥ã¼ã« 331//============================================================================== 332MutualSwitching.run = (function () { 333 // jQueryèªè¾¼ã¿ç¢ºèª 334 if (typeof $ === "undefined") { 335 console.warn("jQuery required."); 336 return; 337 } 338 339 // Cookieå©ç¨ã®å¯å¦ãç¢ºèª 340 if (!navigator.cookieEnabled) { 341 console.warn("Please allow use of cookies."); 342 return; 343 } 344 345 /** 346 * ãã¥ã¼ãã¼ãæ¸æã 347 * @private 348 * @param {String} value ãã¥ã¼ãã¼ãè¨å® 349 */ 350 function rewriteViewPort(value) { 351 var srcViewPort = $("meta[name='viewport']").attr('content'); 352 var destViewPort = value; 353 if (srcViewPort !== destViewPort) { 354 $("meta[name='viewport']").attr('content', destViewPort); 355 } 356 } 357 358 /** 359 * PCç¨CSSã®èªè¾¼ã¿ãã¹ããç¨CSSèªè¾¼ã¿ã«æ¸æã 360 * @private 361 */ 362 function rewriteCssPcToSp() { 363 var deviceCss = $("link[href$='/" + MutualSwitching.config.getPcCssName() + "']"); 364 if (deviceCss.attr('href') != null) { 365 var deviceCssDest = deviceCss.attr('href').replace(MutualSwitching.config.getPcCssName(), MutualSwitching.config.getSpCssName()); 366 deviceCss.attr('href', deviceCssDest); 367 } 368 } 369 370 /** 371 * PCç¨ãã¶ã¤ã³ã§ãã¼ã¸ãé²è¦§ãã¦ããã 372 * @private 373 * @return {Boolean} true: PCãã¶ã¤ã³, false: ããä»¥å¤ 374 */ 375 function isPcView() { 376 return $.cookie('view_mode') === 'pc'; 377 } 378 379 /** 380 * ã¹ããç¨ãã¶ã¤ã³ã§ãã¼ã¸ãé²è¦§ãã¦ããã 381 * @private 382 * @return {Boolean} true: ã¹ãããã¶ã¤ã³, false: ããä»¥å¤ 383 */ 384 function isSpView() { 385 return $.cookie('view_mode') === 'sp' || !$.cookie('view_mode'); 386 } 387 388 /** 389 * PCãã¼ã¸ããSPãã¼ã¸ã¸ã®ãªãã¤ã¬ã¯ãURLãåå¾ãã 390 * @private 391 * @return {String} ãªãã¤ã¬ã¯ãå URL 392 */ 393 function getRedirectUrlPcToSp() { 394 var redirectUrl; 395 if (location.href.split('/').pop().length === 0) { 396 redirectUrl = 'index.html'; 397 } else { 398 redirectUrl = location.href.split('/').pop(); 399 } 400 return redirectUrl; 401 } 402 403 /** 404 * ãã¹æ¯ã«è¨å®ãããã¬ã¤ã¢ã¦ãæ å ±ãè¨å®ãã 405 * @private 406 * @return {[type]} [description] 407 */ 408 function applySettingsForEachPath() { 409 var settings = MutualSwitching.config.getPathSettings(); 410 if (!settings) { 411 return; 412 } 413 414 // èªèº«ã®ãã¹ããé¡ã£ã¦è¨å®ãæ¢ã 415 var pathParts = MutualSwitching.util.getDirPath().split('/'); 416 for (var ii = pathParts.length - 1; ii >= 0; ii--) { 417 var searchPath = ''; 418 var tmpPathParts = []; 419 for (var jj = 0; jj <= ii; jj++) { 420 tmpPathParts.push(pathParts[jj]); 421 } 422 searchPath = tmpPathParts.join('/').length > 0 ? tmpPathParts.join('/') : '/'; 423 424 // å奿å®ããã¦ãã 425 if (settings.hasOwnProperty(searchPath)) { 426 // ã¬ã¤ã¢ã¦ããæå®ããã¦ããã°é©ç¨ãã 427 if (settings[searchPath].layout_type != null) { 428 MutualSwitching.config.setLyaoutType(settings[searchPath].layout_type); 429 } 430 431 // PCç¨Widthãè¨å®ããã¦ããã°é©ç¨ãã
432 if (settings[searchPath].pc_width != null) { 433 MutualSwitching.config.setViewPortWIdthPc(settings[searchPath].pc_width); 434 } 435 436 // ã¹ããç¨Widthãè¨å®ããã¦ããã°é©ç¨ãã 437 if (settings[searchPath].sp_width != null) { 438 MutualSwitching.config.setViewPortWIdthSp(settings[searchPath].sp_width); 439 } 440 break; 441 } 442 } 443 } 444 445 return { 446 /** 447 * ã¡ã¤ã³å¦ç 448 * @public 449 */ 450 ready: function () { 451 $(document).ready(function () { 452 // ãããã° 453 MutualSwitching.util.debugPrint(); 454 455 // PCãµã¤ã表示ãå®è¡ 456 $('.jqs-go-to-pc').on({ 457 'click': function () { 458 $.cookie('view_mode', 'pc', {expires: 0, path: '/', domain: MutualSwitching.util.getDomain()}); 459 } 460 }); 461 462 // ã¹ãããµã¤ã表示ãå®è¡ 463 $('.jqs-go-to-sp').on({ 464 'click': function () { 465 $.cookie('view_mode', 'sp', {expires: 0, path: '/', domain: MutualSwitching.util.getDomain()}); 466 } 467 }); 468 469 // ãã¹æ¯ã«å®ç¾©ãããè¨å®ãé©ç¨ãã 470 applySettingsForEachPath(); 471 472 // ãã¬ãã¥ã¼ç»é¢ããé²è¦§ä¸ 473 if (MutualSwitching.config.isPreviewMode()) { 474 if (MutualSwitching.config.isFlexibleLayout()) { 475 //------------------------------------------------------------------ 476 // ãã¬ãã·ãã«ã¬ã¤ã¢ã¦ã 477 //------------------------------------------------------------------ 478 // ãã¥ã¼ãã¼ãæ¸æã 479 rewriteViewPort(MutualSwitching.config.getViewPortFlexible()); 480 } else if (MutualSwitching.config.isIndividualLayout()) { 481 // CSSæ¸æã 482 rewriteCssPcToSp(); 483 // ãã¥ã¼ãã¼ãæ¸æã 484 rewriteViewPort(MutualSwitching.config.getViewPortSp()); 485 } else { 486 //------------------------------------------------------------------ 487 // ã¬ã¹ãã³ã·ãã¬ã¤ã¢ã¦ã 488 //------------------------------------------------------------------ 489 // ãã¥ã¼ãã¼ãæ¸æã 490 rewriteViewPort(MutualSwitching.config.getViewPortSp()); 491 } 492 } 493 494 // PCãã¼ã¸é²è¦§ä¸ 495 if (isPcView() && MutualSwitching.util.isDeviceSp()) { 496 // ã¹ãããã¼ã¸ã¸ã®åæ¿ãã¿ã³è¡¨ç¤º 497 $('.jqs-go-to-sp').show(); 498 // ã¬ã¤ã¢ã¦ãã®ç¨®é¡ã§åå² 499 if (MutualSwitching.config.isFlexibleLayout()) { 500 //------------------------------------------------------------------ 501 // ãã¬ãã·ãã«ã¬ã¤ã¢ã¦ã 502 //------------------------------------------------------------------ 503 // ãã¥ã¼ãã¼ãæ¸æã 504 rewriteViewPort(MutualSwitching.config.getViewPortFlexible()); 505 } else if (MutualSwitching.config.isIndividualLayout()) { 506 //------------------------------------------------------------------ 507 // åå¥ã¬ã¤ã¢ã¦ã 508 //------------------------------------------------------------------ 509 // ãã¥ã¼ãã¼ãæ¸æã 510 rewriteViewPort(MutualSwitching.config.getViewPortSp()); 511 } else { 512 //------------------------------------------------------------------ 513 // ã¬ã¹ãã³ã·ãã¬ã¤ã¢ã¦ã 514 //------------------------------------------------------------------ 515 // ãã¥ã¼ãã¼ãæ¸æã 516 rewriteViewPort(MutualSwitching.config.getViewPortPc()); 517 } 518 } 519 520 // ã¹ãããã¼ã¸é²è¦§ä¸ 521 if (isSpView() && MutualSwitching.util.isDeviceSp()) { 522 // ã¬ã¤ã¢ã¦ãã®ç¨®é¡ã§åå² 523 if (MutualSwitching.config.isFlexibleLayout()) { 524 //------------------------------------------------------------------ 525 // ãã¬ãã·ãã«ã¬ã¤ã¢ã¦ã 526 //------------------------------------------------------------------ 527 // ãã¥ã¼ãã¼ãæ¸æã 528 rewriteViewPort(MutualSwitching.config.getViewPortFlexible()); 529 } else if (MutualSwitching.config.isIndividualLayout()) { 530 //------------------------------------------------------------------ 531 // åå¥ã¬ã¤ã¢ã¦ã 532 //------------------------------------------------------------------
533 // PCãã¼ã¸ã¸ã®åæ¿ãã¿ã³è¡¨ç¤º 534 $('.jqs-go-to-pc').show(); 535 536 if (MutualSwitching.config.getViewPcBySp()) { 537 if (location.href.indexOf('.sp.') <= 0 && MutualSwitching.config.isExistsSpPage()) { 538 $.cookie('view_mode', 'sp', {expires: 0, path: '/', domain: MutualSwitching.util.getDomain()}); 539 location.href = getRedirectUrlPcToSp().replace('.html', '.sp.html'); 540 } else { 541 // CSSæ¸æã 542 rewriteCssPcToSp(); 543 // ãã¥ã¼ãã¼ãæ¸æã 544 rewriteViewPort(MutualSwitching.config.getViewPortSp()); 545 } 546 } else if (MutualSwitching.config.isExistsSpPage && (location.href.indexOf('.sp.') <= 0)) { 547 location.href = getRedirectUrlPcToSp().replace('.html', '.sp.html'); 548 } else { 549 // CSSæ¸æã 550 rewriteCssPcToSp(); 551 // ãã¥ã¼ãã¼ãæ¸æã 552 rewriteViewPort(MutualSwitching.config.getViewPortSp()); 553 } 554 } else { 555 //------------------------------------------------------------------ 556 // ã¬ã¹ãã³ã·ãã¬ã¤ã¢ã¦ã 557 //------------------------------------------------------------------ 558 // ãã¥ã¼ãã¼ãæ¸æã 559 rewriteViewPort(MutualSwitching.config.getViewPortSp()); 560 } 561 } 562 }); 563 } 564 }; 565})();
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.