📄 kupudrawers.js
字号:
this.selectUpload = function() { this.removeSelection(); this.showupload = 'yes'; this.updateDisplay(this.resourcespanelid); this.updateDisplay(this.propertiespanelid); } /*** Selecting a resource ***/ this.selectItem = function (id) { /* select an item in the item pane, show the item's metadata */ // First turn off current selection, if any this.removeSelection(); // Grab XML DOM node for clicked "resource" and mark it selected var newselxpath = '/libraries/*[@selected]//resource[@id="' + id + '"]'; var newselitem = this.xmldata.selectSingleNode(newselxpath); newselitem.setAttribute("selected", "1"); this.updateDisplay(this.resourcespanelid); this.updateDisplay(this.propertiespanelid); return; } this.search = function() { /* search */ var searchvalue = document.getElementById('kupu-searchbox-input').value; //XXX make search variable configurable var body = 'SearchableText=' + escape(searchvalue); // the search uri might contain query parameters in HTTP GET // style. We want to do a POST though, so find any possible // parameters, trim them from the URI and append them to the // POST body instead. var chunks = this.searchuri.split('?'); var searchuri = chunks[0]; if (chunks[1]) { body += "&" + chunks[1]; }; var wrapped_callback = new ContextFixer(this._searchCallback, this); this._loadXML(searchuri, wrapped_callback.execute, body); }; this._searchCallback = function(dom) { var resultlib = dom.selectSingleNode("/library"); var items = resultlib.selectNodes("items/*"); if (!items.length) { alert("No results found."); return; }; // we need to give the newly retrieved data a unique ID, we // just use the time. date = new Date(); time = date.getTime(); resultlib.setAttribute("id", time); // deselect the previous collection and mark the result // library as selected this.deselectActiveCollection(); resultlib.setAttribute("selected", "1"); // now hook the result library into our DOM if (this.editor.getBrowserName() == 'IE') { resultlib = resultlib.cloneNode(true); } else { this.xmldata.importNode(resultlib, true); } var libraries = this.xmldata.selectSingleNode("/libraries"); libraries.appendChild(resultlib); this.updateDisplay(this.drawerid); var newseldiv = document.getElementById(time); newseldiv.className = 'selected'; }; this.save = function() { /* save the element, should be implemented on subclasses */ throw "Not yet implemented"; }; /*** Auxiliary methods ***/ this._transformXml = function() { /* transform this.xmldata to HTML using this.xsl and return it */ var doc = Sarissa.getDomDocument(); //var xsltproc = new XSLTProcessor(); var result = this.xsltproc.transformToDocument(this.xmldata); // this.xmldata.transformNodeToObject(this.xsl, doc); return result; }; this._loadXML = function(uri, callback, body) { /* load the XML from a uri calls callback with one arg (the XML DOM) when done the (optional) body arg should contain the body for the request*/ var xmlhttp = Sarissa.getXmlHttpRequest(); var method = 'GET'; if (body) { method = 'POST'; } else { // be sure that body is null and not an empty string or // something body = null; }; xmlhttp.open(method, uri, true); // use ContextFixer to wrap the Sarissa callback, both for isolating // the 'this' problem and to be able to pass in an extra argument // (callback) var wrapped_callback = new ContextFixer(this._sarissaCallback, xmlhttp, callback, uri); xmlhttp.onreadystatechange = wrapped_callback.execute; if (method == "POST") { // by default, we would send a 'text/xml' request, which // is a dirty lie; explicitly set the content type to what // a web server expects from a POST. xmlhttp.setRequestHeader('content-type', 'application/x-www-form-urlencoded'); }; xmlhttp.send(body); }; this._replaceNodeContents = function(doc, target, container) { /* replace all childnodes in target with all childnodes in container */ var importedContainer = doc.importNode(container, true); // XXX it seems that IE doesn't allow hacks like these // no need to worry anyway, since the transformed HTML seems // to have the right JS context variables anyway. if (this.editor.getBrowserName() != 'IE') { container.ownerDocument.contentWindow = doc.contentWindow; }; while (target.hasChildNodes()) { target.removeChild(target.firstChild); }; // XXX don't know if this works since i'm not sure whether // appendChild actually removes a child from a previous // location (although i think it does) while (importedContainer.hasChildNodes()) { target.appendChild(importedContainer.firstChild); }; }; this._sarissaCallback = function(user_callback, uri) { /* callback for Sarissa when the callback is called because the data's ready it will get the responseXML DOM and call user_callback with the DOM as the first argument and the uri loaded as the second note that this method should be called in the context of an xmlhttp object */ var errmessage = 'Error loading XML: '; if (uri) { errmessage = 'Error loading ' + uri + ':'; }; if (this.readyState == 4) { if (this.status && this.status != 200) { alert(errmessage + this.status); throw "Error loading XML"; }; var dom = this.responseXML; user_callback(dom, uri); }; };};LibraryDrawer.prototype = new Drawer;function ImageLibraryDrawer(tool, xsluri, libsuri, searchuri) { /* a specific LibraryDrawer for images */ this.drawertitle = "Image Library"; this.drawertype = "image"; this.showupload = ''; this.init(tool, xsluri, libsuri, searchuri); // upload, on submit/insert press this.uploadImage = function() { var form = document.kupu_upload_form; if (!form || form.node_prop_image.value=='') return; if (form.node_prop_caption.value == "") { alert("Please enter a title for the image you are uploading"); return; }; var targeturi = this.xmldata.selectSingleNode('/libraries/*[@selected]/uri/text()').nodeValue document.kupu_upload_form.action = targeturi + "/kupuUploadImage"; document.kupu_upload_form.submit(); }; // called for example when no permission to upload for some reason this.cancelUpload = function(msg) { var s = this.xmldata.selectSingleNode('/libraries/*[@selected]'); s.removeAttribute("selected"); this.updateDisplay(); if (msg != '') { alert(msg); }; }; // called by onLoad within document sent by server this.finishUpload = function(url) { var img = this.tool.createImage(url); if (this.editor.config.captions) { img.className = img.className + " captioned"; } this.newimages = 1; this.drawertool.closeDrawer(); }; this.save = function() { /* create an image in the iframe according to collected data from the drawer */ var selxpath = '//resource[@selected]'; var selnode = this.xmldata.selectSingleNode(selxpath); // If no image resource is selected, check for upload if (!selnode) { var uploadbutton = this.xmldata.selectSingleNode("/libraries/*[@selected]//uploadbutton"); if (uploadbutton) { this.uploadImage(); }; return; }; var uri = selnode.selectSingleNode('uri/text()').nodeValue; uri = uri.strip(); // needs kupuhelpers.js var img = this.tool.createImage(uri); var alt = document.getElementById('image_alt').value; img.setAttribute('alt', alt); // Set image class from the alignment radio buttons var radios = document.getElementsByName('image-align'); for (var i = 0; i < radios.length; i++) { if (radios[i].checked) { img.className = radios[i].value; } } var caption = document.getElementsByName('image-caption'); if (caption && caption.length>0 && caption[0].checked) { img.className = img.className + " captioned"; } this.drawertool.closeDrawer(); };};ImageLibraryDrawer.prototype = new LibraryDrawer;function LinkLibraryDrawer(tool, xsluri, libsuri, searchuri) { /* a specific LibraryDrawer for links */ this.drawertitle = "Link Drawer"; this.drawertype = "link"; this.showupload = ''; this.init(tool, xsluri, libsuri, searchuri); this.save = function() { /* create a link in the iframe according to collected data from the drawer */ var selxpath = '//resource[@selected]'; var selnode = this.xmldata.selectSingleNode(selxpath); if (!selnode) { return; }; var uri = selnode.selectSingleNode('uri/text()').nodeValue; uri = uri.strip(); // needs kupuhelpers.js var title = ''; title = selnode.selectSingleNode('title/text()').nodeValue; title = title.strip(); // XXX requiring the user to know what link type to enter is a // little too much I think. (philiKON) var type = null; var name = document.getElementById('link_name').value; var target = null; if (document.getElementById('link_target') && document.getElementById('link_target').value != '') target = document.getElementById('link_target').value; this.tool.createLink(uri, type, name, target, title); };};LinkLibraryDrawer.prototype = new LibraryDrawer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -