source: resources/assets/js/app.js@ 5e56e8a

develop
Last change on this file since 5e56e8a was 24a616f, checked in by Berat Kjufliju <kufliju@…>, 3 years ago

added documents crud, added last_seen_to_user, edited views

  • Property mode set to 100644
File size: 15.4 KB
RevLine 
[24a616f]1'use strict';
[7304c7f]2
3(function ($) {
4
[24a616f]5 var wind_ = $(window),
6 body_ = $('body');
[7304c7f]7
[24a616f]8 feather.replace({
9 'stroke-width': 1.5
10 });
[7304c7f]11
[24a616f]12 $(document).on('click', '[data-toggle="fullscreen"]', function () {
13 $(this).toggleClass('active-fullscreen');
14 if (document.fullscreenEnabled) {
15 if ($(this).hasClass("active-fullscreen")) {
16 document.documentElement.requestFullscreen();
17 } else {
18 document.exitFullscreen();
19 }
20 } else {
21 alert("Your browser does not support fullscreen.");
22 }
23 return false;
[7304c7f]24 });
25
[24a616f]26 $(document).on('click', '.overlay', function () {
27 $.removeOverlay();
28 if (body_.hasClass('horizontal-navigation')) {
29 $('.horizontal-navigation').removeClass('open');
30 } else {
31 $('.navigation').removeClass('open');
32 }
33 body_.removeClass('navigation-show');
34 });
[7304c7f]35
[24a616f]36 $(document).on('click', '[data-sidebar-target]', function () {
37 var target = $(this).data('sidebar-target');
38 $('body').addClass('no-scroll');
39 $('.sidebar-group').addClass('show');
40 $('.sidebar-group .sidebar').removeClass('show');
41 $('.sidebar-group .sidebar' + target).addClass('show');
42 return false;
43 });
[7304c7f]44
[24a616f]45 $(document).on('click', '.sidebar-group', function (e) {
46 if ($(e.target).is($('.sidebar-group'))) {
47 $('.sidebar-group').removeClass('show');
48 $('body').removeClass('no-scroll');
49 $('.sidebar-group .sidebar').removeClass('show');
[7304c7f]50 }
[24a616f]51 });
[7304c7f]52
[24a616f]53 // Active pages, automatically show on the menu
54 $('.navigation .navigation-menu-body .navigation-menu-group ul li a.active').closest('ul').parent('li').addClass('open').closest('ul').parent('li').addClass('open');
55 $('.navigation .navigation-menu-body .navigation-menu-group ul li a.active').closest('div').addClass('open');
56 $('.navigation .navigation-menu-tab [data-nav-target="#' + $('.navigation .navigation-menu-body .navigation-menu-group ul li a.active').closest('div').attr('id') + '"]').addClass('active');
57 $('body.horizontal-navigation .horizontal-navigation ul li a.active').closest('ul').parent('li').addClass('open').closest('ul').parent('li').addClass('open');
58
59
60 /*------------- create/remove overlay -------------*/
61 $.createOverlay = function () {
62 if ($('.overlay').length < 1) {
63 body_.addClass('no-scroll').append('<div class="overlay"></div>');
64 $('.overlay').addClass('show');
[7304c7f]65 }
[24a616f]66 };
[7304c7f]67
[24a616f]68 $.removeOverlay = function () {
69 body_.removeClass('no-scroll');
70 $('.overlay').remove();
71 };
72 /*------------- create/remove overlay -------------*/
[7304c7f]73
[24a616f]74 $('[data-backround-image]').each(function (e) {
75 $(this).css("background", 'url(' + $(this).data('backround-image') + ')');
76 });
[7304c7f]77
[24a616f]78 /*------------- page loader -------------*/
79 wind_.on('load', function () {
80 $('.preloader').fadeOut(400, function () {
81 setTimeout(function () {
82 toastr.options = {
83 timeOut: 2000,
84 progressBar: true,
85 showMethod: "slideDown",
86 hideMethod: "slideUp",
87 showDuration: 200,
88 hideDuration: 200,
89 positionClass: "toast-top-center",
90 };
91 //toastr.success('Welcome');
92
93 $('.theme-switcher').removeClass('open');
94 }, 500);
95
96 // $('.theme-switcher').css('opacity', 1);
97 });
98 });
99 /*------------- page loader -------------*/
[7304c7f]100
[24a616f]101 /*------------- side menu (sub menü arrow) -------------*/
102 wind_.on('load', function () {
103 setTimeout(function () {
104 $('.navigation .navigation-menu-body ul li a').each(function () {
105 var $this = $(this);
106 if ($this.next('ul').length) {
107 $this.append('<i class="sub-menu-arrow ti-angle-up"></i>');
108 }
109 });
110 $('.navigation .navigation-menu-body ul li.open>a>.sub-menu-arrow').removeClass('ti-plus').addClass('ti-minus').addClass('rotate-in');
111 $('body.horizontal-navigation .horizontal-navigation ul li a').each(function () {
112 var $this = $(this);
113 if ($this.next('ul').length) {
114 $this.append('<i class="sub-menu-arrow ti-angle-right"></i>');
115 }
116 });
117 }, 200);
118 });
119 /*------------- side menu (sub menü arrow) -------------*/
[7304c7f]120
[24a616f]121 $(document).on('click', '[data-action="navigation-toggler"]', function () {
122 if (body_.hasClass('horizontal-navigation')) {
123 $('.horizontal-navigation').toggleClass('open');
124 } else {
125 $('.navigation').toggleClass('open');
[7304c7f]126 }
[24a616f]127 $.createOverlay();
128 });
[7304c7f]129
[24a616f]130 $(document).on('click', '[data-nav-target]', function () {
131 var $this = $(this),
132 target = $this.data('nav-target');
133 if (body_.hasClass('navigation-toggle-one')) {
134 body_.addClass('navigation-show');
135 }
136 if (body_.hasClass('horizontal-navigation')) {
137 $('.navigation .navigation-menu-body').show();
138 }
139 $('.navigation .navigation-menu-body .navigation-menu-group > div').removeClass('open');
140 $('.navigation .navigation-menu-body .navigation-menu-group ' + target).addClass('open');
141 $('[data-nav-target]').removeClass('active');
142 $this.addClass('active');
143 $this.tooltip('hide');
144 return false;
[7304c7f]145 });
146
[24a616f]147 var c = $('.header .header-left .header-logo').clone();
148 $('.navigation .navigation-header').append(c.addClass('navigation-logo').removeClass('header-logo'));
149
150 $(document).on('click', '.navigation-toggler a', function () {
151 if (wind_.width() < 1200) {
152 $.createOverlay();
153 body_.addClass('navigation-show');
154 } else {
155 if (!body_.hasClass('navigation-toggle-one') && !body_.hasClass('navigation-toggle-two')) {
156 body_.addClass('navigation-toggle-one');
157 } else if (body_.hasClass('navigation-toggle-one') && !body_.hasClass('navigation-toggle-two')) {
158 body_.addClass('navigation-toggle-two');
159 body_.removeClass('navigation-toggle-one');
160 } else if (!body_.hasClass('navigation-toggle-one') && body_.hasClass('navigation-toggle-two')) {
161 body_.removeClass('navigation-toggle-two');
162 body_.removeClass('navigation-toggle-one');
163 }
164 }
165 return false;
166 });
[7304c7f]167
[24a616f]168 $(document).on('click', '.header-toggler a', function () {
169 $('.header ul.navbar-nav').toggleClass('open');
170 return false;
[7304c7f]171 });
172
[24a616f]173 $(document).on('click', '*', function (e) {
174 if (!$(e.target).is($('.navigation, .navigation *, .navigation-toggler *')) && body_.hasClass('navigation-toggle-one')) {
175 body_.removeClass('navigation-show');
176 }
177 });
[7304c7f]178
[24a616f]179 $(document).on('click', '*', function (e) {
180 if (!$(e.target).is('.header ul.navbar-nav, .header ul.navbar-nav *, .header-toggler, .header-toggler *')) {
181 $('.header ul.navbar-nav').removeClass('open');
182 }
183 });
184
185 /*------------- form validation -------------*/
186 window.addEventListener('load', function () {
187 // Fetch all the forms we want to apply custom Bootstrap validation styles to
188 var forms = document.getElementsByClassName('needs-validation');
189 // Loop over them and prevent submission
190 Array.prototype.filter.call(forms, function (form) {
191 form.addEventListener('submit', function (event) {
192 if (form.checkValidity() === false) {
193 event.preventDefault();
194 event.stopPropagation();
195 }
196 form.classList.add('was-validated');
197 }, false);
198 });
199 }, false);
200 /*------------- form validation -------------*/
201
202 /*------------- responsive html table -------------*/
203 var table_responsive_stack = $(".table-responsive-stack");
204 table_responsive_stack
205 .find("th")
206 .each(function (i) {
207 $(".table-responsive-stack td:nth-child(" + (i + 1) + ")").prepend(
208 '<span class="table-responsive-stack-thead">' +
209 $(this).text() +
210 ":</span> "
211 );
212 $(".table-responsive-stack-thead").hide();
213 });
214
215 table_responsive_stack.each(function () {
216 var thCount = $(this).find("th").length,
217 rowGrow = 100 / thCount + "%";
218 $(this).find("th, td").css("flex-basis", rowGrow);
219 });
220
221 function flexTable() {
222 if (wind_.width() < 768) {
223 $(".table-responsive-stack").each(function (i) {
224 $(this)
225 .find(".table-responsive-stack-thead")
226 .show();
227 $(this)
228 .find("thead")
229 .hide();
230 });
231
232 // window is less than 768px
233 } else {
234 $(".table-responsive-stack").each(function (i) {
235 $(this)
236 .find(".table-responsive-stack-thead")
237 .hide();
238 $(this)
239 .find("thead")
240 .show();
241 });
242 }
[7304c7f]243 }
244
[24a616f]245 flexTable();
246
247 window.onresize = function (event) {
248 flexTable();
249 };
250 /*------------- responsive html table -------------*/
[7304c7f]251
[24a616f]252 /*------------- header search -------------*/
253 $(document).on('click', '[data-toggle="search"], [data-toggle="search"] *', function () {
254 $('.header .header-body .header-search').show().find('.form-control').focus();
255 return false;
256 });
[7304c7f]257
[24a616f]258 $(document).on('click', '.close-header-search, .close-header-search svg', function () {
259 $('.header .header-body .header-search').hide();
260 return false;
261 });
[7304c7f]262
[24a616f]263 $(document).on('click', '*', function (e) {
264 if (!$(e.target).is($('.header, .header *, [data-toggle="search"], [data-toggle="search"] *'))) {
265 $('.header .header-body .header-search').hide();
266 }
267 });
268 /*------------- header search -------------*/
[7304c7f]269
[24a616f]270 /*------------- custom accordion -------------*/
271 $(document).on('click', '.accordion.custom-accordion .accordion-row a.accordion-header', function () {
272 var $this = $(this);
273 $this.closest('.accordion.custom-accordion').find('.accordion-row').not($this.parent()).removeClass('open');
274 $this.parent('.accordion-row').toggleClass('open');
275 return false;
276 });
277 /*------------- custom accordion -------------*/
278
279 /*------------- responsive table dropdown -------------*/
280 var dropdownMenu,
281 table_responsive = $('.table-responsive');
282
283 table_responsive.on('show.bs.dropdown', function (e) {
284 dropdownMenu = $(e.target).find('.dropdown-menu');
285 body_.append(dropdownMenu.detach());
286 var eOffset = $(e.target).offset();
287 dropdownMenu.css({
288 'display': 'block',
289 'top': eOffset.top + $(e.target).outerHeight(),
290 'left': eOffset.left,
291 'width': '184px',
292 'font-size': '14px'
293 });
294 dropdownMenu.addClass("mobPosDropdown");
295 });
296
297 table_responsive.on('hide.bs.dropdown', function (e) {
298 $(e.target).append(dropdownMenu.detach());
299 dropdownMenu.hide();
300 });
301 /*------------- responsive table dropdown -------------*/
302
303 /*------------- chat -------------*/
304 $(document).on('click', '.chat-block .chat-sidebar .chat-sidebar-content .list-group .list-group-item', function () {
305 $('.chat-block .chat-content').addClass('chat-mobile-open');
306 return false;
307 });
308
309 $(document).on('click', '.chat-block .chat-content .mobile-chat-close-btn a', function () {
310 $('.chat-block .chat-content').removeClass('chat-mobile-open');
311 return false;
312 });
313 /*------------- chat -------------*/
314
315 /*------------- aside menu toggle -------------*/
316 $(document).on('click', '.navigation ul li a', function () {
317 var $this = $(this);
318 if ($this.next('ul').length) {
319 var sub_menu_arrow = $this.find('.sub-menu-arrow');
320 sub_menu_arrow.toggleClass('rotate-in');
321 $this.next('ul').toggle(200);
322 $this.parent('li').siblings().find('ul').not($this.parent('li').find('ul')).slideUp(200);
323 $this.next('ul').find('li ul').slideUp(200);
324 $this.next('ul').find('li>a').find('.sub-menu-arrow').removeClass('ti-minus').addClass('ti-plus');
325 $this.next('ul').find('li>a').find('.sub-menu-arrow').removeClass('rotate-in');
326 $this.parent('li').siblings().not($this.parent('li').find('ul')).find('>a').find('.sub-menu-arrow').removeClass('ti-minus').addClass('ti-plus');
327 $this.parent('li').siblings().not($this.parent('li').find('ul')).find('>a').find('.sub-menu-arrow').removeClass('rotate-in');
328 if (sub_menu_arrow.hasClass('rotate-in')) {
329 setTimeout(function () {
330 sub_menu_arrow.removeClass('ti-plus').addClass('ti-minus');
331 }, 200);
332 } else {
333 sub_menu_arrow.removeClass('ti-minus').addClass('ti-plus');
334 }
335 if (!body_.hasClass('horizontal-side-menu') && wind_.width() >= 1200) {
336 setTimeout(function (e) {
337 $('.navigation .navigation-menu-body').getNiceScroll().resize();
338 }, 300);
339 }
340 return false;
341 }
342 });
[7304c7f]343
[24a616f]344 $(document).on('click', '.horizontal-navigation ul li a', function () {
345 var $this = $(this);
346 if ($this.next('ul').length) {
347 $this.next('ul').toggle(200);
348 $this.parent('li').siblings().find('ul').not($this.parent('li').find('ul')).slideUp(200);
349 $this.next('ul').find('li ul').slideUp(200);
350 return false;
351 }
352 });
353
354 /*------------- aside menu toggle -------------*/
355
356 /*------------- other -------------*/
357 $(document).on('click', '.dropdown-menu', function (e) {
358 e.stopPropagation();
359 });
360
361 $('#exampleModal').on('show.bs.modal', function (event) {
362 var button = $(event.relatedTarget),
363 recipient = button.data('whatever'),
364 modal = $(this);
365
366 modal.find('.modal-title').text('New message to ' + recipient);
367 modal.find('.modal-body input').val(recipient);
368 });
369
370 $('[data-toggle="tooltip"]').tooltip({
371 container: 'body'
372 });
373
374 $('[data-toggle="popover"]').popover();
375
376 $('.carousel').carousel();
377
378 if (wind_.width() >= 992) {
379 $('.card-scroll').niceScroll();
380 $('.table-responsive').niceScroll();
381 $('.sidebar-group .sidebar').niceScroll();
382
383 $('.app-block .app-content .app-lists').niceScroll();
384 $('.app-block .app-sidebar .app-sidebar-menu').niceScroll();
385 $('.chat-block .chat-sidebar .chat-sidebar-content').niceScroll();
386 var chat_messages = $('.chat-block .chat-content .messages');
387 if (chat_messages.length) {
388 chat_messages.niceScroll({
389 horizrailenabled: false
390 });
391 chat_messages.getNiceScroll(0).doScrollTop(chat_messages.get(0).scrollHeight, -1);
392 }
393 }
394
395 if (!body_.hasClass('small-navigation') && !body_.hasClass('horizontal-navigation') && wind_.width() >= 992) {
396 $('.navigation .navigation-menu-body').niceScroll();
397 }
398
399 $('.dropdown-menu ul.list-group').niceScroll();
400})(jQuery);
Note: See TracBrowser for help on using the repository browser.