|
|
|
@ -29,6 +29,135 @@ angular.module('myApp.directives', ['myApp.filters'])
@@ -29,6 +29,135 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|
|
|
|
}; |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
.directive('myDialogs', function ($modalStack) { |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
link: link |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function link ($scope, element, attrs) { |
|
|
|
|
var dialogsWrap = $('.im_dialogs_wrap', element)[0], |
|
|
|
|
scrollableWrap = $('.im_dialogs_scrollable_wrap', element)[0], |
|
|
|
|
searchField = $('.im_dialogs_search_field', element)[0], |
|
|
|
|
searchFocused = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$(searchField).on('focus blur', function (e) { |
|
|
|
|
searchFocused = e.type == 'focus'; |
|
|
|
|
|
|
|
|
|
if (!searchFocused) { |
|
|
|
|
$(scrollableWrap).find('.im_dialog_selected').removeClass('.im_dialog_selected'); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
function onKeyDown(e) { |
|
|
|
|
if (!searchFocused && $modalStack.getTop()) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.keyCode >= 48 && e.keyCode <= 57 && !e.shiftKey && e.altKey) { // Alt + [0-9 keys]
|
|
|
|
|
var currentSelected = $(scrollableWrap).find('.im_dialog_wrap a')[(e.keyCode - 48 || 10) - 1]; |
|
|
|
|
if (currentSelected) { |
|
|
|
|
currentSelected.click(); |
|
|
|
|
} |
|
|
|
|
return cancelEvent(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.keyCode == 27 || e.keyCode == 9 && e.shiftKey) { // ESC or Shift + Tab
|
|
|
|
|
if (!searchFocused) { |
|
|
|
|
searchField.focus(); |
|
|
|
|
if (searchField.value) { |
|
|
|
|
searchField.select(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return cancelEvent(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (searchFocused && e.keyCode == 13) { // Enter
|
|
|
|
|
var currentSelected = $(scrollableWrap).find('.im_dialog_selected')[0] || $(scrollableWrap).find('.im_dialog_wrap a')[0]; |
|
|
|
|
if (currentSelected) { |
|
|
|
|
currentSelected.click(); |
|
|
|
|
} |
|
|
|
|
return cancelEvent(e); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.keyCode == 38 || e.keyCode == 40) { // UP, DOWN
|
|
|
|
|
var skip = !e.shiftKey && e.altKey; |
|
|
|
|
if (!skip && (!searchFocused || e.metaKey)) { |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var next = e.keyCode == 40, |
|
|
|
|
currentSelected = !skip && $(scrollableWrap).find('.im_dialog_selected')[0] || $(scrollableWrap).find('.active a.im_dialog')[0], |
|
|
|
|
currentSelectedWrap = currentSelected && currentSelected.parentNode, |
|
|
|
|
nextDialogWrap; |
|
|
|
|
|
|
|
|
|
if (currentSelectedWrap) { |
|
|
|
|
var nextDialogWrap = currentSelected[next ? 'nextSibling' : 'previousSibling']; |
|
|
|
|
|
|
|
|
|
if (!nextDialogWrap || !nextDialogWrap.className || nextDialogWrap.className.indexOf('im_dialog_wrap') == -1) { |
|
|
|
|
var dialogWraps = $(scrollableWrap).find('.im_dialog_wrap'), |
|
|
|
|
pos = dialogWraps.index(currentSelected.parentNode), |
|
|
|
|
nextPos = pos + (next ? 1 : -1); |
|
|
|
|
|
|
|
|
|
nextDialogWrap = dialogWraps[nextPos]; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
var dialogWraps = $(scrollableWrap).find('.im_dialog_wrap'); |
|
|
|
|
if (next) { |
|
|
|
|
nextDialogWrap = dialogWraps[0]; |
|
|
|
|
} else { |
|
|
|
|
nextDialogWrap = dialogWraps[dialogWraps.length - 1]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (skip) { |
|
|
|
|
if (nextDialogWrap) { |
|
|
|
|
$(nextDialogWrap).find('a')[0].click(); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
if (currentSelectedWrap && nextDialogWrap) { |
|
|
|
|
$(currentSelectedWrap).find('a').removeClass('im_dialog_selected'); |
|
|
|
|
} |
|
|
|
|
if (nextDialogWrap) { |
|
|
|
|
$(nextDialogWrap).find('a').addClass('im_dialog_selected'); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (nextDialogWrap) { |
|
|
|
|
var elTop = nextDialogWrap.offsetTop, |
|
|
|
|
elHeight = nextDialogWrap.offsetHeight, |
|
|
|
|
scrollTop = scrollableWrap.scrollTop, |
|
|
|
|
viewportHeight = scrollableWrap.clientHeight; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (scrollTop > elTop) { |
|
|
|
|
scrollableWrap.scrollTop = elTop; |
|
|
|
|
$(dialogsWrap).nanoScroller({flash: true}); |
|
|
|
|
} |
|
|
|
|
else if (scrollTop < elTop + elHeight - viewportHeight) { |
|
|
|
|
scrollableWrap.scrollTop = elTop + elHeight - viewportHeight; |
|
|
|
|
$(dialogsWrap).nanoScroller({flash: true}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return cancelEvent(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$(document).on('keydown', onKeyDown); |
|
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function () { |
|
|
|
|
$(document).off('keydown', onKeyDown); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
.directive('myDialogsList', function($window, $timeout) { |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
@ -417,7 +546,7 @@ angular.module('myApp.directives', ['myApp.filters'])
@@ -417,7 +546,7 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
.directive('mySendForm', function ($timeout, AppConfigManager, ErrorService) { |
|
|
|
|
.directive('mySendForm', function ($timeout, $modalStack, AppConfigManager, ErrorService) { |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
link: link, |
|
|
|
@ -534,6 +663,14 @@ angular.module('myApp.directives', ['myApp.filters'])
@@ -534,6 +663,14 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
function onKeyDown(e) { |
|
|
|
|
if (e.keyCode == 9 && !e.shiftKey && !$modalStack.getTop()) { // TAB
|
|
|
|
|
editorElement.focus(); |
|
|
|
|
return cancelEvent(e); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
$(document).on('keydown', onKeyDown); |
|
|
|
|
|
|
|
|
|
$('body').on('dragenter dragleave dragover drop', onDragDropEvent); |
|
|
|
|
$(document).on('paste', onPasteEvent); |
|
|
|
|
if (richTextarea) { |
|
|
|
@ -555,6 +692,7 @@ angular.module('myApp.directives', ['myApp.filters'])
@@ -555,6 +692,7 @@ angular.module('myApp.directives', ['myApp.filters'])
|
|
|
|
|
$scope.$on('$destroy', function cleanup() { |
|
|
|
|
$('body').off('dragenter dragleave dragover drop', onDragDropEvent); |
|
|
|
|
$(document).off('paste', onPasteEvent); |
|
|
|
|
$(document).off('keydown', onKeyDown); |
|
|
|
|
if (richTextarea) { |
|
|
|
|
$(richTextarea).off('DOMNodeInserted', onPastedImageEvent); |
|
|
|
|
} |
|
|
|
|