Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page initialization #371

Merged
merged 9 commits into from
Jan 30, 2012
5 changes: 0 additions & 5 deletions node/utils/Minify.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,6 @@ function tarCode(filesInOrder, files, write) {
write("\n\n\n/*** File: static/js/" + filename + " ***/\n\n\n");
write(isolateJS(files[filename], filename));
}

for(var i = 0, ii = filesInOrder.length; i < filesInOrder.length; i++) {
var filename = filesInOrder[i];
write('require(' + JSON.stringify('/' + filename.replace(/^\/+/, '')) + ');\n');
}
}

// Wrap the following code in a self executing function and assign exports to
Expand Down
3 changes: 2 additions & 1 deletion node/utils/tar.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"pad.js": [
"jquery.js"
, "pad.js"
, "ace2_common.js"
, "pad_utils.js"
, "plugins.js"
Expand All @@ -17,7 +18,6 @@
, "pad_impexp.js"
, "pad_savedrevs.js"
, "pad_connectionstatus.js"
, "pad2.js"
, "jquery-ui.js"
, "chat.js"
, "excanvas.js"
Expand Down Expand Up @@ -46,5 +46,6 @@
, "broadcast.js"
, "broadcast_slider.js"
, "broadcast_revisions.js"
, "timeslider.js"
]
}
11 changes: 7 additions & 4 deletions static/js/broadcast.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@
* limitations under the License.
*/

var global = this;

var makeCSSManager = require('/cssmanager_client').makeCSSManager;
var domline = require('/domline_client').domline;
var Changeset = require('/easysync2_client').Changeset;
var AttribPool = require('/easysync2_client').AttribPool;
var linestylefilter = require('/linestylefilter_client').linestylefilter;

function loadBroadcastJS()
// These parameters were global, now they are injected. A reference to the
// Timeslider controller would probably be more appropriate.
function loadBroadcastJS(socket, sendSocketMsg, fireWhenAllScriptsAreLoaded, BroadcastSlider)
{
var changesetLoader = undefined;
// just in case... (todo: this must be somewhere else in the client code.)
// Below Array#map code was direct pasted by AppJet/Etherpad, licence unknown. Possible source: http://www.tutorialspoint.com/javascript/array_map.htm
if (!Array.prototype.map)
Expand Down Expand Up @@ -423,7 +424,7 @@ function loadBroadcastJS()
}));
}

global.changesetLoader = {
changesetLoader = {
running: false,
resolved: [],
requestQueue1: [],
Expand Down Expand Up @@ -763,6 +764,8 @@ function loadBroadcastJS()
}

receiveAuthorData(clientVars.historicalAuthorData);

return changesetLoader;
}

exports.loadBroadcastJS = loadBroadcastJS;
1 change: 0 additions & 1 deletion static/js/broadcast_revisions.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
// revision info is a skip list whos entries represent a particular revision
// of the document. These revisions are connected together by various
// changesets, or deltas, between any two revisions.
var global = this;

function loadBroadcastRevisionsJS()
{
Expand Down
10 changes: 7 additions & 3 deletions static/js/broadcast_slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var global = this;

function loadBroadcastSliderJS()
// These parameters were global, now they are injected. A reference to the
// Timeslider controller would probably be more appropriate.
function loadBroadcastSliderJS(fireWhenAllScriptsAreLoaded)
{
var BroadcastSlider;

(function()
{ // wrap this code in its own namespace
Expand Down Expand Up @@ -203,7 +205,7 @@ function loadBroadcastSliderJS()
}
}

global.BroadcastSlider = {
BroadcastSlider = {
onSlider: onSlider,
getSliderPosition: getSliderPosition,
setSliderPosition: setSliderPosition,
Expand Down Expand Up @@ -495,6 +497,8 @@ function loadBroadcastSliderJS()
{
$("#viewlatest").html(loc == BroadcastSlider.getSliderLength() ? "Viewing latest content" : "View latest content");
})

return BroadcastSlider;
}

exports.loadBroadcastSliderJS = loadBroadcastSliderJS;
77 changes: 49 additions & 28 deletions static/js/pad2.js → static/js/pad.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@

var socket;

var settings = {};
settings.LineNumbersDisabled = false;
settings.noColors = false;
settings.useMonospaceFontGlobal = false;
settings.globalUserName = false;
settings.hideQRCode = false;
settings.rtlIsTrue = false;
// These jQuery things should create local references, but for now `require()`
// assigns to the global `$` and augments it with plugins.
require('/jquery');
require('/jquery-ui');
require('/farbtastic');
require('/excanvas');
require('/json2');
require('/undo-xpopup');

var chat = require('/chat').chat;
var getCollabClient = require('/collab_client').getCollabClient;
Expand All @@ -45,19 +46,6 @@ var padsavedrevs = require('/pad_savedrevs').padsavedrevs;
var paduserlist = require('/pad_userlist').paduserlist;
var padutils = require('/pad_utils').padutils;

$(document).ready(function()
{
//start the costum js
if(typeof costumStart == "function") costumStart();
getParams();
handshake();
});

$(window).unload(function()
{
pad.dispose();
});

function createCookie(name, value, days, path)
{
if (days)
Expand Down Expand Up @@ -309,7 +297,7 @@ function handshake()
clientVars.collab_client_vars.clientAgent = "Anonymous";

//initalize the pad
pad.init();
pad._afterHandshake();
initalized = true;

// If the LineNumbersDisabled value is set to true then we need to hide the Line Numbers
Expand Down Expand Up @@ -421,6 +409,23 @@ var pad = {
},

init: function()
{
padutils.setupGlobalExceptionHandler();

$(document).ready(function()
{
//start the costum js
if(typeof costumStart == "function") costumStart();
getParams();
handshake();
});

$(window).unload(function()
{
pad.dispose();
});
},
_afterHandshake: function()
{
pad.clientTimeOffset = new Date().getTime() - clientVars.serverTimestamp;

Expand All @@ -446,7 +451,7 @@ var pad = {
}

// order of inits is important here:
padcookie.init(clientVars.cookiePrefsToSet);
padcookie.init(clientVars.cookiePrefsToSet, this);

$("#widthprefcheck").click(pad.toggleWidthPref);
// $("#sidebarcheck").click(pad.togglewSidebar);
Expand All @@ -473,16 +478,16 @@ var pad = {
initialTitle: clientVars.initialTitle,
initialPassword: clientVars.initialPassword,
guestPolicy: pad.padOptions.guestPolicy
});
padimpexp.init();
padsavedrevs.init(clientVars.initialRevisionList);
}, this);
padimpexp.init(this);
padsavedrevs.init(clientVars.initialRevisionList, this);

padeditor.init(postAceInit, pad.padOptions.view || {});
padeditor.init(postAceInit, pad.padOptions.view || {}, this);

paduserlist.init(pad.myUserInfo);
paduserlist.init(pad.myUserInfo, this);
// padchat.init(clientVars.chatHistory, pad.myUserInfo);
padconnectionstatus.init();
padmodals.init();
padmodals.init(this);

pad.collabClient = getCollabClient(padeditor.ace, clientVars.collab_client_vars, pad.myUserInfo, {
colorPalette: pad.getColorPalette()
Expand Down Expand Up @@ -981,6 +986,21 @@ var alertBar = (function()
return self;
}());

function init() {
return pad.init();
}

var settings = {
LineNumbersDisabled: false
, noColors: false
, useMonospaceFontGlobal: false
, globalUserName: false
, hideQRCode: false
, rtlIsTrue: false
};

pad.settings = settings;

exports.settings = settings;
exports.createCookie = createCookie;
exports.readCookie = readCookie;
Expand All @@ -990,4 +1010,5 @@ exports.getUrlVars = getUrlVars;
exports.savePassword = savePassword;
exports.handshake = handshake;
exports.pad = pad;
exports.init = init;
exports.alertBar = alertBar;
4 changes: 2 additions & 2 deletions static/js/pad_cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ var padcookie = (function()

var pad = undefined;
var self = {
init: function(prefsToSet)
init: function(prefsToSet, _pad)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
pad = _pad;

var rawCookie = getRawCookie();
if (rawCookie)
Expand Down
4 changes: 2 additions & 2 deletions static/js/pad_docbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ var paddocbar = (function()
var self = {
title: null,
password: null,
init: function(opts)
init: function(opts, _pad)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
pad = _pad;

panels = {
impexp: {
Expand Down
6 changes: 3 additions & 3 deletions static/js/pad_editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ var padeditor = (function()
ace: null,
// this is accessed directly from other files
viewZoom: 100,
init: function(readyFunc, initialViewOptions)
init: function(readyFunc, initialViewOptions, _pad)
{
Ace2Editor = require('/ace').Ace2Editor;
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
settings = require('/pad2').settings;
pad = _pad;
settings = pad.settings;

function aceReady()
{
Expand Down
8 changes: 2 additions & 6 deletions static/js/pad_impexp.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,9 @@ var padimpexp = (function()
/////
var pad = undefined;
var self = {
init: function()
init: function(_pad)
{
try {
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
} catch (e) {
// skip (doesn't require pad when required by timeslider)
}
pad = _pad;

//get /p/padname
var pad_root_path = new RegExp(/.*\/p\/[^\/]+/).exec(document.location.pathname)
Expand Down
4 changes: 2 additions & 2 deletions static/js/pad_modals.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ var padmodals = (function()

var pad = undefined;
var self = {
init: function()
init: function(_pad)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
pad = _pad;

self.initFeedback();
self.initShareBox();
Expand Down
4 changes: 2 additions & 2 deletions static/js/pad_savedrevs.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ var padsavedrevs = (function()

var pad = undefined;
var self = {
init: function(initialRevisions)
init: function(initialRevisions, _pad)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
pad = _pad;
self.newRevisionList(initialRevisions, true);

$("#savedrevs-savenow").click(function()
Expand Down
4 changes: 2 additions & 2 deletions static/js/pad_userlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,9 @@ var paduserlist = (function()

var pad = undefined;
var self = {
init: function(myInitialUserInfo)
init: function(myInitialUserInfo, _pad)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
pad = _pad;

self.setMyUserInfo(myInitialUserInfo);

Expand Down
30 changes: 19 additions & 11 deletions static/js/pad_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var padutils = {
},
uniqueId: function()
{
var pad = require('/pad2').pad; // Sidestep circular dependency
var pad = require('/pad').pad; // Sidestep circular dependency
function encodeNum(n, width)
{
// returns string that is exactly 'width' chars, padding with zeros
Expand Down Expand Up @@ -209,7 +209,7 @@ var padutils = {
},
timediff: function(d)
{
var pad = require('/pad2').pad; // Sidestep circular dependency
var pad = require('/pad').pad; // Sidestep circular dependency
function format(n, word)
{
n = Math.round(n);
Expand Down Expand Up @@ -459,17 +459,25 @@ var padutils = {
}
};

//send javascript errors to the server
window.onerror = function test (msg, url, linenumber)
{
var errObj = {errorInfo: JSON.stringify({msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})};
var loc = document.location;
var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror";
var globalExceptionHandler = undefined;
function setupGlobalExceptionHandler() {
//send javascript errors to the server
if (!globalExceptionHandler) {
globalExceptionHandler = function test (msg, url, linenumber)
{
var errObj = {errorInfo: JSON.stringify({msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})};
var loc = document.location;
var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror";

$.post(url, errObj);
$.post(url, errObj);

return false;
};
return false;
};
window.onerror = globalExceptionHandler;
}
}

padutils.setupGlobalExceptionHandler = setupGlobalExceptionHandler;

padutils.binarySearch = require('/ace2_common').binarySearch;

Expand Down
Loading