source: resources/js/main.js@ 1f059b0

Last change on this file since 1f059b0 was 0924b6c, checked in by Özkan İliyaz <iliyaz_96@…>, 4 years ago

initial commit

  • Property mode set to 100644
File size: 5.2 KB
RevLine 
[0924b6c]1var app = {
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 }
217
218};
219
220$(function() {
221 app.init();
222});
Note: See TracBrowser for help on using the repository browser.