/** * * Find more about the Spinning Wheel function at * http://cubiq.org/spinning-wheel-on-webkit-for-iphone-ipod-touch/11 * * Copyright (c) 2009 Matteo Spinelli, http://cubiq.org/ * Released under MIT license * http://cubiq.org/dropbox/mit-license.txt * * Version 1.4 - Last updated: 2009.07.09 * */ var SpinningWheel = { cellHeight: 44, friction: 0.003, slotData: [], /** * * Event handler * */ handleEvent: function (e) { if (e.type == 'touchstart') { this.lockScreen(e); if (e.currentTarget.id == 'sw-cancel' || e.currentTarget.id == 'sw-done') { this.tapDown(e); } else if (e.currentTarget.id == 'sw-frame') { this.scrollStart(e); } } else if (e.type == 'touchmove') { this.lockScreen(e); if (e.currentTarget.id == 'sw-cancel' || e.currentTarget.id == 'sw-done') { this.tapCancel(e); } else if (e.currentTarget.id == 'sw-frame') { this.scrollMove(e); } } else if (e.type == 'touchend') { if (e.currentTarget.id == 'sw-cancel' || e.currentTarget.id == 'sw-done') { this.tapUp(e); } else if (e.currentTarget.id == 'sw-frame') { this.scrollEnd(e); } } else if (e.type == 'webkitTransitionEnd') { if (e.target.id == 'sw-wrapper') { this.destroy(); } else { this.backWithinBoundaries(e); } } else if (e.type == 'orientationchange') { this.onOrientationChange(e); } else if (e.type == 'scroll') { this.onScroll(e); } }, /** * * Global events * */ onOrientationChange: function (e) { window.scrollTo(0, 0); this.swWrapper.style.top = window.innerHeight + window.pageYOffset + 'px'; this.calculateSlotsWidth(); }, onScroll: function (e) { this.swWrapper.style.top = window.innerHeight + window.pageYOffset + 'px'; }, lockScreen: function (e) { e.preventDefault(); e.stopPropagation(); }, /** * * Initialization * */ reset: function () { this.slotEl = []; this.activeSlot = null; this.swWrapper = undefined; this.swSlotWrapper = undefined; this.swSlots = undefined; this.swFrame = undefined; }, calculateSlotsWidth: function () { var div = this.swSlots.getElementsByTagName('div'); for (var i = 0; i < div.length; i += 1) { this.slotEl[i].slotWidth = div[i].offsetWidth; } }, create: function () { var i, l, out, ul, div; this.reset(); // Initialize object variables // Create the Spinning Wheel main wrapper div = document.createElement('div'); div.id = 'sw-wrapper'; div.style.top = window.innerHeight + window.pageYOffset + 'px'; // Place the SW down the actual viewing screen div.style.webkitTransitionProperty = '-webkit-transform'; div.innerHTML = '