Custom plugin to select date and time, induvidually and within a range.
Defaults
$.automileDatePicker({// @param {bool} - Show more than one(1) calendar to pick start and end date.dateRange:false,// @param {bool|Moment.js object}date:moment(),// @param {bool|Moment.js object} - Show or hide the time picker (takes a Moment.js object if `date` is false).time:false,// @param {Moment.js object}startDate:moment('00:00','H:mm'),// @param {Moment.js object}endDate:moment('23:59','H:mm'),// @param {Moment.js object}minDate:null,// @param {Moment.js object}maxDate:null,// @param {number}firstDayOfWeek:moment.localeData().firstDayOfWeek(),// @param {number} - Number of calendars to show (when `dateRange` is true).calendars:2,// @param {object} - Object with preset date ranges.ranges:null,// @param {function} - Runs when plugin initialize.// @return {Moment.js object|object} - When `dateRange` is true, `date` is an object with `startDate` and `endDate`.onInit:function(date){},// @param {function} - Runs when plugin data changes.// @return {Moment.js object|object} - When `dateRange` is true, `date` is an object with `startDate` and `endDate`.onChange:function(date){},// @param {object} - String localization.resources:{dateRange:'Date Range',endTime:'Choose End Time',startTime:'Choose Start Time',time:'Choose Time'}});
Basic examples
Example 1 (Date)
Example 2 (Date/Time)
Example 3 (Time)
<divclass="row row--space-between"><divclass="push--right"><divclass="label">Example 1 (Date)</div><hr><divclass="date-picker-example"></div><hr><divclass="date-picker-example-output"></div></div><divclass="push--right"><divclass="label">Example 2 (Date/Time)</div><hr><divclass="date-picker-example-with-time"></div><hr><divclass="date-picker-example-with-time-output"></div></div><div><divclass="label">Example 3 (Time)</div><hr><divclass="date-picker-example-no-date"></div><hr><divclass="date-picker-example-no-date-output"></div></div></div><script>(function($){// Example 1var$out1=$('.date-picker-example-output');$('.date-picker-example').automileDatePicker({onInit:function(date){$out1.text(moment(date).format('LL'));},onChange:function(date){$out1.text(moment(date).format('LL'));}});// Example 2var$out2=$('.date-picker-example-with-time-output');$('.date-picker-example-with-time').automileDatePicker({time:true,onInit:function(date){$out2.text(moment(date).format('LLLL'))},onChange:function(date){$out2.text(moment(date).format('LLLL'))}});// Example 3var$out3=$('.date-picker-example-no-date-output');$('.date-picker-example-no-date').automileDatePicker({date:false,time:moment(),onInit:function(date){$out3.text(moment(date).format('LT'))},onChange:function(date){$out3.text(moment(date).format('LT'))}});})(jQuery);</script>
Advanced example
Following example has it all. Date range, time range and predefined date range options, here combined with the Dropdown plugin.
<buttonclass="button button--ghost date-picker-advanced-example"><spanclass="from">/*insert start date from model here*/</span>–<spanclass="to">/*insert end date from model here*/</span><svgclass="shape push-half--left"aria-hidden="true"><usexlink:href="#shape-caret-down"></use></svg></button><script>(function($){// Grab the click targetvar$target=$('.date-picker-advanced-example');// Since this is a `button` element, we probarbly don't want the// default behaviour triggering, submitting a surrounding form for example.$target.on('click',function(e){e.preventDefault();});// Set up the drop instancevardatePicker=newDrop({target:$target[0],content:'',position:'bottom left',openOn:'click'});// When the drop opens, grab the context and initialize our// datepicker plugin there.datePicker.on('open',function(){var$container=$(this.drop).find('.drop-content');$container.addClass('hard--ends hard--right').automileDatePicker({dateRange:true,time:true,startDate:moment('00:00','H:mm').subtract(3,'days'),endDate:moment('23:59','H:mm'),maxDate:moment(),ranges:{'Today':{startDate:functionstartDate(now){returnnow;},endDate:functionendDate(now){returnnow;}},'Yesterday':{startDate:functionstartDate(now){returnnow.add(-1,'days');},endDate:functionendDate(now){returnnow.add(-1,'days');}},'Last 7 Days':{startDate:functionstartDate(now){returnnow.add(-7,'days');},endDate:functionendDate(now){returnnow;}},'Last 30 Days':{startDate:functionstartDate(now){returnnow.add(-30,'days');},endDate:functionendDate(now){returnnow;}}},onChange:function(date){// Update the button text to the selected date and time values$target.find('.from').text(moment(date.startDate).format('L LT'));$target.find('.to').text(moment(date.endDate).format('L LT'));}});});})(jQuery);</script>
<divclass="drop"><aclass="button button--hollow dropdown-example">Click me</a></div><script>(function(){'use strict';vardrop=newDrop({target:document.querySelector('.dropdown-example'),content:'Hello from the the Upside Down',openOn:'click'// could also be 'hover' or 'always'});})();</script>
Custom plugin to replace native browser <select> inputs. Comes with two different styling options, and multiple select support. Select uses a prositioning library called Tether under the hood.
Defaults
$.automileSelect({// @param {bool} - Show chrome around select box.chrome:true,// @param {bool} - Make select will 100% with of its parent.fullWidth:true,// @param {bool} - Show filter input.search:false,// @param {bool} - Show `Select All` option (only viable when `multiple` is true).selectAll:false,// @param {bool} - If the options should be sorted alphabetically or not.sort:false,// @param {object} - i18n strings.resources:{allSelected:'All Selected',nothingMatchedSearch:'Nothing matched your search terms.',nrOfSelected:'{0} of {1} selected',placeholder:'Select...',selectAll:'Select All'}});
Interior bundles, and provide custom styling, a third-party library called DataTables.
Table Heading 1
Table Heading 2
Table Heading 3
Cell 1
Cell 2
Cell 3
Cell 6
Cell 5
Cell 4
Cell 12
Cell 24
Cell 36
Cell 91
Cell 62
Cell 43
<tableclass="table datatables-example"><thead><tr><th>Table Heading 1</th><th>Table Heading 2</th><th>Table Heading 3</th></tr></thead><tbody><tr><td>Cell 1</td><td>Cell 2</td><td>Cell 3</td></tr><tr><td>Cell 6</td><td>Cell 5</td><td>Cell 4</td></tr><tr><td>Cell 12</td><td>Cell 24</td><td>Cell 36</td></tr><tr><td>Cell 91</td><td>Cell 62</td><td>Cell 43</td></tr></tbody></table><script>(function($){'use strict';/**
* 1. Remove the "Show X entries" dropdown
* 2. Speed up rendering by not having Datatables autoresize cols
* 3. Change how many rows is showing before it paginates (default: 10)
* 4. Define what parts of Datatables to render
*/$('.datatables-example').DataTable({'lengthChange':false,/* 1 */'autoWidth':false,/* 2 */'iDisplayLength':30,/* 3 */'sDom':'lrtip'/* 4 */});})(jQuery);</script>
Interior bundles, a third-party library called Vex for modals. You can also use these modals to replace native browser alert, confirm etc.
Alert
<buttonclass="button button--hollow"id="modal-alert-example">Open an alert</button><script>(function($){'use strict';$('#modal-alert-example').on('click',function(){vex.dialog.alert('This is going to be awesome.');});})(jQuery);</script>
Confirm
Callback value:Null
<buttonclass="button button--hollow"id="modal-confirm-example">Open a confirm</button><divclass="box box--small box--warning push-half--top"><strong>Callback value:</strong><span>Null</span></div><script>(function($){'use strict';var$confirm=$('#modal-confirm-example'),$answer=$confirm.next().find('span');$confirm.on('click',function(){vex.dialog.confirm({message:'Are you absolutely sure you want to destroy the alien planet?',callback:function(value){$answer.html(value?'Successfully destroyed the planet.':'Chicken.');}});});})(jQuery);</script>
Prompt
Let’s change the button labels as well.
Callback value:Null
<buttonclass="button button--hollow"id="modal-prompt-example">Open a prompt</button><divclass="box box--small box--warning push-half--top"><strong>Callback value:</strong><span>Null</span></div><script>(function($){'use strict';var$prompt=$('#modal-prompt-example');var$promptAnswer=$prompt.next().find('span');$prompt.on('click',function(){vex.dialog.prompt({message:'What planet did the aliens come from?',placeholder:'Planet name',buttons:[$.extend({},vex.dialog.buttons.YES,{text:'I guess?'}),$.extend({},vex.dialog.buttons.NO,{text:'I don\'t know'})],callback:function(value){if(value===false){return$promptAnswer.text('Cancelled');}$promptAnswer.text(!value.length?'No answer':value);}});});})(jQuery);</script>
Open
With vex.open you can do what ever you’d like in your modal. Here’s an example that adds a class that removes the buttons.
This Is a Headline
Lorem ipsum dolor sit amet.
<buttonclass="button button--hollow"id="modal-open-example">Open</button><divid="modal-open-example-content"style="display: none;"><h1class="h3">This Is a Headline</h1><p>Lorem ipsum dolor sit amet.</p></div><script>(function($){'use strict';$('#modal-open-example').on('click',function(){vex.dialog.open({message:$('#modal-open-example-content').html(),className:'vex-no-buttons'});});})(jQuery);</script>