I am migrating a html site into a Ionic app.
The html site uses a legacy javascript animation runtime file called "Swiffy":http://www.gstatic.com/swiffy/v5.4/runtime.js
Generally this is how it was used in the old site:
1) Including the runtime and declare a swiffyObject with a bunch of generated code.
<script type="text/javascript" src="...path/to/swiffy.js"></script>
<script>swiffyobject = {"internedStrings":["::::50g2s..... a bunch of really long code...</script>
2) Start the Swiffy object when document is ready
$(document).ready(function(){
var stage = new swiffy.Stage(document.getElementById('swiffycontainer'),swiffyobject);
stage.setBackground(null);
stage.start();
....
I tried to do the same in a brand new Ionic 2 project:
1) Including the script in src/index.html
<script type="text/javascript" src="...path/to/swiffy.js"></script>
<script>swiffyobject = {"internedStrings":["::::50g2s..... a bunch of really long code...</script>
2) Insert the script in Homepage ionViewDidLoad:
ionViewDidLoad() {
var stage = new swiffy.Stage(document.getElementById('swiffycontainer'),swiffyobject);
stage.setBackground(null);
stage.start();
}
Unfortunately, it doesnt work. When running ionic serve, two errors happen:
Cannot find name 'swiffy'.
Cannot find name 'swiffyobject'.
I am a newbie in Angular 2, I am quite sure the homepage typescript file is not aware of the global variables swifft and swiffyobject declared in the index.html
I tried this:
var stage = new window["swiffy"].Stage(document.getElementById('swiffycontainer'),window["swiffyobject");
stage.setBackground(null);
stage.start();
}
No Typescript compilation but it doesnt work too, complaining Cannot read property 'Stage' of undefined
How can I get the variables declared in index.html?