-
Notifications
You must be signed in to change notification settings - Fork 0
/
bik-4-0-0.js
311 lines (284 loc) · 10.1 KB
/
bik-4-0-0.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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//--Error Detecting-----------------------
window.onerror=function(msg, url, linenumber){
alert('Error message:\n'+msg+'\n\nURL: '+url+'\n\nLine Number: '+linenumber)
}
function alertVar(object){
var output = '';
for (var property in object) {
output += property + ': ' + object[property]+';\n';
}
alert(output);
}
//--Collect Object By ID------------------
function objId(id){
if(!document.getElementById(id)){
//alert("Developer Message:\nID ("+id+") Not Defined on function `objId`.");
return false;
}
else
return document.getElementById(id);
}
//##Build Pop-Start########################################################################
var title="Title";
function buildPop(id, actionLink, parameters){
//--Create & append Black BG DIV
if(!document.getElementById(id+"_bg")){
var div_bg = document.createElement("div");
div_bg.setAttribute("style", "background: rgba(0, 0, 0, 0.8); width: 100%; position: fixed; top: 0px; height: 100%; z-index:101;");
div_bg.setAttribute("ondblclick", "buildMsgdivClose('"+id+"'); ");
div_bg.setAttribute("id", id+"_bg");
document.body.appendChild(div_bg);
}
//--Creating Main Div
if(!document.getElementById(id)){
var div = document.createElement("div");
div.setAttribute("style", "background:#F9F9F9; position:fixed; right:0px; left:0px; margin:0px auto; width:90%; max-width:1000px; height:90%; top:50%; transform:scale(.5, .5) translate(0%, -100%); -moz-transition: All .3s; -webkit-transition: All .3s; transition: All .3s; border:1px solid #DDD; box-shadow: 0px 0px 3px #FFF; z-index:101;");
div.setAttribute("id", id);
div.setAttribute("class", "pop_show");
div.innerHTML="<div style=\"border-bottom:1px solid #999; font-size:16px;padding: 10px 10px 3px 10px;background: #DDD;\"><button name=\"popExit\" class=\"btn red\" style=\"float:right; padding: 5px 10px;\" onclick=\"buildMsgdivClose('"+id+"');\"><i class=\"fa fa-times-circle\"></i> Exit</i></button><span id='title_details_"+id+"' style=\"line-height: 33px;\">"+title+" </span> : </div><div id='details_"+id+"' style='margin:10px; font-size:16px; overflow: auto; height: 440px;'>Loading...</div>";
//--Append DIV
document.body.appendChild(div);
document.getElementById("details_"+id).style.height= (div.offsetHeight-67)+"px";
}
//--Calling Ajax
if(typeof ajaxPageLoad == 'function')
ajaxPageLoad("details_"+id, actionLink, parameters);
//--Then Display IT (After 2ms)
var t=setTimeout(function(){
if(div)
div.style.transform="scale(1, 1) translate(0%, -50%)";
}, 2);
return false;
}
//--Removing Message/Popup Div
function buildMsgdivClose(id){
if(document.getElementById(id))
document.getElementById(id).style.transform="scale(.5, .5)";
//--Then Remove IT (After 150ms)
var t=setTimeout(function(){
if(document.getElementById(id))
document.getElementById(id).parentNode.removeChild(document.getElementById(id));
//--Clearing div_bg
if(document.getElementById(id+'_bg'))
document.getElementById(id+'_bg').parentNode.removeChild(document.getElementById(id+'_bg'));
}, 150);
//return false;
}
//--Remove Popup On ESC Press
function escPopClose(){
unicode =event.keyCode? event.keyCode : event.charCode;
if(unicode==27){// U=85, C=67, I=73, 47=0, 48=1, 49=2, ........, 13=Enter, 27=ESC;
objLength=document.getElementsByName('popExit').length;
if(document.getElementsByName("popExit")[objLength-1])
document.getElementsByName("popExit")[objLength-1].click();
}
}
//--Installation (Placed on Index)
//window.onkeyup=function(){
// escPopClose();
// //--Code Goes Here
// //--Code Goes Here
//}
//##Build Pop-End########################################################################
//--AJAX Pageload
function ajaxPageLoad(dispId, actionLink, parameters){
parameters +="&dispId="+dispId;
parameters +="&actionLink="+actionLink;
parameters +="&bik=1";
//--Creating Progress DIV
if(!document.getElementById('progress_div')){
var divProg = document.createElement("div");
divProg.setAttribute("id", "progress_div");
divProg.setAttribute("style", "position: fixed; bottom:0px; height:5px; width:100%; overflow:hidden; background:#F90; transition: All 1s; z-index:20001;");
divProg.innerHTML="<div id='progress_st' style='background:#090; width:0%; transition: All .5s;'> </div>";
document.body.appendChild(divProg);
}
var xhr = new XMLHttpRequest();
if (xhr.upload) {
xhr.addEventListener("progress", function(e){
if (e.lengthComputable) {
var percentComplete = e.loaded * 100 / e.total;
var t=setTimeout(function(){
if(document.getElementById('progress_st'))
document.getElementById('progress_st').style.width=percentComplete+"%";
}, 1000);
} else {
// Unable to compute progress information since the total size is unknown
}
}, false);
xhr.onreadystatechange = function(ev){
if (xhr.readyState == 4) {
if(xhr.status == 200){//Yes
//--Response Text Output
var respAr=xhr.responseText.split(";///;");
if(respAr[0] && document.getElementById(dispId))
document.getElementById(dispId).innerHTML=respAr[0];
if(respAr[1])
eval(respAr[1]);
if(divProg && divProg.parentNode){
var t=setTimeout(function(){
//--Clearing divProg
divProg.parentNode.removeChild(divProg);
}, 2000);
}
}
else{//No
if(divProg && divProg.parentNode){
divProg.style.backgroundColor="#F00";
var t=setTimeout(function(){
//--Clearing divProg
divProg.parentNode.removeChild(divProg);
}, 2000);
}
}
}
};
xhr.open('POST', actionLink, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(parameters);
}
return false;
}
//--Ajax Form Load
function ajaxForm(frm, dispId){ // resp, js, form_act
var parameters="";
for (var i = 0; i < (frm.elements.length); i++){
if(frm.elements[i].type=='checkbox'){
if(frm.elements[i].checked==true)
parameters +=frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value)+"&";
else
parameters +=frm.elements[i].name+"=&";
}
else if(frm.elements[i].type=='radio'){
if(frm.elements[i].checked==true)
parameters +=frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value)+"&";
}
else{
parameters +=frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value)+"&";
}
}
parameters +="frmId="+frm.id+"&";
parameters +="dispId="+dispId+"&";
parameters +="actionLink="+frm.action+"&";
parameters +="bik=1";
//--Creating Progress DIV
if(!document.getElementById('progress_div')){
var div_prog = document.createElement("div");
div_prog.setAttribute("id", "progress_div");
div_prog.setAttribute("style", "position: fixed; bottom:0px; height:5px; width:100%; overflow:hidden; background:#F90; transition: All 1s; z-index:20001;");
div_prog.innerHTML="<div id='progress_st' style='background:#090; width:0%; transition: All .5s;'> </div>";
document.body.appendChild(div_prog);
}
var xhr = new XMLHttpRequest();
if (xhr.upload) {
xhr.addEventListener("progress", function(e){
if (e.lengthComputable) {
var percentComplete = e.loaded * 100 / e.total;
var t=setTimeout(function(){
if(document.getElementById('progress_st'))
document.getElementById('progress_st').style.width=percentComplete+"%";
}, 1000);
} else {
// Unable to compute progress information since the total size is unknown
}
}, false);
xhr.onreadystatechange = function(ev){
if (xhr.readyState == 4) {
if(xhr.status == 200){//Yes
//--Response Text Output
var resp_ar=xhr.responseText.split(";///;");
if(resp_ar[0] && document.getElementById(dispId))
document.getElementById(dispId).innerHTML=resp_ar[0];
if(resp_ar[1])
eval(resp_ar[1]);
if(resp_ar[2]!="form_success")
form_act(frm, 'enable');
if(div_prog && div_prog.parentNode){
var t=setTimeout(function(){
//--Clearing div_prog
if(div_prog && div_prog.parentNode)
div_prog.parentNode.removeChild(div_prog);
}, 2000);
}
}
else{//No
if(div_prog && div_prog.parentNode){
div_prog.style.backgroundColor="#F00";
var t=setTimeout(function(){
//--Clearing div_prog
div_prog.parentNode.removeChild(div_prog);
}, 2000);
}
}
}
};
xhr.open('POST', frm.action, true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send(parameters);
}
form_act(frm, 'disable');
return false;
}
//--Form Activation
function form_act(frm, act){ //act=disable, enable
var elements = frm.elements;
for (var i = 0, len = elements.length; i < len; ++i) {
if(act=="disable")
elements[i].disabled = true;
else if(act=="enable")
elements[i].disabled = false;
}
}
//liveSearch("searchJson.php");
//<div class=\"\"><label for=\"search\">Search: </label><input id=\"search\"></div>
var cache = {};
function liveSearch(searchId, jsonLink){
$("#"+searchId).autocomplete({
minLength: 1,
source: function(request, response){
var term = request.term;
if(term in cache){
response(cache[term]);
return;
}
$.getJSON(jsonLink, request, function(data, status, xhr){
cache[term]=data;
response(data);
});
}
});
};
function setCookie(cname, cvalue, exsec) {
var d = new Date();
d.setTime(d.getTime() + (exsec*1000));
var expires = "expires=" + d.toGMTString();
document.cookie = cname+"="+cvalue+"; expires="+expires+"; path=/";
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1);
if (c.indexOf(name) != -1) {
return c.substring(name.length, c.length);
}
}
return "";
}
//--Tools Function CK Editor
function ckEditorFull(id){
CKEDITOR.plugins.addExternal( 'onchange', 'onchange/' );
var config = { extraPlugins: 'onchange'};
CKEDITOR.on('instanceCreated', function (e) {
if (!e.editor.id)
alert('Unknown Textarea ID');
e.editor.on('change', function (ev) {
if(document.getElementById(id))
document.getElementById(id).value=ev.editor.getData()//
});
});
CKEDITOR.replace(id);
}
//--Calling CK Editor
//ckEditorFull('editor1');