Commit d38ec55d authored by Vincent Bechu's avatar Vincent Bechu

[erp5_core] Add maximize to editor gadget

parent e2449281
/*jslint nomen: true, indent: 2 */
/*global window, rJS, RSVP, document, FileReader, Blob*/
(function (window, rJS, RSVP, document, FileReader, Blob) {
/*global window, rJS, RSVP, document, FileReader, Blob, XMLHttpRequest*/
(function (window, rJS, RSVP, document, FileReader, Blob, XMLHttpRequest) {
"use strict";
/*
......@@ -18,12 +18,26 @@
*/
rJS(window)
.declareAcquiredMethod('triggerMaximize', 'triggerMaximize')
.allowPublicAcquisition('triggerMaximize', function (param_list) {
var gadget = this;
if (!this.element.classList.contains('editor-maximize')) {
this.element.classList.toggle('editor-maximize');
}
return this.triggerMaximize.apply(this, param_list)
.push(function () {
if (gadget.element.classList.contains('editor-maximize')) {
gadget.element.classList.remove('editor-maximize');
}
});
})
.declareMethod('render', function (options) {
var state_dict = {
value: options.value || "",
editor: options.editor,
content_type: options.content_type,
maximize: options.maximize,
portal_type: options.portal_type,
editable: options.editable || false,
key: options.key
......@@ -40,17 +54,50 @@
gadget = this,
url,
div = document.createElement('div'),
queue = new RSVP.Queue();
queue = new RSVP.Queue(),
div_max;
if ((modification_dict.hasOwnProperty('editable')) ||
(modification_dict.hasOwnProperty('editor'))) {
(modification_dict.hasOwnProperty('editor')) ||
modification_dict.hasOwnProperty('ojs_editor')) {
// Clear first to DOM, append after to reduce flickering/manip
while (element.firstChild) {
element.removeChild(element.firstChild);
}
if (modification_dict.hasOwnProperty('maximize')) {
if (gadget.state.editable) {
div_max = document.createElement('div');
element.appendChild(div_max);
queue.push(function () {
return gadget.declareGadget("gadget_erp5_button_maximize.html", {
scope: 'maximize',
element: div_max,
sandbox: 'public'
});
})
.push(undefined, function (error) {
if (error instanceof XMLHttpRequest && error.status === 404) {
return;
}
throw error;
});
}
}
element.appendChild(div);
if (gadget.state.editable &&
if (gadget.state.ojs_editor) {
queue.push(function () {
return gadget.declareGadget(
gadget.state.ojs_editor,
{
scope: "editor",
sandbox: 'iframe',
element: div
}
);
});
} else if (gadget.state.editable &&
(gadget.state.editor === 'codemirror')) {
queue
.push(function () {
......@@ -85,7 +132,8 @@
}
if (gadget.state.editable &&
((gadget.state.editor === 'codemirror') || (gadget.state.editor === 'fck_editor'))) {
((gadget.state.editor === 'codemirror') || (gadget.state.editor === 'fck_editor') ||
gadget.state.ojs_editor)) {
queue
.push(function () {
return gadget.getDeclaredGadget('editor');
......@@ -109,7 +157,8 @@
var argument_list = arguments,
result;
if (this.state.editable &&
((this.state.editor === 'codemirror') || (this.state.editor === 'fck_editor'))) {
((this.state.editor === 'codemirror') || (this.state.editor === 'fck_editor')) ||
this.state.ojs_editor) {
return this.getDeclaredGadget('editor')
.push(function (editor_gadget) {
return editor_gadget.getContent.apply(editor_gadget, argument_list);
......@@ -134,4 +183,4 @@
return {};
});
}(window, rJS, RSVP, document, FileReader, Blob));
}(window, rJS, RSVP, document, FileReader, Blob, XMLHttpRequest));
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment