Implement `require` of dependencies for all `pad_*` modules.

Create a lazily-defined local reference for pad on initialization in each pad module in order to avoid circular dependency. At some point in the future this dependency should instead be injected into each module on initialization.
pull/343/head
Chad Weider 2012-01-15 21:37:47 -08:00
parent 7f98116a43
commit fa2a6e9ee6
11 changed files with 62 additions and 5 deletions

View File

@ -34,6 +34,16 @@ settings.rtlIsTrue = false;
var chat = require('/chat').chat;
var getCollabClient = require('/collab_client').getCollabClient;
var padconnectionstatus = require('/pad_connectionstatus').padconnectionstatus;
var padcookie = require('/pad_cookie').padcookie;
var paddocbar = require('/pad_docbar').paddocbar;
var padeditbar = require('/pad_editbar').padeditbar;
var padeditor = require('/pad_editor').padeditor;
var padimpexp = require('/pad_impexp').padimpexp;
var padmodals = require('/pad_modals').padmodals;
var padsavedrevs = require('/pad_savedrevs').padsavedrevs;
var paduserlist = require('/pad_userlist').paduserlist;
var padutils = require('/pad_utils').padutils;
$(document).ready(function()
{
@ -275,13 +285,13 @@ function handshake()
{
$("#editorloadingbox").html("<b>You need a password to access this pad</b><br>" +
"<input id='passwordinput' type='password' name='password'>"+
"<button type='button' onclick='savePassword()'>ok</button>");
"<button type='button' onclick=\"" + padutils.escapeHtml('require('+JSON.stringify(module.id)+").savePassword()") + "\">ok</button>");
}
else if(obj.accessStatus == "wrongPassword")
{
$("#editorloadingbox").html("<b>You're password was wrong</b><br>" +
"<input id='passwordinput' type='password' name='password'>"+
"<button type='button' onclick='savePassword()'>ok</button>");
"<button type='button' onclick=\"" + padutils.escapeHtml('require('+JSON.stringify(module.id)+").savePassword()") + "\">ok</button>");
}
}

View File

