Skip to content

Commit 952e8dd

Browse files
committed
Fix JS related issue in ProTips pages
Move follow-widget UI logic into common file, run initializeProtip() at end.
1 parent 8751129 commit 952e8dd

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

app/assets/javascripts/backbone/views/ProtipGridView.js.coffee

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,12 @@ window.ProtipGridView = Backbone.View.extend(
9898
this.followingUsers = $('#x-following-users').data('users')
9999
this.followingTeams = $('#x-following-teams').data('teams')
100100

101-
markFollowings: ->
102-
$(follow).addClass('followed') for follow in $('.x-protip-pane .follow') when follow.attributes['data-value'].value in eval('this.following' + $(follow).data('follow-type'))
103-
104101
updateFollowList: (e)->
105102
list = eval('this.following' + $(e.target).data('follow-type'))
106103
entity = $(e.target).data('value')
107104
if $(e.target).hasClass('followed') then (list.filter (val) ->
108105
val is entity)
109106
else
110-
list.push entity
111-
this.markFollowed(e.target)
112-
113-
markFollowed: (el)->
114-
unless $(el).data('follow-type') == 'Network'
115-
$(el).toggleClass('followed')
107+
list.push entity
116108

117109
)

app/assets/javascripts/protips.js.coffee

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Place all the behaviors and hooks related to the matching controller here.
2-
# All this logic will automatically be available in application.js.
31
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
42
#= require marked
53
#= require highlight/highlight
@@ -63,6 +61,7 @@ window.initializeProtip = ->
6361
handle_redirect(response)
6462

6563
e.preventDefault()
64+
markFollowings()
6665
registerToggles()
6766
enableSearchBox()
6867
registerMoreHistory()
@@ -210,6 +209,12 @@ uploadFinished = (i, file, response, time)->
210209
$('#protip_body').val $('#protip_body').val() + markdown
211210
$("#dropzone").removeClass 'upload-in-progress'
212211

212+
getFollowings = (type)->
213+
$('#x-following-' + type.toLowerCase()).data(type.toLowerCase())
214+
215+
markFollowings = ->
216+
$(follow).addClass('followed') for follow in $('.x-protip-pane .follow') when follow.attributes['data-value'].value in getFollowings($(follow).data('follow-type'))
217+
213218
window.registerToggles = ->
214219
$('.upvote,.small-upvote').on 'click', ->
215220
if $(@).not('.upvoted').length == 1
@@ -224,9 +229,9 @@ window.registerToggles = ->
224229
$('.like').on 'click', ->
225230
$(@).addClass('liked')
226231
$(@).removeClass('not-liked')
227-
$('.follow-user').on 'click', ->
228-
$(@).addClass('following-user')
229-
$(@).removeClass('follow-user')
232+
$('.follow').on 'click', (e)->
233+
unless $(e.target).data('follow-type') == 'Network'
234+
$(e.target).toggleClass('followed')
230235

231236
enableSearchBox = ->
232237
$('.slidedown').on 'click', (e)->
@@ -358,4 +363,4 @@ enablePreviewEditing = ->
358363

359364
$('#protip_body').on 'keyup', updatePreview
360365

361-
updatePreview()
366+
updatePreview()

app/views/layouts/protip.html.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
%canvas.blur{ src: image_path(users_background_image) }
2929
= yield
3030

31+
#x-following-users.hide{'data-users' => current_user.following_users.map(&:username)}
32+
#x-following-networks.hide{'data-networks' => current_user.following_networks.map(&:slug)}
33+
#x-following-teams.hide{'data-teams' => current_user.teams_being_followed.map(&:name)}
34+
3135
- unless is_admin?
3236
:javascript
3337
window.console.log = function(){}

app/views/protips/show.js.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
$('#x-active-preview-pane').append('<%= escape_javascript(render partial: 'cacheable_protip', locals: { protip: @protip, mode: (@mode || params[:mode]), include_comments: true, job: @job }) %> ');
22
$('.dark-screen').height($('#x-active-preview-pane').height());
33
registerProtipClickOff();
4-
protipGrid.markFollowings();
5-
window.initializeProtip();
6-
hljs.highlightBlock($('#x-active-preview-pane')[0])
4+
hljs.highlightBlock($('#x-active-preview-pane')[0]);
5+
window.initializeProtip();

0 commit comments

Comments
 (0)