# All files / src/lib/markdown-it/plugins/markdown-it-block-embed/services VideoServiceBase.js

91.89% Statements 34/37
82.14% Branches 23/28
62.5% Functions 5/8
91.89% Lines 34/37

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94

    19x

    180x
    180x
    180x

    19x

    19x
    19x

    19x
    19x
    18x

    19x
    19x

    19x
    19x
    18x
    18x
    18x

    19x
    19x
    19x
    19x

    19x
    1x
    1x

    1x
    1x

    19x
    19x
    19x
    19x

    19x

    116x

    19x

    17x
     // Copyright (c) Rotorz Limited and portions by original markdown-it-video authors
    // Licensed under the MIT license. See LICENSE file in the project root.

    "use strict";

    function defaultUrlFilter(url, _videoID, _serviceName, _options) {
      return url;
    }

    class VideoServiceBase {

      constructor(name, options, env) {
        this.name = name;
        this.options = Object.assign(this.getDefaultOptions(), options);
        this.env = env;
      }

      getDefaultOptions() {
        return {};
      }

      extractVideoID(reference) {
        return reference;
      }

      getVideoUrl(_videoID) {
        throw new Error("not implemented");
      }

      getFilteredVideoUrl(videoID) {
        let filterUrlDelegate = typeof this.env.options.filterUrl === "function"
            ? this.env.options.filterUrl
            : defaultUrlFilter;
        let videoUrl = this.getVideoUrl(videoID);
        return filterUrlDelegate(videoUrl, this.name, videoID, this.env.options);
      }

      getEmbedCode(videoID) {
        let containerClassNames = [];
        if (this.env.options.containerClassName && this.options.ignoreStyle !== true) {
          containerClassNames.push(this.env.options.containerClassName);
        }

        let escapedServiceName = this.env.md.utils.escapeHtml(this.name);
        containerClassNames.push(this.env.options.serviceClassPrefix + escapedServiceName);

        let containerStyles = [];
        if (this.options.ignoreStyle !== true) {
          containerStyles.push(["position: relative;"]);
          Eif (this.options.height !== undefined && this.options.width !== undefined) {
            containerStyles.push(`padding-bottom: ${this.options.height / this.options.width * 100}%`);
          }
        }

        let iframeAttributeList = [];
        iframeAttributeList.push([ "type", "text/html" ]);
        iframeAttributeList.push([ "src", this.getFilteredVideoUrl(videoID) ]);
        iframeAttributeList.push([ "frameborder", 0 ]);

        if (this.env.options.outputPlayerSize === true && this.options.ignoreStyle === true) {
          Eif (this.options.width !== undefined && this.options.width !== null) {
            iframeAttributeList.push([ "width", this.options.width ]);
          }
          Eif (this.options.height !== undefined && this.options.height !== null) {
            iframeAttributeList.push([ "height", this.options.height ]);
          }
        }

        Eif (this.env.options.allowFullScreen === true) {
          iframeAttributeList.push([ "webkitallowfullscreen" ]);
          iframeAttributeList.push([ "mozallowfullscreen" ]);
          iframeAttributeList.push([ "allowfullscreen" ]);
        }

        let iframeAttributes = iframeAttributeList
          .map(pair =>
            pair[1] !== undefined
                ? `${pair[0]}="${pair[1]}"`
                : pair[0]
          )
          .join(" ");

        return `<div class="${containerClassNames.join(" ")}" style="${containerStyles.join(" ")}">`
               + `<iframe ${iframeAttributes}></iframe>`
             + `</div>\n`;
      }

    }

    module.exports = VideoServiceBase;