Skip to content
This repository has been archived by the owner on Dec 15, 2017. It is now read-only.

"componentSelector" option #156

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/js/bootstrap-datetimepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@
this.pickTime = options.pickTime;
this.isInput = this.$element.is('input');
this.component = false;
this.componentSelector = options.componentSelector;
if (this.$element.find('.input-append') || this.$element.find('.input-prepend'))
this.component = this.$element.find('.add-on');
this.component = this.$element.find(this.componentSelector);
this.format = options.format;
if (!this.format) {
if (this.isInput) this.format = this.$element.data('format');
Expand Down Expand Up @@ -266,16 +267,16 @@
offset.top = offset.top + this.height;

var $window = $(window);

if ( this.options.width != undefined ) {
this.widget.width( this.options.width );
}

if ( this.options.orientation == 'left' ) {
this.widget.addClass( 'left-oriented' );
offset.left = offset.left - this.widget.width() + 20;
}

if (this._isInFixed()) {
position = 'fixed';
offset.top -= $window.scrollTop();
Expand Down Expand Up @@ -972,7 +973,7 @@
expanded.collapse('hide');
closed.collapse('show')
$this.find('i').toggleClass(self.timeIcon + ' ' + self.dateIcon);
self.$element.find('.add-on i').toggleClass(self.timeIcon + ' ' + self.dateIcon);
self.$element.find(this.componentSelector + ' i').toggleClass(self.timeIcon + ' ' + self.dateIcon);
}
});
}
Expand Down Expand Up @@ -1095,7 +1096,8 @@
pickSeconds: true,
startDate: -Infinity,
endDate: Infinity,
collapse: true
collapse: true,
componentSelector: '.add-on'
};
$.fn.datetimepicker.Constructor = DateTimePicker;
var dpgId = 0;
Expand Down
25 changes: 25 additions & 0 deletions test/specs.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,28 @@ describe 'datetimepicker with pickSeconds = false', ->
expect(@timeWidget.find('[data-action=decrementSeconds]').length).to.equal 0
expect(@timeWidget.find('.timepicker-second').length) .to.equal 0

describe 'datetimepicker with componentSelector = ".btn-calendar"', ->

beforeEach setupDateTimePicker({
componentSelector: '.btn-calendar'
markup:
"""
<div id="datetimepicker" class="input-append date">
<input type="text" value="05/01/1905 05:55" data-format="MM/dd/yyyy hh:mm">
<buttom class="btn btn-calendar">
<i data-time-icon="icon-time" data-date-icon="icon-calendar"></i>
</buttom>
</div>
"""
})

afterEach teardownDateTimePicker()

it 'pops up the widget when icon is clicked', ->
@addon.click()
expect(@widget.is ':visible').to.be.true

it 'hides the widget when clicking outside it', ->
@addon.click()
$('#mocha').mousedown()
expect(@widget.is ':hidden').to.be.true
5 changes: 4 additions & 1 deletion test/utils.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ setupDateTimePicker = (opts) ->
if opts?.markup
markup = opts.markup
delete opts.markup
componentSelector = '.add-on'
if opts?.componentSelector
componentSelector = opts.componentSelector
return ->
@component = $(markup).appendTo($ '#container').datetimepicker(opts)
@input = @component.find 'input'
@addon = @component.find '.add-on'
@addon = @component.find componentSelector
@picker = @component.data 'datetimepicker'
@widget = $ 'body > .bootstrap-datetimepicker-widget'
@dateWidget = @widget.find('.datepicker')
Expand Down