<commit_before>var webircApp = angular.module('webircApp', []);

webircApp.directive('loginbox', function($rootScope) {
	return {
		scope: true,
		link: function(scope) {
			scope.login = function() {
				$rootScope.sendToGateway('Login', {
					username: scope.username,
					password: scope.password
				});

				if (window.webkitNotifications && window.webkitNotifications.checkPermission() !== 0) {
					window.webkitNotifications.requestPermission();
				}
			};

			scope.passwordKeyDown = function(event) {
				if (event.keyCode === 13) {
					scope.login();
				}
			}
		}
	};
});

webircApp.directive('focusKey', function($timeout) {
	return {
		link: function(scope, element, attrs) {
			scope.$on('FocusKey', function(e, focusKey) {
				if (focusKey === attrs.focusKey) {
					$timeout(function() {
						element[0].focus();
					});
				}
			});
		}
	};
});

// TODO: this scrolling code needs to be redesigned
webircApp.directive('resizeMaincell', function($rootScope) {
	return {
		controller: function($scope, $element, $timeout) {
			var chatlogDiv = $element[0];

			$scope.delayedScroll = this.delayedScroll = function(force) {
				function doScroll(force) {
					if (chatlogDiv.lastScrollTopTarget && chatlogDiv.scrollTop >= chatlogDiv.lastScrollTopTarget - 30) {
						// if they scroll near the bottom
						chatlogDiv.scrollLock = false;
					}
					else if (chatlogDiv.lastScrollTop && chatlogDiv.scrollTop < chatlogDiv.lastScrollTop) {
						// if the user scrolled up the chat log
						chatlogDiv.scrollLock = true;
					}

					var chatlogDivJQ = $(chatlogDiv);

					var scrollTopTarget = getScrollTopTarget(chatlogDivJQ);

					function getScrollTopTarget(theDiv) {
						// scrollHeight of 0 means the div is out of view, so we check for that case to avoid returning a negative
						if (theDiv[0].scrollHeight > 0) {
							return theDiv[0].scrollHeight // start with the total scroll height
								- theDiv.outerHeight() // subtract (height + padding + border)
								+ parseInt(theDiv.css('border-top-width')) // readd the top border
								+ parseInt(theDiv.css('border-bottom-width')) // readd the bottom border
						} else {
							return 0;
						}
					}

					if (force) {
						chatlogDiv.scrollLock = false;
					}

					if (!chatlogDiv.scrollLock)
					{
						chatlogDiv.scrollTop = scrollTopTarget;
					}

					chatlogDiv.lastScrollTop = chatlogDiv.scrollTop;
					chatlogDiv.lastScrollTopTarget = scrollTopTarget;
				}

				$timeout(doScroll.bind(null, force));
			}

			this.resetScroll = function() {
				//delete chatlogDiv.lastScrollTopTarget;
				delete chatlogDiv.lastScrollTop;
				//delete chatlogDiv.scrollLock;
			}
		},
		link: function(scope, element, attrs) {
			var getResizeParams = function() {
				var bodyOverflowY = 'hidden';

				var maincellHeight = getTargetHeightForMaincell();

				if (maincellHeight < 300) {
					maincellHeight = 300;
					// if the scrollbars are needed, enable them
					bodyOverflowY = 'auto';
				}

				return {maincellHeight: maincellHeight, bodyOverflowY: bodyOverflowY};
			}

			scope.$watch(getResizeParams, function(newVal, oldVal) {
				scope.maincellHeight = newVal.maincellHeight + 'px';
				//scope.bodyOverflowY = newVal.bodyOverflowY;

				scope.delayedScroll();
			}, true);

			if (attrs.resizeMaincell) {
				scope.$watch(attrs.resizeMaincell, function(newVal, oldVal) {
					if (newVal) {
						// if this window is becoming active, scroll to the bottom
						scope.delayedScroll(true);
					}
				}, true);
			}

			angular.element(window).bind('resize orientationchange', function() {
				// we need to rerun getResizeParams on resize
				scope.$apply();
			});
		}
	}
});

