Skip to content
This repository has been archived by the owner on May 30, 2024. It is now read-only.

spec: input and change event #121

Merged
merged 5 commits into from
Feb 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions dist/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@

// Attach Events
var _this = this;
this.$window.on('resize' + '.' + this.identifier, debounce(function() {
this.$window.on('resize.' + this.identifier, debounce(function() {
// Simulate resizeEnd event.
delay(function() { _this.update(); }, 300);
}, 20));

this.$document.on(this.startEvent, '#' + this.identifier + ':not(.' + this.options.disabledClass + ')', this.handleDown);

// Listen to programmatic value changes
this.$element.on('change' + '.' + this.identifier, function(e, data) {
this.$element.on('change.' + this.identifier, function(e, data) {
if (data && data.origin === _this.identifier) {
return;
}
Expand Down Expand Up @@ -282,6 +282,9 @@
this.$document.off(this.moveEvent, this.handleMove);
this.$document.off(this.endEvent, this.handleEnd);

// Ok we're done fire the change event
this.$element.trigger('change', { origin: this.identifier });

if (this.onSlideEnd && typeof this.onSlideEnd === 'function') {
this.onSlideEnd(this.position, this.value);
}
Expand Down Expand Up @@ -360,9 +363,14 @@
};

Plugin.prototype.setValue = function(value) {
if (value !== this.value) {
this.$element.val(value).trigger('change', {origin: this.identifier});
if (value === this.value) {
return;
}

// Set the new value and fire the `input` event
this.$element
.val(value)
.trigger('input', { origin: this.identifier });
};

Plugin.prototype.destroy = function() {
Expand Down
2 changes: 1 addition & 1 deletion dist/rangeslider.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ <h2>Combination with native <code>&lt;details&gt;</code> element</h2>
for (var i = $element.length - 1; i >= 0; i--) {
valueOutput($element[i]);
};
$document.on('change', 'input[type="range"]', function(e) {
$document.on('input', 'input[type="range"]', function(e) {
valueOutput(e.target);
});

Expand Down
16 changes: 12 additions & 4 deletions src/rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,15 @@

// Attach Events
var _this = this;
this.$window.on('resize' + '.' + this.identifier, debounce(function() {
this.$window.on('resize.' + this.identifier, debounce(function() {
// Simulate resizeEnd event.
delay(function() { _this.update(); }, 300);
}, 20));

this.$document.on(this.startEvent, '#' + this.identifier + ':not(.' + this.options.disabledClass + ')', this.handleDown);

// Listen to programmatic value changes
this.$element.on('change' + '.' + this.identifier, function(e, data) {
this.$element.on('change.' + this.identifier, function(e, data) {
if (data && data.origin === _this.identifier) {
return;
}
Expand Down Expand Up @@ -281,6 +281,9 @@
this.$document.off(this.moveEvent, this.handleMove);
this.$document.off(this.endEvent, this.handleEnd);

// Ok we're done fire the change event
this.$element.trigger('change', { origin: this.identifier });

if (this.onSlideEnd && typeof this.onSlideEnd === 'function') {
this.onSlideEnd(this.position, this.value);
}
Expand Down Expand Up @@ -359,9 +362,14 @@
};

Plugin.prototype.setValue = function(value) {
if (value !== this.value) {
this.$element.val(value).trigger('change', {origin: this.identifier});
if (value === this.value) {
return;
}

// Set the new value and fire the `input` event
this.$element
.val(value)
.trigger('input', { origin: this.identifier });
};

Plugin.prototype.destroy = function() {
Expand Down