root/branches/release-34/default_templates/javascript.mtml @ 1887

Revision 1887, 10.7 kB (checked in by auno, 20 months ago)

Hide url and 'remember me' fields when commenter is logged in. BugzID:74098

  • 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 AUTHOR = 1;
31var COMMENTER = 2;
32var commenter_name;
33var commenter_status;
34var commenter_id;
35var commenter_url
36var is_preview;
37var mtcmtmail;
38var mtcmtauth;
39var mtcmthome;
40
41function individualArchivesOnLoad(commenter_name) {
42    hideDocumentElement('comment-form-reply');
43<MTIfCommentsAccepted>
44<MTElse>
45    hideDocumentElement('comments-open');
46</MTIfCommentsAccepted>
47<MTIfPingsAccepted>
48<MTElse>
49    hideDocumentElement('trackbacks-info');
50</MTIfPingsAccepted>
51<MTIfRegistrationAllowed>
52    <MTIfRegistrationRequired>
53    if ( commenter_status == AUTHOR  ) {
54        hideDocumentElement('comment-form-name');
55        hideDocumentElement('comment-form-email');
56        showDocumentElement('comments-open-text');
57        showDocumentElement('comments-open-footer');
58    } else if ( commenter_status == COMMENTER ) {
59        hideDocumentElement('comment-form-name');
60        hideDocumentElement('comment-form-email');
61        hideDocumentElement('comment-form-url');
62        hideDocumentElement('comment-form-remember-me');
63        showDocumentElement('comments-open-text');
64        showDocumentElement('comments-open-footer');
65    } else {
66        hideDocumentElement('comments-open-data');
67        hideDocumentElement('comments-open-text');
68        hideDocumentElement('comments-open-footer');
69    }
70    <MTElse>
71    // comments are allowed but registration not required
72    if ( commenter_status > 0 ) {
73        hideDocumentElement('comment-form-name');
74        hideDocumentElement('comment-form-email');
75    } else if (is_preview) {
76<MTIfNonEmpty tag="MTCaptchaFields">
77        delayShowCaptcha();
78</MTIfNonEmpty>
79    } else {
80        hideDocumentElement('comments-form');
81    }
82    </MTIfRegistrationRequired>
83</MTIfRegistrationAllowed>
84
85    var cf = document.comments_form;
86    if (cf) {
87        if (!commenter_name && (cf.email != undefined) &&
88            (mtcmtmail = getCookie("mtcmtmail")))
89            cf.email.value = mtcmtmail;
90        if (!commenter_name && (cf.author != undefined) &&
91            (mtcmtauth = getCookie("mtcmtauth")))
92            cf.author.value = mtcmtauth;
93        if (cf.url != undefined &&
94            (mtcmthome = getCookie("mtcmthome")))
95            cf.url.value = mtcmthome;
96        if (cf["bakecookie"]) {
97            if (mtcmtauth || mtcmthome) {
98                cf.bakecookie.checked = true;
99            } else {
100                cf.bakecookie.checked = false;
101            }
102        }
103    }
104}
105
106function writeCommenterGreeting(commenter_name, entry_id, blog_id, commenter_id, commenter_url) {
107<MTIfRegistrationAllowed>
108    if ( commenter_status > 0 ) {
109        var commenter_link;
110        if ( commenter_status == COMMENTER ) {
111            if (commenter_url) {
112                commenter_link = '<a href="' + commenter_url + '">' + commenter_name + '</a>';
113            } else {
114                commenter_link = commenter_name;
115            }
116        } else if ( commenter_status == AUTHOR ) {
117            if (commenter_id) {
118                commenter_link = '<a href="<$MTCGIPath$><$MTCommentScript$>?__mode=edit_profile&commenter=' + commenter_id + '&blog_id=' + blog_id;
119                if (entry_id) {
120                    commenter_link += '&entry_id=' + entry_id;
121                } else {
122                    commenter_link += '&static=1';
123                }
124                commenter_link += '">' + commenter_name + '</a>';
125            }
126
127        }
128        document.write(
129            '<__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>">'
130        );
131    } else if (commenter_name) {
132        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>">');
133    } else {
134<MTIfRegistrationRequired>
135        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>">';
136<MTElse>
137        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();">">';
138</MTIfRegistrationRequired>
139        document.write(phrase);
140    }
141</MTIfRegistrationAllowed>
142}
143
144<MTIfRegistrationAllowed>
145<$MTCGIHost exclude_port="1" setvar="cgi_host"$><$MTBlogHost exclude_port="1" setvar="blog_host"$>
146<MTIf name="cgi_host" eq="$blog_host">
147commenter_name = getCookie('commenter_name');
148commenter_url = getCookie('commenter_url');
149ids = getCookie('commenter_id').split(':');
150commenter_id = ids[0];
151if ( ids[1] == 'S' ) {
152    commenter_status = AUTHOR;
153}
154else if ( ids[1] == 'N' ) {
155    document.write('<script src="<$MTCGIPath$><$MTCommentScript$>?__mode=cmtr_status_js&blog_id=<$MTBlogID$>"></script>');
156}
157else if ( commenter_name && !commenter_id ) {
158    commenter_status = COMMENTER;
159}
160else if ( commenter_name
161  && commenter_id
162  && ( ids[1].indexOf("'<$MTBlogID$>'") > -1 ) ) {
163    commenter_status = AUTHOR;
164}
165else {
166    commenter_status = 0;
167}
168<MTElse>
169document.write('<script src="<$MTCGIPath$><$MTCommentScript$>?__mode=cmtr_name_js&blog_id=<$MTBlogID$>"></script>');
170</MTIf>
171</MTIfRegistrationAllowed>
172
173function replyComment(parent_id, author) {
174    showDocumentElement('comment-form-reply');
175   
176    var checkbox = document.getElementById('comment-reply');
177
178    // Clear the current label but NOT our checkbox!
179    var label = document.getElementById('comment-reply-label');
180    for(var i = 1; i < label.childNodes.length; i++) {
181        label.removeChild(label.childNodes[i]);
182    }
183   
184    // Populate label with new values
185    var reply_text = document.createTextNode(' <__trans phrase="Replying to"> ');
186    label.appendChild(reply_text);
187
188    var anchor = document.createElement('a');
189    anchor.setAttribute('href', '#comment-' + parent_id);
190    anchor.innerHTML = author;
191    label.appendChild(anchor);
192   
193    checkbox.value = parent_id;
194    checkbox.setAttribute('checked', true);
195    checkbox.focus();
196   
197    setCommentParentID();
198}
199
200function setCommentParentID() {
201    var checkbox = document.getElementById('comment-reply');
202    var parent_id_field = document.getElementById('comment-parent-id');
203    var pid = 0;
204   
205    if(checkbox.checked == true)
206        pid = checkbox.value;
207   
208    parent_id_field.value = pid;
209}
210
211
212// Copyright (c) 1996-1997 Athenia Associates.
213// http://www.webreference.com/js/
214// License is granted if and only if this entire
215// copyright notice is included. By Tomer Shiran.
216
217    function setCookie (name, value, expires, path, domain, secure) {
218        var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires.toGMTString() : "") +
219            (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
220        document.cookie = curCookie;
221    }
222
223    function getCookie (name) {
224        var prefix = name + '=';
225        var c = document.cookie;
226        var nullstring = '';
227        var cookieStartIndex = c.indexOf(prefix);
228        if (cookieStartIndex == -1)
229            return nullstring;
230        var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
231        if (cookieEndIndex == -1)
232            cookieEndIndex = c.length;
233        return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
234    }
235
236    function deleteCookie (name, path, domain) {
237        if (getCookie(name))
238            document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
239                ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
240    }
241
242    function fixDate (date) {
243        var base = new Date(0);
244        var skew = base.getTime();
245        if (skew > 0)
246            date.setTime(date.getTime() - skew);
247    }
248
249    function rememberMe (f) {
250        var now = new Date();
251        fixDate(now);
252        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
253        if (f.author != undefined)
254           setCookie('mtcmtauth', f.author.value, now, '/', '', '');
255        if (f.email != undefined)
256           setCookie('mtcmtmail', f.email.value, now, '/', '', '');
257        if (f.url != undefined)
258           setCookie('mtcmthome', f.url.value, now, '/', '', '');
259    }
260
261    function forgetMe (f) {
262        deleteCookie('mtcmtmail', '/', '');
263        deleteCookie('mtcmthome', '/', '');
264        deleteCookie('mtcmtauth', '/', '');
265    }
266
267
268// BEGIN: fast browser onload init
269// Modifications by David Davis, DWD
270// Dean Edwards/Matthias Miller/John Resig
271// http://dean.edwards.name/weblog/2006/06/again/?full#comment5338
272
273function init() {
274  // quit if this function has already been called
275  if (arguments.callee.done) return;
276
277  // flag this function so we don't do the same thing twice
278  arguments.callee.done = true;
279
280  // kill the timer
281  // DWD - check against window
282  if ( window._timer ) clearInterval(window._timer);
283 
284  // DWD - fire the window onload now, and replace it
285  if ( window.onload && ( window.onload !== window.init ) ) {
286    window.onload();
287    window.onload = function() {};
288  }
289};
290
291/* for Mozilla/Opera9 */
292if (document.addEventListener) {
293  document.addEventListener("DOMContentLoaded", init, false);
294}
295
296/* for Internet Explorer */
297/*@cc_on @*/
298/*@if (@_win32)
299  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
300  var script = document.getElementById("__ie_onload");
301  script.onreadystatechange = function() {
302    if (this.readyState == "complete") {
303      init(); // call the onload handler
304    }
305  };
306/*@end @*/
307
308/* for Safari */
309if (/WebKit/i.test(navigator.userAgent)) { // sniff
310  _timer = setInterval(function() {
311    if (/loaded|complete/.test(document.readyState)) {
312      init(); // call the onload handler
313    }
314  }, 10);
315}
316
317/* for other browsers */
318window.onload = init;
319
320// END: fast browser onload init
321
Note: See TracBrowser for help on using the browser.