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

Commit

Permalink
version 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
petethepig committed Dec 8, 2015
1 parent e45036e commit aa54aa7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 49 deletions.
12 changes: 6 additions & 6 deletions dist/daterangepicker.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* knockout-daterangepicker
* version: 0.0.3
* version: 0.0.4
* authors: Sensor Tower team
* license: MIT
* https://sensortower.github.io/daterangepicker
Expand Down Expand Up @@ -158,7 +158,7 @@
transform: translate(6px, -3.5px);
}

.daterangepicker.opens-right:not(.standalone):before {
.daterangepicker.orientation-right:not(.standalone):before {
position: absolute;
top: -7px;
left: 9px;
Expand All @@ -169,7 +169,7 @@
content: '';
}

.daterangepicker.opens-left:not(.standalone):before {
.daterangepicker.orientation-left:not(.standalone):before {
position: absolute;
top: -7px;
right: 9px;
Expand All @@ -180,7 +180,7 @@
content: '';
}

.daterangepicker.opens-right:not(.standalone):after {
.daterangepicker.orientation-right:not(.standalone):after {
position: absolute;
top: -6px;
left: 10px;
Expand All @@ -191,7 +191,7 @@
content: '';
}

.daterangepicker.opens-left:not(.standalone):after {
.daterangepicker.orientation-left:not(.standalone):after {
position: absolute;
top: -6px;
right: 10px;
Expand Down Expand Up @@ -451,6 +451,6 @@
opacity: 0.75;
}

.daterangepicker.opens-left:not(.single) .controls {
.daterangepicker.orientation-left:not(.single) .controls {
order: 2;
}
85 changes: 47 additions & 38 deletions dist/daterangepicker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*!
* knockout-daterangepicker
* version: 0.0.3
* version: 0.0.4
* authors: Sensor Tower team
* license: MIT
* https://sensortower.github.io/daterangepicker
Expand Down Expand Up @@ -102,14 +102,18 @@
})();

$.fn.daterangepicker = function(options, callback) {
if (options == null) {
options = {};
}
this.each(function() {
var $element;
$element = $(this);
if (!$element.data('daterangepicker')) {
options.anchorElement = $element;
if (callback) {
options.callback = $.proxy(callback, this);
options.callback = callback;
}
options.callback = $.proxy(options.callback, this);
return $element.data('daterangepicker', new DateRangePickerView(options));
}
});
Expand All @@ -126,34 +130,37 @@

ko.virtualElements.allowedBindings.stopBinding = true;

ko.bindingHandlers.daterangepicker = {
init: function(element, valueAccessor, allBindings) {
var observable, options;
observable = valueAccessor();
options = allBindings.get('daterangepickerOptions') || {};
return $(element).daterangepicker(options, function(startDate, endDate, period) {
return observable([startDate, endDate, period]);
});
},
update: function(element, valueAccessor, allBindings) {
var $element, dateFormat, endDate, endDateText, period, ref, startDate, startDateText;
$element = $(element);
ref = valueAccessor()(), startDate = ref[0], endDate = ref[1], period = ref[2];
dateFormat = 'MMM D, YYYY';
startDateText = moment(startDate).format(dateFormat);
endDateText = moment(endDate).format(dateFormat);
return ko.ignoreDependencies(function() {
if ($element.data('daterangepicker').single()) {
$element.val(startDateText);
} else {
$element.val(startDateText + " – " + endDateText);
}
$element.data('daterangepicker').period(period);
$element.data('daterangepicker').startDate(startDate);
return $element.data('daterangepicker').endDate(endDate);
});
}
};
ko.bindingHandlers.daterangepicker = (function() {
return $.extend(this, {
_optionsKey: 'daterangepickerOptions',
_formatKey: 'daterangepickerFormat',
init: function(element, valueAccessor, allBindings) {
var observable, options;
observable = valueAccessor();
options = ko.unwrap(allBindings.get(this._optionsKey)) || {};
return $(element).daterangepicker(options, function(startDate, endDate, period) {
return observable([startDate, endDate]);
});
},
update: function(element, valueAccessor, allBindings) {
var $element, dateFormat, endDate, endDateText, ref, startDate, startDateText;
$element = $(element);
ref = valueAccessor()(), startDate = ref[0], endDate = ref[1];
dateFormat = ko.unwrap(allBindings.get(this._formatKey)) || 'MMM D, YYYY';
startDateText = moment(startDate).format(dateFormat);
endDateText = moment(endDate).format(dateFormat);
return ko.ignoreDependencies(function() {
var text;
if (!$element.data('daterangepicker').standalone()) {
text = $element.data('daterangepicker').single() ? startDateText : startDateText + " – " + endDateText;
$element.val(text).text(text);
}
$element.data('daterangepicker').startDate(startDate);
return $element.data('daterangepicker').endDate(endDate);
});
}
});
})();

DateRange = (function() {
function DateRange(title, startDate, endDate) {
Expand Down Expand Up @@ -289,7 +296,7 @@
this.expanded = this._expanded(options.expanded);
this.standalone = this._standalone(options.standalone);
this.locale = this._locale(options.locale);
this.opens = this._opens(options.opens);
this.orientation = this._orientation(options.orientation);
this.forceUpdate = options.forceUpdate;
this.minDate = this._minDate(options.minDate);
this.maxDate = this._maxDate(options.maxDate);
Expand Down Expand Up @@ -414,7 +421,7 @@
};
};

Config.prototype._opens = function(val) {
Config.prototype._orientation = function(val) {
if (val !== 'right' && val !== 'left') {
val = 'right';
}
Expand Down Expand Up @@ -518,7 +525,9 @@
};

Config.prototype._parentElement = function(val) {
if (this.anchorElement) {
if (this.standalone()) {
return this.anchorElement;
} else {
return $(val || 'body');
}
};
Expand Down Expand Up @@ -971,11 +980,11 @@
var j, len, obj, period, ref;
obj = {
single: this.single(),
opened: this.opened(),
opened: this.standalone() || this.opened(),
expanded: this.standalone() || this.single() || this.expanded(),
standalone: this.standalone(),
'opens-left': this.opens() === 'left',
'opens-right': this.opens() === 'right',
'orientation-left': this.orientation() === 'left',
'orientation-right': this.orientation() === 'right',
'hide-periods': this.periods().length === 1
};
ref = Period.allPeriods;
Expand Down Expand Up @@ -1051,7 +1060,7 @@
if (this.opened()) {
return this.close();
} else {
return open();
return this.open();
}
};

Expand All @@ -1077,7 +1086,7 @@
left: 'auto',
right: 'auto'
};
switch (this.opens()) {
switch (this.orientation()) {
case 'left':
if (this.containerElement.offset().left < 0) {
style.left = '9px';
Expand Down
Loading

0 comments on commit aa54aa7

Please sign in to comment.