From f9b00c8bf57f716314c13a2f1d688abb6876d017 Mon Sep 17 00:00:00 2001 From: BorisMoore Date: Wed, 5 Jan 2011 14:49:53 -0800 Subject: [PATCH] Added moviesNoGlobals samples to show how to access functions from templates without creating globals. - Code is wrapped in a function closure: (function($) {...})(jQuery); - The formatDate function within the closure is called from within the template by passing it in with options: $( "#bookingEditTmpl" ).tmpl( booking, { formatDate: formatDate } ) - and accessing it on the template item, $item: ${$item.formatDate()}. See https://github.com/jquery/jquery-tmpl/issues#issue/39 --- demos/movies/PagesCore/movies.html | 4 - demos/movies/PagesCore/moviesNoGlobals.html | 363 ++++++++++++++++++++ 2 files changed, 363 insertions(+), 4 deletions(-) create mode 100644 demos/movies/PagesCore/moviesNoGlobals.html diff --git a/demos/movies/PagesCore/movies.html b/demos/movies/PagesCore/movies.html index 8432ee1..a2f1ab6 100644 --- a/demos/movies/PagesCore/movies.html +++ b/demos/movies/PagesCore/movies.html @@ -347,10 +347,6 @@

Netflix: Book a Movie...

function formatDate( date ) { return date.toLocaleDateString(); } - - function removeContext( item ) { - $( item.nodes ).remove(); - } diff --git a/demos/movies/PagesCore/moviesNoGlobals.html b/demos/movies/PagesCore/moviesNoGlobals.html new file mode 100644 index 0000000..b2b2460 --- /dev/null +++ b/demos/movies/PagesCore/moviesNoGlobals.html @@ -0,0 +1,363 @@ + + + + + jQuery + OData + Netflix Catalog API + + + + +
+

Netflix: Book a Movie...

+ + + +
  • first
  • prev
+ +
+ + +
+ 0 items in Cart... +
+
+
+ + + + + + + + + + + + + + + + +