<commit_before>define([
    'backbone',
    'jqueryui'
], function(Backbone) {

    return Backbone.View.extend({

        initialize: function(options) {
            _.bindAll(this, 'showTab', 'selectTab');

            var routePrefix = options.routePrefix;

            this.tabs = options.tabs;
            this.router = options.router;
            this.vent = options.vent;
            this.appPrefix = options.appPrefix || 'page';
            this.routePrefix = routePrefix;

            this.router.on('route:' + _.last(routePrefix.split('/')), this.selectTab);

            this.$el.tabs({
                activate: this.showTab,
                active: -1
            });

            // this implicitly calls showTab, and will set this.selectedId
            this.$el.tabs('option', 'active', 0);
        },

        showTab: function(e, ui) {
            var id = ui.newPanel.attr('id');

            // if the tab has just been created, we don't want to update the routes, otherwise when you
            // refresh the page you'll get spurious 'back' entries for the first tab in the tab view.
            var tabNewlyCreated = !this.selectedId;
            this.selectedId = id;

            var tab = this.find(id);
            if (!tabNewlyCreated && (!tab.view || !_.result(tab.view, 'suppressTabHistory'))) {
                var newRoute = this.appPrefix + '/' + this.getSelectedRoute(id);

                var isSubtabRoute = newRoute.indexOf(Backbone.history.fragment.replace(/^.*?page/, 'page') + '/') === 0;

                // if the new route is a subtab of the old route, we should replace the old route
                // e.g. when refreshing a page on #page/performance/performanceStatistics/statstab-ACI we
                // briefly go to #page/performance/performanceStatistics.
                this.vent.navigate(newRoute, {
                    trigger: false,
                    replace: isSubtabRoute
                });
            }
        },

        selectTab: function(reqId) {
            var id = reqId || this.selectedId;

            this.$el.tabs('option', 'active', this.indexOf(id));
            this.selectedId = id;
        },

		find: function(id) {
			return _.find(this.tabs, function(tab) {
				return tab.href === id
			});
		},

        indexOf: function(id) {
            return _.indexOf(this.tabs, this.find(id));
        },

        getSelectedRoute: function(id) {
            id = id || this.selectedId;
            return [this.routePrefix, id].join('/');
        }

    });

});
<commit_msg>Use app prefix instead of page.  Add tests for lazy tab view. [rev: matthew.gordon2]<commit_after>define([
    'backbone',
    'jqueryui'
], function(Backbone) {

    return Backbone.View.extend({

        initialize: function(options) {
            _.bindAll(this, 'showTab', 'selectTab');

            var routePrefix = options.routePrefix;

            this.tabs = options.tabs;
            this.router = options.router;
            this.vent = options.vent;
            this.appPrefix = options.appPrefix || 'page';
            this.routePrefix = routePrefix;

            this.router.on('route:' + _.last(routePrefix.split('/')), this.selectTab);

            this.$el.tabs({
                activate: this.showTab,
                active: -1
            });

            // this implicitly calls showTab, and will set this.selectedId
            this.$el.tabs('option', 'active', 0);
        },

        showTab: function(e, ui) {
            var id = ui.newPanel.attr('id');

            // if the tab has just been created, we don't want to update the routes, otherwise when you
            // refresh the page you'll get spurious 'back' entries for the first tab in the tab view.
            var tabNewlyCreated = !this.selectedId;
            this.selectedId = id;

            var tab = this.find(id);
            if (!tabNewlyCreated && (!tab.view || !_.result(tab.view, 'suppressTabHistory'))) {
                var newRoute = this.appPrefix + '/' + this.getSelectedRoute(id);

                var isSubTabRoute = newRoute.indexOf(Backbone.history.fragment.replace(new RegExp('^.*?' + this.appPrefix), this.appPrefix ) + '/') === 0;

                // if the new route is a subtab of the old route, we should replace the old route
                // e.g. when refreshing a page on #page/performance/performanceStatistics/statstab-ACI we
                // briefly go to #page/performance/performanceStatistics.
                this.vent.navigate(newRoute, {
                    trigger: false,
                    replace: isSubTabRoute
                });
            }
        },

        selectTab: function(reqId) {
            var id = reqId || this.selectedId;

            this.$el.tabs('option', 'active', this.indexOf(id));
            this.selectedId = id;
        },

        find: function(id) {
            return _.find(this.tabs, function(tab) {
                return tab.href === id
            });
        },

        indexOf: function(id) {
            return _.indexOf(this.tabs, this.find(id));
        },

        getSelectedRoute: function(id) {
            id = id || this.selectedId;
            return [this.routePrefix, id].join('/');
        }

    });

});

{'fraction_non_alphanumeric': 0.1258328574148106, 'fraction_numerical': 0.001332571863696935, 'mean_word_length': 1.7110423116615068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6156787', 'n_tokens_mistral': 1480, 'n_tokens_neox': 1386, 'n_words': 357}