From bda90f6b6b1bb393435832594e478189bd46f316 Mon Sep 17 00:00:00 2001 From: rolux Date: Thu, 5 Jul 2012 10:58:08 +0200 Subject: [PATCH] remove Ox.Break --- examples/maps/flight_paths/js/example.js | 6 +-- source/Ox.Geo/Ox.Geo.js | 6 +-- source/Ox.Image/Ox.Image.js | 8 ++-- source/Ox.UI/Ox.UI.js | 2 +- source/Ox.UI/js/Bar/Resizebar.js | 2 +- source/Ox.UI/js/Calendar/Calendar.js | 14 +++--- source/Ox.UI/js/Calendar/CalendarEditor.js | 10 +++-- source/Ox.UI/js/Code/DocPage.js | 2 +- source/Ox.UI/js/Code/DocPanel.js | 2 +- source/Ox.UI/js/Code/ExamplePanel.js | 2 +- source/Ox.UI/js/Core/Element.js | 3 +- source/Ox.UI/js/Core/Theme.js | 4 +- source/Ox.UI/js/Core/URL.js | 6 +-- source/Ox.UI/js/Form/Filter.js | 11 +++-- source/Ox.UI/js/Form/Form.js | 2 +- source/Ox.UI/js/Form/InputGroup.js | 4 +- source/Ox.UI/js/Form/OptionGroup.js | 2 +- source/Ox.UI/js/List/List.js | 10 +++-- source/Ox.UI/js/List/TableList.js | 11 +++-- source/Ox.UI/js/List/TreeList.js | 6 +-- source/Ox.UI/js/Map/MapEditor.js | 2 +- source/Ox.UI/js/Map/MapMarker.js | 2 +- source/Ox.UI/js/Menu/MainMenu.js | 6 ++- source/Ox.UI/js/Menu/Menu.js | 18 ++++---- source/Ox.UI/js/Panel/SplitPanel.js | 2 +- source/Ox.UI/js/Video/AnnotationPanel.js | 14 +++--- source/Ox.UI/js/Video/BlockVideoTimeline.js | 5 ++- source/Ox.UI/js/Video/SmallVideoTimeline.js | 2 +- source/Ox.UI/js/Video/VideoEditor.js | 10 +++-- source/Ox.UI/js/Video/VideoEditorPlayer.js | 2 +- source/Ox.UI/js/Video/VideoElement.js | 2 +- source/Ox.UI/js/Video/VideoPlayer.js | 8 ++-- source/Ox.UI/js/Video/VideoTimelinePlayer.js | 2 +- source/Ox.UI/js/Window/Dialog.js | 2 +- source/Ox/js/Array.js | 4 +- source/Ox/js/Async.js | 16 +++---- source/Ox/js/Collection.js | 47 ++++++++------------ source/Ox/js/Core.js | 25 ++--------- source/Ox/js/Format.js | 12 ++--- source/Ox/js/Geo.js | 11 +++-- source/Ox/js/JavaScript.js | 6 +-- source/Ox/js/Object.js | 2 +- source/Ox/js/String.js | 2 +- source/Ox/js/Type.js | 2 +- 44 files changed, 152 insertions(+), 165 deletions(-) diff --git a/examples/maps/flight_paths/js/example.js b/examples/maps/flight_paths/js/example.js index e366106b..a511b78c 100644 --- a/examples/maps/flight_paths/js/example.js +++ b/examples/maps/flight_paths/js/example.js @@ -87,10 +87,10 @@ Ox.load('Image', function() { parts[0].push({lat: lat, lng: lng[0]}); parts[1].unshift({lat: lat, lng: lng[1]}); /* - Ox.Break() breaks the loop. Again, note that this assumes no - path will cross the edge more than once. + Returning `false` breaks the loop. Again, note that this + assumes no path will cross the edge more than once. */ - Ox.Break(); + return false; } }); /* diff --git a/source/Ox.Geo/Ox.Geo.js b/source/Ox.Geo/Ox.Geo.js index 9400fb89..414a3b2c 100644 --- a/source/Ox.Geo/Ox.Geo.js +++ b/source/Ox.Geo/Ox.Geo.js @@ -154,7 +154,7 @@ Ox.load.Geo = function(options, callback) { Ox.forEach(Ox.COUNTRIES, function(c) { if (c.code == code) { country = c; - Ox.Break(); + return false; // break } }); return country; @@ -193,7 +193,7 @@ Ox.load.Geo = function(options, callback) { Ox.forEach(Ox.COUNTRIES, function(c) { if (name == c.name || name == c.googleName || name == c.imdbName) { country = c; - Ox.Break(); + return false; // break } }); return country; @@ -241,7 +241,7 @@ Ox.load.Geo = function(options, callback) { return language.toLowerCase(); }).indexOf(language) > -1) { country = c; - return false; + return false; // break } }); code = country ? country.flag || country.code : 'NTHH'; diff --git a/source/Ox.Image/Ox.Image.js b/source/Ox.Image/Ox.Image.js index c521f225..70af9170 100644 --- a/source/Ox.Image/Ox.Image.js +++ b/source/Ox.Image/Ox.Image.js @@ -441,14 +441,16 @@ Ox.load.Image = function(options, callback) { str = ''; } else { // After length more bytes, break - Ox.Break(); + return false; } } } }); - done == 2 && Ox.Break(); + // If done == 2, break + return done < 2; }); - done == 2 && Ox.Break(); + // If done == 2, break + return done < 2; } }, function() { try { diff --git a/source/Ox.UI/Ox.UI.js b/source/Ox.UI/Ox.UI.js index 0be39d66..62c8ac74 100644 --- a/source/Ox.UI/Ox.UI.js +++ b/source/Ox.UI/Ox.UI.js @@ -363,7 +363,7 @@ Ox.load.UI = function(options, callback) { && !/chrome/.test(userAgent) && !/linux/.test(userAgent) )) { format = f; - Ox.Break(); + return false; // break } } }); diff --git a/source/Ox.UI/js/Bar/Resizebar.js b/source/Ox.UI/js/Bar/Resizebar.js index be4e73fc..7a87a021 100644 --- a/source/Ox.UI/js/Bar/Resizebar.js +++ b/source/Ox.UI/js/Bar/Resizebar.js @@ -89,7 +89,7 @@ Ox.Resizebar = function(options, self) { Ox.forEach(self.options.resize, function(v) { if (self.options.size >= v - 8 && self.options.size <= v + 8) { self.options.size = v; - Ox.Break(); + return false; // break } }); if (self.options.size != size) { diff --git a/source/Ox.UI/js/Calendar/Calendar.js b/source/Ox.UI/js/Calendar/Calendar.js index 17a8d0f6..17a6ac35 100644 --- a/source/Ox.UI/js/Calendar/Calendar.js +++ b/source/Ox.UI/js/Calendar/Calendar.js @@ -737,7 +737,7 @@ Ox.Calendar = function(options, self) { Ox.forEach(self.options.events, function(v) { if (v.id == id) { event = v; - Ox.Break(); + return false; // break } }); return event; @@ -801,7 +801,7 @@ Ox.Calendar = function(options, self) { var $this = $(this); if ($this.data('id') == id) { $element = $this; - return false; + return false; // break } }); return $element; @@ -812,7 +812,7 @@ Ox.Calendar = function(options, self) { Ox.forEach(self.lineEvents, function(events, line_) { if (Ox.getIndexById(events, id) > -1) { line = line_; - Ox.Break(); + return false; // break } }); return line; @@ -852,12 +852,12 @@ Ox.Calendar = function(options, self) { // if overlaps, check next line if (overlaps(event, event_)) { fits = false; - Ox.Break(); + return false; // break } }); if (fits) { line = line_; - Ox.Break(); + return false; // break } }); if (line == self.lineEvents.length) { @@ -955,7 +955,7 @@ Ox.Calendar = function(options, self) { var width = Math.round(v.seconds * pixelsPerSecond); if (width >= self.minLabelWidth) { units = [self.units[i], self.units[i - 1]]; - Ox.Break(); + return false; // break } }); self.units.reverse(); @@ -1252,7 +1252,7 @@ Ox.Calendar = function(options, self) { var calendarDuration = getEventDuration(getCalendarEvent(z)); if (calendarDuration > eventDuration) { zoom = z; - return false; + return false; // break } }); return zoom; diff --git a/source/Ox.UI/js/Calendar/CalendarEditor.js b/source/Ox.UI/js/Calendar/CalendarEditor.js index 70694a8e..99a8869f 100644 --- a/source/Ox.UI/js/Calendar/CalendarEditor.js +++ b/source/Ox.UI/js/Calendar/CalendarEditor.js @@ -58,7 +58,7 @@ Ox.CalendarEditor = function(options, self) { if (eventDuration > duration) { iconSize = size; } else { - Ox.Break(); + return false; // break } }); return data.type @@ -399,10 +399,12 @@ Ox.CalendarEditor = function(options, self) { || event.alternativeNames.indexOf(data.data.value) > -1 )) { exists = value; - Ox.Break(); + return false; // break } }); - exists && Ox.Break(); + if (exists) { + return false; // break + } }); } if (data.id == 'name') { @@ -708,7 +710,7 @@ Ox.CalendarEditor = function(options, self) { || event.alternativeNames.indexOf(name) > -1 ) { exists = true; - Ox.Break(); + return false; // break } }); return exists; diff --git a/source/Ox.UI/js/Code/DocPage.js b/source/Ox.UI/js/Code/DocPage.js index 020f2689..cb4f615a 100644 --- a/source/Ox.UI/js/Code/DocPage.js +++ b/source/Ox.UI/js/Code/DocPage.js @@ -168,7 +168,7 @@ Ox.DocPage = function(options, self) { Ox.forEach(this.className.split(' '), function(v) { if (/Hidden$/.test(v)) { isHidden = true; - Ox.Break(); + return false; // break } }); !isHidden && $this.show(); diff --git a/source/Ox.UI/js/Code/DocPanel.js b/source/Ox.UI/js/Code/DocPanel.js index b5988cfd..0680af09 100644 --- a/source/Ox.UI/js/Code/DocPanel.js +++ b/source/Ox.UI/js/Code/DocPanel.js @@ -207,7 +207,7 @@ Ox.DocPanel = function(options, self) { Ox.forEach(self.options.items, function(v) { if (v.name == name) { item = v; - Ox.Break(); + return false; // break } }); return item; diff --git a/source/Ox.UI/js/Code/ExamplePanel.js b/source/Ox.UI/js/Code/ExamplePanel.js index 051d5187..9b69e7af 100644 --- a/source/Ox.UI/js/Code/ExamplePanel.js +++ b/source/Ox.UI/js/Code/ExamplePanel.js @@ -90,7 +90,7 @@ Ox.ExamplePanel = function(options, self) { Ox.forEach(self.items, function(v) { if (v.id.split('/').pop() == name) { item = v; - Ox.Break(); + return false; // break } }); return item; diff --git a/source/Ox.UI/js/Core/Element.js b/source/Ox.UI/js/Core/Element.js index f5edaaf9..17fa07a1 100644 --- a/source/Ox.UI/js/Core/Element.js +++ b/source/Ox.UI/js/Core/Element.js @@ -242,7 +242,8 @@ Ox.Element = function(options, self) { function update(key, value) { // update is called whenever an option is modified or added Ox.loop(self.updateCallbacks.length - 1, -1, -1, function(i) { - self.updateCallbacks[i](key, value) === false && Ox.Break(); + // break if the callback returns false + return self.updateCallbacks[i](key, value) !== false; }); } diff --git a/source/Ox.UI/js/Core/Theme.js b/source/Ox.UI/js/Core/Theme.js index 981db4f5..1be3ddc7 100644 --- a/source/Ox.UI/js/Core/Theme.js +++ b/source/Ox.UI/js/Core/Theme.js @@ -20,7 +20,7 @@ Ox.Theme = (function() { classNames && Ox.forEach(classNames.split(' '), function(className) { if (Ox.startsWith(className, 'OxTheme')) { theme = className.replace('OxTheme', '').toLowerCase(); - Ox.Break(); + return false; // break } }); return theme; @@ -101,7 +101,7 @@ Ox.Theme = (function() { background: $element_.css('background'), color: $element_.css('color') }); - Ox.Break(); + return false; // break } }); } diff --git a/source/Ox.UI/js/Core/URL.js b/source/Ox.UI/js/Core/URL.js index 0a97389e..6ec997f3 100644 --- a/source/Ox.UI/js/Core/URL.js +++ b/source/Ox.UI/js/Core/URL.js @@ -324,7 +324,7 @@ Ox.URL = function(options) { value: split.join(operator), operator: operator }; - Ox.Break(); + return false; // break } }); if ( @@ -521,7 +521,7 @@ Ox.URL = function(options) { state.view = view; state.span = span; parts.shift(); - Ox.Break(); + return false; // break } }); } @@ -581,7 +581,7 @@ Ox.URL = function(options) { // sort state.sort = parseSort(parts[0], state); parts.shift(); - Ox.Break(); + return false; // break } } ); diff --git a/source/Ox.UI/js/Form/Filter.js b/source/Ox.UI/js/Form/Filter.js index c841aca2..1b8658c4 100644 --- a/source/Ox.UI/js/Form/Filter.js +++ b/source/Ox.UI/js/Form/Filter.js @@ -395,7 +395,7 @@ Ox.Filter = function(options, self) { Ox.forEach(self.options.query.conditions, function(condition) { if (condition.conditions) { hasGroups = true; - Ox.Break(); + return false; // break } }); hasGroups && renderConditions(); @@ -424,12 +424,11 @@ Ox.Filter = function(options, self) { && ( self.options.query.operator == '&' ? ['', '^', '$'] : ['!', '!^', '!$'] ).indexOf(condition.operator) > -1 - && condition.value === '' - // FIXME: this used to be `return isUseless` - but was it intended - // to be the other way around, i.e. `isUseless && Ox.Break()`? - !isUseless && Ox.Break(); + && condition.value === ''; + if (!isUseless) { + return false; // break if one of the conditions is not useless + } }); - Ox.Log('Form', 'isUseless', isUseless); return isUseless; } diff --git a/source/Ox.UI/js/Form/Form.js b/source/Ox.UI/js/Form/Form.js index 4ba7498a..db301408 100644 --- a/source/Ox.UI/js/Form/Form.js +++ b/source/Ox.UI/js/Form/Form.js @@ -25,7 +25,7 @@ Ox.Form = function(options, self) { return Ox.every(valid); } }) - .options(options || {}) // fixme: the || {} can be done once, in the options function + .options(options || {}) .addClass('OxForm'); Ox.extend(self, { diff --git a/source/Ox.UI/js/Form/InputGroup.js b/source/Ox.UI/js/Form/InputGroup.js index 252574d6..f77a2e38 100644 --- a/source/Ox.UI/js/Form/InputGroup.js +++ b/source/Ox.UI/js/Form/InputGroup.js @@ -96,7 +96,7 @@ Ox.InputGroup = function(options, self) { Ox.forEach(self.options.inputs, function($input) { if ($input.focusInput) { $input.focusInput(true); - Ox.Break(); + return false; // break } }); } @@ -150,7 +150,7 @@ Ox.InputGroup = function(options, self) { Ox.forEach(self.options.inputs, function(v, i) { if (v.options('id') == self.options.id + Ox.toTitleCase(id)) { input = v; - Ox.Break(); + return false; // break } }); return input; diff --git a/source/Ox.UI/js/Form/OptionGroup.js b/source/Ox.UI/js/Form/OptionGroup.js index fe5614a3..0c71d678 100644 --- a/source/Ox.UI/js/Form/OptionGroup.js +++ b/source/Ox.UI/js/Form/OptionGroup.js @@ -28,7 +28,7 @@ Ox.OptionGroup = function(items, min, max, property) { ), function(v) { if (items[v][property]) { last = v; - Ox.Break(); + return false; // break } }); return last; diff --git a/source/Ox.UI/js/List/List.js b/source/Ox.UI/js/List/List.js index 79c30eb5..c48d8eba 100644 --- a/source/Ox.UI/js/List/List.js +++ b/source/Ox.UI/js/List/List.js @@ -652,7 +652,7 @@ Ox.List = function(options, self) { Ox.forEach(self.$items, function($item, i) { if ($item.options('data')[self.options.unique] == id) { pos = i; - Ox.Break(); + return false; // break } }); return pos; @@ -744,7 +744,7 @@ Ox.List = function(options, self) { ids.push(self.$items[pos].options('data')[self.options.unique]); } else { notFound = true; - Ox.Break(); + return false; // break } }); if (notFound) { @@ -1195,7 +1195,7 @@ Ox.List = function(options, self) { if (Ox.toLatin(v.title).toUpperCase().indexOf(str) == 0) { select(i); scrollToPosition(i); - Ox.Break(); + return false; // break } }); } @@ -1428,7 +1428,9 @@ Ox.List = function(options, self) { if (oldIds.indexOf(item.id) > -1) { newIds.push(item.id); } - newIds.length == oldIds.length && Ox.Break(); + if (newIds.length == oldIds.length) { + return false; // break + } }); setSelected(newIds); }); diff --git a/source/Ox.UI/js/List/TableList.js b/source/Ox.UI/js/List/TableList.js index bdfdb6c5..7880e46e 100644 --- a/source/Ox.UI/js/List/TableList.js +++ b/source/Ox.UI/js/List/TableList.js @@ -293,7 +293,7 @@ Ox.TableList = function(options, self) { index++; } else if (v.id == id) { column = v; - Ox.Break(); + return false; // break } }); column.visible = true; @@ -317,7 +317,7 @@ Ox.TableList = function(options, self) { if (!self.options.columns[index].visible) { addColumn(id); add = true; - Ox.Break(); + return false; // break } ids.push(id); }); @@ -325,7 +325,7 @@ Ox.TableList = function(options, self) { Ox.forEach(self.visibleColumns, function(column) { if (ids.indexOf(column.id) == -1) { removeColumn(column.id); - Ox.Break(); + return false; // break } }); } @@ -518,7 +518,7 @@ Ox.TableList = function(options, self) { var x = self.drag.listOffset + offset + self.columnWidths[i] / 2; if (i < self.drag.startPos && e.clientX < x) { self.drag.stopPos = i; - Ox.Break(); + return false; // break } else if (i > self.drag.startPos && e.clientX > x) { self.drag.stopPos = i; } @@ -643,13 +643,12 @@ Ox.TableList = function(options, self) { } function getItem(id) { - //Ox.Log('List', 'getItem', id) var $item = null; that.find('.OxItem').each(function() { var $this = $(this); if ($this.data('id') == id) { $item = $this; - return false; + return false; // break } }); return $item; diff --git a/source/Ox.UI/js/List/TreeList.js b/source/Ox.UI/js/List/TreeList.js index 736e5fbf..f2bf5ea1 100644 --- a/source/Ox.UI/js/List/TreeList.js +++ b/source/Ox.UI/js/List/TreeList.js @@ -146,12 +146,12 @@ Ox.TreeList = function(options, self) { ret = Ox.extend(item, { level: level }); - Ox.Break(); + return false; // break } if (item.items) { ret = getItemById(id, item.items, level + 1); if (ret) { - Ox.Break(); + return false; // break } } }); @@ -176,7 +176,7 @@ Ox.TreeList = function(options, self) { ret = getParent(id, item.items); } if (ret) { - Ox.Break(); + return false; // break } } }); diff --git a/source/Ox.UI/js/Map/MapEditor.js b/source/Ox.UI/js/Map/MapEditor.js index 0e7a43eb..9f4e1757 100644 --- a/source/Ox.UI/js/Map/MapEditor.js +++ b/source/Ox.UI/js/Map/MapEditor.js @@ -117,7 +117,7 @@ Ox.MapEditor = function(options, self) { if (data.area >= area) { iconSize = size; } else { - Ox.Break(); + return false; // break } }); return data.type diff --git a/source/Ox.UI/js/Map/MapMarker.js b/source/Ox.UI/js/Map/MapMarker.js index ed8069c1..6ad1551e 100644 --- a/source/Ox.UI/js/Map/MapMarker.js +++ b/source/Ox.UI/js/Map/MapMarker.js @@ -218,7 +218,7 @@ Ox.MapMarker = function(options) { if (that.place.area >= area) { that.size = size; } else { - Ox.Break(); + return false; // break } }); } else if (Ox.isNumber(size)) { diff --git a/source/Ox.UI/js/Menu/MainMenu.js b/source/Ox.UI/js/Menu/MainMenu.js index 20f046e0..781f5cdc 100644 --- a/source/Ox.UI/js/Menu/MainMenu.js +++ b/source/Ox.UI/js/Menu/MainMenu.js @@ -171,7 +171,9 @@ Ox.MainMenu = function(options, self) { if (ids.length == 1) { Ox.forEach(that.menus, function(menu) { item = menu.getItem(id); - item && Ox.Break(); + if (item) { + return false; // break + } }); } else { item = that.getMenu(ids.shift()).getItem(ids.join('_')); @@ -190,7 +192,7 @@ Ox.MainMenu = function(options, self) { Ox.forEach(that.menus, function(v) { if (v.options('id') == id) { menu = v; - Ox.Break(); + return false; // break } }); } else { diff --git a/source/Ox.UI/js/Menu/Menu.js b/source/Ox.UI/js/Menu/Menu.js index 57d74639..ff452608 100644 --- a/source/Ox.UI/js/Menu/Menu.js +++ b/source/Ox.UI/js/Menu/Menu.js @@ -208,7 +208,7 @@ Ox.Menu = function(options, self) { Ox.forEach(that.items, function(item, i) { if (item.options('id') == id) { position = i; - Ox.Break(); + return false; // break } }); return position; @@ -224,7 +224,7 @@ Ox.Menu = function(options, self) { Ox.forEach(that.items, function(item, i) { if (i < self.options.selected && !item.options('disabled')) { ret = false; - Ox.Break(); + return false; // break } }); return ret; @@ -235,7 +235,7 @@ Ox.Menu = function(options, self) { Ox.forEach(that.items, function(item, i) { if (i > self.options.selected && !item.options('disabled')) { ret = false; - Ox.Break(); + return false; // break } }); return ret; @@ -481,7 +481,7 @@ Ox.Menu = function(options, self) { Ox.forEach(that.submenus, function(submenu, id) { if (!submenu.is(':hidden')) { submenu.hideMenu(); - Ox.Break(); + return false; // break } }); item.options('items').length && that.submenus[item.options('id')].showMenu(); @@ -663,13 +663,15 @@ Ox.Menu = function(options, self) { Ox.forEach(that.items, function(v) { if (v.options('id') == id) { item = v; - Ox.Break(); + return false; // break } }); if (!item) { Ox.forEach(that.submenus, function(submenu) { item = submenu.getItem(id); - item && Ox.Break(); + if (item) { + return false; // break + } }); } } else { @@ -703,7 +705,7 @@ Ox.Menu = function(options, self) { Ox.forEach(that.items, function(item) { if (!item.options('disabled')) { ret = true; - Ox.Break(); + return false; // break } }); return ret; @@ -720,7 +722,7 @@ Ox.Menu = function(options, self) { Ox.forEach(that.submenus, function(submenu) { if (submenu.is(':visible')) { submenu.hideMenu(); - Ox.Break(); + return false; // break } }); selectItem(-1); diff --git a/source/Ox.UI/js/Panel/SplitPanel.js b/source/Ox.UI/js/Panel/SplitPanel.js index 1ef6eb1a..bd17acd2 100644 --- a/source/Ox.UI/js/Panel/SplitPanel.js +++ b/source/Ox.UI/js/Panel/SplitPanel.js @@ -101,7 +101,7 @@ Ox.SplitPanel = function(options, self) { Ox.forEach(self.options.elements, function(element, i) { if (element.element.options('id') == id) { position = i; - Ox.Break(); + return false; // break } }); return position; diff --git a/source/Ox.UI/js/Video/AnnotationPanel.js b/source/Ox.UI/js/Video/AnnotationPanel.js index eb0738cc..5342d2aa 100644 --- a/source/Ox.UI/js/Video/AnnotationPanel.js +++ b/source/Ox.UI/js/Video/AnnotationPanel.js @@ -228,10 +228,12 @@ Ox.AnnotationPanel = function(options, self) { if (item.id == annotationId) { annotation = item; found = true; - Ox.Break(); + return false; // break } }); - found && Ox.Break(); + if (found) { + return false; // break + } }); return annotation; } @@ -243,10 +245,12 @@ Ox.AnnotationPanel = function(options, self) { if (item.id == annotationId) { folder = self.$folder[i]; found = true; - Ox.Break(); + return false; // break } }); - found && Ox.Break(); + if (found) { + return false; // break + } }); return folder; } @@ -468,7 +472,7 @@ Ox.AnnotationPanel = function(options, self) { self.deselecting = true; $folder.options({selected: ''}); self.deselecting = false; - Ox.Break(); + return false; // break } }); scrollToSelected(self.options.layers[index].type); diff --git a/source/Ox.UI/js/Video/BlockVideoTimeline.js b/source/Ox.UI/js/Video/BlockVideoTimeline.js index 9e44199d..bfbc6369 100644 --- a/source/Ox.UI/js/Video/BlockVideoTimeline.js +++ b/source/Ox.UI/js/Video/BlockVideoTimeline.js @@ -168,7 +168,8 @@ Ox.BlockVideoTimeline = function(options, self) { } function getPosition(e) { - //FIXME: this might still be broken in opera according to http://acko.net/blog/mouse-handling-and-absolute-positions-in-javascript + // FIXME: this might still be broken in opera according to + // http://acko.net/blog/mouse-handling-and-absolute-positions-in-javascript return e.offsetX ? e.offsetX : e.clientX - $(e.target).offset().left; } @@ -178,7 +179,7 @@ Ox.BlockVideoTimeline = function(options, self) { Ox.forEach(self.options.subtitles, function(v) { if (v['in'] <= position && v.out > position) { subtitle = v; - Ox.Break(); + return false; // break } }); return subtitle; diff --git a/source/Ox.UI/js/Video/SmallVideoTimeline.js b/source/Ox.UI/js/Video/SmallVideoTimeline.js index 9dd325b9..7c722dab 100644 --- a/source/Ox.UI/js/Video/SmallVideoTimeline.js +++ b/source/Ox.UI/js/Video/SmallVideoTimeline.js @@ -155,7 +155,7 @@ Ox.SmallVideoTimeline = function(options, self) { Ox.forEach(self.options.subtitles, function(v) { if (v['in'] <= position && v.out > position) { subtitle = v; - Ox.Break(); + return false; // break } }); return subtitle; diff --git a/source/Ox.UI/js/Video/VideoEditor.js b/source/Ox.UI/js/Video/VideoEditor.js index 578e9494..0281e2cd 100644 --- a/source/Ox.UI/js/Video/VideoEditor.js +++ b/source/Ox.UI/js/Video/VideoEditor.js @@ -929,10 +929,12 @@ Ox.VideoEditor = function(options, self) { if (item.id == annotationId) { value = item.value; found = true; - Ox.Break(); + return false; // break } }); - found && Ox.Break(); + if (found) { + return false; // break + } }); return value; } @@ -983,7 +985,7 @@ Ox.VideoEditor = function(options, self) { ) { position = v; found = true; - Ox.Break(); + return false; // break } }); direction == -1 && positions.reverse(); @@ -1170,7 +1172,7 @@ Ox.VideoEditor = function(options, self) { 'in': i ? self.options.cuts[i - 1] : 0, out: cut - 1 / self.options.fps }; - Ox.Break(); + return false; // break } }); setPoint('in', points['in']); diff --git a/source/Ox.UI/js/Video/VideoEditorPlayer.js b/source/Ox.UI/js/Video/VideoEditorPlayer.js index 4a5fdddc..0c2f37aa 100644 --- a/source/Ox.UI/js/Video/VideoEditorPlayer.js +++ b/source/Ox.UI/js/Video/VideoEditorPlayer.js @@ -239,7 +239,7 @@ Ox.VideoEditorPlayer = function(options, self) { Ox.forEach(self.options.subtitles, function(v) { if (v['in'] <= self.options.position && v['out'] > self.options.position) { subtitle = v.value; - Ox.Break(); + return false; // break } }); return subtitle; diff --git a/source/Ox.UI/js/Video/VideoElement.js b/source/Ox.UI/js/Video/VideoElement.js index 30f5a65f..a05195bb 100644 --- a/source/Ox.UI/js/Video/VideoElement.js +++ b/source/Ox.UI/js/Video/VideoElement.js @@ -275,7 +275,7 @@ Ox.VideoElement = function(options, self) { if (item.offsets[i] <= time) { currentPart = i; currentTime = time - item.offsets[i]; - Ox.Break(); + return false; // break } }); Ox.Log('Video', 'sCT', time, currentPart, currentTime); diff --git a/source/Ox.UI/js/Video/VideoPlayer.js b/source/Ox.UI/js/Video/VideoPlayer.js index e7a0a1b0..a5d21d47 100644 --- a/source/Ox.UI/js/Video/VideoPlayer.js +++ b/source/Ox.UI/js/Video/VideoPlayer.js @@ -1290,7 +1290,7 @@ Ox.VideoPlayer = function(options, self) { && v.out > self.options.position ) { censored = true; - return false; + return false; // break } }); return censored; @@ -1468,7 +1468,7 @@ Ox.VideoPlayer = function(options, self) { && v.out >= self.options.position ) { subtitle = v.text; - return false; + return false; // break } }); return subtitle; @@ -1517,7 +1517,7 @@ Ox.VideoPlayer = function(options, self) { var left = 0; Ox.forEach(self.options.controlsBottom, function(control) { if (control == 'timeline') { - Ox.Break(); + return false; // break } left += control == 'position' ? self.positionWidth : 16 }); @@ -1600,7 +1600,7 @@ Ox.VideoPlayer = function(options, self) { ) { result = v found = true; - Ox.Break(); + return false; // break } }); direction == -1 && self.results.reverse(); diff --git a/source/Ox.UI/js/Video/VideoTimelinePlayer.js b/source/Ox.UI/js/Video/VideoTimelinePlayer.js index 424cc558..dfa12cca 100644 --- a/source/Ox.UI/js/Video/VideoTimelinePlayer.js +++ b/source/Ox.UI/js/Video/VideoTimelinePlayer.js @@ -507,7 +507,7 @@ Ox.VideoTimelinePlayer = function(options, self) { Ox.forEach(self.options.subtitles, function(v) { if (v['in'] <= position && v.out > position) { subtitle = v; - Ox.Break(); + return false; // break } }); return subtitle; diff --git a/source/Ox.UI/js/Window/Dialog.js b/source/Ox.UI/js/Window/Dialog.js index f7878e94..a4df6255 100644 --- a/source/Ox.UI/js/Window/Dialog.js +++ b/source/Ox.UI/js/Window/Dialog.js @@ -271,7 +271,7 @@ Ox.Dialog = function(options, self) { Ox.forEach(self.options.buttons, function(button) { if (button.options && button.options('id') == id) { ret = button; - Ox.Break(); + return false; // break } }); return ret; diff --git a/source/Ox/js/Array.js b/source/Ox/js/Array.js index 3570e7dc..ee36619a 100644 --- a/source/Ox/js/Array.js +++ b/source/Ox/js/Array.js @@ -381,7 +381,7 @@ Ox.api = function(items, options) { (query.operator == '&' && !match) || (query.operator == '|' && match) ) { - Ox.Break(); + return false; // break } }); return match; @@ -604,7 +604,7 @@ Ox.range = function() { length = article.length; sort[value] = sort[value].slice(length + 1) + ', ' + sort[value].slice(0, length); - Ox.Break(); + return false; // break } }); } else { diff --git a/source/Ox/js/Async.js b/source/Ox/js/Async.js index 75d9fa15..07291b34 100644 --- a/source/Ox/js/Async.js +++ b/source/Ox/js/Async.js @@ -60,17 +60,17 @@ function iterate() { Ox.forEach(keys.slice(i), function(key) { if (key in collection) { - try { - iterator.call(that, collection[key], key, collection); - } catch (error) { - if (error === Ox.BreakError) { - i = n; - } - throw error; + if (iterator.call( + that, collection[key], key, collection + ) === false) { + i = n; + return false; } } i++; - +new Date() >= time + ms && Ox.Break(); + if (+new Date() >= time + ms) { + return false; // break + } }); if (i < n) { setTimeout(function() { diff --git a/source/Ox/js/Collection.js b/source/Ox/js/Collection.js index ffb585c9..9613322e 100644 --- a/source/Ox/js/Collection.js +++ b/source/Ox/js/Collection.js @@ -148,10 +148,9 @@ Ox.filter = function(collection, iterator, that) { /*@ Ox.forEach forEach loop - `Ox.forEach` loops over arrays, objects and strings. Calling `Ox.Break` - inside the iterator or returning `false` from the iterator acts like a - `break` statement. Unlike `Array.prototype.forEach`, which leaks its counter - variable to the outer scope, `Ox.forEach` returns it. + `Ox.forEach` loops over arrays, objects and strings. Returning `false` from + the iterator acts like a `break` statement. Unlike `for`, which leaks its + counter variable to the outer scope, `Ox.forEach` returns it. (collection, iterator[, that]) -> Next index collection Collection iterator Iterator @@ -172,33 +171,23 @@ Ox.forEach forEach loop @*/ Ox.forEach = function(collection, iterator, that) { var i = 0, key, type = Ox.typeOf(collection); - try { - if (type == 'object' || type == 'storage') { - for (key in collection) { - if (Ox.hasOwn(collection, key)) { - // iterator.call(that, collection[key], key, collection); - if (iterator.call(that, collection[key], key, collection) === false) { - // console.warn('Returning false in Ox.forEach is deprecated.'); - break; - } - } - i++; - } - } else { - collection = Ox.toArray(collection); - for (i = 0; i < collection.length; i++) { - if (i in collection) { - // iterator.call(that, collection[i], i, collection); - if (iterator.call(that, collection[i], i, collection) === false) { - // console.warn('Returning false in Ox.forEach is deprecated.'); - break; - } + if (type == 'object' || type == 'storage') { + for (key in collection) { + if (Ox.hasOwn(collection, key)) { + if (iterator.call(that, collection[key], key, collection) === false) { + break; } } + i++; } - } catch (error) { - if (error !== Ox.BreakError) { - throw error; + } else { + collection = Ox.toArray(collection); + for (i = 0; i < collection.length; i++) { + if (i in collection) { + if (iterator.call(that, collection[i], i, collection) === false) { + break; + } + } } } return i; @@ -217,7 +206,7 @@ Ox.indexOf Returns the first index of a collection element that passes a tes @*/ Ox.indexOf = function(collection, test) { var index = Ox.forEach(collection, function(value) { - test(value) && Ox.Break(); + return !test(value); // break if test succeeds }); return Ox.isObject(collection) ? Object.keys(collection)[index] || null : index == collection.length ? -1 : index; diff --git a/source/Ox/js/Core.js b/source/Ox/js/Core.js index bf2685a9..30332d9b 100644 --- a/source/Ox/js/Core.js +++ b/source/Ox/js/Core.js @@ -84,15 +84,6 @@ this.Ox = function(value) { return Ox.wrap(value); }; -/*@ -Ox.Break Breaks from `Ox.forEach` and `Ox.loop` -@*/ -Ox.Break = function() { - throw Ox.BreakError; -}; - -Ox.BreakError = new SyntaxError('Illegal Ox.Break() statement'); - /*@ Ox.load Loads one or more modules A module named "Foo" provides `Ox.Foo/Ox.Foo.js`, in which it defines one @@ -283,7 +274,7 @@ Ox.loop For-loop, functional-style step Step value fn Iterator function i Counter value - > Ox.loop(10, function(i) { i == 4 && Ox.Break(); }) + > Ox.loop(10, function(i) { if (i == 4) { return false; } }) 4 > Ox.loop(0, 3, 2, function() {}) 4 @@ -295,17 +286,9 @@ Ox.loop = function() { step = length == 4 ? arguments[2] : (start <= stop ? 1 : -1), iterator = arguments[length - 1], i; - try { - for (i = start; step > 0 ? i < stop : i > stop; i += step) { - // iterator(i); - if (iterator(i) === false) { - // console.warn('Returning false in Ox.loop is deprecated.'); - break; - } - } - } catch (error) { - if (error !== Ox.BreakError) { - throw error; + for (i = start; step > 0 ? i < stop : i > stop; i += step) { + if (iterator(i) === false) { + break; } } return i; diff --git a/source/Ox/js/Format.js b/source/Ox/js/Format.js index 83e9532d..440acc4a 100644 --- a/source/Ox/js/Format.js +++ b/source/Ox/js/Format.js @@ -359,13 +359,13 @@ Ox.formatDateRange = function(start, end, utc) { if (precision[0] == precision[1]) { isOneUnit = true; Ox.loop(precision[0], function(i) { - if (i < precision[0] - 1 && parts[0][i] != parts[1][i]) { + if ( + (i < precision[0] - 1 && parts[0][i] != parts[1][i]) + || (i == precision[0] - 1 && parts[0][i] != parts[1][i] - 1) + ) { isOneUnit = false; + return false; // break } - if (i == precision[0] - 1 && parts[0][i] != parts[1][i] - 1) { - isOneUnit = false; - } - !isOneUnit && Ox.Break(); }); } if (isOneUnit) { @@ -706,7 +706,7 @@ Ox.formatValue = function(number, string, bin) { ret = Ox.formatNumber( number / Math.pow(base, index), index ? index - 1 : 0 ) + ' ' + prefix + (prefix && bin ? 'i' : '') + string; - Ox.Break(); + return false; // break } }); return ret; diff --git a/source/Ox/js/Geo.js b/source/Ox/js/Geo.js index b82b63bb..cc5759d9 100644 --- a/source/Ox/js/Geo.js +++ b/source/Ox/js/Geo.js @@ -252,8 +252,7 @@ // If an area crosses the dateline, // we split it into two parts, // west and east of the dateline - var areas = [areaA, areaB].map(splitArea), - ret; + var areas = [areaA, areaB].map(splitArea), ret; function contains(areaA, areaB) { return areaA.sw.lat <= areaB.sw.lat && areaA.sw.lng <= areaB.sw.lng @@ -266,10 +265,10 @@ Ox.forEach(areas[0], function(area0) { ret = contains(area0, area1); // Break if the outer part contains the inner part - ret && Ox.Break(); + return !ret; }); // Break if no outer part contains the inner part - !ret && Ox.Break(); + return ret; }); return ret; }; @@ -327,7 +326,7 @@ : Ox.joinAreas(intersections); } if (ret === null) { - Ox.Break(); + return false; // break } else { ret = splitArea(ret); } @@ -378,7 +377,7 @@ Ox.forEach(gaps, function(gap, i) { if (Ox.containsArea(gap, area)) { ret = i; - Ox.Break(); + return false; // break } }); return ret; diff --git a/source/Ox/js/JavaScript.js b/source/Ox/js/JavaScript.js index 39ee29a1..17b115dc 100644 --- a/source/Ox/js/JavaScript.js +++ b/source/Ox/js/JavaScript.js @@ -185,7 +185,7 @@ Ox.doc = (function() { Ox.forEach(item.returns, function(v) { if (v['class']) { constructors.push(item); - Ox.Break(); + return false; // break } }); } @@ -654,7 +654,7 @@ Ox.identify = (function() { Ox.forEach(identifiers, function(words, type) { if (words.indexOf(identifier) > -1) { ret = type; - Ox.Break(); + return false; // break } }); } @@ -874,7 +874,7 @@ Ox.test = function(argument, callback) { if (v.tests[statement]) { id = k; test = v.tests[statement]; - Ox.Break(); + return false; // break } }); Ox.test.data[id].results.push(Ox.extend(test, { diff --git a/source/Ox/js/Object.js b/source/Ox/js/Object.js index c05b4480..d3ddb9ec 100644 --- a/source/Ox/js/Object.js +++ b/source/Ox/js/Object.js @@ -96,7 +96,7 @@ Ox.keyOf = function(object, value) { Ox.forEach(object, function(v, k) { if (v === value) { key = k; - Ox.Break(); + return false; // break } }); return key; diff --git a/source/Ox/js/String.js b/source/Ox/js/String.js index 12751400..99567b1d 100644 --- a/source/Ox/js/String.js +++ b/source/Ox/js/String.js @@ -358,7 +358,7 @@ Ox.parseUserAgent = function(userAgent) { string: string, version: versions[version] || version }; - Ox.Break(); + return false; // break } }); }); diff --git a/source/Ox/js/Type.js b/source/Ox/js/Type.js index 38d47fcd..ce4c0f41 100644 --- a/source/Ox/js/Type.js +++ b/source/Ox/js/Type.js @@ -178,7 +178,7 @@ Ox.isEqual = function(a, b) { ret = true; Ox.forEach(a, function(value, key) { ret = Ox.isEqual(value, b[key]); - !ret && Ox.Break(); + return ret; // break if not equal }); } }