Spinner - A custom widget extending spinner. Use the Globalization plugin.


SUBMITTED BY: jlolk3r

DATE: Jan. 18, 2016, 3:18 a.m.

FORMAT: HTML

SIZE: 1.9 kB

HITS: 1394

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI Spinner - Time</title>
  6. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  7. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  8. <script src="/resources/demos/external/jquery-mousewheel/jquery.mousewheel.js"></script>
  9. <script src="/resources/demos/external/globalize/globalize.js"></script>
  10. <script src="/resources/demos/external/globalize/globalize.culture.de-DE.js"></script>
  11. <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  12. <link rel="stylesheet" href="/resources/demos/style.css">
  13. <script>
  14. $.widget( "ui.timespinner", $.ui.spinner, {
  15. options: {
  16. // seconds
  17. step: 60 * 1000,
  18. // hours
  19. page: 60
  20. },
  21. _parse: function( value ) {
  22. if ( typeof value === "string" ) {
  23. // already a timestamp
  24. if ( Number( value ) == value ) {
  25. return Number( value );
  26. }
  27. return +Globalize.parseDate( value );
  28. }
  29. return value;
  30. },
  31. _format: function( value ) {
  32. return Globalize.format( new Date(value), "t" );
  33. }
  34. });
  35. $(function() {
  36. $( "#spinner" ).timespinner();
  37. $( "#culture" ).change(function() {
  38. var current = $( "#spinner" ).timespinner( "value" );
  39. Globalize.culture( $(this).val() );
  40. $( "#spinner" ).timespinner( "value", current );
  41. });
  42. });
  43. </script>
  44. </head>
  45. <body>
  46. <p>
  47. <label for="spinner">Time spinner:</label>
  48. <input id="spinner" name="spinner" value="08:30 PM">
  49. </p>
  50. <p>
  51. <label for="culture">Select a culture to use for formatting:</label>
  52. <select id="culture">
  53. <option value="en-EN" selected="selected">English</option>
  54. <option value="de-DE">German</option>
  55. </select>
  56. </p>
  57. </body>
  58. </html>

comments powered by Disqus