Skip to content

Commit

Permalink
Merge pull request #39 from showy/master
Browse files Browse the repository at this point in the history
Now we first check if an element has an uislider already associated. …
  • Loading branch information
kennethkalmer authored Feb 27, 2017
2 parents 59b7643 + c1f569c commit 3bf36e0
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions addon/components/range-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,38 +57,47 @@ export default Ember.Component.extend({
);
let sliderEvents = Ember.A(['change', 'set', 'slide', 'update', 'start', 'end']);

noUiSlider.create($this, properties);
// We first check if the element has a slider already created
if ($this.noUiSlider && $this.noUiSlider.destroy) {
$this.noUiSlider.destroy();
}

noUiSlider.create($this, properties, true);

let slider = $this.noUiSlider;
this.set('slider', slider);

sliderEvents.forEach(event => {
if (!isEmpty(this.get(`on-${event}`))) {
slider.on(event, () => {
run(this, function() {
let val = this.get("slider").get();
this.sendAction(`on-${event}`, val);
// We set slider next sync cycle to avoid deprecation warnings
run.schedule('sync', () => {
this.set('slider', slider);

sliderEvents.forEach(event => {
if (!isEmpty(this.get(`on-${event}`))) {
slider.on(event, () => {
run(this, function() {
let val = this.get("slider").get();
this.sendAction(`on-${event}`, val);
});
});
});
}
});

/** DEPRECATED AND WILL BE REMOVED BEFORE 1.0 **/
slider.on('change', () => {
run(this, function () {
let val = this.get("slider").get();
this.sendDeprecatedAction("change", val);
}
});
});

if (!isEmpty(this.get('slide'))) {
slider.on('slide', () => {
/** DEPRECATED AND WILL BE REMOVED BEFORE 1.0 **/
slider.on('change', () => {
run(this, function () {
let val = this.get("slider").get();
this.sendDeprecatedAction('slide', val);
let val = this.get("slider").get();
this.sendDeprecatedAction("change", val);
});
});
}

if (!isEmpty(this.get('slide'))) {
slider.on('slide', () => {
run(this, function () {
let val = this.get("slider").get();
this.sendDeprecatedAction('slide', val);
});
});
}
});
}),

update: on('didUpdateAttrs', function() {
Expand Down

0 comments on commit 3bf36e0

Please sign in to comment.