X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F01_core%2F09_XURL.js;h=2ac3f5dc1434d4901ce0610add7a417009848329;hb=4e4ab3be10850546063d4a4b93250ed142bb8cd2;hp=0eaccabe991c0173aa0373bdda1d3f4b2f8a6718;hpb=6b28a86cc49680dac50278ff5617bfe7a3d98613;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/01_core/09_XURL.js b/0.6.x/js/01_core/09_XURL.js index 0eaccab..2ac3f5d 100644 --- a/0.6.x/js/01_core/09_XURL.js +++ b/0.6.x/js/01_core/09_XURL.js @@ -4,6 +4,7 @@ // ------------------------------------------------------------------------- // var X_URL_BASE_URL = ( function( parts ){ var last = 1 < parts.length && parts[ parts.length - 1 ]; + if( last !== false && ( last === '' || //末尾が/で終わるとき last.indexOf( '.' ) !== -1 ) ){ //末尾がファイル名で終わる時 --parts.length; @@ -11,6 +12,8 @@ var X_URL_BASE_URL = ( function( parts ){ return parts.join( '/' ); })( X_URL_cleanup( location.href ).split( '/' ) ), + X_URL_HOST = location.protocol + '//' + location.hostname, + X_URL_IS_FILE = location.protocol === 'file:', X_URL_IS_LOCAL = X_URL_IS_FILE || location.hostname === 'localhost' || location.hostname === '127.0.0.1', @@ -65,7 +68,11 @@ X[ 'URL' ] = { 'cleanup' : X_URL_cleanup, - 'getEXT' : X_URL_getEXT + 'getEXT' : X_URL_getEXT, + + 'getSearch' : X_URL_getSearch, + + 'getHash' : X_URL_getHash }; // ------------------------------------------------------------------------- // @@ -109,7 +116,7 @@ function X_URL_toAbsolutePath( path ){ */ function X_URL_isSameDomain( path ){ path = X_URL_cleanup( X_URL_toAbsolutePath( path ) ); - return path === X_URL_BASE_URL || path.indexOf( X_URL_BASE_URL + '/' ) === 0; + return path === X_URL_HOST || path.indexOf( X_URL_HOST + '/' ) === 0; }; /** * 同一プロトコルか? @@ -149,6 +156,29 @@ function X_URL_getEXT( path ){ return path.length ? path.pop() : ''; }; /** + * サーチクエリを返します。 + * @alias X.URL.getSearch + * @param {string} + * @return {string} + */ +function X_URL_getSearch( path ){ + path = path.split( '#' )[ 0 ].split( '?' ); + path.splice( 0, 1 ); + return path.join( '?' ); +} +/** + * ハッシュフラグメントを返します。 + * @alias X.URL.getHash + * @param {string} + * @return {string} + */ +function X_URL_getHash( path ){ + path = path.split( '#' ); + path.splice( 0, 1 ); + return path.join( '#' ); +} + +/** * object を url パラメータにします。値が object の場合、データは失われます。 * @alias X.URL.objToParam * @param {object}