Learning jQuery (8) Plug-in from scratch: jQuery implementation solution

Source: Internet
Author: User

I. Summary

This series of articles will take you into the wonderful world of jQuery. Many of them have their specific experiences and solutions. Even if you use jQuery, you can find some tips.

This article is a temporary plug-in for introducing my jQuery implementation solution in our company.

Ii. Preface

With the solid basic knowledge of the previous chapters, we can already invest in jQuery In the project. Continue to learn more about jQuery and plug in my jQuery implementation solution.

Different companies have different situations. for example, the webpage files of our company are all user controls, and there is no absolute relationship between the physical path and the virtual path, so we cannot use the relative path (otherwise, the file will not be found in the production environment ). there are many projects. Different folders in the same virtual directory correspond to different project projects.

This solution is not generic, but some methods can be used for reference. I also hope to discuss it with you to help me correct it.

Iii. Library File Management Solution

Root path:Src \ Assembly \ resource. eLong. Web. Files \ Resource \ JSLib \ jquery \

Reference root path:Http://resource.elong.com/JSLib/jquery/

Compressed version Reference Path:Http://resource.elong.com/JSLib/jquery/jquery-min-lastest.js

Root path file list:

Create a js folder under each Web project and place the jquery-vsdoc-lastest.js file:

Note:

First, put all versions of the jQuery class library on the static server, and store the class library files according to the folder. However, the latest version will be selected for reference and placed in the root directory.

The root directory contains the following files:

Name Content Description
Folder 1.3.2 The jQuery class library is organized by version number. For each jquery version later than 1.3.2, class library files will be stored according to the folder, but the latest stable version will be used to overwrite the js files named by each lastest.
Folder plugin Folder for storing plug-ins Store various plug-ins in this path as folders
Jquery. extend-lastest.js JQuery method extended by elong In the future, we will build our own javascript class library. Some of the core class libraries will be put in this file, which is equivalent to our own tool class library. It will be implemented through jQuery extension.
Mainly divided into tool functions and function packaging.
Jquery-lastest.js Latest Version of jQuery uncompressed class library The latest stable version of the original jQuery class library.
Jquery-min-lastest.js Latest Version of jQuery compression class library The latest stable version of The jQuery compression class library.
Jquery-vsdoc-lastest.js JQuery smart prompt library Latest Version The latest stable version of The jQuery smart prompt class library.

To implement SMART awareness during development, you also need to place the version in the js folder of each web project. because there are many Web projects, Please create this folder for the first user in the future and put it into a file.

Iv. Class Library Reference Scheme

In all the page headers, The jQuery class library is first referenced and the absolute path is used:

Http://resource.elong.com/JSLib/jquery/jquery-min-lastest.js

Then, use if (fasle) to introduce the script block of the smart prompt version. Use the path "~ "Start searching from the root directory. I create a unified js folder in the project source code of each channel and place the latest intelligent sensing version library of the jquery-vsdoc-lastest.js. note that this file does not need to be packaged and uploaded. It is only used for smart prompts during development.

This ensures that only the compressed jQuery class library is introduced on the compiled page.

Sample Code:

<Head runat = "server"> <title> jQuery reference scheme </title> <script type = "text/javascript" src = "http://resource.elong.com/JSLib/jquery/jquery-min-lastest.js"> </script> <% if (false) {%> <script src = "~ /Js/jquery-vsdoc-lastest.js "type =" text/javascript "> </script> <% }%> 

Note:

In our website, static files are stored in another second-level domain name resource.elong.com and CDN is used. To ensure the consistency between the test environment and the official environment, only the absolute path can be used to reference the jQuery library.No script prompt will appear after jQuery smart prompt version is referenced using absolute path.Therefore, we can use this feature to directly reference the compressed jQuery class library of the absolute path, thus cleverly solving the problem.1.3.2 SMART system error prompt after compression version Introduction.

Although the smart prompt version library can be removed from the dynamic page through if (false), the server statement block cannot be used on the HTML page.The HTML page must be manually deleted before the development program is released.

5. Development and Use Solutions

JQuery is a script library rather than a script framework, and does not limit how users use it. Therefore, it is easy to confuse scripts on the page.

Use the following script on the page before you can find the script management framework:

1. Add the <script> area at the bottom of the page and place the two functions separately."Event binding"And"Executed during loading"Even when loading javascript, make sure that the DOM is executed after loading. Therefore, both functions are nested in $ () and called after DOM loading.

2. Try to avoid loading scripts in the header. You can add a script area to the header of the page.

3. "user-defined functions" should be placed on the block of "event binding" and "load-based execution" statements, and do not need to be included in $.

The following is a sample code for the complete page:

<% @ Page Language = "C #" %> <! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

Vi. Summary

After confirming that no confidential information has been published, I published this article. There is not much technical content, mainly for the specific implementation method of jQuery promotion in the company.

In addition, I have been looking for a Scripting framework to organize and manage various js class libraries and js files. This requires further exploration in future work.
Author: Zhang Ziqiu
Source: http://www.cnblogs.com/zhangziqiu/

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.