<commit_before>/*
 * Tracelytics PageGuide
 *
 * Copyright 2012 Tracelytics
 * Free to use under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Contributing Author: Tracelytics Team
 */

/* PageGuide usage:

    Preferences:
        auto_show_first - Whether or not to focus on the first visible item
                        immediately on PG open (default true)
        track_events_cb - Optional callback for tracking user interactions
                        with pageguide.  Should be a method taking a single
                        parameter indicating the name of the interaction.
                        (default none)

*/
tl = window.tl || {};
tl.pg = tl.pg || {};

tl.pg.default_prefs = { 'auto_show_first': true,
                        'track_events_cb': null };

$(function() {
    /* page guide object, for pages that have one */

    if ($("#tlyPageGuide").length) {
        var guide = $("#tlyPageGuide");

        var guideWrapper = $('<div/>', {
            id: 'tlyPageGuideWrapper'
        }).appendTo('body');

        $('<div/>', {
            'title': 'Launch Page Guide',
            'class': 'tlypageguide_toggle',
            html: 'page guide<div><span>' + guide.data('tourtitle') +
                    '</span></div><a href="javascript:void(0);" title="close guide">close guide &raquo;</a>'
        }).appendTo(guideWrapper);

        guide.appendTo(guideWrapper);

        $('<div/>', { id: 'tlyPageGuideMessages' }).appendTo(guideWrapper);

        var pg = new tl.pg.PageGuide($('#tlyPageGuideWrapper'));
        new tl.pg.Listener(guideWrapper, $('#loading')).scheduleCallback();
    }
});

tl.pg.PageGuide = function (pg_elem, preferences) {
    this.preferences = $.extend(tl.pg.default_prefs, preferences || {});
    this.$base = pg_elem;
    this.$all_items = $('#tlyPageGuide > li', this.$base);
    this.$items = $([]); /* fill me with visible elements on pg expand */
    this.$message = $('#tlyPageGuideMessages');
    this.$fwd = $('a.tlypageguide_fwd', this.$base);
    this.$back = $('a.tlypageguide_back', this.$base);
    this.cur_idx = 0;
    this.open = false;
    this.track_event = this.preferences.track_events_cb || function (_) { return; };

    /* set up deferred init */
    var that = this;
    $(document).ready( function() {
        that._on_ready();
    });
};

tl.pg.isScrolledIntoView = function(elem) {
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom - 100));
};


/* to be executed on pg expand */
tl.pg.PageGuide.prototype._on_expand = function () {
    var that = this;

    /* set up initial state */
    this.position_tour();
    this.cur_idx = 0;

    $.d = document;<commit_msg>Refactor ready code into its own function<commit_after>/*
 * Tracelytics PageGuide
 *
 * Copyright 2012 Tracelytics
 * Free to use under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 *
 * Contributing Author: Tracelytics Team
 */

/* PageGuide usage:

    Preferences:
        auto_show_first - Whether or not to focus on the first visible item
                        immediately on PG open (default true)
        track_events_cb - Optional callback for tracking user interactions
                        with pageguide.  Should be a method taking a single
                        parameter indicating the name of the interaction.
                        (default none)

*/
tl = window.tl || {};
tl.pg = tl.pg || {};

tl.pg.prefs = { 
    'auto_show_first'   : true,
    'loading_selector'  : '.pgloading',
    'track_events_cb'   : null
};

$(document).ready(function() {
    var guideWrapper = tl.pg.ensureDivs();

    if (guideWrapper.length) {
        new tl.pg.PageGuide(guideWrapper);
        new tl.pg.Listener(guideWrapper, $(tl.pg.prefs.loading_selector)).scheduleCallback();
    }
});

tl.pg.PageGuide = function(pg_elem) {
    this.preferences = $.extend(tl.pg.prefs, {});
    this.$base = pg_elem;
    this.$all_items = $('#tlyPageGuide > li', this.$base);
    this.$items = $([]); /* fill me with visible elements on pg expand */
    this.$message = $('#tlyPageGuideMessages');
    this.$fwd = $('a.tlypageguide_fwd', this.$base);
    this.$back = $('a.tlypageguide_back', this.$base);
    this.cur_idx = 0;
    this.open = false;
    this.track_event = this.preferences.track_events_cb || function (_) { return; };

    /* set up deferred init */
    var that = this;
    $(document).ready( function() {
        that._on_ready();
    });
};

tl.pg.ensureDivs = function() {
    var guideContent = $("#tlyPageGuide"),
        guideWrapper = $('#tlyPageGuideWrapper');


    /* If guideContent doesn't exist, then this page does not support pageguide.
     * But if guideWrapper exists, then we've already setup pageguide and we
     * shouldn't do it again.
     */
    if (guideContent.length == 0 || guideWrapper.length == 1) {
        return $();
    }

    var guideWrapper = $('<div/>', {
        id: 'tlyPageGuideWrapper'
    }).appendTo('body');

    $('<div/>', {
        'title': 'Launch Page Guide',
        'class': 'tlypageguide_toggle'
    }).append('page guide')
      .append('<div><span>' + guideContent.data('tourtitle') + '</span></div>')
      .append('<a href="javascript:void(0);" title="close guide">close guide &raquo;</a>')
    .appendTo(guideWrapper);

    guideWrapper.append(guideContent);
    guideWrapper.append('<div id="tlyPageGuideMessages"/>');
      
    return guideWrapper;
};

tl.pg.isScrolledIntoView = function(elem) {
    var docViewTop = $(window).scrollTop();
    var docViewBottom = docViewTop + $(window).height();

    var elemTop = $(elem).offset().top;
    var elemBottom = elemTop + $(elem).height();

    return ((elemBottom >= docViewTop) && (elemTop <= docViewBottom - 100));
};


/* to be executed on pg expand */
tl.pg.PageGuide.prototype._on_expand = function () {
    var that = this;

    /* set up initial state */
    this.position_tour();
    this.cur_idx = 0;

    $.d = document;
{'fraction_non_alphanumeric': 0.15337224383916992, 'fraction_numerical': 0.0035667963683527885, 'mean_word_length': 2.676400476758045, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5474255', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1831, 'n_words': 458}