Current File : /home/k/a/r/karenpetzb/www/items/category/Slider.php.tar |
home/karenpetzb/library/Zend/Dojo/Form/Element/Slider.php 0000604 00000011006 15071342042 0017317 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Dojo
* @subpackage Form_Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
/** Zend_Dojo_Form_Element_Dijit */
require_once 'Zend/Dojo/Form/Element/Dijit.php';
/**
* Abstract Slider dijit
*
* @uses Zend_Dojo_Form_Element_Dijit
* @package Zend_Dojo
* @subpackage Form_Element
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Slider.php 10003 2008-07-09 02:40:49Z matthew $
*/
abstract class Zend_Dojo_Form_Element_Slider extends Zend_Dojo_Form_Element_Dijit
{
/**
* Set clickSelect flag
*
* @param bool $clickSelect
* @return Zend_Dojo_Form_Element_TextBox
*/
public function setClickSelect($flag)
{
$this->setDijitParam('clickSelect', (bool) $flag);
return $this;
}
/**
* Retrieve clickSelect flag
*
* @return bool
*/
public function getClickSelect()
{
if (!$this->hasDijitParam('clickSelect')) {
return false;
}
return $this->getDijitParam('clickSelect');
}
/**
* Set intermediateChanges flag
*
* @param bool $intermediateChanges
* @return Zend_Dojo_Form_Element_TextBox
*/
public function setIntermediateChanges($flag)
{
$this->setDijitParam('intermediateChanges', (bool) $flag);
return $this;
}
/**
* Retrieve intermediateChanges flag
*
* @return bool
*/
public function getIntermediateChanges()
{
if (!$this->hasDijitParam('intermediateChanges')) {
return false;
}
return $this->getDijitParam('intermediateChanges');
}
/**
* Set showButtons flag
*
* @param bool $showButtons
* @return Zend_Dojo_Form_Element_TextBox
*/
public function setShowButtons($flag)
{
$this->setDijitParam('showButtons', (bool) $flag);
return $this;
}
/**
* Retrieve showButtons flag
*
* @return bool
*/
public function getShowButtons()
{
if (!$this->hasDijitParam('showButtons')) {
return false;
}
return $this->getDijitParam('showButtons');
}
/**
* Set discreteValues
*
* @param int $value
* @return Zend_Dojo_Form_Element_TextBox
*/
public function setDiscreteValues($value)
{
$this->setDijitParam('discreteValues', (int) $value);
return $this;
}
/**
* Retrieve discreteValues
*
* @return int|null
*/
public function getDiscreteValues()
{
return $this->getDijitParam('discreteValues');
}
/**
* Set maximum
*
* @param int $value
* @return Zend_Dojo_Form_Element_TextBox
*/
public function setMaximum($value)
{
$this->setDijitParam('maximum', (int) $value);
return $this;
}
/**
* Retrieve maximum
*
* @return int|null
*/
public function getMaximum()
{
return $this->getDijitParam('maximum');
}
/**
* Set minimum
*
* @param int $value
* @return Zend_Dojo_Form_Element_TextBox
*/
public function setMinimum($value)
{
$this->setDijitParam('minimum', (int) $value);
return $this;
}
/**
* Retrieve minimum
*
* @return int|null
*/
public function getMinimum()
{
return $this->getDijitParam('minimum');
}
/**
* Set pageIncrement
*
* @param int $value
* @return Zend_Dojo_Form_Element_TextBox
*/
public function setPageIncrement($value)
{
$this->setDijitParam('pageIncrement', (int) $value);
return $this;
}
/**
* Retrieve pageIncrement
*
* @return int|null
*/
public function getPageIncrement()
{
return $this->getDijitParam('pageIncrement');
}
}
home/karenpetzb/library/ZendX/JQuery/View/Helper/Slider.php 0000604 00000013271 15071532375 0017650 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category ZendX
* @package ZendX_JQuery
* @subpackage View
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Slider.php 20165 2010-01-09 18:57:56Z bkarwin $
*/
/**
* @see ZendX_JQuery_View_Helper_UiWidget
*/
require_once "ZendX/JQuery/View/Helper/UiWidget.php";
/**
* jQuery Slider View Helper
*
* @uses Zend_Json
* @package ZendX_JQuery
* @subpackage View
* @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class ZendX_JQuery_View_Helper_Slider extends ZendX_JQuery_View_Helper_UiWidget
{
/**
* Create jQuery slider that updates its values into a hidden form input field.
*
* @link http://docs.jquery.com/UI/Slider
* @param string $id
* @param string $value
* @param array $params
* @param array $attribs
* @return string
*/
public function slider($id, $value = null, array $params = array(), array $attribs = array())
{
if(!isset($attribs['id'])) {
$attribs['id'] = $id;
}
$jqh = ZendX_JQuery_View_Helper_JQuery::getJQueryHandler();
$params = $this->initializeStartingValues($value, $params);
$handleCount = $this->getHandleCount($params);
// Build the Change/Update functionality of the Slider via javascript, updating hidden fields. aswell as hidden fields
$hidden = "";
if(!isset($params['change'])) {
$sliderUpdateFn = 'function(e, ui) {'.PHP_EOL;
for($i = 0; $i < $handleCount; $i++) {
// Js Func
if($i === 0) {
$sliderHiddenId = $attribs['id'];
} else {
$sliderHiddenId = $attribs['id']."-".$i;
}
$sliderUpdateFn .= $this->getChangeCallback($jqh, $sliderHiddenId, $attribs['id'], $i);
// Hidden Fields
$startValue = $this->getHandleValue($i, $params);
$hiddenAttribs = array('type' => 'hidden', 'id' => $sliderHiddenId, 'name' => $sliderHiddenId, 'value' => $startValue);
$hidden .= '<input' . $this->_htmlAttribs($hiddenAttribs) . $this->getClosingBracket(). PHP_EOL;
}
$sliderUpdateFn .= "}".PHP_EOL;
$params['change'] = new Zend_Json_Expr($sliderUpdateFn);
}
$attribs['id'] .= "-slider";
if(count($params) > 0) {
$params = ZendX_JQuery::encodeJson($params);
} else {
$params = '{}';
}
$js = sprintf('%s("#%s").slider(%s);', $jqh, $attribs['id'], $params);
$this->jquery->addOnLoad($js);
$html = '<div' . $this->_htmlAttribs($attribs) . '>';
for($i = 0; $i < $handleCount; $i++) {
$html .= '<div class="ui-slider-handle"></div>';
}
$html .= '</div>';
return $hidden.$html;
}
protected function getChangeCallback($jqh, $sliderHiddenId, $elementId, $handlerNum)
{
if(version_compare($this->jquery->getUiVersion(), "1.7.0") >= 0) {
return sprintf(' %s("#%s").attr("value", %s("#%s-slider").slider("values", %d));'.PHP_EOL,
$jqh, $sliderHiddenId, $jqh, $elementId, $handlerNum
);
} else {
return sprintf(' %s("#%s").attr("value", %s("#%s-slider").slider("value", %d));'.PHP_EOL,
$jqh, $sliderHiddenId, $jqh, $elementId, $handlerNum
);
}
}
protected function getHandleCount($params)
{
if(version_compare($this->jquery->getUiVersion(), "1.7.0") >= 0) {
return count($params['values']);
} else {
return count($params['handles']);
}
}
protected function getHandleValue($handleNum, $params)
{
if(version_compare($this->jquery->getUiVersion(), "1.7.0") >= 0) {
return $params['values'][$handleNum];
} else {
return $params['handles'][$handleNum]['start'];
}
}
protected function initializeStartingValues($value, $params)
{
$values = array();
if(isset($params['value'])) {
$values[] = $params['value'];
unset($params['value']);
} else if(isset($params['values'])) {
$values = $params['values'];
unset($params['values']);
} else if(isset($params['handles'])) {
for($i = 0; $i < count($params['handles']); $i++) {
$values[] = $params['handles'][$i]['start'];
}
unset($params['handles']);
} else if(isset($params['startValue'])) {
$values[] = $params['startValue'];
unset($params['startValue']);
} else if(is_numeric($value)) {
$values[] = $value;
}
if(version_compare($this->jquery->getUiVersion(), "1.7.0") >= 0) {
$params['values'] = $values;
} else {
$params['handles'] = array();
for($i = 0; $i < count($values); $i++) {
$params['handles'][$i]['start'] = $values[$i];
}
}
return $params;
}
} home/karenpetzb/library/Zend/Dojo/View/Helper/Slider.php 0000604 00000020523 15071547051 0017167 0 ustar 00 <?php
/**
* Zend Framework
*
* LICENSE
*
* This source file is subject to the new BSD license that is bundled
* with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://framework.zend.com/license/new-bsd
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@zend.com so we can send you a copy immediately.
*
* @category Zend
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @version $Id: Slider.php 13658 2009-01-15 23:37:30Z matthew $
*/
/** Zend_Dojo_View_Helper_Dijit */
require_once 'Zend/Dojo/View/Helper/Dijit.php';
/**
* Abstract class for Dojo Slider dijits
*
* @uses Zend_Dojo_View_Helper_Dijit
* @package Zend_Dojo
* @subpackage View
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
abstract class Zend_Dojo_View_Helper_Slider extends Zend_Dojo_View_Helper_Dijit
{
/**
* Dojo module to use
* @var string
*/
protected $_module = 'dijit.form.Slider';
/**
* Required slider parameters
* @var array
*/
protected $_requiredParams = array('minimum', 'maximum', 'discreteValues');
/**
* Slider type -- vertical or horizontal
* @var string
*/
protected $_sliderType;
/**
* dijit.form.Slider
*
* @param int $id
* @param mixed $value
* @param array $params Parameters to use for dijit creation
* @param array $attribs HTML attributes
* @return string
*/
public function prepareSlider($id, $value = null, array $params = array(), array $attribs = array())
{
$this->_sliderType = strtolower($this->_sliderType);
// Prepare two items: a hidden element to store the value, and the slider
$hidden = $this->_renderHiddenElement($id, $value);
$hidden = preg_replace('/(name=")([^"]*)"/', 'id="$2" $1$2"', $hidden);
foreach ($this->_requiredParams as $param) {
if (!array_key_exists($param, $params)) {
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception('prepareSlider() requires minimally the "minimum", "maximum", and "discreteValues" parameters');
}
}
$content = '';
$params['value'] = $value;
if (!array_key_exists('onChange', $attribs)) {
$attribs['onChange'] = "dojo.byId('" . $id . "').value = arguments[0];";
}
$id = str_replace('][', '-', $id);
$id = str_replace(array('[', ']'), '-', $id);
$id = rtrim($id, '-');
$id .= '-slider';
switch ($this->_sliderType) {
case 'horizontal':
if (array_key_exists('topDecoration', $params)) {
$content .= $this->_prepareDecoration('topDecoration', $id, $params['topDecoration']);
unset($params['topDecoration']);
}
if (array_key_exists('bottomDecoration', $params)) {
$content .= $this->_prepareDecoration('bottomDecoration', $id, $params['bottomDecoration']);
unset($params['bottomDecoration']);
}
if (array_key_exists('leftDecoration', $params)) {
unset($params['leftDecoration']);
}
if (array_key_exists('rightDecoration', $params)) {
unset($params['rightDecoration']);
}
break;
case 'vertical':
if (array_key_exists('leftDecoration', $params)) {
$content .= $this->_prepareDecoration('leftDecoration', $id, $params['leftDecoration']);
unset($params['leftDecoration']);
}
if (array_key_exists('rightDecoration', $params)) {
$content .= $this->_prepareDecoration('rightDecoration', $id, $params['rightDecoration']);
unset($params['rightDecoration']);
}
if (array_key_exists('topDecoration', $params)) {
unset($params['topDecoration']);
}
if (array_key_exists('bottomDecoration', $params)) {
unset($params['bottomDecoration']);
}
break;
default:
require_once 'Zend/Dojo/View/Exception.php';
throw new Zend_Dojo_View_Exception('Invalid slider type; slider must be horizontal or vertical');
}
return $hidden . $this->_createLayoutContainer($id, $content, $params, $attribs);
}
/**
* Prepare slider decoration
*
* @param string $position
* @param string $id
* @param array $decInfo
* @return string
*/
protected function _prepareDecoration($position, $id, $decInfo)
{
if (!in_array($position, array('topDecoration', 'bottomDecoration', 'leftDecoration', 'rightDecoration'))) {
return '';
}
if (!is_array($decInfo)
|| !array_key_exists('labels', $decInfo)
|| !is_array($decInfo['labels'])
) {
return '';
}
$id .= '-' . $position;
if (!array_key_exists('dijit', $decInfo)) {
$dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'Rule';
} else {
$dijit = $decInfo['dijit'];
if ('dijit.form.' != substr($dijit, 0, 10)) {
$dijit = 'dijit.form.' . $dijit;
}
}
$params = array();
$attribs = array();
$labels = $decInfo['labels'];
if (array_key_exists('params', $decInfo)) {
$params = $decInfo['params'];
}
if (array_key_exists('attribs', $decInfo)) {
$attribs = $decInfo['attribs'];
}
$containerParams = null;
if (array_key_exists('container', $params)) {
$containerParams = $params['container'];
unset($params['container']);
}
if (array_key_exists('labels', $params)) {
$labelsParams = $params['labels'];
unset($params['labels']);
} else {
$labelsParams = $params;
}
if (null === $containerParams) {
$containerParams = $params;
}
$containerAttribs = null;
if (array_key_exists('container', $attribs)) {
$containerAttribs = $attribs['container'];
unset($attribs['container']);
}
if (array_key_exists('labels', $attribs)) {
$labelsAttribs = $attribs['labels'];
unset($attribs['labels']);
} else {
$labelsAttribs = $attribs;
}
if (null === $containerAttribs) {
$containerAttribs = $attribs;
}
$containerParams['container'] = $position;
$labelsParams['container'] = $position;
$labelList = $this->_prepareLabelsList($id, $labelsParams, $labelsAttribs, $labels);
$dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'Rule';
$containerAttribs['id'] = $id;
$containerAttribs = $this->_prepareDijit($containerAttribs, $containerParams, 'layout', $dijit);
$containerHtml = '<div' . $this->_htmlAttribs($containerAttribs) . "></div>\n";
switch ($position) {
case 'topDecoration':
case 'leftDecoration':
return $labelList . $containerHtml;
case 'bottomDecoration':
case 'rightDecoration':
return $containerHtml . $labelList;
}
}
/**
* Prepare slider label list
*
* @param string $id
* @param array $params
* @param array $attribs
* @param array $labels
* @return string
*/
protected function _prepareLabelsList($id, array $params, array $attribs, array $labels)
{
$attribs['id'] = $id . '-labels';
$dijit = 'dijit.form.' . ucfirst($this->_sliderType) . 'RuleLabels';
$attribs = $this->_prepareDijit($attribs, $params, 'layout', $dijit);
return $this->view->htmlList($labels, true, $attribs);
}
}