diff --git a/core/client/app/components/gh-selectize.js b/core/client/app/components/gh-selectize.js new file mode 100644 index 0000000000..b540cd7971 --- /dev/null +++ b/core/client/app/components/gh-selectize.js @@ -0,0 +1,26 @@ +import Ember from 'ember'; +import EmberSelectizeComponent from 'ember-cli-selectize/components/ember-selectize'; + +export default EmberSelectizeComponent.extend({ + + /** + * Event callback that is triggered when user creates a tag + * - modified to pass the caret position to the action + */ + _create(input, callback) { + var caret = this._selectize.caretPos; + + // Delete user entered text + this._selectize.setTextboxValue(''); + // Send create action + + // allow the observers and computed properties to run first + Ember.run.schedule('actions', this, function () { + this.sendAction('create-item', input, caret); + }); + // We cancel the creation here, so it's up to you to include the created element + // in the content and selection property + callback(null); + } + +}); diff --git a/core/client/app/controllers/post-settings-menu.js b/core/client/app/controllers/post-settings-menu.js index 9e589dbed2..25bd0fdcd2 100644 --- a/core/client/app/controllers/post-settings-menu.js +++ b/core/client/app/controllers/post-settings-menu.js @@ -469,7 +469,7 @@ export default Ember.Controller.extend(SettingsMenuMixin, { }); }, - addTag: function (tagName) { + addTag: function (tagName, index) { var self = this, currentTags = this.get('model.tags'), currentTagNames = currentTags.map(function (tag) { return tag.get('name').toLowerCase(); }), @@ -500,7 +500,7 @@ export default Ember.Controller.extend(SettingsMenuMixin, { } // push tag onto post relationship - if (tagToAdd) { self.get('model.tags').pushObject(tagToAdd); } + if (tagToAdd) { self.get('model.tags').insertAt(index, tagToAdd); } }); }, diff --git a/core/client/app/templates/post-settings-menu.hbs b/core/client/app/templates/post-settings-menu.hbs index aa2715d05c..2c9f92c06b 100644 --- a/core/client/app/templates/post-settings-menu.hbs +++ b/core/client/app/templates/post-settings-menu.hbs @@ -35,7 +35,7 @@
- {{ember-selectize + {{gh-selectize id="tag-input" multiple=true selection=model.tags