Skip to content

Commit ab8bce0

Browse files
committed
Switch to spin.js v4 and drop support for IE 9
1 parent e050e9f commit ab8bce0

File tree

9 files changed

+53
-117
lines changed

9 files changed

+53
-117
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/node_modules
2-
/.sass-cache
3-
/dist
4-
package-lock.json
1+
/node_modules/
2+
/dist/
53
/test/*-bundle.js

.npmignore

Lines changed: 0 additions & 6 deletions
This file was deleted.

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

Gruntfile.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ module.exports = function(grunt) {
88
sass: {
99
main: {
1010
options: {
11-
style: 'compressed',
12-
sourcemap: 'none'
11+
outputStyle: 'compressed',
1312
},
1413
files: {
1514
'dist/ladda.min.css': [ 'css/ladda-themed.scss' ],
@@ -77,7 +76,7 @@ module.exports = function(grunt) {
7776
// Dependencies
7877
grunt.loadNpmTasks( 'grunt-contrib-jshint' );
7978
grunt.loadNpmTasks( 'grunt-contrib-watch' );
80-
grunt.loadNpmTasks( 'grunt-contrib-sass' );
79+
grunt.loadNpmTasks( 'grunt-sass' );
8180
grunt.loadNpmTasks( 'grunt-contrib-connect' );
8281

8382
// Default task

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Buttons accept the following attributes:
2828
- **data-style**: one of the button styles, full list in [demo](http://lab.hakim.se/ladda/) *[required]*
2929
- **data-color**: green/red/blue/purple/mint
3030
- **data-size**: xs/s/l/xl, defaults to medium
31-
- **data-spinner-size**: 40, pixel dimensions of spinner, defaults to dynamic size based on the button height
32-
- **data-spinner-color**: A hex code or any [named CSS color](http://css-tricks.com/snippets/css/named-colors-and-hex-equivalents/).
33-
- **data-spinner-lines**: 12, the number of lines the for the spinner, defaults to 12
31+
- **data-spinner-size**: pixel dimensions of spinner, defaults to dynamic size based on the button height
32+
- **data-spinner-color**: a hex code or any [named CSS color](https://css-tricks.com/snippets/css/named-colors-and-hex-equivalents/)
33+
- **data-spinner-lines**: the number of lines the for the spinner, defaults to 12
3434

3535
### JavaScript
3636

@@ -40,7 +40,7 @@ Start by importing the Ladda module:
4040
import * as Ladda from 'ladda';
4141
```
4242

43-
If you want JavaScript control over your buttons you can use the following approach:
43+
The following approach is recommended for JavaScript control over your buttons:
4444

4545
```javascript
4646
// Create a new instance of ladda for the specified button
@@ -65,7 +65,7 @@ l.isLoading();
6565
l.remove();
6666
```
6767

68-
If you will be using the loading animation for a form that is submitted to the server (always resulting in a page reload) you can use the `bind()` method:
68+
To show the loading animation for a form that is submitted to the server (always resulting in a page reload) the `bind()` method can be used:
6969

7070
```javascript
7171
// Automatically trigger the loading animation on click
@@ -85,7 +85,12 @@ Ladda.stopAll();
8585

8686
## Browser support
8787

88-
The project is tested in Chrome, Firefox, and Edge. It Should Work™ in the current stable releases of Chrome, Firefox, Edge, and Safari, as well as IE9 and up.
88+
Ladda has been tested in Chrome, Firefox, Edge, and Internet Explorer 11.
89+
It also Should Work™ in Safari and Internet Explorer 10.
90+
91+
Note: Ladda 2.x is distributed as an ES6 module, but not all browsers support importing native ES6 modules.
92+
For full browser compatibility, use a module bundler such as <a href="https://webpack.js.org/">Webpack</a>
93+
or <a href="https://rollupjs.org/">Rollup</a> to create a production-ready code bundle.
8994

9095
## Changelog
9196

css/ladda.scss

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* http://lab.hakim.se/ladda
44
* MIT licensed
55
*
6-
* Copyright (C) 2016 Hakim El Hattab, http://hakim.se
6+
* Copyright (C) 2018 Hakim El Hattab, http://hakim.se
77
*/
88

