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

Revision 1896, 10.2 kB (checked in by bchoate, 20 months ago)

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