Skip to content

Commit

Permalink
[#2304] Tidy up follow button attributes
Browse files Browse the repository at this point in the history
Use HTML5 data- attributes
  • Loading branch information
Sean Hammond committed May 9, 2012
1 parent f094b16 commit 53951fc
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions ckan/public/scripts/application.js
Expand Up @@ -1406,25 +1406,25 @@ CKAN.Utils = function($, my) {
function followButtonClicked(event) {
var button = event.currentTarget;
if (button.id === 'user_follow_button') {
var object_id = button.attributes.user_id.nodeValue;
var object_id = button.getAttribute('data-user-id');
var object_type = 'user';
} else if (button.id === 'dataset_follow_button') {
var object_id = button.attributes.dataset_id.nodeValue;
var object_id = button.getAttribute('data-dataset-id');
var object_type = 'dataset';
}
else {
// This shouldn't happen.
return;
}
if (button.attributes.state.nodeValue === "follow") {
if (button.getAttribute('data-state') === "follow") {
var url = '/api/action/follower_create';
var data = JSON.stringify({
object_id: object_id,
object_type: object_type,
});
var nextState = 'unfollow';
var nextString = 'Unfollow';
} else if (button.attributes.state.nodeValue === "unfollow") {
} else if (button.getAttribute('data-state') === "unfollow") {
var url = '/api/action/follower_delete';
var data = JSON.stringify({
id: object_id,
Expand All @@ -1444,7 +1444,7 @@ CKAN.Utils = function($, my) {
processData: false,
type: 'POST',
success: function(data) {
button.attributes.state.nodeValue = nextState;
button.setAttribute('data-state', nextState);
button.innerHTML = nextString;
},
});
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/package/layout.html
Expand Up @@ -59,8 +59,8 @@
</li>
<li py:if="c.authorized_to_follow" style="float:right;">
<py:choose test="c.pkg_dict.am_following">
<a py:when="True" dataset_id="${c.pkg.id}" state="unfollow" id="dataset_follow_button" class="btn btn-mini">Unfollow</a>
<a py:otherwise="" dataset_id="${c.pkg.id}" state="follow" id="dataset_follow_button" class="btn btn-mini">Follow</a>
<a py:when="True" id="dataset_follow_button" class="btn btn-mini" data-dataset-id="${c.pkg.id}" data-state="unfollow">Unfollow</a>
<a py:otherwise="" id="dataset_follow_button" class="btn btn-mini" data-dataset-id="${c.pkg.id}" data-state="follow">Follow</a>
</py:choose>
</li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions ckan/templates/user/layout.html
Expand Up @@ -24,8 +24,8 @@
<li class="${'active' if c.action=='read' else ''}"><a href="${h.url_for(controller='user', action='read', id=c.user_dict.name)}">View Profile</a></li>
<li style="float:right;" py:if="c.authorized_to_follow">
<py:choose test="c.user_dict.am_following">
<a py:when="True" user_id="${c.user_dict.id}" id="user_follow_button" state="unfollow" class="btn btn-mini">Unfollow</a>
<a py:otherwise="" user_id="${c.user_dict.id}" id="user_follow_button" state="follow" class="btn btn-mini">Follow</a>
<a py:when="True" id="user_follow_button" class="btn btn-mini" data-user-id="${c.user_dict.id}" data-state="unfollow">Unfollow</a>
<a py:otherwise="" id="user_follow_button" class="btn btn-mini" data-user-id="${c.user_dict.id}" data-state="follow">Follow</a>
</py:choose>
</li>
<li style="float:right;" class="${'active' if c.action=='followers' else ''}">
Expand Down

0 comments on commit 53951fc

Please sign in to comment.