Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Created June 9, 2014 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save j-mcnally/f67966a6a0be6f3ece18 to your computer and use it in GitHub Desktop.
Save j-mcnally/f67966a6a0be6f3ece18 to your computer and use it in GitHub Desktop.
EmberJS Component
xtokeninput = Ember.Component.extend
tagName: 'input'
classNames: []
jsonRoot: null
baseURL: ""
tokenValue: 'id'
tokens: []
# Setting tokens externally
updateValue: (->
this.$().tokenInput('clear')
tokens = this.$().val().split(",")
for token in tokens
this.$().tokenInput('add', {id: token, name: token}) if $.trim(token) != ""
).observes('value')
updateTokens: (->
this.set('value', this.get('tokens').join(","))
).observes('tokens')
changeHandler: ->
values = $.map this.$().tokenInput("get"),
(o) =>
o[this.tokenValue]
this.set('tokens', values)
_initializeTokenInput: (->
self = this
this.$().tokenInput(
this.get("baseURL") + this.get("dataSourceURL"),
crossDomain: false
jsonContainer: this.get('jsonRoot')
theme: 'dewey'
tokenValue: this.get('tokenValue')
onAdd: ->
self.changeHandler()
onDelete: ->
self.changeHandler()
onResult: (item) ->
container_root = self.get('jsonRoot')
container = item
container = container['tags'] if (container_root != null)
inputVal = self.$().parent().find('tester').text()
inputObject = {id: inputVal, name: inputVal}
if container.length <= 0
item = []
item['tags'] = [inputObject]
else
unless item['tags'][0]['name'] is inputVal
item['tags'].unshift inputObject
return item
)
).on('didInsertElement')
`export default xtokeninput`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment