app/assets/javascripts/inputs/inverter.coffee in inverter-0.4.7 vs app/assets/javascripts/inputs/inverter.coffee in inverter-0.5.0
- old
+ new
@@ -1,14 +1,9 @@
# -----------------------------------------------------------------------------
# Author: Alexander Kravets <alex@slatestudio.com>,
# Slate Studio (http://www.slatestudio.com)
-#
-# Coding Guide:
-# https://github.com/thoughtbot/guides/tree/master/style/coffeescript
# -----------------------------------------------------------------------------
-
-# -----------------------------------------------------------------------------
# INPUT INVERTER
# -----------------------------------------------------------------------------
# _slugify(string)
if ! @_slugify
@@ -17,11 +12,10 @@
.replace(/\s+/g, '-') # Replace spaces with -
.replace(/[^\w\-]+/g, '') # Remove all non-word chars
.replace(/\-\-+/g, '-') # Replace multiple - with single -
.trim() # Trim - from start/end of text
-
class @InputInverter
constructor: (@name, @value, @config, @object) ->
@startsWith = @config.startsWith
@_create_el()
@@ -32,17 +26,15 @@
@inputs[name] = input
@$el.append input.$el
return this
+ # PRIVATE ===================================================================
- # PRIVATE ===============================================
-
_create_el: ->
@$el =$ "<div class='input-#{ @config.type } #{ @config.klassName }'>"
-
_add_input: (name, value) ->
inputConfig = $.extend {}, @config
# get input label and type from name, e.g. "Page Title : text"
labelAndType = name.split(' : ')
@@ -53,11 +45,11 @@
# input type
inputType = labelAndType[1]
inputType ?= @config.defaultInputType || 'text'
inputType = $.trim(inputType)
- if ! chr.formInputs[inputType]
+ if ! formagicInputs[inputType]
inputType = 'text'
if @startsWith
# update label if @startsWith is used
inputConfig.label = inputConfig.label.replace(@startsWith, '').titleize()
@@ -68,11 +60,11 @@
# input css class
inputConfig.klassName = 'inverter-block-' + _slugify(inputConfig.label)
inputConfig.klass ?= 'stacked'
- inputClass = chr.formInputs[inputType]
+ inputClass = formagicInputs[inputType]
# here we have @config.namePrefix undefined, so the second case works
# where @name is [_blocks] and name is the name of the block
inputName = if @config.namePrefix then "#{ @config.namePrefix }#{ @name }[#{ name }]" else "#{ @name }[#{ name }]"
inputConfig.namePrefix = @config.namePrefix
@@ -80,42 +72,32 @@
# function to work properly
inputConfig.blockName = name
return new inputClass(inputName, value, inputConfig, @object)
+ # PUBLIC ====================================================================
- # PUBLIC ================================================
-
initialize: ->
for name, input of @inputs
input.initialize()
@config.onInitialize?(this)
-
hash: (hash={}) ->
obj = {}
# workaround for using block names to have consistency
# while caching and versioning documents
for key, input of @inputs
obj[input.config.blockName] = input.$input.val()
hash[@config.klassName] = obj
return hash
-
updateValue: (@value) ->
for key, input of @inputs
input.updateValue(@value[key])
-
showErrorMessage: (message) -> ;
-
hideErrorMessage: -> ;
-
-chr.formInputs['inverter'] = InputInverter
-
-
-
-
+formagicInputs['inverter'] = InputInverter