TestDomAbstraction.html"

This website contains links to software which is either no longer maintained or will be supported only until the end of 2019 (CKFinder 2). For the latest documentation about current CKSource projects, including software like CKEditor 4/CKEditor 5, CKFinder 3, Cloud Services, Letters, Accessibility Checker, please visit the new documentation website.

If you look for an information about very old versions of CKEditor, FCKeditor and CKFinder check also the CKEditor forum, which was closed in 2015. If not, please head to StackOverflow for support.

(New page: Test)
 
 
Line 1: Line 1:
Test
+
== Script Block ==
 +
 
 +
<pre>
 +
window.onload = function()
 +
{
 +
var repetitions = 1000 ;
 +
 
 +
var t = new Date() ;
 +
 +
for ( var i = 0 ; i &lt; repetitions ; i++ )
 +
PureDom() ;
 +
 +
t = ( ( new Date ) - t ) ;
 +
 +
var html = '&lt;p&gt;Pure DOM: ' + t + ' ms.&lt;/p&gt;' ;
 +
 
 +
t = new Date() ;
 +
 +
for ( var i = 0 ; i &lt; repetitions ; i++ )
 +
DomAbstraction() ;
 +
 +
t = ( ( new Date ) - t ) ;
 +
 +
html += '&lt;p&gt;DOM Abstraction: ' + t + ' ms.&lt;/p&gt;' ;
 +
 
 +
document.body.innerHTML = html ;
 +
}
 +
 
 +
function PureDom()
 +
{
 +
var p = ( document.parentWindow || document.defaultView ).document.body.firstChild ;
 +
// var p = document.body.firstChild ;
 +
 +
var current = p.firstChild ;
 +
 +
var name ;
 +
while ( current )
 +
{
 +
if ( current.nodeType == 1 )
 +
{
 +
name = current.nodeName.toLowerCase() ;
 +
name = current.ownerDocument.body.firstChild.nodeName.toLowerCase() ;
 +
}
 +
else if ( current.nodeType == 3 )
 +
name = current.nodeValue ;
 +
 
 +
current = current.nextSibling ;
 +
}
 +
}
 +
 
 +
function DomAbstraction()
 +
{
 +
var p = (new DOM.Document(document)).getWindow().getDocument().getBody().getFirst() ;
 +
// var p = new DOM.Element(document.body.firstChild) ;
 +
 +
var current = p.getFirst() ;
 +
 +
var name ;
 +
while ( current )
 +
{
 +
if ( current.isElement )
 +
{
 +
name = current.getName() ;
 +
name = current.getDocument().getBody().getFirst().getName() ;
 +
}
 +
else if ( current.isText )
 +
name = current.getText() ;
 +
 
 +
current = current.getNext() ;
 +
}
 +
}
 +
 
 +
var DOM =
 +
{
 +
Window : (function()
 +
{
 +
var classImpl = function( domWindow )
 +
{
 +
this._W = domWindow ;
 +
}
 +
 +
classImpl.prototype =
 +
{
 +
getDocument : function()
 +
{
 +
return this._document || ( this._document = new DOM.Document( this._W.document ) ) ;
 +
}
 +
}
 +
 
 +
return classImpl ;
 +
})(),
 +
 
 +
Document : (function()
 +
{
 +
var classImpl = function( domDocument )
 +
{
 +
this._D = domDocument ;
 +
}
 +
 +
classImpl.prototype =
 +
{
 +
getWindow : function()
 +
{
 +
return this._window || ( this._window = new DOM.Window( this._D.parentWindow || this._D.defaultView ) ) ;
 +
},
 +
 
 +
getBody : function()
 +
{
 +
return this._body || ( this._body = new DOM.Element( this._D.body ) ) ;
 +
}
 +
}
 +
 
 +
return classImpl ;
 +
})(),
 +
 +
Element : (function()
 +
{
 +
var classImpl = function( domElement )
 +
{
 +
this._E = domElement ;
 +
}
 +
 +
classImpl.prototype =
 +
{
 +
isElement : true,
 +
 +
getDocument : function()
 +
{
 +
return this._document || ( this._document = new DOM.Document( this._E.ownerDocument ) ) ;
 +
},
 +
 
 +
getFirst : function()
 +
{
 +
return DOM.getNode( this._E.firstChild ) ;
 +
},
 +
 
 +
getNext : function()
 +
{
 +
return DOM.getNode( this._E.nextSibling ) ;
 +
},
 +
 
 +
getName : function()
 +
{
 +
return this._name || ( this._name = this._E.nodeName.toLowerCase() ) ;
 +
}
 +
}
 +
 
 +
return classImpl ;
 +
})(),
 +
 
 +
Text : (function()
 +
{
 +
var classImpl = function( domTextNode )
 +
{
 +
this._T = domTextNode ;
 +
}
 +
 +
classImpl.prototype =
 +
{
 +
isText : true,
 +
 
 +
getNext : function()
 +
{
 +
return DOM.getNode( this._T.nextSibling ) ;
 +
},
 +
 
 +
getText : function()
 +
{
 +
return this._T.nodeValue ;
 +
}
 +
}
 +
 
 +
return classImpl ;
 +
})(),
 +
 +
getNode : function( domNode )
 +
{
 +
if ( domNode )
 +
{
 +
if ( domNode.nodeType == 1 )
 +
return new DOM.Element( domNode ) ;
 +
else
 +
return new DOM.Text( domNode ) ;
 +
}
 +
 +
return null ;
 +
}
 +
}
 +
