-
Notifications
You must be signed in to change notification settings - Fork 40
/
app.js
112 lines (92 loc) · 2.76 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// Ionic Starter App
// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
// Set the statusbar to use the default style, tweak this to
// remove the status bar on iOS or change it to use white instead of dark colors.
StatusBar.styleLightContent();
}
});
})
// All this does is allow the message
// to be sent when you tap return
.directive('input', function($timeout) {
return {
restrict: 'E',
scope: {
'returnClose': '=',
'onReturn': '&',
'onFocus': '&',
'onBlur': '&'
},
link: function(scope, element, attr) {
element.bind('focus', function(e) {
if (scope.onFocus) {
$timeout(function() {
scope.onFocus();
});
}
});
element.bind('blur', function(e) {
if (scope.onBlur) {
$timeout(function() {
scope.onBlur();
});
}
});
element.bind('keydown', function(e) {
if (e.which == 13) {
if (scope.returnClose) element[0].blur();
if (scope.onReturn) {
$timeout(function() {
scope.onReturn();
});
}
}
});
}
}
})
.controller('Messages', function($scope, $timeout, $ionicScrollDelegate) {
$scope.showTime = true;
var alternate,
isIOS = ionic.Platform.isWebView() && ionic.Platform.isIOS();
$scope.sendMessage = function() {
alternate = !alternate;
var d = new Date();
d = d.toLocaleTimeString().replace(/:\d+ /, ' ');
$scope.messages.push({
userId: alternate ? '12345' : '54321',
text: $scope.data.message,
time: d
});
delete $scope.data.message;
$ionicScrollDelegate.scrollBottom(true);
};
$scope.inputUp = function() {
if (isIOS) $scope.data.keyboardHeight = 216;
$timeout(function() {
$ionicScrollDelegate.scrollBottom(true);
}, 300);
};
$scope.inputDown = function() {
if (isIOS) $scope.data.keyboardHeight = 0;
$ionicScrollDelegate.resize();
};
$scope.closeKeyboard = function() {
// cordova.plugins.Keyboard.close();
};
$scope.data = {};
$scope.myId = '12345';
$scope.messages = [];
});