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.

44 lines
1.1 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).tokenfield("getTokens").map(function(t){ return t.value});
  16. }
  17. $(function(){
  18. // Set the date from JS
  19. var d = new Date();
  20. $("#note_date").val(d.getFullYear()+"-"+zero_pad(d.getMonth()+1)+"-"+zero_pad(d.getDate()));
  21. $("#note_time").val(zero_pad(d.getHours())+":"+zero_pad(d.getMinutes())+":"+zero_pad(d.getSeconds()));
  22. $("#note_tzoffset").val(tz_seconds_to_offset(d.getTimezoneOffset() * 60 * -1));
  23. // ctrl-s to save
  24. $(window).on('keydown', function(e){
  25. if(e.keyCode == 83 && e.ctrlKey){
  26. $("#btn_post").click();
  27. }
  28. });
  29. })
  30. function auto_prefix_url_field(field) {
  31. var str = field.value;
  32. if(!/^https?:\/\//.test(str)) {
  33. str = "http://" + str;
  34. }
  35. field.value = str;
  36. }