[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/bootstrap/js/ -> bootstrap-button.js (source)

   1  /* ============================================================
   2   * bootstrap-button.js v2.0.1
   3   * http://twitter.github.com/bootstrap/javascript.html#buttons
   4   * ============================================================
   5   * Copyright 2012 Twitter, Inc.
   6   *
   7   * Licensed under the Apache License, Version 2.0 (the "License");
   8   * you may not use this file except in compliance with the License.
   9   * You may obtain a copy of the License at
  10   *
  11   * http://www.apache.org/licenses/LICENSE-2.0
  12   *
  13   * Unless required by applicable law or agreed to in writing, software
  14   * distributed under the License is distributed on an "AS IS" BASIS,
  15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16   * See the License for the specific language governing permissions and
  17   * limitations under the License.
  18   * ============================================================ */
  19  
  20  !function( $ ){
  21  
  22    "use strict"
  23  
  24   /* BUTTON PUBLIC CLASS DEFINITION
  25    * ============================== */
  26  
  27    var Button = function ( element, options ) {
  28      this.$element = $(element)
  29      this.options = $.extend({}, $.fn.button.defaults, options)
  30    }
  31  
  32    Button.prototype = {
  33  
  34        constructor: Button
  35  
  36      , setState: function ( state ) {
  37          var d = 'disabled'
  38            , $el = this.$element
  39            , data = $el.data()
  40            , val = $el.is('input') ? 'val' : 'html'
  41  
  42          state = state + 'Text'
  43          data.resetText || $el.data('resetText', $el[val]())
  44  
  45          $el[val](data[state] || this.options[state])
  46  
  47          // push to event loop to allow forms to submit
  48          setTimeout(function () {
  49            state == 'loadingText' ?
  50              $el.addClass(d).attr(d, d) :
  51              $el.removeClass(d).removeAttr(d)
  52          }, 0)
  53        }
  54  
  55      , toggle: function () {
  56          var $parent = this.$element.parent('[data-toggle="buttons-radio"]')
  57  
  58          $parent && $parent
  59            .find('.active')
  60            .removeClass('active')
  61  
  62          this.$element.toggleClass('active')
  63        }
  64  
  65    }
  66  
  67  
  68   /* BUTTON PLUGIN DEFINITION
  69    * ======================== */
  70  
  71    $.fn.button = function ( option ) {
  72      return this.each(function () {
  73        var $this = $(this)
  74          , data = $this.data('button')
  75          , options = typeof option == 'object' && option
  76        if (!data) $this.data('button', (data = new Button(this, options)))
  77        if (option == 'toggle') data.toggle()
  78        else if (option) data.setState(option)
  79      })
  80    }
  81  
  82    $.fn.button.defaults = {
  83      loadingText: 'loading...'
  84    }
  85  
  86    $.fn.button.Constructor = Button
  87  
  88  
  89   /* BUTTON DATA-API
  90    * =============== */
  91  
  92    $(function () {
  93      $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
  94        $(e.currentTarget).button('toggle')
  95      })
  96    })
  97  
  98  }( window.jQuery );


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1