Post Toolbar Options - Timestamp?


(Rob Meade) #1

Hi,

Often I find users (myself included) returning to the same post and updating it with some new content, I would typically do something like this;

Update

Now I have discovered this etc etc…

As this can happen on multiple occasions for the same post, I thought it would be beneficial to be able to click a button on the post toolbar (bold, italic, underline etc) and have a TimeStamp inserted, there doesn’t appear to be an option for this at this time, nor was I able to discover any shortcut (by typing) to make it appear.

Potentially the output may look like;

blah blah blah

Update 21/10/2016 13:39

something new was discovered

Update 21/10/2016 13:41

something even newer was discovered here…

I fully appreciate this can be achieved manually, but a feature button to insert it for you would be, well, kinda time saving :slight_smile:

I should add, this would be a post CONTENT timestamp, not a timestamp used against the actual posting of the message as it were (I see there are lots of posts on here regarding that)


(Erlend Sogge Heggen) #2

Things that are just “kinda sorta useful” tend to fall into plugin territory :wink: I do end up doing this type of update myself from time to time, but not nearly often enough that I feel like I’d save a significant amount of time by having a dedicated function for it.


(Rob Meade) #3

There is a large sense of relief that it’s not only me :slight_smile:

Well, Santa will soon be on his way so I thought I’d put my requests in now, I have been good all year on occasion, after all! :slight_smile:


(cpradio) #4

Add this to your Admin > Customize > CSS/HTML > </head>

<script type="text/discourse-plugin" version="0.4">
    api.onToolbarCreate(toolbar => {
      toolbar.addButton({
        id: "updated_button",
        group: "extras",
        icon: "clock-o",
        perform: e => e.addText("Updated " + new Date().toString())
      });
    });
</script>

(Rob Meade) #5

Hi @cpradio, sorry for the delay responding.

Thank you for spending the time putting that together and sharing, appreciated. I don’t have the ability on the site to implement it (lowly moderator) but I will pass it over to those that do and see if they are willing.

Thanks again, really appreciated :slight_smile:

Kind regards

Rob


(Rob Meade) #6

Just a quick question to re-open this if I may…

I spotted that when this was being used the time stamp was quite long, looking at the various options using JavaScript to shorten the date it seemed incredibly complex, from what I could tell the desired output would always be 21 characters long so went with a bit of a hacky way of doing this…

<script type="text/discourse-plugin" version="0.4">
    api.onToolbarCreate(toolbar => {
      toolbar.addButton({
        id: "updated_button",
        group: "extras",
        icon: "clock-o",
        perform: e => e.addText("_Updated " + new Date().toString().substring(0,21) + "_")
      });
    });
</script>

I then spotted that the hover text didn’t display a name correctly - so we have added this

title: "Updated Timestamp",

thus;

<script type="text/discourse-plugin" version="0.4">
    api.onToolbarCreate(toolbar => {
      toolbar.addButton({
        id: "updated_button",
        group: "extras",
        icon: "clock-o",
        title: "Updated Timestamp",
        perform: e => e.addText("_Updated " + new Date().toString().substring(0,21) + "_")
      });
    });
</script>

but the output in the hover text appears as [en.Updated Timestamp]

Anyway to remove the square brackets and the en. part?


(cpradio) #7

Try this:

<script type="text/discourse-plugin" version="0.4">
    api.onToolbarCreate(toolbar => {
      I18n.translations.en.js.updated_timestamp = "Updated Timestamp";
      toolbar.addButton({
        id: "updated_button",
        group: "extras",
        icon: "clock-o",
        title: "updated_timestamp",
        perform: e => e.addText("_Updated " + new Date().toString().substring(0,21) + "_")
      });
    });
</script>

(Rob Meade) #8

wow - thanks for such a prompt response! Really appreciated…

I worked out (term used very loosely) the title: part from looking at the page source for the other icons, but wouldn’t have guessed the other line you’ve added - I will forward this on to our admins and see if they can update this for me.

Thank you so much - minor thing really, but will look so much better when I use it! (OCD = True) :smiley:


(cpradio) #9

Yeah, no worries. One thing to help explain it, the title attribute is looking for a translation entry with that key. So I simply created a key and assigned it the verbiage you wanted and then specified that key in the title attribute. :slight_smile:


(Rob Meade) #10

Thanks :slight_smile:

I didn’t even realise that there were language translations going on! Can’t wait to see this finished, it’s been really handy when updating existing posts rather than creating multiple replies :slight_smile: