From 78f3c0e9893d36e0ce039c2b79ede8a92ebe468a Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 1 Oct 2017 00:24:20 -0400 Subject: Adding the code --- apps/calendar/lib.js | 585 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 585 insertions(+) create mode 100644 apps/calendar/lib.js (limited to 'apps/calendar/lib.js') diff --git a/apps/calendar/lib.js b/apps/calendar/lib.js new file mode 100644 index 0000000..43327cc --- /dev/null +++ b/apps/calendar/lib.js @@ -0,0 +1,585 @@ +/* + Simple Planner + A localStorage based personal planner prototype + Made for 10K Apart + + Kailash Nadh, http://kailashnadh.name (August 2011) +*/ +var Planner = { + DAYS: ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday', 'Sunday'], + MONTHS: ['January','February','March','April','May','June','July','August','September','October','November','December'], + LABELS: ['todo', 'personal', 'work', 'important', 'misc'], + Date: new Date(), + UI: null, + EVENTS: {}, + diary_open: false, + + init: function() { + this.EVENTS = localStorage['events']; + if(!this.EVENTS) { + this.EVENTS = {}; + if(!localStorage.setup) { + // initial setup + var holidays = {'1-0': 'New Year', '8-2': 'Commonwealth Day', '17-2': 'St. Patrick\'s Day', '1-3': 'April fools', '22-3': 'Earth Day', '1-4': 'May Day', '5-4': 'Cinco de Mayo', '4-6': 'Independence Day (US)', '3-7': 'Friendship Day', '10-7': 'Rollercoaster Day', '17-8': 'International Day of Peace', '16-9': 'World Food Day', '31-9': 'Halloween', '4-10': 'Diwali', '17-10': 'World Peace Day', '22-10': 'Thanksgiving', '25-11': 'Christmas'}; + + for(var year=this.Date.getFullYear(); year<=this.Date.getFullYear()+1; year++) { + for(var id in holidays) { + this.createEvent( + id + '-' + year, + '00', + '00', + holidays[id], + 'misc' + ); + } + } + + // random entries + for(var i=0; i<7; i++) { + this.createEvent( + Math.floor(Math.random()*28) + '-'+ this.Date.getMonth() + '-'+ this.Date.getFullYear(), + Math.floor(Math.random()*23).pad(2), + '00', + 'This is a dummy event. The number ' + i + ' is cool!', + this.LABELS[Math.floor(Math.random()*(this.LABELS.length-1))] + ); + } + localStorage.setup = 1; + } + } else { + try{ + this.EVENTS = JSON.parse(this.EVENTS); + } catch(e) { + localStorage.clear(); + this.EVENTS = {}; + } + } + + this.phone = navigator.userAgent.match(/phone/i) || navigator.userAgent.match(/android/i); + + this.setDate(); + this.initUI(); + + // what month to render first? + var hash = document.location.href.match(/([0-9]{1,2})\-([0-9]{4})/i); + if(hash && hash[1] >= 1 && hash[1] <= 12 && hash[2] >= 1900 && hash[2] <= 2050) { + this.specificMonth(hash[1], hash[2]); + } else { + this.today(); + } + + // only load the diary on pageload if there's enough space to render it + Planner.renderDiary( $('.day' + this.date).data('id') ); + this.UI.resize(); + + Planner.UI.diary_wrap.show(); + var covered = (Planner.UI.diary_wrap.offset().left - Planner.UI.calendar_wrap.innerWidth()); + Planner.UI.diary_wrap.hide(); + if(!this.phone && covered > -35 && new Date().getMonth() == this.month ) { + Planner.showDiary(); + } + }, + initUI: function() { + this.UI = { + themes: ['Switch to dark theme', 'Switch to light theme'], + 'calendar': $('#calendar'), + 'dialog': $('#dialog'), + 'add': $('#add'), + 'calendar_wrap': $('#calendar-wrap'), + 'diary_wrap': $('#diary-wrap'), + 'event_label': $('#event-label'), + 'event_hour': $('#event-hour'), + 'event_minute': $('#event-minute'), + 'event_description': $('#event-description'), + 'event_delete': $('#event-delete'), + 'event_tweet': $('#event-tweet'), + 'diary': $('#diary') + }; + + // time in create event dialog + var val = ''; + for(i=0; i<24; i++) { + val = i.pad(2); + this.UI.event_hour.append( $('