Changeset 2363

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

Updates to fix signin widget. BugId:79717

Location:
branches/release-38/default_templates
Files:
2 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 
  • branches/release-38/default_templates/signin.mtml

    r2052 r2363  
    1 <script type="text/javascript" src="<$mt:Link template="<__trans phrase="JavaScript">"$>"></script> 
     1<mt:IfRegistrationAllowed> 
    22<div class="widget-sign-in widget"> 
    33    <h3 class="widget-header"><__trans phrase="Sign In"></h3> 
    4     <div class="widget-content"> 
     4    <div class="widget-content" id="signin-widget-content"></div> 
     5</div> 
    56<script type="text/javascript"> 
    67/* <![CDATA[ */ 
    7 var name, id, url, blog_ids; 
    8 if (typeof(commenter_name) != 'undefined') 
    9     name = commenter_name 
    10 if (typeof(commenter_id) != 'undefined') 
    11     id = commenter_id; 
    12 if (typeof(commenter_url) != 'undefined') 
    13     url = commenter_url; 
    14 if (typeof(commenter_blog_ids) != 'undefined') 
    15     blog_ids = commenter_blog_ids; 
    16  
    17 if (!name && !id) { 
    18     if ('<$mt:CGIHost exclude_port="1"$>' != '<$mt:BlogHost exclude_port="1"$>') { 
    19         document.write('<scr' + 'ipt src="<$mt:CGIPath$><$mt:CommentScript$>?__mode=cmtr_name_js">'); 
    20         document.write("</scr" + "ipt>"); 
     8function mtUpdateSignInWidget(u) { 
     9    var el = document.getElementById('signin-widget-content'); 
     10    if (!el) return; 
     11    if (u) { 
     12        if (u && u.is_authenticated) { 
     13            user = u; 
     14            mtSaveUser(); 
     15        } else { 
     16            // user really isn't logged in; so let's do this! 
     17            return mtSignIn(); 
     18        } 
    2119    } else { 
    22         name = getCookie('commenter_name'); 
    23         ids = getCookie('commenter_id').split(':'); 
    24         id = ids[0]; 
    25         blog_ids = ids[1]; 
    26         url = getCookie('commenter_url'); 
     20        u = mtGetUser(); 
    2721    } 
    28 } 
    29 showMessage(name, id, url); 
    30  
    31 function showMessage(commenter_name, commenter_id, commenter_url) { 
    32     static = location.href; 
    33     if ( commenter_name && 
    34          ( !commenter_id  
    35         || commenter_blog_ids.indexOf("'<$mt:BlogID$>'") > -1)) 
    36     { 
     22    if (u) { 
    3723        var url; 
    38         if (commenter_id) { 
    39             url = '<$mt:CGIPath$><$mt:CommentScript$>?__mode=edit_profile&commenter=' + commenter_id + '&blog_id=<$mt:BlogID$>'; 
    40             url += '&static=' + static; 
    41         } else if (commenter_url) { 
    42             url = commenter_url; 
     24        if (u.is_authenticated) { 
     25            url = '<$mt:CGIPath$><$mt:CommentScript$>?__mode=edit_profile&blog_id=<$mt:BlogID$>'; 
     26            url += '&static=' + escape( location.href ); 
     27        } else if (u.url) { 
     28            url = u.url; 
    4329        } else { 
    4430            url = null; 
    4531        } 
    4632        var content = '<__trans phrase="You are signed in as " escape="js">'; 
    47         if (url) { 
    48             content += '<a href="' + url + '">' + commenter_name + '</a>'; 
    49         } else { 
    50             content += commenter_name; 
    51         } 
    52         content += '.  (<a href="<$mt:RemoteSignOutLink no_static="1"$>&static=' + static + '"><__trans phrase="sign out" escape="js"></a>)'; 
    53         document.write(content); 
    54     } else if (commenter_name) { 
    55         document.write('<__trans phrase="You do not have permission to sign in to this blog." escape="js"> (<a href="<$mt:RemoteSignOutLink no_static="1"$>&static=' + static + '"><__trans phrase="sign out" escape="js"></a>)'); 
     33        if (url) 
     34            content += '<a href="' + url + '">' + u.name + '</a>'; 
     35        else 
     36            content += u.name; 
     37        content += '.  (<a href="javascript:void(0)" onclick="return mtSignOutOnClick()"><__trans phrase="sign out" escape="js"></a>)'; 
     38    } else if (u && u.is_banned) { 
     39        content = '<__trans phrase="You do not have permission to sign in to this blog." escape="js">'; 
    5640    } else { 
    57     <mt:IfRegistrationAllowed> 
    58         document.write('<a href="<$mt:CGIPath$><$mt:CommentScript$>?__mode=login&blog_id=<$mt:BlogID$>&static=' + static + '"><__trans phrase="Sign In" escape="js"></a>'); 
    59     </mt:IfRegistrationAllowed> 
     41        content = '<a href="javascript:void(0)" onclick="return mtSignInOnClick(\'signin-widget-content\')"><__trans phrase="Sign In" escape="js"></a>'; 
    6042    } 
     43    el.innerHTML = content; 
    6144} 
     45mtAttachEvent('usersignin', mtUpdateSignInWidget); 
     46mtUpdateSignInWidget(); 
    6247/* ]]> */ 
    6348</script> 
    64     </div> 
    65 </div> 
     49</mt:IfRegistrationAllowed>