andreruffert / rangeslider.js

🎚 HTML5 input range slider element jQuery polyfill
https://rangeslider.js.org
MIT License
2.16k stars 401 forks source link

Using rangeslider.js in RequireJS #155

Closed ChuyUX closed 9 years ago

ChuyUX commented 9 years ago

Hello, I'm trying to call this script in RequireJS. Knowing that this plugins it's AMD enable, the definition that I'm using is this.

define(function (require) { var $ = require('jquery'), rangeslider = require('rangeslider'); $('input[type="range"]').rangeslider({ polyfill: false }); });

But sometimes, this doesn't work, and gets me an error: TypeError: $(...).rangeslider is not a function Hope you can help me out with this issue Thanks

andreruffert commented 9 years ago

I would recommend to take a look at the RequireJS docs again :)

First of all you need a config to define the path to your files e.g.

require.config({
    paths: {
        'jquery': 'path/to/jquery',
        'rangeslider': 'path/to/rangeslider'
        ...
    }
});

Now you can define your modules e.g

define([
    'jquery',
    'rangeslider'
], function ($, rangeslider) {

  $('input[type="range"]').rangeslider({
    polyfill: false
  });

});
ChuyUX commented 9 years ago

Well, I forgot to mentioned and share that. I actually have this require.config with the each path defined as you put it previously. But, as I told you, this sometimes works and sometimes doesn't. I actually have another AMD ready plugins, like Slick, and it always works. So I know that someting I'm doing right. I don't know if there is an error in the way you built the script to be AMD

andreruffert commented 9 years ago

K sorry no idea then. But the code how you load the modules doesn't look right to me. I personally use this plugin in an AMD environment and it works perfectly with the code posted above.