예제 #1
0
 /**
  * Get javascript sliderr options.
  * @return array slider client-side options
  */
 protected function getSliderOptions()
 {
     // PostBack Options :
     $options['ID'] = $this->getClientID();
     $options['EventTarget'] = $this->getUniqueID();
     $options['AutoPostBack'] = $this->getAutoPostBack();
     // Slider Control options
     $minValue = $this->getMinValue();
     $maxValue = $this->getMaxValue();
     $options['axis'] = strtolower($this->getDirection());
     $options['maximum'] = $maxValue;
     $options['minimum'] = $minValue;
     $options['range'] = 'javascript:$R(' . $minValue . "," . $maxValue . ")";
     $options['sliderValue'] = $this->getValue();
     $options['disabled'] = !$this->getEnabled();
     $values = $this->getValues();
     if (!empty($values)) {
         // Values are provided. Check if min/max are present in them
         if (!in_array($minValue, $values)) {
             $values[] = $minValue;
         }
         if (!in_array($maxValue, $values)) {
             $values[] = $maxValue;
         }
         // Remove all values outsize the range [min..max]
         foreach ($values as $idx => $value) {
             if ($value < $minValue) {
                 unset($values[$idx]);
             }
             if ($value > $maxValue) {
                 unset($values[$idx]);
             }
         }
     } else {
         // Values are not provided, generate automatically using stepsize
         $step = $this->getStepSize();
         // We want at most self::MAX_STEPS values, so, change the step if necessary
         if (($maxValue - $minValue) / $step > self::MAX_STEPS) {
             $step = ($maxValue - $minValue) / self::MAX_STEPS;
         }
         $values = array();
         for ($i = $minValue; $i <= $maxValue; $i += $step) {
             $values[] = $i;
         }
         // Add max if it's not in the array because of step
         if (!in_array($maxValue, $values)) {
             $values[] = $maxValue;
         }
     }
     $options['values'] = TJavaScript::Encode($values, false);
     if ($this->_clientScript !== null) {
         $options = array_merge($options, $this->_clientScript->getOptions()->toArray());
     }
     return $options;
 }