├── .github ├── PULL_REQUEST_TEMPLATE.md ├── stale.yml ├── ISSUE_TEMPLATE.md ├── CODE_OF_CONDUCT.md └── CONTRIBUTING.md ├── src ├── assets │ ├── css │ │ ├── jquery.bootstrap-touchspin.min.css │ │ └── jquery.bootstrap-touchspin.css │ └── js │ │ ├── jquery.bootstrap-touchspin.min.js │ │ └── jquery.bootstrap-touchspin.js ├── TouchSpinAsset.php └── TouchSpin.php ├── composer.json ├── LICENSE.md ├── CHANGE.md └── README.md /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Scope 2 | This pull request includes a 3 | 4 | - [ ] Bug fix 5 | - [ ] New feature 6 | - [ ] Translation 7 | 8 | ## Changes 9 | The following changes were made 10 | 11 | - 12 | - 13 | - 14 | 15 | ## Related Issues 16 | If this is related to an existing ticket, include a link to it as well. -------------------------------------------------------------------------------- /src/assets/css/jquery.bootstrap-touchspin.min.css: -------------------------------------------------------------------------------- 1 | .bootstrap-touchspin{width:100%}.bootstrap-touchspin .input-group-btn-vertical{height:100%;z-index:11;width:2em;border:none;background:0 0}.bootstrap-touchspin .input-group-btn-vertical>.btn{position:absolute;right:0;height:50%;width:2em;padding:0;text-align:center;line-height:.4}.bootstrap-touchspin .input-group-btn-vertical>.btn i{font-size:9px}.bootstrap-touchspin .input-group-btn-vertical .bootstrap-touchspin-up{border-radius:0 4px 0 0;top:0}.bootstrap-touchspin .input-group-btn-vertical .bootstrap-touchspin-down{border-radius:0 0 4px;border-top:none;bottom:0} -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 60 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 7 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - bug 8 | - enhancement 9 | - pinned 10 | - security 11 | # Label to use when marking an issue as stale 12 | staleLabel: wontfix 13 | # Comment to post when marking an issue as stale. Set to `false` to disable 14 | markComment: > 15 | This issue has been automatically marked as stale because it has not had 16 | recent activity. It will be closed if no further activity occurs. Thank you 17 | for your contributions. 18 | # Comment to post when closing a stale issue. Set to `false` to disable 19 | closeComment: false -------------------------------------------------------------------------------- /src/TouchSpinAsset.php: -------------------------------------------------------------------------------- 1 | 18 | * @since 1.0 19 | */ 20 | class TouchSpinAsset extends AssetBundle 21 | { 22 | /** 23 | * @inheritdoc 24 | */ 25 | public function init() 26 | { 27 | $this->setSourcePath(__DIR__ . '/assets'); 28 | $this->setupAssets('css', ['css/jquery.bootstrap-touchspin']); 29 | $this->setupAssets('js', ['js/jquery.bootstrap-touchspin']); 30 | parent::init(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kartik-v/yii2-widget-touchspin", 3 | "description": "A Yii2 wrapper widget for the Bootstrap Switch plugin to use checkboxes & radios as toggle touchspines (sub repo split from yii2-widgets)", 4 | "keywords": [ 5 | "yii2", 6 | "extension", 7 | "widget", 8 | "form", 9 | "touch", 10 | "input", 11 | "spinner", 12 | "bootstrap", 13 | "jquery", 14 | "plugin" 15 | ], 16 | "homepage": "https://github.com/kartik-v/yii2-widget-touchspin", 17 | "type": "yii2-extension", 18 | "license": "BSD-3-Clause", 19 | "authors": [ 20 | { 21 | "name": "Kartik Visweswaran", 22 | "email": "kartikv2@gmail.com", 23 | "homepage": "http://www.krajee.com/" 24 | } 25 | ], 26 | "require": { 27 | "kartik-v/yii2-krajee-base": ">=3.0" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "kartik\\touchspin\\": "src" 32 | } 33 | }, 34 | "extra": { 35 | "branch-alias": { 36 | "dev-master": "1.2.x-dev" 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/assets/css/jquery.bootstrap-touchspin.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Bootstrap TouchSpin - v4.2.5 3 | * A mobile and touch friendly input spinner component for Bootstrap 3 & 4. 4 | * http://www.virtuosoft.eu/code/bootstrap-touchspin/ 5 | * 6 | * Made by István Ujj-Mészáros 7 | * Under Apache License v2.0 License 8 | * 9 | * Modified by Kartik Visweswaran, Krajee.com, Sep 2018 10 | */ 11 | /* This CSS file is unnecessary if you are not using vertical buttons functionality */ 12 | 13 | .bootstrap-touchspin { 14 | width: 100%; 15 | } 16 | 17 | .bootstrap-touchspin .input-group-btn-vertical { 18 | height: 100%; 19 | z-index: 11; 20 | width: 2em; 21 | border: none; 22 | background: none; 23 | } 24 | 25 | .bootstrap-touchspin .input-group-btn-vertical > .btn { 26 | position: absolute; 27 | right: 0; 28 | height: 50%; 29 | width: 2em; 30 | padding: 0; 31 | text-align: center; 32 | line-height: 0.4; 33 | } 34 | 35 | .bootstrap-touchspin .input-group-btn-vertical > .btn i { 36 | font-size: 9px; 37 | } 38 | 39 | .bootstrap-touchspin .input-group-btn-vertical .bootstrap-touchspin-up { 40 | border-radius: 0 4px 0 0; 41 | top: 0; 42 | } 43 | 44 | .bootstrap-touchspin .input-group-btn-vertical .bootstrap-touchspin-down { 45 | border-radius: 0 0 4px 0; 46 | border-top: none; 47 | bottom: 0; 48 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 - 2021, Kartik Visweswaran 2 | Krajee.com 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, 6 | are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | * Redistributions in binary form must reproduce the above copyright notice, this 12 | list of conditions and the following disclaimer in the documentation and/or 13 | other materials provided with the distribution. 14 | 15 | * Neither the names of Kartik Visweswaran or Krajee nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 23 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 24 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 26 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 28 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /CHANGE.md: -------------------------------------------------------------------------------- 1 | Change Log: `yii2-widget-touchspin` 2 | =================================== 3 | 4 | ## Version 1.2.4 5 | 6 | **Date:** 02-Sep-2021 7 | 8 | - (enh #12): Enhancements to support Bootstrap v5.x. 9 | 10 | ## Version 1.2.3 11 | 12 | **Date:** 05-Sep-2018 13 | 14 | - (enh #10): Correct `btn-vertical` bootstrap markup styling. 15 | 16 | ## Version 1.2.4 17 | 18 | **Date:** 05-Sep-2018 19 | 20 | - (enh #10): Correct `btn-vertical` bootstrap markup styling. 21 | 22 | ## Version 1.2.2 23 | 24 | **Date:** 17-Aug-2018 25 | 26 | - Add Bootstrap 4.x support 27 | - Upgrade source plugin to latest release 28 | - Add github contribution and PR/issue log templates. 29 | - Update copyright year to current. 30 | - Reorganize all source code in `src` directory. 31 | 32 | ## Version 1.2.1 33 | 34 | **Date:** 10-Jan-2016 35 | 36 | - Enhancements for PJAX based reinitialization. Complements enhancements in kartik-v/yii2-krajee-base#52 and kartik-v/yii2-krajee-base#53. 37 | 38 | ## Version 1.2.0 39 | 40 | **Date:** 04-Dec-2014 41 | 42 | - (enh #2): Enhance widget for updated bootstrap-touchspin plugin. 43 | - (enh #3): Validate InputWidget disabled setting. 44 | 45 | ## Version 1.1.0 46 | 47 | **Date:** 15-Nov-2014 48 | 49 | - (enh [#204](https://github.com/kartik-v/yii2-widgets/issues/204)): Set a better z-index for TouchSpin Input Group to avoid dropdown overlays getting hidden. 50 | - (enh #1): Add special styling for bootstrap input group button addons for success and error states. 51 | - Set release to stable. 52 | 53 | ## Version 1.0.0 54 | 55 | **Date:** 08-Nov-2014 56 | 57 | - Initial release 58 | - Sub repo split from [yii2-widgets](https://github.com/kartik-v/yii2-widgets) -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | 3 | - [ ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate. 4 | - [ ] The issue still exists against the latest `master` branch of yii2-widget-touchspin. 5 | - [ ] This is not an usage question. I confirm having read the [widget documentation and demos](http://demos.krajee.com/widget-details/touchspin). 6 | - [ ] This is not a general programming / coding question. (Those should be directed to the [webtips Q & A forum](http://webtips.krajee.com/questions)). 7 | - [ ] This is not a source plugin (touchspin) issue. (Those should be directed to the [plugin issues repo](https://github.com/touchspin/touchspin/search?q=&type=Issues)). 8 | - [ ] I have attempted to find the simplest possible steps to reproduce the issue. 9 | - [ ] I have included a failing test as a pull request (Optional). 10 | 11 | ## Steps to reproduce the issue 12 | 13 | 1. 14 | 2. 15 | 3. 16 | 17 | ## Expected behavior and actual behavior 18 | 19 | When I follow those steps, I see... 20 | 21 | I was expecting... 22 | 23 | ## Environment 24 | 25 | Browsers 26 | 27 | - [ ] Google Chrome 28 | - [ ] Mozilla Firefox 29 | - [ ] Internet Explorer 30 | - [ ] Safari 31 | 32 | Operating System 33 | 34 | - [ ] Windows 35 | - [ ] Mac OS X 36 | - [ ] Linux 37 | - [ ] Mobile 38 | 39 | Libraries 40 | 41 | - jQuery version: 42 | - yii2-widget-touchspin version: 43 | 44 | ## Isolating the problem 45 | 46 | - [ ] This bug happens [on the widget demos page](http://demos.krajee.com/widget-details/touchspin) 47 | - [ ] The bug happens consistently across all tested browsers 48 | - [ ] This bug happens when using yii2-widget-touchspin without other plugins 49 | - [ ] I can reproduce this bug in [a jsbin](https://jsbin.com/) -------------------------------------------------------------------------------- /src/TouchSpin.php: -------------------------------------------------------------------------------- 1 | 19 | * @since 1.0 20 | * @see http://www.virtuosoft.eu/code/bootstrap-touchspin/ 21 | */ 22 | class TouchSpin extends InputWidget 23 | { 24 | /** 25 | * @inheritdoc 26 | */ 27 | public $pluginName = 'TouchSpin'; 28 | 29 | /** 30 | * @inheritdoc 31 | */ 32 | public function run() 33 | { 34 | parent::run(); 35 | $this->setPluginOptions(); 36 | $this->registerAssets(); 37 | echo $this->getInput('textInput'); 38 | } 39 | 40 | /** 41 | * Set the plugin options 42 | */ 43 | protected function setPluginOptions() 44 | { 45 | $css = 'btn ' . $this->getDefaultBtnCss(); 46 | $iconPrefix = $this->getDefaultIconPrefix(); 47 | if ($this->disabled) { 48 | $css .= ' disabled'; 49 | } 50 | $defaultPluginOptions = [ 51 | 'bsVersion' => $this->getBsVer(), 52 | 'buttonup_class' => $css, 53 | 'buttondown_class' => $css, 54 | 'buttonup_txt' => "", 55 | 'buttondown_txt' => "", 56 | ]; 57 | $this->pluginOptions = array_replace_recursive($defaultPluginOptions, $this->pluginOptions); 58 | } 59 | 60 | /** 61 | * Registers the needed assets 62 | */ 63 | public function registerAssets() 64 | { 65 | $view = $this->getView(); 66 | TouchSpinAsset::registerBundle($view, $this->bsVersion); 67 | $this->registerPlugin($this->pluginName); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at kartikv2@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Krajee Logo 4 | 5 |
6 | yii2-widget-touchspin 7 |
8 | 10 | Donate 11 | 12 |

