# all files / src/js/base/module/ VideoDialog.js

66.95% Statements 79/118
67.21% Branches 41/61
38.89% Functions 7/18
66.67% Lines 78/117

    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
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    2091×
    1×
    1×
    1×
    1×
    1×
    2×
    100×
    100×
    100×
    100×
    100×
    100×

    1×
    97×
    97×

    97×
    97×
    97×

    1×
    2×
    2×

    1×

    1×

    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    9×
    2×
    2×
    2×
    1×
    1×
    1×
    3×

    2×

    7×
    1×

    6×

    6×

    6×

    6×

    6×
    2×
    2×

    4×

    4×
    1×

    3×

    6×
    6×

    1×

    1×

    1×

    1×

     (function(global){global.wrappers['/Users/lqez/Dev/summernote/src/js/base/module/VideoDialog.js']=[function(require,module,exports,__dirname,__filename){ "use strict";
    exports.__esModule = true;
    var jquery_1 = require("jquery");
    var env_1 = require("../core/env");
    var key_1 = require("../core/key");
    var VideoDialog = /** @class */ (function () {
        function VideoDialog(context) {
            this.context = context;
            this.ui = jquery_1["default"].summernote.ui;
            this.$body = jquery_1["default"](document.body);
            this.$editor = context.layoutInfo.editor;
            this.options = context.options;
            this.lang = this.options.langInfo;
        }
        VideoDialog.prototype.initialize = function () {
            var $container = this.options.dialogsInBody ? this.$body : this.$editor;
            var body = [
                '<div class="form-group note-form-group row-fluid">',
                "<label class=\"note-form-label\">" + this.lang.video.url + " <small class=\"text-muted\">" + this.lang.video.providers + "</small></label>",
                '<input class="note-video-url form-control note-form-control note-input" type="text" />',
                '</div>',
            ].join('');
            var buttonClass = 'btn btn-primary note-btn note-btn-primary note-video-btn';
            var footer = "<input type=\"button\" href=\"#\" class=\"" + buttonClass + "\" value=\"" + this.lang.video.insert + "\" disabled>";
            this.$dialog = this.ui.dialog({
                title: this.lang.video.insert,
                fade: this.options.dialogsFade,
                body: body,
                footer: footer
            }).render().appendTo($container);
        };
        VideoDialog.prototype.destroy = function () {
            this.ui.hideDialog(this.$dialog);
            this.$dialog.remove();
        };
        VideoDialog.prototype.bindEnterKey = function ($input, $btn) {
            $input.on('keypress', function (event) {
                if (event.keyCode === key_1["default"].code.ENTER) {
                    event.preventDefault();
                    $btn.trigger('click');
                }
            });
        };
        VideoDialog.prototype.createVideoNode = function (url) {
            // video url patterns(youtube, instagram, vimeo, dailymotion, youku, mp4, ogg, webm)
            var ytRegExp = /\/\/(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w|-]{11})(?:(?:[\?&]t=)(\S+))?$/;
            var ytRegExpForStart = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/;
            var ytMatch = url.match(ytRegExp);
            var igRegExp = /(?:www\.|\/\/)instagram\.com\/p\/(.[a-zA-Z0-9_-]*)/;
            var igMatch = url.match(igRegExp);
            var vRegExp = /\/\/vine\.co\/v\/([a-zA-Z0-9]+)/;
            var vMatch = url.match(vRegExp);
            var vimRegExp = /\/\/(player\.)?vimeo\.com\/([a-z]*\/)*(\d+)[?]?.*/;
            var vimMatch = url.match(vimRegExp);
            var dmRegExp = /.+dailymotion.com\/(video|hub)\/([^_]+)[^#]*(#video=([^_&]+))?/;
            var dmMatch = url.match(dmRegExp);
            var youkuRegExp = /\/\/v\.youku\.com\/v_show\/id_(\w+)=*\.html/;
            var youkuMatch = url.match(youkuRegExp);
            var qqRegExp = /\/\/v\.qq\.com.*?vid=(.+)/;
            var qqMatch = url.match(qqRegExp);
            var qqRegExp2 = /\/\/v\.qq\.com\/x?\/?(page|cover).*?\/([^\/]+)\.html\??.*/;
            var qqMatch2 = url.match(qqRegExp2);
            var mp4RegExp = /^.+.(mp4|m4v)$/;
            var mp4Match = url.match(mp4RegExp);
            var oggRegExp = /^.+.(ogg|ogv)$/;
            var oggMatch = url.match(oggRegExp);
            var webmRegExp = /^.+.(webm)$/;
            var webmMatch = url.match(webmRegExp);
            var fbRegExp = /(?:www\.|\/\/)facebook\.com\/([^\/]+)\/videos\/([0-9]+)/;
            var fbMatch = url.match(fbRegExp);
            var $video;
            if (ytMatch && ytMatch[1].length === 11) {
                var youtubeId = ytMatch[1];
                var start = 0;
                if (typeof ytMatch[2] !== 'undefined') {
                    var ytMatchForStart = ytMatch[2].match(ytRegExpForStart);
                    Eif (ytMatchForStart) {
                        for (var n = [3600, 60, 1], i = 0, r = n.length; i < r; i++) {
                            start += (typeof ytMatchForStart[i + 1] !== 'undefined' ? n[i] * parseInt(ytMatchForStart[i + 1], 10) : 0);
                        }
                    }
                }
                $video = jquery_1["default"]('<iframe>')
                    .attr('frameborder', 0)
                    .attr('src', '//www.youtube.com/embed/' + youtubeId + (start > 0 ? '?start=' + start : ''))
                    .attr('width', '640').attr('height', '360');
            }
            else if (igMatch && igMatch[0].length) {
                $video = jquery_1["default"]('<iframe>')
                    .attr('frameborder', 0)
                    .attr('src', 'https://instagram.com/p/' + igMatch[1] + '/embed/')
                    .attr('width', '612').attr('height', '710')
                    .attr('scrolling', 'no')
                    .attr('allowtransparency', 'true');
            }
            else Iif (vMatch && vMatch[0].length) {
                $video = jquery_1["default"]('<iframe>')
                    .attr('frameborder', 0)
                    .attr('src', vMatch[0] + '/embed/simple')
                    .attr('width', '600').attr('height', '600')
                    .attr('class', 'vine-embed');
            }
            else Iif (vimMatch && vimMatch[3].length) {
                $video = jquery_1["default"]('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>')
                    .attr('frameborder', 0)
                    .attr('src', '//player.vimeo.com/video/' + vimMatch[3])
                    .attr('width', '640').attr('height', '360');
            }
            else Iif (dmMatch && dmMatch[2].length) {
                $video = jquery_1["default"]('<iframe>')
                    .attr('frameborder', 0)
                    .attr('src', '//www.dailymotion.com/embed/video/' + dmMatch[2])
                    .attr('width', '640').attr('height', '360');
            }
            else Iif (youkuMatch && youkuMatch[1].length) {
                $video = jquery_1["default"]('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>')
                    .attr('frameborder', 0)
                    .attr('height', '498')
                    .attr('width', '510')
                    .attr('src', '//player.youku.com/embed/' + youkuMatch[1]);
            }
            else if ((qqMatch && qqMatch[1].length) || (qqMatch2 && qqMatch2[2].length)) {
                var vid = ((qqMatch && qqMatch[1].length) ? qqMatch[1] : qqMatch2[2]);
                $video = jquery_1["default"]('<iframe webkitallowfullscreen mozallowfullscreen allowfullscreen>')
                    .attr('frameborder', 0)
                    .attr('height', '310')
                    .attr('width', '500')
                    .attr('src', 'http://v.qq.com/iframe/player.html?vid=' + vid + '&amp;auto=0');
            }
            else Iif (mp4Match || oggMatch || webmMatch) {
                $video = jquery_1["default"]('<video controls>')
                    .attr('src', url)
                    .attr('width', '640').attr('height', '360');
            }
            else if (fbMatch && fbMatch[0].length) {
                $video = jquery_1["default"]('<iframe>')
                    .attr('frameborder', 0)
                    .attr('src', 'https://www.facebook.com/plugins/video.php?href=' + encodeURIComponent(fbMatch[0]) + '&show_text=0&width=560')
                    .attr('width', '560').attr('height', '301')
                    .attr('scrolling', 'no')
                    .attr('allowtransparency', 'true');
            }
            else {
                // this is not a known video link. Now what, Cat? Now what?
                return false;
            }
            $video.addClass('note-video-clip');
            return $video[0];
        };
        VideoDialog.prototype.show = function () {
            var _this = this;
            var text = this.context.invoke('editor.getSelectedText');
            this.context.invoke('editor.saveRange');
            this.showVideoDialog(text).then(function (url) {
                // [workaround] hide dialog before restore range for IE range focus
                _this.ui.hideDialog(_this.$dialog);
                _this.context.invoke('editor.restoreRange');
                // build node
                var $node = _this.createVideoNode(url);
                if ($node) {
                    // insert video node
                    _this.context.invoke('editor.insertNode', $node);
                }
            }).fail(function () {
                _this.context.invoke('editor.restoreRange');
            });
        };
        /**
         * show image dialog
         *
         * @param {jQuery} $dialog
         * @return {Promise}
         */
        VideoDialog.prototype.showVideoDialog = function (text) {
            var _this = this;
            return jquery_1["default"].Deferred(function (deferred) {
                var $videoUrl = _this.$dialog.find('.note-video-url');
                var $videoBtn = _this.$dialog.find('.note-video-btn');
                _this.ui.onDialogShown(_this.$dialog, function () {
                    _this.context.triggerEvent('dialog.shown');
                    $videoUrl.val(text).on('input', function () {
                        _this.ui.toggleBtn($videoBtn, $videoUrl.val());
                    });
                    if (!env_1["default"].isSupportTouch) {
                        $videoUrl.trigger('focus');
                    }
                    $videoBtn.click(function (event) {
                        event.preventDefault();
                        deferred.resolve($videoUrl.val());
                    });
                    _this.bindEnterKey($videoUrl, $videoBtn);
                });
                _this.ui.onDialogHidden(_this.$dialog, function () {
                    $videoUrl.off('input');
                    $videoBtn.off('click');
                    if (deferred.state() === 'pending') {
                        deferred.reject();
                    }
                });
                _this.ui.showDialog(_this.$dialog);
            });
        };
        return VideoDialog;
    }());
    exports["default"] = VideoDialog;

    },'src/js/base/module/VideoDialog.js',{"jquery":"/Users/lqez/Dev/summernote/node_modules/jquery/dist/jquery.js","../core/env":"/Users/lqez/Dev/summernote/src/js/base/core/env.js","../core/key":"/Users/lqez/Dev/summernote/src/js/base/core/key.js"}];})(this);
    //# sourceMappingURL=data:application/json;charset=utf-8;base64,