From fa2a6e9ee690eef161b5e286e3d21fb186283f1d Mon Sep 17 00:00:00 2001 From: Chad Weider Date: Sun, 15 Jan 2012 21:37:47 -0800 Subject: [PATCH] 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. --- static/js/pad2.js | 14 ++++++++++++-- static/js/pad_connectionstatus.js | 2 ++ static/js/pad_cookie.js | 3 +++ static/js/pad_docbar.js | 6 ++++++ static/js/pad_editbar.js | 4 ++++ static/js/pad_editor.js | 9 ++++++++- static/js/pad_impexp.js | 8 ++++++++ static/js/pad_modals.js | 6 ++++++ static/js/pad_savedrevs.js | 6 +++++- static/js/pad_userlist.js | 7 ++++++- static/js/pad_utils.js | 2 ++ 11 files changed, 62 insertions(+), 5 deletions(-) diff --git a/static/js/pad2.js b/static/js/pad2.js index 3964dae6..5369d422 100644 --- a/static/js/pad2.js +++ b/static/js/pad2.js @@ -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("You need a password to access this pad
" + ""+ - ""); + ""); } else if(obj.accessStatus == "wrongPassword") { $("#editorloadingbox").html("You're password was wrong
" + ""+ - ""); + ""); } } diff --git a/static/js/pad_connectionstatus.js b/static/js/pad_connectionstatus.js index bec359c3..d3a7648c 100644 --- a/static/js/pad_connectionstatus.js +++ b/static/js/pad_connectionstatus.js @@ -20,6 +20,8 @@ * limitations under the License. */ +var padmodals = require('/pad_modals').padmodals; + var padconnectionstatus = (function() { diff --git a/static/js/pad_cookie.js b/static/js/pad_cookie.js index d8eb464c..00dc28f3 100644 --- a/static/js/pad_cookie.js +++ b/static/js/pad_cookie.js @@ -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) { diff --git a/static/js/pad_docbar.js b/static/js/pad_docbar.js index 09315c77..2bf1a1da 100644 --- a/static/js/pad_docbar.js +++ b/static/js/pad_docbar.js @@ -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() diff --git a/static/js/pad_editbar.js b/static/js/pad_editbar.js index 6754e99c..77420894 100644 --- a/static/js/pad_editbar.js +++ b/static/js/pad_editbar.js @@ -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() { diff --git a/static/js/pad_editor.js b/static/js/pad_editor.js index 5fc067cb..45a90f00 100644 --- a/static/js/pad_editor.js +++ b/static/js/pad_editor.js @@ -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() { diff --git a/static/js/pad_impexp.js b/static/js/pad_impexp.js index 638991a6..8f187a5c 100644 --- a/static/js/pad_impexp.js +++ b/static/js/pad_impexp.js @@ -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 diff --git a/static/js/pad_modals.js b/static/js/pad_modals.js index d5e7811b..9d24c5f1 100644 --- a/static/js/pad_modals.js +++ b/static/js/pad_modals.js @@ -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(); }, diff --git a/static/js/pad_savedrevs.js b/static/js/pad_savedrevs.js index 7aadea71..964c8338 100644 --- a/static/js/pad_savedrevs.js +++ b/static/js/pad_savedrevs.js @@ -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() diff --git a/static/js/pad_userlist.js b/static/js/pad_userlist.js index 96513225..b9d08932 100644 --- a/static/js/pad_userlist.js +++ b/static/js/pad_userlist.js @@ -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 = $('
Guest: ' + padutils.escapeHtml(displayName) + '
'); + box = $('
Guest: ' + padutils.escapeHtml(displayName) + '
'); $("#guestprompts").append(box); } else diff --git a/static/js/pad_utils.js b/static/js/pad_utils.js index 3c73aa06..30ff308c 100644 --- a/static/js/pad_utils.js +++ b/static/js/pad_utils.js @@ -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);