PageRenderTime 32ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/static/scripts/tiny_mce/plugins/xhtmlxtras/js/attributes.js

http://n23.googlecode.com/
JavaScript | 123 lines | 94 code | 20 blank | 9 comment | 17 complexity | 569867435dbb6d34877ec48095565983 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
  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 init() {
  8. tinyMCEPopup.resizeToInnerSize();
  9. var inst = tinyMCEPopup.editor;
  10. var dom = inst.dom;
  11. var elm = inst.selection.getNode();
  12. var f = document.forms[0];
  13. var onclick = dom.getAttrib(elm, 'onclick');
  14. setFormValue('title', dom.getAttrib(elm, 'title'));
  15. setFormValue('id', dom.getAttrib(elm, 'id'));
  16. setFormValue('style', dom.getAttrib(elm, "style"));
  17. setFormValue('dir', dom.getAttrib(elm, 'dir'));
  18. setFormValue('lang', dom.getAttrib(elm, 'lang'));
  19. setFormValue('tabindex', dom.getAttrib(elm, 'tabindex', typeof(elm.tabindex) != "undefined" ? elm.tabindex : ""));
  20. setFormValue('accesskey', dom.getAttrib(elm, 'accesskey', typeof(elm.accesskey) != "undefined" ? elm.accesskey : ""));
  21. setFormValue('onfocus', dom.getAttrib(elm, 'onfocus'));
  22. setFormValue('onblur', dom.getAttrib(elm, 'onblur'));
  23. setFormValue('onclick', onclick);
  24. setFormValue('ondblclick', dom.getAttrib(elm, 'ondblclick'));
  25. setFormValue('onmousedown', dom.getAttrib(elm, 'onmousedown'));
  26. setFormValue('onmouseup', dom.getAttrib(elm, 'onmouseup'));
  27. setFormValue('onmouseover', dom.getAttrib(elm, 'onmouseover'));
  28. setFormValue('onmousemove', dom.getAttrib(elm, 'onmousemove'));
  29. setFormValue('onmouseout', dom.getAttrib(elm, 'onmouseout'));
  30. setFormValue('onkeypress', dom.getAttrib(elm, 'onkeypress'));
  31. setFormValue('onkeydown', dom.getAttrib(elm, 'onkeydown'));
  32. setFormValue('onkeyup', dom.getAttrib(elm, 'onkeyup'));
  33. className = dom.getAttrib(elm, 'class');
  34. addClassesToList('classlist', 'advlink_styles');
  35. selectByValue(f, 'classlist', className, true);
  36. TinyMCE_EditableSelects.init();
  37. }
  38. function setFormValue(name, value) {
  39. if(value && document.forms[0].elements[name]){
  40. document.forms[0].elements[name].value = value;
  41. }
  42. }
  43. function insertAction() {
  44. var inst = tinyMCEPopup.editor;
  45. var elm = inst.selection.getNode();
  46. tinyMCEPopup.execCommand("mceBeginUndoLevel");
  47. setAllAttribs(elm);
  48. tinyMCEPopup.execCommand("mceEndUndoLevel");
  49. tinyMCEPopup.close();
  50. }
  51. function setAttrib(elm, attrib, value) {
  52. var formObj = document.forms[0];
  53. var valueElm = formObj.elements[attrib.toLowerCase()];
  54. var inst = tinyMCEPopup.editor;
  55. var dom = inst.dom;
  56. if (typeof(value) == "undefined" || value == null) {
  57. value = "";
  58. if (valueElm)
  59. value = valueElm.value;
  60. }
  61. if (value != "") {
  62. dom.setAttrib(elm, attrib.toLowerCase(), value);
  63. if (attrib == "style")
  64. attrib = "style.cssText";
  65. if (attrib.substring(0, 2) == 'on')
  66. value = 'return true;' + value;
  67. if (attrib == "class")
  68. attrib = "className";
  69. elm[attrib]=value;
  70. } else
  71. elm.removeAttribute(attrib);
  72. }
  73. function setAllAttribs(elm) {
  74. var f = document.forms[0];
  75. setAttrib(elm, 'title');
  76. setAttrib(elm, 'id');
  77. setAttrib(elm, 'style');
  78. setAttrib(elm, 'class', getSelectValue(f, 'classlist'));
  79. setAttrib(elm, 'dir');
  80. setAttrib(elm, 'lang');
  81. setAttrib(elm, 'tabindex');
  82. setAttrib(elm, 'accesskey');
  83. setAttrib(elm, 'onfocus');
  84. setAttrib(elm, 'onblur');
  85. setAttrib(elm, 'onclick');
  86. setAttrib(elm, 'ondblclick');
  87. setAttrib(elm, 'onmousedown');
  88. setAttrib(elm, 'onmouseup');
  89. setAttrib(elm, 'onmouseover');
  90. setAttrib(elm, 'onmousemove');
  91. setAttrib(elm, 'onmouseout');
  92. setAttrib(elm, 'onkeypress');
  93. setAttrib(elm, 'onkeydown');
  94. setAttrib(elm, 'onkeyup');
  95. // Refresh in old MSIE
  96. // if (tinyMCE.isMSIE5)
  97. // elm.outerHTML = elm.outerHTML;
  98. }
  99. function insertAttribute() {
  100. tinyMCEPopup.close();
  101. }
  102. tinyMCEPopup.onInit.add(init);
  103. tinyMCEPopup.requireLangPack();