Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Going to the top of the page after Thanking

Any thoughts on this? Some of my users are complaining that when they click Thank, it sends them automatically to the top of the page.

Comments

  • hgtonighthgtonight ∞ · New Moderator

    What version of Vanilla are you running? 2.0.18.8 :D

    This is the same issue of the JS not loading properly (or at all). With JS enabled, it will catch the click event and adds the thanks asynchronously. Without JS enabled, the link first registers the thanks the redirects back to the same page.

    You could improve the case of JS not being loaded by adding an anchor to the target link.

    In class.thankfulpeople.plugin.php replace the public function DiscussionController_CommentOptions_Handler($Sender) function with the following:

    public function DiscussionController_CommentOptions_Handler($Sender) {
        $EventArguments =& $Sender->EventArguments;
        $Type = $EventArguments['Type'];
        $Object = $EventArguments['Object'];
    
        //$Session = Gdn::Session();
        $SessionUserID = $this->Session->UserID;
        if ($SessionUserID <= 0 || $Object->InsertUserID == $SessionUserID) return;
    
        if (!self::IsThankable($Type)) return;
    
        static $AllowTakeBack;
        if (is_null($AllowTakeBack)) $AllowTakeBack = C('Plugins.ThankfulPeople.AllowTakeBack', False);
        $AllowThank = True;
    
        switch ($Type) {
            case 'Discussion': {
                $DiscussionID = $ObjectID = $Object->DiscussionID;
                $TargetUrl = $Sender->CanonicalUrl();
                if (array_key_exists($SessionUserID, $this->DiscussionData)) $AllowThank = False;
                break;
            }
            case 'Comment': {
                $CommentID = $ObjectID = $Object->CommentID;
                $TargetUrl = '/discussion/comment/'.$CommentID.'#Comment_'.$CommentID;
                if (array_key_exists($CommentID, $this->ThankForComment) && in_array($SessionUserID, $this->ThankForComment[$CommentID])) $AllowThank = False;
                break;
            }
        }
    
        if ($AllowThank) {
            static $LocalizedThankButtonText;
            if ($LocalizedThankButtonText === Null) $LocalizedThankButtonText = T('ThankCommentOption', T('Thanks'));
            $ThankUrl = 'plugin/thankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$TargetUrl;
            $Option = '<span class="Thank">'.Anchor($LocalizedThankButtonText, $ThankUrl).'</span>';
            $Sender->Options .= $Option;
        } elseif ($AllowTakeBack) {
            // Allow unthank
            static $LocalizedUnThankButtonText;
            if (is_null($LocalizedUnThankButtonText)) $LocalizedUnThankButtonText = T('UnThankCommentOption', T('Unthank'));
            $UnThankUrl = 'plugin/unthankfor/'.strtolower($Type).'/'.$ObjectID.'?Target='.$TargetUrl;
            $Option = '<span class="UnThank">'.Anchor($LocalizedUnThankButtonText, $UnThankUrl).'</span>';
            $Sender->Options .= $Option;
        }
    }
    

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.