ostatus.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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.U.DialogBox = {
  27. Subscribe: function (a) {
  28. var f = a.parent().find('.form_settings');
  29. if (f.length > 0) {
  30. f.show();
  31. }
  32. else {
  33. $.ajax({
  34. type: 'GET',
  35. dataType: 'xml',
  36. url: a[0].href + ((a[0].href.match(/[\\?]/) === null)?'?':'&') + 'ajax=1',
  37. beforeSend: function (formData) {
  38. a.addClass('processing');
  39. },
  40. error: function (xhr, textStatus, errorThrown) {
  41. alert(errorThrown || textStatus);
  42. },
  43. success: function (data, textStatus, xhr) {
  44. if (typeof($('form', data)[0]) != 'undefined') {
  45. a.after(document._importNode($('form', data)[0], true));
  46. var form = a.parent().find('.form_settings');
  47. form
  48. .addClass('dialogbox')
  49. .append('<button class="close">&#215;</button>');
  50. form
  51. .find('.submit')
  52. .addClass('submit_dialogbox')
  53. .removeClass('submit')
  54. .bind('click', function () {
  55. form.addClass('processing');
  56. });
  57. form.find('button.close').click(function (){
  58. form.hide();
  59. return false;
  60. });
  61. form.find('#profile').focus();
  62. }
  63. a.removeClass('processing');
  64. }
  65. });
  66. }
  67. }
  68. };
  69. SN.Init.Subscribe = function () {
  70. $(document).on('click',
  71. '.entity_subscribe .entity_remote_subscribe, .entity_tag .entity_remote_tag',
  72. function () { SN.U.DialogBox.Subscribe($(this)); return false; });
  73. };
  74. $(document).ready(function () {
  75. SN.Init.Subscribe();
  76. $('.form_remote_authorize').bind('submit', function () {
  77. $(this).addClass(SN.C.S.Processing); return true;
  78. });
  79. });