Browse Source

Improved send form cleanup

TitanNano-voice_recorder
Igor Zhukov 11 years ago
parent
commit
42085e99c6
  1. 54
      app/js/directives.js

54
app/js/directives.js

@ -627,6 +627,7 @@ angular.module('myApp.directives', ['myApp.filters'])
dragStarted, dragTimeout, dragStarted, dragTimeout,
emojiArea = $(messageField).emojiarea({button: emojiButton, norealTime: true}), emojiArea = $(messageField).emojiarea({button: emojiButton, norealTime: true}),
emojiMenu = $('.emoji-menu', element)[0], emojiMenu = $('.emoji-menu', element)[0],
submitBtn = $('.im_submit', element)[0],
richTextarea = $('.emoji-wysiwyg-editor', element)[0]; richTextarea = $('.emoji-wysiwyg-editor', element)[0];
if (richTextarea) { if (richTextarea) {
@ -635,14 +636,16 @@ angular.module('myApp.directives', ['myApp.filters'])
$(richTextarea).attr('placeholder', $(messageField).attr('placeholder')); $(richTextarea).attr('placeholder', $(messageField).attr('placeholder'));
var updatePromise; var updatePromise;
$(richTextarea).on('keyup', function (e) { $(richTextarea)
updateHeight(); .on('DOMNodeInserted', onPastedImageEvent)
.on('keyup', function (e) {
updateHeight();
$scope.draftMessage.text = richTextarea.innerText; $scope.draftMessage.text = richTextarea.innerText;
$timeout.cancel(updatePromise); $timeout.cancel(updatePromise);
updatePromise = $timeout(updateValue, 1000); updatePromise = $timeout(updateValue, 1000);
}); });
} }
// Head is sometimes slower // Head is sometimes slower
@ -696,7 +699,7 @@ angular.module('myApp.directives', ['myApp.filters'])
}); });
$('.im_submit', element).on('mousedown', function (e) { $(submitBtn).on('mousedown', function (e) {
$(element).trigger('submit'); $(element).trigger('submit');
$(element).trigger('message_send'); $(element).trigger('message_send');
resetAfterSubmit(); resetAfterSubmit();
@ -757,9 +760,6 @@ angular.module('myApp.directives', ['myApp.filters'])
$('body').on('dragenter dragleave dragover drop', onDragDropEvent); $('body').on('dragenter dragleave dragover drop', onDragDropEvent);
$(document).on('paste', onPasteEvent); $(document).on('paste', onPasteEvent);
if (richTextarea) {
$(richTextarea).on('DOMNodeInserted', onPastedImageEvent);
}
if (!Config.Navigator.touch) { if (!Config.Navigator.touch) {
$scope.$on('ui_peer_change', focusField); $scope.$on('ui_peer_change', focusField);
@ -772,21 +772,6 @@ angular.module('myApp.directives', ['myApp.filters'])
$scope.$on('ui_peer_draft', updateField); $scope.$on('ui_peer_draft', updateField);
$scope.$on('ui_message_before_send', updateValue); $scope.$on('ui_message_before_send', updateValue);
$scope.$on('$destroy', function cleanup() {
$('body').off('dragenter dragleave dragover drop', onDragDropEvent);
$(document).off('paste', onPasteEvent);
$(document).off('keydown', onKeyDown);
fileSelects.off('change');
if (richTextarea) {
$(richTextarea).off('DOMNodeInserted', onPastedImageEvent);
}
});
if (!Config.Navigator.touch) {
focusField();
}
function focusField () { function focusField () {
onContentLoaded(function () { onContentLoaded(function () {
editorElement.focus(); editorElement.focus();
@ -873,8 +858,25 @@ angular.module('myApp.directives', ['myApp.filters'])
return cancelEvent(e); return cancelEvent(e);
}; };
}
$scope.$on('$destroy', function cleanup() {
$('body').off('dragenter dragleave dragover drop', onDragDropEvent);
$(document).off('paste', onPasteEvent);
$(document).off('keydown', onKeyDown);
$(submitBtn).off('mousedown')
fileSelects.off('change');
if (richTextarea) {
$(richTextarea).off('DOMNodeInserted keyup', onPastedImageEvent);
}
$(editorElement).off('keydown');
});
if (!Config.Navigator.touch) {
focusField();
}
}
}) })
.directive('myLoadThumb', function(MtpApiFileManager) { .directive('myLoadThumb', function(MtpApiFileManager) {

Loading…
Cancel
Save