-
Notifications
You must be signed in to change notification settings - Fork 687
Expand file tree
/
Copy pathimage.ts
More file actions
53 lines (42 loc) · 1.59 KB
/
Copy pathimage.ts
File metadata and controls
53 lines (42 loc) · 1.59 KB
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
import { addHeader, addFooter } from './functions'
import Print from './print'
import Browser from './browser'
export default {
print: (params, printFrame) => {
// Check if we are printing one image or multiple images
if (params.printable.constructor !== Array) {
// Create array with one image
params.printable = [params.printable]
}
// Create printable element (container)
params.printableElement = document.createElement('div')
// Create all image elements and append them to the printable container
params.printable.forEach(src => {
// Create the image element
const img = document.createElement('img')
img.setAttribute('style', params.imageStyle)
// Set image src with the file url
img.src = src
// The following block is for Firefox, which for some reason requires the image's src to be fully qualified in
// order to print it
if (Browser.isFirefox()) {
const fullyQualifiedSrc = img.src
img.src = fullyQualifiedSrc
}
// Create the image wrapper
const imageWrapper = document.createElement('div')
// Append image to the wrapper element
imageWrapper.appendChild(img)
// Append wrapper to the printable element
params.printableElement.appendChild(imageWrapper)
})
// Check if we are adding a print header
if (params.header) addHeader(params.printableElement, params)
// Check if we are adding a print footer
if (params.footer) {
addFooter(params.printableElement, params)
}
// Print image
Print.send(params, printFrame)
}
}