You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 24, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 24, 2022. It is now read-only.
Activity
cssmagic commentedon May 9, 2015
JavaScript 接口
_.url.composeUrl(parts)根据提供的 URL 各个要素,构造完整的 URL。URL 各个组成部分的名称及含义同
_.url.parseUrl()接口的描述。参数
parts-- 对象。URL 的各个要素的名值对。返回值
字符串。构造出的完整 URL。
当参数不合法时,返回空字符串。
注意事项
host时,将忽略hostname和port字段。pathname必须以/开头;不以/开头则会自动补上。search必须以?开头;不以?开头则会自动补上。hash必须以#开头;不以#开头则会自动补上。host、hostname、pathname中的?和#字符会被编码;search中的#字符会被编码。port值在经过parseInt(port, 10)转换后必须为0或正整数;其它值均视为0。protocol-- 若省略则取当前页面的location.protocol。host-- 若省略则取hostname和port。port-- 若省略则取当前页面的location.port。hostname-- 若省略则取当前页面的location.hostname。pathname-- 若省略则取根目录(/)。search-- 若省略则不输出。hash-- 若省略则不输出。示例
_.url.removeHashFromUrl(url)把 URL 中的 hash 部分去除。
参数
url-- 字符串。待处理的 URL。返回值
字符串。若参数不合法则返回空字符串。
示例
_.url.getHashFromUrl(url)获取 URL 中的 hash 部分。获取结果包含开头的
#字符。若需要得到当前页面 URL 的 hash 部分,请直接使用
location.hash。参数
url-- 字符串。待处理的 URL,可以是完整的 URL,也可以是相对路径。返回值
字符串。若参数不合法则返回空字符串;若 URL 中不包含 hash 部分则返回空字符串。
示例
_.url.getHashFromLink(link)获取指定链接的
href属性值中的 hash 部分。获取结果包含开头的#字符。参数
link-- DOM 元素。待处理的链接元素(<a>或<link>)。返回值
字符串。若参数不合法则返回空字符串;若元素的
href属性值中不包含 hash 部分则返回空字符串。示例
别名
_.url.isHash_.str.isHash()的别名。_.url.stripHash_.str.stripHash()的别名。_.url.isFullUrl_.str.isFullUrl()的别名。_.url.isAbsolutePath_.str.isAbsolutePath()的别名。hax commentedon May 11, 2015
总体上最好需要 follow 某种惯用 API,以减少学习成本和方便记忆。
可以考虑 whatwg URL spec( https://url.spec.whatwg.org/#api ) 或 nodejs 的 API( https://iojs.org/api/url.html )
hax commentedon May 11, 2015
_.url.isInFrame 在 url 下似乎有点诡异。
cssmagic commentedon May 11, 2015
😄 是的,略诡异。好几年前不严谨的 API 组织方式一直残留下来。不过暂时也想不出放进哪个模块(命名空间)更适合。改成
_.env.isInFrame是不是更好?不过单独为它建个模块又觉得略蛋疼。另外还想把这种预定义的变量(属性)改成方法:
.isInFrame()。cssmagic commentedon Jun 24, 2015
决定暂时删掉
_.url.isInFrame这个 API。Remove `_.url.isInFrame` API. See CMUI#56.