Signin  Pricing  Examples  Support

Libraries > gs.js

gs.js - Search Live Website Code
It's like doing CTRL+F on millions of websites' source code



NerdyData is a search engine for source code. Search the source code of 200 million websites.


JAVASCRIPT FILE http://gambit.gg/public/js/gs.js


Libraries on gambit.gg


core.js

dlg.js

gs.js

en.js

scroll.js

tabs.js

jquery.js

modernizr.custom.js

news-js.js

router.js

setup.js

timezone.js

viewer.js



Explore More


jquery.ui.effects.min.js

jquery.validate.min.js

core.js

modal.js

gs.js
				
/**
 * Generate GS gallery.
 */
var GS = {
	/**
	 * Generate GS gallery.
	 */
	id: 'gs',
	/**
	 * Generate GS gallery.
	 */
	slides: 0,
	readyState: 0,
	/**
	 * Generate GS gallery.
	 */
	gsBody: null,
	gsContent: null,
	gsThumbs: null,
	gsShader: null,
	/**
	 * Generate GS gallery.
	 */
	t: null,
	e: null,
	showingVideo: false,
	prevCont: null,
	/**
	 * Generate GS gallery.
	 */
	animationInProgress: false,
	animType: 'slide',
	/**
	 * Has the class been initialized?
	 */
	initialized: false,
	/**
	 * Deffered object for delayed calls
	 */
	deferred: new $.Deferred(),
	/**
	 * Has the class been initialized?
	 */
	options: {
		fullbody: false,
		rotateTime: 6,
		anim: true,
		animTime: 300,
		thumbs: true,
		ajax: false,
		fullinfo: true,
		customThumbsCss: false,
		noImageThumbs: false,
		mouseEvents: false,
		display: "static",
		resizeble: true,
		staticHeight: true,
		nav: {
			left: false,
			right: false,
			fullscreen: false,
			slideShow: false
		}
	},
	
	imgDimentionsOrigin: {},//new Array(),
	imgDimentions: {},//new Array(),
	imgResizedDimentions: {},//new Array(),
	imgArray: new Array(),
	
	/**
	 * Generate GS gallery.
	 *
	 * @constructor
	 */
	initialize: function(options) {
		if (GS.initialized)
			return;
		
		GS.options = $.extend({}, GS.options, options);
		GS.id = GS.options.node ? GS.options.node : "gs";
		GS.gsBody = $("#"+ GS.id);
		GS.gsContent = $('<div class="content"></div>').appendTo(GS.gsBody);
		
		if(GS.gsBody.length < 1)
			return false;
		
		var loader = $("<div/>").addClass("loader huge dark").appendTo(GS.gsBody);
		GS.gsBody.addClass("loading");
		
		$(window).on('gs-ready', function() {
			//GS.gsBody.html('');
			var imgs = [], v = [], r = [], f = [], w = [], spiners = [], maxH = 0;
			var s = GS.gsContent;
			var fb = GS.options.fullbody ? $('<div id="'+ GS.id +'-full"></div>').prependTo("body") : null;
			for(var i=0; i < GS.slides; i++)
			{
				var cls = (i==0)?'block current':'block';
				var clsf = (i==0)?'current':'';
				var d = GS.imgDimentions[i];
				v[i] = $('<div id="gs'+ i +'" class="'+ cls +'" data-index="'+ i +'"></div>').appendTo(s).hide().css({opacity: 0});
				f[i] = fb ? $('<div id="gs'+ i +'full" class="'+ clsf +'"></div>').css({backgroundImage: a[i].fullimg ? a[i].fullimg : "none", opacity: 0}).appendTo(fb) : null;
				var href = a[i].href
					? (a[i].href.indexOf("http://") >= 0 || a[i].href.indexOf("https://") >= 0)
						? 'href="'+ a[i].href +'" target="_blank"'
						: 'href="'+ Core.baseUrl + a[i].href +'"'
					: "";
				r[i] = $('<a class="box" '+ href +' title="'+ (a[i].title ? a[i].title : "") +'"></a>').appendTo(v[i]);
				$('<div class="poster-wrapper"></div>').appendTo(r[i]?r[i]:v[i]);
				if(a[i].video) $('<span class="video-icon"></span>').appendTo(r[i]?r[i]:v[i]);
				spiners[i] = $("<div/>").addClass("loader").appendTo(r[i]?r[i]:v[i]);
				imgs[i] = $('<img src="'+ a[i].src +'" width="'+ d.w +'" height="'+ d.h +'" />').appendTo(r[i]?r[i]:v[i]);
				imgs[i].onImageLoaded({index: i}, function(e) { spiners[e.data.index].remove(); });
				w[i] = GS.options.fullinfo ? $('<div class="related-wrapper"></div>').appendTo(r[i]) : null;
				if(a[i].title && a[i].desc && w[i])
					$('<h1>'+ a[i].title +'</h1>'+ (a[i].date ? '<p class="date">'+ a[i].date +'</p>' : '') +'<p>'+ a[i].desc +'</p>').appendTo(w[i]);
				else if (a[i].title && w[i])
					$('<h1>'+ a[i].title +'</h1>'+ (a[i].date ? '<p class="date">'+ a[i].date +'</p>' : '') +'<p>'+ a[i].title +'</p>').appendTo(w[i]);
				else
					w[i].hide();
				
				if(a[i].video)
				{
					var el = a[i];
					var index = i;
					r[i].on("click", function(e) {
						GS.callVideoPlayer(e, $(this), el, index);
					});
				}
				
				if(d.h > maxH)
					maxH = d.h;
			}
			
			if(!GS.options.staticHeight)
				GS.gsContent.css("height", maxH);
			
			if(GS.options.thumbs)
			{
				var width = GS.gsBody.innerWidth();//GS.options.fullinfo ? GS.gsBody.innerWidth() - w[0].outerWidth(true) : GS.gsBody.innerWidth();
				//GS.gsThumbs = $('<div class="thumbs-wrapper"></div>').css("width", width).appendTo(GS.gsBody);
				GS.gsThumbs = $('<div class="thumbs-wrapper"></div>').css("width", "100%").appendTo(GS.gsBody);
				var v = GS.gsThumbs;
				var u = $('<ul class="thumbs"></ul>').appendTo(v);
				
				for(var i=0; i < GS.slides; i++)
				{
					var l=null,n=null;
					var cls = (i==0)?'thumb-item active':'thumb-item';
					l = $('<li id="gs'+ i +'t" class="'+ cls +'" data-index="'+ i +'"></li>').appendTo(u);
					GS.options.customThumbsCss ? false : l.css("width", GS.slides > 8 ? (width - (l.outerWidth(true) - l.innerWidth()) * GS.slides)/GS.slides : 245);
					n = $('<a class="thumb-lnk" '+ (a[i].href ? 'href="'+ Core.baseUrl + a[i].href +'"' : "") +' title="'+ (a[i].title ? a[i].title : "") +'"></a>').appendTo(l);
					if(!GS.options.noImageThumbs)
						$('<img src="'+ a[i].thumb +'"></div>').appendTo(n?n:l);
					$('<div class="thumb-pointer"></div>').appendTo(n?n:l);
					if(a[i].thumbTitle)
					{
						$('<div class="thumb-shade"></div>').appendTo(n?n:l);
						$('<div class="thumb-title">'+ a[i].thumbTitle +'</div>').appendTo(n?n:l);
					}
				}
				
				GS.gsThumbs.append('<div class="cl"></div>');
				
				$(".thumb-lnk", GS.gsBody).on(GS.options.rotateTime!=0?'mouseenter':'click', function(evt)
				{
					if(GS.showingVideo)
						return false;
					
					var node = $(this).closest('.thumb-item');
					var str = node.attr('id');
					id = str.slice(0,-1);
					if(!node.hasClass("active"))
					{
						node.addClass("active");
						GS.animateSlideChange($(".current", GS.gsBody), $('#'+ id), GS.animType);
					}
				});
				
				if(GS.options.rotateTime!=0)
					$(".thumb-lnk", GS.gsBody).on('mouseleave', function(evt)
					{
						if(GS.showingVideo)
							return false;
						var node = $(this).closest('.thumb-item');
						var frame = $(this).offsetParent().offsetParent().offsetParent();
					});
			}
			
			if(GS.options.nav.left && GS.slides > 1)
			{
				var leftArrow = $("<div/>").addClass("nav-arrow-left").appendTo(GS.gsBody).on("click", function(e) {
					e.preventDefault();
					e.stopPropagation();
					
					clearTimeout(GS.t);
					GS.anim(-1);
				});
			}
			
			if(GS.options.nav.right && GS.slides > 1)
			{
				var rightArrow = $("<div/>").addClass("nav-arrow-right").appendTo(GS.gsBody).on("click", function(e) {
					e.preventDefault();
					e.stopPropagation();
					
					clearTimeout(GS.t);
					GS.anim(1);
				});
			}
			
			if(GS.options.nav.fullscreen)
			{
				var fs = $("<div/>").addClass("nav-fullscreen-off").appendTo(GS.gsBody).on("click", function(e) {
					e.preventDefault();
					e.stopPropagation();
					
					if($(this).hasClass("nav-fullscreen-off"))
					{
						GS.options.display = "relative";
						$(this).removeClass("nav-fullscreen-off");
						$(this).addClass("nav-fullscreen-on");
						GS.gsShader = GS.gsShader ? GS.gsShader : $("<div/>").attr("id",GS.id +"-shader").addClass(GS.id +"-shader").insertAfter(GS.gsBody);
						GS.gsBody.addClass("fullscreen");
						
						var w = GS.gsContent.width();
						var h = GS.gsContent.height();
						$(".box img", GS.gsContent).each(function(i) {
							GS.fitImage($(this), GS.imgArray[i].video_id, w, h, true);
							
							$(this).css("margin-top", (GS.gsContent.height() - GS.imgResizedDimentions[GS.imgArray[i].video_id].h)/2);
							$(this).css("margin-left", (GS.gsContent.width() - GS.imgResizedDimentions[GS.imgArray[i].video_id].w)/2);
						});
					}
					else if($(this).hasClass("nav-fullscreen-on"))
					{
						GS.options.display = "static";
						$(this).removeClass("nav-fullscreen-on");
						$(this).addClass("nav-fullscreen-off");
						GS.gsShader.remove();
						GS.gsShader = null;
						GS.gsBody.removeClass("fullscreen");
						
						$(".box img", GS.gsContent).each(function(i) {
							$(this).removeAttr("style");
						});
					}
				});
			}
			
			if(GS.options.nav.slideShow)
			{
				var fs = $("<div/>").addClass("nav-slideshow-off").appendTo(GS.gsBody).on("click", function(e) {
					e.preventDefault();
					e.stopPropagation();
					
					if($(this).hasClass("nav-slideshow-off"))
					{
						$(this).removeClass("nav-slideshow-off");
						$(this).addClass("nav-slideshow-on");
						if(!GS.showingVideo)
						{
							GS.options.rotateTime = 10;
							GS.t = setTimeout(function() {
								GS.anim();
							}, GS.options.rotateTime * 1000);
						}
					}
					else if($(this).hasClass("nav-slideshow-on"))
					{
						$(this).removeClass("nav-slideshow-on");
						$(this).addClass("nav-slideshow-off");
						GS.options.rotateTime = 0;
						clearTimeout(GS.t);
					}
				});
			}
			
			if(GS.options.display == "relative")
			{
				var w = $("#"+ GS.id +" .content").width();
				var h = $("#"+ GS.id +" .content").height();
				var r;
				$("#"+ GS.options.node +" .content img").each(function(i) {
					GS.fitImage($(this), GS.imgArray[i].video_id, w, h);
				});
				
				if(GS.options.resizeble)
					$(window).on("resize", function() { GS.resize(); });
			}
			else if(GS.options.display == "static") {}
			
			if(GS.options.mouseEvents && !GS.options.nav.slideShow)
			{
				GS.gsBody.on('mouseenter', function(evt) {
					if(GS.showingVideo)
						return false;
					
					clearTimeout(GS.t);
				});
				
				GS.gsBody.on('mouseleave', function(evt) {
					if(GS.showingVideo)
						return false;
					
					if(GS.options.rotateTime > 0)
						GS.t = setTimeout(function(){
							GS.anim();
						}, GS.options.rotateTime * 1000);
				});
			}
			else if(GS.options.thumbs)
			{
				GS.gsThumbs.on('mouseenter', function(evt) {
					if(GS.showingVideo)
						return false;
					
					clearTimeout(GS.t);
				});
				
				GS.gsThumbs.on('mouseleave', function(evt) {
					if(GS.showingVideo)
						return false;
					
					if(GS.options.rotateTime > 0)
						GS.t = setTimeout(function() {
							GS.anim();
						}, GS.options.rotateTime * 1000);
				});
			}
			
			GS.fadeIn($(".current", GS.gsBody));
			if(GS.options.rotateTime > 0)
				GS.t = setTimeout(function() {
					GS.anim();
				}, GS.options.rotateTime * 1000);
			
			loader.remove();
			GS.gsBody.removeClass("loading");
			GS.initialized = true;
		});
		
		$(window).on('gs-imgLoaded', function() {
			$.each($("#"+ GS.id + " img"), function(i, v)
			{
				$(this).remove();
			});
			$(window).trigger('gs-ready');
		});
		
		var delay = true;
		var a = [];
		if(!GS.options.ajax) {
			if($("#"+ GS.id + " img").length < 1)
			{
				loader.remove();
				GS.gsBody.remove();
				GS.initialized = true;
			}
		
			$.each($("#"+ GS.id + " img"), function(i, v)
			{
				var img = $(this);
				img.css({visibility:"hidden", position:"absolute", top:0, left:0});
				b = {};
				b.src = img.attr("src") || false;
				b.title = img.attr("title") || false;
				b.desc = img.attr("descr") || false;
				b.href = img.attr("link") || false;
				b.thumbTitle = img.attr("tTitle") || false;
				b.thumb = img.attr("thumb") || $(this).attr("src");
				b.fullimg = img.attr("fullimg") || null;
				b.video = img.attr("vid") || false;
				b.video_id = img.attr("item_id") || false;
				a.push(b);
				GS.slides = Number(i + 1);
				img.onImageLoaded({index: i}, function(e) {
				//img.on('load', {index: i}, function(e) {
					var el = $(this);
					GS.imgDimentions[e.data.index] = GS.dimensions(el);
					GS.imgDimentionsOrigin[e.data.index] = {w:el.width(), h:el.height()};
					GS.readyState = GS.readyState + 1;
					
					if(GS.readyState == GS.slides)
						$(window).trigger('gs-imgLoaded');
				});
			});
		}
		else {
			var url = Core.baseUrl + (GS.options.requestUrl ? GS.options.requestUrl : '/get-slides') + (GS.options.amount ? '/amount/'+ GS.options.amount : '');
			$.ajax({
				url: url,
				type: 'GET',
				dataType: 'json',
				cache: true
			})
			.done(function(data) {
				if (data.error != 1) {
					for(var i = 0; i < data.items.length; i++) {
						b = {};
						b.src = data.items[i].src || false;
						b.title = data.items[i].title || false;
						b.desc = data.items[i].desc || false;
						b.href = data.items[i].link || false;
						b.thumbTitle = data.items[i].title || false;
						b.thumb = data.items[i].thumb || data.items[i].src;
						b.fullimg = data.items[i].fullimg || null;
						b.video = data.items[i].vid || false;
						b.video_id = data.items[i].item_id || false;
						a.push(b);
						GS.slides = Number(i + 1);
					}
					$(window).trigger('gs-ready');
				}
				else
					Core.showMsg.show("There was an error!");
			})
			.fail(function() {
				Core.showMsg.show("There was an error!");
			});
		}
		
		GS.imgArray = a;
	},
	
	/**
	 * Fading animation
	 */
	fadeIn: function(node) {
		fnode = this.options.fullbody ? $("#"+ node.attr("id") +"full") : null;
		node.addClass("current");
		$('#'+ node.attr('id') +'t').addClass("active");
		node.show();
		node.animate({
			opacity: 1
		},
		GS.options.animTime,
		function() {
			node.show();
		});
		if(fnode) {
			fnode.addClass("current");
			fnode.show();
			fnode.animate({
				opacity: 1
			},
			GS.options.animTime,
			function() {
				node.show();
			});
		}
	},
	
	fadeOut: function(node) {
		fnode = this.options.fullbody ? $("#"+ node.attr("id") +"full") : null;
		node.removeClass("current");
		$('#'+ node.attr('id') +'t').removeClass("active");
		node.animate({
			opacity: 0
		},
		GS.options.animTime,
		function() {
			node.hide();
		});
		if(fnode) {
			fnode.removeClass("current");
			fnode.animate({
				opacity: 0
			},
			GS.options.animTime,
			function() {
				fnode.hide();
			});
		}
	},
	
	/**
	 * Slideing animation
	 */
	slideIn: function(node) {
		fnode = this.options.fullbody ? $("#"+ node.attr("id") +"full") : null;
		node.addClass("current").css({top:"-"+ GS.imgDimentions[node.attr("data-index")].h +"px", opacity:1, zIndex:2});
		$('#'+ node.attr('id') +'t').addClass("active");
		node.show();
		node.animate({
			top: 0
		},
		GS.options.animTime,
		function() {
			node.show();
		});
		if(fnode) {
			fnode.addClass("current");
			fnode.show();
			fnode.animate({
				opacity: 1
			},
			GS.options.animTime,
			function() {
				node.show();
			});
		}
	},
	
	slideOut: function(node) {
		fnode = this.options.fullbody ? $("#"+ node.attr("id") +"full") : null;
		node.removeClass("current").css({zIndex:1});
		$('#'+ node.attr('id') +'t').removeClass("active");
		var tmp = setTimeout(function() {
			node.hide();
			clearTimeout(tmp);
		},
		GS.options.animTime);
		
		if(fnode) {
			fnode.removeClass("current");
			fnode.animate({
				opacity: 0
			},
			GS.options.animTime,
			function() {
				fnode.hide();
			});
		}
	},
	
	animateSlideChange: function(cur,node,animType)
	{
		switch(animType)
		{
			case "fade":
				GS.fadeOut(cur);
				GS.fadeIn(node);
				break;
			case "slide":
				GS.slideOut(cur);
				GS.slideIn(node);
				break;
			default:
				GS.fadeOut(cur);
				GS.fadeIn(node);
				break;
		}
	},
	
	anim: function(d) {
		if(GS.slides == 1)
			return false;
		
		if(!d) d = 1;
		var slide = $(".current", GS.gsBody);
		var str = slide.attr('id');
		if(d > 0) {
			var n = parseInt(str.match(/\d+/)) + 1;
			if(n > GS.slides - 1)
				n = 0;
			var next = $('#gs'+ n);
		}
		else if(d < 0) {
			var n = parseInt(str.match(/\d+/)) - 1;
			if(n < 0)
				n = GS.slides - 1;
			var next = $('#gs'+ n);
		}
		
		var n = parseInt(GS.options.rotateTime * 1000 + GS.options.animTime);
		if(GS.options.rotateTime > 0)
			GS.t = setTimeout(function() {
				GS.anim();
			}, n);
		GS.animateSlideChange($(".current", GS.gsBody), next, GS.animType);
	},
	
	resize: function(m) {
		m = m || this;
		
		var parent = $('#'+ m.options.node);
		var c = $(".content", parent);
		var t = $(".thumbs-wrapper", parent);
		var w = c.width();
		var h = c.height();
		var r;
		
		$("img", c).each(function(i) {
			GS.fitImage($(this), GS.imgArray[i].video_id, w, h);
		});
	},
	
	fitImage: function(img, index, w, h, leaveSmall) {
		var imgW = GS.imgDimentions[index].w;
		var imgH = GS.imgDimentions[index].h;
		r = imgW / imgH;
		
		if(imgW > w && w > (h * r)) {
			$(img).css("width", w);
			$(img).css("height", null);
			GS.imgResizedDimentions[index] = {w:w, h:w / r};
		}
		else if(imgW > w && w < (h * r)) {
			$(img).css("width", null);
			$(img).css("height", h);
			$(img).css("left", "-"+ Math.round(((h * r) - w) / 2) +"px");
			GS.imgResizedDimentions[index] = {w:h * r, h:h};
		}
		else if(imgW < w && w > (h * r) && !leaveSmall) {
			$(img).css("width", w);
			$(img).css("height", null);
			GS.imgResizedDimentions[index] = {w:w, h:w / r};
		}
		else if(imgW < w && w < (h * r) && !leaveSmall) {
			$(img).css("width", null);
			$(img).css("height", h);
			$(img).css("left", "-"+ Math.round(((h * r) - w) / 2) +"px");
			GS.imgResizedDimentions[index] = {w:h * r, h:h};
		}
		else if(leaveSmall) {
			GS.imgResizedDimentions[index] = {w:imgW, h:imgH};
		}
	},
	
	dimensions: function(itm)
	{
		var w = GS.gsContent.width(),
			h = GS.gsContent.height(),
			r = w / h,
			itmW = itm.width(),
			itmH = itm.height(),
			itmR = itmW/itmH,
			tmpW,
			tmpH,
			itmRealW = itm[0].naturalWidth,
			itmRealH = itm[0].naturalHeight;
		
		if(itmW > w)
		{
			tmpW = w;
			tmpH = Math.round(tmpW / itmR);
		}
		else if(itmH > h)
		{
			tmpH = h;
			tmpW = Math.round(tmpH * itmR);
		}
		else if(itmRealW > itmW && itmRealW > w)
		{
			tmpW = w;
			tmpH = Math.round(tmpW / itmR);
		}
		else if(itmRealH > itmH && itmRealH > h)
		{
			tmpH = h;
			tmpW = Math.round(tmpH * itmR);
		}
		else if(itmRealW > itmW && itmRealW < w)
		{
			tmpW = itmRealW;
			tmpH = Math.round(tmpW / itmR);
		}
		else if(itmRealH > itmH && itmRealH < h)
		{
			tmpH = itmRealH;
			tmpW = Math.round(tmpH * itmR);
		}
		else
		{
			tmpW = itmW;
			tmpH = itmH;
		}
		
		/*if(tmpW > w)
			return {w:w, h:Math.round(w / r)}
		else if(tmpH > h)
			return {w:Math.round(h * r), h:h}
		else*/
			return {w:tmpW, h:tmpH}
	},
	
	callVideoPlayer: function(e, el, obj, index) {
		e.preventDefault();
		e.stopPropagation();
		
		var caller = el.parent();
		GS.prevCont = caller.html();
		caller.empty();
		clearTimeout(GS.t);
		GS.showingVideo = true;
		Player.init({id:"player_"+ index, url:obj.video, thumbnail:obj.src, type:"rtmp", server:Core.baseUrl, thumbnailId:obj.video_id, node:"gs"+ index, w:"100%", h:"100%", quality:false})
			.onShow(function() {
				$('<div class="hide">&times;</div>').appendTo("#gs"+ index +"t").on("click", function(e) {
					e.preventDefault();
					e.stopPropagation();
					caller.empty().html(GS.prevCont);
					GS.showingVideo = false;
					GS.t = setTimeout(function() { GS.anim(); }, GS.options.rotateTime * 1000);
					$('a.box', caller).on("click", function(e) {
						GS.callVideoPlayer(e, $(this), obj, index);
					});
					$(this).off("click").remove();
				});
			})
			.show();
	}
};


A B C D E F G H I J K L M N O P Q R S T U V W X Y Z