Skip to content
This repository was archived by the owner on Jan 16, 2020. It is now read-only.

Commit 7862f45

Browse files
committed
Remove out-of-date content in demo page.
Fix white space to use tabs throughout demo pages.
1 parent 678bd7a commit 7862f45

File tree

3 files changed

+141
-149
lines changed

3 files changed

+141
-149
lines changed

demos/demo-contacts.css

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22
css adapted from:
33
http://veerle.duoh.com/blog/comments/a_css_styled_table/
44
*/
5-
a {
6-
color: #6D929B;
7-
}
8-
.contacts {
9-
border: 1px solid #C1DAD7;
10-
margin:20px;
11-
}
12-
.contacts td {
13-
border-right: 1px solid #C1DAD7;
14-
border-bottom: 1px solid #C1DAD7;
15-
padding: 6px 6px 6px 12px;
16-
color: #6D929B;
17-
vertical-align: middle;
18-
}
19-
.contacts th {
20-
border-right: 1px solid #C1DAD7;
21-
border-bottom: 1px solid #C1DAD7;
22-
border-top: 1px solid #C1DAD7;
23-
letter-spacing: 2px;
24-
text-transform: uppercase;
25-
text-align: left;
26-
padding: 6px 6px 6px 12px;
27-
}
28-
.agebar {
5+
a {
6+
color: #6D929B;
7+
}
8+
.contacts {
9+
border: 1px solid #C1DAD7;
10+
margin:20px;
11+
}
12+
.contacts td {
13+
border-right: 1px solid #C1DAD7;
14+
border-bottom: 1px solid #C1DAD7;
15+
padding: 6px 6px 6px 12px;
16+
color: #6D929B;
17+
vertical-align: middle;
18+
}
19+
.contacts th {
20+
border-right: 1px solid #C1DAD7;
21+
border-bottom: 1px solid #C1DAD7;
22+
border-top: 1px solid #C1DAD7;
23+
letter-spacing: 2px;
24+
text-transform: uppercase;
25+
text-align: left;
26+
padding: 6px 6px 6px 12px;
27+
}
28+
.agebar {
2929
color: #000000;
3030
background-color: #8888FF;
3131
text-align: center;
3232
font-weight: bold;
3333
border: solid 1px blue;
3434
width: 2em;
3535
height: 25px;
36-
}
37-
.phones td, .phones th {
38-
border: none;
39-
padding: 2px 2px 2px 4px;
40-
vertical-align: top;
41-
}
42-
36+
}
37+
.phones td, .phones th {
38+
border: none;
39+
padding: 2px 2px 2px 4px;
40+
vertical-align: top;
41+
}
42+

demos/demo-contacts.html

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,57 @@
11
<!DOCTYPE html>
22
<html xmlns="http://www.w3.org/1999/xhtml">
33
<head>
4-
<title>My Contacts - Linking Demo</title>
5-
<link type="text/css" rel="Stylesheet" href="demo-contacts.css" />
4+
<title>My Contacts - Linking Demo</title>
5+
<link type="text/css" rel="Stylesheet" href="demo-contacts.css" />
66

77
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
88
<script type="text/javascript" src="../jquery.datalink.js"></script>
99
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.js"></script>
1010
<script type="text/javascript" src="demo-contacts.js"></script>
1111
<script id="contacttmpl" type="text/x-jquery-tmpl">
12-
<tr>
13-
<th>&nbsp;</th>
14-
<th>First Name</th>
15-
<th>Last Name</th>
16-
<th>Phone Numbers</th>
17-
<th>Age</th>
18-
</tr>
19-
{{each contacts}}
20-
<tr class="contact">
21-
<td>
22-
<a href="#" class="contact-remove">remove</a><br/>
23-
<a href="#" class="contact-reset">reset</a><br/>
24-
</td>
25-
<td>
26-
<input name="firstName" class="contact" type="text" value="${firstName}" />
27-
</td>
28-
<td><input name="lastName" class="contact" type="text" value="${lastName}" /></td>
29-
<td>
30-
<table class="phones">
31-
<tr>
32-
<th>&nbsp;</th>
33-
<th>Type</th>
34-
<th>Number</th>
35-
</tr>
36-
{{each phones}}
37-
<tr class="phone">
38-
<td><a href="#" class="phone-remove">remove</td>
39-
<td><input class="phone phone-type" name="type" type="text" value="${type}" /></td>
40-
<td><input class="phone phone-number" name="number" type="text" value="${number}" /></td>
41-
</tr>
42-
{{/each}}
43-
</table>
44-
<a href="#" class="newphone">add new phone</a>
45-
</td>
46-
<td>
12+
<tr>
13+
<th>&nbsp;</th>
14+
<th>First Name</th>
15+
<th>Last Name</th>
16+
<th>Phone Numbers</th>
17+
<th>Age</th>
18+
</tr>
19+
{{each contacts}}
20+
<tr class="contact">
21+
<td>
22+
<a href="#" class="contact-remove">remove</a><br/>
23+
<a href="#" class="contact-reset">reset</a><br/>
24+
</td>
25+
<td>
26+
<input name="firstName" class="contact" type="text" value="${firstName}" />
27+
</td>
28+
<td><input name="lastName" class="contact" type="text" value="${lastName}" /></td>
29+
<td>
30+
<table class="phones">
31+
<tr>
32+
<th>&nbsp;</th>
33+
<th>Type</th>
34+
<th>Number</th>
35+
</tr>
36+
{{each phones}}
37+
<tr class="phone">
38+
<td><a href="#" class="phone-remove">remove</td>
39+
<td><input class="phone phone-type" name="type" type="text" value="${type}" /></td>
40+
<td><input class="phone phone-number" name="number" type="text" value="${number}" /></td>
41+
</tr>
42+
{{/each}}
43+
</table>
44+
<a href="#" class="newphone">add new phone</a>
45+
</td>
46+
<td>
4747
<input type="text" class="agebar" name="age" value="${age}" />
48-
</td>
49-
</tr>
50-
{{/each}}
48+
</td>
49+
</tr>
50+
{{/each}}
5151
</script>
5252
</head>
5353

