root/branches/release-29/default_templates/javascript.mtml @ 1351

Revision 1351, 7.5 kB (checked in by ddavis, 22 months ago)

js cleanup in default templates

  • Property svn:executable set to *
  • Property svn:keywords set to Id Revision
Line 
1
2function hideDocumentElement(id) {
3    var el = document.getElementById(id);
4    if (el)
5        el.style.display = 'none';
6}
7
8function showDocumentElement(id) {
9    var el = document.getElementById(id);
10    if (el)
11        el.style.display = 'block';
12}
13
14var captcha_timer;
15function showAnonymousForm() {
16    showDocumentElement('comments-form');
17<MTIfNonEmpty tag="MTCaptchaFields">
18    captcha_timer = setInterval('delayShowCaptcha()', 1000);
19</MTIfNonEmpty>
20}
21<MTIfNonEmpty tag="MTCaptchaFields">
22function delayShowCaptcha() {
23    clearInterval(captcha_timer);
24    var div = document.getElementById('comments-open-captcha');
25    if (div)
26        div.innerHTML = '<$MTCaptchaFields$>';
27}
28</MTIfNonEmpty>
29
30var commenter_name;
31var commenter_blog_ids;
32var is_preview;
33var mtcmtmail;
34var mtcmtauth;
35var mtcmthome;
36
37function individualArchivesOnLoad(commenter_name) {
38<MTIfCommentsAccepted>
39<MTElse>
40    hideDocumentElement('comments-open');
41</MTIfCommentsAccepted>
42<MTIfPingsAccepted>
43<MTElse>
44    hideDocumentElement('trackbacks-info');
45</MTIfPingsAccepted>
46<MTIfRegistrationAllowed>
47    <MTIfRegistrationRequired>
48    if ( commenter_name &&
49         ( !commenter_id
50        || commenter_blog_ids.indexOf("'<$MTBlogID$>'") > -1))
51    {
52        hideDocumentElement('comment-form-name');
53        hideDocumentElement('comment-form-email');
54        showDocumentElement('comments-open-text');
55        showDocumentElement('comments-open-footer');
56    } else {
57        hideDocumentElement('comments-open-data');
58        hideDocumentElement('comments-open-text');
59        hideDocumentElement('comments-open-footer');
60    }
61    <MTElse>
62    // comments are allowed but registration not required
63    if ( commenter_name &&
64         ( !commenter_id
65        || commenter_blog_ids.indexOf("'<$MTBlogID$>'") > -1))
66    {
67        hideDocumentElement('comment-form-name');
68        hideDocumentElement('comment-form-email');
69    } else if (is_preview) {
70<MTIfNonEmpty tag="MTCaptchaFields">
71        delayShowCaptcha();
72</MTIfNonEmpty>
73    } else {
74        hideDocumentElement('comments-form');
75    }
76    </MTIfRegistrationRequired>
77</MTIfRegistrationAllowed>
78
79    var cf = document.comments_form;
80    if (cf) {
81        if (!commenter_name && (cf.email != undefined) &&
82            (mtcmtmail = getCookie("mtcmtmail")))
83            cf.email.value = mtcmtmail;
84        if (!commenter_name && (cf.author != undefined) &&
85            (mtcmtauth = getCookie("mtcmtauth")))
86            cf.author.value = mtcmtauth;
87        if (cf.url != undefined &&
88            (mtcmthome = getCookie("mtcmthome")))
89            cf.url.value = mtcmthome;
90        if (cf["bakecookie"]) {
91            if (mtcmtauth || mtcmthome) {
92                cf.bakecookie.checked = true;
93            } else {
94                cf.bakecookie.checked = false;
95            }
96        }
97    }
98}
99
100function writeCommenterGreeting(commenter_name, entry_id, blog_id, commenter_id, commenter_url) {
101<MTIfRegistrationAllowed>
102    if ( commenter_name &&
103         ( !commenter_id
104        || commenter_blog_ids.indexOf("'" + blog_id + "'") > -1))
105    {
106        var url;
107        if (commenter_id) {
108            url = '<$MTCGIPath$><$MTCommentScript$>?__mode=edit_profile&commenter=' + commenter_id + '&blog_id=' + blog_id;
109            if (entry_id) {
110                url += '&entry_id=' + entry_id;
111            } else {
112                url += '&static=1';
113            }
114        } else if (commenter_url) {
115            url = commenter_url;
116        } else {
117            url = null;
118        }
119        var content = '<__trans phrase="Thanks for signing in," escape="js"> ';
120        if (url) {
121            content += '<a href="' + url + '">' + commenter_name + '</a>';
122        } else {
123            content += commenter_name;
124        }
125        content += '<__trans phrase=". Now you can comment." escape="js"> (<a href="<$MTRemoteSignOutLink static="1"$>&entry_id=' + entry_id + '"><__trans phrase="sign out" escape="js"></a>)';
126        document.write(content);
127    } else if (commenter_name) {
128            document.write('<__trans phrase="You do not have permission to comment on this blog." escape="js"> (<a href="<$MTRemoteSignOutLink static="1"$>&entry_id=' + entry_id + '"><__trans phrase="sign out" escape="js"></a>)');
129    } else {
130<MTIfRegistrationRequired>
131        document.write('<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=login&entry_id=' + entry_id + '&blog_id=' + blog_id + '&static=1"><__trans phrase="Sign in" escape="js">' + '</a>' + '<__trans phrase=" to comment on this entry." escape="js">');
132<MTElse>
133        document.write('<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=login&entry_id=' + entry_id + '&blog_id=' + blog_id + '&static=1"><__trans phrase="Sign in" escape="js">' + '</a>' + '<__trans phrase=" to comment on this entry," escape="js"> <__trans phrase="or " escape="js"><a href="javascript:void(0);" onclick="showAnonymousForm();"><__trans phrase="comment anonymously." escape="js"></a>');
134</MTIfRegistrationRequired>
135    }
136</MTIfRegistrationAllowed>
137}
138
139<MTIfRegistrationAllowed>
140<MTsetvarblock name="cgi_host"><$MTCGIHost exclude_port="1"></MTsetvarblock>
141<MTIf tag="MTBlogHost" exclude_port="1" eq="cgi_host">
142commenter_name = getCookie('commenter_name');
143ids = getCookie('commenter_id').split(':');
144commenter_id = ids[0];
145commenter_blog_ids = ids[1];
146commenter_url = getCookie('commenter_url');
147<MTelse>
148document.write('<script src="<$MTCGIPath$><$MTCommentScript$>?__mode=cmtr_name_js&blog_id=<$MTBlogID$>"></script>');
149</MTIf>
150</MTIfRegistrationAllowed>
151
152
153// Copyright (c) 1996-1997 Athenia Associates.
154// http://www.webreference.com/js/
155// License is granted if and only if this entire
156// copyright notice is included. By Tomer Shiran.
157
158    function setCookie (name, value, expires, path, domain, secure) {
159        var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires.toGMTString() : "") +
160            (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
161        document.cookie = curCookie;
162    }
163
164    function getCookie (name) {
165        var prefix = name + '=';
166        var c = document.cookie;
167        var nullstring = '';
168        var cookieStartIndex = c.indexOf(prefix);
169        if (cookieStartIndex == -1)
170            return nullstring;
171        var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
172        if (cookieEndIndex == -1)
173            cookieEndIndex = c.length;
174        return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
175    }
176
177    function deleteCookie (name, path, domain) {
178        if (getCookie(name))
179            document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
180                ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
181    }
182
183    function fixDate (date) {
184        var base = new Date(0);
185        var skew = base.getTime();
186        if (skew > 0)
187            date.setTime(date.getTime() - skew);
188    }
189
190    function rememberMe (f) {
191        var now = new Date();
192        fixDate(now);
193        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
194        now = now.toGMTString();
195        if (f.author != undefined)
196           setCookie('mtcmtauth', f.author.value, now, '/', '', '');
197        if (f.email != undefined)
198           setCookie('mtcmtmail', f.email.value, now, '/', '', '');
199        if (f.url != undefined)
200           setCookie('mtcmthome', f.url.value, now, '/', '', '');
201    }
202
203    function forgetMe (f) {
204        deleteCookie('mtcmtmail', '/', '');
205        deleteCookie('mtcmthome', '/', '');
206        deleteCookie('mtcmtauth', '/', '');
207        f.email.value = '';
208        f.author.value = '';
209        f.url.value = '';
210    }
211
Note: See TracBrowser for help on using the browser.