Skip to content

Commit

Permalink
Merge pull request #239 from glassfordm/tinymce4_filebrowser
Browse files Browse the repository at this point in the history
Changes to work with TinyMCE 4 filebrowser
  • Loading branch information
Natim authored Apr 10, 2020
2 parents f80d373 + 1d87d13 commit c14d510
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
54 changes: 36 additions & 18 deletions tinymce/templates/tinymce/filebrowser.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
function djangoFileBrowser(field_name, url, type, win) {
var url = "{{ fb_url }}?pop=2&type=" + type;
if (tinyMCE.majorVersion >= 4) {
var url = "{{ fb_url }}?pop=4&type=" + type;

tinyMCE.activeEditor.windowManager.open(
{
'file': url,
'width': 820,
'height': 500,
'resizable': "yes",
'scrollbars': "yes",
'inline': "no",
'close_previous': "no"
},
{
'window': win,
'input': field_name,
'editor_id': tinyMCE.selectedInstance.editorId
}
);
return false;
tinyMCE.activeEditor.windowManager.open(
{
'file': url,
'width': 820,
'height': 500,
},
{
'window': win,
'input': field_name,
}
);
return false;
}
else {
var url = "{{ fb_url }}?pop=2&type=" + type;

tinyMCE.activeEditor.windowManager.open(
{
'file': url,
'width': 820,
'height': 500,
'resizable': "yes",
'scrollbars': "yes",
'inline': "no",
'close_previous': "no"
},
{
'window': win,
'input': field_name,
'editor_id': tinyMCE.selectedInstance.editorId
}
);
return false;
}
}
11 changes: 9 additions & 2 deletions tinymce/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
devnull = open(os.devnull, 'w')


def compress_whitespace(s):
# replace whitespace runs with a single space
return ' '.join(s.split())


class TestViews(TestCase):

@patch('tinymce.views.enchant')
Expand Down Expand Up @@ -115,6 +120,8 @@ def test_render_to_image_list(self):
@patch('tinymce.views.reverse', return_value='/filebrowser')
def test_filebrowser(self, reverse_mock):
response = self.client.get('/tinymce/filebrowser/')
response_ok = b'function djangoFileBrowser(field_name, url, type, win) {\n var url = "http://testserver/filebrowser?pop=2&type=" + type;\n\n tinyMCE.activeEditor.windowManager.open(\n {\n \'file\': url,\n \'width\': 820,\n \'height\': 500,\n \'resizable\': "yes",\n \'scrollbars\': "yes",\n \'inline\': "no",\n \'close_previous\': "no"\n },\n {\n \'window\': win,\n \'input\': field_name,\n \'editor_id\': tinyMCE.selectedInstance.editorId\n }\n );\n return false;\n}\n'
with open('tinymce/templates/tinymce/filebrowser.js') as f:
response_ok = f.read()
response_ok = response_ok.replace('{{ fb_url }}', 'http://testserver/filebrowser')
self.assertEqual(200, response.status_code)
self.assertEqual(response_ok, response.content)
self.assertEqual(compress_whitespace(response_ok), compress_whitespace(response.content.decode()))

0 comments on commit c14d510

Please sign in to comment.