Skip to content
Harold.Luo edited this page May 4, 2013 · 1 revision
  # Below is coffeescript

  # Functions set for handling and rendering the data.
  # Others developers can override these methods to tweak At.js such as matcher.
  # We can override them in `callbacks` settings.
  #
  # @mixin
  #
  # The context of these functions is `Controller` object and they are called in this sequences:
  #
  # [before_save, matcher, filter, remote_filter, sorter, tpl_evl, highlighter, before_insert]
  #
  DEFAULT_CALLBACKS =

    # It would be called to restrcture the data before At.js invoke `Model#save` to save data
    # In default, At.js will convert it to a Hash Array.
    #
    # @param data [Array] data to refacotor.
    # @return [Array] Data after refactor.
    before_save: (data) ->

    # It would be called to match the `flag`.
    # It will match at start of line or after whitespace
    #
    # @param flag [String] current `flag` ("@", etc)
    # @param subtext [String] Text from start to current caret position.
    #
    # @return [String | null] Matched result.
    matcher: (flag, subtext) ->

    # ---------------------

    # Filter data by matched string.
    #
    # @param query [String] Matched string.
    # @param data [Array] data list
    # @param search_key [String] key char for seaching.
    #
    # @return [Array] result data.
    filter: (query, data, search_key) ->

    # It function is given, At.js will invoke it if local filter can not find any data
    #
    # @param params [String] matched query
    # @param callback [Function] callback to render page.
    remote_filter: null
    # remote_filter: (query, callback) ->

    # Sorter data of course.
    #
    # @param query [String] matched string
    # @param items [Array] data that was refactored
    # @param search_key [String] key char to search
    #
    # @return [Array] sorted data
    sorter: (query, items, search_key) ->

    # Eval template for every single item in display list.
    #
    # @param tpl [String] The template string.
    # @param map [Hash] Data map to eval.
    tpl_eval: (tpl, map) ->

    # Hightlight the `matched query` string.
    #
    # @param li [String] HTML String after eval.
    # @param query [String] matched query.
    #
    # @return [String] hightlighted string.
    highlighter: (li, query) ->

    # What to do before insert item's value into inputor.
    #
    # @param value [String] content to insert
    # @param $li [jQuery Object] the chosen item
    before_insert: (value, $li) ->
Clone this wiki locally