六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 123|回复: 0

Extjs3.0 DomHelper Bug

[复制链接]

升级  12%

172

主题

172

主题

172

主题

进士

Rank: 4

积分
560
 楼主| 发表于 2013-2-7 20:44:09 | 显示全部楼层 |阅读模式
Ext.apply(Ext.DomHelper,function(){var pub,afterbegin = 'afterbegin',    afterend = 'afterend',    beforebegin = 'beforebegin',    beforeend = 'beforeend';// private    function doInsert(el, o, returnElement, pos, sibling, append){        el = Ext.getDom(el);        var newNode;        //错了,由于闭包,不能在外部设置useDom=true了。        if (pub.useDom) {        //应该为 Ext.DomHelper.useDom            newNode = createDom(o, null);            if (append) {            el.appendChild(newNode);            } else {        (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);            }        } else {            newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));        }        return returnElement ? Ext.get(newNode, true) : newNode;    }// build as dom    /** @ignore */    function createDom(o, parentNode){        var el,        doc = document,        useSet,        attr,        val,        cn;        if (Ext.isArray(o)) {                       // Allow Arrays of siblings to be inserted            el = doc.createDocumentFragment(); // in one shot using a DocumentFragment        Ext.each(o, function(v) {                createDom(v, el);            });        } else if (Ext.isString(o)) {         // Allow a string as a child spec.            el = doc.createTextNode(o);        } else {            el = doc.createElement( o.tag || 'div' );            useSet = !!el.setAttribute; // In IE some elements don't have setAttribute            Ext.iterate(o, function(attr, val){                if(!/tag|children|cn|html|style/.test(attr)){                if(attr == 'cls'){                    el.className = val;                }else{                        if(useSet){                            el.setAttribute(attr, val);                        }else{                            el[attr] = val;                        }                }                }            });            pub.applyStyles(el, o.style);            if ((cn = o.children || o.cn)) {                createDom(cn, el);            } else if (o.html) {                el.innerHTML = o.html;            }        }        if(parentNode){           parentNode.appendChild(el);        }        return el;    }pub = {/**     * Creates a new Ext.Template from the DOM object spec.     * @param {Object} o The DOM object spec (and children)     * @return {Ext.Template} The new template     */    createTemplate : function(o){        var html = Ext.DomHelper.createHtml(o);        return new Ext.Template(html);    },/** True to force the use of DOM instead of html fragments @type Boolean */    useDom : false,    /**     * Applies a style specification to an element.     * @param {String/HTMLElement} el The element to apply styles to     * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or     * a function which returns such a specification.     */    applyStyles : function(el, styles){    if(styles){var i = 0,    len,    style;    el = Ext.fly(el);if(Ext.isFunction(styles)){   styles = styles.call();}if(Ext.isString(styles)){styles = styles.trim().split(/\s*(?::|;)\s*/);for(len = styles.length; i < len;){el.setStyle(styles[i++], styles[i++]);}}else if (Ext.isObject(styles)){el.setStyle(styles);}}    },    /**     * Creates new DOM element(s) and inserts them before el.     * @param {Mixed} el The context element     * @param {Object/String} o The DOM object spec (and children) or raw HTML blob     * @param {Boolean} returnElement (optional) true to return a Ext.Element     * @return {HTMLElement/Ext.Element} The new node         * @hide (repeat)     */    insertBefore : function(el, o, returnElement){        return doInsert(el, o, returnElement, beforebegin);    },    /**     * Creates new DOM element(s) and inserts them after el.     * @param {Mixed} el The context element     * @param {Object} o The DOM object spec (and children)     * @param {Boolean} returnElement (optional) true to return a Ext.Element     * @return {HTMLElement/Ext.Element} The new node         * @hide (repeat)     */    insertAfter : function(el, o, returnElement){        return doInsert(el, o, returnElement, afterend, 'nextSibling');    },    /**     * Creates new DOM element(s) and inserts them as the first child of el.     * @param {Mixed} el The context element     * @param {Object/String} o The DOM object spec (and children) or raw HTML blob     * @param {Boolean} returnElement (optional) true to return a Ext.Element     * @return {HTMLElement/Ext.Element} The new node         * @hide (repeat)     */    insertFirst : function(el, o, returnElement){        return doInsert(el, o, returnElement, afterbegin, 'firstChild');    },    /**     * Creates new DOM element(s) and appends them to el.     * @param {Mixed} el The context element     * @param {Object/String} o The DOM object spec (and children) or raw HTML blob     * @param {Boolean} returnElement (optional) true to return a Ext.Element     * @return {HTMLElement/Ext.Element} The new node         * @hide (repeat)     */    append: function(el, o, returnElement){            return doInsert(el, o, returnElement, beforeend, '', true);        },    /**     * Creates new DOM element(s) without inserting them to the document.     * @param {Object/String} o The DOM object spec (and children) or raw HTML blob     * @return {HTMLElement} The new uninserted node     */        createDom: createDom};return pub;}()); 


        //错了,由于闭包,不能在外部设置useDom=true了。
        if (pub.useDom) {
        //应该为 Ext.DomHelper.useDom

 
 
 
有些情况需要 设置 Ext.DomHelper.useDom =true
 
如:
 
 
Ext.DomHelper 添加 option 问题







现在 Extjs 3.0 设置后无效了


另外发现 ext-core 3.0 和 extjs 3.0 完全版 相同功能的代码实现有些不一样,如 ext-core 3.0 DomHelper 根本没上述代码,也就是说 core 不能用dom方式了 ,好像 core 是 完全版的 简化降级形式,太不爽了!很多有用的基础函数都在core里被删掉了,完全版还有,看来要定制一个自己的core了!
 
 
 
 
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表