From 8bba0ba8e87e9a4addacccc6bbb48e7edcfe933f Mon Sep 17 00:00:00 2001 From: Stephane Balasse Date: Fri, 7 Apr 2017 08:51:05 +0200 Subject: [PATCH 1/5] Added 24-hour selection and display management --- demo/index.html | 2 +- paper-clock-selector.html | 835 ++++++++++++++++------------- paper-time-picker.html | 1059 +++++++++++++++++++------------------ 3 files changed, 1017 insertions(+), 879 deletions(-) diff --git a/demo/index.html b/demo/index.html index 9254a51..212df35 100644 --- a/demo/index.html +++ b/demo/index.html @@ -26,7 +26,7 @@

{{time}}

Change Time - +
CANCEL OK diff --git a/paper-clock-selector.html b/paper-clock-selector.html index 51a4a2a..c848c49 100644 --- a/paper-clock-selector.html +++ b/paper-clock-selector.html @@ -11,7 +11,7 @@ + From c323ab85ad1287fd15466e7f6d1b734ec9acb480 Mon Sep 17 00:00:00 2001 From: Stephane Balasse Date: Mon, 10 Apr 2017 14:59:56 +0200 Subject: [PATCH 2/5] Supports the display of a dial for 24-hour management (without AM and PM) --- paper-time-picker.html | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/paper-time-picker.html b/paper-time-picker.html index 70eeeac..da2e4fa 100644 --- a/paper-time-picker.html +++ b/paper-time-picker.html @@ -200,7 +200,7 @@
-
{{hour12}}
+
{{hour}}
:
{{_zeroPad(minute, 2)}}
+ -
AM
-
PM
+
@@ -219,8 +222,8 @@ selected="{{view}}" entry-animation="fade-in-animation" exit-animation="fade-out-animation"> - + Date: Mon, 10 Apr 2017 15:08:53 +0200 Subject: [PATCH 3/5] Supports the display of a dial for 24-hour management (without AM and PM) --- demo/index.html | 4 +-- paper-clock-selector.html | 57 ++++++++++++++++++++++++++++++--------- paper-time-picker.html | 3 +++ 3 files changed, 50 insertions(+), 14 deletions(-) diff --git a/demo/index.html b/demo/index.html index 212df35..b749518 100644 --- a/demo/index.html +++ b/demo/index.html @@ -26,7 +26,7 @@

{{time}}

Change Time - +
CANCEL OK @@ -48,7 +48,7 @@

{{time}}

