forked from zendesk/demo_apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
40 lines (30 loc) · 1 KB
/
app.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
(function() {
return {
events: {
'app.created': 'init',
'iframe.handshake': 'handleHandshake',
'iframe.messageReceived': 'handleMessageReceived',
'click .send_message .btn': 'sendChatMessage'
},
init: function() {
this.switchTo('iframe');
},
escapeHtml: function(html) {
return this.$('<span/>').text(html).html();
},
handleHandshake: function(data) {
this.$("#chat_content").append("IFrame communication is up and running!");
},
handleMessageReceived: function(data) {
this.$('#chat_content').append('<br/>Received message from the iFrame: ' + this.escapeHtml(data.message));
},
sendChatMessage: function(event) {
event.preventDefault();
var message = this.$('#message')[0].value;
if (message) {
this.$("#chat_content").append("<br/><br/>Sending message '" + this.escapeHtml(message) + "' to the iFrame...");
this.postMessage('app.message', { message: message });
}
}
};
}());