From 2e9e736bdd06e4498fa704b7ab966b9dc7d028ba Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Mon, 28 Apr 2014 12:39:16 +0800 Subject: [PATCH] Select range of messages Fix #224 --- app/js/controllers.js | 38 +++++++++++++++++++++++++++++++++++++- app/js/directives.js | 12 ++++++++++++ app/js/util.js | 5 +++-- app/partials/message.html | 2 +- 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index ab23c252..9480c1a0 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -455,6 +455,7 @@ angular.module('myApp.controllers', []) offset = 0, hasMore = false, maxID = 0, + lastSelectID = false, inputMediaFilters = { photos: 'inputMessagesFilterPhotos', video: 'inputMessagesFilterVideo', @@ -624,11 +625,20 @@ angular.module('myApp.controllers', []) $scope.$broadcast('ui_history_change'); } - function toggleMessage (messageID, target) { + function toggleMessage (messageID, $event) { + var target = $event.target, + shiftClick = $event.shiftKey; + + if (shiftClick) { + $scope.$broadcast('ui_selection_clear'); + } + if (!$scope.selectActions && !$(target).hasClass('icon-select-tick') && !$(target).hasClass('im_content_message_select_area')) { return false; } + if ($scope.selectedMsgs[messageID]) { + lastSelectID = false; delete $scope.selectedMsgs[messageID]; $scope.selectedCount--; if (!$scope.selectedCount) { @@ -636,6 +646,31 @@ angular.module('myApp.controllers', []) $scope.$broadcast('ui_panel_update'); } } else { + + if (!shiftClick) { + lastSelectID = messageID; + } else if (lastSelectID != messageID) { + var dir = lastSelectID > messageID, + i, startPos, curMessageID; + + for (i = 0; i < $scope.history.length; i++) { + if ($scope.history[i].id == lastSelectID) { + startPos = i; + break; + } + } + + i = startPos; + while ($scope.history[i] && + (curMessageID = $scope.history[i].id) != messageID) { + if (!$scope.selectedMsgs[curMessageID]) { + $scope.selectedMsgs[curMessageID] = true; + $scope.selectedCount++; + } + i += dir ? -1 : +1; + } + } + $scope.selectedMsgs[messageID] = true; $scope.selectedCount++; if (!$scope.selectActions) { @@ -649,6 +684,7 @@ angular.module('myApp.controllers', []) $scope.selectedMsgs = {}; $scope.selectedCount = 0; $scope.selectActions = false; + lastSelectID = false; if (!noBroadcast) { $scope.$broadcast('ui_panel_update'); } diff --git a/app/js/directives.js b/app/js/directives.js index d3143c20..7cafbea3 100644 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -328,6 +328,18 @@ angular.module('myApp.directives', ['myApp.filters']) }); }); + $scope.$on('ui_selection_clear', function () { + if (window.getSelection) { + if (window.getSelection().empty) { // Chrome + window.getSelection().empty(); + } else if (window.getSelection().removeAllRanges) { // Firefox + window.getSelection().removeAllRanges(); + } + } else if (document.selection) { // IE? + document.selection.empty(); + } + }); + $scope.$on('ui_editor_resize', updateSizes); $scope.$on('ui_height', function () { onContentLoaded(updateSizes); diff --git a/app/js/util.js b/app/js/util.js index 91d07162..6f533f46 100644 --- a/app/js/util.js +++ b/app/js/util.js @@ -39,9 +39,10 @@ function checkDragEvent(e) { function cancelEvent (event) { event = event || window.event; + if (event) event = event.originalEvent || event; - event.stopPropagation && event.stopPropagation(); - event.preventDefault && event.preventDefault(); + if (event.stopPropagation) event.stopPropagation(); + if (event.preventDefault) event.preventDefault(); return false; } diff --git a/app/partials/message.html b/app/partials/message.html index f5c2a855..2f6aa9de 100644 --- a/app/partials/message.html +++ b/app/partials/message.html @@ -4,7 +4,7 @@ -
+