temporarily disable IE repaint?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan  Ellis

    #1

    temporarily disable IE repaint?

    I have some code that looks like this:

    var options = document.sform. files.options
    for (var i = 0; i < options.length; i++) {
    options[i].selected = true
    }

    As it loops you can see the options scroll by while IE renders each
    one. For a couple hundred options this is okay, but I need to handle
    up to 10,000. (Long story.) Is there a way to hint to IE that "hey,
    I'm going to do a lot of these, wait until we're all done before
    repainting?" Or is there a better way to speed things up?

    Sample html:

    <html>
    <body>
    <script language=javasc ript>
    function selectall() {
    var options = document.sform. files.options
    for (var i = 0; i < options.length; i++) {
    options[i].selected = true
    }
    }
    </script>

    <form name=sform>
    <select name=files multiple size=10>
    <option>foo
    <!-- repeat option line a few thousand times -->
    </select>
    <input type=button onclick="select all()" value="select">
    </form>

    </body>
    </html>

    Thanks,

    -Jonathan

  • Yann-Erwan Perio

    #2
    Re: temporarily disable IE repaint?

    Jonathan Ellis wrote:

    Hi,
    [color=blue]
    > I have some code that looks like this:
    >
    > var options = document.sform. files.options
    > for (var i = 0; i < options.length; i++) {
    > options[i].selected = true
    > }
    >
    > As it loops you can see the options scroll by while IE renders each
    > one. For a couple hundred options this is okay, but I need to handle
    > up to 10,000. (Long story.) Is there a way to hint to IE that "hey,
    > I'm going to do a lot of these, wait until we're all done before
    > repainting?" Or is there a better way to speed things up?[/color]

    I don't think you can prevent the repainting in IE, but you could try
    hiding the select box, select the options and show it again - this would
    give interesting results in IE, which AIUI you're only concerned with.

    Other browsers wouldn't benefit from this approach though, you'd have to
    use other techniques (for instance working on orphaned nodes) - or more
    simply not have a select box with 10,000 entries (short story).


    <script type="text/javascript">
    var SelectOptions = (function(){
    var selectObj=null;
    var options=[];

    function selectOptions(b Select){
    selectObj.style .visibility="hi dden";
    setTimeout(
    function(){
    for(var ii=options.leng th; ii--;)
    options[ii].selected=bSele ct;
    selectObj.style .visibility="vi sible";
    },
    1
    );
    }

    return {
    init : function() {
    selectObj=docum ent.forms["sform"].elements["files"];
    for(var opt=selectObj.o ptions, ii=opt.length; ii--;)
    options[ii]=opt[ii];
    },
    selectAll : function() {
    options[0].selected=true; //to speed IE
    selectOptions(t rue);
    },
    selectNone: function() {
    selectOptions(f alse);
    }
    };
    })();

    window.onload = function() {
    SelectOptions.i nit();
    }
    </script>

    <form name="sform">
    <script type="text/javascript">
    var buf=["<select name='files' multiple='multi ple' size='10'>"];
    for(var ii=0; ii<10000; ii++)
    buf[buf.length]="<option>fo o<\/option>";
    buf[buf.length]="<\/select>";
    document.write( buf.join(""));
    </script>
    <input type=button onclick="Select Options.selectA ll()" value="1">
    <input type=button onclick="Select Options.selectN one()" value="2">
    </form>


    HTH,
    Yep.

    Comment

    • Jim Ley

      #3
      Re: temporarily disable IE repaint?

      On Thu, 09 Jun 2005 17:35:57 +0200, Yann-Erwan Perio <yep@invalid.co m>
      wrote:
      [color=blue]
      >I don't think you can prevent the repainting in IE,[/color]

      screen.updateIn terval

      but use with immense caution, it's almost never sensible to do it.

      Jim.

      Comment

      • Yann-Erwan Perio

        #4
        Re: temporarily disable IE repaint?

        Jim Ley wrote:
        [color=blue][color=green]
        >>I don't think you can prevent the repainting in IE,[/color][/color]
        [color=blue]
        > screen.updateIn terval
        >
        > but use with immense caution, it's almost never sensible to do it.[/color]

        Ahah, I didn't know this one, it's a funny property:-)

        I can't manage to make it work in regards of the OP's needs, though (it
        seems that the selection is not considered as repainting, maybe due to
        select elements being windowed controls - or my test cases being
        completely inadequate, it's been time since I haven't programmed).


        Cheers,
        Yep.

        Comment

        • RobG

          #5
          Re: temporarily disable IE repaint?

          Jonathan Ellis wrote:[color=blue]
          > I have some code that looks like this:
          >
          > var options = document.sform. files.options
          > for (var i = 0; i < options.length; i++) {
          > options[i].selected = true
          > }
          >
          > As it loops you can see the options scroll by while IE renders each
          > one. For a couple hundred options this is okay, but I need to handle
          > up to 10,000. (Long story.) Is there a way to hint to IE that "hey,
          > I'm going to do a lot of these, wait until we're all done before
          > repainting?" Or is there a better way to speed things up?
          >
          > Sample html:
          >
          > <html>
          > <body>
          > <script language=javasc ript>
          > function selectall() {
          > var options = document.sform. files.options
          > for (var i = 0; i < options.length; i++) {
          > options[i].selected = true
          > }
          > }
          > </script>
          >
          > <form name=sform>
          > <select name=files multiple size=10>
          > <option>foo[/color]

          A closing tag is required for option elements, perhaps that was slowing
          you down. The following selects all options in about 2 seconds in IE,
          Firefox takes about 20 seconds (your performance may vary...).

          A do..while does not seem to offer any significant benefit in
          this case (not to mention that I'd love to know the point of 10,000
          options).


          <form action="" name="formA">
          <select multiple name="bigSelect ">
          <script type="text/javascript">
          var s = document.forms['formA'].elements['bigSelect'];
          for ( var i=0; i<10000; i++ ){
          document.write( "<option>Op tion " + i + "</option>");
          }
          </script>
          </select>


          <input type="button" value="Select do..while" onclick="
          var opts = this.form.eleme nts['bigSelect'].options;
          var x, i=0;
          var s = new Date()
          if ( ( x = opts[i] ) ){
          do {
          x.selected = true;
          } while ( ( x = opts[++i] ) )
          }
          var f = new Date();
          alert( (f-s));
          ">

          <input type="button" value="Select for..length" onclick="
          var options = this.form.eleme nts['bigSelect'].options;
          var s = new Date()
          for (var i = 0; i < options.length; i++) {
          options[i].selected = true
          }
          var f = new Date();
          alert( (f-s));
          ">
          </form>



          --
          Rob

          Comment

          • Jim Ley

            #6
            Re: temporarily disable IE repaint?

            On Fri, 10 Jun 2005 07:31:32 GMT, RobG <rgqld@iinet.ne t.auau> wrote:
            [color=blue]
            >Jonathan Ellis wrote:
            > A closing tag is required for option elements, perhaps that was slowing
            > you down.[/color]

            Nope, closing option tag is optional in HTML, IE only understands HTML
            of course.

            Jim.

            Comment

            • RobG

              #7
              Re: temporarily disable IE repaint?

              Jim Ley wrote:[color=blue]
              > On Fri, 10 Jun 2005 07:31:32 GMT, RobG <rgqld@iinet.ne t.auau> wrote:
              >
              >[color=green]
              >>Jonathan Ellis (actually RobG) wrote:
              >> A closing tag is required for option elements, perhaps that was slowing
              >> you down.[/color]
              >
              >
              > Nope, closing option tag is optional in HTML, IE only understands HTML
              > of course.[/color]

              Dang, I even checked the spec - but the 'option' link from the HTML
              elements index takes you to the header for select, optgroup and
              option so I actually read the requirements for select, not option.


              --
              Rob

              Comment

              Working...