imagine_cms 4.1.4 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +2 -1
- data/app/assets/images/interface/form_loading.gif +0 -0
- data/app/assets/images/management/btn-top-delete.png +0 -0
- data/app/assets/images/management/btn-top-edit.png +0 -0
- data/app/assets/images/management/btn-top-exterminate.png +0 -0
- data/app/assets/images/management/btn-top-new.png +0 -0
- data/app/assets/images/management/btn-top-preview.png +0 -0
- data/app/assets/images/management/btn-top-properties.png +0 -0
- data/app/assets/javascripts/codemirror/modes-custom/imagine_cms.js +87 -0
- data/app/assets/javascripts/imagine_cms/core.js +510 -0
- data/app/assets/javascripts/imagine_cms/legacy/misc.js +537 -0
- data/app/assets/javascripts/imagine_cms/legacy/rollovers.js +193 -0
- data/app/assets/javascripts/imagine_cms/legacy/slideshow.js +116 -0
- data/app/assets/javascripts/imagine_cms/legacy/textfieldhints.js +55 -0
- data/app/assets/javascripts/imagine_cms.js +14 -1
- data/app/assets/javascripts/imagine_cms_compat.js +26 -0
- data/app/assets/javascripts/jquery-ui.js +16608 -0
- data/app/assets/javascripts/tag-it.js +591 -0
- data/app/assets/stylesheets/imagine_cms.css.scss +26 -10
- data/app/assets/stylesheets/imagine_controls.css.scss +8 -0
- data/app/assets/stylesheets/jquery-ui.css +1225 -0
- data/app/assets/stylesheets/jquery-ui.structure.css +833 -0
- data/app/assets/stylesheets/jquery-ui.theme.css +410 -0
- data/app/assets/stylesheets/jquery.tagit.css +69 -0
- data/app/assets/stylesheets/management.css.scss +7 -0
- data/app/assets/stylesheets/tagit.ui-imagine.css +100 -0
- data/app/controllers/cms/content_controller.rb +28 -45
- data/app/controllers/management/cms_controller.rb +116 -94
- data/app/helpers/cms_application_helper.rb +76 -39
- data/app/models/cms_page.rb +32 -14
- data/app/models/cms_page_object.rb +1 -1
- data/app/models/cms_page_tag.rb +2 -2
- data/app/models/cms_template.rb +1 -1
- data/app/models/user.rb +6 -6
- data/app/models/user_group.rb +1 -1
- data/app/views/cms/content/_photo_gallery.html.erb +12 -12
- data/app/views/cms/content/_search.html.erb +2 -2
- data/app/views/cms/content/_search_result.html.erb +16 -10
- data/app/views/layouts/management.html.erb +18 -17
- data/app/views/management/cms/_edit_page.html.erb +47 -33
- data/app/views/management/cms/_gallery_index.html.erb +4 -4
- data/app/views/management/cms/_image.html.erb +3 -3
- data/app/views/management/cms/_image_details.html.erb +9 -8
- data/app/views/management/cms/_list_page.html.erb +2 -2
- data/app/views/management/cms/_list_page_select.html.erb +1 -1
- data/app/views/management/cms/_page_list.html.erb +69 -48
- data/app/views/management/cms/_page_list_source_folder.html.erb +2 -2
- data/app/views/management/cms/_template_options.html.erb +4 -4
- data/app/views/management/cms/_template_reference.html.erb +13 -15
- data/app/views/management/cms/edit_page_content.html.erb +3 -3
- data/app/views/management/cms/edit_snippet.html.erb +19 -41
- data/app/views/management/cms/edit_template.html.erb +15 -38
- data/app/views/management/cms/pages.html.erb +17 -29
- data/app/views/management/cms/snippets.html.erb +2 -2
- data/app/views/management/cms/templates.html.erb +2 -2
- data/app/views/management/cms/toolbar_edit.html.erb +2 -0
- data/app/views/management/cms/toolbar_preview.html.erb +2 -2
- data/config/initializers/config_file.rb +1 -1
- data/imagine_cms.gemspec +7 -4
- data/lib/extensions/action_controller_extensions.rb +50 -19
- data/lib/imagine_cms/engine.rb +12 -8
- data/lib/imagine_cms/version.rb +1 -1
- data/lib/prototype_legacy_helper/lib/prototype_legacy_helper.rb +2 -2
- data/lib/tasks/imagine_cms_tasks.rake +8 -0
- metadata +69 -91
- data/app/assets/images/management/btn_archive.gif +0 -0
- data/app/assets/images/management/btn_delete.gif +0 -0
- data/app/assets/images/management/btn_duplicate.gif +0 -0
- data/app/assets/images/management/btn_edit.gif +0 -0
- data/app/assets/images/management/btn_new_page.gif +0 -0
- data/app/assets/images/management/btn_preview.gif +0 -0
- data/app/assets/images/management/btn_properties.gif +0 -0
- data/app/assets/images/management/btn_restore.gif +0 -0
- data/app/assets/images/management/btn_top_delete.gif +0 -0
- data/app/assets/images/management/btn_top_duplicate.gif +0 -0
- data/app/assets/images/management/btn_top_edit.gif +0 -0
- data/app/assets/images/management/btn_top_new.gif +0 -0
- data/app/assets/images/management/btn_top_preview.gif +0 -0
- data/app/assets/images/management/btn_top_properties.gif +0 -0
- data/app/assets/javascripts/codepress/codepress.html +0 -36
- data/app/assets/javascripts/codepress/codepress.js +0 -130
- data/app/assets/javascripts/codepress/engines/gecko.js +0 -240
- data/app/assets/javascripts/codepress/engines/khtml.js +0 -0
- data/app/assets/javascripts/codepress/engines/msie.js +0 -263
- data/app/assets/javascripts/codepress/engines/older.js +0 -0
- data/app/assets/javascripts/codepress/engines/opera.js +0 -259
- data/app/assets/javascripts/codepress/languages/css.js +0 -23
- data/app/assets/javascripts/codepress/languages/generic.js +0 -25
- data/app/assets/javascripts/codepress/languages/html.js +0 -63
- data/app/assets/javascripts/codepress/languages/java.js +0 -24
- data/app/assets/javascripts/codepress/languages/javascript.js +0 -30
- data/app/assets/javascripts/codepress/languages/perl.js +0 -27
- data/app/assets/javascripts/codepress/languages/php.js +0 -60
- data/app/assets/javascripts/codepress/languages/ruby.js +0 -26
- data/app/assets/javascripts/codepress/languages/sql.js +0 -30
- data/app/assets/javascripts/codepress/languages/text.js +0 -9
- data/app/assets/javascripts/imagine.js +0 -1393
- data/app/assets/stylesheets/codepress/codepress.css +0 -7
- data/app/assets/stylesheets/codepress/languages/css.css +0 -10
- data/app/assets/stylesheets/codepress/languages/generic.css +0 -9
- data/app/assets/stylesheets/codepress/languages/html.css +0 -18
- data/app/assets/stylesheets/codepress/languages/java.css +0 -7
- data/app/assets/stylesheets/codepress/languages/javascript.css +0 -8
- data/app/assets/stylesheets/codepress/languages/perl.css +0 -11
- data/app/assets/stylesheets/codepress/languages/php.css +0 -12
- data/app/assets/stylesheets/codepress/languages/ruby.css +0 -10
- data/app/assets/stylesheets/codepress/languages/sql.css +0 -10
- data/app/assets/stylesheets/codepress/languages/text.css +0 -5
@@ -1,240 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* CodePress - Real Time Syntax Highlighting Editor written in JavaScript - http://codepress.org/
|
3
|
-
*
|
4
|
-
* Copyright (C) 2007 Fernando M.A.d.S. <fermads@gmail.com>
|
5
|
-
*
|
6
|
-
* Contributors :
|
7
|
-
*
|
8
|
-
* Michael Hurni <michael.hurni@gmail.com>
|
9
|
-
*
|
10
|
-
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
11
|
-
* GNU Lesser General Public License as published by the Free Software Foundation.
|
12
|
-
*
|
13
|
-
* Read the full licence: http://www.opensource.org/licenses/lgpl-license.php
|
14
|
-
*/
|
15
|
-
|
16
|
-
|
17
|
-
CodePress = {
|
18
|
-
scrolling : false,
|
19
|
-
autocomplete : true,
|
20
|
-
|
21
|
-
// set initial vars and start sh
|
22
|
-
initialize : function() {
|
23
|
-
if(typeof(editor)=='undefined' && !arguments[0]) return;
|
24
|
-
chars = '|32|46|62|'; // charcodes that trigger syntax highlighting
|
25
|
-
cc = '\u2009'; // control char
|
26
|
-
editor = document.getElementsByTagName('body')[0];
|
27
|
-
document.designMode = 'on';
|
28
|
-
document.addEventListener('keypress', this.keyHandler, true);
|
29
|
-
window.addEventListener('scroll', function() { if(!CodePress.scrolling) CodePress.syntaxHighlight('scroll') }, false);
|
30
|
-
completeChars = this.getCompleteChars();
|
31
|
-
// CodePress.syntaxHighlight('init');
|
32
|
-
},
|
33
|
-
|
34
|
-
// treat key bindings
|
35
|
-
keyHandler : function(evt) {
|
36
|
-
keyCode = evt.keyCode;
|
37
|
-
charCode = evt.charCode;
|
38
|
-
|
39
|
-
if((evt.ctrlKey || evt.metaKey) && evt.shiftKey && charCode!=90) { // shortcuts = ctrl||appleKey+shift+key!=z(undo)
|
40
|
-
CodePress.shortcuts(charCode?charCode:keyCode);
|
41
|
-
}
|
42
|
-
else if(completeChars.indexOf('|'+String.fromCharCode(charCode)+'|')!=-1 && CodePress.autocomplete) { // auto complete
|
43
|
-
CodePress.complete(String.fromCharCode(charCode));
|
44
|
-
}
|
45
|
-
else if(chars.indexOf('|'+charCode+'|')!=-1||keyCode==13) { // syntax highlighting
|
46
|
-
CodePress.syntaxHighlight('generic');
|
47
|
-
}
|
48
|
-
else if(keyCode==9 || evt.tabKey) { // snippets activation (tab)
|
49
|
-
CodePress.snippets(evt);
|
50
|
-
}
|
51
|
-
else if(keyCode==46||keyCode==8) { // save to history when delete or backspace pressed
|
52
|
-
CodePress.actions.history[CodePress.actions.next()] = editor.innerHTML;
|
53
|
-
}
|
54
|
-
else if((charCode==122||charCode==121||charCode==90) && evt.ctrlKey) { // undo and redo
|
55
|
-
(charCode==121||evt.shiftKey) ? CodePress.actions.redo() : CodePress.actions.undo();
|
56
|
-
evt.preventDefault();
|
57
|
-
}
|
58
|
-
else if(keyCode==86 && evt.ctrlKey) { // paste
|
59
|
-
// TODO: pasted text should be parsed and highlighted
|
60
|
-
}
|
61
|
-
},
|
62
|
-
|
63
|
-
// put cursor back to its original position after every parsing
|
64
|
-
findString : function() {
|
65
|
-
if(self.find(cc))
|
66
|
-
window.getSelection().getRangeAt(0).deleteContents();
|
67
|
-
},
|
68
|
-
|
69
|
-
// split big files, highlighting parts of it
|
70
|
-
split : function(code,flag) {
|
71
|
-
if(flag=='scroll') {
|
72
|
-
this.scrolling = true;
|
73
|
-
return code;
|
74
|
-
}
|
75
|
-
else {
|
76
|
-
this.scrolling = false;
|
77
|
-
mid = code.indexOf(cc);
|
78
|
-
if(mid-2000<0) {ini=0;end=4000;}
|
79
|
-
else if(mid+2000>code.length) {ini=code.length-4000;end=code.length;}
|
80
|
-
else {ini=mid-2000;end=mid+2000;}
|
81
|
-
code = code.substring(ini,end);
|
82
|
-
return code;
|
83
|
-
}
|
84
|
-
},
|
85
|
-
|
86
|
-
// syntax highlighting parser
|
87
|
-
syntaxHighlight : function(flag) {
|
88
|
-
//if(document.designMode=='off') document.designMode='on'
|
89
|
-
if(flag!='init') window.getSelection().getRangeAt(0).insertNode(document.createTextNode(cc));
|
90
|
-
|
91
|
-
o = editor.innerHTML;
|
92
|
-
o = o.replace(/<br>/g,'\n');
|
93
|
-
o = o.replace(/<.*?>/g,'');
|
94
|
-
x = z = this.split(o,flag);
|
95
|
-
x = x.replace(/\n/g,'<br>');
|
96
|
-
|
97
|
-
if(arguments[1]&&arguments[2]) x = x.replace(arguments[1],arguments[2]);
|
98
|
-
|
99
|
-
for(i=0;i<Language.syntax.length;i++)
|
100
|
-
x = x.replace(Language.syntax[i].input,Language.syntax[i].output);
|
101
|
-
|
102
|
-
editor.innerHTML = this.actions.history[this.actions.next()] = (flag=='scroll') ? x : o.split(z).join(x);
|
103
|
-
if(flag!='init') this.findString();
|
104
|
-
},
|
105
|
-
|
106
|
-
getLastWord : function() {
|
107
|
-
var rangeAndCaret = CodePress.getRangeAndCaret();
|
108
|
-
var words = rangeAndCaret[0].substring(rangeAndCaret[1]-40,rangeAndCaret[1]).split(/[\s\r\n\);]/);
|
109
|
-
return words[words.length-1].replace(/_/g,'');
|
110
|
-
},
|
111
|
-
|
112
|
-
snippets : function(evt) {
|
113
|
-
var snippets = Language.snippets;
|
114
|
-
var trigger = this.getLastWord();
|
115
|
-
for (var i=0; i<snippets.length; i++) {
|
116
|
-
if(snippets[i].input == trigger) {
|
117
|
-
var content = snippets[i].output.replace(/</g,'<');
|
118
|
-
content = content.replace(/>/g,'>');
|
119
|
-
if(content.indexOf('$0')<0) content += cc;
|
120
|
-
else content = content.replace(/\$0/,cc);
|
121
|
-
content = content.replace(/\n/g,'<br>');
|
122
|
-
var pattern = new RegExp(trigger+cc,'g');
|
123
|
-
evt.preventDefault(); // prevent the tab key from being added
|
124
|
-
this.syntaxHighlight('snippets',pattern,content);
|
125
|
-
}
|
126
|
-
}
|
127
|
-
},
|
128
|
-
|
129
|
-
readOnly : function() {
|
130
|
-
document.designMode = (arguments[0]) ? 'off' : 'on';
|
131
|
-
},
|
132
|
-
|
133
|
-
complete : function(trigger) {
|
134
|
-
window.getSelection().getRangeAt(0).deleteContents();
|
135
|
-
var complete = Language.complete;
|
136
|
-
for (var i=0; i<complete.length; i++) {
|
137
|
-
if(complete[i].input == trigger) {
|
138
|
-
var pattern = new RegExp('\\'+trigger+cc);
|
139
|
-
var content = complete[i].output.replace(/\$0/g,cc);
|
140
|
-
parent.setTimeout(function () { CodePress.syntaxHighlight('complete',pattern,content)},0); // wait for char to appear on screen
|
141
|
-
}
|
142
|
-
}
|
143
|
-
},
|
144
|
-
|
145
|
-
getCompleteChars : function() {
|
146
|
-
var cChars = '';
|
147
|
-
for(var i=0;i<Language.complete.length;i++)
|
148
|
-
cChars += '|'+Language.complete[i].input;
|
149
|
-
return cChars+'|';
|
150
|
-
},
|
151
|
-
|
152
|
-
shortcuts : function() {
|
153
|
-
var cCode = arguments[0];
|
154
|
-
if(cCode==13) cCode = '[enter]';
|
155
|
-
else if(cCode==32) cCode = '[space]';
|
156
|
-
else cCode = '['+String.fromCharCode(charCode).toLowerCase()+']';
|
157
|
-
for(var i=0;i<Language.shortcuts.length;i++)
|
158
|
-
if(Language.shortcuts[i].input == cCode)
|
159
|
-
this.insertCode(Language.shortcuts[i].output,false);
|
160
|
-
},
|
161
|
-
|
162
|
-
getRangeAndCaret : function() {
|
163
|
-
var range = window.getSelection().getRangeAt(0);
|
164
|
-
var range2 = range.cloneRange();
|
165
|
-
var node = range.endContainer;
|
166
|
-
var caret = range.endOffset;
|
167
|
-
range2.selectNode(node);
|
168
|
-
return [range2.toString(),caret];
|
169
|
-
},
|
170
|
-
|
171
|
-
insertCode : function(code,replaceCursorBefore) {
|
172
|
-
var range = window.getSelection().getRangeAt(0);
|
173
|
-
var node = window.document.createTextNode(code);
|
174
|
-
var selct = window.getSelection();
|
175
|
-
var range2 = range.cloneRange();
|
176
|
-
// Insert text at cursor position
|
177
|
-
selct.removeAllRanges();
|
178
|
-
range.deleteContents();
|
179
|
-
range.insertNode(node);
|
180
|
-
// Move the cursor to the end of text
|
181
|
-
range2.selectNode(node);
|
182
|
-
range2.collapse(replaceCursorBefore);
|
183
|
-
selct.removeAllRanges();
|
184
|
-
selct.addRange(range2);
|
185
|
-
},
|
186
|
-
|
187
|
-
// get code from editor
|
188
|
-
getCode : function() {
|
189
|
-
var code = editor.innerHTML;
|
190
|
-
code = code.replace(/<br>/g,'\n');
|
191
|
-
code = code.replace(/\u2009/g,'');
|
192
|
-
code = code.replace(/<.*?>/g,'');
|
193
|
-
code = code.replace(/</g,'<');
|
194
|
-
code = code.replace(/>/g,'>');
|
195
|
-
code = code.replace(/&/gi,'&');
|
196
|
-
return code;
|
197
|
-
},
|
198
|
-
|
199
|
-
// put code inside editor
|
200
|
-
setCode : function() {
|
201
|
-
var code = arguments[0];
|
202
|
-
code = code.replace(/\u2009/gi,'');
|
203
|
-
code = code.replace(/&/gi,'&');
|
204
|
-
code = code.replace(/</g,'<');
|
205
|
-
code = code.replace(/>/g,'>');
|
206
|
-
editor.innerHTML = code;
|
207
|
-
},
|
208
|
-
|
209
|
-
// undo and redo methods
|
210
|
-
actions : {
|
211
|
-
pos : -1, // actual history position
|
212
|
-
history : [], // history vector
|
213
|
-
|
214
|
-
undo : function() {
|
215
|
-
if(editor.innerHTML.indexOf(cc)==-1){
|
216
|
-
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(cc));
|
217
|
-
this.history[this.pos] = editor.innerHTML;
|
218
|
-
}
|
219
|
-
this.pos--;
|
220
|
-
if(typeof(this.history[this.pos])=='undefined') this.pos++;
|
221
|
-
editor.innerHTML = this.history[this.pos];
|
222
|
-
CodePress.findString();
|
223
|
-
},
|
224
|
-
|
225
|
-
redo : function() {
|
226
|
-
this.pos++;
|
227
|
-
if(typeof(this.history[this.pos])=='undefined') this.pos--;
|
228
|
-
editor.innerHTML = this.history[this.pos];
|
229
|
-
CodePress.findString();
|
230
|
-
},
|
231
|
-
|
232
|
-
next : function() { // get next vector position and clean old ones
|
233
|
-
if(this.pos>20) this.history[this.pos-21] = undefined;
|
234
|
-
return ++this.pos;
|
235
|
-
}
|
236
|
-
}
|
237
|
-
}
|
238
|
-
|
239
|
-
Language={};
|
240
|
-
window.addEventListener('load', function() { CodePress.initialize('new'); }, true);
|
File without changes
|
@@ -1,263 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* CodePress - Real Time Syntax Highlighting Editor written in JavaScript - http://codepress.org/
|
3
|
-
*
|
4
|
-
* Copyright (C) 2007 Fernando M.A.d.S. <fermads@gmail.com>
|
5
|
-
*
|
6
|
-
* Contributors :
|
7
|
-
*
|
8
|
-
* Michael Hurni <michael.hurni@gmail.com>
|
9
|
-
*
|
10
|
-
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
11
|
-
* GNU Lesser General Public License as published by the Free Software Foundation.
|
12
|
-
*
|
13
|
-
* Read the full licence: http://www.opensource.org/licenses/lgpl-license.php
|
14
|
-
*/
|
15
|
-
|
16
|
-
|
17
|
-
CodePress = {
|
18
|
-
scrolling : false,
|
19
|
-
autocomplete : true,
|
20
|
-
|
21
|
-
// set initial vars and start sh
|
22
|
-
initialize : function() {
|
23
|
-
if(typeof(editor)=='undefined' && !arguments[0]) return;
|
24
|
-
chars = '|32|46|62|'; // charcodes that trigger syntax highlighting
|
25
|
-
cc = '\u2009'; // control char
|
26
|
-
editor = document.getElementsByTagName('pre')[0];
|
27
|
-
editor.contentEditable = 'true';
|
28
|
-
document.getElementsByTagName('body')[0].onfocus = function() {editor.focus();}
|
29
|
-
document.attachEvent('onkeydown', this.metaHandler);
|
30
|
-
document.attachEvent('onkeypress', this.keyHandler);
|
31
|
-
window.attachEvent('onscroll', function() { if(!CodePress.scrolling) setTimeout(function(){CodePress.syntaxHighlight('scroll')},1)});
|
32
|
-
completeChars = this.getCompleteChars();
|
33
|
-
// CodePress.syntaxHighlight('init');
|
34
|
-
setTimeout(function() { window.scroll(0,0) },50); // scroll IE to top
|
35
|
-
},
|
36
|
-
|
37
|
-
// treat key bindings
|
38
|
-
keyHandler : function(evt) {
|
39
|
-
charCode = evt.keyCode;
|
40
|
-
if(completeChars.indexOf('|'+String.fromCharCode(charCode)+'|')!=-1 && CodePress.autocomplete) { // auto complete
|
41
|
-
CodePress.complete(String.fromCharCode(charCode))
|
42
|
-
}
|
43
|
-
else if(chars.indexOf('|'+charCode+'|')!=-1||charCode==13) { // syntax highlighting
|
44
|
-
CodePress.syntaxHighlight('generic');
|
45
|
-
}
|
46
|
-
},
|
47
|
-
|
48
|
-
metaHandler : function(evt) {
|
49
|
-
keyCode = evt.keyCode;
|
50
|
-
if(keyCode==9 || evt.tabKey) {
|
51
|
-
CodePress.snippets();
|
52
|
-
}
|
53
|
-
else if((keyCode==122||keyCode==121||keyCode==90) && evt.ctrlKey) { // undo and redo
|
54
|
-
(keyCode==121||evt.shiftKey) ? CodePress.actions.redo() : CodePress.actions.undo();
|
55
|
-
evt.returnValue = false;
|
56
|
-
}
|
57
|
-
else if(keyCode==34||keyCode==33) { // handle page up/down for IE
|
58
|
-
self.scrollBy(0, (keyCode==34) ? 200 : -200);
|
59
|
-
evt.returnValue = false;
|
60
|
-
}
|
61
|
-
else if(keyCode==46||keyCode==8) { // save to history when delete or backspace pressed
|
62
|
-
CodePress.actions.history[CodePress.actions.next()] = editor.innerHTML;
|
63
|
-
}
|
64
|
-
else if((evt.ctrlKey || evt.metaKey) && evt.shiftKey && keyCode!=90) { // shortcuts = ctrl||appleKey+shift+key!=z(undo)
|
65
|
-
CodePress.shortcuts(keyCode);
|
66
|
-
evt.returnValue = false;
|
67
|
-
}
|
68
|
-
else if(keyCode==86 && evt.ctrlKey) { // paste
|
69
|
-
// TODO: pasted text should be parsed and highlighted
|
70
|
-
}
|
71
|
-
},
|
72
|
-
|
73
|
-
// put cursor back to its original position after every parsing
|
74
|
-
findString : function() {
|
75
|
-
range = self.document.body.createTextRange();
|
76
|
-
if(range.findText(cc)){
|
77
|
-
range.select();
|
78
|
-
range.text = '';
|
79
|
-
}
|
80
|
-
},
|
81
|
-
|
82
|
-
// split big files, highlighting parts of it
|
83
|
-
split : function(code,flag) {
|
84
|
-
if(flag=='scroll') {
|
85
|
-
this.scrolling = true;
|
86
|
-
return code;
|
87
|
-
}
|
88
|
-
else {
|
89
|
-
this.scrolling = false;
|
90
|
-
mid = code.indexOf(cc);
|
91
|
-
if(mid-2000<0) {ini=0;end=4000;}
|
92
|
-
else if(mid+2000>code.length) {ini=code.length-4000;end=code.length;}
|
93
|
-
else {ini=mid-2000;end=mid+2000;}
|
94
|
-
code = code.substring(ini,end);
|
95
|
-
return code.substring(code.indexOf('<P>'),code.lastIndexOf('</P>')+4);
|
96
|
-
}
|
97
|
-
},
|
98
|
-
|
99
|
-
// syntax highlighting parser
|
100
|
-
syntaxHighlight : function(flag) {
|
101
|
-
if(flag!='init') document.selection.createRange().text = cc;
|
102
|
-
o = editor.innerHTML;
|
103
|
-
o = o.replace(/<P>/g,'\n');
|
104
|
-
o = o.replace(/<\/P>/g,'\r');
|
105
|
-
o = o.replace(/<.*?>/g,'');
|
106
|
-
o = o.replace(/ /g,'');
|
107
|
-
o = '<PRE><P>'+o+'</P></PRE>';
|
108
|
-
o = o.replace(/\n\r/g,'<P></P>');
|
109
|
-
o = o.replace(/\n/g,'<P>');
|
110
|
-
o = o.replace(/\r/g,'<\/P>');
|
111
|
-
o = o.replace(/<P>(<P>)+/,'<P>');
|
112
|
-
o = o.replace(/<\/P>(<\/P>)+/,'</P>');
|
113
|
-
o = o.replace(/<P><\/P>/g,'<P><BR/></P>');
|
114
|
-
x = z = this.split(o,flag);
|
115
|
-
|
116
|
-
if(arguments[1]&&arguments[2]) x = x.replace(arguments[1],arguments[2]);
|
117
|
-
|
118
|
-
for(i=0;i<Language.syntax.length;i++)
|
119
|
-
x = x.replace(Language.syntax[i].input,Language.syntax[i].output);
|
120
|
-
|
121
|
-
editor.innerHTML = this.actions.history[this.actions.next()] = (flag=='scroll') ? x : o.replace(z,x);
|
122
|
-
if(flag!='init') this.findString();
|
123
|
-
},
|
124
|
-
|
125
|
-
snippets : function(evt) {
|
126
|
-
var snippets = Language.snippets;
|
127
|
-
var trigger = this.getLastWord();
|
128
|
-
for (var i=0; i<snippets.length; i++) {
|
129
|
-
if(snippets[i].input == trigger) {
|
130
|
-
var content = snippets[i].output.replace(/</g,'<');
|
131
|
-
content = content.replace(/>/g,'>');
|
132
|
-
if(content.indexOf('$0')<0) content += cc;
|
133
|
-
else content = content.replace(/\$0/,cc);
|
134
|
-
content = content.replace(/\n/g,'</P><P>');
|
135
|
-
var pattern = new RegExp(trigger+cc);
|
136
|
-
this.syntaxHighlight('snippets',pattern,content);
|
137
|
-
}
|
138
|
-
}
|
139
|
-
},
|
140
|
-
|
141
|
-
readOnly : function() {
|
142
|
-
editor.contentEditable = (arguments[0]) ? 'false' : 'true';
|
143
|
-
},
|
144
|
-
|
145
|
-
complete : function(trigger) {
|
146
|
-
var complete = Language.complete;
|
147
|
-
for (var i=0; i<complete.length; i++) {
|
148
|
-
if(complete[i].input == trigger) {
|
149
|
-
var pattern = new RegExp('\\'+trigger+cc);
|
150
|
-
var content = complete[i].output.replace(/\$0/g,cc);
|
151
|
-
setTimeout(function () { CodePress.syntaxHighlight('complete',pattern,content)},0); // wait for char to appear on screen
|
152
|
-
}
|
153
|
-
}
|
154
|
-
},
|
155
|
-
|
156
|
-
getCompleteChars : function() {
|
157
|
-
var cChars = '';
|
158
|
-
for(var i=0;i<Language.complete.length;i++)
|
159
|
-
cChars += '|'+Language.complete[i].input;
|
160
|
-
return cChars+'|';
|
161
|
-
},
|
162
|
-
|
163
|
-
shortcuts : function() {
|
164
|
-
var cCode = arguments[0];
|
165
|
-
if(cCode==13) cCode = '[enter]';
|
166
|
-
else if(cCode==32) cCode = '[space]';
|
167
|
-
else cCode = '['+String.fromCharCode(keyCode).toLowerCase()+']';
|
168
|
-
for(var i=0;i<Language.shortcuts.length;i++)
|
169
|
-
if(Language.shortcuts[i].input == cCode)
|
170
|
-
this.insertCode(Language.shortcuts[i].output,false);
|
171
|
-
},
|
172
|
-
|
173
|
-
getLastWord : function() {
|
174
|
-
var rangeAndCaret = CodePress.getRangeAndCaret();
|
175
|
-
words = rangeAndCaret[0].substring(rangeAndCaret[1]-40,rangeAndCaret[1]);
|
176
|
-
words = words.replace(/[\s\r\);]/g,'\n').split('\n');
|
177
|
-
return words[words.length-1];
|
178
|
-
},
|
179
|
-
|
180
|
-
getRangeAndCaret : function() {
|
181
|
-
var range = document.selection.createRange();
|
182
|
-
var caret = Math.abs(range.moveStart('character', -1000000)+1);
|
183
|
-
range = this.getCode();
|
184
|
-
range = range.replace(/\n\r/gi,' ');
|
185
|
-
range = range.replace(/\n/gi,'');
|
186
|
-
return [range.toString(),caret];
|
187
|
-
},
|
188
|
-
|
189
|
-
insertCode : function(code,replaceCursorBefore) {
|
190
|
-
var repdeb = '';
|
191
|
-
var repfin = '';
|
192
|
-
|
193
|
-
if(replaceCursorBefore) { repfin = code; }
|
194
|
-
else { repdeb = code; }
|
195
|
-
|
196
|
-
if(typeof document.selection != 'undefined') {
|
197
|
-
var range = document.selection.createRange();
|
198
|
-
range.text = repdeb + repfin;
|
199
|
-
range = document.selection.createRange();
|
200
|
-
range.move('character', -repfin.length);
|
201
|
-
range.select();
|
202
|
-
}
|
203
|
-
},
|
204
|
-
|
205
|
-
// get code from editor
|
206
|
-
getCode : function() {
|
207
|
-
var code = editor.innerHTML;
|
208
|
-
code = code.replace(/<br>/g,'\n');
|
209
|
-
code = code.replace(/<\/p>/gi,'\r');
|
210
|
-
code = code.replace(/<p>/i,''); // IE first line fix
|
211
|
-
code = code.replace(/<p>/gi,'\n');
|
212
|
-
code = code.replace(/ /gi,'');
|
213
|
-
code = code.replace(/\u2009/g,'');
|
214
|
-
code = code.replace(/<.*?>/g,'');
|
215
|
-
code = code.replace(/</g,'<');
|
216
|
-
code = code.replace(/>/g,'>');
|
217
|
-
code = code.replace(/&/gi,'&');
|
218
|
-
return code;
|
219
|
-
},
|
220
|
-
|
221
|
-
// put code inside editor
|
222
|
-
setCode : function() {
|
223
|
-
var code = arguments[0];
|
224
|
-
code = code.replace(/\u2009/gi,'');
|
225
|
-
code = code.replace(/&/gi,'&');
|
226
|
-
code = code.replace(/</g,'<');
|
227
|
-
code = code.replace(/>/g,'>');
|
228
|
-
editor.innerHTML = '<pre>'+code+'</pre>';
|
229
|
-
},
|
230
|
-
|
231
|
-
|
232
|
-
// undo and redo methods
|
233
|
-
actions : {
|
234
|
-
pos : -1, // actual history position
|
235
|
-
history : [], // history vector
|
236
|
-
|
237
|
-
undo : function() {
|
238
|
-
if(editor.innerHTML.indexOf(cc)==-1){
|
239
|
-
document.selection.createRange().text = cc;
|
240
|
-
this.history[this.pos] = editor.innerHTML;
|
241
|
-
}
|
242
|
-
this.pos--;
|
243
|
-
if(typeof(this.history[this.pos])=='undefined') this.pos++;
|
244
|
-
editor.innerHTML = this.history[this.pos];
|
245
|
-
CodePress.findString();
|
246
|
-
},
|
247
|
-
|
248
|
-
redo : function() {
|
249
|
-
this.pos++;
|
250
|
-
if(typeof(this.history[this.pos])=='undefined') this.pos--;
|
251
|
-
editor.innerHTML = this.history[this.pos];
|
252
|
-
CodePress.findString();
|
253
|
-
},
|
254
|
-
|
255
|
-
next : function() { // get next vector position and clean old ones
|
256
|
-
if(this.pos>20) this.history[this.pos-21] = undefined;
|
257
|
-
return ++this.pos;
|
258
|
-
}
|
259
|
-
}
|
260
|
-
}
|
261
|
-
|
262
|
-
Language={};
|
263
|
-
window.attachEvent('onload', function() { CodePress.initialize('new');});
|
File without changes
|