Skip to content

Commit bf72fcd

Browse files
committed
Add #on method
1 parent 13c3dae commit bf72fcd

4 files changed

Lines changed: 92 additions & 3 deletions

File tree

dist/jsframe-1.4.0.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<!--
5+
JSFrame Examples
6+
Copyright 2007-2019 Tom Misawa, riversun.org@gmail.com
7+
-->
8+
<title>JsFrame.js example</title>
9+
10+
<meta charset="utf-8">
11+
<meta name="description" content="A javascript popup/floating window library.">
12+
13+
</head>
14+
<body style="background: url('http://upload.wikimedia.org/wikipedia/commons/d/d6/Half_Dome_from_Glacier_Point%2C_Yosemite_NP_-_Diliff.jpg') 50% no-repeat fixed; background-size: cover;">
15+
16+
<div style="color:#666666">
17+
<a href="https://github.com/riversun/JSFrame.js">JSFrame.js</a> Example:preset style 'yosemite'
18+
</div>
19+
<script src="../../jsframe.js"></script>
20+
21+
<script>
22+
function start() {
23+
24+
const jsFrame = new JSFrame();
25+
26+
const frames = [];
27+
for (let i = 0; i < 3; i++) {
28+
const yosemiteStyle = jsFrame.createPresetStyle('yosemite');
29+
const frame = jsFrame.createFrame(20 + 320 * i, 40, 300, 200, yosemiteStyle).setTitle(`Window${i}`)
30+
const innerHTML = `<div id="my_element" style="padding:10px;font-size:12px;color:darkgray;">Contents of window${i}</div>`;
31+
frame.setHTML(innerHTML);
32+
frame.setMinFrameSize(160, 100);
33+
frame.getFrameView().style.backgroundColor = "rgba(255,255,255,0.9)";
34+
35+
frame.on('minimizeButton', 'click', (frm) => {
36+
console.log(frm)
37+
const size = frm.getSize();
38+
frm.setSize(size.width - 20, size.height - 20);
39+
});
40+
41+
frame.on('zoomButton', 'click', (frm) => {
42+
console.log(frm)
43+
const size = frm.getSize();
44+
frm.setSize(size.width + 20, size.height + 20);
45+
});
46+
47+
48+
frame.show();
49+
frames.push(frame);
50+
51+
}
52+
53+
frames[0].requestFocus();
54+
}
55+
56+
start();
57+
</script>
58+
59+
</body>
60+
</html>

public/index.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,20 @@
66
</head>
77
<body>
88
<h1>Example of jsFrame.js</h1>
9-
<a href="examples/ex00/index.html">Example 00</a><br>
9+
10+
11+
12+
13+
14+
<a href="examples/ex00/index.html">Simple</a><br>
15+
<a href="examples/ex00/iframe.html">Use Iframe</a><br>
16+
<a href="examples/ex00/modal.html">Modal Window</a><br>
17+
<a href="examples/ex00/modify_content.html">Modify content</a><br>
18+
<a href="examples/ex00/multi_window.html">Show multi-window</a><br>
19+
<a href="examples/ex00/preset_style.html">Use preset style</a><br>
20+
<a href="examples/ex00/preset_yosemite.html">Use preset style 'yosemite'</a><br>
21+
22+
1023
<a href="examples/ex01/index.html">Example 01</a><br>
1124
<a href="examples/ex02/index.html">Example 02</a> <br>
1225
<a href="examples/ex03/index.html">Example 03</a> <br>

src/JSFrame.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,17 @@ CFrame.prototype.getFrameComponentElement = function (id) {
10701070
}
10711071
};
10721072

1073+
CFrame.prototype.on = function (id, eventType, callbackFunc) {
1074+
var me = this;
1075+
var component = me.getFrameComponentElement(id);
1076+
if (component) {
1077+
component.addEventListener(eventType, e => {
1078+
callbackFunc(me);
1079+
});
1080+
}
1081+
1082+
}
1083+
10731084
CFrame.prototype.removeFrameComponentById = function (frameComponentId) {
10741085
var me = this;
10751086

@@ -1368,6 +1379,11 @@ CFrame.prototype.getHeight = function () {
13681379
return parseInt(me.htmlElement.style.height, 10);
13691380
};
13701381

1382+
CFrame.prototype.getSize = function () {
1383+
var me = this;
1384+
return {width: me.getWidth(), height: me.getHeight()};
1385+
};
1386+
13711387
CFrame.prototype.setSize = function (width, height) {
13721388
var me = this;
13731389

@@ -1749,7 +1765,7 @@ CFrame.prototype.showModal = function () {
17491765
var me = this;
17501766

17511767

1752-
var appearance =new CFrameAppearance();
1768+
var appearance = new CFrameAppearance();
17531769
appearance.showTitleBar = false;
17541770
appearance.showCloseButton = false;
17551771
appearance.frameBorderRadius = '0px';

0 commit comments

Comments
 (0)