 				url = ops.url
 			else
 				ops = {}
-		ops.method = ops.method or 'GET'
-		if ops.async == undefined
-			ops.async = true
+		ops.method or= 'GET'
+		ops.async = true unless ops.async?
+
 		xhr = new XMLHttpRequest
-
 		xhr.onreadystatechange = ->
 			if xhr.readyState == 4
 				if xhr.status == 200
-					if ! !ops.success
-						ops.success xhr.responseText, xhr.status, xhr
-				else
-					if ! !ops.error
-						ops.error xhr, xhr.status
-				if ! !ops.complete
-					ops.complete xhr, xhr.status
+					ops.success xhr.responseText, xhr.status, xhr if ops.success?
+				else
+					ops.error xhr, xhr.status if ops.error?
+					ops.complete xhr, xhr.status if ops.complete?
 
 		xhr.open ops.method, url, ops.async, ops.username, ops.password
 		xhr.send null
-) window or this+
+) window or this

((global) ->

	jQuery = ->
		doms = this

		@text = (str) ->
			doms.each (dom) ->
				dom.textContent = str
			@

		@html = (str) ->
			doms.each (dom) ->
				dom.innerHTML = str
			@

		# == DOM ==
		# this.style
		# this.css( { name: value } )
		# this.hasClass
		# this.addClass
		# this.toggleClass
		# this.removeClass
		# this.attr
		# this.hasAttr
		# this.removeAttr
		# this.append

		@style = (name, value) ->
			doms.each (dom) ->
				styleText = dom.getAttribute('style')
				styles = {}
				if styleText
					styleText.split(';').each (n) ->
						nv = n.split(':')
						styles[nv[0]] = nv[1]
				styles[name] = value
				# concat

				dom.setAttribute 'style', styleText
			@

		@hasClass = (name) =>
			if @length == 0
				return false
			# if multiple, every DOM should have the class
			i = 0
			while i < @length
				classText = @[i].getAttribute 'class' or ''
				# not use ' ' to avoid multiple spaces like 'a   b'
				classes = classText.split RegExp ' +'
				if !classes.contains name
					return false
				i++
			@

		@addClass = (name) =>
			@each (dom) ->
				classText = dom.getAttribute 'class' or ''
				classes = classText.split RegExp ' +'
				if not classes.contains name
					classes.push name
					dom.setAttribute 'class', classes.join ' '
			@

		@removeClass = (name) =>
			@each (dom) ->
				classText = dom.getAttribute('class') or ''
				classes = classText.split RegExp ' +'
				if classes.contains name
					classes.remove name
					if classes.length > 0
						dom.setAttribute 'class', classes.join ' '
					else
						dom.removeAttribute 'class'
			@

		@toggleClass = (name) =>
			@each (dom) ->
				classText = dom.getAttribute 'class'  or ''
				classes = classText.split RegExp ' +'
				if classes.contains name
					classes.remove name
				else
					classes.push name
				if classes.length > 0
					dom.setAttribute 'class', classes.join ' '
				else
					dom.removeAttribute 'class'
			@

		# Not giving the attribute value means just add the attribute name
		# or clear the existing attribute value.
		# No, jQuery is to GET the value

		@attr = (name, value) =>
			value or= ''
			@each (dom) ->
				dom.setAttribute name, value
			@

		@hasAttr = (name) =>
			if @length == 0
				return false
			i = 0
			while i < @length
				if not @[i].hasAttribute name
					return false
				i++
			@

		@removeAttr = (name) =>
			@each (dom) ->
				dom.removeAttribute name
			@

	# $.ready()
	global.$.ready = (onLoad) ->
		document.addEventListener 'DOMContentLoaded', onLoad

