| 1 |
lars |
1 |
<?php
|
|
|
2 |
/**
|
|
|
3 |
* TJavascriptLogger class file.
|
|
|
4 |
*
|
|
|
5 |
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
|
|
|
6 |
* @link http://www.pradosoft.com/
|
|
|
7 |
* @copyright Copyright © 2005-2008 PradoSoft
|
|
|
8 |
* @license http://www.pradosoft.com/license/
|
|
|
9 |
* @version $Id: TJavascriptLogger.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
10 |
* @package System.Web.UI.WebControls
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
* TJavascriptLogger class.
|
|
|
15 |
*
|
|
|
16 |
* Provides logging for client-side javascript. Example: template code
|
|
|
17 |
* <code><com:TJavascriptLogger /></code>
|
|
|
18 |
*
|
|
|
19 |
* Client-side javascript code to log info, error, warn, debug
|
|
|
20 |
* <code>Logger.warn('A warning');
|
|
|
21 |
* Logger.info('something happend');
|
|
|
22 |
* </code>
|
|
|
23 |
*
|
|
|
24 |
* To see the logger and console, press ALT-D (or CTRL-D on OS X).
|
|
|
25 |
* More information on the logger can be found at
|
|
|
26 |
* http://gleepglop.com/javascripts/logger/
|
|
|
27 |
*
|
|
|
28 |
* @author Wei Zhuo<weizhuo[at]gmail[dot]com>
|
|
|
29 |
* @version $Id: TJavascriptLogger.php 2541 2008-10-21 15:05:13Z qiang.xue $
|
|
|
30 |
* @package System.Web.UI.WebControls
|
|
|
31 |
* @since 3.0
|
|
|
32 |
*/
|
|
|
33 |
class TJavascriptLogger extends TWebControl
|
|
|
34 |
{
|
|
|
35 |
private static $_keyCodes = array(
|
|
|
36 |
'0'=>48, '1'=>49, '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57,
|
|
|
37 |
'a'=>65, 'b'=>66, 'c'=>67, 'd'=>68, 'e'=>69, 'f'=>70, 'g'=>71, 'h'=>72,
|
|
|
38 |
'i'=>73, 'j'=>74, 'k'=>75, 'l'=>76, 'm'=>77, 'n'=>78, 'o'=>79, 'p'=>80,
|
|
|
39 |
'q'=>81, 'r'=>82, 's'=>83, 't'=>84, 'u'=>85, 'v'=>86, 'w'=>87, 'x'=>88, 'y'=>89, 'z'=>90);
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* @return string tag name of the panel
|
|
|
43 |
*/
|
|
|
44 |
protected function getTagName()
|
|
|
45 |
{
|
|
|
46 |
return 'div';
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* @param string keyboard key for toggling the console, default is J.
|
|
|
51 |
*/
|
|
|
52 |
public function setToggleKey($value)
|
|
|
53 |
{
|
|
|
54 |
$this->setViewState('ToggleKey', $value, 'j');
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/**
|
|
|
58 |
* @return string keyboard key for toggling the console.
|
|
|
59 |
*/
|
|
|
60 |
public function getToggleKey()
|
|
|
61 |
{
|
|
|
62 |
return $this->getViewState('ToggleKey', 'j');
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
/**
|
|
|
66 |
* Registers the required logger javascript.
|
|
|
67 |
* @param TEventParameter event parameter
|
|
|
68 |
*/
|
|
|
69 |
public function onPreRender($param)
|
|
|
70 |
{
|
|
|
71 |
$key = strtolower($this->getToggleKey());
|
|
|
72 |
$code = isset(self::$_keyCodes[$key]) ? self::$_keyCodes[$key] : 74;
|
|
|
73 |
$js = "var logConsole; Event.OnLoad(function() { logConsole = new LogConsole($code)}); ";
|
|
|
74 |
$cs = $this->getPage()->getClientScript();
|
|
|
75 |
$cs->registerBeginScript($this->getClientID(),$js);
|
|
|
76 |
$cs->registerPradoScript('logger');
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* Register the required javascript libraries and
|
|
|
81 |
* display some general usage information.
|
|
|
82 |
* @param THtmlWriter the writer used for the rendering purpose
|
|
|
83 |
*/
|
|
|
84 |
public function renderContents($writer)
|
|
|
85 |
{
|
|
|
86 |
$code = strtoupper($this->getToggleKey());
|
|
|
87 |
$info = '(<a href="http://gleepglop.com/javascripts/logger/" target="_blank">more info</a>).';
|
|
|
88 |
$link = '<a href="javascript:if(logConsole)logConsole.toggle()">toggle the javascript log console.</a>';
|
|
|
89 |
$usage = 'Press ALT-'.$code.' (Or CTRL-'.$code.' on OS X) to';
|
|
|
90 |
$writer->write("{$usage} {$link} {$info}");
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
|