Skip to content

Instantly share code, notes, and snippets.

getCustomStates: function() {
var isSuspendDataStoreEmpty = _.isEmpty(suspendDataStore);
if (!isSuspendDataStoreEmpty && suspendDataRestored) return _.clone(suspendDataStore);
var dataAsString = scorm.getSuspendData();
if (dataAsString === "" || dataAsString === " " || dataAsString === undefined) return {};
var dataAsJSON = this.tryParseJsonWithDefault(dataAsString, {});
if (!isSuspendDataStoreEmpty && !suspendDataRestored) dataAsJSON = _.extend(dataAsJSON, suspendDataStore);
@cajones
cajones / gist:66b665cdd06c2c1452a78d4a616529b5
Created September 9, 2016 09:23
Locating the SCORM API from a module
function locateScormAPI() {
function findAPI(win) {
var attempts = 0;
while (win.API == null && win.parent != null && win.parent != win) {
if (++attempts > 7) return null;
win = win.parent;
}
return win.API;
}
return findAPI(window) || findAPI(window.opener);
@cajones
cajones / Gruntfile.js
Created January 6, 2015 10:11
Fragment of Gruntfile.js - Adding an additional copy task for favicon.ico
/* ... do setup here (omitted for brevity) ... */
grunt.initConfig({
/* ... add a configuration to the copy task ... */
copy: {
/* this config copies the index page from src, leave this alone! */
index: {
files: [
{
expand: true,
src: ['src/index.html'],
@cajones
cajones / install.ps1
Created September 17, 2014 15:31
WIndows MongoDB install script
function Download-File($url, $file) {
Write-Host $url
$webclient = New-Object System.Net.WebClient
$webclient.DownloadFile($url, $file)
return $file
}
$mongoInstaller = 'C:\temp\mongodb-windows-installer.msi'
if(!(Test-Path $mongoInstaller)) {
$osArchitecture = (wmic os get osarchitecture) | ? { $_ -like '*-bit*'}
@cajones
cajones / my-plugin.js
Last active August 29, 2015 14:04
Ideas for Experimental Adapt API for deferred readiness
define(['coreJs/adapt', 'jquery'], function (Adapt, $) }{
var readiness = Adapt.deferReadiness(); //signal the Core that I want to delay startup
//do something async
$.getJson('/data').always(function (data) {
readiness.advance(); //signal that the plugin is ready to move on.
});
{
"_id":"c-140",
"_parentId":"b-70",
"_type":"component",
"_component":"vmcq",
"_classes":"",
"_layout":"full",
"_attempts":1,
"_questionWeight":1,
"_isRandom":false,
@cajones
cajones / bower.json
Last active August 29, 2015 14:00
how to reference jquery mobile from an adapt plugin. This assumes that you have jquery.mobile-1.4.2min.js in the same directory. This can be used to detect orientation change events.
{
"name":"adapt-orientation-change",
"main":"main.js"
}
@cajones
cajones / adapt.json
Created April 25, 2014 14:31
Adapt JSON for beta development branch
{
"dependencies": {
"adapt-contrib-vanilla": "develop",
"adapt-contrib-text": "develop",
"adapt-contrib-narrative": "develop",
"adapt-contrib-media": "develop",
"adapt-contrib-hotgraphic": "develop",
"adapt-contrib-blank": "develop",
"adapt-contrib-accordion": "develop",
"adapt-contrib-graphic": "develop",
@cajones
cajones / gist:10718907
Created April 15, 2014 09:53
Lodash mixin to produce the product of two arrays.
_.mixin({
'combine': function (xArray, yArray, func) {
return xArray.map(function (x) {
return yArray.map(function (y) {
return func(x, y);
});
});
}
});
@cajones
cajones / gist:9052737
Last active August 29, 2015 13:56
Q example
var Q = require('Q');
var mongo = require('mongodb').MongoClient;
var main = function(){
connect('mongodb://localhost')
.then(close)
.catch(logError);
};
function connect(url) {