⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 overview-summary-tinymce_domutils.class.js.html

📁 tinyMCE在线编辑器使用手册
💻 HTML
📖 第 1 页 / 共 2 页
字号:
 *
 * <span class="attrib">@param</span> {HTMLNode} n Node to get children from.
 * <span class="attrib">@param</span> {Array} na Array to fill with children.
 * <span class="attrib">@param</span> {int} t Node type to get.
 * <span class="attrib">@param</span> {string} nn Node name of items to retrive.
 * <span class="attrib">@return</span> Node array.
 * <span class="attrib">@type</span> Array
 */</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.getNodeTree = <span class="reserved">function</span>(n, na, t, nn) {
	var i;

	<span class="reserved">if</span> (typeof(t) == <span class="literal">"undefined"</span> || n.nodeType == t &amp;&amp; (typeof(nn) == <span class="literal">"undefined"</span> || n.nodeName == nn))
		na[na.length] = n;

	<span class="reserved">if</span> (n.hasChildNodes()) {
		<span class="reserved">for</span> (i=0; i&lt;n.childNodes.length; i++)
			tinyMCE.getNodeTree(n.childNodes[i], na, t, nn);
	}

	<span class="reserved">return</span> na;
};

<span class="comment">/**
 * Returns the parent element of the specified node based on the search criteria.
 *
 * <span class="attrib">@param</span> {HTMLNode} node Node to get parent element of.
 * <span class="attrib">@param</span> {string} names Comma separated list of element names to get.
 * <span class="attrib">@param</span> {string} attrib_name Optional attribute name to match.
 * <span class="attrib">@param</span> {string} attrib_value Optional attribute value to match.
 * <span class="attrib">@return</span> HTMLElement or null based on search criteras.
 * <span class="attrib">@type</span> HTMLElement
 */</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.getParentElement = <span class="reserved">function</span>(node, names, attrib_name, attrib_value) {
	<span class="reserved">if</span> (typeof(names) == <span class="literal">"undefined"</span>) {
		<span class="reserved">if</span> (node.nodeType == 1)
			<span class="reserved">return</span> node;

		<span class="comment">// Find parent node that is a element</span>
		<span class="reserved">while</span> ((node = node.parentNode) != null &amp;&amp; node.nodeType != 1) ;

		<span class="reserved">return</span> node;
	}

	<span class="reserved">if</span> (node == null)
		<span class="reserved">return</span> null;

	var namesAr = names.toUpperCase().split(<span class="literal">','</span>);

	do {
		<span class="reserved">for</span> (var i=0; i&lt;namesAr.length; i++) {
			<span class="reserved">if</span> (node.nodeName == namesAr[i] || names == <span class="literal">"*"</span>) {
				<span class="reserved">if</span> (typeof(attrib_name) == <span class="literal">"undefined"</span>)
					<span class="reserved">return</span> node;
				<span class="reserved">else</span> <span class="reserved">if</span> (node.getAttribute(attrib_name)) {
					<span class="reserved">if</span> (typeof(attrib_value) == <span class="literal">"undefined"</span>) {
						<span class="reserved">if</span> (node.getAttribute(attrib_name) != <span class="literal">""</span>)
							<span class="reserved">return</span> node;
					} <span class="reserved">else</span> <span class="reserved">if</span> (node.getAttribute(attrib_name) == attrib_value)
						<span class="reserved">return</span> node;
				}
			}
		}
	} <span class="reserved">while</span> ((node = node.parentNode) != null);

	<span class="reserved">return</span> null;
};

<span class="comment">/**
 * Returns the attribute value of a element or the default value if it wasn't found.
 *
 * <span class="attrib">@param</span> {HTMLElement} elm HTML element to get attribute from.
 * <span class="attrib">@param</span> {string} name Attribute name to retrive.
 * <span class="attrib">@param</span> {string} default_value Optional default value to return, this value defaults to a empty string.
 * <span class="attrib">@return</span> Attribute value or default value if it wasn't found in element.
 * <span class="attrib">@type</span> string
 */</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.getAttrib = <span class="reserved">function</span>(elm, name, default_value) {
	<span class="reserved">if</span> (typeof(default_value) == <span class="literal">"undefined"</span>)
		default_value = <span class="literal">""</span>;

	<span class="comment">// Not a element</span>
	<span class="reserved">if</span> (!elm || elm.nodeType != 1)
		<span class="reserved">return</span> default_value;

	var v = elm.getAttribute(name);

	<span class="comment">// Try className for class attrib</span>
	<span class="reserved">if</span> (name == <span class="literal">"class"</span> &amp;&amp; !v)
		v = elm.className;

	<span class="comment">// Workaround for a issue with Firefox 1.5rc2+</span>
	<span class="reserved">if</span> (tinyMCE.isGecko &amp;&amp; name == <span class="literal">"src"</span> &amp;&amp; elm.src != null &amp;&amp; elm.src != <span class="literal">""</span>)
		v = elm.src;

	<span class="comment">// Workaround for a issue with Firefox 1.5rc2+</span>
	<span class="reserved">if</span> (tinyMCE.isGecko &amp;&amp; name == <span class="literal">"href"</span> &amp;&amp; elm.href != null &amp;&amp; elm.href != <span class="literal">""</span>)
		v = elm.href;

	<span class="reserved">if</span> (name == <span class="literal">"http-equiv"</span> &amp;&amp; tinyMCE.isMSIE)
		v = elm.httpEquiv;

	<span class="reserved">if</span> (name == <span class="literal">"style"</span> &amp;&amp; !tinyMCE.isOpera)
		v = elm.style.cssText;

	<span class="reserved">return</span> (v &amp;&amp; v != <span class="literal">""</span>) ? v : default_value;
};

