Skip to content

Commit

Permalink
Added 'remove' example on 'Observable collection changes' samples.
Browse files Browse the repository at this point in the history
Switched all samples to use $(...).on() rather thatn $(...).click()
  • Loading branch information
BorisMoore committed May 29, 2012
1 parent 16fea05 commit cf89d9d
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 15 deletions.
4 changes: 2 additions & 2 deletions demos/jQueryConfDemosOct2011/07_observable.html
Expand Up @@ -44,7 +44,7 @@ <h3>JsViews: Observable property changes</h3>
$.link.personTmpl( person, "#details" );

// Observable property change
$( "#changeName" ).click( function() {
$( "#changeName" ).on( "click", function() {
$.observable( person ).setProperty( "firstName", person.firstName + "Plus" );
});

Expand All @@ -68,7 +68,7 @@ <h4>Script:</h4>
$.link.personTmpl( person, "#details" );

// Observable property change
$( "#changeName" ).click( function() {
$( "#changeName" ).on( "click", function() {
$.observable( person ).setProperty( "firstName", person.firstName + "Plus" );
});
</pre>
Expand Down
24 changes: 20 additions & 4 deletions demos/jQueryConfDemosOct2011/07_observable2.html
Expand Up @@ -27,6 +27,9 @@ <h3>JsViews: Observable collection changes</h3>
<td>
<input data-link="firstName" />
</td>
<td>
<img class="close" src="../resources/close.png" />
</td>
</tr>
</script>

Expand All @@ -49,11 +52,17 @@ <h3>JsViews: Observable collection changes</h3>
// Data-link details container to people, using the personTmpl template
$.link.personTmpl( people, "#details" );

// Observable array change
$( "#insertPerson" ).click( function() {
// Observable array change: insert
$( "#insertPerson" ).on( "click", function() {
$.observable( people ).insert( 0, { firstName: "NewPerson" + counter++ });
});

// Observable array change: remove
$( "#details" )
.on( "click", ".close", function() {
$.observable( people ).remove( $.view( this ).index, 1 );
});

</script>

<!--================ End of Demo Section ================-->
Expand All @@ -72,10 +81,17 @@ <h4>Script:</h4>
<pre class="brush: js;">
$.link.personTmpl( people, "#details" );

// Observable array change
$( "#insertPerson" ).click( function() {
// Observable array change: insert
$( "#insertPerson" ).on( "click", function() {
$.observable( people ).insert( 0, { firstName: "NewPerson" + counter++ });
});

// Observable array change: remove
$( "#details" )
.on( "click", ".close", function() {
$.observable( people ).remove( $.view( this ).index, 1 );
});

</pre>
</body>
</html>
Expand Down
18 changes: 14 additions & 4 deletions demos/jQueryConfDemosOct2011/07_observable3.html
Expand Up @@ -36,6 +36,9 @@ <h3>JsViews: Two containers data-linked to the same array</h3>
<td>
<input data-link="firstName" />
</td>
<td>
<img class="close" src="../resources/close.png" />
</td>
</tr>
</script>

Expand Down Expand Up @@ -63,15 +66,22 @@ <h3>JsViews: Two containers data-linked to the same array</h3>
$.link.personTmpl2( people, "#details2" );

// Observable array change: insert two new people
$( "#insertPerson" ).click( function() {
$( "#insertPerson" ).on( "click", function() {
var insertAt = people.length ? 1 : 0;
$.observable( people ).insert(
1, // insert at index 1
insertAt, // insert at index 1
[
{ firstName: "NewPerson" + counter++ },
{ firstName: "NewPerson" + counter++ }
]);
});

// Observable array change: remove
$( "#details2" )
.on( "click", ".close", function() {
$.observable( people ).remove( $.view( this ).index, 1 );
});

</script>

<!--================ End of Demo Section ================-->
Expand All @@ -83,9 +93,9 @@ <h4>Script:</h4>
$.link.personTmpl2( people, "#details2" );

// Observable array change: insert two new people at index 1
$( "#insertPerson" ).click( function() {
$( "#insertPerson" ).on( "click", function() {
$.observable( people ).insert(
1, // index 1
1, // index 1
[ // add two new people
{ firstName: "NewPerson" },
{ firstName: "NewPerson2" }
Expand Down
2 changes: 1 addition & 1 deletion demos/jQueryConfDemosOct2011/11_editable-data.html
Expand Up @@ -113,7 +113,7 @@ <h3>JsViews: Fully editable data: JsViews</h3>
return false;
});

$( "#addMovieBtn" ).click( function() {
$( "#addMovieBtn" ).on( "click", function() {
$.observable( movies ).insert( movies.length, {
title: "NewTitle" + counter,
languages: [
Expand Down
2 changes: 1 addition & 1 deletion demos/jQueryConfDemosOct2011/13_converters.html
Expand Up @@ -73,7 +73,7 @@ <h3>JsRender and JsViews: Use converters for custom encoding, data formatting, l
});

// Observable property change
$( "#changeDay" ).click( function() {
$( "#changeDay" ).on( "click", function() {
var dayOff = myWeek.dayOff;
$.observable( myWeek ).setProperty( "dayOff", dayOff < 6 ? dayOff + 1 : 0);
});
Expand Down
2 changes: 1 addition & 1 deletion demos/step-by-step/04_editable-data.html
Expand Up @@ -101,7 +101,7 @@ <h3>Fully editable data: Change events with integrated Data-Link and Templates</
return false;
});

$( "#addMovieBtn" ).click( function() {
$( "#addMovieBtn" ).on( "click", function() {
$.observable( movies ).insert( movies.length, {
title: "NewTitle" + counter ,
languages: [
Expand Down
Expand Up @@ -156,7 +156,7 @@ <h3>Server rendered content, activated in client. With client data 'delta'...</h
return false;
});

$( "#addMovieBtn" ).click( function() {
$( "#addMovieBtn" ).on( "click", function() {
$.observable( movies ).insert( movies.length, {
title: "NewTitle" + counter,
languages: [
Expand Down
2 changes: 1 addition & 1 deletion demos/step-by-step/10_todos.html
Expand Up @@ -128,7 +128,7 @@ <h1>Todos</h1>
}
});

$( ".todo-clear" ).click( function() { todos.clearCompleted(); });
$( ".todo-clear" ).on( "click", function() { todos.clearCompleted(); });

// Link UI, and handle changes to 'done' and 'content' properties of Todo items
$.link( todos, "#todo-stats" );
Expand Down

0 comments on commit cf89d9d

Please sign in to comment.