Learn how to use jQuery at the Blog

Urban Rocks Gym « visit

  • Added 10 months ago
  • 406 Lines of Code shown
  • 1 Links of Interest
http://urbanrocksgym.com
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to Urban Rocks Gym - http://urbanrocksgym.com

var Local = {

    onCommentReply: function(id) {
		Comments.openReply(id);
	},

    onCancelReply: function(id) {
		Comments.closeReply();
	}

};

if(!window['wt']) {
	window['wt'] = {};
	var wt = window['wt'];
}

wt.browserSucks = (jQuery.browser.msie && jQuery.browser.version < 7) ? true : false;

(function() { // This is where jQuery code can safely go without foobarring prototype
	var $ = jQuery
	
	$(document).ready(function() { // These functions get called on DOM ready
		$('a').click(function() { $(this).blur() }) // prevents outlines on links for IE
		wt.rounded();
		wt.navHover();
		wt.hero();
		wt.news();
		wt.facilitiesMap();
		wt.formDefaults();
		wt.logoFix();
		wt.gallery();
		if(wt.browserSucks) {
			$(':first-child').addClass('first-child');
		}
	})
	
	$(window).load(function() { // These functions get called when everything has loaded
		if(wt.browserSucks) {
			$('img[src$=png]').addClass('png-fixed').pngfix({'imageFixSrc': '/images/clear.gif'});
		}
		wt.fixColumns();
		if($('#wrapper').height() < $(window).height() && !$('.gallery').size()) {
			$('#ft').css({
				'padding-top': parseInt($('#ft').css('padding-top'),10) + ($(window).height() - $('#wrapper').height())
			});
		}
	})
	
	$(window).resize(function() {
		wt.logoFix();
	});
	
	wt.formDefaults = function() { // Swaps default text form input values to blank on focus and back to default text on blur
		$('input:text,textarea').each(function() {
			var elem = $(this)
			var defaultText = elem.val()
			elem.focus(function(){
				if(elem.val() == defaultText) {
					elem.val('')
				}
			})
			elem.blur(function(){
				if(elem.val() == '') {
					elem.val(defaultText)
				}
			})
		})
	}

	wt.navHover = function() {
		wt.navHover.isClicked = false;
		$('#hd ul.navigation').addClass('scripted')

		var highlight = $('#highlight')
		var currentLink = $('#hd ul.navigation > li.selected, #hd ul.navigation > li.ancestor')
		if(!currentLink.size()) { return; }
		highlight.css({
			'width': currentLink.width(),
			'left': currentLink.offset().left
		}).addClass('scripted')
		currentLink.find('a').css({'color':'black'})

		var navs = $('#hd ul.navigation > li')
		navs.each(function() {
			var link = $(this)
			link.hover(function() {
				if(highlight.is(':animated')) { highlight.stop(); }
				if(highlight.offset().left == link.offset().left) { return; }
				navs.find('a').css({'color': ''})
				highlight.animate({
					'width': link.outerWidth(),
					'left': link.offset().left
				}, 500, function() {
					link.find('a').css({'color': 'black'})
				})
				clearTimeout(wt.navHover.moveBack)
			}, function() {
				if(!wt.navHover.isClicked) {
					wt.navHover.moveBack = setTimeout(function(){
						if(highlight.offset().left == currentLink.offset().left) { return; }
						navs.find('a').css({'color': ''})
						highlight.animate({
							'width': currentLink.width(),
							'left': currentLink.offset().left
						}, 500, function() {
							currentLink.find('a').css({'color': 'black'})
						})
					},1500)
				}
			});
		});
		
		$('#hd ul.navigation li a').click(function() {
			wt.navHover.isClicked = true;
			clearTimeout(wt.navHover.moveBack)
		});
		
		$(window).resize(function() {
			highlight.css({
				'width': currentLink.outerWidth(),
				'left': currentLink.offset().left
			})
		});
	}
	
	wt.hero = function() {
		var heroContainers = $('div.heroshot')
		if(!heroContainers.size()) { return; }
		
		heroContainers.each(function() {
			var container = $(this);
			
			var images = container.children(':not(ol)')

			var choices = container.find('ol li');
			
			choices.each(function(i) {
				var choice = $(this);
				choice.css({
					'position': 'absolute',
					'bottom': 0,
					'top': 'auto',
					'left': choice.outerWidth({'margin': true}) * i
				})
				var link = choice.find('a');
				choice.hover(function() {
					link.stop().addClass('on').animate({
						'height': (link.find('img').size() ? link.find('img').height() : link.find('span:not(:first-child)').css('height'))
					}, parseInt(link.find('img').height(),10) * 2)
				}, function() {
					if(!link.hasClass('clicked')) {
						link.stop().removeClass('on').animate({
							'height': 0
						}, 'slow')
					}
				});
				
				link.click(function(c) {
					c.preventDefault();
					var currentImage = images.filter(':visible')
					var nextImage = images.filter('[rel=' + link.attr('href').substr(1) + ']')
					if(currentImage.attr('src') == nextImage.attr('src')) { return; }
					nextImage.css({'z-index':1,'display':'block'});
					currentImage.fadeOut('normal',function(){ currentImage.css({'z-index':1}); nextImage.css({'z-index':2}) });
					choices.children('a.on').filter('[href!=' + link.attr('href') +']').removeClass('on').animate({
						'height': 0
					}, 'slow');
					
					choices.children('a.clicked').removeClass('clicked')
					link.addClass('clicked')
				});
			});
			
			images.css({'display':'none','z-index':1});
			$(images.get(0)).css({'z-index':2}).show();
			
			$(window).load(function() {
				$(choices[0]).find('a').css({
					'height': ($(choices[0]).find('a img').size() ? $(choices[0]).find('a img').height() : $(choices[0]).find('a span:not(:first-child)').height())
				}).addClass('on').addClass('clicked')
			});
			
		});
	}

	wt.fixColumns = function() {
		if($('#bd #sb').height() == $('#bd #main').height()) {
			return;
		} else if($('#bd #sb').height() < $('#bd #main').height()) {
			var lastChild = $('#bd #sb > div:last-child');
		} else {
			var lastChild = $('#bd #main > div:last-child');
		}
		if($('.box-with-thumb').size()) {
			$('.box-with-thumb').each(function() {
				var thumb = $(this).find('.thumbnail');
				thumb.height($(this).find('.box').outerHeight() - (thumb.outerHeight() - thumb.height()));
			});
		}
		if(lastChild.hasClass('box-with-thumb')) {
			lastChild = lastChild.find('div.box')
		}
		var difference = Math.abs($('#bd #main').height() - $('#bd #sb').height());
		lastChild.css({
			'padding-bottom': parseInt(lastChild.css('padding-bottom'),10) + difference
		});
		if(lastChild.hasClass('box-right')) {
			lastChild.prev('.box-left').css({
				'padding-bottom': parseInt(lastChild.prev('.box-left').css('padding-bottom'),10) + difference
			});
		}
		if(lastChild.siblings('div.thumbnail').size()) {
			var thumb = lastChild.siblings('div.thumbnail');
			thumb.height(lastChild.outerHeight() - (thumb.outerHeight() - thumb.height()));
		}
		
		$('.box-left').each(function() {
			var left = $(this);
			var right = $(this).next('.box-right');
			left.height(left.height() < right.height() ? right.height() : left.height());
			right.height(right.height() < left.height() ? left.height() : right.height());
		});
	}
	
	wt.facilitiesMap = function() {
		var map = $('#main .box-facility-map');

		var overlay = $(jQuery('<div class="overlay"></div>'))
		overlay.css({'width': map.width(), 'height': map.height(), 'opacity': 1})
		overlay.appendTo(map)

		if(!$.browser.msie) {
			map.find('ol').css({'background-image': 'none'})
		}

		map.find('ol li').hover(function() {
			$(this).addClass('hover').css({'z-index':3});
			if(!$.browser.msie) {
				$(this).siblings('li').add(overlay).css({'opacity': 0.7});
			}
		}, function() {
			$(this).removeClass('hover');
			if(!$.browser.msie) {
				$(this).siblings('li').add(overlay).css({'opacity': 1});
			}
		});
		
	}
	
	wt.news = function() {
		if(!$('body.news').size()) { return; }

		$('div.box-news-item-with-thumb').each(function() {
			$(this).find('div.thumbnail').height($(this).find('div.box').outerHeight())
		});
	}
	
	wt.rounded = function() {
		if($.browser.msie && $.browser.version < 8) { return; }
		$('#main > div.box:first-child, table.aggregator td:first-child, div.aggregator div.blade:first-child').addClass('rounded-top-left')
		$('#sb > div.box:first-child, table.aggregator td:last-child, div.aggregator div.blade:last-child').addClass('rounded-top-right')
		$('#main > div.box:last-child, table.aggregator td:first-child, div.aggregator div.blade:first-child').addClass('rounded-bottom-left')
		$('#sb > div.box:last-child, table.aggregator td:last-child, div.aggregator div.blade:last-child').addClass('rounded-bottom-right')
		
		if($('#main > div.box:last-child').hasClass('box-right')) {
			$('#main > div.box:last-child').removeClass('rounded-bottom-left').siblings('.box-left').addClass('rounded-bottom-left');
		}
		
		$('#main > div.box-with-thumb:first-child > div.thumbnail').addClass('rounded-top-left')
		$('#main > div.box-with-thumb:last-child > div.thumbnail').addClass('rounded-bottom-left')
	}
	
	wt.IE6 = function() {
		$('.box, .black-bar').css({'background': '#111'})
		$('html, body').css({'background-color': '#111'})
		$('.box').removeClass('rounded-top-left').removeClass('rounded-top-right').removeClass('rounded-bottom-right').removeClass('rounded-bottom-left')
	}
	
	wt.logoFix = function() {
		if(wt.browserSucks) { return; }
		var hd = $('#hd');
		var tempImg = new Image();
		tempImg.onload = function() {
			if(tempImg.width <= $('body').width()) {
				var diff = Math.ceil((tempImg.width - hd.width()) / 2) + 1;
			} else {
				var diff = Math.ceil(($('body').width() - hd.width()) / 2) + 1;
			}
			hd.css({
				'padding-left': diff + 'px',
				'margin-left': (0 - diff) + 'px'
			})
		}
		tempImg.src = $('body').css('background-image').replace(/url\(([^)]+)\)/,'$1');
	}
	
	wt.gallery = function() {
		if(!$('body.gallery').size()) { return; }
		
		var target = $(jQuery('<div id="gallery-target"></div>'));
		$('#bd .box .aggregator').after(target);
		target.html('<span></span>');
		
		var blades = $('div.aggregator div.blade');
		
		wt.gallery.bladeSlider = function(currentBlade) {
			currentBlade.siblings().removeClass('current');
			currentBlade.addClass('current');
			if(currentBlade.width() != 36) {
				blades.parents('div.aggregator').css({'width':'auto','margin': '0','float':'left'});
				blades.animate({
					'width': 36
				},500);
			}
		}
		
		blades.each(function() {
			var blade = $(this);
			var link = blade.find('a');
			link.click(function(c) {
				c.preventDefault();
				wt.gallery.bladeSlider(blade);
				target.load(link.attr('href') + ' #gallery-container',{},function(responseText, textStatus){
					wt.gallery.linkHandler(target);
					wt.gallery.thumbsHandler(target);
				});
			});
		});
		
		wt.gallery.linkHandler = function(obj) {
			if(typeof obj == 'undefined') { var obj = $('body'); }
			
			var links = obj.find('a[rel=gallery]').filter(':not(.processed)');
			links.each(function() {
				var link = $(this);
				link.addClass('processed');
				link.click(function(c) {
					c.preventDefault();
					target.find('.gallery-image').addClass('loading').find('img').fadeOut('normal',function(){
						var img = new Image();
						img.onload = function() {
							$(img).css({'display':'none'});
							target.find('.gallery-image').html($(img));
							$(img).fadeIn('normal', function() {
								target.find('.gallery-image').removeClass('loading');
							});
						}
						img.src = link.attr('href');
					});
				});
			});
		}
		
		wt.gallery.linkHandler();
		
		wt.gallery.thumbsHandler = function(obj) {
			if(typeof obj == 'undefined') { var obj = $('body'); }
			
			var thumbsGroups = obj.find('.thumbs-wrapper');
			
			thumbsGroups.each(function() {
				var group = $(this);
				var prev = $(jQuery('<a href="#prev" class="prev">Previous</a>'));
				var next = $(jQuery('<a href="#next" class="next">Next</a>'));
				var slider = group.find('.slider');
				slider.find('a:last-child').css({'margin-right':0});
				
				if(group.find('.thumbs a').size() < 7) { return; }
				
				slider.width((group.find('.thumbs a').size() * 91) -1);
				
				group.prepend(prev);
				group.append(next);
				prev.css({'visibility':'hidden'});
				
				prev.add(next).each(function() {
					var link = $(this);
					link.click(function(c) {
						c.preventDefault();
						if(slider.is(':animated')) { return; }
						var newX = parseInt(slider.css('left'),10) - (link.hasClass('prev') ? (0 - 91) : 91);
						slider.animate({
							'left': newX
						},500);
						if(newX < 0) {
							prev.css({'visibility':'visible'});
						} else {
							prev.css({'visibility':'hidden'});
						}
						if(Math.abs(newX) < slider.width() - slider.parent().width()) {
							next.css({'visibility':'visible'});
						} else {
							next.css({'visibility':'hidden'});
						}
					});
				});
				
			});
		}
		
		wt.gallery.thumbsHandler();

	}
	
})();