public
Description: script.aculo.us is an open-source JavaScript framework for visual effects and interface behaviours.
Homepage: http://script.aculo.us/
Clone URL: git://github.com/madrobby/scriptaculous.git
Click here to lend your support to: scriptaculous and make a donation at www.pledgie.com !
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] [#20 state:resolved]
madrobby (author)
Thu Jul 24 15:16:55 -0700 2008
commit  efb38b665f9e5c48a5179f249f926e96c18ddee7
tree    68fcdafb657db4e7760a8fa4eb7638fac992438d
parent  b352e2b5c05a0a0642cc05cb896780cd5ca01f3e
...
 
 
1
2
3
...
1
2
3
4
5
0
@@ -1,3 +1,5 @@
0
+* 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]
0
+
0
 * 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]
0
 
0
 * 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]
...
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
259
260
261
...
244
245
246
 
 
 
 
 
 
 
 
 
 
 
 
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
0
@@ -244,18 +244,30 @@ Effect.Base = Class.create({
0
     this.totalTime    = this.finishOn-this.startOn;
0
     this.totalFrames  = this.options.fps*this.options.duration;
0
     
0
-    eval('this.render = function(pos){ '+
0
-      'if (this.state=="idle"){this.state="running";'+
0
-      codeForEvent(this.options,'beforeSetup')+
0
-      (this.setup ? 'this.setup();':'')+ 
0
-      codeForEvent(this.options,'afterSetup')+
0
-      '};if (this.state=="running"){'+
0
-      'pos=this.options.transition(pos)*'+this.fromToDelta+'+'+this.options.from+';'+
0
-      'this.position=pos;'+
0
-      codeForEvent(this.options,'beforeUpdate')+
0
-      (this.update ? 'this.update(pos);':'')+
0
-      codeForEvent(this.options,'afterUpdate')+
0
-      '}}');
0
+    this.render = (function() {
0
+      function dispatch(effect, eventName) {
0
+        if (effect.options[eventName + 'Internal'])
0
+          effect.options[eventName + 'Internal'](effect);
0
+        if (effect.options[eventName])
0
+          effect.options[eventName](effect);
0
+      }
0
+
0
+      return function(pos) {
0
+        if (this.state === "idle") {
0
+          this.state = "running";
0
+          dispatch(this, 'beforeSetup');
0
+          if (this.setup) this.setup();
0
+          dispatch(this, 'afterSetup');
0
+        }
0
+        if (this.state === "running") {
0
+          pos = (this.options.transition(pos) * this.fromToDelta) + this.options.from;
0
+          this.position = pos;
0
+          dispatch(this, 'beforeUpdate');
0
+          if (this.update) this.update(pos);
0
+          dispatch(this, 'afterUpdate');
0
+        }
0
+      }
0
+    })();
0
     
0
     this.event('beforeStart');
0
     if (!this.options.sync)
...
37
38
39
40
 
 
 
 
41
42
43
...
60
61
62
 
 
 
 
63
64
65
...
37
38
39
 
40
41
42
43
44
45
46
...
63
64
65
66
67
68
69
70
71
72
0
@@ -37,7 +37,10 @@
0
 <div id="d5" style="width:100px;height:100px;background-color:#dde;" onclick="Effect.Puff(this)">
0
   click to test puff
0
 </div>
0
-<a href="#" onclick="Element.show('d5'); return false;">show puff div again</a>
0
+<p>
0
+  update callbacks: <span id="d5_after">(waiting)</span> -- <span id="d5_before">(waiting)</span>
0
+</p>
0
+<a href="#" onclick="$('d5').appear({beforeUpdate:before,afterUpdate:after}); return false;">show puff div again</a>
0
 
0
 <a href="#" onclick="Effect.Appear('d6')">test appear</a>
0
 <div id="d6" style="width:100px;height:100px;background-color:#dde;display:none">
0
@@ -60,6 +63,10 @@
0
   new Effect.Highlight("d2",{startcolor:"#000000"});
0
   new Effect.Grow("d3",{duration:5.0,direction: 'bottom-right',opacityTransition:Effect.Transitions.linear});
0
   new Effect.BlindDown("d1");
0
+  
0
+  var afterUpdates = 0, beforeUpdates = 0;
0
+  function after(){ afterUpdates++; $('d5_after').update(afterUpdates); }
0
+  function before(){ beforeUpdates--; $('d5_before').update(beforeUpdates); }
0
 // ]]>
0
 </script>    
0
 

Comments