explorer.js
来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· JavaScript 代码 · 共 119 行
JS
119 行
/*
* Copyright 2001-2007 Hippo (www.hippo.nl)
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*/
/*
* explorer.js
*
* User Interface layer for the CMS Editor Framework
*
*/
cocoon.load("site:/generic/generic.js");
cocoon.load("site:/workflow/workflow.js");
cocoon.load("site:/util/flow/lib-io.js");
importClass(Packages.java.io.BufferedOutputStream);
importClass(Packages.java.io.File);
importClass(Packages.java.io.FileOutputStream);
importClass(Packages.java.util.HashSet);
importClass(Packages.nl.hippo.uidgenerator.UIDGenerator);
importClass(Packages.nl.hippo.util.FileDeletionTask);
importClass(Packages.org.apache.cocoon.components.cron.JobScheduler);
// globals
var perspective = null;
function trees() {
var path = cocoon.parameters["path"];
var perspective = cocoon.parameters["perspective"];
var template = cocoon.parameters["template"];
var sources = cocoon.parameters["sources"];
if(sources != null)
sources = sources.split(',');
// each entry in "tree" is a path to a currently expanded node in the folder tree
if(perspective == null || perspective == '')
{
if (path.length > 2 && path.charAt(path.length-1) == '/') {
perspective = path.substring(0, path.length - 1);
}
}
var tree = cocoon.session.getAttribute("tree" + perspective);
// get the requested action (expand or collapse)
var action = cocoon.request.get("action");
// remove trailing slash
if (path.length > 2 && path.charAt(path.length-1) == '/') {
path = path.substring(0, path.length - 1);
}
if (tree == null) { // initialize tree
tree = new HashSet();
cocoon.session.setAttribute("tree"+perspective, tree);
// TODO: root nodes sometimes disappear from tree ?!? (temp fix below)
// UPDATE: [JR] This should be fixed now.
// UPDATE: [AB] Don't add a 'deep' path on init
if(action != "expandPath")
tree.add(path);
}
if (tree.contains(path)) { // collapse or browser refresh
if (action == "collapse") {
// collapse this node and all descendants
var exitTree = new HashSet();
var i = tree.iterator();
while (i.hasNext()) {
var iValue = i.next();
if (iValue.indexOf(path) == 0) {
exitTree.add(iValue)
}
}
var i = exitTree.iterator();
while (i.hasNext()) {
tree.remove(i.next());
}
}
else if(tree.size() == 1) { //init
for(var i=0; i<sources.length;i++){
if(!tree.contains(sources[i]))
tree.add(sources[i]);
}
}
}
else if (action == "expandPath") {
var folders = path.split("/");
var newPath = "";
for(var i=1;i<folders.length;i++){
newPath += "/" + folders[i];
if(!tree.contains(newPath))
tree.add(newPath);
}
}else { // expand is default action
tree.add(path);
}
cocoon.session.setAttribute("tree" + perspective, tree);
cocoon.sendPage(template, {"tree" : tree});
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?