Skip to content

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrice committed Nov 24, 2014
2 parents 84a921f + a8f3907 commit 5c5ad67
Show file tree
Hide file tree
Showing 7 changed files with 213 additions and 3 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zdk-calendar",
"version": "0.2.1",
"version": "0.2.2",
"authors": [
"Fabrice <[email protected]>"
],
Expand All @@ -23,6 +23,7 @@
"dependencies": {
"momentjs": "~2.8.3",
"polymer": "Polymer/polymer#~0.5.1",
"core-icon":"Polymer/core-icon#~0.5.1",
"core-iconset-svg": "Polymer/core-iconset-svg#~0.5.1"
}
}
4 changes: 3 additions & 1 deletion index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ <h1>Calendar component</h1>
<h2>Default calendar</h2>
<p>To use the calendar compondent add to the head of your file :</p>
<pre><code>
&lt;script src="/bower_components/platform/platform.js"&gt;&lt;/script&gt;
&lt;script src="/bower_components/webcomponentsjs/webcomponents.min.js"&gt;&lt;/script&gt;
&lt;link rel="import" href="calendar.htm"&gt;
</code></pre>
<p>To display a calendar just type in your html code :</p>
Expand Down Expand Up @@ -257,5 +257,7 @@ <h2>Styling your calendar</h2>
}
&lt;/style&gt;
</code></pre>
<h2>input date</h2>
<pre><code>&lt;zdk-input-date id="input"&gt;&lt;/zdk-input-date&gt;</code></pre>
</body>
</html>
15 changes: 15 additions & 0 deletions testcalendar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html>
<head>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-touch-fullscreen" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<script src="../webcomponentsjs/webcomponents.min.js"></script>
<link rel="import" href="zdk-input-date.html">
<style>
</style>
</head>
<body>
<label>Date : </label><zdk-input-date autoCollapse="true" currentDateAuto="true" inputDisabled="true" style="width:200px"></zdk-input-date>
</body>
6 changes: 6 additions & 0 deletions zdk-calendar.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
height:300px;
font-family:Verdana, Helvetica;
font-size:14px;
background:white;
}

* { box-sizing: border-box;}
Expand Down Expand Up @@ -80,3 +81,8 @@ div.head: {
div.disable {
background: lightgray;
}

div.selected {
background: dodgerBlue;
font-weight:bold;
}
31 changes: 30 additions & 1 deletion zdk-calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<link rel="import" href="custom-icons.html">
<script src="../momentjs/min/moment-with-locales.min.js"></script>

<polymer-element name="zdk-calendar" attributes="date start stop i18n">
<polymer-element name="zdk-calendar" attributes="date start stop i18n selected">
<template>
<link rel="stylesheet" href="zdk-calendar.css">
<div id="calendar">
Expand All @@ -21,8 +21,11 @@
i18n: null,
start:null,
stop:null,
selected:null,
select:null,
ready: function() {
this.i18n = this.i18n?this.i18n:navigator.language || navigator.userLanguage;
moment.locale(this.i18n)
this.day = (typeof this.date === "string")?moment(this.date):moment();
if(this.start) { this.start = moment(this.start).format("X"); }
if(this.stop) { this.stop = moment(this.stop).format("X"); }
Expand Down Expand Up @@ -80,6 +83,10 @@
div.classList.add("disable");
}

if( this.selected === fday.format("X")) {
div.classList.add("selected");
}

div.addEventListener("click",function(evt){ that.dateClick(evt, this.getAttribute("data-date")) },false);

weekdiv.appendChild(div);
Expand Down Expand Up @@ -124,6 +131,10 @@
day.classList.add("disable");
}

if( that.select && that.select === fday.format("X")) {
day.classList.add("selected");
}

