Oembed all jQuery

Oembed all jQuery

by onigetoc

HTML

<script src="https://rawgit.com/nfl/jquery-oembed-all/master/jquery.oembed.js"></script>
<link rel="stylesheet" href="https://rawgit.com/nfl/jquery-oembed-all/master/jquery.oembed.css">
<textarea id="info" style="width:80%; margin-right:auto; margin-left: auto; height:200px;">
  https://www.youtube.com/watch?v=XpsDr1qePxA</textarea>
<hr/>
<div id="out"></div>

JavaScript

$(document).ready(function() {

   $('#info').keyup(function() {
     tagdata = [];
     eventdata = [];
     var scriptruns = [];
     var text = $('#info').val();
     text = $('<span>' + text + '</span>').text(); //strip html
     text = text.replace(/(\s|>|^)(https?:[^\s<]*)/igm, '$1<div><a href="$2" class="oembed">$2</a></div>');
     text = text.replace(/(\s|>|^)(mailto:[^\s<]*)/igm, '$1<div><a href="$2" class="oembed">$2</a></div>');


     $('#out').empty().html(text);

     $(".oembed").oembed(null, {
       apikeys: {
         //etsy : 'd0jq4lmfi5bjbrxq2etulmjr',
         amazon: 'caterwall-20',
         //eventbrite: 'SKOFRBQRGNQW5VAS6P',
       },
       //maxHeight: 200, maxWidth:300
     });

   });

 });