Đang chuẩn bị liên kết để tải về tài liệu:
Developing Large Web Applications- P12

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

Developing Large Web Applications- P12:This book presents a number of techniques for applying established practices of good software engineering to web development—that is, development primarily using the disparate technologies of HTML, CSS, JavaScript, and server-side scripting languages. Whereas there are many books on how to use languages, how to use libraries, and how to approach software engineering, this is the first book to codify many of the techniques it presents. These techniques will make the components of your own web applications more reusable, maintainable, and reliable | The use of objects also gives you a way to group prototype objects into libraries. You can see examples of this in the YUI library which we ll present later. When you call YAHOO.util.Dom.getStyle for example you re calling a method that is actually a member of the Dom object which is a member of the util object which in turn is a member of the YAHOO object. At the end of this chapter we ll explore a prototype object called MultiSelect that we ve placed in the MVC namespace. Whenever you do this you need to check whether the namespace object already exists so that if it doesn t exist you can create it as shown here Place the component within the MVC namespace create it if needed. if window.MVC MVC . MVC.MultiSelect function text url id name prev . Accessing a module by ID Once you have an object that encapsulates the data and methods for a module that object typically spends most of its time working in just the part of the DOM that contains the elements for that module. Therefore it s useful in the constructor for the module object to set data members to whatever parts of the DOM you ll need access to rather than retrieving them over and over again within various parts of the object. This improves performance and acts somewhat as a means of binding a JavaScript object to the HTML elements for which the object is adding a behavior layer. One of the most important DOM methods for this is document.getElementByld. This method returns a reference to the element with the ID you specify. As we saw in Chapter 4 a good way to scope a module for CSS and JavaScript too is to give its outermost div an id attribute. Once you have a reference to this div you can target all other DOM operations within the proper scope for the module. Thus Example 5-2 illustrates accessing the DOM for a PictureSlider instance in the constructor for the object. The example also uses other DOM methods to get various elements within the module which we ll explore further in the next section. Example .