</pre>
 +
 
 +
== Body Contents ==
 +
 
 +
<pre>
 +
&lt;body&gt;&lt;p&gt;This is &lt;b&gt;some&lt;/b&gt; sample &lt;i&gt;text&lt;/i&gt;.&lt;/p&gt;&lt;/body&gt;
 +
</pre>

Latest revision as of 13:31, 20 February 2008

Script Block

window.onload = function()
{
	var repetitions = 1000 ;

	var t = new Date() ;
	
	for ( var i = 0 ; i < repetitions ; i++ )
		PureDom() ;
	
	t = ( ( new Date ) - t ) ;
	
	var html = '<p>Pure DOM: ' + t + ' ms.</p>' ;

	t = new Date() ;
	
	for ( var i = 0 ; i < repetitions ; i++ )
		DomAbstraction() ;
	
	t = ( ( new Date ) - t ) ;
	
	html += '<p>DOM Abstraction: ' + t + ' ms.</p>' ;

	document.body.innerHTML = html ;
}

function PureDom()
{
	var p = ( document.parentWindow || document.defaultView ).document.body.firstChild ;
//	var p = document.body.firstChild ;
	
	var current = p.firstChild ;
	
	var name ;
	while ( current )
	{
		if ( current.nodeType == 1 )
		{
			name = current.nodeName.toLowerCase() ;
			name = current.ownerDocument.body.firstChild.nodeName.toLowerCase() ;
		}
		else if ( current.nodeType == 3 )
			name = current.nodeValue ;

		current = current.nextSibling ;
	}		
}

function DomAbstraction()
{
	var p = (new DOM.Document(document)).getWindow().getDocument().getBody().getFirst() ;
//	var p = new DOM.Element(document.body.firstChild) ;
	
	var current = p.getFirst() ;
	
	var name ;
	while ( current )
	{
		if ( current.isElement )
		{
			name = current.getName() ;
			name = current.getDocument().getBody().getFirst().getName() ;
		}
		else if ( current.isText )
			name = current.getText() ;

		current = current.getNext() ;
	}		
}

var DOM =
{
	Window : (function()
	{
		var classImpl = function( domWindow )
		{
			this._W = domWindow ;
		}
		
		classImpl.prototype =
		{
			getDocument : function()
			{
				return this._document || ( this._document = new DOM.Document( this._W.document ) ) ;
			}
		}

		return classImpl ;
	})(),

	Document : (function()
	{
		var classImpl = function( domDocument )
		{
			this._D = domDocument ;
		}
		
		classImpl.prototype =
		{
			getWindow : function()
			{
				return this._window || ( this._window = new DOM.Window( this._D.parentWindow || this._D.defaultView ) ) ;
			},

			getBody : function()
			{
				return this._body || ( this._body = new DOM.Element( this._D.body ) ) ;
			}
		}

		return classImpl ;
	})(),
	
	Element : (function()
	{
		var classImpl = function( domElement )
		{
			this._E = domElement ;
		}
		
		classImpl.prototype =
		{
			isElement : true,
			
			getDocument : function()
			{
				return this._document || ( this._document = new DOM.Document( this._E.ownerDocument ) ) ;
			},

			getFirst : function()
			{
				return DOM.getNode( this._E.firstChild ) ;
			},

			getNext : function()
			{
				return DOM.getNode( this._E.nextSibling ) ;
			},

			getName : function()
			{
				return this._name || ( this._name = this._E.nodeName.toLowerCase() ) ;
			}
		}

		return classImpl ;
	})(),

	Text : (function()
	{
		var classImpl = function( domTextNode )
		{
			this._T = domTextNode ;
		}
		
		classImpl.prototype =
		{
			isText : true,

			getNext : function()
			{
				return DOM.getNode( this._T.nextSibling ) ;
			},

			getText : function()
			{
				return this._T.nodeValue ;
			}
		}

		return classImpl ;
	})(),
	
	getNode : function( domNode )
	{
		if ( domNode )
		{		
			if ( domNode.nodeType == 1 )
				return new DOM.Element( domNode ) ;
			else
				return new DOM.Text( domNode ) ;
		}
		
		return null ;
	}
}

Body Contents

<body><p>This is <b>some</b> sample <i>text</i>.</p></body>
This page was last edited on 20 February 2008, at 13:31.