Skip to content

Commit

Permalink
release v1.4.0 fix #32 (see changelog for more details)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouzi committed Mar 7, 2015
1 parent 769a378 commit 37b7e92
Show file tree
Hide file tree
Showing 27 changed files with 4,971 additions and 60 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
Full documentation on usage, configuration, features and so on is available on the [TheaterJS Wiki](https://github.com/Zhouzi/TheaterJS/wiki).
Feel free to submit any [suggestions/issues](https://github.com/Zhouzi/TheaterJS/issues) and [contribute](https://github.com/Zhouzi/TheaterJS/blob/gh-pages/CONTRIBUTING.md) to TheaterJS.

**Note:** Please make sure you are not confusing this project with [TheatreJS](http://theatrejs.org/).
**Note:** Please make sure you are not confusing this project with [TheatreJS](http://theatrejs.org/).
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TheaterJS",
"version": "1.3.2",
"version": "1.4.0",
"main": "build/theater.js",
"license": "MIT",
"ignore": [
Expand Down
50 changes: 23 additions & 27 deletions build/theater.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

TheaterJS.prototype = {
constructor: TheaterJS,
version: "1.3.2",
version: "1.4.0",
keyboards: {},


Expand Down Expand Up @@ -109,22 +109,11 @@
utils: {
keyboard: {},

copy: function (obj) {
var copy = {},
prop;

for (prop in obj) {
if (obj.hasOwnProperty(prop)) copy[prop] = obj[prop];
}

return copy;
},

isArray: function (a) { return a instanceof Array; },
isFunction: function (f) { return typeof f === "function"; },
isString: function (s) { return typeof s === "string"; },
isNumber: function (n) { return typeof n === "number"; },
isObject: function (o) { return o instanceof Object; },
isObject: function (o) { return !this.isArray(o) && !this.isFunction(o) && o instanceof Object; },
stripHTML: function (str) { return str.replace(/(<([^>]+)>)/gi,""); },

mapHTML: function (str) {
Expand Down Expand Up @@ -233,16 +222,19 @@
},

hasClass: function (el, className) {
/* istanbul ignore next: http://youmightnotneedjquery.com/ */
if (el.classList) return el.classList.contains(className);
else return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
},

addClass: function (el, className) {
/* istanbul ignore next: http://youmightnotneedjquery.com/ */
if (el.classList) el.classList.add(className);
else el.className += ' ' + className;
},

removeClass: function (el, className) {
/* istanbul ignore next: http://youmightnotneedjquery.com/ */
if (el.classList) el.classList.remove(className);
else el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
}
Expand All @@ -251,6 +243,7 @@

// When describing a new actor, train merges its attributes with the defaults
train: function (actor) {
/* istanbul ignore next */
var self = this,
defaults = {
experience: .6,
Expand Down Expand Up @@ -287,9 +280,9 @@


// Add a scene to the scenario
write: function () {
write: function (args) {
var self = this,
scenes = Array.prototype.splice.apply(arguments, [0]), // the write function can have an infinite number of params
scenes = self.utils.isArray(args) ? args : Array.prototype.splice.apply(arguments, [0]), // the write function can have an infinite number of params
scene;

for (var i = 0, l = scenes.length; i < l; i++) {
Expand All @@ -302,15 +295,15 @@
speech = params.join(":").replace(/\\:/g, ":");

if (hasActor) self.write({ name: "actor", args: [actor] });
if (self.options.erase && hasActor) self.write({ name: "erase" });
if (self.options.erase && hasActor) self.write({ name: "erase", args: [] });

self.write({ name: "say", args: [speech, !hasActor] });
} else if (typeof scene === "number") {
} else if (self.utils.isNumber(scene)) {
if (scene < 0) self.write({ name: "erase", args: [scene] });
else self.write({ name: "wait", args: [scene] });
} else if (typeof scene === "function") {
} else if (self.utils.isFunction(scene)) {
self.write({ name: "call", args: [scene] });
} else if (scene instanceof Object) {
} else if (self.utils.isObject(scene)) {
self.scenario.push(scene);
}
}
Expand All @@ -325,10 +318,10 @@
play: function (restart) {
var self = this;

if (self.state !== "playing") {
// if restart is passed as true, start from scratch
if (restart === true) self.scene = -1;
// if restart is passed as true, start from scratch
if (restart === true) self.scene = -1;

if (self.state !== "playing") {
// if scenario is not yet playing, do it!
self.state = "ready";
self.next();
Expand Down Expand Up @@ -362,12 +355,15 @@

// emit event
emit: function (scope, event, args) {
var self = this;

if (!self.utils.isString(event)) event = void 0;
else if (event !== void 0 && args === void 0) args = event;
var self = this,
eventName = scope;

var eventName = scope + (event ? ":" + event : "");
if (!self.utils.isString(event)) {
if (args == void 0) args = event;
event = null;
} else {
eventName += ":" + event;
}

self
.trigger(eventName, args)
Expand Down
2 changes: 1 addition & 1 deletion build/theater.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ gulp.task("styles", function () {
.pipe(gulp.dest("build"));
});

gulp.task("coverage", function () { return gulp.src("test/coverage/*/index.html").pipe(plugins.open('<%file.path%>')); });
gulp.task("serve", ["default"], function () { gulp.src("").pipe(plugins.webserver()); });
gulp.task("watch", ["default"], function () { gulp.watch("src/**/*.js", ["scripts"]); gulp.watch("src/styles.scss", ["styles"]) });
gulp.task("default", ["scripts", "styles"]);
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
var args = Array.prototype.splice.apply(arguments, [3]),
log = '{\n name: "' + sceneName + '"';

if (args.length > 0) log += ",\n args: " + JSON.stringify(args).split(",").join(", ").replace(/</g, '&lt;').replace(/>/g, '&gt;');
log += ",\n args: " + JSON.stringify(args).split(",").join(", ").replace(/</g, '&lt;').replace(/>/g, '&gt;');
log += "\n }";

$log.innerHTML = log;
Expand Down

0 comments on commit 37b7e92

Please sign in to comment.