2 // ------------------------------------------------------------------------- //
\r
3 // ------------ local variables -------------------------------------------- //
\r
4 // ------------------------------------------------------------------------- //
\r
5 var X_URL_BASE_URL = ( function( parts ){
\r
6 var last = 1 < parts.length && parts[ parts.length - 1 ];
\r
7 if( last !== false && ( last === '' || //末尾が/で終わるとき
\r
8 last.indexOf( '.' ) !== -1 ) ){ //末尾がファイル名で終わる時
\r
11 return parts.join( '/' );
\r
12 })( location.href.split( '?' )[ 0 ].split( '#' )[ 0 ].split( '/' ) ),
\r
14 X_URL_IS_FILE = location.protocol === 'file:',
\r
16 X_URL_IS_LOCAL = X_URL_IS_FILE || location.hostname === 'localhost' || location.hostname === '127.0.0.1';
\r
18 // ------------------------------------------------------------------------- //
\r
19 // --- interface ----------------------------------------------------------- //
\r
20 // ------------------------------------------------------------------------- //
\r
23 BASE_URL : X_URL_BASE_URL,
\r
25 IS_FILE : X_URL_IS_FILE,
\r
27 IS_LOCAL : X_URL_IS_LOCAL,
\r
29 toAbsolutePath : X_URL_toAbsolutePath
\r
32 // ------------------------------------------------------------------------- //
\r
33 // --- implements ---------------------------------------------------------- //
\r
34 // ------------------------------------------------------------------------- //
\r
37 * AS3で相対パスを絶対パスに変換する
\r
38 * http://www.shin-go.net/motionlab/?p=449
\r
40 function X_URL_toAbsolutePath( path ){
\r
45 if( 'http:file:https:'.indexOf( path.substr( 0, 4 ) ) !== -1 ) return path;
\r
47 _ary = X_URL_BASE_URL.split( ss );
\r
48 ary = _ary[ 1 ].split( s );
\r
50 if( path.charAt( 0 ) === s ) return [ _ary[ 0 ], ss, ary[ 0 ], path ].join( '' );
\r
52 if( path.substr( 0, 2 ) === './' ){
\r
53 path = path.substr( 2 );
\r
55 while( path.substr( i, 3 ) === '../' ){
\r
59 if( i ) path = path.substr( i );
\r
61 return [ _ary[ 0 ], ss, ary.join( s ), s, path ].join( '' );
\r