mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-10-05 01:44:18 +00:00
Slider: add handles in single DOM operation. Fixed #7259 - optimize handle creation.
(cherry picked from commit 7fb6ca146e
)
This commit is contained in:
parent
201b5ed48c
commit
03ce9fb8cd
46
ui/jquery.ui.slider.js
vendored
46
ui/jquery.ui.slider.js
vendored
@ -36,7 +36,11 @@ $.widget( "ui.slider", $.ui.mouse, {
|
|||||||
|
|
||||||
_create: function() {
|
_create: function() {
|
||||||
var self = this,
|
var self = this,
|
||||||
o = this.options;
|
o = this.options,
|
||||||
|
existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ),
|
||||||
|
handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>",
|
||||||
|
handleCount = ( o.values && o.values.length ) || 1,
|
||||||
|
handles = [];
|
||||||
|
|
||||||
this._keySliding = false;
|
this._keySliding = false;
|
||||||
this._mouseSliding = false;
|
this._mouseSliding = false;
|
||||||
@ -50,57 +54,35 @@ $.widget( "ui.slider", $.ui.mouse, {
|
|||||||
" ui-slider-" + this.orientation +
|
" ui-slider-" + this.orientation +
|
||||||
" ui-widget" +
|
" ui-widget" +
|
||||||
" ui-widget-content" +
|
" ui-widget-content" +
|
||||||
" ui-corner-all" );
|
" ui-corner-all" +
|
||||||
|
( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) );
|
||||||
if ( o.disabled ) {
|
|
||||||
this.element.addClass( "ui-slider-disabled ui-disabled" );
|
|
||||||
}
|
|
||||||
|
|
||||||
this.range = $([]);
|
this.range = $([]);
|
||||||
|
|
||||||
if ( o.range ) {
|
if ( o.range ) {
|
||||||
if ( o.range === true ) {
|
if ( o.range === true ) {
|
||||||
this.range = $( "<div></div>" );
|
|
||||||
if ( !o.values ) {
|
if ( !o.values ) {
|
||||||
o.values = [ this._valueMin(), this._valueMin() ];
|
o.values = [ this._valueMin(), this._valueMin() ];
|
||||||
}
|
}
|
||||||
if ( o.values.length && o.values.length !== 2 ) {
|
if ( o.values.length && o.values.length !== 2 ) {
|
||||||
o.values = [ o.values[0], o.values[0] ];
|
o.values = [ o.values[0], o.values[0] ];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
this.range = $( "<div></div>" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.range
|
this.range = $( "<div></div>" )
|
||||||
.appendTo( this.element )
|
.appendTo( this.element )
|
||||||
.addClass( "ui-slider-range" );
|
.addClass( "ui-slider-range" +
|
||||||
|
|
||||||
if ( o.range === "min" || o.range === "max" ) {
|
|
||||||
this.range.addClass( "ui-slider-range-" + o.range );
|
|
||||||
}
|
|
||||||
|
|
||||||
// note: this isn't the most fittingly semantic framework class for this element,
|
// note: this isn't the most fittingly semantic framework class for this element,
|
||||||
// but worked best visually with a variety of themes
|
// but worked best visually with a variety of themes
|
||||||
this.range.addClass( "ui-widget-header" );
|
" ui-widget-header" +
|
||||||
|
( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $( ".ui-slider-handle", this.element ).length === 0 ) {
|
for ( var i = existingHandles.length; i < handleCount; i += 1 ) {
|
||||||
$( "<a href='#'></a>" )
|
handles.push( handle );
|
||||||
.appendTo( this.element )
|
|
||||||
.addClass( "ui-slider-handle" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( o.values && o.values.length ) {
|
this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( self.element ) );
|
||||||
while ( $(".ui-slider-handle", this.element).length < o.values.length ) {
|
|
||||||
$( "<a href='#'></a>" )
|
|
||||||
.appendTo( this.element )
|
|
||||||
.addClass( "ui-slider-handle" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.handles = $( ".ui-slider-handle", this.element )
|
|
||||||
.addClass( "ui-state-default" +
|
|
||||||
" ui-corner-all" );
|
|
||||||
|
|
||||||
this.handle = this.handles.eq( 0 );
|
this.handle = this.handles.eq( 0 );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user