]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/js/ostatus.js
tweak RSSCloud plugin to use new schema layout (but still the old event); the timesta...
[quix0rs-gnu-social.git] / plugins / OStatus / js / ostatus.js
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
27 SN.Init.OStatusCookie = function() {
28     if (SN.U.StatusNetInstance.Get() === null) {
29         SN.U.StatusNetInstance.Set({RemoteProfile: null});
30     }
31 };
32
33 SN.U.DialogBox = {
34     Subscribe: function(a) {
35         var f = a.parent().find('.form_settings');
36         if (f.length > 0) {
37             f.show();
38         }
39         else {
40             $.ajax({
41                 type: 'GET',
42                 dataType: 'xml',
43                 url: a[0].href + ((a[0].href.match(/[\\?]/) === null)?'?':'&') + 'ajax=1',
44                 beforeSend: function(formData) {
45                     a.addClass('processing');
46                 },
47                 error: function (xhr, textStatus, errorThrown) {
48                     alert(errorThrown || textStatus);
49                 },
50                 success: function(data, textStatus, xhr) {
51                     if (typeof($('form', data)[0]) != 'undefined') {
52                         a.after(document._importNode($('form', data)[0], true));
53
54                         var form = a.parent().find('.form_settings');
55
56                         form
57                             .addClass('dialogbox')
58                             .append('<button class="close">&#215;</button>');
59
60                         form
61                             .find('.submit')
62                                 .addClass('submit_dialogbox')
63                                 .removeClass('submit')
64                                 .bind('click', function() {
65                                     form.addClass('processing');
66                                 });
67
68                         form.find('button.close').click(function(){
69                             form.hide();
70
71                             return false;
72                         });
73
74                         form.find('#profile').focus();
75
76                         if (form.attr('id') == 'form_ostatus_connect') {
77                             SN.Init.OStatusCookie();
78                             form.find('#profile').val(SN.U.StatusNetInstance.Get().RemoteProfile);
79
80                             form.find("[type=submit]").bind('click', function() {
81                                 SN.U.StatusNetInstance.Set({RemoteProfile: form.find('#profile').val()});
82                                 return true;
83                             });
84                         }
85                     }
86
87                     a.removeClass('processing');
88                 }
89             });
90         }
91     }
92 };
93
94 SN.Init.Subscribe = function() {
95     $('.entity_subscribe .entity_remote_subscribe').live('click', function() { SN.U.DialogBox.Subscribe($(this)); return false; });
96 };
97
98 $(document).ready(function() {
99     SN.Init.Subscribe();
100
101     $('.form_remote_authorize').bind('submit', function() { $(this).addClass(SN.C.S.Processing); return true; });
102 });