/www/static/javascript/newsletter.js
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
6// Resize iframe element height to frame document height. This
7// should make the iframe vertical scrollbar disappear.
8function Newsletter_ResizePreviewFrame() {
9 var iframe = window.frameElement;
10 if (iframe) {
11 var new_height = document.body.scrollHeight + 10;
12 iframe.style.height = new_height + 'px';
13 }
14}
15
16function Newsletter_Init() {
17 if (!window.frameElement) {
18 /* Only trigger inside the iframe. */
19 return;
20 }
21 Newsletter_ResizePreviewFrame();
22 Newsletter_HijackLinks();
23}
24
25// Hijack all anchor clicks to Newsletter_LinkClick.
26// This only applies inside the iframe.
27function Newsletter_HijackLinks() {
28 map(function(anchor) { anchor.onclick=Newsletter_LinkClick; },
29 MochiKit.DOM.getElementsByTagAndClassName('a'));
30}
31
32// Click handler for links inside the iframe.
33// Instead of navigating inside the iframe, we change the location
34// of the parent window.
35function Newsletter_LinkClick(event) {
36 if (window.frameElement) {
37 window.parent.location = this.href;
38 }
39 return false;
40}
41
42connect(window, 'onload', Newsletter_Init);