Add IE support for dataset.

IE doesn't support dateset, so use a raw `data-ps-id`
attribute.
This commit is contained in:
Hyunje Alex Jun 2015-02-17 01:26:44 +00:00
parent 86a23cb74e
commit c4790bb656

View File

@ -50,18 +50,42 @@ function Instance(element) {
i.railYHeight = null; i.railYHeight = null;
} }
function getId(element) {
if (typeof element.dataset === 'undefined') {
return element.getAttribute('data-ps-id');
} else {
return element.dataset.psId;
}
}
function setId(element, id) {
if (typeof element.dataset === 'undefined') {
element.setAttribute('data-ps-id', id);
} else {
element.dataset.psId = id;
}
}
function removeId(element) {
if (typeof element.dataset === 'undefined') {
element.removeAttribute('data-ps-id');
} else {
delete element.dataset.psId;
}
}
exports.add = function (element) { exports.add = function (element) {
var newId = guid(); var newId = guid();
element.dataset.psId = newId; setId(element, newId);
instances[newId] = new Instance(element); instances[newId] = new Instance(element);
return instances[newId]; return instances[newId];
}; };
exports.remove = function (element) { exports.remove = function (element) {
delete instances[element.dataset.psId]; delete instances[getId(element)];
delete element.dataset.psId; removeId(element);
}; };
exports.get = function (element) { exports.get = function (element) {
return instances[element.dataset.psId]; return instances[getId(element)];
}; };