Permalink
Browse files

Merge pull request #7 from 4teamwork/mle-optimize-js

Set header for dynamic_tooltips.js (Enables merging).
  • Loading branch information...
2 parents bd65945 + fa96392 commit 5a8adf7af8dcf7c4b2cf5124b2d9b2e3ebd9f97f @jone jone committed Mar 5, 2014
View
@@ -4,7 +4,8 @@ Changelog
1.1.4 (unreleased)
------------------
-- Nothing changed yet.
+- Do not render dynamic_tooltips.js inline.
+ [mathias.leimgruber]
1.1.3 (2014-02-10)
@@ -13,6 +13,8 @@ class TooltipJs(BrowserView):
def __call__(self):
"""Returns the js code directly"""
+ self.request.response.setHeader('Content-Type',
+ 'application/javascript')
return self.template()
def get_all_tips(self):
@@ -1,4 +1,3 @@
-<div tal:replace="structure python: '//<![CDATA['" />
<tal:def define="ftwtooltips view/generate_tooltip_js_source">
var ftwtooltips = <span tal:replace="ftwtooltips" />;
@@ -52,4 +51,3 @@ $(function(){
});
});
</tal:def>
-<div tal:replace="structure python: '//]]>'" />
@@ -1,7 +1,7 @@
<?xml version="1.0"?>
<object name="portal_javascripts" meta_type="JavaScripts Registry">
<javascript cacheable="False" compression="safe" cookable="False" expression=""
- enabled="True" id="@@dynamic_tooltips.js" inline="True"
- />
+ enabled="True" id="@@dynamic_tooltips.js" inline="False"
+ insert-after="*" />
<javascript enabled="True" id="++resource++plone.app.jquerytools.plugins.js" />
</object>
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<metadata>
- <version>1131</version>
+ <version>1132</version>
</metadata>
@@ -1,16 +1,17 @@
+from ftw.tooltip.demo_tooltip_source import DemoContentTooltipSource
+from ftw.tooltip.demo_tooltip_source import DemoDynamicTooltipSource
+from ftw.tooltip.demo_tooltip_source import DemoStaticTooltipSource
+from ftw.tooltip.interfaces import ITooltipSource
from ftw.tooltip.testing import FTWTOOLTIP_ZCML_LAYER
from plone.mocktestcase import MockTestCase
+from zope.browser.interfaces import IBrowserView
+from zope.component import adapts
+from zope.component import getGlobalSiteManager
from zope.component import getMultiAdapter, queryMultiAdapter
-from zope.interface.verify import verifyClass
from zope.interface import directlyProvides
-from ftw.tooltip.interfaces import ITooltipSource
-from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-from ftw.tooltip.demo_tooltip_source import (DemoStaticTooltipSource,
- DemoDynamicTooltipSource, DemoContentTooltipSource)
-from zope.component import getGlobalSiteManager
-from zope.browser.interfaces import IBrowserView
from zope.interface import Interface, implements
-from zope.component import adapts
+from zope.interface.verify import verifyClass
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
class TestTooltip(MockTestCase):
@@ -24,6 +25,8 @@ def setUp(self):
setattr(self.request, 'response', self.response)
self.expect(self.response.getHeader('Content-Type')).result(
'text/javascript')
+ self.response.setHeader('Content-Type', 'application/javascript')
+
directlyProvides(self.request, IDefaultBrowserLayer)
self.replay()
@@ -61,20 +64,21 @@ def test_condition_key(self):
def test_js_view_registered(self):
view = getMultiAdapter((object(), self.request),
- name="dynamic_tooltips.js")
+ name="dynamic_tooltips.js")
self.assertTrue(view)
def test_get_all_tooltip(self):
view = getMultiAdapter((object(), self.request),
- name="dynamic_tooltips.js")
+ name="dynamic_tooltips.js")
for name, adapter in view.get_all_tips():
- self.assertTrue(adapter.__class__.__name__ in
+ self.assertTrue(
+ adapter.__class__.__name__ in
['DemoDynamicTooltipSource', 'DemoStaticTooltipSource'])
self.assertTrue(isinstance(name, basestring))
def test_tooltip_js_generation(self):
view = getMultiAdapter((object(), self.request),
- name="dynamic_tooltips.js")
+ name="dynamic_tooltips.js")
js = view.generate_tooltip_js_source()
self.assertEqual(
js,
@@ -88,7 +92,7 @@ def test_tooltip_js_multiple_adapters_generation(self):
# the title attr of the matched element
self.gsm.registerAdapter(DemoDynamicTooltipSource, name="demo2")
view = getMultiAdapter((object(), self.request),
- name="dynamic_tooltips.js")
+ name="dynamic_tooltips.js")
js = view.generate_tooltip_js_source()
self.assertEqual(
js,
@@ -103,7 +107,7 @@ def test_tooltip_js_multiple_adapters_generation(self):
def test_tooltip_js_generation_with_content(self):
self.gsm.registerAdapter(DemoContentTooltipSource, name="demo2")
view = getMultiAdapter((object(), self.request),
- name="dynamic_tooltips.js")
+ name="dynamic_tooltips.js")
js = view.generate_tooltip_js_source()
self.assertEqual(
@@ -118,12 +122,12 @@ def test_tooltip_js_generation_with_content(self):
def test_hole_js(self):
view = getMultiAdapter((object(), self.request),
- name="dynamic_tooltips.js")
+ name="dynamic_tooltips.js")
self.assertIn(view.generate_tooltip_js_source(), view())
def test_tooltip_default_layout(self):
view = getMultiAdapter((object(), self.request),
- name="dynamic_tooltips.js")
+ name="dynamic_tooltips.js")
self.assertEqual(view.get_tooltip_layout(), "<div class='tooltip'/>")
def test_tooltip_custom_layout(self):
@@ -142,7 +146,7 @@ def __call__(self):
self.gsm.registerAdapter(ToolTipSpecifigLayout,
name="ftw_tooltip_layout")
view = getMultiAdapter((object(), self.request),
- name="dynamic_tooltips.js")
+ name="dynamic_tooltips.js")
self.assertEqual(view.get_tooltip_layout(),
"<div class=\\'MyToolTipCustomKlass\\'/>")
self.assertIn(
@@ -15,4 +15,13 @@
directory="profiles/1131"
/>
+ <!-- 1131 -> 1132-->
+ <upgrade-step:importProfile
+ title="Do not render dynamic_tooltips.js inline"
+ profile="ftw.tooltip:default"
+ source="1131"
+ destination="1132"
+ directory="profiles/1132"
+ />
+
</configure>
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<object name="portal_javascripts" meta_type="JavaScripts Registry">
+ <javascript cacheable="False" compression="safe" cookable="False" expression=""
+ enabled="True" id="@@dynamic_tooltips.js" inline="False"
+ insert-after="*"/>
+</object>

0 comments on commit 5a8adf7

Please sign in to comment.