function $$(selector, context) {
context = context || document;
var elements = context.querySelectorAll(selector);
return Array.prototype.slice.call(elements);
}
$$('.image-slider').forEach(function(slider) {
// Create the extra div and
// wrap it around the first image
var div = document.createElement('div');
var img = $$('img', slider)[0];
slider.insertBefore(div, img);
div.appendChild(img);
// Create the slider
var range = document.createElement('input');
range.type = 'range';
range.oninput = function() {
div.style.width = this.value + '%';
};
slider.appendChild(range);
});