chat_func.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*! Front Page */
  2. $(function() {
  3. var i;i = 0;
  4. Messenger.options = {extraClasses: "messenger-fixed messenger-on-bottom messenger-on-left",theme: "flat"};
  5. var msg; msg = Messenger().post({
  6. message: 'I am currently online', type: 'success',
  7. actions: {retry: {label: 'Connect', delay: 30,
  8. action: function(){
  9. txt_dave();
  10. var msg_return; msg_return = Messenger().run({
  11. errorMessage: 'Please wait a moment while I am texted a message to get connected with you.',
  12. successMessage: 'Connecting Now!',
  13. action: function(opts) {
  14. msg.hide();
  15. if (++i < 2) {
  16. return opts.error({status: 500,readyState: 0,responseText: 0});
  17. }
  18. else {
  19. window.location.href = 'contact/chat';
  20. return msg.update({message: 'Redirect to Chat', hideAfter: 20, type: 'success', actions: false});
  21. }
  22. }
  23. });
  24. }
  25. },
  26. cancel: {
  27. label: 'No Thanks',
  28. action: function() {
  29. return msg.update({message: 'Maybe Next Time', hideAfter: 1, type: 'error', actions: false});
  30. }
  31. }
  32. }
  33. });
  34. });
  35. function txt_dave() {
  36. $.ajax({
  37. url: 'https://davidawindham.com/wha/phony/sms',
  38. dataType: 'json',
  39. success: function(data){},
  40. });
  41. }
  42. /*! Chat Page */
  43. Messenger.options = {extraClasses: "messenger-fixed messenger-on-bottom messenger-on-left",theme: "flat"};
  44. var i;i = 0;
  45. $(function(){
  46. var msg_return; msg_return = Messenger().run({
  47. id: 'one',
  48. errorMessage: 'Looking for David...',
  49. action: function(opts) {
  50. if (++i < 2) {
  51. get_dave();
  52. return opts.error({status: 500,readyState: 0,responseText: 0});
  53. }
  54. }
  55. });
  56. });
  57. function get_dave() {
  58. $(function poll() {
  59. var x = 0;
  60. var countTimer = setInterval(function () {
  61. if(x > 5){clearInterval(countTimer)}
  62. else if(x == 5){dave_not_available()}
  63. else{
  64. var URLchatAPI = "http://macs.local:8080/status";
  65. var request = $.ajax({
  66. url: URLchatAPI,
  67. dataType: 'json',
  68. cache: false,
  69. success: function (data) {
  70. online = data.online;
  71. if (online=='yes') {
  72. $('.chat').modal('show');
  73. x = x+5;
  74. };
  75. if (online=='no') {
  76. dave_connecting();
  77. };
  78. },
  79. error: function ( xhr, tStatus, err ) {
  80. dave_error();
  81. x = x+5;
  82. }
  83. });
  84. x++;
  85. }
  86. }, 5000);
  87. });
  88. }
  89. function dave_connecting(){
  90. var y;y = 0;
  91. var msg_waiting; msg_waiting = Messenger().run({
  92. id: 'one',
  93. hideAfter: 4,
  94. errorMessage: 'Waiting on David...',
  95. action: function(opts) {
  96. if (++y < 2) {
  97. get_dave();
  98. return opts.error({status: 500,readyState: 0,responseText: 0});
  99. }
  100. }
  101. });
  102. }
  103. function dave_not_available(){
  104. var msg_error; msg_error = Messenger().post({
  105. message: 'Sorry, but I am busy.',
  106. type: 'error',
  107. id: 'one',
  108. showCloseButton: true,
  109. actions:{
  110. cancel: {
  111. label: 'Leave me a message',
  112. action: function(){
  113. window.location.href = '../';
  114. }
  115. }
  116. }
  117. });
  118. }
  119. function dave_error(){
  120. var msg_error; msg_error = Messenger().post({
  121. message: 'Oops. Something has gone wrong.',
  122. type: 'error',
  123. id: 'one',
  124. showCloseButton: true,
  125. actions:{
  126. cancel: {
  127. label: 'Leave me a message',
  128. action: function(){
  129. window.location.href = '../';
  130. }
  131. }
  132. }
  133. });
  134. }
  135. $(function() {
  136. if (window.location.hash.indexOf("chat") !== -1) {
  137. $('.chat').modal('show');
  138. }
  139. });