Firefox compatibility fixes.

This commit is contained in:
Alan Johnson
2010-09-11 18:07:40 -04:00
parent 2c3b97bb66
commit b4bac7f4f9
2 changed files with 5 additions and 8 deletions
+4 -7
View File
@@ -17,7 +17,7 @@ Handlebars = {
},
isFunction: function(fn) {
return typeof fn == "function";
return Object.prototype.toString.call(fn) == "[object Function]";
},
escapeText: function(string) {
@@ -142,7 +142,7 @@ Handlebars = {
return true;
} else if (!value) {
return true;
} else if(toString.call(value) === "[object Array]" && value.length == 0) {
} else if(Object.prototype.toString.call(value) === "[object Array]" && value.length == 0) {
return true;
} else {
return false;
@@ -192,18 +192,16 @@ Handlebars.SafeString.prototype.toString = function() {
Handlebars.helperMissing = function(object, fn) {
var ret = "";
console.log(object);
if(object === true) {
return fn(this);
} else if(object === false) {
return "";
} else if(object.constructor === Array) {
} else if(Object.prototype.toString.call(object) === "[object Array]") {
for(var i=0, j=object.length; i<j; i++) {
ret = ret + fn(object[i]);
}
return ret;
} else {
console.log("HERE!");
return fn(object);
}
};
@@ -261,7 +259,6 @@ Handlebars.Compiler.prototype = {
addExpression: function(mustache, param) {
var expr = this.lookupFor(mustache);
this.fn += "if (Handlebars.isFunction(" + expr + ")) out = out + Handlebars.filterOutput(" + expr + ".call(Handlebars.buildContext(context, stack), " + param + "), " + this.escaped + "); ";
this.fn += "else if(typeof " + expr + "!== 'undefined') out = out + Handlebars.filterOutput(" + expr + ", " + this.escaped + "); ";
},
@@ -295,7 +292,7 @@ Handlebars.Compiler.prototype = {
if (depth > 0) {
return "( stack[stack.length - " + depth + "]" + paramExpr + ")";
} else {
return "( context" + paramExpr + " || fallback " + paramExpr + " )";
return "( context" + paramExpr + " || fallback" + paramExpr + " )";
}
},
+1 -1
View File
@@ -2,7 +2,7 @@ module("basic context");
var shouldCompileTo = function(string, hash, result, message) {
var template = Handlebars.compile(string);
var params = toString.call(hash) === "[object Array]" ? hash : [hash, undefined];
var params = Object.prototype.toString.call(hash) === "[object Array]" ? hash : [hash, undefined];
equal(template.apply(this, params), result, message);
}