-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
74 lines (72 loc) · 2.84 KB
/
example.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
<!doctype html>
<html>
<head>
<style>
body { font: 14pt Helvetica, Arial, sans-serif; color: #696969; }
h1,h2,h3,h4 { color: #000; }
input{ font-size: 120%; }
textarea{ font-size: 90%; width: 300px; height: 100px; }
#comment-preview { width: 300px; font: 13pt "Courier New", monospace;
border: 1px dashed #ccc; margin: 0 0 10px; }
#comment-preview.submitted { border: 1px solid green; }
</style>
</head>
<body>
<h1>Comments</h1>
<div id="comment">
<div id="comment-preview"></div>
<form>
<textarea name="comment-body" style="display:block"></textarea>
<input type="submit" name="comment-submit" value="Comment">
<input type="submit" value="Erase" name="comment-erase">
</form>
</div>
</body>
</html>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="drop.js"></script>
<script type="text/javascript">
// playtime! create a view based on jQuery selector
// We provide a jQuery selector which will define the view's primary
// container. As the optional second argument we also provide an
// object with some controls.
var cmtview = drop.view().init('#comment', {
submitbtn: { // this will create a new control for this view
selector: 'input[name=comment-submit]', // selector for the control
// this control will also have a method
disable: function(){ this._elmt.attr('disabled', true); }
},
preview: {
selector: '#comment-preview',
contents: function(text) {
this._elmt.text(text);
},
mark: function() { this._elmt.addClass('submitted'); }
}
});
// we can also add a control after the fact
cmtview.control('body', {
selector: 'textarea[name=comment-body]',
text: function(){ return this._elmt.val(); }
});
// now create a new controller
var cmtco = drop.co().init({
init: function() { // controllers can have constructors
// inits a new view and adds it to this namespace
this.addView('view', cmtview);
// bind the controller methods to controls
this.view.submitbtn.bind('click', this.submit);
this.view.body.bind('keyup', this.preview);
},
submit: function(e){
e.preventDefault();
console.log(e);
this.view.submitbtn.disable(); // call method on the control
this.view.preview.mark();
},
preview: function(e) {
this.view.preview.contents(this.view.body.text());
},
reset: function(){ }
});
</script>