Advertisement
Guest User

web page - 5/1/13

a guest
May 1st, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Fuq u</title>
  5. <style>
  6. div{
  7.     width:100%;
  8.     text-align:center;
  9. }
  10. </style>
  11. </head>
  12.  
  13. <body>
  14.     <div id='content'>
  15.       <h1>Events</h1>
  16.     </div>
  17.     <a href='#' id='authorize-button' onclick='handleAuthClick();'>Login</a>
  18.    
  19.     <script>
  20. var firedOnce = false; //used to prevent the function from firing twice.
  21. var year = 2013;
  22. var month = 05;
  23. var day = 09;
  24.    
  25. var clientId = '200816328603.apps.googleusercontent.com';
  26. var apiKey = 'AIzaSyD3rbV__d8u6r9u5GioBU0oVwa-53YXRqM';
  27. var scopes = 'https://www.googleapis.com/auth/calendar';
  28.  
  29. function handleClientLoad() {
  30.   gapi.client.setApiKey(apiKey);
  31.   window.setTimeout(checkAuth,1);
  32.   checkAuth();
  33. }
  34.  
  35. function checkAuth() {
  36.   gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true},
  37.       handleAuthResult);
  38. }
  39.  
  40. function handleAuthResult(authResult) {
  41.   var authorizeButton = document.getElementById('authorize-button');
  42.   if (authResult) {
  43.     authorizeButton.style.visibility = 'hidden';
  44.     makeApiCall();
  45.   } else {
  46.     authorizeButton.style.visibility = '';
  47.     authorizeButton.onclick = handleAuthClick;
  48.    }
  49. }
  50.  
  51. function handleAuthClick(event) {
  52.   gapi.auth.authorize(
  53.       {client_id: clientId, scope: scopes, immediate: false},
  54.       handleAuthResult);
  55.   return false;
  56. }
  57.  
  58. //document.createTextNode(resp.items[i].summary)
  59.  
  60. function makeApiCall() {
  61.  
  62.     if (firedOnce == false) {
  63.       gapi.client.load('calendar', 'v3', function() {
  64.      
  65.       //for (var i=0; i < 7; i++) {
  66.       //increment for days & months goes here
  67.       //day++;
  68.      
  69.         var request = gapi.client.calendar.events.list({
  70.           'calendarId': 'pvhs.k12.nj.us_r6jaor04o80hpsaldf17civeio@group.calendar.google.com',
  71.           'timeMin': 'year-month-dayT00:00:00-06:00'.replace('year', year).replace('month', month).replace('day', day),
  72.           'timeMax': 'year-month-dayT23:59:59-06:00'.replace('year', year).replace('month', month).replace('day', day)
  73.         });
  74.  
  75.         request.execute(function(resp) {
  76.        
  77.             if (resp.items != null) {
  78.            
  79.               for (var i = 0; i < resp.items.length; i++) {
  80.                
  81.                 //---------nodes for html elements
  82.                 var title = document.createTextNode(resp.items[i].summary); //titles are undefined so I'm using the summary as title instead
  83.                 //var description = document.createTextNode(resp.items[i].description); //there are no descriptions apparently
  84.                 var date = document.createTextNode('Start: ' + resp.items[i].start.date + ' End: ' + resp.items[i].end.date); //resp.items[i].date returns undefined
  85.                
  86.                 if (date.textContent == 'Start: undefined End: undefined' || resp.items[i].start.date == (year + '-' + month + '-' + day)) {
  87.                     //---------html elements
  88.                     var div = document.createElement('div');
  89.                     div.className = resp.items[i].summary;
  90.                    
  91.                     var h1 = document.createElement('h1');
  92.                     h1.appendChild(title);
  93.                     div.appendChild(h1);
  94.                    
  95.                     if (date.textContent != 'Start: undefined End: undefined') {
  96.                       var p = document.createElement('p');
  97.                       p.appendChild(date);
  98.                       div.appendChild(p);
  99.                     } else {
  100.                       date = document.createTextNode('Start: ' + year + '-' + month + '-' + day + ' End: ' + year + '-' + month + '-' + day);
  101.                       var p = document.createElement('p');
  102.                       p.appendChild(date);
  103.                       div.appendChild(p);
  104.                     }
  105.                    
  106.                     document.body.appendChild(div);
  107.                 }
  108.                
  109.               }
  110.              
  111.             } else {
  112.                 var h1 = document.createElement('h1');
  113.                 h1.appendChild(document.createTextNode('nothing'));
  114.                 date = document.createTextNode('Start: ' + year + '-' + month + '-' + day + ' End: ' + year + '-' + month + '-' + day);
  115.                 var p = document.createElement('p');
  116.                 p.appendChild(date);
  117.                 var div = document.createElement('div');
  118.                 div.appendChild(h1);
  119.                 div.appendChild(p);
  120.                 document.body.appendChild(div);
  121.             }
  122.         }); //--end resp
  123.         //}
  124.       }); //--end request
  125.  
  126.     }
  127.    
  128.   if (firedOnce == true) {
  129.     firedOnce = false;
  130.   } else if(firedOnce == false) {
  131.     firedOnce = true;
  132.   }
  133.  
  134. } //--end makeApiCall()
  135.     </script>
  136.     <script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
  137. </body>
  138. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement