').addClass( 'ui-slider-label-ticks' )
.css( dir, (Math.round( ( i / cnt ) * 10000 ) / 100) + '%' )
.html( '
' )
.appendTo( $lbl );
}
}
},
_setOption: function( key, value ) {
this._super( key, value );
switch ( key ) {
case 'tickInterval':
case 'tickLabels':
case 'tickArray':
case 'min':
case 'max':
case 'step':
this._alignWithStep();
this._drawLabels();
break;
case 'orientation':
this.element
.removeClass( 'horizontal vertical' )
.addClass( this.orientation );
this._drawLabels();
break;
}
},
_alignWithStep: function () {
if ( this.options.tickInterval < this.options.step )
this.tickInterval = this.options.step;
else
this.tickInterval = this.options.tickInterval;
},
_destroy: function() {
this._super();
this.uiSlider.replaceWith( this.element );
},
widget: function() {
return this.uiSlider;
}
});
}(jQuery));
(function( $ ) {
$.widget( "ui.slidespinner", $.ui.spinner, {
version: "1.1.1",
widgetEventPrefix: "slidespinner",
options: {
alignment: 'vertical',
min: 0,
max: 100,
},
_create: function() {
this.options.min = this.options.min || 0;
this.options.max = this.options.max || 100;
if ( this.options.alignment != 'vertical' &&
this.options.alignment != 'horizontal' ) {
this.options.alignment = 'vertical';
}
this._super();
this._value( this.element.val() );
this.uiSlider.slider( 'value', this.value() | 0 );
},
_draw: function( ) {
var self = this,
options = this.options;
this._super();
this.uiWrapper =
this.uiSpinner
.wrap( '
' )
.parent()
.addClass( 'ui-slidespinner' );
this.uiSlider =
$('')
.appendTo( this.uiWrapper )
.slider({
orientation: options.alignment,
min: options.min,
max: options.max,
slide: function (e, ui) {
self._value( ui.value );
}
});
if ( options.alignment == 'vertical' ) {
this.uiSlider
.position({ my: 'left+5 top+5', at: 'right top', of: this.uiSpinner })
.css( 'height', this.uiSpinner.outerHeight(true) - 10 );
} else {
this.uiSlider
.position({ my: 'left+5 top+5', at: 'left bottom', of: this.uiSpinner })
.css( 'width', this.uiSpinner.outerWidth(true) - 10 );
}
},
_spin: function( step, event ) {
this._super( step, event );
this.uiSlider.slider( 'value', this.value() | 0 );
},
_stop: function( event ) {
if ( event.type == 'keyup' ) {
this.uiSlider.slider( 'value', this.value() | 0 );
}
this._super( event );
},
_destroy: function( ) {
this.uiSlider.remove();
this.uiSpinner.unwrap();
this._super();
}
});
}( jQuery ) );
(function ($) {
"use strict";
var _base_stop = $.ui.spinner.prototype._stop;
$.ui.spinner.prototype._stop = function( event ) {
var value = this.value() || 0;
if (event && event.type == 'keyup' && value != this._adjustValue(value) ) {
this.value(this.previous);
this._trigger( "invalid", event );
} else {
this.previous=value;
this.element.val(this._format(value));
}
_base_stop.call( this, event );
}
$.widget( "ui.paddedspinner", $.ui.spinner, {
widgetEventPrefix: "spin",
options: {
padCount: 2,
padString: '0'
},
_parse: function( value ) {
return +value;
},
_format: function( value ) {
var str = value+'';
while ( str.length < this.options.padCount )
str = this.options.padString + str;
return str;
},
});
$.widget( "ui.ampmspinner", $.ui.spinner, {
widgetEventPrefix: "spin",
options: {
max: 1,
min: 0,
alignment: 'vertical'
},
_parse: function( value ) {
if ( typeof value === "string" ) {
return value == 'AM' ? 0 : 1;
}
return value;
},
_format: function( value ) {
return value === 0 ? 'AM' : 'PM';
},
});
$.widget('osb.timepicker', {
version: "1.1.1",
widgetEventPrefix: 'timepicker',
options: {
format: 'hh:mm A'
},
_init: function () {
var self = this,
html = ':';
this.hour24 = ( this.options.format.indexOf( 'HH' ) > -1 );
if ( !this.hour24 )
html += ' ';
this.element.empty().html( html );
this.$hour = this.element.children( '.ui-timepicker-hour' ).paddedspinner({
alignment: 'vertical',
min: this.hour24 ? -1 : 0,
max: this.hour24 ? 24 : 13,
spin: function( e, ui ) {
var ampm,
val = +ui.value,
min = self.hour24 ? -1 : 0,
max = self.hour24 ? 24 : 13;
if ( val <= min || val >= max ) {
if ( val <= min ) self.$hour.paddedspinner( 'value', max - 1 );
if ( val >= max ) self.$hour.paddedspinner( 'value', min + 1 );
if ( !self.hour24 ) {
ampm = self.$ampm.ampmspinner( 'value' );
self.$ampm.ampmspinner( 'value', ampm == 0 ? 1 : 0 );
}
self._trigger( 'change', self._value() );
return false;
}
self._trigger( 'change', self._value() );
},
stop: function() {
var val = +self.$hour.val(),
min = self.hour24 ? -1 : 0,
max = self.hour24 ? 24 : 13;
if ( val <= min || val >= max ) {
self.$hour.val('')
}
self._ensureValue();
}
});
this.$minute = this.element.children( '.ui-timepicker-minute' ).paddedspinner({
alignment: 'vertical',
min: -1,
max: 60,
spin: function( e, ui ) {
var hour, val = +ui.value;
if ( val <= -1 || val >= 60 ) {
if ( val <= -1 ) self.$minute.paddedspinner( 'value', 59 );
if ( val >= 60 ) self.$minute.paddedspinner( 'value', 0 );
hour = self.$hour.paddedspinner( 'value' );
hour = val == -1 ? hour -1 : hour + 1;
self.$hour
.paddedspinner( 'value', hour )
.data( 'ui-paddedspinner' )._trigger( 'spin', e, { value: hour } );
self._trigger( 'change', self._value() );
return false;
}
self._trigger( 'change', self._value() );
},
stop: function() {
var val = +self.$minute.val();
if ( val == -1 || val == 60 ) {
self.$hour.val('');
}
self._ensureValue();
}
});
if ( !this.hour24 ) {
this.$ampm = this.element.children( '.ui-timepicker-ampm' ).ampmspinner({
spin: function() {
self._trigger( 'change', self._value() );
self._ensureValue();
}
});
}
this._on( this._events );
},
_events: {
'click input': function( e ) {
var $target = $( e.currentTarget );
$target.select();
}
},
_destroy: function () {
this.element.empty();
},
_value: function() {
var hour = +this.$hour.val(),
min = +this.$minute.val(),
ampm = this.hour24 ? '' : this.$ampm.val(),
val;
if ( window.moment ) {
hour = ( ampm == 'PM' && hour < 12 ? hour + 12 : hour );
val = moment({ hour: hour, minute: min });
} else {
val = hour + ':' + min;
if ( !this.hour24 )
val += ' ' + ampm;
}
return val;
},
_parse: function( val ) {
var tm, parts,
hour, min, ampm;
if ( window.moment ) {
if ( val instanceof Date )
tm = moment( val );
else
tm = moment( val, this.options.format );
if ( !tm.isValid() ) return;
hour = tm.hour();
min = tm.minute();
if ( !this.hour24 ) {
ampm = hour >= 12 ? 'PM' : 'AM';
hour = hour > 12 ? hour - 12 : hour
}
} else {
parts = val.split( /[: ]/ );
if ( parts.length < 2 ) return;
hour = parts[0];
min = parts[1];
if ( !this.hour24 ) {
ampm = parts[2] || 'AM';
}
}
this.$hour.paddedspinner( 'value', +hour );
this.$minute.paddedspinner( 'value', +min );
if ( !this.hour24 ) {
this.$ampm.ampmspinner( 'value', ampm == 'AM' ? 0 : 1 );
}
},
_ensureValue: function() {
var dt = new Date(),
hour = this.$hour.val(),
min = this.$minute.val(),
ampm = this.hour24 ? '' : this.$ampm.val();
if ( !hour ) this.$hour.paddedspinner( 'value', ( hour = dt.getHours() ) > 12 ? hour - 12 : hour );
if ( !min ) this.$minute.paddedspinner( 'value', dt.getMinutes() );
if ( !this.hour24 ) {
if ( !ampm ) this.$ampm.ampmspinner( 'value', dt.getHours() > 12 ? 'PM' : 'AM' );
}
},
value: function( val ) {
if ( typeof( val ) == 'undefined' )
return this._value();
else
this._parse( val );
}
});
})(jQuery);
(function ( $, undefined ) {
$.widget( "ui.waitbutton", $.ui.button, {
version: "1.1.1",
// Keep button prefix instead of waitbutton
// otherwise waiting event is waitbuttonwaiting
// which is weird.
widgetEventPrefix: "button",
options: {
waitLabel: null,
waitIcon: 'ui-icon-waiting'
},
_saved: null,
_create: function() {
this._super();
this.element.addClass('ui-wait-button');
this._saved = {};
this._saveOptions();
},
_init: function() {
this._super();
this.disable();
this._toggleWaitState();
this._initWaitClick();
},
_initWaitClick: function() {
/**
* channel clicks through waiting event instead
* base button does not listen to click -
* it listens to mousedown/up. This prevents any external
* listeners from firing when we want to use the callback
* provided by the waiting event.
*/
this.element.off( 'click' );
this.element.one( 'click', $.proxy( this, '_toggleWaitState' ) );
},
_toggleWaitState: function() {
var event;
if ( this.options.disabled ) {
this._setOptions({
disabled: false,
label: this._saved.label,
icons: { primary: this._saved.icon }
});
} else {
this._saveOptions();
this._setOptions({
disabled: true,
label: this.options.waitLabel || this.options.label,
icons: { primary: this.options.waitIcon }
});
event = arguments[0] || (new jQuery.Event( 'click', { target: this.element } ) );
/* channel clicks through waiting event instead */
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
this._trigger( 'waiting', event, { done: $.proxy( this, '_waitComplete' ) } );
}
},
_waitComplete: function() {
// Juggle arguments
var label = (arguments[0] && typeof( arguments[0] ) == 'string' ? arguments[0] : null),
enable = (label ? arguments[1] : arguments[0]);
// Determine next state - either return to start or
// use a different label and/or leave in disabled state
if ( typeof( enable ) == 'undefined' ) enable = true;
this._toggleWaitState();
if ( enable ) {
this._initWaitClick();
} else {
this.disable();
}
if ( label ) {
this._setOption( 'label', label );
}
},
_saveOptions: function() {
this._saved.icon = this.options.icons.primary;
this._saved.label = this.options.label;
}
});
})(jQuery);