summaryrefslogtreecommitdiffstats
path: root/debian/missing-sources/epoch/src/adapters/jQuery.coffee
blob: e115bade6d58e1d16064ddfd804e2ee60ef7870d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
jQueryModule = ($) ->
  # Data key to use for storing a reference to the chart instance on an element.
  DATA_NAME = 'epoch-chart'

  # Adds an Epoch chart of the given type to the referenced element.
  # @param [Object] options Options for the chart.
  # @option options [String] type The type of chart to append to the referenced element.
  # @return [Object] The chart instance that was associated with the containing element.
  $.fn.epoch = (options) ->
    options.el = @get(0)
    unless (chart = @data(DATA_NAME))?
      klass = Epoch._typeMap[options.type]
      unless klass?
        Epoch.exception "Unknown chart type '#{options.type}'"
      @data DATA_NAME, (chart = new klass options)
    return chart

jQueryModule(jQuery) if window.jQuery?