This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/
class.CodePressEditor.js
113 lines (103 loc) · 4.07 KB
/
class.CodePressEditor.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
/*
* Copyright 2007-2011 Charles du Jeu <contact (at) cdujeu.me>
* This file is part of AjaXplorer.
*
* AjaXplorer 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.
*
* AjaXplorer 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 AjaXplorer. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://www.ajaxplorer.info/>.
*/
Class.create("CodePressEditor", TextEditor, {
initialize: function($super, oFormObject, options)
{
$super(oFormObject, options);
},
open : function($super, node){
this.inputNode = node;
var fileName = node.getPath();
// CREATE GUI
var cpStyle = this.codePressStyle(getBaseName(fileName));
var textarea;
this.textareaContainer = document.createElement('div');
this.textarea = $(document.createElement('textarea'));
var hidden = document.createElement('input');
hidden.type = 'hidden';
hidden.name = hidden.id = 'content';
this.element.appendChild(hidden);
this.textarea.name = this.textarea.id = 'cpCode';
$(this.textarea).addClassName('codepress');
$(this.textarea).addClassName(cpStyle);
//$(this.textarea).addClassName('linenumbers-on');
this.currentUseCp = true;
this.contentMainContainer = this.textarea.parentNode;
this.element.observe("editor:resize", function(event){
var cpIframe = $(this.contentMainContainer).select('iframe')[0];
if(!cpIframe) return;
if(event.memo && Object.isNumber(event.memo)){
cpIframe.setStyle({height:event.memo});
}else{
cpIframe.setStyle({width:'100%'});
fitHeightToBottom(cpIframe, this.element);
}
}.bind(this));
this.element.observe("editor:enterFS", function(e){this.textarea.value = this.element.select('iframe')[0].getCode();}.bind(this) );
this.element.observe("editor:exitFS", function(e){this.textarea.value = this.element.select('iframe')[0].getCode();}.bind(this) );
this.textarea.setStyle({width:'100%'});
this.textarea.setAttribute('wrap', 'off');
this.element.appendChild(this.textareaContainer);
this.textareaContainer.appendChild(this.textarea);
fitHeightToBottom($(this.textarea), $(modal.elementName));
// LOAD FILE NOW
this.loadFileContent(fileName);
if(window.ajxpMobile){
this.setFullScreen();
attachMobileScroll(this.textarea, "vertical");
}
},
saveFile : function(){
var connexion = this.prepareSaveConnexion();
var value;
value = this.element.select('iframe')[0].getCode();
this.textarea.value = value;
connexion.addParameter('content', value);
connexion.sendAsync();
},
parseTxt : function(transport){
this.textarea.value = transport.responseText;
var contentObserver = function(el, value){
this.setModified(true);
}.bind(this);
this.textarea.id = 'cpCode_cp';
code = new CodePress(this.textarea, contentObserver);
this.cpCodeObject = code;
this.textarea.parentNode.insertBefore(code, this.textarea);
this.contentMainContainer = this.textarea.parentNode;
this.element.observe("editor:close", function(){
this.cpCodeObject.close();
modal.clearContent(modal.dialogContent);
}, this );
this.removeOnLoad(this.textareaContainer);
},
codePressStyle : function(fileName)
{
if(Prototype.Browser.Opera) return "";
if(fileName.search('\.php$|\.php3$|\.php5$|\.phtml$') > -1) return "php";
else if (fileName.search("\.js$") > -1) return "javascript";
else if (fileName.search("\.java$") > -1) return "java";
else if (fileName.search("\.pl$") > -1) return "perl";
else if (fileName.search("\.sql$") > -1) return "sql";
else if (fileName.search("\.htm$|\.html$|\.xml$") > -1) return "html";
else if (fileName.search("\.css$") > -1) return "css";
else return "";
}
});