From e7b731e808fab8c60aadb691bc1a8a5c6e7cbee7 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 30 Apr 2014 11:09:40 +0800 Subject: [PATCH] Performance improvements for scrollables Fix #257 --- app/js/controllers.js | 8 +++++++ app/js/directives.js | 32 ++++++++++++++++++++++++++ app/partials/contacts_modal.html | 4 ++-- app/partials/country_select_modal.html | 4 ++-- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/app/js/controllers.js b/app/js/controllers.js index 502ef1f3..ba9eecc4 100644 --- a/app/js/controllers.js +++ b/app/js/controllers.js @@ -1554,8 +1554,11 @@ angular.module('myApp.controllers', []) }) .controller('ContactsModalController', function ($scope, $modal, $modalInstance, AppUsersManager) { + $scope.contacts = []; $scope.search = {}; + $scope.slice = {limit: 20, limitDelta: 20} + $scope.selectedContacts = {}; $scope.disabledContacts = {}; @@ -1579,6 +1582,8 @@ angular.module('myApp.controllers', []) function updateContacts (query) { AppUsersManager.getContacts(query).then(function (contactsList) { $scope.contacts = []; + $scope.slice.limit = 20; + angular.forEach(contactsList, function(userID) { var contact = { userID: userID, @@ -1753,6 +1758,7 @@ angular.module('myApp.controllers', []) .controller('CountrySelectModalController', function ($scope, $modalInstance, $rootScope, SearchIndexManager) { $scope.search = {}; + $scope.slice = {limit: 20, limitDelta: 20} var searchIndex = SearchIndexManager.createIndex(); @@ -1770,6 +1776,8 @@ angular.module('myApp.controllers', []) } $scope.countries = []; + $scope.slice.limit = 20; + var j; for (var i = 0; i < Config.CountryCodes.length; i++) { if (!filtered || results[i]) { diff --git a/app/js/directives.js b/app/js/directives.js index 5df0c971..d1fd8b98 100644 --- a/app/js/directives.js +++ b/app/js/directives.js @@ -1120,6 +1120,38 @@ angular.module('myApp.directives', ['myApp.filters']) }; }) + .directive('myInfiniteScroller', function () { + + return { + link: link, + scope: true + }; + + function link($scope, element, attrs) { + + var scrollableWrap = $('.content', element)[0], + moreNotified = false; + + $(scrollableWrap).on('scroll', function (e) { + if (!moreNotified && + scrollableWrap.scrollTop >= scrollableWrap.scrollHeight - scrollableWrap.clientHeight - 300) { + moreNotified = true; + $scope.$apply(function () { + $scope.slice.limit += ($scope.slice.limitDelta || 20); + }); + + onContentLoaded(function () { + moreNotified = false; + $(element).nanoScroller(); + }); + } + }); + + }; + }) + + + .directive('myModalPosition', function ($window, $timeout) { diff --git a/app/partials/contacts_modal.html b/app/partials/contacts_modal.html index 8084fd59..dea71cc5 100644 --- a/app/partials/contacts_modal.html +++ b/app/partials/contacts_modal.html @@ -10,12 +10,12 @@
-