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.

59 lines
1.2 KiB

  1. function tz_seconds_to_offset(seconds) {
  2. var tz_offset = "";
  3. var hours = zero_pad(Math.abs(seconds / 60 / 60));
  4. var minutes = zero_pad(Math.floor(seconds / 60) % 60);
  5. return (seconds < 0 ? "-" : "+") + hours + ":" + minutes;
  6. }
  7. function zero_pad(num) {
  8. num = "" + num;
  9. if (num.length == 1) {
  10. num = "0" + num;
  11. }
  12. return num;
  13. }
  14. function tokenfieldToArray(sel) {
  15. return $(sel)
  16. .tokenfield("getTokens")
  17. .map(function (t) {
  18. return t.value;
  19. });
  20. }
  21. $(function () {
  22. // Set the date from JS
  23. var d = new Date();
  24. $("#note_date").val(
  25. d.getFullYear() +
  26. "-" +
  27. zero_pad(d.getMonth() + 1) +
  28. "-" +
  29. zero_pad(d.getDate())
  30. );
  31. $("#note_time").val(
  32. zero_pad(d.getHours()) +
  33. ":" +
  34. zero_pad(d.getMinutes()) +
  35. ":" +
  36. zero_pad(d.getSeconds())
  37. );
  38. $("#note_tzoffset").val(
  39. tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1)
  40. );
  41. // ctrl-s to save
  42. $(window).on("keydown", function (e) {
  43. if (e.keyCode == 83 && e.ctrlKey) {
  44. $("#btn_post").click();
  45. }
  46. });
  47. });
  48. function auto_prefix_url_field(field) {
  49. var str = field.value;
  50. if (!/^https?:\/\//.test(str)) {
  51. str = "http://" + str;
  52. }
  53. field.value = str;
  54. }