5454
<body>
55-
<div>
56-
This is a demo of the Data Linking feature being proposed by Microsoft. You can follow the discussion and provide feedback on the jQuery developer forum, here:
57-
<br/><a href="http://forum.jquery.com/topic/proposal-for-adding-data-linking-to-jquery">jQuery Discussion</a>
58-
<br/>
59-
And you can view the source from here or keep up to date with it on github, here:
60-
<br/><a href="https://github.com/jquery/jquery-datalink/">DataLink on GitHub</a>
61-
</div>
62-
6355
<table class="contacts">
6456
</table>
6557
<input type="button" id="insert" value="Insert new contact" />

demos/demo-contacts.js

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,59 @@ jQuery( function( $ ){
22

33
// define some basic default data to start with
44
var contacts = [
5-
{ firstName: "Dave", lastName: "Reed", age: 32, phones: [
6-
{ type: "Mobile", number: "(555) 121-2121" },
7-
{ type: "Home", number: "(555) 123-4567" } ] },
8-
{ firstName: "John", lastName: "Doe", age: 87, phones: [
9-
{ type: "Mobile", number: "(555) 444-2222" },
10-
{ type: "Home", number: "(555) 999-1212" } ] }
5+
{ firstName: "Dave", lastName: "Reed", age: 32, phones: [
6+
{ type: "Mobile", number: "(555) 121-2121" },
7+
{ type: "Home", number: "(555) 123-4567" } ] },
8+
{ firstName: "John", lastName: "Doe", age: 87, phones: [
9+
{ type: "Mobile", number: "(555) 444-2222" },
10+
{ type: "Home", number: "(555) 999-1212" } ] }
1111
];
1212

1313
$.extend( $.convertFn, {
14-
// linking converter that normalizes phone numbers
15-
phone: function( value ) {// turn a string phone number into a normalized one with dashes
16-
// and parens
17-
value = (parseInt( value.replace( /[\(\)\- ]/g, "" ), 10 ) || 0 ).toString();
18-
value = "0000000000" + value;
19-
value = value.substr( value.length - 10 );
20-
value = "(" + value.substr( 0, 3 ) + ") " + value.substr( 3, 3 ) + "-" + value.substr( 6 );
21-
return value;
22-
},
23-
fullname: function( value, source, target ) {
24-
return source.firstName + " " + source.lastName;
25-
}
14+
// linking converter that normalizes phone numbers
15+
phone: function( value ) {// turn a string phone number into a normalized one with dashes
16+
// and parens
17+
value = (parseInt( value.replace( /[\(\)\- ]/g, "" ), 10 ) || 0 ).toString();
18+
value = "0000000000" + value;
19+
value = value.substr( value.length - 10 );
20+
value = "(" + value.substr( 0, 3 ) + ") " + value.substr( 3, 3 ) + "-" + value.substr( 6 );
21+
return value;
22+
},
23+
fullname: function( value, source, target ) {
24+
return source.firstName + " " + source.lastName;
25+
}
2626
});
2727

2828
// show the results of the linking -- object graph is already full of the data
2929
$( "#save" ).click( function() {
30-
$( "#results" ).html( JSON.stringify( contacts, null, 4 ));
30+
$( "#results" ).html( JSON.stringify( contacts, null, 4 ));
3131
});
3232

3333
// add a new contact when clicking the insert button.
3434
// notice that no code here exists that explicitly redraws
3535
// the template.
3636
$( "#insert" ).click( function() {
37-
contacts.push({ firstName: "first", lastName: "last", phones: [], age:20 });
38-
refresh();
37+
contacts.push({ firstName: "first", lastName: "last", phones: [], age:20 });
38+
refresh();
3939
});
4040

4141
$( "#sort" ).click( function() {
42-
contacts.sort( function( a, b ) {
43-
return a.lastName < b.lastName ? -1 : 1;
44-
});
45-
refresh();
42+
contacts.sort( function( a, b ) {
43+
return a.lastName < b.lastName ? -1 : 1;
44+
});
45+
refresh();
4646
});
4747

4848
// function that clears the current template and renders it with the
4949
// current state of the global contacts variable.
5050
function refresh() {
51-
$( ".contacts" ).empty();
51+
$( ".contacts" ).empty();
5252
$( "#contacttmpl" ).tmpl( {contacts:contacts} ).appendTo( ".contacts" );
53-
// bind inputs to the data items
54-
$( "tr.contact" ).each( function(i) {
55-
var contact = contacts[i];
56-
$( "input.contact", this ).link( contact );
57-
$( '.agebar', this ).link( contact, {
53+
// bind inputs to the data items
54+
$( "tr.contact" ).each( function(i) {
55+
var contact = contacts[i];
56+
$( "input.contact", this ).link( contact );
57+
$( '.agebar', this ).link( contact, {
5858
age: {
5959
convertBack: function( value, source, target ) {
6060
$( target ).width( value + "px" );
@@ -63,45 +63,45 @@ function refresh() {
6363
});
6464
$( contact ).trigger( "changeData", ["age", contact.age] );
6565

66-
// todo: "update" feature
67-
68-
$( ".contact-remove", this ).click( function() {
69-
contacts.splice( i, 1 );
70-
refresh();
71-
});
72-
var original_firstName = contact.firstName,
73-
original_lastName = contact.lastName;
74-
$( ".contact-reset", this ).click( function() {
75-
$( contact )
76-
.data( "firstName", original_firstName )
77-
.data( "lastName", original_lastName );
78-
});
79-
80-
$( "tr.phone", this ).each( function(i) {
81-
var phone = contact.phones[i];
82-
$( this ).link( phone, {
83-
type: "type",
84-
number: {
85-
name: "number",
86-
convert: "phone"
87-
}
88-
});
89-
$( ".phone-remove", this ).click( function() {
90-
// note: I'd like to only redraw the phones portion of the
91-
// template, but jquery.tmpl.js does not support nested templates
92-
// very easily. So here I am triggering an arrayChange event on
93-
// the main contacts array to force the entire thing to refresh.
94-
// Note that user input is not lost since the live linking has
95-
// already stored the values in the object graph.
96-
contact.phones.splice( i, 1 );
97-
refresh();
98-
});
99-
});
100-
$( ".newphone", this ).click( function() {
101-
contact.phones.push({ type: "", number: "" });
102-
refresh();
103-
});
104-
});
66+
// todo: "update" feature
67+
68+
$( ".contact-remove", this ).click( function() {
69+
contacts.splice( i, 1 );
70+
refresh();
71+
});
72+
var original_firstName = contact.firstName,
73+
original_lastName = contact.lastName;
74+
$( ".contact-reset", this ).click( function() {
75+
$( contact )
76+
.data( "firstName", original_firstName )
77+
.data( "lastName", original_lastName );
78+
});
79+
80+
$( "tr.phone", this ).each( function(i) {
81+
var phone = contact.phones[i];
82+
$( this ).link( phone, {
83+
type: "type",
84+
number: {
85+
name: "number",
86+
convert: "phone"
87+
}
88+
});
89+
$( ".phone-remove", this ).click( function() {
90+
// note: I'd like to only redraw the phones portion of the
91+
// template, but jquery.tmpl.js does not support nested templates
92+
// very easily. So here I am triggering an arrayChange event on
93+
// the main contacts array to force the entire thing to refresh.
94+
// Note that user input is not lost since the live linking has
95+
// already stored the values in the object graph.
96+
contact.phones.splice( i, 1 );
97+
refresh();
98+
});
99+
});
100+
$( ".newphone", this ).click( function() {
101+
contact.phones.push({ type: "", number: "" });
102+
refresh();
103+
});
104+
});
105105
}
106106

107107
// initial view on load

0 commit comments

Comments
 (0)