⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kupudrawers.js

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JS
📖 第 1 页 / 共 3 页
字号:
        // Change by Paul to have cached xslt transformers for reuse of         // multiple transforms and also xslt params        try {            this.xsltproc = new XSLTProcessor();            this.xsltproc.importStylesheet(dom);            this.xsltproc.setParameter("", "drawertype", this.drawertype);            this.xsltproc.setParameter("", "drawertitle", this.drawertitle);            this.xsltproc.setParameter("", "showupload", this.showupload);            if (this.editor.config.captions) {                this.xsltproc.setParameter("", "usecaptions", 'yes');            }        } catch(e) {            return; // No XSLT Processor, maybe IE 5.5?        }    };    this.createContent = function() {        // load the initial XML        if(!this.xmldata) {            // Do a meaningful test to see if this is IE5.5 or some other             // editor-enabled version whose XML support isn't good enough             // for the drawers            if (!Sarissa.IS_ENABLED_XSLTPROC) {               alert("This function requires better XML support in your browser.");               return;            }            this.loadLibraries();        } else {            if (this.newimages) {                this.reloadCurrent();                this.newimages = null;            };            this.updateDisplay();        };        // display the drawer div        this.element.style.display = 'block';        if (this.editor.getBrowserName() == 'IE') {            this.element.focus();        }    };    this._singleLibsXslCallback = function(dom) {        /* callback for then the xsl for single libs (items) is loaded            nothing special needs to be called here, since initially the            items pane will be empty        */        this.singlelibxsl = dom;    };    this.loadLibraries = function() {        /* load the libraries and display them in a redrawn drawer */        var wrapped_callback = new ContextFixer(this._libsContentCallback, this);        this._loadXML(this.libsuri, wrapped_callback.execute);    };    this._libsContentCallback = function(dom) {        /* this is called when the libs xml is loaded            does the xslt transformation to set up or renew the drawer's full            content and adds the content to the drawer        */        this.xmldata = dom;        this.xmldata.setProperty("SelectionLanguage", "XPath");        // replace whatever is in there with our stuff        this.updateDisplay(this.drawerid);    };    this.updateDisplay = function(id) {      /* (re-)transform XML and (re-)display the necessary part       */        if(!id) {            id = this.drawerid;        };        try {            this.xsltproc.setParameter("", "showupload", this.showupload);        } catch(e) {};        var doc = this._transformXml();        var sourcenode = doc.selectSingleNode('//*[@id="'+id+'"]');        var targetnode = document.getElementById(id);        this._replaceNodeContents(document, targetnode, sourcenode);        if (this.editor.getBrowserName() == 'IE' && id == this.resourcespanelid) {            this.updateDisplay(this.drawerid);        };    };    this.deselectActiveCollection = function() {        /* Deselect the currently active collection or library */        while (1) {            // deselect selected DOM node            var selected = this.xmldata.selectSingleNode('//*[@selected]');            if (!selected) {                return;            };            selected.removeAttribute('selected');        };    };    /*** Load a library ***/    this.selectLibrary = function(id) {        /* unselect the currently selected lib and select a new one            the selected lib (libraries pane) will have a specific CSS class             (selected)        */        // remove selection in the DOM        this.deselectActiveCollection();        // as well as visual selection in CSS        // XXX this is slow, but we can't do XPath, unfortunately        var divs = this.element.getElementsByTagName('div');        for (var i=0; i<divs.length; i++ ) {          if (divs[i].className == 'kupu-libsource-selected') {            divs[i].className = 'kupu-libsource';          };        };        var libnode_path = '/libraries/library[@id="' + id + '"]';        var libnode = this.xmldata.selectSingleNode(libnode_path);        libnode.setAttribute('selected', '1');        var items_xpath = "items";        var items_node = libnode.selectSingleNode(items_xpath);                if (items_node && !this.newimages) {            // The library has already been loaded before or was            // already provided with an items list. No need to do            // anything except for displaying the contents in the            // middle pane. Newimages is set if we've lately            // added an image.            this.updateDisplay(this.resourcespanelid);            this.updateDisplay(this.propertiespanelid);        } else {            // We have to load the library from XML first.            var src_uri = libnode.selectSingleNode('src/text()').nodeValue;            src_uri = src_uri.strip(); // needs kupuhelpers.js            // Now load the library into the items pane. Since we have            // to load the XML, do this via a call back            var wrapped_callback = new ContextFixer(this._libraryContentCallback, this);            this._loadXML(src_uri, wrapped_callback.execute, null);            this.newimages = null;        };        // instead of running the full transformations again we get a         // reference to the element and set the classname...        var newseldiv = document.getElementById(id);        newseldiv.className = 'kupu-libsource-selected';    };    this._libraryContentCallback = function(dom, src_uri) {        /* callback for when a library's contents (item list) is loaded        This is also used as he handler for reloading a standard        collection.        */        var libnode = this.xmldata.selectSingleNode('//*[@selected]');        var itemsnode = libnode.selectSingleNode("items");        var newitemsnode = dom.selectSingleNode("//items");        // IE does not support importNode on XML document nodes. As an        // evil hack, clonde the node instead.        if (this.editor.getBrowserName() == 'IE') {            newitemsnode = newitemsnode.cloneNode(true);        } else {            newitemsnode = this.xmldata.importNode(newitemsnode, true);        }        if (!itemsnode) {            // We're loading this for the first time            libnode.appendChild(newitemsnode);        } else {            // User has clicked reload            libnode.replaceChild(newitemsnode, itemsnode);        };        this.updateDisplay(this.resourcespanelid);        this.updateDisplay(this.propertiespanelid);    };    /*** Load a collection ***/    this.selectCollection = function(id) {        this.deselectActiveCollection();        // First turn off current selection, if any        this.removeSelection();                var leafnode_path = "//collection[@id='" + id + "']";        var leafnode = this.xmldata.selectSingleNode(leafnode_path);        // Case 1: We've already loaded the data, so we just need to        // refer to the data by id.        var loadedInNode = leafnode.getAttribute('loadedInNode');        if (loadedInNode) {            var collnode_path = "/libraries/collection[@id='" + loadedInNode + "']";            var collnode = this.xmldata.selectSingleNode(collnode_path);            if (collnode) {                collnode.setAttribute('selected', '1');                this.updateDisplay(this.resourcespanelid);                this.updateDisplay(this.propertiespanelid);                return;            };        };        // Case 2: We've already loaded the data, but there hasn't        // been a reference made yet. So, make one :)        uri = leafnode.selectSingleNode('uri/text()').nodeValue;        uri = (new String(uri)).strip(); // needs kupuhelpers.js        var collnode_path = "/libraries/collection/uri[text()='" + uri + "']/..";        var collnode = this.xmldata.selectSingleNode(collnode_path);        if (collnode) {            id = collnode.getAttribute('id');            leafnode.setAttribute('loadedInNode', id);            collnode.setAttribute('selected', '1');            this.updateDisplay(this.resourcespanelid);            this.updateDisplay(this.propertiespanelid);            return;        };        // Case 3: We've not loaded the data yet, so we need to load it        // this is just so we can find the leafnode much easier in the        // callback.        leafnode.setAttribute('selected', '1');        var src_uri = leafnode.selectSingleNode('src/text()').nodeValue;        src_uri = src_uri.strip(); // needs kupuhelpers.js        var wrapped_callback = new ContextFixer(this._collectionContentCallback, this);        this._loadXML(src_uri, wrapped_callback.execute, null);    };    this._collectionContentCallback = function(dom, src_uri) {        // Unlike with libraries, we don't have to find a node to hook        // our results into (UNLESS we've hit the reload button, but        // that is handled in _libraryContentCallback anyway).        // We need to give the newly retrieved data a unique ID, we        // just use the time.        date = new Date();        time = date.getTime();        // attach 'loadedInNode' attribute to leaf node so Case 1        // applies next time.        var leafnode = this.xmldata.selectSingleNode('//*[@selected]');        leafnode.setAttribute('loadedInNode', time);        this.deselectActiveCollection()        var collnode = dom.selectSingleNode('/collection');        collnode.setAttribute('id', time);        collnode.setAttribute('selected', '1');        var libraries = this.xmldata.selectSingleNode('/libraries');        // IE does not support importNode on XML documet nodes        if (this.editor.getBrowserName() == 'IE') {            collnode = collnode.cloneNode(true);        } else {            collnode = this.xmldata.importNode(collnode, true);        }        libraries.appendChild(collnode);        this.updateDisplay(this.resourcespanelid);        this.updateDisplay(this.propertiespanelid);    };    /*** Reloading a collection or library ***/    this.reloadCurrent = function() {        // Reload current collection or library        this.showupload = '';        var current = this.xmldata.selectSingleNode('//*[@selected]');        // make sure we're dealing with a collection even though a        // resource might be selected        if (current.tagName == "resource") {            current.removeAttribute("selected");            current = current.parentNode;            current.setAttribute("selected", "1");        };        var src_node = current.selectSingleNode('src');        if (!src_node) {            // simply do nothing if the library cannot be reloaded. This            // is currently the case w/ search result libraries.            return;        };        var src_uri = src_node.selectSingleNode('text()').nodeValue;                src_uri = src_uri.strip(); // needs kupuhelpers.js        var wrapped_callback = new ContextFixer(this._libraryContentCallback, this);        this._loadXML(src_uri, wrapped_callback.execute);    };    this.removeSelection = function() {        // turn off current selection, if any        var oldselxpath = '/libraries/*[@selected]//resource[@selected]';        var oldselitem = this.xmldata.selectSingleNode(oldselxpath);        if (oldselitem) {            oldselitem.removeAttribute("selected");        };        this.showupload = '';    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -