-
Notifications
You must be signed in to change notification settings - Fork 0
/
index2.html
170 lines (161 loc) · 7.58 KB
/
index2.html
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Ruto</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link href="https://fonts.googleapis.com/css2?family=Reddit+Mono:wght@200..900&display=swap" rel="stylesheet" />
<style>
body {
font-family: 'Reddit Mono', monospace;
}
</style>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-transparent">
<div class="container">
<a class="navbar-brand" href="/">
<img src="ruto.png" alt="" height="24" class="d-inline-block align-text-top" />
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="index.html">Iframe Demo</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="index2.html">Window Demo</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://github.com/rajnandan1/ruto">Github</a>
</li>
</ul>
</div>
</div>
</nav>
<div class="container my-5">
<h1 class="text-center">Parent + Iframe</h1>
<p class="text-center">Parent sends a message, popup. popup sends a message and sends it back</p>
<div class="col-lg-12 px-0">
<div class="row">
<div class="col-6 chat-root">
<div class="row chat-content">
<div class="col-12">
<h4>Parent Window</h4>
</div>
<div class="col-12 p-0">
<div class="chat" id="mymessage">
<!-- <div class="message">
<div class="mine sent">
<div class="bubble">
Hello, how are you?
</div>
</div>
</div>
<div class="message">
<div class="his received">
<div class="bubble">
I am good, thank you.
</div>
</div>
</div> -->
</div>
</div>
<div class="col-12 mt-4">
<form class="row" onsubmit="event.preventDefault(); sendMessage();">
<div class="col-8">
<label for="message" class="visually-hidden">Message</label>
<input type="text" class="form-control" id="message" placeholder="message" required />
</div>
<div class="col-4">
<button type="submit" class="btn btn-primary mb-3 w-100">SEND</button>
</div>
</form>
</div>
</div>
</div>
<div class="col-6">
<button class="btn btn-primary" onclick="openWindow()">Open Window First</button>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="dist/ruto.min.js"></script>
<script>
function GetUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
const r = (Math.random() * 16) | 0,
v = c == 'x' ? r : (r & 0x3) | 0x8;
return v.toString(16);
});
}
let popup;
function openWindow() {
//position it to the right
popup = window.open('window.html', 'window', 'width=700,height=' + window.innerHeight + ',left=2000');
ruto.receive('/window-to-parent/purple', popup, function (response, message) {
const id = GetUUID();
$('#mymessage').animate({ scrollTop: $('#mymessage').prop('scrollHeight') }, 1000);
$('#mymessage').append(
`<div class="message" id="${id}">
<div class="his sent">
<div class="bubble">
➔ ${message}
</div>
</div>
</div>`,
);
const newMessage = message.split('').reverse().join('');
setTimeout(() => {
$('#mymessage').animate({ scrollTop: $('#mymessage').prop('scrollHeight') }, 1000);
$('#' + id).append(
`<div class="his received">
<div class="bubble">
${newMessage} ➔
</div>
</div>`,
);
return response.send(newMessage);
}, 1000);
});
}
function sendMessage() {
const id = GetUUID();
$('#mymessage').animate({ scrollTop: $('#mymessage').prop('scrollHeight') }, 1000);
$('#mymessage').append(
`<div class="message" id="${id}">
<div class="mine sent">
<div class="bubble">
${$('#message').val()} ➔
</div>
</div>
</div>`,
);
ruto.send(window.location.origin + '/parent-to-window/popup', popup, $('#message').val()).then(
function (message) {
$('#' + id).append(
`<div class="mine received">
<div class="bubble">
➔ ${message}
</div>
</div>`,
);
$('#mymessage').animate({ scrollTop: $('#mymessage').prop('scrollHeight') }, 1000);
},
function (error) {
console.log('Error:', error);
},
);
$('#message').val('');
}
</script>
</body>
</html>