99

@@ -18,28 +18,12 @@ $spinnerSize: 32px;
1818
* MIXINS
1919
*/
2020

21-
@mixin prefix ( $property, $value ) {
22-
-webkit-#{$property}: $value;
23-
-moz-#{$property}: $value;
24-
-ms-#{$property}: $value;
25-
-o-#{$property}: $value;
26-
#{$property}: $value;
27-
}
28-
2921
@mixin transition( $value ) {
30-
-webkit-transition: $value !important; // important to override bootstrap
31-
-moz-transition: $value !important;
32-
-ms-transition: $value !important;
33-
-o-transition: $value !important;
34-
transition: $value !important;
22+
transition: $value !important;
3523
}
3624

3725
@mixin transform( $value ) {
38-
@include prefix( transform, $value );
39-
}
40-
41-
@mixin transform-origin( $value ) {
42-
@include prefix( transform-origin, $value );
26+
transform: $value;
4327
}
4428

4529
@mixin buttonColor( $name, $color ) {
@@ -53,6 +37,20 @@ $spinnerSize: 32px;
5337
}
5438

5539

40+
/*************************************
41+
* Opacity animation for spin.js
42+
*/
43+
44+
@keyframes ladda-spinner-line-fade {
45+
0%, 100% {
46+
opacity: 0.22; /* minimum opacity */
47+
}
48+
1% {
49+
opacity: 1;
50+
}
51+
}
52+
53+
5654
/*************************************
5755
* BUTTON BASE
5856
*/

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ <h1>Ladda</h1>
3434

3535
<section class="button-demo">
3636
<h3>expand-left</h3>
37-
<button class="ladda-button" data-color="green" data-style="expand-left">Submit</button>
37+
<button data-color="green" data-style="expand-left">Submit</button>
3838
</section>
3939

4040
<section class="button-demo">
4141
<h3>expand-right</h3>
42-
<button class="ladda-button" data-color="green" data-style="expand-right">Submit</button>
42+
<button data-color="green" data-style="expand-right">Submit</button>
4343
</section>
4444

4545
<section class="button-demo">
4646
<h3>expand-up</h3>
47-
<button class="ladda-button" data-color="green" data-style="expand-up">Submit</button>
47+
<button data-color="green" data-style="expand-up">Submit</button>
4848
</section>
4949

5050
<section class="button-demo">
5151
<h3>expand-down</h3>
52-
<button class="ladda-button" data-color="green" data-style="expand-down">Submit</button>
52+
<button data-color="green" data-style="expand-down">Submit</button>
5353
</section>
5454

5555

js/ladda.js

Lines changed: 4 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* http://lab.hakim.se/ladda
44
* MIT licensed
55
*
6-
* Copyright (C) 2016 Hakim El Hattab, http://hakim.se
6+
* Copyright (C) 2018 Hakim El Hattab, http://hakim.se
77
*/
88

99
import {Spinner} from 'spin.js';
@@ -26,8 +26,8 @@ export function create( button ) {
2626
}
2727

