Advertisement
Guest User

Untitled

a guest
Jan 24th, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (function() {
  2.    
  3.     var socket = io.connect('/');
  4.  
  5.     /**
  6.      * [Namespacing]
  7.      */
  8.     var Insta = Insta || {};
  9.    
  10.     Insta.App = {
  11.  
  12.         /**
  13.          * [Application initialization method / call for the methods being initializated in order]
  14.          */
  15.         init: function() {
  16.             this.mostRecent();
  17.             this.getData();
  18.             //this.aboutInfo();
  19.             //this.mobileNav();
  20.             //this.attachImageClicked();
  21.             this.contextMenu();
  22.             //this.mostInstantlyUpdate();
  23.         },
  24.         /**
  25.          *
  26.          */
  27.         mostInstantlyUpdate: function () {
  28.             var self = this;
  29.             socket.on('newinstantlyphoto', function(data) {
  30.                 self.renderTemplate(data);
  31.             });
  32.         },
  33.         /**
  34.          *
  35.          */
  36.         contextMenu: function () {
  37.             var $contextMenu = $("#contextMenu");
  38.  
  39.             var target;
  40.  
  41.             $("body").on("contextmenu", "a", function(e) {
  42.                 target = $(e.target).parent();
  43.                 $contextMenu.css({
  44.                     display: "block",
  45.                     left: e.pageX,
  46.                     top: e.pageY
  47.                 });
  48.                 return false;
  49.             });
  50.  
  51.             $contextMenu.on("click", "a", function() {
  52.                 if (target) {
  53.                     target.parent().hide( "slow" ); /*made changes. added parent() here */
  54.                 }
  55.             });
  56.  
  57.             $(document).on("click", function() {
  58.                 $contextMenu.hide();
  59.                 target = null;
  60.             });
  61.         },
  62.        
  63.         /**
  64.          * []
  65.          */
  66.         attachImageClicked: function(e){
  67.  
  68.             var self = this,
  69.             context = {};
  70.  
  71.             $(imgContent).on('click', 'img.photo', function(e){
  72.  
  73.                 e.preventDefault();
  74.  
  75.                 context.url = $(this).attr("src");
  76.                 context.caption = $(this).attr("alt");
  77.                 context.username = $(this).attr("data-photo-username");
  78.                 context.created_time = $(this).attr("data-created-time");
  79.  
  80.                 new Dialog(context, socket);
  81.                
  82.             })
  83.         },
  84.        
  85.         /**
  86.          * [Interaction to open mobile navigation]
  87.        
  88.         mobileNav: function() {
  89.             var btMobNav = $('#js-mobNav'),
  90.                 nav = $('.nav');
  91.  
  92.             btMobNav.on('click', function(e) {
  93.                 e.preventDefault();
  94.                 if( !nav.hasClass('active') ) {
  95.                     nav.addClass('active');
  96.                 } else {
  97.                     nav.removeClass('active');
  98.                 }
  99.             });
  100.  
  101.         },
  102.          */
  103.         /**
  104.          * [get data ajax and send to render method]
  105.          */
  106.         getData: function() {
  107.             var self = this;
  108.             socket.on('show', function(data) {
  109.                 var url = data.show;
  110.                 $.ajax({
  111.                     url: url,
  112.                     type: 'POST',
  113.                     crossDomain: true,
  114.                     dataType: 'jsonp'
  115.                 }).done(function (data) {
  116.                     self.renderTemplate(data);
  117.                 });
  118.             });
  119.         },
  120.  
  121.         /**
  122.          * [Render the images on the page and check for layout resize]
  123.          */
  124.         renderTemplate: function(data) {
  125.             var lastAnimate, lastSrc, nextSrc, last,
  126.                 current = data.data[0].images.standard_resolution.url,
  127.                 w = $(document).width();
  128.  
  129.                 var
  130.                     query = data,
  131.                     source = $('#mostRecent-tpl').html(),
  132.                     compiledTemplate = Handlebars.compile(source),
  133.                     result = compiledTemplate(query),
  134.                     imgWrap = $('#imgContent');
  135.  
  136.                 imgWrap.prepend(result);
  137.  
  138.                 noofphoto = $('#imgContent div.photoslide').size();
  139.                 //console.log(noofphoto);
  140.  
  141.                 last = $('#imgContent div:first-child');
  142.                 lastSrc = $('#imgContent div:first-child').find('img.photo').attr('src');
  143.                 nextSrc = $('#imgContent div:nth-child(2)').find('img.photo').attr('src');
  144.  
  145.                 if( lastSrc === nextSrc ) {
  146.                     last.remove();
  147.                 }
  148.  
  149.                 last = $('#imgContent').find('div:first-child').removeClass('Hvh');
  150.  
  151.                 if( w >= 900 ) {
  152.                     lastAnimate = $('#imgContent').find('div:nth-child(2)').addClass('animated slideInLeft'); /*change here for animation*/
  153.                 }
  154.                 /*
  155.  
  156.                 $(window).resize(function() {
  157.                     var w = $(document).width();
  158.                     if( w >= 900 ) {
  159.                         lastAnimate = $('#imgContent').find(':nth-child(2)').addClass('animated fadeInLeft');
  160.                     }
  161.  
  162.                     if( w <= 900 ) {
  163.                         lastAnimate = $('#imgContent').find(':nth-child(1)').addClass('animated fadeInDown');
  164.                     }
  165.                 });*/
  166.         },
  167.  
  168.         /**
  169.          * [ render most recent pics defined by subscribed hashtag ]
  170.          */
  171.         mostRecent: function() {
  172.             socket.on('firstShow', function (data) {
  173.                 var clean = $('imgContent').find('a').remove();
  174.                 var
  175.                     query = data,
  176.                     source = $('#firstShow-tpl').html(),
  177.                     compiledTemplate = Handlebars.compile(source),
  178.                     result = compiledTemplate(query),
  179.                     imgWrap = $('#imgContent');
  180.                    // console.log(query);
  181.  
  182.                 imgWrap.html(result);
  183.             });
  184.         }
  185.  
  186.         /**
  187.          * [about view interaction show/hide]
  188.        
  189.         aboutInfo: function() {
  190.             var about = $('.aboutWrap'),
  191.                 btClose = $('#js-closeAbout').find('a'),
  192.                 bt = $('#js-btAbout'),
  193.                 user = localStorage.getItem('user');
  194.  
  195.             if( user ) {
  196.                 about.removeClass('active');
  197.             } else {
  198.                 localStorage.setItem('user', 'visited');
  199.             }
  200.  
  201.             btClose.on('click', function(e) {
  202.                 e.preventDefault();
  203.                 about.removeClass('active');
  204.             });
  205.  
  206.             bt.on('click', function(e) {
  207.                 e.preventDefault();
  208.                 if( !about.hasClass('active') ) {
  209.                     about.addClass('active');  
  210.                 } else {
  211.                     about.removeClass('active');
  212.                 }
  213.             });
  214.  
  215.         } */
  216.  
  217.     };
  218.  
  219.     Insta.App.init();
  220.  
  221. })(this);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement