root/branches/release-35/default_templates/javascript.mtml @ 1964

Revision 1964, 10.2 kB (checked in by bsmith, 20 months ago)

bugzid:79382 - Javascript errors on Entry and Page archives when commenting is disabled

  • Property svn:keywords set to Id Revision
Line 
1function hideDocumentElement(id) {
2    var el = document.getElementById(id);
3    if (el)
4        el.style.display = 'none';
5}
6
7function showDocumentElement(id) {
8    var el = document.getElementById(id);
9    if (el)
10        el.style.display = 'block';
11}
12
13var captcha_timer;
14function showAnonymousForm() {
15    showDocumentElement('comments-form');
16<MTIfNonEmpty tag="MTCaptchaFields">
17    captcha_timer = setInterval('delayShowCaptcha()', 1000);
18</MTIfNonEmpty>
19}
20<MTIfNonEmpty tag="MTCaptchaFields">
21function delayShowCaptcha() {
22    clearInterval(captcha_timer);
23    var div = document.getElementById('comments-open-captcha');
24    if (div)
25        div.innerHTML = '<$MTCaptchaFields$>';
26}
27</MTIfNonEmpty>
28
29var AUTHOR = 1;
30var COMMENTER = 2;
31var commenter_name;
32var commenter_status;
33var commenter_id;
34var commenter_url
35var is_preview;
36var mtcmtmail;
37var mtcmtauth;
38var mtcmthome;
39
40function individualArchivesOnLoad(commenter_name) {
41    hideDocumentElement('comment-form-reply');
42<MTIfCommentsAccepted>
43<MTElse>
44    hideDocumentElement('comments-open');
45</MTIfCommentsAccepted>
46<MTIfPingsAccepted>
47<MTElse>
48    hideDocumentElement('trackbacks-info');
49</MTIfPingsAccepted>
50<MTIfRegistrationAllowed>
51    <MTIfRegistrationRequired>
52    if ( commenter_status > 0 ) {
53        hideDocumentElement('comment-form-name');
54        hideDocumentElement('comment-form-email');
55        hideDocumentElement('comment-form-url');
56        hideDocumentElement('comment-form-remember-me');
57        showDocumentElement('comments-open-text');
58        showDocumentElement('comments-open-footer');
59    } else {
60        hideDocumentElement('comments-open-data');
61        hideDocumentElement('comments-open-text');
62        hideDocumentElement('comments-open-footer');
63    }
64    <MTElse>
65    // comments are allowed but registration not required
66    if ( commenter_status > 0 ) {
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_status > 0 ) {
103        var commenter_link;
104        if ( commenter_status == COMMENTER ) {
105            if (commenter_url) {
106                commenter_link = '<a href="' + commenter_url + '">' + commenter_name + '</a>';
107            } else {
108                commenter_link = commenter_name;
109            }
110        } else if ( commenter_status == AUTHOR ) {
111            if (commenter_id) {
112                commenter_link = '<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=edit_profile&commenter=' + commenter_id + '&blog_id=' + blog_id;
113                if (entry_id) {
114                    commenter_link += '&entry_id=' + entry_id;
115                } else {
116                    commenter_link += '&static=1';
117                }
118                commenter_link += '">' + commenter_name + '</a>';
119            }
120
121        }
122        document.write(
123            '<__trans phrase="Thanks for signing in, [_1]. Now you can comment. ([_2]sign out[_3])" params="' + commenter_link + '%%<a href="<$MTRemoteSignOutLink static="1"$>&entry_id=' + entry_id + '">%%</a>">'
124        );
125    } else if (commenter_name) {
126        document.write('<__trans phrase="You do not have permission to comment on this blog. ([_1]sign out[_2])" params="<a href="<$MTRemoteSignOutLink static="1"$>&entry_id=' + entry_id + '">%%</a>">');
127    } else {
128<MTIfRegistrationRequired>
129        var phrase = '<__trans phrase="[_1]Sign in[_2] to comment on this entry." params="<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=login&entry_id=' + entry_id + '&blog_id=' + blog_id + '&static=1&return_to=' + encodeURIComponent(document.URL) + '">%%</a>">';
130<MTElse>
131        var phrase = '<__trans phrase="[_1]Sign in[_2] to comment on this entry, or [_3]comment anonymously[_2]." params="<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=login&entry_id=' + entry_id + '&blog_id=' + blog_id + '&static=1&return_to=' + encodeURIComponent(document.URL) + '">%%</a>%%<a href="javascript:void(0);" onclick="showAnonymousForm();">">';
132</MTIfRegistrationRequired>
133        document.write(phrase);
134    }
135</MTIfRegistrationAllowed>
136}
137
138<MTIfRegistrationAllowed>
139<$MTCGIHost exclude_port="1" setvar="cgi_host"$><$MTBlogHost exclude_port="1" setvar="blog_host"$>
140<MTIf name="cgi_host" eq="$blog_host">
141commenter_name = getCookie('commenter_name');
142commenter_url = getCookie('commenter_url');
143ids = getCookie('commenter_id').split(':');
144commenter_id = ids[0];
145if ( ids[1] == 'S' ) {
146    commenter_status = AUTHOR;
147}
148else if ( ids[1] == 'N' ) {
149    document.write('<script src="<$MTCGIPath$><$MTCommentScript$>?__mode=cmtr_status_js&blog_id=<$MTBlogID$>"></script>');
150}
151else if ( commenter_name && !commenter_id ) {
152    commenter_status = COMMENTER;
153}
154else if ( commenter_name
155  && commenter_id
156  && ( ids[1].indexOf("'<$MTBlogID$>'") > -1 ) ) {
157    commenter_status = AUTHOR;
158}
159else {
160    commenter_status = 0;
161}
162<MTElse>
163document.write('<script src="<$MTCGIPath$><$MTCommentScript$>?__mode=cmtr_name_js&blog_id=<$MTBlogID$>"></script>');
164</MTIf>
165</MTIfRegistrationAllowed>
166
167function replyComment(parent_id, author) {
168    showDocumentElement('comment-form-reply');
169   
170    var checkbox = document.getElementById('comment-reply');
171    var label = document.getElementById('comment-reply-label');
172    var text = document.getElementById('comment-text');
173
174    // Populate label with new values
175    var reply_text = '<__trans phrase="Replying to <a href="#comment-[_1]">comment from [_2]</a>" params="'+ parent_id +'%%'+ author +'">';
176    label.innerHTML = reply_text;
177
178    checkbox.value = parent_id;
179    checkbox.checked = true;
180    text.focus();
181
182    setCommentParentID();
183}
184
185function setCommentParentID() {
186    var checkbox = document.getElementById('comment-reply');
187    var parent_id_field = document.getElementById('comment-parent-id');
188    var pid = 0;
189   
190    if(checkbox.checked == true)
191        pid = checkbox.value;
192   
193    parent_id_field.value = pid;
194}
195
196
197// Copyright (c) 1996-1997 Athenia Associates.
198// http://www.webreference.com/js/
199// License is granted if and only if this entire
200// copyright notice is included. By Tomer Shiran.
201
202    function setCookie (name, value, expires, path, domain, secure) {
203        var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires.toGMTString() : "") +
204            (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
205        document.cookie = curCookie;
206    }
207
208    function getCookie (name) {
209        var prefix = name + '=';
210        var c = document.cookie;
211        var nullstring = '';
212        var cookieStartIndex = c.indexOf(prefix);
213        if (cookieStartIndex == -1)
214            return nullstring;
215        var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
216        if (cookieEndIndex == -1)
217            cookieEndIndex = c.length;
218        return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
219    }
220
221    function deleteCookie (name, path, domain) {
222        if (getCookie(name))
223            document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
224                ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
225    }
226
227    function fixDate (date) {
228        var base = new Date(0);
229        var skew = base.getTime();
230        if (skew > 0)
231            date.setTime(date.getTime() - skew);
232    }
233
234    function rememberMe (f) {
235        var now = new Date();
236        fixDate(now);
237        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
238        if (f.author != undefined)
239           setCookie('mtcmtauth', f.author.value, now, '/', '', '');
240        if (f.email != undefined)
241           setCookie('mtcmtmail', f.email.value, now, '/', '', '');
242        if (f.url != undefined)
243           setCookie('mtcmthome', f.url.value, now, '/', '', '');
244    }
245
246    function forgetMe (f) {
247        deleteCookie('mtcmtmail', '/', '');
248        deleteCookie('mtcmthome', '/', '');
249        deleteCookie('mtcmtauth', '/', '');
250    }
251
252
253// BEGIN: fast browser onload init
254// Modifications by David Davis, DWD
255// Dean Edwards/Matthias Miller/John Resig
256// http://dean.edwards.name/weblog/2006/06/again/?full#comment5338
257
258function init() {
259  // quit if this function has already been called
260  if (arguments.callee.done) return;
261
262  // flag this function so we don't do the same thing twice
263  arguments.callee.done = true;
264
265  // kill the timer
266  // DWD - check against window
267  if ( window._timer ) clearInterval(window._timer);
268 
269  // DWD - fire the window onload now, and replace it
270  if ( window.onload && ( window.onload !== window.init ) ) {
271    window.onload();
272    window.onload = function() {};
273  }
274};
275
276/* for Mozilla/Opera9 */
277if (document.addEventListener) {
278  document.addEventListener("DOMContentLoaded", init, false);
279}
280
281/* for Internet Explorer */
282/*@cc_on @*/
283/*@if (@_win32)
284  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
285  var script = document.getElementById("__ie_onload");
286  script.onreadystatechange = function() {
287    if (this.readyState == "complete") {
288      init(); // call the onload handler
289    }
290  };
291/*@end @*/
292
293/* for Safari */
294if (/WebKit/i.test(navigator.userAgent)) { // sniff
295  _timer = setInterval(function() {
296    if (/loaded|complete/.test(document.readyState)) {
297      init(); // call the onload handler
298    }
299  }, 10);
300}
301
302/* for other browsers */
303window.onload = init;
304
305// END: fast browser onload init
306
Note: See TracBrowser for help on using the browser.