From 595cae50bec860a32fbcee4122674b7fb6e8a027 Mon Sep 17 00:00:00 2001 From: James Long Date: Tue, 6 Mar 2012 16:05:04 -0500 Subject: [PATCH 1/3] debug non-escaped forms on dev site --- .../templates/marketplace/marketplace.html | 2 +- apps/mozorg/forms.py | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/marketplace/templates/marketplace/marketplace.html b/apps/marketplace/templates/marketplace/marketplace.html index 442bd44579..8c187130c7 100644 --- a/apps/marketplace/templates/marketplace/marketplace.html +++ b/apps/marketplace/templates/marketplace/marketplace.html @@ -88,7 +88,7 @@
- {{ field_with_attrs(form.email, placeholder='YOUR EMAIL HERE') }} + {{ form.email }}
diff --git a/apps/mozorg/forms.py b/apps/mozorg/forms.py index cc6b3e2450..6c5770a1b1 100644 --- a/apps/mozorg/forms.py +++ b/apps/mozorg/forms.py @@ -20,11 +20,12 @@ class PrivacyWidget(widgets.CheckboxInput): def render(self, name, value, attrs=None): attrs['required'] = 'true' input_txt = super(PrivacyWidget, self).render(name, value, attrs) - return ('') % input_txt + return mark_safe( + '') % input_txt class EmailInput(widgets.TextInput): input_type = 'email' From f3482603ce15a1944cd470407f87070b631f4b6f Mon Sep 17 00:00:00 2001 From: James Long Date: Tue, 6 Mar 2012 16:16:00 -0500 Subject: [PATCH 2/3] revert debugging --- apps/marketplace/templates/marketplace/marketplace.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/marketplace/templates/marketplace/marketplace.html b/apps/marketplace/templates/marketplace/marketplace.html index 8c187130c7..442bd44579 100644 --- a/apps/marketplace/templates/marketplace/marketplace.html +++ b/apps/marketplace/templates/marketplace/marketplace.html @@ -88,7 +88,7 @@
- {{ form.email }} + {{ field_with_attrs(form.email, placeholder='YOUR EMAIL HERE') }}
From b1916d5904fc72952f69f5a590e9742e4445be2a Mon Sep 17 00:00:00 2001 From: James Long Date: Wed, 7 Mar 2012 15:33:58 -0500 Subject: [PATCH 3/3] add `platform_img` template function --- apps/mozorg/helpers.py | 21 +++++++++++ .../templates/mozorg/firefox/customize.html | 3 +- media/css/sandstone/sandstone.less | 18 ++++++++++ media/js/site.js | 36 +++++++++++++++++++ settings/base.py | 2 ++ templates/base.html | 4 ++- 6 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 media/js/site.js diff --git a/apps/mozorg/helpers.py b/apps/mozorg/helpers.py index 32e29eb027..441360294a 100644 --- a/apps/mozorg/helpers.py +++ b/apps/mozorg/helpers.py @@ -10,6 +10,7 @@ of terms and example values for them: """ from os import path +import re import jinja2 import jingo @@ -211,3 +212,23 @@ def field_with_attrs(bfield, **kwargs): fields from django forms""" bfield.field.widget.attrs.update(kwargs) return bfield + +@jingo.register.function +def platform_img(url, **kwargs): + attrs = ' '.join(('%s="%s"' % (attr, val) + for attr, val in kwargs.items())) + url = path.join(settings.MEDIA_URL, url.lstrip('/')) + (root, ext) = path.splitext(url) + + def url(plat): + return '%s%s%s' % (root, + {'win': '', + 'osx': '-mac', + 'linux': '-linux'}[plat], + ext) + + imgs = ('' + % (plat, url(plat), attrs) + for plat in ('win', 'osx', 'linux')) + + return jinja2.Markup(''.join(imgs)) diff --git a/apps/mozorg/templates/mozorg/firefox/customize.html b/apps/mozorg/templates/mozorg/firefox/customize.html index 5ef6b5ec5c..4184fbddd1 100644 --- a/apps/mozorg/templates/mozorg/firefox/customize.html +++ b/apps/mozorg/templates/mozorg/firefox/customize.html @@ -122,8 +122,7 @@

Plugins are small bits of third-party software built by companies like Adobe Systems or Apple to power videos, animation and games (examples include Flash Player or Quicktime). They can cause browser crashes or pose security risks when they get out of date, so we’ve built an easy tool to help you stay current. Check your plugins.

- - Make It Work: Plugins + {{ platform_img('img/firefox/customize/make-it-work.png', alt='Make It Work: Plugins') }}
diff --git a/media/css/sandstone/sandstone.less b/media/css/sandstone/sandstone.less index 08155310bc..df29a59026 100644 --- a/media/css/sandstone/sandstone.less +++ b/media/css/sandstone/sandstone.less @@ -612,3 +612,21 @@ px 68 160 252 344 436 */ } /* }}} */ + + + +/* {{{ Firefox site functionality + This can be put into its own CSS file if needed. */ + +.platform-img { + display: none; +} + +.osx img.osx, +.mac img.osx, +.linux img.linux, +.win img.win { + display: inline; +} + +/* }}} */ \ No newline at end of file diff --git a/media/js/site.js b/media/js/site.js new file mode 100644 index 0000000000..8918fe73c6 --- /dev/null +++ b/media/js/site.js @@ -0,0 +1,36 @@ + +(function() { + var site = { + platform: 'windows' + }; + + if(navigator.platform.indexOf("Win32") != -1 || + navigator.platform.indexOf("Win64") != -1) { + site.platform = 'windows'; + } + else if(navigator.platform.indexOf("Linux") != -1) { + site.platform = 'linux'; + } + else if (navigator.userAgent.indexOf("Mac OS X") != -1) { + site.platform = 'osx'; + } + else if (navigator.userAgent.indexOf("MSIE 5.2") != -1) { + site.platform = 'osx'; + } + else if (navigator.platform.indexOf("Mac") != -1) { + site.platform = 'mac'; + } + else { + site.platform = 'other'; + } + + function init() { + var b = $(document.body); + // Remove the default platform + b.removeClass('win'); + b.addClass(site.platform); + } + + $(document).ready(init); + window.site = site; +})(); diff --git a/settings/base.py b/settings/base.py index ef454e153d..a88699f52e 100644 --- a/settings/base.py +++ b/settings/base.py @@ -109,9 +109,11 @@ MINIFY_BUNDLES = { ), 'common': ( 'js/libs/jquery-1.7.1.min.js', + 'js/site.js', ), 'firefox': ( 'js/libs/jquery-1.7.1.min.js', + 'js/site.js', 'js/nav-main.js', ), 'firefox-customize': ( diff --git a/templates/base.html b/templates/base.html index 6d8d12312a..4e06348a40 100644 --- a/templates/base.html +++ b/templates/base.html @@ -23,7 +23,9 @@ - + +