powerange icon indicating copy to clipboard operation
powerange copied to clipboard

callback with parameters ???

Open wokung opened this issue 10 years ago • 3 comments

Hey,

is it somehow possible to add parameters to the callback function?

that would make the callback much more useful, since it is possible to pass an index or a classname for the callback.

Would be great if you could implement that. It is not possible at the moment.

Thanks!

with kind regards

wokung avatar May 15 '15 09:05 wokung

:+1: this will be great for multiples powerange.

for the one like me that need multiples powerange, this is my hack until we have a callback with parameters.

$(document).on("ready", function(){
    var cust = document.querySelectorAll('.js-customized');
    var initCust;
    var j = 0;
    for (i = 0 ; i < cust.length ; i++){
        initCust = new Powerange(cust[i], {
            callback: displayValue,
            hideRange: true,
            klass: 'power-ranger',
            min: 0,
            max: 100,
            start: 0
        });
    }

    $('.range-handle').mousedown(function(){
        j = $('.range-handle').index(this);
    });
    function displayValue() {
        $('.display-box')[j].innerHTML = cust[j].value + "%";
    }
});

jorgechato avatar May 15 '15 10:05 jorgechato

Hey,

thanks for the workaround!!!

I used jquery.each for this, but i'm not happy with the solution.

wokung avatar May 18 '15 15:05 wokung

Since ECMAScript 5 added a bind method to function objects, you can assign the element to this and then use that within the function:

var opt = {};
opt.callback = function () {
    document.getElementById(this.id + '-display').innerHTML = this.value;
}.bind(this);
var powerange = new Powerange(this, opt);

In addition, you can also associate the powerange object to the element for later use within both callback and other functions.

jQuery.data(this, 'powerange', powerange);

It would be great if Alexander could mention these workarounds in Readme.md as it would be helpful to others using multiple controls.

mguinness avatar Aug 27 '15 17:08 mguinness