reindent long lines

master
Chakib Benziane 12 years ago
parent a508c4119b
commit d4efc68c8e

@ -18,16 +18,15 @@
* *
* Modified work : bootstrap-button.js v2.0.2 * Modified work : bootstrap-button.js v2.0.2
* Copyright 2012 Twitter, Inc. * Copyright 2012 Twitter, Inc.
* ============================================================ */ * ============================================================ */!
function ($) {
!function( $ ){
"use strict" "use strict"
/* BUTTON PUBLIC CLASS DEFINITION /* BUTTON PUBLIC CLASS DEFINITION
* ============================== */ * ============================== */
var MagicBtn = function ( element, options ) { var MagicBtn = function (element, options) {
this.$element = $(element) this.$element = $(element)
// The parent Div // The parent Div
@ -38,10 +37,8 @@
this.options = $.extend({}, $.fn.magicBtn.defaults, options) this.options = $.extend({}, $.fn.magicBtn.defaults, options)
// Store number of buttons on parent div // Store number of buttons on parent div
if (!this.$parentDiv.data('nbMagicBtns')) if (!this.$parentDiv.data('nbMagicBtns')) this.$parentDiv.data('nbMagicBtns', 1)
this.$parentDiv.data('nbMagicBtns', 1) else this.$parentDiv.data().nbMagicBtns++;
else
this.$parentDiv.data().nbMagicBtns++;
// Store the current button number // Store the current button number
this.$currentBtnNb = this.$parentDiv.data('nbMagicBtns') this.$currentBtnNb = this.$parentDiv.data('nbMagicBtns')
@ -53,15 +50,12 @@
// current button image and toggle image if there is // current button image and toggle image if there is
this.$imgUrl = 'url("' + this.$element.data('image') + '")' this.$imgUrl = 'url("' + this.$element.data('image') + '")'
var toggleimg var toggleimg
if (toggleimg = this.$element.data('toggle-image')) if (toggleimg = this.$element.data('toggle-image')) this.$toggleImgUrl = 'url("' + toggleimg + '")'
this.$toggleImgUrl = 'url("' + toggleimg + '")' else this.$toggleImgUrl = this.$imgUrl
else
this.$toggleImgUrl = this.$imgUrl
this.$isToggled = false this.$isToggled = false
if (this.options.hover) if (this.options.hover) this.addHover()
this.addHover()
} }
MagicBtn.prototype = { MagicBtn.prototype = {
@ -69,11 +63,12 @@
constructor: MagicBtn constructor: MagicBtn
// state is the option recieved from jQuery plugin // state is the option recieved from jQuery plugin
, setState: function ( state ) { ,
var d = 'disabled' setState: function (state) {
, $el = this.$element var d = 'disabled',
, data = $el.data() $el = this.$element,
, val = $el.is('input') ? 'val' : 'html' data = $el.data(),
val = $el.is('input') ? 'val' : 'html'
state = state + 'Text' state = state + 'Text'
data.resetText || $el.data('resetText', $el[val]()) data.resetText || $el.data('resetText', $el[val]())
@ -82,73 +77,47 @@
// push to event loop to allow forms to submit // push to event loop to allow forms to submit
setTimeout(function () { setTimeout(function () {
state == 'loadingText' ? state == 'loadingText' ? $el.addClass(d).attr(d, d) : $el.removeClass(d).removeAttr(d)
$el.addClass(d).attr(d, d) :
$el.removeClass(d).removeAttr(d)
}, 0) }, 0)
} }
, calculatePosition: function(direction) { ,
calculatePosition: function (direction) {
var space = (this.$currentBtnNb === 1) ? 0 : this.options.betweenSpace var space = (this.$currentBtnNb === 1) ? 0 : this.options.betweenSpace
var left = this.$parentPosition.left + this.$parentWidth var left = this.$parentPosition.left + this.$parentWidth
switch (this.options.alignement) { switch (this.options.alignement) {
case 'top': case 'top':
this.$top = ( this.$top = (
(this.$currentBtnNb * this.$height) - (this.$currentBtnNb * this.$height) - this.$height + this.$parentPosition.top + (space * (this.$currentBtnNb - 1)))
this.$height +
this.$parentPosition.top +
(space * (this.$currentBtnNb - 1))
)
break; break;
case 'center': case 'center':
{
if (this.$currentBtnNb === 1) if (this.$currentBtnNb === 1) {
{
this.$top = ( this.$top = (
(this.$parentHeight / 2) - (this.$parentHeight / 2) - (this.$height / 2) + this.$parentPosition.top)
(this.$height / 2) + this.$parentDiv.data('top-space', (this.$parentHeight / 2 - (this.$height / 2)))
this.$parentPosition.top this.$parentDiv.data('bottom-space', (this.$parentHeight / 2 - (this.$height / 2)))
) } else if (this.$currentBtnNb % 2 === 0) {
this.$parentDiv.data('top-space',
(this.$parentHeight / 2 - (this.$height /2))
)
this.$parentDiv.data('bottom-space',
(this.$parentHeight / 2 - (this.$height /2))
)
}
else if (this.$currentBtnNb % 2 === 0) {
this.$top = ( this.$top = (
this.$parentDiv.data('top-space') - this.$parentDiv.data('top-space') - this.$height + this.$parentPosition.top)
this.$height + this.$parentDiv.data('top-space', this.$parentDiv.data('top-space') - this.$height)
this.$parentPosition.top } else {
)
this.$parentDiv.data('top-space',
this.$parentDiv.data('top-space') - this.$height
)
}
else {
this.$top = ( this.$top = (
this.$parentHeight - this.$parentHeight - this.$parentDiv.data('bottom-space') + this.$parentPosition.top)
this.$parentDiv.data('bottom-space') +
this.$parentPosition.top this.$parentDiv.data('bottom-space', this.$parentDiv.data('bottom-space') - this.$height)
)
this.$parentDiv.data('bottom-space',
this.$parentDiv.data('bottom-space') -
this.$height
)
} }
break; break;
}
} }
this.$left = this.$parentPosition.left + this.$parentWidth this.$left = this.$parentPosition.left + this.$parentWidth
} }
, show: function() { ,
show: function () {
var $o = this.options var $o = this.options
this.$element.css({ this.$element.css({
top: this.$top, top: this.$top,
@ -157,41 +126,39 @@
}).show() }).show()
} }
, hide: function() { ,
hide: function () {
this.$element.hide() this.$element.hide()
} }
, toggle: function () { ,
toggle: function () {
var $el = this.$element var $el = this.$element
if (!this.$isToggled) { if (!this.$isToggled) {
$el.css('background-image', this.$toggleImgUrl) $el.css('background-image', this.$toggleImgUrl)
this.$isToggled = true this.$isToggled = true
$el.addClass('magicBtn-active') $el.addClass('magicBtn-active')
} } else {
else {
$el.css('background-image', this.$imgUrl) $el.css('background-image', this.$imgUrl)
this.$isToggled = false this.$isToggled = false
$el.removeClass('magicBtn-active') $el.removeClass('magicBtn-active')
} }
} }
, addHover: function () { ,
addHover: function () {
var $el = this.$element var $el = this.$element
var obj = this var obj = this
var config = { var config = {
over: function () { over: function () {
if (!obj.$isToggled) if (!obj.$isToggled) $(this).toggleClass('magicBtn-active')
$(this).toggleClass('magicBtn-active')
}, },
timeout: 1, timeout: 1,
out: function () { out: function () {
if ((!obj.$isToggled) && if ((!obj.$isToggled) && (!$el.is(':hover')) && ($el.hasClass('magicBtn-active'))) $(this).toggleClass('magicBtn-active', 100)
(!$el.is(':hover')) &&
($el.hasClass('magicBtn-active')))
$(this).toggleClass('magicBtn-active', 100)
} }
} }
$el.hoverIntent( config ) $el.hoverIntent(config)
} }
@ -201,11 +168,11 @@
/* BUTTON PLUGIN DEFINITION /* BUTTON PLUGIN DEFINITION
* ======================== */ * ======================== */
$.fn.magicBtn = function ( option ) { $.fn.magicBtn = function (option) {
return this.each(function () { return this.each(function () {
var $this = $(this) var $this = $(this),
, data = $this.data('magicBtn') data = $this.data('magicBtn'),
, options = typeof option == 'object' && option options = typeof option == 'object' && option
if (!data) $this.data('magicBtn', (data = new MagicBtn(this, options))) if (!data) $this.data('magicBtn', (data = new MagicBtn(this, options)))
data.calculatePosition('right') data.calculatePosition('right')
if (option == 'toggle') data.toggle() if (option == 'toggle') data.toggle()
@ -231,11 +198,11 @@
* =============== */ * =============== */
$(function () { $(function () {
$('body').on('click.magicBtn.data-api', '[data-toggle^=magicBtn]', function ( e ) { $('body').on('click.magicBtn.data-api', '[data-toggle^=magicBtn]', function (e) {
var $btn = $(e.target) var $btn = $(e.target)
if (!$btn.hasClass('magicBtn')) $btn = $btn.closest('.magicBtn') if (!$btn.hasClass('magicBtn')) $btn = $btn.closest('.magicBtn')
$btn.magicBtn('toggle') $btn.magicBtn('toggle')
}) })
}) })
}( window.jQuery ); }(window.jQuery);
Loading…
Cancel
Save