]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/js/ostatus.js
148a05f6f642586ed1702fd6d3751be52615e42d
[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.C.S.StatusNetInstance = 'StatusNetInstance';
28
29 SN.U.StatusNetInstance = {
30     Set: function(value) {
31         $.cookie(
32             SN.C.S.StatusNetInstance,
33             JSON.stringify(value),
34             {
35                 path: '/',
36                 expires: SN.U.GetFullYear(2029, 0, 1)
37             });
38     },
39
40     Get: function() {
41         var cookieValue = $.cookie(SN.C.S.StatusNetInstance);
42         if (cookieValue !== null) {
43             return JSON.parse(cookieValue);
44         }
45         return null;
46     },
47
48     Delete: function() {
49         $.cookie(SN.C.S.StatusNetInstance, null);
50     }
51 };
52
53 SN.Init.OStatusCookie = function() {
54     if (SN.U.StatusNetInstance.Get() === null) {
55         SN.U.StatusNetInstance.Set({profile: null});
56     }
57 };
58
59 SN.U.DialogBox = {
60     Subscribe: function(a) {
61         var f = a.parent().find('.form_settings');
62         if (f.length > 0) {
63             f.show();
64         }
65         else {
66             a[0].href = (a[0].href.match(/[\\?]/) === null) ? a[0].href+'?' : a[0].href+'&';
67             $.ajax({
68                 type: 'GET',
69                 dataType: 'xml',
70                 url: a[0].href+'ajax=1',
71                 beforeSend: function(formData) {
72                     a.addClass('processing');
73                 },
74                 error: function (xhr, textStatus, errorThrown) {
75                     alert(errorThrown || textStatus);
76                 },
77                 success: function(data, textStatus, xhr) {
78                     if (typeof($('form', data)[0]) != 'undefined') {
79                         a.after(document._importNode($('form', data)[0], true));
80
81                         var form = a.parent().find('.form_settings');
82
83                         form
84                             .addClass('dialogbox')
85                             .append('<button class="close">&#215;</button>');
86
87                         form
88                             .find('.submit')
89                                 .addClass('submit_dialogbox')
90                                 .removeClass('submit')
91                                 .bind('click', function() {
92                                     form.addClass('processing');
93                                 });
94
95                         form.find('button.close').click(function(){
96                             form.hide();
97
98                             return false;
99                         });
100
101                         form.find('#profile').focus();
102
103                         if (form.attr('id') == 'form_ostatus_connect') {
104                             SN.Init.OStatusCookie();
105                             form.find('#profile').val(SN.U.StatusNetInstance.Get().profile);
106
107                             form.find("[type=submit]").bind('click', function() {
108                                 SN.U.StatusNetInstance.Set({profile: form.find('#profile').val()});
109                                 return true;
110                             });
111                         }
112                     }
113
114                     a.removeClass('processing');
115                 }
116             });
117         }
118     }
119 };
120
121 SN.Init.Subscribe = function() {
122     $('.entity_subscribe .entity_remote_subscribe').live('click', function() { SN.U.DialogBox.Subscribe($(this)); return false; });
123 };
124
125 $(document).ready(function() {
126     SN.Init.Subscribe();
127 });