javascript


SUBMITTED BY: lewiswhite

DATE: March 29, 2019, midnight

FORMAT: Text only

SIZE: 15.3 kB

HITS: 1645

  1. (function($) {
  2. "use strict";
  3. $(document).ready(function(){
  4. /* ============== DETECT MOBILE DEVICES ============== */
  5. var isMobile = {
  6. Android: function() {
  7. return navigator.userAgent.match(/Android/i);
  8. },
  9. BlackBerry: function() {
  10. return navigator.userAgent.match(/BlackBerry/i);
  11. },
  12. iOS: function() {
  13. return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  14. },
  15. Opera: function() {
  16. return navigator.userAgent.match(/Opera Mini/i);
  17. },
  18. Windows: function() {
  19. return navigator.userAgent.match(/IEMobile/i);
  20. },
  21. any: function() {
  22. return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
  23. }
  24. };
  25. /* ======= VIDEO BG ======= */
  26. if($('#video-background').length > 0) {
  27. $('#video-background').appear(function() {
  28. if (isMobile.any()) jQuery('#video-background').remove();
  29. else jQuery('#video-background').get(0).play();
  30. });
  31. }
  32. /* ======= CURRENT MENU ITEM ======= */
  33. var i, sections, hash, element, pos, pos_sec, current_id, height_element, menu_h;
  34. var menu_h = $("#main_menu").css("height");
  35. menu_h = parseInt(menu_h,10);
  36. var height,
  37. pos,
  38. element_menu,
  39. id_slide;
  40. $(document).scroll(function(){
  41. pos = $(this).scrollTop();
  42. $(".slide-menu").each(function() {
  43. id_slide = $(this).attr("id");
  44. height = $(this).css("height");
  45. element_menu = $('#desktop-menu #nav a[href$="#'+id_slide+'"]:first');
  46. if($(this).offset().top <= pos + 100 && element_menu.length > 0) {
  47. $("#desktop-menu #nav li").removeAttr("id");
  48. element_menu.parent().attr("id","current_menu_item");
  49. }
  50. });
  51. });
  52. /* ======= CLEAR AJAX FORM ======= */
  53. if($("#form-ajax").is('*')) {
  54. $('#form-ajax')[0].reset();
  55. }
  56. /* ======= COMMENT FORM ======= */
  57. $("#post-comment-form textarea").val("Your message...");
  58. var def;
  59. var def2;
  60. $("#post-comment-form input[type='text']").focus(function () {
  61. def = $(this).val();
  62. if ($(this).val() == def ) {
  63. $(this).val("");
  64. }
  65. }).blur(function () {
  66. if ($(this).val() == '') {
  67. $(this).val(def);
  68. }
  69. });
  70. $("#post-comment-form textarea").focus(function () {
  71. def2 = $(this).val();
  72. if ($(this).val() == def2 ) {
  73. $(this).val("");
  74. }
  75. }).blur(function () {
  76. if ($(this).val() == '') {
  77. $(this).val(def2);
  78. }
  79. });
  80. /* ======= MOBILE MENU ======= */
  81. $(".menu-mobile-button").click(function() {
  82. if($("#mobile-menu").css("display") == "none") {
  83. $("#mobile-menu").slideDown(300);
  84. }
  85. else {
  86. $("#mobile-menu").slideUp(300);
  87. }
  88. });
  89. $("#mobile-menu a").click(function() {
  90. $("#mobile-menu").slideUp(300);
  91. });
  92. /* ======= BACK TO TOP ======= */
  93. $(window).scroll(function () {
  94. if ($(this).scrollTop() > 700) {
  95. $('#backtop').css("visibility","visible");
  96. $('#backtop').css("opacity",1);
  97. } else {
  98. $('#backtop').css("opacity",0);
  99. $('#backtop').css("visibility","hidden");
  100. }
  101. });
  102. // scroll body to 0px on click
  103. $('#backtop').click(function () {
  104. $('body,html').animate({
  105. scrollTop: 0
  106. }, 800);
  107. return false;
  108. });
  109. /* ======= SCROLL ITEMS ======= */
  110. $('a').click(function (e) {
  111. var target = this.hash,
  112. $target = $(target);
  113. if(this.hash) {
  114. e.preventDefault();
  115. if(jQuery(this).parent('.arrow-link').length > 0) {
  116. $('html, body').stop().animate( {
  117. 'scrollTop': $target.offset().top
  118. }, 900, 'swing', function () {
  119. } );
  120. }
  121. else {
  122. $('html, body').stop().animate( {
  123. 'scrollTop': $target.offset().top-81
  124. }, 900, 'swing', function () {
  125. } );
  126. }
  127. }
  128. } );
  129. /* ======= FITVIDS ======= */
  130. $(".media-post").fitVids();
  131. $(".fit").fitVids();
  132. /* ======= BAR GRAPH ======= */
  133. $('.bar').appear(function() {
  134. var layer = jQuery(".percent-layer", this).css("width");
  135. var parent = jQuery(this).css("width");
  136. var percent = parseInt(layer,10)*100/parseInt(parent,10);
  137. $(".percent-layer", this).css("width","0%");
  138. $(".percent-layer", this).stop().animate( { width: percent+"%" }, { duration: 2500 } );
  139. });
  140. /* ======= COUNTDOWN ======= */
  141. $('.number_container').appear(function() {
  142. var count_element = $(".number", this).html();
  143. $(".number", this).countTo({
  144. from: 0,
  145. to: count_element,
  146. speed: 2500,
  147. refreshInterval: 50,
  148. });
  149. });
  150. /* ======= CLIENT CAROUSEL ======= */
  151. $(".client-carousel").flexisel({
  152. visibleItems: 5
  153. });
  154. /* ======= ISOTOPE ======= */
  155. var $container = $('.portfolio-container');
  156. $container.isotope({
  157. filter: '*',
  158. animationOptions: {
  159. duration: 750,
  160. easing: 'linear',
  161. queue: false
  162. },
  163. });
  164. $('.portfolio-categories ul li a').click(function(){
  165. $('.portfolio-categories ul li .current').removeClass('current');
  166. $(this).addClass('current');
  167. var selector = $(this).attr('data-filter');
  168. $container.isotope({
  169. filter: selector,
  170. animationOptions: {
  171. duration: 750,
  172. easing: 'linear',
  173. queue: false
  174. }
  175. });
  176. return false;
  177. });
  178. var filtertoggle = $('body');
  179. $(window).load(function() {
  180. var hash = window.location.hash;
  181. $container.isotope('reLayout', function() {
  182. $("html, body").scrollTo(hash, 1000, { offset: -menu_h });
  183. });
  184. $(function(){
  185. setTimeout(function() {
  186. $container.isotope('reLayout');
  187. }, filtertoggle.hasClass("") ? 755: 755);
  188. });
  189. });
  190. $(window).resize(function() {
  191. $(function(){
  192. setTimeout(function() {
  193. $container.isotope('reLayout');
  194. }, filtertoggle.hasClass("") ? 755: 755);
  195. });
  196. });
  197. /* ======= RESPONSIVE SLIDES ======= */
  198. $(function() {
  199. $(".rslides-testimonials").responsiveSlides({
  200. nav: true,
  201. auto: false,
  202. prevText: "<i class='icon-angle-left'></i>",
  203. nextText: "<i class='icon-angle-right'></i>",
  204. navContainer: ".testimonials-navi"
  205. });
  206. });
  207. $(function() {
  208. $(".rslides-twitter").responsiveSlides({
  209. nav: true,
  210. auto: false,
  211. prevText: "<i class='icon-angle-left'></i>",
  212. nextText: "<i class='icon-angle-right'></i>",
  213. navContainer: ".navi-tweet"
  214. });
  215. });
  216. $(function() {
  217. $(".rslides-blog").responsiveSlides({
  218. nav: true,
  219. auto: true,
  220. prevText: "<i class='icon-angle-left'></i>",
  221. nextText: "<i class='icon-angle-right'></i>"
  222. });
  223. });
  224. /* ======= AJAX PORTFOLIO LOAD ======= */
  225. var toLoad;
  226. $('.portfolio-container a').click(function(){
  227. $(window).scrollTo( '.portfolio-works', 1000, { offset: -80 } );
  228. toLoad = $(this).attr('href');
  229. $('.ajax-portfolio-loader').slideDown(500);
  230. $.ajax({
  231. url: toLoad,
  232. success: function(data) {
  233. var content_ajax = $(data).find('#content-ajax').html();
  234. $(".portfolio-view .row").html(content_ajax);
  235. $(".ajax-portfolio-loader").slideUp(500, function() { $(".portfolio-view .row").slideDown(500, function() { $('.close-button').show(500); }); } );
  236. $(window).scrollTo( ".portfolio-view", 1000, { offset: -120 } );
  237. }
  238. });
  239. return false;
  240. });
  241. $(".close-button").click(function() {
  242. $('.portfolio-view .row').slideUp(500, function() { $('.portfolio-view .row').html(''); });
  243. $(this).hide('fast');
  244. $('.ajax-portfolio-loader').slideUp(500);
  245. });
  246. /* ======= AJAX EMAIL CONTACT ======= */
  247. $('#form-ajax').submit(function(){
  248. var errors = false;
  249. var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  250. var email_field = $("#email");
  251. var personal_field = $("#personal");
  252. var message_text = $("#message-contact");
  253. var website_field = $("#website");
  254. if(!emailReg.test($.trim(email_field.val())) || email_field.val() === '') {
  255. email_field.addClass("error-input");
  256. errors = true;
  257. }
  258. if(personal_field.val() === '') {
  259. personal_field.addClass("error-input");
  260. errors = true;
  261. }
  262. if(message_text.val() === '') {
  263. message_text.addClass('error-input');
  264. errors = true;
  265. }
  266. if(personal_field.val() === '') {
  267. personal_field.addClass('error-input');
  268. errors = true;
  269. }
  270. if(errors === false) {
  271. email_field.removeClass("error-input");
  272. personal_field.removeClass("error-input");
  273. message_text.removeClass("error-input");
  274. var formInput = $(this).serialize();
  275. $('input', this).attr('disabled','disabled');
  276. $.ajax({
  277. type: "POST",
  278. url: url_js,
  279. data: formInput,
  280. success: function(response) {
  281. if (response == "success")
  282. {
  283. $(".contact-form").slideUp("fast");
  284. $(".contact-success").fadeIn("slow");
  285. }
  286. else
  287. {
  288. alert('Problem with send email');
  289. }
  290. }
  291. });
  292. }
  293. return false;
  294. });
  295. /* =============================== SHORTCODES =============================== */
  296. /* ======= SINGLE & MULTIPLE TOGGLES ======= */
  297. $(".toggle").click(function() {
  298. var parent = $(this).parent();
  299. var content = $(".toggle-content",this);
  300. if(parent.hasClass("single-toggles")) {
  301. $(".toggle-title-text",parent).addClass("hover-icon");
  302. }
  303. if(content.css("display") === "none") {
  304. if(parent.hasClass("single-toggles")) {
  305. $(".toggle-content",parent).slideUp(200);
  306. $(".toggle-arrow i",parent).removeClass("icon-angle-down");
  307. $(".toggle-arrow i",parent).addClass("icon-angle-right");
  308. $(".toggle-title-text",parent).addClass("hover-icon");
  309. }
  310. content.slideDown(200);
  311. $(".toggle-title-text",this).removeClass("hover-icon");
  312. $(".toggle-arrow i",this).removeClass("icon-angle-right");
  313. $(".toggle-arrow i",this).addClass("icon-angle-down");
  314. }
  315. else {
  316. content.slideUp(200);
  317. $(".toggle-title-text",this).addClass("hover-icon");
  318. $(".toggle-arrow i",this).removeClass("icon-angle-down");
  319. $(".toggle-arrow i",this).addClass("icon-angle-right");
  320. }
  321. });
  322. /* ======= TABS ======= */
  323. $('.tabs-menu').each(function() {
  324. $("ul.tabs-menu > li:first-child").addClass('active-tab');
  325. var $ul = $(this);
  326. var $li = $ul.children('li');
  327. $li.each(function() {
  328. var $trescTaba = $($(this).children('a').attr('href'));
  329. if ($(this).hasClass('active-tab')) {
  330. $trescTaba.show();
  331. } else {
  332. $trescTaba.hide();
  333. }
  334. });
  335. $li.click(function() {$(this).children('a').click();});
  336. $li.children('a').click(function() {
  337. $li.removeClass('active-tab');
  338. $li.each(function() {
  339. $($(this).children('a').attr('href')).hide();
  340. });
  341. $(this).parent().addClass('active-tab');
  342. $($(this).attr('href')).show();
  343. return false;
  344. });
  345. });
  346. /* ======= ALERTS ======= */
  347. $(".close-alert").click(function() {
  348. $(this).parent().hide(400);
  349. });
  350. });
  351. })(jQuery);

comments powered by Disqus