[jQuery] Opera indexOf support

[jQuery] Opera indexOf support

<span style="font-family: trebuchet ms;">I got a note that someone that my sprites didn't work in Opera.  So I fired up my virtual PC and installed Opera.</span><br style="font-family: trebuchet ms;"><span style="font-family: trebuchet ms;">
jQuery was not the culprit.  The problem was that Opera does not support indexOf on an array, just on strings.</span><br style="font-family: trebuchet ms;"><span style="font-family: trebuchet ms;">Info in bottom of this page:
<a href="http://www.howtocreate.co.uk/emails/NicolasR.html">http://www.howtocreate.co.uk/emails/NicolasR.html</a></span><br style="font-family: trebuchet ms;"><br style="font-family: trebuchet ms;"><span style="font-family: trebuchet ms;">
I found this, which extends Opera to solve the problem.</span><br style="font-family: trebuchet ms;"><span style="font-family: trebuchet ms;">Info in middle of this page: <a href="http://www.sitepoint.com/forums/showthread.php?t=318494">
http://www.sitepoint.com/forums/showthread.php?t=318494</a></span><br style="font-family: trebuchet ms;"><br style="font-family: trebuchet ms;"><span style="font-family: trebuchet ms;">Code:</span><br style="font-family: trebuchet ms;">
<span style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">if (!Array.prototype.indexOf) {</span><br style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;"><span style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">
    Array.prototype.indexOf = function(val, fromIndex) {</span><br style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;"><span style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">
        if (typeof(fromIndex) != 'number') fromIndex = 0;</span><br style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;"><span style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">
        for (var index = fromIndex,len = this.length; index < len; index++)</span><br style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;"><span style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">
            if (this[index] == val) return index;</span><br style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;"><span style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">
        return -1;</span><br style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;"><span style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">    }</span><br style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">
<span style="background-color: rgb(255, 255, 153); font-family: courier new,monospace;">}</span><br style="font-family: trebuchet ms;"><br style="font-family: trebuchet ms;"><span style="font-family: trebuchet ms;">This immediately fixed the opera problem with no side-effects I can detect.
</span><br style="font-family: trebuchet ms;"><br style="font-family: trebuchet ms;"><span style="font-family: trebuchet ms;">So my questions are: 
</span><ol><li><span style="font-family: trebuchet ms;">Do any plugins depend on indexOf in a way that will not work in Opera?
</span></li><li><span style="font-family: trebuchet ms;">Maybe this snippet of code should be put in jQuery?</span></li><li><span style="font-family: trebuchet ms;">Maybe I should post this to the dev list?</span></li>
</ol><span style="font-family: trebuchet ms;">Glen<br style="font-family: trebuchet ms;"></span>















    • Topic Participants

    • glen