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.
Files changed (233) hide show
  1. data/ChangeLog +24 -1
  2. data/README +0 -0
  3. data/base/shared_lib/moving_average.rb +34 -33
  4. data/base/shared_lib/system/cross.rb +76 -0
  5. data/base/shared_lib/system/position_manager.rb +160 -0
  6. data/base/shared_lib/system/signal.rb +347 -0
  7. data/html/css/datatable.css +4 -4
  8. data/html/css/default.css +57 -5
  9. data/html/css/treeview.css +205 -0
  10. data/html/img/bin_closed.png +0 -0
  11. data/html/img/bin_empty.png +0 -0
  12. data/html/img/button_add_small.gif +0 -0
  13. data/html/img/button_add_small_gray.gif +0 -0
  14. data/html/img/button_add_small_over.gif +0 -0
  15. data/html/img/button_mkcol.gif +0 -0
  16. data/html/img/button_mkcol_gray.gif +0 -0
  17. data/html/img/button_mkcol_over.gif +0 -0
  18. data/html/img/button_remove_small.gif +0 -0
  19. data/html/img/button_remove_small_gray.gif +0 -0
  20. data/html/img/button_remove_small_over.gif +0 -0
  21. data/html/img/button_rename.gif +0 -0
  22. data/html/img/button_rename_gray.gif +0 -0
  23. data/html/img/button_rename_over.gif +0 -0
  24. data/html/img/control_play.png +0 -0
  25. data/html/img/control_play_blue.png +0 -0
  26. data/html/img/folder.png +0 -0
  27. data/html/img/folder_brick.png +0 -0
  28. data/html/img/folder_user.png +0 -0
  29. data/html/{js/codepress/images → img}/line-numbers.png +0 -0
  30. data/html/img/page_white_ruby.png +0 -0
  31. data/html/img/sidebar_agent_edit.png +0 -0
  32. data/html/img/sidebar_agent_edit_over.png +0 -0
  33. data/html/img/sidebar_agent_edit_s.png +0 -0
  34. data/html/img/yui/treeview-sprite.gif +0 -0
  35. data/html/index.html +34 -18
  36. data/html/js/agent-editor/agent-editor-page.js +324 -0
  37. data/html/js/agent-editor/agent-editor.js +363 -0
  38. data/html/js/agent-editor/agent-list-tree.js +251 -0
  39. data/html/js/agent-selector.js +23 -28
  40. data/html/js/app.js +63 -91
  41. data/html/js/bt-create-page.js +25 -19
  42. data/html/js/container-min.js +1 -1
  43. data/html/js/container.js +944 -0
  44. data/html/js/edit_area/autocompletion.js +11 -13
  45. data/html/js/edit_area/edit_area.css +79 -40
  46. data/html/js/edit_area/edit_area.js +255 -226
  47. data/html/js/edit_area/edit_area_compressor.php +4 -4
  48. data/html/js/edit_area/edit_area_full.gz +0 -0
  49. data/html/js/edit_area/edit_area_full.js +31 -31
  50. data/html/js/edit_area/edit_area_full_with_plugins.gz +0 -0
  51. data/html/js/edit_area/edit_area_full_with_plugins.js +31 -31
  52. data/html/js/edit_area/edit_area_functions.js +448 -341
  53. data/html/js/edit_area/edit_area_loader.js +409 -397
  54. data/html/js/edit_area/elements_functions.js +120 -123
  55. data/html/js/edit_area/highlight.js +305 -197
  56. data/html/js/edit_area/images/goto.png +0 -0
  57. data/html/js/edit_area/images/help.png +0 -0
  58. data/html/js/edit_area/images/redo.png +0 -0
  59. data/html/js/edit_area/images/save.png +0 -0
  60. data/html/js/edit_area/images/search.png +0 -0
  61. data/html/js/edit_area/images/undo.png +0 -0
  62. data/html/js/edit_area/images/word_wrap.gif +0 -0
  63. data/html/js/edit_area/keyboard.js +5 -5
  64. data/html/js/edit_area/langs/bg.js +73 -0
  65. data/html/js/edit_area/langs/cs.js +2 -0
  66. data/html/js/edit_area/langs/de.js +2 -0
  67. data/html/js/edit_area/langs/dk.js +2 -0
  68. data/html/js/edit_area/langs/en.js +2 -0
  69. data/html/js/edit_area/langs/eo.js +2 -0
  70. data/html/js/edit_area/langs/es.js +2 -0
  71. data/html/js/edit_area/langs/fi.js +67 -0
  72. data/html/js/edit_area/langs/fr.js +2 -0
  73. data/html/js/edit_area/langs/hr.js +2 -0
  74. data/html/js/edit_area/langs/it.js +2 -0
  75. data/html/js/edit_area/langs/ja.js +2 -0
  76. data/html/js/edit_area/langs/mk.js +2 -0
  77. data/html/js/edit_area/langs/nl.js +2 -0
  78. data/html/js/edit_area/langs/pl.js +2 -0
  79. data/html/js/edit_area/langs/pt.js +2 -0
  80. data/html/js/edit_area/langs/ru.js +2 -0
  81. data/html/js/edit_area/langs/sk.js +2 -0
  82. data/html/js/edit_area/langs/zh.js +67 -0
  83. data/html/js/edit_area/manage_area.js +362 -205
  84. data/html/js/edit_area/plugins/charmap/langs/bg.js +12 -0
  85. data/html/js/edit_area/plugins/charmap/langs/zh.js +6 -0
  86. data/html/js/edit_area/plugins/test/langs/bg.js +10 -0
  87. data/html/js/edit_area/plugins/test/langs/zh.js +4 -0
  88. data/html/js/edit_area/reg_syntax/java.js +56 -0
  89. data/html/js/edit_area/reg_syntax/ruby.js +9 -9
  90. data/html/js/edit_area/reg_syntax.js +15 -13
  91. data/html/js/edit_area/regexp.js +36 -32
  92. data/html/js/edit_area/resize_area.js +43 -47
  93. data/html/js/edit_area/search_replace.js +29 -29
  94. data/html/js/edit_area/template.html +6 -4
  95. data/html/js/json-broker-client.js +23 -17
  96. data/html/js/result-page.js +107 -57
  97. data/html/js/rt-setting-page.js +38 -15
  98. data/html/js/sidebar.js +41 -27
  99. data/html/js/templates.js +167 -32
  100. data/html/js/utils.js +143 -7
  101. data/html/js/yui/treeview.js +3671 -0
  102. data/html/swf/chart.swf +0 -0
  103. data/html/test/agent_editor_spec.js +815 -0
  104. data/html/test/index.html +40 -0
  105. data/html/test/jsspec/JSSpec.css +224 -0
  106. data/html/test/jsspec/JSSpec.js +1549 -0
  107. data/html/test/jsspec/diff_match_patch.js +1 -0
  108. data/html/test/utils_spec.js +111 -0
  109. data/lib/jiji/agent/agent.rb +69 -12
  110. data/lib/jiji/agent/agent_manager.rb +18 -12
  111. data/lib/jiji/agent/agent_registry.rb +35 -121
  112. data/lib/jiji/collector.rb +16 -6
  113. data/lib/jiji/command.rb +46 -5
  114. data/lib/jiji/dao/file_system_dao.rb +158 -0
  115. data/lib/jiji/dao/timed_data_dao.rb +2 -0
  116. data/lib/jiji/dao/trade_result_dao.rb +1 -1
  117. data/lib/jiji/error.rb +24 -8
  118. data/lib/jiji/migration/migrator1_2_0.rb +67 -0
  119. data/lib/jiji/models.rb +82 -24
  120. data/lib/jiji/operator.rb +55 -51
  121. data/lib/jiji/output.rb +85 -29
  122. data/lib/jiji/output_manager.rb +84 -0
  123. data/lib/jiji/plugin/embedded/single_click_client.rb +2 -2
  124. data/lib/jiji/plugin/securities_plugin.rb +0 -1
  125. data/lib/jiji/process.rb +229 -208
  126. data/lib/jiji/process_manager.rb +190 -96
  127. data/lib/jiji/registry.rb +87 -19
  128. data/lib/jiji/server.rb +1 -0
  129. data/lib/jiji/service/agent_service.rb +147 -48
  130. data/lib/jiji/service/output_service.rb +37 -17
  131. data/lib/jiji/service/process_service.rb +3 -5
  132. data/lib/jiji/service/trade_result_service.rb +4 -5
  133. data/lib/jiji/util/file_lock.rb +4 -4
  134. data/lib/jiji/util/include_proxy.rb +17 -0
  135. data/lib/jiji/util/json_broker.rb +6 -4
  136. data/lib/jiji/util/util.rb +1 -1
  137. data/swf/chart/fx/chart/Chart.as +7 -0
  138. data/swf/chart/fx/chart/ui/graph/GraphManager.as +15 -2
  139. data/test/ProcessTest/agents/foo.rb +10 -0
  140. data/test/ProcessTest/conf/configuration.yaml +3 -0
  141. data/test/agent/agent_tests.rb +10 -0
  142. data/test/agent/test_AgentManager.rb +28 -12
  143. data/test/agent/test_AgentRegistry.rb +194 -99
  144. data/test/agent/test_PeriodicallyAgent.rb +1 -2
  145. data/test/agent/test_Permitter.rb +1 -2
  146. data/test/all_tests.rb +7 -19
  147. data/test/dao/dao_tests.rb +9 -0
  148. data/test/dao/test_FileSystemDao.rb +431 -0
  149. data/test/dao/test_RateDao.rb +5 -7
  150. data/test/dao/test_TradeResultDao.rb +1 -2
  151. data/test/migration/migration_tests.rb +10 -0
  152. data/test/migration/migrator1_2_0test_data/basic/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  153. data/test/migration/migrator1_2_0test_data/basic/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  154. data/test/migration/migrator1_2_0test_data/basic/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  155. data/test/migration/migrator1_2_0test_data/basic/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  156. data/test/migration/migrator1_2_0test_data/basic/props.yaml +85 -0
  157. data/test/migration/migrator1_2_0test_data/illegal_props/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  158. data/test/migration/migrator1_2_0test_data/illegal_props/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  159. data/test/migration/migrator1_2_0test_data/illegal_props/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  160. data/test/migration/migrator1_2_0test_data/illegal_props/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  161. data/test/migration/migrator1_2_0test_data/illegal_props/props.yaml +1 -0
  162. data/test/migration/migrator1_2_0test_data/no_outs/props.yaml +85 -0
  163. data/test/migration/migrator1_2_0test_data/no_props/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  164. data/test/migration/migrator1_2_0test_data/no_props/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  165. data/test/migration/migrator1_2_0test_data/no_props/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  166. data/test/migration/migrator1_2_0test_data/no_props/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  167. data/test/migration/test_Migrator.rb +1 -1
  168. data/test/migration/test_Migrator1_0_3.rb +1 -1
  169. data/test/migration/test_Migrator1_1_0.rb +1 -1
  170. data/test/migration/test_Migrator1_2_0.rb +94 -0
  171. data/test/plugin/embedded/test_SingleClickClient.rb +1 -2
  172. data/test/plugin/plugin_tests.rb +8 -0
  173. data/test/plugin/test_Loader.rb +1 -1
  174. data/test/shared/rate.csv +144 -0
  175. data/test/shared/shared_tests.rb +9 -0
  176. data/test/shared/test_Cross.rb +144 -0
  177. data/test/shared/test_PositionManager.rb +285 -0
  178. data/test/shared/test_Signal.rb +65 -0
  179. data/test/test_Output.rb +28 -21
  180. data/test/test_OutputManager.rb +162 -0
  181. data/test/test_Output_registry.rb +6 -17
  182. data/test/test_Process.rb +434 -222
  183. data/test/test_ProcessManager.rb +458 -101
  184. data/test/test_utils.rb +71 -8
  185. data/test/util/test_BlockToSession.rb +1 -2
  186. data/test/util/test_CSV.rb +1 -2
  187. data/test/util/test_SynchronizeInterceptor.rb +1 -2
  188. data/test/util/util_tests.rb +9 -0
  189. metadata +127 -47
  190. data/html/js/agent-editor-page.js +0 -440
  191. data/html/js/codepress/codepress.css +0 -21
  192. data/html/js/codepress/codepress.html +0 -35
  193. data/html/js/codepress/codepress.js +0 -138
  194. data/html/js/codepress/engines/gecko.js +0 -293
  195. data/html/js/codepress/engines/khtml.js +0 -0
  196. data/html/js/codepress/engines/msie.js +0 -304
  197. data/html/js/codepress/engines/older.js +0 -0
  198. data/html/js/codepress/engines/opera.js +0 -260
  199. data/html/js/codepress/images/line-numbers.gif +0 -0
  200. data/html/js/codepress/index.html +0 -443
  201. data/html/js/codepress/languages/asp.css +0 -71
  202. data/html/js/codepress/languages/asp.js +0 -117
  203. data/html/js/codepress/languages/autoit.css +0 -13
  204. data/html/js/codepress/languages/autoit.js +0 -32
  205. data/html/js/codepress/languages/csharp.css +0 -9
  206. data/html/js/codepress/languages/csharp.js +0 -25
  207. data/html/js/codepress/languages/css.css +0 -10
  208. data/html/js/codepress/languages/css.js +0 -23
  209. data/html/js/codepress/languages/generic.css +0 -9
  210. data/html/js/codepress/languages/generic.js +0 -25
  211. data/html/js/codepress/languages/html.css +0 -13
  212. data/html/js/codepress/languages/html.js +0 -59
  213. data/html/js/codepress/languages/java.css +0 -7
  214. data/html/js/codepress/languages/java.js +0 -24
  215. data/html/js/codepress/languages/javascript.css +0 -8
  216. data/html/js/codepress/languages/javascript.js +0 -30
  217. data/html/js/codepress/languages/perl.css +0 -11
  218. data/html/js/codepress/languages/perl.js +0 -27
  219. data/html/js/codepress/languages/php.css +0 -12
  220. data/html/js/codepress/languages/php.js +0 -61
  221. data/html/js/codepress/languages/ruby.css +0 -10
  222. data/html/js/codepress/languages/ruby.js +0 -26
  223. data/html/js/codepress/languages/sql.css +0 -10
  224. data/html/js/codepress/languages/sql.js +0 -30
  225. data/html/js/codepress/languages/text.css +0 -5
  226. data/html/js/codepress/languages/text.js +0 -9
  227. data/html/js/codepress/languages/vbscript.css +0 -71
  228. data/html/js/codepress/languages/vbscript.js +0 -117
  229. data/html/js/codepress/languages/xsl.css +0 -15
  230. data/html/js/codepress/languages/xsl.js +0 -103
  231. data/html/js/codepress/license.txt +0 -458
  232. data/html/js/edit_area/images/Thumbs.db +0 -0
  233. data/test/plugin/test_gem/a/lib/jiji_plugin_test.rb +0 -6
