Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dmitry Sikorsky
committed
Feb 2, 2017
1 parent
7d9f12c
commit f1ab0f0
Showing
37 changed files
with
456 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/Platformus.Barebone.Backend/Areas/Backend/Scripts/culture.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright © 2017 Dmitry Sikorsky. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
(function (platformus) { | ||
platformus.culture = platformus.culture || {}; | ||
platformus.culture.client = function () { | ||
var culture = window.navigator.userLanguage || window.navigator.language; | ||
|
||
if (platformus.string.isNullOrEmpty(culture)) { | ||
culture = "en"; | ||
} | ||
|
||
if (culture.length > 2) { | ||
culture = culture.substring(0, 2); | ||
} | ||
|
||
return culture; | ||
}; | ||
|
||
platformus.culture.server = function () { | ||
return $("html").data("culture"); | ||
}; | ||
})(window.platformus = window.platformus || {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
147 changes: 147 additions & 0 deletions
147
src/Platformus.Barebone.Backend/Areas/Backend/Scripts/text_box_date_behavior.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
// Copyright © 2017 Dmitry Sikorsky. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
(function (platformus) { | ||
platformus.registerBehavior( | ||
function () { | ||
defineHandlers(); | ||
} | ||
); | ||
|
||
function defineHandlers() { | ||
$(document.body).on("focus click", "input[data-type='date']", textBoxFocusHandler); | ||
$(document.body).on("blur", "input[data-type='date']", textBoxBlurHandler); | ||
} | ||
|
||
function textBoxFocusHandler() { | ||
var picker = getPicker(); | ||
var textBox = $(this); | ||
|
||
if (picker.length != 0 && picker.data("textBoxId") == textBox.attr("id")) { | ||
return; | ||
} | ||
|
||
picker = createPicker(textBox); | ||
positionPicker(picker, textBox); | ||
showPicker(picker); | ||
} | ||
|
||
function textBoxBlurHandler() { | ||
var picker = getPicker(); | ||
|
||
try { | ||
if (picker.is(":hover")) { | ||
return; | ||
} | ||
} | ||
|
||
catch (e) {} | ||
|
||
hideAndRemovePicker(picker); | ||
} | ||
|
||
function createPicker(textBox) { | ||
var picker = $("<div>").addClass("date-picker").addClass("picker").attr("data-text-box-id", textBox.attr("id")).appendTo($(document.body)); | ||
|
||
$("<div>").addClass("picker__arrow").appendTo(picker); | ||
|
||
var today = moment(); | ||
var thisMonth = moment(new Date(today.year(), today.month(), 1)).locale(platformus.culture.server()); | ||
|
||
createCalendar(thisMonth, textBox).appendTo(picker); | ||
return picker; | ||
} | ||
|
||
function positionPicker(picker, textBox) { | ||
picker.css( | ||
{ left: textBox.offset().left + textBox.outerWidth() + 20, top: textBox.offset().top } | ||
) | ||
} | ||
|
||
function showPicker(picker) { | ||
picker.fadeIn("fast"); | ||
} | ||
|
||
function createCalendar(thisMonth, textBox) { | ||
var calendar = $("<div>").addClass("date-picker__calendar").addClass("calendar"); | ||
|
||
createHeader(thisMonth, textBox).appendTo(calendar); | ||
createMonth(thisMonth, textBox).appendTo(calendar); | ||
return calendar; | ||
} | ||
|
||
function createHeader(thisMonth, textBox) { | ||
var header = $("<div>").addClass("calendar__header").html(thisMonth.format("MMMM YYYY")); | ||
var previousMonth = $("<div>").addClass("calendar__previous-month").appendTo(header).click( | ||
function () { | ||
getPicker().find(".calendar").replaceWith(createCalendar(thisMonth.subtract(1, "months"), textBox)); | ||
textBox.focus(); | ||
return false; | ||
} | ||
); | ||
|
||
var nextMonth = $("<div>").addClass("calendar__next-month").appendTo(header).click( | ||
function () { | ||
getPicker().find(".calendar").replaceWith(createCalendar(thisMonth.add(1, "months"), textBox)); | ||
textBox.focus(); | ||
return false; | ||
} | ||
); | ||
|
||
return header; | ||
} | ||
|
||
function createMonth(thisMonth, textBox) { | ||
var month = $("<div>").addClass("calendar__month"); | ||
var week = $("<div>").addClass("calendar__week").appendTo(month); | ||
|
||
for (var i = 0; i != 7; i++) { | ||
$("<div>").addClass("calendar__day").html(moment().day(i + 1).format("dd")).appendTo(week); | ||
} | ||
|
||
var offset = thisMonth.isoWeekday() - 1; | ||
var date = thisMonth.clone().subtract(offset, "days"); | ||
|
||
for (var i = 0; i != 6; i++) { | ||
week = $("<div>").addClass("calendar__week").appendTo(month); | ||
|
||
for (var j = 0; j != 7; j++) { | ||
var day = $("<a>").addClass("calendar__day").attr("href", "#").html(date.format("DD")).appendTo(week).click( | ||
function (formattedDate) { | ||
return function () { | ||
textBox.val(formattedDate); | ||
textBox.focus(); | ||
hideAndRemovePicker(getPicker()); | ||
return false; | ||
}; | ||
}(date.locale(textBox.data("culture")).format("L")) | ||
); | ||
|
||
if (date.month() != thisMonth.month()) { | ||
day.addClass("calendar__day--outer"); | ||
} | ||
|
||
else if (date.month() == moment().month() && date.date() == moment().date()) { | ||
day.addClass("calendar__day--today"); | ||
} | ||
|
||
date.add(1, "days"); | ||
} | ||
} | ||
|
||
return month; | ||
} | ||
|
||
function getPicker() { | ||
return $(".picker"); | ||
} | ||
|
||
function hideAndRemovePicker(picker) { | ||
picker.fadeOut( | ||
"fast", | ||
function () { | ||
picker.remove(); | ||
} | ||
); | ||
} | ||
})(window.platformus = window.platformus || {}); |
96 changes: 96 additions & 0 deletions
96
src/Platformus.Barebone.Backend/Areas/Backend/Styles/calendar.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* Copyright © 2017 Dmitry Sikorsky. All rights reserved. */ | ||
/* Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. */ | ||
|
||
.calendar { | ||
background: #323232; | ||
text-align: center; | ||
} | ||
|
||
.calendar__header { | ||
color: #fff; | ||
padding: 5px 0; | ||
position: relative; | ||
} | ||
|
||
.calendar__previous-month { | ||
background: url(/wwwroot.areas.backend.images.previous_month.png) no-repeat; | ||
cursor: pointer; | ||
position: absolute; | ||
left: 0; | ||
top: 0; | ||
width: 30px; | ||
height: 30px; | ||
} | ||
|
||
.calendar__previous-month:hover { | ||
background-color: #3c3c3c; | ||
} | ||
|
||
.calendar__next-month { | ||
background: url(/wwwroot.areas.backend.images.next_month.png) no-repeat; | ||
cursor: pointer; | ||
position: absolute; | ||
right: 0; | ||
top: 0; | ||
width: 30px; | ||
height: 30px; | ||
} | ||
|
||
.calendar__next-month:hover { | ||
background-color: #3c3c3c; | ||
} | ||
|
||
.calendar__month { | ||
display: table; | ||
width: 100%; | ||
} | ||
|
||
.calendar__week { | ||
display: table-row; | ||
} | ||
|
||
.calendar__day { | ||
text-decoration: none; | ||
color: #fff; | ||
display: table-cell; | ||
padding: 5px 0; | ||
} | ||
|
||
.calendar__day:hover { | ||
background-color: #3c3c3c; | ||
color: #fff; | ||
} | ||
|
||
.calendar__day--today { | ||
background: #0096fa; | ||
} | ||
|
||
.calendar__day--today:hover { | ||
background: #5abeff; | ||
} | ||
|
||
.calendar__day--outer { | ||
color: #666; | ||
} | ||
|
||
.calendar__day--outer:hover { | ||
color: #666; | ||
} | ||
|
||
@media | ||
only screen and (-webkit-min-device-pixel-ratio: 2), | ||
only screen and ( min--moz-device-pixel-ratio: 2), | ||
only screen and ( -o-min-device-pixel-ratio: 2/1), | ||
only screen and ( min-device-pixel-ratio: 2), | ||
only screen and ( min-resolution: 192dpi), | ||
only screen and ( min-resolution: 2dppx) { | ||
.calendar__previous-month { | ||
background-image: url(/wwwroot.areas.backend.images.previous_month@2x.png); | ||
background-size: 30px; | ||
} | ||
|
||
.calendar__next-month { | ||
background-image: url(/wwwroot.areas.backend.images.next_month@2x.png); | ||
background-size: 30px; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Platformus.Barebone.Backend/Areas/Backend/Styles/date_picker.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* Copyright © 2017 Dmitry Sikorsky. All rights reserved. */ | ||
/* Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. */ | ||
|
||
.date-picker { | ||
} | ||
|
||
.date-picker__calendar { | ||
width: 210px; | ||
} |
Oops, something went wrong.