1 /*global $, tizen, app */
5 function UiEvents(parent) {
10 (function () { // strict mode wrapper
12 UiEvents.prototype = {
17 init: function UiEvents_init() {
22 * Bind events to pages
24 addPageEvents: function UiEvents_addPageEvents() {
27 $('#start-header .ui-btn-back').on('tap', function (event) {
28 event.preventDefault();
29 event.stopPropagation();
33 $('#choose-footer').on('tap', '.ui-btn-back', function (event) {
34 event.preventDefault();
35 event.stopPropagation();
36 app.setDoNotSendBye(true);
37 $.mobile.changePage('#start');
40 $('#chat-header').on('tap', '.ui-btn-back', function (event) {
41 event.preventDefault();
42 event.stopPropagation();
43 if (!app.isConnection()) {
44 app.setDoNotSendBye(true);
46 $.mobile.changePage('#start');
49 $('#chat-header').on('tap', '.ui-btn-back', function (event) {
50 event.preventDefault();
53 $('#start').on('pagebeforeshow', function () {
54 self.ui.hideStartButtons();
55 self.ui.clearChatDialog();
56 if (!app.getDoNotSendBye()) {
59 app.setDoNotSendBye(false);
61 if (app.getApplicationMode() === 'server') {
62 app.server.unregisterChatServer();
63 } else if (app.getApplicationMode() === 'client') {
64 app.client.destroyBonding();
68 $('#turnOnButton').on('tap', function (event) {
69 self.ui.hideStartButtons();
73 $('#serverButton').on('tap', function (event) {
74 app.resetApplicationMode();
78 $('#clientButton').on('tap', function (event) {
79 app.resetApplicationMode();
83 $('#keyboard').on('pagebeforeshow', function () {
84 $('#keyboard-text').val('').attr('placeholder', 'Type ' + app.getApplicationMode() + ' name');
85 $('#keyboard-header > h1').html('Type ' + app.getApplicationMode() + ' name');
88 $('#keyboard').on('pageshow', function () {
89 setTimeout(function () { $('#keyboard-text').focus(); }, 500);
92 $('#keyboard-ok-button').on('tap', function (event) {
93 event.preventDefault();
94 var value = $('#keyboard-text').val(), mode;
95 if (value.length !== 0) {
96 app.setUserName(value);
97 mode = app.getApplicationMode();
98 if (mode === 'server') {
100 } else if (mode === 'client') {
101 $.mobile.changePage('#choose');
106 $('#choose').on('pagebeforeshow', function () {
107 app.setAdapterName();
110 $('#choose').on('pagehide', function () {
111 app.clearListOfServers();
112 app.client.stopServerSearching();
115 $('#choose-content').on('tap', 'ul.ui-listview li', function () {
116 app.client.stopServerSearching($(this).attr('address'));
119 $('#chat').on('pagebeforeshow', function () {
120 $('#chat-header-type').html(app.getApplicationMode());
121 $('#chat-header-name').html(app.getCurrentName());
122 if ($(this).data('serverName') !== undefined) {
123 $('#chat-header-type').append(' - connected to ' + $(this).data('serverName'));
124 $(this).removeData('serverName');
126 self.ui.checkSendButtonState();
129 $('#chat').on('pageshow', function () {
130 if (app.getApplicationMode() === 'server') {
131 setTimeout(function () { app.ui.showVisibilityPopup(); }, 100);
135 $('#chat').on('pagehide', function () {
137 app.setConnection(false);
140 $('#text').on('input', function () {
141 self.ui.checkSendButtonState();
144 $('#text').on('focus', function () {
145 var content = $('#chat-content');
146 if (self.ui.scrolltimeout !== null) {
147 clearTimeout(self.ui.scrolltimeout);
149 self.ui.scrolltimeout = setTimeout(function () {
150 self.ui.scrolltimeout = null;
151 self.ui.scrollToBottom(content);
155 $('#text').on('blur', function () {
156 var content = $('#chat-content');
157 if (self.ui.scrolltimeout !== null) {
158 clearTimeout(self.ui.scrolltimeout);
160 self.ui.scrolltimeout = setTimeout(function () {
161 self.ui.scrolltimeout = null;
162 self.ui.scrollToBottom(content);
166 $('#ui-mySend').on('tap', function (event) {
167 event.stopPropagation();
168 var message = $('#text').val();
170 self.ui.disableSendButton();
171 app.sendMessage(message);
174 $('body').on('tap', '#byeOK', function () {
175 self.ui.hideByePopup();
176 $('#keyboard-back-button').trigger('tap');
179 $('body').on('touchstart', '#byePopup-screen', function () {
180 $('#byeOK').trigger('tap');
183 $('body').on('tap', '#visibilityOK', function () {
184 self.ui.hideVisibilityPopup();
187 $('body').on('touchstart', '#visibilityPopup-screen', function () {
188 $('#visibilityOK').trigger('tap');
191 $('#chat-content').on('touchstart', function () {
192 if (self.ui.scrolltimeout !== null) {
193 clearTimeout(self.ui.scrolltimeout);
194 self.ui.scrolltimeout = null;
198 window.addEventListener('tizenhwkey', function(e) {
199 if (e.keyName == "back") {
200 event.preventDefault();
201 app.setDoNotSendBye(true);
202 if ($.mobile.activePage.attr('id') === 'start') {
203 tizen.application.getCurrentApplication().exit();
204 } else if ($.mobile.activePage.attr('id') === 'chat') {
205 $.mobile.changePage('#start');