<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8143334756111340695</id><updated>2011-07-29T02:44:41.229-07:00</updated><title type='text'>Passion for web</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://victorharris.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://victorharris.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Victor</name><uri>http://www.blogger.com/profile/12416490940708538797</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>7</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8143334756111340695.post-8707041647084529461</id><published>2007-06-27T16:20:00.001-07:00</published><updated>2007-06-27T16:20:38.080-07:00</updated><title type='text'>bored with something to array convertion ? map them !</title><content type='html'>I'm rewriting my JSL to include by default inside my next project.&lt;br /&gt;This project will include automatically a lot of standard JS 1.5 methods or functions, and Array.map is one of those.&lt;br /&gt;&lt;br /&gt;While I'm testing some proto performances, I've thought about a really simple way to switch from an array or from a node list (getElementsByTagName) with a simple, fast and single line of function.&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshcomments"&gt;// old example version&lt;br /&gt;&lt;/span&gt;&lt;span class="jshcomments"&gt;// function _A(a){return [].map.call(a,function(a){return a})};&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// new version, Daniel suggest, faster and doesn't require any prototype !&lt;br /&gt;&lt;/span&gt;&lt;span class="jshglobals"&gt;function&lt;/span&gt; _A(a){&lt;span class="jshglobals"&gt;return&lt;/span&gt; [].&lt;span class="jshmethods"&gt;slice&lt;/span&gt;.&lt;span class="jshmethods"&gt;call&lt;/span&gt;(a)};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;and that's all, do You like it ?&lt;br /&gt;&lt;br /&gt;As first point, You need FireFox 1 or greater (or Mozilla if You prefere) or this short piece of code:&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshglobals"&gt;if&lt;/span&gt;(&lt;span class="jshoperators"&gt;!&lt;/span&gt;&lt;span class="jshglobals"&gt;Array&lt;/span&gt;.&lt;span class="jshproperties"&gt;prototype&lt;/span&gt;.&lt;span class="jshmethods"&gt;map&lt;/span&gt;) &lt;span class="jshglobals"&gt;Array&lt;/span&gt;.&lt;span class="jshproperties"&gt;prototype&lt;/span&gt;.&lt;span class="jshmethods"&gt;map&lt;/span&gt; &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt;(callback){&lt;br /&gt;&lt;span class="jshglobals"&gt;for&lt;/span&gt;(&lt;span class="jshglobals"&gt;var&lt;/span&gt; i &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshnumbers"&gt;0&lt;/span&gt;, j &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;this&lt;/span&gt;.&lt;span class="jshproperties"&gt;length&lt;/span&gt;, result &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;new&lt;/span&gt; &lt;span class="jshglobals"&gt;Array&lt;/span&gt;(j), self &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshproperties"&gt;arguments&lt;/span&gt;[&lt;span class="jshnumbers"&gt;1&lt;/span&gt;], u; i &lt; class="jshoperators"&gt;++&lt;/span&gt;) {&lt;br /&gt; &lt;span class="jshglobals"&gt;if&lt;/span&gt;(&lt;span class="jshglobals"&gt;this&lt;/span&gt;[i] &lt;span class="jshoperators"&gt;!==&lt;/span&gt; u)&lt;br /&gt;  result[i] &lt;span class="jshoperators"&gt;=&lt;/span&gt; callback.&lt;span class="jshmethods"&gt;call&lt;/span&gt;(self, &lt;span class="jshglobals"&gt;this&lt;/span&gt;[i], i, &lt;span class="jshglobals"&gt;this&lt;/span&gt;);&lt;br /&gt;};&lt;br /&gt;&lt;span class="jshglobals"&gt;return&lt;/span&gt; result;&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Then You have "everything You need" to get quickly every iterable element.&lt;br /&gt;&lt;br /&gt;These are just two examples&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshglobals"&gt;function&lt;/span&gt; &lt;span class="jshmethods"&gt;sort&lt;/span&gt;(){&lt;br /&gt;&lt;span class="jshglobals"&gt;return&lt;/span&gt; _A(&lt;span class="jshproperties"&gt;arguments&lt;/span&gt;).&lt;span class="jshmethods"&gt;sort&lt;/span&gt;().&lt;span class="jshmethods"&gt;join&lt;/span&gt;(&lt;span class="jshstrings"&gt;"&lt;br /&gt;"&lt;/span&gt;);&lt;br /&gt;};&lt;br /&gt;document.writeln(&lt;span class="jshmethods"&gt;sort&lt;/span&gt;(&lt;span class="jshstrings"&gt;"Luke"&lt;/span&gt;, &lt;span class="jshstrings"&gt;"Jabba"&lt;/span&gt;, &lt;span class="jshstrings"&gt;"Fenner"&lt;/span&gt;));&lt;br /&gt;document.writeln(&lt;span class="jshmethods"&gt;sort&lt;/span&gt;(&lt;span class="jshstrings"&gt;"c"&lt;/span&gt;, &lt;span class="jshstrings"&gt;"a"&lt;/span&gt;, &lt;span class="jshstrings"&gt;"b"&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span class="jshglobals"&gt;var&lt;/span&gt; firstScript &lt;span class="jshoperators"&gt;=&lt;/span&gt; _A(document.getElementsByTagName(&lt;span class="jshstrings"&gt;"script"&lt;/span&gt;)).&lt;span class="jshmethods"&gt;shift&lt;/span&gt;();&lt;br /&gt;alert(firstScript);&lt;br /&gt;&lt;br /&gt;&lt;span class="jshglobals"&gt;var&lt;/span&gt; allUnorderedList &lt;span class="jshoperators"&gt;=&lt;/span&gt; _A(document.getElementsByTagName(&lt;span class="jshstrings"&gt;"ul"&lt;/span&gt;));&lt;br /&gt;&lt;br /&gt;alert(_A(null).&lt;span class="jshproperties"&gt;constructor&lt;/span&gt; &lt;span class="jshoperators"&gt;===&lt;/span&gt; &lt;span class="jshglobals"&gt;Array&lt;/span&gt;); &lt;span class="jshcomments"&gt;// true ;-)&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;These nice trick should be used with forEach method too.&lt;br /&gt;Stop for and while loops, each them !&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshglobals"&gt;function&lt;/span&gt; changeLinks(onclick){&lt;br /&gt;[].&lt;span class="jshmethods"&gt;forEach&lt;/span&gt;.&lt;span class="jshmethods"&gt;apply&lt;/span&gt;(document.getElementsByTagName(&lt;span class="jshstrings"&gt;"a"&lt;/span&gt;),&lt;br /&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt;(&lt;span class="jshmethods"&gt;link&lt;/span&gt;){&lt;br /&gt;  &lt;span class="jshmethods"&gt;link&lt;/span&gt;.onclick &lt;span class="jshoperators"&gt;=&lt;/span&gt; onclick;&lt;br /&gt;});&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;changeLinks(&lt;span class="jshglobals"&gt;function&lt;/span&gt;(){&lt;br /&gt;window.open(&lt;span class="jshglobals"&gt;this&lt;/span&gt;.href, &lt;span class="jshstrings"&gt;""&lt;/span&gt;);&lt;br /&gt;&lt;span class="jshglobals"&gt;return&lt;/span&gt; false;&lt;br /&gt;});&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;... and sure, You need forEach prototype too ...&lt;br /&gt;&lt;br /&gt;I suppose every other JS 1.5 Array method should be cool enought to work with DOM nodes too ... do You agree ?&lt;br /&gt;&lt;br /&gt;Are thinking about performances ? Well guys, quite the same of generic loops, even faster (works in core) with every FireFox !!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8143334756111340695-8707041647084529461?l=victorharris.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victorharris.blogspot.com/feeds/8707041647084529461/comments/default' title='Objavi komentare'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8143334756111340695&amp;postID=8707041647084529461' title='2 komentara'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/8707041647084529461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/8707041647084529461'/><link rel='alternate' type='text/html' href='http://victorharris.blogspot.com/2007/06/bored-with-something-to-array.html' title='bored with something to array convertion ? map them !'/><author><name>Victor</name><uri>http://www.blogger.com/profile/12416490940708538797</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8143334756111340695.post-1901356994395587507</id><published>2007-06-27T16:18:00.000-07:00</published><updated>2007-06-27T16:19:09.860-07:00</updated><title type='text'>bytefx 0.4</title><content type='html'>The good thing is that bytefx now has a new scroll method, the sad thing is that Safari 2 probably doesn't work with MemTronic compressed version and this new method cost about 1 more Kb, then bytefx now is 2.09 Kb and not less than 2 ... however, it is not so important because packer version is less than 3Kb and more compatible with Safari 2 too.&lt;br /&gt;&lt;br /&gt;Fixes: any fix, bytefx seems to be really stable and probably bug free (simple with few lines of code :D).&lt;br /&gt;&lt;br /&gt;Changes: just a new method to scroll the page with elements as target.&lt;br /&gt;&lt;br /&gt;Simple, cool ? Hey guys, It's bytefx ;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8143334756111340695-1901356994395587507?l=victorharris.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victorharris.blogspot.com/feeds/1901356994395587507/comments/default' title='Objavi komentare'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8143334756111340695&amp;postID=1901356994395587507' title='0 komentara'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/1901356994395587507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/1901356994395587507'/><link rel='alternate' type='text/html' href='http://victorharris.blogspot.com/2007/06/bytefx-04.html' title='bytefx 0.4'/><author><name>Victor</name><uri>http://www.blogger.com/profile/12416490940708538797</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8143334756111340695.post-4397295483769217980</id><published>2007-06-27T16:17:00.001-07:00</published><updated>2007-06-27T16:17:48.303-07:00</updated><title type='text'>not yield and the shortest Fibonacci function</title><content type='html'>was joking with new JS 1.7 features,  when I've thought about yield keyword.&lt;br /&gt;&lt;br /&gt;It's a strange keyword because isn't usable as the rest of JS code.&lt;br /&gt;&lt;br /&gt;For example, alert(yield variable) generates an error but alert((yield variable)) shows an undefined value.&lt;br /&gt;(I know, it is quite idiot to think that it should have some value ...)&lt;br /&gt;&lt;br /&gt;Then I've done some test:&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshglobals"&gt;function&lt;/span&gt; fakeGenerator(){&lt;br /&gt;   &lt;span class="jshglobals"&gt;var&lt;/span&gt; i &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshnumbers"&gt;0&lt;/span&gt;;&lt;br /&gt;   &lt;span class="jshglobals"&gt;while&lt;/span&gt;(true)&lt;br /&gt;       &lt;span class="jshcomments"&gt;// alert(yield i++);    // error&lt;br /&gt;&lt;/span&gt;        &lt;span class="jshcomments"&gt;// alert((yield i++));    // undefined&lt;br /&gt;&lt;/span&gt;        yield i&lt;span class="jshoperators"&gt;++&lt;/span&gt;; &lt;span class="jshcomments"&gt;// ok&lt;br /&gt;&lt;/span&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As you can see, (yield something) returns an undefined value and then this is a true expression.&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshoperators"&gt;!&lt;/span&gt;(yield variable) &lt;span class="jshoperators"&gt;===&lt;/span&gt; true&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now You can think that a while loop should use this condiction instead of while(true) {yield variables;} ... for example:&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshglobals"&gt;function&lt;/span&gt; fakeGenerator(i){&lt;br /&gt;   &lt;span class="jshglobals"&gt;while&lt;/span&gt;(&lt;span class="jshoperators"&gt;!&lt;/span&gt;(yield i&lt;span class="jshoperators"&gt;++&lt;/span&gt;)){}&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;works perfectly then maybe I could use this information to write something like this ?&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshglobals"&gt;function&lt;/span&gt; fakeGenerator(i){&lt;br /&gt;   &lt;span class="jshglobals"&gt;while&lt;/span&gt;(&lt;span class="jshoperators"&gt;!&lt;/span&gt;(yield i&lt;span class="jshoperators"&gt;++&lt;/span&gt;));&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Sure, and it works perfectly again !!!&lt;br /&gt;!undefined is true and semi colon stops while loop then with an "OR" or an "AND" and a true value as condiction I could create a lot of &lt;em&gt;dirty&lt;/em&gt; generators ... why not Fibonacci too ?&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshglobals"&gt;function&lt;/span&gt; fib(){&lt;br /&gt;   let(i&lt;span class="jshoperators"&gt;=&lt;/span&gt;&lt;span class="jshnumbers"&gt;0&lt;/span&gt;,j&lt;span class="jshoperators"&gt;=&lt;/span&gt;&lt;span class="jshnumbers"&gt;1&lt;/span&gt;){&lt;br /&gt;       &lt;span class="jshglobals"&gt;while&lt;/span&gt;((yield i)||([i,j]&lt;span class="jshoperators"&gt;=&lt;/span&gt;[j,i&lt;span class="jshoperators"&gt;+&lt;/span&gt;j]));&lt;br /&gt;   }&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;em&gt;so c'mon brother, you can do it better!&lt;/em&gt;, said my dog ... and He was right, I can remove even OR, parentheses and why not, the last semi colon too (thanks to let block).&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshglobals"&gt;function&lt;/span&gt; fib(){let(i&lt;span class="jshoperators"&gt;=&lt;/span&gt;&lt;span class="jshnumbers"&gt;0&lt;/span&gt;,j&lt;span class="jshoperators"&gt;=&lt;/span&gt;&lt;span class="jshnumbers"&gt;1&lt;/span&gt;){&lt;span class="jshglobals"&gt;while&lt;/span&gt;(&lt;span class="jshoperators"&gt;!&lt;/span&gt;(yield i))[i,j]&lt;span class="jshoperators"&gt;=&lt;/span&gt;[j,i&lt;span class="jshoperators"&gt;+&lt;/span&gt;j]}};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;That's what I meant for the shortest Fibonacci function, isn't that ?!?&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;strong&gt;Then ... What's up ?&lt;/strong&gt;&lt;br /&gt;I wrote this stupid post just to tell You that sometimes You don't need the "while(true)" condition, just switch true the "undefined yield" :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8143334756111340695-4397295483769217980?l=victorharris.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victorharris.blogspot.com/feeds/4397295483769217980/comments/default' title='Objavi komentare'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8143334756111340695&amp;postID=4397295483769217980' title='0 komentara'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/4397295483769217980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/4397295483769217980'/><link rel='alternate' type='text/html' href='http://victorharris.blogspot.com/2007/06/not-yield-and-shortest-fibonacci.html' title='not yield and the shortest Fibonacci function'/><author><name>Victor</name><uri>http://www.blogger.com/profile/12416490940708538797</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8143334756111340695.post-2863247248084316702</id><published>2007-06-27T16:16:00.001-07:00</published><updated>2007-06-27T16:16:47.738-07:00</updated><title type='text'>PHP and JavaScript encoding comparison table</title><content type='html'>PHP and JavaScript are used every day for sync or async interactions.&lt;br /&gt;&lt;br /&gt;I often read functions or libraries that use JS escape function and I often read forum discussions where someone writes that to solve chars problems You need to use escape function.&lt;br /&gt;&lt;br /&gt;That's wrong, as is the usage of urlencode instead of rawurlencode.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What's wrong on PHP urlencode function ?&lt;br /&gt;urlencode works quite perfectly with different charsets but has a big problem expecially with one char, the space char " ".&lt;br /&gt;This char is not escaped but is replaced with a "+" sign.&lt;br /&gt;If You write an url with this sign instead of a space there are no problems but if write a response for JavaScript with this char there are different problems.&lt;br /&gt;&lt;br /&gt;As You can see from this comparative table JavaScript escape or encode perfectly the space char but doesn't escape the plus sing "+".&lt;br /&gt;This means that when You'll unsecape an urlencoded string it will convert plus sign correctly.&lt;br /&gt;&lt;br /&gt;To solve this simple but common problem, when You need to encode a PHP string, use always the raw version: rawurlencode.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;What's wrong on JavaScript escape function ?&lt;br /&gt;It has more and more problems than urlencode PHP function because it is an old function (too much) with the best encoding browsers compatibility but without unicode support.&lt;br /&gt;The first point is that it doesn't escape correctly the plus sign, then if You send an escaped string with a simple addiction "1 + 2 = 3" to PHP page, it will recieve a string like this one "1 2 = 3" because PHP urldecode function converts plus sign into a space.&lt;br /&gt;However, the real big problem with escape is that it doesn't support unicode and it converts "correctly" only ASCII chars.&lt;br /&gt;&lt;br /&gt;For example at the end of comparative table You can view that escape converts only in range 0x00 - 0xFF but doesn't convert in UTF-8 compatible way every char in range 0x80 - 0xFF and produces, for example, a string like "%E0" that's not the correct multibyte utf-8 rappresentation of char #224.&lt;br /&gt;&lt;br /&gt;If You read under this line You can see that escape cannot produce a compatible output for unicode chars in a cross language compatible way.&lt;br /&gt;&lt;br /&gt;I mean that every multibyte char in range 0x0100 - 0xFFFF will be converted into a fake JSON rappresentation: %u0100 - %uFFFF that isn't absolutely a correct encoded char and isn't compatible with any other language or url string specs too.&lt;br /&gt;&lt;br /&gt;You can use escape only if You send, and recieve, simple strings like [0-9a-zA-Z] with some extra char ( \w ) but isn't absolutely a portable and correct way to create iso or utf-8 PHP and JavaScript interactions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8143334756111340695-2863247248084316702?l=victorharris.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victorharris.blogspot.com/feeds/2863247248084316702/comments/default' title='Objavi komentare'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8143334756111340695&amp;postID=2863247248084316702' title='0 komentara'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/2863247248084316702'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/2863247248084316702'/><link rel='alternate' type='text/html' href='http://victorharris.blogspot.com/2007/06/php-and-javascript-encoding-comparison.html' title='PHP and JavaScript encoding comparison table'/><author><name>Victor</name><uri>http://www.blogger.com/profile/12416490940708538797</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8143334756111340695.post-3204828211370403980</id><published>2007-06-27T16:15:00.001-07:00</published><updated>2007-06-27T16:15:20.379-07:00</updated><title type='text'>Which function to get an XMLHttpRequest object ?</title><content type='html'>Ajax is "quite old" but I've not found any crossbrowser clean or standard way to create and return the correct XMLHttpRequest.&lt;br /&gt;&lt;br /&gt;I wrote a standard crossbrowser function in my italian Ajax Guide (http://javascript.html.it/guide/leggi/95/guida-ajax/) but someone, every day, try to discard that function or to create a "new way" to get that object.&lt;br /&gt;&lt;br /&gt;My opinion is this one:&lt;br /&gt;- You don't need any conditional comment, these aren't a good code practice&lt;br /&gt;- You don't need any evil eval function ... You can do your check without problems&lt;br /&gt;- You don't need any try catch, first because they're not compatible with old browsers, second because You can simply check browser version and then choose the correct ActiveX, if it's necessary&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Then, if You're looking for a simple, fast and cross browser way to get XMLHttpRequest You could just use this function:&lt;br /&gt;&lt;br /&gt;function xhr(){ // webreflection.blogspot.com&lt;br /&gt;  var    xhr = null,&lt;br /&gt;      b = navigator.userAgent;&lt;br /&gt;  if(window.XMLHttpRequest)&lt;br /&gt;      xhr = new XMLHttpRequest();&lt;br /&gt;  else if(!/MSIE 4/i.test(b)) {&lt;br /&gt;      if(/MSIE 5/i.test(b))&lt;br /&gt;          xhr = new ActiveXObject("Microsoft.XMLHTTP");&lt;br /&gt;      else&lt;br /&gt;          xhr = new ActiveXObject("Msxml2.XMLHTTP");&lt;br /&gt;  };&lt;br /&gt;  return xhr;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Every compatible browser, FF 1+, Opera 8+, Safari 2+, KDE 3.4+, IE 5+, will get a valid XMLHttpRequest while every other browser, for example IE4, will recieve a null value.&lt;br /&gt;Then You can simply verify if client browser support Ajax request using a sintax like this one:&lt;br /&gt;&lt;br /&gt;var    ajax = xhr();&lt;br /&gt;if(ajax)&lt;br /&gt;  // do every async interaction ...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;That's all, I hope this will be helpful :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8143334756111340695-3204828211370403980?l=victorharris.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victorharris.blogspot.com/feeds/3204828211370403980/comments/default' title='Objavi komentare'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8143334756111340695&amp;postID=3204828211370403980' title='0 komentara'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/3204828211370403980'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/3204828211370403980'/><link rel='alternate' type='text/html' href='http://victorharris.blogspot.com/2007/06/which-function-to-get-xmlhttprequest.html' title='Which function to get an XMLHttpRequest object ?'/><author><name>Victor</name><uri>http://www.blogger.com/profile/12416490940708538797</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8143334756111340695.post-5154967724447655026</id><published>2007-06-27T16:09:00.000-07:00</published><updated>2007-06-27T16:11:58.708-07:00</updated><title type='text'>CSS Dropshadow</title><content type='html'>My favourite portal wrote a post about a CSS based dropshadow solution.&lt;br /&gt;It talks about this webtoolkit.info post.&lt;br /&gt;&lt;br /&gt;I didn't know that article then only now I can tell You something about that:&lt;br /&gt;&lt;br /&gt;&lt;ul&gt;&lt;li&gt;graphic effects are good "only" for high bandwidth web surfers&lt;/li&gt;&lt;li&gt;dropshadow isn't important as page content&lt;/li&gt;&lt;li&gt;id attribute should be absolutely unique&lt;/li&gt;&lt;li&gt;markup language has a scope and should be used for this scope (sure, when it's possible)&lt;/li&gt;&lt;li&gt;5 nested divs just to show a simple shadow effect aren't a cool solution (imho)&lt;/li&gt;&lt;/ul&gt;&lt;br /&gt;&lt;br /&gt;Since You can do the same thing using a really basic JavaScript function without a repeated id, nested obsolete elements and in a cross browser way with about 1.8 Kb of uncompressed and goo JavaScript, I think You should think about my alternative proposal.&lt;br /&gt;&lt;br /&gt;The only things You need is a better CSS, not based on id but based on class name and a simple callback.&lt;br /&gt;This is revisited CSS&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshcomments"&gt;/* CSS container shadow */&lt;/span&gt;&lt;br /&gt;.shadow&lt;span class="jshoperators"&gt;-&lt;/span&gt;container {&lt;br /&gt;   position: relative;&lt;br /&gt;   left: 3px;&lt;br /&gt;   top: 3px;&lt;br /&gt;   margin&lt;span class="jshoperators"&gt;-&lt;/span&gt;right: 3px;&lt;br /&gt;   margin&lt;span class="jshoperators"&gt;-&lt;/span&gt;bottom: 3px;&lt;br /&gt;}&lt;br /&gt;   .shadow&lt;span class="jshoperators"&gt;-&lt;/span&gt;container .shadow2,&lt;br /&gt;   .shadow&lt;span class="jshoperators"&gt;-&lt;/span&gt;container .shadow3,&lt;br /&gt;   .shadow&lt;span class="jshoperators"&gt;-&lt;/span&gt;container .container {&lt;br /&gt;       position: relative;&lt;br /&gt;       left: &lt;span class="jshoperators"&gt;-&lt;/span&gt;1px;&lt;br /&gt;       top: &lt;span class="jshoperators"&gt;-&lt;/span&gt;1px;&lt;br /&gt;   }&lt;br /&gt;   .shadow&lt;span class="jshoperators"&gt;-&lt;/span&gt;container .shadow1 {&lt;br /&gt;       background: #F1F0F1;&lt;br /&gt;   }&lt;br /&gt;   .shadow&lt;span class="jshoperators"&gt;-&lt;/span&gt;container .shadow2 {&lt;br /&gt;       background: #DBDADB;&lt;br /&gt;   }&lt;br /&gt;   .shadow&lt;span class="jshoperators"&gt;-&lt;/span&gt;container .shadow3 {&lt;br /&gt;       background: #B8B6B8;&lt;br /&gt;   }&lt;br /&gt;   .shadow&lt;span class="jshoperators"&gt;-&lt;/span&gt;container .container {&lt;br /&gt;       background: #ffffff;&lt;br /&gt;       border: 1px solid #&lt;span class="jshnumbers"&gt;848284&lt;/span&gt;;&lt;br /&gt;       padding: 10px;&lt;br /&gt;   }&lt;br /&gt;&lt;span class="jshcomments"&gt;/* CSS container shadow */&lt;/span&gt; &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And this is simple callback example:&lt;br /&gt;&lt;pre class="code"&gt;onload &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt;(){&lt;br /&gt;   createDropShadow(&lt;br /&gt;       getElementsByClassName(&lt;br /&gt;           document, &lt;span class="jshstrings"&gt;"div"&lt;/span&gt;, &lt;span class="jshstrings"&gt;"dropshadow"&lt;/span&gt;&lt;br /&gt;       )&lt;br /&gt;   );&lt;br /&gt;};&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now You can use a dedicated dropshadow div class name in every div that You want to modify.&lt;br /&gt;&lt;pre class="code"&gt;&lt;div class="jshoperators"&gt;=&lt;/span&gt;&lt;span class="jshstrings"&gt;"container dropshadow"&lt;/span&gt;&gt;&lt;br /&gt;Lorem Ipsum ...&lt;br /&gt;&lt;&lt;span class="jshoperators"&gt;/&lt;/span&gt;div&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That's all, just include ej basic file and my dedicated function and You'll have a cleaner page without nested divs overloads and ... bye bye nested divs :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8143334756111340695-5154967724447655026?l=victorharris.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victorharris.blogspot.com/feeds/5154967724447655026/comments/default' title='Objavi komentare'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8143334756111340695&amp;postID=5154967724447655026' title='0 komentara'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/5154967724447655026'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/5154967724447655026'/><link rel='alternate' type='text/html' href='http://victorharris.blogspot.com/2007/06/css-dropshadow.html' title='CSS Dropshadow'/><author><name>Victor</name><uri>http://www.blogger.com/profile/12416490940708538797</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8143334756111340695.post-8585071626724581907</id><published>2007-06-27T16:05:00.000-07:00</published><updated>2007-06-27T16:07:54.763-07:00</updated><title type='text'>W3 Validator, DOM, byteson and PHP</title><content type='html'>I've uploaded a new byteson&lt;a href="http://www.devpro.it/byteson/"&gt;&lt;/a&gt; example page, based on a single and simple request to a PHP page that uses W3 Validator service, calling a SOAP result, parse them to convert it into an associative array and finally send it with JSON to byteson.&lt;br /&gt;&lt;br /&gt;Here is the PHP code&lt;br /&gt;&lt;pre class="code"&gt;&lt;&lt;span class="jshoperators"&gt;?&lt;/span&gt;php&lt;br /&gt;&lt;span class="jshcomments"&gt;// byteson filter&lt;br /&gt;&lt;/span&gt;&lt;span class="jshglobals"&gt;if&lt;/span&gt;(isset($_POST[&lt;span class="jshstrings"&gt;'byteson'&lt;/span&gt;])) {&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// http://www.phpclasses.org/browse/package/3512.html&lt;br /&gt;&lt;/span&gt; require &lt;span class="jshstrings"&gt;'FastJSON.class.php'&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// http://www.devpro.it/code/143.html&lt;br /&gt;&lt;/span&gt; require &lt;span class="jshstrings"&gt;'W3validator.function.php'&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// remove magic quotes if th it's present&lt;br /&gt;&lt;/span&gt;        &lt;span class="jshcomments"&gt;// magic_quotes is a problem for JSON strings&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;if&lt;/span&gt;(get_magic_quotes_gpc())&lt;br /&gt; $_POST[&lt;span class="jshstrings"&gt;'byteson'&lt;/span&gt;] &lt;span class="jshoperators"&gt;=&lt;/span&gt; stripslashes($_POST[&lt;span class="jshstrings"&gt;'byteson'&lt;/span&gt;]);&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// get the output&lt;br /&gt;&lt;/span&gt; $output &lt;span class="jshoperators"&gt;=&lt;/span&gt; FastJSON::encode(W3validator(FastJSON::decode($_POST[&lt;span class="jshstrings"&gt;'byteson'&lt;/span&gt;])));&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// force new content to download&lt;br /&gt;&lt;/span&gt; header(&lt;span class="jshstrings"&gt;'Content-Type: text/plain; charset=utf-8'&lt;/span&gt;);&lt;br /&gt;header(&lt;span class="jshstrings"&gt;'Content-Length: '&lt;/span&gt;.strlen($output));&lt;br /&gt;header(&lt;span class="jshstrings"&gt;'Expires: Mon, 26 Jul 1997 05:00:00 GMT'&lt;/span&gt;);&lt;br /&gt;header(&lt;span class="jshstrings"&gt;'Last-Modified: '&lt;/span&gt;.gmdate(&lt;span class="jshstrings"&gt;'D, d M Y H:i:s'&lt;/span&gt;).&lt;span class="jshstrings"&gt;' GMT'&lt;/span&gt;);&lt;br /&gt;header(&lt;span class="jshstrings"&gt;'Cache-Control: no-store, no-cache, must-revalidate'&lt;/span&gt;);&lt;br /&gt;header(&lt;span class="jshstrings"&gt;'Cache-Control: post-check=0, pre-check=0'&lt;/span&gt;, false);&lt;br /&gt;header(&lt;span class="jshstrings"&gt;'Pragma: no-cache'&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// exit writing JSON object for byteson&lt;br /&gt;&lt;/span&gt; exit($output);&lt;br /&gt;}&lt;br /&gt;&lt;span class="jshoperators"&gt;?&lt;/span&gt;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This php page uses two other files, my FastJSON class and my last function on devpro, called &lt;a href="http://www.devpro.it/code/143.html"&gt;&lt;/a&gt;W3validator (what a fantasy ...).&lt;br /&gt;&lt;br /&gt;The JavaScript code is this one&lt;br /&gt;&lt;pre class="code"&gt;&lt;span class="jshcomments"&gt;// new browsers filter&lt;br /&gt;&lt;/span&gt;&lt;span class="jshglobals"&gt;if&lt;/span&gt;(document.getElementsByTagName)&lt;br /&gt;onload &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt;(){ &lt;span class="jshcomments"&gt;// (C) Andrea Giammarchi&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// assing tabindex and accesskey&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt; accesstab(&lt;span class="jshproperties"&gt;input&lt;/span&gt;){&lt;br /&gt; &lt;span class="jshproperties"&gt;input&lt;/span&gt;.accesskey &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshproperties"&gt;input&lt;/span&gt;.tabindex &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshoperators"&gt;++&lt;/span&gt;accesskey;&lt;br /&gt; &lt;span class="jshoperators"&gt;++&lt;/span&gt;tabindex;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// assign generic link properties&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt; addLinkProperties(a){&lt;br /&gt; tab(a);&lt;br /&gt; a.href &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshstrings"&gt;"#"&lt;/span&gt;;&lt;br /&gt; a.onclick &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt;(){&lt;br /&gt;  &lt;span class="jshglobals"&gt;var&lt;/span&gt; ul &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;this&lt;/span&gt;.parentNode.getElementsByTagName(&lt;span class="jshstrings"&gt;"ul"&lt;/span&gt;).item(&lt;span class="jshnumbers"&gt;0&lt;/span&gt;);&lt;br /&gt;  ul.style.display &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshoperators"&gt;!!&lt;/span&gt;ul.style.display &lt;span class="jshoperators"&gt;?&lt;/span&gt; &lt;span class="jshstrings"&gt;""&lt;/span&gt; : &lt;span class="jshstrings"&gt;"none"&lt;/span&gt;;&lt;br /&gt;  &lt;span class="jshglobals"&gt;return&lt;/span&gt; false;&lt;br /&gt; };&lt;br /&gt; &lt;span class="jshglobals"&gt;return&lt;/span&gt; a;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// append one or more elements into another&lt;br /&gt;&lt;/span&gt; &lt;span class="jshcomments"&gt;// then return the "parent" element&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt; append(parent, elements){&lt;br /&gt; &lt;span class="jshglobals"&gt;if&lt;/span&gt;(elements.&lt;span class="jshproperties"&gt;constructor&lt;/span&gt; &lt;span class="jshoperators"&gt;!==&lt;/span&gt; &lt;span class="jshglobals"&gt;Array&lt;/span&gt;)&lt;br /&gt;  elements &lt;span class="jshoperators"&gt;=&lt;/span&gt; [elements];&lt;br /&gt; &lt;span class="jshglobals"&gt;for&lt;/span&gt;(&lt;span class="jshglobals"&gt;var&lt;/span&gt; i &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshnumbers"&gt;0&lt;/span&gt;; i &lt; class="jshproperties"&gt;length&lt;/span&gt;; i&lt;span class="jshoperators"&gt;++&lt;/span&gt;)&lt;br /&gt;  parent.appendChild(elements[i]);&lt;br /&gt; &lt;span class="jshglobals"&gt;return&lt;/span&gt; parent;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// create a list if there are errors or warnings&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt; createList(&lt;span class="jshproperties"&gt;message&lt;/span&gt;, obj){&lt;br /&gt; &lt;span class="jshglobals"&gt;for&lt;/span&gt;(&lt;span class="jshglobals"&gt;var&lt;/span&gt; a, span, i &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshnumbers"&gt;0&lt;/span&gt;, key &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshstrings"&gt;""&lt;/span&gt;, list &lt;span class="jshoperators"&gt;=&lt;/span&gt; [], tmp &lt;span class="jshoperators"&gt;=&lt;/span&gt; []; i &lt; class="jshproperties"&gt;length&lt;/span&gt;; i&lt;span class="jshoperators"&gt;++&lt;/span&gt;) {&lt;br /&gt;  &lt;span class="jshglobals"&gt;for&lt;/span&gt;(key &lt;span class="jshglobals"&gt;in&lt;/span&gt; obj[i]) {&lt;br /&gt;   span &lt;span class="jshoperators"&gt;=&lt;/span&gt; node(&lt;span class="jshstrings"&gt;"span"&lt;/span&gt;);&lt;br /&gt;   span.innerHTML &lt;span class="jshoperators"&gt;=&lt;/span&gt; obj[i][key];&lt;br /&gt;   tmp.&lt;span class="jshmethods"&gt;push&lt;/span&gt;(append(&lt;br /&gt;    node(&lt;span class="jshstrings"&gt;"li"&lt;/span&gt;), [&lt;br /&gt;     append(node(&lt;span class="jshstrings"&gt;"strong"&lt;/span&gt;), text(key)),&lt;br /&gt;     span&lt;br /&gt;    ]&lt;br /&gt;   ));&lt;br /&gt;  };&lt;br /&gt;  a &lt;span class="jshoperators"&gt;=&lt;/span&gt; addLinkProperties(append(node(&lt;span class="jshstrings"&gt;"a"&lt;/span&gt;), text(&lt;span class="jshproperties"&gt;message&lt;/span&gt;.&lt;span class="jshmethods"&gt;concat&lt;/span&gt;(i &lt;span class="jshoperators"&gt;+&lt;/span&gt; &lt;span class="jshnumbers"&gt;1&lt;/span&gt;))));&lt;br /&gt;  list.&lt;span class="jshmethods"&gt;push&lt;/span&gt;(append(node(&lt;span class="jshstrings"&gt;"li"&lt;/span&gt;),[a, append(node(&lt;span class="jshstrings"&gt;"ul"&lt;/span&gt;), tmp)]));&lt;br /&gt;  tmp &lt;span class="jshoperators"&gt;=&lt;/span&gt; [];&lt;br /&gt; };&lt;br /&gt; &lt;span class="jshglobals"&gt;return&lt;/span&gt; append(node(&lt;span class="jshstrings"&gt;"ul"&lt;/span&gt;), list);&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// perform the request using byteson&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt; doRequest(oldtab){&lt;br /&gt;&lt;br /&gt; &lt;span class="jshcomments"&gt;// just call the server side page&lt;br /&gt;&lt;/span&gt;  &lt;span class="jshcomments"&gt;// sending input string and adding just&lt;br /&gt;&lt;/span&gt;  &lt;span class="jshcomments"&gt;// one listener ( because I'm sure, this application will works "perfectly" :P )&lt;br /&gt;&lt;/span&gt;  byteson.request(&lt;span class="jshstrings"&gt;"w3validator.php"&lt;/span&gt;, inputuri.value, {&lt;br /&gt;&lt;br /&gt;  &lt;span class="jshcomments"&gt;// onload event&lt;br /&gt;&lt;/span&gt;   load:&lt;span class="jshglobals"&gt;function&lt;/span&gt;(obj, xhr){&lt;br /&gt;   &lt;span class="jshglobals"&gt;var&lt;/span&gt; a, key &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshstrings"&gt;""&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;   &lt;span class="jshcomments"&gt;// remove the loading text&lt;br /&gt;&lt;/span&gt;    resultlist.removeChild(resultlist.firstChild);&lt;br /&gt;&lt;br /&gt;   &lt;span class="jshcomments"&gt;// create a list with every key value ...&lt;br /&gt;&lt;/span&gt;    &lt;span class="jshglobals"&gt;for&lt;/span&gt;(key &lt;span class="jshglobals"&gt;in&lt;/span&gt; obj) {&lt;br /&gt;&lt;br /&gt;    &lt;span class="jshcomments"&gt;// but not with Arrays (errors or warnings)&lt;br /&gt;&lt;/span&gt;     &lt;span class="jshglobals"&gt;if&lt;/span&gt;(obj[key].&lt;span class="jshproperties"&gt;constructor&lt;/span&gt; &lt;span class="jshoperators"&gt;!==&lt;/span&gt; &lt;span class="jshglobals"&gt;Array&lt;/span&gt;) {&lt;br /&gt;     append(&lt;br /&gt;      resultlist,&lt;br /&gt;      append(&lt;br /&gt;       node(&lt;span class="jshstrings"&gt;"li"&lt;/span&gt;), [&lt;br /&gt;        append(node(&lt;span class="jshstrings"&gt;"strong"&lt;/span&gt;), text(key)),&lt;br /&gt;        append(node(&lt;span class="jshstrings"&gt;"span"&lt;/span&gt;), text(obj[key]))&lt;br /&gt;       ]&lt;br /&gt;      )&lt;br /&gt;     );&lt;br /&gt;    };&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;   &lt;span class="jshcomments"&gt;// create last list with each error or each warning&lt;br /&gt;&lt;/span&gt;    &lt;span class="jshglobals"&gt;for&lt;/span&gt;(key &lt;span class="jshglobals"&gt;in&lt;/span&gt; obj) {&lt;br /&gt;    &lt;span class="jshglobals"&gt;if&lt;/span&gt;(obj[key].&lt;span class="jshproperties"&gt;constructor&lt;/span&gt; &lt;span class="jshoperators"&gt;===&lt;/span&gt; &lt;span class="jshglobals"&gt;Array&lt;/span&gt; &amp;&amp;amp; obj[key].&lt;span class="jshproperties"&gt;length&lt;/span&gt; &gt; &lt;span class="jshnumbers"&gt;0&lt;/span&gt;) {&lt;br /&gt;     a &lt;span class="jshoperators"&gt;=&lt;/span&gt; addLinkProperties(append(node(&lt;span class="jshstrings"&gt;"a"&lt;/span&gt;), text(key)));&lt;br /&gt;     append(&lt;br /&gt;      resultlist,&lt;br /&gt;      append(&lt;br /&gt;       node(&lt;span class="jshstrings"&gt;"li"&lt;/span&gt;), [&lt;br /&gt;        a,&lt;br /&gt;        createList(key.&lt;span class="jshmethods"&gt;replace&lt;/span&gt;(/list/, &lt;span class="jshstrings"&gt;' #'&lt;/span&gt;), obj[key])&lt;br /&gt;       ]&lt;br /&gt;      )&lt;br /&gt;     );&lt;br /&gt;     a.onclick();&lt;br /&gt;    };&lt;br /&gt;   };&lt;br /&gt;&lt;br /&gt;   &lt;span class="jshcomments"&gt;// enable the form&lt;br /&gt;&lt;/span&gt;    inputuri.disabled &lt;span class="jshoperators"&gt;=&lt;/span&gt; senduri.disabled &lt;span class="jshoperators"&gt;=&lt;/span&gt; false;&lt;br /&gt;&lt;br /&gt;   &lt;span class="jshcomments"&gt;// set old tabindex for next request&lt;br /&gt;&lt;/span&gt;    &lt;span class="jshcomments"&gt;// (correct tab navigation ready)&lt;br /&gt;&lt;/span&gt;    tabindex &lt;span class="jshoperators"&gt;=&lt;/span&gt; oldtab;&lt;br /&gt;  }&lt;br /&gt; });&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// create and return an element of specified type&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt; node(type){&lt;span class="jshglobals"&gt;return&lt;/span&gt; document.createElement(type)};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// add tabindex property using global scpe tabindex integer value&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt; tab(node){node.tabindex &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshoperators"&gt;++&lt;/span&gt;tabindex};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// create and return a text node with specified content&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt; text(value){&lt;span class="jshglobals"&gt;return&lt;/span&gt; document.createTextNode(value)};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// internal global scope variables&lt;br /&gt;&lt;/span&gt; &lt;span class="jshglobals"&gt;var&lt;/span&gt; accesskey &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshnumbers"&gt;0&lt;/span&gt;,     &lt;span class="jshcomments"&gt;// accesskey (WCAG ready ?)&lt;br /&gt;&lt;/span&gt;  tabindex &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshnumbers"&gt;0&lt;/span&gt;,     &lt;span class="jshcomments"&gt;// tabindex (tab navigation ready)&lt;br /&gt;&lt;/span&gt;  output &lt;span class="jshoperators"&gt;=&lt;/span&gt; document.getElementById(&lt;span class="jshstrings"&gt;"request"&lt;/span&gt;), &lt;span class="jshcomments"&gt;// div container&lt;br /&gt;&lt;/span&gt;  form &lt;span class="jshoperators"&gt;=&lt;/span&gt; node(&lt;span class="jshstrings"&gt;"form"&lt;/span&gt;),    &lt;span class="jshcomments"&gt;// used form&lt;br /&gt;&lt;/span&gt;  inputlabel &lt;span class="jshoperators"&gt;=&lt;/span&gt; node(&lt;span class="jshstrings"&gt;"label"&lt;/span&gt;),   &lt;span class="jshcomments"&gt;// label for input text&lt;br /&gt;&lt;/span&gt;  inputuri &lt;span class="jshoperators"&gt;=&lt;/span&gt; node(&lt;span class="jshstrings"&gt;"input"&lt;/span&gt;),   &lt;span class="jshcomments"&gt;// input text&lt;br /&gt;&lt;/span&gt;  sendlabel &lt;span class="jshoperators"&gt;=&lt;/span&gt; node(&lt;span class="jshstrings"&gt;"label"&lt;/span&gt;),   &lt;span class="jshcomments"&gt;// label for send button&lt;br /&gt;&lt;/span&gt;  senduri &lt;span class="jshoperators"&gt;=&lt;/span&gt; node(&lt;span class="jshstrings"&gt;"input"&lt;/span&gt;),   &lt;span class="jshcomments"&gt;// send button&lt;br /&gt;&lt;/span&gt;  resultlist &lt;span class="jshoperators"&gt;=&lt;/span&gt; node(&lt;span class="jshstrings"&gt;"ul"&lt;/span&gt;);   &lt;span class="jshcomments"&gt;// result unordered list&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// assign accesskey, tabindex and other parameters for each input (in this case text and btn)&lt;br /&gt;&lt;/span&gt; accesstab(inputuri);&lt;br /&gt;inputuri.type &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshstrings"&gt;"text"&lt;/span&gt;;&lt;br /&gt;inputuri.id &lt;span class="jshoperators"&gt;=&lt;/span&gt; inputlabel[&lt;span class="jshstrings"&gt;"for"&lt;/span&gt;] &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshstrings"&gt;"userinput"&lt;/span&gt;;&lt;br /&gt;&lt;span class="jshcomments"&gt;// keyboard event listener (RETURN to perform the request)&lt;br /&gt;&lt;/span&gt; inputuri.onkeyup &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt;(evt){&lt;br /&gt; &lt;span class="jshglobals"&gt;if&lt;/span&gt;(&lt;span class="jshoperators"&gt;!&lt;/span&gt;evt)&lt;br /&gt;  evt &lt;span class="jshoperators"&gt;=&lt;/span&gt; window.event;&lt;br /&gt; &lt;span class="jshglobals"&gt;if&lt;/span&gt;(&lt;span class="jshoperators"&gt;!&lt;/span&gt;evt.wich)&lt;br /&gt;  evt.wich &lt;span class="jshoperators"&gt;=&lt;/span&gt; evt.keyCode;&lt;br /&gt; &lt;span class="jshglobals"&gt;if&lt;/span&gt;(evt.wich &lt;span class="jshoperators"&gt;===&lt;/span&gt; &lt;span class="jshnumbers"&gt;13&lt;/span&gt; &amp;&amp;amp; &lt;span class="jshglobals"&gt;this&lt;/span&gt;.value.&lt;span class="jshmethods"&gt;replace&lt;/span&gt;(/^\s*|\s*$/, &lt;span class="jshstrings"&gt;''&lt;/span&gt;).&lt;span class="jshproperties"&gt;length&lt;/span&gt; &gt; &lt;span class="jshnumbers"&gt;4&lt;/span&gt;)&lt;br /&gt;  senduri.onclick();&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;accesstab(senduri);&lt;br /&gt;senduri.type &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshstrings"&gt;"button"&lt;/span&gt;;&lt;br /&gt;senduri.id &lt;span class="jshoperators"&gt;=&lt;/span&gt; sendlabel[&lt;span class="jshstrings"&gt;"for"&lt;/span&gt;] &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshstrings"&gt;"sendinput"&lt;/span&gt;;&lt;br /&gt;senduri.value &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshstrings"&gt;"verify"&lt;/span&gt;;&lt;br /&gt;&lt;span class="jshcomments"&gt;// request function&lt;br /&gt;&lt;/span&gt; senduri.onclick &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt;(){&lt;br /&gt; &lt;span class="jshglobals"&gt;var&lt;/span&gt; newresult &lt;span class="jshoperators"&gt;=&lt;/span&gt; node(&lt;span class="jshstrings"&gt;"ul"&lt;/span&gt;);&lt;br /&gt;&lt;br /&gt; &lt;span class="jshcomments"&gt;// disable the form&lt;br /&gt;&lt;/span&gt;  inputuri.disabled &lt;span class="jshoperators"&gt;=&lt;/span&gt; senduri.disabled &lt;span class="jshoperators"&gt;=&lt;/span&gt; true;&lt;br /&gt;&lt;br /&gt; &lt;span class="jshcomments"&gt;// blur this button&lt;br /&gt;&lt;/span&gt;  senduri.blur();&lt;br /&gt;&lt;br /&gt; &lt;span class="jshcomments"&gt;// remove precedent unordered list element and replace&lt;br /&gt;&lt;/span&gt;  &lt;span class="jshcomments"&gt;// replace them with a simple "loading response" message&lt;br /&gt;&lt;/span&gt;  &lt;span class="jshcomments"&gt;// inside a new unordered list element&lt;br /&gt;&lt;/span&gt;  resultlist.parentNode.replaceChild(newresult, resultlist);&lt;br /&gt;&lt;br /&gt; &lt;span class="jshcomments"&gt;// assign new ul element to global scope var (to change them on load)&lt;br /&gt;&lt;/span&gt;  resultlist &lt;span class="jshoperators"&gt;=&lt;/span&gt; newresult;&lt;br /&gt; append(resultlist, append(node(&lt;span class="jshstrings"&gt;"li"&lt;/span&gt;), text(&lt;span class="jshstrings"&gt;"loading response"&lt;/span&gt;)));&lt;br /&gt;&lt;br /&gt; &lt;span class="jshcomments"&gt;// perform the request with byteson&lt;br /&gt;&lt;/span&gt;  doRequest(tabindex);&lt;br /&gt; &lt;span class="jshglobals"&gt;return&lt;/span&gt; false;&lt;br /&gt;};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// form should be disabled, by default&lt;br /&gt;&lt;/span&gt; &lt;span class="jshcomments"&gt;// (the form doesn't degrade in this example)&lt;br /&gt;&lt;/span&gt; form.onsubmit &lt;span class="jshoperators"&gt;=&lt;/span&gt; &lt;span class="jshglobals"&gt;function&lt;/span&gt;(){&lt;span class="jshglobals"&gt;return&lt;/span&gt; false};&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// create the output only for the first time&lt;br /&gt;&lt;/span&gt; output.replaceChild(&lt;br /&gt; append(&lt;br /&gt;  form,         &lt;span class="jshcomments"&gt;// the form&lt;br /&gt;&lt;/span&gt;    append(&lt;br /&gt;    node(&lt;span class="jshstrings"&gt;"fieldset"&lt;/span&gt;), [     &lt;span class="jshcomments"&gt;// top fieldset&lt;br /&gt;&lt;/span&gt;      append(&lt;br /&gt;      node(&lt;span class="jshstrings"&gt;"legend"&lt;/span&gt;),    &lt;span class="jshcomments"&gt;// and its legend&lt;br /&gt;&lt;/span&gt;       text(&lt;span class="jshstrings"&gt;"W3 Validator"&lt;/span&gt;)   &lt;span class="jshcomments"&gt;// with its content&lt;br /&gt;&lt;/span&gt;      ),&lt;br /&gt;     append(&lt;br /&gt;      inputlabel,    &lt;span class="jshcomments"&gt;// label for text input&lt;br /&gt;&lt;/span&gt;       text(&lt;span class="jshstrings"&gt;"write a valid url address"&lt;/span&gt;) &lt;span class="jshcomments"&gt;// and its content&lt;br /&gt;&lt;/span&gt;      ),&lt;br /&gt;     inputuri,     &lt;span class="jshcomments"&gt;// input text&lt;br /&gt;&lt;/span&gt;      append(&lt;br /&gt;      sendlabel,    &lt;span class="jshcomments"&gt;// label for button&lt;br /&gt;&lt;/span&gt;       text(&lt;span class="jshstrings"&gt;"verify W3 validator result"&lt;/span&gt;) &lt;span class="jshcomments"&gt;// and its content&lt;br /&gt;&lt;/span&gt;      ),&lt;br /&gt;     senduri      &lt;span class="jshcomments"&gt;// send button&lt;br /&gt;&lt;/span&gt;     ]&lt;br /&gt;   )&lt;br /&gt;), output.firstChild);&lt;br /&gt;&lt;br /&gt;&lt;span class="jshcomments"&gt;// create result fieldset to show informations&lt;br /&gt;&lt;/span&gt; &lt;span class="jshcomments"&gt;// append this fieldset after the precedent output&lt;br /&gt;&lt;/span&gt; append(&lt;br /&gt; output,&lt;br /&gt; append(&lt;br /&gt;  node(&lt;span class="jshstrings"&gt;"fieldset"&lt;/span&gt;), [       &lt;span class="jshcomments"&gt;// bottom fieldset&lt;br /&gt;&lt;/span&gt;   append(&lt;br /&gt;   node(&lt;span class="jshstrings"&gt;"legend"&lt;/span&gt;),       &lt;span class="jshcomments"&gt;// and its legend&lt;br /&gt;&lt;/span&gt;    text(&lt;span class="jshstrings"&gt;"W3 Response"&lt;/span&gt;)      &lt;span class="jshcomments"&gt;// with its content&lt;br /&gt;&lt;/span&gt;   ),&lt;br /&gt;  resultlist        &lt;span class="jshcomments"&gt;// and its unordered list&lt;br /&gt;&lt;/span&gt;   ]         &lt;span class="jshcomments"&gt;// to show the result&lt;br /&gt;&lt;/span&gt;  )&lt;br /&gt;);&lt;br /&gt;};      &lt;span class="jshcomments"&gt;// that's all&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The last file is the external &lt;a href="http://www.devpro.it/byteson/demo/W3validator.css"&gt;&lt;/a&gt;stylesheet used in this page.&lt;br /&gt;&lt;br /&gt;This basic example can explain better than every post, how W3validator PHP function works and how much is simple to implement byteson inside other JS code.&lt;br /&gt;&lt;br /&gt;Have fun with W3 validation ;-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/8143334756111340695-8585071626724581907?l=victorharris.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://victorharris.blogspot.com/feeds/8585071626724581907/comments/default' title='Objavi komentare'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=8143334756111340695&amp;postID=8585071626724581907' title='0 komentara'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/8585071626724581907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8143334756111340695/posts/default/8585071626724581907'/><link rel='alternate' type='text/html' href='http://victorharris.blogspot.com/2007/06/w3-validator-dom-byteson-and-php.html' title='W3 Validator, DOM, byteson and PHP'/><author><name>Victor</name><uri>http://www.blogger.com/profile/12416490940708538797</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
