<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ross Wan's World!</title>
	<atom:link href="http://mrwlwan.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mrwlwan.wordpress.com</link>
	<description>Java, Python, Ajax, PHP and Linux.</description>
	<lastBuildDate>Tue, 30 Jun 2009 03:16:06 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>zh-cn</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='mrwlwan.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/d3712f3c4a6c47fe0fc0d25445595538?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Ross Wan's World!</title>
		<link>http://mrwlwan.wordpress.com</link>
	</image>
			<item>
		<title>Javascript：打印对象</title>
		<link>http://mrwlwan.wordpress.com/2009/03/09/javascript%ef%bc%9a%e6%89%93%e5%8d%b0%e5%af%b9%e8%b1%a1/</link>
		<comments>http://mrwlwan.wordpress.com/2009/03/09/javascript%ef%bc%9a%e6%89%93%e5%8d%b0%e5%af%b9%e8%b1%a1/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 13:04:37 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=325</guid>
		<description><![CDATA[alert() 是我们调试阶段经常使用的方法，可以查看目标变量的值。但是，如果目标变量是对象，如：
var foo = {'key1': 'foo1', 'key2': 'foo2'};
alert(foo);
其显示结果是 [object Object]。这对于调试没有多大用处。再试下这个：
for(myKey in myObj){
    alert ("myObj["+myKey +"] = "+myObj[myKey]);
}
虽然可以显示期待的结果，但有点麻烦（或者可以将上面的代码封装在一个方法里）。
对于 Gecko 内核的浏览器，可以使用对象的 toSource() 方法，这是其 Javascript 的一个特性。
alert(foo.toSource());
其打印结果是： ({key1:&#8221;foo1&#8243;, key2:&#8221;foo2&#8243;})。
最后，当然不能忘了 Firebug 这个利器：
console.log(foo);
其打印结果是：Object key1=foo1 key2=foo2
Posted in Javascript       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=325&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>alert() 是我们调试阶段经常使用的方法，可以查看目标变量的值。但是，如果目标变量是对象，如：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">var foo = {'key1': 'foo1', 'key2': 'foo2'};
alert(foo);</pre>
<p>其显示结果是 [object Object]。这对于调试没有多大用处。再试下这个：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">for(myKey in myObj){
    alert ("myObj["+myKey +"] = "+myObj[myKey]);
}</pre>
<p>虽然可以显示期待的结果，但有点麻烦（或者可以将上面的代码封装在一个方法里）。</p>
<p>对于 Gecko 内核的浏览器，可以使用对象的 toSource() 方法，这是其 Javascript 的一个特性。</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">alert(foo.toSource());</pre>
<p>其打印结果是： ({key1:&#8221;foo1&#8243;, key2:&#8221;foo2&#8243;})。</p>
<p>最后，当然不能忘了 Firebug 这个利器：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">console.log(foo);</pre>
<p>其打印结果是：<a class="objectLink objectLink-object"><span class="objectTitle">Object</span> key1=<span class="objectPropValue">foo1</span> key2=<span class="objectPropValue">foo2</span></a></p>
Posted in Javascript  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=325&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/03/09/javascript%ef%bc%9a%e6%89%93%e5%8d%b0%e5%af%b9%e8%b1%a1/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>Vim: EnhancedCommentify，一个好用的注释插件</title>
		<link>http://mrwlwan.wordpress.com/2009/03/07/vim-enhancedcommentify%ef%bc%8c%e4%b8%80%e4%b8%aa%e5%a5%bd%e7%94%a8%e7%9a%84%e6%b3%a8%e9%87%8a%e6%8f%92%e4%bb%b6/</link>
		<comments>http://mrwlwan.wordpress.com/2009/03/07/vim-enhancedcommentify%ef%bc%8c%e4%b8%80%e4%b8%aa%e5%a5%bd%e7%94%a8%e7%9a%84%e6%b3%a8%e9%87%8a%e6%8f%92%e4%bb%b6/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 04:04:11 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[gVim]]></category>
		<category><![CDATA[comment]]></category>
		<category><![CDATA[EnhancedCommentify]]></category>
		<category><![CDATA[usage]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=320</guid>
		<description><![CDATA[如果不习惯于“老老实实”地一行一行添加注释符的话，可以试下 EnhancedCommentify 这个 Vim 的插件。它对支持目前大多数文件格式的注释，如 PHP、Python、Java、C/C++ 等等。
下载地址
执行 :call EnhancedCommentify(&#8216;yes&#8217;,'comment&#8217;) 即对当前行进行注释；反之，执行 :call EnhancedCommentify(&#8216;yes&#8217;,'decomment&#8217;) 则对当前行进行反注释。
为了使用方便，可以对上面的命令进行键盘映射：
" 设置注释
map &#60;F2&#62; &#60;Esc&#62;&#60;Esc&#62;:call EnhancedCommentify('yes','comment')&#60;CR&#62;
" 取消注释
map &#60;F3&#62; &#60;Esc&#62;&#60;Esc&#62;:call EnhancedCommentify('yes','decomment')&#60;CR&#62;
具体的使用方法，可以查看插件里面的 doc。
Have fun :)
Posted in gVim Tagged: comment, EnhancedCommentify, usage, vim      <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=320&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>如果不习惯于“老老实实”地一行一行添加注释符的话，可以试下 EnhancedCommentify 这个 Vim 的插件。它对支持目前大多数文件格式的注释，如 PHP、Python、Java、C/C++ 等等。</p>
<p><a href="http://www.vim.org/scripts/script.php?script_id=23" target="_blank">下载地址</a></p>
<p>执行 :call EnhancedCommentify(&#8216;yes&#8217;,'comment&#8217;) 即对当前行进行注释；反之，执行 :call EnhancedCommentify(&#8216;yes&#8217;,'decomment&#8217;) 则对当前行进行反注释。</p>
<p>为了使用方便，可以对上面的命令进行键盘映射：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">" 设置注释
map &lt;F2&gt; &lt;Esc&gt;&lt;Esc&gt;:call EnhancedCommentify('yes','comment')&lt;CR&gt;
" 取消注释
map &lt;F3&gt; &lt;Esc&gt;&lt;Esc&gt;:call EnhancedCommentify('yes','decomment')&lt;CR&gt;</pre>
<p>具体的使用方法，可以查看插件里面的 doc。</p>
<p>Have fun :)</p>
Posted in gVim Tagged: comment, EnhancedCommentify, usage, vim <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/320/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=320&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/03/07/vim-enhancedcommentify%ef%bc%8c%e4%b8%80%e4%b8%aa%e5%a5%bd%e7%94%a8%e7%9a%84%e6%b3%a8%e9%87%8a%e6%8f%92%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>Dojo:  Dialog 的 onClose 事件</title>
		<link>http://mrwlwan.wordpress.com/2009/03/06/dojo-dialog-%e7%9a%84-onclose-%e4%ba%8b%e4%bb%b6/</link>
		<comments>http://mrwlwan.wordpress.com/2009/03/06/dojo-dialog-%e7%9a%84-onclose-%e4%ba%8b%e4%bb%b6/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 06:52:46 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[dialog]]></category>
		<category><![CDATA[hide]]></category>
		<category><![CDATA[onClose]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=318</guid>
		<description><![CDATA[对于dijit.Dial0g 为说，是没有 onClose 事件的，当你关闭它，只是将它隐藏而已。所以，应该用 hide 事件来代替。如：
var dialog = dijit.byId("fooDialog");
dialog.connect(dialog, "hide", function(e){
     /* do every thing here */
});
当 dialog 调用 hide() 隐藏自身时，会触发事件。
Posted in Ajax, Dojo Tagged: dialog, Dojo, hide, onClose      <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=318&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>对于dijit.Dial0g 为说，是没有 onClose 事件的，当你关闭它，只是将它隐藏而已。所以，应该用 hide 事件来代替。如：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">var dialog = dijit.byId("fooDialog");
dialog.connect(dialog, "hide", function(e){
     /* do every thing here */
});</pre>
<p>当 dialog 调用 hide() 隐藏自身时，会触发事件。</p>
Posted in Ajax, Dojo Tagged: dialog, Dojo, hide, onClose <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/318/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/318/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/318/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=318&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/03/06/dojo-dialog-%e7%9a%84-onclose-%e4%ba%8b%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>Dojo: Layout 的问题</title>
		<link>http://mrwlwan.wordpress.com/2009/03/03/dojo-layout-%e7%9a%84%e9%97%ae%e9%a2%98/</link>
		<comments>http://mrwlwan.wordpress.com/2009/03/03/dojo-layout-%e7%9a%84%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 15:10:41 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Dojo]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=316</guid>
		<description><![CDATA[&#60;div id="wrap"&#62;
    &#60;div id="main" dojoType="dijit.LayoutContainer"&#62;
...
在使用 Dojo 的 Layout（dijit.layout.xxxx），其 Wrap 容器必须设定其大小，如 style=&#8221;width:100px;height:100px;&#8221;。否则，将会显示空白页。在 1.2.3 和 1.3 都存在这个问题。如果其 Wrap 窗口是 Body，则将 Body 设为 style=&#8221;width:100%;height:100%;position:absolute&#8221; ；或者，将 Body 设为 style=&#8221;width:100%;height:100%;&#8221;, 将 #main 设为 style=&#8221;position:absolute&#8221;。
虽然不知道这是不是 Bugs，或者是不是一个正确的解决方法，但确实能解决目前问题：例如 《Book of Dojo》中的 Mail 应用例子。
Posted in Ajax, Dojo       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=316&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">&lt;div id="wrap"&gt;
    &lt;div id="main" dojoType="dijit.LayoutContainer"&gt;
...</pre>
<p>在使用 Dojo 的 Layout（dijit.layout.xxxx），其 Wrap 容器必须设定其大小，如 style=&#8221;width:100px;height:100px;&#8221;。否则，将会显示空白页。在 1.2.3 和 1.3 都存在这个问题。如果其 Wrap 窗口是 Body，则将 Body 设为 style=&#8221;width:100%;height:100%;position:absolute&#8221; ；或者，将 Body 设为 style=&#8221;width:100%;height:100%;&#8221;, 将 #main 设为 style=&#8221;position:absolute&#8221;。</p>
<p>虽然不知道这是不是 Bugs，或者是不是一个正确的解决方法，但确实能解决目前问题：例如 <a href="http://dojotoolkit.org/book/dojo-book-1-0">《Book of Dojo》</a>中的 <a href="http://dojotoolkit.org/book/dojo-book-0-9/part-1-life-dojo/example-2-postman-always-clicks-twice/basic-layout">Mail </a>应用例子。</p>
Posted in Ajax, Dojo  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/316/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/316/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/316/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=316&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/03/03/dojo-layout-%e7%9a%84%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>CodeIgniter: is_ajax，判断 AJAX 请求</title>
		<link>http://mrwlwan.wordpress.com/2009/02/27/codeigniter-is_ajax%ef%bc%8c%e5%88%a4%e6%96%ad-ajax-%e8%af%b7%e6%b1%82/</link>
		<comments>http://mrwlwan.wordpress.com/2009/02/27/codeigniter-is_ajax%ef%bc%8c%e5%88%a4%e6%96%ad-ajax-%e8%af%b7%e6%b1%82/#comments</comments>
		<pubDate>Fri, 27 Feb 2009 09:07:59 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[is_ajax]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=314</guid>
		<description><![CDATA[CakePHP 的 RequestHandler 组件，有一个方便的方法 isAjax ，可以判断当前的请求是否为 AJAX 请求。貌似 CodeIgniter（以下简称 CI） 没有）。不过不要紧， 可以自行对 CI 的类库进行扩展，添加上 is_ajax 方法（之所以用下划线分隔的方式命名而不是骆驼峰方式，是因为要迎合 CI 的开发规范）。
我们决定扩充 CI 的CI_Input 类，不赞成直接对核心代码的修改，既然 CI 提供了良好的扩充机制，为什么不用呢？ :)
创建一个名为 MY_Input.php 的文件，放在自己的 App（默认是 aplication ）/libraries 文件夹下。内容如下：
&#60;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Input extends CI_Input {
	function MY_Input() {
		parent::CI_Input();
	}

	function isAjax() {
        [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=314&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>CakePHP 的 RequestHandler 组件，有一个方便的方法 isAjax ，可以判断当前的请求是否为 AJAX 请求。貌似 CodeIgniter（以下简称 CI） 没有）。不过不要紧， 可以自行对 CI 的类库进行扩展，添加上 is_ajax 方法（之所以用下划线分隔的方式命名而不是骆驼峰方式，是因为要迎合 CI 的开发规范）。</p>
<p>我们决定扩充 CI 的CI_Input 类，不赞成直接对核心代码的修改，既然 CI 提供了良好的扩充机制，为什么不用呢？ :)</p>
<p>创建一个名为 MY_Input.php 的文件，放在自己的 App（默认是 aplication ）/libraries 文件夹下。内容如下：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class MY_Input extends CI_Input {
	function MY_Input() {
		parent::CI_Input();
	}

	function isAjax() {
        return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &amp;&amp; $_SERVER['HTTP_X_REQUESTED_WITH']=="XMLHttpRequest");
    }
}
// END Input class

/* End of file Input.php */
/* Location: ./system/application/MY_Input.php */</pre>
<p>注意：具体的文件名，要根据你在 config.php 中对 $config['subclass_prefix'] 的设置。默认是 $config['subclass_prefix']  = &#8216;MY_&#8217;;</p>
<p>下面，就可以在 Controller 里对 Input 类自行加载使用：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">......

    function foo() {
        $this-&gt;load-&gt;library('input');
        if ($this-&gt;input-&gt;is_ajax()) {
            do_something();
            ....
        }
    }
......</pre>
Posted in Ajax, CodeIgniter, PHP Tagged: Ajax, CodeIgniter, is_ajax <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/314/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/314/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/314/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=314&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/02/27/codeigniter-is_ajax%ef%bc%8c%e5%88%a4%e6%96%ad-ajax-%e8%af%b7%e6%b1%82/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>神奇的浏览器嗅探代码</title>
		<link>http://mrwlwan.wordpress.com/2009/02/26/%e7%a5%9e%e5%a5%87%e7%9a%84%e6%b5%8f%e8%a7%88%e5%99%a8%e5%97%85%e6%8e%a2%e4%bb%a3%e7%a0%81/</link>
		<comments>http://mrwlwan.wordpress.com/2009/02/26/%e7%a5%9e%e5%a5%87%e7%9a%84%e6%b5%8f%e8%a7%88%e5%99%a8%e5%97%85%e6%8e%a2%e4%bb%a3%e7%a0%81/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 12:30:49 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=312</guid>
		<description><![CDATA[在 shortest way to test for IE 一文中， 讲述了20个方法嗅探 IE 浏览器 ，其中：
ie = '\v'=='v';
上面的代码是不是很神奇，但重要的是，它确实正确地判断出 IE 浏览器。这是利用浏览器的特性来作出判断的。其它的利用浏览器特性判断的 JS 代码：
ie = !!top.execScript;
ie = /*@cc_on!@*/!1;
ie8 = !!window.XDomainRequest;
IEVersion = 0/*@cc_on+ScriptEngineMajorVersion()@*/;
ff = /a/[-1]=='a';
ff3 = (function  x(){})[-5]=='x';
ff2 = (function x(){})[-6]=='x';
safari=/a/.__proto__=='//';
chrome=/source/.test((/a/.toString+''));
opera=/^function \(/.test([].sort);
在 Mootools 1.2.1 里，也是利用浏览器的特性来作出嗅探的：
if (window.opera) Browser.Engine = {
    name: 'presto',
    version: (document.getElementsByClassName) ? 950 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=312&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>在 <a href="http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html" target="_blank">shortest way to test for IE</a> 一文中， 讲述了20个方法嗅探 IE 浏览器 ，其中：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">ie = '\v'=='v';</pre>
<p>上面的代码是不是很神奇，但重要的是，它确实正确地判断出 IE 浏览器。这是利用浏览器的特性来作出判断的。其它的利用浏览器特性判断的 JS 代码：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">ie = !!top.execScript;
ie = /*@cc_on!@*/!1;
ie8 = !!window.XDomainRequest;
IEVersion = 0/*@cc_on+ScriptEngineMajorVersion()@*/;
ff = /a/[-1]=='a';
ff3 = (function  x(){})[-5]=='x';
ff2 = (function x(){})[-6]=='x';
safari=/a/.__proto__=='//';
chrome=/source/.test((/a/.toString+''));
opera=/^function \(/.test([].sort);</pre>
<p>在 Mootools 1.2.1 里，也是利用浏览器的特性来作出嗅探的：</p>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">if (window.opera) Browser.Engine = {
    name: 'presto',
    version: (document.getElementsByClassName) ? 950 : 925};
else if (window.ActiveXObject) Browser.Engine = {
    name: 'trident',
    version: (window.XMLHttpRequest) ? 5 : 4};
else if (!navigator.taintEnabled) Browser.Engine = {
    name: 'webkit',
    version: (Browser.Features.xpath) ? 420 : 419};
else if (document.getBoxObjectFor != null) Browser.Engine = {
    name: 'gecko',
    version: (document.getElementsByClassName) ? 19 : 18};

Browser.Engine[Browser.Engine.name] =
Browser.Engine[Browser.Engine.name + Browser.Engine.version] = true;</pre>
<pre></pre>
Posted in Ajax, Javascript  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/312/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=312&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/02/26/%e7%a5%9e%e5%a5%87%e7%9a%84%e6%b5%8f%e8%a7%88%e5%99%a8%e5%97%85%e6%8e%a2%e4%bb%a3%e7%a0%81/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>cakePHP: 中文乱码问题</title>
		<link>http://mrwlwan.wordpress.com/2009/02/20/cakephp-%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%e9%97%ae%e9%a2%98/</link>
		<comments>http://mrwlwan.wordpress.com/2009/02/20/cakephp-%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%e9%97%ae%e9%a2%98/#comments</comments>
		<pubDate>Fri, 20 Feb 2009 03:29:45 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cakePHP]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=310</guid>
		<description><![CDATA[在默认的配置下，cakePHP 存取的中文字符可以在网页上正常显示，但是在 phpMyadmin 下中文会显示为乱码，已经将数据库、所有的表都设置为 UTF-8，一样无效。
想起平时在 PHP 里处理 MySQL 中文存取的方法，就是在数据库操作前执行一句：

mysql_-&#62;query('SET NAME "UTF8");

于是在自己的 controller 里添加上这一句，果然中文在 phpMyAdmin 里显示正常。但取出数据时显示乱码。看来得“修改” AppModel。在自己的 App 目录下添加 app_model.php 文件，内容如下：

class AppModel extends Model {
    function __contruct() {
        parent::__construct();
        $this-&#62;query('SET NAMES "utf8"');
    }
}

这样，中文乱码消失了。但究竟 cakePHP 有没有更简洁的解决方法呢？于是查看 App [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=310&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>在默认的配置下，cakePHP 存取的中文字符可以在网页上正常显示，但是在 phpMyadmin 下中文会显示为乱码，已经将数据库、所有的表都设置为 UTF-8，一样无效。</p>
<p>想起平时在 PHP 里处理 MySQL 中文存取的方法，就是在数据库操作前执行一句：</p>
<div id="id1" class="section">
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">mysql_-&gt;query('SET NAME "UTF8");</pre>
</div>
<div class="section">于是在自己的 controller 里添加上这一句，果然中文在 phpMyAdmin 里显示正常。但取出数据时显示乱码。看来得“修改” AppModel。在自己的 App 目录下添加 app_model.php 文件，内容如下：</div>
<div class="section">
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">class AppModel extends Model {
    function __contruct() {
        parent::__construct();
        $this-&gt;query('SET NAMES "utf8"');
    }
}</pre>
</div>
<p>这样，中文乱码消失了。但究竟 cakePHP 有没有更简洁的解决方法呢？于是查看 App 的数据库配置文件（config/database.php），发现有一个 encoding 选项，设置其为 &#8216;UTF8&#8242;，记住！不能是&#8217;UTF-8&#8242;，否则无效，问题果然解决。</p>
<p>That&#8217;s all, have fun :)</p>
Posted in cakePHP, PHP  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/310/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/310/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/310/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=310&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/02/20/cakephp-%e4%b8%ad%e6%96%87%e4%b9%b1%e7%a0%81%e9%97%ae%e9%a2%98/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>Mootools: toElement 方法</title>
		<link>http://mrwlwan.wordpress.com/2009/01/31/mootools-toelement-%e6%96%b9%e6%b3%95/</link>
		<comments>http://mrwlwan.wordpress.com/2009/01/31/mootools-toelement-%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 11:31:40 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[feature]]></category>
		<category><![CDATA[toElement]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=308</guid>
		<description><![CDATA[toElement 是 Mootools 1.2 里的一个新特性（但并没有在其官方文档里说明）。toElement 只是一个返回 element 对象的方法。当向 $ 传递一个对象时，它会尝试调用对象的 toElement 方法来取得当前 element。

示例
var User = new Class({
    initialize: function(name){
        this.name = name;
    },

    toElement: function(){
        if (!this.element) {
     [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=308&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>toElement 是 Mootools 1.2 里的一个新特性（但并没有在其官方文档里说明）。toElement 只是一个返回 element 对象的方法。当向 $ 传递一个对象时，它会尝试调用对象的 toElement 方法来取得当前 element。</p>
<div id="id1" class="section">
<h1>示例</h1>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">var User = new Class({
    initialize: function(name){
        this.name = name;
    },

    toElement: function(){
        if (!this.element) {
            this.element = new Element('div', {'class': 'user'});
            var avatar = new Element('img', {
                src: '/avatars/' + this.name + '.jpg'

            });
            var description = new Element('div', {
                'class': 'username',
                'text': this.name
            });
            this.element.adopt(avatar, description);
        }
        return this.element;
    }
});

window.addEvent('domready', function(){
    var alice = new User('Alice');
    var bob = new User('Bob');
    $(alice).inject('header', 'after');
    // let's inject bob after alice
    $(bob).inject(alice, 'after');
});</pre>
</div>
<div id="id2" class="section">
<h1>参考资料</h1>
<ul class="simple">
<li><a class="reference external" href="http://blog.kassens.net/toelement-method">http://blog.kassens.net/toelement-method</a></li>
</ul>
</div>
Posted in Ajax, Javascript, Mootools Tagged: feature, Mootools, toElement <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/308/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/308/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/308/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=308&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/01/31/mootools-toelement-%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>imgslideshow2: 基于 Mootools 的图片幻灯插件</title>
		<link>http://mrwlwan.wordpress.com/2009/01/30/imgslideshow2-%e5%9f%ba%e4%ba%8e-mootools-%e7%9a%84%e5%9b%be%e7%89%87%e5%b9%bb%e7%81%af%e6%8f%92%e4%bb%b6/</link>
		<comments>http://mrwlwan.wordpress.com/2009/01/30/imgslideshow2-%e5%9f%ba%e4%ba%8e-mootools-%e7%9a%84%e5%9b%be%e7%89%87%e5%b9%bb%e7%81%af%e6%8f%92%e4%bb%b6/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 10:53:44 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Mootools]]></category>
		<category><![CDATA[images slide show]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=306</guid>
		<description><![CDATA[
之前写了个 jQuery 的图片幻灯插件，但存在不少问题， 例如“疯狂”点击导航按钮会显示不正常。现在用 Mootools 重写了一个  插件。（近来在学 Mootools，学习 Mootools 的源代码）

代码
/* ImgSlideShow, a plugin with mootools. It make the special images slide show.
*
* Licensed under The MIT License
*
* @author mrwlwan#gmail.com
* @date 01/27/2009
* @version 1.0
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*
* Usage:
* var myImgSlideShow = new ImgSlideShow($('mycontainor'));
* or
* var myImgSlideShow = new ImgSlideShow($('mycontainor'), {delay: 50000});
*
* Available methods:
* [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=306&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><div class="document">
<p>之前写了个 jQuery 的图片幻灯插件，但存在不少问题， 例如“疯狂”点击导航按钮会显示不正常。现在用 Mootools 重写了一个  <a class="reference external" href="../2008/12/11/">插件</a>。（近来在学 Mootools，学习 Mootools 的源代码）</p>
<div id="id2" class="section">
<h1>代码</h1>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">/* ImgSlideShow, a plugin with mootools. It make the special images slide show.
*
* Licensed under The MIT License
*
* @author mrwlwan#gmail.com
* @date 01/27/2009
* @version 1.0
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*
* Usage:
* var myImgSlideShow = new ImgSlideShow($('mycontainor'));
* or
* var myImgSlideShow = new ImgSlideShow($('mycontainor'), {delay: 50000});
*
* Available methods:
* addImage(imgurl, href, where) add a image element, with the image url, reference url, position inserted.
* pause() pause the animation.
* resume() resume the animation.
*/

var ImgSlideShow = new Class({
   Implements: Options,

   // default settings
   options: {
       'delay': 3000, // set every image pauses time.
       'navBnBgcolor': '#fff',
       'navBnHeightLight': '#f00'
   },

   /* Initializes ImgSlideShow Object.
    *
    * @param {Element} container element which contains images.
    * @param {Object} optional, adjust different settings, like delay time.
    */
   initialize: function(imgContainer, options){
       this.setOptions(options);

       this.imgContainer = imgContainer;   // images container element
       this.imagesArray = imgContainer.getElements('img');     // all images elements array
       this.navBar = null;     // navigator bar element
       this.curentImgEl = null;    // image element displayed currently
       this.timer = null;      // timer, use to be cleared

       this.setImgStyle(this.imagesArray);

       this.imgContainer.setStyles({
           'position': 'relative',
           'overflow': 'hidden'
       });

       this.addNavBar();
       this.action(0);     // animate from the 0 index element.
   },

   /* Set the images' style.
    *
    * @param {Iterable} the image elements array.
    */
   setImgStyle: function(imgs){
       $each(imgs, function(item){
           item.setStyles({
               'visibility': 'hidden',
               'display': 'block',
               'position': 'absolute'
           });
       });
   },

   /* Add a image to the ImgSlideShow Object.
    *
    * @param {String} the imgages url.
    * @param {String} optional, the href url.
    * @param {Integer} optional, Insert the images to the possion of the imagesArray.
    */
   addImage: function(imgurl, href, where){
       var myhref = $pick(href, '#');
       // if the user defined the images in the HTML file, just clone the first image element, and configs it with the user setting.
       if(this.imagesArray.length){
           var aEl = this.imagesArray[0].getParent().clone();
           var newImageEl = aEl.getFirst();
           newImageEl.set('src', imgurl);
           aEl.set('href', myhref);
       }else{
           var newImageEl = new Element('img', {
               'src': imgurl
           });
           var aEl = new Element('a', {
               'href': myhref
           });
           aEl.grab(newImageEl);
       }
       this.setImgStyle([newImageEl]);
       if($chk(where)){
           var pos = parseInt(where);
           if(pos &gt;= 0 &amp;&amp; pos &lt; this.imagesArray.length){
               aEl.inject(this.imagesArray[pos].getParent(), 'before');
               this.imagesArray.splice(pos, 0, newImageEl);
               // Refresh the navigator bar buttons.
               this.addNavButton();
               return;
           }
       }
       this.imgContainer.grab(aEl);
       this.imagesArray.push(newImageEl);
       // Refresh the navigator bar buttons.
       this.addNavButton();
   },

   /* Remove the special image element.
    *
    * @param {Integer}
    */
   removeImage: function(index){
       var index = parseInt(index);
       if(!$chk(index) || index &lt; 0 || index &gt;= this.imagesArray.length){
           return;
       }
       this.imagesArray[index].getParent().dispose();
       this.imagesArray.splice(index, 1);
       this.addNavButton();
   },

   /* Add a navigator bar.
    */
   addNavBar: function(){
       var navBar = new Element('div', {
           'id': 'navBar0000'
       });
       navBar.setStyles({
           'position': 'absolute',
           'z-index': 100,
           'right': '5px',
           'bottom': '5px',
           'height': '20px',
           'width': (this.imgContainer.getSize().x - 20),
           'padding-right': 5,
           'overflow': 'hidden'
       });
       navBar.inject(this.imgContainer, 'top');

       this.navBar = navBar;

       this.addNavButton();
   },

   /* Add some buttons to the navigator bar, or refresh the buttons.
    *
    */
   addNavButton: function(){
       if($chk(this.navBar)){
           this.navBar.empty();
       }
       this.imagesArray.each(function(item, index){
           var newBn = new Element('div', {
               'class': 'navbnclass000'
           });
           newBn.setStyles({
               'float': 'right',
               'opacity': 0.5,
               'width': '20px',
               'height': '20px',
               'color': '#000',
               'background-color': this.options['navBnBgcolor'],
               'text-align': 'center',
               'line-height': '20px',
               'margin-right': '2px',
               'cursor': 'pointer',
               'font-weight': 'bold'
           });
           newBn.store('imgEl', item);     // Store the relative image element to the navigator bar button element.
           newBn.store('index', index);    // store the relative index of the image element to the navigator bar button element.
           item.store('bn', newBn);        //Store the relative navigator bar button element to the image element.
           // onClick event, just stop current animation, and resume from the new index.
           newBn.addEvent('click', function(e){
               e.stop();
               var targetEl = e.target;
               targetEl.setStyle('background-color', this.options['navBnHeightLight']);
               this.stop();
               this.action(targetEl.retrieve('index'));
           }.bind(this));
           newBn.appendText(index+1);
           newBn.inject(this.navBar, 'top');
       }, this);
   },

   /* Action the animation. Use recursion algorithm.
    *
    * @param {Integer} animate from the index.
    */
   action: function(index){
       var imagesArrayLength = this.imagesArray.length;
       if(imagesArrayLength&lt;2){
           return;
       }
       if($defined(index) &amp;&amp; (index &gt;= imagesArrayLength)){
           index = parseInt(index) % imagesArrayLength;
       }
       this.curentImgEl = this.imagesArray[index];
       this.curentImgEl.retrieve('bn').setStyle('background-color', this.options['navBnHeightLight']);
       this.curentImgEl.set('tween', {
            duration: 500
       }).fade('in').get('tween').chain(function(){
           this.timer = this.subAction.delay(this.options['delay'], this, index + 1);
       }.bind(this));
   },

   /* Used in the action function.
    *
    * @param {Integer} animate from the index.
    */
   subAction: function(index){
       this.curentImgEl.retrieve('bn').setStyle('background-color', this.options['navBnBgcolor']);
       this.curentImgEl.fade('out').get('tween').chain(function(){
           this.action(index);
       }.bind(this));
   },

   /* Stop the animation.
    */
   stop: function(){
       $clear(this.timer);
       this.curentImgEl.get('tween').cancel();
       this.curentImgEl.setStyle('visibility', 'hidden');
       this.curentImgEl.retrieve('bn').setStyle('background-color', this.options['navBnBgcolor']);
   },

   /* Pause the animation.
    *
    */
   pause: function(){
       $clear(this.timer);
       this.curentImgEl.get('tween').cancel();
       this.curentImgEl.setStyles({
           'visibility': 'visible',
           'opacity': 1
       });
   },

   /* Resume the animation.
    */
   resume: function(){
       $clear(this.timer);
       this.curentImgEl.get('tween').cancel();
       this.action(this.curentImgEl.retrieve('bn').retrieve('index'));
   }

});</pre>
</div>
<div id="id3" class="section">
<h1>用法示例</h1>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;Demo!&lt;/title&gt;
        &lt;script type="text/javascript" src="mootools-1.2.1.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript" src="imgslideshow2.js"&gt;&lt;/script&gt;
        &lt;script type="text/javascript"&gt;
            var imgSlideShow = new ImgSlideShow($('imgscontainer'), {delay:3000});
            imgSlideShow.addImage('imgs/2.jpg');
            imgSlideShow.addImage('imgs/3.jpg', '#', 4);
            imgSlideShow.removeImage(3);

           $('pausebn').addEvent('click', function(){
                imgSlideShow.pause();
           });

           $('resumebn').addEvent('click', function(){
                imgSlideShow.resume();
           });
        &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
    &lt;div id="imgscontainer"&gt;
        &lt;a href='#'&gt;&lt;img class='image' src="imgs/1.jpg"/&gt;&lt;/a&gt;
        &lt;a href='#'&gt;&lt;img class='image' src="imgs/2.jpg"/&gt;&lt;/a&gt;
        &lt;a href='#'&gt;&lt;img class='image' src="imgs/3.jpg"/&gt;&lt;/a&gt;
        &lt;a href='#'&gt;&lt;img class='image' src="imgs/4.jpg"/&gt;&lt;/a&gt;
        &lt;a href='#'&gt;&lt;img class='image' src="imgs/5.jpg"/&gt;&lt;/a&gt;
    &lt;/div&gt;
    &lt;div id="bns"&gt;
        &lt;button id="pausebn"&gt;Pause&lt;/button&gt;
        &lt;button id="resumebn"&gt;Resume&lt;/button&gt;
    &lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;</pre>
</div>
<div id="id4" class="section">
<h1>语法</h1>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">var myImgSlideShow = new ImgSlideShow(element, [, options]);</pre>
</div>
<div id="id5" class="section">
<h1>参数</h1>
<ul class="simple">
<li>element &#8211; 图片的容器对象。</li>
<li>options &#8211; 可选。如下的可选项</li>
</ul>
<div id="id6" class="section">
<h2>可选项</h2>
<ul class="simple">
<li>delay &#8211; 默认为3000（3秒）。设置图片的显示停留时间。</li>
<li>navBnBgcolor &#8211; 右下角导航按钮的背景颜色。</li>
<li>navBnHeightLight 导航按钮高亮时的背景颜色。</li>
</ul>
</div>
</div>
<div id="id7" class="section">
<h1>可用方法</h1>
<ul class="simple">
<li>addImage(imgurl, where) &#8211; 在 where 位置上添加一张图片。</li>
<li>removeImage(index) &#8211; 删除 index 位置上的图片</li>
<li>pause() &#8211; 暂停动画。</li>
<li>resume() &#8211; 重新开始动画。</li>
</ul>
</div>
<div id="id8" class="section">
<h1>兼容性</h1>
<p>支持 IE 6.0+, FF2+, Safari 3.1+, Opera 9.0+</p></div>
<div id="id9" class="section">
<h1>示例</h1>
<ul class="simple">
<li><a class="reference external" href="http://wstudio.web.fc2.com/product/imgslideshow2/index.html">http://wstudio.web.fc2.com/product/imgslideshow2/index.html</a></li>
</ul>
</div>
</div>
Posted in Ajax, Mootools Tagged: images slide show, Mootools, plugins <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/306/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/306/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/306/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=306&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/01/30/imgslideshow2-%e5%9f%ba%e4%ba%8e-mootools-%e7%9a%84%e5%9b%be%e7%89%87%e5%b9%bb%e7%81%af%e6%8f%92%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery: 表格排序插件</title>
		<link>http://mrwlwan.wordpress.com/2009/01/11/jquery-%e8%a1%a8%e6%a0%bc%e6%8e%92%e5%ba%8f%e6%8f%92%e4%bb%b6/</link>
		<comments>http://mrwlwan.wordpress.com/2009/01/11/jquery-%e8%a1%a8%e6%a0%bc%e6%8e%92%e5%ba%8f%e6%8f%92%e4%bb%b6/#comments</comments>
		<pubDate>Sun, 11 Jan 2009 08:38:04 +0000</pubDate>
		<dc:creator>Ross Wan</dc:creator>
				<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jtablesortable]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[table sortable]]></category>

		<guid isPermaLink="false">http://mrwlwan.wordpress.com/?p=304</guid>
		<description><![CDATA[这是本人写的一个简单的表格排序插件。支持字符串和数字的排序。

代码
/*
* jtablesortable plugin for jQuery。表格排序插件
*
* @author mrwlwan#gmail.com
*/
(function($){
    // 定义可排序的数据类型，以及所对应的排序方法
    var sortFuns = {
        'default': sortDefault,
        'string': sortDefault,
        'num': sortNum,
        'date': sortDefault,
 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=304&subd=mrwlwan&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>这是本人写的一个简单的表格排序插件。支持字符串和数字的排序。</p>
<div id="id1" class="section">
<h1>代码</h1>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">/*
* jtablesortable plugin for jQuery。表格排序插件
*
* @author mrwlwan#gmail.com
*/
(function($){
    // 定义可排序的数据类型，以及所对应的排序方法
    var sortFuns = {
        'default': sortDefault,
        'string': sortDefault,
        'num': sortNum,
        'date': sortDefault,
        'none': null
    };
    // 二维数组排序的默认比较函数
    function sortDefault(item1, item2){
        if(item1[1] == item2[1]){
            return 0;
        }
        if(item1[1] &gt; item2[1]){
            return 1;
        }
        if(item1[1] &lt; item2[1]){
            return -1;
        }
    }

    // 二维数组排序的数字比较函数
    function sortNum(item1, item2){
        item1[1] = parseFloat(item1[1]);
        item2[1] = parseFloat(item2[1]);
        return sortDefault(item1, item2);
    }

    // 表格排序函数
    function sortTable(jRows,sortFun, col, jThis){
        // 创建一临时的二维数组，元素数组的第一个元素是 jRows 行的索引，第二个元素是该行的 col 列的值
        var tempArray = [];
        for(var i=0;i&lt;jRows.length;i++){
            tempArray.push([i, $.trim(jRows.eq(i).children('td').eq(col).text())]);
        }
        // 对 tempArray 数组进行排序
        tempArray.sort(sortFun);
        // 重排表格行
        for(var i=0;i&lt;tempArray.length;i++){
            jRows.eq(tempArray[i][0]).appendTo(jThis);
        }
    }

    // 表格反转函数
    function reverseTable(jRows, jThis){
        $.each(jRows.get().reverse(), function(index, item){
            $(item).appendTo(jThis);
        });
    }

    //////////////////////////////////////////////////

    $.fn.extend({
        // 参数是可变的
        jtablesortable: function(){
            // 取得参数数组
            var args = arguments;
            // 设置当前 this 的一个引用。用于部分函数内部
            var jThis = this;

            // 设置 tr 对象样式
            this.find('tr').css({
                cursor: 'default'
                // 设置 thead 样式
            }).eq(0).css({
                cursor: 'pointer'
                //
            }).children().each(function(index, el){
                // 将当前项的索引保存到当前项对象的数据里
                $(el).data('col', index);
                // 取得当前项的排序方式
                var sortFun = 'default';
                if(index &lt; args.length &amp;&amp; ($.trim(args[index]) in sortFuns)){
                    sortFun = $.trim(args[index]);
                }
                // 如果为 none，表示当前项不进行排序操作
                if(sortFun == 'none'){
                    return;
                }
                // 将当前项的排序方式保存到当前项对象的数据里
                $(el).data('sortfun', sortFun);
                // 添加图标，并且处理单击事件
                $(el).append($('&lt;img class="itemimg000" src="bg.gif"/&gt;')).click(function(){
                    // 取得被单击项的索引值
                    var col = $(this).data('col');
                    // 取得当前表格的所有列
                    var jRows = jThis.children('tbody').children('tr');
                    // 取出 this 对象 sortcol 里的值，并判断是否该列上次进行排序过。如果是，则直接调用表格反转函数
                    if(jThis.data('sortcol') == col){
                        // 处理图标。先对当前排序是升序还是降序当出判断
                        var desc = $(this).data('desc');
                        var sortImg = desc ? 'asc.gif' : 'desc.gif';
                        $(this).children('.itemimg000').attr('src', sortImg);
                        $(this).data('desc', !desc);
                        // 反转表格
                        reverseTable(jRows, jThis);
                        return;
                    }
                    // 处理图标
                    $(this).parent('tr').children('td, th').eq(jThis.data('sortcol')).children('.itemimg000').attr('src', 'bg.gif');
                    $(this).children('.itemimg000').attr('src', 'desc.gif');
                    // 设置当前为降序
                    $(this).data('desc', true);
                    // 将当前列的索引保存到 jThis 对象的数据里
                    jThis.data('sortcol', col);

                    // 进行排序
                    sortTable(jRows, sortFuns[$(this).data('sortfun')], col, jThis);
                });
            });
        }
    });
})(jQuery);</pre>
</div>
<div id="id2" class="section">
<h1>用法</h1>
<pre class="literal-block" style="margin-left:2em;margin-right:2em;background-color:#e8e9ea;">$('#tableid').jtablesortable('default', 'num', 'string', 'date', 'num', 'none');</pre>
<p>参数指定对应列的数据类型，插件会根据不用的数据类型选择不同的方法来进行排序。支持的类型有 default(默认的字符串排序方法)、string(字符串)、num(数字)、date(日期)。还有一个是 none，表示对应列不进行排序。</p>
<p>注： 某数据类型还未实现，可能在以后会跟进。</p></div>
<div id="id3" class="section">
<h1>兼容性</h1>
<p>支持 IE 6.0+, FF2+, Safari 3.1+, Opera 9.0+ 。</p></div>
<div id="id4" class="section">
<h1>示例</h1>
<ul class="simple">
<li><a class="reference external" href="http://wstudio.web.fc2.com/product/jtablesortable/index.html">http://wstudio.web.fc2.com/product/jtablesortable/index.html</a></li>
</ul>
</div>
Posted in Ajax, Javascript, jQuery Tagged: jQuery, jtablesortable, plugins, table sortable <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mrwlwan.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mrwlwan.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mrwlwan.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mrwlwan.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mrwlwan.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mrwlwan.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mrwlwan.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mrwlwan.wordpress.com/304/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mrwlwan.wordpress.com/304/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mrwlwan.wordpress.com/304/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mrwlwan.wordpress.com&blog=1448775&post=304&subd=mrwlwan&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://mrwlwan.wordpress.com/2009/01/11/jquery-%e8%a1%a8%e6%a0%bc%e6%8e%92%e5%ba%8f%e6%8f%92%e4%bb%b6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/dd10defb7c99b243726f7b892be03ffc?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Ross Wan</media:title>
		</media:content>
	</item>
	</channel>
</rss>