You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

findDlg.js 34 KiB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986
  1. //Copyright (c) 2001-2016 Aspose Pty Ltd. All Rights Reserved.
  2. /***********************************************************************************************
  3. * Aspose.Cells.GridWeb Component Script File
  4. * Copyright 2003-2011, All Rights Reserverd.
  5. ************************************************************************************************/
  6. var _oFindWhat = null; // The controll that be input what finding
  7. var _oReplaceWith = null; // The controll that be input what replacing whith
  8. var _oCase = null; // The check box to determine whether macthing case
  9. var _oWord = null; // The check box to determine whether macthing whole word
  10. var _oDirection = null; // The check box to determine searching direction. search down and search up.
  11. var _oRegular = null; // The check box to determine whether the seaching string is a regular expression.
  12. var _oFindIn = null; // The drop down list to indicate target is formulas or values.
  13. var _oBtnFind = null; // The find next button.
  14. var _oBtnReplace = null; // The replace button.
  15. var _oBtnReplaceAll = null; // The replace all button.
  16. var _oBtnClose = null; // The close button.
  17. var _parentWindow = null; // The parent window
  18. var _element = null; // The GridWeb object.
  19. var _viewTable = null; // One of the ViewTable objects.
  20. var _viewTable00 = null; // One of the ViewTable objects.
  21. var _viewTable01 = null; // One of the ViewTable objects.
  22. var _viewTable10 = null; // One of the ViewTable objects.
  23. var _activeCell = null; // The active cell.
  24. var _startSearchCell = null; // The first cell in a searching process.
  25. var _callType = 0; // 0 Find; 1 Replace
  26. var _dialogEdgeLeftWidth = 0; // The left edge width of the find/replace dialog window
  27. var _dialogEdgeTopHeight = 0; // The top edge width of the find/replace dialog window, i.e. The title bar width.
  28. var _cidReg = new RegExp("^\\d+#\\d+$");
  29. var _findReg = null;
  30. var _findWhat = null;
  31. var _regexOptions = null;
  32. var _freeze = null;
  33. var _arrCells = new Array();
  34. var _cellIndex = 0;
  35. var _currentViewTable = null;
  36. var _currentCellIndex = 0;
  37. var _currentRowIndex = 0;
  38. var _currentRows = null;
  39. var _currentCells = null;
  40. var _currentRowsLength = 0;
  41. var _currentCellsLength = 0;
  42. //----------------------------------------------------------------------------------------------------
  43. // Initializes variants, gets parameters from parent window after window on load.
  44. //----------------------------------------------------------------------------------------------------
  45. window.onload = function(){
  46. _oFindWhat = document.getElementById("txtFindWhat");
  47. _oReplaceWith = document.getElementById("txtReplaceWith");
  48. _oCase = document.getElementById("ckbCase");
  49. _oWord = document.getElementById("ckbWord");
  50. _oDirection = document.getElementById("ckbDirection");
  51. _oRegular = document.getElementById("ckbRegular");
  52. _oFindIn = document.getElementById("ddlFindIn");
  53. _oBtnFind = document.getElementById("btnFind");
  54. _oBtnReplace = document.getElementById("btnReplace");
  55. _oBtnReplaceAll = document.getElementById("btnReplaceAll");
  56. _oBtnClose = document.getElementById("btnClose");
  57. if(!window.showModelessDialog) // Is not IE
  58. {
  59. _parentWindow = window.opener;
  60. _element = _parentWindow.acwFindReplaceDialog_Element;
  61. _activeCell = _parentWindow.acwFindReplaceDialog_StartCell;
  62. _oBtnFind.style.width = "100px";
  63. _oBtnReplace.style.width = "100px";
  64. _oBtnReplaceAll.style.width = "100px";
  65. _oBtnClose.style.width = "100px";
  66. _dialogEdgeLeftWidth = (window.outerWidth - innerWidth)/2;
  67. _dialogEdgeTopHeight = parseInt((window.outerHeight - innerHeight)/2+1);
  68. }
  69. else{ //IE
  70. _parentWindow = window.dialogArguments[0];
  71. _arrCells = window.dialogArguments[1];
  72. _cellIndex = window.dialogArguments[2];
  73. _element = _parentWindow.acwFindReplaceDialog_Element;
  74. _activeCell = _parentWindow.acwFindReplaceDialog_StartCell;
  75. _dialogEdgeLeftWidth = window.screenLeft - parseFloat(window.dialogLeft);
  76. _dialogEdgeTopHeight = window.screenTop - parseFloat(window.dialogTop);
  77. }
  78. _callType = getUrlParameter("callType");
  79. _freeze = _element.freeze;
  80. init();
  81. }
  82. //----------------------------------------------------------------------------------------------------
  83. // Sets the variants about this window when the window be closed.
  84. //----------------------------------------------------------------------------------------------------
  85. window.onunload = function(){
  86. if(typeof _parentWindow == "undefined" || typeof _parentWindow.acwFindReplaceDialog == "undefined"){
  87. return false;
  88. }
  89. _parentWindow.acwFindReplaceDialog_Element = null;
  90. _parentWindow.acwFindReplaceDialog_StartCell = null;
  91. _parentWindow.acwFindReplaceDialog = null;
  92. }
  93. //----------------------------------------------------------------------------------------------------
  94. // If reload window opener, closes FindReplace Dialog.
  95. //----------------------------------------------------------------------------------------------------
  96. window.onfocus = function(){
  97. if(typeof _parentWindow == "undefined"
  98. || typeof _parentWindow.acwFindReplaceDialog == "undefined"
  99. || (_activeCell != null && _activeCell.parentNode == null)){
  100. window.close();
  101. }
  102. }
  103. //----------------------------------------------------------------------------------------------------
  104. // Handles onkeyown events
  105. //----------------------------------------------------------------------------------------------------
  106. document.onkeydown = function(evt){
  107. if(evt == null)
  108. evt = event;
  109. if(evt.keyCode == 27){ // Esc
  110. window.close();
  111. return false;
  112. }
  113. else if(evt.keyCode == 13){ //enter
  114. _oBtnFind.click();
  115. return false;
  116. }
  117. }
  118. //----------------------------------------------------------------------------------------------------
  119. // Initializes variants, determines how to lay out page.
  120. //----------------------------------------------------------------------------------------------------
  121. function init(){
  122. _viewTable = _element.ownerDocument.getElementById(_element.id + "_viewTable");
  123. if (_freeze)
  124. {
  125. _viewTable00 = _element.ownerDocument.getElementById(_element.id + "_viewTable00");
  126. _viewTable01 = _element.ownerDocument.getElementById(_element.id + "_viewTable01");
  127. _viewTable10 = _element.ownerDocument.getElementById(_element.id + "_viewTable10");
  128. }
  129. if(_activeCell == null){
  130. if(_freeze){
  131. if(_viewTable00.rows.length != 0 && _viewTable00.rows[0].cells.length != 0){
  132. _activeCell = _viewTable00.rows[0].cells[0];
  133. }
  134. else if(_viewTable01.rows.length != 0 && _viewTable01.rows[0].cells.length != 0){
  135. _activeCell = _viewTable01.rows[0].cells[0];
  136. }
  137. else if(_viewTable10.rows.length != 0 && _viewTable10.rows[0].cells.length != 0){
  138. _activeCell = _viewTable10.rows[0].cells[0];
  139. }
  140. else if(_viewTable.rows.length != 0 && _viewTable.rows[0].cells.length != 0){
  141. _activeCell = _viewTable.rows[0].cells[0];
  142. }
  143. else{ // No cell provide for searching
  144. window.close();
  145. return;
  146. }
  147. }
  148. else {
  149. if(_viewTable.rows.length == 0 || _viewTable.rows[0].cells.length == 0){ // No cell provide for searching
  150. window.close();
  151. return;
  152. }
  153. else{
  154. _activeCell = _viewTable.rows[0].cells[0];
  155. }
  156. }
  157. setActiveCell(_activeCell);
  158. }
  159. validateInitArguments();
  160. showElmentByCallType(_callType);
  161. //FillCellsToArray(_activeCell);
  162. if(navigator.appName.indexOf("Microsoft") == -1){ // Is not IE
  163. _currentViewTable = _activeCell.offsetParent;
  164. _currentCellIndex = _activeCell.cellIndex;
  165. _currentRowIndex = _activeCell.parentNode.rowIndex;
  166. _currentRows = _currentViewTable.rows;
  167. _currentRowsLength = _currentRows.length;
  168. _currentCells = _currentRows[_currentRowIndex].cells;
  169. _currentCellsLength = _currentCells.length;
  170. }
  171. }
  172. //----------------------------------------------------------------------------------------------------
  173. // Determines whether can call the Find/Replace feature.
  174. //----------------------------------------------------------------------------------------------------
  175. function validateInitArguments(){
  176. if(_element == null || _activeCell == null || _callType == null){
  177. alert("Arguments are null. Can't call Find/Replace feature!");
  178. window.close();
  179. }
  180. }
  181. //----------------------------------------------------------------------------------------------------
  182. // Determines how to lay out page according to call type(find or replace)
  183. // Arguments:
  184. // callType: o indicates find, 1 indicates replace
  185. //----------------------------------------------------------------------------------------------------
  186. function showElmentByCallType(callType){
  187. if(callType == 0){ // Find
  188. document.getElementById("trReplaceWhat").style.display = "none";
  189. document.getElementById("trReplaceAll").style.display = "none";
  190. }
  191. else if(callType == 1){ // Replace
  192. document.getElementById("trReplaceWhat").style.display = "";
  193. document.getElementById("trReplaceAll").style.display = "";
  194. }
  195. if (!_element.editmode) {
  196. document.getElementById("trReplace").style.display = "none";
  197. }
  198. }
  199. //----------------------------------------------------------------------------------------------------
  200. // Determines whether continueing to execute when executor clicks find next, replace or replace all button
  201. // Arguments:
  202. // obj: The button object.
  203. // Return: Allows to execute return true, otherwise return false.
  204. //----------------------------------------------------------------------------------------------------
  205. function isEnableGo(obj){
  206. if((obj == _oBtnReplace || obj == _oBtnReplaceAll) && !_element.editmode)
  207. return false;
  208. if(obj == _oBtnReplace && _callType == 0){
  209. _callType = 1;
  210. showElmentByCallType(1);
  211. return false;
  212. }
  213. if((obj == _oBtnReplace || obj == _oBtnReplaceAll) && _oFindIn.value == 2){
  214. if(window.confirm("Findin must be set to Formulas. Now, set it to Formulas and continue?")){
  215. _oFindIn.value = 1;
  216. }
  217. else{
  218. return false;
  219. }
  220. }
  221. _findWhat = _oFindWhat.value;
  222. if(_findWhat == ""){
  223. alert("Please input what will be searched!");
  224. return false;
  225. }
  226. _regexOptions = getRegExpOptions();
  227. if(!_oRegular.checked){ // RegularExpression checkbox is false
  228. _findWhat = escapeMetacharacters(_findWhat); // Escapes meta characters. E.g. "\w" to "\\w"
  229. }
  230. if(_oWord.checked){
  231. _findWhat = "(\\W|^)" + _findWhat + "(\\W|$)";
  232. }
  233. try{
  234. _findReg = new RegExp(_findWhat, _regexOptions);
  235. }
  236. catch(e){//Regular Expression is error
  237. alert(e.name + ": " + e.message);
  238. return false;
  239. }
  240. _startSearchCell = _activeCell;
  241. return true;
  242. }
  243. //----------------------------------------------------------------------------------------------------
  244. // Find next cell
  245. //----------------------------------------------------------------------------------------------------
  246. function find_Next() {
  247. var findCell = _startSearchCell;
  248. do{
  249. findCell = moveToNextCell3();
  250. var sourceString;
  251. sourceString = getInnerText(findCell);
  252. // Determines the findCell whether contains the spiciel string.
  253. if(sourceString != null && sourceString != ""){
  254. //_findReg = new RegExp(_findWhat, _regexOptions);
  255. if(_oFindIn.value == 1){ // Find in values or formulas. If cell is set value by formulas, find in formula, but don't find in value.
  256. // otherwise, find in values
  257. var bHadFound = false;
  258. if(getAttribute(findCell,"formula") != null ){
  259. if(_findReg.exec(getAttribute(findCell, "formula"))){
  260. bHadFound = true;
  261. }
  262. }
  263. else if(getAttribute(findCell, "ufv") != null){
  264. if(_findReg.exec(getAttribute(findCell, "ufv"))){
  265. bHadFound = true;
  266. }
  267. }
  268. else if(_findReg.exec(sourceString)){
  269. bHadFound = true;
  270. }
  271. if(bHadFound){
  272. setActiveCell(findCell); // Had found
  273. _activeCell = findCell;
  274. return true;
  275. }
  276. }
  277. else if(_oFindIn.value == 2){ //Only Find values in all cells.
  278. if(_findReg.exec(sourceString)){
  279. setActiveCell(findCell); // Had found
  280. _activeCell = findCell;
  281. return true;
  282. }
  283. }
  284. }
  285. if(findCell == _startSearchCell){
  286. alert("The specified text was not found!");
  287. return false;
  288. }
  289. }
  290. while(true);
  291. }
  292. //----------------------------------------------------------------------------------------------------
  293. // Replaces with the specified string and find next cell
  294. //----------------------------------------------------------------------------------------------------
  295. function replace() {
  296. var replaceCell = _startSearchCell;
  297. var replaceCount = 0;
  298. do{
  299. var sourceString;
  300. sourceString = getInnerText(replaceCell);
  301. if(replaceCount == 0){// Replace
  302. if(isCanReplaced(replaceCell) && sourceString != null && sourceString != ""){
  303. _findReg = new RegExp(_findWhat, _regexOptions);
  304. var txt;
  305. if(getAttribute(replaceCell, "formula") != null ){ // Is Formula
  306. if(_findReg.exec(getAttribute(replaceCell, "formula"))){
  307. if(_oWord.checked){
  308. txt = getAttribute(replaceCell, "formula").replace(_findReg,"$1" + _oReplaceWith.value + "$2");
  309. setCellValue(replaceCell,txt);
  310. }
  311. else{
  312. txt = getAttribute(replaceCell, "formula").replace(_findReg,_oReplaceWith.value);
  313. setCellValue(replaceCell,txt);
  314. }
  315. replaceCount++;
  316. }
  317. }
  318. else if(getAttribute(replaceCell, "ufv") != null){ // Is Data Format
  319. if(_findReg.exec(getAttribute(replaceCell, "ufv"))){
  320. if(_oWord.checked){
  321. txt = getAttribute(replaceCell, "ufv").replace(_findReg,"$1" + _oReplaceWith.value + "$2");
  322. setCellValue(replaceCell,txt);
  323. }
  324. else{
  325. txt = getAttribute(replaceCell, "ufv").replace(_findReg,_oReplaceWith.value);
  326. setCellValue(replaceCell,txt);
  327. }
  328. replaceCount++;
  329. }
  330. }
  331. else if(_findReg.exec(sourceString)){
  332. if(_oWord.checked){
  333. txt = sourceString.replace(_findReg,"$1" + _oReplaceWith.value + "$2");
  334. setCellValue(replaceCell,txt);
  335. }
  336. else{
  337. txt = sourceString.replace(_findReg,_oReplaceWith.value);
  338. setCellValue(replaceCell,txt);
  339. }
  340. replaceCount++;
  341. }
  342. }
  343. }
  344. else{ //Had replaced. Finds next and set it active.
  345. if(isCanReplaced(replaceCell) && sourceString != null && sourceString != ""){
  346. _findReg = new RegExp(_findWhat, _regexOptions);
  347. var bHadFound = false;
  348. if(getAttribute(replaceCell,"formula") != null ){
  349. if(_findReg.exec(getAttribute(replaceCell, "formula"))){
  350. bHadFound = true;
  351. }
  352. }
  353. else if(getAttribute(replaceCell, "ufv") != null){
  354. if(_findReg.exec(getAttribute(replaceCell, "ufv"))){
  355. bHadFound = true;
  356. }
  357. }
  358. else if(_findReg.exec(sourceString)){
  359. bHadFound = true;
  360. }
  361. if(bHadFound){
  362. setActiveCell(replaceCell); // Had found
  363. _activeCell = replaceCell;
  364. return true;
  365. }
  366. }
  367. }
  368. replaceCell = moveToNextCell3();
  369. if(replaceCell == _startSearchCell){
  370. if(replaceCount == 0){
  371. alert("The specified text was not found or the cell is read only!");
  372. }
  373. return false;
  374. }
  375. }
  376. while(true);
  377. }
  378. //----------------------------------------------------------------------------------------------------
  379. // Replaces with the specified string in all cells.
  380. //----------------------------------------------------------------------------------------------------
  381. function replaceAll() {
  382. var replaceCell = _startSearchCell;
  383. var replaceCount = 0;
  384. do{
  385. var sourceString;
  386. sourceString = getInnerText(replaceCell);
  387. if(isCanReplaced(replaceCell) && sourceString != null && sourceString != ""){
  388. _findReg = new RegExp(_findWhat, _regexOptions);
  389. var txt;
  390. if(getAttribute(replaceCell, "formula") != null ){ // Is Formula
  391. if(_findReg.exec(getAttribute(replaceCell, "formula"))){
  392. if(_oWord.checked){
  393. txt = getAttribute(replaceCell, "formula").replace(_findReg,"$1" + _oReplaceWith.value + "$2");
  394. setCellValue(replaceCell,txt);
  395. }
  396. else{
  397. txt = getAttribute(replaceCell, "formula").replace(_findReg,_oReplaceWith.value);
  398. setCellValue(replaceCell,txt);
  399. }
  400. _replaceAllCount++;
  401. }
  402. }
  403. else if(getAttribute(replaceCell, "ufv") != null){ // Is Data Format
  404. if(_findReg.exec(getAttribute(replaceCell, "ufv"))){
  405. if(_oWord.checked){
  406. txt = getAttribute(replaceCell, "ufv").replace(_findReg,"$1" + _oReplaceWith.value + "$2");
  407. setCellValue(replaceCell,txt);
  408. }
  409. else{
  410. txt = getAttribute(replaceCell, "ufv").replace(_findReg,_oReplaceWith.value);
  411. setCellValue(replaceCell,txt);
  412. }
  413. replaceCount++;
  414. }
  415. }
  416. else if(_findReg.exec(sourceString)){
  417. if(_oWord.checked){
  418. txt = sourceString.replace(_findReg,"$1" + _oReplaceWith.value + "$2");
  419. setCellValue(replaceCell,txt);
  420. }
  421. else{
  422. txt = sourceString.replace(_findReg,_oReplaceWith.value);
  423. setCellValue(replaceCell,txt);
  424. }
  425. replaceCount++;
  426. }
  427. }
  428. replaceCell = moveToNextCell3();
  429. if(replaceCell == _startSearchCell){
  430. if(replaceCount > 0){
  431. alert(replaceCount + " occurrence(s) replaced.");
  432. }
  433. else{
  434. alert("The specified text was not found or the cell is read only!");
  435. }
  436. _startSearchCell = null;
  437. return false;
  438. }
  439. }
  440. while(true);
  441. }
  442. //----------------------------------------------------------------------------------------------------
  443. // Indicates whether the cell can execute replacing featrue.
  444. //----------------------------------------------------------------------------------------------------
  445. function isCanReplaced(cell){
  446. var r = false;
  447. if (getAttribute(cell, "protected") != "1" // Is not Read Only
  448. && getAttribute(cell, "vtype") != "dlist"){ // Is not DropDownList
  449. r = true;
  450. }
  451. return r;
  452. }
  453. //----------------------------------------------------------------------------------------------------
  454. // Gets regular expression options
  455. //----------------------------------------------------------------------------------------------------
  456. function getRegExpOptions(){
  457. var r = "gi";
  458. if(_oCase.checked){
  459. r = r.replace("i","");
  460. }
  461. return r;
  462. }
  463. //----------------------------------------------------------------------------------------------------
  464. // Escapes the meta characters in the specified string.
  465. //----------------------------------------------------------------------------------------------------
  466. function escapeMetacharacters(s){
  467. var syntax = "\\^$*+?{}.()|[]"; // meta characters
  468. for(var i=0; i<s.length; i++){
  469. var index = syntax.indexOf(s.charAt(i));
  470. if(index != -1){
  471. s = s.substring(0,i) + "\\" + s.substring(i,s.length);
  472. i++;
  473. }
  474. }
  475. return s;
  476. }
  477. //----------------------------------------------------------------------------------------------------
  478. // Sets the specified cell active
  479. //----------------------------------------------------------------------------------------------------
  480. function setActiveCell(cell){
  481. var index = cell.id.lastIndexOf("_");
  482. var xy = cell.id.substr(index+1,cell.id.length - index + 1).split("#");
  483. _element.setActiveCell(xy[1],xy[0]);
  484. // If cell is cover by dialog window, move the dialog window to the right down corner of the cell.
  485. var offsetParent = cell.offsetParent;
  486. var offsetLeftToBody = cell.offsetLeft;
  487. var offsetTopToBody = cell.offsetTop;
  488. do{
  489. offsetTopToBody += offsetParent.offsetTop;
  490. offsetLeftToBody += offsetParent.offsetLeft;
  491. offsetParent = offsetParent.offsetParent;
  492. }while(offsetParent);
  493. var panel = cell.offsetParent.parentNode;
  494. var x, y;
  495. var condition1, condition2,condition3, condition4;
  496. if(navigator.appName.indexOf("Microsoft") == -1) // Is not IE
  497. {
  498. offsetLeftToBody = offsetLeftToBody - panel.scrollLeft - _parentWindow.document.body.scrollLeft;
  499. offsetTopToBody = offsetTopToBody - panel.scrollTop - _parentWindow.document.body.scrollTop;
  500. x = offsetLeftToBody + _parentWindow.screenX + (_parentWindow.outerWidth - _parentWindow.innerWidth)/2;
  501. y = offsetTopToBody + _parentWindow.screenY + (_parentWindow.outerHeight - _parentWindow.innerHeight - _dialogEdgeTopHeight);
  502. condition1 = x >= window.screenX && x < window.screenX + window.outerWidth;
  503. condition2 = x + cell.offsetWidth > window.screenX && x + cell.offsetWidth <= window.screenX + window.outerWidth;
  504. condition3 = y >= window.screenY && y < window.screenY + window.outerHeight;
  505. condition4 = y + cell.offsetHeight > window.screenY && y + cell.offsetHeight <= window.screenY + window.outerHeight;
  506. if((condition1 || condition2) && (condition3 || condition4)){
  507. window.moveTo(x + cell.offsetWidth,y + cell.offsetHeight);
  508. }
  509. }
  510. else{ // IE
  511. offsetLeftToBody = offsetLeftToBody - panel.scrollLeft - _parentWindow.document.body.scrollLeft;
  512. offsetTopToBody = offsetTopToBody - panel.scrollTop - _parentWindow.document.body.scrollTop;
  513. x = offsetLeftToBody + _parentWindow.screenLeft;
  514. y = offsetTopToBody + _parentWindow.screenTop;
  515. condition1 = x >= window.screenLeft - _dialogEdgeLeftWidth && x < window.screenLeft - _dialogEdgeLeftWidth + parseFloat(dialogWidth);
  516. condition2 = x + cell.offsetWidth > window.screenLeft - _dialogEdgeLeftWidth && x + cell.offsetWidth <= window.screenLeft - _dialogEdgeLeftWidth + parseFloat(dialogWidth);
  517. condition3 = y >= window.screenTop - _dialogEdgeTopHeight && y < window.screenTop - _dialogEdgeTopHeight + parseFloat(dialogHeight);
  518. condition4 = y + cell.offsetHeight > window.screenTop - _dialogEdgeTopHeight && y + cell.offsetHeight <= window.screenTop - _dialogEdgeTopHeight + parseFloat(dialogHeight);
  519. if((condition1 || condition2) && (condition3 || condition4)){
  520. dialogLeft = x + cell.offsetWidth;
  521. dialogTop = y + cell.offsetHeight;
  522. }
  523. }
  524. }
  525. //----------------------------------------------------------------------------------------------------
  526. // Sets cell value to txt.
  527. //----------------------------------------------------------------------------------------------------
  528. function setCellValue(cell,txt){
  529. var index = cell.id.lastIndexOf("_");
  530. var xy = cell.id.substr(index+1,cell.id.length - index + 1).split("#");
  531. _element.setCellValue(xy[1], xy[0],txt);
  532. }
  533. //----------------------------------------------------------------------------------------------------
  534. // Gets the specified name parameter in url string.
  535. //----------------------------------------------------------------------------------------------------
  536. function getUrlParameter(name)
  537. {
  538. var url = window.location.search;
  539. var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
  540. if (reg.exec(url))
  541. return RegExp.$2;
  542. else
  543. return "";
  544. }
  545. function getTimeDistance(a,b){
  546. return b.getMilliseconds() - a.getMilliseconds() + 1000*(b.getSeconds() - a.getSeconds());
  547. }
  548. //----------------------------------------------------------------------------------------------------
  549. // Determines whether the specified object is valid cell.
  550. //----------------------------------------------------------------------------------------------------
  551. function isValidCell(o){
  552. if (o.tagName == "TD" && o.id != null && o.id.indexOf(_element.id) == 0 && _cidReg.exec(o.id.substring(_element.id.length+1,o.id.length)))
  553. return true;
  554. else
  555. return false;
  556. }
  557. //----------------------------------------------------------------------------------------------------
  558. // Obsolete. Gets the next cell.
  559. //----------------------------------------------------------------------------------------------------
  560. function moveToNextCell(cell){
  561. var currentViewTable = cell.offsetParent;
  562. var cellIndex = cell.cellIndex;
  563. var rowIndex = cell.parentNode.rowIndex;
  564. if(_freeze){
  565. if(_oDirection.checked){ // Search up
  566. if(cellIndex == 0 || currentViewTable.rows.length == 0 || currentViewTable.rows[rowIndex].cells.length == 0){
  567. if(rowIndex == 0){
  568. if(currentViewTable == _viewTable00){
  569. currentViewTable = _viewTable;
  570. if(currentViewTable.rows.length > 0)
  571. rowIndex = currentViewTable.rows.length - 1;
  572. }
  573. else if(currentViewTable == _viewTable01){
  574. currentViewTable = _viewTable00;
  575. }
  576. else if(currentViewTable == _viewTable10){
  577. currentViewTable = _viewTable01;
  578. if(currentViewTable.rows.length > 0)
  579. rowIndex = currentViewTable.rows.length - 1;
  580. }
  581. else if(currentViewTable == _viewTable){
  582. currentViewTable = _viewTable10;
  583. }
  584. }
  585. else{
  586. if(currentViewTable == _viewTable00){
  587. currentViewTable = _viewTable01;
  588. rowIndex--;
  589. }
  590. else if(currentViewTable == _viewTable01){
  591. currentViewTable = _viewTable00;
  592. }
  593. else if(currentViewTable == _viewTable10){
  594. currentViewTable = _viewTable;
  595. rowIndex--;
  596. }
  597. else if(currentViewTable == _viewTable){
  598. currentViewTable = _viewTable10;
  599. }
  600. }
  601. if(currentViewTable.rows.length > 0 && currentViewTable.rows[rowIndex].cells.length > 0)
  602. cellIndex = currentViewTable.rows[rowIndex].cells.length -1;
  603. }
  604. else{ // Is not first cell in the row. Reduces cellIndex to 1 for move to next cell.
  605. cellIndex--;
  606. }
  607. }
  608. else{ // Search down
  609. if(currentViewTable.rows.length == 0 ||currentViewTable.rows[rowIndex].cells.length == 0 || cellIndex == currentViewTable.rows[rowIndex].cells.length - 1 ){
  610. cellIndex = 0;
  611. if(rowIndex == currentViewTable.rows.length - 1
  612. || ((currentViewTable == _viewTable00 || currentViewTable == _viewTable01) && _viewTable00.rows.length == 0 && _viewTable01.rows.length == 0)
  613. || ((currentViewTable == _viewTable10 || currentViewTable == _viewTable) && _viewTable10.rows.length == 0 && _viewTable.rows.length == 0)){
  614. if(currentViewTable == _viewTable00){
  615. currentViewTable = _viewTable01;
  616. }
  617. else if(currentViewTable == _viewTable01){
  618. currentViewTable = _viewTable10;
  619. rowIndex = 0;
  620. }
  621. else if(currentViewTable == _viewTable10){
  622. currentViewTable = _viewTable;
  623. }
  624. else if(currentViewTable == _viewTable){
  625. currentViewTable = _viewTable00;
  626. rowIndex = 0;
  627. }
  628. }
  629. else{
  630. if(currentViewTable == _viewTable00){
  631. currentViewTable = _viewTable01;
  632. }
  633. else if(currentViewTable == _viewTable01){
  634. currentViewTable = _viewTable00;
  635. rowIndex++;
  636. }
  637. else if(currentViewTable == _viewTable10){
  638. currentViewTable = _viewTable;
  639. }
  640. else if(currentViewTable == _viewTable){
  641. currentViewTable = _viewTable10;
  642. rowIndex++;
  643. }
  644. }
  645. }
  646. else{ // Is not last cell in the row. Adds cellIndex to 1 for move to next cell.
  647. cellIndex++;
  648. }
  649. }
  650. }
  651. else{
  652. if(_oDirection.checked){ // Search up
  653. if(cellIndex == 0){ // Is the first cell in the row.
  654. // The row move to next row and cellIndex is evaluated to the last cell index of next row.
  655. if(rowIndex == 0){
  656. rowIndex = currentViewTable.rows.length - 1;
  657. }
  658. else{
  659. rowIndex--;
  660. }
  661. cellIndex = currentViewTable.rows[rowIndex].cells.length -1;
  662. }
  663. else{ // Is not first cell in the row. Reduces cellIndex to 1 for move to next cell.
  664. cellIndex--;
  665. }
  666. }
  667. else{ // Search down
  668. if(cellIndex == currentViewTable.rows[rowIndex].cells.length -1){ // Is the last cell in the row.
  669. // The row move to next row and cellIndex is evaluated to the first cell index of next row.
  670. if(rowIndex == currentViewTable.rows.length - 1){
  671. rowIndex = 0;
  672. }
  673. else{
  674. rowIndex++;
  675. }
  676. cellIndex = 0;
  677. }
  678. else{ // Is not last cell in the row. Adds cellIndex to 1 for move to next cell.
  679. cellIndex++;
  680. }
  681. }
  682. }
  683. var cell = null;
  684. if(currentViewTable.rows.length > 0 && currentViewTable.rows[rowIndex].cells.length > 0){
  685. cell = currentViewTable.rows[rowIndex].cells[cellIndex];
  686. }
  687. if(cell != null && isValidCell(cell))
  688. return cell;
  689. else
  690. return moveToNextCell(cell);
  691. }
  692. //----------------------------------------------------------------------------------------------------
  693. // Obsolete. Gets the next cell that is valid cell.
  694. //----------------------------------------------------------------------------------------------------
  695. function moveToNextCell2(cell){
  696. if(_freeze){
  697. var currentViewTable = cell.offsetParent;
  698. var rowIndex;
  699. if(_oDirection.checked){ // Search up
  700. if(cell.previousSibling != null){
  701. cell = cell.previousSibling;
  702. }
  703. else if(cell.parentElement.previousSibling != null){
  704. rowIndex = cell.parentElement.rowIndex;
  705. if(currentViewTable == _viewTable00){
  706. cell = _viewTable01.rows[rowIndex - 1].lastChild;
  707. }
  708. else if(currentViewTable == _viewTable01){
  709. cell = _viewTable00.rows[rowIndex].lastChild;
  710. }
  711. else if(currentViewTable == _viewTable10){
  712. cell = _viewTable.rows[rowIndex - 1].lastChild;
  713. }
  714. else if(currentViewTable == _viewTable){
  715. cell = _viewTable10.rows[rowIndex].lastChild;
  716. }
  717. }
  718. else{
  719. if(currentViewTable == _viewTable00){
  720. cell = _viewTable.rows[_viewTable.rows.length - 1].lastChild;
  721. }
  722. else if(currentViewTable == _viewTable01){
  723. cell = _viewTable00.rows[0].lastChild;
  724. }
  725. else if(currentViewTable == _viewTable10){
  726. cell = _viewTable01.rows[_viewTable01.rows.length - 1].lastChild;
  727. }
  728. else if(currentViewTable == _viewTable){
  729. cell = _viewTable10.rows[0].lastChild;
  730. }
  731. }
  732. }
  733. else{
  734. if(cell.nextSibling != null){
  735. cell = cell.nextSibling;
  736. }
  737. else if(cell.parentElement.nextSibling != null){
  738. rowIndex = cell.parentElement.rowIndex;
  739. if(currentViewTable == _viewTable00){
  740. cell = _viewTable01.rows[rowIndex].firstChild;
  741. }
  742. else if(currentViewTable == _viewTable01){
  743. cell = _viewTable00.rows[rowIndex + 1].firstChild;
  744. }
  745. else if(currentViewTable == _viewTable10){
  746. cell = _viewTable.rows[rowIndex].firstChild;
  747. }
  748. else if(currentViewTable == _viewTable){
  749. cell = _viewTable10.rows[rowIndex + 1].firstChild;
  750. }
  751. }
  752. else{
  753. if(currentViewTable == _viewTable00){
  754. cell = _viewTable01.rows[_viewTable01.rows.length - 1].firstChild;
  755. }
  756. else if(currentViewTable == _viewTable01){
  757. cell = _viewTable10.rows[0].firstChild;
  758. }
  759. else if(currentViewTable == _viewTable10){
  760. cell = _viewTable.rows[_viewTable.rows.length - 1].firstChild;
  761. }
  762. else if(currentViewTable == _viewTable){
  763. cell = _viewTable00.rows[0].firstChild;
  764. }
  765. }
  766. }
  767. }
  768. else{
  769. if(_oDirection.checked){ // Search up
  770. if(cell.previousSibling != null){
  771. cell = cell.previousSibling;
  772. }
  773. else if(cell.parentNode.previousSibling != null){
  774. cell = cell.parentNode.previousSibling.lastChild;
  775. }
  776. else{
  777. cell = cell.parentNode.parentNode.rows[cell.offsetParent.rows.length - 1].lastChild;
  778. }
  779. }
  780. else{
  781. if(cell.nextSibling != null){
  782. cell = cell.nextSibling;
  783. }
  784. else if(cell.parentNode.nextSibling != null && cell.parentNode.nextSibling.nodeType == 1){
  785. cell = cell.parentNode.nextSibling.firstChild;
  786. }
  787. else{
  788. cell = cell.parentNode.parentNode.rows[0].firstChild;
  789. }
  790. }
  791. }
  792. if(isValidCell(cell))
  793. return cell;
  794. else
  795. return moveToNextCell2(cell);
  796. }
  797. //----------------------------------------------------------------------------------------------------
  798. // Gets the next cell that is valid cell.
  799. //----------------------------------------------------------------------------------------------------
  800. function moveToNextCell3(){
  801. if(navigator.appName.indexOf("Microsoft") == -1) {// Is not IE
  802. if(_oDirection.checked){ // Search up
  803. if(_currentCellIndex == 0){ // Is the first cell in the row.
  804. // The row move to next row and cellIndex is evaluated to the last cell index of next row.
  805. if(_currentRowIndex == 0){
  806. _currentRowIndex = _currentRowsLength - 1;
  807. }
  808. else{
  809. _currentRowIndex--;
  810. }
  811. _currentCells = _currentRows[_currentRowIndex].cells;
  812. _currentCellsLength = _currentCells.length;
  813. _currentCellIndex = _currentCellsLength -1;
  814. }
  815. else{ // Is not first cell in the row. Reduces cellIndex to 1 for move to next cell.
  816. _currentCellIndex--;
  817. }
  818. }
  819. else{ // Search down
  820. if(_currentCellIndex == _currentCellsLength -1){ // Is the last cell in the row.
  821. // The row move to next row and cellIndex is evaluated to the first cell index of next row.
  822. if(_currentRowIndex == _currentRowsLength - 1){
  823. _currentRowIndex = 0;
  824. }
  825. else{
  826. _currentRowIndex++;
  827. }
  828. _currentCells = _currentRows[_currentRowIndex].cells;
  829. _currentCellsLength = _currentCells.length;
  830. _currentCellIndex = 0;
  831. }
  832. else{ // Is not last cell in the row. Adds cellIndex to 1 for move to next cell.
  833. _currentCellIndex++;
  834. }
  835. }
  836. var cell = null;
  837. if(_currentRowsLength > 0 && _currentCellsLength > 0){
  838. cell = _currentCells[_currentCellIndex];
  839. }
  840. if(cell != null && isValidCell(cell))
  841. return cell;
  842. else
  843. return moveToNextCell3();
  844. }
  845. else{ //IE
  846. if(_oDirection.checked){ // Search up
  847. if(_cellIndex == 0){
  848. _cellIndex = _arrCells.length;
  849. }
  850. return _arrCells[--_cellIndex];
  851. }
  852. else{ // Search down
  853. if(_cellIndex == _arrCells.length - 1){
  854. _cellIndex = -1;
  855. }
  856. return _arrCells[++_cellIndex];
  857. }
  858. }
  859. }
  860. //----------------------------------------------------------------------------------------------------
  861. // Obsolete. Fills the cells to a array
  862. //----------------------------------------------------------------------------------------------------
  863. function FillCellsToArray(startCell){
  864. //var a = new Date();
  865. var k = 0;
  866. var i = 0;
  867. _arrCells[i] = startCell;
  868. _cellIndex = startCell.cellIndex;
  869. var rows = _viewTable.rows;
  870. var rowslen = rows.length;
  871. var i;
  872. for (i=0; i<rowslen; i++)
  873. {
  874. var cells = rows[i].cells;
  875. var cellslen = cells.length;
  876. var j;
  877. for (j=0; j< cellslen; j++)
  878. {
  879. var cell = cells[j];
  880. _arrCells[k++] = cell;
  881. }
  882. }
  883. //alert(getTimeDistance(a,new Date()));
  884. }
  885. //----------------------------------------------------------------------------------------------------
  886. // Get inner text of the specified object.
  887. //----------------------------------------------------------------------------------------------------
  888. function getInnerText(o){
  889. if(o.hasChildNodes()){
  890. var text = "";
  891. for(var i=0; i<o.childNodes.length; i++){
  892. if(o.childNodes[i].nodeType == 3){ // Is TEXT_NODE
  893. text += o.childNodes[i].nodeValue;
  894. }
  895. else{
  896. var childText = getInnerText(o.childNodes[i]);
  897. if(childText != null)
  898. text += childText;
  899. }
  900. }
  901. if(text != "")
  902. return text;
  903. else
  904. return null;
  905. }
  906. else
  907. return null;
  908. }
  909. //----------------------------------------------------------------------------------------------------
  910. // Gets the value of the specified attribute of the specified object.
  911. //----------------------------------------------------------------------------------------------------
  912. function getAttribute(o, name)
  913. {
  914. if (o.attributes[name] != null)
  915. return o.attributes[name].nodeValue;
  916. return null;
  917. }