/www/static/javascript/newsletter.js

https://bitbucket.org/toni/pywbe · JavaScript · 42 lines · 25 code · 5 blank · 12 comment · 3 complexity · 561032d64dc38c30f2555e1194a4eac2 MD5 · raw file

  1. /**
  2. * DHTML for newsletter preview
  3. * (c) 2009 and onwards, infoarena
  4. */
  5. // Resize iframe element height to frame document height. This
  6. // should make the iframe vertical scrollbar disappear.
  7. function Newsletter_ResizePreviewFrame() {
  8. var iframe = window.frameElement;
  9. if (iframe) {
  10. var new_height = document.body.scrollHeight + 10;
  11. iframe.style.height = new_height + 'px';
  12. }
  13. }
  14. function Newsletter_Init() {
  15. if (!window.frameElement) {
  16. /* Only trigger inside the iframe. */
  17. return;
  18. }
  19. Newsletter_ResizePreviewFrame();
  20. Newsletter_HijackLinks();
  21. }
  22. // Hijack all anchor clicks to Newsletter_LinkClick.
  23. // This only applies inside the iframe.
  24. function Newsletter_HijackLinks() {
  25. map(function(anchor) { anchor.onclick=Newsletter_LinkClick; },
  26. MochiKit.DOM.getElementsByTagAndClassName('a'));
  27. }
  28. // Click handler for links inside the iframe.
  29. // Instead of navigating inside the iframe, we change the location
  30. // of the parent window.
  31. function Newsletter_LinkClick(event) {
  32. if (window.frameElement) {
  33. window.parent.location = this.href;
  34. }
  35. return false;
  36. }
  37. connect(window, 'onload', Newsletter_Init);