« Home « Chủ đề thao tác khi lập trình

Chủ đề : thao tác khi lập trình


Có 40+ tài liệu thuộc chủ đề "thao tác khi lập trình"

Practical prototype and scipt.aculo.us part 21

tailieu.vn

custom events from anywhere in your code. you can also listen for custom events with the same API that you’d use to listen for native browser events.. Use dom:loaded when you want to work with the DOM in that narrow window of time before the page appears on the screen fully rendered. This is also a good time to talk...

Practical prototype and scipt.aculo.us part 22

tailieu.vn

foo.hide();. foo.visible. false foo.show();. Element#visible simply reports on the element’s CSS display , returning true if it’s set to none . if (element.visible. element.hide();. else element.show();. true foo.toggle();. false foo.toggle();. <div class="news-item". id="item_1">. </div>. But what if we want to do more with CSS? It’s remarkably easy to style elements directly through JavaScript using the style property that exists on...

Practical prototype and scipt.aculo.us part 23

tailieu.vn

when the structure or content of the inserted markup isn’t the same every time—because building long strings in JavaScript isn’t my idea of a fun afternoon. Think of it as a thin wrapper around innerHTML —just as assigning to the innerHTML property will erase whatever was there before, update will discard the original contents of the element, replacing it with...

Practical prototype and scipt.aculo.us part 25

tailieu.vn

