use Ox.forEach() when you need to break from the loop

This commit is contained in:
rlx 2011-04-19 15:15:55 +00:00
parent ddf22df242
commit 39501de9d0

View file

@ -168,7 +168,7 @@ requires
function getUserAgent() {
var userAgent = '';
['Chrome', 'Firefox', 'Internet Explorer', 'Opera', 'Safari'].forEach(function(v) {
Ox.forEach(['Chrome', 'Firefox', 'Internet Explorer', 'Opera', 'Safari'], function(v) {
if (navigator.userAgent.indexOf(v) > -1) {
userAgent = v;
return false;
@ -1211,7 +1211,7 @@ requires
var length = arguments.length,
classes = Ox.UI.$body.attr('class').split(' '),
arg, theme;
classes.forEach(function(v) {
Ox.forEach(classes, function(v) {
if (Ox.startsWith(v, 'OxTheme')) {
theme = v.replace('OxTheme', '').toLowerCase();
if (length == 1) {
@ -1345,7 +1345,7 @@ requires
self.options.resize[0],
self.options.resize[self.options.resize.length - 1]
);
self.options.resize.forEach(function(v) {
Ox.forEach(self.options.resize, function(v) {
if (self.options.size >= v - 8 && self.options.size <= v + 8) {
self.options.size = v;
return false;
@ -1663,7 +1663,7 @@ requires
function getButtonById(id) {
var ret = null;
//Ox.print('that.$buttons', that.$buttons, id)
that.$buttons.forEach(function(button) {
Ox.forEach(that.$buttons, function(button) {
if (button.options('id') == id) {
ret = button;
return false;
@ -3728,7 +3728,7 @@ requires
// fixme: is this used?
that.getInputById = function(id) {
var input = null;
self.options.inputs.forEach(function(v, i) {
Ox.forEach(self.options.inputs, function(v, i) {
//Ox.print(v, v.options('id'), id)
if (v.options('id') == self.options.id + Ox.toTitleCase(id)) {
input = v;
@ -4332,10 +4332,10 @@ requires
pos < items.length - 1 ? Ox.range(items.length - 1, pos, -1) : []
))*/
// fixme: why is length not == items.length here?
$.merge(
Ox.forEach($.merge(
pos > 0 ? Ox.range(pos - 1, -1, -1) : [],
pos < items.length - 1 ? Ox.range(items.length - 1, pos, -1) : []
).forEach(function(v) {
), function(v) {
//Ox.print(pos, v)
if (items[v][property]) {
last = v;
@ -5348,7 +5348,7 @@ requires
self.options.labelWidth = (keyPos == 0 ? 0 : self.options.labelWidth) + key.width;
}
self.selectedKey[keyPos] = 0;
key.forEach(function(value, valuePos) {
Ox.forEach(key, function(value, valuePos) {
if (value.checked) {
self.selectedKey[keyPos] = valuePos;
return false;
@ -5407,7 +5407,7 @@ requires
if (self.options.unit) {
if (self.hasSelectableUnits) {
self.options.unit.forEach(function(unit, pos) {
Ox.forEach(self.options.unit, function(unit, pos) {
if (unit.checked) {
self.selectedUnit = pos;
return false;
@ -5772,7 +5772,7 @@ requires
var value = value.toLowerCase(),
ret = '';
if (value !== '') {
self.options.autocomplete.forEach(function(v, i) {
Ox.forEach(self.options.autocomplete, function(v, i) {
if (v.toLowerCase().indexOf(value) == 0) {
ret = v;
return false;
@ -7044,7 +7044,7 @@ requires
function getPositionById(id) {
// fixme: is this really needed?
var pos = -1;
self.$items.forEach(function($item, i) {
Ox.forEach(self.$items, function($item, i) {
if ($item.options('data')[self.options.unique] == id) {
pos = i;
return false;
@ -7201,7 +7201,7 @@ requires
self.$items[pos].appendTo(self.$pages[page]);
});
self.options.type == 'text' && page == 0 && fillFirstPage();
$emptyPage.removeElement();
$emptyPage.remove();
self.$pages[page].appendTo(that.$content);
!Ox.isUndefined(callback) && callback(); // fixme: callback necessary? why not bind to event?
}));
@ -7563,7 +7563,7 @@ requires
}
function selectQuery(str) {
self.$items.forEach(function(v, i) {
Ox.forEach(self.$items, function(v, i) {
if (Ox.toLatin(v.title).toUpperCase().indexOf(str) == 0) {
select(i);
scrollToPosition(i);
@ -8222,7 +8222,7 @@ requires
//Ox.print('addColumn', id);
var column, ids,
index = 0;
self.options.columns.forEach(function(v) {
Ox.forEach(self.options.columns, function(v) {
if (v.visible) {
index++;
} else if (v.id == id) {
@ -8246,7 +8246,7 @@ requires
function changeColumns(event, data) {
var add,
ids = [];
data.selected.forEach(function(column) {
Ox.forEach(data.selected, function(column) {
var index = getColumnIndexById(column.id);
if (!self.options.columns[index].visible) {
addColumn(column.id);
@ -8256,7 +8256,7 @@ requires
ids.push(column.id);
});
if (!add) {
self.visibleColumns.forEach(function(column) {
Ox.forEach(self.visibleColumns, function(column) {
if (ids.indexOf(column.id) == -1) {
removeColumn(column.id);
return false;
@ -8415,7 +8415,7 @@ requires
function dragColumn(id, e) {
var d = e.clientX - self.drag.startX,
pos = self.drag.stopPos;
self.drag.offsets.forEach(function(v, i) {
Ox.forEach(self.drag.offsets, function(v, i) {
if (d < 0 && d < v) {
self.drag.stopPos = i;
return false;
@ -8869,7 +8869,7 @@ requires
var items = items || self.options.items,
level = level || 0,
ret = null;
items.forEach(function(item) {
Ox.forEach(items, function(item) {
if (item.id == id) {
ret = $.extend(item, {
level: level
@ -9775,7 +9775,7 @@ requires
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
if (bounds) {
results.reverse().forEach(function(result, i) {
Ox.forEach(results.reverse(), function(result, i) {
if (
i == length - 1 ||
canContain(bounds, result.geometry.bounds || result.geometry.viewport)
@ -9817,7 +9817,7 @@ requires
function getPositionByName(name) {
var position = -1;
self.options.places.forEach(function(place, i) {
Ox.forEach(self.options.places, function(place, i) {
if (place.name == name) {
position = i;
return false;
@ -9833,7 +9833,7 @@ requires
if (self.resultPlace && self.resultPlace.selected) {
id = self.resultPlace.id;
} else {
self.places.forEach(function(place) {
Ox.forEach(self.places, function(place) {
if (place.selected) {
id = place.id;
return false;
@ -10956,8 +10956,7 @@ requires
var ids = id.split('_'),
item;
if (ids.length == 1) {
Ox.print('TM', that.menus)
that.menus.forEach(function(menu) {
Ox.forEach(that.menus, function(menu) {
item = menu.getItem(id);
return !item;
});
@ -10972,7 +10971,7 @@ requires
var ids = id.split('_'),
menu;
if (ids.length == 1) {
that.menus.forEach(function(v) {
Ox.forEach(that.menus, function(v) {
if (v.options('id') == id) {
menu = v;
return false;
@ -11303,7 +11302,7 @@ requires
function getItemPositionById(id) {
var position;
that.items.forEach(function(item, i) {
Ox.forEach(that.items, function(item, i) {
if (item.options('id') == id) {
position = i;
return false;
@ -11319,7 +11318,7 @@ requires
function isFirstEnabledItem() {
var ret = true;
that.items.forEach(function(item, i) {
Ox.forEach(that.items, function(item, i) {
if (i < self.options.selected && !item.options('disabled')) {
return ret = false;
}
@ -11329,7 +11328,7 @@ requires
function isLastEnabledItem() {
var ret = true;
that.items.forEach(function(item, i) {
Ox.forEach(that.items, function(item, i) {
if (i > self.options.selected && !item.options('disabled')) {
return ret = false;
}
@ -11570,7 +11569,7 @@ requires
var ids = id.split('_'),
item;
if (ids.length == 1) {
that.items.forEach(function(v) {
Ox.forEach(that.items, function(v) {
if (v.options('id') == id) {
item = v;
return false;
@ -11602,7 +11601,7 @@ requires
that.hasEnabledItems = function() {
var ret = false;
that.items.forEach(function(item) {
Ox.forEach(that.items, function(item) {
if (!item.options('disabled')) {
return ret = true;
}
@ -12018,7 +12017,7 @@ requires
element.resize[0],
element.resize[element.resize.length - 1]
);
element.resize.forEach(function(v) {
Ox.forEach(element.resize, function(v) {
if (size >= v - 8 && size <= v + 8) {
size = v;
return false;
@ -12193,7 +12192,7 @@ requires
function getPositionById(id) {
var position = -1;
self.options.elements.forEach(function(element, i) {
Ox.forEach(self.options.elements, function(element, i) {
if (element.element.options('id') == id) {
position = i;
return false;
@ -12683,7 +12682,7 @@ requires
function getSubtitle(position) {
var subtitle = null;
self.options.subtitles.forEach(function(v) {
Ox.forEach(self.options.subtitles, function(v) {
if (v['in'] <= position && v['out'] >= position) {
subtitle = v;
return false;
@ -13271,7 +13270,7 @@ requires
function getSubtitle(position) {
var subtitle = null;
self.options.subtitles.forEach(function(v) {
Ox.forEach(self.options.subtitles, function(v) {
if (v['in'] <= position && v['out'] >= position) {
subtitle = v;
return false;
@ -13604,7 +13603,7 @@ requires
that.triggerEvent('removeAnnotations', data);
},
select: function(event, data) {
self.options.layers.forEach(function(l, j) {
self.options.layers.forEach(function(l, j) { // fixme: l? j?
if(l.id != layer.id) {
self.$annotationPanel[j].deselectItems();
}
@ -13680,7 +13679,7 @@ requires
});
}
direction == -1 && positions.reverse();
positions.forEach(function(v) {
Ox.forEach(positions, function(v) {
if (direction == 1 ? v > self.options.position : v < self.options.position) {
position = v;
found = true;
@ -13711,7 +13710,7 @@ requires
positions.indexOf(0) == -1 && positions.unshift(0);
positions.indexOf(self.options.duration) == -1 &&
positions.push(self.options.duration);
positions.forEach(function(v, i) {
Ox.forEach(positions, function(v, i) {
if (v > self.options.position) {
points = [positions[i - 1], positions[i]];
found = true;
@ -14192,7 +14191,7 @@ requires
function getSubtitle() {
var subtitle = '';
self.options.subtitles.forEach(function(v) {
Ox.forEach(self.options.subtitles, function(v) {
if (v['in'] <= self.options.position && v['out'] > self.options.position) {
subtitle = v.value;
return false;