summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project/.project120
-rw-r--r--project/NOTICE1
-rw-r--r--project/config.xml45
-rw-r--r--project/css/style.css181
-rw-r--r--project/index.html70
-rw-r--r--project/js/app.client.js253
-rw-r--r--project/js/app.client.model.js303
-rw-r--r--project/js/app.config.js57
-rw-r--r--project/js/app.helpers.js37
-rw-r--r--project/js/app.js477
-rw-r--r--project/js/app.model.js190
-rw-r--r--project/js/app.server.js196
-rw-r--r--project/js/app.server.model.js178
-rw-r--r--project/js/app.ui.events.js468
-rw-r--r--project/js/app.ui.js578
-rw-r--r--project/js/app.ui.templateManager.js288
-rw-r--r--project/js/app.ui.templateManager.modifiers.js66
-rw-r--r--project/js/main.js92
-rw-r--r--project/templates/bye_popup.tpl8
-rw-r--r--project/templates/chat_page.tpl40
-rw-r--r--project/templates/choose_page.tpl16
-rw-r--r--project/templates/keyboard_page.tpl33
-rw-r--r--project/templates/left_bubble.tpl4
-rw-r--r--project/templates/message_popup.tpl8
-rw-r--r--project/templates/right_bubble.tpl4
-rw-r--r--project/templates/server_row.tpl14
26 files changed, 1524 insertions, 2203 deletions
diff --git a/project/.project b/project/.project
index 5c23f80..ea56a52 100644
--- a/project/.project
+++ b/project/.project
@@ -1,63 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
- <name>BluetoothChat</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.wst.common.project.facet.core.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>json.validation.builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.tizen.web.jslint.nature.JSLintBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.tizen.web.css.nature.CSSBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.wst.validation.validationbuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.tizen.web.project.builder.WebBuilder</name>
- <arguments>
- <dictionary>
- <key>usedLibraryType</key>
- <value>WebUIFramework</value>
- </dictionary>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.tizen.web.privilege.nature.PrivilegeBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.tizen.web.editor.css.nature.CSSBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>json.validation.nature</nature>
- <nature>org.tizen.web.jslint.nature.JSLintNature</nature>
- <nature>org.tizen.web.css.nature.CSSNature</nature>
- <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
- <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
- <nature>org.tizen.web.project.builder.WebNature</nature>
- <nature>org.tizen.web.privilege.nature.PrivilegeNature</nature>
- <nature>org.tizen.web.editor.css.nature.CSSNature</nature>
- </natures>
+ <name>BluetoothChat</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.wst.common.project.facet.core.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>json.validation.builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.tizen.web.jslint.nature.JSLintBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.tizen.web.css.nature.CSSBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.wst.validation.validationbuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.tizen.web.project.builder.WebBuilder</name>
+ <arguments>
+ <dictionary>
+ <key>usedLibraryType</key>
+ <value>WebUIFramework</value>
+ </dictionary>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.tizen.web.privilege.nature.PrivilegeBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.tizen.web.editor.css.nature.CSSBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>json.validation.nature</nature>
+ <nature>org.tizen.web.jslint.nature.JSLintNature</nature>
+ <nature>org.tizen.web.css.nature.CSSNature</nature>
+ <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
+ <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
+ <nature>org.tizen.web.project.builder.WebNature</nature>
+ <nature>org.tizen.web.privilege.nature.PrivilegeNature</nature>
+ <nature>org.tizen.web.editor.css.nature.CSSNature</nature>
+ </natures>
</projectDescription>
diff --git a/project/NOTICE b/project/NOTICE
index e5d95db..092bc04 100644
--- a/project/NOTICE
+++ b/project/NOTICE
@@ -1,3 +1,4 @@
Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved.
Except as noted, this software is licensed under Flora License, Version 1.1
Please, see the LICENSE.Flora file for Flora License, Version 1.1 terms and conditions.
+
diff --git a/project/config.xml b/project/config.xml
index 3ba17d1..10ca79d 100644
--- a/project/config.xml
+++ b/project/config.xml
@@ -1,35 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
-<widget
- xmlns="http://www.w3.org/ns/widgets"
- xmlns:tizen="http://tizen.org/ns/widgets"
- id="http://sample-web-application.tizen.org/BluetoothChat"
- version="2.2.0"
- viewmodes="maximized">
-
- <tizen:application
- id="QmwDyrmOzO.BluetoothChat"
- package="QmwDyrmOzO"
- required_version="2.2" />
-
- <content src="index.html" />
-
- <icon src="icon.png" />
-
- <name>Bluetooth Chat</name>
-
- <feature name="http://tizen.org/feature/screen.size.normal.720.1280" />
-
- <tizen:privilege name="http://tizen.org/privilege/application.launch" />
- <tizen:privilege name="http://tizen.org/privilege/bluetooth.admin" />
- <tizen:privilege name="http://tizen.org/privilege/bluetooth.gap" />
- <tizen:privilege name="http://tizen.org/privilege/bluetooth.spp" />
- <tizen:privilege name="http://tizen.org/privilege/tizen" />
-
- <tizen:setting
- screen-orientation="portrait"
- context-menu="disable"
- background-support="disable"
- encryption="disable"
- install-location="auto" />
-
+<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://sample-web-application.tizen.org/bt-chat" version="2.2.0" viewmodes="maximized">
+ <tizen:application id="QmwDyrmOzO.BluetoothChat" package="QmwDyrmOzO" required_version="2.2"/>
+ <content src="index.html"/>
+ <icon src="icon.png"/>
+ <name>Bluetooth Chat</name>
+ <feature name="http://tizen.org/feature/screen.size.normal.720.1280"/>
+ <tizen:privilege name="http://tizen.org/privilege/application.launch"/>
+ <tizen:privilege name="http://tizen.org/privilege/bluetooth.admin"/>
+ <tizen:privilege name="http://tizen.org/privilege/bluetooth.gap"/>
+ <tizen:privilege name="http://tizen.org/privilege/bluetooth.spp"/>
+ <tizen:privilege name="http://tizen.org/privilege/tizen"/>
+ <tizen:setting screen-orientation="portrait" context-menu="disable" background-support="disable" encryption="disable" install-location="auto"/>
</widget>
diff --git a/project/css/style.css b/project/css/style.css
index 99053d2..4e74a37 100644
--- a/project/css/style.css
+++ b/project/css/style.css
@@ -1,173 +1,184 @@
html, body {
- overflow: hidden;
- -webkit-user-select: none;
+ overflow: hidden;
}
.box {
- margin: 0px;
- padding: 0px;
- display: table-cell;
- vertical-align: middle;
- height: inherit;
- width: inherit;
+ margin: 0px;
+ padding: 0px;
+ display: table-cell;
+ vertical-align: middle;
+ height: inherit;
+ width: inherit;
}
#start-header .ui-btn-back {
- width: 34px;
+ width: 34px;
}
#chat-header .ui-btn-back {
- width: 34px;
+ width: 34px;
}
#chat-header .ui-btn-footer-down {
- top: 19px;
- right: 0px;
+ top: 19px;
+ right: 0px;
}
.ui-btn-start {
- margin: 10px auto;
- padding: 0;
- width: 90%;
- font-size: 26px;
+ margin: 10px auto;
+ padding: 0;
+ width: 90%;
+ font-size: 26px;
}
.ui-btn-start > span {
- padding-top: 30px;
- padding-bottom: 30px;
+ padding-top: 30px;
+ padding-bottom: 30px;
}
+/*
#keyboard-text {
- width: 90%;
- margin: 16px auto;
+ width: 100%;
+ margin: 0px;
+ padding: 0px;
+ border: 0px;
+ border-radius: 0px;
+ overflow: hidden;
+ font-size: 24px;
+ outline: none;
+}
+*/
+
+#keyboard-text {
+ width: 90%;
+ margin: 16px auto;
}
#keyboard-content .ui-scrollview-view {
- padding: 0px;
- text-align: center;
+ padding: 0px;
+ text-align: center;
}
html {
- background: white !important;
+ background: white !important;
}
#start-content {
- background-color: white;
+ background-color: white;
}
#keyboard-content {
- background-color: white;
+ background-color: white;
}
#keyboard-back-button {
- position: absolute;
- right: 50px;
- bottom: 15px;
- width: 40px;
+ position: absolute;
+ right: 50px;
+ bottom: 15px;
+ width: 40px;
}
#ui-textArea {
- position: absolute;
- width: 100%;
- height: 160px;
- display: -webkit-box;
- -webkit-box-orient: horizontal;
+ position: absolute;
+ width: 100%;
+ height: 160px;
+ display: -webkit-box;
+ -webkit-box-orient: horizontal;
}
#ui-textArea-text {
- -webkit-box-flex: 1;
+ -webkit-box-flex: 1;
}
#ui-textArea-button {
- width: 100px;
- height: 108px;
+ width: 100px;
+ height: 108px;
}
#text {
- background-color: #fff;
- color: #555;
- position: absolute;
- left: 10px;
- right: 110px;
- top: 10px;
- height: 140px;
- margin: 0px;
- border: 0px solid #000;
- border-radius: 5px;
- font-size: 22px;
- overflow: auto;
- white-space: pre-line;
+ background-color: #fff;
+ color: #555;
+ position: absolute;
+ left: 10px;
+ right: 110px;
+ top: 10px;
+ height: 140px;
+ margin: 0px;
+ border: 0px solid #000;
+ border-radius: 5px;
+ font-size: 22px;
+ overflow: auto;
}
#ui-mySend {
- float: left;
- width: 85px;
- margin-top: 10px;
- font-size: 22px;
+ float: left;
+ width: 85px;
+ margin-top: 10px;
+ font-size: 22px;
}
#ui-myCounter {
- float: left;
- margin-top: 47px;
+ float: left;
+ margin-top: 47px;
}
#ui-myCounter p {
- font-size: 20px;
+ font-size: 20px;
}
#chat-footer {
- height: 164px;
+ height: 164px;
}
#start-monit {
- text-align: center;
- width: 100%;
+ text-align: center;
+ width: 100%;
}
#start-monit a {
- font-size: 1.4em;
+ font-size: 1.4em;
}
#chat-header {
- min-height: 2.5em;
+ min-height: 2.5em;
}
#chat-header-type {
- font-size: 0.5em;
- position: absolute;
- top: 3px;
- left: 3px;
- white-space: nowrap;
- overflow: hidden !important;
- text-overflow: ellipsis;
- width: 90%;
+ font-size: 0.5em;
+ position: absolute;
+ top: 3px;
+ left: 3px;
+ white-space: nowrap;
+ overflow: hidden !important;
+ text-overflow: ellipsis;
+ width: 90%;
}
#chat-header-name {
- font-size: 1em;
- position: absolute;
- top: 25px;
- left: 3px;
- white-space: nowrap;
- overflow: hidden !important;
- text-overflow: ellipsis;
- width: 60%;
+ font-size: 1em;
+ position: absolute;
+ top: 25px;
+ left: 3px;
+ white-space: nowrap;
+ overflow: hidden !important;
+ text-overflow: ellipsis;
+ width: 60%;
}
.server-row-name {
- white-space: nowrap;
- overflow: hidden !important;
- text-overflow: ellipsis;
- width: 80%;
+ white-space: nowrap;
+ overflow: hidden !important;
+ text-overflow: ellipsis;
+ width: 80%;
}
#discovering {
- right: 8px;
- top: 8px;
+ right: 8px;
+ top: 8px;
}
.focus {}
.ui-btn-back {
- visibility:hidden;
+ visibility:hidden;
}
diff --git a/project/index.html b/project/index.html
index 80ab628..974a9f5 100644
--- a/project/index.html
+++ b/project/index.html
@@ -1,50 +1,36 @@
<!DOCTYPE html>
<html>
-<head>
-
- <meta charset="utf-8" />
- <meta name="viewport" content="width=360, user-scalable=no" />
-
- <title>Bluetooth chat</title>
- <meta name="description" content="Bluetooth chat" />
- <script src="/usr/share/tizen-web-ui-fw/latest/js/jquery.min.js"></script>
- <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.min.js"></script>
- <script src="/usr/share/tizen-web-ui-fw/latest/js/tizen-web-ui-fw.min.js" data-framework-theme="tizen-white" data-framework-viewport-scale="false"></script>
+<head>
+ <meta charset="utf-8"/>
+ <meta name="description" content="bt-chat"/>
+ <meta name="viewport" content="width=360, user-scalable=no"/>
- <link rel="stylesheet" type="text/css" href="./css/style.css" />
- <script type="text/javascript" src="./js/main.js"></script>
+ <title>Bluetooth chat</title>
+ <script src="tizen-web-ui-fw/latest/js/jquery.min.js"></script>
+ <script src="tizen-web-ui-fw/latest/js/tizen-web-ui-fw-libs.min.js"></script>
+ <script src="tizen-web-ui-fw/latest/js/tizen-web-ui-fw.min.js" data-framework-theme="tizen-white" data-framework-viewport-scale="false"></script>
+ <script type="text/javascript" src="./js/main.js"></script>
+ <link rel="stylesheet" type="text/css" href="./css/style.css"/>
</head>
-<body>
-
- <div id="start" data-role="page">
-
- <div id="start-header" data-role="header" data-position="fixed">
- <h1>Bluetooth chat</h1>
- </div>
-
- <div id="start-content" data-role="content" data-scroll="none">
- <div class="box">
- <div data-role="button" class="ui-btn-start" id="turnOnButton" style="display: none;">Turn bluetooth on</div>
- <div data-role="button" class="ui-btn-start" id="serverButton" style="display: none;">Create server</div>
- <div data-role="button" class="ui-btn-start" id="clientButton" style="display: none;">Join server</div>
- <div id="start-monit" style="display: none;">
- <p>Waiting for Bluetooth...</p>
- </div>
- </div>
- </div>
-
- </div>
-
- <div data-role="page" id="popup_page" data-add-back-btn="false">
- <div data-role="popup" id="popup">
- <div class="ui-popup-text">
- <p></p>
- </div>
- <div class="ui-popup-button-bg"></div>
- </div>
- </div>
+<body>
+ <div id="start" data-role="page">
+ <div id="start-header" data-role="header" data-position="fixed">
+ <h1>Bluetooth chat</h1>
+ </div>
+
+ <div id="start-content" data-role="content" data-scroll="none">
+ <div class="box">
+ <div data-role="button" class="ui-btn-start" id="turnOnButton" style="display: none;">Turn bluetooth on</div>
+ <div data-role="button" class="ui-btn-start" id="serverButton" style="display: none;">Create server</div>
+ <div data-role="button" class="ui-btn-start" id="clientButton" style="display: none;">Join server</div>
+ <div id="start-monit" style="display: none;">
+ <p>Waiting for Bluetooth...</p>
+ </div>
+ </div>
+ </div>
+ </div>
</body>
-</html>
+</html> \ No newline at end of file
diff --git a/project/js/app.client.js b/project/js/app.client.js
index fc863c3..10dd388 100644
--- a/project/js/app.client.js
+++ b/project/js/app.client.js
@@ -1,157 +1,112 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*jslint plusplus: true, sloppy: true, todo: true, vars: true, browser: true, devel: true, maxerr: 999 */
/*global $, tizen, app, ClientModel */
-
/**
-* @class Client
-*/
+ * @class Client
+ */
+
function Client(adapter, serviceUUID) {
- 'use strict';
- this.adapter = adapter;
- this.serviceUUID = serviceUUID;
- this.globalSocket = null;
- this.init();
- this.discovering = false;
- this.chatServerDevice = null;
+ 'use strict';
+ this.adapter = adapter;
+ this.serviceUUID = serviceUUID;
+ this.globalSocket = null;
+ this.init();
+ this.discovering = false;
+ this.chatServerDevice = null;
}
(function () { // strict mode wrapper
- 'use strict';
-
- Client.prototype = {
- /**
- * @type clientModel
- */
- model: null,
-
- /**
- * Initialisation function
- */
- init: function Client_init() {
- this.model = new ClientModel(this);
- return this;
- },
-
- setDiscovering: function Client_setDiscovering(boolean) {
- this.discovering = boolean;
- app.ui.setDiscoveringProgress(boolean);
- },
-
- getDiscovering: function Client_getDiscovering() {
- return this.discovering;
- },
-
- searchServer: function Client_searchServer() {
- this.model.searchServer();
- },
-
- addDeviceToList: function Client_addDeviceToList(device) {
- app.ui.addDeviceToList(device);
- },
-
- stopServerSearching: function Client_stopServerSearching(address) {
- if (address !== undefined) {
- this.model.stopServerSearching(
- this.startBonding.bind(
- this,
- address,
- this.connectToService.bind(this)
- )
- );
- } else {
- this.model.stopServerSearching();
- }
- },
-
- startBonding: function Client_startBonding(address, callback) {
- this.model.startBonding(address, callback);
- },
-
- connectToService: function Client_connectToService(device) {
- this.model.connectToService(
- device,
- this.serviceUUID,
- this.connectToServiceSuccess.bind(this, device),
- this.connectToServiceError.bind(this)
- );
- },
-
- connectToServiceSuccess:
- function Client_connectToServiceSuccess(device, socket) {
- this.globalSocket = socket;
- socket.onmessage = function () {
- var data, recvmsg = '', i, len, messageObj;
- data = socket.readData();
- len = data.length;
- for (i = 0; i < len; i += 1) {
- recvmsg += String.fromCharCode(data[i]);
- }
- messageObj = JSON.parse(recvmsg);
- app.ui.displayReceivedMessage(
- messageObj.name,
- messageObj.text,
- messageObj.ping,
- messageObj.bye
- );
- };
- socket.onerror = function (e) {
- console.error('Client onerror');
- socket.close();
- };
- socket.onclose = function () {
- this.globalSocket = null;
- app.setConnection(false);
- app.serverDisconnected();
- };
- app.setConnection(true);
- app.ui.showChatPage(device.name);
- this.sendPing();
- },
-
- connectToServiceError: function Client_connectToServiceError(error) {
- console.error('Client_connectToServiceError: ' + error.message);
- },
-
- sendPing: function Client_sendPing() {
- this.model.sendPing(this.adapter.name, this.globalSocket);
- },
-
- sendMessage: function Client_sendMessage(message, callback) {
- this.model.sendMessage(
- this.adapter.name,
- this.globalSocket,
- message,
- callback
- );
- },
-
- sendBye: function Client_sendBye() {
- this.model.sendBye(this.adapter.name, this.globalSocket);
- },
-
- destroyBonding: function Client_destroyBonding() {
- this.model.destroyBonding(
- this.chatServerDevice,
- app.restartBluetooth.bind(app),
- app.ui.showStartButtons
- );
- }
-
- };
-
+ 'use strict';
+
+ Client.prototype = {
+ /**
+ * @type clientModel
+ */
+ model: null,
+
+ /**
+ * Initialisation function
+ */
+ init: function Client_init() {
+ this.model = new ClientModel(this);
+ return this;
+ },
+
+ setDiscovering: function Client_setDiscovering(boolean) {
+ this.discovering = boolean;
+ app.ui.setDiscoveringProgress(boolean);
+ },
+
+ getDiscovering: function Client_getDiscovering() {
+ return this.discovering;
+ },
+
+ searchServer: function Client_searchServer() {
+ this.model.searchServer();
+ },
+
+ addDeviceToList: function Client_addDeviceToList(device) {
+ app.ui.addDeviceToList(device);
+ },
+
+ stopServerSearching: function Client_stopServerSearching(address) {
+ if (address !== undefined) {
+ this.model.stopServerSearching(this.startBonding.bind(this, address, this.connectToService.bind(this)));
+ } else {
+ this.model.stopServerSearching();
+ }
+ },
+
+ startBonding: function Client_startBonding(address, callback) {
+ this.model.startBonding(address, callback);
+ },
+
+ connectToService: function Client_connectToService(device) {
+ this.model.connectToService(device, this.serviceUUID, this.connectToServiceSuccess.bind(this, device), this.connectToServiceError.bind(this));
+ },
+
+ connectToServiceSuccess: function Client_connectToServiceSuccess(device, socket) {
+ this.globalSocket = socket;
+ socket.onmessage = function () {
+ var data, recvmsg = '', i, len, messageObj;
+ data = socket.readData();
+ len = data.length;
+ for (i = 0; i < len; i += 1) {
+ recvmsg += String.fromCharCode(data[i]);
+ }
+ messageObj = JSON.parse(recvmsg);
+ app.ui.displayReceivedMessage(messageObj.name, messageObj.text, messageObj.ping, messageObj.bye);
+ };
+ socket.onerror = function (e) {
+ console.error('Client onerror');
+ socket.close();
+ };
+ socket.onclose = function () {
+ this.globalSocket = null;
+ app.setConnection(false);
+ };
+ app.setConnection(true);
+ app.ui.showChatPage(device.name);
+ this.sendPing();
+ },
+
+ connectToServiceError: function Client_connectToServiceError(error) {
+ console.error('Client_connectToServiceError: ' + error.message);
+ },
+
+ sendPing: function Client_sendPing() {
+ this.model.sendPing(this.adapter.name, this.globalSocket);
+ },
+
+ sendMessage: function Client_sendMessage(message, callback) {
+ this.model.sendMessage(this.adapter.name, this.globalSocket, message, callback);
+ },
+
+ sendBye: function Client_sendBye() {
+ this.model.sendBye(this.adapter.name, this.globalSocket);
+ },
+
+ destroyBonding: function Client_destroyBonding() {
+ this.model.destroyBonding(this.chatServerDevice, app.restartBluetooth.bind(app), app.ui.showStartButtons);
+ }
+ };
}());
diff --git a/project/js/app.client.model.js b/project/js/app.client.model.js
index 5493930..8b5960e 100644
--- a/project/js/app.client.model.js
+++ b/project/js/app.client.model.js
@@ -1,202 +1,141 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*jslint plusplus: true, sloppy: true, todo: true, vars: true, browser: true, devel: true, maxerr: 999 */
/*global $, tizen, app */
-
/**
-* @class Model
-*/
+ * @class Model
+ */
function ClientModel(parent) {
- 'use strict';
- this.client = parent;
- this.init();
+ 'use strict';
+ this.client = parent;
+ this.init();
}
(function () { // strict mode wrapper
- 'use strict';
- ClientModel.prototype = {
+ 'use strict';
+ ClientModel.prototype = {
- /**
- * API module initialisation
- */
- init: function ClientModel_init() {},
+ /**
+ * API module initialisation
+ */
+ init: function ClientModel_init() {},
- searchServer: function ClientModel_searchServer() {
- var discoverDevicesSuccessCallback = {
- onstarted: function () {
- this.client.setDiscovering(true);
- }.bind(this),
- ondevicefound: function (device) {
- this.client.addDeviceToList(device);
- }.bind(this),
- ondevicedisappeared: function (address) {},
- onfinished: function (devices) {
- this.client.setDiscovering(false);
- }.bind(this)
- };
- this.client.adapter.discoverDevices(
- discoverDevicesSuccessCallback,
- function (e) { this.client.setDiscovering(false); }
- );
- },
+ searchServer: function ClientModel_searchServer() {
+ var discoverDevicesSuccessCallback = {
+ onstarted: function () {
+ this.client.setDiscovering(true);
+ }.bind(this),
+ ondevicefound: function (device) {
+ this.client.addDeviceToList(device);
+ }.bind(this),
+ ondevicedisappeared: function (address) {},
+ onfinished: function (devices) {
+ this.client.setDiscovering(false);
+ }.bind(this)
+ };
- stopServerSearching: function ClientModel_stopServerSearching(
- callback
- ) {
- if (this.client.getDiscovering()) {
- this.client.adapter.stopDiscovery(function () {
- this.client.setDiscovering(false);
- if (typeof callback === 'function') {
- callback();
- }
- }.bind(this), function (e) {
- console.error("Error while stopDiscovery:" + e.message);
- });
- } else if (typeof callback === 'function') {
- callback();
- }
- },
+ this.client.adapter.discoverDevices(discoverDevicesSuccessCallback, function (e) { this.client.setDiscovering(false); });
+ },
- startBonding: function ClientModel_startBonding(address, callback) {
- this.client.adapter.createBonding(
- address,
- function (device) {
- callback(device);
- },
- function (error) {
- console.error('bondError: ' + error.message);
- }
- );
- },
+ stopServerSearching: function ClientModel_stopServerSearching(callback) {
+ if (this.client.getDiscovering()) {
+ this.client.adapter.stopDiscovery(function () {
+ this.client.setDiscovering(false);
+ if (typeof callback === 'function') {
+ callback();
+ }
+ }.bind(this), function (e) {
+ console.error("Error while stopDiscovery:" + e.message);
+ });
+ } else if (typeof callback === 'function') {
+ callback();
+ }
+ },
- connectToService: function ClientModel_connectToService(
- device,
- serviceUUID,
- successCallback,
- errorCallback
- ) {
- this.client.chatServerDevice = device;
- try {
- device.connectToServiceByUUID(
- serviceUUID,
- successCallback,
- errorCallback
- );
- } catch (error) {
- console.error('connectToServiceByUUID ERROR: ' + error.message);
- }
- },
+ startBonding: function ClientModel_startBonding(address, callback) {
+ this.client.adapter.createBonding(address, function (device) { callback(device); }, function (error) { console.error('bondError: ' + error.message); });
+ },
- sendPing: function ClientModel_sendPing(name, socket) {
- var sendTextMsg, messageObj, messageObjToString, i, len;
- sendTextMsg = [];
- messageObj = {
- name: encodeURIComponent(name),
- text: '',
- ping: true,
- bye: false
- };
- messageObjToString = JSON.stringify(messageObj);
- len = messageObjToString.length;
+ connectToService: function ClientModel_connectToService(device, serviceUUID, successCallback, errorCallback) {
+ this.client.chatServerDevice = device;
+ try {
+ device.connectToServiceByUUID(serviceUUID, successCallback, errorCallback);
+ } catch (error) {
+ console.error('connectToServiceByUUID ERROR: ' + error.message);
+ }
+ },
- for (i = 0; i < len; i += 1) {
- sendTextMsg[i] = messageObjToString.charCodeAt(i);
- }
- try {
- if (socket !== null && socket.state === "OPEN") {
- socket.writeData(sendTextMsg);
- }
- } catch (error) {
- console.error('sendPing: ' + error.message);
- }
- },
+ sendPing: function ClientModel_sendPing(name, socket) {
+ var sendTextMsg, messageObj, messageObjToString, i, len;
+ sendTextMsg = [];
+ messageObj = {name: encodeURIComponent(name), text: '', ping: true, bye: false};
+ messageObjToString = JSON.stringify(messageObj);
+ len = messageObjToString.length;
- sendMessage: function ClientModel_sendMessage(
- name,
- socket,
- message,
- callback
- ) {
- var sendTextMsg = [], messageObj, messageObjToString, i, len;
- name = encodeURIComponent(name);
- message = encodeURIComponent(message);
- messageObj = {name: name, text: message, ping: false, bye: false};
- messageObjToString = JSON.stringify(messageObj);
- len = messageObjToString.length;
- for (i = 0; i < len; i += 1) {
- sendTextMsg[i] = messageObjToString.charCodeAt(i);
- }
- try {
- if (socket !== null && socket.state === "OPEN") {
- socket.writeData(sendTextMsg);
- callback(message);
- }
- } catch (error) {
- console.error('sendMessage: ' + error.message);
- }
- },
+ for (i = 0; i < len; i += 1) {
+ sendTextMsg[i] = messageObjToString.charCodeAt(i);
+ }
+ try {
+ if (socket !== null && socket.state === "OPEN") {
+ socket.writeData(sendTextMsg);
+ }
+ } catch (error) {
+ console.error('sendPing: ' + error.message);
+ }
+ },
- sendBye: function ClientModel_sendBye(name, socket) {
- var sendTextMsg = [], messageObj, messageObjToString, i, len;
- name = encodeURIComponent(name);
- messageObj = {name: name, text: '', ping: false, bye: true};
- messageObjToString = JSON.stringify(messageObj);
- len = messageObjToString.length;
- for (i = 0; i < len; i += 1) {
- sendTextMsg[i] = messageObjToString.charCodeAt(i);
- }
- try {
- if (socket !== null && socket.state === "OPEN") {
- socket.writeData(sendTextMsg);
- }
- } catch (error) {
- console.error('sendBye: ' + error.message);
- }
- },
+ sendMessage: function ClientModel_sendMessage(name, socket, message, callback) {
+ var sendTextMsg = [], messageObj, messageObjToString, i, len;
+ name = encodeURIComponent(name);
+ message = encodeURIComponent(message);
+ messageObj = {name: name, text: message, ping: false, bye: false};
+ messageObjToString = JSON.stringify(messageObj);
+ len = messageObjToString.length;
+ for (i = 0; i < len; i += 1) {
+ sendTextMsg[i] = messageObjToString.charCodeAt(i);
+ }
+ try {
+ if (socket !== null && socket.state === "OPEN") {
+ socket.writeData(sendTextMsg);
+ callback(message);
+ }
+ } catch (error) {
+ console.error('sendMessage: ' + error.message);
+ }
+ },
- destroyBonding: function ClientModel_destroyBonding(
- device,
- restartCallback,
- showStartButtonsCallback
- ) {
- if (device !== null) {
- if (device.isBonded) {
- this.client.adapter.destroyBonding(
- device.address,
- function () {
- device = null;
- restartCallback();
- },
- function (error) {
- console.error(
- 'ClientModel_destroyBonding: ' + error
- );
- }
- );
- } else {
- device = null;
- restartCallback();
- }
- } else {
- this.stopServerSearching();
- showStartButtonsCallback();
- }
- }
+ sendBye: function ClientModel_sendBye(name, socket) {
+ var sendTextMsg = [], messageObj, messageObjToString, i, len;
+ name = encodeURIComponent(name);
+ messageObj = {name: name, text: '', ping: false, bye: true};
+ messageObjToString = JSON.stringify(messageObj);
+ len = messageObjToString.length;
+ for (i = 0; i < len; i += 1) {
+ sendTextMsg[i] = messageObjToString.charCodeAt(i);
+ }
+ try {
+ if (socket !== null && socket.state === "OPEN") {
+ socket.writeData(sendTextMsg);
+ }
+ } catch (error) {
+ console.error('sendBye: ' + error.message);
+ }
+ },
- };
+ destroyBonding: function ClientModel_destroyBonding(device, restartCallback, showStartButtonsCallback) {
+ if (device !== null) {
+ if (device.isBonded) {
+ this.client.adapter.destroyBonding(device.address, function () {
+ device = null;
+ restartCallback();
+ }, function (error) { console.error('ClientModel_destroyBonding: ' + error); });
+ } else {
+ device = null;
+ restartCallback();
+ }
+ } else {
+ this.stopServerSearching();
+ showStartButtonsCallback();
+ }
+ }
+ };
}());
diff --git a/project/js/app.config.js b/project/js/app.config.js
index b1cf599..c40c601 100644
--- a/project/js/app.config.js
+++ b/project/js/app.config.js
@@ -1,48 +1,29 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*jslint plusplus: true, sloppy: true, todo: true, vars: true, browser: true, devel: true, maxerr: 999 */
/*global $, tizen, app */
-
/**
-* @class Config
-*/
+ * @class Config
+ */
function Config() {
- 'use strict';
+ 'use strict';
}
(function () { // strict mode wrapper
- 'use strict';
- Config.prototype = {
-
- properties: {
- 'templateDir': 'templates',
- 'templateExtension': '.tpl'
- },
-
- /**
- * Returns config value
- */
- get: function (value, defaultValue) {
- if (this.properties.hasOwnProperty(value)) {
- return this.properties[value];
- }
- return defaultValue;
- }
+ 'use strict';
+ Config.prototype = {
- };
+ properties: {
+ 'templateDir': 'templates',
+ 'templateExtension': '.tpl'
+ },
+ /**
+ * Returns config value
+ */
+ get: function (value, defaultValue) {
+ if (this.properties.hasOwnProperty(value)) {
+ return this.properties[value];
+ }
+ return defaultValue;
+ }
+ };
}());
diff --git a/project/js/app.helpers.js b/project/js/app.helpers.js
index 0440568..0437bc6 100644
--- a/project/js/app.helpers.js
+++ b/project/js/app.helpers.js
@@ -1,38 +1,19 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*jslint plusplus: true, sloppy: true, todo: true, vars: true, browser: true, devel: true, maxerr: 999 */
/*global $, tizen, app */
-
/**
-* @class Helpers
-*/
+ * @class Helpers
+ */
function Helpers() {
- 'use strict';
+ 'use strict';
}
(function () { // strict mode wrapper
- 'use strict';
-
- Helpers.prototype = {
-
- checkStringLength: function Helpers_checkStringLength(value) {
- return value.length > 0 ? true : false;
- }
+ 'use strict';
+ Helpers.prototype = {
- };
+ checkStringLength: function Helpers_checkStringLength(value) {
+ return value.length > 0 ? true : false;
+ }
+ };
}());
diff --git a/project/js/app.js b/project/js/app.js
index 0ba0f49..c02479e 100644
--- a/project/js/app.js
+++ b/project/js/app.js
@@ -1,274 +1,213 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*global $, tizen, app, Config, Helpers, Model, Ui, Server, Client */
-
var App = null;
(function () { // strict mode wrapper
- 'use strict';
-
- /**
- * Creates a new application object
- *
- * @class Application
- */
- App = function App() {};
-
- App.prototype = {
- /**
- * @type Array
- */
- requires: ['js/app.config.js',
- 'js/app.helpers.js',
- 'js/app.model.js',
- 'js/app.ui.js',
- 'js/app.ui.templateManager.js',
- 'js/app.ui.templateManager.modifiers.js',
- 'js/app.ui.events.js',
- 'js/app.client.js',
- 'js/app.client.model.js',
- 'js/app.server.js',
- 'js/app.server.model.js'
- ],
-
- /**
- * @type Model
- */
- model: null,
-
- /**
- * @type Ui
- */
- ui: null,
-
- /**
- * @type Config
- */
- config: null,
-
- /**
- * @type Helpers
- */
- helpers: null,
-
- /**
- * @type Client
- */
- client: null,
-
- /**
- * @type Server
- */
- server: null,
-
- /**
- * @type String
- */
- currentName: '',
-
- /**
- * @type Boolean
- */
- doNotSendBye: false,
-
- /**
- * @type Boolean
- */
- connection: false,
-
- /**
- * Initialisation function
- */
- init: function App_init() {
- this.config = new Config();
- this.helpers = new Helpers();
- this.model = new Model();
- this.ui = new Ui(this.initModel.bind(this));
- },
-
- initModel: function App_initModel() {
- this.model.init(this.checkPowerState.bind(this));
- },
-
- /**
- * exit application action
- */
- exit: function App_exit() {
- tizen.application.getCurrentApplication().exit();
- },
-
- isConnection: function App_isConnection() {
- return this.connection;
- },
-
- setConnection: function App_setConnection(bool) {
- this.connection = bool;
- },
-
- getDoNotSendBye: function App_getDoNotSendBye() {
- return this.doNotSendBye;
- },
-
- setDoNotSendBye: function App_setDoNotSendBye(bool) {
- this.doNotSendBye = bool;
- },
-
- getCurrentName: function App_getCurrentName() {
- return this.ui.escape(this.currentName);
- },
-
- getApplicationMode: function App_getApplicationMode() {
- var mode = 'start';
- if (this.client !== null) {
- mode = 'client';
- } else if (this.server !== null) {
- mode = 'server';
- }
- return mode;
- },
-
- resetApplicationMode: function App_resetApplicationMode() {
- this.client = null;
- this.server = null;
- },
-
- checkPowerState: function App_checkPowerState() {
- this.ui.setContentStartAttributes(
- this.model.checkPowerState.bind(
- this.model,
- this.ui.showPowerOnButton,
- this.ui.showStartButtons
- )
- );
- },
-
- powerOn: function App_powerOn() {
- this.model.powerOn(this.ui.showStartButtons);
- },
-
- powerOff: function App_powerOff() {
- this.model.powerOff(this.exit);
- },
-
- restartBluetooth: function App_restartBluetooth() {
- this.model.restartBluetooth(this.powerOn.bind(this));
- },
-
- startServer: function App_startServer() {
- this.server = new Server(
- this.model.adapter,
- this.model.serviceUUID
- );
- this.showKeyboardPage();
- },
-
- startClient: function App_startClient() {
- this.client = new Client(
- this.model.adapter,
- this.model.serviceUUID
- );
- this.showKeyboardPage();
- },
-
- serverDisconnected: function App_serverDisconnected() {
- app.ui.popup('Lost connection to Server.', function () {
- history.back();
- });
- },
-
- clientDisconnected: function App_clientDisconnected() {
- app.ui.popup('Lost connection with Client.', function () {
- app.ui.setHeaderType('server');
- });
- },
-
- showKeyboardPage: function App_showKeyboardPage() {
- this.ui.showKeyboardPage();
- },
-
- setUserName: function App_setUserName(value) {
- this.currentName = value;
- },
-
- setAdapterName: function App_setAdapterName() {
- var changeName = false, mode = this.getApplicationMode();
- if (this.model.adapter.name !== this.currentName) {
- changeName = true;
- }
- if (mode === 'server') {
- this.model.setAdapterName(
- changeName,
- this.server.registerServer.bind(this.server)
- );
- } else if (mode === 'client') {
- this.model.setAdapterName(
- changeName,
- this.client.searchServer.bind(this.client)
- );
- }
- },
-
- isBluetoothVisible: function App_isBluetoothVisible() {
- return this.model.adapter.visible;
- },
-
- clearListOfServers: function App_clearListOfServers() {
- this.ui.clearListOfServers();
- },
-
- displaySentMessage: function App_displaySentMessage(message) {
- this.ui.displaySentMessage(message);
- },
-
- sendMessage: function App_sendMessage(message) {
- var mode = this.getApplicationMode();
- if (mode === 'server') {
- this.server.sendMessage(
- message,
- this.displaySentMessage.bind(this)
- );
- } else if (mode === 'client') {
- this.client.sendMessage(
- message,
- this.displaySentMessage.bind(this)
- );
- }
- },
-
- sendBye: function App_sendBye() {
- var mode = this.getApplicationMode();
- if (mode === 'server') {
- this.server.sendBye();
- } else if (mode === 'client') {
- this.client.sendBye();
- }
- },
-
- connectionLost: function App_connectionLost() {
- this.connection = false;
- this.ui.popup(
- "To continue please turn on bluetooth.",
- function () {
- this.checkPowerState();
- $.mobile.changePage("#start");
- }.bind(this)
- );
- }
-
- };
-
+ 'use strict';
+
+ /**
+ * Creates a new application object
+ *
+ * @class Application
+ */
+ App = function App() {};
+
+ App.prototype = {
+ /**
+ * @type Array
+ */
+ requires: ['js/app.config.js',
+ 'js/app.helpers.js',
+ 'js/app.model.js',
+ 'js/app.ui.js',
+ 'js/app.ui.templateManager.js',
+ 'js/app.ui.events.js',
+ 'js/app.client.js',
+ 'js/app.client.model.js',
+ 'js/app.server.js',
+ 'js/app.server.model.js'
+ ],
+
+ /**
+ * @type Model
+ */
+ model: null,
+
+ /**
+ * @type Ui
+ */
+ ui: null,
+
+ /**
+ * @type Config
+ */
+ config: null,
+
+ /**
+ * @type Helpers
+ */
+ helpers: null,
+
+ /**
+ * @type Client
+ */
+ client: null,
+
+ /**
+ * @type Server
+ */
+ server: null,
+
+ /**
+ * @type String
+ */
+ currentName: '',
+
+ /**
+ * @type Boolean
+ */
+ doNotSendBye: false,
+
+ /**
+ * @type Boolean
+ */
+ connection: false,
+
+ /**
+ * Initialisation function
+ */
+ init: function App_init() {
+ this.config = new Config();
+ this.helpers = new Helpers();
+ this.model = new Model();
+ this.ui = new Ui(this.initModel.bind(this));
+ },
+
+ initModel: function App_initModel() {
+ this.model.init(this.checkPowerState.bind(this));
+ },
+
+ /**
+ * exit application action
+ */
+ exit: function App_exit() {
+ tizen.application.getCurrentApplication().exit();
+ },
+
+ isConnection: function App_isConnection() {
+ return this.connection;
+ },
+
+ setConnection: function App_setConnection(bool) {
+ this.connection = bool;
+ },
+
+ getDoNotSendBye: function App_getDoNotSendBye() {
+ return this.doNotSendBye;
+ },
+
+ setDoNotSendBye: function App_setDoNotSendBye(bool) {
+ this.doNotSendBye = bool;
+ },
+
+ getCurrentName: function App_getCurrentName() {
+ return this.currentName;
+ },
+
+ getApplicationMode: function App_getApplicationMode() {
+ var mode = 'start';
+ if (this.client !== null) {
+ mode = 'client';
+ } else if (this.server !== null) {
+ mode = 'server';
+ }
+ return mode;
+ },
+
+ resetApplicationMode: function App_resetApplicationMode() {
+ this.client = null;
+ this.server = null;
+ },
+
+ checkPowerState: function App_checkPowerState() {
+ this.ui.setContentStartAttributes(
+ this.model.checkPowerState.bind(
+ this.model,
+ this.ui.showPowerOnButton,
+ this.ui.showStartButtons
+ )
+ );
+ },
+
+ powerOn: function App_powerOn() {
+ this.model.powerOn(this.ui.showStartButtons);
+ },
+
+ powerOff: function App_powerOff() {
+ this.model.powerOff(this.exit);
+ },
+
+ restartBluetooth: function App_restartBluetooth() {
+ this.model.restartBluetooth(this.powerOn.bind(this));
+ },
+
+ startServer: function App_startServer() {
+ this.server = new Server(this.model.adapter, this.model.serviceUUID);
+ this.showKeyboardPage();
+ },
+
+ startClient: function App_startClient() {
+ this.client = new Client(this.model.adapter, this.model.serviceUUID);
+ this.showKeyboardPage();
+ },
+
+ showKeyboardPage: function App_showKeyboardPage() {
+ this.ui.showKeyboardPage();
+ },
+
+ setUserName: function App_setUserName(value) {
+ this.currentName = value;
+ },
+
+ setAdapterName: function App_setAdapterName() {
+ var changeName = false, mode = this.getApplicationMode();
+ if (this.model.adapter.name !== this.currentName) {
+ changeName = true;
+ }
+ if (mode === 'server') {
+ this.model.setAdapterName(changeName, this.server.registerServer.bind(this.server));
+ } else if (mode === 'client') {
+ this.model.setAdapterName(changeName, this.client.searchServer.bind(this.client));
+ }
+ },
+
+ isBluetoothVisible: function App_isBluetoothVisible() {
+ return this.model.adapter.visible;
+ },
+
+ clearListOfServers: function App_clearListOfServers() {
+ this.ui.clearListOfServers();
+ },
+
+ displaySentMessage: function App_displaySentMessage(message) {
+ this.ui.displaySentMessage(message);
+ },
+
+ sendMessage: function App_sendMessage(message) {
+ var mode = this.getApplicationMode();
+ if (mode === 'server') {
+ this.server.sendMessage(message, this.displaySentMessage.bind(this));
+ } else if (mode === 'client') {
+ this.client.sendMessage(message, this.displaySentMessage.bind(this));
+ }
+ },
+
+ sendBye: function App_sendBye() {
+ var mode = this.getApplicationMode();
+ if (mode === 'server') {
+ this.server.sendBye();
+ } else if (mode === 'client') {
+ this.client.sendBye();
+ }
+ }
+ };
}());
diff --git a/project/js/app.model.js b/project/js/app.model.js
index 782f677..9cf77a4 100644
--- a/project/js/app.model.js
+++ b/project/js/app.model.js
@@ -1,133 +1,85 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*jslint plusplus: true, sloppy: true, todo: true, vars: true, browser: true, devel: true, maxerr: 999 */
/*global $, tizen, app */
-
/**
-* @class Model
-*/
+ * @class Model
+ */
function Model() {
- 'use strict';
- this.adapter = null;
- this.serviceUUID = '5BCE9431-6C75-32AB-AFE0-2EC108A30860';
+ 'use strict';
+ this.adapter = null;
+ this.serviceUUID = '5BCE9431-6C75-32AB-AFE0-2EC108A30860';
}
(function () { // strict mode wrapper
- 'use strict';
- Model.prototype = {
-
- /**
- * API module initialisation
- */
- init: function Model_init(callback) {
- try {
- console.log('getDefaultAdapter');
- var time = new Date().getTime();
- this.adapter = tizen.bluetooth.getDefaultAdapter();
- console.log(
- 'getDefaultAdapter OK: ' +
- (new Date().getTime() - time) +
- ' milliseconds.'
- );
-
- this.adapter.setChangeListener({
- onstatechanged: function (powered) {
- if (!powered) {
- app.connectionLost();
- }
- }
- });
-
- callback();
- } catch (error) {
- app.ui.showMessagePopup(
- 'Problem with bluetooth device. ' +
- 'Application can\'t work properly: ' + error.message
- );
- tizen.application.getCurrentApplication().exit();
- }
- },
-
- checkPowerState: function Model_checkPowerState(
- showPowerOnButtonCallback,
- showStartButtonsCallback
- ) {
- if (!this.adapter.powered) {
- showPowerOnButtonCallback();
- } else {
- showStartButtonsCallback();
- }
- },
+ 'use strict';
+ Model.prototype = {
- powerOn: function Model_powerOn(callback) {
- if (!this.adapter.powered) {
- try {
- this.adapter.setPowered(true,
- function () {
- setTimeout(function () { callback(); }, 500);
- }
- );
- } catch (error) {
- app.ui.showMessagePopup(error.message);
- app.ui.showPowerOnButton();
- }
- } else {
- callback();
- }
- },
+ /**
+ * API module initialisation
+ */
+ init: function Model_init(callback) {
+ try {
+ console.log('getDefaultAdapter');
+ var time = new Date().getTime();
+ this.adapter = tizen.bluetooth.getDefaultAdapter();
+ console.log('getDefaultAdapter OK: ' + (new Date().getTime() - time) + ' milliseconds.');
+ callback();
+ } catch (error) {
+ app.ui.showMessagePopup('Problem with bluetooth device. Application can\'t work properly: ' + error.message);
+ tizen.application.getCurrentApplication().exit();
+ }
+ },
- powerOff: function Model_powerOff(callback) {
- var app = tizen.application.getCurrentApplication();
- if (this.adapter.powered) {
- this.adapter.setPowered(
- false,
- function () { callback(); },
- function () { callback(); }
- );
- } else {
- callback();
- }
- },
+ checkPowerState: function Model_checkPowerState(showPowerOnButtonCallback, showStartButtonsCallback) {
+ if (!this.adapter.powered) {
+ showPowerOnButtonCallback();
+ } else {
+ showStartButtonsCallback();
+ }
+ },
- restartBluetooth: function Model_restartBluetooth(callback) {
- if (this.adapter.powered) {
- this.adapter.setPowered(
- false,
- function () {
- setTimeout(function () { callback(); }, 500);
- },
- function () {}
- );
- } else {
- callback();
- }
- },
+ powerOn: function Model_powerOn(callback) {
+ if (!this.adapter.powered) {
+ try {
+ this.adapter.setPowered(true,
+ function () {
+ setTimeout(function () { callback(); }, 500);
+ }
+ );
+ } catch (error) {
+ app.ui.showMessagePopup(error.message);
+ app.ui.showPowerOnButton();
+ }
+ } else {
+ callback();
+ }
+ },
- setAdapterName: function Model_setAdapterName(changeName, callback) {
- if (changeName) {
- this.adapter.setName(app.currentName, function () {
- callback();
- }, function () {
- });
- } else {
- callback();
- }
- }
+ powerOff: function Model_powerOff(callback) {
+ var app = tizen.application.getCurrentApplication();
+ if (this.adapter.powered) {
+ this.adapter.setPowered(false, function () { callback(); }, function () { callback(); });
+ } else {
+ callback();
+ }
+ },
- };
+ restartBluetooth: function Model_restartBluetooth(callback) {
+ if (this.adapter.powered) {
+ this.adapter.setPowered(false, function () { setTimeout(function () { callback(); }, 500); }, function () {});
+ } else {
+ callback();
+ }
+ },
+ setAdapterName: function Model_setAdapterName(changeName, callback) {
+ if (changeName) {
+ this.adapter.setName(app.currentName, function () {
+ callback();
+ }, function () {
+ });
+ } else {
+ callback();
+ }
+ }
+ };
}());
diff --git a/project/js/app.server.js b/project/js/app.server.js
index 9200bd9..6cf5c5a 100644
--- a/project/js/app.server.js
+++ b/project/js/app.server.js
@@ -1,137 +1,93 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*global $, tizen, app, ServerModel */
-
/**
-* @class Server
-*/
+ * @class Server
+ */
+
function Server(adapter, serviceUUID) {
- 'use strict';
- this.adapter = adapter;
- this.serviceUUID = serviceUUID;
- this.numberOfClients = 0;
- this.globalRecordHandler = null;
- this.globalSocket = null;
- this.init();
+ 'use strict';
+ this.adapter = adapter;
+ this.serviceUUID = serviceUUID;
+ this.numberOfClients = 0;
+ this.globalRecordHandler = null;
+ this.globalSocket = null;
+ this.init();
}
(function () { // strict mode wrapper
- 'use strict';
-
- Server.prototype = {
- /**
- * @type clientModel
- */
- model: null,
-
- /**
- * Initialisation function
- */
- init: function Server_init() {
- this.model = new ServerModel(this);
- return this;
- },
+ 'use strict';
- getNumberOfClients: function Server_getNumberOfClients() {
- return this.numberOfClients;
- },
+ Server.prototype = {
+ /**
+ * @type clientModel
+ */
+ model: null,
- registerServer: function Server_registerServer() {
- this.model.registerServer(
- this.adapter,
- this.serviceUUID,
- this.registerServerSuccess.bind(this)
- );
- },
+ /**
+ * Initialisation function
+ */
+ init: function Server_init() {
+ this.model = new ServerModel(this);
+ return this;
+ },
- registerServerSuccess: function Server_registerServerSuccess(
- recordHandler
- ) {
- this.globalRecordHandler = recordHandler;
- recordHandler.onconnect = function (socket) {
- this.numberOfClients += 1;
- this.globalSocket = socket;
- socket.onmessage = function () {
- var data, recvmsg = '', i, len, messageObj;
- data = socket.readData();
- len = data.length;
- for (i = 0; i < len; i += 1) {
- recvmsg += String.fromCharCode(data[i]);
- }
- messageObj = JSON.parse(recvmsg);
- app.ui.displayReceivedMessage(
- messageObj.name,
- messageObj.text,
- messageObj.ping,
- messageObj.bye
- );
- };
- socket.onerror = function (e) {
- console.error('Server onerror');
- socket.close();
- };
- socket.onclose = function () {
- this.globalSocket = null;
- app.setConnection(false);
- app.clientDisconnected();
- };
- app.setConnection(true);
- }.bind(this);
- app.ui.showChatPage();
- },
+ getNumberOfClients: function Server_getNumberOfClients() {
+ return this.numberOfClients;
+ },
- unregisterChatServer: function Server_unregisterChatServer() {
- this.model.unregisterChatServer(
- this.globalRecordHandler,
- this.unregisterChatServerSuccess.bind(this),
- this.unregisterChatServerError.bind(this),
- app.ui.showStartButtons
- );
- },
+ registerServer: function Server_registerServer() {
+ this.model.registerServer(this.adapter, this.serviceUUID, this.registerServerSuccess.bind(this));
+ },
- unregisterChatServerSuccess:
- function Server_unregisterChatServerSuccess() {
- this.globalRecordHandler = null;
- this.numberOfClients = 0;
- app.restartBluetooth();
- },
+ registerServerSuccess: function Server_registerServerSuccess(recordHandler) {
+ this.globalRecordHandler = recordHandler;
+ recordHandler.onconnect = function (socket) {
+ this.numberOfClients += 1;
+ this.globalSocket = socket;
+ socket.onmessage = function () {
+ var data, recvmsg = '', i, len, messageObj;
+ data = socket.readData();
+ len = data.length;
+ for (i = 0; i < len; i += 1) {
+ recvmsg += String.fromCharCode(data[i]);
+ }
+ messageObj = JSON.parse(recvmsg);
+ app.ui.displayReceivedMessage(messageObj.name, messageObj.text, messageObj.ping, messageObj.bye);
+ };
+ socket.onerror = function (e) {
+ console.error('Server onerror');
+ socket.close();
+ };
+ socket.onclose = function () {
+ this.globalSocket = null;
+ app.setConnection(false);
+ };
+ app.setConnection(true);
+ }.bind(this);
+ app.ui.showChatPage();
+ },
- unregisterChatServerError: function Server_unregisterChatServerError() {
- console.error('Server_unregisterChatServerError');
- this.numberOfClients = 0;
- app.restartBluetooth();
- },
+ unregisterChatServer: function Server_unregisterChatServer() {
+ this.model.unregisterChatServer(this.globalRecordHandler, this.unregisterChatServerSuccess.bind(this), this.unregisterChatServerError.bind(this), app.ui.showStartButtons);
+ },
- sendMessage: function Server_sendMessage(message, callback) {
- this.model.sendMessage(
- this.adapter.name,
- this.globalSocket,
- message,
- callback
- );
- },
+ unregisterChatServerSuccess: function Server_unregisterChatServerSuccess() {
+ this.globalRecordHandler = null;
+ this.numberOfClients = 0;
+ app.restartBluetooth();
+ },
- sendBye: function Server_sendBye() {
- this.model.sendBye(
- this.adapter.name,
- this.globalSocket
- );
- }
+ unregisterChatServerError: function Server_unregisterChatServerError() {
+ console.error('Server_unregisterChatServerError');
+ this.numberOfClients = 0;
+ app.restartBluetooth();
+ },
- };
+ sendMessage: function Server_sendMessage(message, callback) {
+ this.model.sendMessage(this.adapter.name, this.globalSocket, message, callback);
+ },
+ sendBye: function Server_sendBye() {
+ this.model.sendBye(this.adapter.name, this.globalSocket);
+ }
+ };
}());
diff --git a/project/js/app.server.model.js b/project/js/app.server.model.js
index 7efba9f..771353e 100644
--- a/project/js/app.server.model.js
+++ b/project/js/app.server.model.js
@@ -1,123 +1,81 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*global $, tizen, app */
-
/**
-* @class Model
-*/
+ * @class Model
+ */
function ServerModel(parent) {
- 'use strict';
- this.server = parent;
- this.init();
+ 'use strict';
+ this.server = parent;
+ this.init();
}
(function () { // strict mode wrapper
- 'use strict';
- ServerModel.prototype = {
-
- /**
- * API module initialisation
- */
- init: function ServerModel_init() {},
+ 'use strict';
+ ServerModel.prototype = {
- registerServer: function ServerModel_registerServer(
- adapter,
- serviceUUID,
- callback
- ) {
- if (this.server.getNumberOfClients() === 0) {
- try {
- adapter.registerRFCOMMServiceByUUID(
- serviceUUID,
- 'Chat service',
- callback,
- function (error) {
- console.error(error.message);
- }
- );
- } catch (error) {
- console.error(error.message);
- }
- }
- },
+ /**
+ * API module initialisation
+ */
+ init: function ServerModel_init() {},
- unregisterChatServer: function ServerModel_unregisterChatServer(
- globalRecordHandler,
- successCallback,
- errorCallback,
- showButtonsCallback
- ) {
- try {
- if (globalRecordHandler !== null) {
- globalRecordHandler.unregister(
- successCallback,
- errorCallback
- );
- } else {
- showButtonsCallback();
- }
- } catch (error) {
- errorCallback();
- }
- },
+ registerServer: function ServerModel_registerServer(adapter, serviceUUID, callback) {
+ if (this.server.getNumberOfClients() === 0) {
+ try {
+ adapter.registerRFCOMMServiceByUUID(serviceUUID, 'Chat service', callback, function (error) { console.error(error.message); });
+ } catch (error) {
+ console.error(error.message);
+ }
+ }
+ },
- sendMessage: function ServerModel_sendMessage(
- name,
- socket,
- message,
- callback
- ) {
- var sendTextMsg = [], messageObj, messageObjToString, i, len;
- name = encodeURIComponent(name);
- message = encodeURIComponent(message);
- messageObj = {name: name, text: message, ping: false, bye: false};
- messageObjToString = JSON.stringify(messageObj);
- len = messageObjToString.length;
- for (i = 0; i < len; i += 1) {
- sendTextMsg[i] = messageObjToString.charCodeAt(i);
- }
- try {
- if (socket !== null && socket.state === "OPEN") {
- socket.writeData(sendTextMsg);
- callback(message);
- }
- } catch (error) {
- console.error('sendMessage: ' + error.message);
- }
- },
+ unregisterChatServer: function ServerModel_unregisterChatServer(globalRecordHandler, successCallback, errorCallback, showButtonsCallback) {
+ try {
+ if (globalRecordHandler !== null) {
+ globalRecordHandler.unregister(successCallback, errorCallback);
+ } else {
+ showButtonsCallback();
+ }
+ } catch (error) {
+ errorCallback();
+ }
+ },
- sendBye: function ServerModel_sendBye(name, socket) {
- var sendTextMsg = [], messageObj, messageObjToString, i, len;
- name = encodeURIComponent(name);
- messageObj = {name: name, text: '', ping: false, bye: true};
- messageObjToString = JSON.stringify(messageObj);
- len = messageObjToString.length;
- for (i = 0; i < len; i += 1) {
- sendTextMsg[i] = messageObjToString.charCodeAt(i);
- }
- try {
- if (socket !== null && socket.state === "OPEN") {
- socket.writeData(sendTextMsg);
- }
- } catch (error) {
- console.error('sendBye: ' + error.message);
- }
- }
+ sendMessage: function ServerModel_sendMessage(name, socket, message, callback) {
+ var sendTextMsg = [], messageObj, messageObjToString, i, len;
+ name = encodeURIComponent(name);
+ message = encodeURIComponent(message);
+ messageObj = {name: name, text: message, ping: false, bye: false};
+ messageObjToString = JSON.stringify(messageObj);
+ len = messageObjToString.length;
+ for (i = 0; i < len; i += 1) {
+ sendTextMsg[i] = messageObjToString.charCodeAt(i);
+ }
+ try {
+ if (socket !== null && socket.state === "OPEN") {
+ socket.writeData(sendTextMsg);
+ callback(message);
+ }
+ } catch (error) {
+ console.error('sendMessage: ' + error.message);
+ }
+ },
- };
+ sendBye: function ServerModel_sendBye(name, socket) {
+ var sendTextMsg = [], messageObj, messageObjToString, i, len;
+ name = encodeURIComponent(name);
+ messageObj = {name: name, text: '', ping: false, bye: true};
+ messageObjToString = JSON.stringify(messageObj);
+ len = messageObjToString.length;
+ for (i = 0; i < len; i += 1) {
+ sendTextMsg[i] = messageObjToString.charCodeAt(i);
+ }
+ try {
+ if (socket !== null && socket.state === "OPEN") {
+ socket.writeData(sendTextMsg);
+ }
+ } catch (error) {
+ console.error('sendBye: ' + error.message);
+ }
+ }
+ };
}());
diff --git a/project/js/app.ui.events.js b/project/js/app.ui.events.js
index 0ffadf0..f9ae99f 100644
--- a/project/js/app.ui.events.js
+++ b/project/js/app.ui.events.js
@@ -1,266 +1,214 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*global window, $, tizen, app */
-
+/*global $, tizen, app */
/**
-* @class UiEvents
-*/
+ * @class UiEvents
+ */
function UiEvents(parent) {
- 'use strict';
- this.ui = parent;
+ 'use strict';
+ this.ui = parent;
}
(function () { // strict mode wrapper
- 'use strict';
- UiEvents.prototype = {
-
- /**
- * Initialization
- */
- init: function UiEvents_init() {
- this.addPageEvents();
- },
-
- /**
- * Bind events to pages
- */
- addPageEvents: function UiEvents_addPageEvents() {
- var self = this;
-
- $('#start-header .ui-btn-back').on('click', function (event) {
- event.preventDefault();
- event.stopPropagation();
- app.powerOff();
- });
-
- $('#choose-footer').on('click', '.ui-btn-back', function (event) {
- event.preventDefault();
- event.stopPropagation();
- app.setDoNotSendBye(true);
- $.mobile.changePage('#start');
- });
-
- $('#chat-header').on('click', '.ui-btn-back', function (event) {
- event.preventDefault();
- event.stopPropagation();
- if (!app.isConnection()) {
- app.setDoNotSendBye(true);
- }
- $.mobile.changePage('#start');
- });
-
- $('#chat-header').on('click', '.ui-btn-back', function (event) {
- event.preventDefault();
- });
-
- $('#start').on('pagebeforeshow', function () {
- self.ui.hideStartButtons();
- self.ui.clearChatDialog();
- if (!app.getDoNotSendBye()) {
- app.sendBye();
- } else {
- app.setDoNotSendBye(false);
- }
- if (app.getApplicationMode() === 'server') {
- app.server.unregisterChatServer();
- } else if (app.getApplicationMode() === 'client') {
- app.client.destroyBonding();
- }
- });
-
- $('#turnOnButton').on('click', function (event) {
- self.ui.hideStartButtons();
- app.powerOn();
- });
-
- $('#serverButton').on('click', function (event) {
- app.resetApplicationMode();
- app.startServer();
- });
-
- $('#clientButton').on('click', function (event) {
- app.resetApplicationMode();
- app.startClient();
- });
-
- $('#keyboard').on('pagebeforeshow', function () {
- $('#keyboard-text').val('').attr(
- 'placeholder',
- 'Type ' + app.getApplicationMode() + ' name'
- );
- $('#keyboard-header > h1').html(
- 'Type ' + app.getApplicationMode() + ' name'
- );
- });
-
- $('#keyboard').on('pageshow', function () {
- setTimeout(function () { $('#keyboard-text').focus(); }, 500);
- });
-
- $('#keyboard-ok-button').on('click', function (event) {
- event.preventDefault();
- var value = $('#keyboard-text').val(), mode;
- if (value.length !== 0) {
- app.setUserName(value);
- mode = app.getApplicationMode();
- if (mode === 'server') {
- app.setAdapterName();
- } else if (mode === 'client') {
- $.mobile.changePage('#choose');
- }
- }
- });
-
- $('#keyboard-text').on('input', function (event) {
- var btn = $('#keyboard-ok-button');
-
- if ($(this).val().length > 0) {
- if (btn.hasClass('ui-disabled')) {
- btn.removeClass('ui-disabled');
- }
- } else {
- btn.addClass('ui-disabled');
- }
- });
-
- $('#choose').on('pagebeforeshow', function () {
- app.setAdapterName();
- });
-
- $('#choose').on('pagehide', function () {
- app.clearListOfServers();
- app.client.stopServerSearching();
- });
-
- $('#choose-content').on('click', 'ul.ui-listview li', function () {
- app.client.stopServerSearching($(this).attr('address'));
- });
-
- $('#chat').on('pagebeforeshow', function () {
- $('#chat-header-type').html(app.getApplicationMode());
- $('#chat-header-name').html(app.getCurrentName());
- if ($(this).data('serverName') !== undefined) {
- $('#chat-header-type').append(
- ' - connected to ' + $(this).data('serverName')
- );
- $(this).removeData('serverName');
- }
- self.ui.checkSendButtonState();
- });
-
- $('#chat').on('pageshow', function () {
- if (
- app.getApplicationMode() === 'server' &&
- !app.isBluetoothVisible()
- ) {
- setTimeout(
- function () {
- app.ui.showMessagePopup(
- 'Please make your Bluetooth ' +
- 'visible in Settings.'
- );
- },
- 500
- );
- }
- });
-
- $('#chat').on('pagehide', function () {
- $('#text').val('');
- app.setConnection(false);
- });
-
- $('#text').on('input', function () {
- self.ui.checkSendButtonState();
- });
-
- $('#text').on('focus', function () {
- var content = $('#chat-content');
- if (self.ui.scrolltimeout !== null) {
- clearTimeout(self.ui.scrolltimeout);
- }
- self.ui.scrolltimeout = setTimeout(function () {
- self.ui.scrolltimeout = null;
- self.ui.scrollToBottom(content);
- }, 1000);
- });
-
- $('#text').on('blur', function () {
- var content = $('#chat-content');
- if (self.ui.scrolltimeout !== null) {
- clearTimeout(self.ui.scrolltimeout);
- }
- self.ui.scrolltimeout = setTimeout(function () {
- self.ui.scrolltimeout = null;
- self.ui.scrollToBottom(content);
- }, 700);
- });
-
- $('#ui-mySend').on('click', function (event) {
- event.stopPropagation();
- var message = $('#text').val();
- if (message.length === 0) {
- return;
- }
- $('#text').val('');
- self.ui.disableSendButton();
- app.sendMessage(message);
- });
-
- $('body').on('click', '#byeOK', function () {
- self.ui.hideByePopup();
- $('#keyboard-back-button').trigger('click');
- });
-
- $('body').on('touchstart', '#byePopup-screen', function () {
- $('#byeOK').trigger('click');
- });
-
- $('body').on('click', '#messageOK', function () {
- self.ui.hideMessagePopup();
- });
-
- $('body').on('touchstart', '#messagePopup-screen', function () {
- $('#messageOK').trigger('click');
- });
-
- $('#chat-content').on('touchstart', function () {
- if (self.ui.scrolltimeout !== null) {
- clearTimeout(self.ui.scrolltimeout);
- self.ui.scrolltimeout = null;
- }
- });
-
- window.addEventListener('tizenhwkey', function (e) {
- if (e.keyName === 'back') {
- event.preventDefault();
- app.setDoNotSendBye(true);
- if ($.mobile.activePage.attr('id') === 'start') {
- tizen.application.getCurrentApplication().exit();
- } else if ($.mobile.activePage.attr('id') === 'chat') {
- $.mobile.changePage('#start');
- } else {
- history.back();
- }
- }
- });
-
- }
-
- };
-
+ 'use strict';
+ UiEvents.prototype = {
+
+ /**
+ * Initialization
+ */
+ init: function UiEvents_init() {
+ this.addPageEvents();
+ },
+
+ /**
+ * Bind events to pages
+ */
+ addPageEvents: function UiEvents_addPageEvents() {
+ var self = this;
+
+ $('#start-header .ui-btn-back').on('click', function (event) {
+ event.preventDefault();
+ event.stopPropagation();
+ app.powerOff();
+ });
+
+ $('#choose-footer').on('click', '.ui-btn-back', function (event) {
+ event.preventDefault();
+ event.stopPropagation();
+ app.setDoNotSendBye(true);
+ $.mobile.changePage('#start');
+ });
+
+ $('#chat-header').on('click', '.ui-btn-back', function (event) {
+ event.preventDefault();
+ event.stopPropagation();
+ if (!app.isConnection()) {
+ app.setDoNotSendBye(true);
+ }
+ $.mobile.changePage('#start');
+ });
+
+ $('#chat-header').on('click', '.ui-btn-back', function (event) {
+ event.preventDefault();
+ });
+
+ $('#start').on('pagebeforeshow', function () {
+ self.ui.hideStartButtons();
+ self.ui.clearChatDialog();
+ if (!app.getDoNotSendBye()) {
+ app.sendBye();
+ } else {
+ app.setDoNotSendBye(false);
+ }
+ if (app.getApplicationMode() === 'server') {
+ app.server.unregisterChatServer();
+ } else if (app.getApplicationMode() === 'client') {
+ app.client.destroyBonding();
+ }
+ });
+
+ $('#turnOnButton').on('click', function (event) {
+ self.ui.hideStartButtons();
+ app.powerOn();
+ });
+
+ $('#serverButton').on('click', function (event) {
+ app.resetApplicationMode();
+ app.startServer();
+ });
+
+ $('#clientButton').on('click', function (event) {
+ app.resetApplicationMode();
+ app.startClient();
+ });
+
+ $('#keyboard').on('pagebeforeshow', function () {
+ $('#keyboard-text').val('').attr('placeholder', 'Type ' + app.getApplicationMode() + ' name');
+ $('#keyboard-header > h1').html('Type ' + app.getApplicationMode() + ' name');
+ });
+
+ $('#keyboard').on('pageshow', function () {
+ setTimeout(function () { $('#keyboard-text').focus(); }, 500);
+ });
+
+ $('#keyboard-ok-button').on('click', function (event) {
+ event.preventDefault();
+ var value = $('#keyboard-text').val(), mode;
+ if (value.length !== 0) {
+ app.setUserName(value);
+ mode = app.getApplicationMode();
+ if (mode === 'server') {
+ app.setAdapterName();
+ } else if (mode === 'client') {
+ $.mobile.changePage('#choose');
+ }
+ }
+ });
+
+ $('#choose').on('pagebeforeshow', function () {
+ app.setAdapterName();
+ });
+
+ $('#choose').on('pagehide', function () {
+ app.clearListOfServers();
+ app.client.stopServerSearching();
+ });
+
+ $('#choose-content').on('click', 'ul.ui-listview li', function () {
+ app.client.stopServerSearching($(this).attr('address'));
+ });
+
+ $('#chat').on('pagebeforeshow', function () {
+ $('#chat-header-type').html(app.getApplicationMode());
+ $('#chat-header-name').html(app.getCurrentName());
+ if ($(this).data('serverName') !== undefined) {
+ $('#chat-header-type').append(' - connected to ' + $(this).data('serverName'));
+ $(this).removeData('serverName');
+ }
+ self.ui.checkSendButtonState();
+ });
+
+ $('#chat').on('pageshow', function () {
+ if (app.getApplicationMode() === 'server' && !app.isBluetoothVisible()) {
+ setTimeout(function () { app.ui.showMessagePopup('Please make your Bluetooth visible in Settings.'); }, 500);
+ }
+ });
+
+ $('#chat').on('pagehide', function () {
+ $('#text').val('');
+ app.setConnection(false);
+ });
+
+ $('#text').on('input', function () {
+ self.ui.checkSendButtonState();
+ });
+
+ $('#text').on('focus', function () {
+ var content = $('#chat-content');
+ if (self.ui.scrolltimeout !== null) {
+ clearTimeout(self.ui.scrolltimeout);
+ }
+ self.ui.scrolltimeout = setTimeout(function () {
+ self.ui.scrolltimeout = null;
+ self.ui.scrollToBottom(content);
+ }, 1000);
+ });
+
+ $('#text').on('blur', function () {
+ var content = $('#chat-content');
+ if (self.ui.scrolltimeout !== null) {
+ clearTimeout(self.ui.scrolltimeout);
+ }
+ self.ui.scrolltimeout = setTimeout(function () {
+ self.ui.scrolltimeout = null;
+ self.ui.scrollToBottom(content);
+ }, 700);
+ });
+
+ $('#ui-mySend').on('click', function (event) {
+ event.stopPropagation();
+ var message = $('#text').val();
+ $('#text').val('');
+ self.ui.disableSendButton();
+ app.sendMessage(message);
+ });
+
+ $('body').on('click', '#byeOK', function () {
+ self.ui.hideByePopup();
+ $('#keyboard-back-button').trigger('click');
+ });
+
+ $('body').on('touchstart', '#byePopup-screen', function () {
+ $('#byeOK').trigger('click');
+ });
+
+ $('body').on('click', '#messageOK', function () {
+ self.ui.hideMessagePopup();
+ });
+
+ $('body').on('touchstart', '#messagePopup-screen', function () {
+ $('#messageOK').trigger('click');
+ });
+
+ $('#chat-content').on('touchstart', function () {
+ if (self.ui.scrolltimeout !== null) {
+ clearTimeout(self.ui.scrolltimeout);
+ self.ui.scrolltimeout = null;
+ }
+ });
+
+ window.addEventListener('tizenhwkey', function(e) {
+ if (e.keyName == "back") {
+ event.preventDefault();
+ app.setDoNotSendBye(true);
+ if ($.mobile.activePage.attr('id') === 'start') {
+ tizen.application.getCurrentApplication().exit();
+ } else if ($.mobile.activePage.attr('id') === 'chat') {
+ $.mobile.changePage('#start');
+ } else {
+ history.back();
+ }
+ }
+ });
+
+ }
+ };
}());
diff --git a/project/js/app.ui.js b/project/js/app.ui.js
index 5123418..9bd9d99 100644
--- a/project/js/app.ui.js
+++ b/project/js/app.ui.js
@@ -1,349 +1,245 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
/*global $, tizen, app, UiEvents, TemplateManager, document, window, setTimeout */
-
/**
-* @class Ui
-*/
+ * @class Ui
+ */
+
function Ui(callback) {
- 'use strict';
- this.init(callback);
+ 'use strict';
+ this.init(callback);
}
(function () { // strict mode wrapper
- 'use strict';
- Ui.prototype = {
-
- templateManager: null,
-
- /**
- * UI object for UI events
- */
- uiEvents: null,
-
- /**
- * Timeout for chat scroll.
- */
- scrolltimeout: null,
-
- /**
- * UI module initialisation
- */
- init: function Ui_init(callback) {
- this.templateManager = new TemplateManager();
- this.uiEvents = new UiEvents(this);
- $.mobile.tizen.disableSelection(document);
-
- $(document).ready(this.domInit.bind(this, callback));
- },
-
- /**
- * When DOM is ready, initialise it (bind events)
- */
- domInit: function Ui_domInit(callback) {
- var templates = [
- 'keyboard_page',
- 'chat_page',
- 'choose_page',
- 'server_row',
- 'left_bubble',
- 'right_bubble',
- 'bye_popup',
- 'message_popup'
- ];
-
- this.templateManager.loadToCache(
- templates,
- this.initPages.bind(this, callback)
- );
- },
-
- initPages: function Ui_initPages(callback) {
- var pages = [], body = $('body');
-
- body.append(this.templateManager.get('bye_popup'))
- .append(this.templateManager.get('message_popup'))
- .trigger('create');
-
- pages.push(this.templateManager.get('keyboard_page'));
- pages.push(this.templateManager.get('chat_page'));
- pages.push(this.templateManager.get('choose_page'));
- body.append(pages.join(''));
-
- this.uiEvents.init();
- this.fixContentHeight();
- callback();
- },
-
- setContentStartAttributes: function Ui_setContentStartAttributes(
- callback
- ) {
- var contentStart, contentStartHeight;
- contentStart = $('#start-content');
- if (contentStart.height() > $(window).height()) {
- contentStartHeight =
- $(window).height() -
- $('#start-header').height() -
- parseInt(contentStart.css('padding-top'), 10) -
- parseInt(contentStart.css('padding-bottom'), 10);
- } else {
- contentStartHeight = contentStart.height();
- }
- setTimeout(function () { // workaround (setTimeout with 0 delay)
- contentStart
- .css('height', contentStartHeight + 'px')
- .css('min-height', 'auto')
- .css('width', contentStart.width() + 'px');
- $('#start').css('min-height', 'auto');
- callback();
- }, 0);
- },
-
- showChatPage: function Ui_showChatPage(serverName) {
- if (serverName !== undefined) {
- serverName = this.escape(serverName);
- $('#chat').data('serverName', serverName);
- }
- $.mobile.changePage('#chat');
- },
-
- showKeyboardPage: function Ui_showKeyboardPage() {
- $.mobile.changePage('#keyboard');
- },
-
- clearChatDialog: function Ui_clearChatDialog() {
- $('#chat-content .ui-listview').empty();
- },
-
- showPowerOnButton: function Ui_showPowerOnButton() {
- $('#start-monit').hide();
- $('#serverButton').hide();
- $('#clientButton').hide();
- $('#turnOnButton').show();
- },
-
- showStartButtons: function Ui_showStartButtons() {
- $('#start-monit').hide();
- $('#turnOnButton').hide();
- $('#serverButton').show();
- $('#clientButton').show();
- },
-
- hideStartButtons: function Ui_hideStartButtons() {
- $('#serverButton').hide();
- $('#clientButton').hide();
- $('#turnOnButton').hide();
- $('#start-monit').show();
- },
-
- addDeviceToList: function Ui_addDeviceToList(device) {
- var listElement,
- address,
- sub2,
- ul = $('#choose-content ul.ui-listview');
-
- listElement = this.templateManager.get('server_row', {
- 'deviceAddress': device.address,
- 'deviceName': device.name
- });
-
- ul.append(listElement);
- ul.listview('refresh');
- },
-
- clearListOfServers: function Ui_clearListOfServers() {
- $('#choose-content ul.ui-listview').empty();
- },
-
- showByePopup: function Ui_showByePopup(name) {
- var mode = app.getApplicationMode(), message = $('#byeMessage');
- if (mode === 'server') {
- message.html(
- 'Client name "' +
- this.escape(name) +
- '" is unavailable.\n' +
- 'Your bluetooth device will be automatically restarted.'
- );
- } else if (mode === 'client') {
- message.html(
- 'Server name "' +
- this.escape(name) +
- '" is unavailable.\n' +
- 'Your bluetooth device will be automatically restarted.'
- );
- }
- $('#byePopup').popup('open', {'positionTo': 'window'});
- },
-
- hideByePopup: function Ui_hideByePopup() {
- $('#byePopup').popup('close');
- },
-
- showMessagePopup: function Ui_showMessagePopup(message) {
- var messagePopup = $('#messagePopup');
- messagePopup.find('.ui-popup-text').text(message);
- messagePopup.popup('open', {'positionTo': 'window'});
- },
-
- hideMessagePopup: function Ui_hideMessagePopup() {
- $('#messagePopup').popup('close');
- },
-
- displayReceivedMessage: function Ui_displayReceivedMessage(
- name,
- text,
- ping,
- bye
- ) {
- var listElement, span, ul;
- text = decodeURIComponent(text);
- name = decodeURIComponent(name);
- name = this.escape(name);
- if (bye) {
- this.showByePopup(name);
- } else if (ping) {
- app.setConnection(true);
- this.setHeaderType('server - connected with ' + name);
- this.checkSendButtonState();
- } else {
- listElement = this.templateManager.get('left_bubble', {
- 'text': text
- });
- ul = $('#chat-content > .ui-scrollview-view > ul');
- ul.append(listElement);
- ul.listview('refresh');
- }
- },
-
- setHeaderType: function Ui_setHeaderType(message) {
- $('#chat-header-type').html(message);
- },
-
- enableSendButton: function Ui_enableSendButton() {
- $('#ui-mySend')
- .css({'pointer-events': 'auto', 'color': '#000'})
- .removeClass('ui-disabled');
- },
-
- disableSendButton: function Ui_disableSendButton() {
- $('#ui-mySend')
- .css({'pointer-events': 'none', 'color': '#bbb'})
- .addClass('ui-disabled');
- },
-
- checkSendButtonState: function Ui_checkSendButtonState() {
- if (
- app.helpers.checkStringLength($('#text').val().trim()) &&
- app.isConnection()
- ) {
- this.enableSendButton();
- } else {
- this.disableSendButton();
- }
- },
-
- scrollToBottom: function Ui_scrollToBottom(element) {
- var bottom =
- element.children().first().outerHeight(true) - element.height();
- element.scrollview('scrollTo', 0, -Math.max(0, bottom), 0);
- },
-
- displaySentMessage: function Ui_displaySentMessage(message) {
- var listElement, span, ul, content, self = this;
- message = decodeURIComponent(message);
- listElement = this.templateManager.get('right_bubble', {
- 'text': message
- });
- content = $('#chat-content');
- ul = content.find('ul');
- ul.append(listElement);
- ul.listview('refresh');
- this.checkSendButtonState();
- this.scrolltimeout = setTimeout(function () {
- self.scrolltimeout = null;
- self.scrollToBottom(content);
- }, 700);
- },
-
- setDiscoveringProgress: function Ui_setDiscoveringProgress(boolean) {
- $('#discovering')
- .progress('hide', !boolean)
- .progress('running', boolean);
- },
-
- fixContentHeight: function Ui_fixContentHeight() {
- var contentHeight =
- screen.availHeight -
- $('div[data-role="header"]').outerHeight() -
- $('div[data-role="footer"]').outerHeight();
- $('div[data-role="content"]').css('height', contentHeight);
- },
-
- popup: function Ui_popup(text, callback, buttons) {
- var i, popup = $("#popup");
-
- if (!popup.hasClass('ui-popup')) {
- popup.popup();
- }
-
- if (!buttons) {
- buttons = {
- 'OK': function () {
- $("#popup").popup('close');
- }
- };
- }
-
- $(".ui-popup-button-bg", popup).empty();
-
- popup[0].className =
- popup[0].className.replace(/\bcenter_basic.*?\b/g, '');
- popup.addClass(
- 'center_basic_' + Object.keys(buttons).length + 'btn'
- );
-
- for (i in buttons) {
- if (buttons.hasOwnProperty(i)) {
- if (buttons[i]) {
- $('<a/>')
- .text(i)
- .attr(
- {
- 'data-role': 'button',
- 'data-inline': 'true'
- }
- )
- .bind('click', buttons[i])
- .appendTo($(".ui-popup-button-bg", popup));
- }
- }
- }
- $(".ui-popup-text p", popup).text(text);
-
- if (callback instanceof Function) {
- popup.one("popupafterclose", callback);
- }
- popup.trigger("create");
- popup.popup('open', {positionTo: 'window'});
- },
-
- escape: function Ui_escape(str) {
- return $('<span>').text(str).html();
- }
- };
+ 'use strict';
+ Ui.prototype = {
+
+ templateManager: null,
+
+ /**
+ * UI object for UI events
+ */
+ uiEvents: null,
+
+ /**
+ * Timeout for chat scroll.
+ */
+ scrolltimeout: null,
+
+ /**
+ * UI module initialisation
+ */
+ init: function Ui_init(callback) {
+ this.templateManager = new TemplateManager();
+ this.uiEvents = new UiEvents(this);
+ $.mobile.tizen.disableSelection(document);
+
+ $(document).ready(this.domInit.bind(this, callback));
+ },
+
+ /**
+ * When DOM is ready, initialise it (bind events)
+ */
+ domInit: function Ui_domInit(callback) {
+ var templates = [
+ 'keyboard_page',
+ 'chat_page',
+ 'choose_page',
+ 'server_row',
+ 'left_bubble',
+ 'right_bubble',
+ 'bye_popup',
+ 'message_popup'
+ ];
+
+ this.templateManager.loadToCache(templates, this.initPages.bind(this, callback));
+ },
+
+ initPages: function Ui_initPages(callback) {
+ var pages = [], body = $('body');
+
+ body.append(this.templateManager.get('bye_popup'))
+ .append(this.templateManager.get('message_popup'))
+ .trigger('create');
+
+ pages.push(this.templateManager.get('keyboard_page'));
+ pages.push(this.templateManager.get('chat_page'));
+ pages.push(this.templateManager.get('choose_page'));
+ body.append(pages.join(''));
+
+ this.uiEvents.init();
+ this.fixContentHeight();
+ callback();
+ },
+
+ setContentStartAttributes: function Ui_setContentStartAttributes(callback) {
+ var contentStart, contentStartHeight;
+ contentStart = $('#start-content');
+ if (contentStart.height() > $(window).height()) {
+ contentStartHeight = $(window).height() - $('#start-header').height()
+ - parseInt(contentStart.css('padding-top'), 10) - parseInt(contentStart.css('padding-bottom'), 10);
+ } else {
+ contentStartHeight = contentStart.height();
+ }
+ setTimeout(function () { // workaround (setTimeout with 0 delay)
+ contentStart
+ .css('height', contentStartHeight + 'px')
+ .css('min-height', 'auto')
+ .css('width', contentStart.width() + 'px');
+ $('#start').css('min-height', 'auto');
+ callback();
+ }, 0);
+ },
+
+ showChatPage: function Ui_showChatPage(serverName) {
+ if (serverName !== undefined) {
+ $('#chat').data('serverName', serverName);
+ }
+ $.mobile.changePage('#chat');
+ },
+
+ showKeyboardPage: function Ui_showKeyboardPage() {
+ $.mobile.changePage('#keyboard');
+ },
+
+ clearChatDialog: function Ui_clearChatDialog() {
+ $('#chat-content .ui-listview').empty();
+ },
+
+ showPowerOnButton: function Ui_showPowerOnButton() {
+ $('#start-monit').hide();
+ $('#serverButton').hide();
+ $('#clientButton').hide();
+ $('#turnOnButton').show();
+ },
+
+ showStartButtons: function Ui_showStartButtons() {
+ $('#start-monit').hide();
+ $('#turnOnButton').hide();
+ $('#serverButton').show();
+ $('#clientButton').show();
+ },
+
+ hideStartButtons: function Ui_hideStartButtons() {
+ $('#serverButton').hide();
+ $('#clientButton').hide();
+ $('#turnOnButton').hide();
+ $('#start-monit').show();
+ },
+
+ addDeviceToList: function Ui_addDeviceToList(device) {
+ var listElement, address, sub2, ul = $('#choose-content ul.ui-listview');
+
+ listElement = this.templateManager.get('server_row', {
+ 'deviceAddress': device.address,
+ 'deviceName': device.name
+ });
+
+ ul.append(listElement);
+ ul.listview('refresh');
+ },
+
+ clearListOfServers: function Ui_clearListOfServers() {
+ $('#choose-content ul.ui-listview').empty();
+ },
+
+ showByePopup: function Ui_showByePopup(name) {
+ var mode = app.getApplicationMode(), message = $('#byeMessage');
+ if (mode === 'server') {
+ message.html('Client name "' + name + '" is unavailable.\nYour bluetooth device will be automatically restarted.');
+ } else if (mode === 'client') {
+ message.html('Server name "' + name + '" is unavailable.\nYour bluetooth device will be automatically restarted.');
+ }
+ $('#byePopup').popup('open', {'positionTo': 'window'});
+ },
+
+ hideByePopup: function Ui_hideByePopup() {
+ $('#byePopup').popup('close');
+ },
+
+ showMessagePopup: function Ui_showMessagePopup(message) {
+ var messagePopup = $('#messagePopup');
+ messagePopup.find('.ui-popup-text').text(message);
+ messagePopup.popup('open', {'positionTo': 'window'});
+ },
+
+ hideMessagePopup: function Ui_hideMessagePopup() {
+ $('#messagePopup').popup('close');
+ },
+
+ displayReceivedMessage: function Ui_displayReceivedMessage(name, text, ping, bye) {
+ var listElement, span, ul;
+ text = decodeURIComponent(text);
+ name = decodeURIComponent(name);
+ if (bye) {
+ this.showByePopup(name);
+ } else if (ping) {
+ app.setConnection(true);
+ $('#chat-header-type').append(' - connected with ' + name);
+ this.checkSendButtonState();
+ } else {
+ listElement = this.templateManager.get('left_bubble', {
+ 'text': text
+ });
+ ul = $('#chat-content > .ui-scrollview-view > ul');
+ ul.append(listElement);
+ ul.listview('refresh');
+ }
+ },
+
+ enableSendButton: function Ui_enableSendButton() {
+ $('#ui-mySend')
+ .css({'pointer-events': 'auto', 'color': '#000'})
+ .removeClass('ui-disabled');
+ },
+
+ disableSendButton: function Ui_disableSendButton() {
+ setTimeout( function() {
+ $('#ui-mySend')
+ .css({'pointer-events': 'none', 'color': '#bbb'})
+ .addClass('ui-disabled');
+ },
+ 0
+ );
+ },
+
+ checkSendButtonState: function Ui_checkSendButtonState() {
+ if (app.helpers.checkStringLength($('#text').val().trim()) && app.isConnection()) {
+ this.enableSendButton();
+ } else {
+ this.disableSendButton();
+ }
+ },
+
+ scrollToBottom: function Ui_scrollToBottom(element) {
+ var bottom = element.children().first().outerHeight(true) - element.height();
+ element.scrollview('scrollTo', 0, -Math.max(0, bottom), 0);
+ },
+
+ displaySentMessage: function Ui_displaySentMessage(message) {
+ var listElement, span, ul, content, self = this;
+ message = decodeURIComponent(message);
+ listElement = this.templateManager.get('right_bubble', {
+ 'text': message
+ });
+ content = $('#chat-content');
+ ul = content.find('ul');
+ ul.append(listElement);
+ ul.listview('refresh');
+ this.checkSendButtonState();
+ this.scrolltimeout = setTimeout(function () {
+ self.scrolltimeout = null;
+ self.scrollToBottom(content);
+ }, 700);
+ },
+
+ setDiscoveringProgress: function Ui_setDiscoveringProgress(boolean) {
+ $('#discovering').progress('hide', !boolean).progress('running', boolean);
+ },
+
+ fixContentHeight: function Ui_fixContentHeight() {
+ var contentHeight = screen.availHeight - $('div[data-role="header"]').outerHeight() - $('div[data-role="footer"]').outerHeight();
+ $('div[data-role="content"]').css('height', contentHeight);
+ }
+
+ };
}());
diff --git a/project/js/app.ui.templateManager.js b/project/js/app.ui.templateManager.js
index c880c5e..68c6678 100644
--- a/project/js/app.ui.templateManager.js
+++ b/project/js/app.ui.templateManager.js
@@ -1,187 +1,111 @@
-/*
-* Copyright 2013 Samsung Electronics Co., Ltd
-*
-* Licensed under the Flora License, Version 1.1 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://floralicense.org/license/
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-/*global tizen, $, app, ModifierManager */
-
+/*global tizen, $, app */
/**
-* @class TemplateManager
-*/
+ * @class TemplateManager
+ */
function TemplateManager() {
- 'use strict';
- this.init();
+ 'use strict';
+ this.init();
}
(function () { // strict mode wrapper
- 'use strict';
-
- TemplateManager.prototype = {
-
- /**
- * Template cache
- */
- cache: {},
-
- /**
- * UI module initialisation
- */
- init: function init() {
- this.modifiers = new ModifierManager().getAll();
- },
-
- /**
- * Returns template html (from cache)
- * @param {string} tplName
- * @param {string} tplParams
- */
- get: function TemplateManager_get(tplName, tplParams) {
- if (this.cache[tplName] !== undefined) {
- return this.getCompleted(this.cache[tplName], tplParams);
- }
- return '';
- },
-
- /**
- * Load templates to cache
- * @param {string} tplNames
- * @param {function} onSuccess
- */
- loadToCache: function TemplateManager_loadToCache(tplNames, onSuccess) {
- var self = this,
- cachedTemplates = 0,
- tplName,
- tplPath;
-
- if ($.isArray(tplNames)) {
-
- // for each template
- $.each(tplNames, function (index, fileName) {
-
- // cache template html
- if (self.cache[fileName] === undefined) {
- tplName = [
- fileName,
- app.config.get('templateExtension')
- ].join('');
- tplPath = [
- app.config.get('templateDir'),
- tplName
- ].join('/');
-
- $.ajax({
- url: tplPath,
- cache: true,
- dataType: 'html',
- async: true,
- success: function (data) {
- // increase counter
- cachedTemplates += 1;
-
- // save to cache
- self.cache[fileName] = data;
-
- // if all templates are cached launch callback
- if (
- cachedTemplates >= tplNames.length &&
- typeof onSuccess === 'function'
- ) {
- onSuccess();
- }
- },
- error: function (jqXHR, textStatus, errorThrown) {
- console.error(
- 'templateManagerError: ' +
- errorThrown
- );
- }
- });
- } else {
- // template is already cached
- cachedTemplates += 1;
- // if all templates are cached launch callback
- if (
- cachedTemplates >= tplNames.length &&
- typeof onSuccess === 'function'
- ) {
- onSuccess();
- }
- }
- });
-
- }
- },
-
- /**
- * Returns template completed by specified params
- * @param {string} tplHtml
- * @param {string} tplParams
- */
- getCompleted: function TemplateManager_getCompleted(
- tplHtml,
- tplParams
- ) {
- var tplParam;
-
- for (tplParam in tplParams) {
- if (tplParams.hasOwnProperty(tplParam)) {
- tplHtml = this.passThruModifiers(
- tplHtml,
- tplParam,
- tplParams[tplParam]
- );
- }
- }
-
- return tplHtml;
- },
-
- /**
- * Returns template completed by specified params
- * including modifiers
- * @param {string} tplHtml
- * @param {string} tplParams
- * @param {string} content
- */
- passThruModifiers: function (tplHtml, tplParam, content) {
- var regModOn = new RegExp('%' + tplParam + '(\\|(.+?)){1,}%', 'g'),
- regModOff = new RegExp(['%', tplParam, '%'].join(''), 'g'),
- regModGet = new RegExp('%' + tplParam + '\\|(.+?)%'),
- regModPut = new RegExp('%' + tplParam + '\\|(.+?)%', 'g'),
- specRegExp = new RegExp('\\$', 'g'),
- modifiers,
- i;
-
- if (content && (typeof content === 'string')) {
- content = content.replace(specRegExp, '$$$$');
- }
-
- if (regModOn.test(tplHtml)) {
- modifiers = tplHtml.match(regModGet)[1].split('|');
- for (i in modifiers) {
- if (this.modifiers[modifiers[i]] instanceof Function) {
- content = this.modifiers[modifiers[i]](content);
- } else {
- console.error('unknown modifier: ' + modifiers[i]);
- }
- }
- tplHtml = tplHtml.replace(regModPut, content);
- }
- tplHtml = tplHtml.replace(regModOff, content);
-
- return tplHtml;
- }
- };
-
-}());
+ 'use strict';
+ TemplateManager.prototype = {
+
+ /**
+ * Template cache
+ */
+ cache: {},
+
+ /**
+ * UI module initialisation
+ */
+ init: function init() {
+ },
+
+ /**
+ * Returns template html (from cache)
+ * @param {string} tplName
+ * @param {string} tplParams
+ */
+ get: function TemplateManager_get(tplName, tplParams) {
+ if (this.cache[tplName] !== undefined) {
+ return this.getCompleted(this.cache[tplName], tplParams);
+ }
+ return '';
+ },
+
+ /**
+ * Load templates to cache
+ * @param {string} tplNames
+ * @param {function} onSuccess
+ */
+ loadToCache: function TemplateManager_loadToCache(tplNames, onSuccess) {
+ var self = this,
+ cachedTemplates = 0,
+ tplName,
+ tplPath;
+
+ if ($.isArray(tplNames)) {
+
+ // for each template
+ $.each(tplNames, function (index, fileName) {
+
+ // cache template html
+ if (self.cache[fileName] === undefined) {
+ tplName = [fileName, app.config.get('templateExtension')].join('');
+ tplPath = [app.config.get('templateDir'), tplName].join('/');
+
+ $.ajax({
+ url: tplPath,
+ cache: true,
+ dataType: 'html',
+ async: true,
+ success: function (data) {
+ // increase counter
+ cachedTemplates += 1;
+
+ // save to cache
+ self.cache[fileName] = data;
+
+ // if all templates are cached launch callback
+ if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
+ onSuccess();
+ }
+ },
+ error: function (jqXHR, textStatus, errorThrown) {
+ console.error('templateManagerError: ' + errorThrown);
+ }
+ });
+ } else {
+ // template is already cached
+ cachedTemplates += 1;
+ // if all templates are cached launch callback
+ if (cachedTemplates >= tplNames.length && typeof onSuccess === 'function') {
+ onSuccess();
+ }
+ }
+ });
+
+ }
+ },
+
+ /**
+ * Returns template completed by specified params
+ * @param {string} tplHtml
+ * @param {string} tplParams
+ */
+ getCompleted: function TemplateManager_getCompleted(tplHtml, tplParams) {
+ var tplParam, replaceRegExp;
+
+ for (tplParam in tplParams) {
+ if (tplParams.hasOwnProperty(tplParam)) {
+ replaceRegExp = new RegExp(['%', tplParam, '%'].join(''), 'g');
+ tplHtml = tplHtml.replace(replaceRegExp, tplParams[tplParam]);
+ }
+ }
+
+ return tplHtml;
+ }
+ };
+
+}()); \ No newline at end of file
diff --git a/project/js/app.ui.templateManager.modifiers.js b/project/js/app.ui.templateManager.modifiers.js
deleted file mode 100644
index 91c0c66..0000000
--- a/project/js/app.ui.templateManager.modifiers.js
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2013 Samsung Electronics Co., Ltd
- *
- * Licensed under the Flora License, Version 1.1 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://floralicense.org/license/
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*global $*/
-/**
- * @class ModifierManager
- */
-function ModifierManager() {
- 'use strict';
- this.init();
-}
-
-(function () {
- 'use strict';
- ModifierManager.prototype = {
-
- /**
- * UI module initialisation
- */
- init: function () {
- },
-
- /**
- * @return modifiers object
- */
- getAll: function () {
- return this.modifiers;
- },
-
- /**
- * modifiers definitions
- */
- modifiers: {
- escape: function escape(str) {
- return $('<span>').text(str).html();
- },
- escapeEncies: function escapeEncies(str) {
- var tagsToReplace = {
- '&': '&amp;',
- '<': '&lt;',
- '>': '&gt;',
- '"': '&quot;'
- };
- return str.replace(/[&<>\"]/g, function (tag) {
- return tagsToReplace[tag] || tag;
- });
- },
- nl2br: function escape(str) {
- return str.replace(/\n/g, '<br/>');
- }
- }
- };
-}());
diff --git a/project/js/main.js b/project/js/main.js
index dfad722..1a2870e 100644
--- a/project/js/main.js
+++ b/project/js/main.js
@@ -15,57 +15,49 @@
*/
/*global $, tizen, App */
-
var app = null;
(function () { // strict mode wrapper
- 'use strict';
-
- ({
- /**
- * Loader init - load the App constructor
- */
- init: function init() {
- var self = this;
- $.getScript('js/app.js')
- .done(function () {
- app = new App();
- self.loadLibs();
- })
- .fail(this.onGetScriptError);
- },
-
- /**
- * Load dependencies
- */
- loadLibs: function loadLibs() {
- var loadedLibs = 0;
- if ($.isArray(app.requires)) {
- $.each(app.requires, function (index, filename) {
- $.getScript(filename)
- .done(function () {
- loadedLibs += 1;
- if (loadedLibs >= app.requires.length) {
- app.init();
- }
- })
- .fail(this.onGetScriptError);
- });
- }
- },
-
- /**
- * Handle ajax errors
- */
- onGetScriptError: function onGetScriptError(
- e,
- jqxhr,
- setting,
- exception
- ) {
- console.error('An error occurred: ' + e.message);
- }
-
- }).init(); // run the loader
-
+ 'use strict';
+
+ ({
+ /**
+ * Loader init - load the App constructor
+ */
+ init: function init() {
+ var self = this;
+ $.getScript('js/app.js')
+ .done(function () {
+ app = new App();
+ self.loadLibs();
+ })
+ .fail(this.onGetScriptError);
+ },
+
+ /**
+ * Load dependencies
+ */
+ loadLibs: function loadLibs() {
+ var loadedLibs = 0;
+ if ($.isArray(app.requires)) {
+ $.each(app.requires, function (index, filename) {
+ $.getScript(filename)
+ .done(function () {
+ loadedLibs += 1;
+ if (loadedLibs >= app.requires.length) {
+ app.init();
+ }
+ })
+ .fail(this.onGetScriptError);
+ });
+ }
+ },
+
+ /**
+ * Handle ajax errors
+ */
+ onGetScriptError: function onGetScriptError(e, jqxhr, setting, exception) {
+ console.error('An error occurred: ' + e.message);
+ }
+ }).init(); // run the loader
}());
diff --git a/project/templates/bye_popup.tpl b/project/templates/bye_popup.tpl
index 9a8a0b7..69bc1bf 100644
--- a/project/templates/bye_popup.tpl
+++ b/project/templates/bye_popup.tpl
@@ -1,6 +1,6 @@
<div id="byePopup" data-role="popup" class="center_basic_2btn">
- <div class="ui-popup-text" id="byeMessage"></div>
- <div class="ui-popup-button-bg">
- <a data-role="button" data-inline="true" id="byeOK">Ok</a>
- </div>
+ <div class="ui-popup-text" id="byeMessage"></div>
+ <div class="ui-popup-button-bg">
+ <a data-role="button" data-inline="true" id="byeOK">Ok</a>
+ </div>
</div>
diff --git a/project/templates/chat_page.tpl b/project/templates/chat_page.tpl
index 4161c90..57ae3aa 100644
--- a/project/templates/chat_page.tpl
+++ b/project/templates/chat_page.tpl
@@ -1,26 +1,20 @@
<div id="chat" data-role="page" data-footer-exist="true">
- <div id="chat-header" data-role="header" data-position="fixed">
- <h1>
- <span id="chat-header-type"></span>
- <span id="chat-header-name"></span>
- </h1>
- </div>
+ <div id="chat-header" data-role="header" data-position="fixed">
+ <h1><span id="chat-header-type"></span><span id="chat-header-name"></span></h1>
+ </div>
- <div id="chat-content" data-role="content">
- <ul data-role="listview"></ul>
- </div>
+ <div id="chat-content" data-role="content">
+ <ul data-role="listview"></ul>
+ </div>
- <div id="chat-footer" data-role="footer" data-position="fixed">
- <div id="ui-textArea">
- <div id="ui-textArea-text">
- <textarea
- id="text"
- placeholder="Your message"
- data-role="none"></textarea>
- </div>
- <div id="ui-textArea-button">
- <a data-role="button" id="ui-mySend">Send</a>
- </div>
- </div>
- </div>
-</div>
+ <div id="chat-footer" data-role="footer" data-position="fixed">
+ <div id="ui-textArea">
+ <div id="ui-textArea-text">
+ <textarea id="text" placeholder="Your message" data-role="none"></textarea>
+ </div>
+ <div id="ui-textArea-button">
+ <a data-role="button" id="ui-mySend">Send</a>
+ </div>
+ </div>
+ </div>
+</div> \ No newline at end of file
diff --git a/project/templates/choose_page.tpl b/project/templates/choose_page.tpl
index e61cc36..102d358 100644
--- a/project/templates/choose_page.tpl
+++ b/project/templates/choose_page.tpl
@@ -1,10 +1,10 @@
<div data-role="page" id="choose">
- <div data-role="header" id="choose-header" data-position="fixed">
- <h1>Choose your server</h1>
- <div data-role="progress" data-style="circle" id="discovering"></div>
- </div>
+ <div data-role="header" id="choose-header" data-position="fixed">
+ <h1>Choose your server</h1>
+ <div data-role="progress" data-style="circle" id="discovering"></div>
+ </div>
- <div data-role="content" id="choose-content">
- <ul data-role="listview"></ul>
- </div>
-</div>
+ <div data-role="content" id="choose-content">
+ <ul data-role="listview"></ul>
+ </div>
+</div> \ No newline at end of file
diff --git a/project/templates/keyboard_page.tpl b/project/templates/keyboard_page.tpl
index c0a7bb3..1722089 100644
--- a/project/templates/keyboard_page.tpl
+++ b/project/templates/keyboard_page.tpl
@@ -1,21 +1,16 @@
<div data-role="page" id="keyboard">
+ <div data-role="header" id="keyboard-header" data-position="fixed">
+ <h1></h1>
+ </div>
- <div data-role="header" id="keyboard-header" data-position="fixed">
- <h1></h1>
- </div>
-
- <div data-role="content" id="keyboard-content">
- <input type="text" id="keyboard-text" maxlength="20"/>
- </div>
-
- <div data-role="footer" data-position="fixed">
- <div data-role="tabbar" data-style="tabbar">
- <ul>
- <li id="keyboard-ok-button" class="ui-disabled">
- <a href="#">OK</a>
- </li>
- </ul>
- </div>
- </div>
-
-</div>
+ <div data-role="content" id="keyboard-content">
+ <input type="text" id="keyboard-text" maxlength="20"/>
+ </div>
+ <div data-role="footer" data-position="fixed">
+ <div data-role="tabbar" data-style="tabbar">
+ <ul>
+ <li id="keyboard-ok-button"><a href="#">OK</a></li>
+ </ul>
+ </div>
+ </div>
+</div> \ No newline at end of file
diff --git a/project/templates/left_bubble.tpl b/project/templates/left_bubble.tpl
index 4bc8d7e..2d20b1b 100644
--- a/project/templates/left_bubble.tpl
+++ b/project/templates/left_bubble.tpl
@@ -1,3 +1,3 @@
<li class="ui-li-bubble-left">
- %text|escape|nl2br%
-</li>
+ %text%
+</li> \ No newline at end of file
diff --git a/project/templates/message_popup.tpl b/project/templates/message_popup.tpl
index 32f8f1b..d69aafd 100644
--- a/project/templates/message_popup.tpl
+++ b/project/templates/message_popup.tpl
@@ -1,6 +1,6 @@
<div id="messagePopup" data-role="popup" class="center_basic_2btn">
- <div class="ui-popup-text"></div>
- <div class="ui-popup-button-bg">
- <a data-role="button" data-inline="true" id="messageOK">OK</a>
- </div>
+ <div class="ui-popup-text"></div>
+ <div class="ui-popup-button-bg">
+ <a data-role="button" data-inline="true" id="messageOK">OK</a>
+ </div>
</div>
diff --git a/project/templates/right_bubble.tpl b/project/templates/right_bubble.tpl
index f785bd2..507e30f 100644
--- a/project/templates/right_bubble.tpl
+++ b/project/templates/right_bubble.tpl
@@ -1,3 +1,3 @@
<li class="ui-li-bubble-right">
- %text|escape|nl2br%
-</li>
+ %text%
+</li> \ No newline at end of file
diff --git a/project/templates/server_row.tpl b/project/templates/server_row.tpl
index 3066721..7780cc4 100644
--- a/project/templates/server_row.tpl
+++ b/project/templates/server_row.tpl
@@ -1,7 +1,7 @@
-<li class="ui-li-has-multiline" address="%deviceAddress%" name="%deviceName|escape%">
- <a href="#">
- <div class="server-row-name">%deviceName|escape%</div>
- <span class="ui-li-text-sub">%deviceAddress%</span>
- <span class="ui-li-text-sub2"></span>
- </a>
-</li>
+<li class="ui-li-has-multiline" address="%deviceAddress%" name="%deviceName%">
+ <a href="#">
+ <div class="server-row-name">%deviceName%</div>
+ <span class="ui-li-text-sub">%deviceAddress%</span>
+ <span class="ui-li-text-sub2"></span>
+ </a>
+</li> \ No newline at end of file