<commit_before>// Universal Subtitles, universalsubtitles.org
// 
// Copyright (C) 2010 Participatory Culture Foundation
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
// 
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see 
// http://www.gnu.org/licenses/agpl-3.0.html.

goog.provide('mirosubs.widgetizer.VideoPlayerMaker');

/**
 * Abstract base class for making AbstractVideoPlayers out of 
 * video-playing elements on the page.
 * @constructor
 */
mirosubs.widgetizer.VideoPlayerMaker = function() {
};

mirosubs.widgetizer.VideoPlayerMaker.prototype.videosExist = 
    goog.abstractMethod;

mirosubs.widgetizer.VideoPlayerMaker.prototype.makeVideoPlayers =
    goog.abstractMethod;

/**
 * @protected
 * @param {Array.<Element>} videoElements
 */
mirosubs.widgetizer.VideoPlayerMaker.prototype.filterUnwidgetized = 
    function(videoElements) 
{
    return goog.array.filter(
        videoElements,
        function(elem) { return this.isUnwidgetized(elem); }, this);
};

/**
 * @protected
 * @param {Element} element
 */
mirosubs.widgetizer.VideoPlayerMaker.prototype.isUnwidgetized = function(element) {
    return !goog.array.find(
        mirosubs.video.AbstractVideoPlayer.players,
        function(p) { return p.getVideoElement() == element; });
};

mirosubs.widgetizer.VideoPlayerMaker.prototype.findObjectParam_ = 
    function(objElem, paramName) 
{
    return goog.dom.findNode(
        objElem, 
        function(n) {
            return n.nodeName == "PARAM" && 
                goog.string.caseInsensitiveCompare(n['name'], paramName) == 0;
        });
};

mirosubs.widgetizer.VideoPlayerMaker.prototype.findFlashParam =
    function(element, embedParamName, opt_objectParamName) 
{
    if (element.nodeName == "EMBED") {
        return element.getAttribute(embedParamName);
    } else {
        var paramNode = this.findObjectParam_(
            element, opt_objectParamName || embedParamName);
        if (paramNode) {
            return paramNode['value'];
        }
    }
    return null;
};

mirosubs.widgetizer.VideoPlayerMaker.prototype.swfURL = function(element) {
    if (element.nodeName == "OBJECT" && element['data']) {
        return element['data'];
    } else {
        return this.findFlashParam(element, 'src', 'movie');
    }
};

/**
 * To be overridden by classes that widgetize flash-based video elements.
 * @returns {Boolean}
 */
mirosubs.widgetizer.VideoPlayerMaker.prototype.isFlashElementAPlayer = goog.abstractMethod;

/**
 * @protected
 */
mirosubs.widgetizer.VideoPlayerMaker.prototype.unwidgetizedFlashElements = function() {
    var unwidgetizedElements = [];
    var objects = goog.dom.getElementsByTagNameAndClass('object');
    for (var i = 0; i < objects.length; i++)
        if (this.isFlashElementAPlayer(objects[i]) &&
            this.isUnwidgetized(objects[i])) {
            unwidgetizedElements.push(objects[i]);
        }
    var embeds = goog.dom.getElementsByTagNameAndClass('embed');
    for (var i = 0; i < embeds.length; i++) {
        if (this.isFlashElementAPlayer(embeds[i]) &&
            this.isUnwidgetized(embeds[i]) &&
            embeds[i].parentNode.nodeName != 'OBJECT')
            unwidgetizedElements.push(embeds[i]);
    }<commit_msg>Should fix IE issue with widgetizer<commit_after>// Universal Subtitles, universalsubtitles.org
// 
// Copyright (C) 2010 Participatory Culture Foundation
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
// 
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see 
// http://www.gnu.org/licenses/agpl-3.0.html.

goog.provide('mirosubs.widgetizer.VideoPlayerMaker');

/**
 * Abstract base class for making AbstractVideoPlayers out of 
 * video-playing elements on the page.
 * @constructor
 */
mirosubs.widgetizer.VideoPlayerMaker = function() {
};

mirosubs.widgetizer.VideoPlayerMaker.prototype.logger_ = 
    goog.debug.Logger.getLogger(
        'mirosubs.widgetizer.VideoPlayerMaker');

mirosubs.widgetizer.VideoPlayerMaker.prototype.videosExist = 
    goog.abstractMethod;

mirosubs.widgetizer.VideoPlayerMaker.prototype.makeVideoPlayers =
    goog.abstractMethod;

/**
 * @protected
 * @param {Array.<Element>} videoElements
 */
mirosubs.widgetizer.VideoPlayerMaker.prototype.filterUnwidgetized = 
    function(videoElements) 
{
    return goog.array.filter(
        videoElements,
        function(elem) { return this.isUnwidgetized(elem); }, this);
};

/**
 * @protected
 * @param {Element} element
 */
mirosubs.widgetizer.VideoPlayerMaker.prototype.isUnwidgetized = function(element) {
    return !goog.array.find(
        mirosubs.video.AbstractVideoPlayer.players,
        function(p) { return p.getVideoElement() == element; });
};

mirosubs.widgetizer.VideoPlayerMaker.prototype.findObjectParam_ = 
    function(objElem, paramName) 
{
    return goog.dom.findNode(
        objElem, 
        function(n) {
            return n.nodeName == "PARAM" && 
                goog.string.caseInsensitiveCompare(n['name'], paramName) == 0;
        });
};

mirosubs.widgetizer.VideoPlayerMaker.prototype.findFlashParam =
    function(element, embedParamName, opt_objectParamName) 
{
    if (element.nodeName == "EMBED") {
        return element.getAttribute(embedParamName);
    } else {
        var paramNode = this.findObjectParam_(
            element, opt_objectParamName || embedParamName);
        if (paramNode) {
            return paramNode['value'];
        }
    }
    return null;
};

mirosubs.widgetizer.VideoPlayerMaker.prototype.swfURL = function(element) {
    if (element.nodeName == "OBJECT" && element['data']) {
        return element['data'];
    } else {
        return this.findFlashParam(element, 'src', 'movie');
    }
};

/**
 * To be overridden by classes that widgetize flash-based video elements.
 * @returns {Boolean}
 */
mirosubs.widgetizer.VideoPlayerMaker.prototype.isFlashElementAPlayer = goog.abstractMethod;

/**
 * @protected
 */
mirosubs.widgetizer.VideoPlayerMaker.prototype.unwidgetizedFlashElements = function() {
    var unwidgetizedElements = [];
    var objects = goog.dom.getElementsByTagNameAndClass('object');
    for (var i = 0; i < objects.length; i++)
        if (this.isFlashElementAPlayer(objects[i]) &&
            this.isUnwidgetized(objects[i])) {
            unwidgetizedElements.push(objects[i]);
        }
    var embeds = goog.dom.getElementsByTagNameAndClass('embed');
    for (var i = 0; i < embeds.length; i++) {
        if (this.isFlashElementAPlayer(embeds[i]) &&
            this.isUnwidgetized(embeds[i]) &&
            !goog.array.contains(unwidgetizedElements, 
                                 embeds[i].parentNode))
            unwidgetizedElements.push(embeds[i]);
    }
{'fraction_non_alphanumeric': 0.11571317628785918, 'fraction_numerical': 0.0025886616619207868, 'mean_word_length': 3.309537088678193, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7472973', 'n_tokens_mistral': 2314, 'n_tokens_neox': 2252, 'n_words': 520}