Skip to content

Instantly share code, notes, and snippets.

View david-mark's full-sized avatar

David Mark david-mark

  • David Mark LLC
  • West Chester, OH
View GitHub Profile
@david-mark
david-mark / gist:3445646
Created August 24, 2012 05:09
Thoughts on jQuery 2.0

The big question regarding the upcoming (and thoroughly unneeded) 2.0 version of this most dubious script is whether its authors are foolish enough to leave "Sizzle" (their QSA fallback) in the code. If they are foolish enough to offer a "solution" that breaks IE 8- users (or requires conditional comments to avoid doing so), can they possibly think that they need anything but QSA to query the DOM?

Another looming question is how a project that has no way to keep track of plug-in compatibility with just one fork going to handle two at once? Poorly I imagine, but that's for those who remain on board to worry about.

Let's deconstruct this "magic" script. It's roughly 70% "Sizzle" (and supporting functions), 10% "Live" (an atrocious event system), 10% outmoded special effects (which can be done far more efficiently with CSS3 transitions and animations) and 10% miscellaneous (and often wildly confused) DOM "normalization" functions (e.g. measuring the viewport dimensions, reading and writing attributes/propertie

@david-mark
david-mark / gist:4312841
Created December 16, 2012 20:54
Unobtrusive JS === Unrealistic JS

Unobtrusive JS === Unrealistic JS

In general, Web developers want to be seen using the very latest and "greatest" Web technologies. We want to add buzzwords to our CV's as soon as they are coined and want to be considered "cutting edge" developers who are "moving the Web forward". Unfortunately, history takes a dim view of our exuberance and science ignores it completely.

Best to start at the beginning with DOM0, which came out in the 90's. Here we have a button that alerts when clicked:

<button type="button" onclick="window.alert('Hello world!')">Click me!</button>
@david-mark
david-mark / devicetype.md
Last active January 5, 2017 13:31
How to Detect the Device Type?

#How to Detect the Device Type?

The question of how to detect the device type running the given browser comes up a lot these days. It's virtually the same question as how to detect the browser (or browser version). It's often incorrectly "solved" in the same way, using indirect inferences based on browser sniffing.

##What is the Problem?

As with most such problems in browser scripting, it's best to look at what is to be inferred from such information. We know from experience that such information will often be based on coincidence and will expire at some point in the future, so it is best not to rely on it. An issue at the turn of the century was how to determine whether the browser was IE or not. But why was that information thought to be necessary? For example, at the time IE used attachEvent instead of the standard addEventListener to add event listeners.

##Indirect Inferences

@david-mark
david-mark / gist:4349216
Last active January 10, 2017 05:14
Progressive Destruction

Progressive Destruction

Last time we looked at the decade-long (and failed) effort to reinvent event listener attachment. We saw that the inherent graceful degradation of HTML still beats the equivalent "unobtrusive" patterns and is certainly a better bet for prototyping an application than the usual suspect DOM libraries.

There's a myth that progressive enhancement is somehow a "better" technique for browser scripting, but the fact is that they are not mutually exclusive and each has its place. This may remind you of a similar argument regarding feature detection vs. browser sniffing, but it certainly doesn't apply in that context.

We left off with the start of a draggable toolbar that works with any manner or combination of pointing devices (including your fingers).

@david-mark
david-mark / promisespoint.md
Last active January 10, 2017 05:16
Promises, Promises

Always dubious on articles that open with "You're missing the point of..." as they so often demonstrate only that the author has missed a trick (or two or three).

It starts out with a note that one of the most popular implementations of Promises is (and will likely remain) broken:

Contrary to some mistaken statements on the internet, the problems with jQuery’s promises explained here are not fixed in recent versions; as of 2.1 beta 1 they have all the same problems outlined here, and according to one jQuery core team member, they will forever remain broken, in the name of backward compatibility.

Have heard rumors that this is fixed in jQuery 3.0, but jQuery should be a dead issue by now. Perpetually updating a long since irrelevant (and also non-standard) implementation of the browser-provided Selectors API is a non-starter. Using such a thing for a tacked-on Promises implementation can only be attributed to some sort of misguided bran

@david-mark
david-mark / angular-jqlite.adoc
Created January 17, 2017 06:56 — forked from esfand/angular-jqlite.adoc
Angular jqLite

Angular jqLite

jQuery and Angular

Angular doesn’t depend on jQuery. In fact, the Angular source contains an embedded lightweight alternative: jqLite. Still, when Angular detects the presence of a jQuery version in your page, it uses that full jQuery implementation in lieu of jqLite. One direct way in which this manifests itself is with Angular’s element abstraction. For example, in a directive you get access to the element that the directive applies to:

@david-mark
david-mark / crossbrowser.md
Last active January 17, 2017 21:44
Understanding Cross-browser Scripting

#Understanding Cross-browser Scripting

Cross-browser was invented around the turn of the century and is needed more today than ever. Unfortunately, it is also massively misunderstood, both by library developers and their users.

##What Cross-Browser Scripting is Not

Before getting into what cross-browser scripting is, let's look at what it is not. Cross-browser scripting does not imply that scripts will work in every browser and configuration known to man. Certainly a script that does work in every conceivable environment would be considered cross-browser, but such expectations are neither realistic, nor a requirement for a script to be considered cross-browser.

Depsite marketing claims, popular libraries such as jQuery and Lodash are neither cross-browser nor cross-platform. It's critical to understand that they are multi-browser and multi-platform, working in a handful of environments deemed worthy by their authors at the time of each version release. Th

var express = require('express');
var subtitlesUrl = 'http://your-local-ip:8000/subtitles.vtt';
var app = express();
app.use(function(req, res, next) {
res.header('transferMode.dlna.org', 'Streaming');
res.header('contentFeatures.dlna.org', 'DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000')
res.header('CaptionInfo.sec', subtitlesUrl);
@david-mark
david-mark / hostobjectdetection.md
Last active February 1, 2018 03:01
The Last Word on Host Object Feature Detection

Having had some of the first words on "modern" host object detection and testing, feel like it's time to try to issue a final word. At least I hope it is the last word as I've seen a lot misinformation spread over the last several years. The Web is great for that. :)

The original observations and concepts came about from discussions on comp.lang.javascript (CLJ) and were written up by Peter Michaux almost a decade ago.

The first rule to remember is that - with regard to detection - we don't know anything about host objects. How are they implemented? Why do they behave like they do? We can never really know as - unlike objects native and built into javascript (JS) implementations - there are no ECMA specifications for host objects. They are described in t

@david-mark
david-mark / gist:3279190
Created August 6, 2012 22:47
Sencha Touch Still Sucks

Was asked to look at this thing again; only reviewed the JS portion. Last I checked, the CSS was similarly reality-challenged. Graphics are nice, but are tantamount to the paint job on a used car. Under the hood, this thing is all junk. It's hard to imagine the innards of any Web or mobile device-based application would end up like this, which raises the question of whether the authors have ever written such applications (or any amount of meaningful JS).

/**
 * @class Ext
 * @singleton

There (still) are no "classes" or "singletons" in JS (starting off on the wrong foot by mangling JS terms).