[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/media/vendor/tinymce/plugins/media/ -> plugin.js (source)

   1  /**
   2   * Copyright (c) Tiny Technologies, Inc. All rights reserved.
   3   * Licensed under the LGPL or a commercial license.
   4   * For LGPL see License.txt in the project root for license information.
   5   * For commercial licenses see https://www.tiny.cloud/
   6   *
   7   * Version: 5.10.5 (2022-05-25)
   8   */
   9  (function () {
  10      'use strict';
  11  
  12      var global$9 = tinymce.util.Tools.resolve('tinymce.PluginManager');
  13  
  14      var __assign = function () {
  15        __assign = Object.assign || function __assign(t) {
  16          for (var s, i = 1, n = arguments.length; i < n; i++) {
  17            s = arguments[i];
  18            for (var p in s)
  19              if (Object.prototype.hasOwnProperty.call(s, p))
  20                t[p] = s[p];
  21          }
  22          return t;
  23        };
  24        return __assign.apply(this, arguments);
  25      };
  26  
  27      var typeOf = function (x) {
  28        var t = typeof x;
  29        if (x === null) {
  30          return 'null';
  31        } else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
  32          return 'array';
  33        } else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
  34          return 'string';
  35        } else {
  36          return t;
  37        }
  38      };
  39      var isType = function (type) {
  40        return function (value) {
  41          return typeOf(value) === type;
  42        };
  43      };
  44      var isString = isType('string');
  45      var isObject = isType('object');
  46      var isArray = isType('array');
  47      var isNullable = function (a) {
  48        return a === null || a === undefined;
  49      };
  50      var isNonNullable = function (a) {
  51        return !isNullable(a);
  52      };
  53  
  54      var noop = function () {
  55      };
  56      var constant = function (value) {
  57        return function () {
  58          return value;
  59        };
  60      };
  61      var identity = function (x) {
  62        return x;
  63      };
  64      var never = constant(false);
  65      var always = constant(true);
  66  
  67      var none = function () {
  68        return NONE;
  69      };
  70      var NONE = function () {
  71        var call = function (thunk) {
  72          return thunk();
  73        };
  74        var id = identity;
  75        var me = {
  76          fold: function (n, _s) {
  77            return n();
  78          },
  79          isSome: never,
  80          isNone: always,
  81          getOr: id,
  82          getOrThunk: call,
  83          getOrDie: function (msg) {
  84            throw new Error(msg || 'error: getOrDie called on none.');
  85          },
  86          getOrNull: constant(null),
  87          getOrUndefined: constant(undefined),
  88          or: id,
  89          orThunk: call,
  90          map: none,
  91          each: noop,
  92          bind: none,
  93          exists: never,
  94          forall: always,
  95          filter: function () {
  96            return none();
  97          },
  98          toArray: function () {
  99            return [];
 100          },
 101          toString: constant('none()')
 102        };
 103        return me;
 104      }();
 105      var some = function (a) {
 106        var constant_a = constant(a);
 107        var self = function () {
 108          return me;
 109        };
 110        var bind = function (f) {
 111          return f(a);
 112        };
 113        var me = {
 114          fold: function (n, s) {
 115            return s(a);
 116          },
 117          isSome: always,
 118          isNone: never,
 119          getOr: constant_a,
 120          getOrThunk: constant_a,
 121          getOrDie: constant_a,
 122          getOrNull: constant_a,
 123          getOrUndefined: constant_a,
 124          or: self,
 125          orThunk: self,
 126          map: function (f) {
 127            return some(f(a));
 128          },
 129          each: function (f) {
 130            f(a);
 131          },
 132          bind: bind,
 133          exists: bind,
 134          forall: bind,
 135          filter: function (f) {
 136            return f(a) ? me : NONE;
 137          },
 138          toArray: function () {
 139            return [a];
 140          },
 141          toString: function () {
 142            return 'some(' + a + ')';
 143          }
 144        };
 145        return me;
 146      };
 147      var from = function (value) {
 148        return value === null || value === undefined ? NONE : some(value);
 149      };
 150      var Optional = {
 151        some: some,
 152        none: none,
 153        from: from
 154      };
 155  
 156      var nativePush = Array.prototype.push;
 157      var each$1 = function (xs, f) {
 158        for (var i = 0, len = xs.length; i < len; i++) {
 159          var x = xs[i];
 160          f(x, i);
 161        }
 162      };
 163      var flatten = function (xs) {
 164        var r = [];
 165        for (var i = 0, len = xs.length; i < len; ++i) {
 166          if (!isArray(xs[i])) {
 167            throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
 168          }
 169          nativePush.apply(r, xs[i]);
 170        }
 171        return r;
 172      };
 173  
 174      var Cell = function (initial) {
 175        var value = initial;
 176        var get = function () {
 177          return value;
 178        };
 179        var set = function (v) {
 180          value = v;
 181        };
 182        return {
 183          get: get,
 184          set: set
 185        };
 186      };
 187  
 188      var keys = Object.keys;
 189      var hasOwnProperty = Object.hasOwnProperty;
 190      var each = function (obj, f) {
 191        var props = keys(obj);
 192        for (var k = 0, len = props.length; k < len; k++) {
 193          var i = props[k];
 194          var x = obj[i];
 195          f(x, i);
 196        }
 197      };
 198      var get$1 = function (obj, key) {
 199        return has(obj, key) ? Optional.from(obj[key]) : Optional.none();
 200      };
 201      var has = function (obj, key) {
 202        return hasOwnProperty.call(obj, key);
 203      };
 204  
 205      var getScripts = function (editor) {
 206        return editor.getParam('media_scripts');
 207      };
 208      var getAudioTemplateCallback = function (editor) {
 209        return editor.getParam('audio_template_callback');
 210      };
 211      var getVideoTemplateCallback = function (editor) {
 212        return editor.getParam('video_template_callback');
 213      };
 214      var hasLiveEmbeds = function (editor) {
 215        return editor.getParam('media_live_embeds', true);
 216      };
 217      var shouldFilterHtml = function (editor) {
 218        return editor.getParam('media_filter_html', true);
 219      };
 220      var getUrlResolver = function (editor) {
 221        return editor.getParam('media_url_resolver');
 222      };
 223      var hasAltSource = function (editor) {
 224        return editor.getParam('media_alt_source', true);
 225      };
 226      var hasPoster = function (editor) {
 227        return editor.getParam('media_poster', true);
 228      };
 229      var hasDimensions = function (editor) {
 230        return editor.getParam('media_dimensions', true);
 231      };
 232  
 233      var global$8 = tinymce.util.Tools.resolve('tinymce.util.Tools');
 234  
 235      var global$7 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
 236  
 237      var global$6 = tinymce.util.Tools.resolve('tinymce.html.SaxParser');
 238  
 239      var getVideoScriptMatch = function (prefixes, src) {
 240        if (prefixes) {
 241          for (var i = 0; i < prefixes.length; i++) {
 242            if (src.indexOf(prefixes[i].filter) !== -1) {
 243              return prefixes[i];
 244            }
 245          }
 246        }
 247      };
 248  
 249      var DOM$1 = global$7.DOM;
 250      var trimPx = function (value) {
 251        return value.replace(/px$/, '');
 252      };
 253      var getEphoxEmbedData = function (attrs) {
 254        var style = attrs.map.style;
 255        var styles = style ? DOM$1.parseStyle(style) : {};
 256        return {
 257          type: 'ephox-embed-iri',
 258          source: attrs.map['data-ephox-embed-iri'],
 259          altsource: '',
 260          poster: '',
 261          width: get$1(styles, 'max-width').map(trimPx).getOr(''),
 262          height: get$1(styles, 'max-height').map(trimPx).getOr('')
 263        };
 264      };
 265      var htmlToData = function (prefixes, html) {
 266        var isEphoxEmbed = Cell(false);
 267        var data = {};
 268        global$6({
 269          validate: false,
 270          allow_conditional_comments: true,
 271          start: function (name, attrs) {
 272            if (isEphoxEmbed.get()) ; else if (has(attrs.map, 'data-ephox-embed-iri')) {
 273              isEphoxEmbed.set(true);
 274              data = getEphoxEmbedData(attrs);
 275            } else {
 276              if (!data.source && name === 'param') {
 277                data.source = attrs.map.movie;
 278              }
 279              if (name === 'iframe' || name === 'object' || name === 'embed' || name === 'video' || name === 'audio') {
 280                if (!data.type) {
 281                  data.type = name;
 282                }
 283                data = global$8.extend(attrs.map, data);
 284              }
 285              if (name === 'script') {
 286                var videoScript = getVideoScriptMatch(prefixes, attrs.map.src);
 287                if (!videoScript) {
 288                  return;
 289                }
 290                data = {
 291                  type: 'script',
 292                  source: attrs.map.src,
 293                  width: String(videoScript.width),
 294                  height: String(videoScript.height)
 295                };
 296              }
 297              if (name === 'source') {
 298                if (!data.source) {
 299                  data.source = attrs.map.src;
 300                } else if (!data.altsource) {
 301                  data.altsource = attrs.map.src;
 302                }
 303              }
 304              if (name === 'img' && !data.poster) {
 305                data.poster = attrs.map.src;
 306              }
 307            }
 308          }
 309        }).parse(html);
 310        data.source = data.source || data.src || data.data;
 311        data.altsource = data.altsource || '';
 312        data.poster = data.poster || '';
 313        return data;
 314      };
 315  
 316      var guess = function (url) {
 317        var mimes = {
 318          mp3: 'audio/mpeg',
 319          m4a: 'audio/x-m4a',
 320          wav: 'audio/wav',
 321          mp4: 'video/mp4',
 322          webm: 'video/webm',
 323          ogg: 'video/ogg',
 324          swf: 'application/x-shockwave-flash'
 325        };
 326        var fileEnd = url.toLowerCase().split('.').pop();
 327        var mime = mimes[fileEnd];
 328        return mime ? mime : '';
 329      };
 330  
 331      var global$5 = tinymce.util.Tools.resolve('tinymce.html.Schema');
 332  
 333      var global$4 = tinymce.util.Tools.resolve('tinymce.html.Writer');
 334  
 335      var DOM = global$7.DOM;
 336      var addPx = function (value) {
 337        return /^[0-9.]+$/.test(value) ? value + 'px' : value;
 338      };
 339      var setAttributes = function (attrs, updatedAttrs) {
 340        each(updatedAttrs, function (val, name) {
 341          var value = '' + val;
 342          if (attrs.map[name]) {
 343            var i = attrs.length;
 344            while (i--) {
 345              var attr = attrs[i];
 346              if (attr.name === name) {
 347                if (value) {
 348                  attrs.map[name] = value;
 349                  attr.value = value;
 350                } else {
 351                  delete attrs.map[name];
 352                  attrs.splice(i, 1);
 353                }
 354              }
 355            }
 356          } else if (value) {
 357            attrs.push({
 358              name: name,
 359              value: value
 360            });
 361            attrs.map[name] = value;
 362          }
 363        });
 364      };
 365      var updateEphoxEmbed = function (data, attrs) {
 366        var style = attrs.map.style;
 367        var styleMap = style ? DOM.parseStyle(style) : {};
 368        styleMap['max-width'] = addPx(data.width);
 369        styleMap['max-height'] = addPx(data.height);
 370        setAttributes(attrs, { style: DOM.serializeStyle(styleMap) });
 371      };
 372      var sources = [
 373        'source',
 374        'altsource'
 375      ];
 376      var updateHtml = function (html, data, updateAll) {
 377        var writer = global$4();
 378        var isEphoxEmbed = Cell(false);
 379        var sourceCount = 0;
 380        var hasImage;
 381        global$6({
 382          validate: false,
 383          allow_conditional_comments: true,
 384          comment: function (text) {
 385            writer.comment(text);
 386          },
 387          cdata: function (text) {
 388            writer.cdata(text);
 389          },
 390          text: function (text, raw) {
 391            writer.text(text, raw);
 392          },
 393          start: function (name, attrs, empty) {
 394            if (isEphoxEmbed.get()) ; else if (has(attrs.map, 'data-ephox-embed-iri')) {
 395              isEphoxEmbed.set(true);
 396              updateEphoxEmbed(data, attrs);
 397            } else {
 398              switch (name) {
 399              case 'video':
 400              case 'object':
 401              case 'embed':
 402              case 'img':
 403              case 'iframe':
 404                if (data.height !== undefined && data.width !== undefined) {
 405                  setAttributes(attrs, {
 406                    width: data.width,
 407                    height: data.height
 408                  });
 409                }
 410                break;
 411              }
 412              if (updateAll) {
 413                switch (name) {
 414                case 'video':
 415                  setAttributes(attrs, {
 416                    poster: data.poster,
 417                    src: ''
 418                  });
 419                  if (data.altsource) {
 420                    setAttributes(attrs, { src: '' });
 421                  }
 422                  break;
 423                case 'iframe':
 424                  setAttributes(attrs, { src: data.source });
 425                  break;
 426                case 'source':
 427                  if (sourceCount < 2) {
 428                    setAttributes(attrs, {
 429                      src: data[sources[sourceCount]],
 430                      type: data[sources[sourceCount] + 'mime']
 431                    });
 432                    if (!data[sources[sourceCount]]) {
 433                      return;
 434                    }
 435                  }
 436                  sourceCount++;
 437                  break;
 438                case 'img':
 439                  if (!data.poster) {
 440                    return;
 441                  }
 442                  hasImage = true;
 443                  break;
 444                }
 445              }
 446            }
 447            writer.start(name, attrs, empty);
 448          },
 449          end: function (name) {
 450            if (!isEphoxEmbed.get()) {
 451              if (name === 'video' && updateAll) {
 452                for (var index = 0; index < 2; index++) {
 453                  if (data[sources[index]]) {
 454                    var attrs = [];
 455                    attrs.map = {};
 456                    if (sourceCount <= index) {
 457                      setAttributes(attrs, {
 458                        src: data[sources[index]],
 459                        type: data[sources[index] + 'mime']
 460                      });
 461                      writer.start('source', attrs, true);
 462                    }
 463                  }
 464                }
 465              }
 466              if (data.poster && name === 'object' && updateAll && !hasImage) {
 467                var imgAttrs = [];
 468                imgAttrs.map = {};
 469                setAttributes(imgAttrs, {
 470                  src: data.poster,
 471                  width: data.width,
 472                  height: data.height
 473                });
 474                writer.start('img', imgAttrs, true);
 475              }
 476            }
 477            writer.end(name);
 478          }
 479        }, global$5({})).parse(html);
 480        return writer.getContent();
 481      };
 482  
 483      var urlPatterns = [
 484        {
 485          regex: /youtu\.be\/([\w\-_\?&=.]+)/i,
 486          type: 'iframe',
 487          w: 560,
 488          h: 314,
 489          url: 'www.youtube.com/embed/$1',
 490          allowFullscreen: true
 491        },
 492        {
 493          regex: /youtube\.com(.+)v=([^&]+)(&([a-z0-9&=\-_]+))?/i,
 494          type: 'iframe',
 495          w: 560,
 496          h: 314,
 497          url: 'www.youtube.com/embed/$2?$4',
 498          allowFullscreen: true
 499        },
 500        {
 501          regex: /youtube.com\/embed\/([a-z0-9\?&=\-_]+)/i,
 502          type: 'iframe',
 503          w: 560,
 504          h: 314,
 505          url: 'www.youtube.com/embed/$1',
 506          allowFullscreen: true
 507        },
 508        {
 509          regex: /vimeo\.com\/([0-9]+)/,
 510          type: 'iframe',
 511          w: 425,
 512          h: 350,
 513          url: 'player.vimeo.com/video/$1?title=0&byline=0&portrait=0&color=8dc7dc',
 514          allowFullscreen: true
 515        },
 516        {
 517          regex: /vimeo\.com\/(.*)\/([0-9]+)/,
 518          type: 'iframe',
 519          w: 425,
 520          h: 350,
 521          url: 'player.vimeo.com/video/$2?title=0&amp;byline=0',
 522          allowFullscreen: true
 523        },
 524        {
 525          regex: /maps\.google\.([a-z]{2,3})\/maps\/(.+)msid=(.+)/,
 526          type: 'iframe',
 527          w: 425,
 528          h: 350,
 529          url: 'maps.google.com/maps/ms?msid=$2&output=embed"',
 530          allowFullscreen: false
 531        },
 532        {
 533          regex: /dailymotion\.com\/video\/([^_]+)/,
 534          type: 'iframe',
 535          w: 480,
 536          h: 270,
 537          url: 'www.dailymotion.com/embed/video/$1',
 538          allowFullscreen: true
 539        },
 540        {
 541          regex: /dai\.ly\/([^_]+)/,
 542          type: 'iframe',
 543          w: 480,
 544          h: 270,
 545          url: 'www.dailymotion.com/embed/video/$1',
 546          allowFullscreen: true
 547        }
 548      ];
 549      var getProtocol = function (url) {
 550        var protocolMatches = url.match(/^(https?:\/\/|www\.)(.+)$/i);
 551        if (protocolMatches && protocolMatches.length > 1) {
 552          return protocolMatches[1] === 'www.' ? 'https://' : protocolMatches[1];
 553        } else {
 554          return 'https://';
 555        }
 556      };
 557      var getUrl = function (pattern, url) {
 558        var protocol = getProtocol(url);
 559        var match = pattern.regex.exec(url);
 560        var newUrl = protocol + pattern.url;
 561        var _loop_1 = function (i) {
 562          newUrl = newUrl.replace('$' + i, function () {
 563            return match[i] ? match[i] : '';
 564          });
 565        };
 566        for (var i = 0; i < match.length; i++) {
 567          _loop_1(i);
 568        }
 569        return newUrl.replace(/\?$/, '');
 570      };
 571      var matchPattern = function (url) {
 572        var patterns = urlPatterns.filter(function (pattern) {
 573          return pattern.regex.test(url);
 574        });
 575        if (patterns.length > 0) {
 576          return global$8.extend({}, patterns[0], { url: getUrl(patterns[0], url) });
 577        } else {
 578          return null;
 579        }
 580      };
 581  
 582      var getIframeHtml = function (data) {
 583        var allowFullscreen = data.allowfullscreen ? ' allowFullscreen="1"' : '';
 584        return '<iframe src="' + data.source + '" width="' + data.width + '" height="' + data.height + '"' + allowFullscreen + '></iframe>';
 585      };
 586      var getFlashHtml = function (data) {
 587        var html = '<object data="' + data.source + '" width="' + data.width + '" height="' + data.height + '" type="application/x-shockwave-flash">';
 588        if (data.poster) {
 589          html += '<img src="' + data.poster + '" width="' + data.width + '" height="' + data.height + '" />';
 590        }
 591        html += '</object>';
 592        return html;
 593      };
 594      var getAudioHtml = function (data, audioTemplateCallback) {
 595        if (audioTemplateCallback) {
 596          return audioTemplateCallback(data);
 597        } else {
 598          return '<audio controls="controls" src="' + data.source + '">' + (data.altsource ? '\n<source src="' + data.altsource + '"' + (data.altsourcemime ? ' type="' + data.altsourcemime + '"' : '') + ' />\n' : '') + '</audio>';
 599        }
 600      };
 601      var getVideoHtml = function (data, videoTemplateCallback) {
 602        if (videoTemplateCallback) {
 603          return videoTemplateCallback(data);
 604        } else {
 605          return '<video width="' + data.width + '" height="' + data.height + '"' + (data.poster ? ' poster="' + data.poster + '"' : '') + ' controls="controls">\n' + '<source src="' + data.source + '"' + (data.sourcemime ? ' type="' + data.sourcemime + '"' : '') + ' />\n' + (data.altsource ? '<source src="' + data.altsource + '"' + (data.altsourcemime ? ' type="' + data.altsourcemime + '"' : '') + ' />\n' : '') + '</video>';
 606        }
 607      };
 608      var getScriptHtml = function (data) {
 609        return '<script src="' + data.source + '"></script>';
 610      };
 611      var dataToHtml = function (editor, dataIn) {
 612        var data = global$8.extend({}, dataIn);
 613        if (!data.source) {
 614          global$8.extend(data, htmlToData(getScripts(editor), data.embed));
 615          if (!data.source) {
 616            return '';
 617          }
 618        }
 619        if (!data.altsource) {
 620          data.altsource = '';
 621        }
 622        if (!data.poster) {
 623          data.poster = '';
 624        }
 625        data.source = editor.convertURL(data.source, 'source');
 626        data.altsource = editor.convertURL(data.altsource, 'source');
 627        data.sourcemime = guess(data.source);
 628        data.altsourcemime = guess(data.altsource);
 629        data.poster = editor.convertURL(data.poster, 'poster');
 630        var pattern = matchPattern(data.source);
 631        if (pattern) {
 632          data.source = pattern.url;
 633          data.type = pattern.type;
 634          data.allowfullscreen = pattern.allowFullscreen;
 635          data.width = data.width || String(pattern.w);
 636          data.height = data.height || String(pattern.h);
 637        }
 638        if (data.embed) {
 639          return updateHtml(data.embed, data, true);
 640        } else {
 641          var videoScript = getVideoScriptMatch(getScripts(editor), data.source);
 642          if (videoScript) {
 643            data.type = 'script';
 644            data.width = String(videoScript.width);
 645            data.height = String(videoScript.height);
 646          }
 647          var audioTemplateCallback = getAudioTemplateCallback(editor);
 648          var videoTemplateCallback = getVideoTemplateCallback(editor);
 649          data.width = data.width || '300';
 650          data.height = data.height || '150';
 651          global$8.each(data, function (value, key) {
 652            data[key] = editor.dom.encode('' + value);
 653          });
 654          if (data.type === 'iframe') {
 655            return getIframeHtml(data);
 656          } else if (data.sourcemime === 'application/x-shockwave-flash') {
 657            return getFlashHtml(data);
 658          } else if (data.sourcemime.indexOf('audio') !== -1) {
 659            return getAudioHtml(data, audioTemplateCallback);
 660          } else if (data.type === 'script') {
 661            return getScriptHtml(data);
 662          } else {
 663            return getVideoHtml(data, videoTemplateCallback);
 664          }
 665        }
 666      };
 667  
 668      var isMediaElement = function (element) {
 669        return element.hasAttribute('data-mce-object') || element.hasAttribute('data-ephox-embed-iri');
 670      };
 671      var setup$2 = function (editor) {
 672        editor.on('click keyup touchend', function () {
 673          var selectedNode = editor.selection.getNode();
 674          if (selectedNode && editor.dom.hasClass(selectedNode, 'mce-preview-object')) {
 675            if (editor.dom.getAttrib(selectedNode, 'data-mce-selected')) {
 676              selectedNode.setAttribute('data-mce-selected', '2');
 677            }
 678          }
 679        });
 680        editor.on('ObjectSelected', function (e) {
 681          var objectType = e.target.getAttribute('data-mce-object');
 682          if (objectType === 'script') {
 683            e.preventDefault();
 684          }
 685        });
 686        editor.on('ObjectResized', function (e) {
 687          var target = e.target;
 688          if (target.getAttribute('data-mce-object')) {
 689            var html = target.getAttribute('data-mce-html');
 690            if (html) {
 691              html = unescape(html);
 692              target.setAttribute('data-mce-html', escape(updateHtml(html, {
 693                width: String(e.width),
 694                height: String(e.height)
 695              })));
 696            }
 697          }
 698        });
 699      };
 700  
 701      var global$3 = tinymce.util.Tools.resolve('tinymce.util.Promise');
 702  
 703      var cache = {};
 704      var embedPromise = function (data, dataToHtml, handler) {
 705        return new global$3(function (res, rej) {
 706          var wrappedResolve = function (response) {
 707            if (response.html) {
 708              cache[data.source] = response;
 709            }
 710            return res({
 711              url: data.source,
 712              html: response.html ? response.html : dataToHtml(data)
 713            });
 714          };
 715          if (cache[data.source]) {
 716            wrappedResolve(cache[data.source]);
 717          } else {
 718            handler({ url: data.source }, wrappedResolve, rej);
 719          }
 720        });
 721      };
 722      var defaultPromise = function (data, dataToHtml) {
 723        return global$3.resolve({
 724          html: dataToHtml(data),
 725          url: data.source
 726        });
 727      };
 728      var loadedData = function (editor) {
 729        return function (data) {
 730          return dataToHtml(editor, data);
 731        };
 732      };
 733      var getEmbedHtml = function (editor, data) {
 734        var embedHandler = getUrlResolver(editor);
 735        return embedHandler ? embedPromise(data, loadedData(editor), embedHandler) : defaultPromise(data, loadedData(editor));
 736      };
 737      var isCached = function (url) {
 738        return has(cache, url);
 739      };
 740  
 741      var extractMeta = function (sourceInput, data) {
 742        return get$1(data, sourceInput).bind(function (mainData) {
 743          return get$1(mainData, 'meta');
 744        });
 745      };
 746      var getValue = function (data, metaData, sourceInput) {
 747        return function (prop) {
 748          var _a;
 749          var getFromData = function () {
 750            return get$1(data, prop);
 751          };
 752          var getFromMetaData = function () {
 753            return get$1(metaData, prop);
 754          };
 755          var getNonEmptyValue = function (c) {
 756            return get$1(c, 'value').bind(function (v) {
 757              return v.length > 0 ? Optional.some(v) : Optional.none();
 758            });
 759          };
 760          var getFromValueFirst = function () {
 761            return getFromData().bind(function (child) {
 762              return isObject(child) ? getNonEmptyValue(child).orThunk(getFromMetaData) : getFromMetaData().orThunk(function () {
 763                return Optional.from(child);
 764              });
 765            });
 766          };
 767          var getFromMetaFirst = function () {
 768            return getFromMetaData().orThunk(function () {
 769              return getFromData().bind(function (child) {
 770                return isObject(child) ? getNonEmptyValue(child) : Optional.from(child);
 771              });
 772            });
 773          };
 774          return _a = {}, _a[prop] = (prop === sourceInput ? getFromValueFirst() : getFromMetaFirst()).getOr(''), _a;
 775        };
 776      };
 777      var getDimensions = function (data, metaData) {
 778        var dimensions = {};
 779        get$1(data, 'dimensions').each(function (dims) {
 780          each$1([
 781            'width',
 782            'height'
 783          ], function (prop) {
 784            get$1(metaData, prop).orThunk(function () {
 785              return get$1(dims, prop);
 786            }).each(function (value) {
 787              return dimensions[prop] = value;
 788            });
 789          });
 790        });
 791        return dimensions;
 792      };
 793      var unwrap = function (data, sourceInput) {
 794        var metaData = sourceInput ? extractMeta(sourceInput, data).getOr({}) : {};
 795        var get = getValue(data, metaData, sourceInput);
 796        return __assign(__assign(__assign(__assign(__assign({}, get('source')), get('altsource')), get('poster')), get('embed')), getDimensions(data, metaData));
 797      };
 798      var wrap = function (data) {
 799        var wrapped = __assign(__assign({}, data), {
 800          source: { value: get$1(data, 'source').getOr('') },
 801          altsource: { value: get$1(data, 'altsource').getOr('') },
 802          poster: { value: get$1(data, 'poster').getOr('') }
 803        });
 804        each$1([
 805          'width',
 806          'height'
 807        ], function (prop) {
 808          get$1(data, prop).each(function (value) {
 809            var dimensions = wrapped.dimensions || {};
 810            dimensions[prop] = value;
 811            wrapped.dimensions = dimensions;
 812          });
 813        });
 814        return wrapped;
 815      };
 816      var handleError = function (editor) {
 817        return function (error) {
 818          var errorMessage = error && error.msg ? 'Media embed handler error: ' + error.msg : 'Media embed handler threw unknown error.';
 819          editor.notificationManager.open({
 820            type: 'error',
 821            text: errorMessage
 822          });
 823        };
 824      };
 825      var snippetToData = function (editor, embedSnippet) {
 826        return htmlToData(getScripts(editor), embedSnippet);
 827      };
 828      var getEditorData = function (editor) {
 829        var element = editor.selection.getNode();
 830        var snippet = isMediaElement(element) ? editor.serializer.serialize(element, { selection: true }) : '';
 831        return __assign({ embed: snippet }, htmlToData(getScripts(editor), snippet));
 832      };
 833      var addEmbedHtml = function (api, editor) {
 834        return function (response) {
 835          if (isString(response.url) && response.url.trim().length > 0) {
 836            var html = response.html;
 837            var snippetData = snippetToData(editor, html);
 838            var nuData = __assign(__assign({}, snippetData), {
 839              source: response.url,
 840              embed: html
 841            });
 842            api.setData(wrap(nuData));
 843          }
 844        };
 845      };
 846      var selectPlaceholder = function (editor, beforeObjects) {
 847        var afterObjects = editor.dom.select('*[data-mce-object]');
 848        for (var i = 0; i < beforeObjects.length; i++) {
 849          for (var y = afterObjects.length - 1; y >= 0; y--) {
 850            if (beforeObjects[i] === afterObjects[y]) {
 851              afterObjects.splice(y, 1);
 852            }
 853          }
 854        }
 855        editor.selection.select(afterObjects[0]);
 856      };
 857      var handleInsert = function (editor, html) {
 858        var beforeObjects = editor.dom.select('*[data-mce-object]');
 859        editor.insertContent(html);
 860        selectPlaceholder(editor, beforeObjects);
 861        editor.nodeChanged();
 862      };
 863      var submitForm = function (prevData, newData, editor) {
 864        newData.embed = updateHtml(newData.embed, newData);
 865        if (newData.embed && (prevData.source === newData.source || isCached(newData.source))) {
 866          handleInsert(editor, newData.embed);
 867        } else {
 868          getEmbedHtml(editor, newData).then(function (response) {
 869            handleInsert(editor, response.html);
 870          }).catch(handleError(editor));
 871        }
 872      };
 873      var showDialog = function (editor) {
 874        var editorData = getEditorData(editor);
 875        var currentData = Cell(editorData);
 876        var initialData = wrap(editorData);
 877        var handleSource = function (prevData, api) {
 878          var serviceData = unwrap(api.getData(), 'source');
 879          if (prevData.source !== serviceData.source) {
 880            addEmbedHtml(win, editor)({
 881              url: serviceData.source,
 882              html: ''
 883            });
 884            getEmbedHtml(editor, serviceData).then(addEmbedHtml(win, editor)).catch(handleError(editor));
 885          }
 886        };
 887        var handleEmbed = function (api) {
 888          var data = unwrap(api.getData());
 889          var dataFromEmbed = snippetToData(editor, data.embed);
 890          api.setData(wrap(dataFromEmbed));
 891        };
 892        var handleUpdate = function (api, sourceInput) {
 893          var data = unwrap(api.getData(), sourceInput);
 894          var embed = dataToHtml(editor, data);
 895          api.setData(wrap(__assign(__assign({}, data), { embed: embed })));
 896        };
 897        var mediaInput = [{
 898            name: 'source',
 899            type: 'urlinput',
 900            filetype: 'media',
 901            label: 'Source'
 902          }];
 903        var sizeInput = !hasDimensions(editor) ? [] : [{
 904            type: 'sizeinput',
 905            name: 'dimensions',
 906            label: 'Constrain proportions',
 907            constrain: true
 908          }];
 909        var generalTab = {
 910          title: 'General',
 911          name: 'general',
 912          items: flatten([
 913            mediaInput,
 914            sizeInput
 915          ])
 916        };
 917        var embedTextarea = {
 918          type: 'textarea',
 919          name: 'embed',
 920          label: 'Paste your embed code below:'
 921        };
 922        var embedTab = {
 923          title: 'Embed',
 924          items: [embedTextarea]
 925        };
 926        var advancedFormItems = [];
 927        if (hasAltSource(editor)) {
 928          advancedFormItems.push({
 929            name: 'altsource',
 930            type: 'urlinput',
 931            filetype: 'media',
 932            label: 'Alternative source URL'
 933          });
 934        }
 935        if (hasPoster(editor)) {
 936          advancedFormItems.push({
 937            name: 'poster',
 938            type: 'urlinput',
 939            filetype: 'image',
 940            label: 'Media poster (Image URL)'
 941          });
 942        }
 943        var advancedTab = {
 944          title: 'Advanced',
 945          name: 'advanced',
 946          items: advancedFormItems
 947        };
 948        var tabs = [
 949          generalTab,
 950          embedTab
 951        ];
 952        if (advancedFormItems.length > 0) {
 953          tabs.push(advancedTab);
 954        }
 955        var body = {
 956          type: 'tabpanel',
 957          tabs: tabs
 958        };
 959        var win = editor.windowManager.open({
 960          title: 'Insert/Edit Media',
 961          size: 'normal',
 962          body: body,
 963          buttons: [
 964            {
 965              type: 'cancel',
 966              name: 'cancel',
 967              text: 'Cancel'
 968            },
 969            {
 970              type: 'submit',
 971              name: 'save',
 972              text: 'Save',
 973              primary: true
 974            }
 975          ],
 976          onSubmit: function (api) {
 977            var serviceData = unwrap(api.getData());
 978            submitForm(currentData.get(), serviceData, editor);
 979            api.close();
 980          },
 981          onChange: function (api, detail) {
 982            switch (detail.name) {
 983            case 'source':
 984              handleSource(currentData.get(), api);
 985              break;
 986            case 'embed':
 987              handleEmbed(api);
 988              break;
 989            case 'dimensions':
 990            case 'altsource':
 991            case 'poster':
 992              handleUpdate(api, detail.name);
 993              break;
 994            }
 995            currentData.set(unwrap(api.getData()));
 996          },
 997          initialData: initialData
 998        });
 999      };
1000  
1001      var get = function (editor) {
1002        var showDialog$1 = function () {
1003          showDialog(editor);
1004        };
1005        return { showDialog: showDialog$1 };
1006      };
1007  
1008      var register$1 = function (editor) {
1009        var showDialog$1 = function () {
1010          showDialog(editor);
1011        };
1012        editor.addCommand('mceMedia', showDialog$1);
1013      };
1014  
1015      var global$2 = tinymce.util.Tools.resolve('tinymce.html.Node');
1016  
1017      var global$1 = tinymce.util.Tools.resolve('tinymce.Env');
1018  
1019      var global = tinymce.util.Tools.resolve('tinymce.html.DomParser');
1020  
1021      var sanitize = function (editor, html) {
1022        if (shouldFilterHtml(editor) === false) {
1023          return html;
1024        }
1025        var writer = global$4();
1026        var blocked;
1027        global$6({
1028          validate: false,
1029          allow_conditional_comments: false,
1030          comment: function (text) {
1031            if (!blocked) {
1032              writer.comment(text);
1033            }
1034          },
1035          cdata: function (text) {
1036            if (!blocked) {
1037              writer.cdata(text);
1038            }
1039          },
1040          text: function (text, raw) {
1041            if (!blocked) {
1042              writer.text(text, raw);
1043            }
1044          },
1045          start: function (name, attrs, empty) {
1046            blocked = true;
1047            if (name === 'script' || name === 'noscript' || name === 'svg') {
1048              return;
1049            }
1050            for (var i = attrs.length - 1; i >= 0; i--) {
1051              var attrName = attrs[i].name;
1052              if (attrName.indexOf('on') === 0) {
1053                delete attrs.map[attrName];
1054                attrs.splice(i, 1);
1055              }
1056              if (attrName === 'style') {
1057                attrs[i].value = editor.dom.serializeStyle(editor.dom.parseStyle(attrs[i].value), name);
1058              }
1059            }
1060            writer.start(name, attrs, empty);
1061            blocked = false;
1062          },
1063          end: function (name) {
1064            if (blocked) {
1065              return;
1066            }
1067            writer.end(name);
1068          }
1069        }, global$5({})).parse(html);
1070        return writer.getContent();
1071      };
1072  
1073      var isLiveEmbedNode = function (node) {
1074        var name = node.name;
1075        return name === 'iframe' || name === 'video' || name === 'audio';
1076      };
1077      var getDimension = function (node, styles, dimension, defaultValue) {
1078        if (defaultValue === void 0) {
1079          defaultValue = null;
1080        }
1081        var value = node.attr(dimension);
1082        if (isNonNullable(value)) {
1083          return value;
1084        } else if (!has(styles, dimension)) {
1085          return defaultValue;
1086        } else {
1087          return null;
1088        }
1089      };
1090      var setDimensions = function (node, previewNode, styles) {
1091        var useDefaults = previewNode.name === 'img' || node.name === 'video';
1092        var defaultWidth = useDefaults ? '300' : null;
1093        var fallbackHeight = node.name === 'audio' ? '30' : '150';
1094        var defaultHeight = useDefaults ? fallbackHeight : null;
1095        previewNode.attr({
1096          width: getDimension(node, styles, 'width', defaultWidth),
1097          height: getDimension(node, styles, 'height', defaultHeight)
1098        });
1099      };
1100      var appendNodeContent = function (editor, nodeName, previewNode, html) {
1101        var newNode = global({
1102          forced_root_block: false,
1103          validate: false
1104        }, editor.schema).parse(html, { context: nodeName });
1105        while (newNode.firstChild) {
1106          previewNode.append(newNode.firstChild);
1107        }
1108      };
1109      var createPlaceholderNode = function (editor, node) {
1110        var name = node.name;
1111        var placeHolder = new global$2('img', 1);
1112        placeHolder.shortEnded = true;
1113        retainAttributesAndInnerHtml(editor, node, placeHolder);
1114        setDimensions(node, placeHolder, {});
1115        placeHolder.attr({
1116          'style': node.attr('style'),
1117          'src': global$1.transparentSrc,
1118          'data-mce-object': name,
1119          'class': 'mce-object mce-object-' + name
1120        });
1121        return placeHolder;
1122      };
1123      var createPreviewNode = function (editor, node) {
1124        var name = node.name;
1125        var previewWrapper = new global$2('span', 1);
1126        previewWrapper.attr({
1127          'contentEditable': 'false',
1128          'style': node.attr('style'),
1129          'data-mce-object': name,
1130          'class': 'mce-preview-object mce-object-' + name
1131        });
1132        retainAttributesAndInnerHtml(editor, node, previewWrapper);
1133        var styles = editor.dom.parseStyle(node.attr('style'));
1134        var previewNode = new global$2(name, 1);
1135        setDimensions(node, previewNode, styles);
1136        previewNode.attr({
1137          src: node.attr('src'),
1138          style: node.attr('style'),
1139          class: node.attr('class')
1140        });
1141        if (name === 'iframe') {
1142          previewNode.attr({
1143            allowfullscreen: node.attr('allowfullscreen'),
1144            frameborder: '0'
1145          });
1146        } else {
1147          var attrs = [
1148            'controls',
1149            'crossorigin',
1150            'currentTime',
1151            'loop',
1152            'muted',
1153            'poster',
1154            'preload'
1155          ];
1156          each$1(attrs, function (attrName) {
1157            previewNode.attr(attrName, node.attr(attrName));
1158          });
1159          var sanitizedHtml = previewWrapper.attr('data-mce-html');
1160          if (isNonNullable(sanitizedHtml)) {
1161            appendNodeContent(editor, name, previewNode, unescape(sanitizedHtml));
1162          }
1163        }
1164        var shimNode = new global$2('span', 1);
1165        shimNode.attr('class', 'mce-shim');
1166        previewWrapper.append(previewNode);
1167        previewWrapper.append(shimNode);
1168        return previewWrapper;
1169      };
1170      var retainAttributesAndInnerHtml = function (editor, sourceNode, targetNode) {
1171        var attribs = sourceNode.attributes;
1172        var ai = attribs.length;
1173        while (ai--) {
1174          var attrName = attribs[ai].name;
1175          var attrValue = attribs[ai].value;
1176          if (attrName !== 'width' && attrName !== 'height' && attrName !== 'style') {
1177            if (attrName === 'data' || attrName === 'src') {
1178              attrValue = editor.convertURL(attrValue, attrName);
1179            }
1180            targetNode.attr('data-mce-p-' + attrName, attrValue);
1181          }
1182        }
1183        var innerHtml = sourceNode.firstChild && sourceNode.firstChild.value;
1184        if (innerHtml) {
1185          targetNode.attr('data-mce-html', escape(sanitize(editor, innerHtml)));
1186          targetNode.firstChild = null;
1187        }
1188      };
1189      var isPageEmbedWrapper = function (node) {
1190        var nodeClass = node.attr('class');
1191        return nodeClass && /\btiny-pageembed\b/.test(nodeClass);
1192      };
1193      var isWithinEmbedWrapper = function (node) {
1194        while (node = node.parent) {
1195          if (node.attr('data-ephox-embed-iri') || isPageEmbedWrapper(node)) {
1196            return true;
1197          }
1198        }
1199        return false;
1200      };
1201      var placeHolderConverter = function (editor) {
1202        return function (nodes) {
1203          var i = nodes.length;
1204          var node;
1205          var videoScript;
1206          while (i--) {
1207            node = nodes[i];
1208            if (!node.parent) {
1209              continue;
1210            }
1211            if (node.parent.attr('data-mce-object')) {
1212              continue;
1213            }
1214            if (node.name === 'script') {
1215              videoScript = getVideoScriptMatch(getScripts(editor), node.attr('src'));
1216              if (!videoScript) {
1217                continue;
1218              }
1219            }
1220            if (videoScript) {
1221              if (videoScript.width) {
1222                node.attr('width', videoScript.width.toString());
1223              }
1224              if (videoScript.height) {
1225                node.attr('height', videoScript.height.toString());
1226              }
1227            }
1228            if (isLiveEmbedNode(node) && hasLiveEmbeds(editor) && global$1.ceFalse) {
1229              if (!isWithinEmbedWrapper(node)) {
1230                node.replace(createPreviewNode(editor, node));
1231              }
1232            } else {
1233              if (!isWithinEmbedWrapper(node)) {
1234                node.replace(createPlaceholderNode(editor, node));
1235              }
1236            }
1237          }
1238        };
1239      };
1240  
1241      var setup$1 = function (editor) {
1242        editor.on('preInit', function () {
1243          var specialElements = editor.schema.getSpecialElements();
1244          global$8.each('video audio iframe object'.split(' '), function (name) {
1245            specialElements[name] = new RegExp('</' + name + '[^>]*>', 'gi');
1246          });
1247          var boolAttrs = editor.schema.getBoolAttrs();
1248          global$8.each('webkitallowfullscreen mozallowfullscreen allowfullscreen'.split(' '), function (name) {
1249            boolAttrs[name] = {};
1250          });
1251          editor.parser.addNodeFilter('iframe,video,audio,object,embed,script', placeHolderConverter(editor));
1252          editor.serializer.addAttributeFilter('data-mce-object', function (nodes, name) {
1253            var i = nodes.length;
1254            var node;
1255            var realElm;
1256            var ai;
1257            var attribs;
1258            var innerHtml;
1259            var innerNode;
1260            var realElmName;
1261            var className;
1262            while (i--) {
1263              node = nodes[i];
1264              if (!node.parent) {
1265                continue;
1266              }
1267              realElmName = node.attr(name);
1268              realElm = new global$2(realElmName, 1);
1269              if (realElmName !== 'audio' && realElmName !== 'script') {
1270                className = node.attr('class');
1271                if (className && className.indexOf('mce-preview-object') !== -1) {
1272                  realElm.attr({
1273                    width: node.firstChild.attr('width'),
1274                    height: node.firstChild.attr('height')
1275                  });
1276                } else {
1277                  realElm.attr({
1278                    width: node.attr('width'),
1279                    height: node.attr('height')
1280                  });
1281                }
1282              }
1283              realElm.attr({ style: node.attr('style') });
1284              attribs = node.attributes;
1285              ai = attribs.length;
1286              while (ai--) {
1287                var attrName = attribs[ai].name;
1288                if (attrName.indexOf('data-mce-p-') === 0) {
1289                  realElm.attr(attrName.substr(11), attribs[ai].value);
1290                }
1291              }
1292              if (realElmName === 'script') {
1293                realElm.attr('type', 'text/javascript');
1294              }
1295              innerHtml = node.attr('data-mce-html');
1296              if (innerHtml) {
1297                innerNode = new global$2('#text', 3);
1298                innerNode.raw = true;
1299                innerNode.value = sanitize(editor, unescape(innerHtml));
1300                realElm.append(innerNode);
1301              }
1302              node.replace(realElm);
1303            }
1304          });
1305        });
1306        editor.on('SetContent', function () {
1307          editor.$('span.mce-preview-object').each(function (index, elm) {
1308            var $elm = editor.$(elm);
1309            if ($elm.find('span.mce-shim').length === 0) {
1310              $elm.append('<span class="mce-shim"></span>');
1311            }
1312          });
1313        });
1314      };
1315  
1316      var setup = function (editor) {
1317        editor.on('ResolveName', function (e) {
1318          var name;
1319          if (e.target.nodeType === 1 && (name = e.target.getAttribute('data-mce-object'))) {
1320            e.name = name;
1321          }
1322        });
1323      };
1324  
1325      var register = function (editor) {
1326        var onAction = function () {
1327          return editor.execCommand('mceMedia');
1328        };
1329        editor.ui.registry.addToggleButton('media', {
1330          tooltip: 'Insert/edit media',
1331          icon: 'embed',
1332          onAction: onAction,
1333          onSetup: function (buttonApi) {
1334            var selection = editor.selection;
1335            buttonApi.setActive(isMediaElement(selection.getNode()));
1336            return selection.selectorChangedWithUnbind('img[data-mce-object],span[data-mce-object],div[data-ephox-embed-iri]', buttonApi.setActive).unbind;
1337          }
1338        });
1339        editor.ui.registry.addMenuItem('media', {
1340          icon: 'embed',
1341          text: 'Media...',
1342          onAction: onAction
1343        });
1344      };
1345  
1346      function Plugin () {
1347        global$9.add('media', function (editor) {
1348          register$1(editor);
1349          register(editor);
1350          setup(editor);
1351          setup$1(editor);
1352          setup$2(editor);
1353          return get(editor);
1354        });
1355      }
1356  
1357      Plugin();
1358  
1359  }());


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer