-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.html
491 lines (469 loc) · 19.5 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Demo for In Place Edit</title>
<script src="https://github.com/douglascrockford/JSON-js/raw/master/json2.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css" />
<script src="https://raw.github.com/bsimpson/in_place_edit/master/src/in_place_edit.js"></script>
<script src="in_place_edit.js"></script>
<script>
$(function() {
$('.demo_form').bind('submit', function(evt) {
evt.preventDefault();
alert('Form has been submitted');
});
// Autocomplete for demo
$('.autocomplete').autocomplete({ source:
[
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
]
});
$('.in_place_edit').inPlaceEdit();
});
</script>
<style>
.red_background {
background-color: #FFCCCC;
}
body {
margin: 0px auto;
width: 900px;
padding: 10px;
}
.hint {
font-style: italic;
color: #333;
}
dl {
padding-left: 5px;
}
dt, dd {
display: inline;
}
#demo_1, #demo_2, #demo_3 {
margin: 10px 0;
border: 1px solid #ccc;
padding: 10px;
}
</style>
</head>
<body>
<h1>In Place Edit Demo</h1>
<p>
Why another in place edit library? This was born out of a need for extremely specific interactions that varied in different parts of the application. There was no way a blanket set of logic would match every interaction the client wanted.
</p>
<p>
This library is built with customization in mind. When you define your in place edit form, you can pass one or more options to the data-in-place-edit attribute to get the desired effect. The actions are specific and let you choose exactly how you want each form to operate.
</p>
<pre>
$(function() {
$('.in_place_edit').inPlaceEdit();
});
</pre>
<pre>
<div class="in_place_edit" data-in-place-data="submitOnBlur">
<form action="#" method="post">
<input name="foo" value="foo" />
</form>
</div>
</pre>
<p>
We wrap our form inside of a container named in_place_edit. This is the CSS selector we pass to jQuery when we call $.inPlaceEdit(). Options are placed inside of data-in-place-data on the same object (or via an object passed to the jQuery plugin). These options are then wired up to the form via UJS.
</p>
<p>
Some actions require further options to be specified, as is the case with 'Add class on focus'. In this action, we need to specify a value for the class to be added by supplying the data-add-class-on-focus attribute.
</p>
<pre>
<div class="in_place_edit" data-in-place-data="addClassOnFocus" data-add-class-on-focus="red_background">
<form action="#" method="post">
<input name="foo" value="foo" />
</form>
</div>
</pre>
<h1>Options</h1>
<p>
Below is an index of available options. Click a link to see a demo of that option. Further examples are at the bottom.
</p>
<h2>Index</h3>
<h3>Submit control</h3>
<ul>
<li><a href="#submit_on_blur_one">Submit on blur (one field)</a></li>
<li><a href="#submit_on_blur">Submit on blur (multiple fields)</a></li>
<li><a href="#submit_on_click">Submit on click</a></li>
<li><a href="#submit_on_enter">Submit on enter</a></li>
<li><a href="#submit_on_autocomplete_select">Submit on autocomplete select</a></li>
</ul>
<h3>Class manipulation</h3>
<ul>
<li><a href="#add_class_on_focus">Add class on focus</a></li>
<li><a href="#remove_class_on_focus">Remove class on focus</a></li>
<li><a href="#add_class_on_blur">Add class on blur</a></li>
<li><a href="#remove_class_on_blur">Remove class on blur</a></li>
<li><a href="#add_class_on_submit">Add class on submit</a></li>
</ul>
<h3>Label manipulation</h3>
<ul>
<li><a href="#show_form_on_click">Show form on click</a></li>
<li><a href="#hide_label_on_click">Hide label on click</a></li>
<li><a href="#show_label_on_blur">Show label on blur</a></li>
<li><a href="#hide_form_on_blur">Hide form on blur</a></li>
<li><a href="#show_label_on_enter">Show label on enter</a></li>
<li><a href="#hide_form_on_enter">Hide form on enter</a></li>
<li><a href="#focus_respective_inputs">Focus respective inputs</a></li>
</ul>
<h3>Other controls</h3>
<ul>
<li><a href="#blur_on_submit">Blur on submit</a></li>
<li><a href="#blur_on_autocomplete_select">Blur on autocomplete select</a></li>
<li><a href="#disable_inputs_on_submit">Disable inputs on submit</a></li>
<li><a href="#toggle_actions_on_mouseover">Toggle actions on mouseover</a></li>
</ul>
<h2><a name="submit_on_blur_one">Submit on Blur (one field)</a></h2>
<p>
Submitting a form after a field loses focus is the basic functionality of edit in place.
<p>
<div class="in_place_edit" data-in-place-data="submitOnBlur">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
<span class="hint">Note: The value must change for the form to submit</span>
</form>
</div>
<h2><a name="submit_on_blur">Submit on Blur (multiple fields)</a></h2>
<p>
Submitting the form the instant focus is lost may be great if you only have one form field. What happens if you have more than one field in the same form? You probably want to submit them after the user moves on from either field. This is where submitting with a delay an help. If no activity is detected in any fields for longer than 100 milliseconds, the form submits.
</p>
<div class="in_place_edit" data-in-place-data="submitOnBlur">
<form action="#" method="post" class="demo_form">
<div>Field 1</div>
<input name="foo" value="foo">
<div>Field 2</div>
<input name="bar" value="bar">
<span class="hint">Note: At least one value must change for the form to submit</span>
</form>
</div>
<h2><a name="submit_on_click">Submit on Click</a></h2>
<p>
Suitable for a form containing check boxes
</p>
<div class="in_place_edit" data-in-place-data="submitOnClick">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
</form>
</div>
<h2><a name="submit_on_enter">Submit on Enter</a></h2>
<p>
The default action of pressing enter while the focus is in a form is caught with this library. If you want to re-enable this functionality, add this method
</p>
<div class="in_place_edit" data-in-place-data="submitOnEnter">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
<span class="hint">Note: The value must change for the form to submit</span>
</form>
</div>
<h2><a name="submit_on_autocomplete">Submit on Autocomplete Select</a></h2>
<p>
When a field is bound to the <a href="http://jqueryui.com/demos/autocomplete/">jQuery autocomplete UI</a> functionality, a user can select from a list of items. This option will signal to submit the form when an autocomplete item is chosen.
</p>
<div class="in_place_edit" data-in-place-data="submitOnAutocompleteSelect">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo" class="autocomplete">
<span class="hint">Note: Type the letter 'A' in the field to show results</span>
</form>
</div>
<h2><a name="add_class_on_focus">Add Class on Focus</a></h2>
<p>
Add the data('add_class_on_focus') class from the currently focused :input field. Remove data('add_class_on_focus') class back on blur
</p>
<h3>Options</h3>
<dl>
<dt>data-add-class-on-focus</dt>
<dd>The class to add</dd>
</dl>
<div class="in_place_edit" data-in-place-data="addClassOnFocus" data-add-class-on-focus="red_background">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
</form>
</div>
<h2><a name="remove_class_on_focus">Remove Class on Focus</a></h2>
<p>
Remove the data('remove_class_on_focus') class from the blurred :input field. Add data('remove_class_on_focus') class back on blur
</p>
<h3>Options</h3>
<dl>
<dt>data-remove-class-on-focus</dt>
<dd>The class to remove</dd>
</dl>
<div class="in_place_edit" data-in-place-data="removeClassOnFocus" data-remove-class-on-focus="red_background">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo" class="red_background">
</form>
</div>
<h2><a name="add_class_on_blur">Add Class on Blur</a></h2>
<p>
Add the data('add_class_on_blur') class from the currently blured :input field. Remove data('add_class_on_blur') class back on blur
</p>
<h3>Options</h3>
<dl>
<dt>data-add-class-on-blur</dt>
<dd>The class to add</dd>
</dl>
<div class="in_place_edit" data-in-place-data="addClassOnBlur" data-add-class-on-blur="red_background">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
</form>
</div>
<h2><a name="remove_class_on_blur">Remove Class on Blur</a></h2>
<p>
Remove the data('remove_class_on_blur') class from the blurred :input field. Add data('remove_class_on_blur') class back on blur
</p>
<h3>Options</h3>
<dl>
<dt>data-remove-class-on-blur</dt>
<dd>The class to remove</dd>
</dl>
<div class="in_place_edit" data-in-place-data="removeClassOnBlur" data-remove-class-on-blur="red_background">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo" class="red_background">
</form>
</div>
<h2><a name="show_form_on_click">Show Form on Click</a></h2>
<p>
When a display label is clicked, switch to an alternate view containing the form. Requires the label element to have the class display_label. Elements with a class of .no_toggle will be excluded from this event.
</p>
<div class="in_place_edit" data-in-place-data="showFormOnClick">
<form action="#" method="post" class="demo_form" style="display:none">
<input name="foo" value="foo">
</form>
<div class="display_label">
<h4>Click me to show the form</h4>
</div>
</div>
<h2><a name="hide_label_on_click">Hide label on Click</a></h2>
<p>
When a display label is clicked, hide it
</p>
<div class="in_place_edit" data-in-place-data="hideLabelOnClick">
<div class="display_label">
<h4>Click me to hide</h4>
</div>
</div>
<h2><a name="show_label_on_blur">Show Label on Blur</a></h2>
<p>
Inverse of 'Show Form On Click' - returns to display label when form elements blur for longer than 1s. Requires the label element to have the class 'display_label'
</p>
<div class="in_place_edit" data-in-place-data="showLabelOnBlur">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
</form>
<div class="display_label" style="display: none">
<h4>Now you see the display label</h4>
</div>
</div>
<h2><a name="hide_form_on_blur">Hide form on Blur</a></h2>
<p>
When a form loses focus, hide it
</p>
<div class="in_place_edit" data-in-place-data="hideFormOnBlur">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
</form>
</div>
<h2><a name="show_label_on_enter">Show Label on Enter</a></h2>
<p>
Similar to 'Show Label On Blur', watching for the enter key to be pressed in a field instead
</p>
<div class="in_place_edit" data-in-place-data="showLabelOnEnter">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
</form>
<div class="display_label" style="display: none">
<h4>
Now you see the display label
</h4>
</div>
</div>
<h2><a name="hide_form_on_enter">Hide form on Enter</a></h2>
<p>
When enter is pressed inside a form, hide that form
</p>
<div class="in_place_edit" data-in-place-data="hideFormOnEnter">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
</form>
</div>
<h2><a name="focus_respective_inputs">Focus Respective Inputs</a></h2>
<p>
Specify an element to gain the focus on the form when a label is clicked. This element is defined by the data-in-place-focus-element value on the label element. If no element is specified, then the first element, or the element with class .initial_focus is focused.
</p>
<h3>Options</h3>
<dl>
<dt>data-in-place-focus-element</dt>
<dd>The CSS selector of the input element to focus on when clicked</dd>
</dl>
<div class="in_place_edit" data-in-place-data="focusRespectiveInputs">
<form action="#" method="post" class="demo_form">
<p>
<label for="first">First name</label>
<input name="first" value="Benjamin" id="first">
</p>
<p>
<label for="middle">Middle name</label>
<input name="middle" value="Lee" id="middle">
</p>
<p>
<label for="last">Last name</label>
<input name="last" value="Simpson" id="last">
</p>
</form>
<div class="display_label">
<p>Click different parts of my name:</p>
<strong>Mr.</strong>
<strong data-in-place-focus-element="#first">Benjamin</strong>
<strong data-in-place-focus-element="#middle">Lee</strong>
<strong data-in-place-focus-element="#last">Simpson</strong>
</div>
</div>
<h2><a name="add_class_on_submit">Add Class on Submit</a></h2>
<p>
Add class data('add_class_on_submit') to :input element on submit, blur, or enter
</p>
<h3>Options</h3>
<dl>
<dt>data-add-class-on-submit</dt>
<dd>The class to add</dd>
</dl>
<div class="in_place_edit" data-in-place-data="addClassOnSubmit" data-add-class-on-submit="red_background">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
</form>
</div>
<h2><a name="blur_on_submit">Blur on Submit</a></h2>
<p>
Simulate tabbing away from a field on submit, blur, or enter
</p>
<div class="in_place_edit" data-in-place-data="blurOnSubmit">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo">
<span class="hint">Note: The focus leaves the field after submit is fired</span>
</form>
</div>
<h2><a name="blur_on_autocomplete_select">Blur on Autocomplete Select</a></h2>
<p>
When autocompleteselect fires, also fire a blur event
</p>
<div class="in_place_edit" data-in-place-data="blurOnAutocompleteSelect">
<form action="#" method="post" class="demo_form">
<input name="foo" value="foo" class="autocomplete">
</form>
</div>
<h2><a name="disable_inputs_on_submit">Disable Inputs on Submit</a></h2>
<p>
Disable all input fields when submit is fired
</p>
<div class="in_place_edit" data-in-place-data="disableInputsOnSubmit">
<form action="#" method="post" class="demo_form" id="remote">
<input name="foo" value="foo">
</form>
</div>
<h2><a name="toggle_actions_on_mouseover">Toggle Actions on Mouseover</a></h2>
<p>
Toggle a DOM element with class "display_label" on mouseover/out
</p>
<div class="in_place_edit" data-in-place-data="toggleActionsOnMouseover">
<span class="hint">Note: Move the mouse over 'Mouseover me to toggle controls' to see controls</span>
<div class="display_label">
<h3>
Mouseover me to toggle controls
<span class="controls" style="display:none">
<a href="#">Edit</a>
<a href="#">Delete</a>
</span>
</h3>
</div>
</div>
<h1>Examples</h1>
<p>
The following a is a collection of examples that demonstrate the way in which the options can stack together to create meaningful interactions.
</p>
<div id="demo_1">
<h2>Basic In Place Edit</h2>
<div class="in_place_edit" data-in-place-data="submitOnBlur submitOnEnter addClassOnFocus removeClassOnBlur" data-add-class-on-focus="red_background" data-remove-class-on-blur="red_background">
<form action="#" method="post" class="demo_form">
<div>Field 1</div>
<input name="foo" value="foo">
<span class="hint">Note: At least one value must change for the form to submit</span>
</form>
</div>
</div>
<div id="demo_2">
<h2>Display label with multiple clickable areas</h2>
<div class="in_place_edit" data-in-place-data="focusRespectiveInputs hideLabelOnClick showFormOnClick showLabelOnBlur hideFormOnBlur showLabelOnEnter hideFormOnEnter">
<form action="#" method="post" class="demo_form" style="display: none">
<input name="first" value="Benjamin" id="demo_2_first">
<input name="middle" value="Lee" id="demo_2_middle">
<input name="last" value="Simpson" id="demo_2_last">
</form>
<div class="display_label">
<strong data-in-place-focus-element="#demo_2_first">Benjamin</strong>
<strong data-in-place-focus-element="#demo_2_middle">Lee</strong>
<strong data-in-place-focus-element="#demo_2_last">Simpson</strong>
</div>
</div>
<script>
$(function() {
$(['first','middle','last']).each(function(_, x) {
$('#demo_2_' + x, '#demo_2').bind('change', function() {
$('strong[data-in-place-focus-element="#demo_2_' + x + '"]', '#demo_2').html($(this).val());
});
});
});
</script>
</div>
<div id="demo_3">
<h2>Edit an Active Hyperlink</h2>
<div class="in_place_edit" data-in-place-data="toggleActionsOnMouseover focusRespectiveInputs showFormOnClick hideLabelOnClick hideFormOnBlur showLabelOnBlur">
<form action="#" method="post" class="demo_form" style="display: none">
<input name="link" value="http://www.reddit.com" id="demo_3_link">
</form>
<div class="display_label">
<a href="http://www.reddit.com">http://www.reddit.com</a>
<span class="controls" style="display: none">
<span data-in-place-focus-element="#demo_3_link">Edit</span>
</span>
</div>
</div>
<script>
$(function() {
$('#demo_3_link', '#demo_3').bind('change', function() {
$('.display_label a', '#demo_3').attr('href', $(this).val()).html($(this).val());
});
});
</script>
</div>
</body>
</html>