Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 1st, 2012  |  syntax: None  |  size: 5.75 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ;jQuery.RBGStart = function(RBGSettings){
  2.         RBGSettings = jQuery.extend({
  3.                 styleURL: '',
  4.                 jsonURL: '',
  5.                 baseURL: ''
  6.         }, RBGSettings);
  7.         var cssURL = RBGSettings.baseURL+RBGSettings.styleURL,
  8.                 jsonURL = RBGSettings.baseURL+RBGSettings.jsonURL;
  9.        
  10.         function addCss() {
  11.                 $('head').append('<link>');
  12.                 $('head').children(':last').attr({ rel: 'stylesheet', type: 'text/css', href: cssURL, id: 'RBGCssFile' });
  13.         };
  14.         function buildBase() {
  15.                 if ($('#RBGCssFile').length) return; else addCss();
  16.                 $('body').append('<div>').children(':last').attr({ id: 'RBGFader' });
  17.                 $('#RBGFader').append('<div id="RBG-Box"></div>').children('#RBG-Box').hide();
  18.                 $('#RBG-Box').append('<a href="#" class="hideRBG">X</a>');
  19.                 $('#RBG-Box').append('<div id="RBG-View"></div>');
  20.                 $('#RBG-Box').append('<div id="RBG-Control"></div>');
  21.                 $('#RBG-Control').append('<ul id="RBG-Thumbs"></ul>');
  22.         };
  23.         function getItems() {
  24.                 $.getJSON(jsonURL,function(json){
  25.                         var lastPic = $('#RBG-View').children('.RBG-Pic:last'),
  26.                                 lastVid = $('#RBG-View').children('.RBG-Vid:last'),
  27.                                 lastSpecs = $('#RBG-View').children('.RBG-Specs:last');
  28.                         // Check for pictures
  29.                         if (json.pictures.picture === undefined) null;
  30.                         else {
  31.                                 $.each(json.pictures.picture,function(i,s){
  32.                                         if (s.imgURL === undefined) {
  33.                                                 null;
  34.                                         } else {
  35.                                                 if (s.title === undefined && s.thumbURL === undefined) {
  36.                                                         null;
  37.                                                 } else {
  38.                                                         $('#RBG-View').append('<div class="RBG-Pic" id="opt-'+(i+1)+'">');
  39.                                                         lastPic.css({
  40.                                                                 background: 'url("'+s.imgURL+'") no-repeat center',
  41.                                                                 width: s.width,
  42.                                                                 height: s.height
  43.                                                         }).attr('id', 'opt-'+ (i+1));
  44.                                                         if (s.title === undefined) null;
  45.                                                         else lastPic.append('<h1 class="RBG-Title"><a title="'+s.title+'" href="'+s.hrefURL+'">'+s.title+'</a></h1>');
  46.                                                         $.each(json,function(key,val) {
  47.                                                                 if (key == 'title' || key == 'hrefURL' || key == 'imgURL' || key == 'thumbURL' || key == 'height' || key == 'width' || key == 'description' ) null;
  48.                                                                 else {
  49.                                                                         lastPic.append('<span class="RBG-Specs"><'+key+'</span>');
  50.                                                                         lastSpecs.append('<var>'+val+'</var>');
  51.                                                                 };
  52.                                                         });
  53.                                                         if (s.description === undefined) null;
  54.                                                         else lastPic.append('<div class="RBG-Desc">'+s.description+'</div>');
  55.                                                         if (s.thumbURL === undefined) $('#RBG-Thumbs').append('<li><a href="#opt-'+(i+1)+'" title="'+s.title+'">'+s.title+'</a></li>');
  56.                                                         else $('#RBG-Thumbs').append('<li><a href="#opt-'+(i+1)+'" title="'+s.title+'"><img width="80px" height="80px" title="'+s.title+'" alt="'+s.title+'" src="'+s.thumbURL+'" /></a></li>');
  57.                                                 };
  58.                                         };
  59.                                 });
  60.                         };
  61.                         if (json.videos.video === undefined) null;
  62.                         else {
  63.                                 $.each(json.videos.video,function(i,s){
  64.                                         if (s.vidURL === undefined) {
  65.                                                 null;
  66.                                         } else {
  67.                                                 if (s.title === undefined && s.thumbURL === undefined) {
  68.                                                         null;
  69.                                                 } else {
  70.                                                         $('#RBG-View').append('<div class="RBG-Pic" id="opt-'+(i+1)+'">');
  71.                                                         lastVid.css({
  72.                                                                 background: 'url("'+s.bgURL+'") no-repeat center',
  73.                                                                 width: s.width,
  74.                                                                 height: s.height
  75.                                                         }).attr('id', 'opt-'+ (i+1));
  76.                                                         if (s.title === undefined) null;
  77.                                                         else lastVid.append('<h1 class="RBG-Title"><a title="'+s.title+'" href="'+s.hrefURL+'">'+s.title+'</a></h1>');
  78.                                                         $.each(json,function(key,val) {
  79.                                                                 if (key == 'title' || key == 'hrefURL' || key == 'imgURL' || key == 'thumbURL' || key == 'height' || key == 'width' || key == 'description' ) null;
  80.                                                                 else {
  81.                                                                         lastVid.append('<span class="RBG-Specs"><'+key+'</span>');
  82.                                                                         lastSpecs.append('<var>'+val+'</var>');
  83.                                                                 };
  84.                                                         });
  85.                                                         if (s.description === undefined) null;
  86.                                                         else lastVid.append('<div class="RBG-Desc">'+s.description+'</div>');
  87.                                                         if (s.thumbURL === undefined) $('#RBG-Thumbs').append('<li><a href="#opt-'+(i+1)+'" title="'+s.title+'">'+s.title+'</a></li>');
  88.                                                         else $('#RBG-Thumbs').append('<li><a href="#opt-'+(i+1)+'" title="'+s.title+'"><img width="80px" height="80px" title="'+s.title+'" alt="'+s.title+'" src="'+s.thumbURL+'" /></a></li>');
  89.                                                 };
  90.                                         };
  91.                                 });
  92.                         };
  93.                 });
  94.         };
  95.         function readyGal() {
  96.                 // Hide all content, and only show one to activate tabs
  97.                 $('.RBG-Pic').hide(); //Hide all content
  98.                 $('#RBG-Thumbs li:first').addClass('active').show();
  99.                 $('.RBG-Pic:first').show();
  100.                 // After RBG-Box is hidden JQuery will turn it back in to a block,
  101.                 // so before fading it in turn it in to an inline-block
  102.                 $('#RBG-Box').css({display: 'inline-block'}).delay(150).show();
  103.                 $('#RBGFader').fadeIn(300); // In case the fader is hidden in the CSS hidden
  104.         };
  105.         function clearGal() { $('RBG-View').empty(); };
  106.         function errorMsg(message) {
  107.                 $('#RGB-Box').html('<h1>Failure! Here is why:<h1><p>'+message+'</p>');
  108.         };
  109.         function startGal() {
  110.                 if($('.RGB-Pic, .RGB-Vid').length) clearGal(); else buildBase();
  111.                 if(getItems() === null) errorMsg('Either the items in the JSON are lacking titles or thumbs or the file is not compliant with RGB:<br><b>'+RBGSettings.baseURL+RBGSettings.jsonURL+'</b>');
  112.                 readyGal();
  113.         };
  114.         $(document).ready(function(e){
  115.                 $(document).keyup(function(e) {
  116.                         if (e.keyCode == 27) { $('#RBGFader').fadeOut(300); }   // Escape to Hide RBGFader
  117.                 });
  118.                 // Tab function control start
  119.                 $('#RBG-Thumbs li').click(function() {
  120.                         if ($(this).hasClass('active'))
  121.                         return false; // Tab already selected
  122.                        
  123.                         $('#RBG-Thumbs li').removeClass('active');
  124.                         $(this).addClass('active');
  125.                         $('.RBG-Pic').hide();
  126.                
  127.                         var activeTab = $(this).find('a').attr('href');
  128.                         $(activeTab).fadeIn();
  129.                         return false;
  130.                 });
  131.                 // Tab function control end
  132.                 $('.hideRBG').click(function(){
  133.                         $('#RBGFader').fadeOut(300);
  134.                 });
  135.                 $('.showRBG').click(function(){
  136.                         $('#RBGFader').fadeIn(300);
  137.                 });
  138.         });
  139. };