// THIS FILE IS AUTO-GENERATED FROM index.js // DO NOT EDIT. package ui import "time" import "camlistore.org/pkg/fileembed" func init() { Files.Add("index.js", 8945, fileembed.String("/*\n"+ "Copyright 2012 Camlistore Authors.\n"+ "\n"+ "Licensed under the Apache License, Version 2.0 (the \"License\");\n"+ "you may not use this file except in compliance with the License.\n"+ "You may obtain a copy of the License at\n"+ "\n"+ " http://www.apache.org/licenses/LICENSE-2.0\n"+ "\n"+ "Unless required by applicable law or agreed to in writing, software\n"+ "distributed under the License is distributed on an \"AS IS\" BASIS,\n"+ "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n"+ "See the License for the specific language governing permissions and\n"+ "limitations under the License.\n"+ "*/\n"+ "\n"+ "var CamliIndexPage = {};\n"+ "\n"+ "CamliIndexPage.onLoad = function() {\n"+ " CamliIndexPage.startRecentLoading();\n"+ "\n"+ " var selView = $(\"selectView\");\n"+ " var goTargets = {\n"+ " \"recent\": function() { alert(\"not implemented, but it's already in recent m"+ "ode\"); },\n"+ " \"date\": function() { alert(\"TODO: pop up a date selector dialog\"); },\n"+ " \"debug:signing\": \"signing.html\", \n"+ " \"debug:disco\": \"disco.html\",\n"+ " \"debug:misc\": \"debug.html\",\n"+ " \"search\": \"search.html\"\n"+ " };\n"+ " selView.addEventListener(\n"+ " \"change\",\n"+ " function(e) {\n"+ " var target = goTargets[selView.value];\n"+ " if (!target) {\n"+ " return;\n"+ " }\n"+ " if (typeof(target) == \"string\") {\n"+ " window.location = target;\n"+ " }\n"+ " if (typeof(target) == \"function\") {\n"+ " target();\n"+ " }\n"+ " });\n"+ "\n"+ " $(\"formSearch\").addEventListener(\"submit\", CamliIndexPage.onSearchSubmit);\n"+ "\n"+ " setTextContent($(\"topTitle\"), Camli.config.ownerName + \"'s Vault\");\n"+ "};\n"+ "\n"+ "CamliIndexPage.startRecentLoading = function() {\n"+ " camliGetRecentlyUpdatedPermanodes({success: CamliIndexPage.onLoadedRecentItem"+ "s, thumbnails: 150});\n"+ "};\n"+ "\n"+ "CamliIndexPage.onSearchSubmit = function(e) {\n"+ " e.preventDefault();\n"+ " e.stopPropagation();\n"+ " var searchVal = $(\"textSearch\").value;\n"+ " if (searchVal == \"\") {\n"+ " CamliIndexPage.startRecentLoading();\n"+ " } else {\n"+ " // TODO: super lame. for now. should just change filter\n"+ " // of existing page, without navigating away.\n"+ " window.location = \"search.html?t=tag&q=\" + searchVal;\n"+ " }\n"+ "};\n"+ "\n"+ "var lastSelIndex = 0;\n"+ "var selSetter = {}; // numeric index -> func(selected) setter\n"+ "var currentlySelected = {}; // currently selected index -> true\n"+ "var itemsSelected = 0;\n"+ "\n"+ "// divFromResult converts the |i|th searchResult into\n"+ "// a div element, style as a thumbnail tile.\n"+ "function divFromResult(searchRes, i) {\n"+ " var result = searchRes.recent[i];\n"+ " var br = searchRes[result.blobref];\n"+ " var divperm = document.createElement(\"div\");\n"+ " var setSelected = function(selected) {\n"+ " if (divperm.isSelected == selected) {\n"+ " return;\n"+ " }\n"+ " divperm.isSelected = selected;\n"+ " if (selected) {\n"+ " lastSelIndex = i;\n"+ " currentlySelected[i] = true;\n"+ " divperm.classList.add(\"selected\");\n"+ " } else {\n"+ " delete currentlySelected[selected];\n"+ " lastSelIndex = -1;\n"+ " divperm.classList.remove(\"selected\");\n"+ " }\n"+ " itemsSelected += selected ? 1 : -1;\n"+ " $(\"optFromSel\").disabled = (itemsSelected == 0);\n"+ " };\n"+ " selSetter[i] = setSelected;\n"+ " divperm.addEventListener(\"mousedown\", function(e) {\n"+ " if (e.shiftKey) {\n"+ " e.preventDefault(); // prevent browser range selection\n"+ " }\n"+ " });\n"+ " divperm.addEventListener(\"click\", function(e) {\n"+ " if (e.ctrlKey) {\n"+ " setSelected(!divperm.isSelected);\n"+ " return;\n"+ " }\n"+ " if (e.shiftKey) {\n"+ " if (lastSelIndex < 0) {\n"+ " return;\n"+ " }\n"+ " var from = lastSelIndex;\n"+ " var to = i;\n"+ " if (to < from) {\n"+ " from = i;\n"+ " to = lastSelIndex;\n"+ " }\n"+ " for (var j = from; j <= to; j++) {\n"+ " selSetter[j](true);\n"+ " }\n"+ " return;\n"+ " }\n"+ " for (var j in currentlySelected) {\n"+ " if (j != i) {\n"+ " selSetter[j](false);\n"+ " }\n"+ " }\n"+ " setSelected(!divperm.isSelected);\n"+ " });\n"+ " var alink = document.createElement(\"a\");\n"+ " alink.href = \"./?p=\" + br.blobRef;\n"+ " var img = document.createElement(\"img\");\n"+ " img.src = br.thumbnailSrc;\n"+ " img.height = br.thumbnailHeight;\n"+ " img.width = br.thumbnailWidth;\n"+ " alink.appendChild(img);\n"+ " divperm.appendChild(alink);\n"+ " var title = document.createElement(\"p\");\n"+ " setTextContent(title, camliBlobTitle(br.blobRef, searchRes));\n"+ " title.className = 'camli-ui-thumbtitle';\n"+ " divperm.appendChild(title);\n"+ " divperm.className = 'camli-ui-thumb';\n"+ " return divperm;\n"+ "}\n"+ "\n"+ "// createPlusButton returns the div element that is both a button\n"+ "// a drop zone for new file(s).\n"+ "function createPlusButton() {\n"+ " var div = document.createElement(\"div\");\n"+ " div.id = \"plusdrop\";\n"+ " div.className = \"camli-ui-thumb\";\n"+ "\n"+ " var plusLink = document.createElement(\"a\");\n"+ " plusLink.classList.add(\"plusLink\");\n"+ " plusLink.href = '#';\n"+ " plusLink.innerHTML = \"+\";\n"+ " div.appendChild(plusLink);\n"+ "\n"+ " var statusDiv = document.createElement(\"div\");\n"+ " statusDiv.innerHTML = \"Click or drag & drop files here.\";\n"+ " // TODO: use statusDiv instead (hidden by default), but put\n"+ " // it somewhere users can get to it with a click.\n"+ " div.appendChild(statusDiv);\n"+ "\n"+ " plusLink.addEventListener(\"click\", function(e) {\n"+ " e.preventDefault();\n"+ " camliCreateNewPermanode({\n"+ " success: function(blobref) {\n"+ " window.location = \"./?p=\" + blobref;\n"+ " },\n"+ " fail: function(msg) {\n"+ " alert(\"create permanode failed: \" + msg);\n"+ " }\n"+ " });\n"+ " });\n"+ " \n"+ " var stop = function(e) {\n"+ " this.classList && this.classList.add('camli-dnd-over');\n"+ " e.stopPropagation();\n"+ " e.preventDefault();\n"+ " };\n"+ " div.addEventListener(\"dragenter\", stop, false);\n"+ " div.addEventListener(\"dragover\", stop, false);\n"+ " div.addEventListener(\"dragleave\", function() {\n"+ " this.classList.remove('camli-dnd-over');\n"+ " }, false);\n"+ "\n"+ " var drop = function(e) {\n"+ " this.classList.remove('camli-dnd-over');\n"+ " stop(e);\n"+ " var dt = e.dataTransfer;\n"+ " var files = dt.files;\n"+ " var subject = \"\";\n"+ " if (files.length == 1) {\n"+ " subject = files[0].name;\n"+ " } else {\n"+ " subject = files.length + \" files\";\n"+ " }\n"+ " statusDiv.innerHTML = \"Uploading \" + subject + \" (status)\";\n"+ " startFileUploads(files, document.getElementById(\"debugstatus\"), {\n"+ " success: function() {\n"+ " statusDiv.innerHTML = \"Uploaded.\";\n"+ "\n"+ " // TODO(bradfitz): this just re-does the whole initial\n"+ " // query, and only at the very end of all the uploads.\n"+ " // it would be cooler if, when uploading a dozen\n"+ " // large files, we saw the permanodes load in one-at-a-time\n"+ " // as the became available.\n"+ " CamliIndexPage.startRecentLoading();\n"+ " }\n"+ " });\n"+ " };\n"+ " div.addEventListener(\"drop\", drop, false);\n"+ " return div;\n"+ "}\n"+ "\n"+ "// files: array of File objects to upload and create permanods for.\n"+ "// If >1, also create an enclosing permanode for them to all\n"+ "// be members of.\n"+ "// statusdiv: optional div element to log status messages to.\n"+ "// opts:\n"+ "// -- success: function([permanodes])\n"+ "function startFileUploads(files, statusDiv, opts) {\n"+ " var parentNode = opts.parentNode;\n"+ " if (files.length > 1 && !parentNode) {\n"+ " // create a new parent permanode with dummy\n"+ " // title and re-call startFileUploads with\n"+ " // opts.parentNode set, so we upload into that.\n"+ " }\n"+ "\n"+ " var log = function(msg) {\n"+ " if (statusDiv) {\n"+ " var p = document.createElement(\"p\");\n"+ " p.innerHTML = msg;\n"+ " statusDiv.appendChild(p);\n"+ " }\n"+ " };\n"+ "\n"+ " var remain = files.length;\n"+ " log(\"Need to upload \" + remain + \" files\");\n"+ "\n"+ " var permanodes = [];\n"+ " var fails = [];\n"+ " var decr = function() {\n"+ " remain--;\n"+ " log(remain + \" remaining now\");\n"+ " if (remain > 0) {\n"+ " return;\n"+ " }\n"+ " if (fails.length > 0) {\n"+ " if (opts.fail) {\n"+ " opts.fail(fails)\n"+ " }\n"+ " return\n"+ " }\n"+ " if (permanodes.length == files.length) {\n"+ " if (opts.success) {\n"+ " opts.success();\n"+ " }\n"+ " }\n"+ " };\n"+ " var permanodeGood = function(permaRef, fileRef) {\n"+ " log(\"File succeeeded: file=\" + fileRef + \" permanode=\" + permaRef);\n"+ " permanodes.push(permaRef);\n"+ " decr();\n"+ " };\n"+ " var fileFail = function(msg) {\n"+ " log(\"File failed: \" + msg);\n"+ " fails.push(msg);\n"+ " decr();\n"+ " };\n"+ " var fileSuccess = function(fileRef) {\n"+ " camliCreateNewPermanode({\n"+ " success: function(filepn) {\n"+ " camliNewSetAttributeClaim(filepn, \"camliContent\", fileRef, {\n"+ " success: function() {\n"+ " permanodeGood(filepn, fileRef);\n"+ " },\n"+ " fail: fileFail\n"+ " });\n"+ " }\n"+ " });\n"+ " };\n"+ " \n"+ " // TODO(bradfitz): do something smarter than starting all at once.\n"+ " // Only keep n in flight or something?\n"+ " for (var i = 0; i < files.length; i++) {\n"+ " camliUploadFile(files[i], {\n"+ " success: fileSuccess, \n"+ " fail: fileFail\n"+ " });\n"+ " }\n"+ "}\n"+ "\n"+ "CamliIndexPage.onLoadedRecentItems = function (searchRes) {\n"+ " var divrecent = document.getElementById(\"recent\");\n"+ " divrecent.innerHTML = \"\";\n"+ " divrecent.appendChild(createPlusButton());\n"+ " for (var i = 0; i < searchRes.recent.length; i++) {\n"+ " divrecent.appendChild(divFromResult(searchRes, i));\n"+ " }\n"+ "};\n"+ "\n"+ "window.addEventListener(\"load\", CamliIndexPage.onLoad);\n"+ ""), time.Unix(0, 1355281561309868978)) }