<commit_before>/**
* Sample app declaration
*
*/
var app = angular.module('myApp', []);


/**
* @ngDoc directive
* @name ng.directive:paging
*
* @description
* The paging directive allows you to specify custom 
*
* @element E
* 
* @todo
* figure out best commenting structure 
*
*/
app.directive('paging', function () {

    // Private Count Variable
    var pageCount = 0,
        dots = '...',
        adjacent = 2,
		ulClass = 'pagination',
        activeClass = 'active';


    // Add Dots ie: 1 2 [...] 10 11 12 [...] 56 57
    function addDots(scope) {
        scope.List.push({
            value: dots
        });
    }


    // Add Range of Numbers
    function addRange(start, finish, scope) {

        var i = 0;
        for (i = start; i <= finish; i++) {

            var item = {
                value: i,
                title: 'Page ' + i,
                liClass: scope.page == i ? activeClass : '',
                onClick: function () {

                    if (scope.page == this.value) {
                        return;
                    }

                    var value = this.value;
                    scope.page = value;
                    scrollTo(0);
                }
            };

            scope.List.push(item);
        }
    }


    // Add First Pages
    function addFirst(scope) {
        addRange(1, 2, scope);
        addDots(scope);
    }

    // Add Last Pages
    function addLast(scope) {
        addDots(scope);
        addRange(pageCount - 1, pageCount, scope);
    }


	
    function build(scope) {

        if (!scope.pagesize || scope.pagesize < 0) {
            // to block divide by 0
            return;
        }

        if (!scope.page) {
            // default page is 1
            scope.page = 1;
        }
		
		// variables
        var start,
            size = adjacent * 2;

        scope.Hide = false;
		scope.ulClass = ulClass;
        scope.page = parseInt(scope.page);
        scope.List = [];
        pageCount = Math.ceil(scope.total / scope.pagesize);

		
		// Block anything to big
		if(scope.page > pageCount)
		{
			scope.page = pageCount;
		}
		

        // Hide from page if we have 1 or less pages
        if (pageCount <= 1) {
            scope.Hide = true;
            return;
        }
		
		
        if (pageCount < (5 + size)) {
            start = 1;
            addRange(start, pageCount, scope);
        }
        else {
            var finish;
            if (scope.page <= (1 + size)) {
                start = 1;
                finish = 2 + size;
                addRange(start, finish, scope);
                addLast(scope);
            }
            else if (pageCount - size > scope.page && scope.page > size) {
                start = scope.page - adjacent;
                finish = scope.page + adjacent;
                addFirst(scope);
                addRange(start, finish, scope);
                addLast(scope);
            }
            else {
                start = pageCount - (1 + size);
                finish = pageCount;
				addFirst(scope);
                addRange(start, finish, scope);
            }
        }
    }

 


    return {
        restrict: 'EA',
        scope: {
            page: '=',
            pagesize: '=',
            total: '='
        },
        template:
            '<ul ng-hide="Hide" class="{{ulClass}}"> ' +
                '<li ' +
                    'title="{{Item.title}}" ' +
                    'ng-class="Item.liClass" ' +
                    'ng-click="Item.onClick()" ' +
                    'ng-repeat="Item in List"> ' +
                '<span>{{Item.value}}</span> ' +
            '</ul>',
        link: function (scope) {
			build(scope);

            scope.$watch('page', function (value) {
				build(scope);
            });
        }
    }
});<commit_msg>Scope based re-write<commit_after>/**
* @ngDoc module
* @name ng.module:myApp
* 
* @description
* This module is just here for sample purposes
*/
var app = angular.module('myApp', []);


/**
* @ngDoc directive
* @name ng.directive:paging
*
* @description
* The paging directive allows you to specify custom 
*
* @element E
* 
*/
app.directive('paging', function() {


        // Assign null-able scope values from settings
        function defaultValues(scope) {
            scope.page = scope.page || 1;
            scope.dots = scope.dots || '...';
			scope.ulClass = scope.ulClass || 'pagination';
			scope.adjacent = scope.adjacent || 2;
			scope.activeClass = scope.activeClass || 'active'; 
			scope.hideIfEmpty = scope.hideIfEmpty || false;
			scope.scrollTop = scope.scrollTop || true;
        }



        // Add Dots ie: 1 2 [...] 10 11 12 [...] 56 57
        function addDots(scope) {
            scope.List.push({
                value: scope.dots
            });
        }



        // Add Range of Numbers
        function addRange(start, finish, scope) {

            var i = 0;
            for (i = start; i <= finish; i++) {

                var item = {
                    value: i,
                    title: 'Page ' + i,
                    liClass: scope.page == i ? scope.activeClass : '',
                    onClick: function() {

                        if (scope.page == this.value) {
                            return;
                        }

                        var value = this.value;
                        scope.page = value;
                        
						if(scope.scrollTop){
							scrollTo(0,0);
						}
                    }
                };

                scope.List.push(item);
            }
        }


        // Add First Pages
        function addFirst(scope) {
            addRange(1, 2, scope);
            addDots(scope);
        }

        // Add Last Pages
        function addLast(pageCount, scope) {
            addDots(scope);
            addRange(pageCount - 1, pageCount, scope);
        }


        // Main build function
        function build(scope) {

					
			// Block divide by 0 and empty page size
			if (!scope.pageSize || scope.pageSize < 0) {
                return;
            }
		
            // Assign scope values
            scope.List = [];
            defaultValues(scope);
            scope.page = parseInt(scope.page);
	
						
            // local variables
            var start,
                size = scope.adjacent * 2,
                pageCount = Math.ceil(scope.total / scope.pageSize);


            // Block anything to big
            if (scope.page > pageCount) {
                scope.page = pageCount;
            }

            // Hide from page if we have 1 or less pages
            if (pageCount <= 1) {
                scope.hideIfEmpty = true;
                return;
            }


            if (pageCount < (5 + size)) {
                start = 1;
                addRange(start, pageCount, scope);
            } else {
                var finish;
                if (scope.page <= (1 + size)) {
                    start = 1;
                    finish = 2 + size;
                    addRange(start, finish, scope);
                    addLast(pageCount, scope);
                } else if (pageCount - size > scope.page && scope.page > size) {
                    start = scope.page - scope.adjacent;
                    finish = scope.page + scope.adjacent;
                    addFirst(scope);
                    addRange(start, finish, scope);
                    addLast(pageCount, scope);
                } else {
                    start = pageCount - (1 + size);
                    finish = pageCount;
                    addFirst(scope);
                    addRange(start, finish, scope);
                }
            }
        }


        // The actual angular directive return
        return {
            restrict: 'EA',
            scope: {
                page: '=',
                pageSize: '=',
                total: '=',
                dots: '@',
                hideIfEmpty: '@',
                ulClass: '@',
                adjacent: '@',
                activeClass: '@',
				scrollTop: '@'
            },
            template:
                '<ul ng-hide="Hide" class="{{ulClass}}"> ' +
                    '<li ' +
                    'title="{{Item.title}}" ' +
                    'ng-class="Item.liClass" ' +
                    'ng-click="Item.onClick()" ' +
                    'ng-repeat="Item in List"> ' +
                    '<span>{{Item.value}}</span> ' +
                    '</ul>',
            link: function(scope) {
                build(scope);
                scope.$watch('page', function() {
                    build(scope);
                });
            }
        };
    }
);
{'fraction_non_alphanumeric': 0.12310715524216853, 'fraction_numerical': 0.007282395098832505, 'mean_word_length': 1.1087009505240069, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 19, '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': '1935119', 'n_tokens_mistral': 2530, 'n_tokens_neox': 2254, 'n_words': 554}