Changeset 2363 for branches/release-38/default_templates/javascript.mtml
- Timestamp:
- 05/16/08 16:35:41 (19 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/release-38/default_templates/javascript.mtml
r2341 r2363 39 39 var el = (typeof id == "string") ? document.getElementById(id) : id; 40 40 if (el) el.style.display = 'block'; 41 } 42 43 <mt:Ignore> 44 /*** 45 * A utility function for assigning/adding handlers to window events. 46 */ 47 </mt:Ignore> 48 function mtAttachEvent(eventName,func) { 49 var onEventName = 'on' + eventName; 50 var old = window[onEventName]; 51 if( typeof old != 'function' ) 52 window[onEventName] = func; 53 else { 54 window[onEventName] = function( evt ) { 55 old( evt ); 56 return func( evt ); 57 }; 58 } 59 } 60 61 <mt:Ignore> 62 /*** 63 * Calls the event named, if there are handlers for it. 64 */ 65 </mt:Ignore> 66 function mtFireEvent(eventName,param) { 67 var fn = window['on' + eventName]; 68 if (typeof fn == 'function') return fn(param); 69 return; 41 70 } 42 71 … … 150 179 mtSaveUser(); 151 180 // sync up user greeting 152 mt UserOnLoad();181 mtFireEvent('usersignin'); 153 182 } 154 183 } … … 318 347 // if the user is authenticated, hide the 'anonymous' fields 319 348 // and any captcha input if already shown 320 if ( u && u.is_authenticated ) { 321 mtShow('comments-form'); 322 mtHide('comments-open-data'); 323 if (mtCaptchaVisible) 324 mtHide('comments-open-captcha'); 325 } else { 349 if ( document.getElementById('comments-form')) { 350 if ( u && u.is_authenticated ) { 351 mtShow('comments-form'); 352 mtHide('comments-open-data'); 353 if (mtCaptchaVisible) 354 mtHide('comments-open-captcha'); 355 } else { 326 356 <mt:IfRegistrationRequired> 327 mtHide('comments-form');357 mtHide('comments-form'); 328 358 </mt:IfRegistrationRequired> 329 }330 if ( u && u.is_banned ) {331 mtHide('comments-form');332 }333 334 // if we're previewing a comment, make sure the captcha335 // field is visible336 if (is_preview) {337 mtShowCaptcha();338 } else {339 // display greeting appropriate to the current user340 mtShowGreeting();341 }342 343 // populate anonymous comment fields if user is cookied as anonymous344 var cf = document['comments_form'];345 if (cf) {346 if (u && u.is_anonymous) {347 if (u.email) cf.email.value = u.email;348 if (u.name) cf.author.value = u.name;349 if (u.url) cf.url.value = u.url;350 if (cf.bakecookie)351 cf.bakecookie.checked = u.name || u.email;352 359 } 353 if (cf.post.disabled) { 354 cf.post.disabled = false; 355 cf.post.value = '<__trans phrase="Submit">'; 356 } 357 if (cf.preview_button.disabled) { 358 cf.preview_button.disabled = false; 359 cf.preview_button.value = '<__trans phrase="Preview">'; 360 if ( u && u.is_banned ) 361 mtHide('comments-form'); 362 363 // if we're previewing a comment, make sure the captcha 364 // field is visible 365 if (is_preview) 366 mtShowCaptcha(); 367 else 368 mtShowGreeting(); 369 370 // populate anonymous comment fields if user is cookied as anonymous 371 var cf = document['comments_form']; 372 if (cf) { 373 if (u && u.is_anonymous) { 374 if (u.email) cf.email.value = u.email; 375 if (u.name) cf.author.value = u.name; 376 if (u.url) cf.url.value = u.url; 377 if (cf.bakecookie) 378 cf.bakecookie.checked = u.name || u.email; 379 } 380 if (cf.post.disabled) { 381 cf.post.disabled = false; 382 cf.post.value = '<__trans phrase="Submit">'; 383 } 384 if (cf.preview_button.disabled) { 385 cf.preview_button.disabled = false; 386 cf.preview_button.value = '<__trans phrase="Preview">'; 387 } 360 388 } 361 389 } … … 370 398 </mt:Ignore> 371 399 function mtEntryOnLoad() { 372 <mt:Unless tag="IfPingsAccepted"> 373 mtHide('trackbacks-info'); 374 </mt:Unless> 375 376 <mt:Unless tag="IfCommentsAccepted"> 377 mtHide('comments-open'); 378 </mt:Unless> 379 380 mtUserOnLoad(); 381 } 400 <mt:Unless tag="IfPingsAccepted">mtHide('trackbacks-info');</mt:Unless> 401 <mt:Unless tag="IfCommentsAccepted">mtHide('comments-open');</mt:Unless> 402 mtFireEvent('usersignin'); 403 } 404 405 mtAttachEvent('usersignin', mtUserOnLoad); 382 406 383 407 <mt:Ignore> … … 396 420 } 397 421 398 function mtSignInOnClick() { 399 // display throbber 400 var el = document.getElementById('comment-greeting'); 401 if (!el) // legacy MT 4.x element id 402 el = document.getElementById('comment-form-external-auth'); 422 function mtSignInOnClick(sign_in_element) { 423 var el; 424 if (sign_in_element) { 425 // display throbber 426 el = document.getElementById(sign_in_element); 427 if (!el) // legacy MT 4.x element id 428 el = document.getElementById('comment-form-external-auth'); 429 } 403 430 if (el) 404 431 el.innerHTML = '<__trans phrase="Signing in..."> <img src="<$mt:StaticWebPath$>images/indicator.white.gif" height="16" width="16" alt="" />'; … … 420 447 <mt:Ignore> 421 448 /*** 422 * Handles the action of the "Sign out" link. First clears any existing 423 * user cookie, then direts to the MT comment script to sign the user out. 449 * Handles sign out from the web site. 450 * First clears any existing user cookie, then direts to the MT comment 451 * script to sign the user out. 424 452 */ 425 453 </mt:Ignore> 426 454 function mtSignOut(entry_id) { 427 var url = '<$mt:SignOutLink$>&entry_id=' + entry_id;428 455 mtClearUser(); 456 var url = '<$mt:SignOutLink$>&return_to=' + encodeURIComponent(location.href); 429 457 location.href = url; 458 } 459 460 <mt:Ignore> 461 /*** 462 * Handles the action of the "Sign out" link. 463 */ 464 </mt:Ignore> 465 function mtSignOutOnClick() { 466 mtSignOut(); 467 return false; 430 468 } 431 469 … … 457 495 if ( u && u.is_authenticated ) { 458 496 if ( u.is_banned ) { 459 phrase = '<__trans phrase="You do not have permission to comment on this blog. ([_1]sign out[_2])" params="<a href="javascript:void(0);" onclick=" mtSignOut(' + entry_id + ');return false;">%%</a>">';497 phrase = '<__trans phrase="You do not have permission to comment on this blog. ([_1]sign out[_2])" params="<a href="javascript:void(0);" onclick="return mtSignOutOnClick();">%%</a>">'; 460 498 } else { 461 499 var user_link; … … 473 511 } 474 512 // TBD: supplement phrase with userpic if one is available. 475 phrase = '<__trans phrase="Thanks for signing in, [_1]. ([_2]sign out[_3])" params="' + user_link + '%%<a href="javascript:void(0)" onclick=" mtSignOut(' + entry_id + ');return false;">%%</a>">';513 phrase = '<__trans phrase="Thanks for signing in, [_1]. ([_2]sign out[_3])" params="' + user_link + '%%<a href="javascript:void(0)" onclick="return mtSignOutOnClick();">%%</a>">'; 476 514 } 477 515 } else { 478 516 if (reg_reqd) { 479 phrase = '<__trans phrase="[_1]Sign in[_2] to comment." params="<a href="javascript:void(0)" onclick="return mtSignInOnClick( )">%%</a>">';517 phrase = '<__trans phrase="[_1]Sign in[_2] to comment." params="<a href="javascript:void(0)" onclick="return mtSignInOnClick(\'comment-greeting\')">%%</a>">'; 480 518 } else { 481 phrase = '<__trans phrase="[_1]Sign in[_2] to comment, or comment anonymously." params="<a href="javascript:void(0)" onclick="return mtSignInOnClick( )">%%</a>">';519 phrase = '<__trans phrase="[_1]Sign in[_2] to comment, or comment anonymously." params="<a href="javascript:void(0)" onclick="return mtSignInOnClick(\'comment-greeting\')">%%</a>">'; 482 520 } 483 521 } … … 587 625 </mt:Ignore> 588 626 function mtSetCookie(name, value, expires, path, domain, secure) { 627 if (domain && domain.match(/^\.?localhost$/)) 628 domain = null; 589 629 var curCookie = name + "=" + escape(value) + 590 630 (expires ? "; expires=" + expires.toGMTString() : "") + … … 618 658 </mt:Ignore> 619 659 function mtDeleteCookie(name, path, domain, secure) { 620 if (mtGetCookie(name)) 660 if (mtGetCookie(name)) { 661 if (domain && domain.match(/^\.?localhost$/)) 662 domain = null; 621 663 document.cookie = name + "=" + 622 664 (path ? "; path=" + path : "") + … … 624 666 (secure ? "; secure" : "") + 625 667 "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 668 } 626 669 } 627 670