day.setAttribute("data-date",fday.format("YYYY-MM-DD"));
fday.add(1,'d');
});
Expand Down Expand Up @@ -172,6 +183,24 @@
}
this.update();
},
selectedChanged: function( oldValue, newValue ) {
moment.locale(this.i18n);
if( oldValue === newValue) {
return;
}
var select = this.$.calendar.querySelector(".selected");
if( select ) {
select.classList.remove("selected");
}
if(newValue) {
this.select = moment(newValue,moment.localeData().longDateFormat("L")).format("X");
if(isNaN(this.select)) { this.select = null; }
} else {
this.select = null;
this.selected = null;
}
this.update();
},
prevMonth: function() {
// event.preventDefault();
this.day.add(-1,'M');
Expand Down
83 changes: 83 additions & 0 deletions zdk-input-date.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
:host {
display:inline-block;
align-self: baseline;
}
.input {
display:-ms-flexbox;
display:-webkit-flex;
display:flex;
}
input {
height:30px;
padding:0px;
margin: 0px;
border:1px solid lightgray;
/* Pour iOS*/
-webkit-appearance: none;
-webkit-border-radius:0;
box-sizing: border-box;
font-size: 0.8em;
padding-left: 5px;
outline:none;
}
button {
width:30px;
height:30px;
padding: 0px;
margin: 0px;
border:2px;
background-color:lightgray;
outline: none;
}
.dropdown {
-webkit-animation: animation 1.2s;
-moz-animation: animation 1.2s;
animation: animation 1.2s
}
/* Chrome, Safari, Opera */
@-webkit-keyframes animation {
0% {opacity:0;}
100% {opacity:1:}
}
/* Firefox */
@-moz-keyframes animation {
0% {opacity:0;}
100% {opacity:1:}
}
/* IE */
@keyframes animation {
0% {opacity:0;}
100% {opacity:1:}
}
.collapse {
display:none;
}
#arrowup {
position:absolute;
margin-top: -14px;
}
#arrowup div {
position:absolute;
width: 0;
height: 0;
border-left: 15px solid transparent;
border-right: 15px solid transparent;
}
.outside {
border-bottom: 15px solid lightgray;
margin-top: 0px;
}
.inner {
border-bottom: 15px solid white;
margin-top: 1px;
}
zdk-calendar {
border: 1px solid lightgrey;
width:250px;
height:250px;
}
#divcalendar {
position:absolute;
margin-top:7px;
box-shadow: 2px 2px 20px lightgrey;
}
74 changes: 74 additions & 0 deletions zdk-input-date.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../zdk-calendar/zdk-calendar.html">

<polymer-element name="zdk-input-date" attributes="currentDateAuto autoCollapse inputDisabled i18n" onclick="">
<template>
<link rel="stylesheet" href="zdk-input-date.css">
<div class="input">
<input id="dateinput"><button id="button"></button>
</div>
<div id="divcalendar" class="collapse">
<div id="arrowup">
<div class="outside"></div>
<div class="inner"></div>
</div>
<zdk-calendar id="calendar"></zdk-calendar>
</div>
<content></content>
</template>
<script>
Polymer('zdk-input-date', {
i18n: null,
currentDateAuto: false,
autoCollapse:false,
inputDisabled : false,
domReady: function() {
this.i18n = this.i18n?this.i18n:navigator.language || navigator.userLanguage;
console.log("i18n",this.i18n);
moment.locale(this.i18n);
this.$.calendar.i18n = this.i18n;
var pos = this.$.button.offsetLeft+15;
this.$.divcalendar.style.left = (pos - 125)+"px";
this.$.arrowup.style.left = (pos - 125)+"px"
var that=this;
if (this.autoCollapse === true) {
this.toggleCollapse();
}
if (this.inputDisabled === true) {
this.$.dateinput.setAttribute("disabled", "");
}
this.$.button.addEventListener("click", function(e) {
that.toggleCollapse();
});
this.$.dateinput.addEventListener("click", function(e) {
that.toggleCollapse();
});
if (this.currentDateAuto === true) {
console.log("date ",this.$.calendar.day.format("L"), this.$.calendar.i18n );
this.fillInput(this.$.calendar.day.format("L"));
}
this.$.calendar.addEventListener('select', function(e) {
that.fillInput(e.detail.day);
});
},
toggleCollapse: function() {
if( this.$.dateinput.value ) {
this.$.calendar.selected = this.$.dateinput.value;
}
var cad = this.$.divcalendar;
if(cad.getAttribute("class") == "collapse") {
cad.setAttribute("class", "dropdown");
} else {
cad.setAttribute("class", "collapse");
}
},
fillInput: function(date) {
this.$.dateinput.value = date;
this.toggleCollapse();
},
getValue: function() {
return this.$.dateinput.value;
}
});
</script>
</polymer-element>

0 comments on commit 5c5ad67

Please sign in to comment.