|
1 | | -(function(){ |
2 | | - var leoBirthday = new Date(document.getElementById('leo-birthday').getAttribute('data-leo-birthday')); |
3 | | - |
4 | | - // Use shared days helper (CadeOLeoDays). Support require() in environments that have it. |
5 | | - var DaysHelper = (typeof require === 'function') ? require('./lib/days') : (window.CadeOLeoDays || {}); |
6 | | - |
7 | | - var leoDaysUntilNextBirthday = 0; |
8 | | - if (DaysHelper && typeof DaysHelper.daysUntilNextBirthday === 'function') { |
9 | | - leoDaysUntilNextBirthday = DaysHelper.daysUntilNextBirthday(leoBirthday); |
10 | | - } else if (window.CadeOLeoDays && typeof window.CadeOLeoDays.daysUntilNextBirthday === 'function') { |
11 | | - leoDaysUntilNextBirthday = window.CadeOLeoDays.daysUntilNextBirthday(leoBirthday); |
12 | | - } |
13 | | - |
14 | | - var today = new Date(); |
15 | | - |
16 | | - var v = CadeOLeo.Ver.v(leoBirthday, today); |
17 | | - |
18 | | - // console.log({leoBirthday}); |
19 | | - // console.log({leoDaysUntilNextBirthday}); |
20 | | - // console.log({today}); |
21 | | - // console.log({v}); |
22 | | - |
23 | | - document.getElementById('leo-version').innerText = v; |
24 | | - |
25 | | - var languageDatepicker = "en"; |
26 | | - if (window.location.pathname !== '/index_en.html') { |
27 | | - languageDatepicker = "pt-BR"; |
28 | | - } |
29 | | - |
30 | | - $('.input-group > .date').datepicker({ |
31 | | - language: languageDatepicker, |
32 | | - todayHighlight: true, |
33 | | - autoclose: true, |
34 | | - disableTouchKeyboard: true, |
35 | | - immediateUpdates: true, |
36 | | - todayBtn: 'linked' |
37 | | - }); |
38 | | - |
39 | | - $("#dateEnd").datepicker("setDate", today); |
40 | | - |
41 | | - var messageDaysUntil = { |
42 | | - "pt-BR": { |
43 | | - "title": "Quanto falta?", |
44 | | - "content": [ |
45 | | - "Faltam", |
46 | | - "dias", |
47 | | - "pro niver do Léo!" |
48 | | - ] |
49 | | - }, |
50 | | - "en": { |
51 | | - "title": "How many days?", |
52 | | - "content": [ |
53 | | - "There are", |
54 | | - "days", |
55 | | - "until Léo's birthday!" |
56 | | - ] |
57 | | - } |
58 | | - } |
59 | | - |
60 | | - $(function () { |
61 | | - |
62 | | - var content = '<div class="container">' + |
63 | | - '<div class="row text-center">' + |
64 | | - '<p style="font-size: 1em;">' + messageDaysUntil[languageDatepicker].content[0] + '</p>' + |
65 | | - '<p style="font-size: 1.5em;">⏳🎊 <span id="leo-days-until" style="font-size: 2em;">'+ leoDaysUntilNextBirthday +'</span> ⏳🎊</p>' + |
66 | | - '<p style="font-size: 1.5em;">' + messageDaysUntil[languageDatepicker].content[1] + '</p>' + |
67 | | - '<p style="font-size: 1em;">' + messageDaysUntil[languageDatepicker].content[2] + '</p>' + |
68 | | - ' </div>' + |
69 | | - ' </div>'; |
70 | | - |
71 | | - |
72 | | - $('[data-toggle="popover"]').popover({ |
73 | | - trigger: 'focus', |
74 | | - html: true, |
75 | | - title: '<p class="text-center" style="padding: 0; margin: 0;">🎂🎈🎉' + messageDaysUntil[languageDatepicker].title + '🎂🎈🎉</p>', |
76 | | - content: content, |
77 | | - placement: 'bottom', |
78 | | - delay: { |
79 | | - show: 200, |
80 | | - hide: 0 |
81 | | - }, |
82 | | - toggle: 'popover' |
83 | | - }); |
84 | | - |
85 | | - }); |
86 | | - |
87 | | - function trigger() { |
88 | | - c = CadeOLeo.Ver.v( |
89 | | - $('#dateStart').datepicker('getUTCDate'), |
90 | | - $('#dateEnd').datepicker('getUTCDate') |
91 | | - ); |
92 | | - |
93 | | - if (c ==='vNaN.NaN.NaN') { |
94 | | - c = 'v0.0.0'; |
95 | | - } |
96 | | - |
97 | | - $('#result-version').text(c); |
98 | | - JqueryFlash.flash($('#result-version')); |
99 | | - |
100 | | - var dateStartString = $('#dateStart').datepicker('getDate').toISOString().substring(0, 10); |
101 | | - var dateEndString = $('#dateEnd').datepicker('getDate').toISOString().substring(0, 10); |
102 | | - |
103 | | - var url = getUrl() + '?d1=' + dateStartString |
104 | | - + '&d2=' + dateEndString; |
105 | | - |
106 | | - var description = languageDatepicker != 'en' ? |
107 | | - 'Minha versão é ' + c + ' #CadeOLeo' : |
108 | | - 'My version is ' + c + ' #CadeOLeo'; |
109 | | - var buttonText = languageDatepicker != 'en' ? |
110 | | - 'Compartilhar' : |
111 | | - 'Share'; |
112 | | - |
113 | | - var share = new ShareButton({ |
114 | | - url: url, |
115 | | - title: 'CadeOLeo', |
116 | | - description: description, |
117 | | - ui: { |
118 | | - buttonText: buttonText |
119 | | - }, |
120 | | - networks: { |
121 | | - pinterest: { |
122 | | - enabled: false |
123 | | - }, |
124 | | - reddit: { |
125 | | - enabled: false |
126 | | - }, |
127 | | - linkedin: { |
128 | | - enabled: false |
129 | | - }, |
130 | | - email: { |
131 | | - enabled: false |
132 | | - } |
133 | | - } |
134 | | - }); |
135 | | - |
136 | | - share.open(); |
137 | | - |
138 | | - $('.this-share-button').show(); |
139 | | - } |
140 | | - |
141 | | - $('.input-group > .date').on("changeDate", trigger); |
142 | | - |
143 | | - function getUrlVars() { |
144 | | - var vars = [], hash; |
145 | | - var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); |
146 | | - for (var i = 0; i < hashes.length; i++) { |
147 | | - hash = hashes[i].split('='); |
148 | | - vars.push(hash[0]); |
149 | | - vars[hash[0]] = hash[1]; |
150 | | - } |
151 | | - return vars; |
152 | | - } |
153 | | - |
154 | | - var queryObj = getUrlVars(); |
155 | | - |
156 | | - if (queryObj.d1 !== undefined) { |
157 | | - if (/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(queryObj.d1)) { |
158 | | - var d = queryObj.d1; |
159 | | - var date = new Date(parseInt(d.substring(0,4)), parseInt(d.substring(5,7)) - 1, parseInt(d.substring(8,10))); |
160 | | - |
161 | | - $("#dateStart").datepicker("setDate", date); |
162 | | - trigger(); |
163 | | - } |
164 | | - } |
165 | | - |
166 | | - if (queryObj.d2 !== undefined) { |
167 | | - if (/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/.test(queryObj.d2)) { |
168 | | - var d = queryObj.d2; |
169 | | - var date = new Date(parseInt(d.substring(0,4)), parseInt(d.substring(5,7)) - 1, parseInt(d.substring(8,10))); |
170 | | - |
171 | | - $("#dateEnd").datepicker("setDate", date); |
172 | | - trigger(); |
173 | | - } |
174 | | - } |
175 | | - |
176 | | - function getUrl() { |
177 | | - var url = window.location.href; |
178 | | - |
179 | | - return url.indexOf('?') === -1 ? url : url.substring(0, url.indexOf('?')); |
180 | | - } |
181 | | - |
182 | | -})(); |
0 commit comments