Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
- <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- var page = 0;
- $(window).scroll(function () {
- if ($(document).height()-$(document).height()*0.2 <= $(window).scrollTop() + $(window).height()) {
- if(page >= 0)
- { page = page + 1;
- $.ajax({
- type: "POST",
- url: "/",
- dataType: "json",
- data: { 'page' : page, 'csrfmiddlewaretoken': '{{csrf_token}}'},
- success: function(data) {
- if(data.id <= 0){
- $(".fa-spinner").hide();
- $(".messages").append('<center> <p>End of List.. </p></center>');
- page = -10
- }
- obj1 = JSON.parse(data.fulldata);
- for(i = 0; i < obj1.length; i++){
- var newHTML = '<div class="col-sm-4">\
- <div class="product-image-wrapper">\
- <div class="single-products">\
- <div class="productinfo text-center">\
- <img src=/' + obj1[i].fields["image1"] + ' alt="" width = "auto" height="340"/>\
- <h2>'+obj1[i].fields["price"]+ '₹</h2>\
- <p>' + obj1[i].fields["name"] +'</p>\
- <a id="/' + obj1[i].fields["slug"] + '/add" class="btn btn-default add-to-cart add_to_cart">\
- <i class="fa fa-shopping-cart"></i>Add to cart</a>\
- </div>\
- </div><div class="choose">\
- <ul class="nav nav-pills nav-justified">\
- <li><a id="/'+ obj1[i].fields["slug"] +'/add_to_wishlist" class= "add_to_wishlist">\
- <i class="fa fa-plus-square"></i>Add to wishlist</a></li>\
- <li><a id="/' + obj1[i].fields["slug"]+'/add" class= "add_to_cart" >\
- <i class="fa fa-shopping-cart"></i>Add to cart</a></li>\
- </ul></div></div></div>';
- $(".newdata").append(newHTML);
- }
- },
- error: function(data) {
- // alert("error")
- }
- });
- }
- }
- });
- $('.add_to_cart').click(function(){
- i =this;
- $.ajax({
- type: "GET",
- url: $(this).attr('id'),
- dataType: "json",
- success: function(data) {
- if(data.id == 2)
- {
- toastr.options.closeButton = true;
- toastr.options.positionClass = 'toast-top-center';
- toastr.options.preventDuplicates = 'true';
- toastr.success('Please Login First');
- setTimeout(function() {
- window.location.href = './accounts/login/';
- }, 2000);
- }
- if(data.id == 1)
- {
- $(i).closest('.col-sm-4').fadeOut(3000).remove();
- toastr.options.closeButton = true;
- toastr.success('Added to cart')
- }
- }
- });
- });
- $('.add_to_wishlist').click(function(){
- i =this;
- $.ajax({
- type: "GET",
- url: $(this).attr('id'),
- dataType: "json",
- success: function(data) {
- if(data.id == 2)
- {
- toastr.options.closeButton = true;
- toastr.options.positionClass = 'toast-top-center';
- toastr.options.preventDuplicates = 'true';
- toastr.success('Please Login First')
- }
- if(data.id == 1)
- {
- $(i).closest('.col-sm-4').fadeOut(3000).remove();
- toastr.options.closeButton = true;
- toastr.success('Added to Wishlist')
- }
- }
- });
- });
- });
- </script>
- <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
- <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
- {% load staticfiles %}
- <div class="features_items"><!--features_items-->
- <h2 class="title text-center">Features Items</h2>
- {% if queryset %}
- {% for query in queryset %}
- <div class="col-sm-4">
- <div class="product-image-wrapper">
- <div class="single-products">
- <div class="productinfo text-center">
- <img src='/{{ query.image1 }} ' alt="" width = 'auto' height='340'/>
- <h2>{{query.price}} ₹</h2>
- <p>{{query.name}}</p>
- <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>
- </div>
- </div>
- <div class="choose">
- <ul class="nav nav-pills nav-justified">
- <li><a id="/{{query.slug}}/add_to_wishlist" class= "add_to_wishlist"><i class="fa fa-plus-square"></i>Add to wishlist</a></li>
- <li><a id="/{{query.slug}}/add" class= "add_to_cart" ><i class="fa fa-shopping-cart"></i>Add to cart</a></li>
- </ul>
- </div>
- </div>
- </div>
- {% endfor %}
- {% else %}
- <div class="alert alert-success" role="alert">
- <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
- <span class="sr-only"></span>
- Sorry we don't have products for this category...
- </div>
- {%endif%}
- <div class="newdata"></div>
- </div><!--features_items-->
- <div class="alert alert-success messages" role="alert"><center>
- <i class="fa fa-spinner fa-spin fa-2x"></i></center>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement