Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ojsxc.js « js « build - github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 49d0792d602039bb6167411f90c3b6f7f7e577e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*!
 * ojsxc v2.1.2 - 2015-08-12
 * 
 * Copyright (c) 2015 Klaus Herberth <klaus@jsxc.org> <br>
 * Released under the MIT license
 * 
 * Please see http://www.jsxc.org/
 * 
 * @author Klaus Herberth <klaus@jsxc.org>
 * @version 2.1.2
 * @license MIT
 */

/* global jsxc, oc_appswebroots, OC, $, oc_requesttoken, dijit, oc_config */
/* jshint latedef: nofunc */

/**
 * Make room for the roster inside the owncloud template.
 * 
 * @param {type} event
 * @param {type} state State in which the roster is
 * @param {type} duration Time the roster needs to move
 * @returns {undefined}
 */
function onRosterToggle(event, state, duration) {
   "use strict";
   var wrapper = $('#content-wrapper');
   var control = $('#controls');

   var roster_width = (state === 'shown') ? $('#jsxc_roster').outerWidth() : 0;
   var toggle_width = $('#jsxc_toggleRoster').width();
   var navigation_width = $('#navigation').width();

   wrapper.animate({
      paddingRight: (roster_width + toggle_width) + 'px'
   }, duration);

   // only oc < 8
   if (!oc_config || !oc_config.version || !oc_config.version.match(/^([8-9]|[0-9]{2,})\./)) {
      control.animate({
         paddingRight: (roster_width + navigation_width + toggle_width) + 'px'
      }, duration);
   }

   // update webodf
   if (typeof dijit !== 'undefined') {
      $('#mainContainer, #odf-toolbar').animate({
         right: (roster_width + toggle_width) + 'px'
      }, {
         progress: function() {
            dijit.byId("mainContainer").resize();
         }
      });
   }
}

/**
 * Init owncloud template for roster.
 * 
 * @returns {undefined}
 */
