chat_func.js 3.7 KB

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