Skip to content
Browse files

eleventh commit

  • Loading branch information...
1 parent 0115d8a commit 825201f12a9dcc322b5526b88510dd6c07701160 @diverso committed
View
241 AppleClasses/AppleAnimator.js
@@ -0,0 +1,241 @@
+/*
+© Copyright 2007 Apple Inc. All rights reserved.
+
+IMPORTANT: This Apple software and the associated images located in
+/System/Library/WidgetResources/AppleClasses/ (collectively "Apple Software")
+are supplied to you by Apple Computer, Inc. (“Apple”) in consideration of your
+agreement to the following terms. Your use, installation and/or redistribution
+of this Apple Software constitutes acceptance of these terms. If you do not
+agree with these terms, please do not use, install, or redistribute this Apple
+Software.
+
+In consideration of your agreement to abide by the following terms, and subject
+to these terms, Apple grants you a personal, non-exclusive license, under
+Apple’s copyrights in the Apple Software, to use, reproduce, and redistribute
+the Apple Software, in text form (for JavaScript files) or binary form (for
+associated images), for the sole purpose of creating Dashboard widgets for Mac
+OS X.
+
+If you redistribute the Apple Software, you must retain this entire notice and
+the warranty disclaimers and limitation of liability provisions (last two
+paragraphs below) in all such redistributions of the Apple Software.
+
+You may not use the name, trademarks, service marks or logos of Apple to endorse
+or promote products that include the Apple Software without the prior written
+permission of Apple. Except as expressly stated in this notice, no other rights
+or licenses, express or implied, are granted by Apple herein, including but not
+limited to any patent rights that may be infringed by your products that
+incorporate the Apple Software or by other works in which the Apple Software may
+be incorporated.
+
+The Apple Software is provided on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
+EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
+NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
+REGARDING THE APPPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION
+WITH YOUR PRODUCTS.
+
+IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR DISTRIBUTION OF THE
+APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
+(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+function AppleAnimator (duration, interval, optionalFrom, optionalTo, optionalCallback)
+{
+ this.startTime = 0;
+ this.duration = duration;
+ this.interval = interval;
+ this.animations = new Array;
+ this.timer = null;
+ this.oncomplete = null;
+
+ this._firstTime = true;
+
+ var self = this;
+
+ this.animate = function (self) {
+
+ function limit_3 (a, b, c) {
+ return a < b ? b : (a > c ? c : a);
+ }
+
+ var T, time;
+ var ease;
+ var time = (new Date).getTime();
+ var dur = self.duration;
+ var done;
+
+ T = limit_3(time - self.startTime, 0, dur);
+ time = T / dur;
+ ease = 0.5 - (0.5 * Math.cos(Math.PI * time));
+
+ done = T >= dur;
+
+ var array = self.animations;
+ var c = array.length;
+ var first = self._firstTime;
+
+ for (var i = 0; i < c; ++i)
+ {
+ array[i].doFrame (self, ease, first, done, time);
+ }
+
+ if (done)
+ {
+ self.stop();
+ if (self.oncomplete != null)
+ {
+ self.oncomplete();
+ }
+ }
+
+ self._firstTime = false;
+ }
+
+ if (optionalFrom !== undefined && optionalTo !== undefined && optionalCallback !== undefined)
+ {
+ this.addAnimation(new AppleAnimation (optionalFrom, optionalTo, optionalCallback));
+ }
+}
+
+AppleAnimator.prototype.start = function () {
+ if (this.timer == null)
+ {
+ var timeNow = (new Date).getTime();
+ var interval = this.interval;
+
+ this.startTime = timeNow - interval; // see it back one frame
+
+ this.timer = setInterval (this.animate, interval, this);
+ }
+}
+
+AppleAnimator.prototype.stop = function () {
+ if (this.timer != null)
+ {
+ clearInterval(this.timer);
+ this.timer = null;
+ }
+}
+
+AppleAnimator.prototype.addAnimation = function (animation) {
+
+ this.animations[this.animations.length] = animation;
+}
+
+//
+// Animation class
+//
+
+function AppleAnimation (from, to, callback)
+{
+ this.from = from;
+ this.to = to;
+ this.callback = callback;
+
+ this.now = from;
+ this.ease = 0;
+ this.time = 0;
+}
+
+AppleAnimation.prototype.doFrame = function (animation, ease, first, done, time) {
+
+ var now;
+
+ if (done)
+ now = this.to;
+ else
+ now = this.from + (this.to - this.from) * ease;
+
+ this.now = now;
+ this.ease = ease;
+ this.time = time;
+ this.callback (animation, now, first, done);
+}
+
+//
+// RectAnimation class
+//
+
+function AppleRectAnimation (from, to, callback)
+{
+ this.from = from;
+ this.to = to;
+ this.callback = callback;
+
+ this.now = from;
+ this.ease = 0;
+ this.time = 0;
+}
+
+AppleRectAnimation.prototype = new AppleAnimation (0, 0, null);
+
+AppleRectAnimation.prototype.doFrame = function (animation, ease, first, done, time) {
+
+ var now;
+
+ function computeNextRectangle (from, to, ease)
+ {
+ return addRects (from, timesRect (minusRects(to, from), ease));
+ }
+
+ if (done)
+ now = this.to;
+ else
+ now = AppleRect.add (this.from, AppleRect.multiply (AppleRect.subtract (this.to, this.from), ease));
+
+ //computeNextRectangle (this.from, this.to, ease);
+ this.now = now;
+ this.ease = ease;
+ this.time = time;
+ this.callback (animation, now, first, done);
+}
+
+//
+// AppleRect class
+//
+
+function AppleRect (left, top, right, bottom) {
+ this.left = left;
+ this.top = top;
+ this.right = right;
+ this.bottom = bottom;
+}
+
+
+AppleRect.add = function (a, b) {
+ return new AppleRect (a.left + b.left,
+ a.top + b.top,
+ a.right + b.right,
+ a.bottom + b.bottom);
+}
+
+AppleRect.subtract = function (a, b) {
+ return new AppleRect (a.left - b.left,
+ a.top - b.top,
+ a.right - b.right,
+ a.bottom - b.bottom);
+}
+
+AppleRect.multiply = function (a, multiplier) {
+ return new AppleRect (a.left * multiplier,
+ a.top * multiplier,
+ a.right * multiplier,
+ a.bottom * multiplier);
+}
+
+// generic applier, pass methods like Math.floor/round/ceil
+AppleRect.prototype.apply = function (func) {
+ this.left = func(this.left);
+ this.top = func(this.top);
+ this.right = func(this.right);
+ this.bottom = func(this.bottom);
+ return this;
+}
+
+AppleRect.prototype.toString = function () {
+ return "{left:" + this.left + ", top:" + this.top + ", right:" + this.right + ", bottom:" + this.bottom + "}";
+}
View
323 AppleClasses/AppleButton.js
@@ -0,0 +1,323 @@
+/*
+© Copyright 2007 Apple Inc. All rights reserved.
+
+IMPORTANT: This Apple software and the associated images located in
+/System/Library/WidgetResources/AppleClasses/ (collectively "Apple Software")
+are supplied to you by Apple Computer, Inc. (“Apple”) in consideration of your
+agreement to the following terms. Your use, installation and/or redistribution
+of this Apple Software constitutes acceptance of these terms. If you do not
+agree with these terms, please do not use, install, or redistribute this Apple
+Software.
+
+In consideration of your agreement to abide by the following terms, and subject
+to these terms, Apple grants you a personal, non-exclusive license, under
+Apple’s copyrights in the Apple Software, to use, reproduce, and redistribute
+the Apple Software, in text form (for JavaScript files) or binary form (for
+associated images), for the sole purpose of creating Dashboard widgets for Mac
+OS X.
+
+If you redistribute the Apple Software, you must retain this entire notice and
+the warranty disclaimers and limitation of liability provisions (last two
+paragraphs below) in all such redistributions of the Apple Software.
+
+You may not use the name, trademarks, service marks or logos of Apple to endorse
+or promote products that include the Apple Software without the prior written
+permission of Apple. Except as expressly stated in this notice, no other rights
+or licenses, express or implied, are granted by Apple herein, including but not
+limited to any patent rights that may be infringed by your products that
+incorporate the Apple Software or by other works in which the Apple Software may
+be incorporated.
+
+The Apple Software is provided on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
+EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
+NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
+REGARDING THE APPPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION
+WITH YOUR PRODUCTS.
+
+IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR DISTRIBUTION OF THE
+APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
+(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function AppleButton(button, text, height,
+ imgLeft, imgLeftClicked, imgLeftWidth,
+ imgMiddle, imgMiddleClicked,
+ imgRight, imgRightClicked, imgRightWidth,
+ onclick)
+{
+ if (button == null)
+ return;
+
+ /* Objects */
+ this.textElement = null;
+
+ /* Read-write properties */
+ this.onclick = onclick;
+
+ /* Read-only properties */
+ this.enabled = true;
+
+
+ this._init(button, text, height,
+ imgLeft, imgLeftClicked, imgLeftWidth,
+ imgMiddle, imgMiddleClicked,
+ imgRight, imgRightClicked, imgRightWidth);
+
+ this.textElement.innerHTML = text;
+}
+
+AppleButton.prototype._init = function(button, text, height,
+ imgLeft, imgLeftClicked, imgLeftWidth,
+ imgMiddle, imgMiddleClicked,
+ imgRight, imgRightClicked, imgRightWidth)
+{
+ this._imgLeftPath = imgLeft;
+ this._imgLeftClickedPath = imgLeftClicked;
+ this._imgMiddlePath = imgMiddle;
+ this._imgMiddleClickedPath = imgMiddleClicked;
+ this._imgRightPath = imgRight;
+ this._imgRightClickedPath = imgRightClicked;
+
+ var container = document.createElement("div");
+ this._container = container;
+
+ button.appendChild(container);
+
+ // For JavaScript event handlers
+ var _self = this;
+ this._mousedownHandler = function(event) { _self._mousedown(event); }
+ this._mousemoveHandler = function(event)
+ {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+ this._mouseoverHandler = function(event) { _self._mouseover(event); }
+ this._mouseoutHandler = function(event) { _self._mouseout(event); }
+ this._mouseupHandler = function(event) { _self._mouseup(event); }
+
+ // Create the inner elements
+ var element = document.createElement("div");
+ var style = element.style;
+ style.display = "inline-block";
+ style.verticalAlign = "bottom";
+ style.background = "url(" + this._imgLeftPath + ") no-repeat top left";
+ style.height = height + "px";
+ style.width = imgLeftWidth + "px";
+ container.appendChild(element);
+
+ element = document.createElement("div");
+ element.innerText = text;
+ style = element.style;
+ style.display = "inline-block";
+ style.verticalAlign = "bottom";
+ style.backgroundRepeat = "repeat-x";
+ style.backgroundImage = "url(" + this._imgMiddlePath + ")";
+ style.lineHeight = height + "px";
+ style.height = height + "px";
+ style.overflow = "hidden";
+ style.whiteSpace = "nowrap";
+
+ container.appendChild(element);
+ this.textElement = element;
+
+ element = document.createElement("div");
+ style = element.style;
+ style.display = "inline-block";
+ style.verticalAlign = "bottom";
+ style.background = "url(" + this._imgRightPath + ") no-repeat top left";
+ style.height = height + "px";
+ style.width = imgRightWidth + "px";
+ container.appendChild(element);
+ style = container.style;
+ style.appleDashboardRegion = "dashboard-region(control rectangle)";
+ style.height = height + "px";
+
+ // preload clicked images
+ var img = new Image(imgLeftWidth, height);
+ img.src = this._imgLeftClickedPath;
+ img = new Image();
+ img.src = this._imgMiddleClickedPath;
+ img = new Image(imgRightWidth, height);
+ img.src = this._imgRightClickedPath;
+
+ container.addEventListener("mousedown", this._mousedownHandler, true);
+}
+
+AppleButton.prototype.remove = function()
+{
+ var parent = this._container.parentNode;
+ parent.removeChild(this._container);
+}
+
+AppleButton.prototype.setDisabledImages = function(imgLeftDisabled, imgMiddleDisabled, imgRightDisabled)
+{
+ this._imgLeftDisabledPath = imgLeftDisabled;
+ this._imgMiddleDisabledPath = imgMiddleDisabled;
+ this._imgRightDisabledPath = imgRightDisabled;
+}
+
+AppleButton.prototype.setEnabled = function(enabled)
+{
+ this.enabled = enabled;
+ if (enabled)
+ {
+ this._container.children[0].style.backgroundImage = "url(" + this._imgLeftPath + ")";
+ this._container.children[1].style.backgroundImage = "url(" + this._imgMiddlePath + ")";
+ this._container.children[2].style.backgroundImage = "url(" + this._imgRightPath + ")";
+ this._container.style.appleDashboardRegion = "dashboard-region(control rectangle)";
+ }
+ else if (this._imgLeftDisabledPath !== undefined)
+ {
+ this._container.children[0].style.backgroundImage = "url(" + this._imgLeftDisabledPath + ")";
+ this._container.children[1].style.backgroundImage = "url(" + this._imgMiddleDisabledPath + ")";
+ this._container.children[2].style.backgroundImage = "url(" + this._imgRightDisabledPath + ")";
+ this._container.style.appleDashboardRegion = "none";
+ }
+}
+
+
+/*********************
+* Private handlers
+*/
+
+AppleButton.prototype._setPressed = function(pressed)
+{
+ if (pressed)
+ {
+ this._container.children[0].style.backgroundImage = "url(" + this._imgLeftClickedPath + ")";
+ this._container.children[1].style.backgroundImage = "url(" + this._imgMiddleClickedPath + ")";
+ this._container.children[2].style.backgroundImage = "url(" + this._imgRightClickedPath + ")";
+ }
+ else
+ {
+ this._container.children[0].style.backgroundImage = "url(" + this._imgLeftPath + ")";
+ this._container.children[1].style.backgroundImage = "url(" + this._imgMiddlePath + ")";
+ this._container.children[2].style.backgroundImage = "url(" + this._imgRightPath + ")";
+ }
+}
+
+AppleButton.prototype._mousedown = function(event)
+{
+ // If we're disabled, don't do anything
+ if (!this.enabled)
+ {
+ event.stopPropagation();
+ event.preventDefault();
+ return;
+ }
+
+ // Change images to clicked state
+ this._setPressed(true);
+
+ // add temp event listeners
+ document.addEventListener("mousemove", this._mousemoveHandler, true);
+ document.addEventListener("mouseup", this._mouseupHandler, true);
+ this._container.addEventListener("mouseover", this._mouseoverHandler, true);
+ this._container.addEventListener("mouseout", this._mouseoutHandler, true);
+
+ this._inside = true;
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleButton.prototype._mouseover = function(event)
+{
+ // Change images to clicked state
+ this._setPressed(true);
+
+ this._inside = true;
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleButton.prototype._mouseout = function(event)
+{
+ // Change images to regular state
+ this._setPressed(false);
+
+ this._inside = false;
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleButton.prototype._mouseup = function(event)
+{
+ // Change images to regular state
+ this._setPressed(false);
+
+ // Remove temp event listeners
+ document.removeEventListener("mousemove", this._mousemoveHandler, true);
+ document.removeEventListener("mouseup", this._mouseupHandler, true);
+ this._container.removeEventListener("mouseover", this._mouseoverHandler, true);
+ this._container.removeEventListener("mouseout", this._mouseoutHandler, true);
+
+ // Perform callback if we're inside the button
+ try {
+ if (this._inside && this.onclick != null)
+ this.onclick(event);
+ } catch(ex) {
+ throw ex;
+ } finally {
+ event.stopPropagation();
+ event.preventDefault();
+ delete this._inside;
+ }
+}
+
+//
+// AppleGlassButton class
+//
+
+function AppleGlassButton(button, text, onclick)
+{
+ /* Objects */
+ this.textElement = null;
+
+ /* Read-write properties */
+ this.onclick = onclick;
+
+ /* Read-only properties */
+ this.enabled = true;
+
+ this._init(button, text, 23,
+ "file:///System/Library/WidgetResources/button/glassbuttonleft.png",
+ "file:///System/Library/WidgetResources/button/glassbuttonleftclicked.png",
+ 10,
+ "file:///System/Library/WidgetResources/button/glassbuttonmiddle.png",
+ "file:///System/Library/WidgetResources/button/glassbuttonmiddleclicked.png",
+ "file:///System/Library/WidgetResources/button/glassbuttonright.png",
+ "file:///System/Library/WidgetResources/button/glassbuttonrightclicked.png",
+ 10);
+
+ var style = this.textElement.style;
+ style.fontSize = "12px";
+ style.fontFamily = "Helvetica Neue";
+ style.color = "white";
+ style.fontWeight = "bold";
+}
+
+// Inherit from AppleButton
+AppleGlassButton.prototype = new AppleButton(null);
+
+// Override regular disabled functionality
+AppleGlassButton.prototype.setEnabled = function(enabled)
+{
+ this.enabled = enabled;
+ if (enabled)
+ {
+ this._container.children[1].style.color = "white";
+ this._container.style.appleDashboardRegion = "dashboard-region(control rectangle)";
+ }
+ else
+ {
+ this._container.children[1].style.color = "rgb(150,150,150)";
+ this._container.style.appleDashboardRegion = "none";
+ }
+}
View
245 AppleClasses/AppleInfoButton.js
@@ -0,0 +1,245 @@
+/*
+© Copyright 2007 Apple Inc. All rights reserved.
+
+IMPORTANT: This Apple software and the associated images located in
+/System/Library/WidgetResources/AppleClasses/ (collectively "Apple Software")
+are supplied to you by Apple Computer, Inc. (“Apple”) in consideration of your
+agreement to the following terms. Your use, installation and/or redistribution
+of this Apple Software constitutes acceptance of these terms. If you do not
+agree with these terms, please do not use, install, or redistribute this Apple
+Software.
+
+In consideration of your agreement to abide by the following terms, and subject
+to these terms, Apple grants you a personal, non-exclusive license, under
+Apple’s copyrights in the Apple Software, to use, reproduce, and redistribute
+the Apple Software, in text form (for JavaScript files) or binary form (for
+associated images), for the sole purpose of creating Dashboard widgets for Mac
+OS X.
+
+If you redistribute the Apple Software, you must retain this entire notice and
+the warranty disclaimers and limitation of liability provisions (last two
+paragraphs below) in all such redistributions of the Apple Software.
+
+You may not use the name, trademarks, service marks or logos of Apple to endorse
+or promote products that include the Apple Software without the prior written
+permission of Apple. Except as expressly stated in this notice, no other rights
+or licenses, express or implied, are granted by Apple herein, including but not
+limited to any patent rights that may be infringed by your products that
+incorporate the Apple Software or by other works in which the Apple Software may
+be incorporated.
+
+The Apple Software is provided on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
+EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
+NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
+REGARDING THE APPPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION
+WITH YOUR PRODUCTS.
+
+IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR DISTRIBUTION OF THE
+APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
+(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function AppleInfoButton(flipper, front, foregroundStyle, backgroundStyle, onclick)
+{
+ /* Read-write properties */
+ this.onclick = onclick;
+
+ /* Internal */
+ this._front = front;
+ this._flipper = flipper;
+ this._flipLabel = document.createElement("img");
+ this._flipLabel.width = 13;
+ this._flipLabel.height = 13;
+ this._flipLabel.setAttribute("alt", "Info");
+ this._flipCircle = document.createElement("div");
+ flipper.appendChild(this._flipCircle);
+ flipper.appendChild(this._flipLabel);
+ this._labelshown = false;
+
+ // For JavaScript event handlers
+ var _self = this;
+
+ this._updateOpacity = function(animation, now, first, done)
+ {
+ _self._flipLabel.style.opacity = now;
+ }
+
+ this._animationComplete = function()
+ {
+ delete _self._animation;
+ delete _self._animator;
+ }
+
+ this._frontMove = function(event)
+ {
+ if (_self._outdelay !== undefined)
+ {
+ clearTimeout(_self._outdelay);
+ delete _self._outdelay;
+ }
+ if (_self._labelshown)
+ return;
+
+ var from = 0.0;
+ var duration = 500;
+ if (_self._animation !== undefined)
+ {
+ from = _self._animation.now;
+ duration = (new Date).getTime() - _self._animator.startTime;
+ _self._animator.stop();
+ }
+
+ _self._labelshown = true;
+
+ var animator = new AppleAnimator(duration, 13);
+ animator.oncomplete = _self._animationComplete;
+ _self._animator = animator;
+
+ _self._animation = new AppleAnimation(from, 1.0, _self._updateOpacity);
+ animator.addAnimation(_self._animation);
+ animator.start();
+ }
+
+ this._frontOutDelay = function(event)
+ {
+ if (_self._outdelay === undefined)
+ {
+ _self._outdelay = setTimeout(_self._frontOut, 0, _self);
+ }
+ }
+
+ this._frontOut = function(_self)
+ {
+ if (_self._outdelay !== undefined)
+ {
+ clearTimeout(_self._outdelay);
+ delete _self._outdelay;
+ }
+ if (!_self._labelshown)
+ return;
+
+ var from = 1.0;
+ var duration = 500;
+ if (_self._animation !== undefined)
+ {
+ from = _self._animation.now;
+ duration = (new Date).getTime() - _self._animator.startTime;
+ _self._animator.stop();
+ }
+
+ var animator = new AppleAnimator(duration, 13);
+ animator.oncomplete = _self._animationComplete;
+ _self._animator = animator;
+
+ _self._animation = new AppleAnimation(from, 0.0, _self._updateOpacity);
+ animator.addAnimation(_self._animation);
+ animator.start();
+
+ _self._labelshown = false;
+ }
+
+ this._labelOver = function(event)
+ {
+ _self._tempMouseOver = true; // remove later
+ _self._flipCircle.style.visibility = "visible";
+ }
+
+ this._labelOut = function(event)
+ {
+ delete _self._tempMouseOver; // remove later
+ _self._flipCircle.style.visibility = "hidden";
+ }
+
+ this._labelClicked = function(event)
+ {
+ _self._flipCircle.style.visibility = "hidden";
+
+ try {
+ if (_self.onclick != null)
+ _self.onclick(event);
+ } catch(ex) {
+ throw ex;
+ } finally {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+ }
+
+ this._tempLabelDown = function(event)
+ {
+ document.addEventListener("mouseup", _self._tempDocUp, true);
+ event.stopPropagation();
+ event.preventDefault();
+ }
+
+ this._tempDocUp = function(event)
+ {
+ document.removeEventListener("mouseup", _self._tempDocUp, true);
+
+ // if we're over the label
+ if (_self._tempMouseOver !== undefined)
+ {
+ delete _self._tempMouseOver;
+ _self._labelClicked(event);
+ }
+ }
+
+ // Set up style
+ var style = this._flipLabel.style;
+ style.position = "absolute";
+ style.top = 0;
+ style.left = 0;
+ style.opacity = 0;
+
+ style = this._flipCircle.style;
+ style.position = "absolute";
+ style.top = 0;
+ style.left = 0;
+ style.width = "13px";
+ style.height = "13px";
+ this.setCircleOpacity(0.25);
+ style.visibility = "hidden";
+
+ this.setStyle(foregroundStyle, backgroundStyle);
+
+ this._front.addEventListener("mousemove", this._frontMove, true);
+ this._front.addEventListener("mouseout", this._frontOutDelay, true);
+
+// temp stuff
+ this._flipper.addEventListener("mousedown", this._tempLabelDown, true);
+ this._flipper.setAttribute("onclick", "event.stopPropagation(); event.preventDefault();");
+// switch to this later
+// this._flipper.addEventListener("click", this._labelClicked, true);
+ this._flipper.addEventListener("mouseover", this._labelOver, true);
+ this._flipper.addEventListener("mouseout", this._labelOut, true);
+}
+
+AppleInfoButton.prototype.remove = function()
+{
+ this._front.removeEventListener("mousemove", this._frontMove, true);
+ this._front.removeEventListener("mouseout", this._frontOutDelay, true);
+
+ this._flipper.removeEventListener("mousedown", this._tempLabelDown, true);
+// this._flipper.removeEventListener("click", this._labelClicked, true);
+ this._flipper.removeEventListener("mouseover", this._labelOver, true);
+ this._flipper.removeEventListener("mouseout", this._labelOut, true);
+
+ var parent = this._flipLabel.parentNode;
+ parent.removeChild(this._flipCircle);
+ parent.removeChild(this._flipLabel);
+}
+
+AppleInfoButton.prototype.setStyle = function(foregroundStyle, backgroundStyle)
+{
+ this._flipLabel.src = "file:///System/Library/WidgetResources/ibutton/" + foregroundStyle + "_i.png";
+ this._flipCircle.style.background = "url(file:///System/Library/WidgetResources/ibutton/" + backgroundStyle + "_rollie.png) no-repeat top left";
+}
+
+AppleInfoButton.prototype.setCircleOpacity = function(opacity)
+{
+ this._flipCircle.style.opacity = opacity;
+}
View
346 AppleClasses/AppleScrollArea.js
@@ -0,0 +1,346 @@
+/*
+© Copyright 2007 Apple Inc. All rights reserved.
+
+IMPORTANT: This Apple software and the associated images located in
+/System/Library/WidgetResources/AppleClasses/ (collectively "Apple Software")
+are supplied to you by Apple Computer, Inc. (“Apple”) in consideration of your
+agreement to the following terms. Your use, installation and/or redistribution
+of this Apple Software constitutes acceptance of these terms. If you do not
+agree with these terms, please do not use, install, or redistribute this Apple
+Software.
+
+In consideration of your agreement to abide by the following terms, and subject
+to these terms, Apple grants you a personal, non-exclusive license, under
+Apple’s copyrights in the Apple Software, to use, reproduce, and redistribute
+the Apple Software, in text form (for JavaScript files) or binary form (for
+associated images), for the sole purpose of creating Dashboard widgets for Mac
+OS X.
+
+If you redistribute the Apple Software, you must retain this entire notice and
+the warranty disclaimers and limitation of liability provisions (last two
+paragraphs below) in all such redistributions of the Apple Software.
+
+You may not use the name, trademarks, service marks or logos of Apple to endorse
+or promote products that include the Apple Software without the prior written
+permission of Apple. Except as expressly stated in this notice, no other rights
+or licenses, express or implied, are granted by Apple herein, including but not
+limited to any patent rights that may be infringed by your products that
+incorporate the Apple Software or by other works in which the Apple Software may
+be incorporated.
+
+The Apple Software is provided on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
+EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
+NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
+REGARDING THE APPPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION
+WITH YOUR PRODUCTS.
+
+IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR DISTRIBUTION OF THE
+APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
+(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * AppleScrollArea Constructor
+ * content is the element containing the display to be scrolled.
+ * Any additional arguments will be added as scrollbars using this.addScrollbar.
+ */
+function AppleScrollArea(content)
+{
+ /* Objects */
+ this.content = content;
+
+ /* public properties */
+ // These are read-write. Set them as needed.
+ this.scrollsVertically = true;
+ this.scrollsHorizontally = true;
+ this.singlepressScrollPixels = 10;
+
+ // These are read-only.
+ this.viewHeight = 0;
+ this.viewToContentHeightRatio = 1.0;
+ this.viewWidth = 0;
+ this.viewToContentWidthRatio = 1.0;
+
+ /* Internal Objects */
+ this._scrollbars = new Array();
+
+ // For JavaScript event handlers
+ var _self = this;
+
+ /*
+ * Privileged methods
+ * These event handlers need to be here because within an event handler,
+ * "this" refers to the element which called the event, rather than the
+ * class instance.
+ */
+ this._refreshHandler = function() { _self.refresh(); };
+ this._keyPressedHandler = function() { _self.keyPressed(event); };
+ this._mousewheelScrollHandler = function(event) { _self.mousewheelScroll(event); };
+
+ // Set up the style for the content element just to be certain
+ this.content.style.overflow = "hidden";
+ this.content.scrollTop = 0;
+ this.content.scrollLeft = 0;
+
+ // Add event listeners
+ this.content.addEventListener("mousewheel", this._mousewheelScrollHandler, true);
+
+ this.refresh();
+
+ // Add any scrollbars
+ var c = arguments.length;
+ for (var i = 1; i < c; ++i)
+ {
+ this.addScrollbar(arguments[i]);
+ }
+}
+
+AppleScrollArea.prototype.addScrollbar = function(scrollbar)
+{
+ scrollbar.setScrollArea(this);
+ this._scrollbars.push(scrollbar);
+ scrollbar.refresh();
+}
+
+AppleScrollArea.prototype.removeScrollbar = function(scrollbar)
+{
+ var scrollbars = this._scrollbars;
+ var c = scrollbars.length;
+ for (var i = 0; i < c; ++i)
+ {
+ if (scrollbars[i] == scrollbar)
+ {
+ scrollbars.splice(i, 1);
+ break;
+ }
+ }
+}
+
+AppleScrollArea.prototype.remove = function()
+{
+ this.content.removeEventListener("mousewheel", this._mousewheelScrollHandler, true);
+
+ var scrollbars = this._scrollbars;
+ var c = scrollbars.length;
+ for (var i = 0; i < c; ++i)
+ {
+ scrollbars[i].setScrollArea(null);
+ }
+}
+
+/*
+ * refresh() member function
+ * Refresh the current scrollbar position and size.
+ * This should be called whenever the content element changes.
+ */
+AppleScrollArea.prototype.refresh = function()
+{
+ // get the current actual view height. Float because we divide.
+ var style = document.defaultView.getComputedStyle(this.content, '');
+ if (style)
+ {
+ this.viewHeight = parseFloat(style.getPropertyValue("height"));
+ this.viewWidth = parseFloat(style.getPropertyValue("width"));
+ }
+ else
+ {
+ this.viewHeight = 0;
+ this.viewWidth = 0;
+ }
+
+
+ if (this.content.scrollHeight > this.viewHeight)
+ {
+ this.viewToContentHeightRatio = this.viewHeight / this.content.scrollHeight;
+ this.verticalScrollTo(this.content.scrollTop);
+ }
+ else
+ {
+ this.viewToContentHeightRatio = 1.0;
+ this.verticalScrollTo(0);
+ }
+
+ if (this.content.scrollWidth > this.viewWidth)
+ {
+ this.viewToContentWidthRatio = this.viewWidth / this.content.scrollWidth;
+ this.horizontalScrollTo(this.content.scrollLeft);
+ }
+ else
+ {
+ this.viewToContentWidthRatio = 1.0;
+ this.horizontalScrollTo(0);
+ }
+
+ var scrollbars = this._scrollbars;
+ var c = scrollbars.length;
+ for (var i = 0; i < c; ++i)
+ {
+ scrollbars[i].refresh();
+ }
+}
+
+/*
+ * focus() member function.
+ * Tell the scrollarea that it is in focus. It will capture keyPressed events
+ * and if they are arrow keys scroll accordingly.
+ */
+AppleScrollArea.prototype.focus = function()
+{
+ document.addEventListener("keypress", this._keyPressedHandler, true);
+}
+
+/*
+ * blur() member function.
+ * Tell the scrollarea that it is no longer in focus. It will cease capturing
+ * keypress events.
+ */
+AppleScrollArea.prototype.blur = function()
+{
+ document.removeEventListener("keypress", this._keyPressedHandler, true);
+}
+
+
+/*
+ * reveal(element) member function.
+ * Pass in an Element which is contained within the content element.
+ * The content will then be scrolled to reveal that element.
+ */
+AppleScrollArea.prototype.reveal = function(element)
+{
+ var offsetY = 0;
+ var obj = element;
+ do
+ {
+ offsetY += obj.offsetTop;
+ obj = obj.offsetParent;
+ } while (obj && obj != this.content);
+
+ var offsetX = 0;
+ obj = element;
+ do
+ {
+ offsetX += obj.offsetLeft;
+ obj = obj.offsetParent;
+ } while (obj && obj != this.content);
+
+ this.verticalScrollTo(offsetY);
+ this.horizontalScrollTo(offsetX);
+}
+
+
+AppleScrollArea.prototype.verticalScrollTo = function(new_content_top)
+{
+ if (!this.scrollsVertically)
+ return;
+
+ var bottom = this.content.scrollHeight - this.viewHeight;
+
+ if (new_content_top < 0)
+ {
+ new_content_top = 0;
+ }
+ else if (new_content_top > bottom)
+ {
+ new_content_top = bottom;
+ }
+
+ this.content.scrollTop = new_content_top;
+
+ var scrollbars = this._scrollbars;
+ var c = scrollbars.length;
+ for (var i = 0; i < c; ++i)
+ {
+ scrollbars[i].verticalHasScrolled();
+ }
+}
+
+AppleScrollArea.prototype.horizontalScrollTo = function(new_content_left)
+{
+ if (!this.scrollsHorizontally)
+ return;
+
+ var right = this.content_width - this.viewWidth;
+
+ if (new_content_left < 0)
+ {
+ new_content_left = 0;
+ }
+ else if (new_content_left > right)
+ {
+ new_content_left = right;
+ }
+
+ this.content.scrollLeft = new_content_left;
+
+ var scrollbars = this._scrollbars;
+ var c = scrollbars.length;
+ for (var i = 0; i < c; ++i)
+ {
+ scrollbars[i].horizontalHasScrolled();
+ }
+}
+
+/*********************
+ * Keypressed events
+ */
+AppleScrollArea.prototype.keyPressed = function(event)
+{
+ var handled = true;
+
+ if (event.altKey)
+ return;
+ if (event.shiftKey)
+ return;
+
+ switch (event.keyIdentifier)
+ {
+ case "Home":
+ this.verticalScrollTo(0);
+ break;
+ case "End":
+ this.verticalScrollTo(this.content.scrollHeight - this.viewHeight);
+ break;
+ case "Up":
+ this.verticalScrollTo(this.content.scrollTop - this.singlepressScrollPixels);
+ break;
+ case "Down":
+ this.verticalScrollTo(this.content.scrollTop + this.singlepressScrollPixels);
+ break;
+ case "PageUp":
+ this.verticalScrollTo(this.content.scrollTop - this.viewHeight);
+ break;
+ case "PageDown":
+ this.verticalScrollTo(this.content.scrollTop + this.viewHeight);
+ break;
+ case "Left":
+ this.horizontalScrollTo(this.content.scrollLeft - this.singlepressScrollPixels);
+ break;
+ case "Right":
+ this.horizontalScrollTo(this.content.scrollLeft + this.singlepressScrollPixels);
+ break;
+ default:
+ handled = false;
+ }
+
+ if (handled)
+ {
+ event.stopPropagation();
+ event.preventDefault();
+ }
+}
+
+/*********************
+ * Scrollwheel events
+ */
+AppleScrollArea.prototype.mousewheelScroll = function(event)
+{
+ var deltaScroll = event.wheelDelta / 120 * this.singlepressScrollPixels;
+ this.verticalScrollTo(this.content.scrollTop - deltaScroll);
+
+ event.stopPropagation();
+ event.preventDefault();
+}
View
776 AppleClasses/AppleScrollbar.js
@@ -0,0 +1,776 @@
+/*
+© Copyright 2007 Apple Inc. All rights reserved.
+
+IMPORTANT: This Apple software and the associated images located in
+/System/Library/WidgetResources/AppleClasses/ (collectively "Apple Software")
+are supplied to you by Apple Computer, Inc. (“Apple”) in consideration of your
+agreement to the following terms. Your use, installation and/or redistribution
+of this Apple Software constitutes acceptance of these terms. If you do not
+agree with these terms, please do not use, install, or redistribute this Apple
+Software.
+
+In consideration of your agreement to abide by the following terms, and subject
+to these terms, Apple grants you a personal, non-exclusive license, under
+Apple’s copyrights in the Apple Software, to use, reproduce, and redistribute
+the Apple Software, in text form (for JavaScript files) or binary form (for
+associated images), for the sole purpose of creating Dashboard widgets for Mac
+OS X.
+
+If you redistribute the Apple Software, you must retain this entire notice and
+the warranty disclaimers and limitation of liability provisions (last two
+paragraphs below) in all such redistributions of the Apple Software.
+
+You may not use the name, trademarks, service marks or logos of Apple to endorse
+or promote products that include the Apple Software without the prior written
+permission of Apple. Except as expressly stated in this notice, no other rights
+or licenses, express or implied, are granted by Apple herein, including but not
+limited to any patent rights that may be infringed by your products that
+incorporate the Apple Software or by other works in which the Apple Software may
+be incorporated.
+
+The Apple Software is provided on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
+EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
+NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
+REGARDING THE APPPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION
+WITH YOUR PRODUCTS.
+
+IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR DISTRIBUTION OF THE
+APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
+(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function AppleScrollbar(scrollbar)
+{
+}
+
+/*
+ * _init() member function
+ * Initialize the scrollbar.
+ * pre: this.scrollbar
+ * post: this._thumb, this._track + event handlers
+ */
+AppleScrollbar.prototype._init = function()
+{
+ var style = null;
+ var element = null;
+
+ // Scrollbar Track
+ this._track = document.createElement("div");
+ style = this._track.style;
+ // fill our containing div
+ style.height = "100%";
+ style.width = "100%";
+ this.scrollbar.appendChild(this._track);
+
+ // Scrollbar Track Top
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._setObjectStart(element, 0);
+ this._track.appendChild(element);
+
+ // Scrollbar Track Middle
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._track.appendChild(element);
+
+ // Scrollbar Track Bottom
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._setObjectEnd(element, 0);
+ this._track.appendChild(element);
+
+ // Scrollbar Thumb
+ this._thumb = document.createElement("div");
+ style = this._thumb.style;
+ style.position = "absolute";
+ this._setObjectSize(this._thumb, this.minThumbSize); // default size
+ this._track.appendChild(this._thumb);
+
+ // Scrollbar Thumb Top
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._setObjectStart(element, 0);
+ this._thumb.appendChild(element);
+
+ // Scrollbar Thumb Middle
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._thumb.appendChild(element);
+
+ // Scrollbar Thumb Bottom
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._setObjectEnd(element, 0);
+ this._thumb.appendChild(element);
+
+ // Set up styles
+ this.setSize(this.size);
+
+ this.setTrackStart(this.trackStartPath, this.trackStartLength);
+ this.setTrackMiddle(this.trackMiddlePath);
+ this.setTrackEnd(this.trackEndPath, this.trackEndLength);
+ this.setThumbStart(this.thumbStartPath, this.thumbStartLength);
+ this.setThumbMiddle(this.thumbMiddlePath);
+ this.setThumbEnd(this.thumbEndPath, this.thumbEndLength);
+
+ // hide the thumb until we refresh
+ this._thumb.style.display = "none";
+
+ // Add event listeners
+ this._track.addEventListener("mousedown", this._mousedownTrackHandler, false);
+ this._thumb.addEventListener("mousedown", this._mousedownThumbHandler, false);
+
+ // ScrollArea will fire a refresh for us
+}
+
+AppleScrollbar.prototype.remove = function()
+{
+ this.scrollbar.removeChild(this._track);
+}
+
+// Capture events that we don't handle but also don't want getting through
+AppleScrollbar.prototype._captureEvent = function(event)
+{
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+/*********************
+ * Thumb scroll events
+ */
+AppleScrollbar.prototype._mousedownThumb = function(event)
+{
+ // temporary event listeners
+ document.addEventListener("mousemove", this._mousemoveThumbHandler, true);
+ document.addEventListener("mouseup", this._mouseupThumbHandler, true);
+ document.addEventListener("mouseover", this._captureEventHandler, true);
+ document.addEventListener("mouseout", this._captureEventHandler, true);
+
+ this._thumbStart_temp = this._getMousePosition(event);
+
+ this._scroll_thumbStartPos = this._getThumbStartPos();
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleScrollbar.prototype._mousemoveThumb = function(event)
+{
+ var delta = this._getMousePosition(event) - this._thumbStart_temp;
+
+ var new_pos = this._scroll_thumbStartPos + delta;
+ this.scrollTo(this._contentPositionForThumbPosition(new_pos));
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleScrollbar.prototype._mouseupThumb = function(event)
+{
+ // remove temporary event handlers
+ document.removeEventListener("mousemove", this._mousemoveThumbHandler, true);
+ document.removeEventListener("mouseup", this._mouseupThumbHandler, true);
+ document.removeEventListener("mouseover", this._captureEventHandler, true);
+ document.removeEventListener("mouseout", this._captureEventHandler, true);
+
+ // remove temporary properties
+ delete this._thumbStart_temp;
+ delete this._scroll_thumbStartPos;
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+/*********************
+ * Track scroll events
+ */
+AppleScrollbar.prototype._mousedownTrack = function(event)
+{
+ this._track_mouse_temp = this._getMousePosition(event) - this._trackOffset;
+
+ if (event.altKey)
+ {
+ this.scrollTo(this._contentPositionForThumbPosition(this._track_mouse_temp - (this._thumbLength / 2)));
+ delete this._track_mouse_temp;
+ }
+ else
+ {
+ this._track_scrolling = true;
+
+ // temporary event handlers
+ this._track.addEventListener("mousemove", this._mousemoveTrackHandler, true);
+ this._track.addEventListener("mouseover", this._mouseoverTrackHandler, true);
+ this._track.addEventListener("mouseout", this._mouseoutTrackHandler, true);
+ document.addEventListener("mouseup", this._mouseupTrackHandler, true);
+
+ this._trackScrollOnePage(this);
+ this._track_timer = setInterval(this._trackScrollDelay, 500, this);
+ }
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleScrollbar.prototype._trackScrollDelay = function(self)
+{
+ if (!self._track_scrolling) return;
+
+ clearInterval(self._track_timer);
+
+ self._trackScrollOnePage(self);
+ self._track_timer = setInterval(self._trackScrollOnePage, 150, self);
+}
+
+AppleScrollbar.prototype._mousemoveTrack = function(event)
+{
+ this._track_mouse_temp = this._getMousePosition(event) - this._trackOffset;
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleScrollbar.prototype._mouseoverTrack = function(event)
+{
+ this._track_mouse_temp = this._getMousePosition(event) - this._trackOffset;
+ this._track_scrolling = true;
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleScrollbar.prototype._mouseoutTrack = function(event)
+{
+ this._track_scrolling = false;
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleScrollbar.prototype._mouseupTrack = function(event)
+{
+ clearInterval(this._track_timer);
+
+ // clear temporary event handlers
+ this._track.removeEventListener("mousemove", this._mousemoveTrackHandler, true);
+ this._track.removeEventListener("mouseover", this._mouseoverTrackHandler, true);
+ this._track.removeEventListener("mouseout", this._mouseoutTrackHandler, true);
+ document.removeEventListener("mouseup", this._mouseupTrackHandler, true);
+
+ // remove temporary properties
+ delete this._track_mouse_temp;
+ delete this._track_scrolling;
+ delete this._track_timer;
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleScrollbar.prototype._trackScrollOnePage = function(self)
+{
+ // this is called from setInterval, so we need a ptr to this
+
+ if (!self._track_scrolling) return;
+
+ var deltaScroll = Math.round(self._trackLength * self._getViewToContentRatio());
+
+ if (self._track_mouse_temp < self._thumbStart)
+ self.scrollByThumbDelta(-deltaScroll);
+ else if (self._track_mouse_temp > (self._thumbStart + self._thumbLength))
+ self.scrollByThumbDelta(deltaScroll);
+}
+
+/*
+ * setScrollArea(scrollarea)
+ * Sets the AppleScrollArea this scrollbar is using.
+ */
+AppleScrollbar.prototype.setScrollArea = function(scrollarea)
+{
+ // if we already have a scrollarea, remove the mousewheel handler
+ if (this.scrollarea)
+ {
+ this.scrollbar.removeEventListener("mousewheel", this.scrollarea._mousewheelScrollHandler, true);
+ }
+
+ this.scrollarea = scrollarea;
+
+ // add mousewheel handler
+ this.scrollbar.addEventListener("mousewheel", this.scrollarea._mousewheelScrollHandler, true);
+}
+
+/*
+ * refresh()
+ * Refresh the scrollbar size and thumb position
+ */
+AppleScrollbar.prototype.refresh = function()
+{
+ this._trackOffset = this._computeTrackOffset();
+ this._trackLength = this._computeTrackLength();
+
+ var ratio = this._getViewToContentRatio();
+
+ if (ratio >= 1.0 || !this._canScroll())
+ {
+ if (this.autohide)
+ {
+ // hide the scrollbar, all content is visible
+ this.hide();
+ }
+
+ // hide the thumb
+ this._thumb.style.display = "none";
+ this.scrollbar.style.appleDashboardRegion = "none";
+ }
+ else
+ {
+ this._thumbLength = Math.max(Math.round(this._trackLength * ratio), this.minThumbSize);
+ this._numScrollablePixels = this._trackLength - this._thumbLength - (2 * this.padding);
+
+ this._setObjectLength(this._thumb, this._thumbLength);
+
+ // show the thumb
+ this._thumb.style.display = "block";
+ this.scrollbar.style.appleDashboardRegion = "dashboard-region(control rectangle)";
+
+ this.show();
+ }
+
+ // Make sure position is updated appropriately
+ this.verticalHasScrolled();
+ this.horizontalHasScrolled();
+}
+
+AppleScrollbar.prototype.setAutohide = function(autohide)
+{
+ this.autohide = autohide;
+
+ // hide the scrollbar if necessary
+ if (this._getViewToContentRatio() >= 1.0 && autohide)
+ {
+ this.hide();
+ }
+ else
+ {
+ this.show();
+ }
+}
+
+AppleScrollbar.prototype.hide = function()
+{
+ this._track.style.display = "none";
+ this.hidden = true;
+}
+
+AppleScrollbar.prototype.show = function()
+{
+ this._track.style.display = "block";
+ this.hidden = false;
+}
+
+AppleScrollbar.prototype.setSize = function(size)
+{
+ this.size = size;
+
+ this._setObjectSize(this.scrollbar, size);
+ this._setObjectSize(this._track.children[1], size);
+ this._setObjectSize(this._thumb.children[1], size);
+}
+
+AppleScrollbar.prototype.setTrackStart = function(imgpath, length)
+{
+ this.trackStartPath = imgpath;
+ this.trackStartLength = length;
+
+ var element = this._track.children[0];
+ element.style.background = "url(" + imgpath + ") no-repeat top left";
+ this._setObjectLength(element, length);
+ this._setObjectSize(element, this.size);
+ this._setObjectStart(this._track.children[1], length);
+}
+
+AppleScrollbar.prototype.setTrackMiddle = function(imgpath)
+{
+ this.trackMiddlePath = imgpath;
+
+ this._track.children[1].style.background = "url(" + imgpath + ") " + this._repeatType + " top left";
+}
+
+AppleScrollbar.prototype.setTrackEnd = function(imgpath, length)
+{
+ this.trackEndPath = imgpath;
+ this.trackEndLength = length;
+
+ var element = this._track.children[2];
+ element.style.background = "url(" + imgpath + ") no-repeat top left";
+ this._setObjectLength(element, length);
+ this._setObjectSize(element, this.size);
+ this._setObjectEnd(this._track.children[1], length);
+}
+
+AppleScrollbar.prototype.setThumbStart = function(imgpath, length)
+{
+ this.thumbStartPath = imgpath;
+ this.thumbStartLength = length;
+
+ var element = this._thumb.children[0];
+ element.style.background = "url(" + imgpath + ") no-repeat top left";
+ this._setObjectLength(element, length);
+ this._setObjectSize(element, this.size);
+ this._setObjectStart(this._thumb.children[1], length);
+}
+
+AppleScrollbar.prototype.setThumbMiddle = function(imgpath)
+{
+ this.thumbMiddlePath = imgpath;
+
+ this._thumb.children[1].style.background = "url(" + imgpath + ") " + this._repeatType + " top left";
+}
+
+AppleScrollbar.prototype.setThumbEnd = function(imgpath, length)
+{
+ this.thumbEndPath = imgpath;
+ this.thumbEndLength = length;
+
+ var element = this._thumb.children[2];
+ element.style.background = "url(" + imgpath + ") no-repeat top left";
+ this._setObjectLength(element, length);
+ this._setObjectSize(element, this.size);
+ this._setObjectEnd(this._thumb.children[1], length);
+}
+
+AppleScrollbar.prototype._contentPositionForThumbPosition = function(thumb_pos)
+{
+ // if we're currently displaying all content, we don't want it outside the view
+ if (this._getViewToContentRatio() >= 1.0)
+ {
+ return 0;
+ }
+ else
+ {
+ return (thumb_pos - this.padding) * ((this._getContentLength() - this._getViewLength()) / this._numScrollablePixels);
+ }
+}
+
+AppleScrollbar.prototype._thumbPositionForContentPosition = function(page_pos)
+{
+ // if we're currently displaying all content, we don't want it outside the view
+ if (this._getViewToContentRatio() >= 1.0)
+ {
+ return this.padding;
+ }
+ else
+ {
+ var result = this.padding - -(page_pos / ((this._getContentLength() - this._getViewLength()) / this._numScrollablePixels));
+ if (isNaN(result))
+ result = 0;
+ return result;
+ }
+}
+
+AppleScrollbar.prototype.scrollByThumbDelta = function(deltaScroll)
+{
+ if (deltaScroll == 0)
+ return;
+
+ this.scrollTo(this._contentPositionForThumbPosition(this._thumbStart + deltaScroll));
+}
+
+
+/*******************************************************************************
+ * AppleVerticalScrollbar
+ * Implementation of AppleScrollbar
+ *
+ *
+ */
+
+function AppleVerticalScrollbar(scrollbar)
+{
+ /* Objects */
+ this.scrollarea = null;
+ this.scrollbar = scrollbar;
+
+ /* public properties */
+ // These are read-write. Set them as needed.
+ this.minThumbSize = 28;
+ this.padding = -1;
+
+ // These are read-only. Use the setter functions to set them.
+ this.autohide = true;
+ this.hidden = true;
+ this.size = 19; // width
+ this.trackStartPath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_track_vtop.png";
+ this.trackStartLength = 18; // height
+ this.trackMiddlePath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_track_vmid.png";
+ this.trackEndPath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_track_vbottom.png";
+ this.trackEndLength = 18; // height
+ this.thumbStartPath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_thumb_vtop.png";
+ this.thumbStartLength = 9; // height
+ this.thumbMiddlePath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_thumb_vmid.png";
+ this.thumbEndPath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_thumb_vbottom.png";
+ this.thumbEndLength = 9; // height
+
+ /* Internal objects */
+ this._track = null;
+ this._thumb = null;
+
+ /* Dimensions */
+ // these only need to be set during refresh()
+ this._trackOffset = 0;
+ this._trackLength = 0;
+ this._numScrollablePixels = 0;
+ this._thumbLength = 0;
+ this._repeatType = "repeat-y";
+
+ // these change as the content is scrolled
+ this._thumbStart = this.padding;
+
+ // For JavaScript event handlers
+ var _self = this;
+
+ this._captureEventHandler = function(event) { _self._captureEvent(event); };
+ this._mousedownThumbHandler = function(event) { _self._mousedownThumb(event); };
+ this._mousemoveThumbHandler = function(event) { _self._mousemoveThumb(event); };
+ this._mouseupThumbHandler = function(event) { _self._mouseupThumb(event); };
+ this._mousedownTrackHandler = function(event) { _self._mousedownTrack(event); };
+ this._mousemoveTrackHandler = function(event) { _self._mousemoveTrack(event); };
+ this._mouseoverTrackHandler = function(event) { _self._mouseoverTrack(event); };
+ this._mouseoutTrackHandler = function(event) { _self._mouseoutTrack(event); };
+ this._mouseupTrackHandler = function(event) { _self._mouseupTrack(event); };
+
+ this._init();
+}
+
+// Inherit from AppleScrollbar
+AppleVerticalScrollbar.prototype = new AppleScrollbar(null);
+
+
+/*********************
+ * Orientation-specific functions.
+ * These helper functions return vertical values.
+ */
+AppleVerticalScrollbar.prototype.scrollTo = function(pos)
+{
+ this.scrollarea.verticalScrollTo(pos);
+}
+
+AppleVerticalScrollbar.prototype._setObjectSize = function(object, size)
+{ object.style.width = size + "px"; }
+
+AppleVerticalScrollbar.prototype._setObjectLength = function(object, length)
+{ object.style.height = length + "px"; }
+
+AppleVerticalScrollbar.prototype._setObjectStart = function(object, start)
+{ object.style.top = start + "px"; }
+
+AppleVerticalScrollbar.prototype._setObjectEnd = function(object, end)
+{ object.style.bottom = end + "px"; }
+
+AppleVerticalScrollbar.prototype._getMousePosition = function(event)
+{
+ if (event != undefined)
+ return event.y;
+ else
+ return 0;
+}
+
+AppleVerticalScrollbar.prototype._getThumbStartPos = function()
+{
+ return parseInt(document.defaultView.getComputedStyle(this._thumb, '').getPropertyValue("top"), 10);
+}
+
+AppleVerticalScrollbar.prototype._computeTrackOffset = function()
+{
+ // get the absolute top of the track
+ var obj = this.scrollbar;
+ var curtop = 0;
+ while (obj.offsetParent)
+ {
+ curtop += obj.offsetTop;
+ obj = obj.offsetParent;
+ }
+
+ return curtop;
+}
+
+AppleVerticalScrollbar.prototype._computeTrackLength = function()
+{
+ // get the current actual track height
+ var style = document.defaultView.getComputedStyle(this.scrollbar, '');
+ return style ? parseInt(style.getPropertyValue("height"), 10) : 0;
+}
+
+AppleVerticalScrollbar.prototype._getViewToContentRatio = function()
+{ return this.scrollarea.viewToContentHeightRatio; }
+
+AppleVerticalScrollbar.prototype._getContentLength = function()
+{ return this.scrollarea.content.scrollHeight; }
+
+AppleVerticalScrollbar.prototype._getViewLength = function()
+{ return this.scrollarea.viewHeight; }
+
+AppleVerticalScrollbar.prototype._canScroll = function()
+{ return this.scrollarea.scrollsVertically; }
+
+
+AppleVerticalScrollbar.prototype.verticalHasScrolled = function()
+{
+ var new_thumb_pos = this._thumbPositionForContentPosition(this.scrollarea.content.scrollTop);
+ this._thumbStart = new_thumb_pos;
+ this._thumb.style.top = new_thumb_pos + "px";
+}
+
+AppleVerticalScrollbar.prototype.horizontalHasScrolled = function()
+{
+}
+
+
+
+/*******************************************************************************
+* AppleHorizontalScrollbar
+* Implementation of AppleScrollbar
+*
+*
+*/
+
+function AppleHorizontalScrollbar(scrollbar)
+{
+ /* Objects */
+ this.scrollarea = null;
+ this.scrollbar = scrollbar;
+
+ /* public properties */
+ // These are read-write. Set them as needed.
+ this.minThumbSize = 28;
+ this.padding = -1;
+
+ // These are read-only. Use the setter functions to set them.
+ this.autohide = true;
+ this.hidden = true;
+ this.size = 19; // height
+ this.trackStartPath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_track_hleft.png";
+ this.trackStartLength = 18; // width
+ this.trackMiddlePath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_track_hmid.png";
+ this.trackEndPath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_track_hright.png";
+ this.trackEndLength = 18; // width
+ this.thumbStartPath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_thumb_hleft.png";
+ this.thumbStartLength = 9; // width
+ this.thumbMiddlePath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_thumb_hmid.png";
+ this.thumbEndPath = "file:///System/Library/WidgetResources/AppleClasses/Images/scroll_thumb_hright.png";
+ this.thumbEndLength = 9; // width
+
+ /* Internal objects */
+ this._track = null;
+ this._thumb = null;
+
+ /* Dimensions */
+ // these only need to be set during refresh()
+ this._trackOffset = 0;
+ this._trackLength = 0;
+ this._numScrollablePixels = 0;
+ this._thumbLength = 0;
+ this._repeatType = "repeat-x";
+
+ // these change as the content is scrolled
+ this._thumbStart = this.padding;
+
+ // For JavaScript event handlers
+ var _self = this;
+
+ this._captureEventHandler = function(event) { _self._captureEvent(event); };
+ this._mousedownThumbHandler = function(event) { _self._mousedownThumb(event); };
+ this._mousemoveThumbHandler = function(event) { _self._mousemoveThumb(event); };
+ this._mouseupThumbHandler = function(event) { _self._mouseupThumb(event); };
+ this._mousedownTrackHandler = function(event) { _self._mousedownTrack(event); };
+ this._mousemoveTrackHandler = function(event) { _self._mousemoveTrack(event); };
+ this._mouseoverTrackHandler = function(event) { _self._mouseoverTrack(event); };
+ this._mouseoutTrackHandler = function(event) { _self._mouseoutTrack(event); };
+ this._mouseupTrackHandler = function(event) { _self._mouseupTrack(event); };
+
+ this._init();
+}
+
+// Inherit from AppleScrollbar
+AppleHorizontalScrollbar.prototype = new AppleScrollbar(null);
+
+
+/*********************
+* Orientation-specific functions.
+* These helper functions return vertical values.
+*/
+AppleHorizontalScrollbar.prototype.scrollTo = function(pos)
+{
+ this.scrollarea.horizontalScrollTo(pos);
+}
+
+AppleHorizontalScrollbar.prototype._setObjectSize = function(object, size)
+{ object.style.height = size + "px"; }
+
+AppleHorizontalScrollbar.prototype._setObjectLength = function(object, length)
+{ object.style.width = length + "px"; }
+
+AppleHorizontalScrollbar.prototype._setObjectStart = function(object, start)
+{ object.style.left = start + "px"; }
+
+AppleHorizontalScrollbar.prototype._setObjectEnd = function(object, end)
+{ object.style.right = end + "px"; }
+
+AppleHorizontalScrollbar.prototype._getMousePosition = function(event)
+{
+ if (event != undefined)
+ return event.x;
+ else
+ return 0;
+}
+
+AppleHorizontalScrollbar.prototype._getThumbStartPos = function()
+{
+ return parseInt(document.defaultView.getComputedStyle(this._thumb, '').getPropertyValue("left"), 10);
+}
+
+AppleHorizontalScrollbar.prototype._computeTrackOffset = function()
+{
+ // get the absolute top of the track
+ var obj = this.scrollbar;
+ var curtop = 0;
+ while (obj.offsetParent)
+ {
+ curtop += obj.offsetLeft;
+ obj = obj.offsetParent;
+ }
+
+ return curtop;
+}
+
+AppleHorizontalScrollbar.prototype._computeTrackLength = function()
+{
+ // get the current actual track height
+ var style = document.defaultView.getComputedStyle(this.scrollbar, '');
+ return style ? parseInt(style.getPropertyValue("width"), 10) : 0;
+}
+
+AppleHorizontalScrollbar.prototype._getViewToContentRatio = function()
+{ return this.scrollarea.viewToContentWidthRatio; }
+
+AppleHorizontalScrollbar.prototype._getContentLength = function()
+{ return this.scrollarea.content.scrollWidth; }
+
+AppleHorizontalScrollbar.prototype._getViewLength = function()
+{ return this.scrollarea.viewWidth; }
+
+AppleHorizontalScrollbar.prototype._canScroll = function()
+{ return this.scrollarea.scrollsHorizontally; }
+
+
+AppleHorizontalScrollbar.prototype.verticalHasScrolled = function()
+{
+}
+
+AppleHorizontalScrollbar.prototype.horizontalHasScrolled = function()
+{
+ var new_thumb_pos = this._thumbPositionForContentPosition(this.scrollarea.content.scrollLeft);
+ this._thumbStart = new_thumb_pos;
+ this._thumb.style.left = new_thumb_pos + "px";
+}
View
477 AppleClasses/AppleSlider.js
@@ -0,0 +1,477 @@
+/*
+© Copyright 2007 Apple Inc. All rights reserved.
+
+IMPORTANT: This Apple software and the associated images located in
+/System/Library/WidgetResources/AppleClasses/ (collectively "Apple Software")
+are supplied to you by Apple Computer, Inc. (“Apple”) in consideration of your
+agreement to the following terms. Your use, installation and/or redistribution
+of this Apple Software constitutes acceptance of these terms. If you do not
+agree with these terms, please do not use, install, or redistribute this Apple
+Software.
+
+In consideration of your agreement to abide by the following terms, and subject
+to these terms, Apple grants you a personal, non-exclusive license, under
+Apple’s copyrights in the Apple Software, to use, reproduce, and redistribute
+the Apple Software, in text form (for JavaScript files) or binary form (for
+associated images), for the sole purpose of creating Dashboard widgets for Mac
+OS X.
+
+If you redistribute the Apple Software, you must retain this entire notice and
+the warranty disclaimers and limitation of liability provisions (last two
+paragraphs below) in all such redistributions of the Apple Software.
+
+You may not use the name, trademarks, service marks or logos of Apple to endorse
+or promote products that include the Apple Software without the prior written
+permission of Apple. Except as expressly stated in this notice, no other rights
+or licenses, express or implied, are granted by Apple herein, including but not
+limited to any patent rights that may be infringed by your products that
+incorporate the Apple Software or by other works in which the Apple Software may
+be incorporated.
+
+The Apple Software is provided on an "AS IS" basis. APPLE MAKES NO WARRANTIES,
+EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF
+NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
+REGARDING THE APPPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION
+WITH YOUR PRODUCTS.
+
+IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR DISTRIBUTION OF THE
+APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
+(INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+function AppleSlider(slider, onchanged)
+{
+}
+
+/*
+ * init() member function
+ * Initialize the slider.
+ * You do not need to call this directly, it will be called when necessary.
+ * You probably want to be calling refresh().
+ * pre: this.slider
+ * post: this._thumb, this._track + event handlers
+ */
+AppleSlider.prototype._init = function()
+{
+ // For JavaScript event handlers
+ var _self = this;
+
+ this._captureEventHandler = function(event) { _self._captureEvent(event); };
+ this._mousedownThumbHandler = function(event) { _self._mousedownThumb(event); };
+ this._mousemoveThumbHandler = function(event) { _self._mousemoveThumb(event); };
+ this._mouseupThumbHandler = function(event) { _self._mouseupThumb(event); };
+ this._mousedownTrackHandler = function(event) { _self._mousedownTrack(event); };
+
+ var style = null;
+ var element = null;
+
+ // Slider Track
+ this._track = document.createElement("div");
+ style = this._track.style;
+ // fill our containing div
+ style.height = "100%";
+ style.width = "100%";
+ this.slider.appendChild(this._track);
+
+ // Slider Track Left
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._setObjectStart(element, 0);
+ this._track.appendChild(element);
+
+ // Slider Track Middle
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._track.appendChild(element);
+
+ // Slider Track Right
+ element = document.createElement("div");
+ element.style.position = "absolute";
+ this._setObjectEnd(element, 0);
+ this._track.appendChild(element);
+
+ // Slider Thumb
+ this._thumb = document.createElement("div");
+ style = this._thumb.style;
+ style.position = "absolute";
+ this._track.appendChild(this._thumb);
+
+ this.setSize(this.size);
+ this.setTrackStart(this.trackStartPath, this.trackStartLength);
+ this.setTrackMiddle(this.trackMiddlePath);
+ this.setTrackEnd(this.trackEndPath, this.trackEndLength);
+ this.setThumb(this.thumbPath, this.thumbLength);
+
+ this.slider.style.appleDashboardRegion = "dashboard-region(control rectangle)";
+
+ // Add event listeners
+ this._track.addEventListener("mousedown", this._mousedownTrackHandler, true);
+ this._thumb.addEventListener("mousedown", this._mousedownThumbHandler, true);
+
+ this.refresh();
+}
+
+AppleSlider.prototype.remove = function()
+{
+ var parent = this._track.parentNode;
+ parent.removeChild(this._track);
+}
+
+/*
+ * refresh() member function
+ * Refresh the current slider position and size.
+ * Call this to make the slider appear after the widget has loaded and
+ * the AppleSlider object has been instantiated.
+ */
+AppleSlider.prototype.refresh = function()
+{
+ // get the scrollbar offset
+ this._trackOffset = this._computeTrackOffset();
+ this._sliderLength = this._computeSliderLength();
+
+ this._numScrollablePixels = this._sliderLength - this.thumbLength - (2 * this.padding);
+
+ this.slideTo(this._numScrollablePixels * this.value + this.padding);
+}
+
+AppleSlider.prototype.slideTo = function(newThumbPos)
+{
+ if (newThumbPos < this.padding)
+ {
+ newThumbPos = this.padding;
+ }
+ else if (newThumbPos > this._numScrollablePixels)
+ {
+ newThumbPos = this._numScrollablePixels;
+ }
+
+ this.value = (newThumbPos - this.padding) / (this._numScrollablePixels - this.padding);
+ this._setObjectStart(this._thumb, newThumbPos);
+
+ if (this.continuous && this.onchanged != null)
+ this.onchanged(this.value);
+}
+
+// Capture events that we don't handle but also don't want getting through
+AppleSlider.prototype._captureEvent = function(event)
+{
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+/*********************
+ * Thumb scroll events
+ */
+AppleSlider.prototype._mousedownThumb = function(event)
+{
+ // temporary event listeners
+ document.addEventListener("mousemove", this._mousemoveThumbHandler, true);
+ document.addEventListener("mouseup", this._mouseupThumbHandler, true);
+ document.addEventListener("mouseover", this._captureEventHandler, true);
+ document.addEventListener("mouseout", this._captureEventHandler, true);
+
+ this._thumbStartTemp = this._getMousePosition(event);
+
+ this._sliderThumbStartPos = this._getThumbStartPos();
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleSlider.prototype._mousemoveThumb = function(event)
+{
+ var delta = this._getMousePosition(event) - this._thumbStartTemp
+
+ var new_pos = this._sliderThumbStartPos + delta;
+ this.slideTo(new_pos);
+
+ event.stopPropagation();
+ event.preventDefault();
+}
+
+AppleSlider.prototype._mouseupThumb = function(event)
+{
+ document.removeEventListener("mousemove", this._mousemoveThumbHandler, true);
+ document.removeEventListener("mouseup", this._mouseupThumbHandler, true);
+ document.removeEventListener("mouseover", this._captureEventHandler, true);
+ document.removeEventListener("mouseout", this._captureEventHandler, true);
+
+ // reset the starting position
+ delete this._thumbStartTemp;
+ delete this._sliderThumbStartPos;
+
+ event.stopPropagation();
+ event.preventDefault();
+
+ // Fire our onchanged event now if they have discontinuous event firing
+ if (!this.continuous && this.onchanged != null)
+ this.onchanged(this.value);
+}
+
+/*********************
+ * Track scroll events
+ */
+AppleSlider.prototype._mousedownTrack = function(event)
+{
+ this._thumbStartTemp = this._getMousePosition(event);
+ this._sliderThumbStartPos = this._getMousePosition(event) - this._trackOffset - (this.thumbLength / 2);
+
+ // temporary event listeners
+ document.addEventListener("mousemove", this._mousemoveThumbHandler, true);
+ document.addEventListener("mouseup", this._mouseupThumbHandler, true);
+ document.addEventListener("mouseover", this._captureEventHandler, true);
+ document.addEventListener("mouseout", this._captureEventHandler, true);
+
+ this.slideTo(this._sliderThumbStartPos);
+}
+
+AppleSlider.prototype.setSize = function(size)
+{
+ this.size = size;
+
+ this._setObjectSize(this.slider, size);
+ this._setObjectSize(this._track.children[1], size);
+ this._setObjectSize(this._thumb, size);
+}
+
+AppleSlider.prototype.setTrackStart = function(imgpath, length)
+{
+ this.trackStartPath = imgpath;
+ this.trackStartLength = length;
+
+ var element = this._track.children[0];
+ element.style.background = "url(" + imgpath + ") no-repeat top left";
+ this._setObjectLength(element, length);
+ this._setObjectSize(element, this.size);
+ this._setObjectStart(this._track.children[1], length);
+}
+
+AppleSlider.prototype.setTrackMiddle = function(imgpath)
+{
+ this.trackMiddlePath = imgpath;
+
+ this._track.children[1].style.background = "url(" + imgpath + ") " + this._repeatType + " top left";
+}
+
+AppleSlider.prototype.setTrackEnd = function(imgpath, length)
+{
+ this.trackEndPath = imgpath;
+ this.trackEndLength = length;
+
+ var element = this._track.children[2];
+ element.style.background = "url(" + imgpath + ") no-repeat top left";
+ this._setObjectLength(element, length);
+ this._setObjectSize(element, this.size);
+ this._setObjectEnd(this._track.children[1], length);
+}
+
+AppleSlider.prototype.setThumb = function(imgpath, length)
+{
+ this.thumbPath = imgpath;
+ this.thumbLength = length;
+
+ this._thumb.style.background = "url(" + imgpath + ") no-repeat top left";
+ this._setObjectLength(this._thumb, length);
+}
+
+AppleSlider.prototype.setValue = function(newvalue)
+{
+ this.slideTo(this._numScrollablePixels * newvalue + this.padding);
+}
+
+/*******************************************************************************
+* AppleHorizontalSlider
+* Implementation of AppleSlider
+*
+*
+*/
+
+function AppleHorizontalSlider(slider, onchanged)
+{
+ /* Objects */
+ this.slider = slider;
+
+ /* public properties */
+ // These are read-write. Set them as needed.
+ this.onchanged = onchanged;
+ this.continuous = true; // Fire onchanged live, as opposed to onmouseup
+ this.padding = 0;
+
+ // These are read-only. Use the setter functions to set them.
+ this.value = 0.0;
+ this.size = 22;
+ this.trackStartPath = "file:///System/Library/WidgetResources/AppleClasses/Images/slide_track_hleft.png";
+ this.trackStartLength = 8;
+ this.trackMiddlePath = "file:///System/Library/WidgetResources/AppleClasses/Images/slide_track_hmid.png";
+ this.trackEndPath = "file:///System/Library/WidgetResources/AppleClasses/Images/slide_track_hright.png";
+ this.trackEndLength = 8;
+ this.thumbPath = "file:///System/Library/WidgetResources/AppleClasses/Images/slide_thumb.png";
+ this.thumbLength = 23;
+
+ /* Internal objects */
+ this._track = null;
+ this._thumb = null;
+
+ /* Dimensions */
+ // these only need to be set during refresh()
+ this._trackOffset = 0;
+ this._sliderLength = 0;
+ this._numScrollablePixels = 0;
+ this._repeatType = "repeat-x";
+
+ this._init();
+}
+
+// Inherit from AppleSlider
+AppleHorizontalSlider.prototype = new AppleSlider(null);
+
+/*********************
+ * Orientation-specific functions.
+ * These helper functions return vertical values.
+ */
+AppleHorizontalSlider.prototype._computeTrackOffset = function()
+{
+ // get the absolute left of the track
+ var obj = this.slider;
+ var curtop = 0;
+ while (obj.offsetParent)
+ {
+ curtop += obj.offsetLeft;
+ obj = obj.offsetParent;
+ }
+
+ return curtop;
+}
+
+AppleHorizontalSlider.prototype._computeSliderLength = function()
+{
+ // get the current actual slider length
+ var style = document.defaultView.getComputedStyle(this.slider, '');
+ return style ? parseInt(style.getPropertyValue("width"), 10) : 0;
+}
+
+AppleHorizontalSlider.prototype._setObjectSize = function(object, size)
+{ object.style.height = size + "px"; }
+
+AppleHorizontalSlider.prototype._setObjectLength = function(object, length)
+{ object.style.width = length + "px"; }
+
+AppleHorizontalSlider.prototype._setObjectStart = function(object, start)
+{ object.style.left = start + "px"; }
+
+AppleHorizontalSlider.prototype._setObjectEnd = function(object, end)
+{ object.style.right = end + "px"; }
+
+AppleHorizontalSlider.prototype._getMousePosition = function(event)
+{
+ if (event != undefined)
+ return event.x;
+ else
+ return 0;
+}
+
+AppleHorizontalSlider.prototype._getThumbStartPos = function()
+{
+ return parseInt(document.defaultView.getComputedStyle(this._thumb, '').getPropertyValue("left"), 10);
+}
+
+
+/*******************************************************************************