8000 callback with parameters ??? · Issue #20 · abpetkov/powerange · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

callback with parameters ??? #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wokung opened this issue May 15, 2015 · 3 comments
Open

callback with parameters ??? #20

wokung opened this issue May 15, 2015 · 3 comments

Comments

@wokung
Copy link
wokung commented May 15, 2015

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

@jorgechato
Copy link

👍 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 + "%";
    }
});

@wokung
Copy link
Author
wokung commented May 18, 2015

Hey,

thanks for the workaround!!!

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

@mguinness
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
0