From 4bbbfa8baab418324b005214940e21cc892a151f Mon Sep 17 00:00:00 2001 From: Luis Leiva Date: Sun, 12 Nov 2017 20:46:54 +0100 Subject: [PATCH] Unified postProcess() --- jquery.sketchable.js | 5 +++-- sketchable.js | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/jquery.sketchable.js b/jquery.sketchable.js index 4b54995..1214449 100644 --- a/jquery.sketchable.js +++ b/jquery.sketchable.js @@ -44,8 +44,7 @@ elem.bind('touchstart', touchdownHandler); elem.bind('touchmove', touchmoveHandler); elem.bind('touchend', touchupHandler); - // Fix unwanted highlight "bug". Note: `this` is the actual DOM element. - this.onselectstart = function() { return false }; + postProcess(elem, options); } @@ -350,6 +349,8 @@ // Visually indicate whether this element is interactive or not. elem[0].style.cursor = options.interactive ? 'pointer' : 'not-allowed'; } + // Fix unwanted highlight "bug". Note: `this` is the actual DOM element. + this.onselectstart = function() { return false }; }; /** diff --git a/sketchable.js b/sketchable.js index 76581b7..7c5cfde 100644 --- a/sketchable.js +++ b/sketchable.js @@ -69,13 +69,8 @@ Event.add(elem, 'touchstart', touchdownHandler); Event.add(elem, 'touchmove', touchmoveHandler); Event.add(elem, 'touchend', touchupHandler); - // Fix unwanted highlight "bug". - elem.onselectstart = function() { return false }; - if (options.cssCursors) { - // Visually indicate whether this element is interactive or not. - elem.style.cursor = options.interactive ? 'pointer' : 'not-allowed'; - } + postProcess(elem, options); } var sketch = new jSketch(elem, options.graphics); @@ -120,6 +115,7 @@ var elem = this.elem, data = dataBind(elem)[namespace]; if (options) { // setter data.options = deepExtend({}, Sketchable.prototype.defaults, options || {}); + postProcess(elem); return this; } else { // getter return data; @@ -355,6 +351,19 @@ } }; + /** + * @private + */ + function postProcess(elem, options) { + if (!options) options = dataBind(elem)[namespace].options; + if (options.cssCursors) { + // Visually indicate whether this element is interactive or not. + elem.style.cursor = options.interactive ? 'pointer' : 'not-allowed'; + } + // Fix unwanted highlight "bug". + elem.onselectstart = function() { return false }; + }; + /** * @private */