-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_page.coffee
207 lines (166 loc) · 4.15 KB
/
view_page.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
cookie = require './cookie'
isString = (obj) -> toString.call(obj) == "[object #{name}]"
fontsLoaded = false
resize = ->
return unless fontsLoaded
$('.fittext').fitText('clear').fitText()
fullscreenOverlay.fit()
$sections = $('.sections')
$window = $(window)
$html = $('html')
if $sections.outerHeight() > $window.height()
$html.addClass('scroll').removeClass('noscroll')
else
$html.removeClass('scroll').addClass('noscroll')
# this is unfortunately duplicated in app/previews/base.coffee
$placeholders = $('.placeholder')
$placeholders.each (i, el) ->
$el = $ el
width = $el.width()
#size = parseInt(width/4, 10)
size = 60
size = 30 if width < 60*3
$el.css 'font-size', "#{size}px"
pww = null
pwh = null
ppw = null
pph = null
detectChange = ->
$window = $ window
ww = $window.width()
wh = $window.height()
$sections = $ '.sections'
pw = $sections.width()
ph = $sections.height()
changed = pww != ww or pwh != wh or ppw != pw or pph != ph
pww = ww
pwh = wh
ppw = pw
pph = ph
changed
poll = ->
setTimeout ->
resize() if detectChange()
poll()
, 100
keydown = (e) ->
if e.which == 27
return if fullscreenOverlay.hide()
setupPreviewNotification = ->
return unless $('meta[content=noindex]').length # preview only
css = """
.bar {
display: none;
position: fixed;
z-index: 1000;
top: 0;
left: 0;
right: 0;
}
.with-bar .bar {
display: -webkit-flex;
display: -moz-flex;
display: -ms-flexbox;
display: -ms-flex;
display: flex;
}
.bar-button {
font-family: "roboto condensed", "helevetica neue", arial, sans-serif;
font-size: 13px;
line-height: 20px;
color: #333;
padding: 4px 8px;
margin: 0;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.bar-button a {
color: #222;
text-decoration: underline;
}
.bar-button,
.bar-spacer {
background-color: #ffc;
height: 28px;
position: relative;
box-sizing: border-box;
-moz-box-sizing: border-box;
}
.bar-button:after,
.bar-spacer:after {
content: '';
position: absolute;
left: 0;
right: 0;
bottom: -4px;
border-bottom: 4px solid rgba(0, 0, 0, 0.1);
}
button.bar-button {
border: none;
cursor: pointer;
}
.bar-button i {
line-height: 23px;
}
.bar-spacer {
-webkit-flex: 1;
-moz-flex: 1;
-ms-flex: 1;
flex: 1;
}
* + .bar-button {
margin-left: 1px;
}
"""
$title = $ 'title'
version = $title.data('version')
title = $title.html()
editURL = $('link[rel=edit]').attr('href') ? '#'
$html = $ 'html'
$html.addClass('with-bar')
$style = $ '<style>'+css+'</style>'
$html.find('head').append($style)
$bar = $ '<div class="bar"></div>'
$remove = $ '<button class="bar-button remove-bar"></button>'
$remove.html '<i class="ss-delete"></i>'
$version = $ '<div class="bar-button">You are viewing version '+
version+' of </div>'
$edit = $ '<a href="'+editURL+'">'+title+'</a>'
$version.append $edit
$version.append '.'
$bar.append $version
$version.addClass 'bar-spacer'
$bar.append $remove
$('body').prepend($bar)
$('body > .bar .remove-bar').click ->
$html.removeClass 'with-bar'
$('body > .bar').remove()
resize()
module.exports.init = (options) ->
# keep original referrer and query string for analytics
unless cookie.get('referrer')? and cookie.get('query')?
cookie.set 'referrer', document.referrer
cookie.set 'query', location.search
$(document).keydown keydown
$('[data-embed]').click (e) ->
return unless e.which == 1 # skip anything except left click
return if e.ctrlKey or e.metaKey # skip ctrl-click or cmd-click
e.preventDefault()
fullscreenOverlay.show $(e.currentTarget).data('embed')
setupPreviewNotification()
# load fonts
if options.families.length
WebFont.load
google:
families: options.families
active: ->
fontsLoaded = true
resize()
setTimeout ->
resize()
, 1000
else
# resize immediately, because no fonts have to load
fontsLoaded = true
resize()
poll()