better Ox.find() (return exact match first)

This commit is contained in:
rolux 2011-05-20 07:56:42 +02:00
parent 0fc5299bda
commit 28138cc446
3 changed files with 11 additions and 17 deletions

View file

@ -155,7 +155,6 @@ Ox.VideoEditor = function(options, self) {
}).map(function(obj) { }).map(function(obj) {
return obj.word; return obj.word;
}); });
Ox.print('WORDS', self.words)
self.$editor = new Ox.Element() self.$editor = new Ox.Element()
.addClass('OxVideoEditor') .addClass('OxVideoEditor')

View file

@ -1326,7 +1326,7 @@ Ox.VideoPlayer = function(options, self) {
$element.hide().css({opacity: 1}); $element.hide().css({opacity: 1});
}); });
}); });
self.options.fullscreen && hideControls(); //self.options.fullscreen && hideControls();
} }
function hideControls() { function hideControls() {

View file

@ -397,29 +397,24 @@ Ox.filter = function(obj, fn) {
}; };
/*@ /*@
Ox.find <f> Returns array elements that match a string, leading matches first Ox.find <f> Returns array elements that match a string
Returns an array of two arrays, the first containing leading matches
(exact match first), the second containing non-leading matches
> Ox.find(['foo', 'bar', 'foobar', 'barfoo'], 'foo') > Ox.find(['foo', 'bar', 'foobar', 'barfoo'], 'foo')
[['foo', 'foobar'], ['barfoo']] [['foo', 'foobar'], ['barfoo']]
@*/ @*/
Ox.find = function(arr, str) { Ox.find = function(arr, str) {
/* var ret = [[], []];
returns an array with two arrays as elements: str = str.toLowerCase();
an array of elements of arr that begin with str, arr.map(function(v) {
and an array of elements of arr that contain, return v.toLowerCase();
but do not begin with str }).forEach(function(v, i) {
*/ var index = v.indexOf(str);
var arrLowerCase = arr.map(function(v) { index > -1 && ret[index == 0 ? 0 : 1][v == str ? 'unshift' : 'push'](arr[i]);
return v.toLowerCase();
}),
ret = [[], []];
str && arrLowerCase.forEach(function(v, i) {
var index = v.indexOf(str.toLowerCase());
index > -1 && ret[index == 0 ? 0 : 1].push(arr[i]);
}); });
return ret; return ret;
}; };
/*@ /*@
Ox.forEach <f> forEach loop Ox.forEach <f> forEach loop
<code>Ox.forEach()</code> loops over arrays, objects and strings. <code>Ox.forEach()</code> loops over arrays, objects and strings.