Skip to content

Commit

Permalink
Change Effect.Base#render not to use eval(), so certain JavaScript ru…
Browse files Browse the repository at this point in the history
…ntime environments (like Adobe AIR) that do not support eval() work. [King Maxemilian, John-David Dalton] [madrobby#20 state:resolved]
  • Loading branch information
madrobby committed Jul 24, 2008
1 parent b352e2b commit efb38b6
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
@@ -1,3 +1,5 @@
* Change Effect.Base#render not to use eval(), so certain JavaScript runtime environments (like Adobe AIR) that do not support eval() work. [King Maxemilian, John-David Dalton]

* Fixed a calculation error in Effect.Transitions.pulse that could lead to flickering, add easing and change it to be a normal 0 to 1 transition that can be used with any effects; Effect.Pulsate now uses its own implementation. [Thomas Fuchs]

* Fixed Effect.ScrollTo. Changeset 8686 had a typo, document.viewport.getScrollOffsets[0] is always undefined. Removed the max check as it is not a cross-browser way to get scroll height and breaks the effect. Depending on scrollTo to do the right thing. Closes #11306. [Nick Stakenburg]
Expand Down
36 changes: 24 additions & 12 deletions src/effects.js
Expand Up @@ -244,18 +244,30 @@ Effect.Base = Class.create({
this.totalTime = this.finishOn-this.startOn;
this.totalFrames = this.options.fps*this.options.duration;

eval('this.render = function(pos){ '+
'if (this.state=="idle"){this.state="running";'+
codeForEvent(this.options,'beforeSetup')+
(this.setup ? 'this.setup();':'')+
codeForEvent(this.options,'afterSetup')+
'};if (this.state=="running"){'+
'pos=this.options.transition(pos)*'+this.fromToDelta+'+'+this.options.from+';'+
'this.position=pos;'+
codeForEvent(this.options,'beforeUpdate')+
(this.update ? 'this.update(pos);':'')+
codeForEvent(this.options,'afterUpdate')+
'}}');
this.render = (function() {
function dispatch(effect, eventName) {
if (effect.options[eventName + 'Internal'])
effect.options[eventName + 'Internal'](effect);
if (effect.options[eventName])
effect.options[eventName](effect);
}

return function(pos) {
if (this.state === "idle") {
this.state = "running";
dispatch(this, 'beforeSetup');
if (this.setup) this.setup();
dispatch(this, 'afterSetup');
}
if (this.state === "running") {
pos = (this.options.transition(pos) * this.fromToDelta) + this.options.from;
this.position = pos;
dispatch(this, 'beforeUpdate');
if (this.update) this.update(pos);
dispatch(this, 'afterUpdate');
}
}
})();

this.event('beforeStart');
if (!this.options.sync)
Expand Down
9 changes: 8 additions & 1 deletion test/functional/effects_test.html
Expand Up @@ -37,7 +37,10 @@ <h2>Effect.Highlight</h2>
<div id="d5" style="width:100px;height:100px;background-color:#dde;" onclick="Effect.Puff(this)">
click to test puff
</div>
<a href="#" onclick="Element.show('d5'); return false;">show puff div again</a>
<p>
update callbacks: <span id="d5_after">(waiting)</span> -- <span id="d5_before">(waiting)</span>
</p>
<a href="#" onclick="$('d5').appear({beforeUpdate:before,afterUpdate:after}); return false;">show puff div again</a>

<a href="#" onclick="Effect.Appear('d6')">test appear</a>
<div id="d6" style="width:100px;height:100px;background-color:#dde;display:none">
Expand All @@ -60,6 +63,10 @@ <h2>Effect.Highlight</h2>
new Effect.Highlight("d2",{startcolor:"#000000"});
new Effect.Grow("d3",{duration:5.0,direction: 'bottom-right',opacityTransition:Effect.Transitions.linear});
new Effect.BlindDown("d1");

var afterUpdates = 0, beforeUpdates = 0;
function after(){ afterUpdates++; $('d5_after').update(afterUpdates); }
function before(){ beforeUpdates--; $('d5_before').update(beforeUpdates); }
// ]]>
</script>

Expand Down

0 comments on commit efb38b6

Please sign in to comment.