Skip to content

Commit d7ee094

Browse files
committed
文档增加设备侦测说明,$.device增加微信环境判断
1 parent c481e5b commit d7ee094

4 files changed

Lines changed: 43 additions & 5 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<article class="component" id="device">
2+
<h2 class="component-title">设备侦测工具</h2>
3+
<p class="component-description"><code>$.device</code>提供了一些基本的设备侦测信息可供使用。举例如下:</p>
4+
5+
{% highlight js %}
6+
console.log($.device)
7+
// --------
8+
{
9+
android: true
10+
androidChrome: false
11+
ios: false
12+
ipad: false
13+
iphone: false
14+
isWeixin: false
15+
os: "android"
16+
osVersion: "4.4.1"
17+
pixelRatio: 3
18+
statusBar: false
19+
webView: null
20+
}
21+
{% endhighlight %}
22+
23+
<p class="component-description">同时提供<code>$.compareVersion</code>工具用以方便的进行版本号比较:</p>
24+
{% highlight js %}
25+
// arg1 > arg2, return 1; arg1 == arg2, return 0; arg1 < arg2, return -1
26+
$.compareVersion('8.0', '7.1.1')
27+
// return 1
28+
$.compareVersion('4.2', $.device.osVersion)
29+
// return -1
30+
$.compareVersion('5.0', '5.0')
31+
// return 0
32+
33+
{% endhighlight %}
34+
</article>
35+

‎docs/_includes/jump.html‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@
2929
<li><a href="#router" data-ignore="push">路由 <span class='new'>新</span></a></li>
3030
<li><a href="#themes" data-ignore="push">夜间模式</a></li>
3131
<li><a href="#colors" data-ignore="push">颜色主题</a></li>
32+
<li><a href="#device" data-ignore="push">设备侦测</a></li>
3233
</div>

‎docs/components.html‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ <h1 class="title">示例</h1>
5858
{% include _components/icons.html %}
5959
{% include _components/router.html %}
6060
{% include _components/themes.html %}
61+
{% include _components/device.html %}
6162

62-
63-
<!-- Ratchicons -->
6463
<!-- Footer -->
6564
{% include footer.html %}
6665
</div>

‎js/device.js‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Device/OS Detection
1313
var iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/);
1414

1515
device.ios = device.android = device.iphone = device.ipad = device.androidChrome = false;
16-
16+
1717
// Android
1818
if (android) {
1919
device.os = 'android';
@@ -47,7 +47,7 @@ Device/OS Detection
4747

4848
// Webview
4949
device.webView = (iphone || ipad || ipod) && ua.match(/.*AppleWebKit(?!.*Safari)/i);
50-
50+
5151
// Minimal UI
5252
if (device.os && device.os === 'ios') {
5353
var osVersionArr = device.osVersion.split('.');
@@ -87,7 +87,7 @@ Device/OS Detection
8787
classNames.push('ios-gt-' + i);
8888
}
8989
}
90-
90+
9191
}
9292
// Status bar classes
9393
if (device.statusBar) {
@@ -100,5 +100,8 @@ Device/OS Detection
100100
// Add html classes
101101
if (classNames.length > 0) $('html').addClass(classNames.join(' '));
102102

103+
// keng..
104+
device.isWeixin = /MicroMessenger/i.test(ua);
105+
103106
$.device = device;
104107
})(Zepto);

0 commit comments

Comments
 (0)