Skip to content

Multiple Instance of FocusPicker onChange #8

@IronLady

Description

@IronLady

Hi,

I am trying to build a page background customizer using Image focus.
I setup an element with some id and it has 2 hidden input field to hold the x and y value.

Then I initialize the FocusPicker and if the value changed, the 2 hidden field will get updated and later will be submitted along with the rest of the form.

Everything is fine if I use only single instance of FocusPicker. But, when I have two instance of FocusPicker, whenever I move the first focus, the 2 hidden field from the second instance that get updated instead.

I can see that the data attribute in the first focusPicker is fine, it's just the onChange function from the first instance doesn't get executed.

var _this = this;
var focusedImage = new imageFocus.FocusPicker(this.$('img.focus-picker')[0], {
    onChange: function(focus){
        $('[name="[' + _this.data.key + '][x]"]').val(focus.x);
        $('[name="[' + _this.data.key + '][y]"]').val(focus.y);
    }
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions