IonDen / ion.rangeSlider

jQuery only range slider
http://ionden.com/a/plugins/ion.rangeSlider/en.html
MIT License
2.55k stars 507 forks source link

Work with Webpack #430

Closed romanmarkelov closed 7 years ago

romanmarkelov commented 7 years ago

There is a module:

export default ($selector, options = {}) => {
    require.ensure([], (require) => {
        require('ion-rangeslider/css/ion.rangeSlider.css');
        require('ion-rangeslider/css/ion.rangeSlider.skinFlat.css');
        require('ion-rangeslider/js/ion.rangeSlider.js');

        $selector.ionRangeSlider(options);
    });
};

initialize:

import slider from 'modules/slider';
 slider('.slider', {
        hide_min_max: true,
        hide_from_to: true,
        keyboard: true,
        drag_interval: true,
        type: 'double',
        prefix: '',
        grid: false
    });

everything works fine! but when I write down the instance variable, method fails

let instance = $('.slider').data('ionRangeSlider');
instance.reset();
// Uncaught TypeError: Cannot read property 'reset' of undefined(…)

webpack config:

//...
new webpack.ProvidePlugin({
    $: "jquery",
    jQuery: "jquery",
    "window.jQuery": "jquery"
})
//...
IonDen commented 7 years ago

Hmm, try to add callback in to slider function, which will return the instance.

Also, please check, what is $('.slider') at the moment. Maybe your are trying to apply method before slider was initialized.