iframe.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* see Issue "autoresize" http://drupal.org/node/360549 */
  2. (function ($) {
  3. Drupal.behaviors.iframeModule = {
  4. attach: function(context, settings) {
  5. $('iframe.autoresize').each(function() {
  6. var offsetHeight = 20;
  7. var thisIframe = $(this);
  8. var iframeWaitInterval;
  9. function resizeHeight(iframe) {
  10. if ($(iframe).length) { /* Iframe yet loaded ? */
  11. var iframeDoc = $(iframe)[0].contentDocument || $(iframe)[0].contentWindow.document;
  12. var contentheight = 0;
  13. try {
  14. contentheight = $(iframeDoc).find('body').height();
  15. } catch (e) {
  16. elem = $(iframe)[0];
  17. msg = $('<p><small>(' + Drupal.t('Iframe URL is not from the same domain - autoresize not working.') + ')</small></p>');
  18. $(elem).after(msg);
  19. clearInterval(iframeWaitInterval);
  20. }
  21. if (contentheight > 0) {
  22. clearInterval(iframeWaitInterval);
  23. try {
  24. var frameElement = $(iframe)[0].frameElement || $(iframe)[0];
  25. frameElement.style.height = (contentheight + offsetHeight) + 'px';
  26. frameElement.scrolling = 'no';
  27. } catch (e) {
  28. /* here, ist not an correctable error */
  29. }
  30. }
  31. }
  32. }
  33. var delayedResize = function() {
  34. resizeHeight(thisIframe);
  35. }
  36. iframeWaitInterval = setInterval(delayedResize, 300);
  37. //setTimeout(delayedResize, 300);
  38. //resizeHeight(thisIframe);
  39. });
  40. }
  41. }
  42. })(jQuery);