this.$.dialog.toggle(); }; document.addEventListener('WebComponentsReady', function() { - scope.time = '3:30 PM'; + scope.time = '15:30'; scope.showDialog(); }); })(); diff --git a/paper-clock-selector.html b/paper-clock-selector.html index c848c49..d9ba325 100644 --- a/paper-clock-selector.html +++ b/paper-clock-selector.html @@ -213,6 +213,7 @@ this._populate(); this._selectedChanged(this.selected); }, + setClockHand: function (deg, animate, callback) { deg = normalizeAngle(deg); @@ -251,15 +252,19 @@ }); }, + _getTransform: function (el) { return el.style.transform | el.style.webkitTransform | el.style.msTransform; }, + _setTransform: function (el, value) { el.style.msTransform = el.style.webkitTransform = el.style.transform = value; }, + _setTransformOrigin: function (el, value) { el.style.msTransformOrigin = el.style.webkitTransformOrigin = el.style.transformOrigin = value; }, + _setHandRotation: function (deg) { var hasLabel = ((deg / 360) * this.count) % this.step === 0; var transform = 'rotate(' + deg + 'deg)'; @@ -267,6 +272,7 @@ this._setTransform(this.$.clockHand, transform); this._setTransform(this.$.clipCircle, transform); }, + _selectedChanged: function (selected) { if (!this.count || isNaN(selected)) { return; @@ -282,16 +288,17 @@ value = this.count; } if (value !== this.selected && value !== 0) { - this.selected = value; + this.set('selected', value); return; } if (value === 0 && this.twentyFourHours) { - this.selected = 0; + this.set('selected', 0); return; } this._vibrate(); this.setClockHand((360 / this.count) * this.selected); }, + _stepChanged: function (value, oldValue) { this._step = oldValue; if (!this.count || isNaN(value)) { @@ -303,6 +310,7 @@ } this._step = value; }, + _populate: function () { delete this._resizedCache; var display, value, number; @@ -350,7 +358,7 @@ if (this.count === 12 && this.twentyFourHours) { number24 = { index: i, - value: value + 12, + value: value+12, display: value % this._step === 0, x: 0, y: 0, @@ -366,6 +374,7 @@ this.set('_numbers24', numbers24); this._positionClockPoints(); }, + _updateNumber: function (number) { var dom = number.dom; if (!dom) { @@ -380,6 +389,7 @@ dom.textClipped.textContent = this._formatNumber(number.value); } }, + _createNumberElement: function (number) { // We can't use templates inside SVG elements, so we have to create // the numbers in dom and set up attribute bindings manually @@ -419,6 +429,7 @@ return {g: g, text: text, textClipped: textClipped}; }, + _updateSize: function () { var radius = Math.min(this.offsetWidth, this.offsetHeight) / 2; if (!radius || this._resizedCache === radius) { @@ -443,6 +454,7 @@ this._bounds = this.$.face.getBoundingClientRect(); }.bind(this), 150); }, + _positionClockPoints: function () { if (!this._radius) { return; @@ -466,8 +478,7 @@ number.y = this._radius - (Math.cos(a) * selectorCenter); this._updateNumber(number); } - this._handX = this._numbers[0].x; - this._handY = this._numbers[0].y; + if (this.twentyFourHours) { //gestion des 24 heures; @@ -476,13 +487,22 @@ for (var i = 0; i < this.count; i++) { a = angle * i; number = numbers24[i]; - number.x = this._radius + (Math.sin(a) * 68); - number.y = this._radius - (Math.cos(a) * 68); + number.x = this._radius + (Math.sin(a) * (selectorCenter - 40)); + number.y = this._radius - (Math.cos(a) * (selectorCenter - 40)); this._updateNumber(number); } } + if(this.twentyFourHours && this.selected > 12){ + this._handX = this._numbers24[0].x; + this._handY = this._numbers24[0].y; + }else{ + this._handX = this._numbers[0].x; + this._handY = this._numbers[0].y; + } + }, + _notifyNumberChanged: function (path) { var propPath, props = ['x', 'y']; for (var i = 0; i < props.length; i++) { @@ -492,6 +512,7 @@ } } }, + _getSelectArea: function (radius, outer, inner) { return '\n' + 'M ' + (radius - outer) + ' ' + radius + '\n' + @@ -501,6 +522,7 @@ 'A ' + inner + ' ' + inner + ' 0 0 1 ' + (radius + inner) + ' ' + radius + '\n' + 'A ' + inner + ' ' + inner + ' 0 0 1 ' + (radius - inner) + ' ' + radius; }, + _onTouch: function (event) { var x = event.detail.x - this._bounds.left - this._radius; var y = event.detail.y - this._bounds.top - this._radius; @@ -523,21 +545,27 @@ theta = (Math.PI / 2) + (x < 0 ? theta + Math.PI : theta); var intervalRad = (360 / this.count) * (Math.PI / 180); - // determine the selected number - this.selected = Math.round(theta / intervalRad); - this._handX = this._numbers[0].x; - this._handY = this._numbers[0].y; + var selected = Math.round(theta / intervalRad) ; + // determine the selected number if (distance < 88) { - this.selected = this.selected === 0 ? this.selected : this.selected + 12; + selected = selected === 0 ? 24 : Math.round(theta / intervalRad) + 12; this._handX = this._numbers24[0].x; this._handY = this._numbers24[0].y; + }else { + selected = Math.round(theta / intervalRad); + this._handX = this._numbers[0].x; + this._handY = this._numbers[0].y; } + + this.selected = selected; + /* only fire selected when we've tapped or stopped tracking */ if (event.type === 'tap' || event.detail.state === 'end') { this.fire('paper-clock-selected', {value: this.selected, animated: this.animated}); } }, + _formatNumber: function (value) { if (this.zeroPad) { return ('0' + value).substr(-2); @@ -547,6 +575,7 @@ } return value.toString(); }, + _getNumberClass: function (pfx, n, selected) { var cssClass = pfx; if (selected.value === n.value) { @@ -554,6 +583,7 @@ } return cssClass; }, + _vibrate: function () { this.debounce('vibrate', function () { if (navigator.vibrate) { @@ -561,11 +591,13 @@ } }); }, + _zeroPadChanged: function () { this._numbers.forEach(function (number) { this._updateNumber(number); }.bind(this)); }, + _once: function (eventName, callback, node) { node = node || this; function onceCallback() { @@ -575,6 +607,7 @@ node.addEventListener(eventName, onceCallback); } + }); })(); diff --git a/paper-time-picker.html b/paper-time-picker.html index da2e4fa..f77c18b 100644 --- a/paper-time-picker.html +++ b/paper-time-picker.html @@ -253,6 +253,9 @@ Polymer({ is: 'paper-time-picker', properties: { + /** + * If True, Supports the display of a dial for the management of the 24h (without AM and PM) + */ isTwentyFourHours: { type: Boolean, value: false, From a78a194967daf577d2204fd315122b1580f737b7 Mon Sep 17 00:00:00 2001 From: Stephane Balasse Date: Mon, 10 Apr 2017 17:02:47 +0200 Subject: [PATCH 4/5] Supports the display of a dial for 24-hour management (without AM and PM) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 455c659..6bf55e2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "paper-time-picker", - "version": "1.1.4", + "version": "1.1.5", "description": "Provides a responsive time picker based on the material design spec", "main": "index.html", "devDependencies": { From fac34c7f2b0b1e2043de4cae92a3ea67883da23a Mon Sep 17 00:00:00 2001 From: Stephane Balasse Date: Thu, 13 Apr 2017 10:57:43 +0200 Subject: [PATCH 5/5] first commit --- .gitignore | 5 + .idea/inspectionProfiles/Project_Default.xml | 6 + .idea/modules.xml | 8 + .idea/paper-time-picker.iml | 12 + .idea/vcs.xml | 6 + .idea/workspace.xml | 362 +++++++++++ .jshintrc | 25 + LICENSE | 20 + README.md | 56 ++ bower.json | 42 ++ classlist-shim.html | 1 + demo/index.html | 57 ++ index.html | 18 + package.json | 43 ++ paper-clock-selector.html | 581 ++++++++++++++++++ paper-time-picker-dialog-style.html | 41 ++ paper-time-picker.html | 601 +++++++++++++++++++ 17 files changed, 1884 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/paper-time-picker.iml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 .jshintrc create mode 100644 LICENSE create mode 100644 README.md create mode 100644 bower.json create mode 100644 classlist-shim.html create mode 100644 demo/index.html create mode 100644 index.html create mode 100644 package.json create mode 100644 paper-clock-selector.html create mode 100644 paper-time-picker-dialog-style.html create mode 100644 paper-time-picker.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f5d893 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.bowerrc +bower_components +components +node_modules +gulpfile.js diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..eff7139 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..5e2a5f3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/paper-time-picker.iml b/.idea/paper-time-picker.iml new file mode 100644 index 0000000..24643cc --- /dev/null +++ b/.idea/paper-time-picker.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..69f6e78 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,362 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + this.lang + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + project + + + true + + + + DIRECTORY + + false + + + + + + + + + 1491468202991 + + + 1491547865201 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..2de42eb --- /dev/null +++ b/.jshintrc @@ -0,0 +1,25 @@ +{ + "node": true, + "browser": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "noarg": true, + "quotmark": "single", + "undef": true, + "unused": true, + "globals": { + "wrap": true, + "unwrap": true, + "Polymer": true, + "Platform": true, + "HTMLImports": true, + "moment": true + } +} + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..99d4ebe --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2015 Ben Davis + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6fd4572 --- /dev/null +++ b/README.md @@ -0,0 +1,56 @@ +paper-time-picker +========== +Material Design time picker, compatible with *Polymer 1.0* + +Provides a responsive time picker based on the material design spec. This +component aims to be a clone of the time picker introduced in Android Lollipop. + +![wide picker screenshot][wide] ![narrow picker screenshot][narrow] + +See the [component page](http://bendavis78.github.io/paper-time-picker/) for +full documentation. + +## Examples: + +Default picker: + +```html + +``` + +Setting the initial time to 4:20pm (note that hours given as 24-hour): + +```html + +``` + +If you include this element as part of `paper-dialog`, use the class +`"paper-time-picker-dialog"` on the dialog in order to give it proper styling. + +```html + + +
+ Cancel + OK +
+
+``` + +# Reporting Bugs + +When filing a bug report, please provide an example of how to repoduce using +plunker, jsbin, jsfiddle, etc. You can use the following plunker as a starting +point: http://plnkr.co/edit/gVQluG0GrFP3RzCPZPIi + +--- + +If you find this component useful, please show your support by donating to +[Bold Idea](http://boldidea.org). Click the button below! + +[![ideaSpark campaign button][donate]](https://donorbox.org/bold-idea-make-ideaspark-possible-for-dallas-area-students) + +[wide]: http://i.imgur.com/kosRJrF.png +[narrow]: http://i.imgur.com/s3honuG.png +[donate]: http://www.boldidea.org/donate-badge-md-1.png diff --git a/bower.json b/bower.json new file mode 100644 index 0000000..fe7f243 --- /dev/null +++ b/bower.json @@ -0,0 +1,42 @@ +{ + "name": "paper-time-picker", + "version": "1.1.4", + "authors": [ + "Ben Davis " + ], + "description": "Provides a responsive time picker based on the material design spec", + "keywords": [ + "web-component", + "web-components", + "polymer", + "timepicker", + "paper-time-picker" + ], + "main": "paper-time-picker.html", + "license": "MIT", + "homepage": "http://bendavis78.github.io/paper-time-picker/", + "ignore": [ + "/.*", + "/tests/" + ], + "dependencies": { + "polymer": "Polymer/polymer#^1.1.0", + "iron-media-query": "PolymerElements/iron-media-query#^1.0.0", + "iron-selector": "PolymerElements/iron-selector#^1.0.0", + "neon-animation": "PolymerElements/neon-animation#^1.0.0", + "iron-resizable": "PolymerElements/iron-resizable-behavior#^1.0.0", + "iron-flex-layout": "PolymerElements/iron-flex-layout#^1.0.0", + "paper-styles": "PolymerElements/paper-styles#^1.0.0", + "iron-pages": "PolymerElements/iron-pages#^1.0.0", + "classList.js": "https://github.com/eligrey/classList.js.git#~1.1.20150312" + }, + "devDependencies": { + "iron-component-page": "PolymerElements/iron-component-page#^1.0.0", + "paper-dialog": "PolymerElements/paper-dialog#^1.0.0", + "paper-button": "PolymerElements/paper-button#^1.0.0", + "webcomponentsjs": "webcomponents/webcomponentsjs#^0.7.0" + }, + "resolutions": { + "webcomponentsjs": "^0.7.2" + } +} diff --git a/classlist-shim.html b/classlist-shim.html new file mode 100644 index 0000000..52a3c1c --- /dev/null +++ b/classlist-shim.html @@ -0,0 +1 @@ + diff --git a/demo/index.html b/demo/index.html new file mode 100644 index 0000000..212df35 --- /dev/null +++ b/demo/index.html @@ -0,0 +1,57 @@ + + + + + + + + paper-time-picker Demo + + + + + + + + + + + + + + + diff --git a/index.html b/index.html new file mode 100644 index 0000000..42fc3b7 --- /dev/null +++ b/index.html @@ -0,0 +1,18 @@ + + + + + + + + paper-time-picker + + + + + + + + + + diff --git a/package.json b/package.json new file mode 100644 index 0000000..455c659 --- /dev/null +++ b/package.json @@ -0,0 +1,43 @@ +{ + "name": "paper-time-picker", + "version": "1.1.4", + "description": "Provides a responsive time picker based on the material design spec", + "main": "index.html", + "devDependencies": { + "browser-sync": "^2.8.0", + "del": "^1.2.0", + "gulp": "^3.9.0", + "gulp-add": "0.0.2", + "gulp-bower": "0.0.10", + "gulp-bump": "^0.3.1", + "gulp-copy": "0.0.2", + "gulp-filter": "^2.0.2", + "gulp-gh-pages": "^0.5.2", + "gulp-git": "^1.2.4", + "gulp-tag-version": "^1.3.0", + "merge-stream": "^0.1.8", + "portfinder": "^0.4.0", + "vinyl-paths": "^1.0.0", + "web-component-tester": "^3.3.3" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/bendavis78/paper-time-picker.git" + }, + "keywords": [ + "web-component", + "webcomponents", + "polymer", + "timepicker", + "paper-time-picker" + ], + "author": "Ben Davis ", + "license": "MIT", + "bugs": { + "url": "https://github.com/bendavis78/paper-time-picker/issues" + }, + "homepage": "https://github.com/bendavis78/paper-time-picker#readme" +} diff --git a/paper-clock-selector.html b/paper-clock-selector.html new file mode 100644 index 0000000..c848c49 --- /dev/null +++ b/paper-clock-selector.html @@ -0,0 +1,581 @@ + + + + + + + + + + diff --git a/paper-time-picker-dialog-style.html b/paper-time-picker-dialog-style.html new file mode 100644 index 0000000..b104e0d --- /dev/null +++ b/paper-time-picker-dialog-style.html @@ -0,0 +1,41 @@ + + + + + diff --git a/paper-time-picker.html b/paper-time-picker.html new file mode 100644 index 0000000..70eeeac --- /dev/null +++ b/paper-time-picker.html @@ -0,0 +1,601 @@ + + + + + + + + + + + + + + + + + + + + +