mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2024-12-26 12:18:21 +01:00
image insert
This commit is contained in:
parent
a033ea21c5
commit
0eee08855c
@ -34,7 +34,7 @@ afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button:hover, afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button.btactive button
|
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button:hover, afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button.btactive
|
||||||
{
|
{
|
||||||
border: 1px solid #759DC0;
|
border: 1px solid #759DC0;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
main() {
|
main() {
|
||||||
// load session class
|
// load session class
|
||||||
if (!OpenPage.editorSession) {
|
if (!OpenPage.EditorSession) {
|
||||||
require(["webodf/editor/EditorSession"], function(ES) {
|
require(["webodf/editor/EditorSession"], function(ES) {
|
||||||
return OpenPage.EditorSession = ES;
|
return OpenPage.EditorSession = ES;
|
||||||
});
|
});
|
||||||
@ -79,12 +79,10 @@
|
|||||||
el.classList.add("notranslate");
|
el.classList.add("notranslate");
|
||||||
this.userid = "localuser";
|
this.userid = "localuser";
|
||||||
this.canvas = new odf.OdfCanvas(el);
|
this.canvas = new odf.OdfCanvas(el);
|
||||||
this.documentChanged = function(e) {
|
this.documentChanged = function(e) {};
|
||||||
return console.log(e);
|
//console.log e
|
||||||
};
|
this.metaChanged = function(e) {};
|
||||||
this.metaChanged = function(e) {
|
//console.log e
|
||||||
return console.log(e);
|
|
||||||
};
|
|
||||||
this.textStylingChanged = function(e) {
|
this.textStylingChanged = function(e) {
|
||||||
return me.updateToolbar(e);
|
return me.updateToolbar(e);
|
||||||
};
|
};
|
||||||
@ -124,6 +122,13 @@
|
|||||||
me.eventSubscriptions.addFrameSubscription(me.editorSession, OpenPage.EditorSession.signalParagraphStyleModified, function() {
|
me.eventSubscriptions.addFrameSubscription(me.editorSession, OpenPage.EditorSession.signalParagraphStyleModified, function() {
|
||||||
return me.updateHyperlinkButtons();
|
return me.updateHyperlinkButtons();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//image controller
|
||||||
|
me.imageController = me.editorSession.sessionController.getImageController();
|
||||||
|
//imageController.subscribe(gui.ImageController.enabledChanged, enableButtons)
|
||||||
|
|
||||||
|
//text controller
|
||||||
|
me.textController = me.editorSession.sessionController.getTextController();
|
||||||
me.editorSession.sessionController.setUndoManager(new gui.TrivialUndoManager());
|
me.editorSession.sessionController.setUndoManager(new gui.TrivialUndoManager());
|
||||||
me.editorSession.sessionController.getUndoManager().subscribe(gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged);
|
me.editorSession.sessionController.getUndoManager().subscribe(gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged);
|
||||||
me.editorSession.sessionController.getMetadataController().subscribe(gui.MetadataController.signalMetadataChanged, me.metaChanged);
|
me.editorSession.sessionController.getMetadataController().subscribe(gui.MetadataController.signalMetadataChanged, me.metaChanged);
|
||||||
@ -311,6 +316,53 @@
|
|||||||
return this.hyperlinkController.removeHyperlinks();
|
return this.hyperlinkController.removeHyperlinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
undo(e) {
|
||||||
|
return this.editorSession.undo();
|
||||||
|
}
|
||||||
|
|
||||||
|
redo(e) {
|
||||||
|
return this.editorSession.redo();
|
||||||
|
}
|
||||||
|
|
||||||
|
image(e) {
|
||||||
|
var me;
|
||||||
|
me = this;
|
||||||
|
return this.openDialog("FileDiaLog", function(d, n, p) {
|
||||||
|
var fp;
|
||||||
|
fp = p.asFileHandler();
|
||||||
|
return fp.asFileHandler().read(function(data) {
|
||||||
|
var blob, reader;
|
||||||
|
blob = new Blob([data], {
|
||||||
|
type: fp.info.mime
|
||||||
|
});
|
||||||
|
reader = new FileReader();
|
||||||
|
reader.onloadend = function() {
|
||||||
|
var hiddenImage;
|
||||||
|
if (reader.readyState !== 2) {
|
||||||
|
return me.error(__("Couldnt load image {0}", p));
|
||||||
|
}
|
||||||
|
// insert the image to document
|
||||||
|
hiddenImage = new Image();
|
||||||
|
hiddenImage.style.position = "absolute";
|
||||||
|
hiddenImage.style.left = "-99999px";
|
||||||
|
document.body.appendChild(hiddenImage);
|
||||||
|
hiddenImage.onload = function() {
|
||||||
|
var content;
|
||||||
|
content = reader.result.substring(reader.result.indexOf(",") + 1);
|
||||||
|
//insert image
|
||||||
|
me.textController.removeCurrentSelection();
|
||||||
|
me.imageController.insertImage(fp.info.mime, content, hiddenImage.width, hiddenImage.height);
|
||||||
|
return document.body.removeChild(hiddenImage);
|
||||||
|
};
|
||||||
|
return hiddenImage.src = reader.result;
|
||||||
|
};
|
||||||
|
return reader.readAsDataURL(blob);
|
||||||
|
}, "binary");
|
||||||
|
}, __("Select image file"), {
|
||||||
|
mimes: ["image/.*"]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
closeDocument() {
|
closeDocument() {
|
||||||
var me, op;
|
var me, op;
|
||||||
// finish editing
|
// finish editing
|
||||||
@ -354,7 +406,9 @@
|
|||||||
return me.notify("Document closed");
|
return me.notify("Document closed");
|
||||||
});
|
});
|
||||||
me.session = void 0;
|
me.session = void 0;
|
||||||
return me.directFormattingCtl = void 0;
|
me.directFormattingCtl = void 0;
|
||||||
|
me.textController = void 0;
|
||||||
|
return me.imageController = void 0;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -4,7 +4,7 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
|||||||
|
|
||||||
main: () ->
|
main: () ->
|
||||||
# load session class
|
# load session class
|
||||||
if not OpenPage.editorSession
|
if not OpenPage.EditorSession
|
||||||
require ["webodf/editor/EditorSession"], (ES) ->
|
require ["webodf/editor/EditorSession"], (ES) ->
|
||||||
OpenPage.EditorSession = ES
|
OpenPage.EditorSession = ES
|
||||||
@eventSubscriptions = new core.EventSubscriptions()
|
@eventSubscriptions = new core.EventSubscriptions()
|
||||||
@ -56,9 +56,9 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
|||||||
@userid = "localuser"
|
@userid = "localuser"
|
||||||
@canvas = new odf.OdfCanvas(el)
|
@canvas = new odf.OdfCanvas(el)
|
||||||
@documentChanged = (e) ->
|
@documentChanged = (e) ->
|
||||||
console.log e
|
#console.log e
|
||||||
@metaChanged = (e) ->
|
@metaChanged = (e) ->
|
||||||
console.log e
|
#console.log e
|
||||||
@textStylingChanged = (e) ->
|
@textStylingChanged = (e) ->
|
||||||
me.updateToolbar e
|
me.updateToolbar e
|
||||||
#@canvas.enableAnnotations(true, true)
|
#@canvas.enableAnnotations(true, true)
|
||||||
@ -91,6 +91,13 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
|||||||
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalParagraphChanged, ()-> me.updateHyperlinkButtons()
|
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalParagraphChanged, ()-> me.updateHyperlinkButtons()
|
||||||
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalParagraphStyleModified, ()-> me.updateHyperlinkButtons()
|
me.eventSubscriptions.addFrameSubscription me.editorSession, OpenPage.EditorSession.signalParagraphStyleModified, ()-> me.updateHyperlinkButtons()
|
||||||
|
|
||||||
|
#image controller
|
||||||
|
me.imageController = me.editorSession.sessionController.getImageController()
|
||||||
|
#imageController.subscribe(gui.ImageController.enabledChanged, enableButtons)
|
||||||
|
|
||||||
|
#text controller
|
||||||
|
me.textController = me.editorSession.sessionController.getTextController()
|
||||||
|
|
||||||
me.editorSession.sessionController.setUndoManager new gui.TrivialUndoManager()
|
me.editorSession.sessionController.setUndoManager new gui.TrivialUndoManager()
|
||||||
me.editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged
|
me.editorSession.sessionController.getUndoManager().subscribe gui.UndoManager.signalDocumentModifiedChanged, me.documentChanged
|
||||||
me.editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, me.metaChanged
|
me.editorSession.sessionController.getMetadataController().subscribe gui.MetadataController.signalMetadataChanged, me.metaChanged
|
||||||
@ -220,6 +227,38 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
|||||||
unlink: (e) ->
|
unlink: (e) ->
|
||||||
@hyperlinkController.removeHyperlinks()
|
@hyperlinkController.removeHyperlinks()
|
||||||
|
|
||||||
|
undo: (e) ->
|
||||||
|
@editorSession.undo()
|
||||||
|
|
||||||
|
redo: (e) ->
|
||||||
|
@editorSession.redo()
|
||||||
|
|
||||||
|
image: (e) ->
|
||||||
|
me = @
|
||||||
|
@openDialog "FileDiaLog", (d, n, p) ->
|
||||||
|
fp = p.asFileHandler()
|
||||||
|
fp.asFileHandler().read (data) ->
|
||||||
|
blob = new Blob [data], { type: fp.info.mime }
|
||||||
|
reader = new FileReader()
|
||||||
|
reader.onloadend = () ->
|
||||||
|
return me.error __("Couldnt load image {0}", p) if reader.readyState isnt 2
|
||||||
|
# insert the image to document
|
||||||
|
hiddenImage = new Image()
|
||||||
|
hiddenImage.style.position = "absolute"
|
||||||
|
hiddenImage.style.left = "-99999px"
|
||||||
|
document.body.appendChild hiddenImage
|
||||||
|
hiddenImage.onload = () ->
|
||||||
|
content = reader.result.substring(reader.result.indexOf(",") + 1)
|
||||||
|
#insert image
|
||||||
|
me.textController.removeCurrentSelection()
|
||||||
|
me.imageController.insertImage fp.info.mime, content, hiddenImage.width, hiddenImage.height
|
||||||
|
document.body.removeChild hiddenImage
|
||||||
|
hiddenImage.src = reader.result
|
||||||
|
|
||||||
|
reader.readAsDataURL blob
|
||||||
|
, "binary"
|
||||||
|
, __("Select image file"), { mimes: ["image/.*"] }
|
||||||
|
|
||||||
closeDocument: () ->
|
closeDocument: () ->
|
||||||
# finish editing
|
# finish editing
|
||||||
return unless @editorSession and @session
|
return unless @editorSession and @session
|
||||||
@ -252,6 +291,8 @@ class OpenPage extends this.OS.GUI.BaseApplication
|
|||||||
me.notify "Document closed"
|
me.notify "Document closed"
|
||||||
me.session = undefined
|
me.session = undefined
|
||||||
me.directFormattingCtl = undefined
|
me.directFormattingCtl = undefined
|
||||||
|
me.textController = undefined
|
||||||
|
me.imageController = undefined
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button:hover, afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button.btactive button
|
afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button:hover, afx-app-window[data-id="OpenPage"] afx-hbox[data-id="toolbox"] afx-button button.btactive
|
||||||
{
|
{
|
||||||
border: 1px solid #759DC0;
|
border: 1px solid #759DC0;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
|
Loading…
Reference in New Issue
Block a user