如何精简 jquery 以满足您的需求?

发布于 2024-09-12 09:08:49 字数 1851 浏览 4 评论 0原文

我正在运行此脚本,我想知道是否需要所有 http:// code.jquery.com/jquery-latest.min.js

它有 70 kb,我希望能够将其精简。

$('a.inframe').click(function() {
  var e=$(this);

  if (!e.data('state')) { //if state is undefined

   e.data('state','open'); //set the state to 'open'

   // Extract the frame height from the rel attribute
   var frameHeight=e.attr('rel');
   var pat1 = new RegExp('height:');
   pat1.test(frameHeight);
   frameHeight=RegExp.rightContext;
   var pat2 = new RegExp('px');
   pat2.test(frameHeight);
   frameHeight = RegExp.leftContext;
   if ( !frameHeight || (Math.ceil(frameHeight)!=Math.floor(frameHeight)) ) {
    //if it's null or not an integer
    frameHeight = '550'; //default frame height, in case none is specified
   };
   frameHeight += 'px';

   frameWidth = '100%';

   // Insert the iframe just after the link
   e.after('<iframe style="width:'+frameWidth+'; height:'+frameHeight+'; border:solid 0px #ccc; margin-bottom:1em; background:#fff;" src=' + e.attr('href') + ' frameborder="0" ></iframe>');
   var iframe=e.next('iframe');

   // Insert the "loading..." text
   iframe.before(' <small class="quiet"> hold on a sec...</small>')
   iframe.load(function(){ //once content was loaded
    iframe.slideDown(500); //slide it down
    iframe.prev('small').remove(); //remove the 'loading...'
   });
   e.attr('title','Hide'); //set the link title to 'Hide'
  }
  else if(e.data('state')=='closed') { //if state is 'closed'
   e.data('state', 'open');
   e.next('iframe').slideDown(500);
   e.attr('title','Hide');
  }
  else if(e.data('state')=='open') { //if state is 'open'
   e.data('state', 'closed');
   e.next('iframe').slideUp(500);
   e.attr('title','Show');
  }
  return false;
 });
});

I have this script running, and I'm wondering if I need all of http://code.jquery.com/jquery-latest.min.js

It's 70 kb, and I would love to be able to strip it down.

$('a.inframe').click(function() {
  var e=$(this);

  if (!e.data('state')) { //if state is undefined

   e.data('state','open'); //set the state to 'open'

   // Extract the frame height from the rel attribute
   var frameHeight=e.attr('rel');
   var pat1 = new RegExp('height:');
   pat1.test(frameHeight);
   frameHeight=RegExp.rightContext;
   var pat2 = new RegExp('px');
   pat2.test(frameHeight);
   frameHeight = RegExp.leftContext;
   if ( !frameHeight || (Math.ceil(frameHeight)!=Math.floor(frameHeight)) ) {
    //if it's null or not an integer
    frameHeight = '550'; //default frame height, in case none is specified
   };
   frameHeight += 'px';

   frameWidth = '100%';

   // Insert the iframe just after the link
   e.after('<iframe style="width:'+frameWidth+'; height:'+frameHeight+'; border:solid 0px #ccc; margin-bottom:1em; background:#fff;" src=' + e.attr('href') + ' frameborder="0" ></iframe>');
   var iframe=e.next('iframe');

   // Insert the "loading..." text
   iframe.before(' <small class="quiet"> hold on a sec...</small>')
   iframe.load(function(){ //once content was loaded
    iframe.slideDown(500); //slide it down
    iframe.prev('small').remove(); //remove the 'loading...'
   });
   e.attr('title','Hide'); //set the link title to 'Hide'
  }
  else if(e.data('state')=='closed') { //if state is 'closed'
   e.data('state', 'open');
   e.next('iframe').slideDown(500);
   e.attr('title','Hide');
  }
  else if(e.data('state')=='open') { //if state is 'open'
   e.data('state', 'closed');
   e.next('iframe').slideUp(500);
   e.attr('title','Show');
  }
  return false;
 });
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文