2011-12-04 15:33:56 +00:00
|
|
|
|
/**
|
2012-02-20 23:16:25 +01:00
|
|
|
|
* This code is mostly from the old Etherpad. Please help us to comment this code.
|
2011-12-04 15:33:56 +00:00
|
|
|
|
* This helps other people to understand this code better and helps them to improve it.
|
|
|
|
|
* TL;DR COMMENTS ON THIS FILE ARE HIGHLY APPRECIATED
|
|
|
|
|
*/
|
|
|
|
|
|
2011-03-26 13:10:41 +00:00
|
|
|
|
/**
|
2011-08-11 15:26:41 +01:00
|
|
|
|
* Copyright 2009 Google Inc., 2011 Peter 'Pita' Martischka (Primary Technology Ltd)
|
2011-07-07 18:59:34 +01:00
|
|
|
|
*
|
2011-03-26 13:10:41 +00:00
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
2011-07-07 18:59:34 +01:00
|
|
|
|
*
|
2011-03-26 13:10:41 +00:00
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-07-07 18:59:34 +01:00
|
|
|
|
*
|
2011-03-26 13:10:41 +00:00
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS-IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* global $, window */
|
|
|
|
|
|
|
|
|
|
var socket;
|
2012-01-15 18:22:28 -08:00
|
|
|
|
|
2012-01-28 15:26:39 -08:00
|
|
|
|
// These jQuery things should create local references, but for now `require()`
|
|
|
|
|
// assigns to the global `$` and augments it with plugins.
|
|
|
|
|
require('/jquery');
|
|
|
|
|
require('/farbtastic');
|
|
|
|
|
require('/excanvas');
|
2012-01-30 13:27:43 -08:00
|
|
|
|
JSON = require('/json2');
|
2012-01-28 15:26:39 -08:00
|
|
|
|
require('/undo-xpopup');
|
2012-02-04 18:11:41 +01:00
|
|
|
|
require('/prefixfree');
|
2012-01-28 15:26:39 -08:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
var chat = require('/chat').chat,
|
|
|
|
|
getCollabClient = require('/collab_client').getCollabClient,
|
|
|
|
|
padconnectionstatus = require('/pad_connectionstatus').padconnectionstatus,
|
|
|
|
|
padcookie = require('/pad_cookie').padcookie,
|
|
|
|
|
paddocbar = require('/pad_docbar').paddocbar,
|
|
|
|
|
padeditbar = require('/pad_editbar').padeditbar,
|
|
|
|
|
padeditor = require('/pad_editor').padeditor,
|
|
|
|
|
padimpexp = require('/pad_impexp').padimpexp,
|
|
|
|
|
padmodals = require('/pad_modals').padmodals,
|
|
|
|
|
padsavedrevs = require('/pad_savedrevs').padsavedrevs,
|
|
|
|
|
paduserlist = require('/pad_userlist').paduserlist,
|
|
|
|
|
padutils = require('/pad_utils').padutils,
|
|
|
|
|
createCookie = require('/pad_utils').createCookie,
|
|
|
|
|
readCookie = require('/pad_utils').readCookie,
|
|
|
|
|
randomString = require('/pad_utils').randomString;
|
|
|
|
|
|
|
|
|
|
function getParams() {
|
|
|
|
|
var params = getUrlVars(),
|
|
|
|
|
showControls = params['showControls'],
|
|
|
|
|
showChat = params['showChat'],
|
|
|
|
|
userName = params['userName'],
|
|
|
|
|
showLineNumbers = params['showLineNumbers'],
|
|
|
|
|
useMonospaceFont = params['useMonospaceFont'],
|
|
|
|
|
IsnoColors = params['noColors'],
|
|
|
|
|
hideQRCode = params['hideQRCode'],
|
|
|
|
|
rtl = params['rtl'],
|
|
|
|
|
alwaysShowChat = params['alwaysShowChat'];
|
|
|
|
|
|
|
|
|
|
if (IsnoColors) {
|
|
|
|
|
if (IsnoColors == 'true') {
|
2012-01-15 18:22:28 -08:00
|
|
|
|
settings.noColors = true;
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#buttonicon-clearauthorship').hide();
|
2011-09-04 13:48:53 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (showControls) {
|
|
|
|
|
if (showControls == 'false') {
|
2011-08-12 16:00:09 +01:00
|
|
|
|
$('#editbar').hide();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#editorcontainer').css({top:0});
|
2011-08-12 16:00:09 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (showChat) {
|
|
|
|
|
if (showChat == 'false') {
|
2011-08-13 18:37:44 +01:00
|
|
|
|
$('#chaticon').hide();
|
|
|
|
|
}
|
2011-08-12 16:00:09 +01:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (showLineNumbers) {
|
|
|
|
|
if (showLineNumbers == 'false')
|
2012-01-15 18:22:28 -08:00
|
|
|
|
settings.LineNumbersDisabled = true;
|
2011-08-13 18:37:44 +01:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (useMonospaceFont) {
|
|
|
|
|
if (useMonospaceFont == 'true')
|
2012-01-15 18:22:28 -08:00
|
|
|
|
settings.useMonospaceFontGlobal = true;
|
2011-08-13 22:10:58 +01:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (userName) {
|
|
|
|
|
// if the username is set as a parameter we should set a global value that we can call once we have initiated the pad
|
2012-01-15 18:22:28 -08:00
|
|
|
|
settings.globalUserName = unescape(userName);
|
2011-08-13 19:53:02 +01:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (hideQRCode) {
|
2011-12-04 15:33:56 +00:00
|
|
|
|
$('#qrcode').hide();
|
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (rtl) {
|
|
|
|
|
if (rtl == 'true')
|
|
|
|
|
settings.rtlIsTrue = true;
|
2011-12-04 18:55:35 +00:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (alwaysShowChat) {
|
|
|
|
|
if (alwaysShowChat == 'true')
|
2012-02-05 14:23:01 +00:00
|
|
|
|
chat.stickToScreen();
|
|
|
|
|
}
|
2011-08-12 16:00:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
function getUrlVars() {
|
|
|
|
|
var vars = [], hash,
|
|
|
|
|
hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
|
|
|
|
|
for (var i=0, l=hashes.length; i < l; i++) {
|
2011-08-12 16:00:09 +01:00
|
|
|
|
hash = hashes[i].split('=');
|
|
|
|
|
vars.push(hash[0]);
|
|
|
|
|
vars[hash[0]] = hash[1];
|
|
|
|
|
}
|
|
|
|
|
return vars;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
function savePassword() {
|
|
|
|
|
// set the password cookie
|
|
|
|
|
createCookie('password', $('#passwordinput').val(), null, document.location.pathname);
|
|
|
|
|
// reload
|
|
|
|
|
document.location = document.location;
|
2011-08-15 18:26:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
function handshake() {
|
|
|
|
|
var loc = document.location,
|
|
|
|
|
port = loc.port == '' ? (loc.protocol == 'https:' ? 443 : 80) : loc.port, // get the correct port
|
|
|
|
|
url = loc.protocol + '//' + loc.hostname + ':' + port + '/', // create the url
|
|
|
|
|
resource = loc.pathname.substr(1, loc.pathname.indexOf('/p/')) + 'socket.io'; // determine current subfolder
|
|
|
|
|
// connect
|
2012-01-17 00:43:11 -08:00
|
|
|
|
socket = pad.socket = io.connect(url, {
|
2011-11-25 15:24:10 -08:00
|
|
|
|
resource: resource,
|
|
|
|
|
'max reconnection attempts': 3
|
2011-07-07 18:59:34 +01:00
|
|
|
|
});
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
function sendClientReady(isReconnect) {
|
|
|
|
|
var padId = document.location.pathname.substring(document.location.pathname.lastIndexOf('/') + 1);
|
2011-11-28 11:26:36 -08:00
|
|
|
|
padId = decodeURIComponent(padId); // unescape neccesary due to Safari and Opera interpretation of spaces
|
2011-08-15 15:40:38 +01:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (!isReconnect)
|
2012-01-31 14:15:36 +00:00
|
|
|
|
document.title = padId.replace(/_+/g, ' ') + " | " + document.title;
|
2011-07-07 18:59:34 +01:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
var token = readCookie('token');
|
|
|
|
|
if (token == null) {
|
|
|
|
|
token = 't.' + randomString();
|
|
|
|
|
createCookie('token', token, 60);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sessionID = readCookie('sessionID'),
|
|
|
|
|
password = readCookie('password'),
|
|
|
|
|
msg = {
|
|
|
|
|
'component' : 'pad',
|
|
|
|
|
'type' : 'CLIENT_READY',
|
|
|
|
|
'padId' : padId,
|
|
|
|
|
'sessionID' : sessionID,
|
|
|
|
|
'password' : password,
|
|
|
|
|
'token' : token,
|
|
|
|
|
'protocolVersion' : 2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// this is a reconnect, lets tell the server our revision number
|
|
|
|
|
if (isReconnect == true) {
|
2011-11-25 15:24:10 -08:00
|
|
|
|
msg.client_rev=pad.collabClient.getCurrentRevisionNumber();
|
|
|
|
|
msg.reconnect=true;
|
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
|
2011-07-07 18:59:34 +01:00
|
|
|
|
socket.json.send(msg);
|
2011-11-25 15:24:10 -08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var disconnectTimeout;
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
socket.once('connect', function() {
|
2011-11-25 15:24:10 -08:00
|
|
|
|
sendClientReady(false);
|
|
|
|
|
});
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
socket.on('reconnect', function() {
|
|
|
|
|
// reconnect is before timeout, let´s stop the timeout
|
|
|
|
|
if (disconnectTimeout)
|
|
|
|
|
clearTimeout(disconnectTimeout);
|
|
|
|
|
pad.collabClient.setChannelState('CONNECTED');
|
2011-11-25 15:24:10 -08:00
|
|
|
|
sendClientReady(true);
|
|
|
|
|
});
|
2012-02-20 23:16:25 +01:00
|
|
|
|
|
|
|
|
|
socket.on('disconnect', function() {
|
|
|
|
|
function disconnectEvent() {
|
|
|
|
|
pad.collabClient.setChannelState('DISCONNECTED', 'reconnect_timeout');
|
2011-11-25 15:24:10 -08:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
pad.collabClient.setChannelState('RECONNECTING');
|
2011-11-25 15:24:10 -08:00
|
|
|
|
disconnectTimeout = setTimeout(disconnectEvent, 10000);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
});
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
var receivedClientVars = false,
|
|
|
|
|
initalized = false;
|
2011-07-07 18:59:34 +01:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
socket.on('message', function(obj) {
|
|
|
|
|
// access was not granted, give the user a message
|
|
|
|
|
if (!receivedClientVars && obj.accessStatus) {
|
|
|
|
|
if (obj.accessStatus == 'deny')
|
|
|
|
|
$('#editorloadingbox').html("<b>You do not have permission to access this pad</b>");
|
|
|
|
|
else if (obj.accessStatus == "needPassword") {
|
|
|
|
|
$('#editorloadingbox').html("<b>You need a password to access this pad</b><br>" +
|
2011-08-15 18:26:20 +01:00
|
|
|
|
"<input id='passwordinput' type='password' name='password'>"+
|
2012-01-15 21:37:47 -08:00
|
|
|
|
"<button type='button' onclick=\"" + padutils.escapeHtml('require('+JSON.stringify(module.id)+").savePassword()") + "\">ok</button>");
|
2012-02-20 23:16:25 +01:00
|
|
|
|
} else if (obj.accessStatus == 'wrongPassword') {
|
2011-08-15 18:26:20 +01:00
|
|
|
|
$("#editorloadingbox").html("<b>You're password was wrong</b><br>" +
|
|
|
|
|
"<input id='passwordinput' type='password' name='password'>"+
|
2012-01-15 21:37:47 -08:00
|
|
|
|
"<button type='button' onclick=\"" + padutils.escapeHtml('require('+JSON.stringify(module.id)+").savePassword()") + "\">ok</button>");
|
2011-08-15 18:26:20 +01:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
} else if (!receivedClientVars) { // if we haven't received the clientVars yet, then this message should it be
|
|
|
|
|
// log the message
|
|
|
|
|
if (window.console)
|
|
|
|
|
console.log(obj);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
|
|
|
|
|
receivedClientVars = true;
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// set some client vars
|
2011-07-07 18:59:34 +01:00
|
|
|
|
clientVars = obj;
|
2012-02-20 23:16:25 +01:00
|
|
|
|
clientVars.userAgent = 'Anonymous';
|
|
|
|
|
clientVars.collab_client_vars.clientAgent = 'Anonymous';
|
2011-07-07 18:59:34 +01:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// initalize the pad
|
2012-01-26 21:10:41 -08:00
|
|
|
|
pad._afterHandshake();
|
2011-07-07 18:59:34 +01:00
|
|
|
|
initalized = true;
|
2011-08-13 19:53:02 +01:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// if LineNumbersDisabled is set to true, we need to hide the line numbers
|
2012-01-15 18:22:28 -08:00
|
|
|
|
if (settings.LineNumbersDisabled == true)
|
2011-08-13 19:53:02 +01:00
|
|
|
|
pad.changeViewOption('showLineNumbers', false);
|
2011-09-04 13:48:53 +01:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// if noColors is set to true, we need to hide the backround colors on the ace spans
|
2012-01-15 18:22:28 -08:00
|
|
|
|
if (settings.noColors == true)
|
2011-09-04 13:48:53 +01:00
|
|
|
|
pad.changeViewOption('noColors', true);
|
2012-02-20 23:16:25 +01:00
|
|
|
|
|
2012-01-15 18:22:28 -08:00
|
|
|
|
if (settings.rtlIsTrue == true)
|
2011-12-04 18:55:35 +00:00
|
|
|
|
pad.changeViewOption('rtl', true);
|
2011-09-04 13:48:53 +01:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// if Monospacefont is set to true, change it to monospace
|
2012-01-15 18:22:28 -08:00
|
|
|
|
if (settings.useMonospaceFontGlobal == true)
|
2011-08-13 22:10:58 +01:00
|
|
|
|
pad.changeViewOption('useMonospaceFont', true);
|
2012-02-20 23:16:25 +01:00
|
|
|
|
|
|
|
|
|
// if globalUserName is set, tell the server and the client about the new authorname
|
|
|
|
|
if (settings.globalUserName !== false) {
|
|
|
|
|
pad.notifyChangeName(settings.globalUserName); // notify the server
|
2012-01-15 18:22:28 -08:00
|
|
|
|
pad.myUserInfo.name = settings.globalUserName;
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#myusernameedit').attr({"value":settings.globalUserName}); // update the current user´s UI
|
2011-08-13 19:53:02 +01:00
|
|
|
|
}
|
2011-07-07 18:59:34 +01:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// handle every message after the clientVars
|
|
|
|
|
else {
|
|
|
|
|
// advice the client to disconnect
|
|
|
|
|
if (obj.disconnect) {
|
2011-08-16 20:02:30 +01:00
|
|
|
|
padconnectionstatus.disconnected(obj.disconnect);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
socket.disconnect();
|
|
|
|
|
return;
|
2012-02-20 23:16:25 +01:00
|
|
|
|
} else {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
pad.collabClient.handleMessageFromServer(obj);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
}
|
2011-07-07 18:59:34 +01:00
|
|
|
|
}
|
|
|
|
|
});
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// bind the colorpicker
|
2011-08-20 18:22:10 +01:00
|
|
|
|
var fb = $('#colorpicker').farbtastic({ callback: '#mycolorpickerpreview', width: 220});
|
2011-03-26 13:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pad = {
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// don't access these directly from outside this file, except for debugging
|
|
|
|
|
collabClient : null,
|
|
|
|
|
myUserInfo : null,
|
|
|
|
|
diagnosticInfo : {},
|
|
|
|
|
initTime : 0,
|
|
|
|
|
clientTimeOffset : null,
|
|
|
|
|
preloadedImages : false,
|
|
|
|
|
padOptions : {},
|
2011-03-26 13:10:41 +00:00
|
|
|
|
// these don't require init; clientVars should all go through here
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getPadId : function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return clientVars.padId;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getClientIp : function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return clientVars.clientIp;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getIsProPad : function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return clientVars.isProPad;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getColorPalette : function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return clientVars.colorPalette;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getDisplayUserAgent: function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
return padutils.uaDisplay(clientVars.userAgent);
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getIsDebugEnabled : function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return clientVars.debugEnabled;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getPrivilege : function(name) {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return clientVars.accountPrivs[name];
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getUserIsGuest : function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return clientVars.userIsGuest;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getUserId : function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return pad.myUserInfo.userId;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getUserName : function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return pad.myUserInfo.name;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
sendClientMessage : function(msg) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.collabClient.sendClientMessage(msg);
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
init : function() {
|
2012-01-28 18:12:01 -08:00
|
|
|
|
padutils.setupGlobalExceptionHandler();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$(document).ready(function() {
|
2012-02-04 15:22:25 -08:00
|
|
|
|
// start the custom js
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (typeof customStart == 'function')
|
|
|
|
|
customStart();
|
2012-01-26 21:10:41 -08:00
|
|
|
|
getParams();
|
|
|
|
|
handshake();
|
|
|
|
|
});
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$(window).unload(function() {
|
2012-01-26 21:10:41 -08:00
|
|
|
|
pad.dispose();
|
|
|
|
|
});
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
_afterHandshake : function() {
|
2011-07-14 16:15:38 +01:00
|
|
|
|
pad.clientTimeOffset = new Date().getTime() - clientVars.serverTimestamp;
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// initialize the chat
|
2012-01-15 21:05:19 -08:00
|
|
|
|
chat.init(this);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.initTime = +(new Date());
|
|
|
|
|
pad.padOptions = clientVars.initialOptions;
|
|
|
|
|
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if ((!$.browser.msie) && (!($.browser.mozilla && $.browser.version.indexOf("1.8.") == 0)))
|
2011-03-26 13:10:41 +00:00
|
|
|
|
document.domain = document.domain; // for comet
|
|
|
|
|
|
|
|
|
|
// for IE
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if ($.browser.msie) {
|
|
|
|
|
try {
|
|
|
|
|
doc.execCommand('BackgroundImageCache', false, true);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
}
|
|
|
|
|
catch (e)
|
|
|
|
|
{}
|
2011-03-26 13:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// order of inits is important here:
|
2012-01-26 21:02:58 -08:00
|
|
|
|
padcookie.init(clientVars.cookiePrefsToSet, this);
|
2012-02-20 23:16:25 +01:00
|
|
|
|
|
|
|
|
|
$('#widthprefcheck').click(pad.toggleWidthPref);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
|
|
|
|
|
pad.myUserInfo = {
|
2012-02-20 23:16:25 +01:00
|
|
|
|
userId : clientVars.userId,
|
|
|
|
|
name : clientVars.userName,
|
|
|
|
|
ip : pad.getClientIp(),
|
|
|
|
|
colorId : clientVars.userColor,
|
|
|
|
|
userAgent : pad.getDisplayUserAgent()
|
2011-03-26 13:10:41 +00:00
|
|
|
|
};
|
2011-08-20 18:22:10 +01:00
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (clientVars.specialKey) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.myUserInfo.specialKey = clientVars.specialKey;
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (clientVars.specialKeyTranslation)
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#specialkeyarea').html('mode: ' + String(clientVars.specialKeyTranslation).toUpperCase());
|
2011-03-26 13:10:41 +00:00
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
paddocbar.init({
|
|
|
|
|
isTitleEditable : pad.getIsProPad(),
|
|
|
|
|
initialTitle : clientVars.initialTitle,
|
|
|
|
|
initialPassword : clientVars.initialPassword,
|
|
|
|
|
guestPolicy : pad.padOptions.guestPolicy
|
2012-01-26 21:02:58 -08:00
|
|
|
|
}, this);
|
|
|
|
|
padimpexp.init(this);
|
|
|
|
|
padsavedrevs.init(clientVars.initialRevisionList, this);
|
|
|
|
|
padeditor.init(postAceInit, pad.padOptions.view || {}, this);
|
|
|
|
|
paduserlist.init(pad.myUserInfo, this);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
// padchat.init(clientVars.chatHistory, pad.myUserInfo);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padconnectionstatus.init();
|
2012-01-26 21:02:58 -08:00
|
|
|
|
padmodals.init(this);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
pad.collabClient = getCollabClient(padeditor.ace, clientVars.collab_client_vars, pad.myUserInfo, {
|
|
|
|
|
colorPalette: pad.getColorPalette()
|
2012-01-17 00:43:11 -08:00
|
|
|
|
}, pad);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.collabClient.setOnUserJoin(pad.handleUserJoin);
|
|
|
|
|
pad.collabClient.setOnUpdateUserInfo(pad.handleUserUpdate);
|
|
|
|
|
pad.collabClient.setOnUserLeave(pad.handleUserLeave);
|
|
|
|
|
pad.collabClient.setOnClientMessage(pad.handleClientMessage);
|
|
|
|
|
pad.collabClient.setOnServerMessage(pad.handleServerMessage);
|
|
|
|
|
pad.collabClient.setOnChannelStateChange(pad.handleChannelStateChange);
|
|
|
|
|
pad.collabClient.setOnInternalAction(pad.handleCollabAction);
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
function postAceInit() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padeditbar.init();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
setTimeout(function() {padeditor.ace.focus();}, 0);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
dispose: function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padeditor.dispose();
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
notifyChangeName: function(newName) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.myUserInfo.name = newName;
|
|
|
|
|
pad.collabClient.updateUserInfo(pad.myUserInfo);
|
2011-03-27 10:06:16 +00:00
|
|
|
|
//padchat.handleUserJoinOrUpdate(pad.myUserInfo);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
notifyChangeColor: function(newColorId) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.myUserInfo.colorId = newColorId;
|
|
|
|
|
pad.collabClient.updateUserInfo(pad.myUserInfo);
|
2011-03-27 10:06:16 +00:00
|
|
|
|
//padchat.handleUserJoinOrUpdate(pad.myUserInfo);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
notifyChangeTitle: function(newTitle) {
|
|
|
|
|
pad.collabClient.sendClientMessage({
|
|
|
|
|
type : 'padtitle',
|
|
|
|
|
title : newTitle,
|
|
|
|
|
changedBy : pad.myUserInfo.name || 'unnamed'
|
2011-03-26 13:10:41 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
notifyChangePassword: function(newPass) {
|
|
|
|
|
pad.collabClient.sendClientMessage({
|
|
|
|
|
type : 'padpassword',
|
|
|
|
|
password : newPass,
|
|
|
|
|
changedBy : pad.myUserInfo.name || 'unnamed'
|
2011-03-26 13:10:41 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
changePadOption: function(key, value) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
var options = {};
|
|
|
|
|
options[key] = value;
|
|
|
|
|
pad.handleOptionsChange(options);
|
2012-02-20 23:16:25 +01:00
|
|
|
|
pad.collabClient.sendClientMessage({
|
|
|
|
|
type : 'padoptions',
|
|
|
|
|
options : options,
|
|
|
|
|
changedBy : pad.myUserInfo.name || 'unnamed'
|
2011-03-26 13:10:41 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
changeViewOption: function(key, value) {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
var options = {
|
|
|
|
|
view: {}
|
|
|
|
|
};
|
2011-03-26 13:10:41 +00:00
|
|
|
|
options.view[key] = value;
|
|
|
|
|
pad.handleOptionsChange(options);
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleOptionsChange: function(opts) {
|
|
|
|
|
// opts object is a full set of options or just some options to change
|
|
|
|
|
if (opts.view) {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (!pad.padOptions.view)
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.padOptions.view = {};
|
2012-02-20 23:16:25 +01:00
|
|
|
|
for (var k in opts.view) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.padOptions.view[k] = opts.view[k];
|
|
|
|
|
}
|
|
|
|
|
padeditor.setViewOptions(pad.padOptions.view);
|
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (opts.guestPolicy) {
|
|
|
|
|
// order is important here:
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.padOptions.guestPolicy = opts.guestPolicy;
|
|
|
|
|
paddocbar.setGuestPolicy(opts.guestPolicy);
|
|
|
|
|
}
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getPadOptions: function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
// caller shouldn't mutate the object
|
|
|
|
|
return pad.padOptions;
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
isPadPublic: function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
return (!pad.getIsProPad()) || (pad.getPadOptions().guestPolicy == 'allow');
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
suggestUserName: function(userId, name) {
|
|
|
|
|
pad.collabClient.sendClientMessage({
|
|
|
|
|
type : 'suggestUserName',
|
|
|
|
|
unnamedId : userId,
|
|
|
|
|
newName : name
|
2011-03-26 13:10:41 +00:00
|
|
|
|
});
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleUserJoin: function(userInfo) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
paduserlist.userJoinOrUpdate(userInfo);
|
2011-03-27 10:06:16 +00:00
|
|
|
|
//padchat.handleUserJoinOrUpdate(userInfo);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleUserUpdate: function(userInfo) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
paduserlist.userJoinOrUpdate(userInfo);
|
2011-03-27 10:06:16 +00:00
|
|
|
|
//padchat.handleUserJoinOrUpdate(userInfo);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleUserLeave: function(userInfo) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
paduserlist.userLeave(userInfo);
|
2011-03-27 10:06:16 +00:00
|
|
|
|
//padchat.handleUserLeave(userInfo);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleClientMessage: function(msg) {
|
|
|
|
|
switch (msg.type) {
|
|
|
|
|
case 'suggestUserName':
|
|
|
|
|
if (msg.unnamedId == pad.myUserInfo.userId && msg.newName && !pad.myUserInfo.name) {
|
|
|
|
|
pad.notifyChangeName(msg.newName);
|
|
|
|
|
paduserlist.setMyUserInfo(pad.myUserInfo);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'chat':
|
|
|
|
|
// padchat.receiveChat(msg);
|
|
|
|
|
break;
|
|
|
|
|
case 'padtitle':
|
|
|
|
|
paddocbar.changeTitle(msg.title);
|
|
|
|
|
break;
|
|
|
|
|
case 'padpassword':
|
|
|
|
|
paddocbar.changePassword(msg.password);
|
|
|
|
|
break;
|
|
|
|
|
case 'newRevisionList':
|
|
|
|
|
padsavedrevs.newRevisionList(msg.revisionList);
|
|
|
|
|
break;
|
|
|
|
|
case 'revisionLabel':
|
|
|
|
|
padsavedrevs.newRevisionList(msg.revisionList);
|
|
|
|
|
break;
|
|
|
|
|
case 'padoptions':
|
|
|
|
|
var opts = msg.options;
|
|
|
|
|
pad.handleOptionsChange(opts);
|
|
|
|
|
break;
|
|
|
|
|
case 'guestanswer':
|
|
|
|
|
// someone answered a prompt, remove it
|
|
|
|
|
paduserlist.removeGuestPrompt(msg.guestId);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
editbarClick: function(cmd) {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (padeditbar)
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padeditbar.toolbarClick(cmd);
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
dmesg: function(m) {
|
|
|
|
|
if (pad.getIsDebugEnabled()) {
|
|
|
|
|
var djs = $('#djs').get(0),
|
|
|
|
|
wasAtBottom = (djs.scrollTop - (djs.scrollHeight - $(djs).height()) >= -20);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
$('#djs').append('<p>' + m + '</p>');
|
|
|
|
|
if (wasAtBottom)
|
2011-03-26 13:10:41 +00:00
|
|
|
|
djs.scrollTop = djs.scrollHeight;
|
|
|
|
|
}
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleServerMessage: function(m) {
|
|
|
|
|
if (m.type == 'NOTICE') {
|
|
|
|
|
if (m.text) {
|
|
|
|
|
alertBar.displayMessage(function(abar) {
|
|
|
|
|
abar.find('#servermsgdate').html(' (' + padutils.simpleDateTime(new Date) + ')');
|
|
|
|
|
abar.find('#servermsgtext').html(m.text);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (m.js)
|
|
|
|
|
window['ev' + 'al'](m.js);
|
2012-02-20 23:16:25 +01:00
|
|
|
|
} else if (m.type == 'GUEST_PROMPT') {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
paduserlist.showGuestPrompt(m.userId, m.displayName);
|
|
|
|
|
}
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleChannelStateChange: function(newState, message) {
|
|
|
|
|
var oldFullyConnected = !! padconnectionstatus.isFullyConnected(),
|
|
|
|
|
wasConnecting = (padconnectionstatus.getStatus().what == 'connecting');
|
|
|
|
|
if (newState == 'CONNECTED')
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padconnectionstatus.connected();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
else if (newState == 'RECONNECTING')
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padconnectionstatus.reconnecting();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
else if (newState == 'DISCONNECTED') {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.diagnosticInfo.disconnectedMessage = message;
|
2011-11-25 15:24:10 -08:00
|
|
|
|
pad.diagnosticInfo.padId = pad.getPadId();
|
|
|
|
|
pad.diagnosticInfo.socket = {};
|
2012-02-20 23:16:25 +01:00
|
|
|
|
// we filter non objects from the socket object and put them in the diagnosticInfo
|
|
|
|
|
// this ensures we have no cyclic data - this allows us to stringify the data
|
|
|
|
|
for (var i in socket.socket) {
|
|
|
|
|
var value = socket.socket[i],
|
|
|
|
|
type = typeof value;
|
|
|
|
|
if (type == 'string' || type == 'number')
|
2011-11-25 15:24:10 -08:00
|
|
|
|
pad.diagnosticInfo.socket[i] = value;
|
|
|
|
|
}
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.asyncSendDiagnosticInfo();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (typeof window.ajlog == 'string')
|
|
|
|
|
window.ajlog += ('Disconnected: ' + message + '\n');
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padeditor.disable();
|
|
|
|
|
padeditbar.disable();
|
|
|
|
|
paddocbar.disable();
|
|
|
|
|
padimpexp.disable();
|
|
|
|
|
padconnectionstatus.disconnected(message);
|
|
|
|
|
}
|
|
|
|
|
var newFullyConnected = !! padconnectionstatus.isFullyConnected();
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (newFullyConnected != oldFullyConnected)
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.handleIsFullyConnected(newFullyConnected, wasConnecting);
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleIsFullyConnected: function(isConnected, isInitialConnect) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
// load all images referenced from CSS, one at a time,
|
|
|
|
|
// starting one second after connection is first established.
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (isConnected && !pad.preloadedImages) {
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
|
if (!pad.preloadedImages) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.preloadImages();
|
|
|
|
|
pad.preloadedImages = true;
|
|
|
|
|
}
|
|
|
|
|
}, 1000);
|
|
|
|
|
}
|
|
|
|
|
padsavedrevs.handleIsFullyConnected(isConnected);
|
2012-01-28 22:24:14 +00:00
|
|
|
|
// pad.determineSidebarVisibility(isConnected && !isInitialConnect);
|
|
|
|
|
pad.determineChatVisibility(isConnected && !isInitialConnect);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
},
|
2012-01-28 22:24:14 +00:00
|
|
|
|
/* determineSidebarVisibility: function(asNowConnectedFeedback)
|
2011-07-07 18:59:34 +01:00
|
|
|
|
{
|
|
|
|
|
if (pad.isFullyConnected())
|
|
|
|
|
{
|
|
|
|
|
var setSidebarVisibility = padutils.getCancellableAction("set-sidebar-visibility", function()
|
|
|
|
|
{
|
2012-01-28 22:24:14 +00:00
|
|
|
|
// $("body").toggleClass('hidesidebar', !! padcookie.getPref('hideSidebar'));
|
2011-07-07 18:59:34 +01:00
|
|
|
|
});
|
|
|
|
|
window.setTimeout(setSidebarVisibility, asNowConnectedFeedback ? 3000 : 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padutils.cancelActions("set-sidebar-visibility");
|
|
|
|
|
$("body").removeClass('hidesidebar');
|
|
|
|
|
}
|
|
|
|
|
},
|
2012-01-28 22:24:14 +00:00
|
|
|
|
*/
|
2012-02-20 23:16:25 +01:00
|
|
|
|
determineChatVisibility: function(asNowConnectedFeedback) {
|
2012-01-28 22:24:14 +00:00
|
|
|
|
var chatVisCookie = padcookie.getPref('chatAlwaysVisible');
|
2012-02-20 23:16:25 +01:00
|
|
|
|
if (chatVisCookie) { // if the cookie is set for chat always visible
|
|
|
|
|
chat.stickToScreen(true); // stick chat to the screen
|
|
|
|
|
$('#options-stickychat').prop('checked', true); // set the checkbox to on
|
|
|
|
|
} else {
|
|
|
|
|
$('#options-stickychat').prop('checked', false); // set the checkbox for off
|
2012-01-28 22:24:14 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleCollabAction: function(action) {
|
|
|
|
|
if (action == 'commitPerformed')
|
|
|
|
|
padeditbar.setSyncStatus('syncing');
|
|
|
|
|
else if (action == 'newlyIdle')
|
|
|
|
|
padeditbar.setSyncStatus('done');
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
hideServerMessage: function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
alertBar.hideMessage();
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
asyncSendDiagnosticInfo: function() {
|
|
|
|
|
window.setTimeout(function() {
|
|
|
|
|
$.post({
|
|
|
|
|
url : '/ep/pad/connection-diagnostic-info',
|
|
|
|
|
data: {diagnosticInfo: JSON.stringify(pad.diagnosticInfo)}
|
2011-03-26 13:10:41 +00:00
|
|
|
|
});
|
|
|
|
|
}, 0);
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
forceReconnect: function() {
|
|
|
|
|
$('#reconnectform .padId').val(pad.getPadId());
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.diagnosticInfo.collabDiagnosticInfo = pad.collabClient.getDiagnosticInfo();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#reconnectform .diagnosticInfo').val(JSON.stringify(pad.diagnosticInfo));
|
|
|
|
|
$('#reconnectform .missedChanges').val(JSON.stringify(pad.collabClient.getMissedChanges()));
|
|
|
|
|
$('#reconnectform').submit();
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
toggleWidthPref: function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
var newValue = !padcookie.getPref('fullWidth');
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padcookie.setPref('fullWidth', newValue);
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#widthprefcheck').toggleClass('widthprefchecked', !! newValue).toggleClass('widthprefunchecked', !newValue);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.handleWidthChange();
|
|
|
|
|
},
|
2012-01-28 22:24:14 +00:00
|
|
|
|
/*
|
2011-07-07 18:59:34 +01:00
|
|
|
|
toggleSidebar: function()
|
|
|
|
|
{
|
|
|
|
|
var newValue = !padcookie.getPref('hideSidebar');
|
2011-03-26 13:10:41 +00:00
|
|
|
|
padcookie.setPref('hideSidebar', newValue);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
$("#sidebarcheck").toggleClass('sidebarchecked', !newValue).toggleClass('sidebarunchecked', !! newValue);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.determineSidebarVisibility();
|
|
|
|
|
},
|
2012-01-28 22:24:14 +00:00
|
|
|
|
*/
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleWidthChange: function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
var isFullWidth = padcookie.getPref('fullWidth');
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (isFullWidth)
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('BODY').addClass('fullwidth').removeClass('limwidth squish1width squish2width');
|
|
|
|
|
else {
|
|
|
|
|
$('BODY').addClass('limwidth').removeClass('fullwidth');
|
2011-03-26 13:10:41 +00:00
|
|
|
|
var pageWidth = $(window).width();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('BODY').toggleClass('squish1width', (pageWidth < 912 && pageWidth > 812)).toggleClass('squish2width', (pageWidth <= 812));
|
2011-03-26 13:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// this is called from code put into a frame from the server:
|
2012-02-20 23:16:25 +01:00
|
|
|
|
handleImportExportFrameCall: function(callName, varargs) {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
padimpexp.handleFrameCall.call(padimpexp, callName, Array.prototype.slice.call(arguments, 1));
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
callWhenNotCommitting: function(f) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.collabClient.callWhenNotCommitting(f);
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
getCollabRevisionNumber: function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
return pad.collabClient.getCurrentRevisionNumber();
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
isFullyConnected: function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
return padconnectionstatus.isFullyConnected();
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
addHistoricalAuthors: function(data) {
|
|
|
|
|
if (!pad.collabClient) {
|
|
|
|
|
window.setTimeout(function() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
pad.addHistoricalAuthors(data);
|
|
|
|
|
}, 1000);
|
2012-02-20 23:16:25 +01:00
|
|
|
|
} else {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
pad.collabClient.addHistoricalAuthors(data);
|
|
|
|
|
}
|
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
preloadImages: function() {
|
2011-11-25 15:24:10 -08:00
|
|
|
|
var images = ["../static/img/connectingbar.gif"];
|
2012-02-20 23:16:25 +01:00
|
|
|
|
function loadNextImage() {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (images.length == 0)
|
2011-03-26 13:10:41 +00:00
|
|
|
|
return;
|
|
|
|
|
var img = new Image();
|
|
|
|
|
img.src = images.shift();
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (img.complete)
|
2011-03-26 13:10:41 +00:00
|
|
|
|
scheduleLoadNextImage();
|
2011-07-07 18:59:34 +01:00
|
|
|
|
else
|
2011-03-26 13:10:41 +00:00
|
|
|
|
$(img).bind('error load onreadystatechange', scheduleLoadNextImage);
|
|
|
|
|
}
|
2012-02-20 23:16:25 +01:00
|
|
|
|
function scheduleLoadNextImage() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
window.setTimeout(loadNextImage, 0);
|
|
|
|
|
}
|
|
|
|
|
scheduleLoadNextImage();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
var alertBar = (function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
var animator = padutils.makeShowHideAnimator(arriveAtAnimationState, false, 25, 400);
|
2012-02-20 23:16:25 +01:00
|
|
|
|
function arriveAtAnimationState(state) {
|
2011-07-07 18:59:34 +01:00
|
|
|
|
if (state == -1)
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#alertbar').css('opacity', 0).css('display', 'block');
|
2011-07-07 18:59:34 +01:00
|
|
|
|
else if (state == 0)
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#alertbar').css('opacity', 1);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
else if (state == 1)
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#alertbar').css('opacity', 0).css('display', 'none');
|
2011-07-07 18:59:34 +01:00
|
|
|
|
else if (state < 0)
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#alertbar').css('opacity', state + 1);
|
2011-07-07 18:59:34 +01:00
|
|
|
|
else if (state > 0)
|
2012-02-20 23:16:25 +01:00
|
|
|
|
$('#alertbar').css('opacity', 1 - state);
|
2011-03-26 13:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
var self = {
|
2012-02-20 23:16:25 +01:00
|
|
|
|
displayMessage: function(setupFunc) {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
animator.show();
|
2012-02-20 23:16:25 +01:00
|
|
|
|
setupFunc($('#alertbar'));
|
2011-03-26 13:10:41 +00:00
|
|
|
|
},
|
2012-02-20 23:16:25 +01:00
|
|
|
|
hideMessage: function() {
|
2011-03-26 13:10:41 +00:00
|
|
|
|
animator.hide();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
return self;
|
|
|
|
|
}());
|
2012-01-15 17:23:48 -08:00
|
|
|
|
|
2012-01-26 21:10:41 -08:00
|
|
|
|
function init() {
|
|
|
|
|
return pad.init();
|
|
|
|
|
}
|
2012-01-26 21:40:13 -08:00
|
|
|
|
|
|
|
|
|
var settings = {
|
2012-02-20 23:16:25 +01:00
|
|
|
|
LineNumbersDisabled : false,
|
|
|
|
|
noColors : false,
|
|
|
|
|
useMonospaceFontGlobal: false,
|
|
|
|
|
globalUserName : false,
|
|
|
|
|
hideQRCode : false,
|
|
|
|
|
rtlIsTrue : false
|
2012-01-26 21:40:13 -08:00
|
|
|
|
};
|
|
|
|
|
|
2012-02-20 23:16:25 +01:00
|
|
|
|
pad.settings = settings;
|
|
|
|
|
exports.settings = settings;
|
|
|
|
|
exports.createCookie = createCookie;
|
|
|
|
|
exports.readCookie = readCookie;
|
|
|
|
|
exports.randomString = randomString;
|
|
|
|
|
exports.getParams = getParams;
|
|
|
|
|
exports.getUrlVars = getUrlVars;
|
|
|
|
|
exports.savePassword = savePassword;
|
|
|
|
|
exports.handshake = handshake;
|
|
|
|
|
exports.pad = pad;
|
|
|
|
|
exports.init = init;
|
|
|
|
|
exports.alertBar = alertBar;
|