-
Notifications
You must be signed in to change notification settings - Fork 5
/
elonmusk.js
289 lines (252 loc) · 10.3 KB
/
elonmusk.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
function AddSkill3() {
var skillset = document.getElementById('skillset');
var skill = document.getElementById('inputskill').value;
skillset.innerHTML += '<span class="skill">' + skill + '</span>';
}
function Addinterest3() {
var interestset = document.getElementById('interestset');
var interest = document.getElementById('inputinterest').value;
interestset.innerHTML += '<span class="interest">' + interest + '</span>';
}
var workexperienceformat =
'<div class="row">' +
'<div class="row side-design-2">' +
'<h4 id="position-name" class="w-100" contenteditable="true" onclick="selectAll()">' +
'<b>Role at the Company</b>' +
'</h4>' +
'<h5 id="company" contenteditable="true" onclick="selectAll()">' +
'Company Name' +
'</h5>' +
'<div class="space-between text-12">' +
'<span id="work-time" class="color-1" contenteditable="true" onclick="selectAll()">' +
'<i>06/2002-Present</i>' +
'</span><span id="work-location" class="color-1" contenteditable="true" onclick="selectAll()"><i>Company Location</i></span></div></div><div class="pl-75 text-12"><span class="color-1"><i>Accomplishments</i></span><ul class="accomplishments" contenteditable="true" onclick="selectAll()"><li>List of accomplishments here...</li></ul></div></div>';
function addWork() {
var lastrowindex = document.getElementById('work-experience').rows.length - 1;
var newrow = document.getElementById('work-experience').insertRow(lastrowindex);
var cell = newrow.insertCell(0);
cell.innerHTML = workexperienceformat;
}
function removeWork() {
var workexp = document.getElementById('work-experience');
var lastrowindex = workexp.rows.length - 2;
workexp.deleteRow(lastrowindex);
}
function loadfile(event) {
document.getElementById('photo').src =
URL.createObjectURL(event.target.files[0]);
}
function SaveandLoad() {
var user = firebase.auth().currentUser,
template = document.getElementById('template-name').innerText;
var photo = document.getElementById('inputphoto').files[0];
firebase.storage().ref().child(user.uid + "-" + template).put(photo);
setTimeout(() => {
var photourl = firebase.storage().ref(user.uid + "-" + template);
photourl.getDownloadURL().then(function (url) {
document.getElementById('photo').src = url;
printf('photo loaded');
});
}, 1000);
printf('uploaded');
}
function SavetoDatabase() {
var template = document.getElementById('template-name').innerHTML;
//--------------------------
var name = document.getElementById('name').innerHTML;
var yourposition = document.getElementById('your-position').innerHTML;
var about = document.getElementById('about').innerHTML;
//
var emailaddr = document.getElementById('e-mail').innerHTML;
var phone = document.getElementById('phone').innerHTML;
var location = document.getElementById('location').innerHTML;
var twitter = document.getElementById('twitter-handle').innerHTML;
//
//---------------------------
var tablerows = document.getElementById('work-experience').rows;
var workdata = [];
var i;
for (i = 0; i < tablerows.length - 1; i++) {
workdata.push(tablerows[i].cells[0].innerHTML);
}
var skills = document.getElementById('skillset').innerHTML;
var achievements = document.getElementById('achievements').innerHTML;
var interests = document.getElementById('interestset').innerHTML;
var resumeDetails = {
name: name,
position: yourposition,
about: about,
email: emailaddr,
phone: phone,
location: location,
twitter: twitter,
work: workdata,
skillset: skills,
achievements: achievements,
interest: interests
};
firebase.database().ref("users/" + user.uid)
.child(template)
.set(resumeDetails)
.then(function () {
document.getElementById('save-message-div').style.display = 'block';
setTimeout(function () {
document.getElementById('save-message-div').style.opacity = 0;
}, 2500);
setTimeout(function () {
document.getElementById('save-message-div').style.display = 'none';
document.getElementById('save-message-div').style.opacity = 1;
}, 2500 + 800);
});
return "save successful";
}
function LoadfromDatabase() {
var template = document.getElementById('template-name').innerHTML;
//retrieve data
var ref = firebase.database().ref("users/" + user.uid + "/" + template);
ref.on("value", function (snapshot) {
if (snapshot.child('name').val())
document.getElementById('name')
.innerHTML = snapshot.child('name').val();
if (snapshot.child('position').val())
document.getElementById('your-position')
.innerHTML = snapshot.child('position').val();
if (snapshot.child('about').val())
document.getElementById('about')
.innerHTML = snapshot.child('about').val();
//
if (snapshot.child('email').val())
document.getElementById('e-mail')
.innerHTML = snapshot.child('email').val();
if (snapshot.child('phone').val())
document.getElementById('phone')
.innerHTML = snapshot.child('phone').val();
if (snapshot.child('location').val())
document.getElementById('location')
.innerHTML = snapshot.child('location').val();
if (snapshot.child('twitter').val())
document.getElementById('twitter-handle')
.innerHTML = snapshot.child('twitter').val();
//-------------------------------
var work = snapshot.child('work').val();
var rows = document.getElementById('work-experience').rows;
for (var i = 0; i < rows.length - 1; i++) {
rows[i].cells[0].innerHTML = work[i];
}
//
if (snapshot.child('skillset').val())
document.getElementById('skillset')
.innerHTML = snapshot.child('skillset').val();
if (snapshot.child('achievements').val())
document.getElementById('achievements')
.innerHTML = snapshot.child('achievements').val();
if (snapshot.child('interest').val())
document.getElementById('interestset')
.innerHTML = snapshot.child('interest').val();
}, function (error) {
window.alert("Error : " + error.code);
});
}
(function () {
var
form = $('#resume'),
cache_width = form.width(),
a4width = 210, //in mm
a4height = 297,
a4 = [595, 842]; // for a4 size paper width and height in pixels
$('#download-doc').on('click', function () {
$('body').scrollTop(0);
previewResume();
createPDF();
});
//create pdf
function createPDF() {
var doc = new jsPDF({
unit: 'mm',
format: 'a4',
});
getCanvas(form).then(function (canvas) {
var
img = canvas.toDataURL("image/png"),
height = 0.264583 * canvas.height;
doc.addImage(img, 'JPEG', 0, 0, a4width, a4height);
//doc.addPage();
form.width(cache_width);
doc.save(document.getElementById('name').innerText);
previewResume();
});
}
// create canvas object
function getCanvas(page) {
page.width((a4[0] * 1.8) - 80).css('max-width', 'none');
//page.height((a4[1] * 1.3333) - 80).css('max-height','none');
return html2canvas(page, {
imageTimeout: 2000,
removeContainer: true,
});
}
}());
/*
* jQuery helper plugin for examples and tests
*/
(function ($) {
$.fn.html2canvas = function (options) {
var date = new Date(),
$message = null,
timeoutTimer = false,
timer = date.getTime();
html2canvas.logging = options && options.logging;
html2canvas.Preload(this[0], $.extend({
complete: function (images) {
var queue = html2canvas.Parse(this[0], images, options),
$canvas = $(html2canvas.Renderer(queue, options)),
finishTime = new Date();
$canvas.css({
position: 'absolute',
left: 0,
top: 0
}).appendTo(document.body);
$canvas.siblings().toggle();
$(window).click(function () {
if (!$canvas.is(':visible')) {
$canvas.toggle().siblings().toggle();
throwMessage("Canvas Render visible");
} else {
$canvas.siblings().toggle();
$canvas.toggle();
throwMessage("Canvas Render hidden");
}
});
throwMessage('Screenshot created in ' + ((finishTime.getTime() -
timer) / 1000) + " seconds<br />", 4000);
}
}, options));
function throwMessage(msg, duration) {
window.clearTimeout(timeoutTimer);
timeoutTimer = window.setTimeout(function () {
$message.fadeOut(function () {
$message.remove();
});
}, duration || 2000);
if ($message)
$message.remove();
$message = $('<div ></div>').html(msg).css({
margin: 0,
padding: 10,
background: "#000",
opacity: 0.7,
position: "fixed",
top: 10,
right: 10,
fontFamily: 'Tahoma',
color: '#fff',
fontSize: 12,
borderRadius: 12,
width: 'auto',
height: 'auto',
textAlign: 'center',
textDecoration: 'none'
}).hide().fadeIn().appendTo('body');
}
};
})(jQuery);