Skip to content

Commit 3aa1660

Browse files
committed
widget类 设计统一生命周期(二)
1 parent efdcdbb commit 3aa1660

File tree

9 files changed

+370
-0
lines changed

9 files changed

+370
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,
2+
form,fieldset,input,textarea,p,blockquote,th,td {
3+
padding: 0;
4+
margin: 0;
5+
}
6+
table {
7+
border-collapse: collapse;
8+
border-spacing: 0;
9+
}
10+
fieldset,img {
11+
border: 0;
12+
}
13+
address,caption,cite,code,dfn,em,strong,th,var {
14+
font-weight: normal;
15+
font-style: normal;
16+
}
17+
ol,ul {
18+
list-style: none;
19+
}
20+
caption,th {
21+
text-align: left;
22+
}
23+
h1,h2,h3,h4,h5,h6 {
24+
font-weight: normal;
25+
font-size: 100%;
26+
}
27+
q:before,q:after {
28+
content:'';
29+
}
30+
abbr,acronym { border: 0;
31+
}
32+
html body{
33+
height: 100%;
34+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
.btn{
2+
text-decoration: none;
3+
padding:5px 10px;
4+
width: 50px;
5+
text-align: center;
6+
display: block;
7+
margin: 100px;
8+
background: #ddd;
9+
}
10+
11+
.window_boundingBox{
12+
position: fixed;
13+
border: 1px solid #ddd;
14+
width: 500px;
15+
height: 300px;
16+
left: 50%;
17+
margin-left: -250px;
18+
top:100px;
19+
box-shadow: 0 0 12px #888;
20+
background: #fff;
21+
}
22+
23+
.window_mask{
24+
width: 100%;
25+
height: 100%;
26+
background: #000;
27+
opacity: .3;
28+
position: absolute;
29+
left: 0;
30+
top: 0;
31+
}
32+
33+
.window_alertBtn{
34+
width: 100px;
35+
position: absolute;
36+
bottom: 10px;
37+
left: 50%;
38+
margin-left: -50px;
39+
}
40+
41+
.window_header{
42+
background: #999;
43+
color: #fff;
44+
text-align: center;
45+
padding: 5px;
46+
font-size: 20px;
47+
}
48+
49+
.window_body{
50+
padding: 10px;
51+
}
52+
53+
.window_closeBtn{
54+
position: absolute;
55+
right: 0;
56+
top: 0;
57+
font-size: 20px;
58+
color: #fff;
59+
background: red;
60+
cursor: pointer;
61+
padding: 5px;
62+
}
63+
64+
/*skin for window_skin_a*/
65+
.window_skin_a.window_boudingBox{
66+
box-shadow: none;
67+
border: 5px solid #ddc;
68+
border-radius: 5px;
69+
}
70+
71+
.window_skin_a .window_alertBtn{
72+
width: 50px;
73+
left: auto;
74+
right: 20px;
75+
margin-left: 0;
76+
background:red;
77+
border: none;
78+
color: #fff;
79+
padding: 10px;
80+
}
81+
82+
.window_skin_a .window_header{
83+
background: red;
84+
text-align: left;
85+
padding: 10px;
86+
font-weight: bold;
87+
}
88+
89+
.window_skin_a .window_closeBtn{
90+
width: 45px;
91+
height: 45px;
92+
border-radius: 45px;
93+
line-height: 45px;
94+
padding: 0;
95+
text-align: center;
96+
background: blue;
97+
font-size: 24px;
98+
font-weight: bold;
99+
right: -15px;
100+
top: -15px;
101+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Widget抽象类(二)</title>
6+
<link type="text/css" rel="stylesheet" href="css/base.css">
7+
<link type="text/css" rel="stylesheet" href="css/window.css">
8+
</head>
9+
10+
<body>
11+
<a href="#" class="btn">弹窗</a>
12+
<script type="text/javascript" data-main="js/main" src="js/require.js"></script>
13+
</body>
14+
</html>

15.2 widget类 设计统一生命周期(二)/js/jquery-2.1.1.min.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

15.2 widget类 设计统一生命周期(二)/js/jquery-ui.min.js

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
require.config({
2+
paths:{
3+
jquery:'jquery-2.1.1.min',
4+
jqueryUI:'jquery-ui.min'
5+
}
6+
});
7+
8+
require(['jquery','window'],function($,w){
9+
$('.btn').click(function(){
10+
var win = new w.Window().alert({
11+
title:'提示',
12+
content:'Welcome!!!',
13+
width:300,
14+
height:150,
15+
y:250,
16+
x:600,
17+
hasCloseBtn:true,
18+
text4AlertBtn:'OK',
19+
dragHandle:'.window_header',
20+
skinClassName:'window_skin_a',
21+
// handler4AlertBtn:function(){
22+
// alert('你点击了确定按钮');
23+
// },
24+
// handler4CloseBtn:function(){
25+
// alert('你点击了关闭按钮');
26+
// }
27+
}).on('alert',function(){
28+
alert('你点击了确定按钮')
29+
}).on('alert',function(){
30+
alert('确定按钮第二次回调')
31+
}).on('alert',function(){
32+
alert('确定按钮第三次回调')
33+
}).on('close',function(){
34+
alert('第一次点击了关闭按钮')
35+
}).on('close',function(){
36+
alert('关闭按钮第二次回调')
37+
});
38+
});
39+
});

15.2 widget类 设计统一生命周期(二)/js/require.js

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
define(['jquery'],function($){
2+
function Widget(){
3+
this.boudingBox = null; //属性:最外层容器
4+
}
5+
Widget.prototype={
6+
on:function(type,handler){
7+
if (typeof this.handlers[type]=='undefined') {
8+
this.handlers[type]=[];
9+
}
10+
this.handlers[type].push(handler);
11+
return this;
12+
},
13+
fire:function(type,data){
14+
if (this.handlers[type] instanceof Array) {
15+
var handlers = this.handlers[type];
16+
for(var i=0,len=handlers.length;i<len;i++){
17+
handlers[i](data);
18+
}
19+
};
20+
},
21+
render:function(container){ //方法:渲染组件
22+
this.renderUI();
23+
this.handlers={};
24+
this.bindUI();
25+
this.syncUI();
26+
$(container||document.body).append(this.boudingBox);
27+
},
28+
destroy:function(){ //方法:渲染组件
29+
this.destructor();
30+
this.boudingBox.off();
31+
this.boudingBox.remove();
32+
},
33+
renderUI:function(){}, //接口:添加dom节点
34+
bindUI:function(){}, //接口:监听事件
35+
syncUI:function(){}, //接口:初始化组件属性
36+
destructor:function(){} //接口:销毁前的处理函数
37+
}
38+
return{
39+
Widget:Widget
40+
}
41+
})

0 commit comments

Comments
 (0)