javascript/effects.js
author terom
Thu, 31 Jan 2008 19:19:05 +0000
changeset 30 b1d5c32ab771
parent 23 10841abbc01f
permissions -rw-r--r--
moar tweaks/small bugfixes
23
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     1
// script.aculo.us effects.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     2
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     3
// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     4
// Contributors:
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     5
//  Justin Palmer (http://encytemedia.com/)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     6
//  Mark Pilgrim (http://diveintomark.org/)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     7
//  Martin Bialasinki
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     8
// 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
     9
// script.aculo.us is freely distributable under the terms of an MIT-style license.
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    10
// For details, see the script.aculo.us web site: http://script.aculo.us/ 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    11
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    12
// converts rgb() and #xxx to #xxxxxx format,  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    13
// returns self (or first argument) if not convertable  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    14
String.prototype.parseColor = function() {  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    15
  var color = '#';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    16
  if (this.slice(0,4) == 'rgb(') {  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    17
    var cols = this.slice(4,this.length-1).split(',');  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    18
    var i=0; do { color += parseInt(cols[i]).toColorPart() } while (++i<3);  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    19
  } else {  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    20
    if (this.slice(0,1) == '#') {  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    21
      if (this.length==4) for(var i=1;i<4;i++) color += (this.charAt(i) + this.charAt(i)).toLowerCase();  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    22
      if (this.length==7) color = this.toLowerCase();  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    23
    }  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    24
  }  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    25
  return (color.length==7 ? color : (arguments[0] || this));  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    26
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    27
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    28
/*--------------------------------------------------------------------------*/
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    29
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    30
Element.collectTextNodes = function(element) {  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    31
  return $A($(element).childNodes).collect( function(node) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    32
    return (node.nodeType==3 ? node.nodeValue : 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    33
      (node.hasChildNodes() ? Element.collectTextNodes(node) : ''));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    34
  }).flatten().join('');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    35
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    36
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    37
Element.collectTextNodesIgnoreClass = function(element, className) {  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    38
  return $A($(element).childNodes).collect( function(node) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    39
    return (node.nodeType==3 ? node.nodeValue : 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    40
      ((node.hasChildNodes() && !Element.hasClassName(node,className)) ? 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    41
        Element.collectTextNodesIgnoreClass(node, className) : ''));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    42
  }).flatten().join('');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    43
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    44
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    45
Element.setContentZoom = function(element, percent) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    46
  element = $(element);  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    47
  element.setStyle({fontSize: (percent/100) + 'em'});   
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    48
  if (Prototype.Browser.WebKit) window.scrollBy(0,0);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    49
  return element;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    50
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    51
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    52
Element.getInlineOpacity = function(element){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    53
  return $(element).style.opacity || '';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    54
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    55
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    56
Element.forceRerendering = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    57
  try {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    58
    element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    59
    var n = document.createTextNode(' ');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    60
    element.appendChild(n);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    61
    element.removeChild(n);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    62
  } catch(e) { }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    63
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    64
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    65
/*--------------------------------------------------------------------------*/
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    66
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    67
var Effect = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    68
  _elementDoesNotExistError: {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    69
    name: 'ElementDoesNotExistError',
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    70
    message: 'The specified DOM element does not exist, but is required for this effect to operate'
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    71
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    72
  Transitions: {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    73
    linear: Prototype.K,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    74
    sinoidal: function(pos) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    75
      return (-Math.cos(pos*Math.PI)/2) + 0.5;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    76
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    77
    reverse: function(pos) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    78
      return 1-pos;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    79
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    80
    flicker: function(pos) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    81
      var pos = ((-Math.cos(pos*Math.PI)/4) + 0.75) + Math.random()/4;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    82
      return pos > 1 ? 1 : pos;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    83
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    84
    wobble: function(pos) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    85
      return (-Math.cos(pos*Math.PI*(9*pos))/2) + 0.5;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    86
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    87
    pulse: function(pos, pulses) { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    88
      pulses = pulses || 5; 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    89
      return (
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    90
        ((pos % (1/pulses)) * pulses).round() == 0 ? 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    91
              ((pos * pulses * 2) - (pos * pulses * 2).floor()) : 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    92
          1 - ((pos * pulses * 2) - (pos * pulses * 2).floor())
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    93
        );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    94
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    95
    spring: function(pos) { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    96
      return 1 - (Math.cos(pos * 4.5 * Math.PI) * Math.exp(-pos * 6)); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    97
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    98
    none: function(pos) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
    99
      return 0;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   100
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   101
    full: function(pos) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   102
      return 1;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   103
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   104
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   105
  DefaultOptions: {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   106
    duration:   1.0,   // seconds
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   107
    fps:        100,   // 100= assume 66fps max.
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   108
    sync:       false, // true for combining
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   109
    from:       0.0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   110
    to:         1.0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   111
    delay:      0.0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   112
    queue:      'parallel'
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   113
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   114
  tagifyText: function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   115
    var tagifyStyle = 'position:relative';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   116
    if (Prototype.Browser.IE) tagifyStyle += ';zoom:1';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   117
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   118
    element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   119
    $A(element.childNodes).each( function(child) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   120
      if (child.nodeType==3) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   121
        child.nodeValue.toArray().each( function(character) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   122
          element.insertBefore(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   123
            new Element('span', {style: tagifyStyle}).update(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   124
              character == ' ' ? String.fromCharCode(160) : character), 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   125
              child);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   126
        });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   127
        Element.remove(child);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   128
      }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   129
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   130
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   131
  multiple: function(element, effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   132
    var elements;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   133
    if (((typeof element == 'object') || 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   134
        Object.isFunction(element)) && 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   135
       (element.length))
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   136
      elements = element;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   137
    else
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   138
      elements = $(element).childNodes;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   139
      
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   140
    var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   141
      speed: 0.1,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   142
      delay: 0.0
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   143
    }, arguments[2] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   144
    var masterDelay = options.delay;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   145
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   146
    $A(elements).each( function(element, index) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   147
      new effect(element, Object.extend(options, { delay: index * options.speed + masterDelay }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   148
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   149
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   150
  PAIRS: {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   151
    'slide':  ['SlideDown','SlideUp'],
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   152
    'blind':  ['BlindDown','BlindUp'],
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   153
    'appear': ['Appear','Fade']
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   154
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   155
  toggle: function(element, effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   156
    element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   157
    effect = (effect || 'appear').toLowerCase();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   158
    var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   159
      queue: { position:'end', scope:(element.id || 'global'), limit: 1 }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   160
    }, arguments[2] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   161
    Effect[element.visible() ? 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   162
      Effect.PAIRS[effect][1] : Effect.PAIRS[effect][0]](element, options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   163
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   164
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   165
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   166
Effect.DefaultOptions.transition = Effect.Transitions.sinoidal;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   167
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   168
/* ------------- core effects ------------- */
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   169
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   170
Effect.ScopedQueue = Class.create(Enumerable, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   171
  initialize: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   172
    this.effects  = [];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   173
    this.interval = null;    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   174
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   175
  _each: function(iterator) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   176
    this.effects._each(iterator);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   177
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   178
  add: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   179
    var timestamp = new Date().getTime();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   180
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   181
    var position = Object.isString(effect.options.queue) ? 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   182
      effect.options.queue : effect.options.queue.position;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   183
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   184
    switch(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   185
      case 'front':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   186
        // move unstarted effects after this effect  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   187
        this.effects.findAll(function(e){ return e.state=='idle' }).each( function(e) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   188
            e.startOn  += effect.finishOn;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   189
            e.finishOn += effect.finishOn;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   190
          });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   191
        break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   192
      case 'with-last':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   193
        timestamp = this.effects.pluck('startOn').max() || timestamp;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   194
        break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   195
      case 'end':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   196
        // start effect after last queued effect has finished
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   197
        timestamp = this.effects.pluck('finishOn').max() || timestamp;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   198
        break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   199
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   200
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   201
    effect.startOn  += timestamp;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   202
    effect.finishOn += timestamp;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   203
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   204
    if (!effect.options.queue.limit || (this.effects.length < effect.options.queue.limit))
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   205
      this.effects.push(effect);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   206
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   207
    if (!this.interval)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   208
      this.interval = setInterval(this.loop.bind(this), 15);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   209
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   210
  remove: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   211
    this.effects = this.effects.reject(function(e) { return e==effect });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   212
    if (this.effects.length == 0) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   213
      clearInterval(this.interval);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   214
      this.interval = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   215
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   216
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   217
  loop: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   218
    var timePos = new Date().getTime();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   219
    for(var i=0, len=this.effects.length;i<len;i++) 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   220
      this.effects[i] && this.effects[i].loop(timePos);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   221
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   222
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   223
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   224
Effect.Queues = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   225
  instances: $H(),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   226
  get: function(queueName) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   227
    if (!Object.isString(queueName)) return queueName;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   228
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   229
    return this.instances.get(queueName) ||
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   230
      this.instances.set(queueName, new Effect.ScopedQueue());
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   231
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   232
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   233
Effect.Queue = Effect.Queues.get('global');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   234
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   235
Effect.Base = Class.create({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   236
  position: null,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   237
  start: function(options) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   238
    function codeForEvent(options,eventName){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   239
      return (
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   240
        (options[eventName+'Internal'] ? 'this.options.'+eventName+'Internal(this);' : '') +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   241
        (options[eventName] ? 'this.options.'+eventName+'(this);' : '')
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   242
      );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   243
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   244
    if (options && options.transition === false) options.transition = Effect.Transitions.linear;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   245
    this.options      = Object.extend(Object.extend({ },Effect.DefaultOptions), options || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   246
    this.currentFrame = 0;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   247
    this.state        = 'idle';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   248
    this.startOn      = this.options.delay*1000;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   249
    this.finishOn     = this.startOn+(this.options.duration*1000);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   250
    this.fromToDelta  = this.options.to-this.options.from;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   251
    this.totalTime    = this.finishOn-this.startOn;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   252
    this.totalFrames  = this.options.fps*this.options.duration;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   253
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   254
    eval('this.render = function(pos){ '+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   255
      'if (this.state=="idle"){this.state="running";'+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   256
      codeForEvent(this.options,'beforeSetup')+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   257
      (this.setup ? 'this.setup();':'')+ 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   258
      codeForEvent(this.options,'afterSetup')+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   259
      '};if (this.state=="running"){'+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   260
      'pos=this.options.transition(pos)*'+this.fromToDelta+'+'+this.options.from+';'+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   261
      'this.position=pos;'+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   262
      codeForEvent(this.options,'beforeUpdate')+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   263
      (this.update ? 'this.update(pos);':'')+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   264
      codeForEvent(this.options,'afterUpdate')+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   265
      '}}');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   266
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   267
    this.event('beforeStart');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   268
    if (!this.options.sync)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   269
      Effect.Queues.get(Object.isString(this.options.queue) ? 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   270
        'global' : this.options.queue.scope).add(this);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   271
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   272
  loop: function(timePos) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   273
    if (timePos >= this.startOn) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   274
      if (timePos >= this.finishOn) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   275
        this.render(1.0);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   276
        this.cancel();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   277
        this.event('beforeFinish');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   278
        if (this.finish) this.finish(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   279
        this.event('afterFinish');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   280
        return;  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   281
      }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   282
      var pos   = (timePos - this.startOn) / this.totalTime,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   283
          frame = (pos * this.totalFrames).round();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   284
      if (frame > this.currentFrame) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   285
        this.render(pos);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   286
        this.currentFrame = frame;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   287
      }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   288
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   289
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   290
  cancel: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   291
    if (!this.options.sync)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   292
      Effect.Queues.get(Object.isString(this.options.queue) ? 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   293
        'global' : this.options.queue.scope).remove(this);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   294
    this.state = 'finished';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   295
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   296
  event: function(eventName) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   297
    if (this.options[eventName + 'Internal']) this.options[eventName + 'Internal'](this);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   298
    if (this.options[eventName]) this.options[eventName](this);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   299
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   300
  inspect: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   301
    var data = $H();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   302
    for(property in this)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   303
      if (!Object.isFunction(this[property])) data.set(property, this[property]);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   304
    return '#<Effect:' + data.inspect() + ',options:' + $H(this.options).inspect() + '>';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   305
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   306
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   307
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   308
Effect.Parallel = Class.create(Effect.Base, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   309
  initialize: function(effects) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   310
    this.effects = effects || [];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   311
    this.start(arguments[1]);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   312
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   313
  update: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   314
    this.effects.invoke('render', position);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   315
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   316
  finish: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   317
    this.effects.each( function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   318
      effect.render(1.0);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   319
      effect.cancel();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   320
      effect.event('beforeFinish');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   321
      if (effect.finish) effect.finish(position);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   322
      effect.event('afterFinish');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   323
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   324
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   325
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   326
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   327
Effect.Tween = Class.create(Effect.Base, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   328
  initialize: function(object, from, to) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   329
    object = Object.isString(object) ? $(object) : object;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   330
    var args = $A(arguments), method = args.last(), 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   331
      options = args.length == 5 ? args[3] : null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   332
    this.method = Object.isFunction(method) ? method.bind(object) :
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   333
      Object.isFunction(object[method]) ? object[method].bind(object) : 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   334
      function(value) { object[method] = value };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   335
    this.start(Object.extend({ from: from, to: to }, options || { }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   336
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   337
  update: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   338
    this.method(position);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   339
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   340
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   341
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   342
Effect.Event = Class.create(Effect.Base, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   343
  initialize: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   344
    this.start(Object.extend({ duration: 0 }, arguments[0] || { }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   345
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   346
  update: Prototype.emptyFunction
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   347
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   348
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   349
Effect.Opacity = Class.create(Effect.Base, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   350
  initialize: function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   351
    this.element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   352
    if (!this.element) throw(Effect._elementDoesNotExistError);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   353
    // make this work on IE on elements without 'layout'
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   354
    if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   355
      this.element.setStyle({zoom: 1});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   356
    var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   357
      from: this.element.getOpacity() || 0.0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   358
      to:   1.0
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   359
    }, arguments[1] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   360
    this.start(options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   361
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   362
  update: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   363
    this.element.setOpacity(position);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   364
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   365
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   366
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   367
Effect.Move = Class.create(Effect.Base, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   368
  initialize: function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   369
    this.element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   370
    if (!this.element) throw(Effect._elementDoesNotExistError);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   371
    var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   372
      x:    0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   373
      y:    0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   374
      mode: 'relative'
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   375
    }, arguments[1] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   376
    this.start(options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   377
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   378
  setup: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   379
    this.element.makePositioned();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   380
    this.originalLeft = parseFloat(this.element.getStyle('left') || '0');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   381
    this.originalTop  = parseFloat(this.element.getStyle('top')  || '0');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   382
    if (this.options.mode == 'absolute') {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   383
      this.options.x = this.options.x - this.originalLeft;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   384
      this.options.y = this.options.y - this.originalTop;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   385
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   386
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   387
  update: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   388
    this.element.setStyle({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   389
      left: (this.options.x  * position + this.originalLeft).round() + 'px',
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   390
      top:  (this.options.y  * position + this.originalTop).round()  + 'px'
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   391
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   392
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   393
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   394
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   395
// for backwards compatibility
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   396
Effect.MoveBy = function(element, toTop, toLeft) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   397
  return new Effect.Move(element, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   398
    Object.extend({ x: toLeft, y: toTop }, arguments[3] || { }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   399
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   400
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   401
Effect.Scale = Class.create(Effect.Base, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   402
  initialize: function(element, percent) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   403
    this.element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   404
    if (!this.element) throw(Effect._elementDoesNotExistError);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   405
    var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   406
      scaleX: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   407
      scaleY: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   408
      scaleContent: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   409
      scaleFromCenter: false,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   410
      scaleMode: 'box',        // 'box' or 'contents' or { } with provided values
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   411
      scaleFrom: 100.0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   412
      scaleTo:   percent
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   413
    }, arguments[2] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   414
    this.start(options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   415
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   416
  setup: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   417
    this.restoreAfterFinish = this.options.restoreAfterFinish || false;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   418
    this.elementPositioning = this.element.getStyle('position');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   419
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   420
    this.originalStyle = { };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   421
    ['top','left','width','height','fontSize'].each( function(k) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   422
      this.originalStyle[k] = this.element.style[k];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   423
    }.bind(this));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   424
      
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   425
    this.originalTop  = this.element.offsetTop;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   426
    this.originalLeft = this.element.offsetLeft;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   427
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   428
    var fontSize = this.element.getStyle('font-size') || '100%';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   429
    ['em','px','%','pt'].each( function(fontSizeType) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   430
      if (fontSize.indexOf(fontSizeType)>0) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   431
        this.fontSize     = parseFloat(fontSize);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   432
        this.fontSizeType = fontSizeType;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   433
      }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   434
    }.bind(this));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   435
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   436
    this.factor = (this.options.scaleTo - this.options.scaleFrom)/100;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   437
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   438
    this.dims = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   439
    if (this.options.scaleMode=='box')
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   440
      this.dims = [this.element.offsetHeight, this.element.offsetWidth];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   441
    if (/^content/.test(this.options.scaleMode))
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   442
      this.dims = [this.element.scrollHeight, this.element.scrollWidth];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   443
    if (!this.dims)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   444
      this.dims = [this.options.scaleMode.originalHeight,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   445
                   this.options.scaleMode.originalWidth];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   446
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   447
  update: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   448
    var currentScale = (this.options.scaleFrom/100.0) + (this.factor * position);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   449
    if (this.options.scaleContent && this.fontSize)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   450
      this.element.setStyle({fontSize: this.fontSize * currentScale + this.fontSizeType });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   451
    this.setDimensions(this.dims[0] * currentScale, this.dims[1] * currentScale);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   452
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   453
  finish: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   454
    if (this.restoreAfterFinish) this.element.setStyle(this.originalStyle);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   455
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   456
  setDimensions: function(height, width) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   457
    var d = { };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   458
    if (this.options.scaleX) d.width = width.round() + 'px';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   459
    if (this.options.scaleY) d.height = height.round() + 'px';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   460
    if (this.options.scaleFromCenter) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   461
      var topd  = (height - this.dims[0])/2;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   462
      var leftd = (width  - this.dims[1])/2;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   463
      if (this.elementPositioning == 'absolute') {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   464
        if (this.options.scaleY) d.top = this.originalTop-topd + 'px';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   465
        if (this.options.scaleX) d.left = this.originalLeft-leftd + 'px';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   466
      } else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   467
        if (this.options.scaleY) d.top = -topd + 'px';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   468
        if (this.options.scaleX) d.left = -leftd + 'px';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   469
      }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   470
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   471
    this.element.setStyle(d);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   472
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   473
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   474
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   475
Effect.Highlight = Class.create(Effect.Base, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   476
  initialize: function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   477
    this.element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   478
    if (!this.element) throw(Effect._elementDoesNotExistError);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   479
    var options = Object.extend({ startcolor: '#ffff99' }, arguments[1] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   480
    this.start(options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   481
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   482
  setup: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   483
    // Prevent executing on elements not in the layout flow
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   484
    if (this.element.getStyle('display')=='none') { this.cancel(); return; }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   485
    // Disable background image during the effect
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   486
    this.oldStyle = { };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   487
    if (!this.options.keepBackgroundImage) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   488
      this.oldStyle.backgroundImage = this.element.getStyle('background-image');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   489
      this.element.setStyle({backgroundImage: 'none'});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   490
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   491
    if (!this.options.endcolor)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   492
      this.options.endcolor = this.element.getStyle('background-color').parseColor('#ffffff');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   493
    if (!this.options.restorecolor)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   494
      this.options.restorecolor = this.element.getStyle('background-color');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   495
    // init color calculations
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   496
    this._base  = $R(0,2).map(function(i){ return parseInt(this.options.startcolor.slice(i*2+1,i*2+3),16) }.bind(this));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   497
    this._delta = $R(0,2).map(function(i){ return parseInt(this.options.endcolor.slice(i*2+1,i*2+3),16)-this._base[i] }.bind(this));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   498
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   499
  update: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   500
    this.element.setStyle({backgroundColor: $R(0,2).inject('#',function(m,v,i){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   501
      return m+((this._base[i]+(this._delta[i]*position)).round().toColorPart()); }.bind(this)) });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   502
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   503
  finish: function() {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   504
    this.element.setStyle(Object.extend(this.oldStyle, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   505
      backgroundColor: this.options.restorecolor
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   506
    }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   507
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   508
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   509
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   510
Effect.ScrollTo = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   511
  var options = arguments[1] || { },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   512
    scrollOffsets = document.viewport.getScrollOffsets(),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   513
    elementOffsets = $(element).cumulativeOffset(),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   514
    max = (window.height || document.body.scrollHeight) - document.viewport.getHeight();  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   515
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   516
  if (options.offset) elementOffsets[1] += options.offset;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   517
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   518
  return new Effect.Tween(null,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   519
    scrollOffsets.top,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   520
    elementOffsets[1] > max ? max : elementOffsets[1],
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   521
    options,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   522
    function(p){ scrollTo(scrollOffsets.left, p.round()) }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   523
  );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   524
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   525
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   526
/* ------------- combination effects ------------- */
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   527
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   528
Effect.Fade = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   529
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   530
  var oldOpacity = element.getInlineOpacity();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   531
  var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   532
    from: element.getOpacity() || 1.0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   533
    to:   0.0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   534
    afterFinishInternal: function(effect) { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   535
      if (effect.options.to!=0) return;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   536
      effect.element.hide().setStyle({opacity: oldOpacity}); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   537
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   538
  }, arguments[1] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   539
  return new Effect.Opacity(element,options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   540
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   541
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   542
Effect.Appear = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   543
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   544
  var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   545
  from: (element.getStyle('display') == 'none' ? 0.0 : element.getOpacity() || 0.0),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   546
  to:   1.0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   547
  // force Safari to render floated elements properly
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   548
  afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   549
    effect.element.forceRerendering();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   550
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   551
  beforeSetup: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   552
    effect.element.setOpacity(effect.options.from).show(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   553
  }}, arguments[1] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   554
  return new Effect.Opacity(element,options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   555
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   556
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   557
Effect.Puff = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   558
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   559
  var oldStyle = { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   560
    opacity: element.getInlineOpacity(), 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   561
    position: element.getStyle('position'),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   562
    top:  element.style.top,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   563
    left: element.style.left,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   564
    width: element.style.width,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   565
    height: element.style.height
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   566
  };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   567
  return new Effect.Parallel(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   568
   [ new Effect.Scale(element, 200, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   569
      { sync: true, scaleFromCenter: true, scaleContent: true, restoreAfterFinish: true }), 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   570
     new Effect.Opacity(element, { sync: true, to: 0.0 } ) ], 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   571
     Object.extend({ duration: 1.0, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   572
      beforeSetupInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   573
        Position.absolutize(effect.effects[0].element)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   574
      },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   575
      afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   576
         effect.effects[0].element.hide().setStyle(oldStyle); }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   577
     }, arguments[1] || { })
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   578
   );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   579
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   580
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   581
Effect.BlindUp = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   582
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   583
  element.makeClipping();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   584
  return new Effect.Scale(element, 0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   585
    Object.extend({ scaleContent: false, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   586
      scaleX: false, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   587
      restoreAfterFinish: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   588
      afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   589
        effect.element.hide().undoClipping();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   590
      } 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   591
    }, arguments[1] || { })
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   592
  );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   593
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   594
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   595
Effect.BlindDown = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   596
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   597
  var elementDimensions = element.getDimensions();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   598
  return new Effect.Scale(element, 100, Object.extend({ 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   599
    scaleContent: false, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   600
    scaleX: false,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   601
    scaleFrom: 0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   602
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   603
    restoreAfterFinish: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   604
    afterSetup: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   605
      effect.element.makeClipping().setStyle({height: '0px'}).show(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   606
    },  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   607
    afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   608
      effect.element.undoClipping();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   609
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   610
  }, arguments[1] || { }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   611
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   612
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   613
Effect.SwitchOff = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   614
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   615
  var oldOpacity = element.getInlineOpacity();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   616
  return new Effect.Appear(element, Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   617
    duration: 0.4,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   618
    from: 0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   619
    transition: Effect.Transitions.flicker,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   620
    afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   621
      new Effect.Scale(effect.element, 1, { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   622
        duration: 0.3, scaleFromCenter: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   623
        scaleX: false, scaleContent: false, restoreAfterFinish: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   624
        beforeSetup: function(effect) { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   625
          effect.element.makePositioned().makeClipping();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   626
        },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   627
        afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   628
          effect.element.hide().undoClipping().undoPositioned().setStyle({opacity: oldOpacity});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   629
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   630
      })
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   631
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   632
  }, arguments[1] || { }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   633
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   634
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   635
Effect.DropOut = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   636
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   637
  var oldStyle = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   638
    top: element.getStyle('top'),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   639
    left: element.getStyle('left'),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   640
    opacity: element.getInlineOpacity() };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   641
  return new Effect.Parallel(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   642
    [ new Effect.Move(element, {x: 0, y: 100, sync: true }), 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   643
      new Effect.Opacity(element, { sync: true, to: 0.0 }) ],
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   644
    Object.extend(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   645
      { duration: 0.5,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   646
        beforeSetup: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   647
          effect.effects[0].element.makePositioned(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   648
        },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   649
        afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   650
          effect.effects[0].element.hide().undoPositioned().setStyle(oldStyle);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   651
        } 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   652
      }, arguments[1] || { }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   653
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   654
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   655
Effect.Shake = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   656
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   657
  var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   658
    distance: 20,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   659
    duration: 0.5
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   660
  }, arguments[1] || {});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   661
  var distance = parseFloat(options.distance);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   662
  var split = parseFloat(options.duration) / 10.0;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   663
  var oldStyle = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   664
    top: element.getStyle('top'),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   665
    left: element.getStyle('left') };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   666
    return new Effect.Move(element,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   667
      { x:  distance, y: 0, duration: split, afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   668
    new Effect.Move(effect.element,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   669
      { x: -distance*2, y: 0, duration: split*2,  afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   670
    new Effect.Move(effect.element,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   671
      { x:  distance*2, y: 0, duration: split*2,  afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   672
    new Effect.Move(effect.element,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   673
      { x: -distance*2, y: 0, duration: split*2,  afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   674
    new Effect.Move(effect.element,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   675
      { x:  distance*2, y: 0, duration: split*2,  afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   676
    new Effect.Move(effect.element,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   677
      { x: -distance, y: 0, duration: split, afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   678
        effect.element.undoPositioned().setStyle(oldStyle);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   679
  }}) }}) }}) }}) }}) }});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   680
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   681
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   682
Effect.SlideDown = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   683
  element = $(element).cleanWhitespace();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   684
  // SlideDown need to have the content of the element wrapped in a container element with fixed height!
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   685
  var oldInnerBottom = element.down().getStyle('bottom');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   686
  var elementDimensions = element.getDimensions();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   687
  return new Effect.Scale(element, 100, Object.extend({ 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   688
    scaleContent: false, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   689
    scaleX: false, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   690
    scaleFrom: window.opera ? 0 : 1,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   691
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   692
    restoreAfterFinish: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   693
    afterSetup: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   694
      effect.element.makePositioned();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   695
      effect.element.down().makePositioned();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   696
      if (window.opera) effect.element.setStyle({top: ''});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   697
      effect.element.makeClipping().setStyle({height: '0px'}).show(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   698
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   699
    afterUpdateInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   700
      effect.element.down().setStyle({bottom:
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   701
        (effect.dims[0] - effect.element.clientHeight) + 'px' }); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   702
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   703
    afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   704
      effect.element.undoClipping().undoPositioned();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   705
      effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom}); }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   706
    }, arguments[1] || { })
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   707
  );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   708
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   709
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   710
Effect.SlideUp = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   711
  element = $(element).cleanWhitespace();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   712
  var oldInnerBottom = element.down().getStyle('bottom');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   713
  var elementDimensions = element.getDimensions();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   714
  return new Effect.Scale(element, window.opera ? 0 : 1,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   715
   Object.extend({ scaleContent: false, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   716
    scaleX: false, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   717
    scaleMode: 'box',
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   718
    scaleFrom: 100,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   719
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   720
    restoreAfterFinish: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   721
    afterSetup: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   722
      effect.element.makePositioned();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   723
      effect.element.down().makePositioned();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   724
      if (window.opera) effect.element.setStyle({top: ''});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   725
      effect.element.makeClipping().show();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   726
    },  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   727
    afterUpdateInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   728
      effect.element.down().setStyle({bottom:
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   729
        (effect.dims[0] - effect.element.clientHeight) + 'px' });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   730
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   731
    afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   732
      effect.element.hide().undoClipping().undoPositioned();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   733
      effect.element.down().undoPositioned().setStyle({bottom: oldInnerBottom});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   734
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   735
   }, arguments[1] || { })
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   736
  );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   737
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   738
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   739
// Bug in opera makes the TD containing this element expand for a instance after finish 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   740
Effect.Squish = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   741
  return new Effect.Scale(element, window.opera ? 1 : 0, { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   742
    restoreAfterFinish: true,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   743
    beforeSetup: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   744
      effect.element.makeClipping(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   745
    },  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   746
    afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   747
      effect.element.hide().undoClipping(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   748
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   749
  });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   750
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   751
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   752
Effect.Grow = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   753
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   754
  var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   755
    direction: 'center',
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   756
    moveTransition: Effect.Transitions.sinoidal,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   757
    scaleTransition: Effect.Transitions.sinoidal,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   758
    opacityTransition: Effect.Transitions.full
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   759
  }, arguments[1] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   760
  var oldStyle = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   761
    top: element.style.top,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   762
    left: element.style.left,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   763
    height: element.style.height,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   764
    width: element.style.width,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   765
    opacity: element.getInlineOpacity() };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   766
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   767
  var dims = element.getDimensions();    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   768
  var initialMoveX, initialMoveY;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   769
  var moveX, moveY;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   770
  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   771
  switch (options.direction) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   772
    case 'top-left':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   773
      initialMoveX = initialMoveY = moveX = moveY = 0; 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   774
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   775
    case 'top-right':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   776
      initialMoveX = dims.width;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   777
      initialMoveY = moveY = 0;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   778
      moveX = -dims.width;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   779
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   780
    case 'bottom-left':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   781
      initialMoveX = moveX = 0;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   782
      initialMoveY = dims.height;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   783
      moveY = -dims.height;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   784
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   785
    case 'bottom-right':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   786
      initialMoveX = dims.width;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   787
      initialMoveY = dims.height;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   788
      moveX = -dims.width;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   789
      moveY = -dims.height;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   790
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   791
    case 'center':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   792
      initialMoveX = dims.width / 2;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   793
      initialMoveY = dims.height / 2;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   794
      moveX = -dims.width / 2;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   795
      moveY = -dims.height / 2;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   796
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   797
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   798
  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   799
  return new Effect.Move(element, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   800
    x: initialMoveX,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   801
    y: initialMoveY,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   802
    duration: 0.01, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   803
    beforeSetup: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   804
      effect.element.hide().makeClipping().makePositioned();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   805
    },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   806
    afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   807
      new Effect.Parallel(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   808
        [ new Effect.Opacity(effect.element, { sync: true, to: 1.0, from: 0.0, transition: options.opacityTransition }),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   809
          new Effect.Move(effect.element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition }),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   810
          new Effect.Scale(effect.element, 100, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   811
            scaleMode: { originalHeight: dims.height, originalWidth: dims.width }, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   812
            sync: true, scaleFrom: window.opera ? 1 : 0, transition: options.scaleTransition, restoreAfterFinish: true})
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   813
        ], Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   814
             beforeSetup: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   815
               effect.effects[0].element.setStyle({height: '0px'}).show(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   816
             },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   817
             afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   818
               effect.effects[0].element.undoClipping().undoPositioned().setStyle(oldStyle); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   819
             }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   820
           }, options)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   821
      )
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   822
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   823
  });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   824
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   825
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   826
Effect.Shrink = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   827
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   828
  var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   829
    direction: 'center',
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   830
    moveTransition: Effect.Transitions.sinoidal,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   831
    scaleTransition: Effect.Transitions.sinoidal,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   832
    opacityTransition: Effect.Transitions.none
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   833
  }, arguments[1] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   834
  var oldStyle = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   835
    top: element.style.top,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   836
    left: element.style.left,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   837
    height: element.style.height,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   838
    width: element.style.width,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   839
    opacity: element.getInlineOpacity() };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   840
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   841
  var dims = element.getDimensions();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   842
  var moveX, moveY;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   843
  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   844
  switch (options.direction) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   845
    case 'top-left':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   846
      moveX = moveY = 0;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   847
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   848
    case 'top-right':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   849
      moveX = dims.width;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   850
      moveY = 0;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   851
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   852
    case 'bottom-left':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   853
      moveX = 0;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   854
      moveY = dims.height;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   855
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   856
    case 'bottom-right':
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   857
      moveX = dims.width;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   858
      moveY = dims.height;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   859
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   860
    case 'center':  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   861
      moveX = dims.width / 2;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   862
      moveY = dims.height / 2;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   863
      break;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   864
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   865
  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   866
  return new Effect.Parallel(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   867
    [ new Effect.Opacity(element, { sync: true, to: 0.0, from: 1.0, transition: options.opacityTransition }),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   868
      new Effect.Scale(element, window.opera ? 1 : 0, { sync: true, transition: options.scaleTransition, restoreAfterFinish: true}),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   869
      new Effect.Move(element, { x: moveX, y: moveY, sync: true, transition: options.moveTransition })
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   870
    ], Object.extend({            
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   871
         beforeStartInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   872
           effect.effects[0].element.makePositioned().makeClipping(); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   873
         },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   874
         afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   875
           effect.effects[0].element.hide().undoClipping().undoPositioned().setStyle(oldStyle); }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   876
       }, options)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   877
  );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   878
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   879
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   880
Effect.Pulsate = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   881
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   882
  var options    = arguments[1] || { };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   883
  var oldOpacity = element.getInlineOpacity();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   884
  var transition = options.transition || Effect.Transitions.sinoidal;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   885
  var reverser   = function(pos){ return transition(1-Effect.Transitions.pulse(pos, options.pulses)) };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   886
  reverser.bind(transition);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   887
  return new Effect.Opacity(element, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   888
    Object.extend(Object.extend({  duration: 2.0, from: 0,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   889
      afterFinishInternal: function(effect) { effect.element.setStyle({opacity: oldOpacity}); }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   890
    }, options), {transition: reverser}));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   891
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   892
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   893
Effect.Fold = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   894
  element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   895
  var oldStyle = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   896
    top: element.style.top,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   897
    left: element.style.left,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   898
    width: element.style.width,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   899
    height: element.style.height };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   900
  element.makeClipping();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   901
  return new Effect.Scale(element, 5, Object.extend({   
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   902
    scaleContent: false,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   903
    scaleX: false,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   904
    afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   905
    new Effect.Scale(element, 1, { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   906
      scaleContent: false, 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   907
      scaleY: false,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   908
      afterFinishInternal: function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   909
        effect.element.hide().undoClipping().setStyle(oldStyle);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   910
      } });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   911
  }}, arguments[1] || { }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   912
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   913
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   914
Effect.Morph = Class.create(Effect.Base, {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   915
  initialize: function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   916
    this.element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   917
    if (!this.element) throw(Effect._elementDoesNotExistError);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   918
    var options = Object.extend({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   919
      style: { }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   920
    }, arguments[1] || { });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   921
    
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   922
    if (!Object.isString(options.style)) this.style = $H(options.style);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   923
    else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   924
      if (options.style.include(':'))
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   925
        this.style = options.style.parseStyle();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   926
      else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   927
        this.element.addClassName(options.style);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   928
        this.style = $H(this.element.getStyles());
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   929
        this.element.removeClassName(options.style);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   930
        var css = this.element.getStyles();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   931
        this.style = this.style.reject(function(style) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   932
          return style.value == css[style.key];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   933
        });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   934
        options.afterFinishInternal = function(effect) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   935
          effect.element.addClassName(effect.options.style);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   936
          effect.transforms.each(function(transform) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   937
            effect.element.style[transform.style] = '';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   938
          });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   939
        }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   940
      }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   941
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   942
    this.start(options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   943
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   944
  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   945
  setup: function(){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   946
    function parseColor(color){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   947
      if (!color || ['rgba(0, 0, 0, 0)','transparent'].include(color)) color = '#ffffff';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   948
      color = color.parseColor();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   949
      return $R(0,2).map(function(i){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   950
        return parseInt( color.slice(i*2+1,i*2+3), 16 ) 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   951
      });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   952
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   953
    this.transforms = this.style.map(function(pair){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   954
      var property = pair[0], value = pair[1], unit = null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   955
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   956
      if (value.parseColor('#zzzzzz') != '#zzzzzz') {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   957
        value = value.parseColor();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   958
        unit  = 'color';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   959
      } else if (property == 'opacity') {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   960
        value = parseFloat(value);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   961
        if (Prototype.Browser.IE && (!this.element.currentStyle.hasLayout))
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   962
          this.element.setStyle({zoom: 1});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   963
      } else if (Element.CSS_LENGTH.test(value)) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   964
          var components = value.match(/^([\+\-]?[0-9\.]+)(.*)$/);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   965
          value = parseFloat(components[1]);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   966
          unit = (components.length == 3) ? components[2] : null;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   967
      }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   968
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   969
      var originalValue = this.element.getStyle(property);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   970
      return { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   971
        style: property.camelize(), 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   972
        originalValue: unit=='color' ? parseColor(originalValue) : parseFloat(originalValue || 0), 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   973
        targetValue: unit=='color' ? parseColor(value) : value,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   974
        unit: unit
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   975
      };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   976
    }.bind(this)).reject(function(transform){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   977
      return (
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   978
        (transform.originalValue == transform.targetValue) ||
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   979
        (
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   980
          transform.unit != 'color' &&
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   981
          (isNaN(transform.originalValue) || isNaN(transform.targetValue))
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   982
        )
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   983
      )
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   984
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   985
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   986
  update: function(position) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   987
    var style = { }, transform, i = this.transforms.length;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   988
    while(i--)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   989
      style[(transform = this.transforms[i]).style] = 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   990
        transform.unit=='color' ? '#'+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   991
          (Math.round(transform.originalValue[0]+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   992
            (transform.targetValue[0]-transform.originalValue[0])*position)).toColorPart() +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   993
          (Math.round(transform.originalValue[1]+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   994
            (transform.targetValue[1]-transform.originalValue[1])*position)).toColorPart() +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   995
          (Math.round(transform.originalValue[2]+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   996
            (transform.targetValue[2]-transform.originalValue[2])*position)).toColorPart() :
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   997
        (transform.originalValue +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   998
          (transform.targetValue - transform.originalValue) * position).toFixed(3) + 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
   999
            (transform.unit === null ? '' : transform.unit);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1000
    this.element.setStyle(style, true);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1001
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1002
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1003
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1004
Effect.Transform = Class.create({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1005
  initialize: function(tracks){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1006
    this.tracks  = [];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1007
    this.options = arguments[1] || { };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1008
    this.addTracks(tracks);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1009
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1010
  addTracks: function(tracks){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1011
    tracks.each(function(track){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1012
      track = $H(track);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1013
      var data = track.values().first();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1014
      this.tracks.push($H({
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1015
        ids:     track.keys().first(),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1016
        effect:  Effect.Morph,
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1017
        options: { style: data }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1018
      }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1019
    }.bind(this));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1020
    return this;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1021
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1022
  play: function(){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1023
    return new Effect.Parallel(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1024
      this.tracks.map(function(track){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1025
        var ids = track.get('ids'), effect = track.get('effect'), options = track.get('options');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1026
        var elements = [$(ids) || $$(ids)].flatten();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1027
        return elements.map(function(e){ return new effect(e, Object.extend({ sync:true }, options)) });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1028
      }).flatten(),
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1029
      this.options
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1030
    );
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1031
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1032
});
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1033
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1034
Element.CSS_PROPERTIES = $w(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1035
  'backgroundColor backgroundPosition borderBottomColor borderBottomStyle ' + 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1036
  'borderBottomWidth borderLeftColor borderLeftStyle borderLeftWidth ' +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1037
  'borderRightColor borderRightStyle borderRightWidth borderSpacing ' +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1038
  'borderTopColor borderTopStyle borderTopWidth bottom clip color ' +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1039
  'fontSize fontWeight height left letterSpacing lineHeight ' +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1040
  'marginBottom marginLeft marginRight marginTop markerOffset maxHeight '+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1041
  'maxWidth minHeight minWidth opacity outlineColor outlineOffset ' +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1042
  'outlineWidth paddingBottom paddingLeft paddingRight paddingTop ' +
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1043
  'right textIndent top width wordSpacing zIndex');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1044
  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1045
Element.CSS_LENGTH = /^(([\+\-]?[0-9\.]+)(em|ex|px|in|cm|mm|pt|pc|\%))|0$/;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1046
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1047
String.__parseStyleElement = document.createElement('div');
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1048
String.prototype.parseStyle = function(){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1049
  var style, styleRules = $H();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1050
  if (Prototype.Browser.WebKit)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1051
    style = new Element('div',{style:this}).style;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1052
  else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1053
    String.__parseStyleElement.innerHTML = '<div style="' + this + '"></div>';
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1054
    style = String.__parseStyleElement.childNodes[0].style;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1055
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1056
  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1057
  Element.CSS_PROPERTIES.each(function(property){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1058
    if (style[property]) styleRules.set(property, style[property]); 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1059
  });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1060
  
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1061
  if (Prototype.Browser.IE && this.include('opacity'))
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1062
    styleRules.set('opacity', this.match(/opacity:\s*((?:0|1)?(?:\.\d*)?)/)[1]);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1063
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1064
  return styleRules;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1065
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1066
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1067
if (document.defaultView && document.defaultView.getComputedStyle) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1068
  Element.getStyles = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1069
    var css = document.defaultView.getComputedStyle($(element), null);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1070
    return Element.CSS_PROPERTIES.inject({ }, function(styles, property) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1071
      styles[property] = css[property];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1072
      return styles;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1073
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1074
  };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1075
} else {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1076
  Element.getStyles = function(element) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1077
    element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1078
    var css = element.currentStyle, styles;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1079
    styles = Element.CSS_PROPERTIES.inject({ }, function(results, property) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1080
      results[property] = css[property];
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1081
      return results;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1082
    });
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1083
    if (!styles.opacity) styles.opacity = element.getOpacity();
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1084
    return styles;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1085
  };
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1086
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1087
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1088
Effect.Methods = {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1089
  morph: function(element, style) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1090
    element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1091
    new Effect.Morph(element, Object.extend({ style: style }, arguments[2] || { }));
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1092
    return element;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1093
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1094
  visualEffect: function(element, effect, options) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1095
    element = $(element)
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1096
    var s = effect.dasherize().camelize(), klass = s.charAt(0).toUpperCase() + s.substring(1);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1097
    new Effect[klass](element, options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1098
    return element;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1099
  },
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1100
  highlight: function(element, options) {
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1101
    element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1102
    new Effect.Highlight(element, options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1103
    return element;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1104
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1105
};
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1106
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1107
$w('fade appear grow shrink fold blindUp blindDown slideUp slideDown '+
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1108
  'pulsate shake puff squish switchOff dropOut').each(
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1109
  function(effect) { 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1110
    Effect.Methods[effect] = function(element, options){
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1111
      element = $(element);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1112
      Effect[effect.charAt(0).toUpperCase() + effect.substring(1)](element, options);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1113
      return element;
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1114
    }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1115
  }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1116
);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1117
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1118
$w('getInlineOpacity forceRerendering setContentZoom collectTextNodes collectTextNodesIgnoreClass getStyles').each( 
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1119
  function(f) { Effect.Methods[f] = Element[f]; }
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1120
);
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1121
10841abbc01f taggr2, which is starting to shape up
terom
parents:
diff changeset
  1122
Element.addMethods(Effect.Methods);