为 bootstrap carousel js 的 indicators 高亮项目增加灵活性

2013 年 05 月 20 日  15:12 未分类 RSS

bootstrap-carousel.js 的功能先看这里的介绍:http://twitter.github.com/bootstrap/javascript.html#carousel

在 2.3.2 的版本里面,第 120 行是这样的:

var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])

作用是找到现在切换到第 N 个 slide 时,得到这个 N,然后在所有 indicators 元素中找到第 N 个元素使其高亮。

我在项目中会出现 slide 数量与 indicators 数量不相同的情况,这个时候没法正确高亮对应的 indicators。

所以应当在 indicators 元素中增加一个 data-indicators-rel 属性,比如:


然后,修改 bootstrap-carousel.js 第 120 行:

// var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
var $nextIndicator = that.$indicators.children('[data-indicators-rel="' + that.getActiveIndex() + '"]')
暂无回应

解决 bootstrap-collapse.js 没有 toggle collapsed class 的 bug

2013 年 05 月 10 日  17:57 心得 RSS

使用 bootstrap 的 js 做折叠菜单,发现有一个比较严重的 bug。当点击折叠菜单项目时,子菜单加上 in 的 class 后,却没有把 data-toggle=”collapse” 的元素的 collapsed 这个 class 去掉。
解决方法:
找到 bootstrap-collapse.js 增加一句到最底部的一段代码中:

  $(function () {
    $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) {
      var $this = $(this), href
        , target = $this.attr('data-target')
          || e.preventDefault()
          || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
        , option = $(target).data('collapse') ? 'toggle' : $this.data()
      $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed') // 这行是增加的
      $(target).collapse(option)
    })
  })
暂无回应

网站优化:删除空格及 gzip 压缩

2013 年 04 月 23 日  23:52 未分类 RSS

我们的后台工程师介绍:
你可以用{% spaceless %} {% endspaceless %}包起来html内容,它会删除掉html里的多余的空格

gzip相当于zip压缩文件,删除空格配合gzip更好
不用gzip只删除空格不行,删除空格配合gzip能多节省大约10%的流量

暂无回应

2013 年 04 月 20 日  15:44 未分类 RSS

根据热力学第二定律,计算机系统越有序,对应的人类思维就越无序。这解释了为什么世界上一些最好的科学家和程序员,在世人眼里,都有点不太正常,甚至行为混乱。

    暂无回应    

2013 年 02 月 26 日  10:03 未分类 RSS

Url retrieve from wordpress get_option should stripslashes backslashes.

    暂无回应