source: resources/js/main.js@ 7ed1069

Last change on this file since 7ed1069 was f457265, checked in by Berat Kjufliju <kufliju@…>, 4 years ago

ADD technoweek offer, companies

  • Property mode set to 100644
File size: 7.1 KB
RevLine 
[0924b6c]1var app = {
2
[f457265]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 }
[0924b6c]226
227};
228
229$(function() {
[f457265]230 app.init();
[0924b6c]231});
Note: See TracBrowser for help on using the repository browser.