-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPHOTON.js
More file actions
323 lines (259 loc) · 11.1 KB
/
Copy pathPHOTON.js
File metadata and controls
323 lines (259 loc) · 11.1 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
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
312
313
314
315
316
317
318
319
320
321
322
323
function escapeHTML(input) {
text = input.replace(/'/g,''');
text = text.replace(/\"/g,'"');
//text = text.replace(/</g,'<');
//text = text.replace(/>/g,'>');
return text.replace(/\n/g,'<br>');
}
function unescapeHTML(input) {
text = input.replace(/'/g,"'");
text = text.replace(/"/g,'"');
//text = text.replace(/</g,'<');
//text = text.replace(/>/g,'>');
return text.replace(/<br>/g,'\n');
}
function htmlEntities(texto){
//by Micox - elmicoxcodes.blogspot.com - www.ievolutionweb.com
var i,carac,letra,novo='';
for(i=0;i<texto.length;i++){
carac = texto[i].charCodeAt(0);
if((carac < 33) || (carac > 39 && carac < 126)){
//se for numero ou letra normal
novo += texto[i];
}else{
novo += "&#" + texto[i].charCodeAt(0) + ";";
}
}
return novo;
}
function subWindow(subWidth,subHeight,subLocation,subName) {
subName=subName.replace(/ /,'_'); // Added this because IE dosent allow spaces in window names. Yet ALL the other browsers do.
newWindow = window.open(subLocation,subName,'width=' + subWidth + ',height=' + subHeight + ',menubar=yes,scrollbars=yes,resizable=yes');
newWindow.focus();
}
/* PHOTON AJAX */
function phSubmitForm(formName,method,action,callback) {
if (method == "standard"|null) {
// Standard method. Submit form regularly
document.forms[formName].elements['action'].value = action;
document.forms[formName].submit();
}
else if (method == "phAJAX") {
var phAJAXOutbox = "method=phAJAX&action=" + escape(action) + "&";
elementCount = document.forms[formName].elements.length;
for (i=0; i < elementCount; i++) {
if (document.forms[formName].elements[i].name.indexOf("_phIgnore") == -1) {
phAJAXOutbox += (i > 0 ? "&" : "") + encodeURIComponent(document.forms[formName].elements[i].name) + "=" + encodeURIComponent(document.forms[formName].elements[i].value);
}
}
var req = new XMLHttpRequest();
req.open('POST', document.forms[formName].action, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200) { callback(formName,true,req.responseText); }
else { callback(formName,false,req.responseText); }
}
};
req.send(phAJAXOutbox);
}
else if (method == "AJAX") {
var phAJAXOutbox = "";
var req = new XMLHttpRequest();
if (document.forms[formName].method.toLowerCase() == "post" || document.forms[formName].method == null) {
req.open('POST', document.forms[formName].action, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
elementCount = document.forms[formName].elements.length;
for (i=0; i < elementCount; i++) {
if (document.forms[formName].elements[i].name.indexOf("_phIgnore") == -1) {
phAJAXOutbox += (i > 0 ? "&" : "") + encodeURIComponent(document.forms[formName].elements[i].name) + "=" + encodeURIComponent(document.forms[formName].elements[i].value);
}
}
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200) { callback(formName,true,req.responseText); }
else { callback(formName,false,req.responseText); }
}
};
req.send(phAJAXOutbox);
}
else if (document.forms[formName].method.toLowerCase() == "get") {
elementCount = document.forms[formName].elements.length;
if (document.forms[formName].elements["phLocalXML_phIgnore"].value == 0) {
// This means we'll be using the XML.php file to get the results from a source other than locally. Ths means we need to encode the & signs in the URL
encodeAnds = true;
}
else { encodeAnds = false; }
notFirst = false;
for (i=0; i < elementCount; i++) {
if (document.forms[formName].elements[i].name.indexOf("_phIgnore") == -1) {
phAJAXOutbox += ((i > 0 && notFirst) ? (encodeAnds ? encodeURIComponent("&"):"&") : "") + encodeURIComponent(document.forms[formName].elements[i].name) + "=" + encodeURIComponent(document.forms[formName].elements[i].value);
notFirst = true;
}
}
//alert(document.forms[formName].action + "?" + phAJAXOutbox);
req.open('GET', document.forms[formName].action + "?" + phAJAXOutbox, true);
req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200) { callback(formName,true,req.responseText); }
else { callback(formName,false,req.responseText); }
}
};
req.send();
}
}
}
function phLoadDocument(url,callback,layer,show) {
var req = new XMLHttpRequest();
req.open('GET', url, true);
//req.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 200) { callback(req.responseText,layer,show); }
else { callback(req.responseText,layer,show); }
}
};
req.send(url);
}
// PHOTON SWITCHER CODE
function phSwitcherActive(switcher) {
if (switcher.getAttribute("class") != "phScope_clicked") { switcher.setAttribute("class","phScope_active"); }
}
function phSwitcherInactive(switcher) {
if (switcher.getAttribute("class") != "phScope_clicked") { switcher.setAttribute("class","phScope_inActive"); }
}
function phSwitcherClick(switcher) {
switcherItems = document.getElementsByName(switcher.getAttribute("name"));
idCount = switcherItems.length;
for(i=0; i < idCount; i++) {
if (switcherItems.item(i) == switcher) { scope.setAttribute("class","phScope_clicked"); }
else { switcherItems.item(i).setAttribute("class","phScope_inActive"); }
}
}
/*
uuid.js - Version 0.1
JavaScript Class to create a UUID like identifier
Copyright (C) 2006, Erik Giberti (AF-Design), All rights reserved.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
The latest version of this file can be downloaded from
http://www.af-design.com/resources/javascript_uuid.php
HISTORY:
6/5/06 - Initial Release
*/
// on creation of a UUID object, set it's initial value
function UUID(){
this.id = this.createUUID();
}
// When asked what this Object is, lie and return it's value
UUID.prototype.valueOf = function(){ return this.id; }
UUID.prototype.toString = function(){ return this.id; }
//
// INSTANCE SPECIFIC METHODS
//
UUID.prototype.createUUID = function(){
// JavaScript Version of UUID implementation.
//
// Copyright 2006 Erik Giberti, all rights reserved.
//
// Loose interpretation of the specification DCE 1.1: Remote Procedure Call
// described at http://www.opengroup.org/onlinepubs/009629399/apdxa.htm#tagtcjh_37
// since JavaScript doesn't allow access to internal systems, the last 48 bits
// of the node section is made up using a series of random numbers (6 octets long).
//
var dg = UUID.timeInMs(new Date(1582, 10, 15, 0, 0, 0, 0));
var dc = UUID.timeInMs(new Date());
var t = dc - dg;
var h = '-';
var tl = UUID.getIntegerBits(t,0,31);
var tm = UUID.getIntegerBits(t,32,47);
var thv = UUID.getIntegerBits(t,48,59) + '1'; // version 1, security version is 2
var csar = UUID.getIntegerBits(UUID.randrange(0,4095),0,7);
var csl = UUID.getIntegerBits(UUID.randrange(0,4095),0,7);
// since detection of anything about the machine/browser is far to buggy,
// include some more random numbers here
// if nic or at least an IP can be obtained reliably, that should be put in
// here instead.
var n = UUID.getIntegerBits(UUID.randrange(0,8191),0,7) +
UUID.getIntegerBits(UUID.randrange(0,8191),8,15) +
UUID.getIntegerBits(UUID.randrange(0,8191),0,7) +
UUID.getIntegerBits(UUID.randrange(0,8191),8,15) +
UUID.getIntegerBits(UUID.randrange(0,8191),0,15); // this last number is two octets long
return tl + h + tm + h + thv + h + csar + csl + h + n;
}
//
// GENERAL METHODS (Not instance specific)
//
// Pull out only certain bits from a very large integer, used to get the time
// code information for the first part of a UUID. Will return zero's if there
// aren't enough bits to shift where it needs to.
UUID.getIntegerBits = function(val,start,end){
var base16 = UUID.returnBase(val,16);
var quadArray = new Array();
var quadString = '';
var i = 0;
for(i=0;i<base16.length;i++){
quadArray.push(base16.substring(i,i+1));
}
for(i=Math.floor(start/4);i<=Math.floor(end/4);i++){
if(!quadArray[i] || quadArray[i] == '') quadString += '0';
else quadString += quadArray[i];
}
return quadString;
}
// Numeric Base Conversion algorithm from irt.org
// In base 16: 0=0, 5=5, 10=A, 15=F
UUID.returnBase = function(number, base){
//
// Copyright 1996-2006 irt.org, All Rights Reserved.
//
// Downloaded from: http://www.irt.org/script/146.htm
// modified to work in this class by Erik Giberti
var convert = ['0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
if (number < base) var output = convert[number];
else {
var MSD = '' + Math.floor(number / base);
var LSD = number - MSD*base;
if (MSD >= base) var output = this.returnBase(MSD,base) + convert[LSD];
else var output = convert[MSD] + convert[LSD];
}
return output;
}
// This is approximate but should get the job done for general use.
// It gets an approximation of the provided date in milliseconds. WARNING:
// some implementations of JavaScript will choke with these large numbers
// and so the absolute value is used to avoid issues where the implementation
// begin's at the negative value.
UUID.timeInMs = function(d){
var ms_per_second = 100; // constant
var ms_per_minute = 6000; // ms_per second * 60;
var ms_per_hour = 360000; // ms_per_minute * 60;
var ms_per_day = 8640000; // ms_per_hour * 24;
var ms_per_month = 207360000; // ms_per_day * 30;
var ms_per_year = 75686400000; // ms_per_day * 365;
return Math.abs((d.getUTCFullYear() * ms_per_year) + (d.getUTCMonth() * ms_per_month) + (d.getUTCDate() * ms_per_day) + (d.getUTCHours() * ms_per_hour) + (d.getUTCMinutes() * ms_per_minute) + (d.getUTCSeconds() * ms_per_second) + d.getUTCMilliseconds());
}
// pick a random number within a range of numbers
// int c randrange(int a, int b); where a <= c <= b
UUID.randrange = function(min,max){
var num = Math.round(Math.random() * max);
if(num < min){
num = min;
} else if (num > max) {
num = max;
}
return num;
}
// end of UUID class file
var isFunction = function(o) {
return typeof(o) == 'function' && (!Function.prototype.call || typeof(o.call) == 'function');
};