From 28138cc446aa8eea341770e6bcf2652f35c5865b Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 20 May 2011 07:56:42 +0200 Subject: [PATCH] better Ox.find() (return exact match first) --- source/Ox.UI/js/Video/Ox.VideoEditor.js | 1 - source/Ox.UI/js/Video/Ox.VideoPlayer.js | 2 +- source/Ox.js | 25 ++++++++++--------------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/source/Ox.UI/js/Video/Ox.VideoEditor.js b/source/Ox.UI/js/Video/Ox.VideoEditor.js index acd11fd6..23befced 100644 --- a/source/Ox.UI/js/Video/Ox.VideoEditor.js +++ b/source/Ox.UI/js/Video/Ox.VideoEditor.js @@ -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') diff --git a/source/Ox.UI/js/Video/Ox.VideoPlayer.js b/source/Ox.UI/js/Video/Ox.VideoPlayer.js index 321c8c6d..ed3e5cf5 100644 --- a/source/Ox.UI/js/Video/Ox.VideoPlayer.js +++ b/source/Ox.UI/js/Video/Ox.VideoPlayer.js @@ -1326,7 +1326,7 @@ Ox.VideoPlayer = function(options, self) { $element.hide().css({opacity: 1}); }); }); - self.options.fullscreen && hideControls(); + //self.options.fullscreen && hideControls(); } function hideControls() { diff --git a/source/Ox.js b/source/Ox.js index 82249f20..1ed8ef24 100644 --- a/source/Ox.js +++ b/source/Ox.js @@ -397,29 +397,24 @@ Ox.filter = function(obj, fn) { }; /*@ -Ox.find Returns array elements that match a string, leading matches first +Ox.find 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) { - 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]); + var ret = [[], []]; + str = str.toLowerCase(); + arr.map(function(v) { + return v.toLowerCase(); + }).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 forEach loop Ox.forEach() loops over arrays, objects and strings.