Changeset f457265 for resources/js/main.js
- Timestamp:
- 02/24/21 21:58:42 (4 years ago)
- Branches:
- master
- Children:
- ff9da8b
- Parents:
- 0c07a90
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
resources/js/main.js
r0c07a90 rf457265 1 1 var app = { 2 2 3 // Initialize 4 init: function() { 5 this.welcomeSlider(); 6 this.categoryNavbarPosition(); 7 this.categoryNavbarActiveLink(); 8 this.buildSimpleTooltip(); 9 this.scrollSmoothly(); 10 this.scrollToTop(); 11 this.likePost(); 12 this.unlikePost(); 13 this.comment(); 14 }, 15 16 welcomeSlider: function() { 17 var swiper = new Swiper('.swiper-container', { 18 pagination: { 19 el: '.swiper-pagination', 20 clickable: true, 21 renderBullet: function(index, className) { 22 return '<span class="' + className + '">' + (index + 1) + '</span>'; 23 }, 24 }, 25 navigation: { 26 nextEl: '.swiper-button-next', 27 prevEl: '.swiper-button-prev', 28 }, 29 loop: true, 30 centeredSlides: true, 31 autoplay: { 32 delay: 2500, 33 disableOnInteraction: false, 34 }, 35 }); 36 }, 37 38 categoryNavbarPosition: function() { 39 if ($(".categoryNavbar").length) { 40 var distance = $(".navbar").offset().top; 41 var $window = $(window); 42 var navbar = $(".navbar"); 43 44 $window.scroll(function() { 45 if ($window.scrollTop() >= distance) { 46 navbar.addClass("fixed-top"); 47 } else { 48 navbar.removeClass("fixed-top"); 49 } 50 }); 51 } 52 }, 53 54 categoryNavbarActiveLink: function() { 55 if ($(".categoryNavbar").length) { 56 $(".categoryNavbar a[href='http://technoblog.test/category/" + window.location.pathname + "']").addClass("active"); 57 } 58 }, 59 60 buildSimpleTooltip: function() { 61 if (!$("a.elemWithTooltip").length || !$("a.elemWithTooltip").data("tooltip-info")) { 62 return false; 63 } 64 65 var tooltipElem = $("a.elemWithTooltip"); 66 var placements = ["top", "right", "bottom", "left"]; 67 68 tooltipElem.each(function(i) { 69 70 var $this = $(this); 71 var tooltipData = $this.data("tooltip-info"); 72 var title = tooltipData.substring(tooltipData.indexOf("-") + 1); 73 var placement = tooltipData.substring(0, tooltipData.indexOf("-")); 74 75 if (tooltipData.indexOf("-") === -1 || tooltipData.charAt(0) === "-") { 76 $this.addClass("Error_SimpleTooltip"); 77 return false; 78 } 79 80 $.each(placements, function(j) { 81 if (placement === placements[j]) { 82 $this.not(".Error_SimpleTooltip").attr({ 83 "data-toggle": "tooltip", 84 "data-placement": placement, 85 "title": title 86 }).tooltip(); 87 } 88 }); 89 }); 90 91 }, 92 93 scrollSmoothly: function() { 94 var scroll = new SmoothScroll("a.scrollBtn", { 95 easing: "linear" 96 }); 97 }, 98 99 scrollToTop: function() { 100 if ($(".scrollUpArrow").length) { 101 var distance = 150; 102 var $window = $(window); 103 var scrollUp = $(".scrollUpArrow"); 104 105 scrollUp.hide(); 106 107 $window.scroll(function() { 108 if ($window.scrollTop() >= distance) { 109 scrollUp.fadeIn("slow"); 110 } else { 111 scrollUp.fadeOut("slow"); 112 } 113 }); 114 } 115 }, 116 117 likePost: function() { 118 119 $(".post-reaction").on("click", ".likePost", function() { 120 121 var data = $(this).data("post-id"); 122 var _token = $("meta[name='csrf-token']").attr("content"); 123 124 $.ajax({ 125 url: "/like", 126 type: "post", 127 data: { 128 post_id : data, 129 _token : _token, 130 }, 131 dataType: "json", 132 success: function(response) { 133 $(".post-reaction i").remove(); 134 $(".post-reaction").append("<i data-unlike-id=" + response.unlike_id + " class='text-danger fa fa-heart unlikePost' aria-hidden='true'></i>"); 135 $(".likeCounter").text(response.likeCounter); 136 }, 137 error: function(data) { 138 console.log(data); 139 } 140 }); 141 }) 142 }, 143 144 unlikePost: function() { 145 146 $(".post-reaction").on("click", ".unlikePost", function() { 147 148 var data = $(this).data("unlike-id"); 149 var _token = $("meta[name='csrf-token']").attr("content"); 150 151 $.ajax({ 152 url: "/unlike", 153 type: "post", 154 data: { 155 unlike_id : data, 156 _token : _token, 157 }, 158 dataType: "json", 159 success: function(response) { 160 $(".post-reaction i").remove(); 161 $(".post-reaction").append("<i data-post-id=" + response.post_id + " class='text-danger fa fa-heart-o likePost' aria-hidden='true'></i>"); 162 $(".likeCounter").text(response.likeCounter); 163 }, 164 error: function(data) { 165 console.log(data); 166 } 167 }); 168 }) 169 }, 170 171 comment: function() { 172 173 if($("comment-alert").length > 0) { 174 $(".comment-alert").hide(); 175 } 176 177 $(".commentForm").submit(function(e) { 178 179 e.preventDefault(); 180 181 $(this).find("input[type='submit']").prop("disabled", true); 182 $(this).find("input[type='submit']").val("Processing..."); 183 184 var name = $(this).find("input[name='name']").val(); 185 var email = $(this).find("input[name='email']").val(); 186 var comment = $(this).find("textarea[name='comment']").val(); 187 var post_id = $(this).find("input[name='post_id']").val(); 188 var _token = $("meta[name='csrf-token']").attr("content"); 189 190 $.ajax({ 191 url: "/comment", 192 type: "post", 193 data: { 194 name: name, 195 email: email, 196 comment: comment, 197 post_id: post_id, 198 _token : _token, 199 }, 200 dataType: "json", 201 success: function(response) { 202 203 $(".comment-alert").show(); 204 $(".comment-alert").addClass(response.type); 205 $(".comment-alert").find("strong").text(response.message); 206 207 $(".commentForm").find("input[type='submit']").prop("disabled", false); 208 $(".commentForm").find("input[type='submit']").val("Comment"); 209 $(".commentForm")[0].reset(); 210 }, 211 error: function(data) { 212 console.log(data); 213 } 214 }); 215 }); 216 } 3 // Initialize 4 init: function() { 5 this.showCompanyModal(); 6 this.welcomeSlider(); 7 this.categoryNavbarPosition(); 8 this.categoryNavbarActiveLink(); 9 this.buildSimpleTooltip(); 10 this.scrollSmoothly(); 11 this.scrollToTop(); 12 this.likePost(); 13 this.unlikePost(); 14 this.comment(); 15 }, 16 17 showCompanyModal: function() { 18 if($(".company-modal").length) { 19 setTimeout(function () { 20 $(".company-modal").modal("show"); 21 }, 2000); 22 } 23 }, 24 25 welcomeSlider: function() { 26 var swiper = new Swiper('.swiper-container', { 27 pagination: { 28 el: '.swiper-pagination', 29 clickable: true, 30 renderBullet: function(index, className) { 31 return '<span class="' + className + '">' + (index + 1) + '</span>'; 32 }, 33 }, 34 navigation: { 35 nextEl: '.swiper-button-next', 36 prevEl: '.swiper-button-prev', 37 }, 38 loop: true, 39 centeredSlides: true, 40 autoplay: { 41 delay: 2500, 42 disableOnInteraction: false, 43 }, 44 }); 45 }, 46 47 categoryNavbarPosition: function() { 48 if ($(".categoryNavbar").length) { 49 var distance = $(".navbar").offset().top; 50 var $window = $(window); 51 var navbar = $(".navbar"); 52 53 $window.scroll(function() { 54 if ($window.scrollTop() >= distance) { 55 navbar.addClass("fixed-top"); 56 } else { 57 navbar.removeClass("fixed-top"); 58 } 59 }); 60 } 61 }, 62 63 categoryNavbarActiveLink: function() { 64 if ($(".categoryNavbar").length) { 65 $(".categoryNavbar a[href='http://technoblog.test/category/" + window.location.pathname + "']").addClass("active"); 66 } 67 }, 68 69 buildSimpleTooltip: function() { 70 if (!$("a.elemWithTooltip").length || !$("a.elemWithTooltip").data("tooltip-info")) { 71 return false; 72 } 73 74 var tooltipElem = $("a.elemWithTooltip"); 75 var placements = ["top", "right", "bottom", "left"]; 76 77 tooltipElem.each(function(i) { 78 79 var $this = $(this); 80 var tooltipData = $this.data("tooltip-info"); 81 var title = tooltipData.substring(tooltipData.indexOf("-") + 1); 82 var placement = tooltipData.substring(0, tooltipData.indexOf("-")); 83 84 if (tooltipData.indexOf("-") === -1 || tooltipData.charAt(0) === "-") { 85 $this.addClass("Error_SimpleTooltip"); 86 return false; 87 } 88 89 $.each(placements, function(j) { 90 if (placement === placements[j]) { 91 $this.not(".Error_SimpleTooltip").attr({ 92 "data-toggle": "tooltip", 93 "data-placement": placement, 94 "title": title 95 }).tooltip(); 96 } 97 }); 98 }); 99 100 }, 101 102 scrollSmoothly: function() { 103 var scroll = new SmoothScroll("a.scrollBtn", { 104 easing: "linear" 105 }); 106 }, 107 108 scrollToTop: function() { 109 if ($(".scrollUpArrow").length) { 110 var distance = 150; 111 var $window = $(window); 112 var scrollUp = $(".scrollUpArrow"); 113 114 scrollUp.hide(); 115 116 $window.scroll(function() { 117 if ($window.scrollTop() >= distance) { 118 scrollUp.fadeIn("slow"); 119 } else { 120 scrollUp.fadeOut("slow"); 121 } 122 }); 123 } 124 }, 125 126 likePost: function() { 127 128 $(".post-reaction").on("click", ".likePost", function() { 129 130 var data = $(this).data("post-id"); 131 var _token = $("meta[name='csrf-token']").attr("content"); 132 133 $.ajax({ 134 url: "/like", 135 type: "post", 136 data: { 137 post_id : data, 138 _token : _token, 139 }, 140 dataType: "json", 141 success: function(response) { 142 $(".post-reaction i").remove(); 143 $(".post-reaction").append("<i data-unlike-id=" + response.unlike_id + " class='text-danger fa fa-heart unlikePost' aria-hidden='true'></i>"); 144 $(".likeCounter").text(response.likeCounter); 145 }, 146 error: function(data) { 147 console.log(data); 148 } 149 }); 150 }) 151 }, 152 153 unlikePost: function() { 154 155 $(".post-reaction").on("click", ".unlikePost", function() { 156 157 var data = $(this).data("unlike-id"); 158 var _token = $("meta[name='csrf-token']").attr("content"); 159 160 $.ajax({ 161 url: "/unlike", 162 type: "post", 163 data: { 164 unlike_id : data, 165 _token : _token, 166 }, 167 dataType: "json", 168 success: function(response) { 169 $(".post-reaction i").remove(); 170 $(".post-reaction").append("<i data-post-id=" + response.post_id + " class='text-danger fa fa-heart-o likePost' aria-hidden='true'></i>"); 171 $(".likeCounter").text(response.likeCounter); 172 }, 173 error: function(data) { 174 console.log(data); 175 } 176 }); 177 }) 178 }, 179 180 comment: function() { 181 182 if($("comment-alert").length > 0) { 183 $(".comment-alert").hide(); 184 } 185 186 $(".commentForm").submit(function(e) { 187 188 e.preventDefault(); 189 190 $(this).find("input[type='submit']").prop("disabled", true); 191 $(this).find("input[type='submit']").val("Processing..."); 192 193 var name = $(this).find("input[name='name']").val(); 194 var email = $(this).find("input[name='email']").val(); 195 var comment = $(this).find("textarea[name='comment']").val(); 196 var post_id = $(this).find("input[name='post_id']").val(); 197 var _token = $("meta[name='csrf-token']").attr("content"); 198 199 $.ajax({ 200 url: "/comment", 201 type: "post", 202 data: { 203 name: name, 204 email: email, 205 comment: comment, 206 post_id: post_id, 207 _token : _token, 208 }, 209 dataType: "json", 210 success: function(response) { 211 212 $(".comment-alert").show(); 213 $(".comment-alert").addClass(response.type); 214 $(".comment-alert").find("strong").text(response.message); 215 216 $(".commentForm").find("input[type='submit']").prop("disabled", false); 217 $(".commentForm").find("input[type='submit']").val("Comment"); 218 $(".commentForm")[0].reset(); 219 }, 220 error: function(data) { 221 console.log(data); 222 } 223 }); 224 }); 225 } 217 226 218 227 }; 219 228 220 229 $(function() { 221 230 app.init(); 222 231 });
Note:
See TracChangeset
for help on using the changeset viewer.