# _slugify(string) if ! @_slugify @_slugify = (string) -> return string.toString().toLowerCase() .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 # ----------------------------------------------------------------------------- # INPUT HASH # ----------------------------------------------------------------------------- class @InputInverter constructor: (@name, @value, @config, @object) -> @_createEl() @inputs = {} for name, value of @value input = @_addInput(name, value, @config) @inputs[name] = input @$el.append input.$el return this _addInput: (name, value) -> inputConfig = $.extend {}, @config # get input label and type from name, e.g. "Page Title : text" labelAndType = name.split(' : ') # input label inputConfig.label = labelAndType[0].titleize() # input type inputType = labelAndType[1] inputType ?= @config.defaultInputType || 'text' inputType = $.trim(inputType) if ! _chrFormInputs[inputType] inputType = 'text' # input css class inputConfig.klassName = 'inverter-block-' + _slugify(inputConfig.label) inputConfig.klass ?= 'stacked' inputClass = _chrFormInputs[inputType] inputName = if @config.namePrefix then "#{ @config.namePrefix }#{ @name }[#{ name }]" else "#{ @name }[#{ name }]" inputConfig.namePrefix = @config.namePrefix return new inputClass(inputName, value, inputConfig, @object) _createEl: -> @$el =$ "