From 777efab2dfe60e3a1204fd36bfd83130c3d56bdb Mon Sep 17 00:00:00 2001 From: Max Goodman Date: Tue, 8 Nov 2011 12:43:02 -0800 Subject: [PATCH] Move r.config into an r.setup() call after modules load. The inline script now has id="config" and is in JSONP format, which will make it easier for browser extensions and greasemonkey scripts to access reddit config variables in isolated environments. --- r2/r2/public/static/js/base.js | 6 +++ r2/r2/templates/base.compact | 6 +-- r2/r2/templates/base.html | 10 +---- r2/r2/templates/frame.compact | 6 +-- r2/r2/templates/framebuster.html | 6 +-- r2/r2/templates/utils.html | 75 ++++++++++++++++---------------- 6 files changed, 52 insertions(+), 57 deletions(-) diff --git a/r2/r2/public/static/js/base.js b/r2/r2/public/static/js/base.js index ea901475a..3479f5c81 100644 --- a/r2/r2/public/static/js/base.js +++ b/r2/r2/public/static/js/base.js @@ -1,5 +1,11 @@ r = window.r || {} +r.setup = function(config) { + r.config = config + // Set the legacy config global + reddit = config +} + $(function() { r.login.ui.init() r.analytics.init() diff --git a/r2/r2/templates/base.compact b/r2/r2/templates/base.compact index 14a1e853a..9d47edbac 100644 --- a/r2/r2/templates/base.compact +++ b/r2/r2/templates/base.compact @@ -24,7 +24,7 @@ from r2.lib.template_helpers import static from r2.lib import js %> -<%namespace file="utils.html" import="js_preamble, googleanalytics"/> +<%namespace file="utils.html" import="js_setup, googleanalytics"/> ${self.robots()} - ${unsafe(js.use('jquery', 'mobile'))} + ${js_setup()} ${googleanalytics('mobile')} ${self.bodyHTML()} diff --git a/r2/r2/templates/base.html b/r2/r2/templates/base.html index c00809635..0f559cef3 100644 --- a/r2/r2/templates/base.html +++ b/r2/r2/templates/base.html @@ -26,7 +26,7 @@ from r2.models import Link, Comment, Subreddit from r2.lib.tracking import UserInfo %> -<%namespace file="utils.html" import="js_preamble, googleanalytics"/> +<%namespace file="utils.html" import="js_setup, googleanalytics"/> @@ -39,15 +39,9 @@ ${self.robots()} - ##these are globals, so they should be run first - ##things that need are referenced by the reddit, the buttons, and - ##the frame should go here - - ${self.stylesheet()} ${self.javascript()} + ${js_setup()} ##things here may depend on globals, or included js, so we run them last + ${js_setup()} diff --git a/r2/r2/templates/framebuster.html b/r2/r2/templates/framebuster.html index 37ddf4ced..0d1043ac0 100644 --- a/r2/r2/templates/framebuster.html +++ b/r2/r2/templates/framebuster.html @@ -1,14 +1,12 @@ <%namespace file="reddit.html" import="javascript"/> -<%namespace file="utils.html" import="js_preamble"/> +<%namespace file="utils.html" import="js_setup"/> escappit <% from r2.lib import js %> - ${unsafe(js.use('jquery', 'reddit'))} + ${js_setup()} <%def name="googleanalytics(uitype)">