Skip to content

Instantly share code, notes, and snippets.

View kangax's full-sized avatar

Juriy Zaytsev kangax

View GitHub Profile
/**
* Usage:
*
* scout()
* .when(typeof JSON === 'undefined')
* .load('/assets/json2.js')
*
* .when(typeof G_vmlCanvasManager !== 'undefined')
* .load('/assets/fabric/cufon.js')
*
loadFromJSON: function (json, callback) {
if (!json) return;
// serialize if it wasn't already
var serialized = (typeof json === 'string')
? JSON.parse(json)
: json;
if (!serialized || (serialized && !serialized.objects)) return;
initialize: function(id, settings) {
this.id = id;
this.settings = Object.extend(Object.clone(this.defaultOptions), settings || { });
this._container = $(this.id + '_Container');
this._controls = $(this.id + '_Controls');
// attach radio & check boxes
this._hueRadio = $(this.id + '_HueRadio');
this._saturationRadio = $(this.id + '_SaturationRadio');

At this point, however, we can begin to look at some complications. There's two areas where I've skipped over some awkward points that get in the way of MVC theory. The first problem area is to deal with setting the color of the variance. This shouldn't really fit into a domain object, as the color by which we display a value isn't part of the domain. The first step in dealing with this is to realize that part of the logic is domain logic. What we are doing here is making a qualitative statement about the variance, which we could term as good (over by more than 5%), bad (under by more than 10%), and normal (the rest). Making that assessment is certainly domain language, mapping that to colors and altering the variance field is view logic. The problem lies in where we put this view logic - it's not part of our standard text field.

This kind of problem was faced by early smalltalkers and they came up with some solutions. The solution I've shown above is the dirty one - compromise some of the purity of the doma

<p class=">">
// outerHTML in Chrome (17): <p class="&gt;">
// outerHTML in Opera (12): <p class=">">
<input disabled>
// outerHTML in Chrome (17) and Opera (12): <input disabled="">
<input />
function makeFunc(o) {
return function() {
o.otherMethod();
};
}
var obj = {
method: makeFunc({
otherMethod: function() {
throw 1;
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script src="https://raw.github.com/kangax/fabric.js/gh-pages/dist/all.js"></script>
</head>
<body>
<canvas id="c" width="600" height="500"></canvas>
<script>
@kangax
kangax / gist:1051534
Created June 28, 2011 16:28 — forked from maxim/progressify.rb
Progressify - a progress bar approximator for smoothness
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Progressify</title>
<script>
var Plot = (function() {
function Point(duration, progress) {
this.duration = duration;
@kangax
kangax / gist:1032025
Created June 17, 2011 18:48
IE9 developer tools annoyances
  1. Can't debug in minimized pane

  2. console.log(1, 2, 3) shows 123 (not 1 2 3)

  3. console.log(undefined, "undefined") shows undefinedundefined. Ditto for null and "null"

  4. Object properties that are on prototype chain are displayed in console (e.g. console.log("foo") displays object with anything defined on String.prototype)

  5. Can't inspect logged object (by clicking on it) [CLOSED BY DESIGN]