Skip to content

Commit

Permalink
Merge pull request #4 from JonasDoebertin/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
JonasDoebertin committed Nov 4, 2015
2 parents 82fc4fb + 47fa9f5 commit 367697d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 25 deletions.
10 changes: 6 additions & 4 deletions assets/js/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ var RangeSliderField = function($, $field) {
* @since 1.0.0
*/
this.initDisplayWidth = function() {
var testNumber = Math.floor(parseInt(self.config.max)) + parseInt(self.config.step),
var testNumber = Math.floor(parseFloat(self.config.max)) + parseFloat(self.config.step),
testText = '' + self.config.prefix + testNumber + self.config.postfix,
width;

console.log(testText);

self.$display.text(testText);
width = self.$display.outerWidth();
width = self.$display.outerWidth() + 10;

self.$display.parent().css({
minWidth: width + 'px',
Expand Down Expand Up @@ -111,11 +113,11 @@ var RangeSliderField = function($, $field) {
* @return integer
*/
this.calculateDecimals = function() {
if (self.$field.data('step') % 1 === 0) {
if (self.config.step % 1 === 0) {
return 0;
}
else {
return step.toString().split('.')[1].length;
return self.config.step.toString().split('.')[1].length;
}
};

Expand Down
62 changes: 41 additions & 21 deletions rangeslider.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<?php

/**
* Range Slider Field for Kirby 2
* Range Slider Field for Kirby 2.
*
* @version 1.0.0
*
* @author Jonas Döbertin <hello@jd-powered.net>
* @copyright Jonas Döbertin <hello@jd-powered.net>
*
* @link https://github.com/JonasDoebertin/kirby-range-slider
*
* @license GNU GPL v3.0 <http://opensource.org/licenses/GPL-3.0>
*/

/**
* Range Slider Field
* Range Slider Field.
*
* @since 1.0.0
*/
class RangeSliderField extends InputField
{

/**
* Define backend assets.
*
* @since 1.0.0
*
* @var array
*/
public static $assets = array(
Expand All @@ -39,38 +43,43 @@ class RangeSliderField extends InputField
* Minimum value.
*
* @since 1.0.0
* @var integer|float
*
* @var int|float
*/
public $min = 0;

/**
* Maximum value.
*
* @since 1.0.0
* @var integer|float
*
* @var int|float
*/
public $max = 100;

/**
* Step value.
*
* @since 1.0.0
* @var integer|float
*
* @var int|float
*/
public $step = 1;

/**
* Default value.
*
* @since 1.0.0
* @var integer|float
*
* @var int|float
*/
public $default = 0;

/**
* Value display prefix.
*
* @since 1.0.0
*
* @var string
*/
public $prefix = '';
Expand All @@ -79,6 +88,7 @@ class RangeSliderField extends InputField
* Value display postfix.
*
* @since 1.0.0
*
* @var string
*/
public $postfix = '';
Expand All @@ -87,18 +97,20 @@ class RangeSliderField extends InputField
* Get a sanitized option value.
*
* @since 1.0.0
* @param string $key
*
* @param string $key
*
* @return mixed
*/
public function option($key)
{
switch ($key) {

case 'min':
return $this->sanitizeNumber($this->{$key}, 1, false);
return $this->sanitizeNumber($this->{$key}, 1, true);

case 'max':
return $this->sanitizeNumber($this->{$key}, 100, false);
return $this->sanitizeNumber($this->{$key}, 100, true);

case 'step':
case 'default':
Expand All @@ -117,10 +129,12 @@ public function option($key)
* Sanitize a number and maybe apply a default value.
*
* @since 1.0.0
* @param mixed $number
* @param integer $default
* @param bool $float
* @return integer|float
*
* @param mixed $number
* @param int $default
* @param bool $float
*
* @return int|float
*/
protected function sanitizeNumber($number, $default = 0, $float = false)
{
Expand All @@ -131,8 +145,10 @@ protected function sanitizeNumber($number, $default = 0, $float = false)
* Sanitize a boolean value and maybe apply a default value.
*
* @since 1.0.0
* @param mixed $bool
* @param bool $default
*
* @param mixed $bool
* @param bool $default
*
* @return bool
*/
protected function sanitizeBool($bool, $default = false)
Expand All @@ -157,9 +173,10 @@ protected function sanitizeBool($bool, $default = false)
}

/**
* Create input element
* Create input element.
*
* @since 1.0.0
*
* @return Brick
*/
public function input()
Expand Down Expand Up @@ -195,9 +212,10 @@ public function input()
}

/**
* Create outer field element
* Create outer field element.
*
* @since 1.0.0
*
* @return Brick
*/
public function element()
Expand All @@ -209,9 +227,10 @@ public function element()
}

/**
* Create inner field element
* Create inner field element.
*
* @since 1.0.0
*
* @return Brick
*/
public function content()
Expand All @@ -223,12 +242,13 @@ public function content()

/**
* Get the fields value.
*
* @since 1.0.0
* @return integer|float
*
* @return int|float
*/
public function value()
{
return (isset($this->value) and is_numeric($this->value)) ? $this->value : $this->$this->option('default');
}

}

0 comments on commit 367697d

Please sign in to comment.