Giter Club home page Giter Club logo

clockpicker's Introduction

ClockPicker Bower version Build Status devDependency Status

A clock-style timepicker for Bootstrap 4 (or Bootstrap 3 or jQuery).

Light documentation and examples for Bootstrap 4.

Original documentation and examples for Bootstrap 3.

Below are the screens for Bootstrap 4 and Bootstrap 4 with Daemonite material UI

Bootstrap 4 clockpicker Bootstrap 4 clockpicker

And the original screens from Weareoutman for Bootstrap 3

Screenshot clockpicker-12-hour-screenshot

Browser support

All major browsers are supported, including IE 9+. It should look and behave well enough in IE 8.

Device support

Both desktop and mobile device are supported. It also works great in touch screen device.

Dependencies

ClockPicker was designed for Bootstrap in the beginning. So Bootstrap (3 or 4 and jQuery) is the only dependency(s).

Since it only used .popover and some of .btn styles of Bootstrap, I picked these styles to build a jQuery plugin. Feel free to use jquery-* files instead of bootstrap-* , for non-bootstrap project.

Usage

<!-- Bootstrap stylesheet -->
<link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">

<!-- ClockPicker Stylesheet -->
<link rel="stylesheet" type="text/css" href="dist/bootstrap-clockpicker.min.css">

<!-- Input group, just add class 'clockpicker', and optional data-* -->
<div class="input-group clockpicker" data-placement="right" data-align="top" data-autoclose="true">
	<input type="text" class="form-control" value="09:32">
	<span class="input-group-addon">
		<span class="glyphicon glyphicon-time"></span>
	</span>
</div>

<!-- Or just a input -->
<input id="demo-input" />

<!-- jQuery and Bootstrap scripts -->
<script type="text/javascript" src="assets/js/jquery.min.js"></script>
<script type="text/javascript" src="assets/js/bootstrap.min.js"></script>

<!-- ClockPicker script -->
<script type="text/javascript" src="dist/bootstrap-clockpicker.min.js"></script>

<script type="text/javascript">
$('.clockpicker').clockpicker()
	.find('input').change(function(){
		// TODO: time changed
		console.log(this.value);
	});
$('#demo-input').clockpicker({
	autoclose: true
});

if (something) {
	// Manual operations (after clockpicker is initialized).
	$('#demo-input').clockpicker('show') // Or hide, remove ...
			.clockpicker('toggleView', 'minutes');
}
</script>

Options

Name Default Description
default '' default time, 'now' or '13:14' e.g.
placement 'bottom' popover placement
align 'left' popover arrow align
donetext 'OK' ('完成' in BS3) done button text
autoclose false auto close when minute is selected
twelvehour false enables twelve hour mode with AM & PM buttons
vibrate true vibrate the device when dragging clock hand
fromnow 0 set default time to * milliseconds from now (using with default = 'now')
init callback function triggered after the colorpicker has been initiated
beforeShow callback function triggered before popup is shown
afterShow callback function triggered after popup is shown
beforeHide callback function triggered before popup is hidden Note:will be triggered between a beforeDone and afterDone
afterHide callback function triggered after popup is hidden Note:will be triggered between a beforeDone and afterDone
beforeHourSelect callback function triggered before user makes an hour selection
afterHourSelect callback function triggered after user makes an hour selection
beforeDone callback function triggered before time is written to input
afterDone callback function triggered after time is written to input

Operations

operation Arguments Description
show show the clockpicker
hide hide the clockpicker
remove remove the clockpicker (and event listeners)
toggleView 'hours' or 'minutes' toggle to hours or minutes view

What's included

clockpicker/
├── dist/
│   ├── bootstrap-clockpicker.css      # full code for bootstrap 3
│   ├── bootstrap-clockpicker.js
│   ├── bootstrap-clockpicker.min.css  # compiled and minified files for bootstrap 3
│   ├── bootstrap-clockpicker.min.js
|   |── bootstrap4-clockpicker.css      # full code for bootstrap 4
│   ├── bootstrap4-clockpicker.js
│   ├── bootstrap4-clockpicker.min.css  # compiled and minified files for bootstrap 4
│   ├── bootstrap4-clockpicker.min.js
│   ├── jquery-clockpicker.css         # full code for jquery
│   ├── jquery-clockpicker.js
│   ├── jquery-clockpicker.min.css     # compiled and minified files for jquery
│   └── jquery-clockpicker.min.js
└── src/                               # source code
    ├── clockpicker.css
    ├── clockpicker.js
    └── standalone.css                 # some styles picked from bootstrap

Development

git clone https://github.com/weareoutman/clockpicker.git
cd clockpicker
npm install -g gulp
npm install
gulp
# gulp test

Todo

  • Auto placement and align.
  • Events.
  • Customize format.
  • Seconds View ?

Change log

0.2.3

0.2.2

  • phanku : Fixed clock picker so the clock picker will work when the trigger element is within a modal
  • SCSS source file added for easier maintenance
  • Minor CSS tweaks
  • fallback added for a Bootstrap free use (ex: background-color: var(--primary, #007bff);)

0.2.1

  • moved AM-PM buttons to the header and removed AM-PM block
  • inverted animation for top positioned picker
  • unified CSS files (compatible with BS 4.1.3, MDBootstrap 4.5.4 and Daemonite material UI)
  • need help to fix cancel button

0.2

  • migrated all classes to BS4
  • enhenced material design
  • added popover opening animation
  • added Cancel button (doesn't work right now :( )
  • prevent user-select on all elements
  • next version : move AM and PM buttons in popover-header, fix cancel button

0.1

  • Bootstrap 4 compatible (tested with BS 4.1.1)
  • Universal theming using CSS variables

0.0.7

  • Enables twelve hour mode with AM & PM buttons.

0.0.6

  • Default time can be setted to now.
  • Registered as a bower package.

0.0.5

  • Functional operations.

License

MIT

clockpicker's People

Contributors

djibe avatar ericop avatar hermanya avatar poradz avatar r3dqu33n avatar rskrzypczak avatar weareoutman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clockpicker's Issues

[Bug] bootstrap4-clockpicker.min.js minify

Your bootstrap4-clockpicker.min.js file hasn't been properly compiled in the repository
The problem is that it adds a space sometimes between the time and AM/PM
image

It works on the demo version because there is a different bootstrap4-clockpicker.min.js file there
image

Picker appears off-screen

There is a change in dist/bootstrap4-clockpicker.js around line 574 that doesn't appear in src/clockpicker.js. This change was introduced in this commit. The presence of a change in a distribution file and not in a source file is cause enough for concern, but the purpose of this issue is to report that the change introduced a bug (that it is was likely trying to fix).

The referenced change can cause the picker to display off-screen if the input triggering the picker is significantly lower in the document.

Scenario:

  • Document height: 2000px
  • Window height: 700px
  • popoverHeight height: approximately 330px
  • Input element location (top): approximately 1700
  • User scrolls down the page/document to access the input element.
  • User click the input element triggering the picker to show.

In the referenced code, the following calculation and manipulation is applied:

if (popoverHeight + styles.top > windowHeight) {
	styles.top = windowHeight - popoverHeight;
}

That results in the picker appearing somewhere around 370px from the top of the document (not the window) which results in it not appearing within view.

Presumably, a similar issue exists with the "width" check also included in that commit.

Cancel button isn't working

Cancel button isn't working at all. Same behavior in demo.

Steps to reproduce:
Initialize a clockpicker with autoclose = false;
Choose an hour.
Choose a minute.
Cancel.

Expected result:
Blank or previous value.

Actual results:
Cancelled value inserted.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.