webircApp.directive('windowlistbutton', function() {
	return {
		restrict: 'E',
		compile: function(element, attr) {
			return function($scope, $element, $attr) {
				var alertCount = 0;
				var eventCount = 0;
				var isCurrent = false;

				// the elements
				var trElement = angular.element('<div/>').addClass('tablerow');
				var maincellElement = angular.element('<div/>').addClass('windowlistbutton_maincell');
				var rightcellElement = angular.element('<div/>').addClass('windowlistbutton_rightcell');

				trElement.append(maincellElement);
				trElement.append(rightcellElement);

				$element.append(trElement);

				// attributes
				var buttonLabel = $scope.$eval($attr.label);

				maincellElement.text(buttonLabel);

				var windowPath = $scope.$eval($attr.windowPath);

				maincellElement.on('mousedown', function() {
					$scope.requestSetActiveWindow(windowPath);
				});

				rightcellElement.on('mousedown', function() {
					if (isCurrent) {
						// if current, the right cell contains the close button
						$scope.requestCloseWindow(windowPath);
					} else {
						// otherwise treat it the same as clicking on the label
						$scope.requestSetActiveWindow(windowPath);
					}
				});

				$scope.$watch($attr.windowObject + '.numEvents', function(newEventCount) {
					eventCount = newEventCount;

					updateView();
				});
<commit_msg>now properly updating windowPath on windowlistbuttons<commit_after>var webircApp = angular.module('webircApp', []);

webircApp.directive('loginbox', function($rootScope) {
	return {
		scope: true,
		link: function(scope) {
			scope.login = function() {
				$rootScope.sendToGateway('Login', {
					username: scope.username,
					password: <PASSWORD>
				});

				if (window.webkitNotifications && window.webkitNotifications.checkPermission() !== 0) {
					window.webkitNotifications.requestPermission();
				}
			};

			scope.passwordKeyDown = function(event) {
				if (event.keyCode === 13) {
					scope.login();
				}
			}
		}
	};
});

webircApp.directive('focusKey', function($timeout) {
	return {
		link: function(scope, element, attrs) {
			scope.$on('FocusKey', function(e, focusKey) {
				if (focusKey === attrs.focusKey) {
					$timeout(function() {
						element[0].focus();
					});
				}
			});
		}
	};
});

// TODO: this scrolling code needs to be redesigned
webircApp.directive('resizeMaincell', function($rootScope) {
	return {
		controller: function($scope, $element, $timeout) {
			var chatlogDiv = $element[0];

			$scope.delayedScroll = this.delayedScroll = function(force) {
				function doScroll(force) {
					if (chatlogDiv.lastScrollTopTarget && chatlogDiv.scrollTop >= chatlogDiv.lastScrollTopTarget - 30) {
						// if they scroll near the bottom
						chatlogDiv.scrollLock = false;
					}
					else if (chatlogDiv.lastScrollTop && chatlogDiv.scrollTop < chatlogDiv.lastScrollTop) {
						// if the user scrolled up the chat log
						chatlogDiv.scrollLock = true;
					}

					var chatlogDivJQ = $(chatlogDiv);

					var scrollTopTarget = getScrollTopTarget(chatlogDivJQ);

					function getScrollTopTarget(theDiv) {
						// scrollHeight of 0 means the div is out of view, so we check for that case to avoid returning a negative
						if (theDiv[0].scrollHeight > 0) {
							return theDiv[0].scrollHeight // start with the total scroll height
								- theDiv.outerHeight() // subtract (height + padding + border)
								+ parseInt(theDiv.css('border-top-width')) // readd the top border
								+ parseInt(theDiv.css('border-bottom-width')) // readd the bottom border
						} else {
							return 0;
						}
					}

					if (force) {
						chatlogDiv.scrollLock = false;
					}

					if (!chatlogDiv.scrollLock)
					{
						chatlogDiv.scrollTop = scrollTopTarget;
					}

					chatlogDiv.lastScrollTop = chatlogDiv.scrollTop;
					chatlogDiv.lastScrollTopTarget = scrollTopTarget;
				}

				$timeout(doScroll.bind(null, force));
			}

			this.resetScroll = function() {
				//delete chatlogDiv.lastScrollTopTarget;
				delete chatlogDiv.lastScrollTop;
				//delete chatlogDiv.scrollLock;
			}
		},
		link: function(scope, element, attrs) {
			var getResizeParams = function() {
				var bodyOverflowY = 'hidden';

				var maincellHeight = getTargetHeightForMaincell();

				if (maincellHeight < 300) {
					maincellHeight = 300;
					// if the scrollbars are needed, enable them
					bodyOverflowY = 'auto';
				}

				return {maincellHeight: maincellHeight, bodyOverflowY: bodyOverflowY};
			}

			scope.$watch(getResizeParams, function(newVal, oldVal) {
				scope.maincellHeight = newVal.maincellHeight + 'px';
				//scope.bodyOverflowY = newVal.bodyOverflowY;

				scope.delayedScroll();
			}, true);

			if (attrs.resizeMaincell) {
				scope.$watch(attrs.resizeMaincell, function(newVal, oldVal) {
					if (newVal) {
						// if this window is becoming active, scroll to the bottom
						scope.delayedScroll(true);
					}
				}, true);
			}

			angular.element(window).bind('resize orientationchange', function() {
				// we need to rerun getResizeParams on resize
				scope.$apply();
			});
		}
	}
});

webircApp.directive('windowlistbutton', function() {
	return {
		restrict: 'E',
		compile: function(element, attr) {
			return function($scope, $element, $attr) {
				var alertCount = 0;
				var eventCount = 0;
				var isCurrent = false;

				// the elements
				var trElement = angular.element('<div/>').addClass('tablerow');
				var maincellElement = angular.element('<div/>').addClass('windowlistbutton_maincell');
				var rightcellElement = angular.element('<div/>').addClass('windowlistbutton_rightcell');

				trElement.append(maincellElement);
				trElement.append(rightcellElement);

				$element.append(trElement);

				// attributes
				var buttonLabel = $scope.$eval($attr.label);

				maincellElement.text(buttonLabel);

				var windowPath = null;

				// windowPath can change if the index of the window changes
				$scope.$watch($attr.windowPath, function(newWindowPath) {
					windowPath = newWindowPath;
				}, true);

				maincellElement.on('mousedown', function() {
					$scope.requestSetActiveWindow(windowPath);
				});

				rightcellElement.on('mousedown', function() {
					if (isCurrent) {
						// if current, the right cell contains the close button
						$scope.requestCloseWindow(windowPath);
					} else {
						// otherwise treat it the same as clicking on the label
						$scope.requestSetActiveWindow(windowPath);
					}
				});

				$scope.$watch($attr.windowObject + '.numEvents', function(newEventCount) {
					eventCount = newEventCount;

					updateView();
				});

{'fraction_non_alphanumeric': 0.12684537684537683, 'fraction_numerical': 0.003885003885003885, 'mean_word_length': 3.1994290375203915, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4359888', 'n_tokens_mistral': 4053, 'n_tokens_neox': 3068, 'n_words': 668}