Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The Future of post.js?

During my adventures through the old and new templates I eventually developed a lot of hate for a file by the innocent name of post.js. As I understand, it was mainly just carried over from CNPROG. Well, I'm sure these guys had their reasons, but two things bother me:

  • AskBot uses JQuery, post.js however could be written much more efficiently exploiting all of jQuery's features.
  • More importantly: requirements on the site's structure are hard coded into post.js, for example it wants me to use a span with class delete-icon for the delete comment element, but an a tag with edit class for the edit comment action. Where's the consistency in that? It is for example currently impossible to place the comment-button outside the area where the actual comments are displayed, as the javascript will examine the context of the button to find out where to display the widget.

I would propose slowly rewrite post.js to be independent of the site's structure by using the HTML5 data- attribute. That way we can define the behaviour _in the template_ without touching javascript, ie. by

<li class="list-button" data-action="upvote" data-source="{{ post.id }}">Like</li>
...
<span data-role="vote-counter" data-source="{{ post.id }}">...</span>

The script will then dynamically link methods to the elements containing the respective data-action and outputs to the elements defined by data-role. Downside is that this takes a bit longer, but employing jQuery's full power should make up for that. What's your opinion on post.js?

The Future of post.js?

During my adventures through the old and new templates I eventually developed a lot of hate for a file by the innocent name of post.js. As I understand, it was mainly just carried over from CNPROG. Well, I'm sure these guys had their reasons, but two things bother me:

  • AskBot uses JQuery, post.js however could be written much more efficiently exploiting all of jQuery's features.
  • More importantly: requirements on the site's structure are hard coded into post.js, for example it wants me to use a span with class delete-icon for the delete comment element, but an a tag with edit class for the edit comment action. Where's the consistency in that? It is for example currently impossible to place the comment-button outside the area where the actual comments are displayed, as the javascript will examine the context of the button to find out where to display the widget.

I would propose slowly rewrite post.js to be independent of the site's structure by using the HTML5 data- attribute. That way we can define the behaviour _in the template_ without touching javascript, ie. by

<li class="list-button" data-action="upvote" data-source="{{ post.id }}">Like</li>
...
<span data-role="vote-counter" data-source="{{ post.id }}">...</span>

The script will then dynamically link methods to the elements containing the respective data-action and outputs to the elements defined by data-role. Downside is that this takes a bit longer, but employing jQuery's full power should make up for that. What's your opinion on post.js?

__Edit:__ _Separated possible solution into an answer to facilitate discussion._