Changeset 504
- Timestamp:
- 01/15/06 06:24:58 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
mochikit/branches/scriptaculous/MochiKit/Effects.js
r502 r504 14 14 var Effect = { 15 15 tagifyText: function (element) { 16 // XXX: what's this function for ? Doesn't work 16 17 var tagifyStyle = 'position:relative'; 17 18 if (MochiKit.Base.isIE()) { … … 33 34 34 35 multiple: function (element, effect, options) { 36 // XXX: what's this function for ? Doesn't work 35 37 var elements; 36 38 if (((typeof(element) == 'object') || … … 59 61 }, 60 62 61 toggle: function (element, effect, options) { 63 toggle: function (element, /* optional */effect, /* optional */options) { 64 /*** 65 66 Toggle an item between two state depending of its visibility, making 67 a effect between these states. Default effect is 'appear', can be 68 'slide' or 'blind'. 69 70 ***/ 62 71 element = MochiKit.DOM.getElement(element); 63 72 effect = (effect || 'appear').toLowerCase(); … … 66 75 }, options || {}); 67 76 Effect[MochiKit.DOM.isVisible(element) ? 68 Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options);77 Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options); 69 78 } 70 79 }; 71 80 72 /* ------------- transitions ------------- */ 81 /*** 82 83 Transitions: define functions calculating variations depending of a position. 84 85 ***/ 73 86 74 87 Effect.Transitions = {} … … 80 93 return (-Math.cos(pos*Math.PI)/2) + 0.5; 81 94 } 82 Effect.Transitions.reverse = function (pos) {83 return 1 -pos;95 Effect.Transitions.reverse = function (pos) { 96 return 1 - pos; 84 97 } 85 98 Effect.Transitions.flicker = function (pos) { … … 91 104 Effect.Transitions.pulse = function (pos) { 92 105 return (Math.floor(pos*10) % 2 == 0 ? 93 (pos*10 -Math.floor(pos*10)) : 1-(pos*10-Math.floor(pos*10)));106 (pos*10 - Math.floor(pos*10)) : 1 - (pos*10 - Math.floor(pos*10))); 94 107 } 95 108 Effect.Transitions.none = function (pos) { … … 100 113 } 101 114 102 /* ------------- core effects ------------- */ 115 /*** 116 117 Core effects 118 119 ***/ 103 120 104 121 Effect.ScopedQueue = function () { … … 145 162 this.effects.push(effect); 146 163 if (!this.interval) { 147 this.interval = setInterval(MochiKit.Base.bind(this.loop, this), 40); 164 this.interval = setInterval(MochiKit.Base.bind(this.loop, this), 165 40); 148 166 } 149 167 }, … … 169 187 Effect.Queues = { 170 188 instances: new Array(), 189 171 190 get: function (queueName) { 172 191 if (typeof(queueName) != 'string') { … … 197 216 198 217 Effect.Base.prototype = { 218 /*** 219 220 Basic class for all Effects. Define a looping mecanism called for each step 221 of an effect. Don't instanciate it, only subclass it. 222 223 ***/ 199 224 position: null, 200 225 201 226 start: function (options) { 202 this.options = MochiKit.Base.setdefault(options || {}, Effect.DefaultOptions); 227 this.options = MochiKit.Base.setdefault(options || {}, 228 Effect.DefaultOptions); 203 229 this.currentFrame = 0; 204 230 this.state = 'idle'; … … 225 251 } 226 252 var pos = (timePos - this.startOn) / (this.finishOn - this.startOn); 227 var frame = Math.round(pos * this.options.fps * this.options.duration); 253 var frame = 254 Math.round(pos * this.options.fps * this.options.duration); 228 255 if (frame > this.currentFrame) { 229 256 this.render(pos); … … 275 302 276 303 __repr__: function () { 277 return '<Effect:' + MochiKit.Base.repr(this) + ', options:' + MochiKit.Base.repr(this.options) + '>'; 304 return '<Effect:' + MochiKit.Base.repr(this) + ', options:' + 305 MochiKit.Base.repr(this.options) + '>'; 278 306 } 279 307 } … … 286 314 287 315 MochiKit.Base.update(Effect.Parallel.prototype, { 316 /*** 317 318 Run multiple effects at the same time. 319 320 ***/ 288 321 __init__: function (effects, options) { 289 322 this.effects = effects || []; … … 317 350 318 351 MochiKit.Base.update(Effect.Opacity.prototype, { 319 __init__: function (element, options) { 352 /*** 353 354 Change the opacity of an element. 355 356 @param options: 'from' and 'to' change the starting and ending opacities. 357 Must be between 0.0 and 1.0. Default to current opacity and 1.0. 358 359 ***/ 360 __init__: function (element, /* optional */options) { 320 361 this.element = MochiKit.DOM.getElement(element); 321 362 // make this work on IE on elements without 'layout' … … 342 383 343 384 MochiKit.Base.update(Effect.Move.prototype, { 344 __init__: function (element, options) { 385 /*** 386 387 Move an element between its current position to a defined position 388 389 @param options: 'x' and 'y' for final positions, default to 0, 0. 390 391 ***/ 392 __init__: function (element, /* optional */options) { 345 393 this.element = MochiKit.DOM.getElement(element); 346 394 options = MochiKit.Base.update({ … … 353 401 354 402 setup: function () { 355 // Bug in Opera: Opera returns the 'real' position of a static element or356 // relative element that does not have top/left explicitly set.357 // ==> Always set top and left for position relative elements in your stylesheets358 // (to 0 if you do not need them)403 // Bug in Opera: Opera returns the 'real' position of a static element 404 // or relative element that does not have top/left explicitly set. 405 // ==> Always set top and left for position relative elements in your 406 // stylesheets (to 0 if you do not need them) 359 407 MochiKit.DOM.makePositioned(this.element); 360 this.originalLeft = parseFloat(MochiKit.DOM.getStyle(this.element,'left') || '0'); 361 this.originalTop = parseFloat(MochiKit.DOM.getStyle(this.element,'top') || '0'); 408 this.originalLeft = parseFloat(MochiKit.DOM.getStyle(this.element, 409 'left') || '0'); 410 this.originalTop = parseFloat(MochiKit.DOM.getStyle(this.element, 411 'top') || '0'); 362 412 if (this.options.mode == 'absolute') { 363 413 // absolute movement, so we need to calc deltaX and deltaY … … 382 432 383 433 MochiKit.Base.update(Effect.Scale.prototype, { 384 __init__: function (element, percent, options) { 434 /*** 435 436 Change the size of an element. 437 438 @param percent: final_size = percent*original_size 439 440 @param options: several options changing scale behaviour 441 442 ***/ 443 __init__: function (element, percent, /* optional */options) { 385 444 this.element = MochiKit.DOM.getElement(element) 386 445 options = MochiKit.Base.update({ … … 398 457 setup: function () { 399 458 this.restoreAfterFinish = this.options.restoreAfterFinish || false; 400 this.elementPositioning = MochiKit.DOM.getStyle(this.element,'position'); 459 this.elementPositioning = MochiKit.DOM.getStyle(this.element, 460 'position'); 401 461 402 462 this.originalStyle = {}; … … 409 469 this.originalLeft = this.element.offsetLeft; 410 470 411 var fontSize = MochiKit.DOM.getStyle(this.element,'font-size') || '100%'; 412 MochiKit.Iter.forEach(['em','px','%'], MochiKit.Base.bind(function (fontSizeType) { 471 var fontSize = MochiKit.DOM.getStyle(this.element, 472 'font-size') || '100%'; 473 MochiKit.Iter.forEach(['em', 'px', '%'], 474 MochiKit.Base.bind(function (fontSizeType) { 413 475 if (fontSize.indexOf(fontSizeType) > 0) { 414 476 this.fontSize = parseFloat(fontSize); … … 433 495 434 496 update: function (position) { 435 var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position); 497 var currentScale = (this.options.scaleFrom/100.0) + 498 (this.factor * position); 436 499 if (this.options.scaleContent && this.fontSize) { 437 500 MochiKit.DOM.setStyle(this.element, { … … 439 502 }); 440 503 } 441 this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale); 504 this.setDimensions(this.dims[0] * currentScale, 505 this.dims[1] * currentScale); 442 506 }, 443 507 … … 486 550 487 551 MochiKit.Base.update(Effect.Highlight.prototype, { 488 __init__: function (element, options) { 552 /*** 553 554 Highlight an item of the page. 555 556 @param options: 'startcolor' for choosing highlighting color, default 557 to '#ffff99'. 558 559 ***/ 560 __init__: function (element, /* optional */options) { 489 561 this.element = MochiKit.DOM.getElement(element); 490 562 options = MochiKit.Base.update({ 491 startcolor: '#ffff99', 492 numSteps: 16 563 startcolor: '#ffff99' 493 564 }, options || {}); 494 565 this.start(options); … … 503 574 // Disable background image during the effect 504 575 this.oldStyle = { 505 backgroundImage: MochiKit.DOM.getStyle(this.element, 'background-image') 576 backgroundImage: MochiKit.DOM.getStyle(this.element, 577 'background-image') 506 578 }; 507 579 MochiKit.DOM.setStyle(this.element, { … … 510 582 511 583 if (!this.options.endcolor) { 512 this.options.endcolor = MochiKit.Color.Color.fromBackground(this.element).toHexString(); 584 this.options.endcolor = 585 MochiKit.Color.Color.fromBackground(this.element).toHexString(); 513 586 } 514 587 if(!this.options.restorecolor) { 515 this.options.restorecolor = MochiKit.DOM.getStyle(this.element, 'background-color'); 588 this.options.restorecolor = MochiKit.DOM.getStyle(this.element, 589 'background-color'); 516 590 } 517 591 // init color calculations 518 592 this._base = MochiKit.Base.map(MochiKit.Base.bind(function (i) { 519 return parseInt(this.options.startcolor.slice(i*2 + 1, i*2 + 3), 16); 593 return parseInt( 594 this.options.startcolor.slice(i*2 + 1, i*2 + 3), 16); 520 595 }, this), [0, 1, 2]); 521 596 this._delta = MochiKit.Base.map(MochiKit.Base.bind(function (i) { 522 return parseInt(this.options.endcolor.slice(i*2 + 1, i*2 + 3), 16) - this._base[i]; 597 return parseInt(this.options.endcolor.slice(i*2 + 1, i*2 + 3), 16) 598 - this._base[i]; 523 599 }, this), [0, 1, 2]); 524 600 }, … … 527 603 var m = '#'; 528 604 MochiKit.Iter.forEach([0, 1, 2], MochiKit.Base.bind(function (i) { 529 m += MochiKit.Color.toColorPart(Math.round(this._base[i] + (this._delta[i]*position))); 605 m += MochiKit.Color.toColorPart(Math.round(this._base[i] + 606 this._delta[i]*position)); 530 607 }, this)); 531 608 MochiKit.DOM.setStyle(this.element, { … … 535 612 536 613 finish: function () { 537 MochiKit.DOM.setStyle(this.element, MochiKit.Base.update(this.oldStyle, { 614 MochiKit.DOM.setStyle(this.element, 615 MochiKit.Base.update(this.oldStyle, { 538 616 backgroundColor: this.options.endColor 539 617 })); … … 548 626 549 627 MochiKit.Base.update(Effect.ScrollTo.prototype, { 550 __init__: function (element, options) { 628 /*** 629 630 Scroll to an element in the page. 631 632 ***/ 633 __init__: function (element, /* optional */options) { 551 634 this.element = MochiKit.DOM.getElement(element); 552 635 this.start(options || {}); … … 554 637 555 638 setup: function () { 556 Position.prepare();639 MochiKit.Position.prepare(); 557 640 var offsets = MochiKit.Position.cumulativeOffset(this.element); 558 641 if (this.options.offset) { … … 563 646 document.body.scrollHeight - 564 647 (document.documentElement.clientHeight ? 565 document.documentElement.clientHeight : document.body.clientHeight); 648 document.documentElement.clientHeight : 649 document.body.clientHeight); 566 650 this.scrollStart = MochiKit.Position.deltaY; 567 651 this.delta = (offsets[1] > max ? max : offsets[1]) - this.scrollStart; … … 569 653 570 654 update: function (position) { 571 Position.prepare();572 window.scrollTo( Position.deltaX,655 MochiKit.Position.prepare(); 656 window.scrollTo(MochiKit.Position.deltaX, 573 657 this.scrollStart + (position*this.delta)); 574 658 } 575 659 }); 576 660 577 /* ------------- combination effects ------------- */ 661 /*** 662 663 Combination effects. 664 665 ***/ 578 666 579 667 Effect.Fade = function (element, options) {