@@ -5,22 +5,23 @@
5
5
 
6
6
 
7
7
  // need to redefine this functiondue to IE problem
8
- function getAttribute( elm, aname ) {
8
+ function getAttribute( elm, aName ) {
9
+ var aValue,taName,i;
9
10
  try{
10
- var avalue = elm.getAttribute( aname );
11
- }catch(exept){
11
+ aValue = elm.getAttribute( aName );
12
+ }catch(exept){}
12
13
 
13
- }
14
- if ( ! avalue ) {
15
- for ( var i = 0; i < elm.attributes.length; i ++ ) {
16
- var taName = elm.attributes [i] .name.toLowerCase();
17
- if ( taName == aname ) {
18
- avalue = elm.attributes [i] .value;
19
- return avalue;
14
+ if( ! aValue ){
15
+ if ( !elm.attributes ) return null;
16
+ for( i = 0; i < elm.attributes.length; i ++ ) {
17
+ taName = elm.attributes[i] .name.toLowerCase();
18
+ if( taName == aName ) {
19
+ aValue = elm.attributes[i] .value;
20
+ return aValue;
20
21
  }
21
22
  }
22
23
  }
23
- return avalue;
24
+ return aValue;
24
25
  };
25
26
 
26
27
  // need to redefine this function due to IE problem
@@ -50,7 +51,7 @@
50
51
  if(elem){
51
52
  var children= elem.childNodes;
52
53
  var result=null;
53
- var results= new Array();
54
+ var results= [];
54
55
  for (var x=0;x<children.length;x++) {
55
56
  strTagName = new String(children[x].tagName);
56
57
  children_class="?";
@@ -93,46 +94,37 @@
93
94
  };
94
95
 
95
96
  function getMouseX(e){
96
- /*if(document.all)
97
- return event.x + document.body.scrollLeft;
98
- else
99
- return e.pageX;*/
97
+
100
98
  if(e!=null && typeof(e.pageX)!="undefined"){
101
99
  return e.pageX;
102
100
  }else{
103
101
  return (e!=null?e.x:event.x)+ document.documentElement.scrollLeft;
104
102
  }
105
- //return (e!=null) ? e.pageX : event.x + document.documentElement.scrollLeft;
106
103
  };
107
104
 
108
105
  function getMouseY(e){
109
- /*if(document.all)
110
- return event.y + document.body.scrollTop;
111
- else
112
- return e.pageY;*/
113
106
  if(e!=null && typeof(e.pageY)!="undefined"){
114
107
  return e.pageY;
115
108
  }else{
116
109
  return (e!=null?e.y:event.y)+ document.documentElement.scrollTop;
117
110
  }
118
- //return (e!=null) ? e.pageY : event.y + document.documentElement.scrollTop;
119
111
  };
120
112
 
121
113
  function calculeOffsetLeft(r){
122
- return calculeOffset(r,"offsetLeft")
114
+ return calculeOffset(r,"offsetLeft")
123
115
  };
124
116
 
125
117
  function calculeOffsetTop(r){
126
- return calculeOffset(r,"offsetTop")
118
+ return calculeOffset(r,"offsetTop")
127
119
  };
128
120
 
129
121
  function calculeOffset(element,attr){
130
- var offset=0;
131
- while(element){
132
- offset+=element[attr];
133
- element=element.offsetParent
134
- }
135
- return offset;
122
+ var offset=0;
123
+ while(element){
124
+ offset+=element[attr];
125
+ element=element.offsetParent
126
+ }
127
+ return offset;
136
128
  };
137
129
 
138
130
  /** return the computed style
@@ -160,7 +152,8 @@
160
152
  * Moving an element
161
153
  ***/
162
154
 
163
- var move_current_element;
155
+ var _mCE; // currently moving element
156
+
164
157
  /* allow to move an element in a window
165
158
  e: the event
166
159
  id: the id of the element
@@ -179,46 +172,44 @@
179
172
  if(frame.event)
180
173
  e=frame.event;
181
174
 
182
- move_current_element= frame.document.getElementById(elem_id);
183
- move_current_element.frame=frame;
175
+ _mCE= frame.document.getElementById(elem_id);
176
+ _mCE.frame=frame;
184
177
  frame.document.onmousemove= move_element;
185
178
  frame.document.onmouseup= end_move_element;
186
- /*move_current_element.onmousemove= move_element;
187
- move_current_element.onmouseup= end_move_element;*/
179
+ /*_mCE.onmousemove= move_element;
180
+ _mCE.onmouseup= end_move_element;*/
188
181
 
189
- //alert(move_current_element.frame.document.body.offsetHeight);
182
+ //alert(_mCE.frame.document.body.offsetHeight);
190
183
 
191
184
  mouse_x= getMouseX(e);
192
185
  mouse_y= getMouseY(e);
193
- //window.status=frame+ " elem: "+elem_id+" elem: "+ move_current_element + " mouse_x: "+mouse_x;
194
- move_current_element.start_pos_x = mouse_x - (move_current_element.style.left.replace("px","") || calculeOffsetLeft(move_current_element));
195
- move_current_element.start_pos_y = mouse_y - (move_current_element.style.top.replace("px","") || calculeOffsetTop(move_current_element));
186
+ //window.status=frame+ " elem: "+elem_id+" elem: "+ _mCE + " mouse_x: "+mouse_x;
187
+ _mCE.start_pos_x = mouse_x - (_mCE.style.left.replace("px","") || calculeOffsetLeft(_mCE));
188
+ _mCE.start_pos_y = mouse_y - (_mCE.style.top.replace("px","") || calculeOffsetTop(_mCE));
196
189
  return false;
197
190
  };
198
191
 
199
192
  function end_move_element(e){
200
- move_current_element.frame.document.onmousemove= "";
201
- move_current_element.frame.document.onmouseup= "";
202
- move_current_element=null;
193
+ _mCE.frame.document.onmousemove= "";
194
+ _mCE.frame.document.onmouseup= "";
195
+ _mCE=null;
203
196
  };
204
197
 
205
198
  function move_element(e){
206
- /*window.status="move"+frame;
207
- window.status="move2"+frame.event;*/
208
- if(move_current_element.frame && move_current_element.frame.event)
209
- e=move_current_element.frame.event;
210
- var mouse_x=getMouseX(e);
211
- var mouse_y=getMouseY(e);
212
- var new_top= mouse_y - move_current_element.start_pos_y;
213
- var new_left= mouse_x - move_current_element.start_pos_x;
199
+ var newTop,newLeft,maxLeft;
200
+
201
+ if( _mCE.frame && _mCE.frame.event )
202
+ e=_mCE.frame.event;
203
+ newTop = getMouseY(e) - _mCE.start_pos_y;
204
+ newLeft = getMouseX(e) - _mCE.start_pos_x;
214
205
 
215
- var max_left= move_current_element.frame.document.body.offsetWidth- move_current_element.offsetWidth;
216
- max_top= move_current_element.frame.document.body.offsetHeight- move_current_element.offsetHeight;
217
- new_top= Math.min(Math.max(0, new_top), max_top);
218
- new_left= Math.min(Math.max(0, new_left), max_left);
206
+ maxLeft = _mCE.frame.document.body.offsetWidth- _mCE.offsetWidth;
207
+ max_top = _mCE.frame.document.body.offsetHeight- _mCE.offsetHeight;
208
+ newTop = Math.min(Math.max(0, newTop), max_top);
209
+ newLeft = Math.min(Math.max(0, newLeft), maxLeft);
219
210
 
220
- move_current_element.style.top= new_top+"px";
221
- move_current_element.style.left= new_left+"px";
211
+ _mCE.style.top = newTop+"px";
212
+ _mCE.style.left = newLeft+"px";
222
213
  return false;
223
214
  };
224
215
 
@@ -230,85 +221,86 @@
230
221
 
231
222
  // allow to get infos on the selection: array(start, end)
232
223
  function getSelectionRange(textarea){
233
- //if(nav['isIE'])
234
- // get_IE_selection(textarea);
235
224
  return {"start": textarea.selectionStart, "end": textarea.selectionEnd};
236
225
  };
237
226
 
238
227
  // allow to set the selection
239
- function setSelectionRange(textarea, start, end){
240
- textarea.focus();
228
+ function setSelectionRange(t, start, end){
229
+ t.focus();
241
230
 
242
- start= Math.max(0, Math.min(textarea.value.length, start));
243
- end= Math.max(start, Math.min(textarea.value.length, end));
231
+ start = Math.max(0, Math.min(t.value.length, start));
232
+ end = Math.max(start, Math.min(t.value.length, end));
244
233
 
245
- if(nav['isOpera']){ // Opera bug when moving selection start and selection end
246
- textarea.selectionEnd = 1;
247
- textarea.selectionStart = 0;
248
- textarea.selectionEnd = 1;
249
- textarea.selectionStart = 0;
234
+ if( this.isOpera && this.isOpera < 9.6 ){ // Opera bug when moving selection start and selection end
235
+ t.selectionEnd = 1;
236
+ t.selectionStart = 0;
237
+ t.selectionEnd = 1;
238
+ t.selectionStart = 0;
250
239
  }
251
- textarea.selectionStart = start;
252
- textarea.selectionEnd = end;
240
+ t.selectionStart = start;
241
+ t.selectionEnd = end;
253
242
  //textarea.setSelectionRange(start, end);
254
243
 
255
- if(nav['isIE'])
256
- set_IE_selection(textarea);
244
+ if(isIE)
245
+ set_IE_selection(t);
257
246
  };
258
247
 
259
248
 
260
249
  // set IE position in Firefox mode (textarea.selectionStart and textarea.selectionEnd). should work as a repeated task
261
- function get_IE_selection(textarea){
262
-
263
- if(textarea && textarea.focused)
250
+ function get_IE_selection(t){
251
+ var d=document,div,range,stored_range,elem,scrollTop,relative_top,line_start,line_nb,range_start,range_end,tab;
252
+ if(t && t.focused)
264
253
  {
265
- if(!textarea.ea_line_height)
254
+ if(!t.ea_line_height)
266
255
  { // calculate the lineHeight
267
- var div= document.createElement("div");
268
- div.style.fontFamily= get_css_property(textarea, "font-family");
269
- div.style.fontSize= get_css_property(textarea, "font-size");
256
+ div= d.createElement("div");
257
+ div.style.fontFamily= get_css_property(t, "font-family");
258
+ div.style.fontSize= get_css_property(t, "font-size");
270
259
  div.style.visibility= "hidden";
271
260
  div.innerHTML="0";
272
- document.body.appendChild(div);
273
- textarea.ea_line_height= div.offsetHeight;
274
- document.body.removeChild(div);
261
+ d.body.appendChild(div);
262
+ t.ea_line_height= div.offsetHeight;
263
+ d.body.removeChild(div);
275
264
  }
276
- //textarea.focus();
277
- var range = document.selection.createRange();
278
- var stored_range = range.duplicate();
279
- stored_range.moveToElementText( textarea );
280
- stored_range.setEndPoint( 'EndToEnd', range );
281
- if(stored_range.parentElement()==textarea){
282
- // the range don't take care of empty lines in the end of the selection
283
- var elem= textarea;
284
- var scrollTop= 0;
285
- while(elem.parentNode){
286
- scrollTop+= elem.scrollTop;
287
- elem= elem.parentNode;
288
- }
289
-
290
- // var scrollTop= textarea.scrollTop + document.body.scrollTop;
291
-
292
- // var relative_top= range.offsetTop - calculeOffsetTop(textarea) + scrollTop;
293
- var relative_top= range.offsetTop - calculeOffsetTop(textarea)+ scrollTop;
294
- // alert("rangeoffset: "+ range.offsetTop +"\ncalcoffsetTop: "+ calculeOffsetTop(textarea) +"\nrelativeTop: "+ relative_top);
295
- var line_start = Math.round((relative_top / textarea.ea_line_height) +1);
296
-
297
- var line_nb= Math.round(range.boundingHeight / textarea.ea_line_height);
298
-
299
- // alert("store_range: "+ stored_range.text.length+"\nrange: "+range.text.length+"\nrange_text: "+ range.text);
300
- var range_start= stored_range.text.length - range.text.length;
301
- var tab= textarea.value.substr(0, range_start).split("\n");
302
- range_start+= (line_start - tab.length)*2; // add missing empty lines to the selection
303
- textarea.selectionStart = range_start;
265
+ //t.focus();
266
+ range = d.selection.createRange();
267
+ try
268
+ {
269
+ stored_range = range.duplicate();
270
+ stored_range.moveToElementText( t );
271
+ stored_range.setEndPoint( 'EndToEnd', range );
272
+ if(stored_range.parentElement() == t){
273
+ // the range don't take care of empty lines in the end of the selection
274
+ elem = t;
275
+ scrollTop = 0;
276
+ while(elem.parentNode){
277
+ scrollTop+= elem.scrollTop;
278
+ elem = elem.parentNode;
279
+ }
304
280
 
305
- var range_end= textarea.selectionStart + range.text.length;
306
- tab= textarea.value.substr(0, range_start + range.text.length).split("\n");
307
- range_end+= (line_start + line_nb - 1 - tab.length)*2;
308
- textarea.selectionEnd = range_end;
281
+ // var scrollTop= t.scrollTop + document.body.scrollTop;
282
+
283
+ // var relative_top= range.offsetTop - calculeOffsetTop(t) + scrollTop;
284
+ relative_top= range.offsetTop - calculeOffsetTop(t)+ scrollTop;
285
+ // alert("rangeoffset: "+ range.offsetTop +"\ncalcoffsetTop: "+ calculeOffsetTop(t) +"\nrelativeTop: "+ relative_top);
286
+ line_start = Math.round((relative_top / t.ea_line_height) +1);
287
+
288
+ line_nb = Math.round(range.boundingHeight / t.ea_line_height);
289
+
290
+ range_start = stored_range.text.length - range.text.length;
291
+ tab = t.value.substr(0, range_start).split("\n");
292
+ range_start += (line_start - tab.length)*2; // add missing empty lines to the selection
293
+ t.selectionStart = range_start;
294
+
295
+ range_end = t.selectionStart + range.text.length;
296
+ tab = t.value.substr(0, range_start + range.text.length).split("\n");
297
+ range_end += (line_start + line_nb - 1 - tab.length)*2;
298
+ t.selectionEnd = range_end;
299
+ }
309
300
  }
301
+ catch(e){}
310
302
  }
311
- setTimeout("get_IE_selection(document.getElementById('"+ textarea.id +"'));", 50);
303
+ setTimeout("get_IE_selection(document.getElementById('"+ t.id +"'));", 50);
312
304
  };
313
305
 
314
306
  function IE_textarea_focus(){
@@ -320,16 +312,21 @@
320
312
  }
321
313
 
322
314
  // select the text for IE (take into account the \r difference)
323
- function set_IE_selection(textarea){
315
+ function set_IE_selection( t ){
316
+ var nbLineStart,nbLineStart,nbLineEnd,range;
324
317
  if(!window.closed){
325
- var nbLineStart=textarea.value.substr(0, textarea.selectionStart).split("\n").length - 1;
326
- var nbLineEnd=textarea.value.substr(0, textarea.selectionEnd).split("\n").length - 1;
327
- var range = document.selection.createRange();
328
- range.moveToElementText( textarea );
329
- range.setEndPoint( 'EndToStart', range );
330
- range.moveStart('character', textarea.selectionStart - nbLineStart);
331
- range.moveEnd('character', textarea.selectionEnd - nbLineEnd - (textarea.selectionStart - nbLineStart) );
332
- range.select();
318
+ nbLineStart=t.value.substr(0, t.selectionStart).split("\n").length - 1;
319
+ nbLineEnd=t.value.substr(0, t.selectionEnd).split("\n").length - 1;
320
+ try
321
+ {
322
+ range = document.selection.createRange();
323
+ range.moveToElementText( t );
324
+ range.setEndPoint( 'EndToStart', range );
325
+ range.moveStart('character', t.selectionStart - nbLineStart);
326
+ range.moveEnd('character', t.selectionEnd - nbLineEnd - (t.selectionStart - nbLineStart) );
327
+ range.select();
328
+ }
329
+ catch(e){}
333
330
  }
334
331
  };
335
332