A tumblelog CMS built on AJAX, PHP and MySQL.

editable_selects.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * $Id: editable_selects.js 162 2007-01-03 16:16:52Z spocke $
  3. *
  4. * Makes select boxes editable.
  5. *
  6. * @author Moxiecode
  7. * @copyright Copyright © 2004-2007, 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].setAttribute('onchange', 'TinyMCE_EditableSelects.onChangeEditableSelect(this);');
  19. }
  20. }
  21. },
  22. onChangeEditableSelect : function(se) {
  23. var d = document, ne;
  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.clientWidth;
  30. se.parentNode.insertBefore(ne, se);
  31. se.style.display = 'none';
  32. ne.focus();
  33. ne.onblur = TinyMCE_EditableSelects.onBlurEditableSelectInput;
  34. TinyMCE_EditableSelects.editSelectElm = se;
  35. }
  36. },
  37. onBlurEditableSelectInput : function() {
  38. var se = TinyMCE_EditableSelects.editSelectElm;
  39. if (se) {
  40. if (se.previousSibling.value != '') {
  41. addSelectValue(document.forms[0], se.id, se.previousSibling.value, se.previousSibling.value);
  42. selectByValue(document.forms[0], se.id, se.previousSibling.value);
  43. } else
  44. selectByValue(document.forms[0], se.id, '');
  45. se.style.display = 'inline';
  46. se.parentNode.removeChild(se.previousSibling);
  47. TinyMCE_EditableSelects.editSelectElm = null;
  48. }
  49. }
  50. };