@@ -52,25 +52,38 @@ define(["iter2d", "csshelper", "evileval", "net", "ui"], function(iter2d, csshel
52
52
this . currentCode . draw ( context , borders , this . lib ) ;
53
53
} ,
54
54
55
+ toDataUri : function ( jsCode ) {
56
+ return "data:text/javascript;base64," + btoa ( jsCode ) ;
57
+ } ,
58
+
55
59
addCodeStringToEvaluate : function ( codeString ) {
56
- var canvasAnim = this ;
57
60
return new Promise ( function ( resolve , reject ) {
58
- canvasAnim . evaluateCode = function ( ) {
59
- evileval . evalAnimation ( codeString , canvasAnim )
60
- . then ( function ( ) {
61
+ this . evaluateCode = function ( ) {
62
+ var codeAsUri = this . toDataUri ( codeString ) ;
63
+ evileval . loadJsAnim ( codeAsUri )
64
+ . then ( function ( evaluatedAnimationClone ) {
65
+ this . setAnimation ( evaluatedAnimationClone , this . originalUrl ) ;
66
+ this . codeCacheUri = codeAsUri ;
61
67
resolve ( ) ;
62
- } , function ( err ) {
68
+ } . bind ( this ) )
69
+ . catch ( function ( err ) {
63
70
console . log ( err ) ;
64
71
reject ( err ) ;
65
72
} ) ;
66
73
} ;
67
- } ) ;
74
+ } . bind ( this ) ) ;
75
+ } ,
76
+ loadAnim : function ( url ) {
77
+ return evileval . loadJsAnim ( url ) . then ( function ( evaluatedAnimationClone ) {
78
+ this . setAnimation ( evaluatedAnimationClone , url ) ;
79
+ this . codeCacheUri = null ;
80
+ return this ;
81
+ } . bind ( this ) ) ;
68
82
} ,
69
-
70
83
setAnimation : function ( codeToSetup , uri ) {
71
84
this . codeToSetup = codeToSetup ;
72
85
this . animationName = net . extractAnimationNameFromUri ( uri ) ,
73
- this . uri = uri ;
86
+ this . originalUrl = uri ;
74
87
this . setup = function ( ) {
75
88
// force reset matrix
76
89
context . setTransform ( 1 , 0 , 0 , 1 , 0 , 0 ) ;
@@ -83,16 +96,16 @@ define(["iter2d", "csshelper", "evileval", "net", "ui"], function(iter2d, csshel
83
96
84
97
getSourceCodeString : function ( ) {
85
98
//TODO continue refactoring here, see doc.org
86
- if ( this . uri . match ( / ^ d a t a : / ) ) {
99
+ if ( this . codeCacheUri ) {
87
100
// the code is in the cache
88
101
return new Promise ( function ( resolve , reject ) {
89
- var animCodeString = evileval . dataUri2text ( this . uri ) ;
102
+ var animCodeString = evileval . dataUri2text ( this . codeCacheUri ) ;
90
103
resolve ( animCodeString ) ;
91
104
} . bind ( this ) ) ;
92
105
} else {
93
106
// get the code from the internets
94
- return net . HTTPget ( this . uri ) . then ( function ( animCodeString ) {
95
- this . animationName = net . extractAnimationNameFromUri ( this . uri ) ;
107
+ return net . HTTPget ( this . originalUrl ) . then ( function ( animCodeString ) {
108
+ this . animationName = net . extractAnimationNameFromUri ( this . originalUrl ) ;
96
109
this . addCodeStringToEvaluate ( animCodeString ) ;
97
110
return animCodeString ;
98
111
} . bind ( this ) ) ;
@@ -161,7 +174,7 @@ define(["iter2d", "csshelper", "evileval", "net", "ui"], function(iter2d, csshel
161
174
} ) . then ( function ( animationName ) {
162
175
if ( animationName ) {
163
176
var fileUri = store . animationNameToUri ( animationName ) ;
164
- return evileval . loadJsAnimOnCanvasAnim ( fileUri , canvasAnim , animationName ) ;
177
+ return canvasAnim . loadAnim ( fileUri ) ;
165
178
} else {
166
179
throw "no animation name" ;
167
180
}
@@ -236,9 +249,7 @@ define(["iter2d", "csshelper", "evileval", "net", "ui"], function(iter2d, csshel
236
249
cell = makeCell ( row , col , height , width ) ;
237
250
cell . canvasAnim = makeCanvasAnimation ( cell . context ) ;
238
251
addCellUiListeners ( cell . ui , cell . canvasAnim , store ) ;
239
- // TODO the next two lines should be a function on canvasAnim
240
- var animationName = store . uriToAnimationName ( animUri ) ;
241
- evileval . loadJsAnimOnCanvasAnim ( animUri , cell . canvasAnim , animationName ) ;
252
+ cell . canvasAnim . loadAnim ( animUri ) ;
242
253
return cell ;
243
254
} ) ;
244
255
0 commit comments