HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

A few changes

This discussion is related to the OnlyRead addon.
HotBlackHotBlack New
edited May 2012 in Feedback

I have played around with extension abit and made a version with the following modifications
1) Button shows different clicked/not clicked state
2) Defaults to only show unread on main (no category selected view)
3) Defaults to show all when a category is selected.

I have changed 3 files:

onlyread.css

toggleButton.Button {

font-size: 13px;
font-weight: bold;
background: #111;
background: #3F3F3F;
color: #FFFFFF;
border: 3px solid #444;
float: right;
}

toggleButton.inactive {

font-size: 13px;
font-weight: bold;
background: #111;
color: #FFFFFF;
border: 3px solid #444;
float: right;
}

onlyread.js

jQuery(document).ready(function($) {
$('#toggleButton').click(function(){

//Swap UI State
$(this).toggleClass("inactive")

//Swap ???
if($('.Read').is(':visible')) {
$('.Read').hide();
} else {
$('.Read').show();
}
});
});

default.php

<?php if (!defined('APPLICATION')) exit();

// Define the plugin:
$PluginInfo['OnlyRead'] = array(
'Name' => 'OnlyRead',
'Description' => 'Adds an Unread-Discussions Label to menu to show only unread discussions. Additionally, allows user to display or hide discussions that have been read with a toggle button. The Button is placed to the right of Discussion Tabs on the Discussion Listings Page. see Readme.txt to modify button text and menu item text',
'Version' => '1.1',
'RequiredApplications' => FALSE,
'RequiredTheme' => FALSE,
'RequiredPlugins' => FALSE,
'Author' => "Peregrine"
);

//Code
class OnlyReadPlugin extends Gdn_Plugin {

// Add JS, CSS and include button
public function DiscussionsController_AfterDiscussionTabs_Handler($Sender) {
$Session = Gdn::Session();

//Set Default
$Sender->AddCssFile('onlyread.css', 'plugins/OnlyRead');
$Mode="Button";

//Get Current catagory
$CurrentCat = $Sender->Category;
if ($CurrentCat==FALSE) {
$Sender->AddJsFile('/plugins/OnlyRead/js/onlyunread.js');
$Sender->AddJsFile('/plugins/OnlyRead/js/onlyread.js');
} else {
$Sender->AddJsFile('/plugins/OnlyRead/js/onlyread.js');
$Mode="Button inactive";
}

//Get button label
$mybutton = (C('Plugins.OnlyRead.ButtonLabel'));
if (!$mybutton) {
$mybutton = "Read+-";
}

//Show button label
if ($Session->IsValid()) {
echo '';
echo '';
echo '
';
}
}

// XX
public function DiscussionsController_BeforeDiscussionName_Handler($Sender) {
$CssItem = $Sender->EventArguments['CssClass'];
$unread = $Sender->EventArguments['Discussion']->CountUnreadComments;
$Session = Gdn::Session();
if ($unread < 1 ) {
$CssItem = str_replace("Item", "Item Read", $CssItem);
$Sender->EventArguments['CssClass'] = $CssItem;
}
}

// XXX
public function CategoriesController_BeforeDiscussionName_Handler($Sender) {
$this->DiscussionsController_BeforeDiscussionName_Handler($Sender);
}

// XXX
public function CategoriesController_AfterDiscussionTabs_Handler($Sender) {
$this->DiscussionsController_AfterDiscussionTabs_Handler($Sender);
}

public function Setup() { }
public function OnDisable() { }
}

If anybody finds this useful, just copy in the code into your files.

Best Answer

