Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Autocomplete #132

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
88b5b64
First commit ( not done ).
peec Jul 13, 2015
daa6125
Fix keyDown actions on autocomplete input.
peec Jul 14, 2015
9558a8c
Working basic example of autocomplete.
peec Jul 14, 2015
5622431
More fixes
peec Jul 14, 2015
19bc95e
Fix lint
peec Jul 14, 2015
2db4f66
Cleanup code and add handlers for blurs/mousein/mouseout etc with res…
peec Jul 15, 2015
a39ac80
Add support for promise as source. Meaning support for ember-data, jQ…
peec Jul 15, 2015
e844262
Make it progress linear aware when its merged to master.
peec Jul 15, 2015
a5c983a
Implement: floating label, custom template and finish mostly everythi…
peec Jul 16, 2015
137e62b
Fixes lint
peec Jul 16, 2015
e6488f1
Refactor
peec Jul 16, 2015
9810fa2
cleanup, support normal array of strings, documentation of all public…
peec Jul 17, 2015
307dfe1
Fix semi
peec Jul 17, 2015
a7e109e
Fixes autocomplete paper-button by allowing configurable .md-button c…
peec Jul 17, 2015
2613903
Fixes for focus, add support for delay with debouncing state and loading
peec Jul 17, 2015
f1011a0
Support changing template for 'not found'. Thanks block params!
peec Jul 17, 2015
ad21b0a
Make not found template optional.
peec Jul 17, 2015
96dad23
Support allowNonExisting to support usecases of search engine.
peec Jul 18, 2015
2b18b26
Add disableScrolling features as service in util. This is needed when…
peec Jul 18, 2015
034dc0d
Finialize paper-autocomplete. Support the missing highlight feature.
peec Jul 18, 2015
85a8d66
Add all deps for paper-autocomplete-highlight computed property.
peec Jul 18, 2015
7edbffb
More documentation on the AJAX part.
peec Jul 18, 2015
0f225a8
Refactor and more docs
peec Jul 19, 2015
20604b9
Remove keyUp as its not used
peec Jul 19, 2015
9bc173e
Fix cached lookup
peec Jul 19, 2015
ea43ab2
Merged master
peec Jul 19, 2015
3d58b6a
Enable progress bar (since progress-linear was merged to master) and …
peec Jul 19, 2015
bf4d4c3
Merge branch 'master' into feature/autocomplete
peec Jul 20, 2015
fb3a755
Rewrite usage of multi yield in paper-autocomplete to be more declara…
peec Jul 20, 2015
c70e705
add test for paper-autocomplete-highlight.
peec Jul 20, 2015
bdb64a6
Add test for paper-autocomplete
peec Jul 20, 2015
09e01de
Instead of overriding paper-input, enhance paper-input and use that i…
peec Jul 20, 2015
bb3bf4f
Support setting not found message custom ( without the need of overri…
peec Jul 20, 2015
3c35e14
Refactor, decouple autocomplete components
peec Jul 20, 2015
64ae45f
Fixes sometimes not handle click if floating=true
peec Jul 20, 2015
6c03a6d
Cleanup + add test for paper-autocomplete-item
peec Jul 21, 2015
b733abc
Add tests for paper-autocomplete-list and refactor to decouple the co…
peec Jul 21, 2015
6c5ca34
Hidden is always true at first.
peec Jul 21, 2015
e74c5b0
Fix resize event
peec Jul 21, 2015
7cda4c1
Fix button themed for paper-button.
peec Jul 23, 2015
80e13dd
Autocomplete now use to='inverse' for better template that gives mean…
peec Jul 30, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions addon/components/paper-autocomplete-highlight.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import Ember from 'ember';

export default Ember.Component.extend({
tagName: 'span',
flags: '',

highlight: Ember.computed('searchText', 'label', 'flags', function () {
var unsafeText = Ember.Handlebars.Utils.escapeExpression(this.get('label')),
text = unsafeText,
flags = this.get('flags'),
regex = this.getRegExp(this.get('searchText'), flags),
html = text.replace(regex, '<span class="highlight">$&</span>');
return new Ember.Handlebars.SafeString(html);
}),

sanitize (term) {
if (!term) {
return term;
}
return term.replace(/[\\\^\$\*\+\?\.\(\)\|\{}\[\]]/g, '\\$&');
},

getRegExp (text, flags) {
var str = '';
if (flags.indexOf('^') >= 1) {
str += '^';
}
str += text;
if (flags.indexOf('$') >= 1) {
str += '$';
}
return new RegExp(this.sanitize(str), flags.replace(/[\$\^]/g, ''));
}

});
34 changes: 34 additions & 0 deletions addon/components/paper-autocomplete-item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Ember from 'ember';

export default Ember.Component.extend({
tagName: 'li',
attributeBindings: ['tabindex', 'role'],
classNameBindings: ['isSelected:selected'],
tabindex: 0,
role: 'option',


label: Ember.computed('item',function () {
return this.lookupLabelOfItem(this.get('item'));
}),

isSelected: Ember.computed('selectedIndex', function () {
return this.get('selectedIndex') === this.get('index');
}),

lookupLabelOfItem (model) {
var value;
if (this.get('lookupKey')) {
value = model[this.get('lookupKey')];
} else {
value = model;
}
return value;
},



click () {
this.sendAction('pick', this.get('item'));
}
});
124 changes: 124 additions & 0 deletions addon/components/paper-autocomplete-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import Ember from 'ember';

var ITEM_HEIGHT = 41,
MAX_HEIGHT = 5.5 * ITEM_HEIGHT,
MENU_PADDING = 8;

export default Ember.Component.extend({
util: Ember.inject.service(),

tagName: 'ul',
classNames: ['md-default-theme', 'md-autocomplete-suggestions', 'md-whiteframe-z1'],
attributeNameBindings: ['role'],
role: 'presentation',
stickToElement: null,

hidden: true,


isVisible: Ember.computed.not('hidden'),

mouseEnter () {
this.sendAction('mouse-enter');
},
mouseLeave () {
this.sendAction('mouse-leave');
},
mouseUp () {
this.sendAction('mouse-up');
},


hideSuggestionObserver: Ember.observer('hidden', function () {
if (this.get('hidden') === true) {
this.get('util').enableScrolling();
} else {
this.get('util').disableScrollAround(this.$());
this.positionDropdown();
}
}),


positionDropdown () {
var hrect = Ember.$('#' + this.get('wrapToElementId'))[0].getBoundingClientRect(),
vrect = hrect,
root = document.body.getBoundingClientRect(),
top = vrect.bottom - root.top,
bot = root.bottom - vrect.top,
left = hrect.left - root.left,
width = hrect.width,
styles = {
left: left + 'px',
minWidth: width + 'px',
maxWidth: Math.max(hrect.right - root.left, root.right - hrect.left) - MENU_PADDING + 'px'
},
ul = this.$();

if (top > bot && root.height - hrect.bottom - MENU_PADDING < MAX_HEIGHT) {
styles.top = 'auto';
styles.bottom = bot + 'px';
styles.maxHeight = Math.min(MAX_HEIGHT, hrect.top - root.top - MENU_PADDING) + 'px';
} else {
styles.top = top + 'px';
styles.bottom = 'auto';
styles.maxHeight = Math.min(MAX_HEIGHT, root.bottom - hrect.bottom - MENU_PADDING) + 'px';
}
ul.css(styles);
correctHorizontalAlignment();

/**
* Makes sure that the menu doesn't go off of the screen on either side.
*/
function correctHorizontalAlignment () {
var dropdown = ul[0].getBoundingClientRect(),
styles = {};
if (dropdown.right > root.right - MENU_PADDING) {
styles.left = (hrect.right - dropdown.width) + 'px';
}
ul.css(styles);
}
},


observeIndex: Ember.observer('selectedIndex', function () {
var suggestions = this.get('suggestions');
if (!suggestions[this.get('selectedIndex')]) {
return;
}

var ul = this.$(),
li = ul.find('li:eq('+this.get('selectedIndex')+')')[0],
top = li.offsetTop,
bot = top + li.offsetHeight,
hgt = ul[0].clientHeight;
if (top < ul[0].scrollTop) {
ul[0].scrollTop = top;
} else if (bot > ul[0].scrollTop + hgt) {
ul[0].scrollTop = bot - hgt;
}
}),

resizeWindowEvent ()  {
this.positionDropdown();
},


didInsertElement () {
var _self = this;
var ul = this.$().detach();
Ember.$('body').append(ul);

this.set('___resizeFunction', function () {
_self.positionDropdown();
});
Ember.$(window).on('resize', this.get('___resizeFunction'));
},
willDestroyElement () {
Ember.$(window).off('resize',this.get('___resizeFunction'));
this.get('util').enableScrolling();
}




});
Loading