-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguid.js
More file actions
162 lines (143 loc) · 4 KB
/
guid.js
File metadata and controls
162 lines (143 loc) · 4 KB
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
// � by Caspar Goeke and Holger Finger
/**
* generated a global unique id.
*
* @returns {string}
*/
function guid() {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
return s4() + s4() + '' + s4() + '' + s4() + '' +
s4() + '' + s4() + s4() + s4();
}
function getCurrentDate(offset) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (offset) {
var hh = today.getHours() + offset;
}
else {
var hh = today.getHours();
}
if (hh < 0) {
dd--;
hh = 24 - hh;
}
else if (hh > 23) {
dd++;
hh = hh - 24
}
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
var today = yyyy + '/' + mm + '/' + dd;
return today
};
function getCurrentDateModified(offset) {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
var hh = today.getHours() + offset;
if (hh < 0) {
dd--;
hh = 24 - hh;
}
else if (hh > 23) {
dd++;
hh = hh - 24
}
var min = today.getMinutes();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
var date = yyyy + "-" + mm + "-" + dd;
var time = hh + ":" + min;
var obj = {
date: date,
time: time,
data: [yyyy, parseInt(mm), parseInt(dd), hh, min]
};
return obj;
}
function copyTarget(elemId) {
var elem = $('#' + elemId)[0];
// create hidden text element, if it doesn't already exist
var targetId = "_hiddenCopyText_";
var isInput = elem.tagName === "INPUT" || elem.tagName === "TEXTAREA";
var origSelectionStart, origSelectionEnd;
if (isInput) {
// can just use the original source element for the selection and copy
target = elem;
origSelectionStart = elem.selectionStart;
origSelectionEnd = elem.selectionEnd;
} else {
// must use a temporary form element for the selection and copy
target = document.getElementById(targetId);
if (!target) {
var target = document.createElement("textarea");
target.style.position = "absolute";
target.style.left = "-9999px";
target.style.top = "0";
target.id = targetId;
document.body.appendChild(target);
}
target.textContent = elem.textContent;
}
// select the content
var currentFocus = document.activeElement;
target.focus();
target.setSelectionRange(0, target.value.length);
// copy the selection
var succeed;
try {
succeed = document.execCommand("copy");
} catch (e) {
succeed = false;
}
// restore original focus
if (currentFocus && typeof currentFocus.focus === "function") {
currentFocus.focus();
}
if (isInput) {
// restore prior selection
elem.setSelectionRange(origSelectionStart, origSelectionEnd);
} else {
// clear temporary content
target.textContent = "";
}
return succeed;
}
function getBlobURL(url, fallbackMimetype, callback) {
var xhr = new XMLHttpRequest();
xhr.open("get", url);
xhr.responseType = "arraybuffer";
var ext = url.substr(url.lastIndexOf('.') + 1);
xhr.addEventListener("load", function () {
var arrayBufferView = new Uint8Array(this.response);
var mime = xhr.getResponseHeader("Content-Type");
if (!mime) {
mime = fallbackMimetype;
}
var blob = new Blob([arrayBufferView], { type: mime });
var url = null;
if (window.URL) {
url = window.URL.createObjectURL(blob);
} else if (window.URL && window.URL.createObjectURL) {
url = window.URL.createObjectURL(blob);
}
callback(url, blob);
});
xhr.send();
}