??xml version="1.0" encoding="utf-8" standalone="yes"?> In software development, a framework is a defined
support structure in which other project can be organized and
developed. A framework typically consists of several smaller
components; support programs, libraries, and a scripting language.
There may also be other software involved to aid in development and
meshing of the different components of a project. As you can see, dojo
could be part of a framework, but it isn't a framework in itself. 在Y件开发中Q一个框架是一个被定义的支持结构,在其中其他项目可以被l织和开发。一个框架代表性地包含需要小的组件、支持程序、类库、和一个脚?
语言。这些也可能是其他Y件包括帮助开发和不同的项目组件编制。如你看到的Qdojo可能是框架的一部分Q但是本质上它本w不是一个框架?br /> A
library is defined as a collection of related functions and subroutines
used to develop software. They are distinguished from executables in
that they are not independant programs; rather, they are "helper" code
that provide access to common functions in one easy to manage location.
After reading this you are probably saying, "Hey! dojo is a collection
of libraries!", and you would be correct; however, dojo is much more
than just a collection of libraries. Now on to
toolkits. A toolkit is generally used in reference to graphical user
interface (GUI) toolkits. Basically, a library that is mainly focused
on creating a GUI. Yes, dojo could also fall under this category, in
fact our name implies it. Why do we call dojo a toolkit? Certainly not
because it focuses mainly on GUI development, right? Well quite simply,
because dojo is so much more than just a collection of libraries. 现在说说toolkits.
一个工具通常被用在参考图形用L面工兗基圎ͼ一个类库主要集中在创徏一个GUI。是圎ͼdojo可被归入q个cdQ实际上我们命名暗示了它Qؓ什?
我们叫dojo是一个工P当然不是因ؓ它主要集中在GUI开发,正确么?很好Q其实很单,因ؓpojo不仅仅是一个库的集合?br />LibraryQ库Q?/h2>
库被定义Z个相兛_能和被用来开发Y件的子程序的集合。他们区别于执行Q在其中他们不是独立的程序;更适合的,他们是“助手”代码,用来支持通过通用
成ؓ一体的功能Ҏ来进行管理。在dq些Q你可能_“嗨Qdojo是一个库的集合”,你可能是正确的,然而,dojo不仅仅是做ؓ一个库的集合?br />ToolkitQ工P
]]>
Dojo是一个用Javascript~写的开源DHTML工具。它建立于很多已捐献的代码基QnWidgets、Burstlib、f(m)Q?q?
是ؓ什么我们谈到它有时是一?l一"的工兗Dojo致力于解决一些长期存在的伴随DHTML的历史问题,阻止大多数采用动态web应用E序开发?br />
Dojo allows you to easily build dynamic capabilities into web pages and any other environment that supports JavaScript
sanely. You can use the components that Dojo provides to make your web
sites more useable, responsive, and functional With Dojo you can build
degradeable user interfaces more easily, prototype interactive widgets
quickly, and animate transitions. You can use the lower-level APIs and
compatibility layers from Dojo to write portable JavaScript
and simplify complex scripts. Dojo's event system, I/O APIs, and
generic language enhancement form the basis of a powerful programming
environment. You can use the Dojo build tools to write command-line
unit-tests for your JavaScript
code. You can use the Dojo package system to make your code easier to
maintain and less platform dependent. The Dojo build process helps you
optimize your JavaScript for deployment by grouping sets of files together and reuse those groups through "profiles".
Dojo允许你容易地建立动态性能到web面和其他稳健支持javascript地环境中?你可以用Dojo支持lgQ它使你的web站点更有可用行的。伴随dojo,你可以更Ҏ地徏立degradeable用户界面Q迅速地原型交互Cg和动画{变。你可以使用底层地api和兼容层Q从Dojo到写M的Javascript和简单复杂教本。Dojo的事件系l,I/O api,和泛型语a增强l成强大的程序环境的基础?你可以用dojo建造工hZ的Javascript代码写命令行单元试。你可以使用Dojo 包系l来使得你的代码更容易去l护和更^C赖?Dojo建造过E帮助你优化你的JavascriptZ的部|Ԍ它通过一起分l文仉合和通过"profile"重用q些l?
Dojo
does all of these things by layering capabilities onto a very small
core which provides the package system and little else. When you write
scripts with Dojo, you can include as little or as much of the
available APIs as you need to suit your needs. Dojo provides MultiplePointsOfEntry, InterpreterIndependence, ForwardLookingAPIs, and focuses on ReducingBarriersToAdoption.
Dojo处理所有这些事情,通过分层能力分解成一些非常小的和核心Q它支持包系l和其他更少的。单你写是用Dojo写脚本,你可以包含作为很或
者同样多可用的api作ؓ你需要满你的需要的。Dojo支持MutiplePointsOfEntry,
InterprerterIndependence, ForwardLookingAPIs,
和集中ReducingBarriersToAdoption.
Dojo
is being built around a single markup language that will provide
application authors with a (more) simple way of declaring and using
responsive DHTML interface components. Renderings may be made available
in several rendering contexts (such as SVG, or perhaps even the desktop
or Flash), but the markup language (DojoML) and scripting language (JavaScript) will not change. Better yet, the DojoML parser accepts extended HTML and SVG as valid input, and can be used to easily create DegradeableResponsiveApplications.
Dojo是一个被建造在一个单一的标记语aQ它支持应用程序作者采用一个(多个Q简单方法来声明和用作出响应的DHTML界面lg。表现在许多表现上下??
如:SVGQ或甚至可能桌面或flash)可能被合法化,但是标记语言(DojoML)和脚本语aQJavascriptQ将不改变。然而更好的Q?
DojoML
解析器接受已扩展的HTML和SVG作ؓ一个合法的输入Qƈ且可以被Ҏ的创建DegradeableResponsiveApplications.
Web Standards are a three-legged stool, or without metaphors(暗喻), a threesomeQ三Zl) of technologies that should live together in harmonyQ和睦相处). (X)HTML adds structure and semantics to your content, CSS is responsible for Qؓ...负责Qits presentation, and the DOM provides an interface to add behavior. You keep your Web pages flexible (or: easier to understand, maintain, restyle<改变样式> and update behavior) by separating all three layers; structure and content from presentation, structure and content from behavior and presentation from behavior. To accomplish this, try to avoid inline behavior and use unobtrusive techniques instead.
主要表述了三U技术的l合使用Qhtml为细节结构和语法 css现负?nbsp; dom支持增加事g行ؓ的接口?/P>
When you attach behavior on page load, you may have to work around some known issues. First, you may encounter differences in cross-browser event handling. Second, make sure you don't overwrite existing onload handlers. Last, but not least, you may encounter a delay in the attachment of your behavior. The underlying Q潜在的Qproblem is that a window onload event will only execute after the whole document, including all page assets like images and objects, is loaded. If your script needs to respond immediately after an element has loaded or if you work with a lot of content, a series of images or a slow server, you may be forced to look for a solution. You can either hide your content until the behavior is attached or attach the behavior via a script call after your elements are loaded, like at the end of the body element.
介绍在页面开发中主要遇到的问题!
Choose your markup wisely, so you can take full advantage of the power of the DOM.<充分利用dom的力?gt; For example, when you use nested lists to build a navigation bar, you can use the structure of the DOM tree instead of a replicated(复制) structure in arrays.<list dom tree> Scripting should be avoided in some cases where you can use markup or CSS to create behavior. This may sound a bit contradictory(反对), however built-in behavior enabled by (X)HTML attributes (e.g. disabling a form field or setting a max length on an input field) and CSS pseudo-classes (e.g. when building rollovers or drop downs) are regarded to be wider supported and easier to implement than using JavaScript. ToughQuiz on Quirksmode illustrates the discussion and the fine line between the uses of CSS generated content and regular markup and behavior.
In those cases where CSS currently lacks<~Z> cross-browser support or is missing features for adding presentation, DOM based scripting can supplement<补充> CSS. Presentational scripting will probably be replaced in a few years, when browsers have better CSS2.1 compliance<Z> and with the support of CSS3. Please realize that, because of the interrelationship<怺影响> of the different Web Standards and because both Web Standards and Web clients are constantly evolving<q化>, some good practices for using the DOM and JavaScript will change over time<随着旉的过?gt;.
JavaScript is accessible when a page's navigation, content and main functionality (e.g. submitting a form) is available to your whole target audience, independent of their Web client or input device. This includes:
The most common way to create accessible JavaScript is to use unobtrusive techniques that are mouse independent and enhance your already accessible markup with behavior. Progressive enhancement and its predecessor graceful degradation are good strategies to create Web pages that are accessible to the most common denominator, while providing a better user experience for a smaller group of people with more advanced devices or Web clients. No matter what strategy you use, make sure that you always design for multiple scenarios.
The usability of a Web page is often determined by a good information architecture, clear and intuitive(直觉? visual design and well designed functionality. One of the main arguments to enhance your markup using unobtrusive JavaScript is to improve the usability of a Web page by supporting these usability attributes. If you add JavaScript and don't enhance the usability of a Web page, you should rethink if you should apply it at all.
Unobtrusive scripting bridges the gap between 'designers' and 'coders'. There is a big group of people in today's industry that does know how to write (X)HTML and CSS but doesn't feel very comfortable with the DOM and JavaScript. Unobtrusive behavior introduced a mechanism to easily apply small portable scripts to a Web page: "Just make sure your markup looks like A, include this script B, and as a result you have a page that can do C".
Try to create small pieces of independent code. The disadvantages of a lot of existing JavaScript code libraries are that you often have to include a lot more code than you really need and that they are harder to understand and maintain if you didn't create them yourself. Because the functions in these libraries are often grouped and reused by other scripts, it often feels like they are spaghetti-coded. A library with small unobtrusive scripts has the advantage of being light-weight, easy to be understood and easy to be adjusted for more specific implementations.
Create reusable code. If you find yourself duplicating code snippets(片段), create functions. If you find yourself duplicating(复制) similar code snippets, try to abstract your code to the level that you can reuse it for multiple purposes.
Document your code well. If you work together with other people, like to share your code with others, or still want to know why you did certain things one year from now, good documentation is key.
Avoid browser detection, because it is almost impossible to maintain in the future. Feature testing or object detection offers a browser independent and future-proof technique to test to what extent your Web client supports JavaScript.
XHTML (if not used in backwards-compatible mode) introduces media type application/xhtml+xml (currently unsupported by Internet Explorer), which has a huge impact on how we write JavaScript code:
If you want to keep yourself up-to-date with the latest developments, there are a lot of initiatives from different organisations that will impact the ways we use JavaScript and the DOM in the near future:
Although JavaScript is generally well supported by most modern Web clients, support still remains its biggest weakness. Because from the first days of the Web users were often harassed(疲倦的) by all kinds of annoying(讨厌? behavior, browser makers decided to make it easy to switch JavaScript off (Windows XP Service Pack 2 even disables some JavaScript by default, because it regards it as active scripting). If you compare JavaScript with its little stepbrother ActionScript (which is supported when the Flash plug-in is installed and cannot be switched off), you will find that the main difference is that you can rely on its behavior to accomplish certain tasks. Because it is just too easy to switch JavaScript off, simple tasks like form validation always need to be duplicated at the server side. It will be for this reason that in the future most client-side form validation will be replaced by markup and 'built-in behavior'.
As mentioned earlier, the onload event handler is insufficient to get the best out of unobtrusive techniques. I hope that the people of the W3C will respond to this feedback from the JavaScript community and add new handlers like onElementLoad and onDOMLoad to future DOM specifications.
The JavaScript implementations of Internet Explorer and Safari suffer from memory leaks when using circular references like closures. When using circular references, make sure you remove event handlers when a page is unloaded.
JavaScript is a very flexible language and as a result you often have multiple ways of doing things. You could choose for either a procedural(E序? or an object oriented way of coding. For your unobtrusive behavior you can either use custom attributes or use class attributes as triggers to fully control the behavior of your site. Flexibility implies that you have to make certain choices, however often one solution is not necessarily better or worse than another. Base your decisions on the context in which you have to use your scripts and your own philosophy or taste and try to use a consistent coding style.
Currently a lot of outdated(q期? and badly written code is available on the Internet. Many scripts are plagued by browser detection, are using proprietary features that don't work cross-browser, are inaccessible or are not separating behavior from structure, because they rely on inline event handlers and scripts. It seems that Web Standards, Web clients and the practice of writing good JavaScript have evolved so quickly in the past two years, that it is hard to keep up with the latest good practices. This on its turn makes it hard to reuse code from others or reuse code you wrote yourself a year ago. Because some parts of older scripts may still contain valid code constructs, it is best to review them and rewrite the parts that don't suffice anymore. You will probably often find that a complete rewrite will do best.
So how do less experienced DOM and JavaScript users tell the difference between good and bad code on the Internet? There are some experts on the Internet that advocate modern ways of scripting and there are communities that discuss and rate new scripts and techniques. Some examples are:
DHTML Utopia: Modern Web Design Using JavaScript & DOM is the first title of a new range of books focusing on the application of modern JavaScript and unobtrusive scripting techniques.
Optimize your scripts for both download speed and execution speed. <下蝲速度和执行速度>Some tips:
A selection of tools that make life much easier:
© Copyright 2004-2006 Bobby van der Sluis All rights reserved.
eg.
this.isIE = navigator.userAgent.toLowerCase().indexOf("msie") >= 0;
This provides a new method to the core class Function. The method,called bindAsEventListener(),is used to do bind methods to event handlers.
qؓ核心class 函数支持了一个新的方法。这个方法叫bindAsEventListener(),是用来绑定方法给事g处理器的?BR>var obj = new SomeClass();
var closure = obj.someMethod.bindAsEventListener(this);
element.onclick = closure;