mirror of https://github.com/luileito/jsketch.git
Added convenient data accessor (getter)
This commit is contained in:
parent
892d51e457
commit
0d6e09b6f5
|
|
@ -94,6 +94,24 @@
|
||||||
return $(this).data(namespace).options;
|
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;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,24 @@
|
||||||
return data.options;
|
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;
|
return data;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue