<commit_before>/*!
 * Copyright 2006 - 2014 TubePress LLC (http://tubepress.com).
 * This file is part of TubePress (http://tubepress.com).
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/*jslint browser: true */

/**
 * This script expects galleries to "register" themselves by including a snippet of JS
 * anywhere on the page. This snippet of JS should look something like this:
 *
 * <script type="text/javascript">
 *     var tubePressGalleryRegistrar = tubePressGalleryRegistrar || [];
 *     tubePressGalleryRegistrar.push(['register', '123456789', {} ]);
 * </script>
 *
 * As you can see, this is an asynchronous JS call that can happen anywhere on the page.
 * The second argument to push(), "123456789" in the example, is the page-unique gallery identifier.
 * The third argument to push(), "{}" in the example, is JSON config for this gallery. This config
 * should contain the following elements:
 *
 * {
 *     "options" : { ... },       //a dictionary of TubePress options to values
 *                                //that are likely useful for frontend functionality
 *
 *     "ephemeral" : { ... },     //a dictionary of "ephemeral" options to values for this gallery that should be
 *                                //sent in any Ajax request back to the server. We separate these from the
 *                                //"options" attribute to cut down on URL length and server processing.
 * }
 *
 * When this script sees such a registration, it will fire an event called "tubepress.gallery.load" with the following
 * data object:
 *
 * {
 *     "galleryId" : 123456789,
 *     "params"    : {
 *
 *         "options"   : { ... },
 *         "ephemeral" : { ... }
 *     }
 * }
 *
 * This script may also publish the following events:
 *
 * tubepress.gallery.fluidThumbs                    //After we have made thumbnails fluid
 * {
 *     "galleryId"     : 123456789,
 *     "newThumbWidth" : 155
 * }
 *
 * tubepress.gallery.item.change                    //When an item change has been requested
 * {
 *     "galleryId" : 123456789,
 *     "itemId"   : "ekv9384jJD"
 * }
 *
 * tubepress.gallery.player.invoke.<playername>     //When we are invoking a player location (e.g. right after a user clicks
 *                                                  //a thumbnail
 * {
 *     "galleryId" : 123456789,
 *     "itemId"   : "ekv9384jJD"
 * }
 *
 * tubepress.gallery.player.populate.<playername>   //When we have received a response from the server for some player HTML
 * {
 *     "galleryId" : 123456789,
 *     "itemId"    : "ekv9384jJD"
 *     "mediaItem" : { ... },            //a dictionary representing the backing tubepress_app_api_media_MediaItem attributes
 *     "html"      : " ... "             //the HTML for this player
 * }
 */

/**
 * IE8 and below forces us to declare this now.
 *
 * http://tobyho.com/2013/03/13/window-prop-vs-global-var/
 */
var tubePressGalleryRegistrar;