<span class="comment">/**
 * Sets the attribute value for a specific attribute.
 *
 * <span class="attrib">@param</span> {HTMLElement} element HTML element to set attribute on.
 * <span class="attrib">@param</span> {string} name Attribute name to set.
 * <span class="attrib">@param</span> {string} value Attribute value to set.
 * <span class="attrib">@param</span> {boolean} fix_value Optional fix value state, if true only number data will be accepted.
 */</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.setAttrib = <span class="reserved">function</span>(element, name, value, fix_value) {
	<span class="reserved">if</span> (typeof(value) == <span class="literal">"number"</span> &amp;&amp; value != null)
		value = <span class="literal">""</span> + value;

	<span class="reserved">if</span> (fix_value) {
		<span class="reserved">if</span> (value == null)
			value = <span class="literal">""</span>;

		var re = new RegExp(<span class="literal">'[^0-9%]'</span>, <span class="literal">'g'</span>);
		value = value.replace(re, <span class="literal">''</span>);
	}

	<span class="reserved">if</span> (name == <span class="literal">"style"</span>)
		element.style.cssText = value;

	<span class="reserved">if</span> (name == <span class="literal">"class"</span>)
		element.className = value;

	<span class="reserved">if</span> (value != null &amp;&amp; value != <span class="literal">""</span> &amp;&amp; value != -1)
		element.setAttribute(name, value);
	<span class="reserved">else</span>
		element.removeAttribute(name);
};

<span class="comment">/**
 * Sets a style attribute item value.
 *
 * <span class="attrib">@param</span> {HTMLElement} elm HTML element to set style attribute item on.
 * <span class="attrib">@param</span> {string} name Style item name to set.
 * <span class="attrib">@param</span> {string} value Style item value to set.
 */</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.setStyleAttrib = <span class="reserved">function</span>(elm, name, value) {
	eval(<span class="literal">'elm.style.'</span> + name + <span class="literal">'=value;'</span>);

	<span class="comment">// Style attrib deleted</span>
	<span class="reserved">if</span> (tinyMCE.isMSIE &amp;&amp; value == null || value == <span class="literal">''</span>) {
		var str = tinyMCE.serializeStyle(tinyMCE.parseStyle(elm.style.cssText));
		elm.style.cssText = str;
		elm.setAttribute(<span class="literal">"style"</span>, str);
	}
};

<span class="comment">/**
 * Switches the CSS class of the specified element. This method also caches the
 * elements in a lookup table for performance. This should only be used for TinyMCE main UI controls
 * like buttons or select elements.
 *
 * <span class="attrib">@param</span> {HTMLElement} ei Element to set CSS class on.
 * <span class="attrib">@param</span> {string} c CSS class to set.
 */</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.switchClass = <span class="reserved">function</span>(ei, c) {
	var e;

	<span class="reserved">if</span> (tinyMCE.switchClassCache[ei])
		e = tinyMCE.switchClassCache[ei];
	<span class="reserved">else</span>
		e = tinyMCE.switchClassCache[ei] = document.getElementById(ei);

	<span class="reserved">if</span> (e) {
		<span class="comment">// Keep tile mode</span>
		<span class="reserved">if</span> (tinyMCE.settings.button_tile_map &amp;&amp; e.className &amp;&amp; e.className.indexOf(<span class="literal">'mceTiledButton'</span>) == 0)
			c = <span class="literal">'mceTiledButton '</span> + c;

		e.className = c;
	}
};

<span class="comment">/**
 * Returns the absolute x, y position of a node. The position will be returned in a object with
 * two properties absLeft and absTop.
 *
 * <span class="attrib">@param</span> {HTMLNode} n HTML element to get x, y position from.
 * <span class="attrib">@return</span> Absolute position of the specified element.
 * <span class="attrib">@type</span> TinyMCE_ElementPosition
 */</span>
TinyMCE_Engine.<span class="reserved">prototype</span>.getAbsPosition = <span class="reserved">function</span>(n) {
	var p = {absLeft : 0, absTop : 0};

	<span class="reserved">while</span> (n) {
		p.absLeft += n.offsetLeft;
		p.absTop += n.offsetTop;
		n = n.offsetParent;
	}

	<span class="reserved">return</span> p;
};
</pre>
	<hr>



<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> <font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top"><em>
<b></b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<font size="-1">

</font>
<div class="jsdoc_ctime">Documentation generated by <a href="http://jsdoc.sourceforge.net/" target="_parent">JSDoc</a> on Mon Feb 13 16:28:04 2006</div>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -