| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,201 +1,117 @@ | ||
| ZEPTO_VERSION = "0.8" | ||
|
|
||
| DEFAULT_MODULES = %w[ polyfill zepto event detect fx ajax form touch ] | ||
|
|
||
| KILO = 1024 # how many bytes in a "kilobyte" | ||
|
|
||
| task :default => :dist | ||
|
|
||
| # module-aware file task | ||
| class BuildTask < Rake::FileTask | ||
| def modules | ||
| prerequisites.map {|f| File.basename(f, '.js') } | ||
| end | ||
|
|
||
| def remove_prerequisites to_remove | ||
| @prerequisites -= to_remove | ||
| return self | ||
| end | ||
|
|
||
| def modules_mismatch? | ||
| File.open(name, 'r') {|f| f.gets } !~ /modules: ([\w,\s]+)/ or | ||
| $1.split(/\W+/) != modules | ||
| end | ||
|
|
||
| def needed?() super or modules_mismatch? end | ||
| end | ||
|
|
||
| BuildTask.define_task 'dist/zepto.js' => DEFAULT_MODULES.map {|m| "src/#{m}.js" } do |task| | ||
| mkdir_p 'dist', :verbose => false | ||
| File.open(task.name, 'w') do |zepto| | ||
| zepto.puts "/* Zepto %s - %s - zeptojs.com/license */" % | ||
| [version_string, task.modules.join(' ')] | ||
|
|
||
| task.prerequisites.each do |src| | ||
| # bring in source files one by one, but without copyright info | ||
| copyright = true | ||
| File.open(src).each_line do |line| | ||
| copyright = false if copyright and line !~ %r{^(/|\s*$)} | ||
| zepto.puts line unless copyright | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
| file 'dist/zepto.min.js' => 'dist/zepto.js' do |task| | ||
| begin require 'uglifier' | ||
| rescue LoadError; fail "Uglifier not available: #{$!}" | ||
| else | ||
| File.open(task.name, 'w') do |min| | ||
| min << Uglifier.new.compile(File.read(task.prerequisites.first)) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| file 'dist/zepto.min.gz' => 'dist/zepto.min.js' do |task| | ||
| verbose false do | ||
| tmp_file = task.name.sub('.gz', '') | ||
| cp task.prerequisites.first, tmp_file | ||
| sh 'gzip', '--best', tmp_file | ||
| end | ||
| end | ||
|
|
||
| desc "Concatenate source files to build zepto.js" | ||
| task :concat, [:modules] do |task, args| | ||
| modules = args[:modules].to_s.split(':') | ||
| to_add, to_exclude = modules.partition {|m| m.sub!(/^(-)?(.+)/, 'src/\2.js'); !$1 } | ||
|
|
||
| Rake::Task['dist/zepto.js']. | ||
| remove_prerequisites(to_exclude).enhance(to_add). | ||
| invoke | ||
| end | ||
|
|
||
| desc "Generate zepto.js distribution files and report size statistics" | ||
| task :dist => ['dist/zepto.js', 'dist/zepto.min.js', 'dist/zepto.min.gz'] do |task| | ||
| orig_size, min_size, gz_size = task.prerequisites.map {|f| File.size(f) } | ||
|
|
||
| puts "Original version: %.3fk" % (orig_size.to_f / KILO) | ||
| puts "Minified: %.3fk" % (min_size.to_f / KILO) | ||
| puts "Minified and gzipped: %.3fk, compression factor %.3f" % [gz_size.to_f / KILO, orig_size.to_f / gz_size] | ||
|
|
||
| rm_f 'dist/zepto.min.gz', :verbose => false | ||
| end | ||
|
|
||
| task(:clean) { rm_rf 'dist' } | ||
|
|
||
| desc "Run tests with PhantomJS" | ||
| task :test do | ||
| sh 'script/test' | ||
| end | ||
|
|
||
| desc "Strip trailing whitespace and ensure each file ends with a newline" | ||
| task :whitespace do | ||
| verbose false do | ||
| files = Dir['{src,test,examples}/**/*.{js,html}'] | ||
| ruby(*%w'-p -i -e $_.sub!(/\s*\Z/,"\n")'.concat(files)) | ||
| end | ||
| end | ||
|
|
||
| desc "Generate docco documentation from source files" | ||
| task :docco do | ||
| verbose false do | ||
| sh 'docco', *Dir['src/*.js'] | ||
| end | ||
| end | ||
|
|
||
| # Zepto version number + git sha if available | ||
| def version_string | ||
| desc = `git describe --tags HEAD 2>&1`.chomp | ||
| if $?.success? | ||
| desc | ||
| else | ||
| suffix, dir = '', File.basename(Dir.pwd) | ||
| # detect git sha from directory name of GitHub zip/tarball | ||
| suffix = "-g#{$1}" if dir =~ /^madrobby-zepto-([a-f0-9]{7,40})$/ | ||
| ZEPTO_VERSION + suffix | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Load jQuery if Zepto is not supported</title> | ||
| </head> | ||
| <body> | ||
| <h1>Load jQuery if Zepto is not supported</h1> | ||
| </body> | ||
| <script>document.write('<script src='+('__proto__' in {} ? '../dist/zepto' : 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery')+'.js><\/script>')</script> | ||
| <script> | ||
| $('body').append('<p>Hello from '+('Zepto' in window ? 'Zepto' : 'jQuery')+'!</p>') | ||
|
|
||
| $('script').each(function(index,script){ | ||
| if (script.src) | ||
| $('<p><script src="'+script.src+'"></p>').appendTo('body') | ||
| }) | ||
| </script> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>Let it snow with Zepto.js</title> | ||
| <meta name="name" content="content"> | ||
| <meta content="text/html; charset=utf-8" http-equiv="Content-Type"> | ||
| <style> | ||
| body { background: #000; color: #fff; overflow: hidden } | ||
| div { position: absolute; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
|
|
||
| <script src="../../src/zepto.js"></script> | ||
| <script src="../../src/event.js"></script> | ||
| <script src="../../src/fx.js"></script> | ||
|
|
||
| <a href="https://twitter.com/share" class="twitter-share-button" data-url="http://zeptojs.com/let-it-snow" data-text="Let it snow with Zepto.js" data-via="zeptojs" data-lang="en">Tweet</a> | ||
| <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs")</script> | ||
|
|
||
| <script> | ||
| $(document).ready(function(){ | ||
| var i = 100, glyphs = '❄❅❆'.split('') | ||
|
|
||
| function rand(max){ return Math.floor(Math.random()*max) } | ||
|
|
||
| function addFlake(){ | ||
| var el = $('<div><div>' + glyphs[rand(glyphs.length)] + '</div></div>') | ||
| $('body').append(el) | ||
| el.css({ left: rand(100)+'%', top: -100-rand(500), fontSize: 20+rand(30) }) | ||
| el.anim( | ||
| { translateY: 1500+rand(500)+'px', translateX: 50-rand(100)+'px', rotate: (2e3-rand(4e3))+'deg' }, | ||
| 6+rand(10), | ||
| 'linear', | ||
| function(){ | ||
| addFlake() | ||
| el.remove() // garbage collect | ||
| } | ||
| ); | ||
| } | ||
|
|
||
| while(i--) addFlake() | ||
|
|
||
| // enable for extra fun | ||
| //window.ondeviceorientation = function(event){ | ||
| // ('alpha' in event) && $('body').css({ '-webkit-transform': 'rotate('+event.alpha+'deg)'}) | ||
| //} | ||
| }) | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/> | ||
|
|
||
| <script src="../src/zepto.js"></script> | ||
| <script src="../src/event.js"></script> | ||
| <script src="../src/touch.js"></script> | ||
|
|
||
| <style> | ||
| .delete { | ||
| display: none; | ||
| color: red; | ||
| } | ||
| </style> | ||
|
|
||
| <ul id=items> | ||
| <li>List item 1 <span class=delete>DELETE</span></li> | ||
| <li>List item 2 <span class=delete>DELETE</span></li> | ||
| <li>List item 3 <span class=delete>DELETE</span></li> | ||
| <li>List item 4 <span class=delete>DELETE</span></li> | ||
| </ul> | ||
|
|
||
| <script> | ||
| $('#items li').swipe(function(){ | ||
| $('.delete').hide() | ||
| $('.delete', this).show() | ||
| }) | ||
|
|
||
| $('.delete').tap(function(){ | ||
| $(this).parent('li').remove() | ||
| }) | ||
| </script> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/bin/sh | ||
| if [ -z "$BUNDLE_GEMFILE" ]; then | ||
| export BUNDLE_GEMFILE=shutup | ||
| fi | ||
|
|
||
| exec guard --no-notify "$@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/bin/sh | ||
| phantomjs test/runner.coffee "$@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,21 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function($){ | ||
| var cache = [], timeout | ||
|
|
||
| $.fn.remove = function(){ | ||
| return this.each(function(){ | ||
| if(this.parentNode){ | ||
| if(this.tagName === 'IMG'){ | ||
| cache.push(this) | ||
| this.src = 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=' | ||
| if (timeout) clearTimeout(timeout) | ||
| timeout = setTimeout(function(){ cache = [] }, 60000) | ||
| } | ||
| this.parentNode.removeChild(this) | ||
| } | ||
| }) | ||
| } | ||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,66 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| // The following code is heavily inspired by jQuery's $.fn.data() | ||
|
|
||
| ;(function($) { | ||
| var data = {}, dataAttr = $.fn.data, camelize = $.zepto.camelize, | ||
| exp = $.expando = 'Zepto' + (+new Date()) | ||
|
|
||
| // Get value from node: | ||
| // 1. first try key as given, | ||
| // 2. then try camelized key, | ||
| // 3. fall back to reading "data-*" attribute. | ||
| function getData(node, name) { | ||
| var id = node[exp], store = id && data[id] | ||
| if (name === undefined) return store || setData(node) | ||
| else { | ||
| if (store) { | ||
| if (name in store) return store[name] | ||
| var camelName = camelize(name) | ||
| if (camelName in store) return store[camelName] | ||
| } | ||
| return dataAttr.call($(node), name) | ||
| } | ||
| } | ||
|
|
||
| // Store value under camelized key on node | ||
| function setData(node, name, value) { | ||
| var id = node[exp] || (node[exp] = ++$.uuid), | ||
| store = data[id] || (data[id] = attributeData(node)) | ||
| if (name !== undefined) store[camelize(name)] = value | ||
| return store | ||
| } | ||
|
|
||
| // Read all "data-*" attributes from a node | ||
| function attributeData(node) { | ||
| var store = {} | ||
| $.each(node.attributes, function(i, attr){ | ||
| if (attr.name.indexOf('data-') == 0) | ||
| store[camelize(attr.name.replace('data-', ''))] = attr.value | ||
| }) | ||
| return store | ||
| } | ||
|
|
||
| $.fn.data = function(name, value) { | ||
| return value === undefined ? | ||
| // set multiple values via object | ||
| $.isPlainObject(name) ? | ||
| this.each(function(i, node){ | ||
| $.each(name, function(key, value){ setData(node, key, value) }) | ||
| }) : | ||
| // get value from first element | ||
| this.length == 0 ? undefined : getData(this[0], name) : | ||
| // set value on all elements | ||
| this.each(function(){ setData(this, name, value) }) | ||
| } | ||
|
|
||
| $.fn.removeData = function(names) { | ||
| if (typeof names == 'string') names = names.split(/\s+/) | ||
| return this.each(function(){ | ||
| var id = this[exp], store = id && data[id] | ||
| if (store) $.each(names, function(){ delete store[camelize(this)] }) | ||
| }) | ||
| } | ||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,54 +1,40 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function($){ | ||
| function detect(ua){ | ||
| var os = this.os = {}, browser = this.browser = {}, | ||
| webkit = ua.match(/WebKit\/([\d.]+)/), | ||
| android = ua.match(/(Android)\s+([\d.]+)/), | ||
| ipad = ua.match(/(iPad).*OS\s([\d_]+)/), | ||
| iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/), | ||
| webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/), | ||
| touchpad = webos && ua.match(/TouchPad/), | ||
| kindle = ua.match(/Kindle\/([\d.]+)/), | ||
| silk = ua.match(/Silk\/([\d._]+)/), | ||
| blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/) | ||
|
|
||
| // todo clean this up with a better OS/browser | ||
| // separation. we need to discern between multiple | ||
| // browsers on android, and decide if kindle fire in | ||
| // silk mode is android or not | ||
|
|
||
| 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 (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.') | ||
| if (webos) os.webos = true, os.version = webos[2] | ||
| if (touchpad) os.touchpad = true | ||
| if (blackberry) os.blackberry = true, os.version = blackberry[2] | ||
| if (kindle) os.kindle = true, os.version = kindle[1] | ||
| if (silk) browser.silk = true, browser.version = silk[1] | ||
| if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true | ||
| } | ||
|
|
||
| detect.call($, navigator.userAgent) | ||
| // make available to unit tests | ||
| $.__detect = detect | ||
|
|
||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,198 +1,224 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function($){ | ||
| var $$ = $.zepto.qsa, handlers = {}, _zid = 1, specialEvents={} | ||
|
|
||
| specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents' | ||
|
|
||
| function zid(element) { | ||
| return element._zid || (element._zid = _zid++) | ||
| } | ||
| function findHandlers(element, event, fn, selector) { | ||
| event = parse(event) | ||
| if (event.ns) var matcher = matcherFor(event.ns) | ||
| return (handlers[zid(element)] || []).filter(function(handler) { | ||
| return handler | ||
| && (!event.e || handler.e == event.e) | ||
| && (!event.ns || matcher.test(handler.ns)) | ||
| && (!fn || zid(handler.fn) === zid(fn)) | ||
| && (!selector || handler.sel == selector) | ||
| }) | ||
| } | ||
| function parse(event) { | ||
| var parts = ('' + event).split('.') | ||
| return {e: parts[0], ns: parts.slice(1).sort().join(' ')} | ||
| } | ||
| function matcherFor(ns) { | ||
| return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') | ||
| } | ||
|
|
||
| function eachEvent(events, fn, iterator){ | ||
| if ($.isObject(events)) $.each(events, iterator) | ||
| else events.split(/\s/).forEach(function(type){ iterator(type, fn) }) | ||
| } | ||
|
|
||
| function add(element, events, fn, selector, getDelegate, capture){ | ||
| capture = !!capture | ||
| var id = zid(element), set = (handlers[id] || (handlers[id] = [])) | ||
| eachEvent(events, fn, function(event, fn){ | ||
| var delegate = getDelegate && getDelegate(fn, event), | ||
| callback = delegate || fn | ||
| var proxyfn = function (event) { | ||
| var result = callback.apply(element, [event].concat(event.data)) | ||
| if (result === false) event.preventDefault() | ||
| return result | ||
| } | ||
| var handler = $.extend(parse(event), {fn: fn, proxy: proxyfn, sel: selector, del: delegate, i: set.length}) | ||
| set.push(handler) | ||
| element.addEventListener(handler.e, proxyfn, capture) | ||
| }) | ||
| } | ||
| function remove(element, events, fn, selector){ | ||
| var id = zid(element) | ||
| eachEvent(events || '', fn, function(event, fn){ | ||
| findHandlers(element, event, fn, selector).forEach(function(handler){ | ||
| delete handlers[id][handler.i] | ||
| element.removeEventListener(handler.e, handler.proxy, false) | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| $.event = { add: add, remove: remove } | ||
|
|
||
| $.proxy = function(fn, context) { | ||
| if ($.isFunction(fn)) { | ||
| var proxyFn = function(){ return fn.apply(context, arguments) } | ||
| proxyFn._zid = zid(fn) | ||
| return proxyFn | ||
| } else if (typeof context == 'string') { | ||
| return $.proxy(fn[context], fn) | ||
| } else { | ||
| throw new TypeError("expected function") | ||
| } | ||
| } | ||
|
|
||
| $.fn.bind = function(event, callback){ | ||
| return this.each(function(){ | ||
| add(this, event, callback) | ||
| }) | ||
| } | ||
| $.fn.unbind = function(event, callback){ | ||
| return this.each(function(){ | ||
| remove(this, event, callback) | ||
| }) | ||
| } | ||
| $.fn.one = function(event, callback){ | ||
| return this.each(function(i, element){ | ||
| add(this, event, callback, null, function(fn, type){ | ||
| return function(){ | ||
| var result = fn.apply(element, arguments) | ||
| remove(element, type, fn) | ||
| return result | ||
| } | ||
| }) | ||
| }) | ||
| } | ||
|
|
||
| var returnTrue = function(){return true}, | ||
| returnFalse = function(){return false}, | ||
| eventMethods = { | ||
| preventDefault: 'isDefaultPrevented', | ||
| stopImmediatePropagation: 'isImmediatePropagationStopped', | ||
| stopPropagation: 'isPropagationStopped' | ||
| } | ||
| function createProxy(event) { | ||
| var proxy = $.extend({originalEvent: event}, event) | ||
| $.each(eventMethods, function(name, predicate) { | ||
| proxy[name] = function(){ | ||
| this[predicate] = returnTrue | ||
| return event[name].apply(event, arguments) | ||
| } | ||
| proxy[predicate] = returnFalse | ||
| }) | ||
| return proxy | ||
| } | ||
|
|
||
| // emulates the 'defaultPrevented' property for browsers that have none | ||
| function fix(event) { | ||
| if (!('defaultPrevented' in event)) { | ||
| event.defaultPrevented = false | ||
| var prevent = event.preventDefault | ||
| event.preventDefault = function() { | ||
| this.defaultPrevented = true | ||
| prevent.call(this) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $.fn.delegate = function(selector, event, callback){ | ||
| var capture = false | ||
| if(event == 'blur' || event == 'focus'){ | ||
| if($.iswebkit) | ||
| event = event == 'blur' ? 'focusout' : event == 'focus' ? 'focusin' : event | ||
| else | ||
| capture = true | ||
| } | ||
|
|
||
| return this.each(function(i, element){ | ||
| add(element, event, callback, selector, function(fn){ | ||
| return function(e){ | ||
| var evt, match = $(e.target).closest(selector, element).get(0) | ||
| if (match) { | ||
| evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element}) | ||
| return fn.apply(match, [evt].concat([].slice.call(arguments, 1))) | ||
| } | ||
| } | ||
| }, capture) | ||
| }) | ||
| } | ||
| $.fn.undelegate = function(selector, event, callback){ | ||
| return this.each(function(){ | ||
| remove(this, event, callback, selector) | ||
| }) | ||
| } | ||
|
|
||
| $.fn.live = function(event, callback){ | ||
| $(document.body).delegate(this.selector, event, callback) | ||
| return this | ||
| } | ||
| $.fn.die = function(event, callback){ | ||
| $(document.body).undelegate(this.selector, event, callback) | ||
| return this | ||
| } | ||
|
|
||
| $.fn.on = function(event, selector, callback){ | ||
| return selector == undefined || $.isFunction(selector) ? | ||
| this.bind(event, selector) : this.delegate(selector, event, callback) | ||
| } | ||
| $.fn.off = function(event, selector, callback){ | ||
| return selector == undefined || $.isFunction(selector) ? | ||
| this.unbind(event, selector) : this.undelegate(selector, event, callback) | ||
| } | ||
|
|
||
| $.fn.trigger = function(event, data){ | ||
| if (typeof event == 'string') event = $.Event(event) | ||
| fix(event) | ||
| event.data = data | ||
| return this.each(function(){ | ||
| // items in the collection might not be DOM elements | ||
| // (todo: possibly support events on plain old objects) | ||
| if('dispatchEvent' in this) this.dispatchEvent(event) | ||
| }) | ||
| } | ||
|
|
||
| // triggers event handlers on current element just as if an event occurred, | ||
| // doesn't trigger an actual event, doesn't bubble | ||
| $.fn.triggerHandler = function(event, data){ | ||
| var e, result | ||
| this.each(function(i, element){ | ||
| e = createProxy(typeof event == 'string' ? $.Event(event) : event) | ||
| e.data = data | ||
| e.target = element | ||
| $.each(findHandlers(element, event.type || event), function(i, handler){ | ||
| result = handler.proxy(e) | ||
| if (e.isImmediatePropagationStopped()) return false | ||
| }) | ||
| }) | ||
| return result | ||
| } | ||
|
|
||
| // shortcut methods for `.bind(event, fn)` for each event type | ||
| ;('focusin focusout load resize scroll unload click dblclick '+ | ||
| 'mousedown mouseup mousemove mouseover mouseout '+ | ||
| 'change select keydown keypress keyup error').split(' ').forEach(function(event) { | ||
| $.fn[event] = function(callback){ return this.bind(event, callback) } | ||
| }) | ||
|
|
||
| ;['focus', 'blur'].forEach(function(name) { | ||
| $.fn[name] = function(callback) { | ||
| if (callback) this.bind(name, callback) | ||
| else if (this.length) try { this.get(0)[name]() } catch(e){} | ||
| return this | ||
| } | ||
| }) | ||
|
|
||
| $.Event = function(type, props) { | ||
| var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true | ||
| if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) | ||
| event.initEvent(type, bubbles, true, null, null, null, null, null, null, null, null, null, null, null, null) | ||
| return event | ||
| } | ||
|
|
||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,94 +1,40 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function ($) { | ||
| $.fn.serializeArray = function () { | ||
| var result = [], el | ||
| $( Array.prototype.slice.call(this.get(0).elements) ).each(function () { | ||
| el = $(this) | ||
| var type = el.attr('type') | ||
| if (this.nodeName.toLowerCase() != 'fieldset' && | ||
| !this.disabled && type != 'submit' && type != 'reset' && type != 'button' && | ||
| ((type != 'radio' && type != 'checkbox') || this.checked)) | ||
| result.push({ | ||
| name: el.attr('name'), | ||
| value: el.val() | ||
| }) | ||
| }) | ||
| return result | ||
| } | ||
|
|
||
| $.fn.serialize = function () { | ||
| var result = [] | ||
| this.serializeArray().forEach(function (elm) { | ||
| result.push( encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value) ) | ||
| }) | ||
| return result.join('&') | ||
| } | ||
|
|
||
| $.fn.submit = function (callback) { | ||
| if (callback) this.bind('submit', callback) | ||
| else if (this.length) { | ||
| var event = $.Event('submit') | ||
| this.eq(0).trigger(event) | ||
| if (!event.defaultPrevented) this.get(0).submit() | ||
| } | ||
| return this | ||
| } | ||
|
|
||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,78 +1,91 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function($, undefined){ | ||
| var prefix = '', eventPrefix, endEventName, endAnimationName, | ||
| vendors = { Webkit: 'webkit', Moz: '', O: 'o', ms: 'MS' }, | ||
| document = window.document, testEl = document.createElement('div'), | ||
| supportedTransforms = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i, | ||
| clearProperties = {} | ||
|
|
||
| function downcase(str) { return str.toLowerCase() } | ||
| function normalizeEvent(name) { return eventPrefix ? eventPrefix + name : downcase(name) } | ||
|
|
||
| $.each(vendors, function(vendor, event){ | ||
| if (testEl.style[vendor + 'TransitionProperty'] !== undefined) { | ||
| prefix = '-' + downcase(vendor) + '-' | ||
| eventPrefix = event | ||
| return false | ||
| } | ||
| }) | ||
|
|
||
| clearProperties[prefix + 'transition-property'] = | ||
| clearProperties[prefix + 'transition-duration'] = | ||
| clearProperties[prefix + 'transition-timing-function'] = | ||
| clearProperties[prefix + 'animation-name'] = | ||
| clearProperties[prefix + 'animation-duration'] = '' | ||
|
|
||
| $.fx = { | ||
| off: (eventPrefix === undefined && testEl.style.transitionProperty === undefined), | ||
| cssPrefix: prefix, | ||
| transitionEnd: normalizeEvent('TransitionEnd'), | ||
| animationEnd: normalizeEvent('AnimationEnd') | ||
| } | ||
|
|
||
| $.fn.animate = function(properties, duration, ease, callback){ | ||
| if ($.isObject(duration)) | ||
| ease = duration.easing, callback = duration.complete, duration = duration.duration | ||
| if (duration) duration = duration / 1000 | ||
| return this.anim(properties, duration, ease, callback) | ||
| } | ||
|
|
||
| $.fn.anim = function(properties, duration, ease, callback){ | ||
| var transforms, cssProperties = {}, key, that = this, wrappedCallback, endEvent = $.fx.transitionEnd | ||
| if (duration === undefined) duration = 0.4 | ||
| if ($.fx.off) duration = 0 | ||
|
|
||
| if (typeof properties == 'string') { | ||
| // keyframe animation | ||
| cssProperties[prefix + 'animation-name'] = properties | ||
| cssProperties[prefix + 'animation-duration'] = duration + 's' | ||
| endEvent = $.fx.animationEnd | ||
| } else { | ||
| // CSS transitions | ||
| for (key in properties) | ||
| if (supportedTransforms.test(key)) { | ||
| transforms || (transforms = []) | ||
| transforms.push(key + '(' + properties[key] + ')') | ||
| } | ||
| else cssProperties[key] = properties[key] | ||
|
|
||
| if (transforms) cssProperties[prefix + 'transform'] = transforms.join(' ') | ||
| if (!$.fx.off && typeof properties === 'object') { | ||
| cssProperties[prefix + 'transition-property'] = Object.keys(properties).join(', ') | ||
| cssProperties[prefix + 'transition-duration'] = duration + 's' | ||
| cssProperties[prefix + 'transition-timing-function'] = (ease || 'linear') | ||
| } | ||
| } | ||
|
|
||
| wrappedCallback = function(event){ | ||
| if (typeof event !== 'undefined') { | ||
| if (event.target !== event.currentTarget) return // makes sure the event didn't bubble from "below" | ||
| $(event.target).unbind(endEvent, arguments.callee) | ||
| } | ||
| $(this).css(clearProperties) | ||
| callback && callback.call(this) | ||
| } | ||
| if (duration > 0) this.bind(endEvent, wrappedCallback) | ||
|
|
||
| setTimeout(function() { | ||
| that.css(cssProperties) | ||
| if (duration <= 0) setTimeout(function() { | ||
| that.each(function(){ wrappedCallback.call(this) }) | ||
| }, 0) | ||
| }, 0) | ||
|
|
||
| return this | ||
| } | ||
|
|
||
| testEl = null | ||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,98 +1,72 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function($, undefined){ | ||
| var document = window.document, docElem = document.documentElement, | ||
| origShow = $.fn.show, origHide = $.fn.hide, origToggle = $.fn.toggle, | ||
| speeds = { _default: 400, fast: 200, slow: 600 } | ||
|
|
||
| function translateSpeed(speed) { | ||
| return typeof speed == 'number' ? speed : (speeds[speed] || speeds._default) | ||
| } | ||
|
|
||
| function anim(el, speed, opacity, scale, callback) { | ||
| if (typeof speed == 'function' && !callback) callback = speed, speed = undefined | ||
| var props = { opacity: opacity } | ||
| if (scale) { | ||
| props.scale = scale | ||
| el.css($.fx.cssPrefix + 'transform-origin', '0 0') | ||
| } | ||
| return el.anim(props, translateSpeed(speed) / 1000, null, callback) | ||
| } | ||
|
|
||
| function hide(el, speed, scale, callback) { | ||
| return anim(el, speed, 0, scale, function(){ | ||
| origHide.call($(this)) | ||
| callback && callback.call(this) | ||
| }) | ||
| } | ||
|
|
||
| $.fn.show = function(speed, callback) { | ||
| origShow.call(this) | ||
| if (speed === undefined) speed = 0 | ||
| else this.css('opacity', 0) | ||
| return anim(this, speed, 1, '1,1', callback) | ||
| } | ||
|
|
||
| $.fn.hide = function(speed, callback) { | ||
| if (speed === undefined) return origHide.call(this) | ||
| else return hide(this, speed, '0,0', callback) | ||
| } | ||
|
|
||
| $.fn.toggle = function(speed, callback) { | ||
| if (speed === undefined || typeof speed == 'boolean') return origToggle.call(this, speed) | ||
| else return this[this.css('display') == 'none' ? 'show' : 'hide'](speed, callback) | ||
| } | ||
|
|
||
| $.fn.fadeTo = function(speed, opacity, callback) { | ||
| return anim(this, speed, opacity, null, callback) | ||
| } | ||
|
|
||
| $.fn.fadeIn = function(speed, callback) { | ||
| var target = this.css('opacity') | ||
| if (target > 0) this.css('opacity', 0) | ||
| else target = 1 | ||
| return origShow.call(this).fadeTo(speed, target, callback) | ||
| } | ||
|
|
||
| $.fn.fadeOut = function(speed, callback) { | ||
| return hide(this, speed, null, callback) | ||
| } | ||
|
|
||
| $.fn.fadeToggle = function(speed, callback) { | ||
| var hidden = this.css('opacity') == 0 || this.css('display') == 'none' | ||
| return this[hidden ? 'fadeIn' : 'fadeOut'](speed, callback) | ||
| } | ||
|
|
||
| $.extend($.fx, { | ||
| speeds: speeds | ||
| }) | ||
|
|
||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,35 +1,35 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function($){ | ||
| if ($.os.ios) { | ||
| var gesture = {}, gestureTimeout | ||
|
|
||
| function parentIfText(node){ | ||
| return 'tagName' in node ? node : node.parentNode | ||
| } | ||
|
|
||
| $(document).bind('gesturestart', function(e){ | ||
| var now = Date.now(), delta = now - (gesture.last || now) | ||
| gesture.target = parentIfText(e.target) | ||
| gestureTimeout && clearTimeout(gestureTimeout) | ||
| gesture.e1 = e.scale | ||
| gesture.last = now | ||
| }).bind('gesturechange', function(e){ | ||
| gesture.e2 = e.scale | ||
| }).bind('gestureend', function(e){ | ||
| if (gesture.e2 > 0) { | ||
| Math.abs(gesture.e1 - gesture.e2) != 0 && $(gesture.target).trigger('pinch') && | ||
| $(gesture.target).trigger('pinch' + (gesture.e1 - gesture.e2 > 0 ? 'In' : 'Out')) | ||
| gesture.e1 = gesture.e2 = gesture.last = 0 | ||
| } else if ('last' in gesture) { | ||
| gesture = {} | ||
| } | ||
| }) | ||
|
|
||
| ;['pinch', 'pinchIn', 'pinchOut'].forEach(function(m){ | ||
| $.fn[m] = function(callback){ return this.bind(m, callback) } | ||
| }) | ||
| } | ||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,36 +1,36 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function(undefined){ | ||
| if (String.prototype.trim === undefined) // fix for iOS 3.2 | ||
| String.prototype.trim = function(){ return this.replace(/^\s+/, '').replace(/\s+$/, '') } | ||
|
|
||
| // For iOS 3.x | ||
| // from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce | ||
| if (Array.prototype.reduce === undefined) | ||
| Array.prototype.reduce = function(fun){ | ||
| if(this === void 0 || this === null) throw new TypeError() | ||
| var t = Object(this), len = t.length >>> 0, k = 0, accumulator | ||
| if(typeof fun != 'function') throw new TypeError() | ||
| if(len == 0 && arguments.length == 1) throw new TypeError() | ||
|
|
||
| if(arguments.length >= 2) | ||
| accumulator = arguments[1] | ||
| else | ||
| do{ | ||
| if(k in t){ | ||
| accumulator = t[k++] | ||
| break | ||
| } | ||
| if(++k >= len) throw new TypeError() | ||
| } while (true) | ||
|
|
||
| while (k < len){ | ||
| if(k in t) accumulator = fun.call(undefined, accumulator, t[k], k, t) | ||
| k++ | ||
| } | ||
| return accumulator | ||
| } | ||
|
|
||
| })() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| ;(function($){ | ||
| var zepto = $.zepto, oldQsa = zepto.qsa, oldMatches = zepto.matches | ||
|
|
||
| function visible(elem){ | ||
| elem = $(elem) | ||
| return !!(elem.width() || elem.height()) && elem.css("display") !== "none" | ||
| } | ||
|
|
||
| // Implements a subset from: | ||
| // http://api.jquery.com/category/selectors/jquery-selector-extensions/ | ||
| // | ||
| // Each filter function receives the current index, all nodes in the | ||
| // considered set, and a value if there were parentheses. The value | ||
| // of `this` is the node currently being considered. The function returns the | ||
| // resulting node(s), null, or undefined. | ||
| // | ||
| // Complex selectors are not supported: | ||
| // li:has(label:contains("foo")) + li:has(label:contains("bar")) | ||
| // "> h2" | ||
| // ul.inner:first > li | ||
| var filters = zepto.cssFilters = { | ||
| visible: function(){ if (visible(this)) return this }, | ||
| hidden: function(){ if (!visible(this)) return this }, | ||
| selected: function(){ if (this.selected) return this }, | ||
| checked: function(){ if (this.checked) return this }, | ||
| parent: function(){ return this.parentNode }, | ||
| first: function(idx){ if (idx === 0) return this }, | ||
| last: function(idx, nodes){ if (idx === nodes.length - 1) return this }, | ||
| eq: function(idx, _, value){ if (idx === value) return this }, | ||
| contains: function(idx, _, text){ if ($(this).text().indexOf(text) > -1) return this }, | ||
| has: function(idx, _, sel){ if (zepto.qsa(this, sel).length) return this } | ||
| } | ||
|
|
||
| var re = new RegExp('(.*):(\\w+)(?:\\(([^)]+)\\))?$\\s*') | ||
|
|
||
| function process(sel, fn) { | ||
| var filter, arg, match = sel.match(re) | ||
| if (match && match[2] in filters) { | ||
| var filter = filters[match[2]], arg = match[3] | ||
| sel = match[1] | ||
| if (arg) { | ||
| var num = Number(arg) | ||
| if (isNaN(num)) arg = arg.replace(/^["']|["']$/g, '') | ||
| else arg = num | ||
| } | ||
| } | ||
| return fn(sel, filter, arg) | ||
| } | ||
|
|
||
| zepto.qsa = function(node, selector) { | ||
| return process(selector, function(sel, filter, arg){ | ||
| try { | ||
| if (!sel && filter) sel = '*' | ||
| var nodes = oldQsa(node, sel) | ||
| } catch(e) { | ||
| console.error('error performing selector: %o', selector) | ||
| throw e | ||
| } | ||
| return !filter ? nodes : | ||
| zepto.uniq($.map(nodes, function(n, i){ return filter.call(n, i, nodes, arg) })) | ||
| }) | ||
| } | ||
|
|
||
| zepto.matches = function(node, selector){ | ||
| return process(selector, function(sel, filter, arg){ | ||
| return (!sel || oldMatches(node, sel)) && | ||
| (!filter || filter.call(node, null, arg) === node) | ||
| }) | ||
| } | ||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function($){ | ||
| $.fn.end = function(){ | ||
| return this.prevObject || $() | ||
| } | ||
|
|
||
| $.fn.andSelf = function(){ | ||
| return this.add(this.prevObject || $()) | ||
| } | ||
|
|
||
| 'filter,add,not,eq,first,last,find,closest,parents,parent,children,siblings'.split(',').forEach(function(property){ | ||
| var fn = $.fn[property] | ||
| $.fn[property] = function(){ | ||
| var ret = fn.apply(this, arguments) | ||
| ret.prevObject = this | ||
| return ret | ||
| } | ||
| }) | ||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,64 +1,85 @@ | ||
| // Zepto.js | ||
| // (c) 2010-2012 Thomas Fuchs | ||
| // Zepto.js may be freely distributed under the MIT license. | ||
|
|
||
| ;(function($){ | ||
| var touch = {}, touchTimeout | ||
|
|
||
| function parentIfText(node){ | ||
| return 'tagName' in node ? node : node.parentNode | ||
| } | ||
|
|
||
| function swipeDirection(x1, x2, y1, y2){ | ||
| var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2) | ||
| return xDelta >= yDelta ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down') | ||
| } | ||
|
|
||
| var longTapDelay = 750, longTapTimeout | ||
|
|
||
| function longTap(){ | ||
| longTapTimeout = null | ||
| if (touch.last) { | ||
| touch.el.trigger('longTap') | ||
| touch = {} | ||
| } | ||
| } | ||
|
|
||
| function cancelLongTap(){ | ||
| if (longTapTimeout) clearTimeout(longTapTimeout) | ||
| longTapTimeout = null | ||
| } | ||
|
|
||
| $(document).ready(function(){ | ||
| var now, delta | ||
|
|
||
| $(document.body).bind('touchstart', function(e){ | ||
| now = Date.now() | ||
| delta = now - (touch.last || now) | ||
| touch.el = $(parentIfText(e.touches[0].target)) | ||
| touchTimeout && clearTimeout(touchTimeout) | ||
| touch.x1 = e.touches[0].pageX | ||
| touch.y1 = e.touches[0].pageY | ||
| if (delta > 0 && delta <= 250) touch.isDoubleTap = true | ||
| touch.last = now | ||
| longTapTimeout = setTimeout(longTap, longTapDelay) | ||
| }).bind('touchmove', function(e){ | ||
| cancelLongTap() | ||
| touch.x2 = e.touches[0].pageX | ||
| touch.y2 = e.touches[0].pageY | ||
| }).bind('touchend', function(e){ | ||
| cancelLongTap() | ||
|
|
||
| // double tap (tapped twice within 250ms) | ||
| if (touch.isDoubleTap) { | ||
| touch.el.trigger('doubleTap') | ||
| touch = {} | ||
|
|
||
| // swipe | ||
| } else if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) || | ||
| (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30)) { | ||
| touch.el.trigger('swipe') && | ||
| touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2))) | ||
| touch = {} | ||
|
|
||
| // normal tap | ||
| } else if ('last' in touch) { | ||
| touch.el.trigger('tap') | ||
|
|
||
| touchTimeout = setTimeout(function(){ | ||
| touchTimeout = null | ||
| touch.el.trigger('singleTap') | ||
| touch = {} | ||
| }, 250) | ||
| } | ||
| }).bind('touchcancel', function(){ | ||
| if (touchTimeout) clearTimeout(touchTimeout) | ||
| if (longTapTimeout) clearTimeout(longTapTimeout) | ||
| longTapTimeout = touchTimeout = null | ||
| touch = {} | ||
| }) | ||
| }) | ||
|
|
||
| ;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(m){ | ||
| $.fn[m] = function(callback){ return this.bind(m, callback) } | ||
| }) | ||
| })(Zepto) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> | ||
| <link rel="stylesheet" href="test.css"> | ||
| <title>Zepto event tests</title> | ||
| <script src="../vendor/evidence.js"></script> | ||
| <script src="evidence_runner.js"></script> | ||
| <script src="../src/polyfill.js"></script> | ||
| <script src="../src/zepto.js"></script> | ||
| <script src="../src/event.js"></script> | ||
| </head> | ||
| <body> | ||
| <h1>Zepto event tests</h1> | ||
| <p id="results"> | ||
| Running… see browser console for results | ||
| </p> | ||
| <div id="fixtures"> | ||
| </div><!-- fixtures --> | ||
|
|
||
| <script> | ||
| (function(){ | ||
|
|
||
| function click(el){ | ||
| var event = document.createEvent('MouseEvents') | ||
| event.initMouseEvent('click', true, true, document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null) | ||
| $(el).get(0).dispatchEvent(event) | ||
| } | ||
|
|
||
| Evidence('ProxyTest', { | ||
| testProxyFnContext: function(t){ | ||
| var a = {name: 'A', fn: function(n, o){ return this.name + n + o }}, | ||
| b = {name: 'B'} | ||
|
|
||
| t.assertEqual('A13', a.fn(1, 3)) | ||
| t.assertEqual('B52', $.proxy(a.fn, b)(5, 2)) | ||
| }, | ||
|
|
||
| testProxyInvalidFn: function(t){ | ||
| try { | ||
| $.proxy(null) | ||
| t.fail("shouldn't be here") | ||
| } catch(e) { | ||
| t.assertEqual('TypeError', e.name) | ||
| t.assertEqual("expected function", e.message) | ||
| } | ||
| }, | ||
|
|
||
| testProxyContextName: function(t){ | ||
| var b = {name: 'B', fn: function(n, o){ return this.name + n + o }}, | ||
| oldFn = b.fn | ||
|
|
||
| t.assertEqual('B52', $.proxy(b, 'fn')(5, 2)) | ||
| t.assertIdentical(oldFn, b.fn) | ||
| }, | ||
|
|
||
| testProxyUndefinedProperty: function(t){ | ||
| try { | ||
| $.proxy({}, 'nonexistent') | ||
| t.fail("shouldn't be here") | ||
| } catch(e) { | ||
| t.assertEqual('TypeError', e.name) | ||
| t.assertEqual("expected function", e.message) | ||
| } | ||
| }, | ||
|
|
||
| testProxyInvalidProperty: function(t){ | ||
| try { | ||
| $.proxy({num:3}, 'num') | ||
| t.fail("shouldn't be here") | ||
| } catch(e) { | ||
| t.assertEqual('TypeError', e.name) | ||
| t.assertEqual("expected function", e.message) | ||
| } | ||
| } | ||
| }) | ||
|
|
||
| Evidence('EventTest', { | ||
| setUp: function(){ | ||
| this.el = $('<div />').appendTo('#fixtures') | ||
| }, | ||
|
|
||
| tearDown: function(){ | ||
| this.el.off().remove() | ||
| $([document, document.body]).off() | ||
| }, | ||
|
|
||
| testProxiedHandlerCanBeUnbindedWithOriginal: function(t){ | ||
| var obj = {times:0, fn: function(){ this.times++ }} | ||
|
|
||
| this.el.on('click', $.proxy(obj, 'fn')) | ||
| click(this.el) | ||
| t.assertEqual(1, obj.times) | ||
|
|
||
| this.el.off('click', obj.fn) | ||
| click(this.el) | ||
| t.assertEqual(1, obj.times) | ||
| }, | ||
|
|
||
| testOnWithObject: function(t){ | ||
| var log = [] | ||
| this.el.on({ click: function(){ log.push('a') } }). | ||
| on({ click: function(){ log.push('b') } }, null) | ||
|
|
||
| click(this.el) | ||
| t.assertEqual('a b', log.sort().join(' ')) | ||
| }, | ||
|
|
||
| testOnWithNullSelector: function(t){ | ||
| var log = [] | ||
| this.el.on('click', null, function(){ log.push('a') }). | ||
| on('click', undefined, function(){ log.push('b') }) | ||
|
|
||
| click(this.el) | ||
| t.assertEqual('a b', log.sort().join(' ')) | ||
| }, | ||
|
|
||
| testOffWithObject: function(t){ | ||
| var log = [], | ||
| fn = function(){ log.push('a') }, | ||
| fn2 = function(){ log.push('b') }, | ||
| fn3 = function(){ log.push('c') } | ||
|
|
||
| this.el.on('click', fn).on('click', fn2).on('click', fn3) | ||
| click(this.el) | ||
| t.assertEqual('a b c', log.sort().join(' ')) | ||
|
|
||
| this.el.off({ click: fn }).off({ click: fn2 }, null) | ||
| click(this.el) | ||
| t.assertEqual('a b c c', log.sort().join(' ')) | ||
| } | ||
| }) | ||
| })() | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <title>testAjaxLoad</title> | ||
| </head> | ||
| <body> | ||
| <div id="ajax_load_test_div">ajax load with selector</div> | ||
| <div> | ||
| Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. | ||
| </div> | ||
| <script> | ||
| window.testValue = 1; | ||
| </script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,7 @@ | ||
| for (key in window) { | ||
| // we can't read callback from URL, hence this hack | ||
| if (/^jsonp(\d+)$/.test(key)) { | ||
| window[key]({ hello: 'world' }) | ||
| } | ||
| } | ||
| delete window.key |