Advertisement
stephandesouza

IE 7 - Fancybox.init() on jQuery 1.6 Fix

May 5th, 2011
1,876
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.   $.fancybox.init = function() {
  3.     if ($("#fancybox-wrap").length) {
  4.       return;
  5.     }
  6.    
  7.     /*
  8.     * IE 7 Fix
  9.     * Pre-init vars
  10.     */
  11.     tmp = $('<div id="fancybox-tmp"></div>');
  12.     loading = $('<div id="fancybox-loading"><div></div></div>');
  13.     overlay = $('<div id="fancybox-overlay"></div>');
  14.     wrap = $('<div id="fancybox-wrap"></div>');
  15.     content = $('<div id="fancybox-content"></div>');
  16.     close = $('<a id="fancybox-close"></a>');
  17.     title = $('<div id="fancybox-title"></div>');
  18.     nav_left = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>');
  19.     nav_right = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>');
  20.  
  21.     /*
  22.     * IE 7 Fix
  23.     * Old:
  24.     *
  25.         $('body').append(
  26.             tmp = $('<div id="fancybox-tmp"></div>'),
  27.             loading = $('<div id="fancybox-loading"><div></div></div>'),
  28.             overlay = $('<div id="fancybox-overlay"></div>'),
  29.             wrap = $('<div id="fancybox-wrap"></div>')
  30.         );
  31.     */
  32.     if($.browser.msie && $.browser.version < 8) {
  33.       $('body').append(tmp).append(loading).append(overlay).append(wrap);
  34.     } else {
  35.       $('body').append(tmp, loading, overlay, wrap);
  36.     }
  37.    
  38.     outer = $('<div id="fancybox-outer"></div>')
  39.     .append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>')
  40.     .appendTo( wrap );
  41.      
  42.  
  43.     /*
  44.    * IE 7 Fix:
  45.    * Old:
  46.    *
  47.                   outer.append(
  48.                           content = $('<div id="fancybox-content"></div>'),
  49.                           close = $('<a id="fancybox-close"></a>'),
  50.                           title = $('<div id="fancybox-title"></div>'),
  51.  
  52.                           nav_left = $('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),
  53.                           nav_right = $('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>')
  54.                   );
  55.    */
  56.     if($.browser.msie && $.browser.version < 8) {
  57.       outer.append(content).append(close).append(title).append(nav_left).append(nav_right);
  58.     } else {
  59.       outer.append(content, close, title, nav_left, nav_right);
  60.     }
  61.  
  62.     close.click($.fancybox.close);
  63.     loading.click($.fancybox.cancel);
  64.  
  65.     nav_left.click(function(e) {
  66.       e.preventDefault();
  67.       $.fancybox.prev();
  68.     });
  69.  
  70.     nav_right.click(function(e) {
  71.       e.preventDefault();
  72.       $.fancybox.next();
  73.     });
  74.  
  75.     if ($.fn.mousewheel) {
  76.       wrap.bind('mousewheel.fb', function(e, delta) {
  77.         if (busy) {
  78.           e.preventDefault();
  79.  
  80.         } else if ($(e.target).get(0).clientHeight == 0 || $(e.target).get(0).scrollHeight === $(e.target).get(0).clientHeight) {
  81.           e.preventDefault();
  82.           $.fancybox[ delta > 0 ? 'prev' : 'next']();
  83.         }
  84.       });
  85.     }
  86.  
  87.     if (!$.support.opacity) {
  88.       wrap.addClass('fancybox-ie');
  89.     }
  90.  
  91.     if (isIE6) {
  92.       loading.addClass('fancybox-ie6');
  93.       wrap.addClass('fancybox-ie6');
  94.  
  95.       $('<iframe id="fancybox-hide-sel-frame" src="' + (/^https/i.test(window.location.href || '') ? 'javascript:void(false)' : 'about:blank' ) + '" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(outer);
  96.     }
  97.   };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement