Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exactmins #7

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ gulp.task('watch', function () {
})
});

gulp.task('build', ['js', 'sass']);

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ autoclose: false, // auto close when minute is selected
ampmclickable: false, // set am/pm button on itself
darktheme: false, // set to dark theme
twelvehour: true, // change to 12 hour AM/PM clock from 24 hour
vibrate: true // vibrate the device when dragging clock hand
vibrate: true, // vibrate the device when dragging clock hand
exactmins: true // enable exact minutes, if false you can only click 5, 10, 15 etc.
```

## Screenshots:
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
Copy link

@danswater danswater Apr 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also update the entry point of main property?

  "main": [
     "./dist/js/materialize.clockpicker.js",
     "./dist/css/materialize.clockpicker.css"
   ],

this is also useful when injecting files to index.html e.g when using gulp-inject

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danswater good one, I will change that.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@victor-perez, Thanks! I am amazed that you're still online right now.

"version": "1.0.0",
"version": "1.0.1",
"name": "materialize-clockpicker",
"homepage": "https://github.com/chingyawhao/materialize-clockpicker",
"authors": [
Expand Down
2 changes: 1 addition & 1 deletion dist/js/materialize.clockpicker.js

Large diffs are not rendered by default.

26 changes: 24 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,27 @@
</div>
</div>



<div class="row">
<div class="input-field col s12">
<label for="timepicker_vibrate">Time options - vibrate: true</label>
<input id="timepicker_vibrate" class="timepicker" type="time">
</div>
</div>

<div class="row">
<div class="input-field col s12">
<label for="timepicker_exactmins">Time options - exactmins: false</label>
<input id="timepicker_exactmins" class="timepicker" type="time">
</div>
</div>

<div class="row">
<div class="input-field col s12">
<label for="timepicker_exactmins_now">Time options - exactmins: false, default: 'now'</label>
<input id="timepicker_exactmins_now" class="timepicker" type="time">
</div>
</div>

</form>
</div>
</div>
Expand Down Expand Up @@ -148,6 +160,16 @@
$('#timepicker_vibrate').pickatime({
vibrate: true
});
//exactmins
$('#timepicker_exactmins').pickatime({
exactmins: false
});
//exactmin + now
$('#timepicker_exactmins_now').pickatime({
exactmins: false,
default: 'now'
});

</script>
</body>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "materialize-clockpicker",
"version": "1.0.0",
"version": "1.0.1",
"description": "A materialize clockpicker",
"main": "js/materialize.clockpicker.js",
"repository": {
Expand Down
28 changes: 24 additions & 4 deletions src/js/materialize.clockpicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
// Clicking on minutes view space
plate.on(mousedownEvent, function(e) {
if ($(e.target).closest('.clockpicker-tick').length === 0)
mousedown(e, true);
mousedown(e, options.exactmins);
});

// Mousedown or touchstart
Expand Down Expand Up @@ -291,7 +291,7 @@
// Clicking in chrome on windows will trigger a mousemove event
return;
moved = true;
self.setHand(x, y, false, true);
self.setHand(x, y, !options.exactmins, true);
});

// Mouseup on document
Expand Down Expand Up @@ -376,9 +376,10 @@
donetext: 'Done', // done button text
autoclose: false, // auto close when minute is selected
ampmclickable: false, // set am/pm button on itself
darktheme: false, // set to dark theme
darktheme: false, // set to dark theme
twelvehour: true, // change to 12 hour AM/PM clock from 24 hour
vibrate: true // vibrate the device when dragging clock hand
vibrate: true, // vibrate the device when dragging clock hand
exactmins: true // enable exact minutes, if false you can only click 5, 10, 15 etc.
};

// Show or hide popover
Expand Down Expand Up @@ -449,6 +450,25 @@
now.getHours(),
now.getMinutes()
];
//set exact minutes
if (!this.options.exactmins && value[1] % 5) {
//go down
if (value[1] % 5 < 3) {
value[1] -= value[1] % 5;
//go up
} else {
value[1] += (5 - (value[1] % 5));
}
//next hour
if (value[1] === 60) {
value[0]++;
value[1] = 0;
}
//24 -> 0
if (value[0] === 24) {
value[0] = 0;
}
}
}
this.hours = + value[0] || 0;
this.minutes = + value[1] || 0;
Expand Down