function onRosterReady() {
   "use strict";
   var roster_width, navigation_width, roster_right, toggle_width;

   getValues();

   $('#content-wrapper').css('paddingRight', roster_width + roster_right + toggle_width);

   // only oc < 8
   if (!oc_config || !oc_config.version || !oc_config.version.match(/^([8-9]|[0-9]{2,})\./)) {
      $('#controls').css('paddingRight', roster_width + navigation_width + roster_right + toggle_width);
   }

   // update webodf
   var contentbg = $('#content-wrapper').css('background-color');
   $(window).on('hashchange', function() {
      $('#content-wrapper').css('background-color', contentbg);

      if (window.location.pathname.match(/\/documents\/$/)) {
         var docNo = window.location.hash.replace(/^#/, '');

         if (docNo.match(/[0-9]+/) && typeof dijit !== 'undefined') {
            getValues();

            $('#content-wrapper').css('background-color', $('#mainContainer').css('background-color'));

            $('#mainContainer, #odf-toolbar').css('right', roster_width + roster_right + toggle_width);
            dijit.byId("mainContainer").resize();
         }
      }
   });

   function getValues() {
      roster_width = $('#jsxc_roster').outerWidth();
      navigation_width = $('#navigation').width();
      roster_right = parseFloat($('#jsxc_roster').css('right'));
      toggle_width = $('#jsxc_toggleRoster').width();
   }
}

// initialization
$(function() {
   "use strict";

   if (location.pathname.substring(location.pathname.lastIndexOf("/") + 1) === 'public.php') {
      return;
   }

   $(document).one('ready.roster.jsxc', onRosterReady);
   $(document).on('toggle.roster.jsxc', onRosterToggle);

   $(document).on('connected.jsxc', function() {
      // reset default avatar cache
      jsxc.storage.removeUserItem('defaultAvatars');
   });

   $(document).on('status.contacts.count status.contact.updated', function() {
      if (jsxc.restoreCompleted) {
         setTimeout(function() {
            jsxc.gui.detectEmail($('table#contactlist'));
         }, 500);
      } else {
         $(document).on('restoreCompleted.jsxc', function() {
            jsxc.gui.detectEmail($('table#contactlist'));
         });
      }
   });

   jsxc.init({
      app_name: 'Owncloud',
      loginForm: {
         form: '#body-login form',
         jid: '#user',
         pass: '#password',
         attachIfFound: false
      },
      logoutElement: $('#logout'),
      rosterAppend: 'body',
      root: oc_appswebroots.ojsxc + '/js/jsxc',
      RTCPeerConfig: {
         url: OC.filePath('ojsxc', 'ajax', 'getturncredentials.php')
      },
      displayRosterMinimized: function() {
         return OC.currentUser != null;
      },
      defaultAvatar: function(jid) {
         var cache = jsxc.storage.getUserItem('defaultAvatars') || {};
         var user = Strophe.unescapeNode(jid.replace(/@[^@]+$/, ''));
         var ie8fix = true;

         $(this).each(function() {

            var $div = $(this).find('.jsxc_avatar');
            var size = $div.width();
            var key = user + '@' + size;

            var handleResponse = function(result) {
               if (typeof (result) === 'object') {
                  if (result.data && result.data.displayname) {
                     $div.imageplaceholder(user, result.data.displayname);
                  } else {
                     $div.imageplaceholder(user);
                  }
               } else {
                  $div.show();
                  if (ie8fix === true) {
                     $div.html('<img src="' + result + '#' + Math.floor(Math.random() * 1000) + '">');
                  } else {
                     $div.html('<img src="' + result + '">');
                  }
               }
            };

            if (typeof cache[key] === 'undefined' || cache[key] === null) {
               var url;

               if (OC.generateUrl) {
                  // oc >= 7
                  url = OC.generateUrl('/avatar/' + encodeURIComponent(user) + '/' + size + '?requesttoken={requesttoken}', {
                     user: user,
                     size: size,
                     requesttoken: oc_requesttoken
                  });
               } else {
                  // oc < 7
                  url = OC.Router.generate('core_avatar_get', {
                     user: user,
                     size: size
                  }) + '?requesttoken=' + oc_requesttoken;
               }

               $.get(url, function(result) {

                  var val = (typeof result === 'object') ? result : url;
                  handleResponse(val);

                  jsxc.storage.updateItem('defaultAvatars', key, val, true);
               });

            } else {
               handleResponse(cache[key]);
            }
         });
      },
      loadSettings: function(username, password, cb) {
         $.ajax({
            type: 'POST',
            url: OC.filePath('ojsxc', 'ajax', 'getsettings.php'),
            data: {
               username: username,
               password: password
            },
            success: function(d) {
               if (d.result === 'success') {
                  cb(d.data);
               } else {
                  cb(false);
               }
            },
            error: function() {
               jsxc.error('XHR error on getsettings.php');

               cb(false);
            }
         });
      },
      saveSettinsPermanent: function(data) {
         var ret = 1;

         $.ajax({
            async: false,
            type: 'POST',
            url: OC.filePath('ojsxc', 'ajax', 'setUserSettings.php'),
            data: data,
            success: function(data) {
               if (data.trim() === 'true') {
                  ret = 0;
               }
            }
         });

         return ret;
      },
      getUsers: function(search, cb) {
         $.ajax({
            type: 'GET',
            url: OC.filePath('ojsxc', 'ajax', 'getUsers.php'),
            data: {
               search: search
            },
            success: cb,
            error: function() {
               jsxc.error('XHR error on getUsers.php');
            }
         });
      }
   });

   // Add submit link without chat functionality
   if (jsxc.el_exists(jsxc.options.loginForm.form) && jsxc.el_exists(jsxc.options.loginForm.jid) && jsxc.el_exists(jsxc.options.loginForm.pass)) {

      var link = $('<a/>').text($.t('Log_in_without_chat')).attr('href', '#').click(function() {
         jsxc.submitLoginForm();
      });

      var alt = $('<p id="jsxc_alt"/>').append(link);
      $('#body-login form fieldset').append(alt);
   }
});