You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Installing.md 6.2 KiB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. # Minimal Requirements
  2. 1. jQuery
  3. 2. Moment.js
  4. 3. Bootstrap.js (transition and collapse are required if you're not using the full Bootstrap)
  5. 4. Bootstrap Datepicker script
  6. 5. Bootstrap CSS
  7. 6. Bootstrap Datepicker CSS
  8. 7. Locales: Moment's locale files are [here](https://github.com/moment/moment/tree/master/locale)
  9. # Installation Guides
  10. * [Bower](#bower-)
  11. * [Nuget](#nuget)
  12. * [Rails](#rails-)
  13. * [Angular](#angular-wrapper)
  14. * [Meteor.js](#meteorjs)
  15. * [Manual](#manual)
  16. ## [bower](http://bower.io) ![Bower version](https://badge.fury.io/bo/eonasdan-bootstrap-datetimepicker.png)
  17. Run the following command:
  18. ```
  19. bower install eonasdan-bootstrap-datetimepicker#latest --save
  20. ```
  21. Include necessary scripts and styles:
  22. ```html
  23. <head>
  24. <!-- ... -->
  25. <script type="text/javascript" src="/bower_components/jquery/jquery.min.js"></script>
  26. <script type="text/javascript" src="/bower_components/moment/min/moment.min.js"></script>
  27. <script type="text/javascript" src="/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
  28. <script type="text/javascript" src="/bower_components/eonasdan-bootstrap-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
  29. <link rel="stylesheet" href="/bower_components/bootstrap/dist/css/bootstrap.min.css" />
  30. <link rel="stylesheet" href="/bower_components/eonasdan-bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css" />
  31. </head>
  32. ```
  33. ## Nuget
  34. ### [LESS](https://www.nuget.org/packages/Bootstrap.v3.Datetimepicker/): ![NuGet version](https://badge.fury.io/nu/Bootstrap.v3.Datetimepicker.png)
  35. ```
  36. PM> Install-Package Bootstrap.v3.Datetimepicker
  37. ```
  38. ### [CSS](https://www.nuget.org/packages/Bootstrap.v3.Datetimepicker.CSS/): ![NuGet version](https://badge.fury.io/nu/Bootstrap.v3.Datetimepicker.CSS.png)
  39. ```
  40. PM> Install-Package Bootstrap.v3.Datetimepicker.CSS
  41. ```
  42. ```html
  43. <head>
  44. <script type="text/javascript" src="/scripts/jquery.min.js"></script>
  45. <script type="text/javascript" src="/scripts/moment.min.js"></script>
  46. <script type="text/javascript" src="/scripts/bootstrap.min.js"></script>
  47. <script type="text/javascript" src="/scripts/bootstrap-datetimepicker.*js"></script>
  48. <!-- include your less or built css files -->
  49. <!--
  50. bootstrap-datetimepicker-build.less will pull in "../bootstrap/variables.less" and "bootstrap-datetimepicker.less";
  51. or
  52. <link rel="stylesheet" href="/Content/bootstrap-datetimepicker.css" />
  53. -->
  54. </head>
  55. ```
  56. ## [Rails](http://rubygems.org/gems/bootstrap3-datetimepicker-rails) ![Gem Version](https://badge.fury.io/rb/bootstrap3-datetimepicker-rails.png)
  57. Add the following to your `Gemfile`:
  58. ```ruby
  59. gem 'momentjs-rails', '>= 2.9.0'
  60. gem 'bootstrap3-datetimepicker-rails', '~> 4.14.30'
  61. ```
  62. Note: You may need to change the version number above to the version number on the badge above.
  63. Read the rest of the install instructions @
  64. [TrevorS/bootstrap3-datetimepicker-rails](https://github.com/TrevorS/bootstrap3-datetimepicker-rails)
  65. ## Angular Wrapper
  66. Follow the link [here](https://gist.github.com/eugenekgn/f00c4d764430642dca4b)
  67. ## Meteor.js
  68. This widget has been package for the [Meteor.js](http://www.meteor.com/) platform, to install it use meteorite as follows:
  69. `$ mrt add tsega:bootstrap3-datetimepicker`
  70. For more detail see the package page on [Atmosphere](http://atmospherejs.com/package/bootstrap3-datetimepicker)
  71. ## Manual
  72. ### Acquire [jQuery](http://jquery.com)
  73. ### Acquire [Moment.js](https://github.com/moment/moment)
  74. ### Bootstrap 3 collapse and transition plugins
  75. Make sure to include *.JS files for plugins [collapse](http://getbootstrap.com/javascript/#collapse) and [transitions](http://getbootstrap.com/javascript/#transitions). They are included with [bootstrap in js/ directory](https://github.com/twbs/bootstrap/tree/master/js)
  76. Alternatively you could include the whole bundle of bootstrap plugins from [bootstrap.js](https://github.com/twbs/bootstrap/tree/master/dist/js)
  77. ```html
  78. <script type="text/javascript" src="/path/to/jquery.js"></script>
  79. <script type="text/javascript" src="/path/to/moment.js"></script>
  80. <script type="text/javascript" src="/path/to/bootstrap/js/transition.js"></script>
  81. <script type="text/javascript" src="/path/to/bootstrap/js/collapse.js"></script>
  82. <script type="text/javascript" src="/path/to/bootstrap/dist/bootstrap.min.js"></script>
  83. <script type="text/javascript" src="/path/to/bootstrap-datetimepicker.min.js"></script>
  84. ```
  85. ## Knockout
  86. ```
  87. ko.bindingHandlers.dateTimePicker = {
  88. init: function (element, valueAccessor, allBindingsAccessor) {
  89. //initialize datepicker with some optional options
  90. var options = allBindingsAccessor().dateTimePickerOptions || {};
  91. $(element).datetimepicker(options);
  92. //when a user changes the date, update the view model
  93. ko.utils.registerEventHandler(element, "dp.change", function (event) {
  94. var value = valueAccessor();
  95. if (ko.isObservable(value)) {
  96. if (event.date != null && !(event.date instanceof Date)) {
  97. value(event.date.toDate());
  98. } else {
  99. value(event.date);
  100. }
  101. }
  102. });
  103. ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
  104. var picker = $(element).data("DateTimePicker");
  105. if (picker) {
  106. picker.destroy();
  107. }
  108. });
  109. },
  110. update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
  111. var picker = $(element).data("DateTimePicker");
  112. //when the view model is updated, update the widget
  113. if (picker) {
  114. var koDate = ko.utils.unwrapObservable(valueAccessor());
  115. //in case return from server datetime i am get in this form for example /Date(93989393)/ then fomat this
  116. koDate = (typeof (koDate) !== 'object') ? new Date(parseFloat(koDate.replace(/[^0-9]/g, ''))) : koDate;
  117. picker.date(koDate);
  118. }
  119. }
  120. };
  121. ```
  122. ### CSS styles
  123. #### Using LESS
  124. ```css
  125. @import "/path/to/bootstrap/less/variables";
  126. @import "/path/to/bootstrap-datetimepicker/src/less/bootstrap-datetimepicker-build.less";
  127. // [...] your custom styles and variables
  128. ```
  129. Using CSS (default color palette)
  130. ```html
  131. <link rel="stylesheet" href="/path/to/bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css" />
  132. ```