-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmainMenu.js
More file actions
55 lines (43 loc) · 1.94 KB
/
mainMenu.js
File metadata and controls
55 lines (43 loc) · 1.94 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
54
// Main Menu functions
// This is also a good template for writing imagejs modules.
// The main thing is to keep your code within a function call and not generate global variables.
// use instead imagejs.modules[yourModule].
imagejs.msg('mainMenu loaded'); // to notify via console and div#msg
// Merges both canvases and provides a way to save the image as a PNG file using the FileSaver API.
function handleDownloadImage(ev) {
ev.preventDefault();
document.getElementById('cvBase').getContext('2d').drawImage(document.getElementById('cvTop'),0,0);
imagejs.canvas2Image('cvBase', function (blob) {
saveAs(blob, 'image.png');
});
}
(function(){
var listOfModules={
'Hello world':function(evt){imagejs.loadModule('helloWorld.js')},
'Chromomarkers':function(evt){imagejs.loadModule('mathbiol.chromomarkers.js')},
'Count Shapes':function(evt){imagejs.loadModules(['mathbiol.chromomarkers.js','mathbiol.countshapes.js'])},
'KI67 analysis':function(evt){imagejs.loadModules(['mathbiol.chromomarkers.js','ki67.js'])}
}
var menu={
Load:function(){
console.log('Load Module');
var msg=jmat.gId('msg'); // message div
msg.innerHTML='Load module from <span id=listOfModules></span> or from URL:<input type=text size=50 onkeyup="if(event.keyCode==13)(imagejs.loadModule(this.value))">';
jmat.gId('listOfModules').appendChild(imagejs.menu(listOfModules,'List'));
cvTop.style.left=cvBase.offsetLeft;cvTop.style.top=cvBase.offsetTop; // make sure the two canvas are aligned
},
Save:function(){
console.log('Save Results');
}
}
var name= 'Main Menu';
jmat.gId('menu').appendChild(imagejs.menu(menu,name)); // <-- this
cvTop.style.left=cvBase.offsetLeft;cvTop.style.top=cvBase.offsetTop; // make sure the two canvas are aligned
// --------------
var a = document.createElement('a');
document.body.appendChild(a);
a.id = "dButton";
a.href="";
a.textContent="Download Image";
a.addEventListener('click', handleDownloadImage, false);
})()