fix($demos): Refactor demo code

The JavaScript parts are at the top, and the template
is at the bottom. Makes the whole thing more friendly/readable/understandable.