TimeSpinner.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.form.TimeSpinner"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.form.TimeSpinner"] = true;
  8. dojo.provide("dojox.form.TimeSpinner");
  9. dojo.require("dijit.form._Spinner");
  10. dojo.require("dojo.date");
  11. dojo.require("dojo.date.locale");
  12. dojo.require("dojo.date.stamp");
  13. dojo.declare(
  14. "dojox.form.TimeSpinner",
  15. [dijit.form._Spinner],
  16. {
  17. // summary: Time Spinner
  18. // description: This widget is the same as a normal NumberSpinner, but for the time component of a date object instead
  19. required: false,
  20. adjust: function(/* Object */ val, /*Number*/ delta){
  21. return dojo.date.add(val, "minute", delta)
  22. },
  23. //FIXME should we allow for constraints in this widget?
  24. isValid: function(){return true;},
  25. smallDelta: 5,
  26. largeDelta: 30,
  27. timeoutChangeRate: 0.50,
  28. parse: function(time, locale){
  29. return dojo.date.locale.parse(time, {selector:"time", formatLength:"short"});
  30. },
  31. format: function(time, locale){
  32. if (dojo.isString(time)) { return time; }
  33. return dojo.date.locale.format(time, {selector:"time", formatLength:"short"});
  34. },
  35. serialize: dojo.date.stamp.toISOString,
  36. value: "12:00 AM",
  37. _onKeyPress: function(e){
  38. if((e.charOrCode == dojo.keys.HOME || e.charOrCode == dojo.keys.END) && !(e.ctrlKey || e.altKey || e.metaKey)
  39. && typeof this.get('value') != 'undefined' /* gibberish, so HOME and END are default editing keys*/){
  40. var value = this.constraints[(e.charOrCode == dojo.keys.HOME ? "min" : "max")];
  41. if(value){
  42. this._setValueAttr(value,true);
  43. }
  44. // eat home or end key whether we change the value or not
  45. dojo.stopEvent(e);
  46. }
  47. }
  48. });
  49. }