|
337 | 337 | return; |
338 | 338 | } |
339 | 339 |
|
340 | | - if (html && html.indexOf('</script>') > -1) { |
341 | | - // Store embed code with <script> tag inside wrapper attribute value. |
342 | | - // Make nice attribute value escaping using jQuery. |
343 | | - var $div = $('<div>') |
344 | | - .attr('data-embed-code', html) |
345 | | - .html(html); |
346 | | - html = $('<div>').append($div).html(); |
347 | | - } |
348 | | - |
349 | 340 | if (pasted) { |
350 | 341 | $.proxy(that, 'embed', html, url)(); |
351 | 342 | } |
|
382 | 373 | Embeds.prototype.parseUrl = function (url, pasted) { |
383 | 374 | var html; |
384 | 375 |
|
385 | | - if (!(new RegExp(['youtube', 'youtu.be', 'vimeo', 'instagram'].join('|')).test(url))) { |
| 376 | + if (!(new RegExp(['youtube', 'youtu.be', 'vimeo', 'instagram', 'twitter', 'facebook'].join('|')).test(url))) { |
386 | 377 | $.proxy(this, 'convertBadEmbed', url)(); |
387 | 378 | return false; |
388 | 379 | } |
389 | 380 |
|
390 | 381 | html = url.replace(/\n?/g, '') |
391 | 382 | .replace(/^((http(s)?:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/(watch\?v=|v\/)?)([a-zA-Z0-9\-_]+)(.*)?$/, '<div class="video video-youtube"><iframe width="420" height="315" src="//www.youtube.com/embed/$7" frameborder="0" allowfullscreen></iframe></div>') |
392 | 383 | .replace(/^https?:\/\/vimeo\.com(\/.+)?\/([0-9]+)$/, '<div class="video video-vimeo"><iframe src="//player.vimeo.com/video/$2" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe></div>') |
393 | | - //.replace(/^https:\/\/twitter\.com\/(\w+)\/status\/(\d+)\/?$/, '<blockquote class="twitter-tweet" align="center" lang="en"><a href="https://twitter.com/$1/statuses/$2"></a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>') |
394 | | - //.replace(/^https:\/\/www\.facebook\.com\/(video.php|photo.php)\?v=(\d+).+$/, '<div class="fb-post" data-href="https://www.facebook.com/photo.php?v=$2"><div class="fb-xfbml-parse-ignore"><a href="https://www.facebook.com/photo.php?v=$2">Post</a></div></div>') |
| 384 | + .replace(/^https:\/\/twitter\.com\/(\w+)\/status\/(\d+)\/?$/, '<blockquote class="twitter-tweet" align="center" lang="en"><a href="https://twitter.com/$1/statuses/$2"></a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>') |
| 385 | + .replace(/^(https:\/\/www\.facebook\.com\/(.*))$/, '<script src="//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.2" async></script><div class="fb-post" data-href="$1"><div class="fb-xfbml-parse-ignore"><a href="$1">Loading Facebook post...</a></div></div>') |
395 | 386 | .replace(/^https?:\/\/instagram\.com\/p\/(.+)\/?$/, '<span class="instagram"><iframe src="//instagram.com/p/$1/embed/" width="612" height="710" frameborder="0" scrolling="no" allowtransparency="true"></iframe></span>'); |
396 | 387 |
|
| 388 | + if ((/<("[^"]*"|'[^']*'|[^'">])*>/).test(html) === false) { |
| 389 | + $.proxy(this, 'convertBadEmbed', url)(); |
| 390 | + return false; |
| 391 | + } |
| 392 | + |
397 | 393 | if (pasted) { |
398 | | - this.embed((/<("[^"]*"|'[^']*'|[^'">])*>/).test(html) ? html : false, url); |
| 394 | + this.embed(html, url); |
399 | 395 | } |
400 | 396 | else { |
401 | | - this.embed((/<("[^"]*"|'[^']*'|[^'">])*>/).test(html) ? html : false); |
| 397 | + this.embed(html); |
402 | 398 | } |
403 | 399 | }; |
404 | 400 |
|
|
417 | 413 | alert('Incorrect URL format specified'); |
418 | 414 | return false; |
419 | 415 | } else { |
| 416 | + if (html.indexOf('</script>') > -1) { |
| 417 | + // Store embed code with <script> tag inside wrapper attribute value. |
| 418 | + // Make nice attribute value escaping using jQuery. |
| 419 | + var $div = $('<div>') |
| 420 | + .attr('data-embed-code', html) |
| 421 | + .html(html); |
| 422 | + html = $('<div>').append($div).html(); |
| 423 | + } |
| 424 | + |
420 | 425 | if (pastedUrl) { |
421 | 426 | // Get the element with the pasted url |
422 | 427 | // place the embed template and remove the pasted text |
|
477 | 482 |
|
478 | 483 | this.core.triggerInput(); |
479 | 484 |
|
480 | | - this.core.moveCaret($place); |
| 485 | + this.core.moveCaret($empty); |
481 | 486 | }; |
482 | 487 |
|
483 | 488 | /** |
|
0 commit comments