tr.appendChild(td1);. tr.appendChild(td2);. tr.appendChild(td3);. ...and append the row to the table body.. $('cities').down('tbody').insert(tr, 'bottom');. Three times as many lines! As is often the case, one approach is easy but sloppy, and the other is harder but more “correct.” Can’t we split the difference?. var tr = new Element('tr. tr.appendChild( new Element('td').update('Total'). tr.appendChild( new Element('td',. 'class': 'number'}).update(totalPopulation). tr.appendChild( new Element('td. Now append...

Practical prototype and scipt.aculo.us part 26

tailieu.vn

Because scripts from different authors often coexist on the same page, it’s a bad idea to define too many functions in the global scope. Instead, what if you were to define one object in the global scope, and then attach all your functions to that object? You’d balk at defining a method named run , but BreakfastLog.run is much less...

Practical prototype and scipt.aculo.us part 27

tailieu.vn

"Andrew Dupont throws for 23yds.". "Andrew Dupont throws for 39yds.". define properties for receivers this.receivingYards = 0;. this.receivingYards. this.catchPass(yards);. this.scorePoints(6);. Notice again that we’re not writing copy-and-paste code. this.isActive = true;. will be a starter for Sunday's game.");. this.isActive = false;. will spend Sunday on the bench.");. So now we’ve got two new methods on the Player class for managing...

Practical prototype and scipt.aculo.us part 28

tailieu.vn

this.element = $(element);. this.totalElement = $(totalElement);. this.options = Object.extend({. selector: ".number". var numberElements = this.element.select(this.options.selector);. this.updateTotal();. this.totalElement.update(total);. We’re done writing the Totaler class, at least for now. Save it as totaler.js. We’ll be using the same data for this example, but we’ll need to change the table’s markup to fit with the changes we’ve made. <table id="cities">. <tr>. <th scope="col">Name</th>....

Practical prototype and scipt.aculo.us part 29

tailieu.vn

arguments.length. If we take the parentheses off, though, we’re no longer calling the function—we’re just referring to it:. In the first example, result is set to 0 —the result of calling sum with no arguments. In the second example, result is set to the sum function itself. In effect, we’re giving sum an alias.. We’re going to look at a...

Practical prototype and scipt.aculo.us part 30

tailieu.vn

Many of them are used within Prototype itself, but they’re likely to be useful in your own code as well.. "Never, never pour salt in your eyes.".gsub('never', 'always');. "Never, always pour salt in your eyes.". "Never, never pour salt in your eyes.".gsub(/never/i, 'always');. "always, always pour salt in your eyes.". But now we’ve got a new problem. The first. “never”...

Practical prototype and scipt.aculo.us part 31

tailieu.vn

pour salt in your eyes.".escapeHTML();. pour salt in your eyes.". pour salt in your eyes.".unescapeHTML();. pour salt in your eyes.".stripTags();. "Never, never pour salt in your eyes.". "lorem-ipsum-dolor".underscore. "lorem_ipsum_dolor".dasherize. "lorem-ipsum-dolor".camelize. "never".capitalize. "NEVER".capitalize. "Never".capitalize. var warning = "Never, never pour salt in your eyes.". "Never, never...". ".blank. ".empty. "".empty. "".blank. var t = new Template("The quick brown #{first} jumps over the...

Practical prototype and scipt.aculo.us part 32

tailieu.vn

just won the Heisman trophy.";. "Andrew Dupont just won the Heisman trophy.". "#{position} #{firstName} #{lastName} just won the Heisman trophy.");. Andrew Dupont just won the Heisman trophy.". firstName: this.firstName, lastName: this.lastName. "QB Andrew Dupont just won the Heisman trophy.". "The quick brown fox jumps over the lazy dog.". var warning = "Never, never pour salt in your eyes.". "Never, never...

Practical prototype and scipt.aculo.us part 33

tailieu.vn

Object.toJSON(player);. Object.toJSON(qb);. Type Sniffing with Object.isX. The Object.isString, Object.isNumber, Object.isFunction Methods. Object.isString("foo". true Object.isNumber("foo". false Object.isFunction. Object.isNumber(4). true Object.isNumber(3 + 9). true Object.isNumber("3". The Object.isUndefined Method. Instead, we’ll use Object.isUndefined. alert(Object.isUndefined(third));. The Object.isArray, Object.isHash, Object.isElement Methods. 'object' Object.isArray(amigos). 'object' Object.isElement(villain). 'object' Object.isHash(partyFavors). if (Object.isString(element)). presidents.reverse();. presidents.reverse(true);. presidents.clear();. presidents.uniq();. presidents.without("Adams Monroe");

Practical prototype and scipt.aculo.us part 34

tailieu.vn

Visualizing with Block-Level Elements. Visually, most elements are represented as blocks—big rectangles, if you prefer—and are thus called block-level elements.. As the primary pieces of page construction, block-level elements are broadly cus- tomizable. Block-level elements have implicit line breaks. But, as Figure 9-2 illustrates, any element can be made to behave like a block-level element, even if it isn’t one,...

Practical prototype and scipt.aculo.us part 35

tailieu.vn

So we’ve got a box with 10 pixels of padding, 25 pixels of margin, and 5 pixels of border on all sides.. There are several ways to measure the box’s dimensions:. The most obvious way to the human eye is to measure from the outside edges of the border. A related approach would be to measure from the inside edges...

Practical prototype and scipt.aculo.us part 36

tailieu.vn

We’ll call this the element’s positioning context. We can see for ourselves how changing the positioning mode of an element affects how that element’s children are rendered (see Figure 9-11):. A position value of relative , then, can be used to assign a new positioning context for all the element’s children while leaving it otherwise unchanged.. When we discuss an...

Practical prototype and scipt.aculo.us part 37

tailieu.vn

oftentimes the version bundled with script.aculo.us is a little behind the stand-alone version. But the latest script.aculo.us and the latest Prototype, each fetched from its respective web site, are guaranteed to work together.. scriptaculous.js is the main file, the one that declares the script.aculo.us version number and ensures that Prototype is already loaded.. effects.js provides animations and advanced UI flourishes.....

Practical prototype and scipt.aculo.us part 38

tailieu.vn

Figure 10-1. Here, we’re changing the element’s left and top properties from 0px to 50px . When we set the new style, it happens instantaneously—the box jumps down to its new place, as in Figure 10-2.. Figure 10-2. Unfortunately, when we run this code, we find that it behaves exactly the same way as the first example—the box seems to...

Practical prototype and scipt.aculo.us part 39

tailieu.vn

new Effect.Morph('box',. Effect.Morph is smart enough to figure out how to get from A to B.. Perhaps the best thing about Effect.Morph is its ability to animate several different things at once. Effect.Morph handles it with aplomb (see Figure 10-6).. Effect.Morph can animate any number of CSS properties at once.. There’s no way to animate the switch from uppercase to...

Practical prototype and scipt.aculo.us part 40

tailieu.vn

Figure 10-8. Effect.Move animates an element’s position.. Effect.Scale. Effect.Scale handles, well, scaling—changing the size of an element (and, optionally, the size of its contents) by a given percentage (see Figure 10-9):. new Effect.Scale('box', 150);. Figure 10-9. Effect.Scale animates an element’s height and width.. (Note that the contents of the box have been scaled as well—the text is also 150 percent...

Practical prototype and scipt.aculo.us part 41

tailieu.vn

Effect.ScrollTo. Effect.ScrollTo is far more focused than the other core effects. It animates the scrolling of the browser viewport to bring the specified element into view. In other words, it’s a time-lapse version of Prototype’s Element#scrollTo function.. Let’s also change the height of the page so that we’ll have some space below the box:. JS: */new Effect.ScrollTo('box');. It helps the...