-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.html
166 lines (151 loc) · 5.07 KB
/
demo.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<!doctype>
<html>
<head>
<title>pluie.org - svan demo - v0.4</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body { background-color:#888; color:white; font-family:arial; font-size:1.3rem; }
#test { border: 1px dashed #ccc; }
body > div { border-radius:20px; margin:40px; padding:20px; background-color: #ccc; color:black; }
body > span { font-size:0.8rem; }
button { padding:5px 15px; }
h3 { margin:35px 0 10px 0; }
h2 { margin:5px 0 0 0; }
textarea { padding:8px 5px; border-radius:10px; border-style:solid; width:100%; height:120px; font-size:1.2rem; }
#test { margin:20px; background-color:white; padding:20px; border: 1px dashed #aaa; }
.cssAdded { color:#990000; }
#output { margin-top:250px; }
</style>
</head>
<body>
<h2>pluie.org - svan demo : </h2>
<div style="border:1px dashed #ccc; position:fixed; width:90%; ">
<button id="click">click</button>
<button id="addClass">addClass</button>
<button id="removeClass">removeClass</button>
<button id="toggle">toggle</button>
<button id="fade">fade</button>
<button id="find">$('div').find('button')</button>
<button id="ajax">ajax</button>
</div>
<div style="border:1px dashed #ccc; position:fixed; width:90%; top:150px;">
<select id="selnode">
<option value="0">value : 0</option>
<option value="1">value : 1</option>
<option value="2">value : 2</option>
</select>
<button id="attrget">attr getselect</button>
<button id="attrset">attr set select to 1 </button>
</div>
<div id="output"></div>
<script type="text/javascript" src="src/svan-min.js"></script>
<script type="text/javascript">
var $l = (function alias() {
var a = localStorage;
return {
clear : function() { return a.clear(); },
get : function(k) { return a.getItem(k); },
rem : function(k) { return a.removeItem(k); },
set : function(k, v) { return a.setItem(k, v); }
};
}());
var $j = (function alias() {
var a = JSON;
return {
str : function(o) { return a.stringify(o); },
obj : function(s) { return a.parse(s); }
};
}());
$(document).ready(function() {
var sep = "<br/>----------------";
var o = function(msg, c) {
msg += '<br/>';
$('#output').append(msg);
if (c) console.log(msg.replace(/\<br\/\>/g, '\n'));
}
o('on dom ready event<br/>', 1);
$('#click').on('click', function(e) {
o(sep);
o('click click event<br/>context : #'+this.id);
console.log(e);
console.log(this);
});
$('#addClass').on('click', function(e) {
o(sep);
o('addClass click event<br/>context : #'+this.id+'<br/>css before : '+this.className);
$(this).addClass('cssAdded');
o('css after : '+this.className);
});
$('#removeClass').on('click', function(e) {
o(sep);
var n = $('#addClass').first();
o('removeClass event<br/>context : #'+this.id+'<br/>css before : '+n.className);
$(n).removeClass('cssAdded');
o('css after : '+n.className);
});
$('#toggle').on('click', function(e) {
o(sep);
var n = $('#addClass').first();
o('toogle event<br/>context : #'+this.id+'<br/>css before : '+n.className);
$(n).toggle('cssAdded');
o('css after : '+n.className);
});
$('#attrset').on('click', function(e) {
o(sep);
$('#selnode').val(1);
o('set selectedIndex to 1');
});
$('#attrget').on('click', function(e) {
o(sep);
o('get selected value : '+($('#selnode').val()));
});
$('#find').on('click', function(e) {
o(sep);
o("find $('div').find('button')");
$('div').find('button').all().forEach(function(n) {
o(n.getAttribute('id'));
});
});
$('#fade').on('click', function(e) {
o(sep);
o('fade click event<br/>context : #'+this.id);
$('#output').fadeOut(600, function() {
o('end fade out');
$(this).fadeIn(1600, function() {
o('end fadeIn');
});
});
});
$('#ajax').on('click', function(e) {
o(sep);
o('ajax click event');
$.ajax({
url : 'http://domain.dev/ajax-done',
async : true,
data : { toto : "tata" },
done : function(data) {
o('ajax done receiving data<br/>' + $j.str(data) +'<br/>');
o($j.str(xhr));
},
always : function(data) {
o('ajax always<br/>');
},
method : 'POST'
});
$.ajax({
url : 'http://domain.dev/ajax-fail',
async : false,
fail : function(data, xhr) {
o('ajax fail receiving data<br/>' + $j.str(data) +'<br/>');
o($j.str(xhr));
},
always : function(data) {
o('ajax always<br/>');
},
method : 'GET'
});
});
});
</script>
</body>
</html>