Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.03 KB | None | 0 0
  1. (function($){
  2.  
  3. "use strict";
  4.  
  5. window.themeFrontCore = {
  6.  
  7. /**
  8. Constructor
  9. **/
  10. initialize: function() {
  11.  
  12. var self = this;
  13.  
  14. $(document).ready(function(){
  15. self.build();
  16. self.events();
  17. });
  18.  
  19. },
  20. /**
  21. Build page elements, plugins init
  22. **/
  23. build: function() {
  24.  
  25. var self = this;
  26.  
  27. // Setup body classes
  28. this.setupDocumentClasses();
  29.  
  30. // page preloader
  31. this.initPreloader();
  32.  
  33. // Add additional markup for form inputs
  34. this.wrapFormInputs();
  35.  
  36. // Headroom
  37. this.setupHeader();
  38.  
  39. // Setup home sections
  40. this.setupHomeSections();
  41.  
  42. // Setup animations
  43. this.setupAnimations();
  44.  
  45. // Create a slider
  46. this.setupSlider();
  47.  
  48. // Setup hero sections
  49. this.setupHeroSections();
  50.  
  51. // Setup menus
  52. this.setupMenu();
  53.  
  54. // Setup carousels
  55. this.setupCarousels();
  56.  
  57. // Setup tabs
  58. this.setupTabs();
  59.  
  60. // Setup footer
  61. this.setupFooter();
  62.  
  63. // Setup one-page scrolling
  64. this.setupOnePage();
  65.  
  66. // Go Top link
  67. this.setupGoTop();
  68.  
  69. // Lazy YouTube videos
  70. this.setupVideos();
  71.  
  72. // Portfolio Galleries
  73. this.setupPortfolio();
  74.  
  75. // Init Lightbox
  76. this.setupLightbox();
  77.  
  78. // Contact form sender
  79. this.bindContactForm();
  80.  
  81. // sudmit form sender
  82. this.bindSignupForm();
  83.  
  84. },
  85. /**
  86. Set page events
  87. **/
  88. events: function() {
  89.  
  90. var self = this;
  91.  
  92. // Force page scroll position to top at page refresh
  93. $(window).on('beforeunload', function(){
  94. $(window).scrollTop(0);
  95. });
  96.  
  97. // Re-init some sections of window resize
  98. $( window ).on( 'resize', function() {
  99. self.setupHeroSections();
  100. self.setupFooter();
  101. self.setupHomeSections();
  102. });
  103.  
  104. // Skip intro
  105. $('#skip-intro').on( 'click', function() {
  106. $('html, body').animate({
  107. scrollTop: $("#content").offset().top - 80
  108. }, 800);
  109. return false;
  110. });
  111.  
  112. // Comment reply link
  113. $('.reply-link').on( 'click', function() {
  114. $('html, body').animate({
  115. scrollTop: $("#comment-form").offset().top
  116. }, 2000);
  117. return false;
  118. });
  119.  
  120. },
  121. /**************************************************************************************************************************************************/
  122. /** init preloader **/
  123. initPreloader: function() {
  124.  
  125. // Close preloader
  126. $(window).on( 'load', function() {
  127.  
  128. if( $('body.preloader').length ) {
  129.  
  130. $('body').waitForImages({
  131. waitForAll: true,
  132. finished: function() {
  133. $('#preloader').fadeOut( 1200, function() {
  134. $('body.preloader').removeClass('preloader');
  135. $(this).remove();
  136.  
  137. if (location.hash) {
  138. $('html, body').animate({
  139. scrollTop: $( location.hash ).offset().top
  140. }, 200);
  141. }
  142.  
  143. });
  144.  
  145.  
  146. }
  147. });
  148.  
  149. if( $('.ie7, .ie8, .ie9, .ie10').length ) {
  150. $('#preloader').remove();
  151. $('body').removeClass('preloader');
  152. }
  153.  
  154. }
  155. });
  156.  
  157. },
  158. /** setup documents classes **/
  159. setupDocumentClasses: function() {
  160.  
  161. $('html').removeClass('no-js');
  162.  
  163. // Detect mobile browser
  164. if( (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) || (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.platform)) ) {
  165. $('html').addClass('mobile');
  166. }
  167.  
  168. // Detect MAC
  169. if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Mac') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
  170. $('html').addClass('mac');
  171. }
  172.  
  173. // Detect IE
  174. if (navigator.appName == "Microsoft Internet Explorer") {
  175. var ie = true;
  176. var ua = navigator.userAgent;
  177. var re = new RegExp("MSIE ([0-9]{1,}[.0-9]{0,})");
  178. if (re.exec(ua) != null) {
  179. var ieVersion = parseInt(RegExp.$1);
  180. $('html').addClass('ie' + ieVersion );
  181. }
  182. }
  183.  
  184. },
  185. /** wrap inputs with additional markup **/
  186. wrapFormInputs: function() {
  187.  
  188. var $inputs = $('input[type=text], input[type=number], input[type=password], input[type=email], input[type=search], input[type=tel], input[type=url], textarea, select');
  189.  
  190. $inputs.wrap('<div class="input-wrapper"></div>');
  191.  
  192. $inputs.on( 'focus', function() {
  193. $(this).parents('.input-wrapper').addClass('hovered');
  194. });
  195.  
  196. $inputs.on( 'focusout', function() {
  197. $(this).parents('.input-wrapper').removeClass('hovered');
  198. });
  199.  
  200. },
  201. /** sticky header **/
  202. setupHeader: function() {
  203.  
  204. $(".fixed-header #header, .transparent-header #header").headroom({
  205. "offset": 200,
  206. "tolerance": 0,
  207. "classes": {
  208. "initial": "animated",
  209. "pinned": "headroom--pinned",
  210. "unpinned": "headroom--unpinned"
  211. }
  212. });
  213.  
  214. },
  215. /** home slider **/
  216. setupSlider: function() {
  217.  
  218. if( $('#slider').length ) {
  219.  
  220. var slider = sequence( document.getElementById("slider"), {
  221. pagination: true,
  222. swipeNavigation: true,
  223. swipeEvents: {
  224. left: function(sequence) {sequence.next();},
  225. right: function(sequence) {sequence.prev();}
  226. }
  227. });
  228.  
  229. $('.skip-slider').on( 'click', function() {
  230. $('html, body').animate({
  231. scrollTop: $(window).height()
  232. }, 800);
  233. return false;
  234. });
  235.  
  236. }
  237.  
  238. },
  239. /** fix slider height **/
  240. setupHomeSections: function() {
  241.  
  242. var windowHeight = $(window).height();
  243. $(".home .section").css('min-height', windowHeight + 'px' );
  244.  
  245. },
  246. /** animations **/
  247. setupAnimations: function() {
  248.  
  249. var wow = new WOW({
  250. boxClass: 'wow',
  251. animateClass: 'animated',
  252. offset: 0,
  253. mobile: true,
  254. live: true,
  255. callback: function(box) {
  256.  
  257. var $box = $(box);
  258.  
  259. if( $box.hasClass('animationNuminate') ) {
  260. $box.each( function() {
  261. var $item = $(this);
  262. var to = $item.data('to');
  263.  
  264. $item.numinate({ format: '%counter%', from: 1, to: to, runningInterval: 5, stepUnit: 5});
  265. });
  266. }
  267.  
  268. }
  269. });
  270.  
  271. wow.init();
  272.  
  273. },
  274. /** hero sections **/
  275. setupHeroSections: function() {
  276.  
  277. var $hero = $('#hero');
  278.  
  279. if( $hero.length ) {
  280.  
  281. var heroHeight = $hero.height(),
  282. $heroText = $hero.find('.intro-text'),
  283. heroTextHeight = $heroText.height();
  284.  
  285. $heroText.css( 'margin-top', '-' + heroTextHeight / 2 + 'px' );
  286.  
  287. }
  288.  
  289. },
  290. /** mobile responsive header menu **/
  291. setupMenu: function() {
  292.  
  293. // Mobile menu effects
  294. var $menu = $( '#header-nav' );
  295. $menu.dlmenu({
  296. 'backLabel' : $menu.data('back-label')
  297. });
  298.  
  299. },
  300. /** setup carousels **/
  301. setupCarousels: function() {
  302.  
  303. // Swiper carousel, news posts
  304. $('.news-carousel').swiper({
  305. loop: true,
  306. pagination: '.swiper-pagination',
  307. freeMode: true,
  308. spaceBetween: 30,
  309. slidesPerView: 'auto',
  310. paginationClickable: true
  311. });
  312.  
  313. // Swiper carousel, screenshots
  314. $('.screenshots-carousel').swiper({
  315. loop: true,
  316. spaceBetween: 0,
  317. centeredSlides: true,
  318. slidesPerView: 'auto'
  319. });
  320.  
  321. // OWL carousel
  322. $('.owl-carousel').owlCarousel({
  323. items: 1,
  324. navigation: true,
  325. navigationText: ['', ''],
  326. singleItem: true,
  327. autoHeight: true,
  328. transitionStyle: 'fade'
  329. });
  330.  
  331. setInterval(function(){
  332. $(".owl-carousel").each( function(){
  333. $(this).data('owlCarousel').updateVars();
  334. });
  335. },1500);
  336.  
  337. // Team members carousel
  338. var teamCarousel = $('#team .items').owlCarousel({
  339. items: 1,
  340. singleItem: true,
  341. transitionStyle: 'fade',
  342. afterAction: function( carousel ) {
  343.  
  344. var newBg = carousel.find('.item').eq( this.owl.currentItem ).data('bg'),
  345. $parentSection = carousel.parents('.section').css('background-image', 'url(' + newBg + ')');
  346.  
  347. $('#team .team-pagination a').removeClass('current');
  348. $('#team .team-pagination a').eq( this.owl.currentItem ).addClass('current');
  349.  
  350. }
  351. }).data('owlCarousel');
  352.  
  353. // Team carousel custom pagination
  354. $('#team .team-pagination a').on( 'click', function() {
  355.  
  356. var slideNum = $('#team .team-pagination a').index( $(this) );
  357. teamCarousel.goTo( slideNum );
  358.  
  359. return false;
  360. });
  361.  
  362. },
  363. /** tabs script **/
  364. setupTabs: function() {
  365.  
  366. $('.services').each( function() {
  367.  
  368. var $tabs = $(this);
  369. var $pagination = $tabs.next('.services-pagination').find('.tab-link');
  370.  
  371. $pagination.on( 'click', function() {
  372.  
  373. var target = $(this).attr('href');
  374. var $target = $( target );
  375. $tabs.find('.service-item').hide().removeClass('selected');
  376.  
  377. var bgImg = $target.data('image');
  378.  
  379. $target.fadeIn(300, function() {
  380. $target.addClass('selected');
  381.  
  382. $('html, body').animate({
  383. scrollTop: $target.offset().top - 20
  384. }, 800);
  385.  
  386. });
  387.  
  388. $pagination.removeClass('selected');
  389.  
  390. $(this).addClass('selected');
  391.  
  392. return false;
  393. });
  394.  
  395. });
  396.  
  397. },
  398. /** setup footer **/
  399. setupFooter: function() {
  400.  
  401. var self = this;
  402.  
  403. if( $( window ).width() < 992 ) {
  404. $('div.section').last().css('margin-bottom', '0px');
  405. } else {
  406.  
  407. if( $('body').hasClass('parallax-footer') && $( window ).width() >= 992 ) {
  408. var $footer = $('#footer');
  409.  
  410. $footer.waitForImages({
  411. waitForAll: true,
  412. finished: function() {
  413.  
  414. $('#content-wrapper').css( 'margin-bottom', $footer.height() + 'px' );
  415.  
  416. }
  417. });
  418.  
  419. }
  420.  
  421. }
  422.  
  423. },
  424. /** setup one-page scroller **/
  425. setupOnePage: function() {
  426.  
  427. var self = this;
  428.  
  429. // Preload images
  430. if( $('body.home-agency').length ) {
  431.  
  432. self.preloadImages([
  433. 'images/demo-images/home_1_slider_1.jpg',
  434. 'images/demo-images/home_1_slider_2.jpg',
  435. 'images/demo-images/home_1_slider_3.jpg',
  436. 'images/demo-images/home_1_slider_4.jpg',
  437. 'images/demo-images/home_1_slider_5.jpg'
  438. ]);
  439.  
  440. }
  441.  
  442. // One-page navigation
  443. if( $('body.one-page').length ) {
  444.  
  445. $('body.one-page #header-menu').singlePageNav({
  446. currentClass: 'current-link',
  447. updateHash: true,
  448. offset: 50,
  449. speed: 1100,
  450. filter: ':not(.external)',
  451. easing: 'easeOutBack'
  452. });
  453.  
  454. }
  455.  
  456. },
  457. /** go top link **/
  458. setupGoTop: function() {
  459. $.scrollUp({
  460. scrollName: 'scrollUp',
  461. topDistance: '1000',
  462. topSpeed: 100,
  463. animation: 'slide', // Fade, slide, none
  464. animationInSpeed: 500, // Animation in speed (ms)
  465. animationOutSpeed: 500, // Animation out speed (ms)
  466. scrollText: '', // Text for element
  467. activeOverlay: false, // Set CSS color to display scrollUp active point, e.g '#00FFFF'
  468. });
  469. },
  470. /** lazy YouTube videos **/
  471. setupVideos: function() {
  472.  
  473. var $videos = $('.lazy-video');
  474.  
  475. $videos.each( function() {
  476. $(this).lazyYT();
  477. });
  478.  
  479. },
  480. /** Portfolio galleries **/
  481. setupPortfolio: function() {
  482.  
  483. $('.portfolio').each( function() {
  484.  
  485. var $portfolio = $(this);
  486. var $galleryElem = $portfolio.find('.portfolio-gallery');
  487. var gallery = $galleryElem.justifiedGallery({
  488. sizeRangeSuffixes: {},
  489. rowHeight: 400,
  490. maxRowHeight: 200,
  491. margins: 0,
  492. captionSettings: {
  493. visibleOpacity: 0.9,
  494. animationDuration: 300,
  495. nonVisibleOpacity: 0.0
  496. },
  497. captions: true
  498. });
  499.  
  500. $portfolio.find('.portfolio-header .filters a').on( 'click touchstart', function() {
  501.  
  502. $portfolio.find('.portfolio-header .filters a').removeClass('selected');
  503.  
  504. $(this).addClass('selected');
  505.  
  506. var filterClass = $(this).data('filter');
  507.  
  508. $galleryElem.justifiedGallery({
  509. 'filter': filterClass
  510. });
  511.  
  512. return false;
  513. });
  514.  
  515. });
  516.  
  517. },
  518. /** setup LightBox **/
  519. setupLightbox: function() {
  520.  
  521. // init lightbox
  522. if( $('.lightbox').length ) {
  523. $('.lightbox').nivoLightbox({
  524. effect: 'fadeScale'
  525. });
  526. }
  527.  
  528. },
  529.  
  530. /** send a contact form **/
  531. bindSignupForm: function() {
  532.  
  533. var self = this;
  534.  
  535. $('#signup-form').submit( function() {
  536.  
  537. var form = $(this);
  538.  
  539. var nameInput = $('#input-name');
  540. var name = nameInput.val();
  541.  
  542. var emailInput = $('#input-email');
  543. var email = emailInput.val();
  544.  
  545. var phoneInput = $('#input-phone');
  546. var phone = phoneInput.val();
  547.  
  548.  
  549.  
  550. var messageInput = $('#input-message');
  551. var message = messageInput.val();
  552.  
  553. if( $.trim( name ) == '' ) {
  554. nameInput.focus();
  555. return false;
  556. }
  557.  
  558. if( $.trim( email ) == '' || !self.isValidEmailAddress( email ) ) {
  559. emailInput.focus();
  560. return false;
  561. }
  562.  
  563. if( $.trim( message ) == '' ) {
  564. messageInput.focus();
  565. return false;
  566. }
  567.  
  568. $.ajax({
  569. url: 'signup-form.php',
  570. type: "POST",
  571. data: {
  572. 'name' : name,
  573. 'email' : email,
  574. 'phone' : phone,
  575.  
  576. 'message' : message
  577. },
  578. beforeSend: function() {
  579. $('#signup-form input, #signup-form textarea, #signup-form button').attr('disabled', 'disabled');
  580. $('#signup-form').fadeTo(500, '0.7');
  581. },
  582. success: function() {
  583.  
  584. form.html( '<h4>Din tilmelding er modtaget, Tak for tilmeldingen!</h4>' ).css('opacity', '1');
  585.  
  586. }
  587. });
  588.  
  589. return false;
  590. });
  591.  
  592. },
  593.  
  594. /** send a contact form **/
  595. bindContactForm: function() {
  596.  
  597. var self = this;
  598.  
  599. $('#contact-form').submit( function() {
  600.  
  601. var form = $(this);
  602.  
  603. var nameInput = $('#input-name-contact');
  604. var name = nameInput.val();
  605.  
  606. var emailInput = $('#input-email-contact');
  607. var email = emailInput.val();
  608.  
  609. var phoneInput = $('#input-phone-contact');
  610. var phone = phoneInput.val();
  611.  
  612. var subject = $('#input-subject-contact').val();
  613.  
  614. var messageInput = $('#input-message-contact');
  615. var message = messageInput.val();
  616.  
  617. if( $.trim( name ) == '' ) {
  618. nameInput.focus();
  619. return false;
  620. }
  621.  
  622. if( $.trim( email ) == '' || !self.isValidEmailAddress( email ) ) {
  623. emailInput.focus();
  624. return false;
  625. }
  626.  
  627. if( $.trim( message ) == '' ) {
  628. messageInput.focus();
  629. return false;
  630. }
  631.  
  632. $.ajax({
  633. url: 'contact-form.php',
  634. type: "POST",
  635. data: {
  636. 'name' : name,
  637. 'email' : email,
  638. 'phone' : phone,
  639. 'subject' : subject,
  640. 'message' : message
  641. },
  642. beforeSend: function() {
  643. $('#contact-form input, #contact-form textarea, #contact-form button').attr('disabled', 'disabled');
  644. $('#contact-form').fadeTo(500, '0.7');
  645. },
  646. success: function() {
  647.  
  648. form.html( '<h4>Din besked blev sendt, vi vender tilbage indenfor 24 timer!</h4>' ).css('opacity', '1');
  649.  
  650. }
  651. });
  652.  
  653. return false;
  654. });
  655.  
  656. },
  657. /**************************************************************************************************************************
  658. Utils
  659. **************************************************************************************************************************/
  660. /**
  661. Check email address
  662. **/
  663. isValidEmailAddress: function( emailAddress ) {
  664. var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
  665. return pattern.test( emailAddress );
  666. },
  667. preloadImages: function(arrayOfImages) {
  668. $(arrayOfImages).each(function(){
  669. $('<img/>')[0].src = this;
  670. });
  671. }
  672.  
  673. }
  674.  
  675. window.themeFrontCore.initialize();
  676.  
  677. })( window.jQuery );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement