Added convenient data accessor (getter)

This commit is contained in:
Luis Leiva 2019-07-18 11:39:11 +03:00
parent 892d51e457
commit 0d6e09b6f5
2 changed files with 36 additions and 0 deletions

View File

@ -94,6 +94,24 @@
return $(this).data(namespace).options;
}
},
/**
* Retrieve data associated to an existing Sketchable instance.
* @param {string} [property] - Top-level data property, e.g. "instance", "sketch", "options".
* @return {*}
* @memberof Sketchable
* @example
* // Read all the data associated to this instance.
* var data = $('canvas').sketchable('data');
* // Quick access to the Sketchable instance.
* var inst = $('canvas').sketchable('data', 'instance');
*/
data: function(property) {
var data = $(this).data(namespace);
if (property) {
return data[property];
} else {
return data;
}
},
/**

View File

@ -122,6 +122,24 @@
return data.options;
}
},
/**
* Retrieve data associated to an existing Sketchable instance.
* @param {string} [property] - Top-level data property, e.g. "instance", "sketch", "options".
* @return {*}
* @memberof Sketchable
* @example
* var sketcher = new Sketchable('#my-canvas', { interactive: false });
* // Read all the data associated to this instance.
* var data = sketcher.data();
* // Quick access to Sketchable instance.
* var inst = sketcher.data('instance');
*/
data: function(property) {
var elem = this.elem, data = dataBind(elem)[namespace];
if (property) {
return data[property];
} else {
return data;
}
},