Skip to content

Commit

Permalink
Fixed #7
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Sikorsky committed Feb 2, 2017
1 parent 7d9f12c commit f1ab0f0
Show file tree
Hide file tree
Showing 37 changed files with 456 additions and 44 deletions.
11 changes: 4 additions & 7 deletions .gitignore
Expand Up @@ -4,12 +4,9 @@ bin/
obj/
src/Platformus.Barebone.Backend/wwwroot/areas/backend/css
src/Platformus.Barebone.Backend/wwwroot/areas/backend/js
src/Platformus.Barebone.Backend/node_modules/
src/Platformus.Content.Backend/wwwroot/areas/backend/css
src/Platformus.Content.Backend/wwwroot/areas/backend/js
src/Platformus.Content.Backend/node_modules/
src/Platformus.Static.Backend/wwwroot/areas/backend/css
src/Platformus.Static.Backend/wwwroot/areas/backend/js
src/Platformus.Static.Backend/node_modules/
src/Platformus.Domain.Backend/wwwroot/areas/backend/css
src/Platformus.Domain.Backend/wwwroot/areas/backend/js
src/Platformus.FileManager.Backend/wwwroot/areas/backend/css
src/Platformus.FileManager.Backend/wwwroot/areas/backend/js
*.xproj.user
*.lock.json
23 changes: 23 additions & 0 deletions src/Platformus.Barebone.Backend/Areas/Backend/Scripts/culture.js
@@ -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 || {});
Expand Up @@ -23,9 +23,9 @@

if (this.hasClass("drop-down-list")) {
var dropDownList = this,
selectedDropDownListItem = dropDownList.find(".drop-down-list-item--selected"),
dropDownListItems = dropDownList.find(".drop-down-list-items"),
dropDownListItem = dropDownListItems.find(".drop-down-list-item[data-value='" + value + "']"),
selectedDropDownListItem = dropDownList.find(".drop-down-list__item--selected"),
dropDownListItems = dropDownList.find(".drop-down-list__items"),
dropDownListItem = dropDownListItems.find(".drop-down-list__item[data-value='" + value + "']"),
input = dropDownList.find("input");

selectedDropDownListItem.html(dropDownListItem.html());
Expand All @@ -42,17 +42,17 @@

function defineHandlers() {
$(document.body).on("click", globalClickHandler);
$(document.body).on("click", ".drop-down-list-item--selected", selectedDropDownListItemClickHandler);
$(document.body).on("click", ".drop-down-list-item:not(.drop-down-list-item--selected)", dropDownListItemClickHandler);
$(document.body).on("click", ".drop-down-list__item--selected", selectedDropDownListItemClickHandler);
$(document.body).on("click", ".drop-down-list__item:not(.drop-down-list__item--selected)", dropDownListItemClickHandler);
}

function globalClickHandler() {
$(".drop-down-list-items").slideUp("fast");
$(".drop-down-list__items").slideUp("fast");
return true;
}

function selectedDropDownListItemClickHandler() {
$(this).parent().find(".drop-down-list-items").slideDown("fast");
$(this).parent().find(".drop-down-list__items").slideDown("fast");
return false;
}

Expand Down
Expand Up @@ -48,7 +48,7 @@
}

function showMaxLengthIndicator(maxLengthIndicator) {
maxLengthIndicator.animate({ opacity: 1 }, "fast");
maxLengthIndicator.fadeIn("fast");
}

function bindMaxLengthIndicatorToControl(maxLengthIndicator, control) {
Expand All @@ -71,8 +71,7 @@
}

function hideAndRemoveMaxLengthIndicator(maxLengthIndicator) {
maxLengthIndicator.animate(
{ opacity: 0 },
maxLengthIndicator.fadeOut(
"fast",
function () {
maxLengthIndicator.remove();
Expand Down
@@ -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 src/Platformus.Barebone.Backend/Areas/Backend/Styles/calendar.css
@@ -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;
}
}
@@ -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;
}

0 comments on commit f1ab0f0

Please sign in to comment.