Browse Source

Improved mobile experience

master
Igor Zhukov 10 years ago
parent
commit
2aed661086
  1. 10
      app/css/mobile.css
  2. 4
      app/js/directives.js
  3. 61
      app/js/message_composer.js

10
app/css/mobile.css

@ -1165,13 +1165,17 @@ a.mobile_modal_action .tg_checkbox_label {
.composer_emoji_tooltip { .composer_emoji_tooltip {
margin-left: 10px; margin-left: 6px;
margin-top: -175px; margin-top: -170px;
width: 262px; width: 262px;
z-index: 10000;
} }
.composer_emoji_tooltip .composer_emoji_tooltip_content { .composer_emoji_tooltip .composer_emoji_tooltip_content_wrap {
height: 106px; height: 106px;
} }
.composer_emoji_tooltip_tabs {
margin-bottom: 3px;
}
.composer_emoji_tooltip .composer_emoji_tooltip_content .composer_emoji_btn { .composer_emoji_tooltip .composer_emoji_tooltip_content .composer_emoji_btn {
padding: 5px; padding: 5px;
} }

4
app/js/directives.js

@ -1204,7 +1204,9 @@ angular.module('myApp.directives', ['myApp.filters'])
composer.setValue($scope.draftMessage.text || ''); composer.setValue($scope.draftMessage.text || '');
updateHeight(); updateHeight();
} }
if (!Config.Navigator.touch) {
composer.focus(); composer.focus();
}
}); });
var sendAwaiting = false; var sendAwaiting = false;
@ -1214,7 +1216,9 @@ angular.module('myApp.directives', ['myApp.filters'])
}); });
$scope.$on('ui_message_send', function () { $scope.$on('ui_message_send', function () {
sendAwaiting = false; sendAwaiting = false;
if (!Config.Navigator.touch) {
focusField(); focusField();
}
}); });
function focusField () { function focusField () {

61
app/js/message_composer.js

@ -139,6 +139,7 @@ function EmojiTooltip (btnEl, options) {
this.onStickerSelected = options.onStickerSelected; this.onStickerSelected = options.onStickerSelected;
this.getStickers = options.getStickers; this.getStickers = options.getStickers;
if (!Config.Navigator.touch) {
$(this.btnEl).on('mouseenter mouseleave', function (e) { $(this.btnEl).on('mouseenter mouseleave', function (e) {
self.isOverBtn = e.type == 'mouseenter'; self.isOverBtn = e.type == 'mouseenter';
self.createTooltip(); self.createTooltip();
@ -149,16 +150,19 @@ function EmojiTooltip (btnEl, options) {
self.onMouseLeave(true); self.onMouseLeave(true);
} }
}); });
}
$(this.btnEl).on('mousedown', function (e) { $(this.btnEl).on('mousedown', function (e) {
if (!self.shown) { if (!self.shown) {
clearTimeout(self.showTimeout); clearTimeout(self.showTimeout);
delete self.showTimeout; delete self.showTimeout;
self.createTooltip();
self.show(); self.show();
} else { } else {
clearTimeout(self.hideTimeout); clearTimeout(self.hideTimeout);
delete self.hideTimeout; delete self.hideTimeout;
self.hide(); self.hide();
} }
return cancelEvent(e);
}); });
} }
@ -202,20 +206,23 @@ EmojiTooltip.prototype.createTooltip = function () {
this.settingsEl = $('.composer_emoji_tooltip_settings', this.tooltip); this.settingsEl = $('.composer_emoji_tooltip_settings', this.tooltip);
angular.forEach(['recent', 'smile', 'flower', 'bell', 'car', 'grid', 'stickers'], function (tabName, tabIndex) { angular.forEach(['recent', 'smile', 'flower', 'bell', 'car', 'grid', 'stickers'], function (tabName, tabIndex) {
$('<a class="composer_emoji_tooltip_tab composer_emoji_tooltip_tab_' + tabName + '"></a>') var tab = $('<a class="composer_emoji_tooltip_tab composer_emoji_tooltip_tab_' + tabName + '"></a>')
.on('mousedown', function (e) { .on('mousedown', function (e) {
self.selectTab(tabIndex); self.selectTab(tabIndex);
return cancelEvent(e); return cancelEvent(e);
}) })
.on('mouseenter mouseleave', function (e) { .appendTo(self.tabsEl);
if (!Config.Navigator.touch) {
tab.on('mouseenter mouseleave', function (e) {
clearTimeout(self.selectTabTimeout); clearTimeout(self.selectTabTimeout);
if (e.type == 'mouseenter') { if (e.type == 'mouseenter') {
self.selectTabTimeout = setTimeout(function () { self.selectTabTimeout = setTimeout(function () {
self.selectTab(tabIndex); self.selectTab(tabIndex);
}, 300); }, 300);
} }
}) });
.appendTo(self.tabsEl); }
}); });
if (!Config.Mobile) { if (!Config.Mobile) {
@ -238,10 +245,14 @@ EmojiTooltip.prototype.createTooltip = function () {
if (self.onStickerSelected) { if (self.onStickerSelected) {
self.onStickerSelected(sticker); self.onStickerSelected(sticker);
} }
if (Config.Mobile) {
self.hide();
}
} }
return cancelEvent(e); return cancelEvent(e);
}); });
if (!Config.Navigator.touch) {
this.tooltipEl.on('mouseenter mouseleave', function (e) { this.tooltipEl.on('mouseenter mouseleave', function (e) {
if (e.type == 'mouseenter') { if (e.type == 'mouseenter') {
self.onMouseEnter(); self.onMouseEnter();
@ -249,9 +260,12 @@ EmojiTooltip.prototype.createTooltip = function () {
self.onMouseLeave(); self.onMouseLeave();
} }
}); });
}
this.selectTab(0); this.selectTab(0);
$(window).on('resize', this.updatePosition.bind(this));
return true; return true;
} }
@ -473,19 +487,7 @@ MessageComposer.prototype.onKeyEvent = function (e) {
if (e.type == 'keyup') { if (e.type == 'keyup') {
this.checkAutocomplete(); this.checkAutocomplete();
if (this.onTyping) { var length = false;
var now = tsNow();
if (now - this.lastTyping > 5000) {
var length = (this.richTextareaEl ? this.richTextareaEl[0].textContent : this.textareaEl[0].value).length;
if (length != this.lastLength) {
this.lastTyping = now;
this.lastLength = length;
this.onTyping();
}
}
}
if (this.richTextareaEl) { if (this.richTextareaEl) {
clearTimeout(this.updateValueTO); clearTimeout(this.updateValueTO);
var now = tsNow(); var now = tsNow();
@ -496,10 +498,30 @@ MessageComposer.prototype.onKeyEvent = function (e) {
this.onChange(); this.onChange();
} }
else { else {
length = this.richTextareaEl[0].textContent.length;
if (this.wasEmpty != !length) {
this.wasEmpty = !this.wasEmpty;
this.onChange();
} else {
this.updateValueTO = setTimeout(this.onChange.bind(this), 1000); this.updateValueTO = setTimeout(this.onChange.bind(this), 1000);
} }
} }
}
if (this.onTyping) {
var now = tsNow();
if (now - this.lastTyping > 5000) {
if (length === false) {
length = (this.richTextareaEl ? this.richTextareaEl[0].textContent : this.textareaEl[0].value).length;
}
if (length != this.lastLength) {
this.lastTyping = now;
this.lastLength = length;
this.onTyping();
}
}
}
} }
if (e.type == 'keydown') { if (e.type == 'keydown') {
var checkSubmit = !this.autocompleteShown; var checkSubmit = !this.autocompleteShown;
@ -597,6 +619,9 @@ MessageComposer.prototype.restoreSelection = function () {
MessageComposer.prototype.checkAutocomplete = function () { MessageComposer.prototype.checkAutocomplete = function () {
if (Config.Mobile) {
return false;
}
var pos, value; var pos, value;
if (this.richTextareaEl) { if (this.richTextareaEl) {
var textarea = this.richTextareaEl[0]; var textarea = this.richTextareaEl[0];
@ -815,6 +840,8 @@ MessageComposer.prototype.setValue = function (text) {
if (this.richTextareaEl) { if (this.richTextareaEl) {
this.richTextareaEl.html(this.getRichHtml(text)); this.richTextareaEl.html(this.getRichHtml(text));
this.lastLength = text.length; this.lastLength = text.length;
this.wasEmpty = !text.length;
this.onKeyEvent({type: 'keyup'});
} else { } else {
this.textareaEl.val(text); this.textareaEl.val(text);
} }

Loading…
Cancel
Save