13 | 14 | [![Stable Version](https://poser.pugx.org/kartik-v/yii2-widget-touchspin/v/stable)](https://packagist.org/packages/kartik-v/yii2-widget-touchspin) 15 | [![Unstable Version](https://poser.pugx.org/kartik-v/yii2-widget-touchspin/v/unstable)](https://packagist.org/packages/kartik-v/yii2-widget-touchspin) 16 | [![License](https://poser.pugx.org/kartik-v/yii2-widget-touchspin/license)](https://packagist.org/packages/kartik-v/yii2-widget-touchspin) 17 | [![Total Downloads](https://poser.pugx.org/kartik-v/yii2-widget-touchspin/downloads)](https://packagist.org/packages/kartik-v/yii2-widget-touchspin) 18 | [![Monthly Downloads](https://poser.pugx.org/kartik-v/yii2-widget-touchspin/d/monthly)](https://packagist.org/packages/kartik-v/yii2-widget-touchspin) 19 | [![Daily Downloads](https://poser.pugx.org/kartik-v/yii2-widget-touchspin/d/daily)](https://packagist.org/packages/kartik-v/yii2-widget-touchspin) 20 | 21 | The TouchSpin widget is a Yii 2 wrapper for for the [bootstrap-touchspin](http://www.virtuosoft.eu/code/bootstrap-touchspin) plugin by István Ujj-Mészáros, with certain additional enhancements. This input widget is a mobile and touch friendly input spinner component for Bootstrap 3. You can use the widget buttons to rapidly increase and decrease numeric and/or decimal values in your input field. The widget can be setup to include model validation rules for the related model attribute. 22 | 23 | > NOTE: This extension is a sub repo split of [yii2-widgets](https://github.com/kartik-v/yii2-widgets). The split has been done since 08-Nov-2014 to allow developers to install this specific widget in isolation if needed. One can also use the extension the previous way with the whole suite of [yii2-widgets](http://demos.krajee.com/widgets). 24 | 25 | ## Installation 26 | 27 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). Check the [composer.json](https://github.com/kartik-v/yii2-widget-touchspin/blob/master/composer.json) for this extension's requirements and dependencies. Read this [web tip /wiki](http://webtips.krajee.com/setting-composer-minimum-stability-application/) on setting the `minimum-stability` settings for your application's composer.json. 28 | 29 | To install, either run 30 | 31 | ``` 32 | $ php composer.phar require kartik-v/yii2-widget-touchspin "*" 33 | ``` 34 | 35 | or add 36 | 37 | ``` 38 | "kartik-v/yii2-widget-touchspin": "*" 39 | ``` 40 | 41 | to the ```require``` section of your `composer.json` file. 42 | 43 | ## Release Changes 44 | 45 | > NOTE: Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-widget-touchspin/blob/master/CHANGE.md) for details on changes to various releases. 46 | 47 | ## Demo 48 | 49 | You can refer detailed [documentation and demos](http://demos.krajee.com/widget-details/touchspin) on usage of the extension. 50 | 51 | ## Usage 52 | 53 | ```php 54 | use kartik\touchspin\TouchSpin; 55 | 56 | echo TouchSpin::widget([ 57 | 'name' => 'volume', 58 | 'options' => ['placeholder' => 'Adjust...'], 59 | 'pluginOptions' => ['step' => 1] 60 | ]); 61 | ``` 62 | 63 | ## License 64 | 65 | **yii2-widget-touchspin** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details. 66 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to yii2-widget-touchspin 2 | ===================================== 3 | Looking to contribute something to yii2-widget-touchspin? **Here's how you can help.** 4 | 5 | Please take a moment to review this document in order to make the contribution 6 | process easy and effective for everyone involved. 7 | 8 | Following these guidelines helps to communicate that you respect the time of 9 | the developers managing and developing this open source project. In return, 10 | they should reciprocate that respect in addressing your issue or assessing 11 | patches and features. 12 | 13 | Using the issue tracker 14 | ----------------------- 15 | When [reporting bugs][reporting-bugs] or 16 | [requesting features][requesting-features], the 17 | [issue tracker on GitHub][issue-tracker] is the recommended channel to use. 18 | 19 | The issue tracker **is not** a place for support requests. Refer the 20 | [widget documentation and demos](http://demos.krajee.com/widget-details/touchspin) and/or refer to the 21 | [webtips Q & A forum](http://webtips.krajee.com/questions) which are the better places to get help. 22 | 23 | Reporting bugs with yii2-widget-touchspin 24 | ----------------------------------------- 25 | We really appreciate clear bug reports that _consistently_ show an issue 26 | _within yii2-widget-touchspin_. 27 | 28 | The ideal bug report follows these guidelines: 29 | 30 | 1. **Use the [GitHub issue search][issue-search]** — Check if the issue 31 | has already been reported. 32 | 2. **Check if the issue has been fixed** — Try to reproduce the problem 33 | using the code in the `master` branch. 34 | 3. **Isolate the problem** — Try to create an 35 | [isolated js fiddle][isolated-case] that consistently reproduces the problem 36 | in case of javascript/client level code issues. 37 | 38 | Please try to be as detailed as possible in your bug report, especially if an 39 | isolated test case cannot be made. Some useful questions to include the answer 40 | to are: 41 | 42 | - What steps can be used to reproduce the issue? 43 | - What is the bug and what is the expected outcome? 44 | - What browser(s) and Operating System have you tested with? 45 | - Does the bug happen consistently across all tested browsers? 46 | - What version of jQuery are you using? And what version of yii2-widget-touchspin? 47 | - Are you using yii2-widget-touchspin with other plugins? 48 | 49 | All of these questions will help others fix and identify any potential bugs. 50 | 51 | Requesting features in yii2-widget-touchspin 52 | ------------------------------------------ 53 | Before starting work on a major feature for yii2-widget-touchspin, **read the 54 | [documentation](http://demos.krajee.com/widget-details/touchspin) first** or you may risk spending a considerable amount of 55 | time on something which the project developers are not interested in bringing into the project. 56 | 57 | ### Submitting a pull request 58 | 59 | We use GitHub's pull request system for submitting patches. Here are some 60 | guidelines to follow when creating the pull request for your fix. 61 | 62 | 1. Make sure to create a ticket for your pull request. This will serve as the 63 | bug ticket, and any discussion about the bug will take place there. Your pull 64 | request will be focused on the specific changes that fix the bug. 65 | 2. Make sure to reference the ticket you are fixing within your pull request. 66 | This will allow us to close off the ticket once we merge the pull request, or 67 | follow up on the ticket if there are any related blocking issues. 68 | 3. Explain why the specific change was made. Not everyone who is reviewing your 69 | pull request will be familiar with the problem it is fixing. 70 | 4. Run your tests first. If your tests aren't passing, the pull request won't 71 | be able to be merged. If you're breaking existing tests, make sure that you 72 | aren't causing any breaking changes. 73 | 5. Only include source changes. While it's not required, only including changes 74 | from the `src` directory will prevent merge conflicts from occuring. Making 75 | this happen can be as a simple as not committing changes from the `dist` 76 | directory. 77 | 78 | By following these steps, you will make it easier for your pull request to be 79 | reviewed and eventually merged. 80 | 81 | Triaging issues and pull requests 82 | --------------------------------- 83 | Anyone can help the project maintainers triage issues and review pull requests. 84 | 85 | ### Handling new issues 86 | 87 | yii2-widget-touchspin regularly receives new issues which need to be tested and organized. 88 | 89 | When a new issue that comes in that is similar to another existing issue, it 90 | should be checked to make sure it is not a duplicate. Duplicates issues should 91 | be marked by replying to the issue with "Duplicate of #[issue number]" where 92 | `[issue number]` is the url or issue number for the existing issue. This will 93 | allow the project maintainers to quickly close off additional issues and keep 94 | the discussion focused within a single issue. 95 | 96 | If you can test issues that are reported to yii2-widget-touchspin that contain test cases and 97 | confirm under what conditions bugs happen, that will allow others to identify 98 | what causes a bug quicker. 99 | 100 | ### Reviewing pull requests 101 | 102 | It is very common for pull requests to be opened for issues that contain a clear 103 | solution to the problem. These pull requests should be rigorously reviewed by 104 | the community before being accepted. If you are not sure about a piece of 105 | submitted code, or know of a better way to do something, do not hesitate to make 106 | a comment on the pull request. 107 | 108 | ### Reviving old tickets 109 | 110 | If you come across tickets which have not been updated for a while, you are 111 | encouraged to revive them. While this can be as simple as saying `:+1:`, it is 112 | best if you can include more information on the issue. Common bugs and feature 113 | requests are more likely to be fixed, whether it is by the community or the 114 | developers, so keeping tickets up to date is encouraged. 115 | 116 | Licensing 117 | --------- 118 | 119 | It should also be made clear that **all code contributed to yii2-widget-touchspin** must be 120 | licensable under the [BSD-3 license][licensing]. Code that cannot be released 121 | under this license **cannot be accepted** into the project. 122 | 123 | [isolated-case]: https://jsfiddle.net/ 124 | [issue-search]: https://github.com/kartik-v/yii2-widget-touchspin/search?q=&type=Issues 125 | [issue-tracker]: https://github.com/kartik-v/yii2-widget-touchspin/issues 126 | [licensing]: https://github.com/kartik-v/yii2-widget-touchspin/blob/master/LICENSE.md 127 | [reporting-bugs]: #reporting-bugs-with-yii2-widget-touchspin 128 | [requesting-features]: #requesting-features-in-yii2-widget-touchspin -------------------------------------------------------------------------------- /src/assets/js/jquery.bootstrap-touchspin.min.js: -------------------------------------------------------------------------------- 1 | !function(t){"function"==typeof define&&define.amd?define(["jquery"],t):"object"==typeof module&&module.exports?module.exports=function(n,o){return void 0===o&&(o="undefined"!=typeof window?require("jquery"):require("jquery")(n)),t(o),o}:t(jQuery)}(function(t){"use strict";var n=0;t.fn.TouchSpin=function(o){var s={min:0,max:100,bsVersion:4,initval:"",replacementval:"",step:1,decimals:0,stepinterval:100,forcestepdivisibility:"round",stepintervaldelay:500,verticalbuttons:!1,verticalup:"+",verticaldown:"-",verticalupclass:"",verticaldownclass:"",prefix:"",postfix:"",prefix_extraclass:"",postfix_extraclass:"",booster:!0,boostat:10,maxboostedstep:!1,mousewheel:!0,buttondown_class:"btn btn-primary",buttonup_class:"btn btn-primary",buttondown_txt:"-",buttonup_txt:"+",callback_before_calculation:function(t){return t},callback_after_calculation:function(t){return t}},p={min:"min",max:"max",initval:"init-val",replacementval:"replacement-val",step:"step",decimals:"decimals",stepinterval:"step-interval",verticalbuttons:"vertical-buttons",verticalupclass:"vertical-up-class",verticaldownclass:"vertical-down-class",forcestepdivisibility:"force-step-divisibility",stepintervaldelay:"step-interval-delay",prefix:"prefix",postfix:"postfix",prefix_extraclass:"prefix-extra-class",postfix_extraclass:"postfix-extra-class",booster:"booster",boostat:"boostat",maxboostedstep:"max-boosted-step",mousewheel:"mouse-wheel",buttondown_class:"button-down-class",buttonup_class:"button-up-class",buttondown_txt:"button-down-txt",buttonup_txt:"button-up-txt"};return this.each(function(){function a(){if(!A.data("alreadyinitialized")){if(A.data("alreadyinitialized",!0),n+=1,A.data("spinnerid",n),!A.is("input"))return void console.log("Must be an input.");u(),i(),w(),d(),h(),v(),x(),g()}}function i(){""!==N.initval&&""===A.val()&&A.val(N.initval)}function e(t){l(t),w();var n=q.input.val();""!==n&&(n=Number(N.callback_before_calculation(q.input.val())),q.input.val(N.callback_after_calculation(Number(n).toFixed(N.decimals))))}function u(){N=t.extend({},s,E,r(),o)}function r(){var n={};return t.each(p,function(t,o){var s="bts-"+o;A.is("[data-"+s+"]")&&(n[t]=A.data(s))}),n}function c(){var n=A.parent();D(),A.off(".touchspin"),n.hasClass("bootstrap-touchspin-injected")?(A.siblings().remove(),A.unwrap()):(t(".bootstrap-touchspin-injected",n).remove(),n.removeClass("bootstrap-touchspin")),A.data("alreadyinitialized",!1)}function l(n){if(N=t.extend({},N,n),n.postfix){var o=A.parent().find(".bootstrap-touchspin-postfix");0===o.length&&M.insertAfter(A),A.parent().find(".bootstrap-touchspin-postfix .input-group-text").text(n.postfix)}if(n.prefix){var s=A.parent().find(".bootstrap-touchspin-prefix");0===s.length&&F.insertBefore(A),A.parent().find(".bootstrap-touchspin-prefix .input-group-text").text(n.prefix)}v()}function d(){var t=A.val(),n=A.parent();""!==t&&(t=N.callback_after_calculation(Number(t).toFixed(N.decimals))),A.data("initvalue",t).val(t),A.addClass("form-control"),n.hasClass("input-group")?f(n):b()}function f(n){n.addClass("bootstrap-touchspin");var o,s,p=A.prev(),a=A.next(),i=N.bsVersion,e=''+N.prefix+"",u=''+N.postfix+"";5==i&&(e=''+N.prefix+"",u=''+N.postfix+""),p.hasClass("input-group-btn")||p.hasClass("input-group-prepend")?(o='",p.append(o)):(o=5==i?'":'",t(o).insertBefore(A)),a.hasClass("input-group-btn")||a.hasClass("input-group-append")?(s='",a.prepend(s)):(s=5==i?'":'",t(s).insertAfter(A)),t(e).insertBefore(A),t(u).insertAfter(A),P=n}function b(){var n,o=N.bsVersion,s="";A.hasClass("input-sm")&&(s="input-group-sm"),A.hasClass("input-lg")&&(s="input-group-lg"),n=N.verticalbuttons?'
'+(5!=o?'':"")+''+N.prefix+""+(5!=o?"":"")+(5!=o?'':"")+''+N.postfix+""+(5!=o?"":"")+(5!=o?'':"")+'"+(5!=o?"":"")+"
":'
'+(5!=o?'':"")+'"+(5!=o?"":"")+(5!=o?'':"")+''+N.prefix+""+(5!=o?"":"")+(5!=o?'':"")+''+N.postfix+""+(5!=o?"":"")+(5!=o?'':"")+'"+(5!=o?"":"")+"
",P=t(n).insertBefore(A),t(".bootstrap-touchspin-prefix",P).after(A),A.hasClass("input-sm")?P.addClass("input-group-sm"):A.hasClass("input-lg")&&P.addClass("input-group-lg")}function h(){q={down:t(".bootstrap-touchspin-down",P),up:t(".bootstrap-touchspin-up",P),input:t("input",P),prefix:t(".bootstrap-touchspin-prefix",P).addClass(N.prefix_extraclass),postfix:t(".bootstrap-touchspin-postfix",P).addClass(N.postfix_extraclass)}}function v(){""===N.prefix&&(F=q.prefix.detach()),""===N.postfix&&(M=q.postfix.detach())}function x(){A.on("keydown.touchspin",function(t){var n=t.keyCode||t.which;38===n?("up"!==O&&(y(),j()),t.preventDefault()):40===n&&("down"!==O&&(k(),C()),t.preventDefault())}),A.on("keyup.touchspin",function(t){var n=t.keyCode||t.which;38===n?D():40===n&&D()}),A.on("blur.touchspin",function(){w(),A.val(N.callback_after_calculation(A.val()))}),q.down.on("keydown",function(t){var n=t.keyCode||t.which;32!==n&&13!==n||("down"!==O&&(k(),C()),t.preventDefault())}),q.down.on("keyup.touchspin",function(t){var n=t.keyCode||t.which;32!==n&&13!==n||D()}),q.up.on("keydown.touchspin",function(t){var n=t.keyCode||t.which;32!==n&&13!==n||("up"!==O&&(y(),j()),t.preventDefault())}),q.up.on("keyup.touchspin",function(t){var n=t.keyCode||t.which;32!==n&&13!==n||D()}),q.down.on("mousedown.touchspin",function(t){q.down.off("touchstart.touchspin"),A.is(":disabled")||(k(),C(),t.preventDefault(),t.stopPropagation())}),q.down.on("touchstart.touchspin",function(t){q.down.off("mousedown.touchspin"),A.is(":disabled")||(k(),C(),t.preventDefault(),t.stopPropagation())}),q.up.on("mousedown.touchspin",function(t){q.up.off("touchstart.touchspin"),A.is(":disabled")||(y(),j(),t.preventDefault(),t.stopPropagation())}),q.up.on("touchstart.touchspin",function(t){q.up.off("mousedown.touchspin"),A.is(":disabled")||(y(),j(),t.preventDefault(),t.stopPropagation())}),q.up.on("mouseup.touchspin mouseout.touchspin touchleave.touchspin touchend.touchspin touchcancel.touchspin",function(t){O&&(t.stopPropagation(),D())}),q.down.on("mouseup.touchspin mouseout.touchspin touchleave.touchspin touchend.touchspin touchcancel.touchspin",function(t){O&&(t.stopPropagation(),D())}),q.down.on("mousemove.touchspin touchmove.touchspin",function(t){O&&(t.stopPropagation(),t.preventDefault())}),q.up.on("mousemove.touchspin touchmove.touchspin",function(t){O&&(t.stopPropagation(),t.preventDefault())}),A.on("mousewheel.touchspin DOMMouseScroll.touchspin",function(t){if(N.mousewheel&&A.is(":focus")){var n=t.originalEvent.wheelDelta||-t.originalEvent.deltaY||-t.originalEvent.detail;t.stopPropagation(),t.preventDefault(),0>n?k():y()}})}function g(){A.on("touchspin.destroy",function(){c()}),A.on("touchspin.uponce",function(){D(),y()}),A.on("touchspin.downonce",function(){D(),k()}),A.on("touchspin.startupspin",function(){j()}),A.on("touchspin.startdownspin",function(){C()}),A.on("touchspin.stopspin",function(){D()}),A.on("touchspin.updatesettings",function(t,n){e(n)})}function m(t){switch(N.forcestepdivisibility){case"round":return(Math.round(t/N.step)*N.step).toFixed(N.decimals);case"floor":return(Math.floor(t/N.step)*N.step).toFixed(N.decimals);case"ceil":return(Math.ceil(t/N.step)*N.step).toFixed(N.decimals);default:return t}}function w(){var t,n,o;return t=N.callback_before_calculation(A.val()),""===t?void(""!==N.replacementval&&(A.val(N.replacementval),A.trigger("change"))):void(N.decimals>0&&"."===t||(n=parseFloat(t),isNaN(n)&&(n=""!==N.replacementval?N.replacementval:0),o=n,n.toString()!==t&&(o=n),null!==N.min&&nN.max&&(o=N.max),o=m(o),Number(t).toString()!==o.toString()&&(A.val(o),A.trigger("change"))))}function _(){if(N.booster){var t=Math.pow(2,Math.floor(V/N.boostat))*N.step;return N.maxboostedstep&&t>N.maxboostedstep&&(t=N.maxboostedstep,S=Math.round(S/t)*t),Math.max(N.step,t)}return N.step}function y(){w(),S=parseFloat(N.callback_before_calculation(q.input.val())),isNaN(S)&&(S=0);var t=S,n=_();S+=n,null!==N.max&&S>N.max&&(S=N.max,A.trigger("touchspin.on.max"),D()),q.input.val(N.callback_after_calculation(Number(S).toFixed(N.decimals))),t!==S&&A.trigger("change")}function k(){w(),S=parseFloat(N.callback_before_calculation(q.input.val())),isNaN(S)&&(S=0);var t=S,n=_();S-=n,null!==N.min&&S', 246 | postfixhtml = '' + settings.postfix + ''; 247 | if (bsVersion == 5) { 248 | prefixhtml = '' + settings.prefix + ''; 249 | postfixhtml = '' + settings.postfix + ''; 250 | } 251 | if (prev.hasClass('input-group-btn') || prev.hasClass('input-group-prepend')) { 252 | downhtml = ''; 253 | prev.append(downhtml); 254 | } else { 255 | if (bsVersion == 5) { 256 | downhtml = ''; 257 | } else { 258 | downhtml = ''; 259 | } 260 | $(downhtml).insertBefore(originalinput); 261 | } 262 | 263 | if (next.hasClass('input-group-btn') || next.hasClass('input-group-append')) { 264 | uphtml = ''; 265 | next.prepend(uphtml); 266 | } else { 267 | if (bsVersion == 5) { 268 | uphtml = ''; 269 | } else { 270 | uphtml = ''; 271 | } 272 | $(uphtml).insertAfter(originalinput); 273 | } 274 | 275 | $(prefixhtml).insertBefore(originalinput); 276 | $(postfixhtml).insertAfter(originalinput); 277 | 278 | container = parentelement; 279 | } 280 | 281 | function _buildInputGroup() { 282 | var html, bsVer = settings.bsVersion; 283 | 284 | var inputGroupSize = ''; 285 | if (originalinput.hasClass('input-sm')) { 286 | inputGroupSize = 'input-group-sm'; 287 | } 288 | 289 | if (originalinput.hasClass('input-lg')) { 290 | inputGroupSize = 'input-group-lg'; 291 | } 292 | 293 | if (settings.verticalbuttons) { 294 | /* 295 | * BEGIN change by Kartik for better BS3 & BS4 styling 296 | */ 297 | html = '
' + 298 | (bsVer != 5 ? '' : '') + 299 | '' + settings.prefix + '' + 300 | (bsVer != 5 ? '' : '') + 301 | (bsVer != 5 ? '' : '') + 302 | '' + settings.postfix + '' + 303 | (bsVer != 5 ? '' : '') + 304 | (bsVer != 5 ? '' : '') + 305 | '' + 306 | '' + 309 | '' + 312 | (bsVer != 5 ? '' : '') + 313 | '
'; 314 | /* 315 | * END change by Kartik for better BS3 & BS4 styling 316 | */ 317 | } else { 318 | html = '
' + 319 | (bsVer != 5 ? '' : '') + 320 | '' + 323 | (bsVer != 5 ? '' : '') + 324 | (bsVer != 5 ? '' : '') + 325 | '' + settings.prefix + '' + 326 | (bsVer != 5 ? '' : '') + 327 | (bsVer != 5 ? '' : '') + 328 | '' + settings.postfix + '' + 329 | (bsVer != 5 ? '' : '') + 330 | (bsVer != 5 ? '' : '') + 331 | '' + 332 | (bsVer != 5 ? '' : '') + 333 | '
'; 334 | } 335 | 336 | container = $(html).insertBefore(originalinput); 337 | 338 | $('.bootstrap-touchspin-prefix', container).after(originalinput); 339 | 340 | if (originalinput.hasClass('input-sm')) { 341 | container.addClass('input-group-sm'); 342 | } else if (originalinput.hasClass('input-lg')) { 343 | container.addClass('input-group-lg'); 344 | } 345 | } 346 | 347 | function _initElements() { 348 | elements = { 349 | down: $('.bootstrap-touchspin-down', container), 350 | up: $('.bootstrap-touchspin-up', container), 351 | input: $('input', container), 352 | prefix: $('.bootstrap-touchspin-prefix', container).addClass(settings.prefix_extraclass), 353 | postfix: $('.bootstrap-touchspin-postfix', container).addClass(settings.postfix_extraclass) 354 | }; 355 | } 356 | 357 | function _hideEmptyPrefixPostfix() { 358 | if (settings.prefix === '') { 359 | _detached_prefix = elements.prefix.detach(); 360 | } 361 | 362 | if (settings.postfix === '') { 363 | _detached_postfix = elements.postfix.detach(); 364 | } 365 | } 366 | 367 | function _bindEvents() { 368 | originalinput.on('keydown.touchspin', function (ev) { 369 | var code = ev.keyCode || ev.which; 370 | 371 | if (code === 38) { 372 | if (spinning !== 'up') { 373 | upOnce(); 374 | startUpSpin(); 375 | } 376 | ev.preventDefault(); 377 | } else if (code === 40) { 378 | if (spinning !== 'down') { 379 | downOnce(); 380 | startDownSpin(); 381 | } 382 | ev.preventDefault(); 383 | } 384 | }); 385 | 386 | originalinput.on('keyup.touchspin', function (ev) { 387 | var code = ev.keyCode || ev.which; 388 | 389 | if (code === 38) { 390 | stopSpin(); 391 | } else if (code === 40) { 392 | stopSpin(); 393 | } 394 | }); 395 | 396 | originalinput.on('blur.touchspin', function () { 397 | _checkValue(); 398 | originalinput.val(settings.callback_after_calculation(originalinput.val())); 399 | }); 400 | 401 | elements.down.on('keydown', function (ev) { 402 | var code = ev.keyCode || ev.which; 403 | 404 | if (code === 32 || code === 13) { 405 | if (spinning !== 'down') { 406 | downOnce(); 407 | startDownSpin(); 408 | } 409 | ev.preventDefault(); 410 | } 411 | }); 412 | 413 | elements.down.on('keyup.touchspin', function (ev) { 414 | var code = ev.keyCode || ev.which; 415 | 416 | if (code === 32 || code === 13) { 417 | stopSpin(); 418 | } 419 | }); 420 | 421 | elements.up.on('keydown.touchspin', function (ev) { 422 | var code = ev.keyCode || ev.which; 423 | 424 | if (code === 32 || code === 13) { 425 | if (spinning !== 'up') { 426 | upOnce(); 427 | startUpSpin(); 428 | } 429 | ev.preventDefault(); 430 | } 431 | }); 432 | 433 | elements.up.on('keyup.touchspin', function (ev) { 434 | var code = ev.keyCode || ev.which; 435 | 436 | if (code === 32 || code === 13) { 437 | stopSpin(); 438 | } 439 | }); 440 | 441 | elements.down.on('mousedown.touchspin', function (ev) { 442 | elements.down.off('touchstart.touchspin'); // android 4 workaround 443 | 444 | if (originalinput.is(':disabled')) { 445 | return; 446 | } 447 | 448 | downOnce(); 449 | startDownSpin(); 450 | 451 | ev.preventDefault(); 452 | ev.stopPropagation(); 453 | }); 454 | 455 | elements.down.on('touchstart.touchspin', function (ev) { 456 | elements.down.off('mousedown.touchspin'); // android 4 workaround 457 | 458 | if (originalinput.is(':disabled')) { 459 | return; 460 | } 461 | 462 | downOnce(); 463 | startDownSpin(); 464 | 465 | ev.preventDefault(); 466 | ev.stopPropagation(); 467 | }); 468 | 469 | elements.up.on('mousedown.touchspin', function (ev) { 470 | elements.up.off('touchstart.touchspin'); // android 4 workaround 471 | 472 | if (originalinput.is(':disabled')) { 473 | return; 474 | } 475 | 476 | upOnce(); 477 | startUpSpin(); 478 | 479 | ev.preventDefault(); 480 | ev.stopPropagation(); 481 | }); 482 | 483 | elements.up.on('touchstart.touchspin', function (ev) { 484 | elements.up.off('mousedown.touchspin'); // android 4 workaround 485 | 486 | if (originalinput.is(':disabled')) { 487 | return; 488 | } 489 | 490 | upOnce(); 491 | startUpSpin(); 492 | 493 | ev.preventDefault(); 494 | ev.stopPropagation(); 495 | }); 496 | 497 | elements.up.on('mouseup.touchspin mouseout.touchspin touchleave.touchspin touchend.touchspin touchcancel.touchspin', function (ev) { 498 | if (!spinning) { 499 | return; 500 | } 501 | 502 | ev.stopPropagation(); 503 | stopSpin(); 504 | }); 505 | 506 | elements.down.on('mouseup.touchspin mouseout.touchspin touchleave.touchspin touchend.touchspin touchcancel.touchspin', function (ev) { 507 | if (!spinning) { 508 | return; 509 | } 510 | 511 | ev.stopPropagation(); 512 | stopSpin(); 513 | }); 514 | 515 | elements.down.on('mousemove.touchspin touchmove.touchspin', function (ev) { 516 | if (!spinning) { 517 | return; 518 | } 519 | 520 | ev.stopPropagation(); 521 | ev.preventDefault(); 522 | }); 523 | 524 | elements.up.on('mousemove.touchspin touchmove.touchspin', function (ev) { 525 | if (!spinning) { 526 | return; 527 | } 528 | 529 | ev.stopPropagation(); 530 | ev.preventDefault(); 531 | }); 532 | 533 | originalinput.on('mousewheel.touchspin DOMMouseScroll.touchspin', function (ev) { 534 | if (!settings.mousewheel || !originalinput.is(':focus')) { 535 | return; 536 | } 537 | 538 | var delta = ev.originalEvent.wheelDelta || -ev.originalEvent.deltaY || -ev.originalEvent.detail; 539 | 540 | ev.stopPropagation(); 541 | ev.preventDefault(); 542 | 543 | if (delta < 0) { 544 | downOnce(); 545 | } else { 546 | upOnce(); 547 | } 548 | }); 549 | } 550 | 551 | function _bindEventsInterface() { 552 | originalinput.on('touchspin.destroy', function () { 553 | _destroy(); 554 | }); 555 | 556 | originalinput.on('touchspin.uponce', function () { 557 | stopSpin(); 558 | upOnce(); 559 | }); 560 | 561 | originalinput.on('touchspin.downonce', function () { 562 | stopSpin(); 563 | downOnce(); 564 | }); 565 | 566 | originalinput.on('touchspin.startupspin', function () { 567 | startUpSpin(); 568 | }); 569 | 570 | originalinput.on('touchspin.startdownspin', function () { 571 | startDownSpin(); 572 | }); 573 | 574 | originalinput.on('touchspin.stopspin', function () { 575 | stopSpin(); 576 | }); 577 | 578 | originalinput.on('touchspin.updatesettings', function (e, newsettings) { 579 | changeSettings(newsettings); 580 | }); 581 | } 582 | 583 | function _forcestepdivisibility(value) { 584 | switch (settings.forcestepdivisibility) { 585 | case 'round': 586 | return (Math.round(value / settings.step) * settings.step).toFixed(settings.decimals); 587 | case 'floor': 588 | return (Math.floor(value / settings.step) * settings.step).toFixed(settings.decimals); 589 | case 'ceil': 590 | return (Math.ceil(value / settings.step) * settings.step).toFixed(settings.decimals); 591 | default: 592 | return value; 593 | } 594 | } 595 | 596 | function _checkValue() { 597 | var val, parsedval, returnval; 598 | 599 | val = settings.callback_before_calculation(originalinput.val()); 600 | 601 | if (val === '') { 602 | if (settings.replacementval !== '') { 603 | originalinput.val(settings.replacementval); 604 | originalinput.trigger('change'); 605 | } 606 | return; 607 | } 608 | 609 | if (settings.decimals > 0 && val === '.') { 610 | return; 611 | } 612 | 613 | parsedval = parseFloat(val); 614 | 615 | if (isNaN(parsedval)) { 616 | if (settings.replacementval !== '') { 617 | parsedval = settings.replacementval; 618 | } else { 619 | parsedval = 0; 620 | } 621 | } 622 | 623 | returnval = parsedval; 624 | 625 | if (parsedval.toString() !== val) { 626 | returnval = parsedval; 627 | } 628 | 629 | if ((settings.min !== null) && (parsedval < settings.min)) { 630 | returnval = settings.min; 631 | } 632 | 633 | if ((settings.max !== null) && (parsedval > settings.max)) { 634 | returnval = settings.max; 635 | } 636 | 637 | returnval = _forcestepdivisibility(returnval); 638 | 639 | if (Number(val).toString() !== returnval.toString()) { 640 | originalinput.val(returnval); 641 | originalinput.trigger('change'); 642 | } 643 | } 644 | 645 | function _getBoostedStep() { 646 | if (!settings.booster) { 647 | return settings.step; 648 | } else { 649 | var boosted = Math.pow(2, Math.floor(spincount / settings.boostat)) * settings.step; 650 | 651 | if (settings.maxboostedstep) { 652 | if (boosted > settings.maxboostedstep) { 653 | boosted = settings.maxboostedstep; 654 | value = Math.round((value / boosted)) * boosted; 655 | } 656 | } 657 | 658 | return Math.max(settings.step, boosted); 659 | } 660 | } 661 | 662 | function upOnce() { 663 | _checkValue(); 664 | 665 | value = parseFloat(settings.callback_before_calculation(elements.input.val())); 666 | if (isNaN(value)) { 667 | value = 0; 668 | } 669 | 670 | var initvalue = value, 671 | boostedstep = _getBoostedStep(); 672 | 673 | value = value + boostedstep; 674 | 675 | if ((settings.max !== null) && (value > settings.max)) { 676 | value = settings.max; 677 | originalinput.trigger('touchspin.on.max'); 678 | stopSpin(); 679 | } 680 | 681 | elements.input.val(settings.callback_after_calculation(Number(value).toFixed(settings.decimals))); 682 | 683 | if (initvalue !== value) { 684 | originalinput.trigger('change'); 685 | } 686 | } 687 | 688 | function downOnce() { 689 | _checkValue(); 690 | 691 | value = parseFloat(settings.callback_before_calculation(elements.input.val())); 692 | if (isNaN(value)) { 693 | value = 0; 694 | } 695 | 696 | var initvalue = value, 697 | boostedstep = _getBoostedStep(); 698 | 699 | value = value - boostedstep; 700 | 701 | if ((settings.min !== null) && (value < settings.min)) { 702 | value = settings.min; 703 | originalinput.trigger('touchspin.on.min'); 704 | stopSpin(); 705 | } 706 | 707 | elements.input.val(settings.callback_after_calculation(Number(value).toFixed(settings.decimals))); 708 | 709 | if (initvalue !== value) { 710 | originalinput.trigger('change'); 711 | } 712 | } 713 | 714 | function startDownSpin() { 715 | stopSpin(); 716 | 717 | spincount = 0; 718 | spinning = 'down'; 719 | 720 | originalinput.trigger('touchspin.on.startspin'); 721 | originalinput.trigger('touchspin.on.startdownspin'); 722 | 723 | downDelayTimeout = setTimeout(function () { 724 | downSpinTimer = setInterval(function () { 725 | spincount++; 726 | downOnce(); 727 | }, settings.stepinterval); 728 | }, settings.stepintervaldelay); 729 | } 730 | 731 | function startUpSpin() { 732 | stopSpin(); 733 | 734 | spincount = 0; 735 | spinning = 'up'; 736 | 737 | originalinput.trigger('touchspin.on.startspin'); 738 | originalinput.trigger('touchspin.on.startupspin'); 739 | 740 | upDelayTimeout = setTimeout(function () { 741 | upSpinTimer = setInterval(function () { 742 | spincount++; 743 | upOnce(); 744 | }, settings.stepinterval); 745 | }, settings.stepintervaldelay); 746 | } 747 | 748 | function stopSpin() { 749 | clearTimeout(downDelayTimeout); 750 | clearTimeout(upDelayTimeout); 751 | clearInterval(downSpinTimer); 752 | clearInterval(upSpinTimer); 753 | 754 | switch (spinning) { 755 | case 'up': 756 | originalinput.trigger('touchspin.on.stopupspin'); 757 | originalinput.trigger('touchspin.on.stopspin'); 758 | break; 759 | case 'down': 760 | originalinput.trigger('touchspin.on.stopdownspin'); 761 | originalinput.trigger('touchspin.on.stopspin'); 762 | break; 763 | } 764 | 765 | spincount = 0; 766 | spinning = false; 767 | } 768 | 769 | }); 770 | 771 | }; 772 | 773 | })); 774 | --------------------------------------------------------------------------------