Saturday, June 30, 2007

Nicholas C. Zakas: dynamically inserting CSS into your page

Itt van az egesz, de a lenyeg:

Safari requires dynamically created <style/> elements to be inserted into the for the rules to be applied

When IE encounters style.appendChild() it throws the rather obtuse and not-very-helpful error message, “unexpected call to method or property access”. Try replacing that with a call to set innerHTML, and you’ll get an equally useless error message of “unknown runtime error”. What’s going on here? It turns out that IE won’t let you manipulate <style/> elements in this way. There is, however, a different way to do the same thing. IE supports a styleSheet property on each style element that allows for the manipulation of the style sheet and the rules contained within. The styleSheet property has a property called cssText, which can be used to set and retrieve the CSS text for the style sheet.

This code now works in all A-grade browsers:

function addCss(cssCode) {
var styleElement = document.createElement(”style”);
styleElement.type = “text/css”;
if (styleElement.styleSheet) {
styleElement.styleSheet.cssText = cssCode;
} else {
styleElement.appendChild(document.createTextNode(cssCode));
}
document.getElementsByTagName(”head”)[0].appendChild(styleElement);
}

A warning: IE only allows writing to styleSheet.cssText one time per <style> element. If you try to do it more than one time, it can crash the browser. For this reason, it’s best not to reuse <style> elements on your page. Instead, remove them or just add new ones.

A commentek kozul:

According to the HTML 4.01 spec section 14.2.3, style tags must be contained in the head element: “HTML permits any number of STYLE elements in the HEAD section of a document.”

Link to the spec:
http://www.w3.org/TR/html401/present/styles.html#edef-STYLE

browser csoportositas a YUI-nel

Azt irjak, hogy tobb mint 10.000 fele browser marka, verzio es konfiguracio van ezert ok teszteles szempontjabol 3 csoportba bontottak oket:

C-grade

C-grade is the base level of support, providing core content and functionality. It is sometimes called core support. Delivered via nothing more than semantic HTML, the content and experience is highly accessible, unenhanced by decoration or advanced functionality, and forward and backward compatible. Layers of style and behavior are omitted.

C-grade browsers are identified on a blacklist. Approximately 3% of our audience receives a C-grade experience.

Summary: C-grade browsers are identified, incapable, antiquated and rare. QA tests a sampling of C-grade browsers, and bugs are addressed with high priority.

A-grade

A-grade support is the highest support level. By taking full advantage of the powerful capabilities of modern web standards, the A-grade experience provides advanced functionality and visual fidelity.

A-grade browsers are identified on a whitelist. Approximately 96% of our audience enjoys an A-grade experience.

Summary: A-grade browsers are identified, capable, modern and common. QA tests all A-grade browsers, and bugs are addressed with high priority.

X-grade

X-grade provides support for unknown, fringe or rare browsers. Browsers receiving X-grade support are assumed to be capable. (If a browser is shown to be incapable — if it chokes on modern methodologies and its user would be better served without decoration or functionality — then it is considered a C-grade browser.)

X-grade browsers include all browsers not on the C-grade blacklist or the A-grade whitelist. Approximately 1% of our audience receives the X-grade experience.

Summary: X-grade browsers are generally unknown, assumed to be capable, modern, and rare or fringe. QA does not test, and bugs are not opened against X-grade browsers.

The Relationship Between A- and X-grade Support

A bit more on the relationship between A and X grade browsers: One unexpected instance of X-grade is a newly-released version of an A-grade browser. Since thorough QA testing is an A-grade requirement, a brand-new (and therefore untested) browser does not qualify as an A-grade browser. This example highlights a strength of the Graded Browser Support approach. The only practical difference between A and X-grade browsers is that QA actively tests against A-grade browsers.

Unlike the C-grade, which receives only HTML, X-grade receives everything that A-grade does. Though a brand-new browser might be characterized initially as a X-grade browser, we give its users every chance to have the same experience as A-grade browsers.

javascriptben lassuak a bitwise operatorok

Crockford video (30:10)

Mert eloszor atkonvertaljak a 64 bites floating point-ban tarolt szamot 32 bites signed integerre, aztan shiftelik es utana visszakonvertaljak az eredmenyt 64 bites floating point-ba.

