-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
90 lines (73 loc) · 2.67 KB
/
main.js
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
import $ from 'jquery'
import g from './mvarstore.js'
import managerBoxesMeasures from './managerBoxesMeasures.js'
const headerHeight = 80 //px
const sideDivWidth = 80 //px
const sideDivHeight = 50 //px
const sideDivMargin = 10 //px
const paper = $('#paper')
const printArea = $('#printArea')
const topSide = $('#topSide')
const leftSide = $('#leftSide')
const rightSide = $('#rightSide')
const bottomSide = $('#bottomSide')
$('header').height(headerHeight)
function setLanguage(language) {
if(language.startsWith('de')){
$('title').html('Erstelle ein Photo Raster')
$(':lang(de)').show()
$(':lang(en)').hide()
}else{
$('title').html('create a photo raster')
$(':lang(en)').show()
$(':lang(de)').hide()
}
}
setLanguage(navigator.language || navigator.userLanguage)
$('#englishLanguageButton').click( () => {setLanguage('en')} )
$('#germanLanguageButton').click( () => {setLanguage('de')} )
topSide.height(sideDivHeight).width('100%').css('top', -sideDivHeight - sideDivMargin)
leftSide.width(sideDivWidth).height('100%').css('left', -sideDivWidth - sideDivMargin)
rightSide.width(sideDivWidth).height('100%').css('right', -sideDivWidth - sideDivMargin)
bottomSide.height(sideDivHeight).width('100%').css('bottom', -sideDivHeight - sideDivMargin)
g.on_paperWidth_changed( () => {
paper.trigger('mlayout')
printArea.trigger('mlayout')})
g.on_paperHeight_changed( () => {
paper.trigger('mlayout')
printArea.trigger('mlayout')})
g.on_printerMargin_changed( () => { printArea.trigger('mlayout') })
$(window).on('resize', function(){
//center paper in body
const mleft = 0.5 * ($(window).width() - paper.width())
paper.css('left', Math.max(sideDivWidth + sideDivMargin, mleft))
const mtop = 0.5 * ($(window).height() - paper.height())
paper.css('top', Math.max(sideDivHeight + sideDivMargin + headerHeight + 20, mtop))
})
paper.on('mlayout', function(e){
e.stopPropagation()
e.preventDefault()
$(this)
.width(g.paperWidth() + 'mm')
.height(g.paperHeight() + 'mm')
})
printArea.on('mlayout', function(e){
e.stopPropagation()
e.preventDefault()
$(this)
.css('left', g.printerMargin() + 'mm')
.css('top', g.printerMargin() + 'mm')
.width(g.printWidth() + 'mm')
.height(g.printHeight() + 'mm')
})
$('#plusColumn').on('click', () => { g.columns(g.columns() + 1) })
$('#minusColumn').on('click', () => { g.columns(Math.max(1, g.columns() - 1)) })
$('#plusRow').on('click', () => { g.rows(g.rows() + 1) })
$('#minusRow').on('click', () => { g.rows(Math.max(1, g.rows() - 1)) })
managerBoxesMeasures({$, topSide, leftSide, rightSide, bottomSide, boxContainer: printArea, g})
$(document).ready(function(){
g.rows(4)
g.columns(3)
g.paperWidth(g.paperWidth())
$(window).trigger('resize')
})