Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ie-touch
Browse files Browse the repository at this point in the history
  • Loading branch information
charsleysa committed Sep 13, 2013
2 parents 751c44f + a4e3142 commit 0fcda59
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pkg
docs/*
.jhw-cache
.rbenv-version
public/
public
node_modules
24 changes: 24 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
## Contributing to Zepto

**Thanks for helping out!**

In order for your code to make it in, several conditions must be met:

* It's more likely your pull request will make it in if you adhere to **Zepto's
project goals**. Be sure to read the README in its entirety before setting out
to code.
* Please talk to the maintainers (@madrobby and @mislav) first if you want
to write a plugin, those are better kept in their own repositories.
* Fix only ONE thing or have only ONE feature in your pull request. If you have multiple unrelated code updatates, please submit a seperate pull request for each one.
* **Your pull request must be written in English and be accompanied by a
detailed description**, ideally something we can use as documentation.
If you're not fluent in English, try your best and let us know so we'll help!
* Changes to jQuery-based API methods **must match their jQuery counterparts**.
* **All code must have tests, and all tests must pass.** See the README on running the test suite.
* Please **also test manually** on as many target platforms you have access to,
but at least on latest Chrome (desktop) and Firefox (desktop).
See http://zeptojs.com for a full list of platforms.
* It's required that you follow Zepto's **code style guidelines** (see below)

Whew, now that we have that out of the way thanks again!

## Code style guidelines

* `function name() { }` for named functions
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ href="https://github.com/madrobby/zepto/blob/master/src/selector.js#files">selec

Get in touch:

* IRC channel: [#zepto on freenode.net](irc://irc.freenode.net/zepto)
* @[zeptojs](http://twitter.com/zeptojs)

### Write documentation
Expand Down Expand Up @@ -180,6 +179,9 @@ $ ./make test
$ script/test
~~~

To run manually run tests (all except for the ajax module) on a device,
you can serve the whole Zepto folder on a web server and open
`test/index.html` in the device's browser.

[zeptojs.com]: http://zeptojs.com
[master]: https://github.com/madrobby/zepto/commits/master
Expand Down
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
12 changes: 9 additions & 3 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 @@ -18,7 +19,9 @@
rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/),
playbook = ua.match(/PlayBook/),
chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/),
firefox = ua.match(/Firefox\/([\d.]+)/)
firefox = ua.match(/Firefox\/([\d.]+)/),
safari = webkit && ua.match(/Mobile\//) && !chrome,
webview = ua.match(/(iPhone|iPod|iPad).*AppleWebKit(?!.*Safari)/) && !chrome

// Todo: clean this up with a better OS/browser seperation:
// - discern (more) between multiple browsers on android
Expand All @@ -29,8 +32,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 @@ -42,9 +46,11 @@
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]
if (safari && (ua.match(/Safari/) || !!os.ios)) browser.safari = true
if (webview) browser.webview = true

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
18 changes: 12 additions & 6 deletions src/fx.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
document = window.document, testEl = document.createElement('div'),
supportedTransforms = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i,
transform,
transitionProperty, transitionDuration, transitionTiming,
animationName, animationDuration, animationTiming,
transitionProperty, transitionDuration, transitionTiming, transitionDelay,
animationName, animationDuration, animationTiming, animationDelay,
cssReset = {}

function dasherize(str) { return downcase(str.replace(/([a-z])([A-Z])/, '$1-$2')) }
Expand All @@ -27,9 +27,11 @@
transform = prefix + 'transform'
cssReset[transitionProperty = prefix + 'transition-property'] =
cssReset[transitionDuration = prefix + 'transition-duration'] =
cssReset[transitionDelay = prefix + 'transition-delay'] =
cssReset[transitionTiming = prefix + 'transition-timing-function'] =
cssReset[animationName = prefix + 'animation-name'] =
cssReset[animationDuration = prefix + 'animation-duration'] =
cssReset[animationDelay = prefix + 'animation-delay'] =
cssReset[animationTiming = prefix + 'animation-timing-function'] = ''

$.fx = {
Expand All @@ -40,25 +42,28 @@
animationEnd: normalizeEvent('AnimationEnd')
}

$.fn.animate = function(properties, duration, ease, callback){
$.fn.animate = function(properties, duration, ease, callback, delay){
if ($.isPlainObject(duration))
ease = duration.easing, callback = duration.complete, duration = duration.duration
ease = duration.easing, callback = duration.complete, delay = duration.delay, duration = duration.duration
if (duration) duration = (typeof duration == 'number' ? duration :
($.fx.speeds[duration] || $.fx.speeds._default)) / 1000
return this.anim(properties, duration, ease, callback)
if (delay) delay = (typeof delay == 'number' ? delay / 1000 : 0)
return this.anim(properties, duration, ease, callback, delay)
}

$.fn.anim = function(properties, duration, ease, callback){
$.fn.anim = function(properties, duration, ease, callback, delay){
var key, cssValues = {}, cssProperties, transforms = '',
that = this, wrappedCallback, endEvent = $.fx.transitionEnd

if (duration === undefined) duration = 0.4
if (delay === undefined) delay = 0
if ($.fx.off) duration = 0

if (typeof properties == 'string') {
// keyframe animation
cssValues[animationName] = properties
cssValues[animationDuration] = duration + 's'
cssValues[animationDelay] = delay + 's'
cssValues[animationTiming] = (ease || 'linear')
endEvent = $.fx.animationEnd
} else {
Expand All @@ -72,6 +77,7 @@
if (duration > 0 && typeof properties === 'object') {
cssValues[transitionProperty] = cssProperties.join(', ')
cssValues[transitionDuration] = duration + 's'
cssValues[transitionDelay] = delay + 's'
cssValues[transitionTiming] = (ease || 'linear')
}
}
Expand Down
22 changes: 14 additions & 8 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 @@ -665,9 +667,13 @@ var Zepto = (function() {
})
})
},
scrollTop: function(){
scrollTop: function(value){
if (!this.length) return
return ('scrollTop' in this[0]) ? this[0].scrollTop : this[0].scrollY
var hasScrollTop = 'scrollTop' in this[0]
if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].scrollY
return this.each(hasScrollTop ?
function(){ this.scrollTop = value } :
function(){ this.scrollTo(this.scrollX, value) })
},
position: function() {
if (!this.length) return
Expand Down Expand Up @@ -787,4 +793,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
Loading

0 comments on commit 0fcda59

Please sign in to comment.