﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-java神谕-随笔分类-Ajax</title><link>http://www.blogjava.net/javaora/category/7731.html</link><description /><language>zh-cn</language><lastBuildDate>Tue, 27 Feb 2007 09:19:51 GMT</lastBuildDate><pubDate>Tue, 27 Feb 2007 09:19:51 GMT</pubDate><ttl>60</ttl><item><title>Dojo的设计哲学</title><link>http://www.blogjava.net/javaora/archive/2006/07/07/57156.html</link><dc:creator>java世界畅谈</dc:creator><author>java世界畅谈</author><pubDate>Fri, 07 Jul 2006 08:46:00 GMT</pubDate><guid>http://www.blogjava.net/javaora/archive/2006/07/07/57156.html</guid><wfw:comment>http://www.blogjava.net/javaora/comments/57156.html</wfw:comment><comments>http://www.blogjava.net/javaora/archive/2006/07/07/57156.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/javaora/comments/commentRss/57156.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/javaora/services/trackbacks/57156.html</trackback:ping><description><![CDATA[Dojo的设计哲学<br /><br /><strong>Understanding Your Own Footprint<br />理解你自己的足迹</strong><br />Every useful system carries the imprint of its designers. From bridges to spoons, the expression of a builder's skill, philosophies, and production constraints are exposed in the final product. Software is no different, except in its propensity to change. Software mutates in response to users needs, and in that change, a continual re-impriting of a designer's skill and sense of taste takes place.<br />每一个有用的系统留下它的设计师的烙印。从桥梁到勺子，一个建造者技巧的表达，哲学家，和产品约束在最终的产品中被暴露。软件是不同的，除了它的变化的倾向。在用户需要的反应中的软件变异，和在那种改变中，一个连续的重复的不可能的一个设计师的技巧和味觉产生。<br />This has the potential to cause continuity problems for others, be they end users or other developers. Reducing these confusing aspects (cognitive load) allows software consumers of every type to feel better about a block of code. With every interaction, their pre-conceived notions of how the thing will behave serve them instead of forming an obstacle for them to overcome. Their instincts are turned into a valuable tool by elegantly and consistently designed software.<br />这是为其他产生持续问题的本质，是他们最终用户或其他开发者。减少这些混乱的方面（认知的负荷）允许每一种类型的软件消费者感觉更好关于一些代码。伴随每一次交互，他们的预设想的概念是这些东西如何运转服务他们而不是组成一个为他们跨越的障碍。他们的本能是通过优美和一贯地设计的软件变成一个有价值的工具。<br />Dojo, as a project, should meet expectations in this way. This doesn't mean that you have to agree with every design decision that's been made in the project (dissent is healthy) or that the guiding principles outlined here are written in stone. They should, however, capture the way design choices have been made to date and serve as a guide for making future decisions.<br />     Dojo，作为一个项目，应该满足这样的期望。这不意味这你不得不同意每一个设计决定，即它已经向项目中进入（不同意是健康的）或者那写入石头中的导向原理轮廓。他们应该是，然而，捕捉设计选择的方法已经提到日程和作为未来决定的向导。<br /><br /><strong>Dojo Guiding Principles<br />Dojo的设计导向原则</strong><br />Reduce barriers to adoption. <br />采用减少障碍物。<br />Simply put, do not give users reasons not to choose your code. This affects everything from design to licensing to packaging. <br />简单放置，但是不给用户不使用你代码的原因。这影响从设计到专利的包装的每件事情。<br />Simple first, fast later <br />简单优先，快在后<br />Make it simple to use first, make it fast when it's approprite. Simple here means simple for users, not for us. We should work as hard as necessary to make things simple for end users. This principle goes to reducing barriers to adoption. Things should be as easy as possible for the common case but transparently "upgradeable" to a faster code path if the end user is willing to learn about the performance dials and knobs. <br />首要的简单使用，当它是适合的将它打上结。 简单这里意味这对用户简单，不是对我们。我们应该使工作对最终用户尽可能的变得简单。这些原则定位在采用减少障碍的原则。事情应该尽可能容易对共同的情形但是明显“可升级的”对一个快速的代码路径 如果终端用户想要了解执行的表盘和旋钮。<br />Bend to the constraints of your environment <br />混合你环境的约束<br />Do not bludgeon a problem to death with code. If the environment can do most of something, let it. Fill in as necessary, but do not re-invent. Make the path smooth for users, but do not introduce your own idioms where they aren't required. <br />不要棒击一个问题来伴随代码死亡。如果这个环境可以做大部分是事情，让它做。尽可能替代，不要重新发明。对用户来说将路径平滑，当他们不需要的地方不要介绍你自己的方言。<br /><br /><strong>Improving From Here<br />从这里改进</strong><br />Dojo may not yet completely embody the principles outlined here, but it is their purpose to serve as a guide for the project when making determinations how things should change.<br />Dojo可能没有完全包含这里轮廓的原则，但它是当描述这些事情应该如何改变,他们作为一个向导对项目来服务的目的。<br />If you think that Dojo has not yet met one or more of these goals in a particular way, please raise the issue on one of the project mailing lists or file a bug.<br />如果你认为Dojo还没有满足在特定方法中的一个或多个这些目标，请提出一个issue在一个项目邮件列表或文件作为一个bug。<br /><img src ="http://www.blogjava.net/javaora/aggbug/57156.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/javaora/" target="_blank">java世界畅谈</a> 2006-07-07 16:46 <a href="http://www.blogjava.net/javaora/archive/2006/07/07/57156.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ajax in acion 阅读笔记(1)</title><link>http://www.blogjava.net/javaora/archive/2006/02/22/31996.html</link><dc:creator>java世界畅谈</dc:creator><author>java世界畅谈</author><pubDate>Wed, 22 Feb 2006 10:55:00 GMT</pubDate><guid>http://www.blogjava.net/javaora/archive/2006/02/22/31996.html</guid><wfw:comment>http://www.blogjava.net/javaora/comments/31996.html</wfw:comment><comments>http://www.blogjava.net/javaora/archive/2006/02/22/31996.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/javaora/comments/commentRss/31996.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/javaora/services/trackbacks/31996.html</trackback:ping><description><![CDATA[<P>A&nbsp; web browser provides two input mechanisms out of the box:hyperlinks and </P>
<P>HTML forms.</P>
<P>Second, the requests themselves are asynchronous,meaning that the </P>
<P>contextual links, zoom control , and the other page features remain </P>
<P>accessible while the map is gathering new data.</P>
<P>The four main components of Ajax:Javascript defines business rules and </P>
<P>program flow. The Document Object Model and Cascading Style Sheets allow </P>
<P>the application to reorgnize its appearance in response to data feteched in </P>
<P>the background from the server by the XMLHttpRequest object or its close </P>
<P>cousins. </P>
<P>We've hightlighted a few more here , to demonstrate the breadth of concerns </P>
<P>to which CSS can be applied:<BR>(1)on-screen placement<BR>(2)texturing elements<BR>(3)assisting in layout of elements<BR>(4)placing text relative to accompanying graphics</P>
<P>The DOM presents an HTML document as a tree structure , with each element </P>
<P>representing a tag in the HTML markup.</P>
<P><BR>Working with the DOM using Javascript</P>
<P>An Example:<BR>window.onload=function(){<BR>&nbsp;&nbsp; var hello=document.getElementById('hello');<BR>&nbsp;&nbsp; hello.className='declared';</P>
<P>&nbsp;&nbsp; var empty = document.getElementById('empty');<BR>&nbsp;&nbsp; addNode(empty,"reader of");<BR>&nbsp;&nbsp; addNode(empty,"Ajax in action");</P>
<P>&nbsp;&nbsp; var children = empty.childNodes;<BR>&nbsp;&nbsp; for (var i=0;i&lt;children.length;i++){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; children[i].className='programmed';<BR>&nbsp;&nbsp; }<BR>&nbsp;&nbsp; <BR>&nbsp;&nbsp; empty.style.border='solid green 2px';<BR>&nbsp;&nbsp; empty.style.width='200px';<BR>}</P>
<P>function addNode(el,text){<BR>&nbsp;&nbsp; var childEl = document.createElement('div'); --create new element<BR>&nbsp;&nbsp; el.appendChild(childEl);<BR>&nbsp;&nbsp; var txtNode=document.createTextNode(txt); --create text element<BR>&nbsp;&nbsp; childEl.appendChild(txtNode);<BR>}</P>
<P>A third method worth mentioning allows us to make a shortcut through </P>
<P>documets that we haven't tagged with unique IDs. DOM nodes can also be <BR>searched for based on their HTML tag type,usinf getElementByTagName(). For </P>
<P>example , document.getElementByTagName('UL') will return an array of all </P>
<P>&lt;UL&gt; tags in the document.</P>
<P>FINDING A DOM NODE<BR>CREATING A DOM NODE</P>
<P>Adding styles to your document:<BR>hello.className='declared';<BR>empty.style.border="solid green 2px";</P>
<P><BR>innerHTML</P>
<P>refactoring 重构</P>
<P>Working with DOM elements<BR>A web page is exposed to Javascript through the Document Object Model</P>
<P>(DOM),a tree-like structure whose elements correspond to the tags of an </P>
<P>HTML document. When manipulating a DOM tree progarmmatically ,it is quite </P>
<P>common to want to find out an element's position on the page. </P>
<P>Unfortunately,browser vendors have provided various nonstandard methods for </P>
<P>doing so over the years,making it diffcult to write fail-safe cross-browser </P>
<P>code to accommplish the task. </P>
<P>window.onloadListeners = new Array();<BR>window.addOnLoadListener(listener){<BR>&nbsp;&nbsp; window.onloadListener[window.onloadListeners.length]=listener;<BR>}</P>
<P>window.onload=function(){<BR>&nbsp;&nbsp; for(var i=0;i&lt;window.onloadListeners.length;i++){<BR>&nbsp;&nbsp;&nbsp;&nbsp; var func = window.onloadListeners[i];<BR>&nbsp; }<BR>}</P>
<P>//------------------------------------------<BR>Reusing user action handlers:命令模式</P>
<P>function buttonOnClickHandler(event){<BR>&nbsp; var data = new Array();<BR>&nbsp; data[0]=6;<BR>&nbsp; data[1]=data[0]/3;<BR>&nbsp; data[2]=data[0]*data[1]+7;<BR>&nbsp; var newRow = createTableRow(dataTable);<BR>&nbsp; for (var i=0;i&lt;data.length;i++){<BR>&nbsp;&nbsp;&nbsp;&nbsp; createTableCell(newRow,data[i]);<BR>&nbsp; }<BR>}<BR>buttonDiv.onclick=buttonOnClickHandler;</P>
<P>//------------------------------------<BR>Keeping only one reference to a resource:Singleton pattern</P>
<P>function TradingMode(){<BR>&nbsp; this.mode=MODE_RED;<BR>}</P>
<P>TradingMode.prototype.setMode=function(){</P>
<P>}</P>
<P>TradingMode.instance = new TradingMode();</P>
<P>var TradingMode={<BR>&nbsp;&nbsp; mode:MODE_RED,<BR>&nbsp;&nbsp; setMode:function(){<BR>&nbsp;&nbsp;&nbsp; ...<BR>&nbsp;&nbsp; }<BR>};</P>
<P>基于模板的系统：</P>
<P><BR>Prototype:<BR>Prototype是一个为Javascript编程提供多用途的助手类库，使用一个导向扩展</P>
<P>Javascript语言自己支持一个OO编程方式。Prototype有一个有特色的Javascript编码</P>
<P>样式，基于这些已经增加的语言特性。虽然Prototype编码自身很难阅读，从Java/C#/</P>
<P>样式中被移除存在很久了，使用Prototype，和内建在它上的，是直接的。Prototype</P>
<P>可以考虑为类开发者提供类。AJax应用程序作者更多希望使用类建立类而不是使用</P>
<P>Prototype自身。我们将查询这些类在下面的部分中。在期间，一个主要的关于</P>
<P>Prototype核心的特性讨论将帮助介绍它自身的编码的样式和将在我们讨论</P>
<P>Scriptaculous、Rico和Rubt on Rail.<BR>　　Prototype允许一个对象扩展通过复制所有的父对象的属性和方法给子其他。这个</P>
<P>特性是最好的举个例子,让我们看一下定义的Vehicle父类<BR>function Vehicle(numWheels,maxSpeed){<BR>&nbsp; this.numWheels = numWheels;<BR>&nbsp; this.maxSpeed = maxSpeed;<BR>}</P>
<P>对此我们想要定义一个精确的实例来表现一个乘客列车。在我们的子类中我们也想表</P>
<P>现客车的数量并支持增加或减少的机制。在常用的Javascript中，我们可能这样写：</P>
<P>var passTrain = new Vehicle(24,100);<BR>passTrain.carriageCount = 12;<BR>passTrain.addCarriage = function(){<BR>&nbsp; this.carriageCount++;<BR>}<BR>passTrain.removeCarriage=function(){<BR>&nbsp; this.carriageCount--;<BR>}</P>
<P>这为我们的PassTrain对象提供需要的功能性。从设计的视图的查看这些代码，虽然它</P>
<P>有点掩饰了扩展扩展性功能性到一个连贯的单元。Prototyp可以在这里帮助我们，通</P>
<P>过允许我们定义扩展行为作为一个对象并且接着使用它扩展基础对象。首先，我们作</P>
<P>为一个对象定义扩展的功能性：</P>
<P>function CarriagePuller(carriageCount){<BR>&nbsp; this.carriageCount = carriageCount;<BR>&nbsp; this.addCarriage=function(){<BR>&nbsp;&nbsp;&nbsp; this.carriageCount++;<BR>&nbsp; }<BR>&nbsp; this.removeCarriage=function(){<BR>&nbsp;&nbsp; this.carriageCount--;<BR>&nbsp;}<BR>}</P>
<P>接着我们合并这两个来支持一个对象包含所有的需要的行为：<BR>var parent = new Vehicle(24,100);<BR>var extension = new CarriagePuller(12);<BR>var passTrain = Object.extend(parent,extension);</P>
<P>注意我们分别在开始后来定义父和扩展对象，接着将他们进行混合。这父子关系存在</P>
<P>这些例中，不在Vehicle和CarriagePuller类中。当它不是正确的经典的面向对象，它</P>
<P>允许我们保持我们代码与系统功能进行关联，在这个拉车按例中，在一个地方，通过</P>
<P>在我们更容易进行复用。我们做这个例子看起来似乎没有什么用处，在大的项目中，</P>
<P>用这种方法封装功能性是非常有用的。</P>
<P>Prototype也以AJax对象的方式提供对Ajax支持，这可以解决超平台XMLHttpRequest对</P>
<P>象。Ajax是被Ajax.Request类型扩展，它可以使用XMLHttpRequest向服务器发送请求</P>
<P>，例如： var req = new Ajax.Request('myData.xml');</P>
<P>这个构造子使用一个我们也将要看到的在很多Prototype-based类库中的样式。它使用</P>
<P>结合的数组来作为一个可选的参数，允许一个宽范围的按照需要进行配置。</P>
<P>Ajax.Updater</P>
<P><BR>The View in an Ajax application<BR>Keepling the logic out of the View 将View分离出logic<BR>间接使用CSS增加事件<BR>绑定事件控制代码</P>
<P><BR>The Rico framework has a concept of Behavior objects that target specific </P>
<P>sections of a DOM tree and add interactivity to them.</P>
<P>Keeping the view out of logic</P>
<P>&nbsp;</P><img src ="http://www.blogjava.net/javaora/aggbug/31996.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/javaora/" target="_blank">java世界畅谈</a> 2006-02-22 18:55 <a href="http://www.blogjava.net/javaora/archive/2006/02/22/31996.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>