Permalink
Browse files

Change Effect.Base#render not to use eval(), so certain JavaScript ru…

…ntime environments (like Adobe AIR) that do not support eval() work. [King Maxemilian, John-David Dalton] [#20 state:resolved]
  • Loading branch information...
1 parent b352e2b commit efb38b665f9e5c48a5179f249f926e96c18ddee7 @madrobby madrobby committed Jul 24, 2008
Showing with 34 additions and 13 deletions.
  1. +2 −0 CHANGELOG
  2. +24 −12 src/effects.js
  3. +8 −1 test/functional/effects_test.html
View
@@ -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]
View
@@ -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)
@@ -37,7 +37,10 @@
<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">
@@ -60,6 +63,10 @@
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>

0 comments on commit efb38b6

Please sign in to comment.