// Copy+pasted from /static/filer/js/popup_handling.js, because we can't always count on this being loaded.
(function($) {
dismissPopupAndReload = function(win) {
document.location.reload();
win.close();
};
dismissRelatedImageLookupPopup = function(win, chosenId, chosenThumbnailUrl, chosenDescriptionTxt) {
var name = windowname_to_id(win.name);
var img_name = name + '_thumbnail_img';
var txt_name = name + '_description_txt';
var clear_name = name + '_clear';
var elem = document.getElementById(name);
document.getElementById(name).value = chosenId;
document.getElementById(img_name).src = chosenThumbnailUrl;
document.getElementById(txt_name).innerHTML = chosenDescriptionTxt;
document.getElementById(clear_name).style.display = 'inline';
win.close();
};
dismissRelatedFolderLookupPopup = function(win, chosenId, chosenName) {
var id = windowname_to_id(win.name);
var id_name = id + '_description_txt';
document.getElementById(id).value = chosenId;
document.getElementById(id_name).innerHTML = chosenName;
win.close();
};
})(jQuery);
CKEDITOR.dialog.add( 'filerImageDialog', function ( editor ) {
dialog = CKEDITOR.dialog.getCurrent();
var imageWidth = 0;
var imageHeight = 0;
function getImageUrl() {
var url = dialog.getContentElement("tab-basic", "url");
var thumb_sel_val = dialog.getContentElement("tab-basic", "thumbnail_option").getValue();
if (thumb_sel_val != 0) {
server_url = '?djangocms_ckeditor_filer_image='+ django.jQuery('#id_image').val() + '&thumb_options=' + thumb_sel_val;
} else {
width = dialog.getContentElement("tab-basic", "width").getValue();
height = dialog.getContentElement("tab-basic", "height").getValue();
server_url = '?djangocms_ckeditor_filer_image='+ django.jQuery('#id_image').val() + '&width=' + width + '&height=' + height;
}
django.jQuery.get(server_url, function(data) {
url.setValue(data.url);
imageWidth = data.width;
imageHeight = data.height;
});
}
return {
title: 'Filer Image Properties',
minWidth: 400,
minHeight: 200,
onShow: function() {
dialog = CKEDITOR.dialog.getCurrent();
var document = this.getElement().getDocument();
// document = CKEDITOR.dom.document
var id_image = document.getById( 'id_image' );
var oldVal = id_image.getValue();
setInterval(function () {
if (oldVal != id_image.getValue()) {
oldVal = id_image.getValue();
getImageUrl();
}
}, 1000);
if ( id_image )
id_image.hide();
var id_image_clear = document.getById( 'id_image_clear' );
id_image_clear.on('click', function () {
id_image.setValue("");
id_image.removeAttribute("value");
id_image_thumbnail_img = document.getById( 'id_image_thumbnail_img' );
id_image_thumbnail_img.setAttribute("src", editor.config.settings.static_url +'/../filer/icons/nofile_48x48.png');
id_image_description_txt = document.getById( 'id_image_description_txt' );
id_image_description_txt.setHtml("");
id_image_clear = document.getById( 'id_image_clear' );
id_image_clear.hide();
});
// Get the selection in the editor.
var selection = editor.getSelection();
// Get the element at the start of the selection.
var element = selection.getStartElement();
// Get the element closest to the selection, if any.
if ( element )
element = element.getAscendant( 'img', true );
// Create a new element if it does not exist.
if ( !element || element.getName() != 'img' ) {
element = editor.document.createElement( 'img' );
// Flag the insertion mode for later use.
this.insertMode = true;
}
else
this.insertMode = false;
// Store the reference to the element in an internal property, for later use.
this.element = element;
// Invoke the setup methods of all dialog elements, so they can load the element attributes.
if ( !this.insertMode )
this.setupContent( this.element );
else
id_image_clear.fire('click');
},
// This method is invoked once a user clicks the OK button, confirming the dialog.
onOk: function() {
// The context of this function is the dialog object itself.
// http://docs.ckeditor.com/#!/api/CKEDITOR.dialog
var dialog = this;
// Creates a new element.
var abbr = this.element;
// Invoke the commit methods of all dialog elements, so the element gets modified.
this.commitContent( abbr );
// Finally, in if insert mode, inserts the element at the editor caret position.
if ( this.insertMode )
editor.insertElement( abbr );
},
contents: [
{
id: 'tab-basic',
label: 'Basic Settings',
elements: [
{
type: 'html',
html:
'