Sha256: 9d48ff0e40b7b51faf6fc552cddb9ba69ec98caff54a9d4265f92e75fe86c76d

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

this.FK = FK = FrontKit =

  updaters: []

  decode: (str) ->
    JSON.parse(Base64.decode64(str))

  encode: (object) ->
    Base64.encode64(JSON.stringify(object))

  meta: (id) ->
    jQuery("""meta[property="#{id}"]""").attr('content')

  log: (args...) ->
    args.unshift('FK:')
    console.log(args...)

  ready: (callback) -> jQuery(callback)

  push: (callback) ->
    @updaters.push(callback)

  update: (element=document) ->
    @log "Running application update on: ", element
    for updater in @updaters
      updater.call null, jQuery(element)

  init: ->
    if content = @meta('fk:state')
      gotState = true
      content = @decode(content)
    else
      development = !!window.location.port ||
        /\.(?:dev|local)$/.test window.location.hostname ||
        'localhost' == window.location.hostname
      content = { production: !development }

    @state = new State(content)

    console.disable() if !!@state.production

    if gotState
      @log 'Got application state: ', @state
    else
      @log 'No application state detected'

    this.ready -> FK.update()

class State
  constructor: (state) ->
    jQuery.extend this, state

  get: (path) ->
    for chunk in path.split('.')
      value = (value or this)[chunk]
      return null unless value?

    value

FK.init()

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
frontkit-rails-0.0.5 vendor/assets/javascripts/fk/fk.js.coffee
frontkit-rails-0.0.4 vendor/assets/javascripts/fk/fk.js.coffee
frontkit-rails-0.0.3 vendor/assets/javascripts/fk/fk.js.coffee