Show
Ignore:
Timestamp:
05/16/08 16:35:41 (19 months ago)
Author:
bchoate
Message:

Updates to fix signin widget. BugId:79717

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-38/default_templates/javascript.mtml

    r2341 r2363  
    3939    var el = (typeof id == "string") ? document.getElementById(id) : id; 
    4040    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> 
     48function 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> 
     66function mtFireEvent(eventName,param) { 
     67    var fn = window['on' + eventName]; 
     68    if (typeof fn == 'function') return fn(param); 
     69    return; 
    4170} 
    4271 
     
    150179        mtSaveUser(); 
    151180        // sync up user greeting 
    152         mtUserOnLoad(); 
     181        mtFireEvent('usersignin'); 
    153182    } 
    154183} 
     
    318347    // if the user is authenticated, hide the 'anonymous' fields 
    319348    // 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 { 
    326356<mt:IfRegistrationRequired> 
    327         mtHide('comments-form'); 
     357            mtHide('comments-form'); 
    328358</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 captcha 
    335     // field is visible 
    336     if (is_preview) { 
    337         mtShowCaptcha(); 
    338     } else { 
    339         // display greeting appropriate to the current user 
    340         mtShowGreeting(); 
    341     } 
    342  
    343     // populate anonymous comment fields if user is cookied as anonymous 
    344     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; 
    352359        } 
    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            } 
    360388        } 
    361389    } 
     
    370398</mt:Ignore> 
    371399function 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 
     405mtAttachEvent('usersignin', mtUserOnLoad); 
    382406 
    383407<mt:Ignore> 
     
    396420} 
    397421 
    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'); 
     422function 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    } 
    403430    if (el) 
    404431        el.innerHTML = '<__trans phrase="Signing in..."> <img src="<$mt:StaticWebPath$>images/indicator.white.gif" height="16" width="16" alt="" />'; 
     
    420447<mt:Ignore> 
    421448/*** 
    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. 
    424452 */ 
    425453</mt:Ignore> 
    426454function mtSignOut(entry_id) { 
    427     var url = '<$mt:SignOutLink$>&entry_id=' + entry_id; 
    428455    mtClearUser(); 
     456    var url = '<$mt:SignOutLink$>&return_to=' + encodeURIComponent(location.href); 
    429457    location.href = url; 
     458} 
     459 
     460<mt:Ignore> 
     461/*** 
     462 * Handles the action of the "Sign out" link. 
     463 */ 
     464</mt:Ignore> 
     465function mtSignOutOnClick() { 
     466    mtSignOut(); 
     467    return false; 
    430468} 
    431469 
     
    457495    if ( u && u.is_authenticated ) { 
    458496        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>">'; 
    460498        } else { 
    461499            var user_link; 
     
    473511            } 
    474512            // 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>">'; 
    476514        } 
    477515    } else { 
    478516        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>">'; 
    480518        } 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>">'; 
    482520        } 
    483521    } 
     
    587625</mt:Ignore> 
    588626function mtSetCookie(name, value, expires, path, domain, secure) { 
     627    if (domain && domain.match(/^\.?localhost$/)) 
     628        domain = null; 
    589629    var curCookie = name + "=" + escape(value) + 
    590630        (expires ? "; expires=" + expires.toGMTString() : "") + 
     
    618658</mt:Ignore> 
    619659function mtDeleteCookie(name, path, domain, secure) { 
    620     if (mtGetCookie(name)) 
     660    if (mtGetCookie(name)) { 
     661        if (domain && domain.match(/^\.?localhost$/)) 
     662            domain = null; 
    621663        document.cookie = name + "=" + 
    622664            (path ? "; path=" + path : "") + 
     
    624666            (secure ? "; secure" : "") + 
    625667            "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
     668    } 
    626669} 
    627670