Skip to content

Commit

Permalink
Updated from upstream/master
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Andres Charsley committed Sep 13, 2013
2 parents 5269256 + 04a63a6 commit 81fce95
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
, "devDependencies": {
"uglify-js": "1.2.6"
, "express": "3.1.x"
, "coffee-script": "1.4.x"
, "coffee-script": "1.5.x"
, "shelljs": "0.1.x"
}
}
9 changes: 7 additions & 2 deletions src/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@
$.ajaxJSONP = function(options){
if (!('type' in options)) return $.ajax(options)

var callbackName = 'jsonp' + (++jsonpID),
var _callbackName = options.jsonpCallback,
callbackName = ($.isFunction(_callbackName) ?
_callbackName() : _callbackName) || ('jsonp' + (++jsonpID)),
script = document.createElement('script'),
cleanup = function() {
clearTimeout(abortTimeout)
Expand Down Expand Up @@ -156,6 +158,7 @@
}

function appendQuery(url, query) {
if (query == '') return url
return (url + '&' + query).replace(/[&?]{1,2}/, '?')
}

Expand All @@ -182,7 +185,9 @@

var dataType = settings.dataType, hasPlaceholder = /=\?/.test(settings.url)
if (dataType == 'jsonp' || hasPlaceholder) {
if (!hasPlaceholder) settings.url = appendQuery(settings.url, 'callback=?')
if (!hasPlaceholder)
settings.url = appendQuery(settings.url,
settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?')
return $.ajaxJSONP(settings)
}

Expand Down
16 changes: 14 additions & 2 deletions src/detect.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
webkit = ua.match(/WebKit\/([\d.]+)/),
android = ua.match(/(Android)\s+([\d.]+)/),
ipad = ua.match(/(iPad).*OS\s([\d_]+)/),
ipod = ua.match(/(iPod)(.*OS\s([\d_]+))?/),
iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/),
webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/),
touchpad = webos && ua.match(/TouchPad/),
Expand All @@ -19,7 +20,12 @@
playbook = ua.match(/PlayBook/),
chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/),
firefox = ua.match(/Firefox\/([\d.]+)/),
<<<<<<< HEAD
ie = ua.match(/MSIE ([\d.]+)/)
=======
safari = webkit && ua.match(/Mobile\//) && !chrome,
webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome
>>>>>>> upstream/master

// Todo: clean this up with a better OS/browser seperation:
// - discern (more) between multiple browsers on android
Expand All @@ -30,8 +36,9 @@
if (browser.webkit = !!webkit) browser.version = webkit[1]

if (android) os.android = true, os.version = android[2]
if (iphone) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.')
if (iphone && !ipod) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.')
if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.')
if (ipod) os.ios = os.ipod = true, os.version = ipod[3] ? ipod[3].replace(/_/g, '.') : null
if (webos) os.webos = true, os.version = webos[2]
if (touchpad) os.touchpad = true
if (blackberry) os.blackberry = true, os.version = blackberry[2]
Expand All @@ -43,10 +50,15 @@
if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true
if (chrome) browser.chrome = true, browser.version = chrome[1]
if (firefox) browser.firefox = true, browser.version = firefox[1]
<<<<<<< HEAD
if (ie) browser.ie = true, browser.verson = ie[1]
=======
if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true
if (webview) browser.webview = true
>>>>>>> upstream/master

os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) || (firefox && ua.match(/Tablet/)))
os.phone = !!(!os.tablet && (android || iphone || webos || blackberry || bb10 ||
os.phone = !!(!os.tablet && !os.ipod && (android || iphone || webos || blackberry || bb10 ||
(chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) || (firefox && ua.match(/Mobile/))))
}

Expand Down
14 changes: 8 additions & 6 deletions src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ var Zepto = (function() {
}

function filtered(nodes, selector) {
return selector === undefined ? $(nodes) : $(nodes).filter(selector)
return selector == null ? $(nodes) : $(nodes).filter(selector)
}

$.contains = function(parent, node) {
Expand Down Expand Up @@ -287,7 +287,9 @@ var Zepto = (function() {
}

$.camelCase = camelize
$.trim = function(str) { return str.trim() }
$.trim = function(str) {
return str == null ? "" : String.prototype.trim.call(str)
}

// plugin compatibility
$.uuid = 0
Expand Down Expand Up @@ -537,15 +539,15 @@ var Zepto = (function() {
prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') },
next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') },
html: function(html){
return html === undefined ?
return arguments.length === 0 ?
(this.length > 0 ? this[0].innerHTML : null) :
this.each(function(idx){
var originHtml = this.innerHTML
$(this).empty().append( funcArg(this, html, idx, originHtml) )
})
},
text: function(text){
return text === undefined ?
return arguments.length === 0 ?
(this.length > 0 ? this[0].textContent : null) :
this.each(function(){ this.textContent = text })
},
Expand Down Expand Up @@ -577,7 +579,7 @@ var Zepto = (function() {
return data !== null ? deserializeValue(data) : undefined
},
val: function(value){
return (value === undefined) ?
return arguments.length === 0 ?
(this[0] && (this[0].multiple ?
$(this[0]).find('option').filter(function(o){ return this.selected }).pluck('value') :
this[0].value)
Expand Down Expand Up @@ -787,4 +789,4 @@ var Zepto = (function() {

// If `$` is not yet defined, point it to `Zepto`
window.Zepto = Zepto
'$' in window || (window.$ = Zepto)
window.$ === undefined && (window.$ = Zepto)
60 changes: 60 additions & 0 deletions test/ajax.html
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,66 @@ <h1>Zepto Ajax unit tests</h1>
})
},

testAjaxJSONPWithCallbackName: function(t) {
var xhr = $.ajax({
url: 'jsonp',
dataType: 'jsonp',
jsonpCallback: 'blah',
success: t.reg.resumeHandler('success', function(data){
t.assertFalse('blah' in window)
})
})

t.assert($.isFunction(window.blah))
t.pause()
},

testAjaxJSONPWithCallbackNameAsFunction: function(t) {
var xhr = $.ajax({
url: 'jsonp',
dataType: 'jsonp',
jsonpCallback: function(){ return 'blah' },
success: t.reg.resumeHandler('success', function(data){
t.assertFalse('blah' in window)
})
})

t.assert($.isFunction(window.blah))
t.pause()
},

testAjaxJSONPWithCallbackNameAndJSONPsetToFalse: function(t) {
var xhr = $.ajax({
url: 'jsonpBlah',
dataType: 'jsonp',
jsonp: false,
jsonpCallback: 'blah',
success: t.reg.resumeHandler('success', function(data){
t.assertFalse('blah' in window)
})
})

t.assertEqual($('head script:last-child').attr('src'), 'jsonpBlah')
t.assert($.isFunction(window.blah))
t.pause()
},

testAjaxJSONPWithCallbackNameAsFunctionAndJSONPsetToFalse: function(t) {
var xhr = $.ajax({
url: 'jsonpBlah',
dataType: 'jsonp',
jsonp: false,
jsonpCallback: function(){ return 'blah' },
success: t.reg.resumeHandler('success', function(data){
t.assertFalse('blah' in window)
})
})

t.assertEqual($('head script:last-child').attr('src'), 'jsonpBlah')
t.assert($.isFunction(window.blah))
t.pause()
},

testNoCacheParam: function(t) {
t.pause()
var xhr = $.ajax({
Expand Down
88 changes: 74 additions & 14 deletions test/detect.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ <h1>Browser detection</h1>
iOS_4_2_iPad: "Mozilla/5.0 (iPad; U; CPU OS 4_2 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8C134 Safari/6533.18.5",
iOS_4_3_iPhone_Simulator: "Mozilla/5.0 (iPhone Simulator; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5",
iOS_5_0_iPhone: "Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3",
iOS_5_1_iPad_webView: "Mozilla/5.0 (iPad; CPU OS 5_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/98176",
iOS_6_0_iPad_mini: "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A406 Safari/8536.25",
iOS_6_1_iPhone: "Mozilla/5.0 (iPhone; CPI iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B143 Safari/8536.25",
iOS_6_1_iPhone: "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10B143 Safari/8536.25",

iOS_3_2_iPad_2: "Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10",

iOS_7_0_iPhone: "Mozilla 5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KTHML, like Gecko) Version/7.0 Mobile/11A449d Safari/9537.53",
iOS_7_0_iPhone_Chrome: "Mozilla 5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/536.26 (KHTM, like Gecko) CriOS/28.0.1500.17 Mobile/11A4449d Safari/8536.25",

Android_1_5: "Mozilla/5.0 (Linux; U; Android 1.5; de-; HTC Magic Build/PLAT-RC33) AppleWebKit/528.5+ (KHTML, like Gecko) Version/3.1.2 Mobile Safari/525.20.1",
Android_2_1: "Mozilla/5.0 (Linux; U; Android 2.1-update1; en-us; Nexus One Build/ERE27) AppleWebKit/530.17 (KHTML, like Gecko) Version/4.0 Mobile Safari/530.17 Chrome/4.1.249.1025",
Android_4_1_1: "Mozilla/5.0 (Linux; Android 4.1.1; Galaxy Nexus Build/JRO03O) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19",
Android_4_1_1_Tablet: "Mozilla/5.0 (Linux; Android 4.1.1; Nexus 7 Build/JRO03S) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Safari/535.19",
Android_4_3: "Mozilla/5.0 (Linux; Android 4.3; Nexus 4 Build/JWR66Y) AppleWebKit/537.36 (KTHML, like Gecko) Chrome/29.0.1547.59 Mobile Safari/537.36",

BlackBerry_6_0_0_141: "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en-GB) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.141 Mobile Safari/534.1+",
PlayBook_1_0_0: "Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US) AppleWebKit/534.8+ (KHTML, like Gecko) Version/0.0.1 Safari/534.8+",
Expand Down Expand Up @@ -104,12 +109,14 @@ <h1>Browser detection</h1>
t.assertTrue(browser.webkit)
t.assertEqual("1.5", os.version)
t.assertTrue(os.phone)
t.assertFalse(!!browser.safari)
})
detect(UA.Android_2_1, function(os, browser){
t.assertTrue(os.android)
t.assertTrue(browser.webkit)
t.assertEqual("2.1", os.version)
t.assertTrue(os.phone)
t.assertFalse(!!browser.safari)
})
detect(UA.Android_4_1_1, function(os, browser){
t.assertTrue(os.android)
Expand All @@ -119,13 +126,25 @@ <h1>Browser detection</h1>
t.assertTrue(os.phone)
t.assertFalse(!!os.iphone)
t.assertTrue(browser.chrome)
t.assertFalse(!!browser.safari)
})
detect(UA.Android_4_1_1_Tablet, function(os, browser){
t.assertTrue(os.android)
t.assertTrue(browser.webkit)
t.assertEqual("4.1.1", os.version)
t.assertTrue(os.tablet)
t.assertTrue(browser.chrome)
t.assertFalse(!!browser.safari)
})
detect(UA.Android_4_3, function(os, browser){
t.assertTrue(os.android)
t.assertTrue(browser.webkit)
t.assertFalse(!!os.ios)
t.assertEqual("4.3", os.version)
t.assertTrue(os.phone)
t.assertFalse(!!os.iphone)
t.assertTrue(browser.chrome)
t.assertFalse(!!browser.safari)
})
},

Expand All @@ -137,69 +156,110 @@ <h1>Browser detection</h1>
t.assertEqual("3.0", os.version)
t.assertEqual("420.1", browser.version)
t.assertTrue(os.phone)
t.assertTrue(browser.safari)
})
detect(UA.iOS_3_1_1_iPod, function(os){
detect(UA.iOS_3_1_1_iPod, function(os, browser){
t.assertTrue(os.ios)
t.assertTrue(os.iphone)
t.assertUndefined(os.ipod)
t.assertUndefined(os.iphone)
t.assertTrue(os.ipod)
t.assertEqual("3.1.1", os.version)
t.assertTrue(os.phone)
t.assertFalse(!!os.phone)
t.assertTrue(browser.safari)
})
detect(UA.iOS_3_2_iPad, function(os){
detect(UA.iOS_3_2_iPad, function(os, browser){
t.assertTrue(os.ios)
t.assertTrue(os.ipad)
t.assert(!os.iphone)
t.assertFalse(!!os.iphone)
t.assertEqual("3.2", os.version)
t.assertTrue(os.tablet)
t.assertTrue(browser.safari)
})
detect(UA.iOS_3_2_iPad_2, function(os){
detect(UA.iOS_3_2_iPad_2, function(os, browser){
t.assertTrue(os.ios)
t.assertTrue(os.ipad)
t.assert(!os.iphone)
t.assertEqual("3.2", os.version)
t.assertTrue(os.tablet)
t.assertTrue(browser.safari)
})
detect(UA.iOS_4_0_iPhone, function(os){
detect(UA.iOS_4_0_iPhone, function(os, browser){
t.assertTrue(os.ios)
t.assertTrue(os.iphone)
t.assert(!os.ipad)
t.assertEqual("4.0", os.version)
t.assertTrue(os.phone)
t.assertTrue(browser.safari)
})
detect(UA.iOS_4_2_iPad, function(os){
detect(UA.iOS_4_2_iPad, function(os, browser){
t.assertTrue(os.ios)
t.assertTrue(os.ipad)
t.assertEqual("4.2", os.version)
t.assertFalse(os.phone)
t.assertTrue(os.tablet)
t.assertTrue(browser.safari)
})
detect(UA.iOS_4_3_iPhone_Simulator, function(os){
detect(UA.iOS_4_3_iPhone_Simulator, function(os, browser){
t.assertTrue(os.ios)
t.assertTrue(os.iphone)
t.assertEqual("4.3", os.version)
t.assertTrue(os.phone)
t.assertFalse(os.tablet)
t.assertTrue(browser.safari)
})
detect(UA.iOS_5_0_iPhone, function(os){
detect(UA.iOS_5_0_iPhone, function(os, browser){
t.assert(os.ios)
t.assert(os.iphone)
t.assertEqual("5.0", os.version)
t.assertTrue(os.phone)
t.assertFalse(os.tablet)
t.assertTrue(browser.safari)
})
detect(UA.iOS_6_1_iPhone, function(os){
detect(UA.iOS_5_1_iPad_webView, function(os, browser){
t.assert(os.ios)
t.assert(os.ipad)
t.assertEqual("5.1", os.version)
t.assertTrue(browser.webview)
t.assertTrue(browser.safari)
})
detect(UA.iOS_6_1_iPhone, function(os, browser){
t.assert(os.ios)
t.assert(os.iphone)
t.assertEqual("6.1", os.version)
t.assertTrue(os.phone)
t.assertFalse(os.tablet)
t.assertTrue(browser.safari)
t.assertFalse(!!browser.webview)
t.assertFalse(!!browser.chrome)
t.assertFalse(!!browser.firefox)
})
detect(UA.iOS_6_0_iPad_mini, function(os){
detect(UA.iOS_6_0_iPad_mini, function(os, browser){
t.assert(os.ios)
t.assert(os.ipad)
t.assertEqual("6.0", os.version)
t.assertFalse(os.phone)
t.assertTrue(os.tablet)
t.assertTrue(browser.safari)
})
detect(UA.iOS_7_0_iPhone, function(os, browser){
t.assert(os.ios)
t.assert(os.iphone)
t.assertEqual("7.0", os.version)
t.assertTrue(os.phone)
t.assertFalse(os.tablet)
t.assertTrue(browser.safari)
t.assertFalse(!!browser.chrome)
t.assertFalse(!!browser.firefox)
})
detect(UA.iOS_7_0_iPhone_Chrome, function(os, browser){
t.assert(os.ios)
t.assert(os.iphone)
t.assertEqual("7.0", os.version)
t.assertTrue(os.phone)
t.assertFalse(os.tablet)
t.assertFalse(!!browser.safari)
t.assertTrue(browser.chrome)
t.assertFalse(!!browser.firefox)
t.assertFalse(!!browser.webview)
})
},

Expand Down
Loading

0 comments on commit 81fce95

Please sign in to comment.