X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=0.6.x%2Fjs%2F01_core%2F06_XURL.js;h=39951cb52901bbc970e7befe8d264900513f082a;hb=d836e6243878426d4cfd7a14ceb9b77db9f92b57;hp=96be64371c8cac577a6ca656e5f5fe02bc9b94f4;hpb=714d9a512e8d9e09001183ebf15f549ea51e48ad;p=pettanr%2FclientJs.git diff --git a/0.6.x/js/01_core/06_XURL.js b/0.6.x/js/01_core/06_XURL.js index 96be643..39951cb 100644 --- a/0.6.x/js/01_core/06_XURL.js +++ b/0.6.x/js/01_core/06_XURL.js @@ -1,33 +1,78 @@ +// ------------------------------------------------------------------------- // +// ------------ local variables -------------------------------------------- // +// ------------------------------------------------------------------------- // var X_URL_BASE_URL = ( function( parts ){ var last = 1 < parts.length && parts[ parts.length - 1 ]; if( last !== false && ( last === '' || //末尾が/で終わるとき - last.indexOf( '.' ) !== -1 ) ){//末尾がファイル名で終わる時 - + last.indexOf( '.' ) !== -1 ) ){ //末尾がファイル名で終わる時 --parts.length; }; return parts.join( '/' ); - })( location.href.split( '?' )[ 0 ].split( '#' )[ 0 ].split( '/' ) ), + })( X_URL_cleanup( location.href ).split( '/' ) ), - X_URL_IS_LOCAL = location.protocol === 'file:' || location.hostname === 'localhost' || location.hostname === '127.0.0.1'; + X_URL_IS_FILE = location.protocol === 'file:', + + X_URL_IS_LOCAL = X_URL_IS_FILE || location.hostname === 'localhost' || location.hostname === '127.0.0.1', + + X_URL_PARAMS = ( function( search ){ + var str = search.slice( 1 ), + parts = str.split( '&' ), + i = 0, + l = parts.length, + obj = {}, + pair, p; + + if( !str ) return obj; + + for( ; i < l; ++i ){ + pair = parts[ i ]; + p = pair.indexOf( '=' ); + if( p === -1 ){ + obj[ decodeURIComponent( pair ) ] = true; + } else { + obj[ decodeURIComponent( pair.substr( 0, p ) ) ] = X_String_parse( decodeURIComponent( pair.substr( p + 1 ) ) ); + }; + }; + + return obj; + } )( location.search ); +// ------------------------------------------------------------------------- // +// --- interface ----------------------------------------------------------- // +// ------------------------------------------------------------------------- // -X.URL = { +/** + * @namespace X.URL + * @alias X.URL + */ +X[ 'URL' ] = { - BASE_URL : X_URL_BASE_URL, + 'BASE_URL' : X_URL_BASE_URL, + + 'IS_FILE' : X_URL_IS_FILE, + + 'IS_LOCAL' : X_URL_IS_LOCAL, + + 'PARAMS' : X_URL_PARAMS, + + 'toAbsolutePath' : X_URL_toAbsolutePath, + + 'isSameDomain' : X_URL_isSameDomain, - IS_LOCAL : X_URL_IS_LOCAL, + 'cleanup' : X_URL_cleanup, - toAbsolutePath : X_URL_toAbsolutePath + 'getEXT' : X_URL_getEXT }; - - - /* - * original - * AS3で相対パスを絶対パスに変換する - * http://www.shin-go.net/motionlab/?p=449 - */ +// ------------------------------------------------------------------------- // +// --- implements ---------------------------------------------------------- // +// ------------------------------------------------------------------------- // +/* + * original + * AS3で相対パスを絶対パスに変換する + * http://www.shin-go.net/motionlab/?p=449 + */ function X_URL_toAbsolutePath( path ){ var s = '/', ss = '//', @@ -50,4 +95,19 @@ function X_URL_toAbsolutePath( path ){ if( i ) path = path.substr( i ); }; return [ _ary[ 0 ], ss, ary.join( s ), s, path ].join( '' ); -}; \ No newline at end of file +}; + +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; +}; + +function X_URL_cleanup( path ){ + return path.split( '?' )[ 0 ].split( '#' )[ 0 ]; +}; + +function X_URL_getEXT( path ){ + path = X_URL_cleanup( path ).split( '.' ); + return path.length ? path.pop() : ''; +}; +