Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #9114
| From | Matt McDonald <matt@fortybelow.ca> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: MS Excel mashup |
| Date | 2011-12-10 20:27 -0700 |
| Organization | A noiseless patient Spider |
| Message-ID | <jc17vt$h32$1@dont-email.me> (permalink) |
| References | <LfednVuBOfRzaH7TnZ2dnUVZ_oGdnZ2d@westnet.com.au> |
On 12/10/2011 5:14 PM, Andrew Poulos wrote:
> I just checked out Microsoft's "new" Excel "mashup"
> <http://www.excelmashup.com/>
> and the examples use jquery.
Unsurprising. I see Microsoft has taken to using an
in-browser "text editor" ("CodeMirror"). When will people
learn that such projects are tremendous wastes of time?
If you can recall, Microsoft made a "native" HTML 5
"demo"[0] with some drag/drop pieces. The name of one
of the script files used was "FeatureDetection"(.js)[1].
It was ironically—of course—rife with user-agent sniffing.
In one word, it was spaghetti. To wit, it doesn't work in
Opera 11.60 and the drag "target" disappears while "dragging"
in Chrome 15. What's truly astonishing is whomever wrote that
script botched Opera "sniffing". How hard is it to "sniff" for
`global.opera`? That's child's play.
> Is this
> $("#Meal").hide();
> really better than
> document.getElementById("Meal").style.visibility = "hidden";
Neither are preferable. Try to keep style out of JavaScript.
Let CSS (classes) dictate style.
For example, a class such as the following is an idea:
.invisible
{
visibility: hidden;
}
Even so, the class name is dictated by style. That goes against
advice given by Garrett Smith in the CLJ FAQ[2] and surely
others. Without knowing the purpose for such code, the class
name *should* be representative of a feature. This nomenclature
is optimal:
.animating
{
position: relative;
}
Instead of labeling it "relative", the class has been named
after a feature. There's no need for a polar opposite as
removing a class from an element will remove the corresponding
style as well. This is a very powerful technique. By utilizing
it, one can leave style out of JavaScript (aside from dynamic
calculations such as animation).
> [...](By "hide" I'm assuming that jquery is
> referring to style.visibility and not style.display nor style.opacity.)
Per James Padolsey's "jsapi.info" website[3], my suspicions
are confirmed. `hide()` is a wrapper for `display: none;`.
I took to breaking up one of jQuery's infamously long lines
of code into something sensible. Here, you can see more
inane binding of the `this` value. If you search the entire
source, `apply` and `call` will probably be the most popular
methods (in fact, ".apply(" has 30 matches in jQuery 1.7.1
while ".call(" has *60* matches). It's one of the many reasons
jQuery blows up in older browsers (aside from general myopia).
Code below:
var elem, display,
i = 0,
j = this.length;
for ( ; i < j; i++ ) {
elem = this[i];
if ( elem.style ) {
display = jQuery.css( elem, "display" );
if ( display !== "none" &&
!jQuery._data( elem, "olddisplay" ) ) {
jQuery._data( elem, "olddisplay", display );
}
}
}
// Set the display of the elements in a second loop
// to avoid the constant reflow
for ( i = 0; i < j; i++ ) {
if ( this[i].style ) {
this[i].style.display = "none";
}
}
The full snippet[4] is accessible through "jsapi".
Links:
[0]: http://ie.microsoft.com/testdrive/Graphics/MagneticPoetry/Default.html
[1]: http://ie.microsoft.com/testdrive/Includes/Script/FeatureDetection.js
[2]:
http://www.fortybelow.ca/hosted/comp-lang-javascript/faq/notes/code-guidelines/
[3]: http://jsapi.info
[4]: http://jsapi.info/jquery/1.7/jQuery.fn.hide/
Notes:
[*]: Regarding links[2], the "CSS" section is being referred to.
--
Matt McDonald: Web/Flash Developer; Edmonton, Alberta, Canada
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
MS Excel mashup Andrew Poulos <ap_prog@hotmail.com> - 2011-12-11 11:14 +1100
Re: MS Excel mashup Matt McDonald <matt@fortybelow.ca> - 2011-12-10 20:27 -0700
Re: MS Excel mashup Andrew Poulos <ap_prog@hotmail.com> - 2011-12-11 16:57 +1100
Re: MS Excel mashup Jake Verbaten <raynos2@gmail.com> - 2011-12-11 10:25 -0800
Re: MS Excel mashup Andrew Poulos <ap_prog@hotmail.com> - 2011-12-12 08:24 +1100
Re: MS Excel mashup David Mark <dmark.cinsoft@gmail.com> - 2011-12-11 14:16 -0800
Re: MS Excel mashup David Mark <dmark.cinsoft@gmail.com> - 2011-12-11 14:07 -0800
Re: MS Excel mashup David Mark <dmark.cinsoft@gmail.com> - 2011-12-11 14:01 -0800
csiph-web