root/branches/release-32/default_templates/javascript.mtml @ 1561

Revision 1561, 10.1 kB (checked in by bchoate, 20 months ago)

Applying comment threading support. BugId:70228

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