2 * StatusNet - a distributed open-source microblogging tool
3 * Copyright (C) 2010, StatusNet, Inc.
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.
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.
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/>.
18 * @category OStatus UI interaction
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.
27 SN.C.S.StatusNetInstance = 'StatusNetInstance';
29 SN.U.StatusNetInstance = {
30 Set: function(value) {
32 SN.C.S.StatusNetInstance,
33 JSON.stringify(value),
36 expires: SN.U.GetFullYear(2029, 0, 1)
41 var cookieValue = $.cookie(SN.C.S.StatusNetInstance);
42 if (cookieValue !== null) {
43 return JSON.parse(cookieValue);
49 $.cookie(SN.C.S.StatusNetInstance, null);
53 SN.Init.OStatusCookie = function() {
54 if (SN.U.StatusNetInstance.Get() === null) {
55 SN.U.StatusNetInstance.Set({profile: null});
60 Subscribe: function(a) {
61 var f = a.parent().find('.form_settings');
66 a[0].href = (a[0].href.match(/[\\?]/) === null) ? a[0].href+'?' : a[0].href+'&';
70 url: a[0].href+'ajax=1',
71 beforeSend: function(formData) {
72 a.addClass('processing');
74 error: function (xhr, textStatus, errorThrown) {
75 alert(errorThrown || textStatus);
77 success: function(data, textStatus, xhr) {
78 if (typeof($('form', data)[0]) != 'undefined') {
79 a.after(document._importNode($('form', data)[0], true));
81 var form = a.parent().find('.form_settings');
84 .addClass('dialogbox')
85 .append('<button class="close">×</button>');
89 .addClass('submit_dialogbox')
90 .removeClass('submit')
91 .bind('click', function() {
92 form.addClass('processing');
95 form.find('button.close').click(function(){
101 form.find('#profile').focus();
103 if (form.attr('id') == 'form_ostatus_connect') {
104 SN.Init.OStatusCookie();
105 form.find('#profile').val(SN.U.StatusNetInstance.Get().profile);
107 form.find("[type=submit]").bind('click', function() {
108 SN.U.StatusNetInstance.Set({profile: form.find('#profile').val()});
114 a.removeClass('processing');
121 SN.Init.Subscribe = function() {
122 $('.entity_subscribe .entity_remote_subscribe').live('click', function() { SN.U.DialogBox.Subscribe($(this)); return false; });
125 $(document).ready(function() {