@ -20,6 +20,8 @@
* limitations under the License.
*/
var padmodals = require('/pad_modals').padmodals;
var padconnectionstatus = (function()
{

View File

@ -85,9 +85,12 @@ var padcookie = (function()
var alreadyWarnedAboutNoCookies = false;
var inited = false;
var pad = undefined;
var self = {
init: function(prefsToSet)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
var rawCookie = getRawCookie();
if (rawCookie)
{

View File

@ -20,6 +20,7 @@
* limitations under the License.
*/
var padutils = require('/pad_utils').padutils;
var paddocbar = (function()
{
@ -113,11 +114,14 @@ var paddocbar = (function()
self.renderPassword();
}
var pad = undefined;
var self = {
title: null,
password: null,
init: function(opts)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
panels = {
impexp: {
animator: getPanelOpenCloseAnimator("impexp", 160)
@ -444,6 +448,8 @@ var paddocbar = (function()
},
handleResizePage: function()
{
// Side-step circular reference. This should be injected.
var padsavedrevs = require('/pad_savedrevs').padsavedrevs;
padsavedrevs.handleResizePage();
},
hideLaterIfNoOtherInteraction: function()

View File

@ -20,6 +20,10 @@
* limitations under the License.
*/
var padutils = require('/pad_utils').padutils;
var padeditor = require('/pad_editor').padeditor;
var padsavedrevs = require('/pad_savedrevs').padsavedrevs;
var padeditbar = (function()
{

View File

@ -20,16 +20,23 @@
* limitations under the License.
*/
var Ace2Editor = require('/ace').Ace2Editor;
var padcookie = require('/pad_cookie').padcookie;
var padutils = require('/pad_utils').padutils;
var padeditor = (function()
{
var Ace2Editor = undefined;
var pad = undefined;
var settings = undefined;
var self = {
ace: null,
// this is accessed directly from other files
viewZoom: 100,
init: function(readyFunc, initialViewOptions)
{
Ace2Editor = require('/ace').Ace2Editor;
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
settings = require('/pad2').settings;
function aceReady()
{

View File

@ -20,6 +20,7 @@
* limitations under the License.
*/
var paddocbar = require('/pad_docbar').paddocbar;
var padimpexp = (function()
{
@ -233,9 +234,16 @@ var padimpexp = (function()
}
/////
var pad = undefined;
var self = {
init: function()
{
try {
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
} catch (e) {
// skip (doesn't require pad when required by timeslider)
}
//get /p/padname
var pad_root_path = new RegExp(/.*\/p\/[^\/]+/).exec(document.location.pathname)
//get http://example.com/p/padname

View File

@ -20,6 +20,9 @@
* limitations under the License.
*/
var padutils = require('/pad_utils').padutils;
var paddocbar = require('/pad_docbar').paddocbar;
var padmodals = (function()
{
@ -70,9 +73,12 @@ var padmodals = (function()
clearShareBoxTo();
}
var pad = undefined;
var self = {
init: function()
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
self.initFeedback();
self.initShareBox();
},

View File

@ -20,6 +20,8 @@
* limitations under the License.
*/
var padutils = require('/pad_utils').padutils;
var paddocbar = require('/pad_docbar').paddocbar;
var padsavedrevs = (function()
{
@ -39,7 +41,7 @@ var padsavedrevs = (function()
box.find(".srauthor").html("by " + padutils.escapeHtml(revisionInfo.savedBy));
var viewLink = '/ep/pad/view/' + pad.getPadId() + '/' + revisionInfo.id;
box.find(".srview").attr('href', viewLink);
var restoreLink = 'javascript:void padsavedrevs.restoreRevision(' + rnum + ');';
var restoreLink = 'javascript:void(require('+JSON.stringify(module.id)+').padsavedrevs.restoreRevision(' + JSON.stringify(rnum) + ');';
box.find(".srrestore").attr('href', restoreLink);
box.find(".srname").click(function(evt)
{
@ -345,9 +347,11 @@ var padsavedrevs = (function()
$(document).unbind('mouseup', clearScrollRepeatTimer);
}
var pad = undefined;
var self = {
init: function(initialRevisions)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
self.newRevisionList(initialRevisions, true);
$("#savedrevs-savenow").click(function()

View File

@ -20,6 +20,8 @@
* limitations under the License.
*/
var padutils = require('/pad_utils').padutils;
var myUserInfo = {};
var colorPickerOpen = false;
@ -460,9 +462,12 @@ var paduserlist = (function()
return true;
}, 1000);
var pad = undefined;
var self = {
init: function(myInitialUserInfo)
{
pad = require('/pad2').pad; // Sidestep circular dependency (should be injected).
self.setMyUserInfo(myInitialUserInfo);
$("#otheruserstable tr").remove();
@ -652,7 +657,7 @@ var paduserlist = (function()
if (box.length == 0)
{
// make guest prompt box
box = $('<div id="guestprompt-' + encodedUserId + '" class="guestprompt"><div class="choices"><a href="javascript:void(paduserlist.answerGuestPrompt(\'' + encodedUserId + '\',false))">Deny</a> <a href="javascript:void(paduserlist.answerGuestPrompt(\'' + encodedUserId + '\',true))">Approve</a></div><div class="guestname"><strong>Guest:</strong> ' + padutils.escapeHtml(displayName) + '</div></div>');
box = $('<div id="'+padutils.escapeHtml('guestprompt-' + encodedUserId) + '" class="guestprompt"><div class="choices"><a href="' + padutils.escapeHtml('javascript:void(require('+JSON.stringify(module.id)+').paduserlist.answerGuestPrompt(' + JSON.stringify(encodedUserId) + ',false))')+'">Deny</a> <a href="' + padutils.escapeHtml('javascript:void(require('+JSON.stringify(module.id)+').paduserlist.answerGuestPrompt(' + JSON.stringify(encodedUserId) + ',true))') + '">Approve</a></div><div class="guestname"><strong>Guest:</strong> ' + padutils.escapeHtml(displayName) + '</div></div>');
$("#guestprompts").append(box);
}
else

View File

@ -34,6 +34,7 @@ var padutils = {
},
uniqueId: function()
{
var pad = require('/pad2').pad; // Sidestep circular dependency
function encodeNum(n, width)
{
// returns string that is exactly 'width' chars, padding with zeros
@ -226,6 +227,7 @@ var padutils = {
},
timediff: function(d)
{
var pad = require('/pad2').pad; // Sidestep circular dependency
function format(n, word)
{
n = Math.round(n);