mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-02-13 07:55:11 -05:00
base: Add a method to inject variables into r.setup
This commit is contained in:
@@ -206,7 +206,6 @@ class VWikiPage(Validator):
|
||||
|
||||
page = normalize_page(page)
|
||||
|
||||
c.wiki_page = page
|
||||
if (not c.is_wiki_mod) and self.modonly:
|
||||
return self.set_error('MOD_REQUIRED', code=403)
|
||||
|
||||
|
||||
@@ -137,12 +137,13 @@ class Reddit(Templated):
|
||||
def __init__(self, space_compress = True, nav_menus = None, loginbox = True,
|
||||
infotext = '', content = None, short_description='', title = '', robots = None,
|
||||
show_sidebar = True, footer = True, srbar = True, page_classes = None,
|
||||
show_wiki_actions = False, **context):
|
||||
show_wiki_actions = False, extra_js_config = {}, **context):
|
||||
Templated.__init__(self, **context)
|
||||
self.title = title
|
||||
self.short_description = short_description
|
||||
self.robots = robots
|
||||
self.infotext = infotext
|
||||
self.extra_js_config = extra_js_config
|
||||
self.show_wiki_actions = show_wiki_actions
|
||||
self.loginbox = True
|
||||
self.show_sidebar = show_sidebar
|
||||
|
||||
@@ -93,7 +93,8 @@ class WikiBase(Reddit):
|
||||
elif c.wikidisabled:
|
||||
context['infotext'] = _("this wiki is currently disabled, only mods may interact with this wiki")
|
||||
context['content'] = WikiBasePage(content, action, pageactions, page=page, **context)
|
||||
Reddit.__init__(self, show_wiki_actions=True, **context)
|
||||
Reddit.__init__(self, extra_js_config={'wiki_page': page},
|
||||
show_wiki_actions=True, **context)
|
||||
|
||||
class WikiPageView(WikiBase):
|
||||
def __init__(self, content, page, diff=None, **context):
|
||||
|
||||
@@ -116,7 +116,7 @@ def s3_https_if_secure(url):
|
||||
replace = "https://%s/" % s3_direct_url
|
||||
return url.replace("http://", replace)
|
||||
|
||||
def js_config():
|
||||
def js_config(extra_config={}):
|
||||
config = {
|
||||
# is the user logged in?
|
||||
"logged": c.user_is_loggedin and c.user.name,
|
||||
@@ -151,8 +151,7 @@ def js_config():
|
||||
"static_root": static(''),
|
||||
}
|
||||
|
||||
if c.wiki_page:
|
||||
config["wiki_page"] = c.wiki_page
|
||||
config.update(extra_config)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
${self.robots()}
|
||||
<link rel="stylesheet" href="${static('compact.css')}" type="text/css" media="screen" />
|
||||
${unsafe(js.use('jquery', 'mobile'))}
|
||||
${js_setup()}
|
||||
${js_setup(thing.extra_js_config)}
|
||||
${googleanalytics('mobile')}
|
||||
</head>
|
||||
${self.bodyHTML()}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
${self.pagemeta()}
|
||||
${self.stylesheet()}
|
||||
${self.javascript()}
|
||||
${js_setup()}
|
||||
${js_setup(getattr(thing, "extra_js_config", None))}
|
||||
|
||||
##things here may depend on globals, or included js, so we run them last
|
||||
<script type="text/javascript">
|
||||
|
||||
@@ -407,9 +407,9 @@ ${unsafe(txt)}
|
||||
</%def>
|
||||
|
||||
|
||||
<%def name="js_setup()">
|
||||
<%def name="js_setup(extra_config={})">
|
||||
<script type="text/javascript" id="config">
|
||||
r.setup(${unsafe(json.dumps(js_config()))})
|
||||
r.setup(${unsafe(json.dumps(js_config(extra_config)))})
|
||||
</script>
|
||||
</%def>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user