Index: /lang/javascript/nanashi.js/nanashi.js
===================================================================
--- /lang/javascript/nanashi.js/nanashi.js (revision 19102)
+++ /lang/javascript/nanashi.js/nanashi.js (revision 19109)
@@ -8,7 +8,7 @@
 if (typeof(window.nanashi) == "undefined") window.nanashi = {};
 
-nanashi.namespace = function (nsName, fn) {
+nanashi.namespace = function(nsName, fn) {
 	if (typeof(nsName) != "string") return;
-	
+
 	// create namespace
 	var tokens = (nsName.length > 0) ? nsName.split(".") : [];
@@ -19,13 +19,13 @@
 		ns = ns[t];
 	}
-	
+
 	// bind properties
 	var props = (typeof(fn) == "function") ? fn(ns) : fn;
-	if(typeof(props) != "object") return;
-	
-	for(var key in props) {
+	if (typeof(props) != "object") return;
+
+	for (var key in props) {
 		ns[key] = props[key];
 	}
-}
+};
 
 nanashi.proto = (function() {
@@ -60,10 +60,10 @@
 			if (typeof(props) != "object") continue;
 			for (var key in props) {
-				if(typeof(p[key]) == "undefined") p[key] = props[key];
+				if (typeof(p[key]) == "undefined") p[key] = props[key];
 			}
 		}
 		return this;
 	}
-	
+
 	function newInstance(/* ... */) {
 		if (arguments.length <= 0) {
@@ -73,32 +73,32 @@
 			var init = p.initialize;
 			p.initialize = null;
-			
+
 			var instance = new this();
 			init.apply(instance, arguments);
-			
+
 			p.initialize = init;
-			
+
 			return instance;
 		}
 	}
-	
-	var Basetype = function () {}
-	Basetype.prototype.invokesuper = function (method, data) {
+
+	var Basetype = function() {};
+	Basetype.prototype.invokesuper = function(method, data) {
 		if (!this.__refsuper) this.__refsuper = this.constructor;
 		var self = this.__refsuper;
 		var parent = this.__refsuper.supertype;
-		
+
 		this.__refsuper = parent;
 		var ret = parent.prototype[method].apply(this, data || []);
 		this.__refsuper = self;
-		
+
 		if (this.__refsuper == this.constructor) delete this.__refsuper;
-		
+
 		return ret;
-	}
-	
-	return function (supertype) {
+	};
+
+	return function(supertype) {
 		if (typeof(supertype) != "function") supertype = Basetype;
-		
+
 		var Subtype = function() {
 			var init = this.initialize;
@@ -106,5 +106,5 @@
 			return init.apply(this, arguments);
 		};
-		
+
 		var F = function() {};
 		F.prototype = supertype.prototype;
@@ -112,5 +112,5 @@
 		Subtype.prototype.constructor = Subtype;
 		Subtype.supertype = supertype;
-		
+
 		Subtype.def   = def;
 		Subtype.undef = undef;
@@ -118,5 +118,5 @@
 		Subtype.alias = alias;
 		Subtype.newInstance = newInstance;
-		
+
 		return Subtype;
 	};
@@ -125,5 +125,5 @@
 nanashi.namespace("", function() {
 	var StopIteration = window.StopIteration || {};
-	
+
 	var RuntimeError = nanashi.proto(Error).def({
 		"name": "RuntimeError",
@@ -132,5 +132,5 @@
 		}
 	});
-	
+
 	function _defError(name) {
 		if (typeof(window[name]) == "undefined") {
@@ -140,5 +140,5 @@
 		}
 	}
-		
+
 	return {
 		"StopIteration": StopIteration,
@@ -152,5 +152,5 @@
 		"ArgumentError":    _defError("ArgumentError"),
 		"NoDataFoundError": _defError("NoDataFoundError")
-	}
+	};
 });
 
@@ -159,5 +159,5 @@
 	function copy(org) {
 		if (org === null) return null;
-		
+
 		switch (typeof(org)) {
 		case "function":
@@ -195,5 +195,5 @@
 				copy = new F();
 			}
-			for(var key in org) copy[key] = org[key];
+			for (var key in org) copy[key] = org[key];
 			return copy;
 		case "undefined":
@@ -209,11 +209,8 @@
 		var arglen = arguments.length;
 		if (arglen <= 1 || arglen == 2 && typeof(arguments[2]) != "object") return obj;
-		
-		var force = false;
-		if (arguments[arglen-1] === true) {
-			force = true;
-			--arglen;
-		}
-		
+
+		var force = (arguments[arglen-1] === true) ? true : false;
+		if (force) --arglen;
+
 		for (var i = 1; i < arglen; i++) {
 			var props = arguments[i];
@@ -224,11 +221,11 @@
 			}
 		}
-		
+
 		return obj;
 	};
