remove Ox.Break

This commit is contained in:
rolux 2012-07-05 10:58:08 +02:00
parent 4139e171ca
commit bda90f6b6b
44 changed files with 152 additions and 165 deletions

View file

@ -87,10 +87,10 @@ Ox.load('Image', function() {
parts[0].push({lat: lat, lng: lng[0]}); parts[0].push({lat: lat, lng: lng[0]});
parts[1].unshift({lat: lat, lng: lng[1]}); parts[1].unshift({lat: lat, lng: lng[1]});
/* /*
Ox.Break() breaks the loop. Again, note that this assumes no Returning `false` breaks the loop. Again, note that this
path will cross the edge more than once. assumes no path will cross the edge more than once.
*/ */
Ox.Break(); return false;
} }
}); });
/* /*

View file

@ -154,7 +154,7 @@ Ox.load.Geo = function(options, callback) {
Ox.forEach(Ox.COUNTRIES, function(c) { Ox.forEach(Ox.COUNTRIES, function(c) {
if (c.code == code) { if (c.code == code) {
country = c; country = c;
Ox.Break(); return false; // break
} }
}); });
return country; return country;
@ -193,7 +193,7 @@ Ox.load.Geo = function(options, callback) {
Ox.forEach(Ox.COUNTRIES, function(c) { Ox.forEach(Ox.COUNTRIES, function(c) {
if (name == c.name || name == c.googleName || name == c.imdbName) { if (name == c.name || name == c.googleName || name == c.imdbName) {
country = c; country = c;
Ox.Break(); return false; // break
} }
}); });
return country; return country;
@ -241,7 +241,7 @@ Ox.load.Geo = function(options, callback) {
return language.toLowerCase(); return language.toLowerCase();
}).indexOf(language) > -1) { }).indexOf(language) > -1) {
country = c; country = c;
return false; return false; // break
} }
}); });
code = country ? country.flag || country.code : 'NTHH'; code = country ? country.flag || country.code : 'NTHH';

View file

@ -441,14 +441,16 @@ Ox.load.Image = function(options, callback) {
str = ''; str = '';
} else { } else {
// After length more bytes, break // 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() { }, function() {
try { try {

View file

@ -363,7 +363,7 @@ Ox.load.UI = function(options, callback) {
&& !/chrome/.test(userAgent) && !/linux/.test(userAgent) && !/chrome/.test(userAgent) && !/linux/.test(userAgent)
)) { )) {
format = f; format = f;
Ox.Break(); return false; // break
} }
} }
}); });

View file

@ -89,7 +89,7 @@ Ox.Resizebar = function(options, self) {
Ox.forEach(self.options.resize, function(v) { Ox.forEach(self.options.resize, function(v) {
if (self.options.size >= v - 8 && self.options.size <= v + 8) { if (self.options.size >= v - 8 && self.options.size <= v + 8) {
self.options.size = v; self.options.size = v;
Ox.Break(); return false; // break
} }
}); });
if (self.options.size != size) { if (self.options.size != size) {

View file

@ -737,7 +737,7 @@ Ox.Calendar = function(options, self) {
Ox.forEach(self.options.events, function(v) { Ox.forEach(self.options.events, function(v) {
if (v.id == id) { if (v.id == id) {
event = v; event = v;
Ox.Break(); return false; // break
} }
}); });
return event; return event;
@ -801,7 +801,7 @@ Ox.Calendar = function(options, self) {
var $this = $(this); var $this = $(this);
if ($this.data('id') == id) { if ($this.data('id') == id) {
$element = $this; $element = $this;
return false; return false; // break
} }
}); });
return $element; return $element;
@ -812,7 +812,7 @@ Ox.Calendar = function(options, self) {
Ox.forEach(self.lineEvents, function(events, line_) { Ox.forEach(self.lineEvents, function(events, line_) {
if (Ox.getIndexById(events, id) > -1) { if (Ox.getIndexById(events, id) > -1) {
line = line_; line = line_;
Ox.Break(); return false; // break
} }
}); });
return line; return line;
@ -852,12 +852,12 @@ Ox.Calendar = function(options, self) {
// if overlaps, check next line // if overlaps, check next line
if (overlaps(event, event_)) { if (overlaps(event, event_)) {
fits = false; fits = false;
Ox.Break(); return false; // break
} }
}); });
if (fits) { if (fits) {
line = line_; line = line_;
Ox.Break(); return false; // break
} }
}); });
if (line == self.lineEvents.length) { if (line == self.lineEvents.length) {
@ -955,7 +955,7 @@ Ox.Calendar = function(options, self) {
var width = Math.round(v.seconds * pixelsPerSecond); var width = Math.round(v.seconds * pixelsPerSecond);
if (width >= self.minLabelWidth) { if (width >= self.minLabelWidth) {
units = [self.units[i], self.units[i - 1]]; units = [self.units[i], self.units[i - 1]];
Ox.Break(); return false; // break
} }
}); });
self.units.reverse(); self.units.reverse();
@ -1252,7 +1252,7 @@ Ox.Calendar = function(options, self) {
var calendarDuration = getEventDuration(getCalendarEvent(z)); var calendarDuration = getEventDuration(getCalendarEvent(z));
if (calendarDuration > eventDuration) { if (calendarDuration > eventDuration) {
zoom = z; zoom = z;
return false; return false; // break
} }
}); });
return zoom; return zoom;

View file

@ -58,7 +58,7 @@ Ox.CalendarEditor = function(options, self) {
if (eventDuration > duration) { if (eventDuration > duration) {
iconSize = size; iconSize = size;
} else { } else {
Ox.Break(); return false; // break
} }
}); });
return data.type return data.type
@ -399,10 +399,12 @@ Ox.CalendarEditor = function(options, self) {
|| event.alternativeNames.indexOf(data.data.value) > -1 || event.alternativeNames.indexOf(data.data.value) > -1
)) { )) {
exists = value; exists = value;
Ox.Break(); return false; // break
} }
}); });
exists && Ox.Break(); if (exists) {
return false; // break
}
}); });
} }
if (data.id == 'name') { if (data.id == 'name') {
@ -708,7 +710,7 @@ Ox.CalendarEditor = function(options, self) {
|| event.alternativeNames.indexOf(name) > -1 || event.alternativeNames.indexOf(name) > -1
) { ) {
exists = true; exists = true;
Ox.Break(); return false; // break
} }
}); });
return exists; return exists;

View file

@ -168,7 +168,7 @@ Ox.DocPage = function(options, self) {
Ox.forEach(this.className.split(' '), function(v) { Ox.forEach(this.className.split(' '), function(v) {
if (/Hidden$/.test(v)) { if (/Hidden$/.test(v)) {
isHidden = true; isHidden = true;
Ox.Break(); return false; // break
} }
}); });
!isHidden && $this.show(); !isHidden && $this.show();

View file

@ -207,7 +207,7 @@ Ox.DocPanel = function(options, self) {
Ox.forEach(self.options.items, function(v) { Ox.forEach(self.options.items, function(v) {
if (v.name == name) { if (v.name == name) {
item = v; item = v;
Ox.Break(); return false; // break
} }
}); });
return item; return item;

View file

@ -90,7 +90,7 @@ Ox.ExamplePanel = function(options, self) {
Ox.forEach(self.items, function(v) { Ox.forEach(self.items, function(v) {
if (v.id.split('/').pop() == name) { if (v.id.split('/').pop() == name) {
item = v; item = v;
Ox.Break(); return false; // break
} }
}); });
return item; return item;

View file

@ -242,7 +242,8 @@ Ox.Element = function(options, self) {
function update(key, value) { function update(key, value) {
// update is called whenever an option is modified or added // update is called whenever an option is modified or added
Ox.loop(self.updateCallbacks.length - 1, -1, -1, function(i) { 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;
}); });
} }

View file

@ -20,7 +20,7 @@ Ox.Theme = (function() {
classNames && Ox.forEach(classNames.split(' '), function(className) { classNames && Ox.forEach(classNames.split(' '), function(className) {
if (Ox.startsWith(className, 'OxTheme')) { if (Ox.startsWith(className, 'OxTheme')) {
theme = className.replace('OxTheme', '').toLowerCase(); theme = className.replace('OxTheme', '').toLowerCase();
Ox.Break(); return false; // break
} }
}); });
return theme; return theme;
@ -101,7 +101,7 @@ Ox.Theme = (function() {
background: $element_.css('background'), background: $element_.css('background'),
color: $element_.css('color') color: $element_.css('color')
}); });
Ox.Break(); return false; // break
} }
}); });
} }

View file

@ -324,7 +324,7 @@ Ox.URL = function(options) {
value: split.join(operator), value: split.join(operator),
operator: operator operator: operator
}; };
Ox.Break(); return false; // break
} }
}); });
if ( if (
@ -521,7 +521,7 @@ Ox.URL = function(options) {
state.view = view; state.view = view;
state.span = span; state.span = span;
parts.shift(); parts.shift();
Ox.Break(); return false; // break
} }
}); });
} }
@ -581,7 +581,7 @@ Ox.URL = function(options) {
// sort // sort
state.sort = parseSort(parts[0], state); state.sort = parseSort(parts[0], state);
parts.shift(); parts.shift();
Ox.Break(); return false; // break
} }
} }
); );

View file

@ -395,7 +395,7 @@ Ox.Filter = function(options, self) {
Ox.forEach(self.options.query.conditions, function(condition) { Ox.forEach(self.options.query.conditions, function(condition) {
if (condition.conditions) { if (condition.conditions) {
hasGroups = true; hasGroups = true;
Ox.Break(); return false; // break
} }
}); });
hasGroups && renderConditions(); hasGroups && renderConditions();
@ -424,12 +424,11 @@ Ox.Filter = function(options, self) {
&& ( && (
self.options.query.operator == '&' ? ['', '^', '$'] : ['!', '!^', '!$'] self.options.query.operator == '&' ? ['', '^', '$'] : ['!', '!^', '!$']
).indexOf(condition.operator) > -1 ).indexOf(condition.operator) > -1
&& condition.value === '' && condition.value === '';
// FIXME: this used to be `return isUseless` - but was it intended if (!isUseless) {
// to be the other way around, i.e. `isUseless && Ox.Break()`? return false; // break if one of the conditions is not useless
!isUseless && Ox.Break(); }
}); });
Ox.Log('Form', 'isUseless', isUseless);
return isUseless; return isUseless;
} }

View file

@ -25,7 +25,7 @@ Ox.Form = function(options, self) {
return Ox.every(valid); return Ox.every(valid);
} }
}) })
.options(options || {}) // fixme: the || {} can be done once, in the options function .options(options || {})
.addClass('OxForm'); .addClass('OxForm');
Ox.extend(self, { Ox.extend(self, {

View file

@ -96,7 +96,7 @@ Ox.InputGroup = function(options, self) {
Ox.forEach(self.options.inputs, function($input) { Ox.forEach(self.options.inputs, function($input) {
if ($input.focusInput) { if ($input.focusInput) {
$input.focusInput(true); $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) { Ox.forEach(self.options.inputs, function(v, i) {
if (v.options('id') == self.options.id + Ox.toTitleCase(id)) { if (v.options('id') == self.options.id + Ox.toTitleCase(id)) {
input = v; input = v;
Ox.Break(); return false; // break
} }
}); });
return input; return input;

View file

@ -28,7 +28,7 @@ Ox.OptionGroup = function(items, min, max, property) {
), function(v) { ), function(v) {
if (items[v][property]) { if (items[v][property]) {
last = v; last = v;
Ox.Break(); return false; // break
} }
}); });
return last; return last;

View file

@ -652,7 +652,7 @@ Ox.List = function(options, self) {
Ox.forEach(self.$items, function($item, i) { Ox.forEach(self.$items, function($item, i) {
if ($item.options('data')[self.options.unique] == id) { if ($item.options('data')[self.options.unique] == id) {
pos = i; pos = i;
Ox.Break(); return false; // break
} }
}); });
return pos; return pos;
@ -744,7 +744,7 @@ Ox.List = function(options, self) {
ids.push(self.$items[pos].options('data')[self.options.unique]); ids.push(self.$items[pos].options('data')[self.options.unique]);
} else { } else {
notFound = true; notFound = true;
Ox.Break(); return false; // break
} }
}); });
if (notFound) { if (notFound) {
@ -1195,7 +1195,7 @@ Ox.List = function(options, self) {
if (Ox.toLatin(v.title).toUpperCase().indexOf(str) == 0) { if (Ox.toLatin(v.title).toUpperCase().indexOf(str) == 0) {
select(i); select(i);
scrollToPosition(i); scrollToPosition(i);
Ox.Break(); return false; // break
} }
}); });
} }
@ -1428,7 +1428,9 @@ Ox.List = function(options, self) {
if (oldIds.indexOf(item.id) > -1) { if (oldIds.indexOf(item.id) > -1) {
newIds.push(item.id); newIds.push(item.id);
} }
newIds.length == oldIds.length && Ox.Break(); if (newIds.length == oldIds.length) {
return false; // break
}
}); });
setSelected(newIds); setSelected(newIds);
}); });

View file

@ -293,7 +293,7 @@ Ox.TableList = function(options, self) {
index++; index++;
} else if (v.id == id) { } else if (v.id == id) {
column = v; column = v;
Ox.Break(); return false; // break
} }
}); });
column.visible = true; column.visible = true;
@ -317,7 +317,7 @@ Ox.TableList = function(options, self) {
if (!self.options.columns[index].visible) { if (!self.options.columns[index].visible) {
addColumn(id); addColumn(id);
add = true; add = true;
Ox.Break(); return false; // break
} }
ids.push(id); ids.push(id);
}); });
@ -325,7 +325,7 @@ Ox.TableList = function(options, self) {
Ox.forEach(self.visibleColumns, function(column) { Ox.forEach(self.visibleColumns, function(column) {
if (ids.indexOf(column.id) == -1) { if (ids.indexOf(column.id) == -1) {
removeColumn(column.id); 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; var x = self.drag.listOffset + offset + self.columnWidths[i] / 2;
if (i < self.drag.startPos && e.clientX < x) { if (i < self.drag.startPos && e.clientX < x) {
self.drag.stopPos = i; self.drag.stopPos = i;
Ox.Break(); return false; // break
} else if (i > self.drag.startPos && e.clientX > x) { } else if (i > self.drag.startPos && e.clientX > x) {
self.drag.stopPos = i; self.drag.stopPos = i;
} }
@ -643,13 +643,12 @@ Ox.TableList = function(options, self) {
} }
function getItem(id) { function getItem(id) {
//Ox.Log('List', 'getItem', id)
var $item = null; var $item = null;
that.find('.OxItem').each(function() { that.find('.OxItem').each(function() {
var $this = $(this); var $this = $(this);
if ($this.data('id') == id) { if ($this.data('id') == id) {
$item = $this; $item = $this;
return false; return false; // break
} }
}); });
return $item; return $item;

View file

@ -146,12 +146,12 @@ Ox.TreeList = function(options, self) {
ret = Ox.extend(item, { ret = Ox.extend(item, {
level: level level: level
}); });
Ox.Break(); return false; // break
} }
if (item.items) { if (item.items) {
ret = getItemById(id, item.items, level + 1); ret = getItemById(id, item.items, level + 1);
if (ret) { if (ret) {
Ox.Break(); return false; // break
} }
} }
}); });
@ -176,7 +176,7 @@ Ox.TreeList = function(options, self) {
ret = getParent(id, item.items); ret = getParent(id, item.items);
} }
if (ret) { if (ret) {
Ox.Break(); return false; // break
} }
} }
}); });

View file

@ -117,7 +117,7 @@ Ox.MapEditor = function(options, self) {
if (data.area >= area) { if (data.area >= area) {
iconSize = size; iconSize = size;
} else { } else {
Ox.Break(); return false; // break
} }
}); });
return data.type return data.type

View file

@ -218,7 +218,7 @@ Ox.MapMarker = function(options) {
if (that.place.area >= area) { if (that.place.area >= area) {
that.size = size; that.size = size;
} else { } else {
Ox.Break(); return false; // break
} }
}); });
} else if (Ox.isNumber(size)) { } else if (Ox.isNumber(size)) {

View file

@ -171,7 +171,9 @@ Ox.MainMenu = function(options, self) {
if (ids.length == 1) { if (ids.length == 1) {
Ox.forEach(that.menus, function(menu) { Ox.forEach(that.menus, function(menu) {
item = menu.getItem(id); item = menu.getItem(id);
item && Ox.Break(); if (item) {
return false; // break
}
}); });
} else { } else {
item = that.getMenu(ids.shift()).getItem(ids.join('_')); item = that.getMenu(ids.shift()).getItem(ids.join('_'));
@ -190,7 +192,7 @@ Ox.MainMenu = function(options, self) {
Ox.forEach(that.menus, function(v) { Ox.forEach(that.menus, function(v) {
if (v.options('id') == id) { if (v.options('id') == id) {
menu = v; menu = v;
Ox.Break(); return false; // break
} }
}); });
} else { } else {

View file

@ -208,7 +208,7 @@ Ox.Menu = function(options, self) {
Ox.forEach(that.items, function(item, i) { Ox.forEach(that.items, function(item, i) {
if (item.options('id') == id) { if (item.options('id') == id) {
position = i; position = i;
Ox.Break(); return false; // break
} }
}); });
return position; return position;
@ -224,7 +224,7 @@ Ox.Menu = function(options, self) {
Ox.forEach(that.items, function(item, i) { Ox.forEach(that.items, function(item, i) {
if (i < self.options.selected && !item.options('disabled')) { if (i < self.options.selected && !item.options('disabled')) {
ret = false; ret = false;
Ox.Break(); return false; // break
} }
}); });
return ret; return ret;
@ -235,7 +235,7 @@ Ox.Menu = function(options, self) {
Ox.forEach(that.items, function(item, i) { Ox.forEach(that.items, function(item, i) {
if (i > self.options.selected && !item.options('disabled')) { if (i > self.options.selected && !item.options('disabled')) {
ret = false; ret = false;
Ox.Break(); return false; // break
} }
}); });
return ret; return ret;
@ -481,7 +481,7 @@ Ox.Menu = function(options, self) {
Ox.forEach(that.submenus, function(submenu, id) { Ox.forEach(that.submenus, function(submenu, id) {
if (!submenu.is(':hidden')) { if (!submenu.is(':hidden')) {
submenu.hideMenu(); submenu.hideMenu();
Ox.Break(); return false; // break
} }
}); });
item.options('items').length && that.submenus[item.options('id')].showMenu(); 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) { Ox.forEach(that.items, function(v) {
if (v.options('id') == id) { if (v.options('id') == id) {
item = v; item = v;
Ox.Break(); return false; // break
} }
}); });
if (!item) { if (!item) {
Ox.forEach(that.submenus, function(submenu) { Ox.forEach(that.submenus, function(submenu) {
item = submenu.getItem(id); item = submenu.getItem(id);
item && Ox.Break(); if (item) {
return false; // break
}
}); });
} }
} else { } else {
@ -703,7 +705,7 @@ Ox.Menu = function(options, self) {
Ox.forEach(that.items, function(item) { Ox.forEach(that.items, function(item) {
if (!item.options('disabled')) { if (!item.options('disabled')) {
ret = true; ret = true;
Ox.Break(); return false; // break
} }
}); });
return ret; return ret;
@ -720,7 +722,7 @@ Ox.Menu = function(options, self) {
Ox.forEach(that.submenus, function(submenu) { Ox.forEach(that.submenus, function(submenu) {
if (submenu.is(':visible')) { if (submenu.is(':visible')) {
submenu.hideMenu(); submenu.hideMenu();
Ox.Break(); return false; // break
} }
}); });
selectItem(-1); selectItem(-1);

View file

@ -101,7 +101,7 @@ Ox.SplitPanel = function(options, self) {
Ox.forEach(self.options.elements, function(element, i) { Ox.forEach(self.options.elements, function(element, i) {
if (element.element.options('id') == id) { if (element.element.options('id') == id) {
position = i; position = i;
Ox.Break(); return false; // break
} }
}); });
return position; return position;

View file

@ -228,10 +228,12 @@ Ox.AnnotationPanel = function(options, self) {
if (item.id == annotationId) { if (item.id == annotationId) {
annotation = item; annotation = item;
found = true; found = true;
Ox.Break(); return false; // break
} }
}); });
found && Ox.Break(); if (found) {
return false; // break
}
}); });
return annotation; return annotation;
} }
@ -243,10 +245,12 @@ Ox.AnnotationPanel = function(options, self) {
if (item.id == annotationId) { if (item.id == annotationId) {
folder = self.$folder[i]; folder = self.$folder[i];
found = true; found = true;
Ox.Break(); return false; // break
} }
}); });
found && Ox.Break(); if (found) {
return false; // break
}
}); });
return folder; return folder;
} }
@ -468,7 +472,7 @@ Ox.AnnotationPanel = function(options, self) {
self.deselecting = true; self.deselecting = true;
$folder.options({selected: ''}); $folder.options({selected: ''});
self.deselecting = false; self.deselecting = false;
Ox.Break(); return false; // break
} }
}); });
scrollToSelected(self.options.layers[index].type); scrollToSelected(self.options.layers[index].type);

View file

@ -168,7 +168,8 @@ Ox.BlockVideoTimeline = function(options, self) {
} }
function getPosition(e) { 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 return e.offsetX ? e.offsetX
: e.clientX - $(e.target).offset().left; : e.clientX - $(e.target).offset().left;
} }
@ -178,7 +179,7 @@ Ox.BlockVideoTimeline = function(options, self) {
Ox.forEach(self.options.subtitles, function(v) { Ox.forEach(self.options.subtitles, function(v) {
if (v['in'] <= position && v.out > position) { if (v['in'] <= position && v.out > position) {
subtitle = v; subtitle = v;
Ox.Break(); return false; // break
} }
}); });
return subtitle; return subtitle;

View file

@ -155,7 +155,7 @@ Ox.SmallVideoTimeline = function(options, self) {
Ox.forEach(self.options.subtitles, function(v) { Ox.forEach(self.options.subtitles, function(v) {
if (v['in'] <= position && v.out > position) { if (v['in'] <= position && v.out > position) {
subtitle = v; subtitle = v;
Ox.Break(); return false; // break
} }
}); });
return subtitle; return subtitle;

View file

@ -929,10 +929,12 @@ Ox.VideoEditor = function(options, self) {
if (item.id == annotationId) { if (item.id == annotationId) {
value = item.value; value = item.value;
found = true; found = true;
Ox.Break(); return false; // break
} }
}); });
found && Ox.Break(); if (found) {
return false; // break
}
}); });
return value; return value;
} }
@ -983,7 +985,7 @@ Ox.VideoEditor = function(options, self) {
) { ) {
position = v; position = v;
found = true; found = true;
Ox.Break(); return false; // break
} }
}); });
direction == -1 && positions.reverse(); direction == -1 && positions.reverse();
@ -1170,7 +1172,7 @@ Ox.VideoEditor = function(options, self) {
'in': i ? self.options.cuts[i - 1] : 0, 'in': i ? self.options.cuts[i - 1] : 0,
out: cut - 1 / self.options.fps out: cut - 1 / self.options.fps
}; };
Ox.Break(); return false; // break
} }
}); });
setPoint('in', points['in']); setPoint('in', points['in']);

View file

@ -239,7 +239,7 @@ Ox.VideoEditorPlayer = function(options, self) {
Ox.forEach(self.options.subtitles, function(v) { Ox.forEach(self.options.subtitles, function(v) {
if (v['in'] <= self.options.position && v['out'] > self.options.position) { if (v['in'] <= self.options.position && v['out'] > self.options.position) {
subtitle = v.value; subtitle = v.value;
Ox.Break(); return false; // break
} }
}); });
return subtitle; return subtitle;

View file

@ -275,7 +275,7 @@ Ox.VideoElement = function(options, self) {
if (item.offsets[i] <= time) { if (item.offsets[i] <= time) {
currentPart = i; currentPart = i;
currentTime = time - item.offsets[i]; currentTime = time - item.offsets[i];
Ox.Break(); return false; // break
} }
}); });
Ox.Log('Video', 'sCT', time, currentPart, currentTime); Ox.Log('Video', 'sCT', time, currentPart, currentTime);

View file

@ -1290,7 +1290,7 @@ Ox.VideoPlayer = function(options, self) {
&& v.out > self.options.position && v.out > self.options.position
) { ) {
censored = true; censored = true;
return false; return false; // break
} }
}); });
return censored; return censored;
@ -1468,7 +1468,7 @@ Ox.VideoPlayer = function(options, self) {
&& v.out >= self.options.position && v.out >= self.options.position
) { ) {
subtitle = v.text; subtitle = v.text;
return false; return false; // break
} }
}); });
return subtitle; return subtitle;
@ -1517,7 +1517,7 @@ Ox.VideoPlayer = function(options, self) {
var left = 0; var left = 0;
Ox.forEach(self.options.controlsBottom, function(control) { Ox.forEach(self.options.controlsBottom, function(control) {
if (control == 'timeline') { if (control == 'timeline') {
Ox.Break(); return false; // break
} }
left += control == 'position' ? self.positionWidth : 16 left += control == 'position' ? self.positionWidth : 16
}); });
@ -1600,7 +1600,7 @@ Ox.VideoPlayer = function(options, self) {
) { ) {
result = v result = v
found = true; found = true;
Ox.Break(); return false; // break
} }
}); });
direction == -1 && self.results.reverse(); direction == -1 && self.results.reverse();

View file

@ -507,7 +507,7 @@ Ox.VideoTimelinePlayer = function(options, self) {
Ox.forEach(self.options.subtitles, function(v) { Ox.forEach(self.options.subtitles, function(v) {
if (v['in'] <= position && v.out > position) { if (v['in'] <= position && v.out > position) {
subtitle = v; subtitle = v;
Ox.Break(); return false; // break
} }
}); });
return subtitle; return subtitle;

View file

@ -271,7 +271,7 @@ Ox.Dialog = function(options, self) {
Ox.forEach(self.options.buttons, function(button) { Ox.forEach(self.options.buttons, function(button) {
if (button.options && button.options('id') == id) { if (button.options && button.options('id') == id) {
ret = button; ret = button;
Ox.Break(); return false; // break
} }
}); });
return ret; return ret;

View file

@ -381,7 +381,7 @@ Ox.api = function(items, options) {
(query.operator == '&' && !match) (query.operator == '&' && !match)
|| (query.operator == '|' && match) || (query.operator == '|' && match)
) { ) {
Ox.Break(); return false; // break
} }
}); });
return match; return match;
@ -604,7 +604,7 @@ Ox.range = function() {
length = article.length; length = article.length;
sort[value] = sort[value].slice(length + 1) + ', ' sort[value] = sort[value].slice(length + 1) + ', '
+ sort[value].slice(0, length); + sort[value].slice(0, length);
Ox.Break(); return false; // break
} }
}); });
} else { } else {

View file

@ -60,17 +60,17 @@
function iterate() { function iterate() {
Ox.forEach(keys.slice(i), function(key) { Ox.forEach(keys.slice(i), function(key) {
if (key in collection) { if (key in collection) {
try { if (iterator.call(
iterator.call(that, collection[key], key, collection); that, collection[key], key, collection
} catch (error) { ) === false) {
if (error === Ox.BreakError) { i = n;
i = n; return false;
}
throw error;
} }
} }
i++; i++;
+new Date() >= time + ms && Ox.Break(); if (+new Date() >= time + ms) {
return false; // break
}
}); });
if (i < n) { if (i < n) {
setTimeout(function() { setTimeout(function() {

View file

@ -148,10 +148,9 @@ Ox.filter = function(collection, iterator, that) {
/*@ /*@
Ox.forEach <f> forEach loop Ox.forEach <f> forEach loop
`Ox.forEach` loops over arrays, objects and strings. Calling `Ox.Break` `Ox.forEach` loops over arrays, objects and strings. Returning `false` from
inside the iterator or returning `false` from the iterator acts like a the iterator acts like a `break` statement. Unlike `for`, which leaks its
`break` statement. Unlike `Array.prototype.forEach`, which leaks its counter counter variable to the outer scope, `Ox.forEach` returns it.
variable to the outer scope, `Ox.forEach` returns it.
(collection, iterator[, that]) -> <n> Next index (collection, iterator[, that]) -> <n> Next index
collection <a|o|s> Collection collection <a|o|s> Collection
iterator <f> Iterator iterator <f> Iterator
@ -172,33 +171,23 @@ Ox.forEach <f> forEach loop
@*/ @*/
Ox.forEach = function(collection, iterator, that) { Ox.forEach = function(collection, iterator, that) {
var i = 0, key, type = Ox.typeOf(collection); var i = 0, key, type = Ox.typeOf(collection);
try { if (type == 'object' || type == 'storage') {
if (type == 'object' || type == 'storage') { for (key in collection) {
for (key in collection) { if (Ox.hasOwn(collection, key)) {
if (Ox.hasOwn(collection, key)) { if (iterator.call(that, collection[key], key, collection) === false) {
// iterator.call(that, collection[key], key, collection); break;
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;
}
} }
} }
i++;
} }
} catch (error) { } else {
if (error !== Ox.BreakError) { collection = Ox.toArray(collection);
throw error; for (i = 0; i < collection.length; i++) {
if (i in collection) {
if (iterator.call(that, collection[i], i, collection) === false) {
break;
}
}
} }
} }
return i; return i;
@ -217,7 +206,7 @@ Ox.indexOf <f> Returns the first index of a collection element that passes a tes
@*/ @*/
Ox.indexOf = function(collection, test) { Ox.indexOf = function(collection, test) {
var index = Ox.forEach(collection, function(value) { 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 return Ox.isObject(collection) ? Object.keys(collection)[index] || null
: index == collection.length ? -1 : index; : index == collection.length ? -1 : index;

View file

@ -84,15 +84,6 @@ this.Ox = function(value) {
return Ox.wrap(value); return Ox.wrap(value);
}; };
/*@
Ox.Break <f> Breaks from `Ox.forEach` and `Ox.loop`
@*/
Ox.Break = function() {
throw Ox.BreakError;
};
Ox.BreakError = new SyntaxError('Illegal Ox.Break() statement');
/*@ /*@
Ox.load <f> Loads one or more modules Ox.load <f> Loads one or more modules
A module named "Foo" provides `Ox.Foo/Ox.Foo.js`, in which it defines one A module named "Foo" provides `Ox.Foo/Ox.Foo.js`, in which it defines one
@ -283,7 +274,7 @@ Ox.loop <f> For-loop, functional-style
step <n> Step value step <n> Step value
fn <f> Iterator function fn <f> Iterator function
i <n> Counter value i <n> Counter value
> Ox.loop(10, function(i) { i == 4 && Ox.Break(); }) > Ox.loop(10, function(i) { if (i == 4) { return false; } })
4 4
> Ox.loop(0, 3, 2, function() {}) > Ox.loop(0, 3, 2, function() {})
4 4
@ -295,17 +286,9 @@ Ox.loop = function() {
step = length == 4 ? arguments[2] : (start <= stop ? 1 : -1), step = length == 4 ? arguments[2] : (start <= stop ? 1 : -1),
iterator = arguments[length - 1], iterator = arguments[length - 1],
i; i;
try { for (i = start; step > 0 ? i < stop : i > stop; i += step) {
for (i = start; step > 0 ? i < stop : i > stop; i += step) { if (iterator(i) === false) {
// iterator(i); break;
if (iterator(i) === false) {
// console.warn('Returning false in Ox.loop is deprecated.');
break;
}
}
} catch (error) {
if (error !== Ox.BreakError) {
throw error;
} }
} }
return i; return i;

View file

@ -359,13 +359,13 @@ Ox.formatDateRange = function(start, end, utc) {
if (precision[0] == precision[1]) { if (precision[0] == precision[1]) {
isOneUnit = true; isOneUnit = true;
Ox.loop(precision[0], function(i) { 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; isOneUnit = false;
return false; // break
} }
if (i == precision[0] - 1 && parts[0][i] != parts[1][i] - 1) {
isOneUnit = false;
}
!isOneUnit && Ox.Break();
}); });
} }
if (isOneUnit) { if (isOneUnit) {
@ -706,7 +706,7 @@ Ox.formatValue = function(number, string, bin) {
ret = Ox.formatNumber( ret = Ox.formatNumber(
number / Math.pow(base, index), index ? index - 1 : 0 number / Math.pow(base, index), index ? index - 1 : 0
) + ' ' + prefix + (prefix && bin ? 'i' : '') + string; ) + ' ' + prefix + (prefix && bin ? 'i' : '') + string;
Ox.Break(); return false; // break
} }
}); });
return ret; return ret;

View file

@ -252,8 +252,7 @@
// If an area crosses the dateline, // If an area crosses the dateline,
// we split it into two parts, // we split it into two parts,
// west and east of the dateline // west and east of the dateline
var areas = [areaA, areaB].map(splitArea), var areas = [areaA, areaB].map(splitArea), ret;
ret;
function contains(areaA, areaB) { function contains(areaA, areaB) {
return areaA.sw.lat <= areaB.sw.lat return areaA.sw.lat <= areaB.sw.lat
&& areaA.sw.lng <= areaB.sw.lng && areaA.sw.lng <= areaB.sw.lng
@ -266,10 +265,10 @@
Ox.forEach(areas[0], function(area0) { Ox.forEach(areas[0], function(area0) {
ret = contains(area0, area1); ret = contains(area0, area1);
// Break if the outer part contains the inner part // Break if the outer part contains the inner part
ret && Ox.Break(); return !ret;
}); });
// Break if no outer part contains the inner part // Break if no outer part contains the inner part
!ret && Ox.Break(); return ret;
}); });
return ret; return ret;
}; };
@ -327,7 +326,7 @@
: Ox.joinAreas(intersections); : Ox.joinAreas(intersections);
} }
if (ret === null) { if (ret === null) {
Ox.Break(); return false; // break
} else { } else {
ret = splitArea(ret); ret = splitArea(ret);
} }
@ -378,7 +377,7 @@
Ox.forEach(gaps, function(gap, i) { Ox.forEach(gaps, function(gap, i) {
if (Ox.containsArea(gap, area)) { if (Ox.containsArea(gap, area)) {
ret = i; ret = i;
Ox.Break(); return false; // break
} }
}); });
return ret; return ret;

View file

@ -185,7 +185,7 @@ Ox.doc = (function() {
Ox.forEach(item.returns, function(v) { Ox.forEach(item.returns, function(v) {
if (v['class']) { if (v['class']) {
constructors.push(item); constructors.push(item);
Ox.Break(); return false; // break
} }
}); });
} }
@ -654,7 +654,7 @@ Ox.identify = (function() {
Ox.forEach(identifiers, function(words, type) { Ox.forEach(identifiers, function(words, type) {
if (words.indexOf(identifier) > -1) { if (words.indexOf(identifier) > -1) {
ret = type; ret = type;
Ox.Break(); return false; // break
} }
}); });
} }
@ -874,7 +874,7 @@ Ox.test = function(argument, callback) {
if (v.tests[statement]) { if (v.tests[statement]) {
id = k; id = k;
test = v.tests[statement]; test = v.tests[statement];
Ox.Break(); return false; // break
} }
}); });
Ox.test.data[id].results.push(Ox.extend(test, { Ox.test.data[id].results.push(Ox.extend(test, {

View file

@ -96,7 +96,7 @@ Ox.keyOf = function(object, value) {
Ox.forEach(object, function(v, k) { Ox.forEach(object, function(v, k) {
if (v === value) { if (v === value) {
key = k; key = k;
Ox.Break(); return false; // break
} }
}); });
return key; return key;

View file

@ -358,7 +358,7 @@ Ox.parseUserAgent = function(userAgent) {
string: string, string: string,
version: versions[version] || version version: versions[version] || version
}; };
Ox.Break(); return false; // break
} }
}); });
}); });

View file

@ -178,7 +178,7 @@ Ox.isEqual = function(a, b) {
ret = true; ret = true;
Ox.forEach(a, function(value, key) { Ox.forEach(a, function(value, key) {
ret = Ox.isEqual(value, b[key]); ret = Ox.isEqual(value, b[key]);
!ret && Ox.Break(); return ret; // break if not equal
}); });
} }
} }