{"size": 2265, "ext": "js", "max_stars_repo_path": "public/controller/article.js", "max_stars_repo_name": "loehx/WikiReader", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "public/controller/article.js", "max_issues_repo_name": "loehx/WikiReader", "max_issues_repo_issues_event_min_datetime": "2015-01-12T11:07:02.000Z", "max_issues_repo_issues_event_max_datetime": "2015-01-12T11:28:06.000Z", "max_forks_repo_path": "public/controller/article.js", "max_forks_repo_name": "loehx/WikiReader", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 32.3571428571, "max_line_length": 113, "alphanum_fraction": 0.4754966887}
app.controller('ArticleController', ['$scope', '$location', '$routeParams', '$sce', '$anchorScroll',
    function ($scope, $location, $routeParams, $sce) {

        var wiki = new Wikipedia(app.settings.language);
        var linkRegex = new RegExp('href="/wiki/(((?!").)+)', 'g');
        var hashRegex = new RegExp('href="#(((?!").)+)', 'g');

        $scope.articleName = $routeParams.articleName;
        $scope.pageClass = 'page-article';

        
        // Scroll smoothly to the top.
        $('body').animate({
            scrollTop: '0'
        }, $('body').scrollTop());

        
        // If the article name isn't specified, go back to search.
        if (!$scope.articleName) {
            $location.path('/');
        }

        
        // Load the article from the Wikipedia module.
        wiki.getArticle($scope.articleName, function (response) {
            if (!response) {
                $scope.error = true;
                $scope.$apply();
                return;
            }
            
            // Set the article content.
            $scope.content = $sce.trustAsHtml(adjustLinks(response.text['*']));
            $scope.$apply();
            
            // Adjust the images afterwards.
            setTimeout(function () {
                adjustImages()
            }, 0);
        });

        
        /**
        *   Cleans up the links in the article content.
        *   Some links would crash if they get clicked.
        */
        function adjustLinks(html) {
            
            // Fix the table of contents links
            html = html.replace(hashRegex, "href=\"javascript: document.getElementById('$1').scrollIntoView();");
            
            // Fix all Wikipedia internal links.
            html = html.replace(linkRegex, 'href="#/article/$1');
            
            return html;
        }

        /**
        *   Set the link around all image to the full size image.
        */
        function adjustImages() {
            var article = $('#article');
            var regex = new RegExp("/((?!/).)+$|/thumb", "g");

            article.find('img').each(function (i, e) {
                $(e).parent('a')
                    .attr('href', e.src.replace(regex, ''));
            });
        }
}]);