From 0ae18df7ae00987f09b84e295619ce590bbcf38f Mon Sep 17 00:00:00 2001 From: Kenneth Cachia Date: Mon, 30 Dec 2013 21:02:47 -0500 Subject: [PATCH] Fix broken examples on IE9. --- examples/build/scripts/drag.js | 2 +- examples/build/scripts/slider.js | 30 +++++++++++++++++++----------- test/test-css-backgrounds.js | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/examples/build/scripts/drag.js b/examples/build/scripts/drag.js index 416fc0b..ec6197d 100644 --- a/examples/build/scripts/drag.js +++ b/examples/build/scripts/drag.js @@ -50,7 +50,7 @@ offset = { x: e.offsetX || e.layerX, y: e.offsetY || e.layerY, - fixed: drag.classList.contains('border--fixed') + fixed: drag.className.indexOf('border--fixed') !== -1 }; window.addEventListener(touch ? 'touchmove' : 'mousemove', updatePosition); diff --git a/examples/build/scripts/slider.js b/examples/build/scripts/slider.js index 3733183..ea885d7 100644 --- a/examples/build/scripts/slider.js +++ b/examples/build/scripts/slider.js @@ -84,20 +84,28 @@ } + function classList(node, name, mode) { + var className = node.className; + + switch (mode) { + case 'add': + className += ' ' + name; + break; + case 'remove': + var pattern = new RegExp('(?:^|\\s)' + name + '(?!\\S)', 'g'); + className = className.replace(pattern, ''); + break; + } + + node.className = className.trim(); + } + + function hideArrows() { var hiddenClass = 'slider-arrow--hidden'; - if (x === 0) { - arrows[0].classList.add(hiddenClass); - } else { - arrows[0].classList.remove(hiddenClass); - } - - if (x === slides.length - 1) { - arrows[1].classList.add(hiddenClass); - } else { - arrows[1].classList.remove(hiddenClass); - } + classList(arrows[0], hiddenClass, x === 0 ? 'add' : 'remove'); + classList(arrows[1], hiddenClass, x === slides.length - 1 ? 'add' : 'remove'); } diff --git a/test/test-css-backgrounds.js b/test/test-css-backgrounds.js index 2ac2672..8279e7b 100644 --- a/test/test-css-backgrounds.js +++ b/test/test-css-backgrounds.js @@ -42,7 +42,7 @@ asyncTest('Test CSS Backgrounds', function () { element = document.createElement('div'); element.style.backgroundImage = 'url("../examples/build/images/' + image + '.jpg")'; - element.classList.add('css-background-image'); + element.className = 'css-background-image'; css = snippet.split(';');