| | 549 | |
| | 550 | /** Helper Function: add buttons/drop-downs boxes with title or separator to the toolbar |
| | 551 | * if the buttons/drop-downs boxes doesn't allready exists. |
| | 552 | * id: button or selectbox (as array with separator or title) |
| | 553 | * where: button or selectbox (as array if the first is not found take the second and so on) |
| | 554 | * position: |
| | 555 | * -1 = insert button (id) one position before the button (where) |
| | 556 | * 0 = replace button (where) by button (id) |
| | 557 | * +1 = insert button (id) one position after button (where) |
| | 558 | * |
| | 559 | * cfg.addToolbarElement(["T[title]", "button_id", "separator"] , ["first_id","second_id"], -1); |
| | 560 | */ |
| | 561 | |
| | 562 | HTMLArea.Config.prototype.addToolbarElement = function(id, where, position) { |
| | 563 | var toolbar = this.toolbar; |
| | 564 | var a, i, j, o, sid; |
| | 565 | var idIsArray = false; |
| | 566 | var whereIsArray = false; |
| | 567 | var whereLength = 0; |
| | 568 | var whereJ = 0; |
| | 569 | var whereI = 0; |
| | 570 | var exists = false; |
| | 571 | var found = false; |
| | 572 | // check if id and where are arrys |
| | 573 | if ((id && typeof id == "object") && (id.constructor == Array)) { |
| | 574 | idIsArray = true; |
| | 575 | } |
| | 576 | if ((where && typeof where == "object") && (where.constructor == Array)) { |
| | 577 | whereIsArray = true; |
| | 578 | whereLength = where.length; |
| | 579 | } |
| | 580 | |
| | 581 | if (idIsArray) { //find the button/select box in input array |
| | 582 | for (i = 0; i < id.length; ++i) { |
| | 583 | if ((id[i] != "separator") && (id[i].indexOf("T[") != 0)) { |
| | 584 | sid = id[i]; |
| | 585 | } |
| | 586 | } |
| | 587 | } else { |
| | 588 | sid = id; |
| | 589 | } |
| | 590 | |
| | 591 | for (var i = 0; !exists && !found && i < toolbar.length; ++i) { |
| | 592 | a = toolbar[i] |
| | 593 | for (j = 0; !found && j < a.length; ++j) { |
| | 594 | if (a[i] == sid) { // check if button/select box exists |
| | 595 | exists = true; |
| | 596 | break; |
| | 597 | } |
| | 598 | if (whereIsArray) { |
| | 599 | for (o = 0; o < whereLength; ++o) { |
| | 600 | if(a[j] == where[o]) { |
| | 601 | if (o == 0) { |
| | 602 | found = true; |
| | 603 | j--; |
| | 604 | break; |
| | 605 | } else { |
| | 606 | whereI = i; |
| | 607 | whereJ = j; |
| | 608 | whereLength = o; |
| | 609 | } |
| | 610 | } |
| | 611 | } |
| | 612 | } else { |
| | 613 | if (a[j] == where) { // find the position to insert |
| | 614 | found = true; |
| | 615 | break; |
| | 616 | } |
| | 617 | } |
| | 618 | } |
| | 619 | } |
| | 620 | |
| | 621 | if (!exists) { |
| | 622 | if (!found && whereIsArray) { //if check found any other as the first button |
| | 623 | if (where.length != whereLength) { |
| | 624 | j = whereJ; |
| | 625 | a = toolbar[whereI]; |
| | 626 | found = true; |
| | 627 | } |
| | 628 | } |
| | 629 | if (found) { |
| | 630 | if (position == 0) { // replace the found button |
| | 631 | if (idIsArray) { |
| | 632 | a[j] = id[id.length-1]; |
| | 633 | for (i = id.length-1; --i >= 0;) { |
| | 634 | a.splice(j, 0, id[i]); |
| | 635 | } |
| | 636 | } else { |
| | 637 | a[j] = id; |
| | 638 | } |
| | 639 | } else { // insert before/after the found button |
| | 640 | if (position < 0) { |
| | 641 | j = j + position + 1; //correct position before |
| | 642 | } else if (position > 0) { |
| | 643 | j = j + position; //correct posion after |
| | 644 | } |
| | 645 | if (idIsArray) { |
| | 646 | for (i = id.length; --i >= 0;) { |
| | 647 | a.splice(j, 0, id[i]); |
| | 648 | } |
| | 649 | } else { |
| | 650 | a.splice(j, 0, id); |
| | 651 | } |
| | 652 | } |
| | 653 | } else { // no button found |
| | 654 | toolbar[0].splice(0, 0, "separator"); |
| | 655 | if (idIsArray) { |
| | 656 | for (i = id.length; --i >= 0;) { |
| | 657 | toolbar[0].splice(0, 0, id[i]); |
| | 658 | } |
| | 659 | } else { |
| | 660 | toolbar[0].splice(0, 0, id); |
| | 661 | } |
| | 662 | } |
| | 663 | } |
| | 664 | } |