Sha256: 085e1271da71b4b2a275500b7261c0596a70646a93e3ff4e5df4ee0251e74c19

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

this.FK = FK = FrontKit =

  updaters: []

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

  meta: (id) ->
    @Driver.meta(id)

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

  ready: (callback) ->
    @Driver.onready(callback)

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

  update: (element=document) ->
    @log "Running application update on: ", element
    for updater in @updaters
      updater.call null, @Driver.prepare(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) ->
    FK.Driver.extend this, state

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

    value

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
frontkit-rails-0.0.0 vendor/assets/javascripts/fk/fk.js.coffee