Skip to content

Instantly share code, notes, and snippets.

@mikeknoop
Created February 23, 2012 22:07
Show Gist options
  • Save mikeknoop/1895318 to your computer and use it in GitHub Desktop.
Save mikeknoop/1895318 to your computer and use it in GitHub Desktop.
Backbone Chrome Extension Zap.coffee
define([
'jquery',
'use!underscore',
'use!backbone',
'mustache',
'text!template/zaps/__init__.html',
],
($, _, Backbone, MustacheWrapper, InitTemplate) ->
ZapsView = Backbone.View.extend
###
Zaps view
###
events:
'click a[data-action]': 'actionClick'
initialize: (options) ->
_.bindAll(@)
@render()
render: () ->
zapHtml: '<div>Hello World!</div>'
view =
zapHtml: zapHtml
@$el.html(Mustache.to_html(InitTemplate, view))
actionClick: (e) ->
# Callback handler for clicking an action item
action = $(e.currentTarget).attr('data-action')
zapId = $(e.currentTarget).attr('data-zap')
switch action
when 'run' then @run(zapId)
when 'pause' then @pause(zapId)
when 'unpause' then @unpause(zapId)
return false # cancel click
run: (id) ->
# Run the zap with the id specified
pause: (id) ->
# Puase the zap with the id specified
unpause: (id) ->
# Unpuase the zap with the id specified
unload: () ->
# This function called when the content view changes away from this view
return ZapsView
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment