/
cuba.html
150 lines (111 loc) · 3.69 KB
/
cuba.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>cuba.js micro JavaScript Framework</title>
<style type="text/css">
pre, code {
padding: 5px 10px;
margin-bottom: 20px;
overflow: auto;
font-family: courier;
background: ghostwhite;
border: 1px solid #ddd;
}
code {
padding: 2px 5px;
}
pre code {
padding: 0;
margin-bottom: 0;
border: 0;
}
#out {
font-weight: bold
}
#sandbox .box {
border: 1px solid #ccc;
width: 100px;
height: 100px;
transition: margin-left 2s;
-moz-transition: margin-left 2s;
-webkit-transition: margin-left 2s;
}
</style>
<script type="text/javascript" src="src/cuba.js"></script>
<script type="text/javascript">
var $ = function(id) { return cuba.grab( id ) }
//if dom is ready go ahead!!!
cuba.ready(function() {
//select an element and added a handler on event 'click'
cuba.select("#btn").on('click', function(){
cuba.select('#out').toggleClass('myClass')
alert('is clicked')
})
//added label
cuba.select("#btn").html("Click Me")
//select an element, then called the methods: html and css
cuba.select("#out")
.html("Jean Baptiste Poquelin")
.css("width: 100px; height: 100px;border: 1px solid #ccc;background: #393;color: #fff")
//make an YQL request
cuba.yql("select title from rss where url=\"http://rss.news.yahoo.com/rss/topstories\"", function( data ) {
if(window.console) console.log( data )
})
//cuba.addClass($('out'),'myClass')
//OR
cuba.select('#out').addClass('myClass')
$('move').Click( function( event ){
cuba.stopPropagation( event )
cuba.select('#sandbox .box').css('margin-left:100px')
} )
$('moveback').Click( function( event ){
cuba.stopPropagation( event )
cuba.select('#sandbox .box').css('margin-left:0px')
} )
})
</script>
</head>
<body>
<h1>cuba.js micro JavaScript Framework</h1>
<button id="btn"></button>
<div id="out"></div>
<div id="sandbox">
<div class="box"></div>
</div>
<a href="#" id="move">move</a>
<a href="#" id="moveback">move back</a>
<h2>How it works</h3>
<pre><code>
cuba.ready(function() {
//select an element and added a handler on event 'click'
cuba.select("#btn").on('click', function(){
cuba.select('#out').toggleClass('myClass')
alert('clicked')
})
//added label
cuba.select("#btn").html("Click Me")
//select an element, then called the methods: html and css
cuba.select("#out")
.html("Jean Baptiste Poquelin")
.css("width: 100px; height: 100px;border: 1px solid #ccc;background: #393;color: #fff")
//make an YQL request
cuba.yql("select title from rss where url=\"http://rss.news.yahoo.com/rss/topstories\"", function( data ) {
if(window.console) console.log( data )
})
//cuba.addClass($('out'),'myClass')
//OR
cuba.select('#out').addClass('myClass')
//using CSS3 transitions
$('move').Click( function( event ){
cuba.stopPropagation( event )
cuba.select('#sandbox .box').css('margin-left:100px')
} )
$('moveback').Click( function( event ){
cuba.stopPropagation( event )
cuba.select('#sandbox .box').css('margin-left:0px')
} )
})
</code></pre>
</body>
</html>