Guest User

sun

a guest
Apr 9th, 2013
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // #Initialization
  2. // _Declaration of variables and initial initialization_
  3. var city, xPos, xOrg, xCor, pinch = false, time, icon, info, reveal, blur;
  4. var doc = $(this);
  5. active = 1;
  6. //$('head').append('<meta name="viewport" content="user-scalable=0, initial-scale=1.0">');
  7. $('body').removeClass('preview').addClass('initialize').html('<div id="app"><div id="box"><div id="layer"><div class="slide"><div class="background"></div><a class="in">In</a><div class="pagination"><span class="active"></span><span></span><span></span><span></span></div></div></div></div></div>');
  8. if(!window.navigator.onLine) {
  9.     $('.pagination').hide();
  10.     $(document).bind('touchstart', function(e) {
  11.         e.preventDefault();
  12.     });
  13.     notification("Sun requires a working 3G or WiFi connection.");
  14. } else {
  15.     var tz = jstz.determine().name();
  16.     if(tz == 'Europe/Berlin') {
  17.         var timezone = 'normal';
  18.     } else {
  19.         var timezone = tz;
  20.     }
  21.     // Check if a new cache is available on page load.
  22.     window.addEventListener('load', function(e) {
  23.         window.applicationCache.addEventListener('updateready', function(e) {
  24.             if (window.applicationCache.status == window.applicationCache.UPDATEREADY) {
  25.                 notification("An update has been installed.");
  26.                 window.applicationCache.swapCache();
  27.             } else {
  28.                 // Manifest didn't change. Nothing new to server.
  29.             }
  30.         }, false);
  31.     }, false);
  32.    
  33.     // #Application start
  34.     // _Take-off_
  35.     $('.slide').append('<div class="loading" />');
  36.    
  37.     // #First Time
  38.     // _If a user visits for the first time — fill in local storage values_
  39.     if(localStorage.getItem("init2") != 'false') {
  40.         localStorage.setItem("init2", 'false');
  41.         if(navigator.language == 'en-US') {
  42.             localStorage.setItem("unit", 'f');
  43.             localStorage.setItem("w_unit", 'mph');
  44.         } else {
  45.             localStorage.setItem("unit", 'c');
  46.             localStorage.setItem("w_unit", 'm/s');
  47.         }
  48.         localStorage.setItem("theme", 'pansage');
  49.        
  50.         localStorage.setItem("city0", 'Copenhagen'); // <3
  51.         localStorage.setItem("city1", 'Vienna');
  52.         localStorage.setItem("city2", 'Hong Kong');
  53.        
  54.         localStorage.setItem("city0-lat", '55.680682'); // Copenhagen
  55.         localStorage.setItem("city0-lon", '12.568703');
  56.         localStorage.setItem("city1-lat", '48.202541'); // Vienna
  57.         localStorage.setItem("city1-lon", '16.368799');
  58.         localStorage.setItem("city2-lat", '22.309426'); // Hong Kong
  59.         localStorage.setItem("city2-lon", '114.200134');
  60.        
  61.         localStorage.setItem("city0-id", '554890');
  62.         localStorage.setItem("city1-id", '551801');
  63.         localStorage.setItem("city2-id", '2165352');    
  64.     }
  65.    
  66.    
  67.    
  68.     // #Declaration
  69.     // _This will fuck completely, if a browser doesn't support localStorage — but this is an iOS concept_ //
  70.     var cities = [
  71.         [localStorage.getItem("city0"), localStorage.getItem("city0-lat"), localStorage.getItem("city0-lon"), localStorage.getItem("city0-id")],
  72.         [localStorage.getItem("city1"), localStorage.getItem("city1-lat"), localStorage.getItem("city1-lon"), localStorage.getItem("city1-id")],
  73.         [localStorage.getItem("city2"), localStorage.getItem("city2-lat"), localStorage.getItem("city2-lon"), localStorage.getItem("city2-id")]
  74.     ];
  75.    
  76.     unit = localStorage.getItem("unit"); // // Celcius (c) or Fahrenheit (f)
  77.     w_unit = localStorage.getItem("w_unit"); // Meters per second (m/s), kilometers per second (km/h) or, god forbid, miles per hour (mph)
  78.     theme = localStorage.getItem("theme"); // Setting theme, defaults to 'Jour'
  79.    
  80.    
  81.     //$('head').append('<link id="icon" rel="apple-touch-icon-precomposed" href="resources/icon_pastel.png" />');
  82.     iconID = Math.round(Math.random()*10000000000);
  83.     $('head').append('<link id="icon" rel="apple-touch-icon-precomposed" href="http://pattern.dk/sun/icon.php?id='+iconID+'" />');
  84.    
  85.     $('body').addClass(theme);
  86.    
  87.     var themes = ['Sunnyside', 'Pastels', 'Adrift', 'Stardust', 'Looper', 'Goldfish', 'Moon', 'Envious', 'Pansage'];
  88.     color = new Array();
  89.    
  90.     color['sunnyside'] = '#fbbc2b';
  91.     color['pastels'] = '#e17569';
  92.     color['adrift'] = '#26c9b4';
  93.     color['stardust'] = '#9395a1';
  94.     color['looper'] = '#33a6aa';
  95.     color['goldfish'] = '#00c8e4';
  96.     color['moon'] = '#e174a4';
  97.     color['envious'] = '#00a6ca';
  98.     color['pansage'] = '#11b2a1';
  99.     color['gordon'] = '#3e524f';
  100.    
  101.     var lists = ['Cities', 'Temperature', 'Wind', 'Colors', 'Credits'];
  102.    
  103.     var settings = $('<div id="settings" />').append('<div class="content" />').append('<div id="hide" />');
  104.     var smallDiv = $('<div id="small" />').append('<div id="slides" />');
  105.     var forecast = $('<div id="forecasts" />');
  106.    
  107.     forecast.appendTo($('#app'));
  108.     settings.appendTo($('#app'));
  109.     smallDiv.appendTo($('#app'));
  110.  
  111.     for(var i = 0; i < 4; i++) {
  112.         $('<div />').attr('class', 'slide').appendTo($('#slides'));
  113.     }
  114.     $.each(lists, function(i) {
  115.         var h2 = $('<h2>' + lists[i] + '</h2>');
  116.         var ul = $('<ul />').attr('class', lists[i].toLowerCase());
  117.         h2.appendTo( $('#settings .content') );
  118.         ul.appendTo($('#settings .content'));
  119.        
  120.         if(lists[i] == 'Temperature') {
  121.             ul.append('<li data-unit="c">Celsius</li><li data-unit="f">Fahrenheit</li>');
  122.         }
  123.        
  124.         if(lists[i] == 'Wind') {
  125.             ul.append('<li data-unit="m/s">Meters per second</li><li data-unit="km/h">Kilometers per hour</li><li data-unit="mph">Miles per hour</li>');
  126.         }
  127.         if(lists[i] == 'Credits') {
  128.             ul.append('<li><span></span></li>');
  129.         }
  130.     });
  131.     $.each(themes, function(i) {
  132.         var li = $('<li />');
  133.         for(var x = 0; x < 4; x++) {
  134.             $('<span />').attr('class', themes[i].toLowerCase()).appendTo(li);
  135.         }
  136.         li.attr('data-theme', themes[i].toLowerCase());
  137.         li.appendTo('ul.colors');
  138.     });
  139.    
  140.     $('a.back').live('touchstart', function() {
  141.         $(this).addClass('touchdown');
  142.         $(this).css('color', $(this).data('color'));
  143.     });
  144.     $('a.back').live('touchend', function() {
  145.         $(this).removeAttr('style');
  146.         $(this).removeClass('touchdown');
  147.     });
  148.     $('a.back').live('touchmove', function(e) {
  149.         e.preventDefault();
  150.         return false;
  151.     });
  152.     $('a.back').live('tap', function(e) {
  153.         pinchOut = true;
  154.         playSound('woosh2', 0);
  155.         $('body').addClass('unbuild')
  156.         $('body').removeClass('revealed build');
  157.         $(this).delay(450).queue(function(){
  158.             isActive = false;
  159.             pinchOut = false;
  160.             $('body').removeClass('animate unbuild');
  161.             $('.slide.active').removeClass('active');
  162.             $(this).dequeue();
  163.         });
  164.     });
  165.     $('.scroll ul li').live('tap', function() {
  166.         playSound('plop2', 0);
  167.         if($(this).hasClass('active')) {
  168.             $(this).removeClass('active');
  169.         } else {
  170.             $('.scroll ul li.active').removeClass('active');
  171.             $(this).addClass('active');
  172.            
  173.         }
  174.     });
  175.     $('#layer a.in').live('touchstart', function() {
  176.         if(!$('body').hasClass('settings')) {
  177.             isSettings = true;
  178.             isActive = true;
  179.             playSound('plop', 0);
  180.             $('body').addClass('settings');
  181.         }
  182.     });
  183.     $('.settings #box').live('touchstart', function() {
  184.         if(isInputActive == false) {
  185.             playSound('plop3', 0);
  186.             $('body').addClass('back').delay(250).queue(function() {
  187.                 isActive = false;
  188.                 $(this).removeClass('settings back');
  189.                 $(this).dequeue();
  190.             });
  191.         }
  192.     });
  193.     $('.settings #box').live('touchend', function() {
  194.         if(isInputActive == false) {
  195.             $(this).delay(250).queue(function() {
  196.                 isSettings = false;
  197.                 $(this).dequeue();
  198.             });
  199.         }
  200.     });
  201.     $('#slides').bind('touchstart', function(e) {
  202.         if($('body').hasClass('settings')) {
  203.             $('body').addClass('fadeout').delay(250).queue(function() {
  204.                 $(this).removeClass('settings fadeout');
  205.                 $(this).dequeue();
  206.             });
  207.             return false;
  208.         }
  209.         e.preventDefault();
  210.     });
  211.    
  212.     $('.chart').live('touchstart', function(e) {
  213.         e.preventDefault();
  214.         return false;
  215.     });
  216.     $('#small .slide').live('tap', function() {
  217.         if(isActive == true) {
  218.             isSettings = true;
  219.             isActive = false;
  220.             if($('body').hasClass('settings')) {
  221.                 $('body').removeClass('settings');
  222.             } else {
  223.                 playSound('woosh', 0);
  224.                 $('#small .slide').removeClass('non');
  225.                 $('#small .slide.active').removeClass('active');
  226.                 switch($(this).index()) {
  227.                     case 0:
  228.                         degree = 0;
  229.                         active = 1;
  230.                         break;
  231.                     case 1:
  232.                         degree = -90;
  233.                         active = 2;
  234.                         break;
  235.                     case 2:
  236.                         degree = -180;
  237.                         active = 3;
  238.                         break;
  239.                     case 3:
  240.                         degree = -270;
  241.                         active = 4;
  242.                         break;
  243.                     default:
  244.                         // Do nothing, yet?
  245.                 }
  246.                 $('#layer').css('-webkit-transform', 'translate3d(0px, 0px, -' + width/2 + 'px) rotate3d(0, 1, 0, ' + degree + 'deg)');
  247.                
  248.                 $(this).addClass('in').delay(250).queue(function() {
  249.                     $(this).removeClass('in');
  250.                     isSettings = false;
  251.                     $('body').removeClass('out');
  252.                     $(this).dequeue();
  253.                 });
  254.             }
  255.         }
  256.     });
  257.    
  258.     var gordon = 0;
  259.     $('.icon').live('tap', function() {
  260.         gordon++;
  261.         if(gordon == 25) {
  262.             notification('You just unleashed Robin.');
  263.             localStorage.setItem('theme', 'gordon');
  264.             $.each(themes, function(i) {
  265.                 if($('body').hasClass(themes[i].toLowerCase())) {
  266.                     $('body').removeClass(themes[i].toLowerCase());
  267.                 }
  268.             });
  269.             $('body').addClass('gordon').delay(2000).queue(function() {
  270.                 notification('Changing colors...');
  271.                 $('body').delay(250).queue(function() {
  272.                     $(this).delay(1500).queue(function() {
  273.                         location.reload(true);
  274.                         $(this).dequeue();
  275.                     });
  276.                     $(this).dequeue();
  277.                 });
  278.                 $(this).dequeue();
  279.             });                
  280.            
  281.            
  282.            
  283.         }
  284.     });
  285.    
  286.    
  287.     $('.weather').live('tap', function() {
  288.         if($(this).parents('.slide').parent().attr('id') != 'slides') {
  289.             isActive = true;
  290.             $('body').addClass('animate build');
  291.             $(this).parents('.slide').addClass('active');
  292.             playSound('woosh', 0);
  293.             $(this).delay(450).queue(function() {
  294.                 $('body').addClass('revealed');
  295.                 $(this).dequeue();
  296.             });
  297.         }
  298.     });
  299.    
  300.     if(localStorage.getItem("restart") != 'true') {
  301.         fetching(); // Fetches all available sounds with the Web Audio API, only supported on iOS 6.
  302.     }
  303.    
  304.     // #Settings
  305.     // _Applying settings and listening for any settings changes_ //
  306.    
  307.     $('#settings ul.temperature li[data-unit="'+unit+'"]').addClass('current');
  308.     $('#settings ul.wind li[data-unit="'+w_unit+'"]').addClass('current');
  309.     $('#settings ul.colors li[data-theme="'+theme+'"]').addClass('current').data('set', true);
  310.     var scrollable = document.getElementById("settings"); // WebKit in iOS 5 is fantastic, except for this weird behavior that bounces the entire view.
  311.     new ScrollFix(scrollable); // And totally fixed now.
  312.     function check(input) {
  313.         var name = input.val();
  314.         var index = input.parent().index();
  315.         if (name!=null && name!="") {
  316.             $.ajax({
  317.               url: 'find.php',
  318.               dataType: 'html',
  319.               type: 'post',
  320.               data: { city: name },
  321.               success: function(data) {
  322.                 if(data=='0') {
  323.                     notification("The city <strong>" + name + "</strong> didn't return any results.");
  324.                     input.val($(this).data('city'));
  325.                     blur = true;
  326.                     input.blur();
  327.                 } else {
  328.                     // 554890@[email protected]@12.56761 -> WOEID@City@lat@lon
  329.                    
  330.                    
  331.                    
  332.                     //localStorage.setItem('city' + index, name);  
  333.                     active = index + 2;
  334.                     blur = true;
  335.                     input.blur();
  336.                    
  337.                    
  338.                     var values = data.split("@");
  339.                     input.data('city', values[1]);
  340.                     input.val(values[1])
  341.                    
  342.                     $.ajax({
  343.                       url: 'api2.php',
  344.                       dataType: 'json',
  345.                       type: 'post',
  346.                       data: {
  347.                                 id: values[0],  
  348.                                 lat: values[2],
  349.                                 lon: values[3],
  350.                                 timezone: timezone
  351.                             },
  352.                       success: function(data) {
  353.                         graphData[index + 1] = '';
  354.                         weather(data, index + 1, values[1]);
  355.                        
  356.                         localStorage.setItem('city' + (index), values[1]);
  357.                         localStorage.setItem('city' + (index) + '-lat', values[2]);
  358.                         localStorage.setItem('city' + (index) + '-lon', values[3]);
  359.                         localStorage.setItem('city' + (index) + '-id', values[0]);
  360.                        
  361.                         //playSound('plop3', 0);
  362.                         $('#layer').css('-webkit-transform', 'translate3d(0px, 0%, -' + width/2 + 'px) rotate3d(0, 1, 0, ' + current() + 'deg)');
  363.                         $('body').addClass('back').delay(250).queue(function() {
  364.                             isActive = false;
  365.                             isSettings = false;
  366.                             $(this).removeClass('settings back');
  367.                             notification(values[1] + ' added.');
  368.                             $(this).dequeue();
  369.                         });
  370.                        
  371.                         $('#small div.slide:eq('+(index + 1)+')').html($('#layer .slide:eq('+(index + 1)+')').html());
  372.                       }
  373.                     });
  374.                 }
  375.               }
  376.             });
  377.         } else {
  378.             input.val(input.data('city'));
  379.         }
  380.     }
  381.     $('input').live('keydown', function(e) {
  382.         if(e.which == 13) {
  383.             e.preventDefault();
  384.             check($(this));
  385.         }
  386.     });
  387.     $('input').live('blur', function() {
  388.         if(blur!=true) {
  389.             check($(this));
  390.         } else {
  391.             blur = false;
  392.             $(this).val($(this).data('city'));
  393.         }
  394.         isInputActive = false;
  395.     });
  396.     $('input').live('focus', function() {
  397.         isInputActive = true;
  398.         $(this).val('');
  399.        
  400.     });
  401.    
  402.     $('ul.colors li').live('touchstart', function() {
  403.         if($(this).data('set') != true) $(this).addClass('current');
  404.     });
  405.     $('ul.colors li').live('touchend', function() {
  406.         if($(this).data('set') != true) $(this).removeClass('current');
  407.     });        
  408.    
  409.     $('#settings ul li').live('tap', function() {      
  410.         // Change of temperature units
  411.         if($(this).parent().attr('class') == 'temperature' && $(this).attr('class') != 'current') {
  412.             unit = $(this).data('unit');
  413.             localStorage.setItem('unit', unit);
  414.             $(this).parent().children('.current').removeClass('current');
  415.             $(this).addClass('current');
  416.             $('.slide > .weather .info > span, .forecast .data strong, ul.underlay li .temp strong').each(function() {
  417.                 $(this).html(convert(parseInt($(this).html().split('°')[0]), unit) + '°');
  418.             });
  419.            
  420.             for(var c = 0; c < 4; c++) {
  421.                 chart[c].destroy();
  422.                 chart[c] = '';
  423.                
  424.                 var arry = graphData[c].substring(0, graphData[c].length - 2).split(', ');
  425.                 var newString = '';
  426.                 for(var i=0; i<arry.length; i++){
  427.                     newString = newString + convert(arry[i], unit) + ', ';
  428.                 }
  429.                 graphData[c] = newString;
  430.                
  431.                 raw[c] = JSON.parse('[' + graphData[c].substring(0, graphData[c].length - 2) + ']');
  432.                 chart[c] = newChart(chartID[c], startDate[c], raw[c], chartColor[c]);
  433.             }
  434.            
  435.         }
  436.        
  437.         // Change of wind units
  438.         if($(this).parent().attr('class')=='wind' && $(this).attr('class')!='current') {
  439.             w_unit = $(this).data('unit');
  440.             localStorage.setItem('w_unit', w_unit);
  441.             $(this).parent().children('.current').removeClass('current');
  442.             $(this).addClass('current');
  443.            
  444.             $('ul.underlay li .temp span em').each(function() {
  445.                 var newWind = $(this).attr('data-orgwind');
  446.                 var save = newWind;
  447.                 if(w_unit == 'mph') {
  448.                     newWind = Math.round(newWind * 2.23693629);
  449.                 } else if (w_unit == 'km/h') {
  450.                     newWind = Math.round(newWind * 3.6);
  451.                 }
  452.                
  453.                 $(this).parent().html('<em data-orgwind="'+save+'">'+newWind+'</em> ' + w_unit);
  454.             })
  455.            
  456.         }
  457.        
  458.         // Change of themes
  459.         if($(this).parent().attr('class')=='colors' && $(this).attr('class')!='current') {
  460.             localStorage.setItem('theme', $(this).data('theme'));
  461.             $.each(themes, function(i) {
  462.                 if($('body').hasClass(themes[i].toLowerCase())) {
  463.                     $('body').removeClass(themes[i].toLowerCase());
  464.                 }
  465.             });
  466.             $('body').addClass($(this).data('theme')).delay(1000).queue(function() {
  467. //                      for(var c = 0; c < 4; c++) {
  468. //                          chart[c].destroy();
  469. //                          chart[c] = '';
  470. //                          raw[c] = JSON.parse('[' + graphData[c].substring(0, graphData[c].length - 2) + ']');
  471. //                          chartColor[c] = $('#layer .slide:eq('+c+') .background').css("background-color");
  472. //                          chart[c] = newChart(chartID[c], startDate[c], raw[c], chartColor[c]);
  473. //                          $('#' + chartID[c]).parent().css('background-color', chartColor[c]);
  474. //                      }
  475.                 localStorage.setItem('restart', 'true');
  476.                 $('#layer').css('-webkit-transform', 'translate3d(0px, 0%, -' + width/2 + 'px) rotate3d(0, 1, 0, ' + current() + 'deg)');
  477.                 notification('Changing colors...');
  478.                 $('body').addClass('back').delay(250).queue(function() {
  479.                     isActive = false;
  480.                     isSettings = false;
  481.                     $(this).removeClass('settings back');
  482.                    
  483.                     $(this).delay(1500).queue(function() {
  484.                         location.reload();
  485.                         $(this).dequeue();
  486.                     });
  487.                     $(this).dequeue();
  488.                 });
  489.                 $(this).dequeue();
  490.             });
  491.            
  492.             $(this).parent().children('.current').removeClass('current');
  493.             $(this).addClass('current');
  494.         }
  495.        
  496.     });
  497.    
  498.     // #Weather fetching
  499.     // _Google and Yahoo! in wonderful cooperation. Beautiful_ //
  500.     if (navigator.geolocation) {  
  501.         navigator.geolocation.getCurrentPosition(
  502.             function(position) {  
  503.                 var lat = position.coords.latitude;
  504.                 var lon = position.coords.longitude;
  505.                 //lat = '34.04697';
  506.                 //lon = '-118.238983';
  507.                
  508.                 $.ajax({ url:'http://maps.googleapis.com/maps/api/geocode/json?latlng='+lat+','+lon+'&sensor=true',
  509.                         success: function(data){
  510.                             var city = false, country = false;
  511.                             for (var i = 0; i < data.results[4].address_components.length; i++) {
  512.                                 for (var j = 0; j < data.results[4].address_components[i].types.length; j++) {
  513.                                     if(data.results[4].address_components[i].types[j] == 'locality' && city == false) {
  514.                                         city = data.results[4].address_components[i].long_name;
  515.                                     }
  516.                                     if(data.results[4].address_components[i].types[j] == 'country' && country == false) {
  517.                                         country = data.results[4].address_components[i].long_name;
  518.                                     }
  519.                                 }
  520.                             }
  521.                            
  522.                             $.ajax({
  523.                               url: 'api2.php',
  524.                               dataType: 'json',
  525.                               type: 'post',
  526.                               data: {
  527.                                         city: city + ',' + country,
  528.                                         id: city.toLowerCase().replace(/[^a-zA-Z0-9]+/g, ""),  
  529.                                         lat: lat,
  530.                                         lon: lon,
  531.                                         timezone: timezone
  532.                                     },
  533.                               success: function(data) {
  534.                                 if(city == 'København') city = 'Copenhagen';
  535.                                 $('.loading').remove();
  536.                                 weather(data, '0', city, true);
  537.                                 $('#small div.slide:eq(0)').html($('#layer .slide:eq(0)').html());
  538.                                 $('body').removeClass('initialize');
  539.                               }
  540.                             });
  541.                         },
  542.                         error: function(request, status, error) {
  543.                             console.log('Error');
  544.                         }
  545.                 });
  546.                
  547.             },
  548.             function(error) {              
  549.                 notification('An error occurred', 'Your location could not be determined.');
  550.                 console.log(error);
  551.             },
  552.             {
  553.                 enableHighAccuracy: true,
  554.                 timeout: 10000,
  555.                 maximumAge: 0
  556.             }
  557.         );
  558.     }
  559.     $.each(cities, function(index) {
  560.         var i = index + 1;
  561.         $('#settings .cities').append('<li><span></span><input value="'+cities[index][0]+'" autocorrect="off" />');
  562.        
  563.         $('#settings .cities input').each(function() {
  564.             $(this).data('city', $(this).val());
  565.         });
  566.         $('#layer').append('<div class="slide"><div class="background"></div><a class="in"><span>In</span></a><div class="pagination"><span></span><span></span><span></span><span></span></div><div class="weather"><div class="icon"></div><div class="info">' + cities[index][0].split(',')[0] + '</div></div></div>');
  567.         $('#layer .slide:eq('+i+') .pagination span:eq('+i+')').addClass('active');
  568.        
  569.         $.ajax({
  570.             url: 'api2.php',
  571.             dataType: 'json',
  572.             type: 'post',
  573.             data: {
  574.                 lat: cities[index][1],
  575.                 lon: cities[index][2],
  576.                 id: cities[index][3],
  577.                 timezone: timezone
  578.             },
  579.             success: function(data) {
  580.                 weather(data, i, cities[index][0]);
  581.                 $('#small div.slide:eq(' + i + ')').html($('#layer .slide:eq(' + i + ')').html());
  582.             }
  583.         });
  584.     });
  585.     transform();
  586.     doc.bind('orientationchange', transform);
  587.     doc.bind('orientationchange', redraw);
  588.    
  589.     var slide, isSettings = false, pinchOut = false;
  590.     $('#layer .slide').bind('touchstart', function(e) {
  591.         e.preventDefault();
  592.         var touch = event.touches[0];
  593.         xOrg = touch.pageX;
  594.        
  595.         if($('body').hasClass('settings')) {
  596.             isSettings = true;
  597.         } else {
  598.             isSettings = false;
  599.         }
  600.        
  601.         $('.forecast.active').removeClass('active');
  602.         $('#' + $(this).data('forecast')).addClass('active');  
  603.     });
  604.     $('#layer .slide').bind('touchmove', function(e) {
  605.         e.preventDefault();
  606.        
  607.         // Swiping
  608.         if(isActive != true && event.touches.length == 1 && isSettings == false && pinchOut == false) {
  609.             var touch = event.touches[0];
  610.             xPos = touch.pageX;
  611.             xCor = (xOrg-xPos)/4;
  612.             current();
  613.             $('#layer').css('-webkit-transform', 'translate3d(0px, 0px, -' + width/2 + 'px) rotate3d(0, 1, 0, ' + (degree - xCor) + 'deg)');
  614.             e.preventDefault();
  615.         }
  616.         // Pinch in
  617.         if(event.touches.length == 2 && event.scale > 1 && isActive != true && isSettings == false && pinchOut == false) {
  618.             isActive = true;
  619.             $('body').addClass('animate build');
  620.             $(this).addClass('active');
  621.             playSound('woosh', 0);
  622.             $(this).delay(450).queue(function() {
  623.                 $('body').addClass('revealed');
  624.                 $(this).dequeue();
  625.             });
  626.         }
  627.         // Pinch out
  628.         if(event.touches.length == 2 && event.scale < 1 && isActive != true && isSettings == false && pinchOut == false) {
  629.             if(!$('body').hasClass('out')) {
  630.                 isActive = true;
  631.                 playSound('woosh2', 0);
  632.                 var slider = $(this);
  633.                 var small = $('#small .slide:eq('+ slider.index() +')');
  634.                
  635.                 $('body').addClass('out');
  636.                 small.siblings().addClass('non');
  637.                 small.addClass('active').delay(850).queue(function() {
  638.                     $(this).removeClass('active');
  639.                     $(this).dequeue();
  640.                 });
  641.             }
  642.         }  
  643.     });
  644.     $('#layer .slide').bind('touchend', function(e) {
  645.         if(isActive == false) {
  646.             if(xCor > 10) {
  647.                 switch(active) {
  648.                     case 1:
  649.                         degree = -90;
  650.                         active = 2;
  651.                         break;
  652.                     case 2:
  653.                         degree = -180;
  654.                         active = 3;
  655.                         break;
  656.                     case 3:
  657.                         degree = -270;
  658.                         active = 4;
  659.                         break;
  660.                     case 4:
  661.                         degree = 0;
  662.                         active = 1;
  663.                         break;
  664.                     default:
  665.                         // Do nothing, yet?
  666.                 }
  667.                 $('#layer').css('-webkit-transform', 'translate3d(0px, 0px, -' + width/2 + 'px) rotate3d(0, 1, 0, ' + degree + 'deg)');
  668.             } else if(xCor < -10) {
  669.                 switch(active) {
  670.                     case 1:
  671.                         degree = -270;
  672.                         active = 4;
  673.                         break;
  674.                     case 2:
  675.                         degree = 0;
  676.                         active = 1;
  677.                         break;
  678.                     case 3:
  679.                         degree = -90;
  680.                         active = 2;
  681.                         break;
  682.                     case 4:
  683.                         degree = -180;
  684.                         active = 3;
  685.                         break;
  686.                     default:
  687.                         // Do nothing, yet?
  688.                 }
  689.                 $('#layer').css('-webkit-transform', 'translate3d(0px, 0px, -' + width/2 + 'px) rotate3d(0, 1, 0, ' + degree + 'deg)');
  690.             } else {
  691.                 switch(active) {
  692.                     case 1:
  693.                         degree = 0;
  694.                         active = 1;
  695.                         break;
  696.                     case 2:
  697.                         degree = -90;
  698.                         active = 2;
  699.                         break;
  700.                     case 3:
  701.                         degree = -180;
  702.                         active = 3;
  703.                         break;
  704.                     case 4:
  705.                         degree = -270;
  706.                         active = 4;
  707.                         break;
  708.                     default:
  709.                         // Do nothing, yet?
  710.                 }
  711.                 $('#layer').css('-webkit-transform', 'translate3d(0px, 0px, -' + width/2 + 'px) rotate3d(0, 1, 0, ' + degree + 'deg)');
  712.             }
  713.             xCor = 0;
  714.             isActive = true;
  715.             doc.delay(551).queue(function(){
  716.                 isActive = false;
  717.                 $(this).dequeue()
  718.             });
  719.         }
  720.     });
  721.     $('.forecast').live('touchmove', function(e) {
  722.         if(event.touches.length == 2 && event.scale < 1 && pinchOut == false) {
  723.             pinchOut = true;
  724.             playSound('woosh2', 0);
  725.             $('body').addClass('unbuild')
  726.             $('body').removeClass('revealed build');
  727.             $(this).delay(450).queue(function(){
  728.                 isActive = false;
  729.                 pinchOut = false;
  730.                 $('body').removeClass('animate unbuild');
  731.                 $('.slide.active').removeClass('active');
  732.                 $(this).dequeue();
  733.             });
  734.             e.preventDefault();
  735.         }
  736.     });
  737.    
  738.     if(localStorage.getItem("restart") == 'true') {
  739.         fetching(); // Fetches all available sounds with the Web Audio API, only supported on iOS 6.
  740.         localStorage.setItem('restart', 'false');
  741.     }
  742.    
  743. }
Advertisement
Add Comment
Please, Sign In to add comment