A QCodo powered CMS
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.

69 lines
2.0 KiB

  1. /**
  2. * $Id: editable_selects.js 422 2008-12-12 18:28:35Z erikwinn $
  3. *
  4. * Makes select boxes editable.
  5. *
  6. * @author Moxiecode
  7. * @copyright Copyright 2004-2008, Moxiecode Systems AB, All rights reserved.
  8. */
  9. var TinyMCE_EditableSelects = {
  10. editSelectElm : null,
  11. init : function() {
  12. var nl = document.getElementsByTagName("select"), i, d = document, o;
  13. for (i=0; i<nl.length; i++) {
  14. if (nl[i].className.indexOf('mceEditableSelect') != -1) {
  15. o = new Option('(value)', '__mce_add_custom__');
  16. o.className = 'mceAddSelectValue';
  17. nl[i].options[nl[i].options.length] = o;
  18. nl[i].onchange = TinyMCE_EditableSelects.onChangeEditableSelect;
  19. }
  20. }
  21. },
  22. onChangeEditableSelect : function(e) {
  23. var d = document, ne, se = window.event ? window.event.srcElement : e.target;
  24. if (se.options[se.selectedIndex].value == '__mce_add_custom__') {
  25. ne = d.createElement("input");
  26. ne.id = se.id + "_custom";
  27. ne.name = se.name + "_custom";
  28. ne.type = "text";
  29. ne.style.width = se.offsetWidth + 'px';
  30. se.parentNode.insertBefore(ne, se);
  31. se.style.display = 'none';
  32. ne.focus();
  33. ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
  34. ne.onkeydown = TinyMCE_EditableSelects.onKeyDown;
  35. TinyMCE_EditableSelects.editSelectElm = se;
  36. }
  37. },
  38. onBlurEditableSelectInput : function() {
  39. var se = TinyMCE_EditableSelects.editSelectElm;
  40. if (se) {
  41. if (se.previousSibling.value != '') {
  42. addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);
  43. selectByValue(document.forms[0], se.id, se.previousSibling.value);
  44. } else
  45. selectByValue(document.forms[0], se.id, '');
  46. se.style.display = 'inline';
  47. se.parentNode.removeChild(se.previousSibling);
  48. TinyMCE_EditableSelects.editSelectElm = null;
  49. }
  50. },
  51. onKeyDown : function(e) {
  52. e = e || window.event;
  53. if (e.keyCode == 13)
  54. TinyMCE_EditableSelects.onBlurEditableSelectInput();
  55. }
  56. };