index.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <link rel="apple-touch-icon" sizes="57x57" href="/apple-touch-icon-57x57.png">
  8. <link rel="apple-touch-icon" sizes="114x114" href="/apple-touch-icon-114x114.png">
  9. <link rel="apple-touch-icon" sizes="72x72" href="/apple-touch-icon-72x72.png">
  10. <link rel="apple-touch-icon" sizes="144x144" href="/apple-touch-icon-144x144.png">
  11. <link rel="apple-touch-icon" sizes="60x60" href="/apple-touch-icon-60x60.png">
  12. <link rel="apple-touch-icon" sizes="120x120" href="/apple-touch-icon-120x120.png">
  13. <link rel="apple-touch-icon" sizes="76x76" href="/apple-touch-icon-76x76.png">
  14. <link rel="apple-touch-icon" sizes="152x152" href="/apple-touch-icon-152x152.png">
  15. <link rel="icon" type="image/png" href="/favicon-196x196.png" sizes="196x196">
  16. <link rel="icon" type="image/png" href="/favicon-160x160.png" sizes="160x160">
  17. <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
  18. <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
  19. <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
  20. <meta name="msapplication-TileColor" content="#2b5797">
  21. <meta name="msapplication-TileImage" content="/mstile-144x144.png">
  22. <title></title>
  23. <link rel="stylesheet" type="text/css" media="screen"
  24. href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"/>
  25. <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  26. <link href="../css/prettify-1.0.css" rel="stylesheet">
  27. <link href="../css/base.css" rel="stylesheet">
  28. <link href="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/build/css/bootstrap-datetimepicker.css" rel="stylesheet">
  29. <script type="text/javascript" src="//code.jquery.com/jquery-2.1.1.min.js"></script>
  30. <script type="text/javascript" src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
  31. <script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment-with-locales.js"></script>
  32. <script src="//cdn.rawgit.com/Eonasdan/bootstrap-datetimepicker/e8bddc60e73c1ec2475f827be36e1957af72e2ea/src/js/bootstrap-datetimepicker.js"></script>
  33. </head>
  34. <body>
  35. <div class="navbar navbar-default navbar-fixed-top" role="navigation">
  36. <div class="container">
  37. <!-- Collapsed navigation -->
  38. <div class="navbar-header">
  39. <!-- Expander button -->
  40. <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
  41. <span class="sr-only">Toggle navigation</span>
  42. <span class="icon-bar"></span>
  43. <span class="icon-bar"></span>
  44. <span class="icon-bar"></span>
  45. </button>
  46. <!-- Main title -->
  47. <a class="navbar-brand" href=""></a>
  48. </div>
  49. <!-- Expanded navigation -->
  50. <div class="navbar-collapse collapse">
  51. <!-- Main navigation -->
  52. <ul class="nav navbar-nav">
  53. <li >
  54. <a href="..">Usage</a>
  55. </li>
  56. <li >
  57. <a href="../Installing/">Installing</a>
  58. </li>
  59. <li >
  60. <a href="../Functions/">Functions</a>
  61. </li>
  62. <li >
  63. <a href="../Options/">Options</a>
  64. </li>
  65. <li >
  66. <a href="../Events/">Events</a>
  67. </li>
  68. <li >
  69. <a href="../Changelog.md">Change Log</a>
  70. </li>
  71. <li >
  72. <a href="../ContributorsGuide/">Dev Guide</a>
  73. </li>
  74. <li class="active">
  75. <a href="./">Extras</a>
  76. </li>
  77. <li >
  78. <a href="../FAQ/">FAQs</a>
  79. </li>
  80. </ul>
  81. <!-- Search, Navigation and Repo links -->
  82. <ul class="nav navbar-nav navbar-right">
  83. </ul>
  84. </div>
  85. </div>
  86. </div>
  87. <div class="container">
  88. <div class="row">
  89. <div class="col-md-3"><script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?serve=CK7DC5QN&placement=eonasdangithubio" id="_carbonads_js"></script>
  90. <div class="bs-sidebar hidden-print affix well" role="complementary"> <ul class="nav bs-sidenav">
  91. <li class="main active"><a href="#extras">Extras</a></li>
  92. <li><a href="#rails-3">Rails 3</a></li>
  93. <li><a href="#ie-7">IE 7</a></li>
  94. </ul>
  95. </div></div>
  96. <div class="col-md-8" role="main">
  97. <div class="alert alert-danger" style="font-size:1.5em;">
  98. <strong>Important!</strong>
  99. Please read this <a href="https://eonasdan.com/posts/state-of-my-picker" target="_blank">blog post</a>
  100. </div>
  101. <h1 id="extras">Extras</h1>
  102. <p>Guides for making the picker work better with rails, IE, etc</p>
  103. <h2 id="rails-3">Rails 3</h2>
  104. <p>by <a href="https://github.com/dhulihan">dhulihan</a></p>
  105. <p>You can easily override the default rails form helpers (<code>date_select</code> and <code>datetime_select</code>) with bootstrap-datetimepicker for a much nicer experience. </p>
  106. <pre><code class="rb"># Add to config/initializers/form.rb or the end of app/helpers/application_helper.rb
  107. module ActionView
  108. module Helpers
  109. class FormBuilder
  110. def date_select(method, options = {}, html_options = {})
  111. existing_date = @object.send(method)
  112. formatted_date = existing_date.to_date.strftime(&quot;%F&quot;) if existing_date.present?
  113. @template.content_tag(:div, :class =&gt; &quot;input-group&quot;) do
  114. text_field(method, :value =&gt; formatted_date, :class =&gt; &quot;form-control datepicker&quot;, :&quot;data-date-format&quot; =&gt; &quot;YYYY-MM-DD&quot;) +
  115. @template.content_tag(:span, @template.content_tag(:span, &quot;&quot;, :class =&gt; &quot;glyphicon glyphicon-calendar&quot;) ,:class =&gt; &quot;input-group-addon&quot;)
  116. end
  117. end
  118. def datetime_select(method, options = {}, html_options = {})
  119. existing_time = @object.send(method)
  120. formatted_time = existing_time.to_time.strftime(&quot;%F %I:%M %p&quot;) if existing_time.present?
  121. @template.content_tag(:div, :class =&gt; &quot;input-group&quot;) do
  122. text_field(method, :value =&gt; formatted_time, :class =&gt; &quot;form-control datetimepicker&quot;, :&quot;data-date-format&quot; =&gt; &quot;YYYY-MM-DD hh:mm A&quot;) +
  123. @template.content_tag(:span, @template.content_tag(:span, &quot;&quot;, :class =&gt; &quot;glyphicon glyphicon-calendar&quot;) ,:class =&gt; &quot;input-group-addon&quot;)
  124. end
  125. end
  126. end
  127. end
  128. end
  129. </code></pre>
  130. <p>The time format used here is ActiveRecord-friendly, which means it will be parsed correctly when passed in through <code>params</code> to your record.</p>
  131. <p>That's all there is to it! Now all of your forms that use <code>datetime_select</code> or <code>date_select</code> will be automatically updated:</p>
  132. <pre><code class="erb">&lt;% form_for @post do |f| %&gt;
  133. &lt;div class=&quot;form-group&quot;&gt;
  134. &lt;label&gt;Published At&lt;/label&gt;
  135. &lt;%= f.datetime_select :published_at %&gt;
  136. &lt;/div&gt;
  137. &lt;% end %&gt;
  138. </code></pre>
  139. <h2 id="ie-7">IE 7</h2>
  140. <p>by <a href="https://github.com/EquilibriumCST">EquilibriumCST</a></p>
  141. <p>I succeed to run this widget under IE7.
  142. Here is what I did.</p>
  143. <ol>
  144. <li>
  145. <p>gliphicons are not working under IE7 so add <a href="https://github.com/coliff/bootstrap-ie7">this css file</a>. And this enables the icons.</p>
  146. </li>
  147. <li>
  148. <p>Z-index problem with IE 7. I added position: relative and <code>z-index: 10</code> to the parent container. Otherwise popup is shown under the next elements.</p>
  149. </li>
  150. <li>
  151. <p>JS events were not working well. </p>
  152. </li>
  153. </ol>
  154. <p>If you open the datetimepicker widget and click on some button or date inside it, widget is automatically closed.
  155. So I added <code>debug: true</code> as an option when initializing the widget. Why I did this? I saw on line 1121 from bootsrap-datetimepicker.js the code <code>'blur': options.debug ? '' : hide</code>.
  156. And now widget window is not closed on every click inside it, but now you can't close it anyway :)
  157. And closing should be done manually. I've added this document click handler. If you click something outside the widget, now closing works.</p>
  158. <pre><code>$(document).click(function(e){
  159. var target = $(e.target);
  160. if(target.parents('.bootstrap-datetimepicker-widget').length &lt; 1 &amp;&amp; !target.hasClass('datetimepickerInput') &amp;&amp; !target.hasClass('datepickerIcon') &amp;&amp; !target.hasClass('clockpickerIcon')){
  161. if($('.bootstrap-datetimepicker-widget').length &gt; 0){
  162. $('#startDate').data('DateTimePicker').hide();
  163. $('#startTime').data('DateTimePicker').hide();
  164. $('.datetimepickerInput').blur();
  165. }
  166. }
  167. });
  168. </code></pre>
  169. <p>But if you have more than one widget on the page like I did, clicking on one widget does'n close the other. Added below lines and now all works fine.</p>
  170. <pre><code>$('#widget1').on(&quot;dp.show&quot;,function (e) {
  171. $('#widget2).data('DateTimePicker').hide();
  172. });
  173. $('#widget2').on(&quot;dp.show&quot;,function (e) {
  174. $('#widget1).data('DateTimePicker').hide();
  175. });
  176. </code></pre>
  177. <p>I hope this will help to the others who are fighting with the old IE versions :)</p>
  178. </div>
  179. </div>
  180. </div>
  181. <script src="../js/prettify-1.0.min.js"></script>
  182. <script src="../js/base.js"></script>
  183. <script>
  184. if (top != self) {
  185. top.location.replace(self.location.href);
  186. }
  187. (function (i, s, o, g, r, a, m) {
  188. i['GoogleAnalyticsObject'] = r;
  189. i[r] = i[r] || function () {
  190. (i[r].q = i[r].q || []).push(arguments)
  191. }, i[r].l = 1 * new Date();
  192. a = s.createElement(o),
  193. m = s.getElementsByTagName(o)[0];
  194. a.async = 1;
  195. a.src = g;
  196. m.parentNode.insertBefore(a, m)
  197. })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
  198. ga('create', 'UA-47462200-1', 'eonasdan.github.io');
  199. ga('send', 'pageview');
  200. </script>
  201. </body>
  202. </html>