Pregunta

jQuery-Terminal is a very good plug in to have a text mode terminal interface on web page. But it pops up an error : " Invalid operation to 'in': Object expected" when run on .HTA instead of .HTML. Don't worry, I have fixed it in an ugly way. Question is : how to fix it by jQuery-Terminal.js itself ?

/* .HTA file is like .HTML but, instead of run by browsers, Microsoft Windows built-in a differet interpreter, mshta.exe, to run HTA without all those restrictions on .HTML. */

My solution is to add an if() statement into "jquery-1.10.2.js" (so it's ugly), as shown below:

    inArray: function( elem, arr, i ) {
        var len;

        if ( arr ) {
            if ( core_indexOf ) {
                return core_indexOf.call( arr, elem, i );
            }

            len = arr.length;
            i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0;

            for ( ; i < len; i++ ) {
// ----------- I add this statement -------------------------------------------------------
                if ( typeof arr == 'string' && arr.indexOf(elem) != -1 ) {
                    return i;
                }
// --------------------------------------------------------------------------------------
                // Skip accessing in sparse arrays
                if ( i in arr && arr[ i ] === elem ) {
                    return i;
                }
            }
        }

        return -1;
    },

The strage thing is 'arr' is supposed an array. But when it is actually a 'string' the WWW browser won't complain anything but HTA interpreter mshta.exe will alert the error mentioned above. I believe this is a bug in jQuery-Terminal-xxxx.js plugin itself.

I hope jQuery-Terminal-xxxx.js plugin would fix it someday or even better to know how to fix it into jQuery-Terminal-xxxx.js now?

Simplified example and all the details can be found here, http://www.evernote.com/shard/s22/sh/9f47a3fb-16ad-4761-b2ab-d702b9886c2e/577e35cd6e9ab8ee0cb7f3529e985be9

¿Fue útil?

Solución

If you search for inArray in source code you find only two places, the one is

if (!$.inArray(interpreter_name, name)) {
    names.push(interpreter_name);
    $.Storage.set(name, $.json_stringify(names));
}

which is a typo it should be names (array) not name (a string)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top