??xml version="1.0" encoding="utf-8" standalone="yes"?>
Understanding Your Own Footprint
理解你自q
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.
每一个有用的pȝ留下它的设计师的烙印。从桥梁到勺子,一个徏造者技巧的表达Q哲学家Q和产品U束在最l的产品中被暴露。Y件是不同的,除了它的变化的們。在用户需要的反应中的软g变异Q和在那U改变中Q一个连l的重复的不可能的一个设计师的技巧和呌产生?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.
q是为其他生持l问题的本质Q是他们最l用h其他开发者。减这些q斚wQ认知的负荷Q允许每一U类型的软g消费者感觉更好关于一些代码。伴随每一ơ交互,他们的预设想的概忉|q些东西如何q{服务他们而不是组成一个ؓ他们跨越的障。他们的本能是通过优美和一贯地设计的Y件变成一个有价值的工具?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.
DojoQ作Z个项目,应该满q样的期望。这不意呌你不得不同意每一个设计决定,卛_已经向项目中q入Q不同意是健LQ或者那写入矛_中的导向原理轮廓。他们应该是Q然而,捕捉设计选择的方法已l提到日E和作ؓ未来军_的向对{?br />
Dojo Guiding Principles
Dojo的设计导向原?/strong>
Reduce barriers to adoption.
采用减少障碍物?br />Simply put, do not give users reasons not to choose your code. This affects everything from design to licensing to packaging.
单放|,但是不给用户不用你代码的原因。这影响从设计到专利的包装的每g事情?br />Simple first, fast later
单优先,快在?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.
首要的简单用,当它是适合的将它打上结?单这里意呌对用L单,不是Ҏ们。我们应该工作Ҏl用户尽可能的变得简单。这些原则定位在采用减少障碍的原则。事情应该尽可能Ҏ对共同的情Ş但是明显“可升的”对一个快速的代码路径 如果l端用户惌了解执行的表盘和旋钮?br />Bend to the constraints of your environment
混合你环境的U束
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.
不要击一个问题来伴随代码M。如果这个环境可以做大部分是事情Q让它做。尽可能替代Q不要重新发明。对用户来说\径^滑,当他们不需要的地方不要介绍你自q方言?br />
Improving From Here
从这里改q?/strong>
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.
Dojo可能没有完全包含q里轮廓的原则,但它是当描述q些事情应该如何改变,他们作ؓ一个向导对目来服务的目的?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.
如果你认为Dojoq没有满_特定Ҏ中的一个或多个q些目标Q请提出一个issue在一个项目邮件列表或文g作ؓ一个bug?br />
]]>
HTML forms.
Second, the requests themselves are asynchronous,meaning that the
contextual links, zoom control , and the other page features remain
accessible while the map is gathering new data.
The four main components of Ajax:Javascript defines business rules and
program flow. The Document Object Model and Cascading Style Sheets allow
the application to reorgnize its appearance in response to data feteched in
the background from the server by the XMLHttpRequest object or its close
cousins.
We've hightlighted a few more here , to demonstrate the breadth of concerns
to which CSS can be applied:
(1)on-screen placement
(2)texturing elements
(3)assisting in layout of elements
(4)placing text relative to accompanying graphics
The DOM presents an HTML document as a tree structure , with each element
representing a tag in the HTML markup.
Working with the DOM using Javascript
An Example:
window.onload=function(){
var hello=document.getElementById('hello');
hello.className='declared';
var empty = document.getElementById('empty');
addNode(empty,"reader of");
addNode(empty,"Ajax in action");
var children = empty.childNodes;
for (var i=0;i<children.length;i++){
children[i].className='programmed';
}
empty.style.border='solid green 2px';
empty.style.width='200px';
}
function addNode(el,text){
var childEl = document.createElement('div'); --create new element
el.appendChild(childEl);
var txtNode=document.createTextNode(txt); --create text element
childEl.appendChild(txtNode);
}
A third method worth mentioning allows us to make a shortcut through
documets that we haven't tagged with unique IDs. DOM nodes can also be
searched for based on their HTML tag type,usinf getElementByTagName(). For
example , document.getElementByTagName('UL') will return an array of all
<UL> tags in the document.
FINDING A DOM NODE
CREATING A DOM NODE
Adding styles to your document:
hello.className='declared';
empty.style.border="solid green 2px";
innerHTML
refactoring 重构
Working with DOM elements
A web page is exposed to Javascript through the Document Object Model
(DOM),a tree-like structure whose elements correspond to the tags of an
HTML document. When manipulating a DOM tree progarmmatically ,it is quite
common to want to find out an element's position on the page.
Unfortunately,browser vendors have provided various nonstandard methods for
doing so over the years,making it diffcult to write fail-safe cross-browser
code to accommplish the task.
window.onloadListeners = new Array();
window.addOnLoadListener(listener){
window.onloadListener[window.onloadListeners.length]=listener;
}
window.onload=function(){
for(var i=0;i<window.onloadListeners.length;i++){
var func = window.onloadListeners[i];
}
}
//------------------------------------------
Reusing user action handlers:命o模式
function buttonOnClickHandler(event){
var data = new Array();
data[0]=6;
data[1]=data[0]/3;
data[2]=data[0]*data[1]+7;
var newRow = createTableRow(dataTable);
for (var i=0;i<data.length;i++){
createTableCell(newRow,data[i]);
}
}
buttonDiv.onclick=buttonOnClickHandler;
//------------------------------------
Keeping only one reference to a resource:Singleton pattern
function TradingMode(){
this.mode=MODE_RED;
}
TradingMode.prototype.setMode=function(){
}
TradingMode.instance = new TradingMode();
var TradingMode={
mode:MODE_RED,
setMode:function(){
...
}
};
Z模板的系l:
Prototype:
Prototype是一个ؓJavascript~程提供多用途的助手cdQ用一个导向扩?/P>
Javascript语言自己支持一个OO~程方式。Prototype有一个有特色的Javascript~码
样式Q基于这些已l增加的语言Ҏ。虽然Prototype~码自n很难阅读Q从Java/C#/
样式中被U除存在很久了,使用PrototypeQ和内徏在它上的Q是直接的。Prototype
可以考虑为类开发者提供类。AJax应用E序作者更多希望用类建立c而不是?/P>
Prototype自n。我们将查询q些cd下面的部分中。在期间Q一个主要的关于
Prototype核心的特性讨论将帮助介绍它自w的~码的样式和在我们讨论
Scriptaculous、Rico和Rubt on Rail.
Prototype允许一个对象扩展通过复制所有的父对象的属性和Ҏl子其他。这?/P>
Ҏ是最好的举个例子,让我们看一下定义的Vehicle父类
function Vehicle(numWheels,maxSpeed){
this.numWheels = numWheels;
this.maxSpeed = maxSpeed;
}
Ҏ我们惌定义一个精的实例来表C个乘客列车。在我们的子cM我们也想?/P>
现客车的数量q支持增加或减少的机制。在常用的Javascript中,我们可能q样写:
var passTrain = new Vehicle(24,100);
passTrain.carriageCount = 12;
passTrain.addCarriage = function(){
this.carriageCount++;
}
passTrain.removeCarriage=function(){
this.carriageCount--;
}
qؓ我们的PassTrain对象提供需要的功能性。从设计的视囄查看q些代码Q虽然它
有点掩饰了扩展扩展性功能性到一个连贯的单元。Prototyp可以在这里帮助我们,?/P>
q允许我们定义扩展行ZZ个对象ƈ且接着使用它扩展基对象。首先,我们?/P>
Z个对象定义扩展的功能性:
function CarriagePuller(carriageCount){
this.carriageCount = carriageCount;
this.addCarriage=function(){
this.carriageCount++;
}
this.removeCarriage=function(){
this.carriageCount--;
}
}
接着我们合ƈq两个来支持一个对象包含所有的需要的行ؓQ?BR>var parent = new Vehicle(24,100);
var extension = new CarriagePuller(12);
var passTrain = Object.extend(parent,extension);
注意我们分别在开始后来定义父和扩展对象,接着他们进行合。这父子关系存在
q些例中Q不在Vehicle和CarriagePullercM。当它不是正的l典的面向对象,?/P>
允许我们保持我们代码与系l功能进行关联,在这个拉车按例中Q在一个地方,通过
在我们更Ҏq行复用。我们做q个例子看v来似乎没有什么用处,在大的项目中Q?/P>
用这U方法封装功能性是非常有用的?/P>
Prototype也以AJax对象的方式提供对Ajax支持Q这可以解决^台XMLHttpRequest?/P>
象。Ajax是被Ajax.Requestcd扩展Q它可以使用XMLHttpRequest向服务器发送请?/P>
Q例如: var req = new Ajax.Request('myData.xml');
q个构造子使用一个我们也要看到的在很多Prototype-basedcd中的样式。它使用
l合的数l来作ؓ一个可选的参数Q允怸个宽范围的按照需要进行配|?/P>
Ajax.Updater
The View in an Ajax application
Keepling the logic out of the View View分离出logic
间接使用CSS增加事g
l定事g控制代码
The Rico framework has a concept of Behavior objects that target specific
sections of a DOM tree and add interactivity to them.
Keeping the view out of logic