(function (jquery, tubepress) {

    /** http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ */
    'use strict';

    var text_tubepress      = 'tubepress',
        text_gallery        = 'gallery',
        text_item           = 'item',
        text_dot            = '.',
        text_underscore     = '_',
        text_dash           = '-',
        text_hash           = '#',
        text_space          = ' ',
        text_player         = 'player',
        text_Id             = 'Id',
        text_id             = 'id',
        text_params         = 'params',
        text_sys            = 'sys',
        text_js             = 'js',
        text_div            = 'div',
        text_fluid          = 'fluid',
        text_class          = 'class',
        text_fluidThumbs    = text_fluid + 'Thumbs',
        text_html           = 'html',
        text_thumb          = 'thumb',
        text_length         = 'length',
        text_thumbs         = text_thumb + 's',
        text_js_dash        = text_js + text_dash,
        text_tubepress_dash = text_tubepress + text_dash,
        text_galleryId      = text_gallery + text_Id,
        text_itemId         = text_item + text_Id,
        text_dot_js_dash    = text_dot + text_js_dash,
        text_un_gallery_un  = text_underscore + text_gallery + text_underscore,

        text_eventPrefix_gallery        = text_tubepress + text_dot + text_gallery + text_dot,
        text_event_tx_galleryLoad       = text_eventPrefix_gallery + 'load',
        text_event_rx_galleryNewThumbs  = text_eventPrefix_gallery + 'new' + text_thumbs,

        text_event_tx_itemChange = text_eventPrefix_gallery + text_item + text_dot + 'change',

        text_eventPrefix_player         = text_eventPrefix_gallery + text_player + text_dot,
        text_eventPrefix_playerPopulate = text_eventPrefix_player + 'populate' + text_dot,
        text_eventPrefix_playerInvoke   = text_eventPrefix_player + 'invoke' + text_dot,

        beacon            = tubepress.Beacon,
        subscribe         = beacon.subscribe,
        publish           = beacon.publish,
        langUtils         = tubepress.Lang.Utils,
        isDefined         = langUtils.isDefined,
        environment       = tubepress.Environment,
        troo              = true,
        fawlse            = false,

        /**
         * Provides convenient selectors to access the outermost gallery div.
         */
        selectors = (function () {

            var outerMostCache = {},
                thumbAreaCache = {},

                getOutermostSelectorLegacy = function (galleryId) {

                    return text_hash + text_tubepress + text_un_gallery_un + galleryId;
                },

                getOutermostSelectorModern = function (galleryId) {

                    return text_dot_js_dash + text_tubepress_dash + text_gallery + text_dash + galleryId;
                },

                getOutermostElement = function (galleryId) {

                    if (!langUtils.isDefined(outerMostCache[galleryId])) {

                        outerMostCache[galleryId] = jquery(getOutermostSelectorLegacy(galleryId)).add(getOutermostSelectorModern(galleryId));
                    }

                    return outerMostCache[galleryId];
                },

                getThumbAreaSelectorModern = function (galleryId) {

                    return getOutermostSelectorModern(galleryId) + text_space + text_dot_js_dash + text_tubepress_dash + 'pagination-and-' + text_thumbs;
                },

                getThumbAreaSelectorLegacy = function (galleryId) {

                    return text_hash + text_tubepress + text_un_gallery_un + galleryId + '_thumbnail_area';
                },

                getThumbAreaElement = function (galleryId) {

                    if (!langUtils.isDefined(thumbAreaCache[galleryId])) {

                        thumbAreaCache[galleryId] = jquery(getThumbAreaSelectorLegacy(galleryId)).add(getThumbAreaSelectorModern(galleryId));<commit_msg>Minor improvements to detection of existing galleries via gallery.js<commit_after>/*!
 * Copyright 2006 - 2014 TubePress LLC (http://tubepress.com).
 * This file is part of TubePress (http://tubepress.com).
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

/*jslint browser: true */

/**
 * This script expects galleries to "register" themselves by including a snippet of JS
 * anywhere on the page. This snippet of JS should look something like this:
 *
 * <script type="text/javascript">
 *     var tubePressGalleryRegistrar = tubePressGalleryRegistrar || [];
 *     tubePressGalleryRegistrar.push(['register', '123456789', {} ]);
 * </script>
 *
 * As you can see, this is an asynchronous JS call that can happen anywhere on the page.
 * The second argument to push(), "123456789" in the example, is the page-unique gallery identifier.
 * The third argument to push(), "{}" in the example, is JSON config for this gallery. This config
 * should contain the following elements:
 *
 * {
 *     "options" : { ... },       //a dictionary of TubePress options to values
 *                                //that are likely useful for frontend functionality
 *
 *     "ephemeral" : { ... },     //a dictionary of "ephemeral" options to values for this gallery that should be
 *                                //sent in any Ajax request back to the server. We separate these from the
 *                                //"options" attribute to cut down on URL length and server processing.
 * }
 *
 * When this script sees such a registration, it will fire an event called "tubepress.gallery.load" with the following
 * data object:
 *
 * {
 *     "galleryId" : 123456789,
 *     "params"    : {
 *
 *         "options"   : { ... },
 *         "ephemeral" : { ... }
 *     }
 * }
 *
 * This script may also publish the following events:
 *
 * tubepress.gallery.fluidThumbs                    //After we have made thumbnails fluid
 * {
 *     "galleryId"     : 123456789,
 *     "newThumbWidth" : 155
 * }
 *
 * tubepress.gallery.item.change                    //When an item change has been requested
 * {
 *     "galleryId" : 123456789,
 *     "itemId"   : "ekv9384jJD"
 * }
 *
 * tubepress.gallery.player.invoke.<playername>     //When we are invoking a player location (e.g. right after a user clicks
 *                                                  //a thumbnail
 * {
 *     "galleryId" : 123456789,
 *     "itemId"   : "ekv9384jJD"
 * }
 *
 * tubepress.gallery.player.populate.<playername>   //When we have received a response from the server for some player HTML
 * {
 *     "galleryId" : 123456789,
 *     "itemId"    : "ekv9384jJD"
 *     "mediaItem" : { ... },            //a dictionary representing the backing tubepress_app_api_media_MediaItem attributes
 *     "html"      : " ... "             //the HTML for this player
 * }
 */

/**
 * IE8 and below forces us to declare this now.
 *
 * http://tobyho.com/2013/03/13/window-prop-vs-global-var/
 */
var tubePressGalleryRegistrar;

(function (jquery, tubepress) {

    /** http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ */
    'use strict';

    var text_tubepress      = 'tubepress',
        text_gallery        = 'gallery',
        text_item           = 'item',
        text_dot            = '.',
        text_underscore     = '_',
        text_dash           = '-',
        text_hash           = '#',
        text_space          = ' ',
        text_player         = 'player',
        text_Id             = 'Id',
        text_id             = 'id',
        text_params         = 'params',
        text_sys            = 'sys',
        text_js             = 'js',
        text_div            = 'div',
        text_fluid          = 'fluid',
        text_class          = 'class',
        text_fluidThumbs    = text_fluid + 'Thumbs',
        text_html           = 'html',
        text_thumb          = 'thumb',
        text_length         = 'length',
        text_thumbs         = text_thumb + 's',
        text_js_dash        = text_js + text_dash,
        text_tubepress_dash = text_tubepress + text_dash,
        text_galleryId      = text_gallery + text_Id,
        text_itemId         = text_item + text_Id,
        text_dot_js_dash    = text_dot + text_js_dash,
        text_un_gallery_un  = text_underscore + text_gallery + text_underscore,

        text_eventPrefix_gallery        = text_tubepress + text_dot + text_gallery + text_dot,
        text_event_tx_galleryLoad       = text_eventPrefix_gallery + 'load',
        text_event_rx_galleryNewThumbs  = text_eventPrefix_gallery + 'new' + text_thumbs,

        text_event_tx_itemChange = text_eventPrefix_gallery + text_item + text_dot + 'change',

        text_eventPrefix_player         = text_eventPrefix_gallery + text_player + text_dot,
        text_eventPrefix_playerPopulate = text_eventPrefix_player + 'populate' + text_dot,
        text_eventPrefix_playerInvoke   = text_eventPrefix_player + 'invoke' + text_dot,

        beacon            = tubepress.Beacon,
        subscribe         = beacon.subscribe,
        publish           = beacon.publish,
        langUtils         = tubepress.Lang.Utils,
        isDefined         = langUtils.isDefined,
        environment       = tubepress.Environment,
        troo              = true,
        fawlse            = false,

        /**
         * Provides convenient selectors to access the outermost gallery div.
         */
        selectors = (function () {

            var outerMostCache = {},
                thumbAreaCache = {},

                getOutermostSelectorLegacy = function (galleryId) {

                    return text_hash + text_tubepress + text_un_gallery_un + galleryId;
                },

                getOutermostSelectorModern = function (galleryId) {

                    return text_dot_js_dash + text_tubepress_dash + text_gallery + text_dash + galleryId;
                },

                getOutermostElement = function (galleryId) {

                    if (langUtils.isDefined(outerMostCache[galleryId])) {

                        return outerMostCache[galleryId];
                    }

                    var legacyOutermostSelector = getOutermostSelectorLegacy(galleryId),
                        modernOutermostSelector = getOutermostSelectorModern(galleryId),
                        element                 = jquery(legacyOutermostSelector).add(modernOutermostSelector);

                    if (element.length > 0) {

                        outerMostCache[galleryId] = element;
                    }

                    return element;
                },

                getThumbAreaSelectorModern = function (galleryId) {

                    return getOutermostSelectorModern(galleryId) + text_space + text_dot_js_dash + text_tubepress_dash + 'pagination-and-' + text_thumbs;
                },

                getThumbAreaSelectorLegacy = function (galleryId) {

                    return text_hash + text_tubepress + text_un_gallery_un + galleryId + '_thumbnail_area';
                },

                getThumbAreaElement = function (galleryId) {

                    if (!langUtils.isDefined(thumbAreaCache[galleryId])) {

                        thumbAreaCache[galleryId] = jquery(getThumbAreaSelectorLegacy(galleryId)).add(getThumbAreaSelectorModern(galleryId));
{'fraction_non_alphanumeric': 0.0948489010989011, 'fraction_numerical': 0.013804945054945054, 'mean_word_length': 1.899442453205894, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6065592', 'n_tokens_mistral': 4403, 'n_tokens_neox': 3943, 'n_words': 995}