includes/clientside/static/flyin.js
changeset 1125 367768040a61
parent 420 301f546688d1
child 1227 bdac73ed481e
equal deleted inserted replaced
1124:1e956881d362 1125:367768040a61
     8 var FI_BOTTOM = 2;
     8 var FI_BOTTOM = 2;
     9 var FI_IN = 1;
     9 var FI_IN = 1;
    10 var FI_OUT = 2;
    10 var FI_OUT = 2;
    11 var FI_UP = 1;
    11 var FI_UP = 1;
    12 var FI_DOWN = 2;
    12 var FI_DOWN = 2;
       
    13 // increase to slow down transitions (for debug)
       
    14 var FI_MULTIPLIER = 1;
    13 
    15 
    14 /**
    16 /**
    15  * You can thank Robert Penner for the math used here. Ported from an ActionScript class.
    17  * You can thank Robert Penner for the math used here. Ported from an ActionScript class.
    16  * License: Modified BSD license <http://www.robertpenner.com/easing_terms_of_use.html>
    18  * License: Modified BSD license <http://www.robertpenner.com/easing_terms_of_use.html>
    17  */
    19  */
    66 
    68 
    67 function fly_core(element, nofade, origin, direction, height_taken_care_of)
    69 function fly_core(element, nofade, origin, direction, height_taken_care_of)
    68 {
    70 {
    69   if ( !element || typeof(element) != 'object' )
    71   if ( !element || typeof(element) != 'object' )
    70     return false;
    72     return false;
       
    73   
       
    74   // force to array
       
    75   if ( !element.length )
       
    76     element = [ element ];
       
    77   
    71   // target dimensions
    78   // target dimensions
    72   var top, left;
    79   var top, left;
    73   // initial dimensions
    80   // initial dimensions
    74   var topi, lefti;
    81   var topi, lefti;
    75   // current dimensions
    82   // current dimensions
    79   var h = getHeight();
    86   var h = getHeight();
    80   var y = parseInt ( getScrollOffset() );
    87   var y = parseInt ( getScrollOffset() );
    81   // temp vars
    88   // temp vars
    82   var dim, off, diff, dist, ratio, opac_factor;
    89   var dim, off, diff, dist, ratio, opac_factor;
    83   // setup element
    90   // setup element
    84   element.style.position = 'absolute';
    91   for ( var i = 0; i < element.length; i++ )
       
    92     element[i].style.position = 'absolute';
    85   
    93   
    86   dim = [ $dynano(element).Height(), $dynano(element).Width() ];
    94   dim = [ $dynano(element[0]).Height(), $dynano(element[0]).Width() ];
    87   off = [ $dynano(element).Top(), $dynano(element).Left() ];
    95   off = [ $dynano(element[0]).Top(), $dynano(element[0]).Left() ];
    88   
    96   
    89   if ( height_taken_care_of )
    97   if ( height_taken_care_of )
    90   {
    98   {
    91     top = off[0];
    99     top = off[0];
    92     left = off[1];
   100     left = off[1];
   125   var diff_top = top - topi;
   133   var diff_top = top - topi;
   126   var diff_left = left - lefti;
   134   var diff_left = left - lefti;
   127   
   135   
   128   var frames = 100;
   136   var frames = 100;
   129   var timeout = 0;
   137   var timeout = 0;
   130   var timerstep = 8;
   138   var timerstep = 8 * FI_MULTIPLIER;
   131   
   139   
   132   // cache element so it can be changed from within setTimeout()
   140   // cache element so it can be changed from within setTimeout()
   133   var rand_seed = Math.floor(Math.random() * 1000000);
   141   var rand_seed = Math.floor(Math.random() * 1000000);
   134   fly_in_cache[rand_seed] = element;
   142   fly_in_cache[rand_seed] = element;
   135   
   143   
   136   for ( var i = 0; i < frames; i++ )
   144   for ( var i = 0; i < frames; i++ )
   137   {
   145   {
   138     topc = GlideEffect.easeInOut(i, topi, diff_top, frames);
   146     topc = GlideEffect.easeInOut(i, topi, diff_top, frames);
   139     leftc = GlideEffect.easeInOut(i, lefti, diff_left, frames);
   147     leftc = GlideEffect.easeInOut(i, lefti, diff_left, frames);
   140     var code = 'var o = fly_in_cache['+rand_seed+']; o.style.top=\''+topc+'px\';';
   148     
       
   149     var code = 'var element = fly_in_cache[' + rand_seed + '];' + "\n";
       
   150     code +=    'for ( var i = 0; i < element.length; i++ )' + "\n";
       
   151     code +=    '{' + "\n";
       
   152     code +=    '  element[i].style.top = "' + topc + 'px";' + "\n";
   141     if ( !height_taken_care_of )
   153     if ( !height_taken_care_of )
   142       code += ' o.style.left=\''+leftc+'px\'';
   154       code +=  '  element[i].style.left = "' + leftc + 'px";' + "\n";
   143     code += ';';
   155     code +=    '}';
       
   156     
   144     setTimeout(code, timeout);
   157     setTimeout(code, timeout);
       
   158     
   145     timeout += timerstep;
   159     timeout += timerstep;
   146     
   160     
   147     var ratio = i / frames;
   161     var ratio = i / frames;
   148     
   162     
   149     if ( !nofade )
   163     if ( !nofade )
   150     {
   164     {
   151       // handle fade
   165       // handle fade
   152       var opac_factor = ratio * 100;
   166       var opac_factor = ratio * 100;
   153       if ( direction == FI_OUT )
   167       if ( direction == FI_OUT )
   154         opac_factor = 100 - opac_factor;
   168         opac_factor = 100 - opac_factor;
   155       setTimeout('var o = fly_in_cache['+rand_seed+']; domObjChangeOpac('+opac_factor+', o);', timeout);
   169       
       
   170       var code = 'var element = fly_in_cache[' + rand_seed + '];' + "\n";
       
   171       code +=    'for ( var i = 0; i < element.length; i++ )' + "\n";
       
   172       code +=    '{' + "\n";
       
   173       code +=    '  domObjChangeOpac(' + opac_factor + ', element[i]);' + "\n";
       
   174       code +=    '}';
       
   175       
       
   176       setTimeout(code, timeout);
   156     }
   177     }
   157     
   178     
   158   }
   179   }
   159   
   180   
   160   // old framestepper code removed from here in Loch Ness
   181   // old framestepper code removed from here in Loch Ness