
function tinyDjangoBrowser (field_name, url, type, win) {
var managerURL = window.location.toString ()
+ '../../../shop/pagepicture/?type=' + type;
tinyMCE.activeEditor.windowManager.open ({
file: managerURL,
title: 'Click on the thumbnail of the desired image',
width: 800,
height: 450,
resizable: 'yes',
inline: 'yes',
close_previous: 'no',
popup_css: false
}, {
window: win,
input: field_name
});
return false;
}
$ (). ready (function () {
var tinymceOptions = {
script_url: '/media/lib/tiny_mce/tiny_mce.js',
theme: 'advanced',
plugins: 'safari, pagebreak, layer, table, advhr, advimage, advlink, iespell, inlinepopups, insertdatetime, preview, media, searchreplace, print, contextmenu, fullscreen, noneditable, visualchars, nonbreaking, xhtmlxtras',
theme_advanced_buttons1: 'bold, italic, underline, strikethrough, |, justifyleft, justifycenter, justifyright, justifyfull, formatselect, fontselect, fontsizeselect',
theme_advanced_buttons2: 'search, replace, |, bullist, numlist, |, outdent, indent, blockquote, |, undo, redo, |, link, unlink, anchor, image, cleanup, help, code, |, insertdate, inserttime, preview , |, forecolor, backcolor ',
theme_advanced_buttons3: 'tablecontrols, |, hr, removeformat, visualaid, |, sub, sup, |, charmap, iespell, media, advhr, |, print, |, fullscreen',
theme_advanced_buttons4: 'insertlayer, moveforward, movebackward, absolute, |, cite, abbr, acronym, del, ins, attribs, |, visualchars, nonbreaking, pagebreak',
theme_advanced_toolbar_location: 'top',
theme_advanced_toolbar_align: 'left',
theme_advanced_statusbar_location: 'bottom',
theme_advanced_resizing: true
// Drop lists for link / image / media / template dialogs
template_external_list_url: 'lists / template_list.js',
external_link_list_url: 'lists / link_list.js',
external_image_list_url: 'lists / image_list.js',
media_external_list_url: 'lists / media_list.js',
doctype: '<! DOCTYPE HTML PUBLIC "- // W3C // DTD HTML 4.01 // EN" "http://www.w3.org/TR/html4/strict.dtd">',
content_css: '/media/css/admin/editor.css',
file_browser_callback: 'tinyDjangoBrowser'
};
$ ('textarea # id_content'). tinymce (tinymceOptions);
}); 

$ (). ready (function () {
if (window.parent) {
$ .getScript ('/ media / lib / tiny_mce / tiny_mce_popup.js', function () {
$ ('# changelist tbody a.image-picker'). click (function (e) {
var url = $ (this) .attr ('href');
var win = tinyMCEPopup.getWindowArg ("window");
var alt = $ (this) .find ('img'). attr ('alt');
win.document.getElementById (tinyMCEPopup.getWindowArg ("input")). value = url;
win.document.getElementById ('alt'). value = alt;
if (typeof (win.ImageDialog)! = "undefined") {
if (win.ImageDialog.getImageData) win.ImageDialog.getImageData ();
if (win.ImageDialog.showPreviewImage) win.ImageDialog.showPreviewImage (url);
}
tinyMCEPopup.close ();
return false;
});
});
}
}); class PagePictureAdmin (admin.ModelAdmin):
class Media:
js = ['js / admin / display_thumbs.js', 'js / admin / tiny_django_browser.js']
list_display = ['get_thumbnail_html', '__unicode__', 'description']
list_display_links = ['__unicode__']
admin.site.register (PagePicture, PagePictureAdmin) 
Source: https://habr.com/ru/post/78469/
All Articles