better Ox.find() (return exact match first)
This commit is contained in:
parent
0fc5299bda
commit
28138cc446
3 changed files with 11 additions and 17 deletions
|
@ -155,7 +155,6 @@ Ox.VideoEditor = function(options, self) {
|
|||
}).map(function(obj) {
|
||||
return obj.word;
|
||||
});
|
||||
Ox.print('WORDS', self.words)
|
||||
|
||||
self.$editor = new Ox.Element()
|
||||
.addClass('OxVideoEditor')
|
||||
|
|
|
@ -1326,7 +1326,7 @@ Ox.VideoPlayer = function(options, self) {
|
|||
$element.hide().css({opacity: 1});
|
||||
});
|
||||
});
|
||||
self.options.fullscreen && hideControls();
|
||||
//self.options.fullscreen && hideControls();
|
||||
}
|
||||
|
||||
function hideControls() {
|
||||
|
|
23
source/Ox.js
23
source/Ox.js
|
@ -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')
|
||||
[['foo', 'foobar'], ['barfoo']]
|
||||
@*/
|
||||
Ox.find = function(arr, str) {
|
||||
/*
|
||||
returns an array with two arrays as elements:
|
||||
an array of elements of arr that begin with str,
|
||||
and an array of elements of arr that contain,
|
||||
but do not begin with str
|
||||
*/
|
||||
var arrLowerCase = arr.map(function(v) {
|
||||
var ret = [[], []];
|
||||
str = str.toLowerCase();
|
||||
arr.map(function(v) {
|
||||
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]);
|
||||
}).forEach(function(v, i) {
|
||||
var index = v.indexOf(str);
|
||||
index > -1 && ret[index == 0 ? 0 : 1][v == str ? 'unshift' : 'push'](arr[i]);
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
/*@
|
||||
Ox.forEach <f> forEach loop
|
||||
<code>Ox.forEach()</code> loops over arrays, objects and strings.
|
||||
|
|
Loading…
Reference in a new issue