A tumblelog CMS built on AJAX, PHP and MySQL.

attributes.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /**
  2. * $Id: editor_plugin_src.js 42 2006-08-08 14:32:24Z spocke $
  3. *
  4. * @author Moxiecode - based on work by Andrew Tetlaw
  5. * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
  6. */
  7. function preinit() {
  8. // Initialize
  9. tinyMCE.setWindowArg('mce_windowresize', false);
  10. }
  11. function init() {
  12. tinyMCEPopup.resizeToInnerSize();
  13. var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
  14. var elm = inst.getFocusElement();
  15. var f = document.forms[0];
  16. var onclick = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onclick'));
  17. setFormValue('title', tinyMCE.getAttrib(elm, 'title'));
  18. setFormValue('id', tinyMCE.getAttrib(elm, 'id'));
  19. setFormValue('style', tinyMCE.serializeStyle(tinyMCE.parseStyle(tinyMCE.getAttrib(elm, "style"))));
  20. setFormValue('dir', tinyMCE.getAttrib(elm, 'dir'));
  21. setFormValue('lang', tinyMCE.getAttrib(elm, 'lang'));
  22. setFormValue('tabindex', tinyMCE.getAttrib(elm, 'tabindex', typeof(elm.tabindex) != "undefined" ? elm.tabindex : ""));
  23. setFormValue('accesskey', tinyMCE.getAttrib(elm, 'accesskey', typeof(elm.accesskey) != "undefined" ? elm.accesskey : ""));
  24. setFormValue('onfocus', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onfocus')));
  25. setFormValue('onblur', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onblur')));
  26. setFormValue('onclick', onclick);
  27. setFormValue('ondblclick', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'ondblclick')));
  28. setFormValue('onmousedown', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmousedown')));
  29. setFormValue('onmouseup', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseup')));
  30. setFormValue('onmouseover', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseover')));
  31. setFormValue('onmousemove', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmousemove')));
  32. setFormValue('onmouseout', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseout')));
  33. setFormValue('onkeypress', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeypress')));
  34. setFormValue('onkeydown', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeydown')));
  35. setFormValue('onkeyup', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeyup')));
  36. className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(elm, 'class'), false);
  37. addClassesToList('classlist', 'advlink_styles');
  38. selectByValue(f, 'classlist', className, true);
  39. TinyMCE_EditableSelects.init();
  40. }
  41. function setFormValue(name, value) {
  42. if(value && document.forms[0].elements[name]){
  43. document.forms[0].elements[name].value = value;
  44. }
  45. }
  46. function insertAction() {
  47. var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
  48. var elm = inst.getFocusElement();
  49. tinyMCEPopup.execCommand("mceBeginUndoLevel");
  50. tinyMCEPopup.restoreSelection();
  51. setAllAttribs(elm);
  52. tinyMCE.handleVisualAid(inst.getBody(), true, inst.visualAid, inst);
  53. tinyMCE._setEventsEnabled(inst.getBody(), false);
  54. tinyMCEPopup.execCommand("mceEndUndoLevel");
  55. tinyMCEPopup.close();
  56. }
  57. function setAttrib(elm, attrib, value) {
  58. var formObj = document.forms[0];
  59. var valueElm = formObj.elements[attrib.toLowerCase()];
  60. if (typeof(value) == "undefined" || value == null) {
  61. value = "";
  62. if (valueElm)
  63. value = valueElm.value;
  64. }
  65. if (value != "") {
  66. tinyMCE.setAttrib(elm, attrib.toLowerCase(), value);
  67. if (attrib == "style")
  68. attrib = "style.cssText";
  69. if (attrib.substring(0, 2) == 'on')
  70. value = 'return true;' + value;
  71. if (attrib == "class")
  72. attrib = "className";
  73. eval('elm.' + attrib + "=value;");
  74. } else
  75. elm.removeAttribute(attrib);
  76. }
  77. function setAllAttribs(elm) {
  78. var f = document.forms[0];
  79. setAttrib(elm, 'title');
  80. setAttrib(elm, 'id');
  81. setAttrib(elm, 'style');
  82. setAttrib(elm, 'class', getSelectValue(f, 'classlist'));
  83. setAttrib(elm, 'dir');
  84. setAttrib(elm, 'lang');
  85. setAttrib(elm, 'tabindex');
  86. setAttrib(elm, 'accesskey');
  87. setAttrib(elm, 'onfocus');
  88. setAttrib(elm, 'onblur');
  89. setAttrib(elm, 'onclick');
  90. setAttrib(elm, 'ondblclick');
  91. setAttrib(elm, 'onmousedown');
  92. setAttrib(elm, 'onmouseup');
  93. setAttrib(elm, 'onmouseover');
  94. setAttrib(elm, 'onmousemove');
  95. setAttrib(elm, 'onmouseout');
  96. setAttrib(elm, 'onkeypress');
  97. setAttrib(elm, 'onkeydown');
  98. setAttrib(elm, 'onkeyup');
  99. // Refresh in old MSIE
  100. if (tinyMCE.isMSIE5)
  101. elm.outerHTML = elm.outerHTML;
  102. }
  103. function insertAttribute() {
  104. tinyMCEPopup.close();
  105. }