2
1
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2023-12-13 21:00:40 +01:00

Merge pull request #6222 from kevinansfield/remove-ember-on

Remove use of Ember.on
This commit is contained in:
Hannah Wolfe 2016-01-12 21:09:00 +00:00
commit 563a085c42
4 changed files with 50 additions and 37 deletions

View file

@ -1,6 +1,6 @@
import Ember from 'ember';
const {Component, on, run} = Ember;
const {Component, run} = Ember;
export default Component.extend({
tagName: 'li',
@ -8,9 +8,9 @@ export default Component.extend({
active: false,
linkClasses: null,
unfocusLink: on('click', function () {
click() {
this.$('a').blur();
}),
},
actions: {
setActive(value) {

View file

@ -2,7 +2,7 @@
import Ember from 'ember';
import EmberSelectizeComponent from 'ember-cli-selectize/components/ember-selectize';
const {computed, isArray, isBlank, get, on, run} = Ember;
const {computed, isArray, isBlank, get, run} = Ember;
const emberA = Ember.A;
export default EmberSelectizeComponent.extend({
@ -15,28 +15,6 @@ export default EmberSelectizeComponent.extend({
return options;
}),
_dontOpenWhenBlank: on('didInsertElement', function () {
let openOnFocus = this.get('openOnFocus');
if (!openOnFocus) {
run.schedule('afterRender', this, function () {
let selectize = this._selectize;
if (selectize) {
selectize.on('dropdown_open', function () {
if (isBlank(selectize.$control_input.val())) {
selectize.close();
}
});
selectize.on('type', function (filter) {
if (isBlank(filter)) {
selectize.close();
}
});
}
});
}
}),
/**
* Event callback that is triggered when user creates a tag
* - modified to pass the caret position to the action
@ -105,9 +83,7 @@ export default EmberSelectizeComponent.extend({
// we have a re-order, update the selection
args.forEach((value) => {
let obj = selection.find(function (item) {
// jscs:disable
return (get(item, valuePath) + '') === value;
// jscs:enable
return `${get(item, valuePath)}` === value;
});
if (obj) {
@ -116,6 +92,33 @@ export default EmberSelectizeComponent.extend({
});
this.set('selection', reorderedSelection);
},
_preventOpeningWhenBlank() {
let openOnFocus = this.get('openOnFocus');
if (!openOnFocus) {
run.schedule('afterRender', this, function () {
let selectize = this._selectize;
if (selectize) {
selectize.on('dropdown_open', function () {
if (isBlank(selectize.$control_input.val())) {
selectize.close();
}
});
selectize.on('type', function (filter) {
if (isBlank(filter)) {
selectize.close();
}
});
}
});
}
},
didInsertElement() {
this._super(...arguments);
this._preventOpeningWhenBlank();
}
});

View file

@ -1,7 +1,7 @@
/*jshint scripturl:true*/
import Ember from 'ember';
const {$, Component, on} = Ember;
const {$, Component} = Ember;
export default Component.extend({
tagName: 'a',
@ -15,7 +15,7 @@ export default Component.extend({
// anchor behaviors or ignored
href: Ember.String.htmlSafe('javascript:;'),
scrollTo: on('click', function () {
click() {
let anchor = this.get('anchor');
let $el = Ember.$(anchor);
@ -32,5 +32,5 @@ export default Component.extend({
$(this).removeAttr('tabindex');
}).focus();
}
})
}
});

View file

@ -1,7 +1,7 @@
/*global device*/
import Ember from 'ember';
const {TextField, computed, on} = Ember;
const {TextField, computed} = Ember;
export default TextField.extend({
focus: true,
@ -16,16 +16,26 @@ export default TextField.extend({
return false;
}),
focusField: on('didInsertElement', function () {
_focusField() {
// This fix is required until Mobile Safari has reliable
// autofocus, select() or focus() support
if (this.get('focus') && !device.ios()) {
this.$().val(this.$().val()).focus();
}
}),
},
trimValue: on('focusOut', function () {
_trimValue() {
let text = this.$().val();
this.$().val(text.trim());
})
},
didInsertElement() {
this._super(...arguments);
this._focusField();
},
focusOut() {
this._super(...arguments);
this._trimValue();
}
});