From c4790bb656298ded554431a591a80c9f272e55ff Mon Sep 17 00:00:00 2001 From: Hyunje Alex Jun Date: Tue, 17 Feb 2015 01:26:44 +0000 Subject: [PATCH] Add IE support for dataset. IE doesn't support dateset, so use a raw `data-ps-id` attribute. --- src/js/plugin/instances.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/js/plugin/instances.js b/src/js/plugin/instances.js index e0d4b79..507c0cc 100644 --- a/src/js/plugin/instances.js +++ b/src/js/plugin/instances.js @@ -50,18 +50,42 @@ function Instance(element) { 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) { var newId = guid(); - element.dataset.psId = newId; + setId(element, newId); instances[newId] = new Instance(element); return instances[newId]; }; exports.remove = function (element) { - delete instances[element.dataset.psId]; - delete element.dataset.psId; + delete instances[getId(element)]; + removeId(element); }; exports.get = function (element) { - return instances[element.dataset.psId]; + return instances[getId(element)]; };