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