/* ========================================================================
* Bootstrap: button.js v3.3.7
* http://getbootstrap.com/javascript/#buttons
* ========================================================================
* Copyright 2011-2016 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
* ======================================================================== */ +function ($) {
'use strict'; // BUTTON PUBLIC CLASS DEFINITION
// ============================== var Button = function (element, options) {//构造函数,并初始化一些参数
this.$element = $(element)
this.options = $.extend({}, Button.DEFAULTS, options)
this.isLoading = false
} Button.VERSION = '3.3.7' Button.DEFAULTS = {
loadingText: 'loading...'
} Button.prototype.setState = function (state) {
var d = 'disabled'
var $el = this.$element
var val = $el.is('input') ? 'val' : 'html'
var data = $el.data() state += 'Text' if (data.resetText == null) $el.data('resetText', $el[val]())//把原来的val或html存起来 // push to event loop to allow forms to submit 不立马执行而是往后推 ???
setTimeout($.proxy(function () {
$el[val](data[state] == null ? this.options[state] : data[state])//如果等于null就用默认的,否则用data-里面的 if (state == 'loadingText') {
this.isLoading = true
$el.addClass(d).attr(d, d).prop(d, true)//不经设置了html的还设置的dom的???
} else if (this.isLoading) {
this.isLoading = false
$el.removeClass(d).removeAttr(d).prop(d, false)
}
}, this), 0)
} Button.prototype.toggle = function () {
var changed = true
var $parent = this.$element.closest('[data-toggle="buttons"]') if ($parent.length) {
var $input = this.$element.find('input')
if ($input.prop('type') == 'radio') {
if ($input.prop('checked')) changed = false
$parent.find('.active').removeClass('active')//清空所有的active
this.$element.addClass('active')
} else if ($input.prop('type') == 'checkbox') {
console.log($input.prop('checked'));
console.log(this.$element.hasClass('active'));
if (($input.prop('checked')) !== this.$element.hasClass('active')) changed = false//永远不会相等 checked事件无法触发,只能通过代码触发,因为我们点不到他
this.$element.toggleClass('active')
}
$input.prop('checked', this.$element.hasClass('active'))//手动设置选中与否
if (changed) $input.trigger('change')
} else {
this.$element.attr('aria-pressed', !this.$element.hasClass('active'))
this.$element.toggleClass('active')
}
} // BUTTON PLUGIN DEFINITION
// ======================== function Plugin(option) {
return this.each(function () {
var $this = $(this)
var data = $this.data('bs.button')
var options = typeof option == 'object' && option if (!data) $this.data('bs.button', (data = new Button(this, options)))//如果没有就传一个 if (option == 'toggle') data.toggle()
else if (option) data.setState(option)
})
} var old = $.fn.button $.fn.button = Plugin
$.fn.button.Constructor = Button // BUTTON NO CONFLICT
// ================== $.fn.button.noConflict = function () {
//$.fn.button = old
return this
}
var fffff=$.fn.button.noConflict();
console.log(fffff); // BUTTON DATA-API
// =============== $(document)
.on('click.bs.button.data-api', '[data-toggle^="button"]', function (e) {
var $btn = $(e.target).closest('.btn')//从labale位置找.btn 就找到他本身了
Plugin.call($btn, 'toggle')
if (!($(e.target).is('input[type="radio"], input[type="checkbox"]'))) {
// Prevent double click on radios, and the double selections (so cancellation) on checkboxes
e.preventDefault()
// The target component still receive the focus
if ($btn.is('input,button')) $btn.trigger('focus')
else $btn.find('input:visible,button:visible').first().trigger('focus')
}
})
.on('focus.bs.button.data-api blur.bs.button.data-api', '[data-toggle^="button"]', function (e) {
$(e.target).closest('.btn').toggleClass('focus', /^focus(in)?$/.test(e.type))
}) }(jQuery);

