Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

weui

Package Overview
Dependencies
Maintainers
1
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

weui - npm Package Compare versions

Comparing version 0.2.3 to 0.3.0

bower.json

379

dist/example/example.js
/**
* Created by jfengjiang on 2015/9/11.
* Created by jf on 2015/9/11.
*/
$(function () {
// page stack
var stack = [];
var $container = $('.js_container');
$container.on('click', '.js_cell[data-id]', function () {
var id = $(this).data('id');
go(id);
});
// location.hash = '#hash1' 和点击后退都会触发`hashchange`,这个demo页面只关心后退
$(window).on('hashchange', function (e) {
if (/#.+/gi.test(e.newURL)) {
return;
var pageManager = {
$container: $('.js_container'),
_pageStack: [],
_configs: [],
_defaultPage: null,
_isGo: false,
default: function (defaultPage) {
this._defaultPage = defaultPage;
return this;
},
init: function () {
var self = this;
$(window).on('hashchange', function (e) {
var _isBack = !self._isGo;
self._isGo = false;
if (!_isBack) {
return;
}
var url = location.hash.indexOf('#') === 0 ? location.hash : '#';
var found = null;
for(var i = 0, len = self._pageStack.length; i < len; i++){
var stack = self._pageStack[i];
if (stack.config.url === url) {
found = stack;
break;
}
}
if (found) {
self.back();
}
else {
goDefault();
}
});
function goDefault(){
var url = location.hash.indexOf('#') === 0 ? location.hash : '#';
var page = self._find('url', url) || self._find('name', self._defaultPage);
self.go(page.name);
}
goDefault();
return this;
},
push: function (config) {
this._configs.push(config);
return this;
},
go: function (to) {
var config = this._find('name', to);
if (!config) {
return;
}
var html = $(config.template).html();
var $html = $(html).addClass('slideIn').addClass(config.name);
this.$container.append($html);
this._pageStack.push({
config: config,
dom: $html
});
this._isGo = true;
location.hash = config.url;
if (!config.isBind) {
this._bind(config);
}
return this;
},
back: function () {
var stack = this._pageStack.pop();
if (!stack) {
return;
}
stack.dom.addClass('slideOut').on('animationend', function () {
stack.dom.remove();
}).on('webkitAnimationEnd', function () {
stack.dom.remove();
});
return this;
},
_find: function (key, value) {
var page = null;
for (var i = 0, len = this._configs.length; i < len; i++) {
if (this._configs[i][key] === value) {
page = this._configs[i];
break;
}
}
return page;
},
_bind: function (page) {
var events = page.events || {};
for (var t in events) {
for (var type in events[t]) {
this.$container.on(type, t, events[t][type]);
}
}
page.isBind = true;
}
var $top = stack.pop();
if (!$top) {
return;
};
var home = {
name: 'home',
url: '#',
template: '#tpl_home',
events: {
'.js_grid': {
click: function (e) {
var id = $(this).data('id');
pageManager.go(id);
}
}
}
$top.addClass('slideOut').on('animationend', function () {
$top.remove();
}).on('webkitAnimationEnd', function () {
$top.remove();
});
});
};
var button = {
name: 'button',
url: '#button',
template: '#tpl_button'
};
var cell = {
name: 'cell',
url: '#cell',
template: '#tpl_cell',
events: {
'#showTooltips': {
click: function () {
var $tooltips = $('.js_tooltips');
if ($tooltips.css('display') != 'none') {
return;
}
function go(id){
var $tpl = $($('#tpl_' + id).html()).addClass('slideIn').addClass(id);
$container.append($tpl);
stack.push($tpl);
// why not use `history.pushState`, https://github.com/weui/weui/issues/26
//history.pushState({id: id}, '', '#' + id);
location.hash = '#' + id;
// 如果有`animation`, `position: fixed`不生效
$('.page.cell').removeClass('slideIn');
$tooltips.show();
setTimeout(function () {
$tooltips.hide();
}, 2000);
}
}
}
};
var toast = {
name: 'toast',
url: '#toast',
template: '#tpl_toast',
events: {
'#showToast': {
click: function (e) {
var $toast = $('#toast');
if ($toast.css('display') != 'none') {
return;
}
$($tpl).on('webkitAnimationEnd', function (){
$(this).removeClass('slideIn');
}).on('animationend', function (){
$(this).removeClass('slideIn');
});
// tooltips
if (id == 'cell') {
$('.js_tooltips').show();
setTimeout(function (){
$('.js_tooltips').hide();
}, 3000);
$toast.show();
setTimeout(function () {
$toast.hide();
}, 2000);
}
},
'#showLoadingToast': {
click: function (e) {
var $loadingToast = $('#loadingToast');
if ($loadingToast.css('display') != 'none') {
return;
}
$loadingToast.show();
setTimeout(function () {
$loadingToast.hide();
}, 2000);
}
}
}
}
};
var dialog = {
name: 'dialog',
url: '#dialog',
template: '#tpl_dialog',
events: {
'#showDialog1': {
click: function (e) {
var $dialog = $('#dialog1');
$dialog.show();
$dialog.find('.weui_btn_dialog').on('click', function () {
$dialog.hide();
});
}
},
'#showDialog2': {
click: function (e) {
var $dialog = $('#dialog2');
$dialog.show();
$dialog.find('.weui_btn_dialog').on('click', function () {
$dialog.hide();
});
}
}
}
};
var progress = {
name: 'progress',
url: '#progress',
template: '#tpl_progress',
events: {
'#btnStartProgress': {
click: function () {
if (/#.*/gi.test(location.href)) {
go(location.hash.slice(1));
}
if ($(this).hasClass('weui_btn_disabled')) {
return;
}
// toast
$container.on('click', '#showToast', function () {
$('#toast').show();
setTimeout(function () {
$('#toast').hide();
}, 5000);
});
$container.on('click', '#showLoadingToast', function () {
$('#loadingToast').show();
setTimeout(function () {
$('#loadingToast').hide();
}, 5000);
});
$(this).addClass('weui_btn_disabled');
$container.on('click', '#showDialog1', function () {
$('#dialog1').show();
$('#dialog1').find('.weui_btn_dialog').on('click', function () {
$('#dialog1').hide();
});
});
$container.on('click', '#showDialog2', function () {
$('#dialog2').show();
$('#dialog2').find('.weui_btn_dialog').on('click', function () {
$('#dialog2').hide();
});
});
var progress = 0;
var $progress = $('.js_progress');
function hideActionSheet(weuiActionsheet, mask) {
weuiActionsheet.removeClass('weui_actionsheet_toggle');
mask.removeClass('weui_fade_toggle');
weuiActionsheet.on('transitionend', function () {
mask.hide();
}).on('webkitTransitionEnd', function () {
mask.hide();
})
}
$container.on('click','#showActionSheet', function () {
var mask = $('#mask');
var weuiActionsheet = $('#weui_actionsheet');
weuiActionsheet.addClass('weui_actionsheet_toggle');
mask.show().addClass('weui_fade_toggle').click(function () {
hideActionSheet(weuiActionsheet, mask);
});
$('#actionsheet_cancel').click(function () {
hideActionSheet(weuiActionsheet, mask);
});
weuiActionsheet.unbind('transitionend').unbind('webkitTransitionEnd');
});
function next() {
$progress.css({width: progress + '%'});
progress = ++progress % 100;
setTimeout(next, 30);
}
next();
}
}
}
};
var msg = {
name: 'msg',
url: '#msg',
template: '#tpl_msg',
events: {}
};
var article = {
name: 'article',
url: '#article',
template: '#tpl_article',
events: {}
};
var actionSheet = {
name: 'actionsheet',
url: '#actionsheet',
template: '#tpl_actionsheet',
events: {
'#showActionSheet': {
click: function () {
var mask = $('#mask');
var weuiActionsheet = $('#weui_actionsheet');
weuiActionsheet.addClass('weui_actionsheet_toggle');
mask.show().addClass('weui_fade_toggle').click(function () {
hideActionSheet(weuiActionsheet, mask);
});
$('#actionsheet_cancel').click(function () {
hideActionSheet(weuiActionsheet, mask);
});
weuiActionsheet.unbind('transitionend').unbind('webkitTransitionEnd');
function hideActionSheet(weuiActionsheet, mask) {
weuiActionsheet.removeClass('weui_actionsheet_toggle');
mask.removeClass('weui_fade_toggle');
weuiActionsheet.on('transitionend', function () {
mask.hide();
}).on('webkitTransitionEnd', function () {
mask.hide();
})
}
}
}
}
};
var icons = {
name: 'icons',
url: '#icons',
template: '#tpl_icons',
events: {}
};
pageManager.push(home)
.push(button)
.push(cell)
.push(toast)
.push(dialog)
.push(progress)
.push(msg)
.push(article)
.push(actionSheet)
.push(icons)
.default('home')
.init();
});

@@ -0,1 +1,4 @@

var path = require('path');
var fs = require('fs');
var yargs = require('yargs').argv;

@@ -5,3 +8,4 @@ var gulp = require('gulp');

var header = require('gulp-header');
var minify = require('gulp-minify-css');
var tap = require('gulp-tap');
var nano = require('gulp-cssnano');
var autoprefixer = require('gulp-autoprefixer');

@@ -17,3 +21,3 @@ var rename = require('gulp-rename');

gulp.task('source', function(){
gulp.src('src/example/**/*.!(less)', option)
gulp.src('src/example/**/*.!(less|html)', option)
.pipe(gulp.dest(dist))

@@ -30,6 +34,21 @@ .pipe(browserSync.reload({stream: true}));

.pipe(autoprefixer())
.pipe(minify())
.pipe(nano())
.pipe(gulp.dest(dist))
.pipe(browserSync.reload({stream: true}));
gulp.src('src/example/index.html', option)
.pipe(tap(function (file){
var dir = path.dirname(file.path);
var contents = file.contents.toString();
contents = contents.replace(/<link\s+rel="import"\s+href="(.*)">/gi, function (match, $1){
var filename = path.join(dir, $1);
var id = path.basename(filename, '.html');
var content = fs.readFileSync(filename, 'utf-8');
return '<script type="text/html" id="tpl_'+ id +'">\n'+ content +'\n</script>';
});
file.contents = new Buffer(contents);
}))
.pipe(gulp.dest(dist))
.pipe(browserSync.reload({stream: true}));
var banner = [

@@ -52,3 +71,3 @@ '/*!',

.pipe(gulp.dest(dist))
.pipe(minify())
.pipe(nano())
.pipe(rename(function (path) {

@@ -55,0 +74,0 @@ path.basename += '.min';

{
"name": "weui",
"version": "0.2.3",
"version": "0.3.0",
"description": "为微信 Web 服务量身设计",

@@ -34,10 +34,11 @@ "keywords": [

"gulp-autoprefixer": "^2.3.1",
"gulp-cssnano": "^2.0.0",
"gulp-header": "^1.7.1",
"gulp-less": "^3.0.2",
"gulp-minify-css": "^0.4.4",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-tap": "^0.1.3",
"yargs": "^1.3.3"
}
}

@@ -6,3 +6,3 @@ WeUI 为微信 Web 服务量身设计 ![](https://travis-ci.org/weui/weui.svg?branch=master)

WeUI是一套同微信原生视觉体验一致的基础样式库,由微信官方设计团队为微信 Web 开发量身设计,可以令用户的使用感知更加统一。包含`button`、`cell`、`dialog`、 `progress`、 `toast`、`article`、`icon`等各式元素。
WeUI是一套同微信原生视觉体验一致的基础样式库,由微信官方设计团队为微信 Web 开发量身设计,可以令用户的使用感知更加统一。包含`button`、`cell`、`dialog`、 `progress`、 `toast`、`article`、`actionsheet`、`icon`等各式元素。

@@ -47,3 +47,3 @@ ## 使用

npm install
gulp -ws
npm start
```

@@ -57,3 +57,3 @@ 运行`gulp -ws`命令,会监听`src`目录下所有文件的变更,并且默认会在`8080`端口启动服务器,然后在浏览器打开 `http://localhost:8080/example`。

![](./dist/example/snapshot/qrcode.png)
![](https://raw.githubusercontent.com/weui/weui/master/dist/example/snapshot/qrcode.png)

@@ -65,287 +65,14 @@ [http://weui.github.io/weui/](http://weui.github.io/weui)

- [lihongxun945/jquery-weui](http://lihongxun945.github.io/jquery-weui/components)
- [kevyu/weui-sass](https://github.com/kevyu/weui-sass)
- [Eric-Guo/weui-rails](https://github.com/Eric-Guo/weui-rails)(Using kevyu/weui-sass)
- [n7best/react-weui](https://github.com/n7best/react-weui)
- [aidenzou/vue-weui](https://github.com/aidenzou/vue-weui)
- [ZTfer/weui-sketch](https://github.com/ZTfer/weui-sketch)
- [i5ting/weui-practice](https://github.com/i5ting/weui-practice)
## Button
## 文档
按钮可以使用`a`或者`button`标签。wap上要触发按钮的active态,必须触发ontouchstart事件,可以在`body`上加上`ontouchstart=""`全局触发。
WeUI 说明文档参考 [Wiki](https://github.com/weui/weui/wiki)
按钮常见的操作场景:确定、取消、警示,分别对应class:`weui_btn_primary`、`weui_btn_default`、`weui_btn_warn`,每种场景都有自己的置灰态`weui_btn_disabled`,除此外还有一种镂空按钮`weui_btn_plain_xxx`,客户端webview里的按钮尺寸有两类,默认宽度100%,小型按钮宽度自适应,两边边框与文本间距0.75em:
![](./dist/example/snapshot/button.png)
```html
<a href="javascript:;" class="weui_btn weui_btn_primary">按钮</a>
<a href="javascript:;" class="weui_btn weui_btn_disabled weui_btn_primary">按钮</a>
<a href="javascript:;" class="weui_btn weui_btn_warn">确认</a>
<a href="javascript:;" class="weui_btn weui_btn_disabled weui_btn_warn">确认</a>
<a href="javascript:;" class="weui_btn weui_btn_default">按钮</a>
<a href="javascript:;" class="weui_btn weui_btn_disabled weui_btn_default">按钮</a>
<div class="button_sp_area">
<a href="javascript:;" class="weui_btn weui_btn_plain_default">按钮</a>
<a href="javascript:;" class="weui_btn weui_btn_plain_primary">按钮</a>
<a href="javascript:;" class="weui_btn weui_btn_mini weui_btn_primary">按钮</a>
<a href="javascript:;" class="weui_btn weui_btn_mini weui_btn_default">按钮</a>
</div>
```
## Cell
`Cell`,列表视图,用于将信息以列表的结构显示在页面上,是wap上最常用的内容结构。`Cell`由多个section组成,每个section包括section header`weui_cells_title`以及cells`weui_cells`。
`cell`由thumbnail`weui_cell_hd`、body`weui_cell_bd`、accessory`weui_cell_ft`三部分组成,`cell`采用自适应布局,在需要自适应的部分加上class`weui_cell_primary`即可:
![](./dist/example/snapshot/cell.png)
带说明的列表项
```html
<div class="weui_cells_title">带说明的列表项</div>
<div class="weui_cells">
<div class="weui_cell">
<div class="weui_cell_bd weui_cell_primary">
<p>标题文字</p>
</div>
<div class="weui_cell_ft">
说明文字
</div>
</div>
</div>
```
`Cell`可根据需要进行各种自定义扩展,包括辅助说明、跳转、单选、复选等。下面以带图标、说明、跳转的列表项,其他情况可以直接参考`example`下的代码:
```html
<div class="weui_cells_title">带图标、说明、跳转的列表项</div>
<div class="weui_cells weui_cells_access">
<a class="weui_cell" href="javascript:;">
<div class="weui_cell_hd">
<img src="" alt="icon" style="width:20px;margin-right:5px;display:block">
</div>
<div class="weui_cell_bd weui_cell_primary">
<p>cell standard</p>
</div>
<div class="weui_cell_ft">
说明文字
</div>
</a>
<a class="weui_cell" href="javascript:;">
<div class="weui_cell_hd">
<img src="" alt="icon" style="width:20px;margin-right:5px;display:block">
</div>
<div class="weui_cell_bd weui_cell_primary">
<p>cell standard</p>
</div>
<div class="weui_cell_ft">
说明文字
</div>
</a>
</div>
```
## Dialog
若系统的alert窗体无法满足网页的临时视图内容需求,则可以自定义实现与alert形式相似的dialog,并且在dialog中可以自定义地使用各种控件,来满足需求。
![](./dist/example/snapshot/dialog1.png)
```html
<div class="weui_dialog_confirm">
<div class="weui_mask"></div>
<div class="weui_dialog">
<div class="weui_dialog_hd"><strong class="weui_dialog_title">弹窗标题</strong></div>
<div class="weui_dialog_bd">自定义弹窗内容<br>...</div>
<div class="weui_dialog_ft">
<a href="javascript:;" class="weui_btn_dialog default">取消</a>
<a href="javascript:;" class="weui_btn_dialog primary">确定</a>
</div>
</div>
</div>
```
![](./dist/example/snapshot/dialog2.png)
```html
<div class="weui_dialog_alert">
<div class="weui_mask"></div>
<div class="weui_dialog">
<div class="weui_dialog_hd"><strong class="weui_dialog_title">弹窗标题</strong></div>
<div class="weui_dialog_bd">弹窗内容,告知当前页面信息等</div>
<div class="weui_dialog_ft">
<a href="javascript:;" class="weui_btn_dialog primary">确定</a>
</div>
</div>
</div>
```
## Progress
progress用于上传、下载等耗时并且需要显示进度的场景,用户可以随时中断该操作。
![](./dist/example/snapshot/progress.png)
```html
<div class="weui_progress">
<div class="weui_progress_bar">
<div class="weui_progress_inner_bar" style="width: 50%;"></div>
</div>
<a href="javascript:;" class="weui_progress_opr">
<i class="weui_icon_cancel"></i>
</a>
</div>
```
## Toast
toast用于临时显示某些信息,并且会在数秒后自动消失。这些信息通常是轻量级操作的成功、失败或等待状态信息。
![](./dist/example/snapshot/toast1.png)
```html
<div id="toast" style="display: none;">
<div class="weui_mask_transparent"></div>
<div class="weui_toast">
<i class="weui_icon_toast"></i>
<p class="weui_toast_content">已完成</p>
</div>
</div>
```
![](./dist/example/snapshot/toast2.png)
```html
<div id="loadingToast" class="weui_loading_toast" style="display:none;">
<div class="weui_mask_transparent"></div>
<div class="weui_toast">
<div class="weui_loading">
<!-- :) -->
<div class="weui_loading_leaf weui_loading_leaf_0"></div>
<div class="weui_loading_leaf weui_loading_leaf_1"></div>
<div class="weui_loading_leaf weui_loading_leaf_2"></div>
<div class="weui_loading_leaf weui_loading_leaf_3"></div>
<div class="weui_loading_leaf weui_loading_leaf_4"></div>
<div class="weui_loading_leaf weui_loading_leaf_5"></div>
<div class="weui_loading_leaf weui_loading_leaf_6"></div>
<div class="weui_loading_leaf weui_loading_leaf_7"></div>
<div class="weui_loading_leaf weui_loading_leaf_8"></div>
<div class="weui_loading_leaf weui_loading_leaf_9"></div>
<div class="weui_loading_leaf weui_loading_leaf_10"></div>
<div class="weui_loading_leaf weui_loading_leaf_11"></div>
</div>
<p class="weui_toast_content">数据加载中</p>
</div>
</div>
```
## Msg Page
结果页通常来说可以认为进行一系列操作步骤后,作为流程结束的总结性页面。结果页的作用主要是告知用户操作处理结果以及必要的相关细节(可用于确认之前的操作是否有误)等信息;若该流程用于开启或关闭某些重要功能,可在结果页增加与该功能相关的描述性内容;除此之外,结果页也可以承载一些附加价值操作,例如提供抽奖、关注公众号等功能入口。
![](./dist/example/snapshot/result.png)
```html
<div class="weui_msg">
<div class="weui_icon_area"><i class="weui_icon_success weui_icon_msg"></i></div>
<div class="weui_text_area">
<h2 class="weui_msg_title">操作成功</h2>
<p class="weui_msg_desc">内容详情,可根据实际需要安排</p>
</div>
<div class="weui_opr_area">
<p class="weui_btn_area">
<a href="javascript:;" class="weui_btn weui_btn_primary">确定</a>
<a href="javascript:;" class="weui_btn weui_btn_default">取消</a>
</p>
</div>
<div class="weui_extra_area">
<a href="">查看详情</a>
</div>
</div>
```
## Article
文字视图显示大段文字,这些文字通常是页面上的主体内容。`Article`支持分段、多层标题、引用、内嵌图片、有/无序列表等富文本样式,并可响应用户的选择操作。
在微信客户端webview中使用`Article`,必须保证文字有足够的可读性和可辨识性、使用规范字体、保证足够的段间距、段首无缩进。
![](./dist/example/snapshot/text.png)
```html
<article class="weui_article">
<h1>大标题</h1>
<section>
<h2 class="title">章标题</h2>
<section>
<h3>1.1 节标题</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
consequat. Duis aute</p>
</section>
<section>
<h3>1.2 节标题</h3>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non
proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
</section>
</article>
```
## ActionSheet
`ActionSheet`用于显示包含一系列可交互的动作集合,包括说明、跳转等。由底部弹出,一般用于响应用户对页面的点击。
![](./dist/example/snapshot/actionSheet.png)
```html
<div id="actionSheet_wrap">
<div class="weui_mask_transition" id="mask"></div>
<div class="weui_actionsheet" id="weui_actionsheet">
<div class="weui_actionsheet_menu">
<div class="weui_actionsheet_cell">示例菜单</div>
<div class="weui_actionsheet_cell">示例菜单</div>
<div class="weui_actionsheet_cell">示例菜单</div>
<div class="weui_actionsheet_cell">示例菜单</div>
</div>
<div class="weui_actionsheet_action">
<div class="weui_actionsheet_cell" id="actionsheet_cancel">取消</div>
</div>
</div>
</div>
```
## Icon
![](./dist/example/snapshot/icons.png)
```html
<i class="weui_icon_msg weui_icon_success"></i>
<i class="weui_icon_msg weui_icon_info"></i>
<i class="weui_icon_msg weui_icon_warn"></i>
<i class="weui_icon_msg weui_icon_waiting"></i>
<i class="weui_icon_safe weui_icon_safe_success"></i>
<i class="weui_icon_safe weui_icon_safe_warn"></i>
<div class="icon_sp_area">
<i class="weui_icon_success"></i>
<i class="weui_icon_success_circle"></i>
<i class="weui_icon_success_no_circle"></i>
<i class="weui_icon_info"></i>
<i class="weui_icon_waiting"></i>
<i class="weui_icon_waiting_circle"></i>
<i class="weui_icon_circle"></i>
<i class="weui_icon_warn"></i>
<i class="weui_icon_download"></i>
<i class="weui_icon_info_circle"></i>
<i class="weui_icon_cancel"></i>
</div>
```
## TODO
- 更多的组件
- react-weui
## License

@@ -352,0 +79,0 @@ The MIT License(http://opensource.org/licenses/MIT)

/**
* Created by jfengjiang on 2015/9/11.
* Created by jf on 2015/9/11.
*/
$(function () {
// page stack
var stack = [];
var $container = $('.js_container');
$container.on('click', '.js_cell[data-id]', function () {
var id = $(this).data('id');
go(id);
});
// location.hash = '#hash1' 和点击后退都会触发`hashchange`,这个demo页面只关心后退
$(window).on('hashchange', function (e) {
if (/#.+/gi.test(e.newURL)) {
return;
var pageManager = {
$container: $('.js_container'),
_pageStack: [],
_configs: [],
_defaultPage: null,
_isGo: false,
default: function (defaultPage) {
this._defaultPage = defaultPage;
return this;
},
init: function () {
var self = this;
$(window).on('hashchange', function (e) {
var _isBack = !self._isGo;
self._isGo = false;
if (!_isBack) {
return;
}
var url = location.hash.indexOf('#') === 0 ? location.hash : '#';
var found = null;
for(var i = 0, len = self._pageStack.length; i < len; i++){
var stack = self._pageStack[i];
if (stack.config.url === url) {
found = stack;
break;
}
}
if (found) {
self.back();
}
else {
goDefault();
}
});
function goDefault(){
var url = location.hash.indexOf('#') === 0 ? location.hash : '#';
var page = self._find('url', url) || self._find('name', self._defaultPage);
self.go(page.name);
}
goDefault();
return this;
},
push: function (config) {
this._configs.push(config);
return this;
},
go: function (to) {
var config = this._find('name', to);
if (!config) {
return;
}
var html = $(config.template).html();
var $html = $(html).addClass('slideIn').addClass(config.name);
this.$container.append($html);
this._pageStack.push({
config: config,
dom: $html
});
this._isGo = true;
location.hash = config.url;
if (!config.isBind) {
this._bind(config);
}
return this;
},
back: function () {
var stack = this._pageStack.pop();
if (!stack) {
return;
}
stack.dom.addClass('slideOut').on('animationend', function () {
stack.dom.remove();
}).on('webkitAnimationEnd', function () {
stack.dom.remove();
});
return this;
},
_find: function (key, value) {
var page = null;
for (var i = 0, len = this._configs.length; i < len; i++) {
if (this._configs[i][key] === value) {
page = this._configs[i];
break;
}
}
return page;
},
_bind: function (page) {
var events = page.events || {};
for (var t in events) {
for (var type in events[t]) {
this.$container.on(type, t, events[t][type]);
}
}
page.isBind = true;
}
var $top = stack.pop();
if (!$top) {
return;
};
var home = {
name: 'home',
url: '#',
template: '#tpl_home',
events: {
'.js_grid': {
click: function (e) {
var id = $(this).data('id');
pageManager.go(id);
}
}
}
$top.addClass('slideOut').on('animationend', function () {
$top.remove();
}).on('webkitAnimationEnd', function () {
$top.remove();
});
});
};
var button = {
name: 'button',
url: '#button',
template: '#tpl_button'
};
var cell = {
name: 'cell',
url: '#cell',
template: '#tpl_cell',
events: {
'#showTooltips': {
click: function () {
var $tooltips = $('.js_tooltips');
if ($tooltips.css('display') != 'none') {
return;
}
function go(id){
var $tpl = $($('#tpl_' + id).html()).addClass('slideIn').addClass(id);
$container.append($tpl);
stack.push($tpl);
// why not use `history.pushState`, https://github.com/weui/weui/issues/26
//history.pushState({id: id}, '', '#' + id);
location.hash = '#' + id;
// 如果有`animation`, `position: fixed`不生效
$('.page.cell').removeClass('slideIn');
$tooltips.show();
setTimeout(function () {
$tooltips.hide();
}, 2000);
}
}
}
};
var toast = {
name: 'toast',
url: '#toast',
template: '#tpl_toast',
events: {
'#showToast': {
click: function (e) {
var $toast = $('#toast');
if ($toast.css('display') != 'none') {
return;
}
$($tpl).on('webkitAnimationEnd', function (){
$(this).removeClass('slideIn');
}).on('animationend', function (){
$(this).removeClass('slideIn');
});
// tooltips
if (id == 'cell') {
$('.js_tooltips').show();
setTimeout(function (){
$('.js_tooltips').hide();
}, 3000);
$toast.show();
setTimeout(function () {
$toast.hide();
}, 2000);
}
},
'#showLoadingToast': {
click: function (e) {
var $loadingToast = $('#loadingToast');
if ($loadingToast.css('display') != 'none') {
return;
}
$loadingToast.show();
setTimeout(function () {
$loadingToast.hide();
}, 2000);
}
}
}
}
};
var dialog = {
name: 'dialog',
url: '#dialog',
template: '#tpl_dialog',
events: {
'#showDialog1': {
click: function (e) {
var $dialog = $('#dialog1');
$dialog.show();
$dialog.find('.weui_btn_dialog').on('click', function () {
$dialog.hide();
});
}
},
'#showDialog2': {
click: function (e) {
var $dialog = $('#dialog2');
$dialog.show();
$dialog.find('.weui_btn_dialog').on('click', function () {
$dialog.hide();
});
}
}
}
};
var progress = {
name: 'progress',
url: '#progress',
template: '#tpl_progress',
events: {
'#btnStartProgress': {
click: function () {
if (/#.*/gi.test(location.href)) {
go(location.hash.slice(1));
}
if ($(this).hasClass('weui_btn_disabled')) {
return;
}
// toast
$container.on('click', '#showToast', function () {
$('#toast').show();
setTimeout(function () {
$('#toast').hide();
}, 5000);
});
$container.on('click', '#showLoadingToast', function () {
$('#loadingToast').show();
setTimeout(function () {
$('#loadingToast').hide();
}, 5000);
});
$(this).addClass('weui_btn_disabled');
$container.on('click', '#showDialog1', function () {
$('#dialog1').show();
$('#dialog1').find('.weui_btn_dialog').on('click', function () {
$('#dialog1').hide();
});
});
$container.on('click', '#showDialog2', function () {
$('#dialog2').show();
$('#dialog2').find('.weui_btn_dialog').on('click', function () {
$('#dialog2').hide();
});
});
var progress = 0;
var $progress = $('.js_progress');
function hideActionSheet(weuiActionsheet, mask) {
weuiActionsheet.removeClass('weui_actionsheet_toggle');
mask.removeClass('weui_fade_toggle');
weuiActionsheet.on('transitionend', function () {
mask.hide();
}).on('webkitTransitionEnd', function () {
mask.hide();
})
}
$container.on('click','#showActionSheet', function () {
var mask = $('#mask');
var weuiActionsheet = $('#weui_actionsheet');
weuiActionsheet.addClass('weui_actionsheet_toggle');
mask.show().addClass('weui_fade_toggle').click(function () {
hideActionSheet(weuiActionsheet, mask);
});
$('#actionsheet_cancel').click(function () {
hideActionSheet(weuiActionsheet, mask);
});
weuiActionsheet.unbind('transitionend').unbind('webkitTransitionEnd');
});
function next() {
$progress.css({width: progress + '%'});
progress = ++progress % 100;
setTimeout(next, 30);
}
next();
}
}
}
};
var msg = {
name: 'msg',
url: '#msg',
template: '#tpl_msg',
events: {}
};
var article = {
name: 'article',
url: '#article',
template: '#tpl_article',
events: {}
};
var actionSheet = {
name: 'actionsheet',
url: '#actionsheet',
template: '#tpl_actionsheet',
events: {
'#showActionSheet': {
click: function () {
var mask = $('#mask');
var weuiActionsheet = $('#weui_actionsheet');
weuiActionsheet.addClass('weui_actionsheet_toggle');
mask.show().addClass('weui_fade_toggle').click(function () {
hideActionSheet(weuiActionsheet, mask);
});
$('#actionsheet_cancel').click(function () {
hideActionSheet(weuiActionsheet, mask);
});
weuiActionsheet.unbind('transitionend').unbind('webkitTransitionEnd');
function hideActionSheet(weuiActionsheet, mask) {
weuiActionsheet.removeClass('weui_actionsheet_toggle');
mask.removeClass('weui_fade_toggle');
weuiActionsheet.on('transitionend', function () {
mask.hide();
}).on('webkitTransitionEnd', function () {
mask.hide();
})
}
}
}
}
};
var icons = {
name: 'icons',
url: '#icons',
template: '#tpl_icons',
events: {}
};
pageManager.push(home)
.push(button)
.push(cell)
.push(toast)
.push(dialog)
.push(progress)
.push(msg)
.push(article)
.push(actionSheet)
.push(icons)
.default('home')
.init();
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc