Bug Tracker

Opened 6 years ago

Closed 6 years ago

#14890 closed bug (notabug)

TypeError: Argument 1 of Window.getDefaultComputedStyle is not an object

Reported by: mr.efrem@… Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 2.1.0
Keywords: Cc:
Blocked by: Blocking:

Description

I use hack for support of client-size XSLT:

var defaultNS = document.documentElement.namespaceURI;
/**
 * Use the given object to override the given methods in its prototype
 * with namespace-aware equivalents
 */
function addNS(obj, methods) {
    var proto = obj.constructor.prototype;

    for (var methodName in methods) {
        (function() {
            var methodNS = proto[methodName + "NS"];

            if (methodNS) {
                proto[methodName] = function() {
                    var args = Array.prototype.slice.call(arguments, 0);
                    args.unshift(defaultNS);
                    return methodNS.apply(this, args);
                };
            }
        })();
    }
}

// Play nice with IE -- who doesn't need this hack in the first place
if (document.constructor) {
    // Override document methods that are used by jQuery
    addNS(document, {
        createElement: 1/*,
        getElementsByTagName: 1*/
    });

    // Override element methods that are used by jQuery
    /*addNS(document.createElement("div"), {
        getElementsByTagName: 1,
        getAttribute: 1,
        getAttributeNode: 1,
        removeAttribute: 1,
        setAttribute: 1
    });*/
}

And in funcion get error in line 5422: "TypeError: Argument 1 of Window.getDefaultComputedStyle is not an object."

function actualDisplay( name, doc ) {
        var elem=jQuery( doc.createElement( name ) ).appendTo( doc.body );

        // getDefaultComputedStyle might be reliably used only on attached element
            display = window.getDefaultComputedStyle ?

                // Use of this method is a temporary fix (more like optmization) until something better comes along,
                // since it was removed from specification and supported only in FF
                window.getDefaultComputedStyle( elem[0] ).display : jQuery.css( elem[0], "display" );

        // We don't have any data stored on the element,
        // so use "detach" method as fast way to get rid of the element
        elem.detach();

        return display;
    }

As for me works:

function actualDisplay( name, doc ) {
        var origElem=doc.createElement( name );
        var elem = jQuery( origElem ).appendTo( doc.body ),

        // getDefaultComputedStyle might be reliably used only on attached element
            display = window.getDefaultComputedStyle ?

                // Use of this method is a temporary fix (more like optmization) until something better comes along,
                // since it was removed from specification and supported only in FF
                window.getDefaultComputedStyle( origElem ).display : jQuery.css( origElem, "display" );

        // We don't have any data stored on the element,
        // so use "detach" method as fast way to get rid of the element
        elem.detach();

        return display;
    }

Change History (3)

comment:1 Changed 6 years ago by mr.efrem@…

I use jquery-ui-autocomplete and get error "TypeError: this.menu is undefined" likely for the same reason. I have a suspicion that a problem in appendTo.

this.menu = $( "<ul>" )
            .addClass( "ui-autocomplete ui-front" )
            .appendTo( this._appendTo() )
			.menu({
				// disable ARIA support, the live region takes care of that
				role: null
			})
			.hide()
			.data( "ui-menu" );

		this._on( this.menu.element, {

comment:2 Changed 6 years ago by mr.efrem@…

The most interesting that this problem is watched only in Firefox 27.0.1. In Google Chrome 33.0.1750.149 and IE 11.0.1 it isn't present.

comment:3 Changed 6 years ago by dmethvin

Resolution: notabug
Status: newclosed

This is the jQuery core bug tracker. Read the page at http://bugs.jquery.com to see what to do next. They'll need a full test case as well, which didn't come with this report.

Note: See TracTickets for help on using tickets.