Pārlūkot izejas kodu

Added a delete button with a jQuery transition.

Frederic G. MARAND 9 gadi atpakaļ
vecāks
revīzija
fe790d06b5
5 mainītis faili ar 16 papildinājumiem un 11 dzēšanām
  1. 1 0
      .meteor/packages
  2. 2 0
      .meteor/versions
  3. 2 1
      image_share.html
  4. 7 7
      image_share.js
  5. 4 3
      startup.js

+ 1 - 0
.meteor/packages

@@ -22,3 +22,4 @@ ejson
 spacebars
 check
 ecmascript
+barbatus:stars-rating

+ 2 - 0
.meteor/versions

@@ -2,6 +2,7 @@ autopublish@1.0.4
 autoupdate@1.2.4
 babel-compiler@5.8.24_1
 babel-runtime@0.1.4
+barbatus:stars-rating@1.0.7
 base64@1.0.4
 binary-heap@1.0.4
 blaze@2.1.3
@@ -31,6 +32,7 @@ id-map@1.0.4
 insecure@1.0.4
 jquery@1.11.4
 launch-screen@1.0.4
+less@2.5.1
 livedata@1.0.15
 logging@1.0.8
 meteor@1.1.10

+ 2 - 1
image_share.html

@@ -12,7 +12,7 @@
 <template name="images">
   <div class="row">
     {{#each images}}
-      <div class="col-xs-12 col-md-3">
+      <div class="col-xs-12 col-md-3" id="{{_id}}">
         <div class="thumbnail">
 
           <img class="js-image" src="{{img_src}}" alt="{{img_alt}}" />
@@ -20,6 +20,7 @@
           <div class="caption">
             <h3>Thumbnail label</h3>
             <p>description of the image</p>
+            <button class="js-del-image btn btn-warning">delete</button>
           </div>
         </div>
       </div> <!-- / col -->

+ 7 - 7
image_share.js

@@ -7,13 +7,13 @@ if (Meteor.isClient) {
   Template.images.events({
     "click .js-image": function (event) {
       $(event.target).css("width", "50px");
+    },
+    "click .js-del-image": function (event) {
+      let imageId = this._id;
+      console.log(imageId);
+      $("#" + imageId).hide(200, function () {
+        Images.remove({ _id: imageId });
+      });
     }
   });
 }
-
-if (Meteor.isServer) {
-  Meteor._debug("I am the server");
-}
-
-Meteor._debug("where am I running");
-

+ 4 - 3
startup.js

@@ -6,9 +6,10 @@ if (Meteor.isServer) {
           "img_src": "img_" + i + ".jpg",
           "img_alt": "image number " + i
         });
-      } // end of for loop
-      Meteor._debug(Images.find().count());
+      } // end of for insert images
+      // count the images!
+      Meteor._debug("startup.js says: " + Images.find().count());
     } // end of if have no images.
   });
 
-}
+}