-	
+
 	function serialize(obj) {
 		var result;
-		switch(typeof(obj)) {
+		switch (typeof(obj)) {
 		case "string":
 			result = '"' + _escapeJsonString(obj) + '"';
@@ -246,5 +243,5 @@
 			if (obj == null) {
 				result = "null";
-			} else if(obj instanceof Array) {
+			} else if (obj instanceof Array) {
 				var callee = arguments.callee;
 				result = "[" + collect(obj, function(v) {
@@ -261,11 +258,11 @@
 			result = '"' + _escapeJsonString(obj.toString()) + '"';
 		}
-		
+
 		return result;
 	}
 	function _escapeJsonString(text) {
-		return text.replace(/\\/g, "\\\\").replace(/\"/g, "\\\"");
-	}
-	
+		return text.replace(/(?=["\\])/g, "\\");
+	}
+
 	function deserialize(text) {
 		var ret;
@@ -276,18 +273,18 @@
 	function each(list, fn, reverse) {
 		if (typeof(list) != "object" || typeof(fn) != "function") throw new ArgumentError();
-		
+
 		try {
 			if (list instanceof Array || typeof(list.length) == "number") {
-				if(true !== reverse) {
-					for(var i = 0, len = list.length; i < len; i++) {
+				if (true !== reverse) {
+					for (var i = 0, len = list.length; i < len; i++) {
 						fn(list[i], i);
 					}
 				} else {
-					for(var i = list.length-1; i >= 0; i--) {
+					for (var i = list.length-1; i >= 0; i--) {
 						fn(list[i], i);
 					}
 				}
 			} else {
-				for(var i in list) {
+				for (var i in list) {
 					fn(list[i], i);
 				}
@@ -301,5 +298,5 @@
 		var result = false;
 		each(list, function(v, i) {
-			if(true == fn(v, i)) {
+			if (true == fn(v, i)) {
 				result = true;
 				throw StopIteration;
@@ -308,9 +305,9 @@
 		return result;
 	}
-	
+
 	function all(list, fn, reverse) {
 		var result = true;
 		each(list, function(v, i) {
-			if(true != fn(v, i)) {
+			if (true != fn(v, i)) {
 				result = false;
 				throw StopIteration;
@@ -319,5 +316,5 @@
 		return result;
 	}
-	
+
 	function collect(list, fn, reverse) {
 		var result = [];
@@ -327,9 +324,9 @@
 		return result;
 	}
-	
+
 	function select(list, fn, reverse) {
 		var result = [];
 		each(list, function(v, i) {
-			if(true == fn(v, i)) {
+			if (true == fn(v, i)) {
 				result.push(v);
 			}
@@ -337,9 +334,9 @@
 		return result;
 	}
-	
+
 	function reject(list, fn, reverse) {
 		var result = [];
 		each(list, function(v, i) {
-			if(true != fn(v, i)) {
+			if (true != fn(v, i)) {
 				result.push(v);
 			}
@@ -347,9 +344,9 @@
 		return result;
 	}
-	
+
 	function detect(list, fn, reverse) {
 		var result = null;
 		each(list, function(v, i) {
-			if(true == fn(v, i)) {
+			if (true == fn(v, i)) {
 				result = v;
 				throw StopIteration;
@@ -358,5 +355,5 @@
 		return result;
 	}
-	
+
 	function forloop(/* ... */) {
 		var from, to, step, fn;
@@ -383,5 +380,5 @@
 			throw new ArgumentError();
 		}
-		
+
 		try {
 			for (var i = from; i < to; i += step) {
@@ -392,17 +389,17 @@
 		}
 	}
-	
+
 	function trim(text) {
-		return (""+text).replace(/(^\s+|\s+$)/g, "");
-	}
-	
+		return (""+text).replace(/^\s+|\s+$/g, "");
+	}
+
 	function ltrim(text) {
-		return (""+text).replace(/(^\s+)/g, "");
-	}
-	
+		return (""+text).replace(/^\s+/g, "");
+	}
+
 	function rtrim(text) {
-		return (""+text).replace(/(\s+$)/g, "");
-	}
-	
+		return (""+text).replace(/\s+$/g, "");
+	}
+
 	return {
 		"copy": copy,
@@ -427,21 +424,21 @@
 nanashi.namespace("nanashi.modules", function() {
 	var Events = {
-		bind: function (type, fn, once) {
+		bind: function(type, fn, once) {
 			if (typeof(type) != "string" || typeof(fn) != "function")
 				throw new ArgumentError();
-			
+
 			if (!this._handlerMap) this._handlerMap = {};
-			
+
 			var map = this._handlerMap;
 			if (!map[type]) map[type] = [];
 			map[type].push([fn, once]);
 		},
-		
-		unbind: function (type, fn) {
+
+		unbind: function(type, fn) {
 			if (typeof(type) != "string" || typeof(fn) != "function")
 				throw new ArgumentError();
-			
+
 			if (!this._handlerMap) return;
-			
+
 			var handlers = this._handlerMap[type];
 			if (!handlers) return;
@@ -453,23 +450,23 @@
 			}
 		},
-		
-		onebind: function (type, fn) {
+
+		onebind: function(type, fn) {
 			this.bind(type, fn, true);
 		},
-		
-		trigger: function (type/* ... */) {
+
+		trigger: function(type/* ... */) {
 			var map = this._handlerMap;
-			if(!map || !map[type]) return;
-			
+			if (!map || !map[type]) return;
+
 			var handlers = map[type];
 			var hendlersCount = handlers.length;
 			if (hendlersCount <= 0) return;
-			
+
 			var args = [];
 			args.push.apply(args, arguments);
 			args = args.slice(1);
-			
+
 			var newHandlers = [];
-			for(var i = 0; i < hendlersCount; i++) {
+			for (var i = 0; i < hendlersCount; i++) {
 				var handler = handlers[i];
 				var fn = handler[0];
@@ -478,12 +475,12 @@
 				if (once !== true) newHandlers.push(handler);
 			}
-			
+
 			map[type] = newHandlers;
 		}
 	};
-	
+
 	return {
 		"Events": Events
-	}
+	};
 });
 
@@ -493,10 +490,10 @@
 
 	var _createXmlHttpRequest = (window.XMLHttpRequest) ? (
-		function() { return new XMLHttpRequest() }
-	) :(
+		function() { return new XMLHttpRequest(); }
+	) : (
 		function() {
 			try {
 				return new ActiveXObject("Msxml2.XMLHTTP");
-			} catch(e) {
+			} catch (e) {
 				return new ActiveXObject("Microsoft.XMLHTTP");
 			}
@@ -506,5 +503,5 @@
 	function send(url, opt) {
 		opt = opt || {};
-		var method  = (opt.method  || "get").toLowerCase();
+		var method  = (opt.method || "get").toLowerCase();
 		var param   = opt.param   || {};
 		var header  = opt.header  || {};
@@ -518,71 +515,72 @@
 		var onstart   = opt.onstart   || null;
 		var onend     = opt.onend     || null;
-		
+
 		var timeoutTimer;
 		var isTimeout = false;
-		
+
 		var requestBody;
 		var buffer = [];
-		for(key in param) { buffer.push(key + "=" + encodeURIComponent(param[key])); }
-		if(method == "get" && buffer.length > 0) {
-			url = url + ((url.indexOf('?') < 0) ? "?" : "&") + buffer.join("&");
+		var key;
+		for (key in param) { buffer.push(key + "=" + encodeURIComponent(param[key])); }
+		if (method == "get" && buffer.length > 0) {
+			url = url + ((url.indexOf("?") < 0) ? "?" : "&") + buffer.join("&");
 			requestBody = null;
 		} else {
 			requestBody = buffer.join("&");
 		}
-		
+
 		var xhr = _createXmlHttpRequest();
 		var reqId = xhrList.length;
 		xhr.__isAborted == false;
 		xhrList[reqId] = xhr;
-		
+
 		xhr.open(method, url, async);
-		if(!!onstart) onstart(xhr);
+		if (!!onstart) onstart(xhr);
 		xhr.onreadystatechange = function() {
-			if(xhr.readyState != 4) return;
-			if(timeout > 0) clearTimeout(timeoutTimer);
-			if(xhr.status == 200) {
-				if(!!onsuccess) onsuccess(xhr);
+			if (xhr.readyState != 4) return;
+			if (timeout > 0) clearTimeout(timeoutTimer);
+			if (xhr.status == 200) {
+				if (!!onsuccess) onsuccess(xhr);
 			} else {
-				if(!isTimeout) {
-					if(xhr.__isAborted) {
-						if(!!onabort) onabort(xhr);
+				if (!isTimeout) {
+					if (xhr.__isAborted) {
+						if (!!onabort) onabort(xhr);
 					} else {
-						if(!!onerror) onerror(xhr);
+						if (!!onerror) onerror(xhr);
 					}
 				}
 			}
-			if(!!onend) onend(xhr);
+			if (!!onend) onend(xhr);
 			xhrList[reqId] = null;
-		}
-		
-		if(method == "post") xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
-		if(!cache) xhr.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
-		for(key in header) {
+		};
+
+		if (method == "post") xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
+		if (!cache) xhr.setRequestHeader("If-Modified-Since", "Thu, 01 Jun 1970 00:00:00 GMT");
+		for (key in header) {
 			xhr.setRequestHeader(key, header[key]);
 		}
 		xhr.send(requestBody);
-		
-		if(timeout > 0) {
+
+		if (timeout > 0) {
 			timeoutTimer = setTimeout(function() {
 				isTimeout = true;
 				xhr.abort();
-				if(!!ontimeout) ontimeout(xhr);
+				if (!!ontimeout) ontimeout(xhr);
 			}, timeout);
 		}
-		
+
 		return reqId;
 	}
-	
+
 	function abort(id) {
 		var xhr = xhrList[id];
-		if(!xhr) return;
+		if (!xhr) return;
 		xhr.__isAborted == true;
 		xhr.abort();
 	}
-	
+
 	return {
 		"send": send,
 		"abort": abort
-	}
+	};
 });
