-
Notifications
You must be signed in to change notification settings - Fork 1
/
pokemon.coffee
58 lines (48 loc) · 1.59 KB
/
pokemon.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
pokemon = (name, link, options)->
pokemonsList = [
'pikachu', 'aerodactyl',
'alakazam', 'bulbasaur',
'charmander'
]
if !name
name = pokemonsList[Math.floor(Math.random() * pokemonsList.length)];
if name and link
html = '<div class="pokemonBlock">
<a href="@pokemonHref" target="_blank">
<div id="@pokemonId">
<img src="https://antirek.github.io/pokemon/pokemons/@pokemonName.gif">
</div>
</a>
</div>'
if !options
options = {}
if options and options.id
id = options.id
else
id = "pokemon" + Date.now()
css = '
#@pokemonId {
position: fixed !important;
top: @pokemonTop;
left: @pokemonLeft;
right: @pokemonRight;
bottom: @pokemonBottom;
z-index: 1000000 !important;
}'
css = css
.replace '@pokemonId', id
.replace '@pokemonTop', options.top || ''
.replace '@pokemonLeft', options.left || ''
.replace '@pokemonRight', options.right || ''
.replace '@pokemonBottom', options.bottom || ''
style = document.createElement "style"
style.setAttribute 'type', 'text/css'
style.appendChild document.createTextNode css
document.body.appendChild style
component = document.createElement "div"
html = html
.replace '@pokemonHref', link
.replace '@pokemonId', id
.replace '@pokemonName', name || 'pikachu'
component.innerHTML = html
document.body.appendChild component