/
index.haml
160 lines (125 loc) · 4.71 KB
/
index.haml
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
!!! 5
%html(lang='en')
%head
%meta(http-equiv='content-type' content='text/html;charset=utf-8')/
%title jQuery-typing
- version = '0.2.0'
- version_h1 = 'v0.2'
%link(rel='stylesheet' href='style.css' type='text/css')
-#-----------
-# scripts
-#-----------
%script(src='jquery-1.4.2.min.js' type='text/javascript')
%script(src='jquery.typing-#{version}.min.js' type='text/javascript')
:javascript
$(function () {
// focus on first input if user can see it without scrolling
var $input = $(':text').first();
if ($input.offset().top + $input.height() < $(window).height()) {
$input.focus();
}
// assign typing handlers
$('tbody tr').each(function (i, tr) {
var $tr = $(tr),
$input = $tr.find(':input'),
delay = $tr.find('.delay').text(),
$inProgress = $tr.find('.in-progress'),
$dot = $('<span class="bright">●</span>');
$inProgress.empty();
$dot.appendTo($inProgress);
$input.typing({
start: function () {$dot.removeClass('bright')},
stop: function () {$dot.addClass('bright')},
delay: delay
});
});
});
%body
-#--------------------
-# Google Analytics
-#--------------------
:javascript
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-8752416-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
})();
-#-----------------
-# GitHub ribbon
-#-----------------
<a href="http://github.com/narfdotpl/jquery-typing"><img style="position: absolute; top: 0; right: 0; border: 0;" src="http://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub" /></a>
-#-----------
-# content
-#-----------
#content
%h1
jQuery-typing
%span.version #{version_h1}
%p Assign callbacks for started/stopped typing events.
%h2 Usage
:markdown
$(':text').typing({
start: function (event, $elem) {
$elem.css('background', '#fa0');
},
stop: function (event, $elem) {
$elem.css('background', '#f00');
},
delay: 400
});
`typing` command takes key-value object with `start`, `stop` and
`delay` keys. They are all optional, so you can either pass only
`start` callback, `stop` callback, `stop` callback and `delay` time,
or everything.
`delay` is amount of time the plugin waits for another keypress before
judging that typing has stopped; it is expressed in milliseconds and
defaults to 400. Regardless of `delay`'s value, the `stop` callback is
called immediately when blur event occurs.
Callbacks are passed two arguments: event that caused callback
execution and jQuery object for matched element. Possible events are
`keypress` or `keydown` for `start` callbacks and `keyup` or `blur`
for `stop` callbacks.
%h2 Demo
%table
%thead
%tr
%th type
%th.wide element
%th.wide typing in progress
%th delay [ms]
%tbody
%tr
%td text
%td
%input(type='text')
%td.in-progress JavaScript disabled
%td.delay 400
%tr
%td text
%td
%input(type='text')
%td.in-progress JavaScript disabled
%td.delay 1000
%tr
%td textarea
%td
%textarea(rows='3')
%td.in-progress JavaScript disabled
%td.delay 0
%h2 Download
:markdown
Get production version from<br />
<http://narf.pl/jquery-typing/jquery.typing-#{version}.min.js>
For development version visit [GitHub][].
[GitHub]: http://github.com/narfdotpl/jquery-typing
%h2 Meta
:markdown
jQuery-typing is written by [Maciej Konieczny][]. This software is
released into the [public domain][] and uses [semantic versioning][]
for release numbering.
[Maciej Konieczny]: http://narf.pl/
[public domain]: http://unlicense.org/
[semantic versioning]: http://semver.org/