Bootstrap button源码分析的更多相关文章

  1. Bootstrap Tooltip源码分析

    /* ======================================================================== * Bootstrap: tooltip.js ...

  2. Bootstrap popover源码分析

    /* ======================================================================== * Bootstrap: popover.js ...

  3. Bootstrap Dropdown 源码分析

    /* ======================================================================== * Bootstrap: dropdown.js ...

  4. Bootstrap tabs 源码分析

    前言: 阅读建议:去github下载一个完整dom然后把,本篇代码复制进去然后运行就好了以地址 tab组件是非常简单的一种组件,因为这是一个系列,所以就顺便看了,其实它写的这个还算不错的,很有条例,也 ...

  5. BOOtstrap源码分析之 tooltip、popover

    一.tooltip(提示框) 源码文件: Tooltip.jsTooltip.scss 实现原理: 1.获取当前要显示tooltip的元素的定位信息(top.left.bottom.right.wid ...

  6. Bootstrap源码分析系列之初始化和依赖项

    在上一节中我们介绍了Bootstrap整体架构,本节我们将介绍Bootstrap框架第二部分初始化及依赖项,这部分内容位于源码的第8~885行,打开源码这部分内容似乎也不是很难理解.但是请站在一个开发 ...

  7. Bootstrap导航栏navbar源码分析

    1.本文目地:分析bootstrap导航栏及其响应式的实现方式,提升自身css水平 先贴一个bootstrap的导航栏模板 http://v3.bootcss.com/examples/navbar- ...

  8. Bootstrap源码分析之dropdown

    源码分析: Dropdowns.scss:下拉框模块 Javascripts/bootstrap/dropdown.js:实现下拉框响应 实现功能及原理: 下拉选项卡,默认不能实现显示选中项的功能 原 ...

  9. Appium Server源码分析之作为Bootstrap客户端

    Appium Server拥有两个主要的功能: 它是个http服务器,它专门接收从客户端通过基于http的REST协议发送过来的命令 他是bootstrap客户端:它接收到客户端的命令后,需要想办法把 ...

随机推荐

  1. JAVA基础——对象流

    对象的输入输出流的作用: 用于写入对象 的信息和读取对象的信息. 使得对象持久化.    ObjectInputStream   : 对象输入流    ObjectOutPutStream  :对象输 ...

  2. 单线制DS18B20温度传感器LED数码管显示当前的温度值

    /******************************************* 程序功能:利用单线制DS18B20温度传感器 LED数码管显示当前的温度值 ***************** ...

  3. sscanf,sprintf

    sprintf函数 sprintf函数原型为 int sprintf(char str, const char format, ...).作用是格式化字符串,具体功能如下所示: 将数字变量转换为字符串 ...

  4. c/c++ 位域的概念

    位域 有些信息在存储时,并不需要占用一个完整的字节, 而只需占几个或一个二进制位.例如在存放一个开关量时,只有0和1 两种状态, 用一位二进位即可.为了节省存储空间,并使处理简便,C语言又提供了一种数 ...

  5. NOIP2012提高组D1T3 开车旅行

    n<=100000个山,每个山有高度,从一个山到另一个山代价为高度差,有A和B两人一起开车,A每次选前进方向的次近山,B选最近,保证山高度不同且如果代价相同的山低的代价算小,每次旅行先A走,然后 ...

  6. Apache 使用localhost(127.0.0.1)可以访问,使用本机IP(局域网)不能访问

    本机ip是:192.168.1.25,输入后提示: Forbidden You don't have permission to access / on this server 对于此问题的解决办法, ...

  7. 绿盟NF防火墙系统

    http://www.nsfocus.com.cn/ http://www.nsfocus.com.cn/products/details_22_5.html

  8. sql 按中文排序

    sql server:select * from [表名]order by [字段],[字段] collate Chinese_PRC_CS_AS_KS_WS mysql:select * from ...

  9. eclipse bug之No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK

    解决办法: 1.eclipse菜单 - Window - Preferences- Java - Installed JREs 将配置的JRE定位到JDK,例如JRE home:D:\Program ...

  10. cocos2d-x CCScrollView和CCTableView的使用

    在游戏和应用中常常要实现左右滑动展示游戏帮助.以列表显示内容的UI效果,就像android中的Gallery和ListView. 本文通过CCScrollView和CCTableView分别来实现这两 ...