1// JQuery URL Parser plugin - https://github.com/allmarkedup/jQuery-URL-Parser 2// Written by Mark Perkins, [email protected] 3// License: http://unlicense.org/ (i.e. do what you want with it!) 4 5; 6(function ($, undefined) { 7 8 var tag2attr = { 9 a: 'href', 10 img: 'src', 11 form: 'action', 12 base: 'href', 13 script: 'src', 14 iframe: 'src', 15 link: 'href' 16 }, 17 18 key = ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "fragment"], // keys available to query 19 20 aliases = { 21 "anchor": "fragment" 22 }, // aliases for backwards compatability 23 24 parser = { 25 strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, //less intuitive, more accurate to the specs 26 loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // more intuitive, fails on relative paths and deviates from specs 27 }, 28 29 querystring_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g, // supports both ampersand and semicolon-delimted query string key/value pairs 30 31 fragment_parser = /(?:^|&|;)([^&=;]*)=?([^&;]*)/g; // supports both ampersand and semicolon-delimted fragment key/value pairs 32 33 function parseUri(url, strictMode) { 34 var str = decodeURI(url), 35 res = parser[strictMode || false ? "strict" : "loose"].exec(str), 36 uri = { 37 attr: {}, 38 param: {}, 39 seg: {} 40 }, 41 i = 14; 42 43 while (i--) { 44 uri.attr[key[i]] = res[i] || ""; 45 } 46 47 // build query and fragment parameters 48 49 uri.param['query'] = {}; 50 uri.param['fragment'] = {}; 51 52 uri.attr['query'].replace(querystring_parser, function ($0, $1, $2) { 53 if ($1) { 54 uri.param['query'][$1] = $2; 55 } 56 }); 57 58 uri.attr['fragment'].replace(fragment_parser, function ($0, $1, $2) { 59 if ($1) { 60 uri.param['fragment'][$1] = $2; 61 } 62 }); 63 64 // split path and fragement into segments 65 66 uri.seg['path'] = uri.attr.path.replace(/^\/+|\/+$/g, '').split('/'); 67 68 uri.seg['fragment'] = uri.attr.fragment.replace(/^\/+|\/+$/g, '').split('/'); 69 70 // compile a 'base' domain attribute 71 72 uri.attr['base'] = uri.attr.host ? uri.attr.protocol + "://" + uri.attr.host + (uri.attr.port ? ":" + uri.attr.port : '') : ''; 73 74 return uri; 75 }; 76 77 function getAttrName(elm) { 78 var tn = elm.tagName; 79 if (tn !== undefined) return tag2attr[tn.toLowerCase()]; 80 return tn; 81 } 82 83 $.fn.url = function (strictMode) { 84 var url = ''; 85 86 if (this.length) { 87 url = $(this).attr(getAttrName(this[0])) || ''; 88 } 89 90 return $.url(url, strictMode); 91 }; 92 93 $.url = function (url, strictMode) { 94 if (arguments.length === 1 && url === true) { 95 strictMode = true; 96 url = undefined; 97 } 98 99 strictMode = strictMode || false; 100 url = url || window.location.toString(); 101 102 return { 103 104 data: parseUri(url, strictMode), 105 106 // get various attributes from the URI 107 attr: function (attr) { 108 attr = aliases[attr] || attr; 109 return attr !== undefined ? this.data.attr[attr] : this.data.attr; 110 }, 111 112 // return query string parameters 113 param: function (param) { 114 return param !== undefined ? this.data.param.query[param] : this.data.param.query; 115 }, 116 117 // return fragment parameters 118 fparam: function (param) { 119 return param !== undefined ? this.data.param.fragment[param] : this.data.param.fragment; 120 }, 121 122 // return path segments 123 segment: function (seg) { 124 if (seg === undefined) { 125 return this.data.seg.path; 126 } else { 127 seg = seg < 0 ? this.data.seg.path.length + seg : seg - 1; // negative segments count from the end 128 return this.data.seg.path[seg]; 129 } 130 }, 131 132 // return fragment segments 133 fsegment: function (seg) { 134 if (seg === undefined) { 135 return this.data.seg.fragment; 136 } else { 137 seg = seg < 0 ? this.data.seg.fragment.length + seg : seg - 1; // negative segments count from the end 138 return this.data.seg.fragment[seg]; 139 } 140 } 141 142 }; 143 144 }; 145 146})(jQuery); 147 148//ããã²ã¼ã·ã§ã³ 149$(function () { 150 var url = $.url(); 151 $dire = url.segment(0);ã //ã©ãã®é層ã§å¤å®ï¼ 152 if (!$dire) { 153 $dire = 'index.html'; 154 } 155 $('.navi > li > a').each(function () { 156 var $href = $(this).attr('href'); 157 if (($href == $dire) || ($href == '')) { 158 $(this).addClass('current'); 159 } else { 160 $(this).removeClass('current'); 161 } 162 }); 163}); 164 165// ãµãããã²ã¼ã·ã§ã³ 166$(function () { 167 var url = $.url(); 168 $page = url.attr('file'); 169 if (!$page) { 170 $page = 'index.html'; 171 } 172 $('.subNavi li a').each(function () { 173 var $href = $(this).attr('href'); 174 if (($href == $page) || ($href == '')) { 175 $(this).addClass('current'); 176 } else { 177 $(this).removeClass('current'); 178 } 179 }); 180}); 181 182// ãµãã¡ãã¥ã¼ 183$(function () { 184 var url = $.url(); 185 $page = url.attr('file'); 186 if (!$page) { 187 $page = 'index.html'; 188 } 189 $('#subMenu li a').each(function () { 190 var $href = $(this).attr('href'); 191 if (($href == $page) || ($href == '')) { 192 $(this).addClass('menuCurrent'); 193 } else { 194 $(this).removeClass('menuCurrent'); 195 } 196 }); 197}); 198
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.