embed_oembed_integration.html 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <script>
  2. function bx_oembed_process_links(el) {
  3. var alinksHref = [];
  4. var alinksEl = [];
  5. if (typeof el.tagName != 'undefined' && el.tagName == 'A') {
  6. alinksEl.push(el);
  7. alinksHref.push($(el).attr('href'));
  8. } else {
  9. $('a[bx-oembed-url]', el).each(function (i, a) {
  10. alinksEl.push(a);
  11. alinksHref.push($(a).attr('href'));
  12. });
  13. }
  14. if (alinksEl.length) {
  15. $.post(sUrlRoot + 'oembed.php', {l: alinksHref}, function (oResponse) {
  16. if (oResponse.length)
  17. for (i in oResponse) {
  18. if (oResponse[i].html.length) {
  19. $(alinksEl[i]).replaceWith(oResponse[i].html);
  20. } else {
  21. $(alinksEl[i]).removeAttr('bx-oembed-url');
  22. }
  23. }
  24. }, 'json');
  25. }
  26. }
  27. $(document).ready(function(){
  28. bx_oembed_process_links(this);
  29. if (typeof glOnProcessHtml === 'undefined')
  30. glOnProcessHtml = [];
  31. if (glOnProcessHtml instanceof Array) {
  32. glOnProcessHtml.push(bx_oembed_process_links);
  33. }
  34. });
  35. </script>