diff --git a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js index f91355961b..cbff2c8af8 100644 --- a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js +++ b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js @@ -1,3 +1,15 @@ +var halloPlugins = { + 'halloformat': {}, + 'halloheadings': {formatBlocks: ["p", "h2", "h3", "h4", "h5"]}, + 'hallolists': {}, + 'hallohr': {}, + 'halloreundo': {}, + 'hallowagtaillink': {}, +}; +function registerHalloPlugin(name, opts) { + halloPlugins[name] = (opts || {}); +} + function makeRichTextEditable(id) { var input = $('#' + id); var richText = $('
').html(input.val()); @@ -19,17 +31,7 @@ function makeRichTextEditable(id) { richText.hallo({ toolbar: 'halloToolbarFixed', toolbarcssClass: 'testy', - plugins: { - 'halloformat': {}, - 'halloheadings': {formatBlocks: ["p", "h2", "h3", "h4", "h5"]}, - 'hallolists': {}, - 'hallohr': {}, - 'halloreundo': {}, - 'hallowagtailimage': {}, - 'hallowagtailembeds': {}, - 'hallowagtaillink': {}, - 'hallowagtaildoclink': {} - } + plugins: halloPlugins }).bind('hallomodified', function(event, data) { input.val(data.content); if (!removeStylingPending) { diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_css.html b/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_css.html index 9c6e832e8e..2e140c89c1 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_css.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_css.html @@ -4,11 +4,6 @@ CSS declarations to be included on the 'create page' and 'edit page' views {% endcomment %} -{% comment %} - TODO: have a mechanism for sub-apps to specify their own declarations - - ideally wagtailadmin shouldn't have to know anything at all about wagtailimages and friends -{% endcomment %} - {% compress css %} diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_js.html b/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_js.html index 6efaecf12d..37d600f07d 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_js.html +++ b/wagtail/wagtailadmin/templates/wagtailadmin/pages/_editor_js.html @@ -4,6 +4,11 @@ Javascript declarations to be included on the 'create page' and 'edit page' views {% endcomment %} + {% compress js %} @@ -14,21 +19,9 @@ - - - - {% comment %} - TODO: use the insert_editor_js hook to inject things like image-chooser.js and hallo-wagtailimage.js - from their respective apps such as wagtailimages - - ideally wagtailadmin shouldn't have to know anything at all about wagtailimages. - TODO: a method of injecting these sorts of things on demand when the modal is spawned. - {% endcomment %} - - - {% hook_output 'insert_editor_js' %} @@ -41,19 +34,10 @@ {% comment %} Additional js from widgets media. Allows for custom widgets in admin panel. - Can be used for TODO above (including image-choser.js at wagtailimages) {% endcomment %} {{ edit_handler.form.media.js }} ', + ((settings.STATIC_URL, filename) for filename in js_files) + ) + return js_includes + format_html( + """ + + """, + urlresolvers.reverse('wagtaildocs_chooser') + ) +hooks.register('insert_editor_js', editor_js) diff --git a/wagtail/wagtailembeds/embeds.py b/wagtail/wagtailembeds/embeds.py index d66c5ebcc1..f8ab35f165 100644 --- a/wagtail/wagtailembeds/embeds.py +++ b/wagtail/wagtailembeds/embeds.py @@ -152,6 +152,17 @@ def get_embed(url, max_width=None, finder=None): finder = get_default_finder() embed_dict = finder(url, max_width) + # Make sure width and height are valid integers before inserting into database + try: + embed_dict['width'] = int(embed_dict['width']) + except (TypeError, ValueError): + embed_dict['width'] = None + + try: + embed_dict['height'] = int(embed_dict['height']) + except (TypeError, ValueError): + embed_dict['height'] = None + # Create database record embed, created = Embed.objects.get_or_create( url=url, diff --git a/wagtail/wagtailembeds/tests.py b/wagtail/wagtailembeds/tests.py index e3ac82d2ba..b1eefdb178 100644 --- a/wagtail/wagtailembeds/tests.py +++ b/wagtail/wagtailembeds/tests.py @@ -8,6 +8,20 @@ class TestEmbeds(TestCase): def setUp(self): self.hit_count = 0 + def dummy_finder(self, url, max_width=None): + # Up hit count + self.hit_count += 1 + + # Return a pretend record + return { + 'title': "Test: " + url, + 'type': 'video', + 'thumbnail_url': '', + 'width': max_width if max_width else 640, + 'height': 480, + 'html': "

Blah blah blah

", + } + def test_get_embed(self): embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder) @@ -31,20 +45,23 @@ class TestEmbeds(TestCase): embed = get_embed('www.test.com/4321', finder=self.dummy_finder) self.assertEqual(self.hit_count, 3) - def dummy_finder(self, url, max_width=None): - # Up hit count - self.hit_count += 1 - - # Return a pretend record + def dummy_finder_invalid_width(self, url, max_width=None): + # Return a record with an invalid width return { 'title': "Test: " + url, 'type': 'video', 'thumbnail_url': '', - 'width': max_width if max_width else 640, + 'width': '100%', 'height': 480, 'html': "

Blah blah blah

", } + def test_invalid_width(self): + embed = get_embed('www.test.com/1234', max_width=400, finder=self.dummy_finder_invalid_width) + + # Width must be set to None + self.assertEqual(embed.width, None) + class TestChooser(TestCase): def setUp(self): diff --git a/wagtail/wagtailembeds/wagtail_hooks.py b/wagtail/wagtailembeds/wagtail_hooks.py index 0db627881d..89c5e66a55 100644 --- a/wagtail/wagtailembeds/wagtail_hooks.py +++ b/wagtail/wagtailembeds/wagtail_hooks.py @@ -1,4 +1,7 @@ +from django.conf import settings from django.conf.urls import include, url +from django.core import urlresolvers +from django.utils.html import format_html from wagtail.wagtailadmin import hooks from wagtail.wagtailembeds import urls @@ -9,3 +12,18 @@ def register_admin_urls(): url(r'^embeds/', include(urls)), ] hooks.register('register_admin_urls', register_admin_urls) + + +def editor_js(): + return format_html(""" + + + """, + settings.STATIC_URL, + 'wagtailembeds/js/hallo-plugins/hallo-wagtailembeds.js', + urlresolvers.reverse('wagtailembeds_chooser') + ) +hooks.register('insert_editor_js', editor_js) diff --git a/wagtail/wagtailimages/wagtail_hooks.py b/wagtail/wagtailimages/wagtail_hooks.py index f14d229043..51492d4046 100644 --- a/wagtail/wagtailimages/wagtail_hooks.py +++ b/wagtail/wagtailimages/wagtail_hooks.py @@ -1,5 +1,7 @@ +from django.conf import settings from django.conf.urls import include, url from django.core import urlresolvers +from django.utils.html import format_html, format_html_join from django.utils.translation import ugettext_lazy as _ from wagtail.wagtailadmin import hooks @@ -21,3 +23,23 @@ def construct_main_menu(request, menu_items): MenuItem(_('Images'), urlresolvers.reverse('wagtailimages_index'), classnames='icon icon-image', order=300) ) hooks.register('construct_main_menu', construct_main_menu) + + +def editor_js(): + js_files = [ + 'wagtailimages/js/hallo-plugins/hallo-wagtailimage.js', + 'wagtailimages/js/image-chooser.js', + ] + js_includes = format_html_join('\n', '', + ((settings.STATIC_URL, filename) for filename in js_files) + ) + return js_includes + format_html( + """ + + """, + urlresolvers.reverse('wagtailimages_chooser') + ) +hooks.register('insert_editor_js', editor_js) diff --git a/wagtail/wagtailsnippets/wagtail_hooks.py b/wagtail/wagtailsnippets/wagtail_hooks.py index 35468f7d88..3745d1a510 100644 --- a/wagtail/wagtailsnippets/wagtail_hooks.py +++ b/wagtail/wagtailsnippets/wagtail_hooks.py @@ -1,5 +1,7 @@ +from django.conf import settings from django.conf.urls import include, url from django.core import urlresolvers +from django.utils.html import format_html from django.utils.translation import ugettext_lazy as _ from wagtail.wagtailadmin import hooks @@ -22,3 +24,15 @@ def construct_main_menu(request, menu_items): MenuItem(_('Snippets'), urlresolvers.reverse('wagtailsnippets_index'), classnames='icon icon-snippet', order=500) ) hooks.register('construct_main_menu', construct_main_menu) + + +def editor_js(): + return format_html(""" + + + """, + settings.STATIC_URL, + 'wagtailsnippets/js/snippet-chooser.js', + urlresolvers.reverse('wagtailsnippets_choose_generic') + ) +hooks.register('insert_editor_js', editor_js)