2828
// The button must have the class "ladda-button"
29-
if( !/ladda-button/i.test( button.className ) ) {
30-
button.className += ' ladda-button';
29+
if ( !button.classList.contains('ladda-button') ) {
30+
button.classList.add( 'ladda-button' );
3131
}
3232

3333
// Style is required, default to "expand-right"
@@ -244,34 +244,6 @@ function getAncestorOfTagType( elem, type ) {
244244

245245
}
246246

247-
/**
248-
* Returns a list of all inputs in the given form that
249-
* have their `required` attribute set.
250-
*
251-
* @param form The from HTML element to look in
252-
*
253-
* @return A list of elements
254-
*/
255-
function getRequiredFields( form ) {
256-
257-
var requirables = [ 'input', 'textarea', 'select' ];
258-
var inputs = [];
259-
260-
requirables.forEach(function (r) {
261-
var candidates = form.getElementsByTagName( r );
262-
263-
for( var j = 0; j < candidates.length; j++ ) {
264-
// legacy browsers don't support required property
265-
if ( candidates[j].hasAttribute('required') ) {
266-
inputs.push( candidates[j] );
267-
}
268-
}
269-
});
270-
271-
return inputs;
272-
273-
}
274-
275247
function createSpinner( button ) {
276248

277249
var height = button.offsetHeight,
@@ -314,6 +286,7 @@ function createSpinner( button ) {
314286
radius: radius,
315287
length: length,
316288
width: width,
289+
animation: 'ladda-spinner-line-fade',
317290
zIndex: 'auto',
318291
top: 'auto',
319292
left: 'auto',
@@ -351,43 +324,6 @@ function bindElement( element, options ) {
351324
if( typeof form.checkValidity === 'function' ) {
352325
valid = form.checkValidity();
353326
}
354-
// Fallback to manual validation for old browsers
355-
else {
356-
var requireds = getRequiredFields( form );
357-
for( var i = 0; i < requireds.length; i++ ) {
358-
var field = requireds[i];
359-
360-
// The input type property will always return "text" for email and url fields in IE 9.
361-
// Note that emulating IE 9 in IE 11 will also return "text" for the type attribute,
362-
// but the actual IE 9 browser will return the correct attribute.
363-
var fieldType = field.getAttribute('type');
364-
365-
if( field.value.replace( /^\s+|\s+$/g, '' ) === '' ) {
366-
valid = false;
367-
}
368-
369-
// Radiobuttons and Checkboxes need to be checked for the "checked" attribute
370-
if( (fieldType === 'checkbox' || fieldType === 'radio' ) && !field.checked ) {
371-
valid = false;
372-
}
373-
374-
// Email field validation
375-
if( fieldType === 'email' ) {
376-
// regex from https://stackoverflow.com/a/7786283/1170489
377-
valid = /^[a-z0-9!#$%&'*+/=?^_`{|}~.-]+@[a-z0-9-]+(\.[a-z0-9-]+)*$/i.test( field.value );
378-
}
379-
380-
// URL field validation
381-
if (fieldType === 'url') {
382-
// regex from https://stackoverflow.com/a/10637803/1170489
383-
valid = /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test( field.value );
384-
}
385-
386-
if (!valid) {
387-
break;
388-
}
389-
}
390-
}
391327
}
392328

393329
if( valid ) {

package.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
22
"name": "ladda",
3-
"version": "1.0.6",
3+
"version": "2.0.0",
44
"description": "Buttons with built-in loading indicators",
55
"homepage": "http://lab.hakim.se/ladda",
6+
"files": [
7+
"dist/*.css",
8+
"js/ladda.d.ts",
9+
"js/ladda.js"
10+
],
611
"main": "./js/ladda.js",
712
"types": "./js/ladda.d.ts",
813
"scripts": {
@@ -20,16 +25,16 @@
2025
"url": "git://github.com/hakimel/Ladda.git"
2126
},
2227
"devDependencies": {
23-
"grunt": "^1.0.1",
28+
"grunt": "^1.0.2",
2429
"grunt-contrib-connect": "^1.0.2",
2530
"grunt-contrib-jshint": "^1.1.0",
26-
"grunt-contrib-sass": "^1.0.0",
27-
"grunt-contrib-watch": "^1.0.0",
28-
"rollup": "^0.53.3",
29-
"rollup-plugin-node-resolve": "^3.0.0"
31+
"grunt-contrib-watch": "^1.1.0",
32+
"grunt-sass": "^2.1.0",
33+
"rollup": "^0.58.2",
34+
"rollup-plugin-node-resolve": "^3.3.0"
3035
},
3136
"license": "MIT",
3237
"dependencies": {
33-
"spin.js": "^3.1.0"
38+
"spin.js": "^4.0.0"
3439
}
3540
}

0 commit comments

Comments
 (0)