home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Plugins / tinymce-advanced / mce / xhtmlxtras / jscripts / attributes.js < prev    next >
Encoding:
JavaScript  |  2008-02-20  |  4.4 KB  |  130 lines

  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.  
  8. function preinit() {
  9.     // Initialize
  10.     tinyMCE.setWindowArg('mce_windowresize', false);
  11. }
  12.  
  13. function init() {
  14.     tinyMCEPopup.resizeToInnerSize();
  15.     var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
  16.     var elm = inst.getFocusElement();
  17.  
  18.     var f = document.forms[0];
  19.     
  20.     var onclick = tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onclick'));
  21.  
  22.     setFormValue('title', tinyMCE.getAttrib(elm, 'title'));
  23.     setFormValue('id', tinyMCE.getAttrib(elm, 'id'));
  24.     setFormValue('style', tinyMCE.serializeStyle(tinyMCE.parseStyle(tinyMCE.getAttrib(elm, "style"))));
  25.     setFormValue('dir', tinyMCE.getAttrib(elm, 'dir'));
  26.     setFormValue('lang', tinyMCE.getAttrib(elm, 'lang'));
  27.     setFormValue('tabindex', tinyMCE.getAttrib(elm, 'tabindex', typeof(elm.tabindex) != "undefined" ? elm.tabindex : ""));
  28.     setFormValue('accesskey', tinyMCE.getAttrib(elm, 'accesskey', typeof(elm.accesskey) != "undefined" ? elm.accesskey : ""));
  29.     setFormValue('onfocus', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onfocus')));
  30.     setFormValue('onblur', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onblur')));
  31.     setFormValue('onclick', onclick);
  32.     setFormValue('ondblclick', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'ondblclick')));
  33.     setFormValue('onmousedown', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmousedown')));
  34.     setFormValue('onmouseup', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseup')));
  35.     setFormValue('onmouseover', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseover')));
  36.     setFormValue('onmousemove', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmousemove')));
  37.     setFormValue('onmouseout', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onmouseout')));
  38.     setFormValue('onkeypress', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeypress')));
  39.     setFormValue('onkeydown', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeydown')));
  40.     setFormValue('onkeyup', tinyMCE.cleanupEventStr(tinyMCE.getAttrib(elm, 'onkeyup')));
  41.     
  42.     className = tinyMCE.getVisualAidClass(tinyMCE.getAttrib(elm, 'class'), false);
  43.         
  44.     addClassesToList('classlist', 'advlink_styles');
  45.     selectByValue(f, 'classlist', className, true);
  46.     
  47.     TinyMCE_EditableSelects.init();
  48. }
  49.  
  50. function setFormValue(name, value) {
  51.     if(value && document.forms[0].elements[name]){
  52.         document.forms[0].elements[name].value = value;
  53.     }
  54. }
  55.  
  56. function insertAction() {
  57.     var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
  58.     var elm = inst.getFocusElement();
  59.  
  60.     tinyMCEPopup.execCommand("mceBeginUndoLevel");    
  61.     tinyMCEPopup.restoreSelection();
  62.     
  63.     setAllAttribs(elm);
  64.     
  65.     tinyMCE.handleVisualAid(inst.getBody(), true, inst.visualAid, inst);
  66.     tinyMCE._setEventsEnabled(inst.getBody(), false);
  67.     tinyMCEPopup.execCommand("mceEndUndoLevel");
  68.     tinyMCEPopup.close();
  69. }
  70.  
  71. function setAttrib(elm, attrib, value) {
  72.     var formObj = document.forms[0];
  73.     var valueElm = formObj.elements[attrib.toLowerCase()];
  74.  
  75.     if (typeof(value) == "undefined" || value == null) {
  76.         value = "";
  77.  
  78.         if (valueElm)
  79.             value = valueElm.value;
  80.     }
  81.  
  82.     if (value != "") {
  83.         tinyMCE.setAttrib(elm, attrib.toLowerCase(), value);
  84.  
  85.         if (attrib == "style")
  86.             attrib = "style.cssText";
  87.  
  88.         if (attrib.substring(0, 2) == 'on')
  89.             value = 'return true;' + value;
  90.  
  91.         if (attrib == "class")
  92.             attrib = "className";
  93.  
  94.         eval('elm.' + attrib + "=value;");
  95.     } else
  96.         elm.removeAttribute(attrib);
  97. }
  98.  
  99. function setAllAttribs(elm) {
  100.     var f = document.forms[0];
  101.  
  102.     setAttrib(elm, 'title');
  103.     setAttrib(elm, 'id');
  104.     setAttrib(elm, 'style');
  105.     setAttrib(elm, 'class', getSelectValue(f, 'classlist'));
  106.     setAttrib(elm, 'dir');
  107.     setAttrib(elm, 'lang');
  108.     setAttrib(elm, 'tabindex');
  109.     setAttrib(elm, 'accesskey');
  110.     setAttrib(elm, 'onfocus');
  111.     setAttrib(elm, 'onblur');
  112.     setAttrib(elm, 'onclick');
  113.     setAttrib(elm, 'ondblclick');
  114.     setAttrib(elm, 'onmousedown');
  115.     setAttrib(elm, 'onmouseup');
  116.     setAttrib(elm, 'onmouseover');
  117.     setAttrib(elm, 'onmousemove');
  118.     setAttrib(elm, 'onmouseout');
  119.     setAttrib(elm, 'onkeypress');
  120.     setAttrib(elm, 'onkeydown');
  121.     setAttrib(elm, 'onkeyup');
  122.  
  123.     // Refresh in old MSIE
  124.     if (tinyMCE.isMSIE5)
  125.         elm.outerHTML = elm.outerHTML;
  126. }
  127.  
  128. function insertAttribute() {
  129.     tinyMCEPopup.close();
  130. }