ostatus.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * StatusNet - a distributed open-source microblogging tool
  3. * Copyright (C) 2010, StatusNet, Inc.
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * @category OStatus UI interaction
  19. * @package StatusNet
  20. * @author Sarven Capadisli <csarven@status.net>
  21. * @copyright 2010 StatusNet, Inc.
  22. * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  23. * @link http://status.net/
  24. * @note Everything in here should eventually migrate over to /js/util.js's SN.
  25. */
  26. SN.Init.OStatusCookie = function () {
  27. if (SN.U.StatusNetInstance.Get() === null) {
  28. SN.U.StatusNetInstance.Set({RemoteProfile: null});
  29. }
  30. };
  31. SN.U.DialogBox = {
  32. Subscribe: function (a) {
  33. var f = a.parent().find('.form_settings');
  34. if (f.length > 0) {
  35. f.show();
  36. }
  37. else {
  38. $.ajax({
  39. type: 'GET',
  40. dataType: 'xml',
  41. url: a[0].href + ((a[0].href.match(/[\\?]/) === null)?'?':'&') + 'ajax=1',
  42. beforeSend: function (formData) {
  43. a.addClass('processing');
  44. },
  45. error: function (xhr, textStatus, errorThrown) {
  46. alert(errorThrown || textStatus);
  47. },
  48. success: function (data, textStatus, xhr) {
  49. if (typeof($('form', data)[0]) != 'undefined') {
  50. a.after(document._importNode($('form', data)[0], true));
  51. var form = a.parent().find('.form_settings');
  52. form
  53. .addClass('dialogbox')
  54. .append('<button class="close">&#215;</button>');
  55. form
  56. .find('.submit')
  57. .addClass('submit_dialogbox')
  58. .removeClass('submit')
  59. .bind('click', function () {
  60. form.addClass('processing');
  61. });
  62. form.find('button.close').click(function (){
  63. form.hide();
  64. return false;
  65. });
  66. form.find('#profile').focus();
  67. if (form.attr('id') == 'form_ostatus_connect') {
  68. SN.Init.OStatusCookie();
  69. form.find('#profile').val(SN.U.StatusNetInstance.Get().RemoteProfile);
  70. form.find("[type=submit]").bind('click', function () {
  71. SN.U.StatusNetInstance.Set({RemoteProfile: form.find('#profile').val()});
  72. return true;
  73. });
  74. }
  75. }
  76. a.removeClass('processing');
  77. }
  78. });
  79. }
  80. }
  81. };
  82. SN.Init.Subscribe = function () {
  83. $(document).on('click',
  84. '.entity_subscribe .entity_remote_subscribe, .entity_tag .entity_remote_tag',
  85. function () { SN.U.DialogBox.Subscribe($(this)); return false; });
  86. };
  87. $(document).ready(function () {
  88. SN.Init.Subscribe();
  89. $('.form_remote_authorize').bind('submit', function () {
  90. $(this).addClass(SN.C.S.Processing); return true;
  91. });
  92. });