Advertisement
Guest User

Snippet

a guest
Nov 27th, 2014
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * @copyright   2014 Galaxy Developments
  3. * @author:     Eran Machiels
  4. */
  5.  
  6. var Galaxy = (function (Galaxy) {
  7.     //'use strict';
  8.     var url = 'http://localhost/Galaxy/';
  9.  
  10.     var Init = function () {
  11.         setContentboxWidth();
  12.         initNews();
  13.         console.log('Galaxy Core Initialized');
  14.     };
  15.  
  16.     var Redirect = function (page, target) {
  17.         window.open(page, target);
  18.     };
  19.  
  20.     var setContentboxWidth = function () {
  21.         var contentBox = $('.contentBox');
  22.  
  23.         for(var i = 0; i < contentBox.length; i++) {
  24.             var parentWidth = $(contentBox[i]).parent().width();
  25.             $(contentBox[i]).css({width: parentWidth - 5})
  26.         }
  27.     };
  28.  
  29.     /*var getCurrency = function () {
  30.  
  31.         $.ajax({
  32.             url: url + 'requests/requestcurrency',
  33.             type: 'GET',
  34.             succes: function (data) {
  35.                 for(var currency in data) {
  36.                     if(!data.hasOwnProperty(currency)) continue;
  37.                     $('.currencyIndicator#' + currency.type).find('span').text(currency.ammount);
  38.                 };
  39.             }
  40.         });
  41.     };*/
  42.  
  43.     var initNews = function () {
  44.         var captions = $('#newsContainer').find('.newsCaptionContainer .caption');
  45.  
  46.         var triggerNextNewsitem = function () {
  47.             var captions = $('#newsContainer').find('.newsCaptionContainer .caption'),
  48.                 firstNews = captions.first(),
  49.                 selectedNews = $('#newsContainer').find('.newsCaptionContainer li.selected'),
  50.                 newsCount = captions.length;
  51.  
  52.             if((selectedNews.index() + 1) == newsCount) {
  53.                 firstNews.trigger("click");
  54.             }  else {
  55.                 selectedNews.next().trigger("click");
  56.             }
  57.         };
  58.         var interval = setInterval(triggerNextNewsitem, 5000);
  59.  
  60.         captions.on('click', function () {
  61.             var id = $(this).attr('newsid');
  62.             if($(this).hasClass('selected')) {
  63.                 return;
  64.             } else {
  65.                 captions.removeClass('selected');
  66.             }
  67.             $(this).addClass('selected');
  68.         });
  69.  
  70.         $('#newsContainer').on('mouseover', function () {
  71.             clearInterval(interval);
  72.         }).on('mouseleave', function () {
  73.             interval = setInterval(triggerNextNewsitem, 5000);
  74.         });
  75.     };
  76.  
  77.     (function () {
  78.         $ = window.jQuery;
  79.         $(document).ready(Init);
  80.     })();
  81.  
  82.     return Galaxy;
  83.  
  84. })(Galaxy || {});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement