-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeveloper.js
400 lines (344 loc) · 12.6 KB
/
developer.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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/**
@Author: Paul Visco
@Version: 4.11 11/03/08 01/20/2008
@Description:These functions are used when developing. This file does not need to be included in production version of your site. It basically allows for debugging during development. Used Internally.
*/
sb.include('date.formatter');
sb.include('css.rules');
sb.include('math.rand');
sb.include('colors.rand');
sb.include('String.prototype.nl2br');
sb.include('String.prototype.escapeHTML');
sb.include('Element.prototype.disableSelection');
sb.include('Element.prototype.mv');
sb.include('Element.prototype.getPosition');
sb.debug =1;
sb.developer = {};
//sb.devel =1;
/**
@Name: sb.messages
@Description: Used Internally. A lookup table for surebert error messages
*/
sb.messages = {
10 :"FlashPlayer not installed or not detected. You will need at least Flash play 8 to use sb's flash functionality\n GET FLASH PLAYER: http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash",
11 :"You have disabled flash functionality. i.e. sound and flash shared object storage space access by setting the sbNoFlash=1 before calling surebert.",
12 :"Surebert has tried to play this track 5 times with no sucess, perhaps you have flash functionality disabled or the sound does not exist.",
13: " is not a well formatted javascript file and cannot be loaded by sb.javascript",
14: ' cannot be used by $, perhaps it does not exist or is not in the DOM yet?',
15 : 'The surebert.swf has not loaded yet and cannot receive calls to its internal functions, e.g. upload, sound, setDebug.',
16 : "sb.sound has tried to play the following file 10 times but surebert.flashGate has not loaded. Try pushing the play function into the sb.onFlashGateLoad array \nSOUND: ",
17 : "The following image is not reporting height or width properly, perhaps because it has never been in view and so will not work with sb.ie6.pngFix, try running pngFix after it is in view\n",
18 : "Cannot read style: "
};
/**
@Name: sb.objects.alert
@Description: Alerts the properties and their values for an object
@Param: Object o The object to alert the properties of
@Example:
var o = {name : 'paul, language : 'javascript'};
sb.objects.alert({o});
*/
sb.objects.alert = function(o){
window.alert(sb.objects.dump(o));
};
/**
@Name: sb.debugMe
@Package: sb.developer.js
@Description: Sends surebert debugging info to the surebert consol. It shows window size, agent, version, flashplayer and cookies. This only fires after the document is finsihed loading. If you call it before, it will wait until the document has loaded before firing.
@Example:
sb.debugMe();
*/
sb.debugMe = function(){
/*
if(sb.initialized !=1){
sb.ondomload.push(sb.debugMe);
return;
}*/
//list all cookies that are stored
sb.include('cookies');
sb.include('swf');
sb.consol.log([
'agent='+window.navigator.userAgent,
'browser detection:'+"\nsb.browser.agent="+sb.browser.agent+"\nsb.browser.version="+sb.browser.version,
'window.width='+sb.browser.w+"\n"+'window.height='+sb.browser.h,
'flashPlayer='+sb.swf.version,
'cookies found: '+sb.cookies.listAll()
].join("\n\n")
);
};
/**
@Name: sb.debugStyle
@Package: sb.developer.js
@Description: Creates a new debugging color scheme for use with the sb.consol debugging system.
@Param: String color The text color of the debug message produced with the resulting function
@Param: String backgroundColor The background color of the debug message produced with the resulting function
@Example:
var paulDebugStyle = new sb.debugStyle('red', 'yellow');
paulDebug('hello world');
//this debugs the message 'hello world' to the surebert debug consol in red text on a yellow background.
*/
sb.debugStyle = function(color, backgroundColor, allowHTML){
return function(message){
sb.consol.write(message, color, backgroundColor, allowHTML);
};
};
/**
@Name: sb.consol
@Found In: sb.developer.js
@Description: The consol is a cross browser debugging area that allows the programmer and surebert to debug messages to the screen in the handy dandy surebert consol. The consol is a element node that gets inserted at the top of the page before all other content. Messages can be written with difference background colors to speficiy what type of message sthey are. By default red is an error, orange is a warning, green is a log message and pink is a debug message. You can make you own combos very easily. ATTENTION: If you specify a function called sb.consol.onlog - the strings that would normally be written to the consol, during debugging are redirected to the function with the string passed as the only argument.
@Example:
//this would override writing to the consol with your own function whenever sb.consol functions were called.
sb.consol.onlog = function(str){
alert(str);
}
*/
sb.consol = {
/**
@Name: sb.consol.write
@Description: Used internally. This should never been accessed directly. If you wish to write to the consol use sb.consol.error, sb.consol.warning, sb.consol.log, or sb.consol.debug all of which use this method to write formatted strings to the sb.consol. If you wish to create you own debug message style, refer to sb.debugStyle.
*/
write : function(str, color, bgColor, allowHTML){
var note,preWrap;
str = String(str);
if(sb.debug ==1){
color = color || 'green';
bgColor = bgColor || 'black';
if(typeof this.onlog == "function"){
this.onlog(str);
} else {
if(typeof this.box == 'undefined'){
this.open();
}
if(allowHTML !== true){
str = String(str).escapeHTML();
}
sb.css.rules.write("sbConsolNote", 'display:block;font-size:0.8em;margin-bottom:20px;padding:10px;font-size:12px;font-family:tahoma,verdana;text-align:left;');
sb.css.rules.write("sbConsolNote a", 'color:orange;font-size:1.2em;');
sb.css.rules.write("sbConsolNote h1", 'margin-bottom:0;font-size:1.2em;');
sb.css.rules.write("sbConsolNote hr", 'height:2px;margin:3px 0 3px 0;color:orange;background-color:orange;');
str = str.replace(/\n/g, "<br />");
str = str.replace(/\t/g, " ");
note = new sb.element({
tag : 'sbConsolNote',
innerHTML : this.num+'. '+new sb.date.formatter().format('m/d - g:i:s a')+"<hr />"+str
});
note.styles({
backgroundColor : bgColor,
color : color
});
note.appendToTop(this.box.firstChild);
note = null;
str =null;
this.num++;
}
}
},
/**
@Name: sb.consol.error
@Description: Write to the sb.consol in white color text on a red background. You should reserve this for debugging error messages. Only works if sb.debug =1 which it is by default otherwise debugging is turned off.
@Param: String message The message to write to the consol in error style
@Example:
sb.consol.error('OMG there was a horrible error in when trying to make the top div');
*/
error : new sb.debugStyle('white', 'red'),
/**
@Name: sb.consol.warning
@Description: Write to the sb.consol in red color text on a yellow background. You should reserve this for debugging warning messages. Only works if sb.debug =1 which it is by default otherwise debugging is turned off.
@Param: String message The message to write to the consol in warning style
@Example:
sb.consol.warning('You should specify the height of the widget in pixels');
*/
warning : new sb.debugStyle('red', 'yellow'),
/**
@Name: sb.consol.debug
@Description: Write to the sb.consol in white color text on a light blue background. You should reserve this for debugging non-error messages. Only works if sb.debug =1 which it is by default otherwise debugging is turned off.
@Param: String message The message to write to the consol in debug style
@Example:
sb.consol.debug('You should specify the height of the widget in pixels');
*/
debug : new sb.debugStyle('white', '#19a29a'),
/**
@Name: sb.consol.ajaxLog
@Description: Used internally to debug ajax messages
*/
ajaxLog : new sb.debugStyle('#8fb0d2', '#1866b7', 0),
/**
@Name: sb.consol.dump
@Description: Dumps an objects properties to the sb.consol
@Param: Object/String str Object reference of a string that references an object by ID e.g. '#mYDiv'
@Example:
var myObj = {
name: 'paul,
day : 'monday'
};
sb.consol.dump(myObj);
*/
dump : function(str){
var obj;
if(typeof str =='string'){
obj = eval(str);
} else {
obj = str;
}
this.debug('OBJECT: '+str+"\n"+sb.objects.dump(obj), 'white', 'red', 1);
},
/**
@Name: sb.consol.log
@Description: Used Internally.
*/
log : new sb.debugStyle('yellow', 'green'),
/**
@Name: sb.consol.num
@Description: Used internally
*/
num : 1,
/**
@Name: sb.consol.open
@Description: Used internally
*/
open : function(){
var self = this;
this.box = new sb.element({
tag : 'sbConsol',
styles : {
width:'100%',
height:'200px',
marginBottom: '20px',
borderTop : '5px solid black',
backgroundColor: '#84b439',
display : 'block'
},
resize : function(h){
self.box.style.height = h+'px';
self.box.firstChild.style.height = h+'px';
},
children : [
{
tag : 'div',
styles: {
height : '100%',
overflow : 'auto'
}
}
]
});
this.box.appendToTop(((sb.browser.ie6) ? 'body' : 'html'));
this.resizer = new sb.element({
resizing : 0,
tag : 'div',
children : [
{
tag : 'span',
innerHTML : 'clear',
styles : {
marginLeft : '10px',
cursor : 'pointer'
},
events : {
mousedown : function(){
self.box.firstChild.innerHTML ='';
}
}
},{
tag : 'span',
innerHTML : 'hide',
styles : {
marginLeft : '10px',
cursor : 'pointer'
},
events : {
mousedown : function(){
self.box.resize(self.box.getY());
self.resizer.mv(self.box.getX(), 0, 999);
}
}
},
{
tag : 'span',
innerHTML : 'capture',
styles : {
marginLeft : '10px',
cursor : 'pointer'
},
events : {
click : function(){
var randColor = sb.colors.rand(1);
var pwin = window.open('', sb.uniqueID(), 'width=500,height=600,resizeable=yes,scrollbars=yes');
pwin.document.write('<style type="text/css">body{background-color:black;color:green;}</style><h2>Captured At'+new Date()+' from '+window.location+'</h2>'+self.box.firstChild.innerHTML);
pwin.document.close();
pwin.focus();
}
}
}
],
title : 'Drag to resize consol, double click to hide',
styles: {
height : '15px',
width : '100%',
backgroundColor :'black',
color: 'white',
cursor : 'n-resize',
position : 'relative',
left : '0px',
padding: '2px 0 2px 0',
textAlign : 'left'
},
events : {
mousedown : function(e){
var target = e.target;
target.origY = target.getY();
target.style.width = self.box.offsetWidth+'px';
target.style.position = 'absolute';
target.resizing =1;
},
dblclick : function(e){
if(e.target.nodeName == 'DIV'){
self.box.resize(0);
self.resizer.mv(self.box.getX(), self.box.getY(), 999);
}
}
}
});
this.resizer.disableSelection();
sb.events.add(document, 'mouseup', function(){
self.resizer.resizing =0;
});
sb.events.add(document, 'mousemove', function(e){
var rszr = self.resizer;
if(rszr.resizing ==1 && e.clientY > self.box.getY()){
rszr.mv(self.box.getX(), e.clientY, 999);
self.box.resize(e.clientY);
}
});
this.resizer.appendTo(this.box);
return;
},
/**
@Name: sb.consol.swfDebug
@Description: Used Internally to accept messages from surebert.swf for debugging
@Param: String message The message to write to the consol in swfDebug style
@Example:
sb.consol.swfDebug('file paul.jpg uploaded');
*/
flashGateDebug : function(message){
if(sb.flashGateDebug ==1){
sb.consol.write(message, 'orange', '#660066', 1);
}
}
};
/**
@Name: sb.performance
@Description: Determines the time it takes to run a function in milliseconds
@Param: Function func The function to time
@Return: Number The number of milliseconds required to run the function.
@Example:
function getImages(){
var images = sb.$('img');
}
var timeItTakes = sb.performace(getImages);
*/
sb.performance = function(func){
var t0 = new Date().getTime();
func();
return new Date().getTime() - t0;
};