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

📄 kupuhelpers.js

📁 一个使用struts+hibernate+spring开发的完的网站源代码。
💻 JS
📖 第 1 页 / 共 4 页
字号:
/***************************************************************************** * * Copyright (c) 2003-2004 Kupu Contributors. All rights reserved. * * This software is distributed under the terms of the Kupu * License. See LICENSE.txt for license text. For a list of Kupu * Contributors see CREDITS.txt. * *****************************************************************************/// $Id: kupuhelpers.js,v 1.1 2005/03/26 20:31:36 svieujot Exp $/*Some notes about the scripts:- Problem with bound event handlers:        When a method on an object is used as an event handler, the method uses     its reference to the object it is defined on. The 'this' keyword no longer    points to the class, but instead refers to the element on which the event    is bound. To overcome this problem, you can wrap the method in a class that    holds a reference to the object and have a method on the wrapper that calls    the input method in the input object's context. This wrapped method can be    used as the event handler. An example:    class Foo() {        this.foo = function() {            // the method used as an event handler            // using this here wouldn't work if the method            // was passed to addEventListener directly            this.baz();        };        this.baz = function() {            // some method on the same object        };    };    f = new Foo();    // create the wrapper for the function, args are func, context    wrapper = new ContextFixer(f.foo, f);    // the wrapper can be passed to addEventListener, 'this' in the method    // will be pointing to the right context.    some_element.addEventListener("click", wrapper.execute, false);- Problem with window.setTimeout:    The window.setTimeout function has a couple of problems in usage, all     caused by the fact that it expects a *string* argument that will be    evalled in the global namespace rather than a function reference with    plain variables as arguments. This makes that the methods on 'this' can    not be called (the 'this' variable doesn't exist in the global namespace)    and references to variables in the argument list aren't allowed (since    they don't exist in the global namespace). To overcome these problems,     there's now a singleton instance of a class called Timer, which has one     public method called registerFunction. This can be called with a function    reference and a variable number of extra arguments to pass on to the     function.    Usage:        timer_instance.registerFunction(this, this.myFunc, 10, 'foo', bar);        will call this.myFunc('foo', bar); in 10 milliseconds (with 'this'        as its context).*///----------------------------------------------------------------------------// Helper classes and functions//----------------------------------------------------------------------------function addEventHandler(element, event, method, context) {    /* method to add an event handler for both IE and Mozilla */    var wrappedmethod = new ContextFixer(method, context);    try {        if (_SARISSA_IS_MOZ) {            element.addEventListener(event, wrappedmethod.execute, false);        } else if (_SARISSA_IS_IE) {            element.attachEvent("on" + event, wrappedmethod.execute);        } else {            throw "Unsupported browser!";        };    } catch(e) {        alert('exception ' + e.message + ' while registering an event handler for element ' + element + ', event ' + event + ', method ' + method);    };};function removeEventHandler(element, event, method) {    /* method to remove an event handler for both IE and Mozilla */    if (_SARISSA_IS_MOZ) {        window.removeEventListener('focus', method, false);    } else if (_SARISSA_IS_IE) {        element.detachEvent("on" + event, method);    } else {        throw "Unsupported browser!";    };};function openPopup(url, width, height) {    /* open and center a popup window */    var sw = screen.width;    var sh = screen.height;    var left = sw / 2 - width / 2;    var top = sh / 2 - height / 2;    var win = window.open(url, 'someWindow',                 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top);    return win;};function selectSelectItem(select, item) {    /* select a certain item from a select */    for (var i=0; i < select.options.length; i++) {        var option = select.options[i];        if (option.value == item) {            select.selectedIndex = i;            return;        }    }    select.selectedIndex = 0;};function ParentWithStyleChecker(tagnames, style, stylevalue) {    /* small wrapper that provides a generic function to check if a       button should look pressed in */    return function(selNode, button, editor, event) {        /* check if the button needs to look pressed in */        var currnode = selNode;        if (!currnode) {            return;        };        if (currnode.nodeType == 3) {            currnode = currnode.parentNode;        };        while (currnode && currnode.style) {            for (var i=0; i < tagnames.length; i++) {                if (currnode.nodeName.toLowerCase() == tagnames[i].toLowerCase()) {                    return true;                };            };            if (tagnames.contains(currnode.nodeName.toLowerCase()) &&                     (style && currnode.style[style] == stylevalue)) {                return true;            };            currnode = currnode.parentNode;        };        return false;    };};function _load_dict_helper(element) {    /* walks through a set of XML nodes and builds a nested tree of objects */    var dict = {};    for (var i=0; i < element.childNodes.length; i++) {        var child = element.childNodes[i];        if (child.nodeType == 1) {            var value = '';            for (var j=0; j < child.childNodes.length; j++) {                // test if we can recurse, if so ditch the string (probably                // ignorable whitespace) and dive into the node                if (child.childNodes[j].nodeType == 1) {                    value = _load_dict_helper(child);                    break;                } else if (typeof(value) == typeof('')) {                    value += child.childNodes[j].nodeValue;                };            };            if (typeof(value) == typeof('') && !isNaN(parseInt(value)) &&                     parseInt(value).toString().length == value.length) {                value = parseInt(value);            } else if (typeof(value) != typeof('')) {                if (value.length == 1) {                    value = value[0];                };            };            var name = child.nodeName.toLowerCase();            if (dict[name] != undefined) {                if (!dict[name].push) {                    dict[name] = new Array(dict[name], value);                } else {                    dict[name].push(value);                };            } else {                dict[name] = value;            };        };    };    return dict;};function loadDictFromXML(document, islandid) {    /* load configuration values from an XML chunk        this is quite generic, it just reads data from a chunk of XML into        an object, checking if the object is complete should be done in the        calling context.    */    var dict = {};    var confnode = document.getElementById(islandid);    var root = null;    for (var i=0; i < confnode.childNodes.length; i++) {        if (confnode.childNodes[i].nodeType == 1) {            root = confnode.childNodes[i];            break;        };    };    if (!root) {        throw('No element found in the config island!');    };    dict = _load_dict_helper(root);    return dict;};function NodeIterator(node, continueatnextsibling) {    /* simple node iterator        can be used to recursively walk through all children of a node,        the next() method will return the next node until either the next        sibling of the startnode is reached (when continueatnextsibling is         false, the default) or when there's no node left (when         continueatnextsibling is true)        returns false if no nodes are left    */        this.node = node;    this.current = node;    this.terminator = continueatnextsibling ? null : node;        this.next = function() {        /* return the next node */        if (this.current === false) {            // restart            this.current = this.node;        };        var current = this.current;        if (current.firstChild) {            this.current = current.firstChild;        } else {            // walk up parents until we finish or find one with a nextSibling            while (current != this.terminator && !current.nextSibling) {                current = current.parentNode;            };            if (current == this.terminator) {                this.current = false;            } else {                this.current = current.nextSibling;            };        };        return this.current;    };    this.reset = function() {        /* reset the iterator so it starts at the first node */        this.current = this.node;    };    this.setCurrent = function(node) {        /* change the current node                        can be really useful for specific hacks, the user must take            care that the node is inside the iterator's scope or it will            go wild        */        this.current = node;    };};/* selection classes, these are wrappers around the browser-specific    selection objects to provide a generic abstraction layer*/function BaseSelection() {    /* superclass for the Selection objects            this will contain higher level methods that don't contain         browser-specific code    */    this.splitNodeAtSelection = function(node) {        /* split the node at the current selection            remove any selected text, then split the node on the location            of the selection, thus creating a new node, this is attached to            the node's parent after the node            this will fail if the selection is not inside the node        */        if (!this.selectionInsideNode(node)) {            throw('Selection not inside the node!');        };        // a bit sneaky: what we'll do is insert a new br node to replace        // the current selection, then we'll walk up to that node in both        // the original and the cloned node, in the original we'll remove        // the br node and everything that's behind it, on the cloned one        // we'll remove the br and everything before it        // anyway, we'll end up with 2 nodes, the first already in the         // document (the original node) and the second we can just attach        // to the doc after the first one        var doc = this.document.getDocument();        var br = doc.createElement('br');        br.setAttribute('node_splitter', 'indeed');        this.replaceWithNode(br);                var clone = node.cloneNode(true);        // now walk through the original node        var iterator = new NodeIterator(node);        var currnode = iterator.next();        var remove = false;        while (currnode) {            if (currnode.nodeName.toLowerCase() == 'br' && currnode.getAttribute('node_splitter') == 'indeed') {                // here's the point where we should start removing                remove = true;            };            // we should fetch the next node before we remove the current one, else the iterator            // will fail (since the current node is removed)            var lastnode = currnode;            currnode = iterator.next();            // XXX this will leave nodes that *became* empty in place, since it doesn't visit it again,

⌨️ 快捷键说明

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