Merge branch 'staging' of github.com:xwiki-labs/cryptpad into staging
This commit is contained in:
@@ -197,6 +197,16 @@ define([
|
||||
return hexArray.join("");
|
||||
};
|
||||
|
||||
var deduplicate = common.deduplicateString = function (array) {
|
||||
var a = array.slice();
|
||||
for(var i=0; i<a.length; i++) {
|
||||
for(var j=i+1; j<a.length; j++) {
|
||||
if(a[i] === a[j]) { a.splice(j--, 1); }
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
|
||||
|
||||
var parseHash = common.parseHash = function (hash) {
|
||||
var parsed = {};
|
||||
@@ -430,6 +440,7 @@ define([
|
||||
|
||||
var getRelativeHref = common.getRelativeHref = function (href) {
|
||||
if (!href) { return; }
|
||||
if (href.indexOf('#') === -1) { return; }
|
||||
var parsed = common.parsePadUrl(href);
|
||||
return '/' + parsed.type + '/#' + parsed.hash;
|
||||
};
|
||||
|
||||
@@ -322,6 +322,66 @@ define([
|
||||
return rootpaths.concat(unsortedpaths, templatepaths, trashpaths);
|
||||
};
|
||||
|
||||
var search = exp.search = function (value) {
|
||||
if (typeof(value) !== "string") { return []; }
|
||||
var res = [];
|
||||
// Search in ROOT
|
||||
var findIn = function (root) {
|
||||
Object.keys(root).forEach(function (k) {
|
||||
if (isFile(root[k])) {
|
||||
if (k.toLowerCase().indexOf(value.toLowerCase()) !== -1) {
|
||||
res.push(root[k]);
|
||||
}
|
||||
return;
|
||||
}
|
||||
findIn(root[k]);
|
||||
});
|
||||
};
|
||||
findIn(files[ROOT]);
|
||||
// Search in TRASH
|
||||
var trash = files[TRASH];
|
||||
Object.keys(trash).forEach(function (k) {
|
||||
if (k.toLowerCase().indexOf(value.toLowerCase()) !== -1) {
|
||||
trash[k].forEach(function (el) {
|
||||
if (isFile(el.element)) {
|
||||
res.push(el.element);
|
||||
}
|
||||
});
|
||||
}
|
||||
trash[k].forEach(function (el) {
|
||||
if (isFolder(el.element)) {
|
||||
findIn(el.element);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Search title
|
||||
var allFilesList = files[FILES_DATA].slice();
|
||||
allFilesList.forEach(function (t) {
|
||||
if (t.title && t.title.toLowerCase().indexOf(value.toLowerCase()) !== -1) {
|
||||
res.push(t.href);
|
||||
}
|
||||
});
|
||||
|
||||
// Search Href
|
||||
var href = Cryptpad.getRelativeHref(value);
|
||||
if (href) {
|
||||
res.push(href);
|
||||
}
|
||||
|
||||
res = Cryptpad.deduplicateString(res);
|
||||
|
||||
var ret = [];
|
||||
res.forEach(function (l) {
|
||||
var paths = findFile(l);
|
||||
ret.push({
|
||||
paths: findFile(l),
|
||||
data: getFileData(l)
|
||||
});
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
||||
// Remove the selected 'href' from the tree located at 'path', and push its locations to the 'paths' array
|
||||
var removeFileFromRoot = function (path, href) {
|
||||
var paths = [];
|
||||
|
||||
@@ -7,16 +7,6 @@ define([
|
||||
|
||||
var Nacl = window.nacl;
|
||||
|
||||
var deduplicate = function (array) {
|
||||
var a = array.slice();
|
||||
for(var i=0; i<a.length; i++) {
|
||||
for(var j=i+1; j<a.length; j++) {
|
||||
if(a[i] === a[j]) { a.splice(j--, 1); }
|
||||
}
|
||||
}
|
||||
return a;
|
||||
};
|
||||
|
||||
var create = function (network, ed) {
|
||||
var exp = {};
|
||||
var rpc = Rpc.create(network, ed);
|
||||
@@ -31,7 +21,7 @@ define([
|
||||
if (!parsedHash || !parsedHash.channel) { return; }
|
||||
channelIdList.push(Cryptpad.base64ToHex(parsedHash.channel));
|
||||
});
|
||||
var uniqueList = deduplicate(channelIdList).sort();
|
||||
var uniqueList = Cryptpad.deduplicateString(channelIdList).sort();
|
||||
|
||||
/*
|
||||
1. every time you want to pin or unpid a pad you send a message to the server
|
||||
|
||||
Reference in New Issue
Block a user