Browse Source

Improved mustache and zepto examples

Maurits van der Schee 8 years ago
parent
commit
61b49bdecd
2 changed files with 12 additions and 12 deletions
  1. 5
    5
      examples/client_mustache.html
  2. 7
    7
      examples/client_zepto.html

+ 5
- 5
examples/client_mustache.html View File

@@ -45,7 +45,7 @@ function PostList(element, template) {
45 45
 		$.post(url, {user_id:1,category_id:1,content:content}, self.update);
46 46
 	};
47 47
 	self.render = function(data) {
48
-		$(element).html(Mustache.to_html($(template).html(),php_crud_api_transform(data)));
48
+		element.html(Mustache.to_html(template.html(),php_crud_api_transform(data)));
49 49
 	};
50 50
 	self.update = function() {
51 51
 		$.get(url, self.render);
@@ -53,12 +53,12 @@ function PostList(element, template) {
53 53
 	self.post = function() {
54 54
 		$.post(url, {user_id:1,category_id:1,content:"from mustache"}, self.update);
55 55
 	};
56
-	$(element).on('submit','form',self.submit);
57
-	$(element).on('click','a.edit',self.edit)
58
-	$(element).on('click','a.delete',self.delete)
56
+	element.on('submit','form',self.submit);
57
+	element.on('click','a.edit',self.edit)
58
+	element.on('click','a.delete',self.delete)
59 59
 	self.post();
60 60
 };
61
-$(function(){ new PostList('#PostListDiv','#PostListTemplate'); });
61
+$(function(){ new PostList($('#PostListDiv'),$('#PostListTemplate')); });
62 62
 </script>
63 63
 </head>
64 64
 <body>

+ 7
- 7
examples/client_zepto.html View File

@@ -43,15 +43,15 @@ function PostList(element,template) {
43 43
 	};
44 44
 	self.render = function(data) {
45 45
 		data = php_crud_api_transform(data);
46
-		$(element).html($(template).html());
47
-		var item = $(element).find('li').first().remove();
46
+		element.html(template.html());
47
+		var item = element.find('li').first().remove();
48 48
 		for (var i=0;i<data.posts.length; i++) {
49 49
 			var clone = item.clone();
50 50
 			clone.find('span').each(function(){
51 51
 				var field = $(this).attr("class");
52 52
 				$(this).text(data.posts[i][field]);
53 53
 			});
54
-			clone.insertBefore($(element).find('li').last());
54
+			clone.insertBefore(element.find('li').last());
55 55
 		}
56 56
 	};
57 57
 	self.update = function() {
@@ -60,12 +60,12 @@ function PostList(element,template) {
60 60
 	self.post = function() {
61 61
 		$.post(url, {user_id:1,category_id:1,content:"from zepto"}, self.update);
62 62
 	};
63
-	$(element).on('submit','form',self.submit);
64
-	$(element).on('click','a.edit',self.edit)
65
-	$(element).on('click','a.delete',self.delete)
63
+	element.on('submit','form',self.submit);
64
+	element.on('click','a.edit',self.edit)
65
+	element.on('click','a.delete',self.delete)
66 66
 	self.post();
67 67
 };
68
-$(function(){ new PostList('#PostListDiv','#PostListTemplate'); });
68
+$(function(){ new PostList($('#PostListDiv'),$('#PostListTemplate')); });
69 69
 </script>
70 70
 </head>
71 71
 <body>

Loading…
Cancel
Save