Skip to content

Instantly share code, notes, and snippets.

@mattparker
Created October 16, 2012 12:34
Show Gist options
  • Select an option

  • Save mattparker/3898998 to your computer and use it in GitHub Desktop.

Select an option

Save mattparker/3898998 to your computer and use it in GitHub Desktop.
To assign the correct graphics implementation when all are loaded statically
// relates to YUI ticket http://yuilibrary.com/projects/yui3/ticket/2532864
//
//
YUI.add("graphics-static-chooser", function (Y) {
//
//
// Loading graphics (statically) using the configurator is tricky,
// because it feature detects on the browser you're using the configurator
// on, rather than the browser that will be used to view a graphic.
//
// So, we need to include the graphics stuff for all 3 engines
// (canvas, svg, vml) and then feature detect after they are all
// loaded, and assign the correct type to the 'generic' objects.
// So, if we're using SVG, we'll want to call
// Y.Path = Y.SVGPath
// manually
//
// There also seems to be a bug in configurator that loads the graphics
// bit in the wrong order.
//
//
// So after all the Y.SVGGraphic, Y.CanvasGraphic, Y.VMLGraphic is
// YUI.add()ed we do a feature detection and assign accordingly.
//
// The features test functions are all built and added automatically
//
// http://yui.yahooapis.com/3.7.2/build/features/features-debug.js
//
// The numbers in each call to test() below refer to the
// tests for different graphics features. This seems rather
// fragile but there's not obviously any way to find the right test
// to do without looping through the Y.Features.tests object and looking
// for the names we want. Maybe I should do that... This will only
// happen once, after all.
//
// For now, '6' == "graphics-canvas"
// '8' == "graphics-svg"
// '10' == "graphics-vml"
//
// I'm also not clear what the correct order of these tests should be.
//
// The code in each block is the content of the relevant block
// that would usually get conditionally loaded.
//
if (Y.Features.test('load', '6', [Y])) {
YUI().use("graphics-canvas", function (y) {
// this is the content of graphics-canvas-default
Y.Graphic=y.CanvasGraphic;
Y.Shape=y.CanvasShape;
Y.Circle=y.CanvasCircle;
Y.Rect=y.CanvasRect;
Y.Ellipse=y.CanvasEllipse;
Y.Path=y.CanvasPath;
Y.Drawing=y.CanvasDrawing;
});
} else if (Y.Features.test('load', '8', [Y])) {
YUI().use("graphics-svg", function (y) {
// this is the content of graphics-svg-default
Y.Graphic=y.SVGGraphic;
Y.Shape=y.SVGShape;
Y.Circle=y.SVGCircle;
Y.Rect=y.SVGRect;
Y.Ellipse=y.SVGEllipse;
Y.Path=y.SVGPath;
Y.Drawing=y.SVGDrawing;
});
} else if (Y.Features.test('load', '10', [Y])) {
YUI().use("graphics-vml", function (y) {
// this is the content of graphics-vml-default
Y.Graphic=y.VMLGraphic;
Y.Shape=y.VMLShape;
Y.Circle=y.VMLCircle;
Y.Rect=y.VMLRect;
Y.Ellipse=y.VMLEllipse;
Y.Path=y.VMLPath;
Y.Drawing=y.VMLDrawing;
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment