0

I'm having an issue with LABjs. I load all my scripts, but when I use it in IE it completely breaks down.

 $LAB
     .script('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js').wait()
     .script('https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js')

And if I add a conditional statement

<!--[if IE ]>
     <script type="text/javascript" src="somescript.js"></script>
<![endif]-->

This would fail. How would I include this into LABjs?

Thanks.

xivo
  • 2,054
  • 3
  • 22
  • 37
  • I note that you're using jQuery 1.7.2. Be aware that 1.8 has recently been released, and has a significant number of fixes, particularly for IE. This is probably relevant to you, given the IE-specific nature of the question. – Spudley Aug 25 '12 at 16:48
  • also note that if you are going to upgrade to jquery 1.8, then you have to be careful to use a compatible version of jquery-ui. I recently got bitten by a huge breaking incompat when upgrading only jquery. – Kyle Simpson Aug 25 '12 at 17:33

1 Answers1

1

I would first STRONGLY say, you shouldn't be doing IE-only scripts any more. But if you really absolutely must, and after you slap yourself on the wrist several times for that bad practice...

(function(){

   // From: http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/
   var ie_version=(function(){var c,a=3,b=document.createElement('div'),d=b.getElementsByTagName('i');while(b.innerHTML='<!--[if gt IE '+(++a)+']><i></i><![endif]-->',d[0]);return a>4?a:c})();

   $LAB.setOptions({AlwaysPreserveOrder:true})
   .script('https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js')
   .script('https:///ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js')
   .script(ie_version ? 'somescript.js' : '')
})();

The ie_version snippet of code comes from: http://james.padolsey.com/javascript/detect-ie-in-js-using-conditional-comments/ which uses dynamically created IE conditional comments to determine an IE version.

NOTE: I'm assuming that "somescript.js" needs to be executed strictly after the jquery and jquery-ui scripts, based on what you posted. If that's not the case, you could put it in a different position in the $LAB chain if you wanted to, and you could take out the setOptions({AlwaysPreserveOrder:true}) and instead use wait() in the chain only where desired/necessary.

Kyle Simpson
  • 15,725
  • 2
  • 33
  • 55
  • I'd agree with your initial assertion, as applied to "any version of IE"; IE9 should be considered modern enough not to need IE-specific hacks, and IE10 doesn't even support conditional comments. But there is a good case to be had still for IE version specific hacks, if you need to support IE8 or earlier. There are some things which are very difficult to deal with any other way. – Spudley Aug 25 '12 at 16:46
  • Most of the things that are "hard" to do identically in chrome 22 vs IE6 (CSS styling wise that is) are things which you shouldn't be trying to do identically in the first place. Allowing bosses/clients/marketing depts to convince you that 100% pixel identical cross-browser/cross-version is realistic -- THAT is the big lie that holds us back. If you stop trying to be identical, most of this stops being "hard" to handle. Let things degrade/fail as they will, and accept THAT as the true identity of the evolving web platform. – Kyle Simpson Aug 25 '12 at 17:36
  • If you can't handle that IE6 will put extra padding on your floats, or the box model is different, and the *different* (aka, not broken) rendering is unacceptable, then you're forced to do this kind of crap. But the reality is, most legacy IE6 users don't care that you went to that extra effort to make the two boxes identically line up. It's wasted effort. Plain and simple. – Kyle Simpson Aug 25 '12 at 17:38
  • Moreover, to the point of THIS question, there's even FEWER cases where the JS you write for chrome 22 is incompatible with the JS you write for IE6. And frameworks usually take care of those diffs for you. So, the need to do IE-specific JavaScript is a wholly unlikely to be a "good thing" that you should want to keep supporting. Better to remove a feature entirely than to do that. – Kyle Simpson Aug 25 '12 at 17:40
  • Although, I do support what you feel about this Kyle. I'm very limited to what I can do on the server. The problems arise base on situations and this is the only solution possible at this point (very limited permissions). Our clients are mainly IE8 and below. But, I will take into consideration what you have told me. I will see if I can eliminate IE8 and below from the universe by not supporting it eventually :) Thank you for your solution and you wonderful script! – xivo Aug 26 '12 at 03:15