1. #1
    Ext User
    Join Date
    Apr 2008
    Posts
    2
    Vote Rating
    0
    haremyak is on a distinguished road

      0  

    Default [2.??] DomHelper.insertHtml -"INVALID_NODE_TYPE_ERR:DOM Range Exception 2" in Safari

    [2.??] DomHelper.insertHtml -"INVALID_NODE_TYPE_ERR:DOM Range Exception 2" in Safari


    In safari 3.1.1, when $element is not attached to the document the following calls:
    Code:
    var $range = $element.ownerDocument.createRange();
    $range.setStartBefore($element);
    $range.setStartAfter($element.lastChild);
    fails with RangeException: "INVALID_NODE_TYPE_ERR: DOM Range Exception 2"

    So for safari and not attached element I write the following fix:
    Code:
    /**
     * Inserts an HTML fragment into the DOM.
     * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
     * @param {HTMLElement} el The context element
     * @param {String} html The HTML fragmenet
     * @return {HTMLElement} The new node
     */
    Ext.DomHelper.insertHtml = (function() {
    	var insertHtmlOld = Ext.DomHelper.insertHtml;
    
    	function isAttached( $element ) {
    		var $body = $element.ownerDocument.body;
    
    		while ($element != null && $element != $body) {
    			$element = $element.parentNode;
    		}
    
    		return $element != null;
    	}
    
    	function isHackApplicable( $element, $exception ) {
    		if (!RangeException || !RangeException["INVALID_NODE_TYPE_ERR"]) {
    			return false;
    		}
    		if (!($exception instanceof RangeException)) {
    			return false;
    		}
    		if ($exception.code != RangeException["INVALID_NODE_TYPE_ERR"]) {
    			return false;
    		}
    		if (!Ext.isSafari) {
    			return false;
    		}
    		if (isAttached($element)) {
    			return false;
    		}
    
    		return true;
    	}
    
    	return function( $where, $element, $html ) {
    		var $exception;
    
    		try {
    			return insertHtmlOld.apply(Ext.DomHelper, arguments);
    		} catch ($e) {
    			$exception = $e;
    		}
    
    		/**
    		 * In safari 3.1.1, when $element is not attached to the document the following calls:
    		 *      var $range = $element.ownerDocument.createRange();
    		 *      $range.setStartBefore($element);
    		 *      $range.setStartAfter($element.lastChild);
    		 *
    		 *  always fails with RangeException:
    		 * "INVALID_NODE_TYPE_ERR: DOM Range Exception 2"
    		 *
    		 * So for safari and not attached element the following fix was written
    		 */
    		if (isHackApplicable($element, $exception)) {
    			var $div = document.createElement("DIV");
    			$div.innerHTML = $html;
    
    			switch ($where.toLowerCase()) {
    				case "beforebegin":
    					while ($div.childNodes.length > 0) {
    						$element.parentNode.insertBefore($div.childNodes[0], $element);
    					}
    					return $element.previousSibling;
    
    				case "beforeend":
    					while ($div.childNodes.length > 0) {
    						$element.appendChild($div.childNodes[0]);
    					}
    					return $element.lastChild;
    			}
    		}
    
    		$html = $html.length > 60 ? $html.substr(0, 57) + "..." : $html;
    		Ext.console.error("insertHtml("
    				+ "\"" + $where + "\""
    				+ ", \"" + $element.nodeName.toLowerCase() + "\""
    				+ ", \"" + $html.replace(/(["\\])/g, "\\$1") + "\""
    				+ ") failed with exception:\n" + $exception);
    
    		/** If hack is not applicable - throw original exception */
    		throw $exception;
    	};
    })();

  2. #2
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default


    i don't see $element anywhere in the source.

    what's an "$element", and under what circumstances would it not be attached to the document?

    please post details as per http://www.sencha.com/forum/showthread.php?t=13985

  3. #3
    Ext User
    Join Date
    Apr 2007
    Posts
    168
    Vote Rating
    0
    SmyersM is on a distinguished road

      0  

    Default Hmm

    Hmm


    I verified this bug as existing in our product.

    To the support person: His solution is a drop-in replacement on top of the existing ExtJS code. So the parameters ($element) are the same as the normal ExtJS api.

    He tests for a crash of a specific type, then attaches something to the dom, then does the work on that dom attached div.

    The drop-in solution worked well for me. Thanks.
    Michael Smyers / Lead Developer / msmyers -a@t- zipwhip.com
    www.zipwhip.com

  4. #4
    Sencha - Community Support Team mystix's Avatar
    Join Date
    Mar 2007
    Location
    Singapore
    Posts
    6,236
    Vote Rating
    5
    mystix will become famous soon enough

      0  

    Default


    Which version of Safari did you see this bug in?

    Also, did you encounter it with ext-base or the jquery adapter?

    and lastly, was this with Ext 2.2.1?

  5. #5
    Sencha User
    Join Date
    Dec 2011
    Location
    Ukraine
    Posts
    1
    Vote Rating
    0
    sdima2 is on a distinguished road

      0  

    Default I had the sane problem

    I had the sane problem


    I had the sane problem under Chrome, Sencha SDK 1.1

Thread Participants: 3