📄 clipboard.js
字号:
/*
* 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.
*/
/**
* Clipboard class.
* The clipboard contains a list of resources. The resources can be selected
* from any view in the CMS implementing the "add to clipboard" action.
* The list can be imported from a document, and pasted back into a document
* (after editing).
*/
function Clipboard() {
if(!Cfx.Class.IsDefined(Clipboard)) {
Cfx.Class.New(Clipboard);
if(Cfx.Class.IsInitializing(Clipboard)) {
Clipboard.Method(init);
Clipboard.Method(reset);
Clipboard.Method(activate);
Clipboard.Method(deactivate);
Clipboard.Method(copy);
Clipboard.Method(paste);
Clipboard.Method(importItems);
Clipboard.Method(importXml);
Clipboard.Method(getListView);
return;
}
}
this.InitInstance();
var list = null;
var visible = false;
var destination = null;
var workbench = null;
var destinationPerspective = null;
var listview = null;
function init()
{
this.list = new List();
this.list.init();
this.list.setCaptionAttributeName(null);
this.list.setUriPrefix("");
this.list.setUriPostfix("");
this.workbench = top.frames["topframe"];
this.listView = new ListGUI();
this.listView.init(this.list);
this.pasteAction = null;
this.updateAction = null;
}
function reset()
{
this.destination = null;
this.visible = false;
this.list.clear();
this.init();
}
/**
* Activates the clipboard.
*
* @param selectionPerspective perspective to switch to on activation
* @param destinationPerspective perspective to switch to on "paste"
* @param destinationFormField form field to paste list xml into
* @param pasteAction optional javascript function to call on paste
* @param maxNumberOfItems optional max number of items allowed
*/
function activate(selectionPerspective, destinationPerspective, destinationFormField, updateAction, pasteAction, uriPrefix, uriPostfix, listElementName, itemElementName, uriAttributeName, maxNumberOfItems)
{
this.init();
this.destination = destinationFormField;
this.destinationPerspective = destinationPerspective;
this.updateAction = updateAction;
if (uriPrefix != null)
{
this.list.setUriPrefix(uriPrefix);
}
if (uriPostfix != null)
{
this.list.setUriPostfix(uriPostfix);
}
if (maxNumberOfItems != null)
{
this.list.setMaxNumberOfItems(maxNumberOfItems);
}
this.list.setTopLevelElementName(listElementName);
this.list.setItemElementName(itemElementName);
this.list.setUriAttributeName(uriAttributeName);
this.importXml(destinationFormField.value);
if (!this.visible)
{
this.workbench.showClipboard();
this.visible = true;
}
this.workbench.workbench.showMenu(selectionPerspective);
if (pasteAction != null)
{
this.pasteAction = pasteAction;
}
setTimeout("window.top.window.frames['topframe'].Application.sm.lookup('framework.eventmanager').fireEvent('doSearch', [{'key':'addClipboard','val':'true'}])",1500);
}
/**
* Deactivates the clipboard.
*
*/
function deactivate()
{
if (this.visible)
{
this.workbench.hideClipboard();
this.visible = false;
}
if (this.destinationPerspective)
{
this.workbench.workbench.showMenu(this.destinationPerspective);
}
}
/**
* Adds a resource to the clipboard's list.
*
* @param uri the resource's uri
* @param caption the resource's caption
*/
function copy(uri, caption)
{
if (this.visible && this.list != null)
{
this.list.addItem(uri, unescape(caption));
}
if (this.listView != null)
{
this.listView.update();
}
}
/**
* Pastes the clipboard's list into the destination form field (in XML format).
*/
function paste()
{
if (this.destination != null && this.list != null)
{
this.updateAction(this.list.serializeAsXml());
}
if (this.pasteAction != null)
{
this.pasteAction.call();
}
this.deactivate();
}
/**
* Imports an array of items into the clipboard's list. This method is called from
* the iframe in which the captions are retrieved from the repository.
*/
function importItems(items)
{
if (this.list != null)
{
for (var i = 0; i < items.length; i++)
{
this.list.addItem(items[i].uri, items[i].caption);
}
this.listView.update();
}
}
/**
* Import a list in XML format by posting it to an iframe in which the captions
* of the resources in the list are retrieved.
*/
function importXml(xml)
{
document.getElementById("clipboardContents").value = xml;
document.getElementById("import").value = "true";
document.getElementById("uriPrefix").value = this.list.getUriPrefix();
document.getElementById("uriPostfix").value = this.list.getUriPostfix();
document.getElementById("listElementName").value = this.list.getTopLevelElementName();
document.getElementById("itemElementName").value = this.list.getItemElementName();
document.getElementById("uriAttributeName").value = this.list.getUriAttributeName();
document.forms["clipboardForm"].submit();
document.getElementById("import").value = "false";
}
function getListView()
{
return this.listView;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -