This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/
class.PixlrEditor.js
142 lines (131 loc) · 5.23 KB
/
class.PixlrEditor.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/
Class.create("PixlrEditor", AbstractEditor, {
fullscreenMode: false,
initialize: function($super, oFormObject, options)
{
this.editorOptions = options;
this.element = $(oFormObject);
this.defaultActions = new Hash();
this.createTitleSpans();
modal.setCloseAction(function(){this.close();}.bind(this));
this.container = $(oFormObject).select('div[id="pixlrContainer"]')[0];
fitHeightToBottom($(this.container), $(options.context.elementName));
this.contentMainContainer = new Element("iframe", {
style:"border:none;width:100%;"
});
this.container.update(this.contentMainContainer);
},
resize:function($super, s){
$super(s);
fitHeightToBottom(this.element);
fitHeightToBottom(this.container, this.element);
fitHeightToBottom(this.contentMainContainer);
},
save : function(pixlrUrl){
this.setOnLoad();
var conn = new Connexion();
conn.addParameter("get_action", "retrieve_pixlr_image");
conn.addParameter("original_file", this.currentNode.getPath());
conn.addParameter("new_url", pixlrUrl);
conn.onComplete = function(transp){
var date = new Date();
this.currentNode.getParent().getMetadata().set('preview_seed', Math.round(date.getTime()*Math.random()));
this.removeOnLoad();
if(this.editorOptions.context.__className == "Modal"){
hideLightBox(true);
}else if(this.editorOptions.context.__className == "AjxpTabulator"){
this.editorOptions.context.closeTab("editor.pixlr:/" + this.currentNode.getPath());
}
ajaxplorer.actionBar.fireAction('refresh');
}.bind(this);
conn.sendAsync();
},
open : function($super, node)
{
this.setOnLoad(true);
this.currentNode = node;
var fName = this.currentNode.getPath();
var src = ajxpBootstrap.parameters.get('ajxpServerAccess')+"&get_action=post_to_server&file=" + base64_encode(fName) + "&parent_url=" + base64_encode(getRepName(document.location.href));
this.contentMainContainer.src = src;
var pe = new PeriodicalExecuter(function(){
var href;
try{
href = this.contentMainContainer.contentDocument.location.href;
}catch(e){
if(this.loading){
this.resize();
// Force here for WebKit
this.contentMainContainer.setStyle({height:this.container.getHeight() + 'px'});
this.removeOnLoad();
}
}
if(href && href.indexOf('image=') > -1){
pe.stop();
this.save(href);
}else if(href && href.indexOf('close_pixlr')>-1){
pe.stop();
hideLightBox(true);
}
}.bind(this) , 0.5);
this.element.fire("editor:updateTitle", node.getLabel());
return;
},
setOnLoad: function(openMessage){
if(this.loading) return;
addLightboxMarkupToElement(this.container);
var waiter = new Element("div", {align:"center", style:"font-family:Arial, Helvetica, Sans-serif;font-size:25px;color:#AAA;font-weight:bold;"});
if(openMessage){
waiter.update('<br><br><br>Please wait while opening Pixlr editor...<br>');
}
waiter.insert(new Element("img", {src:ajxpResourcesFolder+'/images/loadingImage.gif'}));
$(this.container).select("#element_overlay")[0].insert(waiter);
this.loading = true;
},
removeOnLoad: function(){
removeLightboxFromElement(this.container);
this.loading = false;
},
getPreview : function(ajxpNode){
if(ajxpNode.getAjxpMime() == "bmp" || ajxpNode.getAjxpMime() == "pxd"){
return AbstractEditor.prototype.getPreview(ajxpNode);
}
var img = new Element('img', {src:Diaporama.prototype.getThumbnailSource(ajxpNode), border:0});
img.resizePreviewElement = function(dimensionObject){
var imgDim = {
width:parseInt(ajxpNode.getMetadata().get("image_width")),
height:parseInt(ajxpNode.getMetadata().get("image_height"))
};
var styleObj = fitRectangleToDimension(imgDim, dimensionObject);
img.setStyle(styleObj);
};
return img;
},
getThumbnailSource : function(ajxpNode){
if(ajxpNode.getAjxpMime() == "bmp" || ajxpNode.getAjxpMime() == "pxd"){
return AbstractEditor.prototype.getThumbnailSource(ajxpNode);
}
var repoString = "";
if(ajaxplorer.repositoryId && ajxpNode.getMetadata().get("repository_id") && ajxpNode.getMetadata().get("repository_id") != ajaxplorer.repositoryId){
repoString = "&tmp_repository_id=" + ajxpNode.getMetadata().get("repository_id");
}
return ajxpServerAccessPath+"&get_action=preview_data_proxy"+repoString+"&get_thumb=true&file="+encodeURIComponent(ajxpNode.getPath());
}
});