2012-11-09 18:35:59 +00:00
|
|
|
/*
|
|
|
|
Copyright 2012 Camlistore Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
2012-12-01 18:55:22 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2012-11-09 18:35:59 +00:00
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
function indexOnLoad(e) {
|
2012-11-25 17:45:30 +00:00
|
|
|
camliGetRecentlyUpdatedPermanodes({success: indexBuildRecentlyUpdatedPermanodes, thumbnails: 150});
|
2012-11-09 18:35:59 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 18:15:39 +00:00
|
|
|
var lastSelIndex = 0;
|
|
|
|
var selSetter = {}; // numeric index -> func(selected) setter
|
|
|
|
var currentlySelected = {}; // currently selected index -> true
|
|
|
|
|
|
|
|
function divFromResult(searchRes, i) {
|
2012-12-01 18:55:22 +00:00
|
|
|
var result = searchRes.recent[i];
|
|
|
|
var br = searchRes[result.blobref];
|
|
|
|
var divperm = document.createElement("div");
|
|
|
|
var setSelected = function(selected) {
|
|
|
|
divperm.isSelected = selected;
|
|
|
|
if (selected) {
|
|
|
|
lastSelIndex = i;
|
|
|
|
currentlySelected[i] = true;
|
|
|
|
divperm.attributes.class.value = "camli-ui-thumb selected";
|
|
|
|
} else {
|
|
|
|
delete currentlySelected[selected];
|
|
|
|
lastSelIndex = -1;
|
|
|
|
divperm.attributes.class.value = "camli-ui-thumb";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
selSetter[i] = setSelected;
|
|
|
|
divperm.addEventListener("mousedown", function(e) {
|
|
|
|
if (e.shiftKey) {
|
|
|
|
e.preventDefault(); // prevent browser range selection
|
|
|
|
}
|
|
|
|
});
|
|
|
|
divperm.addEventListener("click", function(e) {
|
|
|
|
if (e.ctrlKey) {
|
|
|
|
setSelected(!divperm.isSelected);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (e.shiftKey) {
|
|
|
|
if (lastSelIndex < 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var from = lastSelIndex;
|
|
|
|
var to = i;
|
|
|
|
if (to < from) {
|
|
|
|
from = i;
|
|
|
|
to = lastSelIndex;
|
|
|
|
}
|
|
|
|
for (var j = from; j <= to; j++) {
|
|
|
|
selSetter[j](true);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (var j in currentlySelected) {
|
|
|
|
if (j != i) {
|
|
|
|
selSetter[j](false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setSelected(!divperm.isSelected);
|
|
|
|
});
|
|
|
|
var alink = document.createElement("a");
|
|
|
|
alink.href = "./?p=" + br.blobRef;
|
|
|
|
var img = document.createElement("img");
|
|
|
|
img.src = br.thumbnailSrc;
|
|
|
|
img.height = br.thumbnailHeight;
|
|
|
|
img.width = br.thumbnailWidth;
|
|
|
|
alink.appendChild(img);
|
|
|
|
divperm.appendChild(alink);
|
|
|
|
var title = document.createElement("p");
|
|
|
|
setTextContent(title, camliBlobTitle(br.blobRef, searchRes));
|
|
|
|
title.className = 'camli-ui-thumbtitle';
|
|
|
|
divperm.appendChild(title);
|
|
|
|
divperm.className = 'camli-ui-thumb';
|
|
|
|
return divperm;
|
2012-11-28 18:15:39 +00:00
|
|
|
}
|
|
|
|
|
2012-11-09 18:35:59 +00:00
|
|
|
function indexBuildRecentlyUpdatedPermanodes(searchRes) {
|
|
|
|
var divrecent = document.getElementById("recent");
|
|
|
|
divrecent.innerHTML = "";
|
|
|
|
for (var i = 0; i < searchRes.recent.length; i++) {
|
2012-12-01 18:55:22 +00:00
|
|
|
divrecent.appendChild(divFromResult(searchRes, i));
|
2012-11-09 18:35:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("load", indexOnLoad);
|