Skip to content

Commit

Permalink
Version 0.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
santoshrajan committed Jul 6, 2013
1 parent 52ec9ae commit b8c6030
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ Same as document.querySelectorAll
Changes the selector(s) style.display to displayValue. eg. "none", "block" etc
#### $.ready(callback)
#### XHR functions
Success is called with responseText, or JSON object if JSON response. Failure is called with the request object.
#### $.get(url, success, failure [,overrideMimeType])
#### $.post(url, body, contenttype, success, failure)
#### $.postJSON(url, body, success, failure)
Callback is called with `error` as first argument. Second argument is responseText, or JSON object if JSON response. `error` will be `null` for success, or the `XMLHttpRequest` object for failure.
#### $.get(url, callback [,overrideMimeType])
#### $.post(url, body, contenttype, callback)
#### $.postJSON(url, body, callback)
`body` is json object
#### $.getR(success, failure)
#### $.getR(callback)
Returns the request object with onload set. Set request parameters and call `request.send`. Use if the request types provided above are not enough.
#### <Element>.on
Same as <Element>.addEventListener
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"author" : "Santosh Rajan <santrajan@gmail.com>",
"repository" : {"type": "git", "url": "git://github.com/santoshrajan/tinix.git"},
"main" : "tinix.js",
"version" : "0.0.5",
"version" : "0.0.6",
"license" : "MIT"
}
30 changes: 15 additions & 15 deletions tinix.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var tinix = function(id) {
return document.querySelector(id)
}

tinix.version = "0.0.5"
tinix.version = "0.0.6"

tinix.all = function(id) {
return document.querySelectorAll(id)
Expand Down Expand Up @@ -41,43 +41,43 @@ tinix.ready = function(f) {
}
}

tinix.getR = function(s, f) {
tinix.getR = function(c) {
var r = new XMLHttpRequest()
r.onload = function() {
if (r.status == 200) {
if (r.getResponseHeader("Content-Type") == "application/json") {
s(JSON.parse(r.responseText))
c(null, JSON.parse(r.responseText))
} else {
s(r.responseText)
c(null, r.responseText)
}
} else {
f(r)
c(r)
}
}
return r
}

// get(url, success, failure [,overrideMimeType])
tinix.get = function(u, s, f, o) {
var r = this.getR(s, f)
// get(url, callback [,overrideMimeType])
tinix.get = function(u, c, o) {
var r = this.getR(c)
r.open("GET", u)
if (o) {
r.overrideMimeType(o)
}
r.send()
}

// post(url, body, contenttype, success, failure)
tinix.post = function(u, b, c, s, f) {
var r = this.getR(s, f)
// post(url, body, contenttype, callback)
tinix.post = function(u, b, t, c) {
var r = this.getR(c)
r.open("POST", u)
r.setRequestHeader("Content-Type", c)
r.setRequestHeader("Content-Type", t)
r.send(b)
}

// postJSON(url, body, success, failure)
tinix.postJSON = function(u, b, s, f) {
this.post(u, JSON.stringify(b), "application/json", s, f)
// postJSON(url, body, callback)
tinix.postJSON = function(u, b, c) {
this.post(u, JSON.stringify(b), "application/json", c)
}

/*\
Expand Down

0 comments on commit b8c6030

Please sign in to comment.