Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit aa54aa7

Browse files
committed
version 0.0.4
1 parent e45036e commit aa54aa7

5 files changed

+58
-49
lines changed

dist/daterangepicker.css

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* knockout-daterangepicker
3-
* version: 0.0.3
3+
* version: 0.0.4
44
* authors: Sensor Tower team
55
* license: MIT
66
* https://sensortower.github.io/daterangepicker
@@ -158,7 +158,7 @@
158158
transform: translate(6px, -3.5px);
159159
}
160160

161-
.daterangepicker.opens-right:not(.standalone):before {
161+
.daterangepicker.orientation-right:not(.standalone):before {
162162
position: absolute;
163163
top: -7px;
164164
left: 9px;
@@ -169,7 +169,7 @@
169169
content: '';
170170
}
171171

172-
.daterangepicker.opens-left:not(.standalone):before {
172+
.daterangepicker.orientation-left:not(.standalone):before {
173173
position: absolute;
174174
top: -7px;
175175
right: 9px;
@@ -180,7 +180,7 @@
180180
content: '';
181181
}
182182

183-
.daterangepicker.opens-right:not(.standalone):after {
183+
.daterangepicker.orientation-right:not(.standalone):after {
184184
position: absolute;
185185
top: -6px;
186186
left: 10px;
@@ -191,7 +191,7 @@
191191
content: '';
192192
}
193193

194-
.daterangepicker.opens-left:not(.standalone):after {
194+
.daterangepicker.orientation-left:not(.standalone):after {
195195
position: absolute;
196196
top: -6px;
197197
right: 10px;
@@ -451,6 +451,6 @@
451451
opacity: 0.75;
452452
}
453453

454-
.daterangepicker.opens-left:not(.single) .controls {
454+
.daterangepicker.orientation-left:not(.single) .controls {
455455
order: 2;
456456
}

dist/daterangepicker.js

+47-38
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* knockout-daterangepicker
3-
* version: 0.0.3
3+
* version: 0.0.4
44
* authors: Sensor Tower team
55
* license: MIT
66
* https://sensortower.github.io/daterangepicker
@@ -102,14 +102,18 @@
102102
})();
103103

104104
$.fn.daterangepicker = function(options, callback) {
105+
if (options == null) {
106+
options = {};
107+
}
105108
this.each(function() {
106109
var $element;
107110
$element = $(this);
108111
if (!$element.data('daterangepicker')) {
109112
options.anchorElement = $element;
110113
if (callback) {
111-
options.callback = $.proxy(callback, this);
114+
options.callback = callback;
112115
}
116+
options.callback = $.proxy(options.callback, this);
113117
return $element.data('daterangepicker', new DateRangePickerView(options));
114118
}
115119
});
@@ -126,34 +130,37 @@
126130

127131
ko.virtualElements.allowedBindings.stopBinding = true;
128132

129-
ko.bindingHandlers.daterangepicker = {
130-
init: function(element, valueAccessor, allBindings) {
131-
var observable, options;
132-
observable = valueAccessor();
133-
options = allBindings.get('daterangepickerOptions') || {};
134-
return $(element).daterangepicker(options, function(startDate, endDate, period) {
135-
return observable([startDate, endDate, period]);
136-
});
137-
},
138-
update: function(element, valueAccessor, allBindings) {
139-
var $element, dateFormat, endDate, endDateText, period, ref, startDate, startDateText;
140-
$element = $(element);
141-
ref = valueAccessor()(), startDate = ref[0], endDate = ref[1], period = ref[2];
142-
dateFormat = 'MMM D, YYYY';
143-
startDateText = moment(startDate).format(dateFormat);
144-
endDateText = moment(endDate).format(dateFormat);
145-
return ko.ignoreDependencies(function() {
146-
if ($element.data('daterangepicker').single()) {
147-
$element.val(startDateText);
148-
} else {
149-
$element.val(startDateText + " – " + endDateText);
150-
}
151-
$element.data('daterangepicker').period(period);
152-
$element.data('daterangepicker').startDate(startDate);
153-
return $element.data('daterangepicker').endDate(endDate);
154-
});
155-
}
156-
};
133+
ko.bindingHandlers.daterangepicker = (function() {
134+
return $.extend(this, {
135+
_optionsKey: 'daterangepickerOptions',
136+
_formatKey: 'daterangepickerFormat',
137+
init: function(element, valueAccessor, allBindings) {
138+
var observable, options;
139+
observable = valueAccessor();
140+
options = ko.unwrap(allBindings.get(this._optionsKey)) || {};
141+
return $(element).daterangepicker(options, function(startDate, endDate, period) {
142+
return observable([startDate, endDate]);
143+
});
144+
},
145+
update: function(element, valueAccessor, allBindings) {
146+
var $element, dateFormat, endDate, endDateText, ref, startDate, startDateText;
147+
$element = $(element);
148+
ref = valueAccessor()(), startDate = ref[0], endDate = ref[1];
149+
dateFormat = ko.unwrap(allBindings.get(this._formatKey)) || 'MMM D, YYYY';
150+
startDateText = moment(startDate).format(dateFormat);
151+
endDateText = moment(endDate).format(dateFormat);
152+
return ko.ignoreDependencies(function() {
153+
var text;
154+
if (!$element.data('daterangepicker').standalone()) {
155+
text = $element.data('daterangepicker').single() ? startDateText : startDateText + " – " + endDateText;
156+
$element.val(text).text(text);
157+
}
158+
$element.data('daterangepicker').startDate(startDate);
159+
return $element.data('daterangepicker').endDate(endDate);
160+
});
161+
}
162+
});
163+
})();
157164

158165
DateRange = (function() {
159166
function DateRange(title, startDate, endDate) {
@@ -289,7 +296,7 @@
289296
this.expanded = this._expanded(options.expanded);
290297
this.standalone = this._standalone(options.standalone);
291298
this.locale = this._locale(options.locale);
292-
this.opens = this._opens(options.opens);
299+
this.orientation = this._orientation(options.orientation);
293300
this.forceUpdate = options.forceUpdate;
294301
this.minDate = this._minDate(options.minDate);
295302
this.maxDate = this._maxDate(options.maxDate);
@@ -414,7 +421,7 @@
414421
};
415422
};
416423

417-
Config.prototype._opens = function(val) {
424+
Config.prototype._orientation = function(val) {
418425
if (val !== 'right' && val !== 'left') {
419426
val = 'right';
420427
}
@@ -518,7 +525,9 @@
518525
};
519526

520527
Config.prototype._parentElement = function(val) {
521-
if (this.anchorElement) {
528+
if (this.standalone()) {
529+
return this.anchorElement;
530+
} else {
522531
return $(val || 'body');
523532
}
524533
};
@@ -971,11 +980,11 @@
971980
var j, len, obj, period, ref;
972981
obj = {
973982
single: this.single(),
974-
opened: this.opened(),
983+
opened: this.standalone() || this.opened(),
975984
expanded: this.standalone() || this.single() || this.expanded(),
976985
standalone: this.standalone(),
977-
'opens-left': this.opens() === 'left',
978-
'opens-right': this.opens() === 'right',
986+
'orientation-left': this.orientation() === 'left',
987+
'orientation-right': this.orientation() === 'right',
979988
'hide-periods': this.periods().length === 1
980989
};
981990
ref = Period.allPeriods;
@@ -1051,7 +1060,7 @@
10511060
if (this.opened()) {
10521061
return this.close();
10531062
} else {
1054-
return open();
1063+
return this.open();
10551064
}
10561065
};
10571066

@@ -1077,7 +1086,7 @@
10771086
left: 'auto',
10781087
right: 'auto'
10791088
};
1080-
switch (this.opens()) {
1089+
switch (this.orientation()) {
10811090
case 'left':
10821091
if (this.containerElement.offset().left < 0) {
10831092
style.left = '9px';

0 commit comments

Comments
 (0)