If js/core/core_retouch.js is customized for prototype users, js/dom/dom_retouch.js is customized for jquery users and yui users, can I also customize my own projects.
Yes. Let's take the youa user as an example to see what kind of personalization he has.
/*
* Repeated click Protection
*/
(Function (){
Var F = function (e, handler ){
Var element = this,
Ban = element. nodeType! = 9? Element. getAttribute ('data -- ban '): null;
If (ban &&! IsNaN (ban )){
If (element. _ BAN_TIMER ){
QW. EventH. preventDefault (e );
Return;
}
Element. _ BAN_TIMER = setTimeout (function (){
Element. _ BAN_TIMER = 0;
}, Ban );
}
Handler. call (element, e );
};
QW. EventTargetH. typedef ('click', 'click', F );
QW. EventTargetH. typedef ('dblclick', 'dblclick', F );
QW. EventTargetH. typedef ('submit ', 'submit', F );
}());
/*
* Add an alias
*/
QW. g = QW. NodeH. g;
QW. W = QW. NodeW;
/*
* The method and namespace directly attached to QW are provided to the window
*/
QW. ObjectH. mix (window, QW );
/*
* Increase provide output
*/
QW. ModuleH. provideDomains. push (window );
We can see that there are several things in his code:
1. To prevent repeated page clicks and lead to multiple submissions, a custom attribute is added to set the repeated Click Time.
2. Add a brief alias.
3. Mix the QW method or attribute to the window.
4. Increase provide output.
Of course, it can also handle many things. Let's analyze these four things first.
1. To prevent repeated page clicks and lead to multiple submissions, a custom attribute is added to set the repeated Click Time.
Repeated click protection is a common requirement. Why do I have to let the project owner do it without a browser or js framework?
---- It's hard for them to do it! Because "anti-repetition" is too general, it is difficult for users to express: "What events are protected, how far are they protected, and what effect are they protected ......"
The browser or framework cannot provide a perfect solution now, so it is better to put it aside first.
However, it is necessary for business projects. So I had to work hard on the project.
The project team had no choice but to implement a barely universal solution-of course, this reluctantly required the project's demand side to accept it.
2. Add a brief alias.
The brief alias is also very personalized. A thinks it is short, B may think it is not short, C may think it is not beautiful, and D may think it is easy to conflict, E think that naming too many people is at a loss, and so on.
The js framework does not require many brief names. A brief name can only be recommended. For details, the project personnel must decide.
Youa_retouch.js is used in the YOUA project. The short name here also represents the recommended usage in this project.
3. Mix the QW method or attribute to the window.
Some students have doubts: It is too rash to do so.
Yes, it is a little aggressive, but let's take a look at the risks of the rash: the emergence of many global variables, possible global variable conflicts, increased the chance of conflicts with other libraries ......
But what are the advantages of it: When writing code, you can write less "QW." Three characters.
Why are so many risks overwhelmed by "three characters saved? ---- Because we are very lazy, we are working on projects. The cost of "avoiding those risks" is less than the cost of "Knocking several characters more.
"Generate many global variables" ---- nothing terrible,
"There may be global variable conflicts" ---- we didn't touch it either. Besides, there is no overide in mix,
"Increased the chance of conflicts with other libraries" ---- qwrap does not seem to conflict with other libraries in terms of naming style.
After saving three characters, we can safely use "use ('drag', function (){....}) ", instead of adding" QW. ".
4. Increase provide output.
QW. provide comes from QW. ModuleH. provide, which is a recommended method for QWrap component output.
For example, we can use this sentence to add an Ajax component for QW: QW. provide ('ajax ', Ajax); by default, a QW. Ajax is generated.
Because the provide output location is added to youa_retouch.js, the ajax. js component code will be introduced later. You can also use Ajax. post (...) for page js, instead of adding "QW." Before Ajax .".
For more information about provideDomains, see js/core/module. h. js.
Youa_retouch is a typical example of personalized js libraries by project. In the youa project, three types of retouch are performed: core_retouch, dom_retouch, and youa_retouch.
The retouch user manual can be seen here:Http://dev.qwrap.com/resource/js/_docs/_jk/
As you can see, in the youa project, you can perform dom operations like jquery, prototype operations, and use as YUI3.
In fact, Dom can also be used like YUI2. However, the YUI2 style is just a product of history and is no longer recommended, so it is not mentioned in the document.
Repeat it again. youa_retouch is just a typical example of personalized js libraries by project. For those who understand QWrap, they can make more personalization in their own projects.
Appendix: QWrap Web site: http://www.qwrap.com