Find some poor information about dojo. Thank you! _ Javascript skills

Source: Internet
Author: User
Find some poor information about dojo. Thank you! Introduction:
Here we will give you an initial course on dojo. You may say to yourself, "skip this section because I already know javascript and know website development very well. "But here is an opportunity for you to realize that your knowledge is not so solid, and there are still many basic things to learn.

When we introduced dojo to people, we encountered two problems. Some users have been using DHTML for a long time and have a deep understanding of javascript. They know what javascript can do, what it cannot do, and there are stereotypes in their minds. Sometimes, it is more difficult for these people to understand dojo. The second challenge is for beginners who are too inexperienced and have a good understanding of javascript.

I encourage both of them to read the introduction, and you may not even read it completely.

What is Dojo?

In fact, it is very difficult to summarize what Dojo is. I said it is very difficult to sum up Dojo because Dojo is an extensible code set (expandable collection of code ). Expansion is not only from many developers, but also you will find that you can expand your own set of things according to your own needs. That is to say, the reason why you focus on Dojo is that Dojo can complement javascript.

The client-side development consists of three main parts: events, repeated use of DHTML blocks, and information transmission by the client and server. Dojo is very good at these three aspects and makes them easy to change.

History

Note: I really don't want to translate history. If anyone is interested, I can leave a message and I will translate it later.

............

What is Toolkit )?

Many people think that the structure (framework), library (library), and tool share the same meaning. However, figuring out the differences between them will be helpful for future understanding.

Framework

In software development, a framework is usually defined to allow other projects to share and cooperate ). A structure usually contains support programs, libraries, and a script program. You may realize that Dojo is a part of the framework, but it is not the framework itself.

Library

Library files define a lot of methods (functions) that can be referenced. They can be run anywhere and are not the methods we usually define in programs. After reading this, you may say, "Hey! Dojo is the collection of libraries !". You should be right, but dojo is much more contained than a collection of libraries.

Toolkit

After reading the previous article, you may still be wondering what dojo is. Obviously, it is not a framework. Is it a tool or a library? Finally, let me explain. Generally, the libraries are defined previously. You can reference them in your program and use them, but in dojo, we added a package system to the database. In this way, it is different from the general library.

In this system, we divide the database into many parts. There are core functions and many other sub-libraries that are not commonly used ). This makes it simple when you use dojo. The following is a more detailed analysis that will help you better understand dojo.

What does Dojo give you?

At one time, most people were using Netscape, So Netscape gave a website creation standard. After a long time, Microsoft's Internet Explorer emerged. At that time, Internet Explorer was better than Netscape and became a new standard. However, this standard is different from W3C, so when people make websites, they begin to move closer to the new IE standard.

After many years, IE is still undefeated and has not been updated much. There are as many bugs as possible, and there is a lack of standardization. Net worms gradually started to use firefox, opera, and safari. They were updated very quickly to keep up with W3C standards.

Many of the same functions, but different browsers need to write different code. What does this mean for us? This means that it is very difficult for us to make a perfect website. What will a programmer do?

Knowledge supplement

If you use static html to create a website, of course, the above problems will not occur, but this also means that the website cannot be interactive, the most is to provide a form for users to submit, then, a new page is displayed.

Javascript is designed to solve these problems.

Resolve all problems

Dojo not only exists in the abstract layer, but also exists independently. It not only provides some libraries, methods, and functions, but also makes the code more concise and ensures that your code only contains the necessary parts.

Dojo makes your life easier, because it links a lot of things for you and divides your complex projects into small problems, making your code simpler and more efficient, and it can be used repeatedly better.


Chapter 1: Start Using Dojo

Dojo has many versions, so you don't know which one to choose. Here, you can rest assured that no matter what version you are using, you can run the examples in this book.

Download Dojo

(Translator's note: This is my version and zip file. You can also download it on the Dojoa homepage .)

Dojo module (Modules)

The library definition of Dojo uses modules, Just Like JAVA. In this way, you can only reference what you need, not all, to ensure the browsing speed.

For example, the event package of Dojo is defined in the module dojo. event.

(Translator's note: This part of the original is very cool. I have simplified it. If you are interested, refer to the original article .)

Format of the reference module:

Dojo. require ("dojo. module [. sub module]");

For example, we want to reference lite effects systems,

Dojo. require ("dojo. lfx ");

This will introduce all sub-modules in lfx. Of course you can also use dojo. lfx. *. If you want to independently reference the toggle module in lfx:

Dojo. require ("dojo. lfx. toggle ");

Widgets

What is a widget? A button and an image are all Widgets. The most common html widgets include links, buttons, and input boxes.

You can use Dojo to change Widgets. For example, you can add a color calendar next to the date input box so that you can select a date. At the same time, Dojo does not destroy your original input box, because Dojo extends your html instead of replacing it.

The main advantages of using widgets are as follows:
Cross-platform: With Dojo widgets, no matter which browser is used, the results will be accurate.
Automatic degradation: Some Old browsers may not support javascript perfectly. Dojo can also display the correct content, for example, the preceding example of a color calendar. If the browser does not support it, dojo will automatically degrade the calendar to a simple selection box or something else (depending on different widgets ).
Scalability: You can use the widgets provided by Dojo to create new widgets. In this process, you do not need to copy any code from the library or modify the code in the library.

How to Use Widgets

Widgets have many usage methods. The Widget searches for the entire web framework and automatically adds the content to it.

The following is a simple example. We can also see how widgets are automatically degraded, because we didn't define a choice for ComboBox, but just a value, in addition, the result is displayed as a simple inputbox. if javascript is disabled, the result is displayed as well.

But if we only want to use W3C standards (Note: there are no additional tags, such as dojoType), we can use the following method.

You may notice that dataUrl is used to add the content in comboBoxData. js to comboBox, but no content is used in comboBoxData. js. (Note: Of course, you can change the dataUrl content at will. The name is not fixed .)

The following is an example of a select statement:

FooBarBazThud

In the above example, you know a lot of things, but it seems useless. Here I just want to tell you that dojo is not that complicated.

Backward and forward

Dynamic web applications (dynamic web applications) Avoid frequent page refresh, but usually bring back and forward button will lose function. More, sometimes it is difficult for users to add webpages to favorites.

Dojo provides a solution to allow web programs to process the browser backward and forward, and provide the browser with a unique address. The solution is to use dojo. undo. browser.

Use dojo. undo. browser

In dojo 0.2.2, no dojo. undo. browser exists. This is added in Versions later than 0.3.

First, you need to use dojo. undo. browser. setInitialStae (state) to set the state of the web page when the browser loads the web page for the first time.

Theory

The dynamic web page program calls XMLHTTPRequest and DOM to update the content of the Web page. This avoids refreshing, updating the browsing history, and does not change the address bar of the browser. This means that when the user clicks the back button, the entire web page program loses the current running state ). Even if you want to add the current webpage content to your favorites, It is impossible because favorites does not record the status of Webpage Programs, instead, it simply records the URL of the webpage program ).

Developers can use the dojo. undo. browser package to get the events that the user clicks back and advances, and then update the page content based on these events. Dojo. undo. browser transmits browsing history by using a hidden form (hidden IFRAME) or a unique tag (fragment identifier. (Note: It can be imagined as a cookie or session, but the session information is stored in the hidden IFRAME or tag.) For example:

Http://some.domain.com/my/path/to/page.html#fragmentIdentifier

(Note: # fragmentIdentifier indicates the tag record)

Because changing tags does not refresh the web page, it is very suitable to record the status of the current web page program. Of course, developers can customize a tag that is easier to understand and allow users to add it to favorites.

Dojo. undo. browser allows developers to create a state object relative to the running state. This object will get callback when the user clicks back or forward.

Development

The following are some things that must be done before using dojo. undo. browser:

1: Set preventBackButtonFix: false in djConfig. This ensures that the hidden form (hidden IFRAME) will be added to the page. If this section is not added, dojo. undo. browser will not work normally.

Note: The setting method is to add the following code to the header:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.