Tehat a shiftelgetes itt lassabb lesz mintha siman megszoroznank mondjuk kettovel az erteket.

&& es || operatorok javascriptben

Crockford video (28:20)

&& operator

  • The guard operator, aka logical and
  • If first operand is truthy
    then result is second operand
    else result is first operand
  • It can be used to avoid null references
    if (a) {
    return a.member;
    } else {
    return a;
    }
  • can be written as
    return a && a.member;

|| operator

  • The default operator, aka logical or
  • If first operand is truthy
    then result is first operand
    else result is second operand
  • It can be used to fill in default values.
    var last = input || nr_items;
  • (If input is truthy, then last is input, otherwise set last to nr_items.)

Friday, June 29, 2007

== es != operatorok tipust castolhatnak javascriptben

Ezert jobb a === es a !== operatorokat hasznalni mert azok a tipusellenorzest is elvegzik

var a = 5
var b = “5″

Print(a == b) //True
Print(a === b) //False

Crockford video (27:25)

falsy - truthy values in javascript

Crockford video (20:40)

Falsy values:

  • false
  • null
  • undefinded
  • “” (empty string)
  • 0
  • NaN

All other values (including all Objects) are truthy “0″, “false”

NaN != NaN

Javascriptben a NaN nem egyenlo semmivel, meg onmagaval sem.

Es azzal egyutt, hogy a NaN azt jelenti, hogy Not a Number, a tipusa megis number:

Print(typeof(NaN)) // number

Numbres in javascript

Douglas Crockford video (13:40)
  • Only one number type (No integers)
  • 64-bit floating point
  • IEEE-754 (aka “Double”)
  • Does not map well to common understanding of arithmetic:
  • 0.1 + 0.2 = 0.30000000000000004

Tehat az Crackford tanacsa, hogy ha penzzel szamolunk akkor szorozzuk fel szazzal az operandusokat, vegezzuk el a szamitast majd az eredmenyt osszuk vissza szazzal.

Wednesday, June 27, 2007

Brad Abrams: Silent install of the .NET Framework

Itt van az eredeti, de inkabb bemasolom az egeszet:

When I talked to ISV, they often just want to use the .NET Framework as an implementation detail of their applications.. they don’t want their users to have to go to windows update or MSDN to download the framework, and they don’t want to have some Microsoft setup UI popping up during the install experience of their application.

For this scenario, we have a little known feature of setup where you can install it the .NET Framework silently.. that is with no-UI popping up at all. This allows you to have full control of the experience…

For .NET FX 3.0: the magic command line is: Dotnetfx3.exe /q
See this white paper for more details.

Oh, and if you are still on .NET Fx 2.0, the command is: Dotnetfx.exe /q:a /c:”install /q”
And you can find more out here.

lifted function

Eric Lippert irt rola a C# 2.0 Standard-ban tortent teves hasznalat kapcsan:

Precisely what mathematicians mean by “lifted”.

Suppose we’ve got a function f which maps values from a set A into a set B. That is f:A→B.

Suppose further that null is not a member of either A or B.

Now consider the sets A’ = A ∪ { null } and B’ = B ∪ { null }

We define the “lifted function” f’ as

f’:A’→B’ such that f’(x) = f(x) for all x ∈ A and f’(null) = null

Similarly, if we had a two-argument function f: A × B → C, we would define f’: A’ × B’ → C’ as f’(x,y) = f(x,y) for all (x,y) ∈ A × B and null if either x or y is null.

What we’re getting at here is that “lifted” means “takes nulls, always agrees with the unlifted version when arguments are not null, maps everything else onto null”.

ubiquitous, mature

ubiquitous: mindenutt jelenlevo, szeles korben hasznalt

mature: megfontolt, atgondolt, erett

Tuesday, June 26, 2007

parseInt radix attibutuma

A javascript-ben a parseInt igy nez ki:

parseInt(string[, radix])

A radix-et tehat el lehet hagyni csak nem erdemes, mert ha nem adjuk meg akkor a string alapjan probalja megallapitani es ha “0″-val kezdodik akkor 8-as alapunak veszi es peldaul a “011″-bol decimalis 9 lesz, a “08″-bol pedig 0, mert ugye 8 nincs okatlis szamrendszerben.