PageSourceSearch

https://www.softbank.jp/site/set/common/shared/js/global.js

js softbank.jp collected 2026-10-01 07:25:03 UTC 4,883 bytes, 169 lines download raw bytes

1// import
2'jQuery' in window && (function () {
3'use strict';
4var win = window;
5var loc = win.location;
6var doc = win.document;
7var SoftBank;
8
9
10// polyfil
11(function () {
12    if (!Array.prototype.filter) {
13        Array.prototype.filter = function(aCallBack, aThisObject) {
14            var ret = [];
15            for (var i = 0, n = this.length; i < n; i++) {
16                if (aCallBack.call(aThisObject, this[i], i, this)) {
17                    ret.push(this[i]);
18                }
19            }
20            return ret;
21        };
22    }
23
24    String.prototype._startsWith = function(str) {
25        return (this.indexOf(str) === 0);
26    };
27}());
28
29// パス/階層を判別するオブジェクト
30win.SoftBank = SoftBank = (function () {
31    var _SoftBank = function (path) {
32        var _path = path || loc.pathname;
33
34        this.url = {};
35
36        this.lang = $('html').attr('lang');
37        this.fullPath = _path.replace(/^\/s\//, '/');
38
39        this.path = (function (sb) {
40            var pt = sb.fullPath;
41            var ret;
42
43            if (pt === '/') {
44                ret = pt;
45            } else if (pt.match(/\./)) {
46                // .html等の拡張子が含まれている場合は末尾全てreplaceする
47                ret = pt.replace(/[a-zA-Z0-9.]+$/, '');
48            } else if (pt.slice(-1) !== '/') {
49                // 拡張子が存在しないが/で終わっていない場合もはこちらで足す
50                ret = pt + '/';
51            } else {
52                ret = pt;
53            }
54
55            return ret;
56
57        }(this));
58
59        this.langPath = '';
60        this.categoryPath = '';
61        this.SP = '';
62
63        this.voidPath = /\/(en|cn|kr)\//i;
64
65
66        this.url.commonDir = this.getCommonDir('common') || this.getCommonDir('shared');
67        this.url.imgDir    = this.url.commonDir + 'img/';
68        this.url.cssDir    = this.url.commonDir + 'css/';
69        this.url.jsDir     = this.url.commonDir + 'js/';
70
71        this.TK_FLG = 0;
72
73        this._init();
74    };
75
76    _SoftBank.prototype = {
77        _init : function () {
78            this._setPath();
79            this._setCategoryPath();
80            this._checkUserAgent();
81            this._getTK_FLG();
82            return this;
83        },
84
85        _setPath : function () {
86            var pt = this.path.match(this.voidPath);
87
88            if (pt) {
89                pt = pt[0].replace(/\//g, '');
90                this.path = this.path.replace(this.voidPath, '/');
91            } else {
92                pt = 'ja';
93                this.path = this.path.replace(this.voidPath, '');
94            }
95
96            this.langPath = pt;
97
98            this.hierarchy = this.path.match(/\//g).length;
99
100        },
101
102        _setCategoryPath : function () {
103            var h = this.hierarchy;
104            var str;
105
106            if (h < 3) {
107                this.categoryPath = this.path;
108                this.categoryLocation = '/';
109            } else {
110                // 3階層以降は下層のパスまで入るので削る必要がある
111                this.categoryPath = this.path.match(/\/[a-z-0-9]+\//i)[0];
112                this.categoryLocation = '/under/';
113            }
114
115
116        },
117
118        getCommonDir : function (dirName) {
119            var path  = './';
120            var nodes = document.getElementsByTagName('head')[0].getElementsByTagName('script');
121
122            for (var i = 0, n = nodes.length; i < n; i++) {
123                var arr = nodes[i].src.split('/');
124                var idx = $.inArray(dirName, arr);
125                if (idx != -1) {
126                    path = arr.slice(0, idx + 1).join('/') + '/';
127                    break;
128                }
129            }
130
131            if (!path.match(':')) {   // if path is not absolute url (workaround for IE)
132                var base = document.getElementsByTagName('base')[0];
133                var burl = (base) ? base.href : location.href;
134                if (path._startsWith('/')) {
135                    path = burl.match(/^\w+:\/*[^\/]+/)[0] + path;
136                }
137            }
138
139            return path;
140        },
141
142        _checkUserAgent : function () {
143            var ua = win.navigator.userAgent;
144            this.SP = (-1 < ua.indexOf('iPhone') || -1 < ua.indexOf('iPod') || (-1 < ua.indexOf('Android') && -1 < ua.indexOf('Mobile')));
145
146        },
147
148        //新モジュール適用ページかどうかを判定する
149        _getTK_FLG : function(){
150            var linkTag = document.getElementsByTagName('link');
151            for(var i=0; i<linkTag.length; i++){
152                if(linkTag[i].href.match(/\/site\/set\/common\/(p|s)\/css\/(tk-|l3-)modules.css/)){
153                    this.TK_FLG = 1;
154
155                    break;
156                }
157            }
158        },
159
160        reBuild : function (path) {
161            return new _SoftBank(path);
162        }
163
164    };
165
166    return new _SoftBank();
167}());
168
169}());

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.