-
Notifications
You must be signed in to change notification settings - Fork 21
/
checkin.js
76 lines (71 loc) · 2.54 KB
/
checkin.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
window.pf = window.pf || {};
window.pf.checkIn = {
frame: {},
iteration: 0,
sheet: "1YCzGHTdubM37kGlubJRsBzRaZCXxmN-oVJS-dDSt0Q8",
form: "1FAIpQLSfBCTuRhZ95glaa-748OyTfjYzU_uM-1q0QzS_sFZ13z5BJTg",
values: function(){
return {
"entry.133052561": document.getElementById('wp-admin-bar-site-name').innerText.trim(),
"entry.638951200": location.host,
"entry.63627490": '1',
"fvv": "1"
}
},
submitFrame: function(parentFrame, path, params, method){
method = method || "post"; // Set method to post by default if not specified.
// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var formEl = parentFrame.createElement("form");
formEl.setAttribute("method", method);
formEl.setAttribute("action", path);
for(var key in params) {
if(params.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "text");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", params[key]);
formEl.appendChild(hiddenField);
}
}
parentFrame.body.appendChild(formEl);
formEl.submit();
},
initCheckin: function(){
if ( 0 === this.iteration){
var values = this.values();
this.submitFrame(this.frame.contentDocument, this.googleForm, values, "POST");
//this.frame.document.getElementsByTagName('input')[0].value = values.siteName;
//this.frame.document.getElementsByTagName('input')[1].value = values.siteURL;
//this.frame.document.getElementsByTagName('input')[2].value = values.scriptVer;
//this.frame.document.querySelectorAll('[role="button"]')[1].click();
this.iteration = this.iteration+1;
}
},
activate: function(){
//var tag = document.createElement("script");
//tag.src = "https://apis.google.com/js/api.js";
//tag.setAttribute('onload', "window.pf.checkIn.initCheckin()");
//var docHead = document.getElementsByTagName("head");
var tag = document.createElement('iframe');
this.googleForm = 'http://docs.google.com/forms/d/e/'+this.form+'/formResponse';
tag.setAttribute('onload', "window.pf.checkIn.initCheckin()");
tag.setAttribute('id', 'iframe-checkin');
//tag.setAttribute('style', 'display:none;');
//tag.name('iframe-checkin');
tag.style.display = 'none';
this.frame = tag;
window.addEventListener("load", function () {
document.body.appendChild(tag);
});
jQuery.post(ajaxurl, {
action: 'pf_checked_in'
},
function (response) {
console.log( 'pf install logged', response );
});
}
};
if ( pf_checkin.active ){
window.pf.checkIn.activate();
}