<?php class ReduxFramework_spinner extends ReduxFramework {

    /**
     * Field Constructor.
     *
     * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
     *
     * @since ReduxFramework 3.0.0
     */
    function __construct($field = array(), $value = '', $parent) {

        parent::__construct($parent->sections, $parent-&gt;args, $parent-&gt;extra_tabs);&#13;
        $this-&gt;field = $field;&#13;
        $this-&gt;value = $value;&#13;
        //$this-&gt;render();&#13;
    }&#13;
&#13;
    //function&#13;
&#13;
    /**&#13;
     * Field Render Function.&#13;
     *&#13;
     * Takes the vars and outputs the HTML for the field in the settings&#13;
     *&#13;
     * @since ReduxFramework 3.0.0&#13;
     */&#13;
    function render() {&#13;
&#13;
        if (empty($this-&gt;field['min'])) {&#13;
            $this-&gt;field['min'] = 0;&#13;
        } else {&#13;
            $this-&gt;field['min'] = intval($this-&gt;field['min']);&#13;
        }&#13;
&#13;
        if (empty($this-&gt;field['max'])) {&#13;
            $this-&gt;field['max'] = intval($this-&gt;field['min']) + 1;&#13;
        } else {&#13;
            $this-&gt;field['max'] = intval($this-&gt;field['max']);&#13;
        }&#13;
&#13;
        if (empty($this-&gt;field['step']) || $this-&gt;field['step'] &gt; $this-&gt;field['max']) {&#13;
            $this-&gt;field['step'] = 1;&#13;
        } else {&#13;
            $this-&gt;field['step'] = intval($this-&gt;field['step']);&#13;
        }&#13;
&#13;
        if (empty($this-&gt;value) &amp;&amp; !empty($this-&gt;field['default']) &amp;&amp; intval($this-&gt;field['min']) &gt;= 1) {&#13;
            $this-&gt;value = intval($this-&gt;field['default']);&#13;
        }&#13;
&#13;
        if (empty($this-&gt;value) &amp;&amp; intval($this-&gt;field['min']) &gt;= 1) {&#13;
            $this-&gt;value = intval($this-&gt;field['min']);&#13;
        }&#13;
&#13;
        if (empty($this-&gt;value)) {&#13;
            $this-&gt;value = 0;&#13;
        }&#13;
&#13;
        // Extra Validation&#13;
        if ($this-&gt;value field['min']) {&#13;
            $this-&gt;value = intval($this-&gt;field['min']);&#13;
        } else if ($this-&gt;value &gt; $this-&gt;field['max']) {&#13;
            $this-&gt;value = intval($this-&gt;field['max']);&#13;
        }&#13;
&#13;
        $params = array(&#13;
            'id' =&gt; '',&#13;
            'min' =&gt; '',&#13;
            'max' =&gt; '',&#13;
            'step' =&gt; '',&#13;
            'val' =&gt; '',&#13;
            'default' =&gt; '',&#13;
        );&#13;
&#13;
        $params = wp_parse_args($this-&gt;field, $params);&#13;
        $params['val'] = $this-&gt;value;&#13;
&#13;
        // Don't allow input edit if there's a step&#13;
        $readonly = "";&#13;
        if (isset($this-&gt;field['edit']) &amp;&amp; $this-&gt;field['edit'] == false) {&#13;
            $readonly = ' readonly="readonly"';&#13;
        }&#13;
&#13;
        // Use javascript globalization, better than any other method.&#13;
        global $wp_scripts;&#13;
        $asteria = $wp_scripts-&gt;get_data('redux-field-spinner-js', 'data');&#13;
&#13;
        if (!empty($asteria)) { // Adding to the previous localize script object&#13;
            if (!is_array($asteria)) {&#13;
                $asteria = json_decode(str_replace('var reduxSpinners = ', '', substr($asteria, 0, -1)), true);&#13;
            }&#13;
            foreach ($asteria as $key =&gt; $value) {&#13;
                $localized_data[$key] = $value;&#13;
            }&#13;
            $wp_scripts-&gt;add_data('redux-field-spinner-js', 'data', '');&#13;
        }&#13;
        $localized_data[$this-&gt;field['id']] = $params;&#13;
        wp_localize_script('redux-field-spinner-js', 'reduxSpinners', $localized_data);&#13;
&#13;
        echo '<input type="text" name="' . $this-&gt;args['opt_name'] . '[' . $this-&gt;field['id'] . ']" id="' . $this-&gt;field['id'] . '" value="' . $this-&gt;value . '" class="mini spinner-input' . $this-&gt;field['class'] . '" .>';&#13;
        echo '<div id="' . $this-&gt;field['id'] . '-spinner" class="redux_spinner" rel="' . $this-&gt;field['id'] . '"></div>';&#13;
    }&#13;
&#13;
//function&#13;
&#13;
    /**&#13;
     * Enqueue Function.&#13;
     *&#13;
     * If this field requires any scripts, or css define this function and register/enqueue the scripts/css&#13;
     *&#13;
     * @since ReduxFramework 3.0.0&#13;
     */&#13;
    function enqueue() {&#13;
&#13;
        wp_enqueue_script(&#13;
                'redux-typewatch-js', ReduxFramework::$_url . 'assets/js/vendor/jquery.typewatch.min.js', array('jquery'), time(), true&#13;
        );&#13;
&#13;
        wp_enqueue_script(&#13;
                'redux-spinner-js', ReduxFramework::$_url . 'inc/fields/spinner/spinner_custom.js', array('jquery'), time(), true&#13;
        );&#13;
&#13;
        wp_enqueue_script(&#13;
                'redux-field-spinner-js', ReduxFramework::$_url . 'inc/fields/spinner/field_spinner.min.js', array('jquery', 'redux-spinner-js', 'jquery-numeric', 'jquery-ui-core', 'jquery-ui-dialog', 'redux-typewatch-js'), time(), true&#13;
        );&#13;
&#13;
        wp_enqueue_style(&#13;
                'redux-field-spinner-css', ReduxFramework::$_url . 'inc/fields/spinner/field_spinner.css', time(), true&#13;
        );&#13;
    }&#13;
&#13;
//function&#13;
}&#13;
&#13;
//class&#13;
