jimdoescode/jqScribble

not able to get a callback to detect when isblank variable changes

Closed this issue · 4 comments

I think that we should change the library to add some trigger like:
https://stackoverflow.com/a/17528593/2860124

$('button').click(function (e) {
    $('#someID').data("key", "newValue").trigger('changeData'); 
});

$('#someID').on('changeData', function (e) {    
    alert('My Custom Event - Change Data Called! for ' + this.id);
});

or

some proxy or emitter
https://stackoverflow.com/questions/36258502/why-has-object-observe-been-deprecated

@jimdoescode

I don't know if the following is the best solution but It satisfies my expectations:

image

I would advise against modifying the existing source. If you need this functionality, you should make a wrapper around the jqScribble element and have that fire the change event and call the clear method.

something like:

function wrapScribble(jqScribble) {
    return {
        clearJQScribble: function() {
            jqScribble.clear();
            jQuery(jqScribble.canvas).trigger('canvasCleared');
        }
    };
}

I personally feel like a wrapper is the best way to go so that a developer can wrap whatever functionality they wish instead of jqScribble having to do all the triggering.

Let's continue the discussion but I'm going to close this ticket since this feature can be satisfied without having to change the core jqScribble code.

Do you suggest to do a wrapper in every function and event like this one? @jimdoescode

canvas.addEventListener('touchend', function(e)
            {
                e.preventDefault();
                if(e.touches.length == 0)self.blank = !self.brush.strokeEnd() && self.blank;
            }, false);

I really want to detect when blank variable is changed to make a validator.

@danicomas events like that should be handled by the brushes. You can implement the strokeEnd function on a custom brush to do whatever validation you'd like.