Diligent web site
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

custom.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. "use strict";
  2. function isOnScreen(elem) {
  3. // if the element doesn't exist, abort
  4. if( elem.length == 0 ) {
  5. return;
  6. }
  7. var $window = jQuery(window)
  8. var viewport_top = $window.scrollTop()
  9. var viewport_height = $window.height()
  10. var viewport_bottom = viewport_top + viewport_height
  11. var $elem = jQuery(elem)
  12. var top = $elem.offset().top
  13. var height = $elem.height()
  14. var bottom = top + height
  15. return (top >= viewport_top && top < viewport_bottom) ||
  16. (bottom > viewport_top && bottom <= viewport_bottom) ||
  17. (height > viewport_height && top <= viewport_top && bottom >= viewport_bottom)
  18. }
  19. // start custom scripts
  20. (function($) {
  21. jQuery(document).ready(function($){
  22. /*========== Swicher ==========*/
  23. /*========== Progress bar ==========*/
  24. function animate() {
  25. $(".progress-bar").each(function(){
  26. var progressValue = $(this).attr('data-value');
  27. $(this).animate({width: progressValue +'%'}, 6000);
  28. });
  29. }
  30. function scrollToID(url, id, speed) {
  31. if(url!==null)
  32. {
  33. window.location.href = url;
  34. }
  35. var offSet = 50;
  36. var obj = jQuery(id).offset();
  37. var targetOffset = 0;
  38. if(jQuery(id).length)
  39. {
  40. targetOffset = jQuery(id).offset().top - offSet;
  41. }
  42. jQuery('html,body').animate({ scrollTop: targetOffset }, speed);
  43. }
  44. //homepage
  45. $('.link-expand').on('click', function()
  46. {
  47. $('.dropdown-menu').addClass('active');
  48. });
  49. //homepage end
  50. //career
  51. var expand = false;
  52. $('.position').on('click', function(ev) {
  53. //ev.preventDefault();
  54. $(this).find(".chev").toggleClass('chevron--down chevron--up');
  55. $(this).closest(".position-cont").find(".collapse").toggleClass("show");
  56. $(this).toggleClass("active"); //css({"background-color": "#993c95", "color": "white"});
  57. expand= !expand;
  58. });
  59. $('.chev').on('click', function(ev) {
  60. //ev.preventDefault();
  61. $(this).toggleClass('chevron--down chevron--up');
  62. $(this).closest(".position-cont").find(".collapse").toggleClass("show");
  63. $(this).closest(".position").toggleClass("active"); //css({"background-color": "#993c95", "color": "white"});
  64. expand= !expand;
  65. });
  66. //end career
  67. //apply
  68. // $(".resume-cont").click(function()
  69. // {
  70. // $(".resume-file").click();
  71. // });
  72. if( $("#positions").length)
  73. {
  74. $("#positions").selectize({
  75. create: true,
  76. sortField: {
  77. field: 'text',
  78. direction: 'asc'
  79. },
  80. });
  81. }
  82. var resume = "";
  83. $("input:file").change(function (event){
  84. var fileName = $(this).val();
  85. var reader = new FileReader();
  86. reader.onload = function(e)
  87. {
  88. resume = e.target.result;
  89. }
  90. reader.readAsDataURL(this.files[0]);
  91. var fileExtensionAt = fileName.lastIndexOf(".") + 1;
  92. console.log(fileName.substring(fileExtension, fileName.length));
  93. var fileExtension = fileName.substring(fileExtensionAt, fileName.length);
  94. if(fileName!="" && fileExtension == "doc" || fileExtension == "docx" || fileExtension == "pdf")
  95. {
  96. var from = fileName.lastIndexOf("\\") + 1;
  97. var to = fileName.length ;
  98. fileName = fileName.substring(from, to);
  99. }
  100. else{
  101. fileName="Choose file";
  102. }
  103. $(".resume-file-cont label").html(fileName);
  104. });
  105. $(".btn-delete-file").click(function(e)
  106. {
  107. e.preventDefault();
  108. $(".resume-file-cont label").html("Choose file");
  109. });
  110. var btn_apply = $("#apply-submit");
  111. var apply_form = $("#apply-form");
  112. apply_form.bind('submit', function(ev) {
  113. ev.preventDefault();
  114. var resume_file = document.getElementById("resume-file").files[0];
  115. console.log(resume.toString());
  116. var data = new FormData(document.getElementById("apply-form"));
  117. data.append("resume", "'" + resume + "'");
  118. data.append("resume-file", resume_file);
  119. $.ajax({
  120. url: "job_apply.php?call=upload",
  121. method: "POST",
  122. data: data,
  123. contentType: false,
  124. cache: false,
  125. processData:false,
  126. success : function(data) {
  127. console.log(data)
  128. $(".apply-msg").addClass("active");
  129. },
  130. error: function(error)
  131. {
  132. console.log(console.error);
  133. }
  134. });
  135. });
  136. //apply end
  137. //contact form
  138. var form = document.getElementById("contact-form");
  139. var button = jQuery("#contact-form #submit");
  140. var status = jQuery(".log");
  141. function success(data)
  142. {
  143. form.append(xhr.response);
  144. }
  145. function error()
  146. {
  147. form.append(xhr.response);
  148. }
  149. button.on("submit", function(ev)
  150. {
  151. var data = new FormData(form);
  152. ajax(form.method, form.action, data, success, error);
  153. });
  154. function ajax(method, url, data, success, error) {
  155. var xhr = new XMLHttpRequest();
  156. xhr.open(method, url);
  157. xhr.setRequestHeader("Accept", "application/json");
  158. xhr.onreadystatechange = function() {
  159. if (xhr.readyState !== XMLHttpRequest.DONE) return;
  160. if (xhr.status === 200) {
  161. success();
  162. } else {
  163. error();
  164. }
  165. };
  166. xhr.send(data);
  167. }
  168. //end contact form
  169. // $('#contact-wrap').waypoint(function() {
  170. // animate();
  171. // });
  172. //nikola
  173. $('.clear_storage').on('click', function(e){
  174. window.localStorage.clear();
  175. });
  176. var get_id = localStorage.getItem('pg_id');
  177. var setupUrl = false;
  178. // check page id, then scroll to its div
  179. if(get_id)
  180. {
  181. scrollToID(null, get_id, 300);
  182. }
  183. jQuery(document).ready(function()
  184. {
  185. var loc = window.location;
  186. if(!get_id && loc.pathname.substring(loc.pathname.lastIndexOf('/') + 1, loc.pathname.length) == 'index.html' && !setupUrl)
  187. {
  188. var sectionType = window.location.hash;
  189. console.log(sectionType.substr(sectionType.indexOf('=') + 1, sectionType.length ) );
  190. var id = sectionType.substr(sectionType.indexOf('=') + 1, sectionType.length );
  191. id+="-section";
  192. if(id != "" && id != null)
  193. {
  194. //console.log(loc.pathname);
  195. console.log(id);
  196. var nav_link = "#navigation ."+ id +" > a";
  197. console.log(item);
  198. var item = $(nav_link);
  199. console.log(item);
  200. item.trigger('click');
  201. //localStorage.setItem('pg_id', id);
  202. //scrollToID('index.html', "#"+id, 300);
  203. setupUrl =true;;
  204. }
  205. }
  206. });
  207. // click event to scroll to div
  208. //section link in nav which refer to section on homepage
  209. $('.home_link').on('click', function(e){
  210. e.preventDefault();
  211. var id = '#'+$(this).data('id');
  212. localStorage.setItem('pg_id', id);
  213. var url = $(this).attr("href");
  214. scrollToID(url, id, 300);
  215. });
  216. //Link from our partners section on homepage which refer to section on portfolio page
  217. $('.partners_link').on('click', function(e){
  218. e.preventDefault();
  219. var id = '#'+$(this).data('id');
  220. localStorage.setItem('pg_id', id);
  221. var url = $(this).attr("href");
  222. scrollToID(url, id, 300);
  223. });
  224. var siteUrl = window.location.hash;
  225. window.addEventListener('scroll', function(e) {
  226. var loc = window.location;
  227. if(loc.pathname.substring(loc.pathname.lastIndexOf('/') + 1, loc.pathname.length) == 'index.html')
  228. {
  229. var newUrl = "";
  230. if( isOnScreen( $( '#intro-section' ) ) ) { /* Pass element id/class you want to check */
  231. $("nav li.active").removeClass("active").find('.nav-active-mark').remove();
  232. $("nav li.intro-section").addClass("active").append('<span class="nav-active-mark"></span>');
  233. //newUrl = siteUrl.substring(0, siteUrl.indexOf("/"));
  234. parent.location.hash = "?section=intro";
  235. }
  236. if( isOnScreen( $( '#about-section' ) ) ) { /* Pass element id/class you want to check */
  237. $("nav li.active").removeClass("active").find('.nav-active-mark').remove();
  238. $("nav li.about-section").addClass("active").append('<span class="nav-active-mark"></span>');
  239. //newUrl = siteUrl.substring(0, siteUrl.lastIndexOf("/") -1) + "about-wrap";
  240. parent.location.hash = "?section=about";
  241. //console.log(siteUrl.substring(0, siteUrl.lastIndexOf("/")));
  242. }
  243. if( isOnScreen( $( '#our_partners-section' ) ) ) { /* Pass element id/class you want to check */
  244. $("nav li.active").removeClass("active").find('.nav-active-mark').remove();
  245. $("nav li.our_partners-section").addClass("active").append('<span class="nav-active-mark"></span>');
  246. //newUrl = siteUrl.substring(0, siteUrl.lastIndexOf("/") -1) + "our_partners-wrap";
  247. parent.location.hash = "?section=our_partners";
  248. }
  249. if( isOnScreen( $( '#services-section' ) ) ) { /* Pass element id/class you want to check */
  250. $("nav li.active").removeClass("active").find('.nav-active-mark').remove();
  251. $("nav li.services-section").addClass("active").append('<span class="nav-active-mark"></span>');
  252. //newUrl = siteUrl.substring(0, siteUrl.lastIndexOf("/") -1) + "services";
  253. parent.location.hash = "?section=services";
  254. }
  255. if( isOnScreen( $( '#teams-wrap' ) ) ) { /* Pass element id/class you want to check */
  256. $("nav li.active").removeClass("active").find('.nav-active-mark').remove();
  257. $("nav li.teams-wrap").addClass("active").append('<span class="nav-active-mark"></span>');
  258. newUrl = siteUrl.substring(0, siteUrl.lastIndexOf("/") -1) + "teams-wrap";
  259. parent.location.hash = "?section=teams"
  260. }
  261. if( isOnScreen( $( '#contact-section' ) ) ) { /* Pass element id/class you want to check */
  262. $("nav li.active").removeClass("active").find('.nav-active-mark').remove();
  263. $("nav li.contact-section").addClass("active").append('<span class="nav-active-mark"></span>');
  264. //newUrl = siteUrl.substring(0, siteUrl.lastIndexOf("/") -1) + "contact-wrap";
  265. parent.location.hash = "?section=contact"
  266. }
  267. //history.pushState({}, null, newUrl);
  268. }
  269. });
  270. //nikola
  271. /*========== Disables ==========*/
  272. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry/i.test(navigator.userAgent) ) {
  273. $('#animate_css_file, #wow_js_file').remove();
  274. } else {
  275. /*========== WOW Animations ==========*/
  276. var wow = new WOW(
  277. {
  278. animateClass: 'animated',
  279. offset: 100
  280. }
  281. );
  282. wow.init();
  283. }
  284. /*========== Logo Retina ==========*/
  285. if( window.devicePixelRatio > 1 ) {
  286. var logoWidth = $('#logo img').width();
  287. var logoHeight = $('#logo img').height();
  288. $('#logo img').attr("src", "images/logo@2x.png");
  289. $('#logo img').css({ 'width': logoWidth , 'height': logoHeight });
  290. }
  291. /*========== Team Item Hover ==========*/
  292. $('.team-item').each(function(){
  293. var memberImage = $(this).find('.member-face').attr('style');
  294. var current = $(this).find('.change-color');
  295. $(this).find('.hex-in2.outer-hex').first().hover(function(){
  296. $(this).find('.member-face').css('background','#000');
  297. $(current).css('background-color','#f3b202');
  298. $(this).find('.socials').show();
  299. },function(){
  300. $(this).find('.socials').hide();
  301. $(this).find('.member-face').attr('style', memberImage);
  302. $(current).css('background-color','#000');
  303. });
  304. });
  305. /*========== Gallery Item Hover ==========*/
  306. $('.gallery-item').hover(function(){
  307. $(this).find('.gallery-info').stop(true,true).animate({ "top": "0" } );
  308. },function(){
  309. $(this).find('.gallery-info').stop(true,true).animate({ "top": "-999" } );
  310. });
  311. /*========== FlexSlider ==========*/
  312. $('.flexslider').flexslider({
  313. animation: "fade",
  314. animationLoop: false,
  315. directionNav: false,
  316. slideshow: false
  317. });
  318. /*========== Pie Chart ==========*/
  319. $('.days').waypoint(function() {
  320. $('.chart').easyPieChart({
  321. easing: 'easeOutBounce',
  322. barColor: '#f3b202',
  323. trackColor: '#595959',
  324. lineWidth: '18',
  325. lineCap: 'butt',
  326. size: '160',
  327. scaleColor: false,
  328. onStep: function(from, to, percent) {
  329. $(this.el).find('.percent').text(Math.round(percent));
  330. }
  331. });
  332. });
  333. /*========== Smooth Scroll ==========*/
  334. $('a[href*=#]:not([href=#])').click(function() {
  335. $("li.active").removeClass("active").find('.nav-active-mark').remove();
  336. $(this).parent().addClass('active').end().append('<span class="nav-active-mark"></span>');
  337. if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  338. var target = $(this.hash);
  339. target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
  340. if (target.length) {
  341. $('html,body').animate({
  342. scrollTop: target.offset().top - 53
  343. }, 1000);
  344. return false;
  345. }
  346. }
  347. });
  348. /*========== Graph Bars Animate ==========*/
  349. $('.days').waypoint(function() {
  350. $('.graph ul li.bar').each(function() {
  351. var curBarHeight = $(this).data('bar-height');
  352. $(this).animate({ height: curBarHeight }, 2000, "easeInOutBack");
  353. });
  354. });
  355. /*========== Intro Note Box Tooltip ==========*/
  356. /*$('.note-1').hover(function(){
  357. $(this).find('.note-tooltip').fadeIn();
  358. },function(){
  359. $(this).find('.note-tooltip').fadeOut();
  360. });
  361. */
  362. /*========== PrettyPhoto ==========*/
  363. $("a[data-rel^='prettyPhoto']").prettyPhoto({theme:'dark_rounded', hook: 'data-rel'});
  364. /*========== Flickr ==========*/
  365. var flickrImageSrc = [ ];
  366. var flickrLink = [ ];
  367. $('.flickr_badge_image').each(function(i){
  368. flickrImageSrc[i] = $(this).find('img').attr('src');
  369. flickrLink[i] = $(this).find('a').attr('href');
  370. });
  371. $('.flickr-item').each(function(i){
  372. $(this).find('.hex-area').css('background-image', 'url(' + flickrImageSrc[i] + ')');
  373. $(this).find('.flickr-link').attr('href', flickrLink[i] );
  374. });
  375. /*========== Window Resize ==========*/
  376. var windowWidth = $(window).width();
  377. var numberOfHexagon = windowWidth / 106;
  378. var offsetBackground = ((numberOfHexagon - 14) * 106 ) /2;
  379. $('#hexagon-overlay').css('background-position', offsetBackground + 'px' + ' ' + 'top');
  380. $(window).resize(function() {
  381. var currentWindowWidth = $(window).width();
  382. if(currentWindowWidth <= 940) return;
  383. $('#hexagon-overlay').css('background-position', - ( ( (windowWidth - currentWindowWidth)/2 ) - offsetBackground ) + 'px' + ' ' + 'top');
  384. });
  385. /*========== Mobile Menu ==========*/
  386. $('.mobile-nav-toggle').on('click',function(){
  387. if($(this).attr('class') == 'mobile-nav-toggle deactive') {
  388. $('#mobile-navigation').fadeIn();
  389. $(this).removeClass('deactive');
  390. } else {
  391. $('#mobile-navigation').fadeOut();
  392. $(this).addClass('deactive');
  393. }
  394. });
  395. $("#mobile-navigation li a").on("click", function(){
  396. $('#mobile-navigation').fadeOut();
  397. $(".mobile-nav-toggle").addClass('deactive');
  398. });
  399. $(window).resize(function(){
  400. var w = $(window).width();
  401. if(w > 767) {
  402. $('#mobile-navigation').fadeOut();
  403. $(".mobile-nav-toggle").addClass('deactive');
  404. }
  405. });
  406. /*========== Contact Form Validation ==========*/
  407. function isValidEmailAddress(emailAddress) {
  408. var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
  409. return pattern.test(emailAddress);
  410. }
  411. // $('.contact-form form').submit(function() {
  412. // var hasError = false;
  413. // var comment = $('#message-txt').val();
  414. // if ($.trim(comment) == '') {
  415. // $('#message-txt').addClass('error');
  416. // $('#message-txt').focus();
  417. // hasError = true;
  418. // }
  419. // else {
  420. // $('#message-txt').removeClass('error');
  421. // }
  422. // var subject = $('#subject-txt').val();
  423. // if ($.trim(subject) == '') {
  424. // $('#subject-txt').addClass('error');
  425. // $('#subject-txt').focus();
  426. // hasError = true;
  427. // }
  428. // else {
  429. // $('#subject-txt').removeClass('error');
  430. // }
  431. // var emailVal = $('#email-txt').val();
  432. // if ($.trim(emailVal) == '' || !isValidEmailAddress(emailVal)) {
  433. // $('#email-txt').addClass('error');
  434. // $('#email-txt').focus();
  435. // hasError = true;
  436. // }
  437. // else {
  438. // $('#email-txt').removeClass('error');
  439. // }
  440. // var name = $('#name-txt').val();
  441. // if ($.trim(name) == '') {
  442. // $('#name-txt').addClass('error');
  443. // $('#name-txt').focus();
  444. // hasError = true;
  445. // }
  446. // else {
  447. // $('#name-txt').removeClass('error');
  448. // }
  449. // if (!hasError) {
  450. // $('#submit').fadeOut('normal', function(){
  451. // $('.loading').css({
  452. // display: "block"
  453. // });
  454. // });
  455. // // $.post($('.contact-form form').attr('action'), $('.contact-form form').serialize(), function(data){
  456. // // $('.log').html(data);
  457. // // $('.loading').remove();
  458. // // $('.contact-form form').slideUp('slow');
  459. // // });
  460. // }
  461. // return false;
  462. // });
  463. }); // end jquery init
  464. })(jQuery);