Source for file JavaScriptConsole.php

Documentation is available at JavaScriptConsole.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
  7. 7:  *
  8. 8:  * This source file is subject to the "Nette license" that is bundled
  9. 9:  * with this package in the file license.txt.
  10. 10:  *
  11. 11:  * For more information please see https://nette.org
  12. 12:  *
  13. 13:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  14. 14:  * @license    https://nette.org/license  Nette license
  15. 15:  * @link       https://nette.org
  16. 16:  * @category   Nette
  17. 17:  * @package    Nette\Web
  18. 18:  * @version    $Id$
  19. 19:  */
  20. 20:  
  21. 21:  
  22. 22:  
  23. 23: require_once dirname(__FILE__'/../Object.php';
  24. 24:  
  25. 25:  
  26. 26:  
  27. 27: /**
  28. 28:  * JavaScript output console.
  29. 29:  *
  30. 30:  * <code>
  31. 31:  * $js = new JavaScriptConsole;
  32. 32:  * $js->jQuery('table tr:eq(2) img')
  33. 33:  *         ->css('z-index', 1000)
  34. 34:  *         ->animate(array('top' => '100px'));
  35. 35:  *
  36. 36:  * $js->fifteen->move(5, 6);
  37. 37:  *
  38. 38:  * $js->fifteen->partialId = '';
  39. 39:  * $js->flush();
  40. 40:  * </code>
  41. 41:  *
  42. 42:  * @author     David Grudl
  43. 43:  * @copyright  Copyright (c) 2004, 2009 David Grudl
  44. 44:  * @package    Nette\Web
  45. 45:  */
  46. 46: class JavaScriptConsole extends Object
  47. 47: {
  48. 48:     /** @var array */
  49. 49:     private $out array();
  50. 50:  
  51. 51:  
  52. 52:  
  53. 53:     /**
  54. 54:      * @return void 
  55. 55:      */
  56. 56:     public function flush()
  57. 57:     {
  58. 58:         echo implode(";\n"$this->out";\n";
  59. 59:         $this->out array();
  60. 60:     }
  61. 61:  
  62. 62:  
  63. 63:  
  64. 64:     /**
  65. 65:      * Sets value of a JavaScript property.
  66. 66:      * @param  string  property name
  67. 67:      * @param  mixed   property value
  68. 68:      * @return void 
  69. 69:      */
  70. 70:     public function __set($name$value)
  71. 71:     {
  72. 72:         $js new JavaScript(''$this->out[]);
  73. 73:         $js->__set($name$value);
  74. 74:     }
  75. 75:  
  76. 76:  
  77. 77:  
  78. 78:     /**
  79. 79:      * Returns JavaScript property value.
  80. 80:      * @param  string  property name
  81. 81:      * @return JavaScript 
  82. 82:      */
  83. 83:     public function &__get($name)
  84. 84:     {
  85. 85:         $js new JavaScript(''$this->out[]);
  86. 86:         return $js->__get($name);
  87. 87:     }
  88. 88:  
  89. 89:  
  90. 90:  
  91. 91:     /**
  92. 92:      * Calls JavaScript function.
  93. 93:      * @param  string  method name
  94. 94:      * @param  array   arguments
  95. 95:      * @return JavaScript 
  96. 96:      */
  97. 97:     public function __call($method$args)
  98. 98:     {
  99. 99:         $js new JavaScript(''$this->out[]);
  100. 100:         return $js->__call($method$args);
  101. 101:     }
  102. 102:  
  103. 103:  
  104. 104:  
  105. 105:     /**
  106. 106:      * Appends user expressions.
  107. 107:      * @param  mixed  one or more parameters
  108. 108:      * @return JavaScript 
  109. 109:      */
  110. 110:     public function raw($arg)
  111. 111:     {
  112. 112:         $args func_get_args();
  113. 113:         return call_user_func_array(array(new JavaScript(''$this->out[])'raw')$args);
  114. 114:     }
  115. 115: