-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrowserZoom.js
94 lines (78 loc) · 2.72 KB
/
BrowserZoom.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
91
92
93
94
define( ['jquery', 'text!./prova.css'],
function ( $, cssContent ) {
'use strict';
$( "<style>" ).html(cssContent).appendTo( "head" );
return {
initialProperties: {
qListObjectDef: {
qShowAlternatives: true,
qFrequencyMode: "V",
qSortCriterias: {
qSortByState: 1
},
qInitialDataFetch: [{
qWidth: 2,
qHeight: 50
}]
},
fixed: true,
width: 25,
percent: true,
selectionMode: "CONFIRM"
},
//Paint resp.Rendering logic
paint: function ( $element, layout ) {
console.log("Layout ID:"+layout.qInfo.qId)
var id = layout.qInfo.qId + '_ZoomIn';
var $zoomIN = $( '#' + id);
if ( !$zoomIN.length ) {
//console.log( 'No element found with the given Id, so create the element' );
$zoomIN = $( document.createElement( 'button' ) );
$zoomIN.attr( 'id', id );
$zoomIN.html( '+' );
$zoomIN.attr("class", "zoombutton");
$element.append( $zoomIN );
var $zoomLabel = $( document.createElement('h1') )
$zoomLabel.html('ZOOM')
$zoomLabel.attr("class", "zoomlabel")
$element.append($zoomLabel);
} else {
//DO NOTHING $button.html( 'You just resized it' );
}
var id = layout.qInfo.qId + '_ZoomOut';
var $zoomOUT = $( '#' + id );
if ( !$zoomOUT.length ) {
//console.log( 'No element found with the given Id, so create the element' );
$zoomOUT = $( document.createElement( 'button' ) );
$zoomOUT.attr( 'id', id );
$zoomOUT.html( '-' );
$zoomOUT.addClass("zoombutton");
$element.append( $zoomOUT );
} else {
//DO NOTHING
}
$zoomIN.click(function(){zoomPage(10)});
$zoomOUT.click(function(){zoomPage(-10)});
var zoomLevel = 100;
function zoomPage(step){
zoomLevel = zoomLevel + step;
document.body.style.zoom = zoomLevel.toString() + "%"
};
var windowWidth = $(window).width();
var windowHeight = $(window).height();
$(window).resize(function(){
var newWidth = $(window).width();
var newHeight = $(window).height();
// windowWidth & windowHeight are automatically updated when the browser size is modified
var widthDiff = newWidth - windowWidth;
var heightDiff = newHeight - windowHeight;
if(widthDiff > 100 || heightDiff > 100){zoomLevel = zoomLevel + 10;}
else if(widthDiff < 100 || heightDiff < 100){zoomLevel = zoomLevel - 10};
document.body.style.zoom = zoomLevel.toString() + "%"
windowWidth = $(window).width();
windowHeight = $(window).height()
});
console.log(windowWidth, windowHeight)
}
};
} );