官术网_书友最值得收藏!

Knowing our MooTools version

This recipe is an introduction to the different MooTools versions and how to be sure we are coding in the right version.

Getting ready

Note

Not all are equal nor are backwards compatible!

The biggest switch in compatibility came between MooTools 1.1 and MooTools 1.2. This minor version change caused clamor in the community given the rather major changes included. In our experience, we find that 1.2 and 1.3 MooTool scripts play well together while 1.0 and 1.1 scripts tend to be agreeable as well. However, Moo's popularity spiked with version 1.1, and well-used scripts written with 1.0, like MooTabs, were upgraded to 1.1 when released. The exact note in Google Libraries for the version difference between 1.1 and 1.2 reads:

Since 1.1 versions are not compatible with 1.2 versions, specifying version "1" will map to the latest 1.1 version (currently 1.1.2).

MooTools 1.1.1 has inline comments, which cause the uncompressed version to be about 180% larger than version 1.2.5 and 130% larger than the 1.3.0 release. When compressed, with YUI compression, 1.1 and 1.2 weigh in at about 65K while 1.3.0 with the CSS3 selectors is a modest 85K. In the code snippets, the compressed versions are denoted with a c.js file ending.

Two great additions in 1.3.0 that account for most of the difference in size from 1.2.5 are Slick.Parser and Slick.Finder. We may not need CSS3 parsing; so we may download the MooTools Core with only the particular class or classes we need. Browse http://mootools.net/core/ and pick and choose the classes needed for the project. We should note that the best practice is to download all modules during development and pare down to what is needed when taking an application into production.

When we are more concerned with functionality than we are with performance and have routines that require backwards compatibility with MooTools 1.1, we can download the 1.2.5 version with the 1.1 classes from the MooTools download page at http://mootools.net/download. The latest MooTools version as of authoring is 1.3.0. All scripts within this cookbook are built and tested using MooTools version 1.3.0 as hosted by Google Libraries (more to follow on that in this chapter).

How to do it...

This is the basic HTML framework within which all recipes of this book will be launched and comprises the first recipe of the book:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MooTools Recipes</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />

Tip

Note that the portion above is necessary but is not included in the other recipes to save space. Please do always include a DOCTYPE, and opening HTML, HEAD, TITLE, and META tag for the HTTP-EQUIV and CONTENT.

<script type="text/javascript" src="mootools-1.3.0.js"></script>
</head>
<body>
<noscript>Your Browser has JavaScript Disabled. Please use industry best practices for coding in JavaScript; letting users know they are missing out is crucial!</noscript>
<script type="text/javascript">
// best practice: ALWAYS include a NOSCRIPT tag!
var mooversion = MooTools.version;
var msg = 'version: '+mooversion;
document.write(msg);
// just for fun:
var question = 'Use MooTools version '+msg+'?';
var yes = 'It is as you have requested!';
var no = "Please change the mootools source attribute in HTML->head->script.";
// give 'em ham
alert((confirm(question)?yes:no));
</script>
</body>
</html>

Tip

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

How it works...

Inclusion of external libraries like MooTools is usually handled within the HEAD element of the HTML document. The NOSCRIPT tag will only be read by browsers that have their JavaScript disabled. The SCRIPT tag may be placed directly within the layout of the page.

There's more...

Using the XHTML doctype (or any doctype for that matter) allows your HTML to validate, helps browsers parse your pages faster, and helps the Dynamic Object Model (DOM) behave consistently. When our HTML does not validate, our JavaScript errors will be more random and difficult to solve.

Note

Many seasoned developers have settled upon a favorite doctype. This allows them to become familiar with the ad-nauseam of cross browser oddities associated with that particular doctype. To further delve into doctypes, quirksmode, and other HTML specification esoterica, the heavily trafficked http://www.quirksmode.org/css/quirksmode.html provides an easy-to-follow and complete discourse.

See also

Be sure we are familiar with how non-sighted users browse our pages. We can make others' lives very difficult in the same stroke that we as programmers call user friendly. Check out the American Disabilities Act, ADA website for more information.

主站蜘蛛池模板: 兴仁县| 桑植县| 广平县| 龙泉市| 呼玛县| 囊谦县| 县级市| 珠海市| 鸡西市| 武山县| 巢湖市| 中卫市| 富民县| 信阳市| 定州市| 汶上县| 罗平县| 西乌| 东丰县| 辰溪县| 房山区| 霍邱县| 柘荣县| 佛冈县| 普兰县| 平安县| 博湖县| 大渡口区| 河西区| 肃北| 石家庄市| 佳木斯市| 海林市| 乳山市| 临泉县| 大丰市| 衢州市| 五寨县| 霍州市| 民勤县| 湘阴县|