From aaaeb7208008fa0c05a8fb79e92233e64ce75f41 Mon Sep 17 00:00:00 2001 From: "Brian J. Miller" Date: Fri, 24 Jan 2014 15:09:09 -0600 Subject: [PATCH] Handle 'category' property in context.contextActivities --- package.json | 2 +- src/ContextActivities.js | 22 ++++++++++++++++++++-- test/js/unit/ContextActivities.js | 28 +++++++++++++++++++++++++++- yuidoc.json | 2 +- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index e3a99c3..5755d0b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tincanjs", "description": "Tin Can API Library", - "version": "0.20.1", + "version": "0.21.1", "private": false, "main": "build/tincan-node.js", "directories": { diff --git a/src/ContextActivities.js b/src/ContextActivities.js index 2efc8a2..f636d9a 100644 --- a/src/ContextActivities.js +++ b/src/ContextActivities.js @@ -30,6 +30,12 @@ TinCan client library var ContextActivities = TinCan.ContextActivities = function (cfg) { this.log("constructor"); + /** + @property category + @type Array + */ + this.category = null; + /** @property parent @type Array @@ -71,6 +77,7 @@ TinCan client library var i, j, objProps = [ + "category", "parent", "grouping", "other" @@ -100,11 +107,11 @@ TinCan client library /** @method add - @param String key Property to add value to one of "parent", "grouping", "other" + @param String key Property to add value to one of "category", "parent", "grouping", "other" @return Number index where the value was added */ add: function (key, val) { - if (key !== "parent" && key !== "grouping" && key !== "other") { + if (key !== "category" && key !== "parent" && key !== "grouping" && key !== "other") { return; } @@ -160,6 +167,17 @@ TinCan client library } } } + if (this.category !== null && this.category.length > 0) { + if (version === "0.9" || version === "0.95") { + this.log("[WARNING] version does not support the 'category' property"); + } + else { + result.category = []; + for (i = 0; i < this.category.length; i += 1) { + result.category.push(this.category[i].asVersion(version)); + } + } + } return result; } diff --git a/test/js/unit/ContextActivities.js b/test/js/unit/ContextActivities.js index 8352db6..9278ae8 100644 --- a/test/js/unit/ContextActivities.js +++ b/test/js/unit/ContextActivities.js @@ -38,6 +38,7 @@ function () { var obj = new TinCan.ContextActivities (), nullProps = [ + "category", "parent", "grouping", "other" @@ -121,7 +122,7 @@ ] } ], - props = [ "parent", "other", "grouping" ], + props = [ "category", "parent", "other", "grouping" ], i, j, instanceConfig, @@ -163,6 +164,31 @@ latest: {} } }, + { + name: "category 1", + instanceConfig: { + category: commonActivity + }, + versions: { + latest: { category: [ commonRaw ] }, + "0.95": {}, + "0.9": {} + } + }, + { + name: "category 2", + instanceConfig: { + category: [ + commonActivity, + commonActivity2 + ] + }, + versions: { + latest: { category: [ commonRaw, commonRaw2 ] }, + "0.95": {}, + "0.9": {} + } + }, { name: "parent 1", instanceConfig: { diff --git a/yuidoc.json b/yuidoc.json index 2134840..aa951f0 100644 --- a/yuidoc.json +++ b/yuidoc.json @@ -1,5 +1,5 @@ { - "version": "0.20.1", + "version": "0.21.1", "name": "TinCanJS", "description": "Library for working with Tin Can API in JavaScript", "url": "http://rusticisoftware.github.com/TinCanJS/",