Skip to content

Commit

Permalink
fixed version 2
Browse files Browse the repository at this point in the history
version bump
  • Loading branch information
Andres Olave committed Jun 20, 2016
1 parent a4bf329 commit d5c2fab
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 78 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-chat-scroller",
"version": "0.1.3",
"version": "0.2.0",
"homepage": "https://github.com/sloops77/ngChatScroller",
"authors": [
"Andres Olave <[email protected]"
Expand Down
81 changes: 48 additions & 33 deletions dist/ngChatScroller.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* Copyright 2016 Thinking Bytes Ltd.
*
* ngChatScroller, v0.1.3
* ngChatScroller, v0.2.0
* Smooth Chat based scrolling for Angular.
* http://angularjs.org/
*
Expand All @@ -22,6 +22,18 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
* First created for Sportwize
* Smooth chat scroll for both scroll to bottom & maintaining scroll
*/
ngcsUtils = {
size: function size(arr) {
if (!arr) return 0;

return arr.length;
},
last: function last(arr) {
if (!arr) return undefined;

return arr[arr.length - 1];
}
};

var ChatScroller = function () {
function ChatScroller($elem, $log) {
Expand Down Expand Up @@ -110,49 +122,52 @@ var ChatScroller = function () {
return ChatScroller;
}();

utils = {
size: function size(arr) {
if (!arr) return 0;
var NgChatScrollerController = function () {
function NgChatScrollerController($scope, $element, $attrs, $log) {
_classCallCheck(this, NgChatScrollerController);

return arr.length;
},
last: function last(arr) {
if (!arr) return undefined;
this.$log = $log;
this.chatScroller = new ChatScroller($element[0], $log);
this.messages = null;
$scope.ngcsNumRendered = $scope.ngcsLimit = 0;

return arr[arr.length - 1];
this.watches($scope, $attrs.chatScrollView);
}
};

angular.module('ngChatScroller', []).directive('chatScrollView', ['$log', function ($log) {
return {
restrict: 'A',
controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
undefined.init = function () {
undefined.chatScroller = new ChatScroller($element[0], $log);
undefined.messages = null;
$scope.ngcsNumRendered = $scope.ngcsLimit = 0;
};
_createClass(NgChatScrollerController, [{
key: 'watches',
value: function watches($scope, scrollViewAttr) {
var _this2 = this;

$scope.$watchCollection($attrs.chatScrollView, function (newVal) {
// $log.info(`@ChatMessages.updateMessages(${utils.size(newVal)}), current=${$scope.ngcsLimit}, numRendered=${$scope.ngcsNumRendered})}`)
$scope.$watchCollection(scrollViewAttr, function (newVal) {
// this.$log.info(`@ChatMessages.updateMessages(${ngcsUtils.size(newVal)}), current=${$scope.ngcsLimit}, numRendered=${$scope.ngcsNumRendered})}`)

if (newVal === null || utils.size(newVal) === $scope.ngcsLimit) return;
if (newVal === null || ngcsUtils.size(newVal) === $scope.ngcsLimit) return;

if (utils.last(undefined.messages) === utils.last(newVal)) {
// $log.info('MaintainScroll');
undefined.chatScroller.startScroll('MaintainScroll', false);
if (ngcsUtils.last(_this2.messages) === ngcsUtils.last(newVal)) {
// this.$log.info('MaintainScroll');
_this2.chatScroller.startScroll('MaintainScroll', false);
} else {
// $log.info(`ScrollBottom(${$scope.ngcsNumRendered > 0})`);
undefined.chatScroller.startScroll('ScrollBottom', $scope.ngcsNumRendered > 0);
// this.$log.info(`ScrollBottom(${$scope.ngcsNumRendered > 0})`);
_this2.chatScroller.startScroll('ScrollBottom', $scope.ngcsNumRendered > 0);
}

undefined.messages = newVal;
$scope.ngcsLimit = utils.size(newVal);
_this2.messages = newVal;
$scope.ngcsLimit = ngcsUtils.size(newVal);
});
}
}]);

return NgChatScrollerController;
}();

undefined.init();
}],
link: function link($scope, $element, $attrs) {
NgChatScrollerController.$inject = ['$scope', '$element', '$attrs', '$log'];

angular.module('ngChatScroller', []).directive('chatScrollView', ['$log', function ($log) {
return {
restrict: 'A',
controller: NgChatScrollerController,
link: function link($scope, $element, $attrs, $ctrl) {
var chatMessageSelector = $attrs.ngcsMessageSelector ? $attrs.ngcsMessageSelector : '.chat-message';
return $scope.$watch(function () {
return $element[0].querySelectorAll(chatMessageSelector).length;
Expand All @@ -162,7 +177,7 @@ angular.module('ngChatScroller', []).directive('chatScrollView', ['$log', functi
$scope.$evalAsync(function () {
if ($scope.ngcsLimit === newVal) {
$scope.ngcsNumRendered = newVal;
undefined.chatScroller.stopCurrentScroll();
$ctrl.chatScroller.stopCurrentScroll();
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions dist/ngChatScroller.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.3",
"version": "0.2.0",
"date": "2016-06-20",
"time": "11:34:55"
"time": "12:01:24"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ng-chat-scroller",
"private": false,
"version": "0.1.3",
"version": "0.2.0",
"repository": {
"url": "git://github.com/sloops77/ngChatScroller.git"
},
Expand Down
86 changes: 47 additions & 39 deletions src/ngChatScroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@
* First created for Sportwize
* Smooth chat scroll for both scroll to bottom & maintaining scroll
*/
ngcsUtils = {
size(arr) {
if (!arr)
return 0;

return arr.length;
},
last(arr) {
if (!arr)
return undefined;

return arr[arr.length - 1];
}
};

class ChatScroller {
constructor($elem, $log) {
this.scrollView = $elem;
Expand Down Expand Up @@ -73,52 +88,45 @@ class ChatScroller {
}
}

utils = {
size(arr) {
if (!arr)
return 0;
class NgChatScrollerController {
constructor($scope, $element, $attrs, $log) {
this.$log = $log;
this.chatScroller = new ChatScroller($element[0], $log);
this.messages = null;
$scope.ngcsNumRendered = $scope.ngcsLimit = 0;

return arr.length;
},
last(arr) {
if (!arr)
return undefined;
this.watches($scope, $attrs.chatScrollView)
}

return arr[arr.length - 1];
watches($scope, scrollViewAttr) {
$scope.$watchCollection(scrollViewAttr, (newVal) => {
// this.$log.info(`@ChatMessages.updateMessages(${ngcsUtils.size(newVal)}), current=${$scope.ngcsLimit}, numRendered=${$scope.ngcsNumRendered})}`)

if (newVal === null || ngcsUtils.size(newVal) === $scope.ngcsLimit)
return;

if (ngcsUtils.last(this.messages) === ngcsUtils.last(newVal)) {
// this.$log.info('MaintainScroll');
this.chatScroller.startScroll('MaintainScroll', false);
} else {
// this.$log.info(`ScrollBottom(${$scope.ngcsNumRendered > 0})`);
this.chatScroller.startScroll('ScrollBottom', $scope.ngcsNumRendered > 0);
}

this.messages = newVal;
$scope.ngcsLimit = ngcsUtils.size(newVal);
});
}
}


NgChatScrollerController.$inject = ['$scope', '$element', '$attrs', '$log'];

angular.module('ngChatScroller', []).directive('chatScrollView', ['$log', ($log) => {
return {
restrict: 'A',
controller: ['$scope', '$element', '$attrs', ($scope, $element, $attrs) => {
this.init = () => {
this.chatScroller = new ChatScroller($element[0], $log);
this.messages = null;
$scope.ngcsNumRendered = $scope.ngcsLimit = 0;
};

$scope.$watchCollection($attrs.chatScrollView, (newVal) => {
// $log.info(`@ChatMessages.updateMessages(${utils.size(newVal)}), current=${$scope.ngcsLimit}, numRendered=${$scope.ngcsNumRendered})}`)

if (newVal === null || utils.size(newVal) === $scope.ngcsLimit)
return;

if (utils.last(this.messages) === utils.last(newVal)) {
// $log.info('MaintainScroll');
this.chatScroller.startScroll('MaintainScroll', false);
} else {
// $log.info(`ScrollBottom(${$scope.ngcsNumRendered > 0})`);
this.chatScroller.startScroll('ScrollBottom', $scope.ngcsNumRendered > 0);
}

this.messages = newVal;
$scope.ngcsLimit = utils.size(newVal);
});

this.init();
}],
link: ($scope, $element, $attrs) => {
controller: NgChatScrollerController,
link: ($scope, $element, $attrs, $ctrl) => {
const chatMessageSelector = $attrs.ngcsMessageSelector ? $attrs.ngcsMessageSelector : '.chat-message';
return $scope.$watch(
() => $element[0].querySelectorAll(chatMessageSelector).length,
Expand All @@ -128,7 +136,7 @@ angular.module('ngChatScroller', []).directive('chatScrollView', ['$log', ($log)
$scope.$evalAsync(() => {
if ($scope.ngcsLimit === newVal) {
$scope.ngcsNumRendered = newVal;
this.chatScroller.stopCurrentScroll();
$ctrl.chatScroller.stopCurrentScroll();
}
});
}
Expand Down

0 comments on commit d5c2fab

Please sign in to comment.