English version: http://manual.dojotoolkit.org/wikihome/dojodotbook translation: BURNET
Translator's order: With the warning of Web2.0, Google, Yahoo and other major web suppliers rushed to quit their Ajax development kits, intend to compete for Ajax standard. Who is deer? Someone is optimistic about YUI, some people like GWT, some people like these They all have noses, think that they write JavaScript is king.
Ok, who is very inferior, now I want to give you a first volume of the Dojo Development Tool (Toolkit) developed by IBM, and I will translate.
Finally, I have a question, I have been going abroad, although I usually regularly get 9CBS forums, but I am not very proficient in Chinese terminology, so when I translate some terms, I will not be very accurate. I will take those I can't take it. The quasi-based terminology is labeled in English, and the book author style is more humorous, some can't directly translate Chinese, and there is no need to translate, I will do my best to let everyone master dojo.
It is necessary to be able to do it, please reprint, please famous from Burnet's Blog.
Introduction:
Here will give you an enlightenment course for Dojo. You may tell yourself "this can be skipped, because I have known JavaScript and I have known the development of the website." But here has a chance to let you realize that your knowledge is not so solid, there are a lot. The foundation thing needs to be learned.
When we introduced people to dojo, we met two problems. Some users have already used DHTML for a long time, and I have a deep understanding of JavaScript. They know what JavaScript can do, what can't be done, there is styling thinking in my mind, some, it is more difficult to let these people understand dojo. The second problem is for those newcomers, they are too lack of experience and understanding JavaScript.
I encourage these two friends to read the introduction, and you can even look at it.
What is dojo?
In fact, summarizing that dojo is very difficult. I have said that DOJO is very difficult because dojo is an extensible code set (Expandable Collection Of Code). The extension is not just from many developers, and you will find that you can extend your own set according to your own needs. That is to say, the reason you put on dojo is because Dojo can take a long-term addition to JavaScript.
There is a total of 3 main parts: Events, Reudent information of DHTML Blocks, client, and servers. Dojo is very in this three aspects and makes them easy.
history
Translator Note: I really don't want to translate history. If someone is very interested, I can leave a message, I have time to translate.
. . . . . . . . . . . .
What is Toolkit?
Many people think the structure (library), tools are the same meaning. But figure out the difference between them, it is very helpful for future understanding.
Framework
In software development, in order to allow other items to share and cooperate, a structure is typically defined. A structure typically contains support programs, libraries, and a script. You may realize that dojo is a part of Framework, but it is not Framework itself.
Library
Library files define a lot of methods that can be referenced, they can run anywhere, not what we usually be defined in the program. Looking at these, you may say "Hey! Dojo is the collection of libraries!" You should be right, however, dojo is much more than a collection of libraries. Toolkit
I have seen the previous article, you may still think that dojo is doing something. Obviously, he is not a structure (Framework), is it a tool (Toolkit) or a library? Finally, let me answer, usually the library is defined before, you can quote into your program and use them, but in dojo, we add a package system outside this library. This makes it different from the general library.
In this system, we divide the library into a lot of parts. There is a core method, there are many other sub-library (SUB Library). This makes you feel very simple when you use Dojo. There will be a more specific analysis below will make you more understand Dojo.
What will dojo give you?
Once, Netscape prevails, most people are in use, so Netscape gives a standard for website production. The good scene is not long, and later there is a Microsoft IE, IE is strong at Netscape, which has become a new standard. However, this standard has a certain difference with W3C, so when people make websites, they have begun to close to IE.
Many years have passed, IE is still unbeaten, and there is no more updated. As more bugs, lack of standardization. Slowly nevars began to use Firefox, Opera, Safari, which in order to keep up with the W3C standard, so updated very quickly.
A lot of equality, but what do you mean for different browsers, what does this mean? It means that we have to make a perfect website is very hard. What is the programmer going?
Knowledge supplement
If the light uses a static HTML to make a website, there is of course the above problem, but this also means that this site is impossible to have interactivity, and the most is just a form (Form) to let the user commit, and then return a new page display. data.
The emergence of JavaScript is in order to solve these problems.
Solve all problems
Dojo is not only an abstract layer, but also independently exists. Not just providing some libraries, some methods, some functions, and make the code more simple, and ensure that your code contains only the required parts.
Dojo will make your life simpler, because he linked a lot of things for you, dividing your complex project into some small problems, making your code more concise, more efficient, and can be more reused.
Chapter 1: Start using dojo
Dojo has a lot of versions, you can don't know which one you choose, here you can rest assured, no matter what version you use, you can run in this book.
Download Dojo
(Translator Note: This is the version I use, ZIP file, you can also download itself to the Dojoa home page.)
Dojo module (modules)
Dojo's library definition uses modules, just like Java. This allows you to only quote the parts you need, not all, guarantee the browsing speed.
For example, Dojo's EVENT package is defined in the module dojo.event.
(Translator Note: This section is very embarrassed, I will streamline, interested friends can see the original text.) Reference module format:
Dojo.require ("Dojo.module [.sub Module]");
For example, we want to quote Lite Effects Systems.
Dojo.require ("dojo.lfx");
This will introduce the submodule under all LFX, of course you can also use dojo.lfx. *, If you want to separately reference the Toggle module under LFX:
Dojo.require ("dojo.lfx.toggle);
Widgets
What is widget? A button, a picture, this is widget, the most common HTML Widget has a link, button, input box.
With Dojo, you can change the widget, for example, add a color calendar next to the date input box, so that the user can select the date, and dojo does not destroy your original input box, because dojo is extended with your HTML instead of replacing it. it.
The main three points of the advantage of using widgets:
Cross-platform: Use Dojo Widget, which will accurately get the correct effect regardless of any browser. Automatic degradation: Some old browsers may not be so perfect for JavaScript, dojo can also make them display correct content, such as examples of the previous color calendar, if the browser does not support, dojo will automatically degenerate the calendar to a simple The selection box, or other (depending on the Widget). Scalability: You can use the widget provided by Dojo to create a new Widget, you don't need to copy any code or modify the code in the library from the library.
How to use widget
Widget has many ways to use. Widget searches the entire web frame, then automatically adds the content you should add to it.
Here is a simple example, we can also see how the widget is automatically degraded, because we have not given the ComboBox definition selection, but only a value, and so the last display is just a simple inputbox, if the user is disabled JavaScript, the results will be the same.
But if we just want to use W3C standards (Translator Note: There are no extra tags, such as dojotype), we can use the following methods.
You may notice DataURL, his role is to add content in ComboBoxData.js to ComboBox, but now there is no content in ComboBoxData.js. (Translator Note: Of course, you can change the content of DataURL at will, and the name is not fixed.)
Below is an example of SELECT:
Back and advance
Dynamic Web Application avoids frequent refreshing pages, but usually also bring back and forward buttons will lose its role. More, sometimes, users may hardly add web pages to favorites.
Dojo provides a solution to let webpage processes the back and advancement of the browser and provide a unique address to your browser. This solution is to use dojo.undo.browser.
Use dojo.undo.browser
In the DOJO 0.2.2, there is no dojo.undo.browser, which is added in the version after 0.3.
First, you need to use Dojo.undo.Browser.SetInitialStae (state) to set the status of the browser to load the web page.
theory
The dynamic webpage program calls XMLHTTPREQUEST and DOM to update the content of the web page and avoid refresh, update the browsing history, and will not change the browser's address bar. This means that when the user clicks the back button, the entire webpage program has lost the current state (state). And even if the user wants to add the current web page content to the favorites, it is impossible, because the favorites do not record the status of the webpage line, and only simply record the address (URL) of the webpage program.
Developers can use dojo.undo.browser package to get the user clicked back and advanced events (Event), and then update the page content according to these events. Dojo.undo.Browser passes the history of browsing by using a hidden form (Hidden iframe) or a unique label (Fragment Identifier). (Translator Note: You can imagine a cookie or a session, but this session information is stored in the hidden iframe or tag), for example:
Http://some.domain.com/my/path/to/page.html#fragmentidentiDentifier
(Translator Note: #fragmentidentifier is the label record)
Because when changing the label does not refresh the web page, it is very suitable for recording the status of the current webpage program. Of course, developers can customize a tag that is easier to read and enable users to add it to favorites.
Dojo.undo.Browser allows developers to create a STATE OBACT, this object will be called (callback) When the user clicks the back or the forward button.
Develop
Here is some things that must be made before using dojo.undo.browser:
1: Set preventbackbuttonfix: false in DJConfig. This guarantees hidden forms (hidden iframe) will be added to the page, if this is not added, dojo.undo.browser will not work properly. Translator Note: Setting method is to add the following code in Header: