unageanu-jiji 1.1.4 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +24 -1
- data/README +0 -0
- data/base/shared_lib/moving_average.rb +34 -33
- data/base/shared_lib/system/cross.rb +76 -0
- data/base/shared_lib/system/position_manager.rb +160 -0
- data/base/shared_lib/system/signal.rb +347 -0
- data/html/css/datatable.css +4 -4
- data/html/css/default.css +57 -5
- data/html/css/treeview.css +205 -0
- data/html/img/bin_closed.png +0 -0
- data/html/img/bin_empty.png +0 -0
- data/html/img/button_add_small.gif +0 -0
- data/html/img/button_add_small_gray.gif +0 -0
- data/html/img/button_add_small_over.gif +0 -0
- data/html/img/button_mkcol.gif +0 -0
- data/html/img/button_mkcol_gray.gif +0 -0
- data/html/img/button_mkcol_over.gif +0 -0
- data/html/img/button_remove_small.gif +0 -0
- data/html/img/button_remove_small_gray.gif +0 -0
- data/html/img/button_remove_small_over.gif +0 -0
- data/html/img/button_rename.gif +0 -0
- data/html/img/button_rename_gray.gif +0 -0
- data/html/img/button_rename_over.gif +0 -0
- data/html/img/control_play.png +0 -0
- data/html/img/control_play_blue.png +0 -0
- data/html/img/folder.png +0 -0
- data/html/img/folder_brick.png +0 -0
- data/html/img/folder_user.png +0 -0
- data/html/{js/codepress/images → img}/line-numbers.png +0 -0
- data/html/img/page_white_ruby.png +0 -0
- data/html/img/sidebar_agent_edit.png +0 -0
- data/html/img/sidebar_agent_edit_over.png +0 -0
- data/html/img/sidebar_agent_edit_s.png +0 -0
- data/html/img/yui/treeview-sprite.gif +0 -0
- data/html/index.html +34 -18
- data/html/js/agent-editor/agent-editor-page.js +324 -0
- data/html/js/agent-editor/agent-editor.js +363 -0
- data/html/js/agent-editor/agent-list-tree.js +251 -0
- data/html/js/agent-selector.js +23 -28
- data/html/js/app.js +63 -91
- data/html/js/bt-create-page.js +25 -19
- data/html/js/container-min.js +1 -1
- data/html/js/container.js +944 -0
- data/html/js/edit_area/autocompletion.js +11 -13
- data/html/js/edit_area/edit_area.css +79 -40
- data/html/js/edit_area/edit_area.js +255 -226
- data/html/js/edit_area/edit_area_compressor.php +4 -4
- data/html/js/edit_area/edit_area_full.gz +0 -0
- data/html/js/edit_area/edit_area_full.js +31 -31
- data/html/js/edit_area/edit_area_full_with_plugins.gz +0 -0
- data/html/js/edit_area/edit_area_full_with_plugins.js +31 -31
- data/html/js/edit_area/edit_area_functions.js +448 -341
- data/html/js/edit_area/edit_area_loader.js +409 -397
- data/html/js/edit_area/elements_functions.js +120 -123
- data/html/js/edit_area/highlight.js +305 -197
- data/html/js/edit_area/images/goto.png +0 -0
- data/html/js/edit_area/images/help.png +0 -0
- data/html/js/edit_area/images/redo.png +0 -0
- data/html/js/edit_area/images/save.png +0 -0
- data/html/js/edit_area/images/search.png +0 -0
- data/html/js/edit_area/images/undo.png +0 -0
- data/html/js/edit_area/images/word_wrap.gif +0 -0
- data/html/js/edit_area/keyboard.js +5 -5
- data/html/js/edit_area/langs/bg.js +73 -0
- data/html/js/edit_area/langs/cs.js +2 -0
- data/html/js/edit_area/langs/de.js +2 -0
- data/html/js/edit_area/langs/dk.js +2 -0
- data/html/js/edit_area/langs/en.js +2 -0
- data/html/js/edit_area/langs/eo.js +2 -0
- data/html/js/edit_area/langs/es.js +2 -0
- data/html/js/edit_area/langs/fi.js +67 -0
- data/html/js/edit_area/langs/fr.js +2 -0
- data/html/js/edit_area/langs/hr.js +2 -0
- data/html/js/edit_area/langs/it.js +2 -0
- data/html/js/edit_area/langs/ja.js +2 -0
- data/html/js/edit_area/langs/mk.js +2 -0
- data/html/js/edit_area/langs/nl.js +2 -0
- data/html/js/edit_area/langs/pl.js +2 -0
- data/html/js/edit_area/langs/pt.js +2 -0
- data/html/js/edit_area/langs/ru.js +2 -0
- data/html/js/edit_area/langs/sk.js +2 -0
- data/html/js/edit_area/langs/zh.js +67 -0
- data/html/js/edit_area/manage_area.js +362 -205
- data/html/js/edit_area/plugins/charmap/langs/bg.js +12 -0
- data/html/js/edit_area/plugins/charmap/langs/zh.js +6 -0
- data/html/js/edit_area/plugins/test/langs/bg.js +10 -0
- data/html/js/edit_area/plugins/test/langs/zh.js +4 -0
- data/html/js/edit_area/reg_syntax/java.js +56 -0
- data/html/js/edit_area/reg_syntax/ruby.js +9 -9
- data/html/js/edit_area/reg_syntax.js +15 -13
- data/html/js/edit_area/regexp.js +36 -32
- data/html/js/edit_area/resize_area.js +43 -47
- data/html/js/edit_area/search_replace.js +29 -29
- data/html/js/edit_area/template.html +6 -4
- data/html/js/json-broker-client.js +23 -17
- data/html/js/result-page.js +107 -57
- data/html/js/rt-setting-page.js +38 -15
- data/html/js/sidebar.js +41 -27
- data/html/js/templates.js +167 -32
- data/html/js/utils.js +143 -7
- data/html/js/yui/treeview.js +3671 -0
- data/html/swf/chart.swf +0 -0
- data/html/test/agent_editor_spec.js +815 -0
- data/html/test/index.html +40 -0
- data/html/test/jsspec/JSSpec.css +224 -0
- data/html/test/jsspec/JSSpec.js +1549 -0
- data/html/test/jsspec/diff_match_patch.js +1 -0
- data/html/test/utils_spec.js +111 -0
- data/lib/jiji/agent/agent.rb +69 -12
- data/lib/jiji/agent/agent_manager.rb +18 -12
- data/lib/jiji/agent/agent_registry.rb +35 -121
- data/lib/jiji/collector.rb +16 -6
- data/lib/jiji/command.rb +46 -5
- data/lib/jiji/dao/file_system_dao.rb +158 -0
- data/lib/jiji/dao/timed_data_dao.rb +2 -0
- data/lib/jiji/dao/trade_result_dao.rb +1 -1
- data/lib/jiji/error.rb +24 -8
- data/lib/jiji/migration/migrator1_2_0.rb +67 -0
- data/lib/jiji/models.rb +82 -24
- data/lib/jiji/operator.rb +55 -51
- data/lib/jiji/output.rb +85 -29
- data/lib/jiji/output_manager.rb +84 -0
- data/lib/jiji/plugin/embedded/single_click_client.rb +2 -2
- data/lib/jiji/plugin/securities_plugin.rb +0 -1
- data/lib/jiji/process.rb +229 -208
- data/lib/jiji/process_manager.rb +190 -96
- data/lib/jiji/registry.rb +87 -19
- data/lib/jiji/server.rb +1 -0
- data/lib/jiji/service/agent_service.rb +147 -48
- data/lib/jiji/service/output_service.rb +37 -17
- data/lib/jiji/service/process_service.rb +3 -5
- data/lib/jiji/service/trade_result_service.rb +4 -5
- data/lib/jiji/util/file_lock.rb +4 -4
- data/lib/jiji/util/include_proxy.rb +17 -0
- data/lib/jiji/util/json_broker.rb +6 -4
- data/lib/jiji/util/util.rb +1 -1
- data/swf/chart/fx/chart/Chart.as +7 -0
- data/swf/chart/fx/chart/ui/graph/GraphManager.as +15 -2
- data/test/ProcessTest/agents/foo.rb +10 -0
- data/test/ProcessTest/conf/configuration.yaml +3 -0
- data/test/agent/agent_tests.rb +10 -0
- data/test/agent/test_AgentManager.rb +28 -12
- data/test/agent/test_AgentRegistry.rb +194 -99
- data/test/agent/test_PeriodicallyAgent.rb +1 -2
- data/test/agent/test_Permitter.rb +1 -2
- data/test/all_tests.rb +7 -19
- data/test/dao/dao_tests.rb +9 -0
- data/test/dao/test_FileSystemDao.rb +431 -0
- data/test/dao/test_RateDao.rb +5 -7
- data/test/dao/test_TradeResultDao.rb +1 -2
- data/test/migration/migration_tests.rb +10 -0
- data/test/migration/migrator1_2_0test_data/basic/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/basic/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/basic/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/basic/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
- data/test/migration/migrator1_2_0test_data/basic/props.yaml +85 -0
- data/test/migration/migrator1_2_0test_data/illegal_props/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/illegal_props/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/illegal_props/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/illegal_props/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
- data/test/migration/migrator1_2_0test_data/illegal_props/props.yaml +1 -0
- data/test/migration/migrator1_2_0test_data/no_outs/props.yaml +85 -0
- data/test/migration/migrator1_2_0test_data/no_props/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/no_props/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/no_props/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
- data/test/migration/migrator1_2_0test_data/no_props/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
- data/test/migration/test_Migrator.rb +1 -1
- data/test/migration/test_Migrator1_0_3.rb +1 -1
- data/test/migration/test_Migrator1_1_0.rb +1 -1
- data/test/migration/test_Migrator1_2_0.rb +94 -0
- data/test/plugin/embedded/test_SingleClickClient.rb +1 -2
- data/test/plugin/plugin_tests.rb +8 -0
- data/test/plugin/test_Loader.rb +1 -1
- data/test/shared/rate.csv +144 -0
- data/test/shared/shared_tests.rb +9 -0
- data/test/shared/test_Cross.rb +144 -0
- data/test/shared/test_PositionManager.rb +285 -0
- data/test/shared/test_Signal.rb +65 -0
- data/test/test_Output.rb +28 -21
- data/test/test_OutputManager.rb +162 -0
- data/test/test_Output_registry.rb +6 -17
- data/test/test_Process.rb +434 -222
- data/test/test_ProcessManager.rb +458 -101
- data/test/test_utils.rb +71 -8
- data/test/util/test_BlockToSession.rb +1 -2
- data/test/util/test_CSV.rb +1 -2
- data/test/util/test_SynchronizeInterceptor.rb +1 -2
- data/test/util/util_tests.rb +9 -0
- metadata +127 -47
- data/html/js/agent-editor-page.js +0 -440
- data/html/js/codepress/codepress.css +0 -21
- data/html/js/codepress/codepress.html +0 -35
- data/html/js/codepress/codepress.js +0 -138
- data/html/js/codepress/engines/gecko.js +0 -293
- data/html/js/codepress/engines/khtml.js +0 -0
- data/html/js/codepress/engines/msie.js +0 -304
- data/html/js/codepress/engines/older.js +0 -0
- data/html/js/codepress/engines/opera.js +0 -260
- data/html/js/codepress/images/line-numbers.gif +0 -0
- data/html/js/codepress/index.html +0 -443
- data/html/js/codepress/languages/asp.css +0 -71
- data/html/js/codepress/languages/asp.js +0 -117
- data/html/js/codepress/languages/autoit.css +0 -13
- data/html/js/codepress/languages/autoit.js +0 -32
- data/html/js/codepress/languages/csharp.css +0 -9
- data/html/js/codepress/languages/csharp.js +0 -25
- data/html/js/codepress/languages/css.css +0 -10
- data/html/js/codepress/languages/css.js +0 -23
- data/html/js/codepress/languages/generic.css +0 -9
- data/html/js/codepress/languages/generic.js +0 -25
- data/html/js/codepress/languages/html.css +0 -13
- data/html/js/codepress/languages/html.js +0 -59
- data/html/js/codepress/languages/java.css +0 -7
- data/html/js/codepress/languages/java.js +0 -24
- data/html/js/codepress/languages/javascript.css +0 -8
- data/html/js/codepress/languages/javascript.js +0 -30
- data/html/js/codepress/languages/perl.css +0 -11
- data/html/js/codepress/languages/perl.js +0 -27
- data/html/js/codepress/languages/php.css +0 -12
- data/html/js/codepress/languages/php.js +0 -61
- data/html/js/codepress/languages/ruby.css +0 -10
- data/html/js/codepress/languages/ruby.js +0 -26
- data/html/js/codepress/languages/sql.css +0 -10
- data/html/js/codepress/languages/sql.js +0 -30
- data/html/js/codepress/languages/text.css +0 -5
- data/html/js/codepress/languages/text.js +0 -9
- data/html/js/codepress/languages/vbscript.css +0 -71
- data/html/js/codepress/languages/vbscript.js +0 -117
- data/html/js/codepress/languages/xsl.css +0 -15
- data/html/js/codepress/languages/xsl.js +0 -103
- data/html/js/codepress/license.txt +0 -458
- data/html/js/edit_area/images/Thumbs.db +0 -0
- data/test/plugin/test_gem/a/lib/jiji_plugin_test.rb +0 -6
@@ -1,293 +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
|
-
* Developers:
|
7
|
-
* Fernando M.A.d.S. <fermads@gmail.com>
|
8
|
-
* Michael Hurni <michael.hurni@gmail.com>
|
9
|
-
* Contributors:
|
10
|
-
* Martin D. Kirk
|
11
|
-
*
|
12
|
-
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
13
|
-
* GNU Lesser General Public License as published by the Free Software Foundation.
|
14
|
-
*
|
15
|
-
* Read the full licence: http://www.opensource.org/licenses/lgpl-license.php
|
16
|
-
*/
|
17
|
-
|
18
|
-
CodePress = {
|
19
|
-
scrolling : false,
|
20
|
-
autocomplete : true,
|
21
|
-
|
22
|
-
// set initial vars and start sh
|
23
|
-
initialize : function() {
|
24
|
-
if(typeof(editor)=='undefined' && !arguments[0]) return;
|
25
|
-
body = document.getElementsByTagName('body')[0];
|
26
|
-
body.innerHTML = body.innerHTML.replace(/\n/g,"");
|
27
|
-
chars = '|32|46|62|8|'; // charcodes that trigger syntax highlighting
|
28
|
-
cc = '\u2009'; // carret char
|
29
|
-
editor = document.getElementsByTagName('pre')[0];
|
30
|
-
document.designMode = 'on';
|
31
|
-
document.addEventListener('keypress', this.keyHandler, true);
|
32
|
-
window.addEventListener('scroll', function() { if(!CodePress.scrolling) CodePress.syntaxHighlight('scroll') }, false);
|
33
|
-
completeChars = this.getCompleteChars();
|
34
|
-
completeEndingChars = this.getCompleteEndingChars();
|
35
|
-
},
|
36
|
-
|
37
|
-
// treat key bindings
|
38
|
-
keyHandler : function(evt) {
|
39
|
-
keyCode = evt.keyCode;
|
40
|
-
charCode = evt.charCode;
|
41
|
-
fromChar = String.fromCharCode(charCode);
|
42
|
-
|
43
|
-
if((evt.ctrlKey || evt.metaKey) && evt.shiftKey && charCode!=90) { // shortcuts = ctrl||appleKey+shift+key!=z(undo)
|
44
|
-
CodePress.shortcuts(charCode?charCode:keyCode);
|
45
|
-
}
|
46
|
-
else if( (completeEndingChars.indexOf('|'+fromChar+'|')!= -1 || completeChars.indexOf('|'+fromChar+'|')!=-1) && CodePress.autocomplete) { // auto complete
|
47
|
-
if(!CodePress.completeEnding(fromChar))
|
48
|
-
CodePress.complete(fromChar);
|
49
|
-
}
|
50
|
-
else if(chars.indexOf('|'+charCode+'|')!=-1||keyCode==13) { // syntax highlighting
|
51
|
-
top.setTimeout(function(){CodePress.syntaxHighlight('generic');},100);
|
52
|
-
}
|
53
|
-
else if(keyCode==9 || evt.tabKey) { // snippets activation (tab)
|
54
|
-
CodePress.snippets(evt);
|
55
|
-
}
|
56
|
-
else if(keyCode==46||keyCode==8) { // save to history when delete or backspace pressed
|
57
|
-
CodePress.actions.history[CodePress.actions.next()] = editor.innerHTML;
|
58
|
-
}
|
59
|
-
else if((charCode==122||charCode==121||charCode==90) && evt.ctrlKey) { // undo and redo
|
60
|
-
(charCode==121||evt.shiftKey) ? CodePress.actions.redo() : CodePress.actions.undo();
|
61
|
-
evt.preventDefault();
|
62
|
-
}
|
63
|
-
else if(charCode==118 && evt.ctrlKey) { // handle paste
|
64
|
-
top.setTimeout(function(){CodePress.syntaxHighlight('generic');},100);
|
65
|
-
}
|
66
|
-
else if(charCode==99 && evt.ctrlKey) { // handle cut
|
67
|
-
//alert(window.getSelection().getRangeAt(0).toString().replace(/\t/g,'FFF'));
|
68
|
-
}
|
69
|
-
|
70
|
-
},
|
71
|
-
|
72
|
-
// put cursor back to its original position after every parsing
|
73
|
-
findString : function() {
|
74
|
-
if(self.find(cc))
|
75
|
-
window.getSelection().getRangeAt(0).deleteContents();
|
76
|
-
},
|
77
|
-
|
78
|
-
// split big files, highlighting parts of it
|
79
|
-
split : function(code,flag) {
|
80
|
-
if(flag=='scroll') {
|
81
|
-
this.scrolling = true;
|
82
|
-
return code;
|
83
|
-
}
|
84
|
-
else {
|
85
|
-
this.scrolling = false;
|
86
|
-
mid = code.indexOf(cc);
|
87
|
-
if(mid-2000<0) {ini=0;end=4000;}
|
88
|
-
else if(mid+2000>code.length) {ini=code.length-4000;end=code.length;}
|
89
|
-
else {ini=mid-2000;end=mid+2000;}
|
90
|
-
code = code.substring(ini,end);
|
91
|
-
return code;
|
92
|
-
}
|
93
|
-
},
|
94
|
-
|
95
|
-
getEditor : function() {
|
96
|
-
if(!document.getElementsByTagName('pre')[0]) {
|
97
|
-
body = document.getElementsByTagName('body')[0];
|
98
|
-
if(!body.innerHTML) return body;
|
99
|
-
if(body.innerHTML=="<br>") body.innerHTML = "<pre> </pre>";
|
100
|
-
else body.innerHTML = "<pre>"+body.innerHTML+"</pre>";
|
101
|
-
}
|
102
|
-
return document.getElementsByTagName('pre')[0];
|
103
|
-
},
|
104
|
-
|
105
|
-
// syntax highlighting parser
|
106
|
-
syntaxHighlight : function(flag) {
|
107
|
-
//if(document.designMode=='off') document.designMode='on'
|
108
|
-
if(flag != 'init') { window.getSelection().getRangeAt(0).insertNode(document.createTextNode(cc));}
|
109
|
-
editor = CodePress.getEditor();
|
110
|
-
o = editor.innerHTML;
|
111
|
-
o = o.replace(/<br>/g,'\n');
|
112
|
-
o = o.replace(/<.*?>/g,'');
|
113
|
-
x = z = this.split(o,flag);
|
114
|
-
x = x.replace(/\n/g,'<br>');
|
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.split(z).join(x);
|
122
|
-
if(flag!='init') this.findString();
|
123
|
-
},
|
124
|
-
|
125
|
-
getLastWord : function() {
|
126
|
-
var rangeAndCaret = CodePress.getRangeAndCaret();
|
127
|
-
words = rangeAndCaret[0].substring(rangeAndCaret[1]-40,rangeAndCaret[1]);
|
128
|
-
words = words.replace(/[\s\n\r\);\W]/g,'\n').split('\n');
|
129
|
-
return words[words.length-1].replace(/[\W]/gi,'').toLowerCase();
|
130
|
-
},
|
131
|
-
|
132
|
-
snippets : function(evt) {
|
133
|
-
var snippets = Language.snippets;
|
134
|
-
var trigger = this.getLastWord();
|
135
|
-
for (var i=0; i<snippets.length; i++) {
|
136
|
-
if(snippets[i].input == trigger) {
|
137
|
-
var content = snippets[i].output.replace(/</g,'<');
|
138
|
-
content = content.replace(/>/g,'>');
|
139
|
-
if(content.indexOf('$0')<0) content += cc;
|
140
|
-
else content = content.replace(/\$0/,cc);
|
141
|
-
content = content.replace(/\n/g,'<br>');
|
142
|
-
var pattern = new RegExp(trigger+cc,'gi');
|
143
|
-
evt.preventDefault(); // prevent the tab key from being added
|
144
|
-
this.syntaxHighlight('snippets',pattern,content);
|
145
|
-
}
|
146
|
-
}
|
147
|
-
},
|
148
|
-
|
149
|
-
readOnly : function() {
|
150
|
-
document.designMode = (arguments[0]) ? 'off' : 'on';
|
151
|
-
},
|
152
|
-
|
153
|
-
complete : function(trigger) {
|
154
|
-
window.getSelection().getRangeAt(0).deleteContents();
|
155
|
-
var complete = Language.complete;
|
156
|
-
for (var i=0; i<complete.length; i++) {
|
157
|
-
if(complete[i].input == trigger) {
|
158
|
-
var pattern = new RegExp('\\'+trigger+cc);
|
159
|
-
var content = complete[i].output.replace(/\$0/g,cc);
|
160
|
-
parent.setTimeout(function () { CodePress.syntaxHighlight('complete',pattern,content)},0); // wait for char to appear on screen
|
161
|
-
}
|
162
|
-
}
|
163
|
-
},
|
164
|
-
|
165
|
-
getCompleteChars : function() {
|
166
|
-
var cChars = '';
|
167
|
-
for(var i=0;i<Language.complete.length;i++)
|
168
|
-
cChars += '|'+Language.complete[i].input;
|
169
|
-
return cChars+'|';
|
170
|
-
},
|
171
|
-
|
172
|
-
getCompleteEndingChars : function() {
|
173
|
-
var cChars = '';
|
174
|
-
for(var i=0;i<Language.complete.length;i++)
|
175
|
-
cChars += '|'+Language.complete[i].output.charAt(Language.complete[i].output.length-1);
|
176
|
-
return cChars+'|';
|
177
|
-
},
|
178
|
-
|
179
|
-
completeEnding : function(trigger) {
|
180
|
-
var range = window.getSelection().getRangeAt(0);
|
181
|
-
try {
|
182
|
-
range.setEnd(range.endContainer, range.endOffset+1)
|
183
|
-
}
|
184
|
-
catch(e) {
|
185
|
-
return false;
|
186
|
-
}
|
187
|
-
var next_character = range.toString()
|
188
|
-
range.setEnd(range.endContainer, range.endOffset-1)
|
189
|
-
if(next_character != trigger) return false;
|
190
|
-
else {
|
191
|
-
range.setEnd(range.endContainer, range.endOffset+1)
|
192
|
-
range.deleteContents();
|
193
|
-
return true;
|
194
|
-
}
|
195
|
-
},
|
196
|
-
|
197
|
-
shortcuts : function() {
|
198
|
-
var cCode = arguments[0];
|
199
|
-
if(cCode==13) cCode = '[enter]';
|
200
|
-
else if(cCode==32) cCode = '[space]';
|
201
|
-
else cCode = '['+String.fromCharCode(charCode).toLowerCase()+']';
|
202
|
-
for(var i=0;i<Language.shortcuts.length;i++)
|
203
|
-
if(Language.shortcuts[i].input == cCode)
|
204
|
-
this.insertCode(Language.shortcuts[i].output,false);
|
205
|
-
},
|
206
|
-
|
207
|
-
getRangeAndCaret : function() {
|
208
|
-
var range = window.getSelection().getRangeAt(0);
|
209
|
-
var range2 = range.cloneRange();
|
210
|
-
var node = range.endContainer;
|
211
|
-
var caret = range.endOffset;
|
212
|
-
range2.selectNode(node);
|
213
|
-
return [range2.toString(),caret];
|
214
|
-
},
|
215
|
-
|
216
|
-
insertCode : function(code,replaceCursorBefore) {
|
217
|
-
var range = window.getSelection().getRangeAt(0);
|
218
|
-
var node = window.document.createTextNode(code);
|
219
|
-
var selct = window.getSelection();
|
220
|
-
var range2 = range.cloneRange();
|
221
|
-
// Insert text at cursor position
|
222
|
-
selct.removeAllRanges();
|
223
|
-
range.deleteContents();
|
224
|
-
range.insertNode(node);
|
225
|
-
// Move the cursor to the end of text
|
226
|
-
range2.selectNode(node);
|
227
|
-
range2.collapse(replaceCursorBefore);
|
228
|
-
selct.removeAllRanges();
|
229
|
-
selct.addRange(range2);
|
230
|
-
},
|
231
|
-
|
232
|
-
// get code from editor
|
233
|
-
getCode : function() {
|
234
|
-
if(!document.getElementsByTagName('pre')[0] || editor.innerHTML == '')
|
235
|
-
editor = CodePress.getEditor();
|
236
|
-
var code = editor.innerHTML;
|
237
|
-
code = code.replace(/<br>/g,'\n');
|
238
|
-
code = code.replace(/\u2009/g,'');
|
239
|
-
code = code.replace(/<.*?>/g,'');
|
240
|
-
code = code.replace(/</g,'<');
|
241
|
-
code = code.replace(/>/g,'>');
|
242
|
-
code = code.replace(/&/gi,'&');
|
243
|
-
return code;
|
244
|
-
},
|
245
|
-
|
246
|
-
// put code inside editor
|
247
|
-
setCode : function() {
|
248
|
-
var code = arguments[0];
|
249
|
-
code = code.replace(/\u2009/gi,'');
|
250
|
-
code = code.replace(/&/gi,'&');
|
251
|
-
code = code.replace(/</g,'<');
|
252
|
-
code = code.replace(/>/g,'>');
|
253
|
-
editor.innerHTML = code;
|
254
|
-
if (code == '')
|
255
|
-
document.getElementsByTagName('body')[0].innerHTML = '';
|
256
|
-
},
|
257
|
-
|
258
|
-
// undo and redo methods
|
259
|
-
actions : {
|
260
|
-
pos : -1, // actual history position
|
261
|
-
history : [], // history vector
|
262
|
-
|
263
|
-
undo : function() {
|
264
|
-
editor = CodePress.getEditor();
|
265
|
-
if(editor.innerHTML.indexOf(cc)==-1){
|
266
|
-
if(editor.innerHTML != " ")
|
267
|
-
window.getSelection().getRangeAt(0).insertNode(document.createTextNode(cc));
|
268
|
-
this.history[this.pos] = editor.innerHTML;
|
269
|
-
}
|
270
|
-
this.pos --;
|
271
|
-
if(typeof(this.history[this.pos])=='undefined') this.pos ++;
|
272
|
-
editor.innerHTML = this.history[this.pos];
|
273
|
-
if(editor.innerHTML.indexOf(cc)>-1) editor.innerHTML+=cc;
|
274
|
-
CodePress.findString();
|
275
|
-
},
|
276
|
-
|
277
|
-
redo : function() {
|
278
|
-
// editor = CodePress.getEditor();
|
279
|
-
this.pos++;
|
280
|
-
if(typeof(this.history[this.pos])=='undefined') this.pos--;
|
281
|
-
editor.innerHTML = this.history[this.pos];
|
282
|
-
CodePress.findString();
|
283
|
-
},
|
284
|
-
|
285
|
-
next : function() { // get next vector position and clean old ones
|
286
|
-
if(this.pos>20) this.history[this.pos-21] = undefined;
|
287
|
-
return ++this.pos;
|
288
|
-
}
|
289
|
-
}
|
290
|
-
}
|
291
|
-
|
292
|
-
Language={};
|
293
|
-
window.addEventListener('load', function() { CodePress.initialize('new'); }, true);
|
File without changes
|
@@ -1,304 +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
|
-
* Developers:
|
7
|
-
* Fernando M.A.d.S. <fermads@gmail.com>
|
8
|
-
* Michael Hurni <michael.hurni@gmail.com>
|
9
|
-
* Contributors:
|
10
|
-
* Martin D. Kirk
|
11
|
-
*
|
12
|
-
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
13
|
-
* GNU Lesser General Public License as published by the Free Software Foundation.
|
14
|
-
*
|
15
|
-
* Read the full licence: http://www.opensource.org/licenses/lgpl-license.php
|
16
|
-
*/
|
17
|
-
|
18
|
-
CodePress = {
|
19
|
-
scrolling : false,
|
20
|
-
autocomplete : true,
|
21
|
-
|
22
|
-
// set initial vars and start sh
|
23
|
-
initialize : function() {
|
24
|
-
if(typeof(editor)=='undefined' && !arguments[0]) return;
|
25
|
-
chars = '|32|46|62|'; // charcodes that trigger syntax highlighting
|
26
|
-
cc = '\u2009'; // carret char
|
27
|
-
editor = document.getElementsByTagName('pre')[0];
|
28
|
-
editor.contentEditable = 'true';
|
29
|
-
document.getElementsByTagName('body')[0].onfocus = function() {editor.focus();}
|
30
|
-
document.attachEvent('onkeydown', this.metaHandler);
|
31
|
-
document.attachEvent('onkeypress', this.keyHandler);
|
32
|
-
window.attachEvent('onscroll', function() { if(!CodePress.scrolling) setTimeout(function(){CodePress.syntaxHighlight('scroll')},1)});
|
33
|
-
completeChars = this.getCompleteChars();
|
34
|
-
completeEndingChars = this.getCompleteEndingChars();
|
35
|
-
setTimeout(function() { window.scroll(0,0) },50); // scroll IE to top
|
36
|
-
},
|
37
|
-
|
38
|
-
// treat key bindings
|
39
|
-
keyHandler : function(evt) {
|
40
|
-
charCode = evt.keyCode;
|
41
|
-
fromChar = String.fromCharCode(charCode);
|
42
|
-
|
43
|
-
if( (completeEndingChars.indexOf('|'+fromChar+'|')!= -1 || completeChars.indexOf('|'+fromChar+'|')!=-1 )&& CodePress.autocomplete) { // auto complete
|
44
|
-
if(!CodePress.completeEnding(fromChar))
|
45
|
-
CodePress.complete(fromChar);
|
46
|
-
}
|
47
|
-
else if(chars.indexOf('|'+charCode+'|')!=-1||charCode==13) { // syntax highlighting
|
48
|
-
CodePress.syntaxHighlight('generic');
|
49
|
-
}
|
50
|
-
},
|
51
|
-
|
52
|
-
metaHandler : function(evt) {
|
53
|
-
keyCode = evt.keyCode;
|
54
|
-
|
55
|
-
if(keyCode==9 || evt.tabKey) {
|
56
|
-
CodePress.snippets();
|
57
|
-
}
|
58
|
-
else if((keyCode==122||keyCode==121||keyCode==90) && evt.ctrlKey) { // undo and redo
|
59
|
-
(keyCode==121||evt.shiftKey) ? CodePress.actions.redo() : CodePress.actions.undo();
|
60
|
-
evt.returnValue = false;
|
61
|
-
}
|
62
|
-
else if(keyCode==34||keyCode==33) { // handle page up/down for IE
|
63
|
-
self.scrollBy(0, (keyCode==34) ? 200 : -200);
|
64
|
-
evt.returnValue = false;
|
65
|
-
}
|
66
|
-
else if(keyCode==46||keyCode==8) { // save to history when delete or backspace pressed
|
67
|
-
CodePress.actions.history[CodePress.actions.next()] = editor.innerHTML;
|
68
|
-
}
|
69
|
-
else if((evt.ctrlKey || evt.metaKey) && evt.shiftKey && keyCode!=90) { // shortcuts = ctrl||appleKey+shift+key!=z(undo)
|
70
|
-
CodePress.shortcuts(keyCode);
|
71
|
-
evt.returnValue = false;
|
72
|
-
}
|
73
|
-
else if(keyCode==86 && evt.ctrlKey) { // handle paste
|
74
|
-
window.clipboardData.setData('Text',window.clipboardData.getData('Text').replace(/\t/g,'\u2008'));
|
75
|
-
top.setTimeout(function(){CodePress.syntaxHighlight('paste');},10);
|
76
|
-
}
|
77
|
-
else if(keyCode==67 && evt.ctrlKey) { // handle cut
|
78
|
-
// window.clipboardData.setData('Text',x[0]);
|
79
|
-
// code = window.clipboardData.getData('Text');
|
80
|
-
}
|
81
|
-
},
|
82
|
-
|
83
|
-
// put cursor back to its original position after every parsing
|
84
|
-
|
85
|
-
|
86
|
-
findString : function() {
|
87
|
-
range = self.document.body.createTextRange();
|
88
|
-
if(range.findText(cc)){
|
89
|
-
range.select();
|
90
|
-
range.text = '';
|
91
|
-
}
|
92
|
-
},
|
93
|
-
|
94
|
-
// split big files, highlighting parts of it
|
95
|
-
split : function(code,flag) {
|
96
|
-
if(flag=='scroll') {
|
97
|
-
this.scrolling = true;
|
98
|
-
return code;
|
99
|
-
}
|
100
|
-
else {
|
101
|
-
this.scrolling = false;
|
102
|
-
mid = code.indexOf(cc);
|
103
|
-
if(mid-2000<0) {ini=0;end=4000;}
|
104
|
-
else if(mid+2000>code.length) {ini=code.length-4000;end=code.length;}
|
105
|
-
else {ini=mid-2000;end=mid+2000;}
|
106
|
-
code = code.substring(ini,end);
|
107
|
-
return code.substring(code.indexOf('<P>'),code.lastIndexOf('</P>')+4);
|
108
|
-
}
|
109
|
-
},
|
110
|
-
|
111
|
-
// syntax highlighting parser
|
112
|
-
syntaxHighlight : function(flag) {
|
113
|
-
if(flag!='init') document.selection.createRange().text = cc;
|
114
|
-
o = editor.innerHTML;
|
115
|
-
if(flag=='paste') { // fix pasted text
|
116
|
-
o = o.replace(/<BR>/g,'\r\n');
|
117
|
-
o = o.replace(/\u2008/g,'\t');
|
118
|
-
}
|
119
|
-
o = o.replace(/<P>/g,'\n');
|
120
|
-
o = o.replace(/<\/P>/g,'\r');
|
121
|
-
o = o.replace(/<.*?>/g,'');
|
122
|
-
o = o.replace(/ /g,'');
|
123
|
-
o = '<PRE><P>'+o+'</P></PRE>';
|
124
|
-
o = o.replace(/\n\r/g,'<P></P>');
|
125
|
-
o = o.replace(/\n/g,'<P>');
|
126
|
-
o = o.replace(/\r/g,'<\/P>');
|
127
|
-
o = o.replace(/<P>(<P>)+/,'<P>');
|
128
|
-
o = o.replace(/<\/P>(<\/P>)+/,'</P>');
|
129
|
-
o = o.replace(/<P><\/P>/g,'<P><BR/></P>');
|
130
|
-
x = z = this.split(o,flag);
|
131
|
-
|
132
|
-
if(arguments[1]&&arguments[2]) x = x.replace(arguments[1],arguments[2]);
|
133
|
-
|
134
|
-
for(i=0;i<Language.syntax.length;i++)
|
135
|
-
x = x.replace(Language.syntax[i].input,Language.syntax[i].output);
|
136
|
-
|
137
|
-
editor.innerHTML = this.actions.history[this.actions.next()] = (flag=='scroll') ? x : o.replace(z,x);
|
138
|
-
if(flag!='init') this.findString();
|
139
|
-
},
|
140
|
-
|
141
|
-
snippets : function(evt) {
|
142
|
-
var snippets = Language.snippets;
|
143
|
-
var trigger = this.getLastWord();
|
144
|
-
for (var i=0; i<snippets.length; i++) {
|
145
|
-
if(snippets[i].input == trigger) {
|
146
|
-
var content = snippets[i].output.replace(/</g,'<');
|
147
|
-
content = content.replace(/>/g,'>');
|
148
|
-
if(content.indexOf('$0')<0) content += cc;
|
149
|
-
else content = content.replace(/\$0/,cc);
|
150
|
-
content = content.replace(/\n/g,'</P><P>');
|
151
|
-
var pattern = new RegExp(trigger+cc,"gi");
|
152
|
-
this.syntaxHighlight('snippets',pattern,content);
|
153
|
-
}
|
154
|
-
}
|
155
|
-
},
|
156
|
-
|
157
|
-
readOnly : function() {
|
158
|
-
editor.contentEditable = (arguments[0]) ? 'false' : 'true';
|
159
|
-
},
|
160
|
-
|
161
|
-
complete : function(trigger) {
|
162
|
-
var complete = Language.complete;
|
163
|
-
for (var i=0; i<complete.length; i++) {
|
164
|
-
if(complete[i].input == trigger) {
|
165
|
-
var pattern = new RegExp('\\'+trigger+cc);
|
166
|
-
var content = complete[i].output.replace(/\$0/g,cc);
|
167
|
-
setTimeout(function () { CodePress.syntaxHighlight('complete',pattern,content)},0); // wait for char to appear on screen
|
168
|
-
}
|
169
|
-
}
|
170
|
-
},
|
171
|
-
|
172
|
-
getCompleteChars : function() {
|
173
|
-
var cChars = '';
|
174
|
-
for(var i=0;i<Language.complete.length;i++)
|
175
|
-
cChars += '|'+Language.complete[i].input;
|
176
|
-
return cChars+'|';
|
177
|
-
},
|
178
|
-
|
179
|
-
getCompleteEndingChars : function() {
|
180
|
-
var cChars = '';
|
181
|
-
for(var i=0;i<Language.complete.length;i++)
|
182
|
-
cChars += '|'+Language.complete[i].output.charAt(Language.complete[i].output.length-1);
|
183
|
-
return cChars+'|';
|
184
|
-
},
|
185
|
-
|
186
|
-
completeEnding : function(trigger) {
|
187
|
-
var range = document.selection.createRange();
|
188
|
-
try {
|
189
|
-
range.moveEnd('character', 1)
|
190
|
-
}
|
191
|
-
catch(e) {
|
192
|
-
return false;
|
193
|
-
}
|
194
|
-
var next_character = range.text
|
195
|
-
range.moveEnd('character', -1)
|
196
|
-
if(next_character != trigger ) return false;
|
197
|
-
else {
|
198
|
-
range.moveEnd('character', 1)
|
199
|
-
range.text=''
|
200
|
-
return true;
|
201
|
-
}
|
202
|
-
},
|
203
|
-
|
204
|
-
shortcuts : function() {
|
205
|
-
var cCode = arguments[0];
|
206
|
-
if(cCode==13) cCode = '[enter]';
|
207
|
-
else if(cCode==32) cCode = '[space]';
|
208
|
-
else cCode = '['+String.fromCharCode(keyCode).toLowerCase()+']';
|
209
|
-
for(var i=0;i<Language.shortcuts.length;i++)
|
210
|
-
if(Language.shortcuts[i].input == cCode)
|
211
|
-
this.insertCode(Language.shortcuts[i].output,false);
|
212
|
-
},
|
213
|
-
|
214
|
-
getLastWord : function() {
|
215
|
-
var rangeAndCaret = CodePress.getRangeAndCaret();
|
216
|
-
words = rangeAndCaret[0].substring(rangeAndCaret[1]-40,rangeAndCaret[1]);
|
217
|
-
words = words.replace(/[\s\n\r\);\W]/g,'\n').split('\n');
|
218
|
-
return words[words.length-1].replace(/[\W]/gi,'').toLowerCase();
|
219
|
-
},
|
220
|
-
|
221
|
-
getRangeAndCaret : function() {
|
222
|
-
var range = document.selection.createRange();
|
223
|
-
var caret = Math.abs(range.moveStart('character', -1000000)+1);
|
224
|
-
range = this.getCode();
|
225
|
-
range = range.replace(/\n\r/gi,' ');
|
226
|
-
range = range.replace(/\n/gi,'');
|
227
|
-
return [range.toString(),caret];
|
228
|
-
},
|
229
|
-
|
230
|
-
insertCode : function(code,replaceCursorBefore) {
|
231
|
-
var repdeb = '';
|
232
|
-
var repfin = '';
|
233
|
-
|
234
|
-
if(replaceCursorBefore) { repfin = code; }
|
235
|
-
else { repdeb = code; }
|
236
|
-
|
237
|
-
if(typeof document.selection != 'undefined') {
|
238
|
-
var range = document.selection.createRange();
|
239
|
-
range.text = repdeb + repfin;
|
240
|
-
range = document.selection.createRange();
|
241
|
-
range.move('character', -repfin.length);
|
242
|
-
range.select();
|
243
|
-
}
|
244
|
-
},
|
245
|
-
|
246
|
-
// get code from editor
|
247
|
-
getCode : function() {
|
248
|
-
var code = editor.innerHTML;
|
249
|
-
code = code.replace(/<br>/g,'\n');
|
250
|
-
code = code.replace(/<\/p>/gi,'\r');
|
251
|
-
code = code.replace(/<p>/i,''); // IE first line fix
|
252
|
-
code = code.replace(/<p>/gi,'\n');
|
253
|
-
code = code.replace(/ /gi,'');
|
254
|
-
code = code.replace(/\u2009/g,'');
|
255
|
-
code = code.replace(/<.*?>/g,'');
|
256
|
-
code = code.replace(/</g,'<');
|
257
|
-
code = code.replace(/>/g,'>');
|
258
|
-
code = code.replace(/&/gi,'&');
|
259
|
-
return code;
|
260
|
-
},
|
261
|
-
|
262
|
-
// put code inside editor
|
263
|
-
setCode : function() {
|
264
|
-
var code = arguments[0];
|
265
|
-
code = code.replace(/\u2009/gi,'');
|
266
|
-
code = code.replace(/&/gi,'&');
|
267
|
-
code = code.replace(/</g,'<');
|
268
|
-
code = code.replace(/>/g,'>');
|
269
|
-
editor.innerHTML = '<pre>'+code+'</pre>';
|
270
|
-
},
|
271
|
-
|
272
|
-
|
273
|
-
// undo and redo methods
|
274
|
-
actions : {
|
275
|
-
pos : -1, // actual history position
|
276
|
-
history : [], // history vector
|
277
|
-
|
278
|
-
undo : function() {
|
279
|
-
if(editor.innerHTML.indexOf(cc)==-1){
|
280
|
-
document.selection.createRange().text = cc;
|
281
|
-
this.history[this.pos] = editor.innerHTML;
|
282
|
-
}
|
283
|
-
this.pos--;
|
284
|
-
if(typeof(this.history[this.pos])=='undefined') this.pos++;
|
285
|
-
editor.innerHTML = this.history[this.pos];
|
286
|
-
CodePress.findString();
|
287
|
-
},
|
288
|
-
|
289
|
-
redo : function() {
|
290
|
-
this.pos++;
|
291
|
-
if(typeof(this.history[this.pos])=='undefined') this.pos--;
|
292
|
-
editor.innerHTML = this.history[this.pos];
|
293
|
-
CodePress.findString();
|
294
|
-
},
|
295
|
-
|
296
|
-
next : function() { // get next vector position and clean old ones
|
297
|
-
if(this.pos>20) this.history[this.pos-21] = undefined;
|
298
|
-
return ++this.pos;
|
299
|
-
}
|
300
|
-
}
|
301
|
-
}
|
302
|
-
|
303
|
-
Language={};
|
304
|
-
window.attachEvent('onload', function() { CodePress.initialize('new');});
|
File without changes
|