Spinner.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category ZendX
  16. * @package ZendX_JQuery
  17. * @subpackage View
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see ZendX_JQuery_View_Helper_UiWidget
  24. */
  25. require_once "ZendX/JQuery/View/Helper/UiWidget.php";
  26. /**
  27. * jQuery Spinner View Helper
  28. *
  29. * @uses Zend_Json
  30. * @package ZendX_JQuery
  31. * @subpackage View
  32. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class ZendX_JQuery_View_Helper_Spinner extends ZendX_JQuery_View_Helper_UiWidget
  36. {
  37. /**
  38. * Create FormText field for numeric values that can be spinned through its values.
  39. *
  40. * @link http://docs.jquery.com/UI/Spinner
  41. * @param string $id
  42. * @param string $value
  43. * @param array $params
  44. * @param array $attribs
  45. * @return string
  46. */
  47. public function spinner($id, $value="", array $params=array(), array $attribs=array())
  48. {
  49. $attribs = $this->_prepareAttributes($id, $value, $attribs);
  50. if(!isset($params['start']) && is_numeric($value)) {
  51. $params['start'] = $value;
  52. }
  53. if(count($params)) {
  54. $params = ZendX_JQuery::encodeJson($params);
  55. } else {
  56. $params = '{}';
  57. }
  58. $js = sprintf('%s("#%s").spinner(%s);',
  59. ZendX_JQuery_View_Helper_JQuery::getJQueryHandler(),
  60. $attribs['id'],
  61. $params
  62. );
  63. $this->jquery->addOnLoad($js);
  64. return $this->view->formText($id, $value, $attribs);
  65. }
  66. }