2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2010-01-07 03:19:50 +00:00
|
|
|
* jQuery UI Button @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2010-01-07 03:19:50 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:01:04 +00:00
|
|
|
* http://jquery.org/license
|
2010-01-07 03:19:50 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Button
|
|
|
|
//>>group: Widgets
|
|
|
|
//>>description: Enhances a form with themeable buttons.
|
|
|
|
//>>docs: http://api.jqueryui.com/button/
|
|
|
|
//>>demos: http://jqueryui.com/button/
|
2014-04-15 14:45:46 +00:00
|
|
|
//>>css.structure: ../themes/base/core.css
|
|
|
|
//>>css.structure: ../themes/base/button.css
|
|
|
|
//>>css.theme: ../themes/base/theme.css
|
2014-10-30 19:55:08 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
(function( factory ) {
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define([
|
|
|
|
"jquery",
|
2015-07-15 20:43:33 +00:00
|
|
|
"./data",
|
2015-07-15 22:03:01 +00:00
|
|
|
"./keycode",
|
2015-07-15 22:14:26 +00:00
|
|
|
"./labels",
|
2015-07-15 22:26:12 +00:00
|
|
|
"./version",
|
2013-12-02 18:36:12 +00:00
|
|
|
"./widget"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
|
|
|
}(function( $ ) {
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2013-10-27 02:33:25 +00:00
|
|
|
var lastActive,
|
2010-01-07 03:19:50 +00:00
|
|
|
baseClasses = "ui-button ui-widget ui-state-default ui-corner-all",
|
2010-05-26 19:08:37 +00:00
|
|
|
typeClasses = "ui-button-icons-only ui-button-icon-only ui-button-text-icons ui-button-text-icon-primary ui-button-text-icon-secondary ui-button-text-only",
|
2011-05-18 14:32:59 +00:00
|
|
|
formResetHandler = function() {
|
2013-04-07 16:57:15 +00:00
|
|
|
var form = $( this );
|
2011-05-18 14:32:59 +00:00
|
|
|
setTimeout(function() {
|
2013-04-07 16:57:15 +00:00
|
|
|
form.find( ":ui-button" ).button( "refresh" );
|
2011-05-18 14:32:59 +00:00
|
|
|
}, 1 );
|
2010-03-11 06:31:16 +00:00
|
|
|
},
|
2010-03-11 20:10:43 +00:00
|
|
|
radioGroup = function( radio ) {
|
2010-03-11 06:31:16 +00:00
|
|
|
var name = radio.name,
|
|
|
|
form = radio.form,
|
2010-03-11 20:10:43 +00:00
|
|
|
radios = $( [] );
|
2010-03-11 06:31:16 +00:00
|
|
|
if ( name ) {
|
2012-11-19 13:37:41 +00:00
|
|
|
name = name.replace( /'/g, "\\'" );
|
2010-03-11 06:31:16 +00:00
|
|
|
if ( form ) {
|
2014-01-28 15:46:23 +00:00
|
|
|
radios = $( form ).find( "[name='" + name + "'][type=radio]" );
|
2010-03-11 06:31:16 +00:00
|
|
|
} else {
|
2014-01-28 15:46:23 +00:00
|
|
|
radios = $( "[name='" + name + "'][type=radio]", radio.ownerDocument )
|
2010-03-11 06:31:16 +00:00
|
|
|
.filter(function() {
|
|
|
|
return !this.form;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return radios;
|
|
|
|
};
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
$.widget( "ui.button", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2011-01-23 22:55:53 +00:00
|
|
|
defaultElement: "<button>",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2010-08-18 18:51:30 +00:00
|
|
|
disabled: null,
|
2010-01-07 03:19:50 +00:00
|
|
|
text: true,
|
|
|
|
label: null,
|
|
|
|
icons: {
|
|
|
|
primary: null,
|
|
|
|
secondary: null
|
|
|
|
}
|
|
|
|
},
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2010-03-11 20:10:43 +00:00
|
|
|
this.element.closest( "form" )
|
2015-05-14 01:54:37 +00:00
|
|
|
.off( "reset" + this.eventNamespace )
|
|
|
|
.on( "reset" + this.eventNamespace, formResetHandler );
|
2010-03-11 20:10:43 +00:00
|
|
|
|
2010-08-18 18:51:30 +00:00
|
|
|
if ( typeof this.options.disabled !== "boolean" ) {
|
2012-01-18 21:37:04 +00:00
|
|
|
this.options.disabled = !!this.element.prop( "disabled" );
|
|
|
|
} else {
|
|
|
|
this.element.prop( "disabled", this.options.disabled );
|
2010-08-18 18:51:30 +00:00
|
|
|
}
|
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
this._determineButtonType();
|
2010-01-18 01:58:15 +00:00
|
|
|
this.hasTitle = !!this.buttonElement.attr( "title" );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2012-02-12 14:25:41 +00:00
|
|
|
var that = this,
|
2010-01-07 03:19:50 +00:00
|
|
|
options = this.options,
|
2010-01-18 01:58:15 +00:00
|
|
|
toggleButton = this.type === "checkbox" || this.type === "radio",
|
2013-04-11 18:03:51 +00:00
|
|
|
activeClass = !toggleButton ? "ui-state-active" : "";
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( options.label === null ) {
|
2012-05-22 01:52:48 +00:00
|
|
|
options.label = (this.type === "input" ? this.buttonElement.val() : this.buttonElement.html());
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2012-01-01 16:44:22 +00:00
|
|
|
this._hoverable( this.buttonElement );
|
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
this.buttonElement
|
2010-01-18 01:58:15 +00:00
|
|
|
.addClass( baseClasses )
|
|
|
|
.attr( "role", "button" )
|
2015-05-14 01:54:37 +00:00
|
|
|
.on( "mouseenter" + this.eventNamespace, function() {
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( options.disabled ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ( this === lastActive ) {
|
|
|
|
$( this ).addClass( "ui-state-active" );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
})
|
2015-05-14 01:54:37 +00:00
|
|
|
.on( "mouseleave" + this.eventNamespace, function() {
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( options.disabled ) {
|
|
|
|
return;
|
|
|
|
}
|
2012-01-01 16:44:22 +00:00
|
|
|
$( this ).removeClass( activeClass );
|
2010-01-20 17:44:54 +00:00
|
|
|
})
|
2015-05-14 01:54:37 +00:00
|
|
|
.on( "click" + this.eventNamespace, function( event ) {
|
2011-05-05 12:45:06 +00:00
|
|
|
if ( options.disabled ) {
|
2011-05-26 16:22:40 +00:00
|
|
|
event.preventDefault();
|
2011-05-05 12:45:06 +00:00
|
|
|
event.stopImmediatePropagation();
|
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
2010-03-11 20:10:43 +00:00
|
|
|
|
2013-04-11 18:03:51 +00:00
|
|
|
// Can't use _focusable() because the element that receives focus
|
|
|
|
// and the element that gets the ui-state-focus class are different
|
|
|
|
this._on({
|
|
|
|
focus: function() {
|
|
|
|
this.buttonElement.addClass( "ui-state-focus" );
|
|
|
|
},
|
|
|
|
blur: function() {
|
|
|
|
this.buttonElement.removeClass( "ui-state-focus" );
|
|
|
|
}
|
|
|
|
});
|
2011-05-26 15:28:17 +00:00
|
|
|
|
2010-03-11 06:31:16 +00:00
|
|
|
if ( toggleButton ) {
|
2015-05-14 01:54:37 +00:00
|
|
|
this.element.on( "change" + this.eventNamespace, function() {
|
2012-02-12 14:25:41 +00:00
|
|
|
that.refresh();
|
2010-03-11 06:31:16 +00:00
|
|
|
});
|
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2010-03-14 17:53:18 +00:00
|
|
|
if ( this.type === "checkbox" ) {
|
2015-05-14 01:54:37 +00:00
|
|
|
this.buttonElement.on( "click" + this.eventNamespace, function() {
|
2013-10-27 02:33:25 +00:00
|
|
|
if ( options.disabled ) {
|
2010-03-15 14:00:53 +00:00
|
|
|
return false;
|
2010-01-18 01:58:15 +00:00
|
|
|
}
|
|
|
|
});
|
2010-03-14 17:53:18 +00:00
|
|
|
} else if ( this.type === "radio" ) {
|
2015-05-14 01:54:37 +00:00
|
|
|
this.buttonElement.on( "click" + this.eventNamespace, function() {
|
2013-10-27 02:33:25 +00:00
|
|
|
if ( options.disabled ) {
|
2010-03-15 14:00:53 +00:00
|
|
|
return false;
|
2010-01-18 01:58:15 +00:00
|
|
|
}
|
|
|
|
$( this ).addClass( "ui-state-active" );
|
2012-02-12 14:25:41 +00:00
|
|
|
that.buttonElement.attr( "aria-pressed", "true" );
|
2010-01-18 01:58:15 +00:00
|
|
|
|
2012-02-12 14:25:41 +00:00
|
|
|
var radio = that.element[ 0 ];
|
2010-03-11 06:31:16 +00:00
|
|
|
radioGroup( radio )
|
|
|
|
.not( radio )
|
|
|
|
.map(function() {
|
|
|
|
return $( this ).button( "widget" )[ 0 ];
|
|
|
|
})
|
|
|
|
.removeClass( "ui-state-active" )
|
2011-07-12 15:36:34 +00:00
|
|
|
.attr( "aria-pressed", "false" );
|
2010-01-18 01:58:15 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.buttonElement
|
2015-05-14 01:54:37 +00:00
|
|
|
.on( "mousedown" + this.eventNamespace, function() {
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( options.disabled ) {
|
2010-03-15 14:00:53 +00:00
|
|
|
return false;
|
2010-01-18 01:58:15 +00:00
|
|
|
}
|
|
|
|
$( this ).addClass( "ui-state-active" );
|
|
|
|
lastActive = this;
|
2012-02-12 14:25:41 +00:00
|
|
|
that.document.one( "mouseup", function() {
|
2010-01-18 01:58:15 +00:00
|
|
|
lastActive = null;
|
2010-01-07 03:19:50 +00:00
|
|
|
});
|
2010-01-18 01:58:15 +00:00
|
|
|
})
|
2015-05-14 01:54:37 +00:00
|
|
|
.on( "mouseup" + this.eventNamespace, function() {
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( options.disabled ) {
|
2010-03-15 14:00:53 +00:00
|
|
|
return false;
|
2010-01-18 01:58:15 +00:00
|
|
|
}
|
|
|
|
$( this ).removeClass( "ui-state-active" );
|
2010-01-22 22:46:32 +00:00
|
|
|
})
|
2015-05-14 01:54:37 +00:00
|
|
|
.on( "keydown" + this.eventNamespace, function(event) {
|
2010-03-14 17:53:18 +00:00
|
|
|
if ( options.disabled ) {
|
2010-03-15 14:00:53 +00:00
|
|
|
return false;
|
2010-03-14 17:53:18 +00:00
|
|
|
}
|
2012-04-02 23:12:21 +00:00
|
|
|
if ( event.keyCode === $.ui.keyCode.SPACE || event.keyCode === $.ui.keyCode.ENTER ) {
|
2010-01-22 22:46:32 +00:00
|
|
|
$( this ).addClass( "ui-state-active" );
|
|
|
|
}
|
|
|
|
})
|
2012-11-22 00:58:59 +00:00
|
|
|
// see #8559, we bind to blur here in case the button element loses
|
|
|
|
// focus between keydown and keyup, it would be left in an "active" state
|
2015-05-14 01:54:37 +00:00
|
|
|
.on( "keyup" + this.eventNamespace + " blur" + this.eventNamespace, function() {
|
2010-01-22 22:46:32 +00:00
|
|
|
$( this ).removeClass( "ui-state-active" );
|
2010-01-18 01:58:15 +00:00
|
|
|
});
|
2010-03-11 20:10:43 +00:00
|
|
|
|
|
|
|
if ( this.buttonElement.is("a") ) {
|
2015-05-14 01:54:37 +00:00
|
|
|
this.buttonElement.on( "keyup", function(event) {
|
2010-03-11 20:10:43 +00:00
|
|
|
if ( event.keyCode === $.ui.keyCode.SPACE ) {
|
2010-01-22 22:52:31 +00:00
|
|
|
// TODO pass through original event correctly (just as 2nd argument doesn't work)
|
2015-05-14 01:54:37 +00:00
|
|
|
$( this ).trigger( "click" );
|
2010-01-22 22:52:31 +00:00
|
|
|
}
|
2010-02-18 01:45:23 +00:00
|
|
|
});
|
2010-01-22 22:52:31 +00:00
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
|
2010-03-14 17:53:18 +00:00
|
|
|
this._setOption( "disabled", options.disabled );
|
2011-05-12 05:16:06 +00:00
|
|
|
this._resetButton();
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_determineButtonType: function() {
|
2012-04-02 23:12:21 +00:00
|
|
|
var ancestor, labelSelector, checked;
|
2011-03-20 02:19:36 +00:00
|
|
|
|
2012-05-21 16:47:15 +00:00
|
|
|
if ( this.element.is("[type=checkbox]") ) {
|
2010-03-11 21:17:28 +00:00
|
|
|
this.type = "checkbox";
|
2012-05-21 16:02:28 +00:00
|
|
|
} else if ( this.element.is("[type=radio]") ) {
|
2011-03-20 02:19:36 +00:00
|
|
|
this.type = "radio";
|
|
|
|
} else if ( this.element.is("input") ) {
|
|
|
|
this.type = "input";
|
2010-03-11 21:17:28 +00:00
|
|
|
} else {
|
2011-03-20 02:19:36 +00:00
|
|
|
this.type = "button";
|
2010-03-11 21:17:28 +00:00
|
|
|
}
|
2011-03-20 02:19:36 +00:00
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( this.type === "checkbox" || this.type === "radio" ) {
|
2010-03-11 03:50:20 +00:00
|
|
|
// we don't search against the document in case the element
|
|
|
|
// is disconnected from the DOM
|
2012-04-02 23:12:21 +00:00
|
|
|
ancestor = this.element.parents().last();
|
|
|
|
labelSelector = "label[for='" + this.element.attr("id") + "']";
|
2011-03-11 15:52:13 +00:00
|
|
|
this.buttonElement = ancestor.find( labelSelector );
|
|
|
|
if ( !this.buttonElement.length ) {
|
|
|
|
ancestor = ancestor.length ? ancestor.siblings() : this.element.siblings();
|
|
|
|
this.buttonElement = ancestor.filter( labelSelector );
|
|
|
|
if ( !this.buttonElement.length ) {
|
|
|
|
this.buttonElement = ancestor.find( labelSelector );
|
|
|
|
}
|
|
|
|
}
|
2010-03-17 12:56:15 +00:00
|
|
|
this.element.addClass( "ui-helper-hidden-accessible" );
|
2010-01-18 01:58:15 +00:00
|
|
|
|
2012-04-02 23:12:21 +00:00
|
|
|
checked = this.element.is( ":checked" );
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( checked ) {
|
|
|
|
this.buttonElement.addClass( "ui-state-active" );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
2011-06-08 21:02:57 +00:00
|
|
|
this.buttonElement.prop( "aria-pressed", checked );
|
2010-01-07 03:19:50 +00:00
|
|
|
} else {
|
|
|
|
this.buttonElement = this.element;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
widget: function() {
|
2010-07-30 16:38:18 +00:00
|
|
|
return this.buttonElement;
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
|
|
|
|
2011-01-14 22:11:22 +00:00
|
|
|
_destroy: function() {
|
2010-03-17 12:49:27 +00:00
|
|
|
this.element
|
|
|
|
.removeClass( "ui-helper-hidden-accessible" );
|
2010-01-07 03:19:50 +00:00
|
|
|
this.buttonElement
|
2013-04-11 18:03:51 +00:00
|
|
|
.removeClass( baseClasses + " ui-state-active " + typeClasses )
|
2015-03-18 00:22:49 +00:00
|
|
|
.removeAttr( "role aria-pressed" )
|
2010-01-18 01:58:15 +00:00
|
|
|
.html( this.buttonElement.find(".ui-button-text").html() );
|
2010-01-07 03:19:50 +00:00
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( !this.hasTitle ) {
|
|
|
|
this.buttonElement.removeAttr( "title" );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
_setOption: function( key, value ) {
|
2011-11-18 11:19:32 +00:00
|
|
|
this._super( key, value );
|
2010-03-15 14:00:53 +00:00
|
|
|
if ( key === "disabled" ) {
|
2013-03-14 23:08:21 +00:00
|
|
|
this.widget().toggleClass( "ui-state-disabled", !!value );
|
|
|
|
this.element.prop( "disabled", !!value );
|
2013-04-11 18:03:51 +00:00
|
|
|
if ( value ) {
|
2013-12-12 04:53:48 +00:00
|
|
|
if ( this.type === "checkbox" || this.type === "radio" ) {
|
|
|
|
this.buttonElement.removeClass( "ui-state-focus" );
|
|
|
|
} else {
|
|
|
|
this.buttonElement.removeClass( "ui-state-focus ui-state-active" );
|
|
|
|
}
|
2013-04-11 18:03:51 +00:00
|
|
|
}
|
2011-05-12 05:16:06 +00:00
|
|
|
return;
|
2010-03-15 14:00:53 +00:00
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
this._resetButton();
|
|
|
|
},
|
2010-03-11 20:10:43 +00:00
|
|
|
|
2010-03-11 06:31:16 +00:00
|
|
|
refresh: function() {
|
2012-11-19 20:42:28 +00:00
|
|
|
//See #8237 & #8828
|
|
|
|
var isDisabled = this.element.is( "input, button" ) ? this.element.is( ":disabled" ) : this.element.hasClass( "ui-button-disabled" );
|
|
|
|
|
2010-03-15 14:13:17 +00:00
|
|
|
if ( isDisabled !== this.options.disabled ) {
|
|
|
|
this._setOption( "disabled", isDisabled );
|
|
|
|
}
|
2010-03-11 06:31:16 +00:00
|
|
|
if ( this.type === "radio" ) {
|
|
|
|
radioGroup( this.element[0] ).each(function() {
|
2010-03-11 20:10:43 +00:00
|
|
|
if ( $( this ).is( ":checked" ) ) {
|
|
|
|
$( this ).button( "widget" )
|
|
|
|
.addClass( "ui-state-active" )
|
2011-07-12 15:36:34 +00:00
|
|
|
.attr( "aria-pressed", "true" );
|
2010-03-11 06:31:16 +00:00
|
|
|
} else {
|
2010-03-11 20:10:43 +00:00
|
|
|
$( this ).button( "widget" )
|
|
|
|
.removeClass( "ui-state-active" )
|
2011-07-12 15:36:34 +00:00
|
|
|
.attr( "aria-pressed", "false" );
|
2010-03-11 06:31:16 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else if ( this.type === "checkbox" ) {
|
2010-03-11 20:10:43 +00:00
|
|
|
if ( this.element.is( ":checked" ) ) {
|
2010-03-11 06:31:16 +00:00
|
|
|
this.buttonElement
|
2010-03-11 20:10:43 +00:00
|
|
|
.addClass( "ui-state-active" )
|
2011-07-12 15:36:34 +00:00
|
|
|
.attr( "aria-pressed", "true" );
|
2010-03-11 06:31:16 +00:00
|
|
|
} else {
|
|
|
|
this.buttonElement
|
2010-03-11 20:10:43 +00:00
|
|
|
.removeClass( "ui-state-active" )
|
2011-07-12 15:36:34 +00:00
|
|
|
.attr( "aria-pressed", "false" );
|
2010-03-11 06:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2010-01-07 03:19:50 +00:00
|
|
|
|
|
|
|
_resetButton: function() {
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( this.type === "input" ) {
|
|
|
|
if ( this.options.label ) {
|
|
|
|
this.element.val( this.options.label );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2010-04-30 01:38:23 +00:00
|
|
|
var buttonElement = this.buttonElement.removeClass( typeClasses ),
|
2011-10-20 20:57:47 +00:00
|
|
|
buttonText = $( "<span></span>", this.document[0] )
|
2010-01-18 01:58:15 +00:00
|
|
|
.addClass( "ui-button-text" )
|
|
|
|
.html( this.options.label )
|
|
|
|
.appendTo( buttonElement.empty() )
|
2010-03-11 21:17:28 +00:00
|
|
|
.text(),
|
|
|
|
icons = this.options.icons,
|
2011-02-11 03:11:59 +00:00
|
|
|
multipleIcons = icons.primary && icons.secondary,
|
2011-11-18 11:19:32 +00:00
|
|
|
buttonClasses = [];
|
2011-02-11 03:11:59 +00:00
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( icons.primary || icons.secondary ) {
|
2011-02-26 10:13:00 +00:00
|
|
|
if ( this.options.text ) {
|
|
|
|
buttonClasses.push( "ui-button-text-icon" + ( multipleIcons ? "s" : ( icons.primary ? "-primary" : "-secondary" ) ) );
|
|
|
|
}
|
2011-02-11 03:11:59 +00:00
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( icons.primary ) {
|
|
|
|
buttonElement.prepend( "<span class='ui-button-icon-primary ui-icon " + icons.primary + "'></span>" );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
2011-02-11 03:11:59 +00:00
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( icons.secondary ) {
|
|
|
|
buttonElement.append( "<span class='ui-button-icon-secondary ui-icon " + icons.secondary + "'></span>" );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
2011-02-11 03:11:59 +00:00
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( !this.options.text ) {
|
2011-02-11 03:11:59 +00:00
|
|
|
buttonClasses.push( multipleIcons ? "ui-button-icons-only" : "ui-button-icon-only" );
|
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
if ( !this.hasTitle ) {
|
2012-06-25 13:52:42 +00:00
|
|
|
buttonElement.attr( "title", $.trim( buttonText ) );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2011-02-11 03:11:59 +00:00
|
|
|
buttonClasses.push( "ui-button-text-only" );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
2011-02-11 03:11:59 +00:00
|
|
|
buttonElement.addClass( buttonClasses.join( " " ) );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2010-01-18 01:58:15 +00:00
|
|
|
$.widget( "ui.buttonset", {
|
2012-05-21 17:51:49 +00:00
|
|
|
version: "@VERSION",
|
2010-11-12 15:28:55 +00:00
|
|
|
options: {
|
2012-11-09 18:28:13 +00:00
|
|
|
items: "button, input[type=button], input[type=submit], input[type=reset], input[type=checkbox], input[type=radio], a, :data(ui-button)"
|
2010-11-12 15:28:55 +00:00
|
|
|
},
|
|
|
|
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2010-03-17 13:16:40 +00:00
|
|
|
this.element.addClass( "ui-buttonset" );
|
2010-03-17 13:07:46 +00:00
|
|
|
},
|
2011-11-18 11:19:32 +00:00
|
|
|
|
2010-03-17 13:07:46 +00:00
|
|
|
_init: function() {
|
|
|
|
this.refresh();
|
|
|
|
},
|
|
|
|
|
|
|
|
_setOption: function( key, value ) {
|
|
|
|
if ( key === "disabled" ) {
|
|
|
|
this.buttons.button( "option", key, value );
|
|
|
|
}
|
|
|
|
|
2011-11-18 11:19:32 +00:00
|
|
|
this._super( key, value );
|
2010-03-17 13:07:46 +00:00
|
|
|
},
|
2011-11-18 11:19:32 +00:00
|
|
|
|
2010-03-17 13:07:46 +00:00
|
|
|
refresh: function() {
|
2014-04-01 18:42:38 +00:00
|
|
|
var rtl = this.element.css( "direction" ) === "rtl",
|
|
|
|
allButtons = this.element.find( this.options.items ),
|
|
|
|
existingButtons = allButtons.filter( ":ui-button" );
|
2011-11-18 11:19:32 +00:00
|
|
|
|
2014-04-01 18:42:38 +00:00
|
|
|
// Initialize new buttons
|
|
|
|
allButtons.not( ":ui-button" ).button();
|
|
|
|
|
|
|
|
// Refresh existing buttons
|
|
|
|
existingButtons.button( "refresh" );
|
|
|
|
|
|
|
|
this.buttons = allButtons
|
2010-01-07 03:19:50 +00:00
|
|
|
.map(function() {
|
2010-01-18 01:58:15 +00:00
|
|
|
return $( this ).button( "widget" )[ 0 ];
|
2010-01-07 03:19:50 +00:00
|
|
|
})
|
2010-03-17 13:07:46 +00:00
|
|
|
.removeClass( "ui-corner-all ui-corner-left ui-corner-right" )
|
2010-11-12 15:28:55 +00:00
|
|
|
.filter( ":first" )
|
2011-09-06 15:00:42 +00:00
|
|
|
.addClass( rtl ? "ui-corner-right" : "ui-corner-left" )
|
2010-11-12 15:28:55 +00:00
|
|
|
.end()
|
|
|
|
.filter( ":last" )
|
2011-09-06 15:00:42 +00:00
|
|
|
.addClass( rtl ? "ui-corner-left" : "ui-corner-right" )
|
2010-01-07 03:19:50 +00:00
|
|
|
.end()
|
|
|
|
.end();
|
|
|
|
},
|
|
|
|
|
2011-01-15 11:34:07 +00:00
|
|
|
_destroy: function() {
|
2010-03-17 13:16:40 +00:00
|
|
|
this.element.removeClass( "ui-buttonset" );
|
2010-01-07 03:19:50 +00:00
|
|
|
this.buttons
|
2010-03-17 13:03:23 +00:00
|
|
|
.map(function() {
|
|
|
|
return $( this ).button( "widget" )[ 0 ];
|
|
|
|
})
|
|
|
|
.removeClass( "ui-corner-left ui-corner-right" )
|
|
|
|
.end()
|
2010-04-23 16:08:55 +00:00
|
|
|
.button( "destroy" );
|
2010-01-07 03:19:50 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
return $.ui.button;
|
|
|
|
|
|
|
|
}));
|