From 8b763cab7218dfe2cffef9788a81cdb80c01e799 Mon Sep 17 00:00:00 2001 From: jordij Date: Mon, 15 Feb 2016 15:30:43 +1300 Subject: [PATCH] Templates and logic adapted to 1.3.1 changes --- setup.py | 2 +- wagtailembedder/format.py | 8 ++++- wagtailembedder/helper.py | 1 + .../wagtailembedder/js/hallo-embedder.js | 17 +++++++++ .../wagtailembedder/snippets/types_list.html | 4 +-- wagtailembedder/views/chooser.py | 35 +++++++++++++------ wagtailembedder/wagtail_hooks.py | 2 ++ 7 files changed, 54 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index b2a512f..a966688 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='wagtailembedder', - version='0.1.4', + version='0.1.5', packages=['wagtailembedder'], include_package_data=True, license='BSD License', diff --git a/wagtailembedder/format.py b/wagtailembedder/format.py index e7f1d83..8be2394 100644 --- a/wagtailembedder/format.py +++ b/wagtailembedder/format.py @@ -1,10 +1,13 @@ from django.core.exceptions import ObjectDoesNotExist from django.template.loader import render_to_string + from wagtail.wagtailsnippets.views.snippets import get_content_type_from_url_params -# from wagtail.wagtailembedder.embeds import get_embed def embed_to_frontend_html(id, content_type_app_name, content_type_model_name): + """ + Provides the Snippet representation through the appropiate template + """ try: content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name) model = content_type.model_class() @@ -22,6 +25,9 @@ def embed_to_frontend_html(id, content_type_app_name, content_type_model_name): def embed_to_editor_html(id, content_type_app_name, content_type_model_name): + """ + Provides the Snippet representation to display in the RichTextEditor + """ try: content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name) model = content_type.model_class() diff --git a/wagtailembedder/helper.py b/wagtailembedder/helper.py index 34ff748..46cc4c3 100644 --- a/wagtailembedder/helper.py +++ b/wagtailembedder/helper.py @@ -1,4 +1,5 @@ from wagtail.wagtailcore.rich_text import EMBED_HANDLERS + from wagtailembedder.format import embed_to_editor_html, embed_to_frontend_html diff --git a/wagtailembedder/static/wagtailembedder/js/hallo-embedder.js b/wagtailembedder/static/wagtailembedder/js/hallo-embedder.js index 38ba34c..4a03fb6 100644 --- a/wagtailembedder/static/wagtailembedder/js/hallo-embedder.js +++ b/wagtailembedder/static/wagtailembedder/js/hallo-embedder.js @@ -1,3 +1,20 @@ +function placeCaretAtEnd(el) { + el.focus(); + if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") { + var range = document.createRange(); + range.selectNodeContents(el); + range.collapse(false); + var sel = window.getSelection(); + sel.removeAllRanges(); + sel.addRange(range); + } else if (typeof document.body.createTextRange != "undefined") { + var textRange = document.body.createTextRange(); + textRange.moveToElementText(el); + textRange.collapse(false); + textRange.select(); + } +} + (function() { (function($) { return $.widget("IKS.halloembedder", { diff --git a/wagtailembedder/templates/wagtailembedder/snippets/types_list.html b/wagtailembedder/templates/wagtailembedder/snippets/types_list.html index 34b5977..354cdd8 100644 --- a/wagtailembedder/templates/wagtailembedder/snippets/types_list.html +++ b/wagtailembedder/templates/wagtailembedder/snippets/types_list.html @@ -10,11 +10,11 @@