Answers

  • UnderDogUnderDog MVP
    Answer ✓

    Thanks man! If you have any more additions to other plugins, don't hesitate :-)

  • Well, I am going to setup a test version of 2.1, as it seems so much changes with 2.1 that developing some things are pointless. I have been looking for a roadmap (other than the rather limited list on github). Some comment I read here seemed to suggest that a whole new read/unread system is baked into 2.1? (I am very new here and still finding my way around - Vanillia is full of potential).

    Can you point me to, or make a post, about what will be in 2.1? Is there more developer documentation that what is on the wiki?

    UnderDog
  • peregrineperegrine MVP
    edited May 2012

    @HotBlack - I thank you in behalf of the user(s) who use this plugin.

    you know you can highlight code areas and just click the C button in the buttonbar and it produces more readable results here and easier to copy.

    can you > HotBlack said:

    I have played around with extension abit and made a version with the following modifications
    1) Button shows different clicked/not clicked state
    2) Defaults to only show unread on main (no category selected view)
    3) Defaults to show all when a category is selected.

    I have changed 3 files:

    onlyread.css
     #toggleButton.Button { 
        font-size: 13px;
        font-weight: bold;   
        background: #111;
        background: #3F3F3F;
         color: #FFFFFF;
        border: 3px solid #444; 
        float: right;
     }
    
     #toggleButton.inactive { 
        font-size: 13px;
        font-weight: bold;   
        background: #111;   
         color: #FFFFFF;
        border: 3px solid #444; 
        float: right;
     }
    
    -  onlyread.js
     jQuery(document).ready(function($) {
        $('#toggleButton').click(function(){    
    
            //Swap UI State
            $(this).toggleClass("inactive") 
    
            //Swap ???
            if($('.Read').is(':visible')) {
                $('.Read').hide();
            } else {
                $('.Read').show();
            }
        });
     });
    
    default.php
     <?php if (!defined('APPLICATION'))  exit();
    
     // Define the plugin:
     $PluginInfo['OnlyRead'] = array(
         'Name' => 'OnlyRead',
         'Description' => 'Adds an Unread-Discussions Label to menu to show only unread discussions. Additionally, allows user to display or hide discussions that have been read with a toggle button.  The Button is placed to the right of Discussion Tabs on the Discussion Listings Page.  see Readme.txt to modify button text and menu item text',
        'Version' => '1.1',
         'RequiredApplications' => FALSE,
        'RequiredTheme' => FALSE,
         'RequiredPlugins' => FALSE,
         'Author' => "Peregrine"
     );
    
     //Code
     class OnlyReadPlugin extends Gdn_Plugin {
    
        // Add  JS, CSS and include button
        public function DiscussionsController_AfterDiscussionTabs_Handler($Sender) {
            $Session = Gdn::Session();
    
            //Set  Default
            $Sender->AddCssFile('onlyread.css', 'plugins/OnlyRead');    
            $Mode="Button";
    
            //Get Current catagory  
            $CurrentCat =  $Sender->Category;       
        if ($CurrentCat==FALSE) {
                $Sender->AddJsFile('/plugins/OnlyRead/js/onlyunread.js');       
                $Sender->AddJsFile('/plugins/OnlyRead/js/onlyread.js'); 
            } else {
                $Sender->AddJsFile('/plugins/OnlyRead/js/onlyread.js'); 
            }
    
            //Get button label
            $mybutton = (C('Plugins.OnlyRead.ButtonLabel'));
            if (!$mybutton) {
                $mybutton = "Read+-";
            }
    
            //Show button label
            if ($Session->IsValid()) {
                echo '<span id = "controlbuttons" >';
                echo '<input type="button"  class="';
                echo $Mode;
                echo '" id="toggleButton" value="';
                echo $mybutton; 
                echo '" />';
                echo '</span>';
            }
        }
    
        // XX
       public function DiscussionsController_BeforeDiscussionName_Handler($Sender) {
            $CssItem = $Sender->EventArguments['CssClass'];
            $unread =  $Sender->EventArguments['Discussion']->CountUnreadComments;
            $Session = Gdn::Session();
            if ($unread < 1 )   {
                $CssItem = str_replace("Item", "Item Read", $CssItem);
                $Sender->EventArguments['CssClass'] = $CssItem;
            }       
         }
    
        // XXX
        public function CategoriesController_BeforeDiscussionName_Handler($Sender) {
            $this->DiscussionsController_BeforeDiscussionName_Handler($Sender);
        }
    
        // XXX
        public function CategoriesController_AfterDiscussionTabs_Handler($Sender) { 
            $this->DiscussionsController_AfterDiscussionTabs_Handler($Sender);        
        }
    
         public function Setup() {    }
         public function OnDisable() {    }
     }
    

    If anybody finds this useful, just copy in the code into your files.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

    UnderDog
  • peregrineperegrine MVP
    edited May 2012

    BTW,

    thanks for your changes @HotBlack. a few suggestions:

    if you want to post the diffs to the code changes, it might be helpful for others to pick and choose what they want. You can say modified lines so and so to (particularly for default.php.

    some code oddities in css.
    lines 5 and 6
    duplication of background.

    if you highlight and post with the C (code) button, it is easier to cut and paste).

    last but not least the word is "Category" not catagory.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.