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

Revision 1889, 10.4 kB (checked in by bsmith, 20 months ago)

bugzid:74303 - Review Design of Threaded Comments

  • 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    var label = document.getElementById('comment-reply-label');
178    var text = document.getElementById('comment-text');
179
180    // Populate label with new values
181    var reply_text = '<__trans phrase="Replying to <a href="#comment-[_1]">comment from [_2]</a>" params="'+ parent_id +'%%'+ author +'">';
182    label.innerHTML = reply_text;
183
184    checkbox.value = parent_id;
185    checkbox.checked = true;
186    text.focus();
187
188    setCommentParentID();
189}
190
191function setCommentParentID() {
192    var checkbox = document.getElementById('comment-reply');
193    var parent_id_field = document.getElementById('comment-parent-id');
194    var pid = 0;
195   
196    if(checkbox.checked == true)
197        pid = checkbox.value;
198   
199    parent_id_field.value = pid;
200}
201
202
203// Copyright (c) 1996-1997 Athenia Associates.
204// http://www.webreference.com/js/
205// License is granted if and only if this entire
206// copyright notice is included. By Tomer Shiran.
207
208    function setCookie (name, value, expires, path, domain, secure) {
209        var curCookie = name + "=" + escape(value) + (expires ? "; expires=" + expires.toGMTString() : "") +
210            (path ? "; path=" + path : "") + (domain ? "; domain=" + domain : "") + (secure ? "secure" : "");
211        document.cookie = curCookie;
212    }
213
214    function getCookie (name) {
215        var prefix = name + '=';
216        var c = document.cookie;
217        var nullstring = '';
218        var cookieStartIndex = c.indexOf(prefix);
219        if (cookieStartIndex == -1)
220            return nullstring;
221        var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
222        if (cookieEndIndex == -1)
223            cookieEndIndex = c.length;
224        return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
225    }
226
227    function deleteCookie (name, path, domain) {
228        if (getCookie(name))
229            document.cookie = name + "=" + ((path) ? "; path=" + path : "") +
230                ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
231    }
232
233    function fixDate (date) {
234        var base = new Date(0);
235        var skew = base.getTime();
236        if (skew > 0)
237            date.setTime(date.getTime() - skew);
238    }
239
240    function rememberMe (f) {
241        var now = new Date();
242        fixDate(now);
243        now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
244        if (f.author != undefined)
245           setCookie('mtcmtauth', f.author.value, now, '/', '', '');
246        if (f.email != undefined)
247           setCookie('mtcmtmail', f.email.value, now, '/', '', '');
248        if (f.url != undefined)
249           setCookie('mtcmthome', f.url.value, now, '/', '', '');
250    }
251
252    function forgetMe (f) {
253        deleteCookie('mtcmtmail', '/', '');
254        deleteCookie('mtcmthome', '/', '');
255        deleteCookie('mtcmtauth', '/', '');
256    }
257
258
259// BEGIN: fast browser onload init
260// Modifications by David Davis, DWD
261// Dean Edwards/Matthias Miller/John Resig
262// http://dean.edwards.name/weblog/2006/06/again/?full#comment5338
263
264function init() {
265  // quit if this function has already been called
266  if (arguments.callee.done) return;
267
268  // flag this function so we don't do the same thing twice
269  arguments.callee.done = true;
270
271  // kill the timer
272  // DWD - check against window
273  if ( window._timer ) clearInterval(window._timer);
274 
275  // DWD - fire the window onload now, and replace it
276  if ( window.onload && ( window.onload !== window.init ) ) {
277    window.onload();
278    window.onload = function() {};
279  }
280};
281
282/* for Mozilla/Opera9 */
283if (document.addEventListener) {
284  document.addEventListener("DOMContentLoaded", init, false);
285}
286
287/* for Internet Explorer */
288/*@cc_on @*/
289/*@if (@_win32)
290  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
291  var script = document.getElementById("__ie_onload");
292  script.onreadystatechange = function() {
293    if (this.readyState == "complete") {
294      init(); // call the onload handler
295    }
296  };
297/*@end @*/
298
299/* for Safari */
300if (/WebKit/i.test(navigator.userAgent)) { // sniff
301  _timer = setInterval(function() {
302    if (/loaded|complete/.test(document.readyState)) {
303      init(); // call the onload handler
304    }
305  }, 10);
306}
307
308/* for other browsers */
309window.onload = init;
310
311// END: fast browser onload init
312
Note: See TracBrowser for help on using the browser.