Created
March 3, 2012 17:25
-
-
Save mytharcher/1967066 to your computer and use it in GitHub Desktop.
jslib路径计算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* jslib JavaScript Library | |
* | |
* create: | |
* @2011-11-30 by mytharcher | |
* | |
* update: | |
*/ | |
///import js.util.Class; | |
///import js.net; | |
/** | |
* @class js.net.Path URL地址处理类 | |
*/ | |
js.net.Path = js.util.Class.create({ | |
constructor: function (path) { | |
this._path = path; | |
}, | |
forward: function (base, rel) { | |
var relArr = rel.split('../'); | |
var len = relArr.length - 1; | |
var baseArr = base.split('/'); | |
baseArr.splice(baseArr.length - len, len); | |
return baseArr.join('/') + '/' + relArr.pop(); | |
} | |
}); | |
/* | |
* usage: | |
* path.forward("http://jntest.baidu.com:8080/src/jn/landmark/promotion/material_list.app.html", "../../../jn/a.css"); | |
* => "http://jntest.baidu.com:8080/src/jn/jn/a.css" | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment