GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — javaScript/roundabout/js/jquery.roundabout.js at master · GaogaoHub/javaScript Expand file tree/ Copy pathjquery.roundabout.jsMore file actions 1156 lines (959 loc) · 32.3 KB / Copy pathjquery.roundabout.jsFile metadata and controls1156 lines (959 loc) · 32.3 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 (function($) { "use strict"; var defaults, internalData, methods; // add default shape $.extend({ roundaboutShapes: { def: "lazySusan", lazySusan: function (r, a, t) { return { x: Math.sin(r + a), y: (Math.sin(r + 3 * Math.PI / 2 + a) / 8) * t, z: (Math.cos(r + a) + 1) / 2, scale: (Math.sin(r + Math.PI / 2 + a) / 2) + 0.5 }; } } }); defaults = { bearing: 0.0, tilt: 0.0, minZ: 100, maxZ: 280, minOpacity: 0.4, maxOpacity: 1.0, minScale: 0.4, maxScale: 1.0, duration: 600, btnNext: null, btnNextCallback: function() {}, btnPrev: null, btnPrevCallback: function() {}, btnToggleAutoplay: null, btnStartAutoplay: null, btnStopAutoplay: null, easing: "swing", clickToFocus: true, clickToFocusCallback: function() {}, focusBearing: 0.0, shape: "lazySusan", debug: false, childSelector: "li", startingChild: null, reflect: false, floatComparisonThreshold: 0.001, autoplay: false, autoplayDuration: 1000, autoplayPauseOnHover: false, autoplayCallback: function() {}, autoplayInitialDelay: 0, enableDrag: false, dropDuration: 600, dropEasing: "swing", dropAnimateTo: "nearest", dropCallback: function() {}, dragAxis: "x", dragFactor: 4, triggerFocusEvents: true, triggerBlurEvents: true, responsive: false }; internalData = { autoplayInterval: null, autoplayIsRunning: false, autoplayStartTimeout: null, animating: false, childInFocus: -1, touchMoveStartPosition: null, stopAnimation: false, lastAnimationStep: false }; methods = { // starters // ----------------------------------------------------------------------- // init // starts up roundabout init: function(options, callback, relayout) { var settings, now = (new Date()).getTime(); options = (typeof options === "object") ? options : {}; callback = ($.isFunction(callback)) ? callback : function() {}; callback = ($.isFunction(options)) ? options : callback; settings = $.extend({}, defaults, options, internalData); return this .each(function() { // make options var self = $(this), childCount = self.children(settings.childSelector).length, period = 360.0 / childCount, startingChild = (settings.startingChild && settings.startingChild > (childCount - 1)) ? (childCount - 1) : settings.startingChild, startBearing = (settings.startingChild === null) ? settings.bearing : 360 - (startingChild * period), holderCSSPosition = (self.css("position") !== "static") ? self.css("position") : "relative"; self .css({ // starting styles padding: 0, position: holderCSSPosition }) .addClass("roundabout-holder") .data( // starting options "roundabout", $.extend( {}, settings, { startingChild: startingChild, bearing: startBearing, oppositeOfFocusBearing: methods.normalize.apply(null, [settings.focusBearing - 180]), dragBearing: startBearing, period: period } ) ); // unbind any events that we set if we're relaying out if (relayout) { self .unbind(".roundabout") .children(settings.childSelector) .unbind(".roundabout"); } else { // bind responsive action if (settings.responsive) { $(window).bind("resize", function() { methods.stopAutoplay.apply(self); methods.relayoutChildren.apply(self); }); } } // bind click-to-focus if (settings.clickToFocus) { self .children(settings.childSelector) .each(function(i) { $(this) .bind("click.roundabout", function() { var degrees = methods.getPlacement.apply(self, [i]); if (!methods.isInFocus.apply(self, [degrees])) { methods.stopAnimation.apply($(this)); if (!self.data("roundabout").animating) { methods.animateBearingToFocus.apply(self, [degrees, self.data("roundabout").clickToFocusCallback]); } return false; } }); }); } // bind next buttons if (settings.btnNext) { $(settings.btnNext) .bind("click.roundabout", function() { if (!self.data("roundabout").animating) { methods.animateToNextChild.apply(self, [self.data("roundabout").btnNextCallback]); } return false; }); } // bind previous buttons if (settings.btnPrev) { $(settings.btnPrev) .bind("click.roundabout", function() { methods.animateToPreviousChild.apply(self, [self.data("roundabout").btnPrevCallback]); return false; }); } // bind toggle autoplay buttons if (settings.btnToggleAutoplay) { $(settings.btnToggleAutoplay) .bind("click.roundabout", function() { methods.toggleAutoplay.apply(self); return false; }); } // bind start autoplay buttons if (settings.btnStartAutoplay) { $(settings.btnStartAutoplay) .bind("click.roundabout", function() { methods.startAutoplay.apply(self); return false; }); } // bind stop autoplay buttons if (settings.btnStopAutoplay) { $(settings.btnStopAutoplay) .bind("click.roundabout", function() { methods.stopAutoplay.apply(self); return false; }); } // autoplay pause on hover if (settings.autoplayPauseOnHover) { self .bind("mouseenter.roundabout.autoplay", function() { methods.stopAutoplay.apply(self, [true]); }) .bind("mouseleave.roundabout.autoplay", function() { methods.startAutoplay.apply(self); }); } // drag and drop if (settings.enableDrag) { // on screen if (!$.isFunction(self.drag)) { if (settings.debug) { alert("You do not have the drag plugin loaded."); } } else if (!$.isFunction(self.drop)) { if (settings.debug) { alert("You do not have the drop plugin loaded."); } } else { self .drag(function(e, properties) { var data = self.data("roundabout"), delta = (data.dragAxis.toLowerCase() === "x") ? "deltaX" : "deltaY"; methods.stopAnimation.apply(self); methods.setBearing.apply(self, [data.dragBearing + properties[delta] / data.dragFactor]); }) .drop(function(e) { var data = self.data("roundabout"), method = methods.getAnimateToMethod(data.dropAnimateTo); methods.allowAnimation.apply(self); methods[method].apply(self, [data.dropDuration, data.dropEasing, data.dropCallback]); data.dragBearing = data.period * methods.getNearestChild.apply(self); }); } // on mobile self .each(function() { var element = $(this).get(0), data = $(this).data("roundabout"), page = (data.dragAxis.toLowerCase() === "x") ? "pageX" : "pageY", method = methods.getAnimateToMethod(data.dropAnimateTo); // some versions of IE don't like this if (element.addEventListener) { element.addEventListener("touchstart", function(e) { data.touchMoveStartPosition = e.touches[0][page]; }, false); element.addEventListener("touchmove", function(e) { var delta = (e.touches[0][page] - data.touchMoveStartPosition) / data.dragFactor; e.preventDefault(); methods.stopAnimation.apply($(this)); methods.setBearing.apply($(this), [data.dragBearing + delta]); }, false); element.addEventListener("touchend", function(e) { e.preventDefault(); methods.allowAnimation.apply($(this)); method = methods.getAnimateToMethod(data.dropAnimateTo); methods[method].apply($(this), [data.dropDuration, data.dropEasing, data.dropCallback]); data.dragBearing = data.period * methods.getNearestChild.apply($(this)); }, false); } }); } // start children methods.initChildren.apply(self, [callback, relayout]); }); }, // initChildren // applys settings to child elements, starts roundabout initChildren: function(callback, relayout) { var self = $(this), data = self.data("roundabout"); callback = callback || function() {}; self.children(data.childSelector).each(function(i) { var startWidth, startHeight, startFontSize, degrees = methods.getPlacement.apply(self, [i]); // on relayout, grab these values from current data if (relayout && $(this).data("roundabout")) { startWidth = $(this).data("roundabout").startWidth; startHeight = $(this).data("roundabout").startHeight; startFontSize = $(this).data("roundabout").startFontSize; } // apply classes and css first $(this) .addClass("roundabout-moveable-item") .css("position", "absolute"); // now measure $(this) .data( "roundabout", { startWidth: startWidth || $(this).width(), startHeight: startHeight || $(this).height(), startFontSize: startFontSize || parseInt($(this).css("font-size"), 10), degrees: degrees, backDegrees: methods.normalize.apply(null, [degrees - 180]), childNumber: i, currentScale: 1, parent: self } ); }); methods.updateChildren.apply(self); // start autoplay if necessary if (data.autoplay) { data.autoplayStartTimeout = setTimeout(function() { methods.startAutoplay.apply(self); }, data.autoplayInitialDelay); } self.trigger('ready'); callback.apply(self); return self; }, // positioning // ----------------------------------------------------------------------- // updateChildren // move children elements into their proper locations updateChildren: function() { return this .each(function() { var self = $(this), data = self.data("roundabout"), inFocus = -1, info = { bearing: data.bearing, tilt: data.tilt, stage: { width: Math.floor($(this).width() * 0.9), height: Math.floor($(this).height() * 0.9) }, animating: data.animating, inFocus: data.childInFocus, focusBearingRadian: methods.degToRad.apply(null, [data.focusBearing]), shape: $.roundaboutShapes[data.shape] || $.roundaboutShapes[$.roundaboutShapes.def] }; // calculations info.midStage = { width: info.stage.width / 2, height: info.stage.height / 2 }; info.nudge = { width: info.midStage.width + (info.stage.width * 0.05), height: info.midStage.height + (info.stage.height * 0.05) }; info.zValues = { min: data.minZ, max: data.maxZ, diff: data.maxZ - data.minZ }; info.opacity = { min: data.minOpacity, max: data.maxOpacity, diff: data.maxOpacity - data.minOpacity }; info.scale = { min: data.minScale, max: data.maxScale, diff: data.maxScale - data.minScale }; // update child positions self.children(data.childSelector) .each(function(i) { if (methods.updateChild.apply(self, [$(this), info, i, function() { $(this).trigger('ready'); }]) && (!info.animating || data.lastAnimationStep)) { inFocus = i; $(this).addClass("roundabout-in-focus"); } else { $(this).removeClass("roundabout-in-focus"); } }); if (inFocus !== info.inFocus) { // blur old child if (data.triggerBlurEvents) { self.children(data.childSelector) .eq(info.inFocus) .trigger("blur"); } data.childInFocus = inFocus; if (data.triggerFocusEvents && inFocus !== -1) { // focus new child self.children(data.childSelector) .eq(inFocus) .trigger("focus"); } } self.trigger("childrenUpdated"); }); }, // updateChild // repositions a child element into its new position updateChild: function(childElement, info, childPos, callback) { var factors, self = this, child = $(childElement), data = child.data("roundabout"), out = [], rad = methods.degToRad.apply(null, [(360.0 - data.degrees) + info.bearing]); callback = callback || function() {}; // adjust radians to be between 0 and Math.PI * 2 rad = methods.normalizeRad.apply(null, [rad]); // get factors from shape factors = info.shape(rad, info.focusBearingRadian, info.tilt); // correct factors.scale = (factors.scale > 1) ? 1 : factors.scale; factors.adjustedScale = (info.scale.min + (info.scale.diff * factors.scale)).toFixed(4); factors.width = (factors.adjustedScale * data.startWidth).toFixed(4); factors.height = (factors.adjustedScale * data.startHeight).toFixed(4); // update item child .css({ left: ((factors.x * info.midStage.width + info.nudge.width) - factors.width / 2.0).toFixed(0) + "px", top: ((factors.y * info.midStage.height + info.nudge.height) - factors.height / 2.0).toFixed(0) + "px", width: factors.width + "px", height: factors.height + "px", opacity: (info.opacity.min + (info.opacity.diff * factors.scale)).toFixed(2), zIndex: Math.round(info.zValues.min + (info.zValues.diff * factors.z)), fontSize: (factors.adjustedScale * data.startFontSize).toFixed(1) + "px" }); data.currentScale = factors.adjustedScale; // for debugging purposes if (self.data("roundabout").debug) { out.push("<div style=\"font-weight: normal; font-size: 10px; padding: 2px; width: " + child.css("width") + "; background-color: #ffc;\">"); out.push("<strong style=\"font-size: 12px; white-space: nowrap;\">Child " + childPos + "</strong><br />"); out.push("<strong>left:</strong> " + child.css("left") + "<br />"); out.push("<strong>top:</strong> " + child.css("top") + "<br />"); out.push("<strong>width:</strong> " + child.css("width") + "<br />"); out.push("<strong>opacity:</strong> " + child.css("opacity") + "<br />"); out.push("<strong>height:</strong> " + child.css("height") + "<br />"); out.push("<strong>z-index:</strong> " + child.css("z-index") + "<br />"); out.push("<strong>font-size:</strong> " + child.css("font-size") + "<br />"); out.push("<strong>scale:</strong> " + child.data("roundabout").currentScale); out.push("</div>"); child.html(out.join("")); } // trigger event child.trigger("reposition"); // callback callback.apply(self); return methods.isInFocus.apply(self, [data.degrees]); }, // manipulation // ----------------------------------------------------------------------- // setBearing // changes the bearing of the roundabout setBearing: function(bearing, callback) { callback = callback || function() {}; bearing = methods.normalize.apply(null, [bearing]); this .each(function() { var diff, lowerValue, higherValue, self = $(this), data = self.data("roundabout"), oldBearing = data.bearing; // set bearing data.bearing = bearing; self.trigger("bearingSet"); methods.updateChildren.apply(self); // not animating? we're done here diff = Math.abs(oldBearing - bearing); if (!data.animating || diff > 180) { return; } // check to see if any of the children went through the back diff = Math.abs(oldBearing - bearing); self.children(data.childSelector).each(function(i) { var eventType; if (methods.isChildBackDegreesBetween.apply($(this), [bearing, oldBearing])) { eventType = (oldBearing > bearing) ? "Clockwise" : "Counterclockwise"; $(this).trigger("move" + eventType + "ThroughBack"); } }); }); // call callback if one was given callback.apply(this); return this; }, // adjustBearing // change the bearing of the roundabout by a given degree adjustBearing: function(delta, callback) { callback = callback || function() {}; if (delta === 0) { return this; } this .each(function() { methods.setBearing.apply($(this), [$(this).data("roundabout").bearing + delta]); }); callback.apply(this); return this; }, // setTilt // changes the tilt of the roundabout setTilt: function(tilt, callback) { callback = callback || function() {}; this .each(function() { $(this).data("roundabout").tilt = tilt; methods.updateChildren.apply($(this)); }); // call callback if one was given callback.apply(this); return this; }, // adjustTilt // changes the tilt of the roundabout adjustTilt: function(delta, callback) { callback = callback || function() {}; this .each(function() { methods.setTilt.apply($(this), [$(this).data("roundabout").tilt + delta]); }); callback.apply(this); return this; }, // animation // ----------------------------------------------------------------------- // animateToBearing // animates the roundabout to a given bearing, all animations come through here animateToBearing: function(bearing, duration, easing, passedData, callback) { var now = (new Date()).getTime(); callback = callback || function() {}; // find callback function in arguments if ($.isFunction(passedData)) { callback = passedData; passedData = null; } else if ($.isFunction(easing)) { callback = easing; easing = null; } else if ($.isFunction(duration)) { callback = duration; duration = null; } this .each(function() { var timer, easingFn, newBearing, self = $(this), data = self.data("roundabout"), thisDuration = (!duration) ? data.duration : duration, thisEasingType = (easing) ? easing : data.easing || "swing"; // is this your first time? if (!passedData) { passedData = { timerStart: now, start: data.bearing, totalTime: thisDuration }; } // update the timer timer = now - passedData.timerStart; if (data.stopAnimation) { methods.allowAnimation.apply(self); data.animating = false; return; } // we need to animate more if (timer < thisDuration) { if (!data.animating) { self.trigger("animationStart"); } data.animating = true; if (typeof $.easing.def === "string") { easingFn = $.easing[thisEasingType] || $.easing[$.easing.def]; newBearing = easingFn(null, timer, passedData.start, bearing - passedData.start, passedData.totalTime); } else { newBearing = $.easing[thisEasingType]((timer / passedData.totalTime), timer, passedData.start, bearing - passedData.start, passedData.totalTime); } // fixes issue #24, animation changed as of jQuery 1.7.2 // also addresses issue #29, using easing breaks "linear" if (methods.compareVersions.apply(null, [$().jquery, "1.7.2"]) >= 0 && !($.easing["easeOutBack"])) { newBearing = passedData.start + ((bearing - passedData.start) * newBearing); } newBearing = methods.normalize.apply(null, [newBearing]); data.dragBearing = newBearing; methods.setBearing.apply(self, [newBearing, function() { setTimeout(function() { // done with a timeout so that each step is displayed methods.animateToBearing.apply(self, [bearing, thisDuration, thisEasingType, passedData, callback]); }, 0); }]); // we're done animating } else { data.lastAnimationStep = true; bearing = methods.normalize.apply(null, [bearing]); methods.setBearing.apply(self, [bearing, function() { self.trigger("animationEnd"); }]); data.animating = false; data.lastAnimationStep = false; data.dragBearing = bearing; callback.apply(self); } }); return this; }, // animateToNearbyChild // animates roundabout to a nearby child animateToNearbyChild: function(passedArgs, which) { var duration = passedArgs[0], easing = passedArgs[1], callback = passedArgs[2] || function() {}; // find callback if ($.isFunction(easing)) { callback = easing; easing = null; } else if ($.isFunction(duration)) { callback = duration; duration = null; } return this .each(function() { var j, range, self = $(this), data = self.data("roundabout"), bearing = (!data.reflect) ? data.bearing % 360 : data.bearing, length = self.children(data.childSelector).length; if (!data.animating) { // reflecting, not moving to previous || not reflecting, moving to next if ((data.reflect && which === "previous") || (!data.reflect && which === "next")) { // slightly adjust for rounding issues bearing = (Math.abs(bearing) < data.floatComparisonThreshold) ? 360 : bearing; // clockwise for (j = 0; j < length; j += 1) { range = { lower: (data.period * j), upper: (data.period * (j + 1)) }; range.upper = (j === length - 1) ? 360 : range.upper; if (bearing <= Math.ceil(range.upper) && bearing >= Math.floor(range.lower)) { if (length === 2 && bearing === 360) { methods.animateToDelta.apply(self, [-180, duration, easing, callback]); } else { methods.animateBearingToFocus.apply(self, [range.lower, duration, easing, callback]); } break; } } } else { // slightly adjust for rounding issues bearing = (Math.abs(bearing) < data.floatComparisonThreshold || 360 - Math.abs(bearing) < data.floatComparisonThreshold) ? 0 : bearing; // counterclockwise for (j = length - 1; j >= 0; j -= 1) { range = { lower: data.period * j, upper: data.period * (j + 1) }; range.upper = (j === length - 1) ? 360 : range.upper; if (bearing >= Math.floor(range.lower) && bearing < Math.ceil(range.upper)) { if (length === 2 && bearing === 360) { methods.animateToDelta.apply(self, [180, duration, easing, callback]); } else { methods.animateBearingToFocus.apply(self, [range.upper, duration, easing, callback]); } break; } } } } }); }, // animateToNearestChild // animates roundabout to the nearest child animateToNearestChild: function(duration, easing, callback) { callback = callback || function() {}; // find callback if ($.isFunction(easing)) { callback = easing; easing = null; } else if ($.isFunction(duration)) { callback = duration; duration = null; } return this .each(function() { var nearest = methods.getNearestChild.apply($(this)); methods.animateToChild.apply($(this), [nearest, duration, easing, callback]); }); }, // animateToChild // animates roundabout to a given child position animateToChild: function(childPosition, duration, easing, callback) { callback = callback || function() {}; // find callback if ($.isFunction(easing)) { callback = easing; easing = null; } else if ($.isFunction(duration)) { callback = duration; duration = null; } return this .each(function() { var child, self = $(this), data = self.data("roundabout"); if (data.childInFocus !== childPosition && !data.animating) { child = self.children(data.childSelector).eq(childPosition); methods.animateBearingToFocus.apply(self, [child.data("roundabout").degrees, duration, easing, callback]); } }); }, // animateToNextChild // animates roundabout to the next child animateToNextChild: function(duration, easing, callback) { return methods.animateToNearbyChild.apply(this, [arguments, "next"]); }, // animateToPreviousChild // animates roundabout to the preious child animateToPreviousChild: function(duration, easing, callback) { return methods.animateToNearbyChild.apply(this, [arguments, "previous"]); }, // animateToDelta // animates roundabout to a given delta (in degrees) animateToDelta: function(degrees, duration, easing, callback) { callback = callback || function() {}; // find callback if ($.isFunction(easing)) { callback = easing; easing = null; } else if ($.isFunction(duration)) { callback = duration; duration = null; } return this .each(function() { var delta = $(this).data("roundabout").bearing + degrees; methods.animateToBearing.apply($(this), [delta, duration, easing, callback]); }); }, // animateBearingToFocus // animates roundabout to bring a given angle into focus animateBearingToFocus: function(degrees, duration, easing, callback) { callback = callback || function() {}; // find callback if ($.isFunction(easing)) { callback = easing; easing = null; } else if ($.isFunction(duration)) { callback = duration; duration = null; } return this .each(function() { var delta = $(this).data("roundabout").bearing - degrees; delta = (Math.abs(360 - delta) < Math.abs(delta)) ? 360 - delta : -delta; delta = (delta > 180) ? -(360 - delta) : delta; if (delta !== 0) { methods.animateToDelta.apply($(this), [delta, duration, easing, callback]); } }); }, // stopAnimation // if an animation is currently in progress, stop it stopAnimation: function() { return this .each(function() { $(this).data("roundabout").stopAnimation = true; }); }, // allowAnimation // clears the stop-animation hold placed by stopAnimation allowAnimation: function() { return this .each(function() { $(this).data("roundabout").stopAnimation = false; }); }, // autoplay // ----------------------------------------------------------------------- // startAutoplay // starts autoplaying this roundabout startAutoplay: function(callback) { return this .each(function() { var self = $(this), data = self.data("roundabout"); callback = callback || data.autoplayCallback || function() {}; clearInterval(data.autoplayInterval); data.autoplayInterval = setInterval(function() { methods.animateToNextChild.apply(self, [callback]); }, data.autoplayDuration); data.autoplayIsRunning = true; self.trigger("autoplayStart"); }); }, // stopAutoplay // stops autoplaying this roundabout stopAutoplay: function(keepAutoplayBindings) { return this .each(function() { clearInterval($(this).data("roundabout").autoplayInterval); $(this).data("roundabout").autoplayInterval = null; $(this).data("roundabout").autoplayIsRunning = false; // this will prevent autoplayPauseOnHover from restarting autoplay if (!keepAutoplayBindings) { $(this).unbind(".autoplay"); } $(this).trigger("autoplayStop"); }); }, // toggleAutoplay // toggles autoplay pause/resume toggleAutoplay: function(callback) { return this .each(function() { var self = $(this), data = self.data("roundabout"); callback = callback || data.autoplayCallback || function() {}; if (!methods.isAutoplaying.apply($(this))) { methods.startAutoplay.apply($(this), [callback]); } else { methods.stopAutoplay.apply($(this), [callback]); } }); }, // isAutoplaying // is this roundabout currently autoplaying? isAutoplaying: function() { return (this.data("roundabout").autoplayIsRunning); }, // changeAutoplayDuration // stops the autoplay, changes the duration, restarts autoplay changeAutoplayDuration: function(duration) { return this .each(function() { var self = $(this), data = self.data("roundabout"); data.autoplayDuration = duration; if (methods.isAutoplaying.apply(self)) { methods.stopAutoplay.apply(self); setTimeout(function() { methods.startAutoplay.apply(self); }, 10); } }); }, // helpers // ----------------------------------------------------------------------- // normalize // regulates degrees to be >= 0.0 and < 360 normalize: function(degrees) { var inRange = degrees % 360.0; return (inRange < 0) ? 360 + inRange : inRange; }, // normalizeRad // regulates radians to be >= 0 and < Math.PI * 2 normalizeRad: function(radians) { while (radians < 0) { radians += (Math.PI * 2); } |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |