Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1206 from jwarby/issue-disabled-spinner
Browse files Browse the repository at this point in the history
Spinner: use data attributes when initialising indirectly
  • Loading branch information
Stephen Williams committed May 6, 2015
2 parents 08a8e99 + 8ef7bb9 commit 4876a35
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ define(function(require) {
var data = $this.data( 'spinner' );
var options = typeof option === 'object' && option;

options = $.extend({}, $this.data(), options);

if( !data ) $this.data('spinner', (data = new Spinner( this, options ) ) );
if( typeof option === 'string' ) methodReturn = data[ option ].apply( data, args );
});
Expand Down Expand Up @@ -235,4 +237,4 @@ define(function(require) {
$this.spinner($this.data());
});
});
});
});
30 changes: 30 additions & 0 deletions test/spinner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ require(['jquery', 'fuelux/spinner'], function($) {
'</button>' +
'</div>';

var spinnerHTMLWithDataAttributes = '<div id="ex-spinner" class="spinner"' +
' data-min="5" data-max="20" data-value="7" data-cycle="true">' +
'<input type="text" class="input-mini spinner-input">' +
'<button class="btn spinner-up">' +
'<i class="icon-chevron-up"></i>' +
'</button>' +
'<button class="btn spinner-down">' +
'<i class="icon-chevron-down"></i>' +
'</button>' +
'</div>';

test("should behave as designed", function () {
var $spinner = $(spinnerHTML).spinner();

Expand Down Expand Up @@ -102,4 +113,23 @@ require(['jquery', 'fuelux/spinner'], function($) {
equal($spinner.spinner('value'), 2, 'spinner value cycled at min');
});

test("instantiating indirectly via method uses data attributes", function() {
var $spinner = $(spinnerHTMLWithDataAttributes);
var expected = {
max: 20,
min: 5,
value: 7,
cycle: true
};
var options;

// Call a method to indirectly instantiate the spinner
$spinner.spinner('disable');

options = $spinner.data('spinner').options;

for (var e in expected) {
equal(options[e], expected[e]);
}
});
});

0 comments on commit 4876a35

Please sign in to comment.