Advertisement
Guest User

code

a guest
Oct 28th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
  3. <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  4.  
  5. <script type="text/javascript">
  6.  
  7.         $(document).ready(function() {
  8.  
  9. var page = 0;
  10.  $(window).scroll(function () {
  11.  
  12.         if ($(document).height()-$(document).height()*0.2  <= $(window).scrollTop() + $(window).height()) {
  13.  
  14.             if(page >= 0)
  15.                 {   page = page + 1;
  16.                    $.ajax({
  17.                     type: "POST",
  18.                     url: "/",
  19.                     dataType: "json",
  20.                     data: { 'page' : page, 'csrfmiddlewaretoken': '{{csrf_token}}'},
  21.                     success: function(data) {
  22.                       if(data.id <= 0){
  23.                         $(".fa-spinner").hide();
  24.                         $(".messages").append('<center> <p>End of List.. </p></center>');
  25.                         page  = -10
  26.  
  27.                       }
  28.  
  29.                         obj1 = JSON.parse(data.fulldata);
  30.                         for(i = 0; i < obj1.length; i++){
  31.                                
  32.                         var newHTML = '<div class="col-sm-4">\
  33.                             <div class="product-image-wrapper">\
  34.                                 <div class="single-products">\
  35.                                         <div class="productinfo text-center">\
  36.                                             <img src=/' + obj1[i].fields["image1"] + ' alt="" width = "auto" height="340"/>\
  37.                                             <h2>'+obj1[i].fields["price"]+ '₹</h2>\
  38.                                             <p>' + obj1[i].fields["name"] +'</p>\
  39.                                     <a id="/' + obj1[i].fields["slug"] + '/add" class="btn btn-default add-to-cart add_to_cart">\
  40.                                     <i class="fa fa-shopping-cart"></i>Add to cart</a>\
  41.                                         </div>\
  42.                                 </div><div class="choose">\
  43.                                     <ul class="nav nav-pills nav-justified">\
  44.                                         <li><a id="/'+ obj1[i].fields["slug"] +'/add_to_wishlist" class= "add_to_wishlist">\
  45.                                         <i class="fa fa-plus-square"></i>Add to wishlist</a></li>\
  46.                                         <li><a id="/' + obj1[i].fields["slug"]+'/add"  class= "add_to_cart" >\
  47.                                         <i class="fa fa-shopping-cart"></i>Add to cart</a></li>\
  48.                                     </ul></div></div></div>';
  49.                        
  50.                         $(".newdata").append(newHTML);
  51.  
  52.                     }
  53.  
  54.                     },
  55.                     error: function(data) {
  56.                      // alert("error")
  57.                     }
  58.                 });
  59.  
  60.                }
  61.  
  62.  
  63.  
  64.  
  65.         }
  66.     });
  67.  
  68.  
  69.  
  70.  
  71.             $('.add_to_cart').click(function(){
  72.                 i =this;
  73.                 $.ajax({
  74.                     type: "GET",
  75.                     url: $(this).attr('id'),
  76.                     dataType: "json",
  77.                    
  78.                     success: function(data) {
  79.                     if(data.id == 2)
  80.                     {
  81.                         toastr.options.closeButton = true;
  82.                         toastr.options.positionClass = 'toast-top-center';
  83.                         toastr.options.preventDuplicates = 'true';
  84.                         toastr.success('Please Login First');
  85.                         setTimeout(function() {
  86.                            window.location.href = './accounts/login/';
  87.                           }, 2000);
  88.  
  89.                     }
  90.  
  91.                     if(data.id == 1)
  92.                      {
  93.                        $(i).closest('.col-sm-4').fadeOut(3000).remove();
  94.                         toastr.options.closeButton = true;
  95.                         toastr.success('Added to cart')    
  96.                       }
  97.                     }
  98.                 });
  99.             });
  100.  
  101.  
  102.  
  103.  
  104.  
  105.              $('.add_to_wishlist').click(function(){
  106.                 i =this;
  107.                 $.ajax({
  108.                     type: "GET",
  109.                     url: $(this).attr('id'),
  110.                     dataType: "json",
  111.                    
  112.                     success: function(data) {
  113.                     if(data.id == 2)
  114.                     {
  115.                         toastr.options.closeButton = true;
  116.                         toastr.options.positionClass = 'toast-top-center';
  117.                         toastr.options.preventDuplicates = 'true';
  118.                         toastr.success('Please Login First')  
  119.                     }
  120.                     if(data.id == 1)
  121.                      {
  122.                        $(i).closest('.col-sm-4').fadeOut(3000).remove();
  123.                         toastr.options.closeButton = true;
  124.                         toastr.success('Added to Wishlist')    
  125.                       }
  126.                     }
  127.                 });
  128.             });
  129.         });
  130. </script>
  131.  
  132. <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
  133. <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
  134. {% load staticfiles %}
  135.  
  136.  
  137. <div class="features_items"><!--features_items-->
  138.                         <h2 class="title text-center">Features Items</h2>
  139.                 {% if queryset %}
  140.                     {% for query in queryset %}
  141.  
  142.                         <div class="col-sm-4">
  143.                             <div class="product-image-wrapper">
  144.                                 <div class="single-products">
  145.                                         <div class="productinfo text-center">
  146.                                             <img src='/{{ query.image1 }} ' alt="" width = 'auto' height='340'/>
  147.                                             <h2>{{query.price}} ₹</h2>
  148.                                             <p>{{query.name}}</p>
  149.                                             <a id="/{{query.slug}}/add" class="btn btn-default add-to-cart add_to_cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
  150.                                         </div>
  151.  
  152.                                 </div>
  153.                                 <div class="choose">
  154.                                     <ul class="nav nav-pills nav-justified">
  155.                                         <li><a id="/{{query.slug}}/add_to_wishlist" class= "add_to_wishlist"><i class="fa fa-plus-square"></i>Add to wishlist</a></li>
  156.  
  157.                                         <li><a id="/{{query.slug}}/add"  class= "add_to_cart" ><i class="fa fa-shopping-cart"></i>Add to cart</a></li>
  158.                                     </ul>
  159.                                 </div>
  160.                             </div>
  161.                         </div>
  162.                        
  163.                     {% endfor %}
  164.  
  165.  
  166.                 {% else %}
  167.                     <div class="alert alert-success" role="alert">
  168.                       <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
  169.                       <span class="sr-only"></span>
  170.                        Sorry we don't have products for this category...
  171.                     </div>
  172.  
  173.                 {%endif%}        
  174.  
  175.                 <div class="newdata"></div>
  176.  
  177.                
  178.     </div><!--features_items-->
  179.  
  180.     <div class="alert alert-success messages" role="alert"><center>
  181.   <i class="fa fa-spinner fa-spin fa-2x"></i></center>
  182. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement