Skip to content

Instantly share code, notes, and snippets.

View philmander's full-sized avatar

Phil Mander philmander

View GitHub Profile
@philmander
philmander / casper.fetchMicrodata.js
Last active August 29, 2015 13:58
Microdata util for CasperJS
//microdata polyfill (see https://github.com/termi/Microdata-JS)
casper.options.clientScripts.push("../../../support/a.js");
casper.options.clientScripts.push("../../../support/microdata-js.js");
/**
* Fetches microdata from the remote DOM environment, in a json object structure.
* @param itemType The item type of item scopes to fetch data for
* @returns {Object|mixed}
*/
casper.fetchMicrodata = function(itemType) {
// Mixed.js
define(function() {
var Mixed = function(a, b) {
this.a = a;
this.b = b;
};
Mixed.prototype.getA = function() {
return this.a;
};
Mixed.prototype.getB = function() {
//app-config.js
define(function() {
return {
protos: {
movieLister: {
module: "movies/movie-lister",
args: [
"*movieFinder"
]
mixin: {
@philmander
philmander / inverted-interface-1.js
Last active December 11, 2015 00:09
Demonstrates using an interface in the app config
//app-config.js
define(function() {
return {
protos: {
movieLister: {
module: "movies/movie-lister",
args: [
//injects a json movie finder which must implement the movieFinder interface
"*jsonMovieFinder [movieFinder]"
]
@philmander
philmander / inverted-inject-context-1.js
Last active December 11, 2015 00:09
Demonstrates property injecting the appContext into a proto instance
// movies/move-finder.js
define(["jquery"], function($) {
var MovieFinder = function() {
var self = this;
$(document).on("click", ".open-prefs", function() {
self.openPreferences();
});
};
MovieFinder.prototype.openPreferences = function() {
// movies/movie-lister.js
var MovieLister = function(movieFinder) {
this.movieFinder = movieFinder;
};
MovieLister.prototype.showMovies = function(query) {
var keywords = query.split(" ");
var movieResult = this.movieFinder.getMovies(keywords);
//example app config defining a jquery proto
define({function() {
return: {
protos: {
jquery: {
//assuming jquery's url is
//defined in the amd paths config
module: "jquery",
scope: "static"
},
@philmander
philmander / inverted-app-config-reference.js
Last active December 10, 2015 10:59
Reference Inverted application config object.
var applicationConfig = {
// a map of 'protos', inverted objects
protos: {
//the unique id of a proto
protoId: {
//the amd or common js module name which exports the proto
module: "moduleName",
//contructor arguments to inject into protos with prototype or singleton scope
args: [
//a literal value argument
@philmander
philmander / inverted-factory-1.js
Created December 31, 2012 20:58
Using factory methods to generate values or dependencies to inject
//movies/move-finder.js
define(function() {
var MovieFinder = function(username, accessCode) {
this.username = username;
this.accessCode = accessCode;
};
return MovieFinder;
});
//movies/movie-util.js
@philmander
philmander / inverted-inheritance-1.js
Created December 31, 2012 20:48
Creating a prototypal inheritance chain with the Inverted
//movies/json-movie-finder.js
define(function() {
var JsonMovieFinder = function(jsonpUrl) {
this.jsonpUrl = jsonpUrl;
};
return JsonMovieFinder;
});
//movies/base-movie-finder.js