PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/js/jquery.custom.js

https://github.com/eduardomadeira/NovaNatal
JavaScript | 542 lines | 379 code | 91 blank | 72 comment | 49 complexity | 45afd9bc39594ae5d09a8d2680b1b011 MD5 | raw file
  1. /* Add PrettyPhoto to Images
  2. ================================================== */
  3. jQuery(document).ready(function () {
  4. jQuery("a[data-rel^='prettyPhoto']").prettyPhoto({
  5. hook: 'data-rel', /* the attribute tag to use for prettyPhoto hooks. default: 'rel'. For HTML5, use "data-rel" or similar. */
  6. animation_speed:'fast',
  7. slideshow:3000,
  8. autoplay_slideshow:false,
  9. opacity:0.80,
  10. show_title:false,
  11. theme:'pp_default', /* light_rounded / dark_rounded / light_square / dark_square / facebook */
  12. overlay_gallery:false,
  13. social_tools:false
  14. });
  15. });
  16. /* Add Class "current-menu-item" to menu items
  17. ================================================== */
  18. jQuery(document).ready(function () {
  19. var url = jQuery(location).attr('pathname');
  20. var path = url.substring(1);
  21. if (path == "") {pat="home.html"};
  22. jQuery('.sf-menu li a[href="' + path + '"]').parent().addClass(".current-menu-item");
  23. });
  24. /* Remove Image Width and Height Attr
  25. ================================================== */
  26. jQuery(document).ready(function () {
  27. var a = jQuery(window).width();
  28. if (a<980) {
  29. jQuery('img:not(.flickr-widget img, .service-3 .icon img)').removeAttr("width").removeAttr("height");
  30. }
  31. });
  32. jQuery(window).resize(function () {
  33. var a = jQuery(window).width();
  34. if (a<980) {
  35. jQuery('img:not(.flickr-widget img, .service-3 .icon img)').removeAttr("width").removeAttr("height");
  36. }
  37. });
  38. /* Add tooltip
  39. ================================================== */
  40. jQuery(document).ready(function () {
  41. jQuery('a[data-rel="tipsy"]').tipsy({fade: true, gravity: 'n'});
  42. });
  43. /* Create Select Responsive menu
  44. ================================================== */
  45. jQuery(document).ready(function () {
  46. // DOM ready
  47. jQuery(function() {
  48. // Create the dropdown base
  49. jQuery("<select />").appendTo("#menu-wrapper");
  50. // Create default option "Go to..."
  51. jQuery("<option />", {
  52. "selected": "selected",
  53. "value" : "",
  54. "text" : "Go to..."
  55. }).appendTo("#menu-wrapper select");
  56. // Populate dropdown with menu items
  57. jQuery("#menu-wrapper a").each(function() {
  58. var el = jQuery(this);
  59. if (jQuery(el).parents('.sub-menu .sub-menu .sub-menu').length >= 1) {
  60. jQuery('<option />', {
  61. 'value' : el.attr('href'),
  62. 'text' : '- - - ' + el.text()
  63. }).appendTo('#menu-wrapper select');
  64. }
  65. else if (jQuery(el).parents('.sub-menu .sub-menu').length >= 1) {
  66. jQuery('<option />', {
  67. 'value' : el.attr('href'),
  68. 'text' : '- - ' + el.text()
  69. }).appendTo('#menu-wrapper select');
  70. }
  71. else if (jQuery(el).parents('.sub-menu').length >= 1) {
  72. jQuery('<option />', {
  73. 'value' : el.attr('href'),
  74. 'text' : '- ' + el.text()
  75. }).appendTo('#menu-wrapper select');
  76. }
  77. else {
  78. jQuery('<option />', {
  79. 'value' : el.attr('href'),
  80. 'text' : el.text()
  81. }).appendTo('#menu-wrapper select');
  82. }
  83. });
  84. // To make dropdown actually work
  85. // To make more unobtrusive: http://css-tricks.com/4064-unobtrusive-page-changer/
  86. jQuery("#menu-wrapper select").change(function() {
  87. window.location = jQuery(this).find("option:selected").val();
  88. });
  89. });
  90. });
  91. /* slogan width resize
  92. ================================================== */
  93. jQuery(window).resize(function () {
  94. var a = jQuery(window).width();
  95. if (a<980) {
  96. jQuery('#slogan li').css({width:"auto"});
  97. } else { jQuery('#slogan li').css({width:"860px"}); }
  98. });
  99. /* client width resize
  100. ================================================== */
  101. jQuery(window).resize(function() {
  102. jQuery(".clients-wrap").width(jQuery(".clients-wrapper").width());
  103. });
  104. /* Set height For Post Date
  105. ================================================== */
  106. jQuery(document).ready(function () {
  107. el = jQuery('#postsinglepage.posts .date-wrap, .posts .date-wrap');
  108. var a = el.height();
  109. var b = el.parent().height();
  110. a = ((b-a)/2);
  111. el.css("padding-top",a);
  112. });
  113. jQuery(window).resize(function () {
  114. el = jQuery('.posts .date-wrap');
  115. var a = el.height();
  116. var b = el.parent().height();
  117. a = ((b-a)/2);
  118. el.css("padding-top",a);
  119. });
  120. /* Animate Zoom Icon
  121. ================================================== */
  122. jQuery(document).ready(function () {
  123. jQuery(".posts .featured-thumbnail a.image-wrapper, #portfoliosinglepage a.image-wrapper, .portfolio-item-wrapper:not(.gallery) a.image-wrapper, .featured-thumbnail.image-frame a.image-wrapper").hover(function(){
  124. jQuery(this).animate({ opacity: 0.7 }, 500, 'easeOutExpo');
  125. jQuery(this).find('span').animate({ top: '0'}, 200, 'easeOutExpo');
  126. }, function(){
  127. jQuery(this).find('span').animate({ top: '100%'}, 200, 'easeInExpo', function(){
  128. jQuery(this).css('top','-100%');
  129. });
  130. jQuery(this).animate({ opacity: 1 }, 500, 'easeInExpo');
  131. });
  132. });
  133. /* Animate Zoom Icon for ralated post/portfolio
  134. ================================================== */
  135. jQuery(document).ready(function () {
  136. jQuery(".related .image-wrap").hover(function(){
  137. jQuery(this).children('.zoom-icon.related-post').animate({ left: '0'}, 500, 'easeOutExpo');
  138. }, function(){
  139. jQuery(this).children('.zoom-icon.related-post').animate({ left: '100%'}, 500, 'easeInExpo', function(){
  140. jQuery(this).css('left','-100%');
  141. });
  142. });
  143. });
  144. /* Animate Zoom Icon for gallery style
  145. ================================================== */
  146. jQuery(document).ready(function () {
  147. jQuery(".gallery .image-wrap").hover(function(){
  148. jQuery(this).children('.zoom-icon.gallery-port').animate({ left: '0'}, 500, 'easeOutExpo');
  149. }, function(){
  150. jQuery(this).children('.zoom-icon.gallery-port').animate({ left: '100%'}, 500, 'easeInExpo', function(){
  151. jQuery(this).css('left','-100%');
  152. });
  153. });
  154. });
  155. /* Created button effect
  156. ================================================== */
  157. jQuery(document).ready(function() {
  158. jQuery(".shortcode-button").children("img").attr('width', function(){
  159. return jQuery(this).parent().width()+30;
  160. }).attr('height', function(){
  161. return jQuery(this).parent().height()+12;
  162. })
  163. jQuery(".shortcode-button").mouseenter(function(){
  164. jQuery(this).find("img").attr("src", function(){
  165. var value = jQuery(this).attr("src").replace("buttonlight", "buttonlightb");
  166. return value;
  167. });
  168. });
  169. jQuery(".shortcode-button").mouseleave(function(){
  170. jQuery(this).find('img').attr('src', function(){
  171. var value = jQuery(this).attr("src").replace("buttonlightb", "buttonlight");
  172. return value;
  173. });
  174. });
  175. });
  176. /* Social icon effect
  177. ================================================== */
  178. jQuery(document).ready(function() {
  179. jQuery(".social-icon a").mouseenter(function() {
  180. jQuery(this).fadeTo(400,.5);
  181. jQuery(this).children('img').animate({"top":"-20px","opacity":"0"},400,function() {
  182. jQuery(this).css({"top":"0px"}).fadeTo(200,1);
  183. });
  184. });
  185. jQuery(".social-icon a").mouseleave(function() {
  186. jQuery(this).fadeTo(400,1);
  187. });
  188. });
  189. /* Scroll Top
  190. ================================================== */
  191. jQuery(document).ready(function() {
  192. jQuery(window).scroll(function () {
  193. if (jQuery(this).scrollTop() > 300) {
  194. jQuery('#backtotop').fadeIn();
  195. } else {
  196. jQuery('#backtotop').fadeOut();
  197. }
  198. });
  199. jQuery('#backtotop, div.divider .divider-gotop').click(function () {
  200. jQuery('body,html').stop(false, false).animate({
  201. scrollTop: 0
  202. }, 800);
  203. return false;
  204. });
  205. });
  206. /* Progress Bar
  207. ================================================== */
  208. jQuery(document).ready(function() {
  209. jQuery('.progress-bar-meter img').each(function() {
  210. jQuery(this).width(jQuery(this).parent().width());
  211. jQuery(this).height(jQuery(this).parent().height());
  212. });
  213. });
  214. jQuery(window).load(function() {
  215. jQuery('.progress-bar-wrapper').each(function() {
  216. var a = jQuery(this).find('.value').text();
  217. jQuery(this).find('.progress-bar-meter').css('width','0');
  218. jQuery(this).find('.progress-bar-meter').css('display','block').delay(1000).animate({'width':a});
  219. });
  220. });
  221. /* Flickr Preview
  222. ================================================== */
  223. this.imagePreview = function(){
  224. xOffset = 30;
  225. yOffset = 10;
  226. var winwid = jQuery(window).width();
  227. winwid = winwid/2;
  228. jQuery("a.flickr-image").hover(function(e){
  229. jQuery("body").append("<div id='flickr-preview'><img src='"+ jQuery(this).attr('alt') +"' alt='preview' /></div>");
  230. if (e.pageX < winwid) { var a = (e.pageX + xOffset) } else { a = (e.pageX - xOffset - jQuery("#flickr-preview img").width())}
  231. jQuery("#flickr-preview")
  232. .css("top",(e.pageY - yOffset) + "px")
  233. .css("left",a + "px")
  234. .fadeIn("fast");
  235. },
  236. function(){
  237. jQuery("#flickr-preview").remove();
  238. });
  239. jQuery("a.flickr-image").mousemove(function(e){
  240. if (e.pageX < winwid) { var a = (e.pageX + xOffset) } else { a = (e.pageX - xOffset - jQuery("#flickr-preview img").width())}
  241. jQuery("#flickr-preview")
  242. .css("top",(e.pageY - yOffset) + "px")
  243. .css("left",a + "px");
  244. });
  245. };
  246. jQuery(document).ready(function(){
  247. imagePreview();
  248. });
  249. /* Accordion
  250. ================================================== */
  251. jQuery(document).ready(function(){
  252. jQuery("ul.pa-accordion li").each(function(){
  253. jQuery(this).children(".accordion-content").css('height', function() {
  254. return jQuery(this).height();
  255. });
  256. if (jQuery(this).index() > 0) {
  257. jQuery(this).children(".accordion-content").css('display','none');
  258. } else {
  259. jQuery(this).addClass('active').find(".accordion-head-sign").html("&minus;");
  260. jQuery(this).siblings("li").find(".accordion-head-sign").html("&#43;");
  261. }
  262. jQuery(this).children(".accordion-head").bind("click", function() {
  263. jQuery(this).parent().addClass(function() {
  264. if (jQuery(this).hasClass("active")) return "";
  265. return "active";
  266. });
  267. jQuery(this).siblings(".accordion-content").slideDown();
  268. jQuery(this).parent().find(".accordion-head-sign").html("&minus;");
  269. jQuery(this).parent().siblings("li").children(".accordion-content").slideUp();
  270. jQuery(this).parent().siblings("li").removeClass("active");
  271. jQuery(this).parent().siblings("li").find(".accordion-head-sign").html("&#43;");
  272. });
  273. });
  274. });
  275. /* Toggle
  276. ================================================== */
  277. jQuery(document).ready(function(){
  278. jQuery("ul.pa-toggle li").each(function(){
  279. jQuery(this).children(".toggle-content").css('height', function() {
  280. return jQuery(this).height();
  281. });
  282. jQuery(this).children(".toggle-content").css('display','none');
  283. jQuery(this).find(".toggle-head-sign").html("&#43;");
  284. jQuery(this).children(".toggle-head").bind("click", function() {
  285. if (jQuery(this).parent().hasClass("active")) jQuery(this).parent().removeClass("active");
  286. else jQuery(this).parent().addClass("active");
  287. jQuery(this).find(".toggle-head-sign").html(function() {
  288. if (jQuery(this).parent().parent().hasClass("active")) return "&minus;";
  289. else return "&#43;";
  290. });
  291. jQuery(this).siblings(".toggle-content").slideToggle();
  292. });
  293. });
  294. jQuery("ul.pa-toggle").find(".toggle-content.active").siblings(".toggle-head").trigger('click');
  295. });
  296. /* Tab
  297. ================================================== */
  298. jQuery(document).ready(function(){
  299. var tabs = jQuery('ul.tabs');
  300. tabs.each(function(i) {
  301. // get tabs
  302. var tab = jQuery(this).find('> li > a');
  303. tab.click(function(e) {
  304. // get tab's location
  305. var contentLocation = jQuery(this).attr('href');
  306. // Let go if not a hashed one
  307. if(contentLocation.charAt(0)=="#") {
  308. e.preventDefault();
  309. // add class active
  310. tab.removeClass('active');
  311. jQuery(this).addClass('active');
  312. // show tab content & add active class
  313. jQuery(contentLocation).fadeIn(1000).addClass('active').siblings().hide().removeClass('active');
  314. }
  315. });
  316. });
  317. });
  318. /* jcarousellite
  319. ================================================== */
  320. jQuery(window).load(function() {
  321. // Call jcarousellite
  322. var carousellite = jQuery('.jcarousellite');
  323. carousellite.jCarouselLite({ btnNext: ".next", btnPrev: ".prev", visible: 1 });
  324. });
  325. /* create equal height for content and sidebar
  326. ================================================== */
  327. jQuery(window).load(function() {
  328. var a = jQuery('#content').height();
  329. var b = jQuery('.grid_3.bothleft').height();
  330. var c = jQuery('.grid_3.bothright').height();
  331. var d = jQuery('.grid_4.indent.pleft').height();
  332. var e = jQuery('.grid_4.indent.pright').height();
  333. var columns = [a,b,c,d,e];
  334. var currentTallest = 0;
  335. for (i=0; i<columns.length; i++) {
  336. if (columns[i] > currentTallest) { currentTallest = columns[i] }
  337. }
  338. if (jQuery('#main div').hasClass('sidebar')) {
  339. jQuery('#content').css('min-height',currentTallest);
  340. jQuery('.grid_3.bothleft').css('min-height',currentTallest);
  341. jQuery('.grid_3.bothright').css('min-height',currentTallest);
  342. jQuery('.grid_4.indent.pleft').css('min-height',currentTallest);
  343. jQuery('.grid_4.indent.pright').css('min-height',currentTallest);
  344. }
  345. });
  346. /* create equal height for portfolio item
  347. ================================================== */
  348. function equalHeight(group) {
  349. var tallest = 0;
  350. group.each(function() {
  351. var thisHeight = jQuery(this).height();
  352. if(thisHeight > tallest) {
  353. tallest = thisHeight;
  354. }
  355. });
  356. group.height(tallest);
  357. }
  358. jQuery(document).ready(function() {
  359. /*equalHeight(jQuery('#portfolio-item-wrapper li'));*/
  360. var a = jQuery('#port-content-wrapper > div');
  361. if (a.length > 1) {
  362. equalHeight(jQuery('#port-content-wrapper > div'));
  363. }
  364. });
  365. /* contact form
  366. ================================================== */
  367. jQuery(document).ready(function() {
  368. jQuery('#contactForm').submit(function() {
  369. jQuery('#contactForm .error-message').remove();
  370. var hasError = false;
  371. jQuery('#contactForm .requiredField').each(function() {
  372. var labelText = jQuery(this).parent().prev('label').attr('data-rel');
  373. if(jQuery.trim(jQuery(this).val()) == '' || jQuery.trim(jQuery(this).val()) == labelText) {
  374. jQuery(this).parent().append('<span class="error-message">Please enter your '+labelText+'</span>').find('.error-message').width(jQuery(this).parent().width()).height(jQuery(this).parent().height()-9).hover(function(e) { jQuery(this).fadeOut(300); });
  375. jQuery(this).addClass('inputError');
  376. hasError = true;
  377. } else if(jQuery(this).hasClass('email')) {
  378. var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  379. if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
  380. jQuery(this).parent().append('<span class="error-message">Please enter a valid email address</span>').find('.error-message').width(jQuery(this).parent().width()).height(jQuery(this).parent().height()-9).hover(function(e) { jQuery(this).fadeOut(300); });
  381. jQuery(this).addClass('inputError');
  382. hasError = true;
  383. }
  384. }
  385. });
  386. if(!hasError) {
  387. if (jQuery('#contact-recaptcha').hasClass('true')) {
  388. return true;
  389. } else {
  390. jQuery('#contactForm #contact-submit').fadeOut('normal', function() {
  391. jQuery(this).parent().append('<div class="wait"></div>');
  392. });
  393. var formInput = jQuery(this).serialize();
  394. jQuery.post(jQuery(this).attr('action'), formInput, function(data){
  395. jQuery('#contactForm').slideUp('fast', function() {
  396. jQuery('#contactForm .wait').slideUp("fast");
  397. jQuery(this).before('<p class="message-box no-icon green"><strong>Thanks!</strong> Your email was successfully sent. I check my email all the time, so I should be in touch soon.</p>');
  398. });
  399. });
  400. }
  401. }
  402. return false;
  403. });
  404. });
  405. /* widget contact form
  406. ================================================== */
  407. jQuery(document).ready(function() {
  408. jQuery('#widget-contactForm').submit(function() {
  409. jQuery('#widget-contactForm .error-message').remove();
  410. var hasError = false;
  411. jQuery('#widget-contactForm .requiredField').each(function() {
  412. var labelText = jQuery(this).siblings('label').attr('data-rel');
  413. if(jQuery.trim(jQuery(this).val()) == '' || jQuery.trim(jQuery(this).val()) == labelText) {
  414. jQuery(this).parent().append('<span class="error-message">Please enter your '+labelText+'</span>').find('.error-message').width(jQuery(this).width()).height(jQuery(this).height()-7).delay(1000).fadeOut(350);
  415. jQuery(this).addClass('inputError');
  416. hasError = true;
  417. } else if(jQuery(this).hasClass('email')) {
  418. var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  419. if(!emailReg.test(jQuery.trim(jQuery(this).val()))) {
  420. jQuery(this).parent().append('<span class="error-message">Please enter a valid email address</span>').find('.error-message').width(jQuery(this).width()).height(jQuery(this).height()-7).delay(1000).fadeOut(350);
  421. jQuery(this).addClass('inputError');
  422. hasError = true;
  423. }
  424. }
  425. });
  426. if(!hasError) {
  427. jQuery('#widget-contactForm #widget-contact-submit').fadeOut('normal', function() {
  428. jQuery(this).parent().append('<div class="wait"></div>');
  429. });
  430. var formInput = jQuery(this).serialize();
  431. jQuery.post(jQuery(this).attr('action'), formInput, function(data){
  432. jQuery('#widget-contactForm').slideUp('fast', function() {
  433. jQuery('#widget-contactForm .wait').slideUp("fast");
  434. jQuery(this).before('<p class="message-box no-icon green"><strong>Thanks!</strong> Your email was successfully sent. I check my email all the time, so I should be in touch soon.</p>');
  435. });
  436. });
  437. }
  438. return false;
  439. });
  440. });
  441. /* auto-hide for top bar (please uncomment the code if needed)
  442. ================================================== */
  443. /*jQuery(document).ready(function () {
  444. jQuery('#top-nav-left, #top-nav-right').slideUp(300);
  445. jQuery('#top-nav-wrapper').mouseenter(function(){
  446. jQuery('#top-nav-left, #top-nav-right').slideDown(300);
  447. });
  448. jQuery('#top-nav-wrapper').mouseleave(function(){
  449. jQuery('#top-nav-left, #top-nav-right').slideUp(300);
  450. });
  451. });*/