OSDN Git Service

Version 0.6.134, add comments for closure compiler.
[pettanr/clientJs.git] / 0.6.x / js / 01_core / 06_XURL.js
index 6973201..9d2dd87 100644 (file)
@@ -9,24 +9,60 @@ var X_URL_BASE_URL = ( function( parts ){
                        --parts.length;\r
                };\r
                return parts.join( '/' );\r
-       })( location.href.split( '?' )[ 0 ].split( '#' )[ 0 ].split( '/' ) ),\r
+       })( X_URL_cleanup( location.href ).split( '/' ) ),\r
        \r
        X_URL_IS_FILE  = location.protocol === 'file:',\r
        \r
-       X_URL_IS_LOCAL = X_URL_IS_FILE || location.hostname === 'localhost' || location.hostname === '127.0.0.1';\r
+       X_URL_IS_LOCAL = X_URL_IS_FILE || location.hostname === 'localhost' || location.hostname === '127.0.0.1',\r
+       \r
+       X_URL_PARAMS = ( function( search ){\r
+               var str   = search.slice( 1 ),\r
+                       parts = str.split( '&' ),\r
+                       i     = 0,\r
+                       l     = parts.length,\r
+                       obj   = {},\r
+                       pair, p;\r
+\r
+               if( !str ) return obj;\r
+               \r
+               for( ; i < l; ++i ){\r
+                       pair = parts[ i ];\r
+                       p    = pair.indexOf( '=' );\r
+                       if( p === -1 ){\r
+                               obj[ decodeURIComponent( pair ) ] = true;\r
+                       } else {\r
+                               obj[ decodeURIComponent( pair.substr( 0, p ) ) ] = X_String_parse( decodeURIComponent( pair.substr( p + 1 ) ) );\r
+                       };\r
+               };\r
+\r
+               return obj;\r
+       } )( location.search );\r
 \r
 // ------------------------------------------------------------------------- //\r
 // --- interface ----------------------------------------------------------- //\r
 // ------------------------------------------------------------------------- //\r
-X.URL = {\r
 \r
-       BASE_URL : X_URL_BASE_URL,\r
+/**\r
+ * @namespace X.URL\r
+ * @alias X.URL\r
+ */\r
+X[ 'URL' ] = {\r
+\r
+       'BASE_URL' : X_URL_BASE_URL,\r
+       \r
+       'IS_FILE'  : X_URL_IS_FILE,\r
+       \r
+       'IS_LOCAL' : X_URL_IS_LOCAL,\r
+       \r
+       'PARAMS'   : X_URL_PARAMS,\r
        \r
-       IS_FILE  : X_URL_IS_FILE,\r
+       'toAbsolutePath' : X_URL_toAbsolutePath,\r
        \r
-       IS_LOCAL : X_URL_IS_LOCAL,\r
+       'isSameDomain'   : X_URL_isSameDomain,\r
        \r
-       toAbsolutePath : X_URL_toAbsolutePath\r
+       'cleanup'        : X_URL_cleanup,\r
+       \r
+       'getEXT'         : X_URL_getEXT\r
 };\r
 \r
 // ------------------------------------------------------------------------- //\r
@@ -59,4 +95,19 @@ function X_URL_toAbsolutePath( path ){
                if( i ) path = path.substr( i );\r
        };\r
        return [ _ary[ 0 ], ss, ary.join( s ), s, path ].join( '' );\r
-};
\ No newline at end of file
+};\r
+\r
+function X_URL_isSameDomain( path ){\r
+       path = X_URL_cleanup( X_URL_toAbsolutePath( path ) );\r
+       return path === X_URL_BASE_URL || path.indexOf( X_URL_BASE_URL + '/' ) === 0;\r
+};\r
+\r
+function X_URL_cleanup( path ){\r
+       return path.split( '?' )[ 0 ].split( '#' )[ 0 ];\r
+};\r
+\r
+function X_URL_getEXT( path ){\r
+       path = X_URL_cleanup( path ).split( '.' );\r
+       return path.length ? path.pop() : '';\r
+};\r
+\r