Skip to content

Instantly share code, notes, and snippets.

Created December 16, 2014 15:05
Show Gist options
  • Save anonymous/749f37045f85454b680e to your computer and use it in GitHub Desktop.
Save anonymous/749f37045f85454b680e to your computer and use it in GitHub Desktop.
A quick Backbone.View to handle a sort caret icon; depends on FontAwesome.
class App.Views.SortCaret extends Backbone.View
tagName: 'span'
classname: 'sort-caret-container'
downCaret: 'fa-caret-down'
upCaret: 'fa-caret-up'
constructor: (options = {}) ->
this.downCaret = options.downCaret if options.downCaret
this.upCaret = options.upCaret if options.upCaret
super(options)
render: () ->
this._insertIcon()
this.setDownCaret()
return this
setDownCaret: () -> this._setCaret this.downCaret, this.upCaret
setUpCaret: () -> this._setCaret this.upCaret, this.downCaret
_insertIcon: () ->
@icon = $('<i class="sort-caret fa" />')
this.$el.html @icon
return
_setCaret: (addCaret, removeCaret) ->
@icon.removeClass removeCaret
@icon.addClass addCaret
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment