diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..1f4c224 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,41 @@ +name: Release +on: + push: + branches: + - main + - master + +jobs: + release: + name: Release + runs-on: ubuntu-latest + permissions: + contents: write + issues: write + pull-requests: write + id-token: write # This enables provenance + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "lts/*" + cache: 'npm' + registry-url: 'https://registry.npmjs.org' + + - name: Install dependencies + run: npm ci + + - name: Verify the integrity of provenance attestations and registry signatures + run: npm audit signatures + + - name: Release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + run: npx semantic-release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..150aeeb --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,31 @@ +name: Tests + +on: + push: + branches: [ main, master ] + pull_request: + branches: [ main, master ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js + uses: actions/setup-node@v4 + with: + node-version: '20.x' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm run test:single + + - name: Upload coverage + uses: codecov/codecov-action@v4 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 485dee6..1c45971 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ .idea +node_modules +.DS_Store +npm-debug.log +npm-debug.log.* +yarn-debug.log +yarn-debug.log.* +yarn-error.log~ +coverage \ No newline at end of file diff --git a/.releaserc.json: b/.releaserc.json: new file mode 100644 index 0000000..ae15ad0 --- /dev/null +++ b/.releaserc.json: @@ -0,0 +1,17 @@ +{ + "branches": ["main", "master"], + "plugins": [ + "@semantic-release/commit-analyzer", + "@semantic-release/release-notes-generator", + "@semantic-release/changelog", + "@semantic-release/npm", + "@semantic-release/github", + [ + "@semantic-release/git", + { + "assets": ["package.json", "CHANGELOG.md"], + "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ] + ] +} \ No newline at end of file diff --git a/README.md b/README.md index a137ae8..1b5ba98 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ HTML5 like input number, but better ## Installation +### Simple + Include jQuery and `jquery.inputNumber.js` onto your page: ```html @@ -34,6 +36,20 @@ $('input.num').inputNumber({ }); ``` +### Npm + +```bash +npm install jquery-inputnumber +``` + +```javascript + +import InputNumber from 'jquery-inputnumber'; +import 'jquery-inputnumber/inputNumber.css'; + +$('input.num').inputNumber(); +``` + --- ## License diff --git a/bower.json b/bower.json deleted file mode 100644 index 52fa670..0000000 --- a/bower.json +++ /dev/null @@ -1,35 +0,0 @@ -{ - "name": "jquery.inputNumber", - "version": "0.1.3", - "main": [ - "./jquery.inputNumber.js" - ], - "dependencies": { - "jquery": ">=1.7" - }, - "homepage": "https://github.com/JiLiZART/jquery.inputNumber", - "authors": [ - "Nikolay Kostyurin " - ], - "description": "HTML5 like input number, but better", - "moduleType": [ - "globals" - ], - "keywords": [ - "jquery", - "number", - "html5", - "decimal", - "enumerable", - "input", - "form" - ], - "license": "MIT", - "ignore": [ - "**/.*", - "node_modules", - "bower_components", - "test", - "tests" - ] -} diff --git a/index.html b/index.html index eddb4a2..8772918 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ input number demo - + diff --git a/inputnumber.jquery.json b/inputnumber.jquery.json index 41684ca..dbb9695 100644 --- a/inputnumber.jquery.json +++ b/inputnumber.jquery.json @@ -1,6 +1,6 @@ { "name": "inputnumber", - "version": "0.1.2", + "version": "0.1.3", "title": "jQuery HTML5 like input number", "author": { "name": "Nikolay Kostyurn", diff --git a/jquery.inputNumber.js b/jquery.inputNumber.js index b10ce0b..e545df0 100644 --- a/jquery.inputNumber.js +++ b/jquery.inputNumber.js @@ -1,11 +1,40 @@ /** * @author Nikolay Kostyurin - * HTML5 Like enumerable input + * @version 0.1.3 HTML5 Like enumerable input */ -(function($) { + +// Uses CommonJS, AMD or browser globals to create a jQuery plugin. + +(function (factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define(['jquery'], factory); + } else if (typeof module === 'object' && module.exports) { + // Node/CommonJS + module.exports = function(root, jQuery) { + if (jQuery === undefined ) { + // require('jQuery') returns a factory that requires window to + // build a jQuery instance, we normalize how we use modules + // that require this pattern but the window provided is a noop + // if it's defined (how jquery works) + if (typeof window !== 'undefined' ) { + jQuery = require('jquery'); + } + else { + jQuery = require('jquery')(root); + } + } + factory(jQuery); + return jQuery; + }; + } else { + // Browser globals + factory(jQuery); + } +}(function ($) { 'use strict'; - var InputNumber = function(el, options) { + var InputNumber = function InputNumber(el, options) { this.el = el; this.$el = $(el); this.options = $.extend({}, this.defaults, options); @@ -13,57 +42,63 @@ }; InputNumber.prototype = { - el: null, // input element $el: null, // input element $wrap: null, //div wrapper element + $up: null, + $down: null, options: null, defaults: { - 'negative': true, - 'positive': true, - 'wrapClass': 'ranged-input', - 'inputClass': 'ranged-input__input', - 'upClass': 'ranged-input__up', - 'upTitle': 'Incrase', - 'downClass': 'ranged-input__down', - 'downTitle': 'Decrace' + min: -Infinity, + max: Infinity, + negative: true, + positive: true, + decimal: null, + wrapClass: 'ranged-input', + inputClass: 'ranged-input__input', + upClass: 'ranged-input__up', + upTitle: 'Incrase', + downClass: 'ranged-input__down', + downTitle: 'Decrace' }, init: function() { var opts = this.options; + + this.$up = $('