remove Ox.each, , $.extend, $.map and $.merge

This commit is contained in:
rolux 2011-09-17 20:36:30 +02:00
parent 6d35c64eb1
commit f7ea2f71ee
19 changed files with 62 additions and 69 deletions

View file

@ -90,10 +90,12 @@ function constructList() {
return 0;
return -1;
}
if(!data.keys) {
if (!data.keys) {
app.api.api(function(results) {
var items = [];
$.each(results.data.actions, function(i, k) {items.push({'name': i})});
Ox.forEach(results.data.actions, function(v, k) {
items.push({'name': v})
});
items.sort(_sort);
var result = {'data': {'items': items.length}};
callback(result);
@ -101,7 +103,9 @@ function constructList() {
} else {
app.api.api(function(results) {
var items = [];
$.each(results.data.actions, function(i, k) {items.push({'name': i})});
Ox.forEach(results.data.actions, function(v, k) {
items.push({'name': v})
});
items.sort(_sort);
var result = {'data': {'items': items}};
callback(result);
@ -120,13 +124,13 @@ function constructList() {
var info = $('<div>').addClass('OxSelectable'),
hash = '#';
if(data.ids.length)
$.each(data.ids, function(v, k) {
info.append($("<h2>").html(k));
data.ids.forEach(function(id) {
info.append($("<h2>").html(id));
var $doc =$('<pre>')
.html(app.actions[k].doc.replace('/\n/<br>\n/g'))
.html(app.actions[id].doc.replace('/\n/<br>\n/g'))
.appendTo(info);
var $code = $('<code class=" python">')
.html(app.actions[k].code[1].replace('/\n/<br>\n/g'))
var $code = $('<code class="python">')
.html(app.actions[id].code[1].replace('/\n/<br>\n/g'))
.hide();
var $button = new Ox.Button({
title: [
@ -143,7 +147,7 @@ function constructList() {
$('<pre>').append($code).appendTo(info)
hljs.highlightBlock($code[0], ' ');
hash += k + ','
hash += id + ','
});
else
info.html(app.site.default_info);

View file

@ -11,7 +11,7 @@ Ox.load('UI', {
window.pandora = new Ox.App({url: '/api/'}).bindEvent({
apiURL: '/api/',
}).bindEvent('load', function(data) {
$.extend(pandora, {
Ox.extend(pandora, {
ui: {},
info: function(item) {
var that = Ox.Element()
@ -116,7 +116,7 @@ window.pandora = new Ox.App({url: '/api/'}).bindEvent({
'value': value
}
});
$.each(args, function(i, a) {
args.forEach(function(a, i) {
Ox.print(i, a);
if (a.key == key) {
result = a.value;

View file

@ -52,7 +52,7 @@ Ox.load({
user: data.user.level == 'guest' ? Ox.extend({}, data.site.user) : data.user
});
Ox.extend(pandora.site, {
findKeys: $.map(data.site.itemKeys, function(key, i) {
findKeys: data.site.itemKeys.map(function(key) {
return key.find ? key : null;
}),
sectionFolders: {
@ -73,7 +73,7 @@ Ox.load({
{id: 'featured', title: 'Featured Texts', showBrowser: false}
]
},
sortKeys: $.map(data.site.itemKeys, function(key, i) {
sortKeys: data.site.itemKeys.map(function(key) {
return key.columnWidth ? key : null;
})
});

View file

@ -96,7 +96,7 @@ pandora.afterLaunch.push(function() {
pandora.local.volumes(function(data) {
Ox.print("got volumes", data);
var volumes = 0;
$.each(data, function(name, info) {
Ox.forEach(data, function(info, name) {
volumes ++;
Ox.print("add volume", name, info);
var status = info.available?"online":"offline";
@ -269,10 +269,10 @@ pandora.afterLaunch.push(function() {
var videos = {};
function parseResult(result) {
//extract and upload requested videos
$.each(result.data.data, function(i, oshash) {
$.each(folder_ids, function(i, ids) {
if($.inArray(oshash, ids) > -1) {
if(!videos[i]) {
result.data.data.forEach(function(oshash) {
folder_ids.forEach(function(ids, i) {
if (ids.indexOf(oshash) > -1) {
if (!videos[i]) {
videos[i] = [];
var button = new Ox.Button({
id: 'upload_' + oshash,
@ -285,7 +285,7 @@ pandora.afterLaunch.push(function() {
title: 'Cancel',
width: 48
}).bindEvent('click', function(data) {
$.each(videos[fid], function(i, oshash) {
videos[fid].forEach(function(oshash) {
_this.cancel(oshash);
});
});
@ -312,13 +312,13 @@ pandora.afterLaunch.push(function() {
});
});
//upload requested files
$.each(result.data.file, function(i, oshash) {
result.data.file.forEach(function(oshash) {
pandora.local.uploadFile(oshash);
});
};
if (result.data.info.length>0) {
var post = {'info': {}};
$.each(result.data.info, function(i, oshash) {
result.data.info.forEach(function(oshash) {
if(fileInfo[oshash]) {
post.info[oshash] = fileInfo[oshash];
}
@ -336,7 +336,7 @@ pandora.afterLaunch.push(function() {
}
var folder_ids = {};
var folders = {};
$.each(result.files, function(i, file) {
result.files.forEach(function(file) {
var f = pandora.local.parsePath(file.path);
if(!folders[f.folder]) {
folders[f.folder] = {
@ -352,7 +352,7 @@ pandora.afterLaunch.push(function() {
folder_ids[folders[f.folder].id].push(file.oshash);
});
var j = 1;
$.each(folders, function(i, folder) {
folders.forEach(function(folder) {
data.items.push(folder);
});
r = {

View file

@ -62,7 +62,7 @@ pandora.URL = (function() {
? /[\d\.:,-]+/.exec(split[split.length - 1])
: null,
view = new RegExp(
'^(' + $.map(pandora.site.itemViews, function(v) {
'^(' + pandora.site.itemViews.map(function(v) {
return v.id;
}).join('|') + ')$'
).exec(split[1]);

View file

@ -1,13 +1,13 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
pandora.autovalidateCode = function(value, blur, callback) {
value = $.map(value.toUpperCase().split(''), function(v) {
value = value.toUpperCase().split('').map(function(v) {
return /[0-9A-Z]/(v) ? v : null;
}).join('');
callback(value);
};
pandora.autovalidateEmail = function(value, blur, callback) {
value = $.map(value.toLowerCase().split(''), function(v, i) {
value = value.toLowerCase().split('').map(function(v, i) {
return /[0-9a-z\.\+\-_@]/(v) ? v : null;
}).join('');
callback(value);
@ -15,14 +15,14 @@ pandora.autovalidateEmail = function(value, blur, callback) {
pandora.autovalidateListname = function(value, blur, callback) {
var length = value.length;
value = $.map(value.split(''), function(v, i) {
value = value.split('').map(function(v, i) {
if (new RegExp('[0-9' + Ox.regexp.letters + '\\(\\)' + ((i == 0 || (i == length - 1 && blur)) ? '' : ' \-') + ']', 'i').test(v)) {
return v;
} else {
return null;
}
}).join('');
$.each([' ', ' -', '- ', '--', '\\(\\(', '\\)\\(', '\\)\\)'], function(i, v) {
[' ', ' -', '- ', '--', '\\(\\(', '\\)\\(', '\\)\\)'].forEach(function(v) {
//Ox.print(v, v[0], v[0] == '\\')
while (value.indexOf(v) > -1) {
value = value.replace(new RegExp(v, 'g'), v[0] + (v[0] == '\\' ? v[1] : ''));
@ -33,14 +33,14 @@ pandora.autovalidateListname = function(value, blur, callback) {
pandora.autovalidateUsername = function(value, blur, callback) {
var length = value.length;
value = $.map(value.toLowerCase().split(''), function(v, i) {
value = value.toLowerCase().split('').map(function(v, i) {
if (new RegExp('[0-9a-z' + ((i == 0 || (i == length - 1 && blur)) ? '' : '\-_') + ']').test(v)) {
return v;
} else {
return null;
}
}).join('');
$.each(['--', '-_', '_-', '__'], function(i, v) {
['--', '-_', '_-', '__'].forEach(function(v) {
while (value.indexOf(v) > -1) {
value = value.replace(new RegExp(v, 'g'), v[0]);
}

View file

@ -276,24 +276,13 @@ pandora.getFoldersHeight = function() {
height += 16 + pandora.user.ui.showFolder[pandora.user.ui.section][folder.id] * (
!!folder.showBrowser * 40 + folder.items * 16
);
// // // Ox.print('h', height);
});
/*
$.each(pandora.user.ui.showFolder[pandora.user.ui.section], function(id, show) {
var i = Ox.getPositionById(pandora.site.sectionFolders[pandora.user.ui.section], id);
height += show * (
pandora.site.sectionFolders[pandora.user.ui.section][i].showBrowser * 40 +
pandora.site.sectionFolders[pandora.user.ui.section][i].items * 16
);
});
*/
return height;
};
pandora.getFoldersWidth = function() {
var width = pandora.user.ui.sidebarSize;
// fixme: don't use height(), look up in splitpanels
// // // Ox.print(pandora.getFoldersHeight(), '>', pandora.$ui.leftPanel.height() - 24 - 1 - pandora.$ui.info.height());
if (pandora.getFoldersHeight() > pandora.$ui.leftPanel.height() - 24 - 1 - pandora.$ui.info.height()) {
width -= Ox.UI.SCROLLBAR_SIZE;
}
@ -413,7 +402,7 @@ pandora.reloadGroups = function(i) {
}
});
}
$.each(pandora.user.ui.groups, function(i_, id) {
Ox.forEach(pandora.user.ui.groups, function(id, i_) {
if (i_ != i) {
//Ox.print('setting groups request', i, i_)
pandora.$ui.groups[i_].options({

View file

@ -136,7 +136,7 @@ Ox.FilesView = function(options, self) {
columnsVisible: true,
id: 'files',
items: function(data, callback) {
pandora.api.findFiles($.extend(data, {
pandora.api.findFiles(Ox.extend(data, {
query: {
conditions: [{
key: 'id',

View file

@ -1,7 +1,7 @@
// vim: et:ts=4:sw=4:sts=4:ft=javascript
pandora.ui.accountDialog = function(action) {
var that = Ox.Dialog($.extend({
var that = Ox.Dialog(Ox.extend({
fixedSize: true,
height: 192,
id: 'accountDialog',
@ -72,7 +72,7 @@ pandora.ui.accountDialogOptions = function(action, value) {
}
}
return {
buttons: Ox.merge($.map(buttons[action], function(type) {
buttons: Ox.merge(buttons[action].map(function(type) {
return button(type);
}), [{}, button('cancel'), button('submit')]),
content: Ox.Element()
@ -120,7 +120,7 @@ pandora.ui.accountForm = function(action, value) {
'reset': ['usernameOrEmail'],
'resetAndSignin': ['oldUsername', 'newPassword', 'code']
},
$items = $.map(items[action], function(v) {
$items = items[action].map(function(v) {
return item(v, value);
}),
that = Ox.Form({

View file

@ -18,7 +18,7 @@ pandora.ui.annotations = function() {
}
}),
$bins = [];
$.each(pandora.site.layers, function(i, layer) {
pandora.site.layers.forEach(function(layer) {
var $bin = Ox.CollapsePanel({
id: layer.id,
size: 16,
@ -37,7 +37,7 @@ pandora.ui.annotations = function() {
)
);
});
$.each($bins, function(i, bin) {
$bins.forEach(function(bin) {
that.append(bin);
});
return that;

View file

@ -178,7 +178,7 @@ pandora.ui.folderBrowserList = function(id) {
select: function(data) {
// fixme: duplicated
if (data.ids.length) {
$.each(pandora.$ui.folderList, function(id_, $list) {
Ox.forEach(pandora.$ui.folderList, function($list, id_) {
id != id_ && $list.options('selected', []);
});
pandora.UI.set({list: data.ids[0]});

View file

@ -127,11 +127,11 @@ pandora.ui.group = function(id) {
}
});
Ox.Select({
items: $.map(pandora.site.groups, function(v) {
items: pandora.site.groups.map(function(group) {
return {
checked: v.id == id,
id: v.id,
title: v.title
checked: group.id == id,
id: group.id,
title: group.title
}
}),
max: 1,

View file

@ -203,7 +203,7 @@ pandora.ui.item = function() {
operator: '='
}]},
query = {conditions:[]};
return pandora.api.findPlaces($.extend(data, {
return pandora.api.findPlaces(Ox.extend(data, {
itemQuery: itemQuery,
query: query
}), callback);
@ -216,7 +216,7 @@ pandora.ui.item = function() {
if(place) {
pandora.$ui.clips.options({
items: function(data, callback) {
return pandora.api.findAnnotations($.extend(data, {
return pandora.api.findAnnotations(Ox.extend(data, {
query: {
conditions:[{key: 'place', value: place.id, operator:'='}]
},
@ -296,8 +296,8 @@ pandora.ui.item = function() {
// fixme: duplicated
var layers = [],
video = {};
$.each(pandora.site.layers, function(i, layer) {
layers[i] = $.extend({}, layer, {items: result.data.layers[layer.id]});
pandora.site.layers.forEach(function(layer, i) {
layers[i] = Ox.extend({}, layer, {items: result.data.layers[layer.id]});
});
pandora.site.video.resolutions.forEach(function(resolution) {
video[resolution] = Ox.range(result.data.parts).map(function(i) {

View file

@ -48,7 +48,7 @@ pandora.ui.leftPanel = function() {
toggle: function(data) {
pandora.UI.set({showSidebar: !data.collapsed});
if (data.collapsed) {
$.each(pandora.$ui.folderList, function(k, $list) {
Ox.forEach(pandora.$ui.folderList, function($list) {
$list.loseFocus();
});
}

View file

@ -554,7 +554,7 @@ pandora.ui.list = function() { // fixme: remove view argument
init: function(data) {
pandora.$ui.total.html(pandora.ui.status('total', data));
data = [];
$.each(pandora.site.totals, function(i, v) {
pandora.site.totals.forEach(function(v) {
data[v.id] = 0;
});
pandora.$ui.selected.html(pandora.ui.status('selected', data));
@ -569,7 +569,7 @@ pandora.ui.list = function() { // fixme: remove view argument
pandora.requests.preview = pandora.api.find({
keys: ['director', 'id', 'posterRatio', 'title'],
query: {
conditions: $.map(data.ids, function(id, i) {
conditions: data.ids.map(function(id) {
return {
key: 'id',
value: id,
@ -658,7 +658,7 @@ pandora.ui.list = function() { // fixme: remove view argument
pandora.$ui.leftPanel.replaceElement(2, pandora.$ui.info = pandora.ui.info(data.ids[0]));
pandora.api.find({
query: {
conditions: $.map(data.ids, function(id, i) {
conditions: data.ids.map(function(id) {
return {
key: 'id',
value: id,

View file

@ -67,7 +67,7 @@ pandora.ui.mainMenu = function() {
] },
{ id: 'viewMenu', title: 'View', items: [
{ id: 'movies', title: 'View ' + pandora.site.itemName.plural, items: [
{ group: 'viewmovies', min: 1, max: 1, items: $.map(pandora.site.listViews, function(view, i) {
{ group: 'viewmovies', min: 1, max: 1, items: pandora.site.listViews.map(function(view) {
return Ox.extend({
checked: pandora.user.ui.lists[pandora.user.ui.list].listView == view.id,
}, view);
@ -88,7 +88,7 @@ pandora.ui.mainMenu = function() {
]},
{},
{ id: 'openmovie', title: ['Open ' + pandora.site.itemName.singular, 'Open ' + pandora.site.itemName.plural], items: [
{ group: 'movieview', min: 1, max: 1, items: $.map(pandora.site.itemViews, function(view, i) {
{ group: 'movieview', min: 1, max: 1, items: pandora.site.itemViews.map(function(view) {
return Ox.extend({
checked: pandora.user.ui.itemView == view.id,
}, view);
@ -114,7 +114,7 @@ pandora.ui.mainMenu = function() {
]},
{ id: 'sortMenu', title: 'Sort', items: [
{ id: 'sortmovies', title: 'Sort ' + pandora.site.itemName.plural + ' by', items: [
{ group: 'sortmovies', min: 1, max: 1, items: $.map(pandora.site.sortKeys, function(key, i) {
{ group: 'sortmovies', min: 1, max: 1, items: pandora.site.sortKeys.map(function(key) {
return Ox.extend({
checked: pandora.user.ui.lists[pandora.user.ui.list].sort[0].key == key.id
}, key);

View file

@ -17,7 +17,7 @@ pandora.ui.placesDialog = function() {
content: pandora.$ui.placesElement = Ox.ListMap({
height: height - 48,
places: function(data, callback) {
return pandora.api.findPlaces($.extend({
return pandora.api.findPlaces(Ox.extend({
query: {conditions: [], operator: ''}
}, data), callback);
},

View file

@ -2,9 +2,9 @@
pandora.ui.sortSelect = function() {
var that = Ox.Select({
id: 'sortSelect',
items: $.map(pandora.site.sortKeys, function(key) {
items: pandora.site.sortKeys.map(function(key) {
//Ox.print('????', pandora.user.ui.lists[pandora.user.ui.list].sort.key, key.id)
return $.extend($.extend({}, key), {
return Ox.extend(Ox.extend({}, key), {
checked: pandora.user.ui.lists[pandora.user.ui.list].sort[0].key == key.id,
title: 'Sort by ' + key.title
});

View file

@ -3,12 +3,12 @@ pandora.ui.viewSelect = function() {
var that = Ox.Select({
id: 'viewSelect',
items: !pandora.user.ui.item ? pandora.site.listViews.map(function(view) {
return $.extend($.extend({}, view), {
return Ox.extend(Ox.extend({}, view), {
checked: pandora.user.ui.lists[pandora.user.ui.list].listView == view.id,
title: 'View ' + view.title
});
}) : pandora.site.itemViews.map(function(view) {
return $.extend($.extend({}, view), {
return Ox.extend(Ox.extend({}, view), {
checked: pandora.user.ui.itemView == view.id,
title: 'View: ' + view.title
});