├── .gitignore ├── .travis.yml ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── Rakefile ├── accept.coffee ├── beforesend.coffee ├── bower.json ├── confirm.coffee ├── csrf.coffee ├── disable.coffee ├── index.js ├── method.coffee ├── prepare.coffee ├── remote.coffee ├── remote_submit.coffee ├── script ├── server └── test ├── test ├── config.ru ├── index.html ├── test.coffee └── unit │ ├── accept.coffee │ ├── confirm.coffee │ ├── csrf.coffee │ ├── disable.coffee │ ├── method.coffee │ ├── prepare.coffee │ ├── remote.coffee │ └── remote_submit.coffee └── vendor ├── jquery-1.7.2.js ├── jquery-1.8.3.js ├── jquery-1.9.1.js ├── jquery-2.0.3.js ├── jquery-2.1.3.js ├── qunit.css ├── qunit.js ├── run-qunit.coffee ├── zepto-1.0.js └── zepto-1.1.6.js /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle 2 | .ruby-version 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: ruby 3 | rvm: 4 | - 1.9.3 5 | 6 | script: script/test 7 | 8 | notifications: 9 | disabled: true 10 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rack' 4 | gem 'sprockets' 5 | gem 'coffee-script' 6 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | coffee-script (2.2.0) 5 | coffee-script-source 6 | execjs 7 | coffee-script-source (1.6.3) 8 | execjs (2.0.2) 9 | hike (1.2.3) 10 | multi_json (1.8.4) 11 | rack (1.5.2) 12 | sprockets (2.10.1) 13 | hike (~> 1.2) 14 | multi_json (~> 1.0) 15 | rack (~> 1.0) 16 | tilt (~> 1.1, != 1.3.0) 17 | tilt (1.4.1) 18 | 19 | PLATFORMS 20 | ruby 21 | 22 | DEPENDENCIES 23 | coffee-script 24 | rack 25 | sprockets 26 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Joshua Peek 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rails Behaviors (Deprecated) 2 | 3 | Rails Behaviors implements the `data-*` behaviors generated by Rails 3.x. 4 | 5 | This is an alternative to [jquery-ujs](https://github.com/rails/jquery-ujs). First, it is all CoffeeScript goodness — well, that's mostly good for me! Second, it is written in a modular fashion. This makes it possible to cherry pick the components you need and replace specific functionaly without having to rewrite the entire library. Third, it uses built-in global ajax events rather than adding its own. O, one more thing, **Zepto**. 6 | 7 | 8 | ## Dependencies 9 | 10 | **jQuery 1.7.2+** or **Zepto 0.8+** 11 | 12 | You'll need [Sprockets 2](https://github.com/sstephenson/sprockets) if you want to use the gem version. 13 | 14 | 15 | ## Installation 16 | 17 | rails-behaviors is distributed through the [bower](https://github.com/twitter/bower) package manager. 18 | 19 | ``` bash 20 | bower install rails-behaviors 21 | ``` 22 | 23 | ## Testing 24 | 25 | For testing you will need: 26 | 27 | * Ruby 1.9.3+ 28 | * Bundler (`gem install bundler`) 29 | 30 | ``` bash 31 | bundle install 32 | bundle exec rackup -E test ./test/config.ru 33 | # now open the browser at http://localhost:9292 34 | ``` 35 | 36 | ## Migrating from jquery-ujs 37 | 38 | This library handles all the `data-*` behaviors defined in Rails, so it is roughly feature for feature identicial in your Views. 39 | 40 | The differences are in the JavaScript. 41 | 42 | 1. There are no `ajax:*` events. jQuery already has global ajax events built in, so there is no point in duplicating that functionality. Doing a find and replace for `"ajax:"` events should give you a good start. You're looking to replace `ajax:success` with `ajaxSuccess`, `ajax:error` with `ajaxError`, etc. 43 | 2. There are no global configuration options. Theres no equivalent for `$.rails`. You probably should have never used that in the first place. 44 | 45 | **NOTE:** You **cannot** use `rails-behaviors` and `jquery-ujs` at the same time. 46 | 47 | 48 | ## Reference 49 | 50 | See [josh.github.com/rails-behaviors](http://josh.github.com/rails-behaviors/) for a markup and event reference. 51 | 52 | ## Contributing 53 | 54 | Setup: 55 | 56 | $ git clone git://github.com/josh/rails-behaviors.git 57 | $ cd rails-behaviors/ 58 | $ bundle install 59 | 60 | Run tests: 61 | 62 | $ rackup -p 3000 test/config.ru 63 | $ open http://localhost:3000/ 64 | 65 | ## License 66 | 67 | Copyright © 2011 Joshua Peek <> 68 | 69 | Rails Behaviors is distributed under an MIT-style license. See LICENSE for details. 70 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'coffee-script' 2 | 3 | task :build do 4 | Dir['./*.coffee'].each do |src| 5 | dest = src.sub(/\.coffee/, '.js') 6 | data = CoffeeScript.compile(File.read(src)) 7 | File.open(dest, 'w') { |f| f.write(data) } 8 | end 9 | end 10 | 11 | task :default => :build 12 | -------------------------------------------------------------------------------- /accept.coffee: -------------------------------------------------------------------------------- 1 | # Accept 2 | # 3 | #= require ./beforesend 4 | # 5 | # Make default Accept header prefer JS. 6 | # 7 | # jQuery's default Accept header is just `"*/*"`, which means accept 8 | # anything back. To make AJAX requests work nicer with Rails' 9 | # `respond_to` block, this prioritizes JS responds over others. 10 | # 11 | # For an example: 12 | # 13 | # respond_to do |format| 14 | # format.html 15 | # format.js 16 | # end 17 | # 18 | # Would return `html` for `"*/*"` just because its first in the list. 19 | # Adjusting the Accept header makes it work as expected. 20 | # 21 | # Otherwise, if there is no `format.js`, the first responder will be used. 22 | # 23 | # The new Accept value is: 24 | # 25 | # "*/*;q=0.5, text/javascript, application/javascript, 26 | # application/ecmascript, application/x-ecmascript" 27 | # 28 | 29 | $(document).on 'ajaxBeforeSend', (event, xhr, settings) -> 30 | unless settings.dataType 31 | xhr.setRequestHeader 'Accept', '*/*;q=0.5, ' + settings.accepts.script 32 | -------------------------------------------------------------------------------- /beforesend.coffee: -------------------------------------------------------------------------------- 1 | # Implements global `ajaxBeforeSend` event. 2 | # 3 | # jQuery already provides a handful of global AJAX events. However, 4 | # there is no global version of `beforeSend`, so `ajaxBeforeSend` is 5 | # added to complement it. 6 | # 7 | # Reference: http://docs.jquery.com/Ajax_Events 8 | 9 | # Skip for Zepto which doesn't have ajaxSetup but does already support 10 | # `ajaxBeforeSend`. It'd be better to feature test for the event and 11 | # see if we need to install it. 12 | unless Zepto? 13 | 14 | # One caveat about using `$.ajaxSetup` is that its easily clobbered. 15 | # If anything else tries to register another global `beforeSend` 16 | # handler, ours will be overriden. 17 | # 18 | # To work around this, register your global `beforeSend` handler with: 19 | # 20 | # $(document).on('ajaxBeforeSend', function() {}) 21 | # 22 | $.ajaxSetup 23 | beforeSend: (xhr, settings) -> 24 | # Skip if global events are disabled 25 | return unless settings.global 26 | 27 | # Default to document if context isn't set 28 | element = settings.context || document 29 | 30 | # Provide a global version of the `beforeSend` callback 31 | event = $.Event 'ajaxBeforeSend' 32 | $(element).trigger event, [xhr, settings] 33 | if event.isDefaultPrevented() then false else event.result 34 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rails-behaviors", 3 | "version": "0.8.4", 4 | "main": "./index.js", 5 | "ignore": [ 6 | ".travis.yml", 7 | "Gemfile", 8 | "Gemfile.lock", 9 | "Rakefile", 10 | "script/", 11 | "test/", 12 | "vendor/" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /confirm.coffee: -------------------------------------------------------------------------------- 1 | # Confirm 2 | # 3 | #= require ./prepare 4 | # 5 | # Prompts native confirm dialog before activating link. 6 | # 7 | # ### Markup 8 | # 9 | # `` 10 | # 11 | # ``` definition-table 12 | # Attribute - Description 13 | # 14 | # `data-confirm` - Message to pass to `confirm()`. 15 | # ``` 16 | # 17 | # ``` html 18 | # Delete 19 | # ``` 20 | # 21 | # `").appendTo('body') 51 | 52 | submit = form.find('button[type=submit]') 53 | 54 | window.formSubmitted = -> 55 | start() 56 | 57 | equal "Comment", submit.text() 58 | click submit[0] 59 | ok submit[0].disabled 60 | equal "Commenting...", submit.text() 61 | 62 | 63 | asyncTest "submit button is disabled with default text", 3, -> 64 | form = @$("
").appendTo('body') 65 | 66 | submit = form.find('button[type=submit]') 67 | 68 | window.formSubmitted = -> 69 | start() 70 | 71 | equal "Comment", submit.text() 72 | click submit[0] 73 | ok submit[0].disabled 74 | equal "Comment", submit.text() 75 | 76 | asyncTest "submit input with default value is disabled and enabled on remote form", 5, -> 77 | form = @$("
").appendTo('body') 78 | 79 | submit = form.find('input[type=submit]') 80 | 81 | @window.formSubmitted = -> 82 | setTimeout -> 83 | ok !submit[0].disabled 84 | equal "Submit", submit.val() 85 | start() 86 | , 0 87 | 88 | equal "", submit.val() 89 | click submit[0] 90 | ok submit[0].disabled 91 | equal "Submitting...", submit.val() 92 | 93 | asyncTest "submit input is disabled and enabled on remote form", 5, -> 94 | form = @$("
").appendTo('body') 95 | 96 | submit = form.find('input[type=submit]') 97 | 98 | @window.formSubmitted = -> 99 | setTimeout -> 100 | ok !submit[0].disabled 101 | equal "Comment", submit.val() 102 | start() 103 | , 0 104 | 105 | equal "Comment", submit.val() 106 | click submit[0] 107 | ok submit[0].disabled 108 | equal "Commenting...", submit.val() 109 | 110 | asyncTest "submit button is disabled and enabled on remote form", 5, -> 111 | form = @$("
").appendTo('body') 112 | 113 | submit = form.find('button[type=submit]') 114 | 115 | @window.formSubmitted = -> 116 | setTimeout -> 117 | ok !submit[0].disabled 118 | equal "Comment", submit.text() 119 | start() 120 | , 0 121 | 122 | equal "Comment", submit.text() 123 | click submit[0] 124 | ok submit[0].disabled 125 | equal "Commenting...", submit.text() 126 | -------------------------------------------------------------------------------- /test/unit/method.coffee: -------------------------------------------------------------------------------- 1 | each frameworks, (framework) -> 2 | module "#{framework} - Method", 3 | setup: -> 4 | setupFrame this, "/#{framework}.html" 5 | window.formSubmitted = -> 6 | 7 | teardown: -> 8 | delete window.formSubmitted 9 | 10 | asyncTest "link is submitted with GET method", 1, -> 11 | @window.clickLink = -> 12 | ok true 13 | start() 14 | return 15 | 16 | link = @$("
").appendTo('body') 17 | 18 | click link[0] 19 | 20 | asyncTest "link is submitted with POST method", 2, -> 21 | link = @$("").appendTo('body') 22 | 23 | window.formSubmitted = (data) -> 24 | equal 'POST', data.REQUEST_METHOD 25 | equal '/echo', data.REQUEST_PATH 26 | start() 27 | 28 | click link[0] 29 | 30 | asyncTest "link is submitted with PUT method", 2, -> 31 | link = @$("").appendTo('body') 32 | 33 | window.formSubmitted = (data) -> 34 | equal 'PUT', data.REQUEST_METHOD 35 | equal '/echo', data.REQUEST_PATH 36 | start() 37 | 38 | click link[0] 39 | 40 | asyncTest "link is submitted with DELETE method", 2, -> 41 | link = @$("").appendTo('body') 42 | 43 | window.formSubmitted = (data) -> 44 | equal 'DELETE', data.REQUEST_METHOD 45 | equal '/echo', data.REQUEST_PATH 46 | start() 47 | 48 | click link[0] 49 | -------------------------------------------------------------------------------- /test/unit/prepare.coffee: -------------------------------------------------------------------------------- 1 | each frameworks, (framework) -> 2 | module "#{framework} - prepare", 3 | setup: -> 4 | setupFrame this, "/#{framework}.html" 5 | window.formSubmitted = -> 6 | 7 | teardown: -> 8 | delete window.formSubmitted 9 | 10 | asyncTest "click:prepare events run before others", 4, -> 11 | link = @$("Click").appendTo('body') 12 | 13 | count = 0 14 | 15 | link.on 'click', -> 16 | equal ++count, 3 17 | 18 | link.on 'click:prepare', -> 19 | equal ++count, 1 20 | 21 | link.on 'click', -> 22 | equal ++count, 4 23 | 24 | link.on 'click:prepare', -> 25 | equal ++count, 2 26 | 27 | click link[0] 28 | 29 | start() 30 | 31 | asyncTest "click:prepare event can prevent default", 1, -> 32 | link = @$("Click").appendTo('body') 33 | 34 | link.on 'click:prepare', (event) -> 35 | event.preventDefault() 36 | 37 | link.on 'click', (event) -> 38 | ok event.defaultPrevented or event.isDefaultPrevented() 39 | 40 | click link[0] 41 | 42 | start() 43 | 44 | asyncTest "click:prepare event can stop propagation", 1, -> 45 | link = @$("Click").appendTo('body') 46 | 47 | link.on 'click:prepare', (event) -> 48 | event.stopPropagation() 49 | ok true 50 | 51 | link.on 'click', (event) -> 52 | ok false 53 | 54 | click link[0] 55 | 56 | start() 57 | 58 | 59 | asyncTest "submit:prepare events run before others", 4, -> 60 | form = @$("
").appendTo('body') 61 | 62 | count = 0 63 | 64 | form.on 'submit', -> 65 | equal ++count, 3 66 | 67 | form.on 'submit:prepare', -> 68 | equal ++count, 1 69 | 70 | form.on 'submit', -> 71 | equal ++count, 4 72 | 73 | form.on 'submit:prepare', -> 74 | equal ++count, 2 75 | 76 | form.submit() 77 | start() 78 | 79 | asyncTest "submit:prepare event can prevent default", 1, -> 80 | form = @$("
").appendTo('body') 81 | 82 | form.on 'submit:prepare', (event) -> 83 | event.preventDefault() 84 | 85 | form.on 'submit', (event) -> 86 | ok event.defaultPrevented or event.isDefaultPrevented() 87 | 88 | form.submit() 89 | start() 90 | 91 | asyncTest "submit:prepare event can stop propagation", 1, -> 92 | form = @$("
").appendTo('body') 93 | 94 | form.on 'submit:prepare', (event) -> 95 | event.stopPropagation() 96 | ok true 97 | 98 | form.on 'submit', (event) -> 99 | ok false 100 | 101 | form.submit() 102 | start() 103 | -------------------------------------------------------------------------------- /test/unit/remote.coffee: -------------------------------------------------------------------------------- 1 | each frameworks, (framework) -> 2 | module "#{framework} - Remote", 3 | setup: -> 4 | setupFrame this, "/#{framework}.html" 5 | 6 | asyncTest "link is submitted via AJAX with GET method", 2, -> 7 | link = @$("").appendTo('body') 8 | 9 | @window.formSubmitted = (data) -> 10 | equal 'GET', data.REQUEST_METHOD 11 | equal '/echo', data.REQUEST_PATH 12 | start() 13 | 14 | click link[0] 15 | 16 | asyncTest "link is submitted via AJAX with POST method", 2, -> 17 | link = @$("").appendTo('body') 18 | 19 | @window.formSubmitted = (data) -> 20 | equal 'POST', data.REQUEST_METHOD 21 | equal '/echo', data.REQUEST_PATH 22 | start() 23 | 24 | click link[0] 25 | 26 | asyncTest "link is submitted via AJAX with PUT method", 2, -> 27 | link = @$("").appendTo('body') 28 | 29 | @window.formSubmitted = (data) -> 30 | equal 'PUT', data.REQUEST_METHOD 31 | equal '/echo', data.REQUEST_PATH 32 | start() 33 | 34 | click link[0] 35 | 36 | asyncTest "link is submitted via AJAX with DELETE method", 2, -> 37 | link = @$("").appendTo('body') 38 | 39 | @window.formSubmitted = (data) -> 40 | equal 'DELETE', data.REQUEST_METHOD 41 | equal '/echo', data.REQUEST_PATH 42 | start() 43 | 44 | click link[0] 45 | 46 | asyncTest "link is submitted via AJAX that accepts JSON", 2, -> 47 | link = @$("").appendTo('body') 48 | 49 | @$(@document).on 'ajaxSuccess.test', 'a', (event, xhr, settings, data) -> 50 | equal 'GET', data.REQUEST_METHOD 51 | equal '/echo', data.REQUEST_PATH 52 | start() 53 | 54 | click link[0] 55 | 56 | asyncTest "link is prevented from being submitted", 1, -> 57 | link = @$("").appendTo('body') 58 | 59 | @$(@document).on 'ajaxBeforeSend.test', 'a', -> 60 | ok true 61 | false 62 | 63 | @$(@document).on 'ajaxSuccess.test', 'a', -> 64 | ok false 65 | 66 | click link[0] 67 | 68 | setTimeout (-> start()), 50 69 | 70 | asyncTest "link xhr is exposed via data remote-xhr", 2, -> 71 | link = @$("").appendTo('body') 72 | 73 | @$(@document).on 'ajaxSend.test', 'a', -> 74 | ok link.data 'remote-xhr' 75 | 76 | @$(@document).on 'ajaxSuccess.test', 'a', => 77 | setTimeout => 78 | if @$.fn.removeData 79 | ok !link.data('remote-xhr') 80 | else 81 | ok true 82 | start() 83 | , 0 84 | 85 | click link[0] 86 | 87 | 88 | asyncTest "form is submitted via AJAX with GET method", 3, -> 89 | form = @$("
").appendTo('body') 90 | 91 | @window.formSubmitted = (data) -> 92 | equal 'GET', data.REQUEST_METHOD 93 | equal '/echo', data.REQUEST_PATH 94 | equal 'bar', data.params['foo'] 95 | start() 96 | 97 | form.submit() 98 | 99 | asyncTest "form is submitted via AJAX with POST method", 3, -> 100 | form = @$("
").appendTo('body') 101 | 102 | @window.formSubmitted = (data) -> 103 | equal 'POST', data.REQUEST_METHOD 104 | equal '/echo', data.REQUEST_PATH 105 | equal 'bar', data.params['foo'] 106 | start() 107 | 108 | form.submit() 109 | 110 | asyncTest "form is submitted via AJAX with PUT method", 3, -> 111 | form = @$("
").appendTo('body') 112 | 113 | @window.formSubmitted = (data) -> 114 | equal 'PUT', data.REQUEST_METHOD 115 | equal '/echo', data.REQUEST_PATH 116 | equal 'bar', data.params['foo'] 117 | start() 118 | 119 | form.submit() 120 | 121 | asyncTest "form is submitted via AJAX with DELETE method", 2, -> 122 | form = @$("
").appendTo('body') 123 | 124 | @window.formSubmitted = (data) -> 125 | equal 'DELETE', data.REQUEST_METHOD 126 | equal '/echo', data.REQUEST_PATH 127 | start() 128 | 129 | form.submit() 130 | 131 | asyncTest "form is submitted via AJAX that accepts JSON", 3, -> 132 | form = @$("
").appendTo('body') 133 | 134 | @$(@document).on 'ajaxSuccess.test', 'form', (event, xhr, settings, data) -> 135 | equal 'GET', data.REQUEST_METHOD 136 | equal '/echo', data.REQUEST_PATH 137 | equal 'bar', data.params['foo'] 138 | start() 139 | 140 | form.submit() 141 | 142 | asyncTest "form is prevented from being submitted", 1, -> 143 | form = @$("
").appendTo('body') 144 | 145 | @$(@document).on 'ajaxBeforeSend.test', 'form', -> 146 | ok true 147 | false 148 | 149 | @$(@document).on 'ajaxSuccess.test', 'form', -> 150 | ok false 151 | 152 | form.submit() 153 | 154 | setTimeout (-> start()), 50 155 | 156 | asyncTest "form xhr is exposed via data remote-xhr", 2, -> 157 | form = @$("
").appendTo('body') 158 | 159 | @$(@document).on 'ajaxSend.test', 'form', -> 160 | ok form.data 'remote-xhr' 161 | 162 | @$(@document).on 'ajaxSuccess.test', 'form', => 163 | setTimeout => 164 | if @$.fn.removeData 165 | ok !form.data('remote-xhr') 166 | else 167 | ok true 168 | start() 169 | , 0 170 | 171 | form.submit() 172 | -------------------------------------------------------------------------------- /test/unit/remote_submit.coffee: -------------------------------------------------------------------------------- 1 | each frameworks, (framework) -> 2 | module "#{framework} - Remote Submit Button", 3 | setup: -> 4 | setupFrame this, "/#{framework}.html" 5 | 6 | asyncTest "form submit button value is serialized", 1, -> 7 | form = @$("
").appendTo('body') 8 | 9 | @window.formSubmitted = (data) -> 10 | equal data.params['submit'], "" 11 | start() 12 | 13 | click form.find('button[name=submit]')[0] 14 | 15 | asyncTest "form submit comment button value is serialized", 1, -> 16 | form = @$("
").appendTo('body') 17 | 18 | @window.formSubmitted = (data) -> 19 | equal data.params['submit'], "comment" 20 | start() 21 | 22 | click form.find('button[name=submit][value=comment]')[0] 23 | 24 | asyncTest "form submit cancel button value is serialized", 1, -> 25 | form = @$("
").appendTo('body') 26 | 27 | @window.formSubmitted = (data) -> 28 | equal data.params['submit'], "cancel" 29 | start() 30 | 31 | click form.find('button[name=submit][value=cancel]')[0] 32 | 33 | test "form submit button value is serialized for data-remote-submit", 1, -> 34 | form = @$("
").appendTo('body') 35 | 36 | form.on 'submit', -> 37 | equal form.serialize(), "submit=comment" 38 | false 39 | 40 | click form.find('button[name=submit][value=comment]')[0] 41 | -------------------------------------------------------------------------------- /vendor/qunit.css: -------------------------------------------------------------------------------- 1 | /** 2 | * QUnit v1.11.0 - A JavaScript Unit Testing Framework 3 | * 4 | * http://qunitjs.com 5 | * 6 | * Copyright 2012 jQuery Foundation and other contributors 7 | * Released under the MIT license. 8 | * http://jquery.org/license 9 | */ 10 | 11 | /** Font Family and Sizes */ 12 | 13 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { 14 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; 15 | } 16 | 17 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 18 | #qunit-tests { font-size: smaller; } 19 | 20 | 21 | /** Resets */ 22 | 23 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter { 24 | margin: 0; 25 | padding: 0; 26 | } 27 | 28 | 29 | /** Header */ 30 | 31 | #qunit-header { 32 | padding: 0.5em 0 0.5em 1em; 33 | 34 | color: #8699a4; 35 | background-color: #0d3349; 36 | 37 | font-size: 1.5em; 38 | line-height: 1em; 39 | font-weight: normal; 40 | 41 | border-radius: 5px 5px 0 0; 42 | -moz-border-radius: 5px 5px 0 0; 43 | -webkit-border-top-right-radius: 5px; 44 | -webkit-border-top-left-radius: 5px; 45 | } 46 | 47 | #qunit-header a { 48 | text-decoration: none; 49 | color: #c2ccd1; 50 | } 51 | 52 | #qunit-header a:hover, 53 | #qunit-header a:focus { 54 | color: #fff; 55 | } 56 | 57 | #qunit-testrunner-toolbar label { 58 | display: inline-block; 59 | padding: 0 .5em 0 .1em; 60 | } 61 | 62 | #qunit-banner { 63 | height: 5px; 64 | } 65 | 66 | #qunit-testrunner-toolbar { 67 | padding: 0.5em 0 0.5em 2em; 68 | color: #5E740B; 69 | background-color: #eee; 70 | overflow: hidden; 71 | } 72 | 73 | #qunit-userAgent { 74 | padding: 0.5em 0 0.5em 2.5em; 75 | background-color: #2b81af; 76 | color: #fff; 77 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; 78 | } 79 | 80 | #qunit-modulefilter-container { 81 | float: right; 82 | } 83 | 84 | /** Tests: Pass/Fail */ 85 | 86 | #qunit-tests { 87 | list-style-position: inside; 88 | } 89 | 90 | #qunit-tests li { 91 | padding: 0.4em 0.5em 0.4em 2.5em; 92 | border-bottom: 1px solid #fff; 93 | list-style-position: inside; 94 | } 95 | 96 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { 97 | display: none; 98 | } 99 | 100 | #qunit-tests li strong { 101 | cursor: pointer; 102 | } 103 | 104 | #qunit-tests li a { 105 | padding: 0.5em; 106 | color: #c2ccd1; 107 | text-decoration: none; 108 | } 109 | #qunit-tests li a:hover, 110 | #qunit-tests li a:focus { 111 | color: #000; 112 | } 113 | 114 | #qunit-tests li .runtime { 115 | float: right; 116 | font-size: smaller; 117 | } 118 | 119 | .qunit-assert-list { 120 | margin-top: 0.5em; 121 | padding: 0.5em; 122 | 123 | background-color: #fff; 124 | 125 | border-radius: 5px; 126 | -moz-border-radius: 5px; 127 | -webkit-border-radius: 5px; 128 | } 129 | 130 | .qunit-collapsed { 131 | display: none; 132 | } 133 | 134 | #qunit-tests table { 135 | border-collapse: collapse; 136 | margin-top: .2em; 137 | } 138 | 139 | #qunit-tests th { 140 | text-align: right; 141 | vertical-align: top; 142 | padding: 0 .5em 0 0; 143 | } 144 | 145 | #qunit-tests td { 146 | vertical-align: top; 147 | } 148 | 149 | #qunit-tests pre { 150 | margin: 0; 151 | white-space: pre-wrap; 152 | word-wrap: break-word; 153 | } 154 | 155 | #qunit-tests del { 156 | background-color: #e0f2be; 157 | color: #374e0c; 158 | text-decoration: none; 159 | } 160 | 161 | #qunit-tests ins { 162 | background-color: #ffcaca; 163 | color: #500; 164 | text-decoration: none; 165 | } 166 | 167 | /*** Test Counts */ 168 | 169 | #qunit-tests b.counts { color: black; } 170 | #qunit-tests b.passed { color: #5E740B; } 171 | #qunit-tests b.failed { color: #710909; } 172 | 173 | #qunit-tests li li { 174 | padding: 5px; 175 | background-color: #fff; 176 | border-bottom: none; 177 | list-style-position: inside; 178 | } 179 | 180 | /*** Passing Styles */ 181 | 182 | #qunit-tests li li.pass { 183 | color: #3c510c; 184 | background-color: #fff; 185 | border-left: 10px solid #C6E746; 186 | } 187 | 188 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } 189 | #qunit-tests .pass .test-name { color: #366097; } 190 | 191 | #qunit-tests .pass .test-actual, 192 | #qunit-tests .pass .test-expected { color: #999999; } 193 | 194 | #qunit-banner.qunit-pass { background-color: #C6E746; } 195 | 196 | /*** Failing Styles */ 197 | 198 | #qunit-tests li li.fail { 199 | color: #710909; 200 | background-color: #fff; 201 | border-left: 10px solid #EE5757; 202 | white-space: pre; 203 | } 204 | 205 | #qunit-tests > li:last-child { 206 | border-radius: 0 0 5px 5px; 207 | -moz-border-radius: 0 0 5px 5px; 208 | -webkit-border-bottom-right-radius: 5px; 209 | -webkit-border-bottom-left-radius: 5px; 210 | } 211 | 212 | #qunit-tests .fail { color: #000000; background-color: #EE5757; } 213 | #qunit-tests .fail .test-name, 214 | #qunit-tests .fail .module-name { color: #000000; } 215 | 216 | #qunit-tests .fail .test-actual { color: #EE5757; } 217 | #qunit-tests .fail .test-expected { color: green; } 218 | 219 | #qunit-banner.qunit-fail { background-color: #EE5757; } 220 | 221 | 222 | /** Result */ 223 | 224 | #qunit-testresult { 225 | padding: 0.5em 0.5em 0.5em 2.5em; 226 | 227 | color: #2b81af; 228 | background-color: #D2E0E6; 229 | 230 | border-bottom: 1px solid white; 231 | } 232 | #qunit-testresult .module-name { 233 | font-weight: bold; 234 | } 235 | 236 | /** Fixture */ 237 | 238 | #qunit-fixture { 239 | position: absolute; 240 | top: -10000px; 241 | left: -10000px; 242 | width: 1000px; 243 | height: 1000px; 244 | } 245 | -------------------------------------------------------------------------------- /vendor/run-qunit.coffee: -------------------------------------------------------------------------------- 1 | fs = require 'fs' 2 | print = (s) -> fs.write "/dev/stderr", s, 'w' 3 | 4 | page = new WebPage() 5 | page.onConsoleMessage = (msg) -> console.error msg 6 | 7 | timeoutId = null 8 | deferTimeout = -> 9 | clearTimeout timeoutId if timeoutId 10 | timeoutId = setTimeout -> 11 | console.error "Timeout" 12 | phantom.exit 1 13 | , 3000 14 | 15 | page.open phantom.args[0], -> 16 | deferTimeout() 17 | 18 | setInterval -> 19 | tests = page.evaluate -> 20 | tests = document.getElementById('qunit-tests').children 21 | for test in tests when test.className isnt 'running' and not test.recorded 22 | test.recorded = true 23 | if test.className is 'pass' 24 | '.' 25 | else if test.className is 'fail' 26 | 'F' 27 | 28 | for test in tests when test 29 | deferTimeout() 30 | print test 31 | 32 | result = page.evaluate -> 33 | result = document.getElementById('qunit-testresult') 34 | tests = document.getElementById('qunit-tests').children 35 | 36 | if result.innerText.match /completed/ 37 | console.error "" 38 | 39 | for test in tests when test.className is 'fail' 40 | console.error test.innerText 41 | 42 | console.error result.innerText 43 | return parseInt result.getElementsByClassName('failed')[0].innerText 44 | 45 | return 46 | 47 | phantom.exit result if result? 48 | , 100 49 | -------------------------------------------------------------------------------- /vendor/zepto-1.0.js: -------------------------------------------------------------------------------- 1 | /* Zepto v1.0-1-ga3cab6c - polyfill zepto detect event ajax form fx - zeptojs.com/license */ 2 | 3 | 4 | ;(function(undefined){ 5 | if (String.prototype.trim === undefined) // fix for iOS 3.2 6 | String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, '') } 7 | 8 | // For iOS 3.x 9 | // from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce 10 | if (Array.prototype.reduce === undefined) 11 | Array.prototype.reduce = function(fun){ 12 | if(this === void 0 || this === null) throw new TypeError() 13 | var t = Object(this), len = t.length >>> 0, k = 0, accumulator 14 | if(typeof fun != 'function') throw new TypeError() 15 | if(len == 0 && arguments.length == 1) throw new TypeError() 16 | 17 | if(arguments.length >= 2) 18 | accumulator = arguments[1] 19 | else 20 | do{ 21 | if(k in t){ 22 | accumulator = t[k++] 23 | break 24 | } 25 | if(++k >= len) throw new TypeError() 26 | } while (true) 27 | 28 | while (k < len){ 29 | if(k in t) accumulator = fun.call(undefined, accumulator, t[k], k, t) 30 | k++ 31 | } 32 | return accumulator 33 | } 34 | 35 | })() 36 | 37 | var Zepto = (function() { 38 | var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter, 39 | document = window.document, 40 | elementDisplay = {}, classCache = {}, 41 | getComputedStyle = document.defaultView.getComputedStyle, 42 | cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 }, 43 | fragmentRE = /^\s*<(\w+|!)[^>]*>/, 44 | tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, 45 | rootNodeRE = /^(?:body|html)$/i, 46 | 47 | // special attributes that should be get/set via method calls 48 | methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'], 49 | 50 | adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ], 51 | table = document.createElement('table'), 52 | tableRow = document.createElement('tr'), 53 | containers = { 54 | 'tr': document.createElement('tbody'), 55 | 'tbody': table, 'thead': table, 'tfoot': table, 56 | 'td': tableRow, 'th': tableRow, 57 | '*': document.createElement('div') 58 | }, 59 | readyRE = /complete|loaded|interactive/, 60 | classSelectorRE = /^\.([\w-]+)$/, 61 | idSelectorRE = /^#([\w-]*)$/, 62 | tagSelectorRE = /^[\w-]+$/, 63 | class2type = {}, 64 | toString = class2type.toString, 65 | zepto = {}, 66 | camelize, uniq, 67 | tempParent = document.createElement('div') 68 | 69 | zepto.matches = function(element, selector) { 70 | if (!element || element.nodeType !== 1) return false 71 | var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector || 72 | element.oMatchesSelector || element.matchesSelector 73 | if (matchesSelector) return matchesSelector.call(element, selector) 74 | // fall back to performing a selector: 75 | var match, parent = element.parentNode, temp = !parent 76 | if (temp) (parent = tempParent).appendChild(element) 77 | match = ~zepto.qsa(parent, selector).indexOf(element) 78 | temp && tempParent.removeChild(element) 79 | return match 80 | } 81 | 82 | function type(obj) { 83 | return obj == null ? String(obj) : 84 | class2type[toString.call(obj)] || "object" 85 | } 86 | 87 | function isFunction(value) { return type(value) == "function" } 88 | function isWindow(obj) { return obj != null && obj == obj.window } 89 | function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE } 90 | function isObject(obj) { return type(obj) == "object" } 91 | function isPlainObject(obj) { 92 | return isObject(obj) && !isWindow(obj) && obj.__proto__ == Object.prototype 93 | } 94 | function isArray(value) { return value instanceof Array } 95 | function likeArray(obj) { return typeof obj.length == 'number' } 96 | 97 | function compact(array) { return filter.call(array, function(item){ return item != null }) } 98 | function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array } 99 | camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) } 100 | function dasherize(str) { 101 | return str.replace(/::/g, '/') 102 | .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') 103 | .replace(/([a-z\d])([A-Z])/g, '$1_$2') 104 | .replace(/_/g, '-') 105 | .toLowerCase() 106 | } 107 | uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) } 108 | 109 | function classRE(name) { 110 | return name in classCache ? 111 | classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)')) 112 | } 113 | 114 | function maybeAddPx(name, value) { 115 | return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value 116 | } 117 | 118 | function defaultDisplay(nodeName) { 119 | var element, display 120 | if (!elementDisplay[nodeName]) { 121 | element = document.createElement(nodeName) 122 | document.body.appendChild(element) 123 | display = getComputedStyle(element, '').getPropertyValue("display") 124 | element.parentNode.removeChild(element) 125 | display == "none" && (display = "block") 126 | elementDisplay[nodeName] = display 127 | } 128 | return elementDisplay[nodeName] 129 | } 130 | 131 | function children(element) { 132 | return 'children' in element ? 133 | slice.call(element.children) : 134 | $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node }) 135 | } 136 | 137 | // `$.zepto.fragment` takes a html string and an optional tag name 138 | // to generate DOM nodes nodes from the given html string. 139 | // The generated DOM nodes are returned as an array. 140 | // This function can be overriden in plugins for example to make 141 | // it compatible with browsers that don't support the DOM fully. 142 | zepto.fragment = function(html, name, properties) { 143 | if (html.replace) html = html.replace(tagExpanderRE, "<$1>") 144 | if (name === undefined) name = fragmentRE.test(html) && RegExp.$1 145 | if (!(name in containers)) name = '*' 146 | 147 | var nodes, dom, container = containers[name] 148 | container.innerHTML = '' + html 149 | dom = $.each(slice.call(container.childNodes), function(){ 150 | container.removeChild(this) 151 | }) 152 | if (isPlainObject(properties)) { 153 | nodes = $(dom) 154 | $.each(properties, function(key, value) { 155 | if (methodAttributes.indexOf(key) > -1) nodes[key](value) 156 | else nodes.attr(key, value) 157 | }) 158 | } 159 | return dom 160 | } 161 | 162 | // `$.zepto.Z` swaps out the prototype of the given `dom` array 163 | // of nodes with `$.fn` and thus supplying all the Zepto functions 164 | // to the array. Note that `__proto__` is not supported on Internet 165 | // Explorer. This method can be overriden in plugins. 166 | zepto.Z = function(dom, selector) { 167 | dom = dom || [] 168 | dom.__proto__ = $.fn 169 | dom.selector = selector || '' 170 | return dom 171 | } 172 | 173 | // `$.zepto.isZ` should return `true` if the given object is a Zepto 174 | // collection. This method can be overriden in plugins. 175 | zepto.isZ = function(object) { 176 | return object instanceof zepto.Z 177 | } 178 | 179 | // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and 180 | // takes a CSS selector and an optional context (and handles various 181 | // special cases). 182 | // This method can be overriden in plugins. 183 | zepto.init = function(selector, context) { 184 | // If nothing given, return an empty Zepto collection 185 | if (!selector) return zepto.Z() 186 | // If a function is given, call it when the DOM is ready 187 | else if (isFunction(selector)) return $(document).ready(selector) 188 | // If a Zepto collection is given, juts return it 189 | else if (zepto.isZ(selector)) return selector 190 | else { 191 | var dom 192 | // normalize array if an array of nodes is given 193 | if (isArray(selector)) dom = compact(selector) 194 | // Wrap DOM nodes. If a plain object is given, duplicate it. 195 | else if (isObject(selector)) 196 | dom = [isPlainObject(selector) ? $.extend({}, selector) : selector], selector = null 197 | // If it's a html fragment, create nodes from it 198 | else if (fragmentRE.test(selector)) 199 | dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null 200 | // If there's a context, create a collection on that context first, and select 201 | // nodes from there 202 | else if (context !== undefined) return $(context).find(selector) 203 | // And last but no least, if it's a CSS selector, use it to select nodes. 204 | else dom = zepto.qsa(document, selector) 205 | // create a new Zepto collection from the nodes found 206 | return zepto.Z(dom, selector) 207 | } 208 | } 209 | 210 | // `$` will be the base `Zepto` object. When calling this 211 | // function just call `$.zepto.init, which makes the implementation 212 | // details of selecting nodes and creating Zepto collections 213 | // patchable in plugins. 214 | $ = function(selector, context){ 215 | return zepto.init(selector, context) 216 | } 217 | 218 | function extend(target, source, deep) { 219 | for (key in source) 220 | if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { 221 | if (isPlainObject(source[key]) && !isPlainObject(target[key])) 222 | target[key] = {} 223 | if (isArray(source[key]) && !isArray(target[key])) 224 | target[key] = [] 225 | extend(target[key], source[key], deep) 226 | } 227 | else if (source[key] !== undefined) target[key] = source[key] 228 | } 229 | 230 | // Copy all but undefined properties from one or more 231 | // objects to the `target` object. 232 | $.extend = function(target){ 233 | var deep, args = slice.call(arguments, 1) 234 | if (typeof target == 'boolean') { 235 | deep = target 236 | target = args.shift() 237 | } 238 | args.forEach(function(arg){ extend(target, arg, deep) }) 239 | return target 240 | } 241 | 242 | // `$.zepto.qsa` is Zepto's CSS selector implementation which 243 | // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`. 244 | // This method can be overriden in plugins. 245 | zepto.qsa = function(element, selector){ 246 | var found 247 | return (isDocument(element) && idSelectorRE.test(selector)) ? 248 | ( (found = element.getElementById(RegExp.$1)) ? [found] : [] ) : 249 | (element.nodeType !== 1 && element.nodeType !== 9) ? [] : 250 | slice.call( 251 | classSelectorRE.test(selector) ? element.getElementsByClassName(RegExp.$1) : 252 | tagSelectorRE.test(selector) ? element.getElementsByTagName(selector) : 253 | element.querySelectorAll(selector) 254 | ) 255 | } 256 | 257 | function filtered(nodes, selector) { 258 | return selector === undefined ? $(nodes) : $(nodes).filter(selector) 259 | } 260 | 261 | $.contains = function(parent, node) { 262 | return parent !== node && parent.contains(node) 263 | } 264 | 265 | function funcArg(context, arg, idx, payload) { 266 | return isFunction(arg) ? arg.call(context, idx, payload) : arg 267 | } 268 | 269 | function setAttribute(node, name, value) { 270 | value == null ? node.removeAttribute(name) : node.setAttribute(name, value) 271 | } 272 | 273 | // access className property while respecting SVGAnimatedString 274 | function className(node, value){ 275 | var klass = node.className, 276 | svg = klass && klass.baseVal !== undefined 277 | 278 | if (value === undefined) return svg ? klass.baseVal : klass 279 | svg ? (klass.baseVal = value) : (node.className = value) 280 | } 281 | 282 | // "true" => true 283 | // "false" => false 284 | // "null" => null 285 | // "42" => 42 286 | // "42.5" => 42.5 287 | // JSON => parse if valid 288 | // String => self 289 | function deserializeValue(value) { 290 | var num 291 | try { 292 | return value ? 293 | value == "true" || 294 | ( value == "false" ? false : 295 | value == "null" ? null : 296 | !isNaN(num = Number(value)) ? num : 297 | /^[\[\{]/.test(value) ? $.parseJSON(value) : 298 | value ) 299 | : value 300 | } catch(e) { 301 | return value 302 | } 303 | } 304 | 305 | $.type = type 306 | $.isFunction = isFunction 307 | $.isWindow = isWindow 308 | $.isArray = isArray 309 | $.isPlainObject = isPlainObject 310 | 311 | $.isEmptyObject = function(obj) { 312 | var name 313 | for (name in obj) return false 314 | return true 315 | } 316 | 317 | $.inArray = function(elem, array, i){ 318 | return emptyArray.indexOf.call(array, elem, i) 319 | } 320 | 321 | $.camelCase = camelize 322 | $.trim = function(str) { return str.trim() } 323 | 324 | // plugin compatibility 325 | $.uuid = 0 326 | $.support = { } 327 | $.expr = { } 328 | 329 | $.map = function(elements, callback){ 330 | var value, values = [], i, key 331 | if (likeArray(elements)) 332 | for (i = 0; i < elements.length; i++) { 333 | value = callback(elements[i], i) 334 | if (value != null) values.push(value) 335 | } 336 | else 337 | for (key in elements) { 338 | value = callback(elements[key], key) 339 | if (value != null) values.push(value) 340 | } 341 | return flatten(values) 342 | } 343 | 344 | $.each = function(elements, callback){ 345 | var i, key 346 | if (likeArray(elements)) { 347 | for (i = 0; i < elements.length; i++) 348 | if (callback.call(elements[i], i, elements[i]) === false) return elements 349 | } else { 350 | for (key in elements) 351 | if (callback.call(elements[key], key, elements[key]) === false) return elements 352 | } 353 | 354 | return elements 355 | } 356 | 357 | $.grep = function(elements, callback){ 358 | return filter.call(elements, callback) 359 | } 360 | 361 | if (window.JSON) $.parseJSON = JSON.parse 362 | 363 | // Populate the class2type map 364 | $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { 365 | class2type[ "[object " + name + "]" ] = name.toLowerCase() 366 | }) 367 | 368 | // Define methods that will be available on all 369 | // Zepto collections 370 | $.fn = { 371 | // Because a collection acts like an array 372 | // copy over these useful array functions. 373 | forEach: emptyArray.forEach, 374 | reduce: emptyArray.reduce, 375 | push: emptyArray.push, 376 | sort: emptyArray.sort, 377 | indexOf: emptyArray.indexOf, 378 | concat: emptyArray.concat, 379 | 380 | // `map` and `slice` in the jQuery API work differently 381 | // from their array counterparts 382 | map: function(fn){ 383 | return $($.map(this, function(el, i){ return fn.call(el, i, el) })) 384 | }, 385 | slice: function(){ 386 | return $(slice.apply(this, arguments)) 387 | }, 388 | 389 | ready: function(callback){ 390 | if (readyRE.test(document.readyState)) callback($) 391 | else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false) 392 | return this 393 | }, 394 | get: function(idx){ 395 | return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length] 396 | }, 397 | toArray: function(){ return this.get() }, 398 | size: function(){ 399 | return this.length 400 | }, 401 | remove: function(){ 402 | return this.each(function(){ 403 | if (this.parentNode != null) 404 | this.parentNode.removeChild(this) 405 | }) 406 | }, 407 | each: function(callback){ 408 | emptyArray.every.call(this, function(el, idx){ 409 | return callback.call(el, idx, el) !== false 410 | }) 411 | return this 412 | }, 413 | filter: function(selector){ 414 | if (isFunction(selector)) return this.not(this.not(selector)) 415 | return $(filter.call(this, function(element){ 416 | return zepto.matches(element, selector) 417 | })) 418 | }, 419 | add: function(selector,context){ 420 | return $(uniq(this.concat($(selector,context)))) 421 | }, 422 | is: function(selector){ 423 | return this.length > 0 && zepto.matches(this[0], selector) 424 | }, 425 | not: function(selector){ 426 | var nodes=[] 427 | if (isFunction(selector) && selector.call !== undefined) 428 | this.each(function(idx){ 429 | if (!selector.call(this,idx)) nodes.push(this) 430 | }) 431 | else { 432 | var excludes = typeof selector == 'string' ? this.filter(selector) : 433 | (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector) 434 | this.forEach(function(el){ 435 | if (excludes.indexOf(el) < 0) nodes.push(el) 436 | }) 437 | } 438 | return $(nodes) 439 | }, 440 | has: function(selector){ 441 | return this.filter(function(){ 442 | return isObject(selector) ? 443 | $.contains(this, selector) : 444 | $(this).find(selector).size() 445 | }) 446 | }, 447 | eq: function(idx){ 448 | return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1) 449 | }, 450 | first: function(){ 451 | var el = this[0] 452 | return el && !isObject(el) ? el : $(el) 453 | }, 454 | last: function(){ 455 | var el = this[this.length - 1] 456 | return el && !isObject(el) ? el : $(el) 457 | }, 458 | find: function(selector){ 459 | var result, $this = this 460 | if (typeof selector == 'object') 461 | result = $(selector).filter(function(){ 462 | var node = this 463 | return emptyArray.some.call($this, function(parent){ 464 | return $.contains(parent, node) 465 | }) 466 | }) 467 | else if (this.length == 1) result = $(zepto.qsa(this[0], selector)) 468 | else result = this.map(function(){ return zepto.qsa(this, selector) }) 469 | return result 470 | }, 471 | closest: function(selector, context){ 472 | var node = this[0], collection = false 473 | if (typeof selector == 'object') collection = $(selector) 474 | while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector))) 475 | node = node !== context && !isDocument(node) && node.parentNode 476 | return $(node) 477 | }, 478 | parents: function(selector){ 479 | var ancestors = [], nodes = this 480 | while (nodes.length > 0) 481 | nodes = $.map(nodes, function(node){ 482 | if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) { 483 | ancestors.push(node) 484 | return node 485 | } 486 | }) 487 | return filtered(ancestors, selector) 488 | }, 489 | parent: function(selector){ 490 | return filtered(uniq(this.pluck('parentNode')), selector) 491 | }, 492 | children: function(selector){ 493 | return filtered(this.map(function(){ return children(this) }), selector) 494 | }, 495 | contents: function() { 496 | return this.map(function() { return slice.call(this.childNodes) }) 497 | }, 498 | siblings: function(selector){ 499 | return filtered(this.map(function(i, el){ 500 | return filter.call(children(el.parentNode), function(child){ return child!==el }) 501 | }), selector) 502 | }, 503 | empty: function(){ 504 | return this.each(function(){ this.innerHTML = '' }) 505 | }, 506 | // `pluck` is borrowed from Prototype.js 507 | pluck: function(property){ 508 | return $.map(this, function(el){ return el[property] }) 509 | }, 510 | show: function(){ 511 | return this.each(function(){ 512 | this.style.display == "none" && (this.style.display = null) 513 | if (getComputedStyle(this, '').getPropertyValue("display") == "none") 514 | this.style.display = defaultDisplay(this.nodeName) 515 | }) 516 | }, 517 | replaceWith: function(newContent){ 518 | return this.before(newContent).remove() 519 | }, 520 | wrap: function(structure){ 521 | var func = isFunction(structure) 522 | if (this[0] && !func) 523 | var dom = $(structure).get(0), 524 | clone = dom.parentNode || this.length > 1 525 | 526 | return this.each(function(index){ 527 | $(this).wrapAll( 528 | func ? structure.call(this, index) : 529 | clone ? dom.cloneNode(true) : dom 530 | ) 531 | }) 532 | }, 533 | wrapAll: function(structure){ 534 | if (this[0]) { 535 | $(this[0]).before(structure = $(structure)) 536 | var children 537 | // drill down to the inmost element 538 | while ((children = structure.children()).length) structure = children.first() 539 | $(structure).append(this) 540 | } 541 | return this 542 | }, 543 | wrapInner: function(structure){ 544 | var func = isFunction(structure) 545 | return this.each(function(index){ 546 | var self = $(this), contents = self.contents(), 547 | dom = func ? structure.call(this, index) : structure 548 | contents.length ? contents.wrapAll(dom) : self.append(dom) 549 | }) 550 | }, 551 | unwrap: function(){ 552 | this.parent().each(function(){ 553 | $(this).replaceWith($(this).children()) 554 | }) 555 | return this 556 | }, 557 | clone: function(){ 558 | return this.map(function(){ return this.cloneNode(true) }) 559 | }, 560 | hide: function(){ 561 | return this.css("display", "none") 562 | }, 563 | toggle: function(setting){ 564 | return this.each(function(){ 565 | var el = $(this) 566 | ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide() 567 | }) 568 | }, 569 | prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') }, 570 | next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') }, 571 | html: function(html){ 572 | return html === undefined ? 573 | (this.length > 0 ? this[0].innerHTML : null) : 574 | this.each(function(idx){ 575 | var originHtml = this.innerHTML 576 | $(this).empty().append( funcArg(this, html, idx, originHtml) ) 577 | }) 578 | }, 579 | text: function(text){ 580 | return text === undefined ? 581 | (this.length > 0 ? this[0].textContent : null) : 582 | this.each(function(){ this.textContent = text }) 583 | }, 584 | attr: function(name, value){ 585 | var result 586 | return (typeof name == 'string' && value === undefined) ? 587 | (this.length == 0 || this[0].nodeType !== 1 ? undefined : 588 | (name == 'value' && this[0].nodeName == 'INPUT') ? this.val() : 589 | (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result 590 | ) : 591 | this.each(function(idx){ 592 | if (this.nodeType !== 1) return 593 | if (isObject(name)) for (key in name) setAttribute(this, key, name[key]) 594 | else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name))) 595 | }) 596 | }, 597 | removeAttr: function(name){ 598 | return this.each(function(){ this.nodeType === 1 && setAttribute(this, name) }) 599 | }, 600 | prop: function(name, value){ 601 | return (value === undefined) ? 602 | (this[0] && this[0][name]) : 603 | this.each(function(idx){ 604 | this[name] = funcArg(this, value, idx, this[name]) 605 | }) 606 | }, 607 | data: function(name, value){ 608 | var data = this.attr('data-' + dasherize(name), value) 609 | return data !== null ? deserializeValue(data) : undefined 610 | }, 611 | val: function(value){ 612 | return (value === undefined) ? 613 | (this[0] && (this[0].multiple ? 614 | $(this[0]).find('option').filter(function(o){ return this.selected }).pluck('value') : 615 | this[0].value) 616 | ) : 617 | this.each(function(idx){ 618 | this.value = funcArg(this, value, idx, this.value) 619 | }) 620 | }, 621 | offset: function(coordinates){ 622 | if (coordinates) return this.each(function(index){ 623 | var $this = $(this), 624 | coords = funcArg(this, coordinates, index, $this.offset()), 625 | parentOffset = $this.offsetParent().offset(), 626 | props = { 627 | top: coords.top - parentOffset.top, 628 | left: coords.left - parentOffset.left 629 | } 630 | 631 | if ($this.css('position') == 'static') props['position'] = 'relative' 632 | $this.css(props) 633 | }) 634 | if (this.length==0) return null 635 | var obj = this[0].getBoundingClientRect() 636 | return { 637 | left: obj.left + window.pageXOffset, 638 | top: obj.top + window.pageYOffset, 639 | width: Math.round(obj.width), 640 | height: Math.round(obj.height) 641 | } 642 | }, 643 | css: function(property, value){ 644 | if (arguments.length < 2 && typeof property == 'string') 645 | return this[0] && (this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property)) 646 | 647 | var css = '' 648 | if (type(property) == 'string') { 649 | if (!value && value !== 0) 650 | this.each(function(){ this.style.removeProperty(dasherize(property)) }) 651 | else 652 | css = dasherize(property) + ":" + maybeAddPx(property, value) 653 | } else { 654 | for (key in property) 655 | if (!property[key] && property[key] !== 0) 656 | this.each(function(){ this.style.removeProperty(dasherize(key)) }) 657 | else 658 | css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';' 659 | } 660 | 661 | return this.each(function(){ this.style.cssText += ';' + css }) 662 | }, 663 | index: function(element){ 664 | return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]) 665 | }, 666 | hasClass: function(name){ 667 | return emptyArray.some.call(this, function(el){ 668 | return this.test(className(el)) 669 | }, classRE(name)) 670 | }, 671 | addClass: function(name){ 672 | return this.each(function(idx){ 673 | classList = [] 674 | var cls = className(this), newName = funcArg(this, name, idx, cls) 675 | newName.split(/\s+/g).forEach(function(klass){ 676 | if (!$(this).hasClass(klass)) classList.push(klass) 677 | }, this) 678 | classList.length && className(this, cls + (cls ? " " : "") + classList.join(" ")) 679 | }) 680 | }, 681 | removeClass: function(name){ 682 | return this.each(function(idx){ 683 | if (name === undefined) return className(this, '') 684 | classList = className(this) 685 | funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){ 686 | classList = classList.replace(classRE(klass), " ") 687 | }) 688 | className(this, classList.trim()) 689 | }) 690 | }, 691 | toggleClass: function(name, when){ 692 | return this.each(function(idx){ 693 | var $this = $(this), names = funcArg(this, name, idx, className(this)) 694 | names.split(/\s+/g).forEach(function(klass){ 695 | (when === undefined ? !$this.hasClass(klass) : when) ? 696 | $this.addClass(klass) : $this.removeClass(klass) 697 | }) 698 | }) 699 | }, 700 | scrollTop: function(){ 701 | if (!this.length) return 702 | return ('scrollTop' in this[0]) ? this[0].scrollTop : this[0].scrollY 703 | }, 704 | position: function() { 705 | if (!this.length) return 706 | 707 | var elem = this[0], 708 | // Get *real* offsetParent 709 | offsetParent = this.offsetParent(), 710 | // Get correct offsets 711 | offset = this.offset(), 712 | parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset() 713 | 714 | // Subtract element margins 715 | // note: when an element has margin: auto the offsetLeft and marginLeft 716 | // are the same in Safari causing offset.left to incorrectly be 0 717 | offset.top -= parseFloat( $(elem).css('margin-top') ) || 0 718 | offset.left -= parseFloat( $(elem).css('margin-left') ) || 0 719 | 720 | // Add offsetParent borders 721 | parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0 722 | parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0 723 | 724 | // Subtract the two offsets 725 | return { 726 | top: offset.top - parentOffset.top, 727 | left: offset.left - parentOffset.left 728 | } 729 | }, 730 | offsetParent: function() { 731 | return this.map(function(){ 732 | var parent = this.offsetParent || document.body 733 | while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static") 734 | parent = parent.offsetParent 735 | return parent 736 | }) 737 | } 738 | } 739 | 740 | // for now 741 | $.fn.detach = $.fn.remove 742 | 743 | // Generate the `width` and `height` functions 744 | ;['width', 'height'].forEach(function(dimension){ 745 | $.fn[dimension] = function(value){ 746 | var offset, el = this[0], 747 | Dimension = dimension.replace(/./, function(m){ return m[0].toUpperCase() }) 748 | if (value === undefined) return isWindow(el) ? el['inner' + Dimension] : 749 | isDocument(el) ? el.documentElement['offset' + Dimension] : 750 | (offset = this.offset()) && offset[dimension] 751 | else return this.each(function(idx){ 752 | el = $(this) 753 | el.css(dimension, funcArg(this, value, idx, el[dimension]())) 754 | }) 755 | } 756 | }) 757 | 758 | function traverseNode(node, fun) { 759 | fun(node) 760 | for (var key in node.childNodes) traverseNode(node.childNodes[key], fun) 761 | } 762 | 763 | // Generate the `after`, `prepend`, `before`, `append`, 764 | // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods. 765 | adjacencyOperators.forEach(function(operator, operatorIndex) { 766 | var inside = operatorIndex % 2 //=> prepend, append 767 | 768 | $.fn[operator] = function(){ 769 | // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings 770 | var argType, nodes = $.map(arguments, function(arg) { 771 | argType = type(arg) 772 | return argType == "object" || argType == "array" || arg == null ? 773 | arg : zepto.fragment(arg) 774 | }), 775 | parent, copyByClone = this.length > 1 776 | if (nodes.length < 1) return this 777 | 778 | return this.each(function(_, target){ 779 | parent = inside ? target : target.parentNode 780 | 781 | // convert all methods to a "before" operation 782 | target = operatorIndex == 0 ? target.nextSibling : 783 | operatorIndex == 1 ? target.firstChild : 784 | operatorIndex == 2 ? target : 785 | null 786 | 787 | nodes.forEach(function(node){ 788 | if (copyByClone) node = node.cloneNode(true) 789 | else if (!parent) return $(node).remove() 790 | 791 | traverseNode(parent.insertBefore(node, target), function(el){ 792 | if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && 793 | (!el.type || el.type === 'text/javascript') && !el.src) 794 | window['eval'].call(window, el.innerHTML) 795 | }) 796 | }) 797 | }) 798 | } 799 | 800 | // after => insertAfter 801 | // prepend => prependTo 802 | // before => insertBefore 803 | // append => appendTo 804 | $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){ 805 | $(html)[operator](this) 806 | return this 807 | } 808 | }) 809 | 810 | zepto.Z.prototype = $.fn 811 | 812 | // Export internal API functions in the `$.zepto` namespace 813 | zepto.uniq = uniq 814 | zepto.deserializeValue = deserializeValue 815 | $.zepto = zepto 816 | 817 | return $ 818 | })() 819 | 820 | window.Zepto = Zepto 821 | '$' in window || (window.$ = Zepto) 822 | 823 | ;(function($){ 824 | function detect(ua){ 825 | var os = this.os = {}, browser = this.browser = {}, 826 | webkit = ua.match(/WebKit\/([\d.]+)/), 827 | android = ua.match(/(Android)\s+([\d.]+)/), 828 | ipad = ua.match(/(iPad).*OS\s([\d_]+)/), 829 | iphone = !ipad && ua.match(/(iPhone\sOS)\s([\d_]+)/), 830 | webos = ua.match(/(webOS|hpwOS)[\s\/]([\d.]+)/), 831 | touchpad = webos && ua.match(/TouchPad/), 832 | kindle = ua.match(/Kindle\/([\d.]+)/), 833 | silk = ua.match(/Silk\/([\d._]+)/), 834 | blackberry = ua.match(/(BlackBerry).*Version\/([\d.]+)/), 835 | bb10 = ua.match(/(BB10).*Version\/([\d.]+)/), 836 | rimtabletos = ua.match(/(RIM\sTablet\sOS)\s([\d.]+)/), 837 | playbook = ua.match(/PlayBook/), 838 | chrome = ua.match(/Chrome\/([\d.]+)/) || ua.match(/CriOS\/([\d.]+)/), 839 | firefox = ua.match(/Firefox\/([\d.]+)/) 840 | 841 | // Todo: clean this up with a better OS/browser seperation: 842 | // - discern (more) between multiple browsers on android 843 | // - decide if kindle fire in silk mode is android or not 844 | // - Firefox on Android doesn't specify the Android version 845 | // - possibly devide in os, device and browser hashes 846 | 847 | if (browser.webkit = !!webkit) browser.version = webkit[1] 848 | 849 | if (android) os.android = true, os.version = android[2] 850 | if (iphone) os.ios = os.iphone = true, os.version = iphone[2].replace(/_/g, '.') 851 | if (ipad) os.ios = os.ipad = true, os.version = ipad[2].replace(/_/g, '.') 852 | if (webos) os.webos = true, os.version = webos[2] 853 | if (touchpad) os.touchpad = true 854 | if (blackberry) os.blackberry = true, os.version = blackberry[2] 855 | if (bb10) os.bb10 = true, os.version = bb10[2] 856 | if (rimtabletos) os.rimtabletos = true, os.version = rimtabletos[2] 857 | if (playbook) browser.playbook = true 858 | if (kindle) os.kindle = true, os.version = kindle[1] 859 | if (silk) browser.silk = true, browser.version = silk[1] 860 | if (!silk && os.android && ua.match(/Kindle Fire/)) browser.silk = true 861 | if (chrome) browser.chrome = true, browser.version = chrome[1] 862 | if (firefox) browser.firefox = true, browser.version = firefox[1] 863 | 864 | os.tablet = !!(ipad || playbook || (android && !ua.match(/Mobile/)) || (firefox && ua.match(/Tablet/))) 865 | os.phone = !!(!os.tablet && (android || iphone || webos || blackberry || bb10 || 866 | (chrome && ua.match(/Android/)) || (chrome && ua.match(/CriOS\/([\d.]+)/)) || (firefox && ua.match(/Mobile/)))) 867 | } 868 | 869 | detect.call($, navigator.userAgent) 870 | // make available to unit tests 871 | $.__detect = detect 872 | 873 | })(Zepto) 874 | 875 | ;(function($){ 876 | var $$ = $.zepto.qsa, handlers = {}, _zid = 1, specialEvents={}, 877 | hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' } 878 | 879 | specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents' 880 | 881 | function zid(element) { 882 | return element._zid || (element._zid = _zid++) 883 | } 884 | function findHandlers(element, event, fn, selector) { 885 | event = parse(event) 886 | if (event.ns) var matcher = matcherFor(event.ns) 887 | return (handlers[zid(element)] || []).filter(function(handler) { 888 | return handler 889 | && (!event.e || handler.e == event.e) 890 | && (!event.ns || matcher.test(handler.ns)) 891 | && (!fn || zid(handler.fn) === zid(fn)) 892 | && (!selector || handler.sel == selector) 893 | }) 894 | } 895 | function parse(event) { 896 | var parts = ('' + event).split('.') 897 | return {e: parts[0], ns: parts.slice(1).sort().join(' ')} 898 | } 899 | function matcherFor(ns) { 900 | return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') 901 | } 902 | 903 | function eachEvent(events, fn, iterator){ 904 | if ($.type(events) != "string") $.each(events, iterator) 905 | else events.split(/\s/).forEach(function(type){ iterator(type, fn) }) 906 | } 907 | 908 | function eventCapture(handler, captureSetting) { 909 | return handler.del && 910 | (handler.e == 'focus' || handler.e == 'blur') || 911 | !!captureSetting 912 | } 913 | 914 | function realEvent(type) { 915 | return hover[type] || type 916 | } 917 | 918 | function add(element, events, fn, selector, getDelegate, capture){ 919 | var id = zid(element), set = (handlers[id] || (handlers[id] = [])) 920 | eachEvent(events, fn, function(event, fn){ 921 | var handler = parse(event) 922 | handler.fn = fn 923 | handler.sel = selector 924 | // emulate mouseenter, mouseleave 925 | if (handler.e in hover) fn = function(e){ 926 | var related = e.relatedTarget 927 | if (!related || (related !== this && !$.contains(this, related))) 928 | return handler.fn.apply(this, arguments) 929 | } 930 | handler.del = getDelegate && getDelegate(fn, event) 931 | var callback = handler.del || fn 932 | handler.proxy = function (e) { 933 | var result = callback.apply(element, [e].concat(e.data)) 934 | if (result === false) e.preventDefault(), e.stopPropagation() 935 | return result 936 | } 937 | handler.i = set.length 938 | set.push(handler) 939 | element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 940 | }) 941 | } 942 | function remove(element, events, fn, selector, capture){ 943 | var id = zid(element) 944 | eachEvent(events || '', fn, function(event, fn){ 945 | findHandlers(element, event, fn, selector).forEach(function(handler){ 946 | delete handlers[id][handler.i] 947 | element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 948 | }) 949 | }) 950 | } 951 | 952 | $.event = { add: add, remove: remove } 953 | 954 | $.proxy = function(fn, context) { 955 | if ($.isFunction(fn)) { 956 | var proxyFn = function(){ return fn.apply(context, arguments) } 957 | proxyFn._zid = zid(fn) 958 | return proxyFn 959 | } else if (typeof context == 'string') { 960 | return $.proxy(fn[context], fn) 961 | } else { 962 | throw new TypeError("expected function") 963 | } 964 | } 965 | 966 | $.fn.bind = function(event, callback){ 967 | return this.each(function(){ 968 | add(this, event, callback) 969 | }) 970 | } 971 | $.fn.unbind = function(event, callback){ 972 | return this.each(function(){ 973 | remove(this, event, callback) 974 | }) 975 | } 976 | $.fn.one = function(event, callback){ 977 | return this.each(function(i, element){ 978 | add(this, event, callback, null, function(fn, type){ 979 | return function(){ 980 | var result = fn.apply(element, arguments) 981 | remove(element, type, fn) 982 | return result 983 | } 984 | }) 985 | }) 986 | } 987 | 988 | var returnTrue = function(){return true}, 989 | returnFalse = function(){return false}, 990 | ignoreProperties = /^([A-Z]|layer[XY]$)/, 991 | eventMethods = { 992 | preventDefault: 'isDefaultPrevented', 993 | stopImmediatePropagation: 'isImmediatePropagationStopped', 994 | stopPropagation: 'isPropagationStopped' 995 | } 996 | function createProxy(event) { 997 | var key, proxy = { originalEvent: event } 998 | for (key in event) 999 | if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key] 1000 | 1001 | $.each(eventMethods, function(name, predicate) { 1002 | proxy[name] = function(){ 1003 | this[predicate] = returnTrue 1004 | return event[name].apply(event, arguments) 1005 | } 1006 | proxy[predicate] = returnFalse 1007 | }) 1008 | return proxy 1009 | } 1010 | 1011 | // emulates the 'defaultPrevented' property for browsers that have none 1012 | function fix(event) { 1013 | if (!('defaultPrevented' in event)) { 1014 | event.defaultPrevented = false 1015 | var prevent = event.preventDefault 1016 | event.preventDefault = function() { 1017 | this.defaultPrevented = true 1018 | prevent.call(this) 1019 | } 1020 | } 1021 | } 1022 | 1023 | $.fn.delegate = function(selector, event, callback){ 1024 | return this.each(function(i, element){ 1025 | add(element, event, callback, selector, function(fn){ 1026 | return function(e){ 1027 | var evt, match = $(e.target).closest(selector, element).get(0) 1028 | if (match) { 1029 | evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element}) 1030 | return fn.apply(match, [evt].concat([].slice.call(arguments, 1))) 1031 | } 1032 | } 1033 | }) 1034 | }) 1035 | } 1036 | $.fn.undelegate = function(selector, event, callback){ 1037 | return this.each(function(){ 1038 | remove(this, event, callback, selector) 1039 | }) 1040 | } 1041 | 1042 | $.fn.live = function(event, callback){ 1043 | $(document.body).delegate(this.selector, event, callback) 1044 | return this 1045 | } 1046 | $.fn.die = function(event, callback){ 1047 | $(document.body).undelegate(this.selector, event, callback) 1048 | return this 1049 | } 1050 | 1051 | $.fn.on = function(event, selector, callback){ 1052 | return !selector || $.isFunction(selector) ? 1053 | this.bind(event, selector || callback) : this.delegate(selector, event, callback) 1054 | } 1055 | $.fn.off = function(event, selector, callback){ 1056 | return !selector || $.isFunction(selector) ? 1057 | this.unbind(event, selector || callback) : this.undelegate(selector, event, callback) 1058 | } 1059 | 1060 | $.fn.trigger = function(event, data){ 1061 | if (typeof event == 'string' || $.isPlainObject(event)) event = $.Event(event) 1062 | fix(event) 1063 | event.data = data 1064 | return this.each(function(){ 1065 | // items in the collection might not be DOM elements 1066 | // (todo: possibly support events on plain old objects) 1067 | if('dispatchEvent' in this) this.dispatchEvent(event) 1068 | }) 1069 | } 1070 | 1071 | // triggers event handlers on current element just as if an event occurred, 1072 | // doesn't trigger an actual event, doesn't bubble 1073 | $.fn.triggerHandler = function(event, data){ 1074 | var e, result 1075 | this.each(function(i, element){ 1076 | e = createProxy(typeof event == 'string' ? $.Event(event) : event) 1077 | e.data = data 1078 | e.target = element 1079 | $.each(findHandlers(element, event.type || event), function(i, handler){ 1080 | result = handler.proxy(e) 1081 | if (e.isImmediatePropagationStopped()) return false 1082 | }) 1083 | }) 1084 | return result 1085 | } 1086 | 1087 | // shortcut methods for `.bind(event, fn)` for each event type 1088 | ;('focusin focusout load resize scroll unload click dblclick '+ 1089 | 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+ 1090 | 'change select keydown keypress keyup error').split(' ').forEach(function(event) { 1091 | $.fn[event] = function(callback) { 1092 | return callback ? 1093 | this.bind(event, callback) : 1094 | this.trigger(event) 1095 | } 1096 | }) 1097 | 1098 | ;['focus', 'blur'].forEach(function(name) { 1099 | $.fn[name] = function(callback) { 1100 | if (callback) this.bind(name, callback) 1101 | else this.each(function(){ 1102 | try { this[name]() } 1103 | catch(e) {} 1104 | }) 1105 | return this 1106 | } 1107 | }) 1108 | 1109 | $.Event = function(type, props) { 1110 | if (typeof type != 'string') props = type, type = props.type 1111 | var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true 1112 | if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) 1113 | event.initEvent(type, bubbles, true, null, null, null, null, null, null, null, null, null, null, null, null) 1114 | event.isDefaultPrevented = function(){ return this.defaultPrevented } 1115 | return event 1116 | } 1117 | 1118 | })(Zepto) 1119 | 1120 | ;(function($){ 1121 | var jsonpID = 0, 1122 | document = window.document, 1123 | key, 1124 | name, 1125 | rscript = /)<[^<]*)*<\/script>/gi, 1126 | scriptTypeRE = /^(?:text|application)\/javascript/i, 1127 | xmlTypeRE = /^(?:text|application)\/xml/i, 1128 | jsonType = 'application/json', 1129 | htmlType = 'text/html', 1130 | blankRE = /^\s*$/ 1131 | 1132 | // trigger a custom event and return false if it was cancelled 1133 | function triggerAndReturn(context, eventName, data) { 1134 | var event = $.Event(eventName) 1135 | $(context).trigger(event, data) 1136 | return !event.defaultPrevented 1137 | } 1138 | 1139 | // trigger an Ajax "global" event 1140 | function triggerGlobal(settings, context, eventName, data) { 1141 | if (settings.global) return triggerAndReturn(context || document, eventName, data) 1142 | } 1143 | 1144 | // Number of active Ajax requests 1145 | $.active = 0 1146 | 1147 | function ajaxStart(settings) { 1148 | if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart') 1149 | } 1150 | function ajaxStop(settings) { 1151 | if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop') 1152 | } 1153 | 1154 | // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable 1155 | function ajaxBeforeSend(xhr, settings) { 1156 | var context = settings.context 1157 | if (settings.beforeSend.call(context, xhr, settings) === false || 1158 | triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false) 1159 | return false 1160 | 1161 | triggerGlobal(settings, context, 'ajaxSend', [xhr, settings]) 1162 | } 1163 | function ajaxSuccess(data, xhr, settings) { 1164 | var context = settings.context, status = 'success' 1165 | settings.success.call(context, data, status, xhr) 1166 | triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data]) 1167 | ajaxComplete(status, xhr, settings) 1168 | } 1169 | // type: "timeout", "error", "abort", "parsererror" 1170 | function ajaxError(error, type, xhr, settings) { 1171 | var context = settings.context 1172 | settings.error.call(context, xhr, type, error) 1173 | triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error]) 1174 | ajaxComplete(type, xhr, settings) 1175 | } 1176 | // status: "success", "notmodified", "error", "timeout", "abort", "parsererror" 1177 | function ajaxComplete(status, xhr, settings) { 1178 | var context = settings.context 1179 | settings.complete.call(context, xhr, status) 1180 | triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings]) 1181 | ajaxStop(settings) 1182 | } 1183 | 1184 | // Empty function, used as default callback 1185 | function empty() {} 1186 | 1187 | $.ajaxJSONP = function(options){ 1188 | if (!('type' in options)) return $.ajax(options) 1189 | 1190 | var callbackName = 'jsonp' + (++jsonpID), 1191 | script = document.createElement('script'), 1192 | cleanup = function() { 1193 | clearTimeout(abortTimeout) 1194 | $(script).remove() 1195 | delete window[callbackName] 1196 | }, 1197 | abort = function(type){ 1198 | cleanup() 1199 | // In case of manual abort or timeout, keep an empty function as callback 1200 | // so that the SCRIPT tag that eventually loads won't result in an error. 1201 | if (!type || type == 'timeout') window[callbackName] = empty 1202 | ajaxError(null, type || 'abort', xhr, options) 1203 | }, 1204 | xhr = { abort: abort }, abortTimeout 1205 | 1206 | if (ajaxBeforeSend(xhr, options) === false) { 1207 | abort('abort') 1208 | return false 1209 | } 1210 | 1211 | window[callbackName] = function(data){ 1212 | cleanup() 1213 | ajaxSuccess(data, xhr, options) 1214 | } 1215 | 1216 | script.onerror = function() { abort('error') } 1217 | 1218 | script.src = options.url.replace(/=\?/, '=' + callbackName) 1219 | $('head').append(script) 1220 | 1221 | if (options.timeout > 0) abortTimeout = setTimeout(function(){ 1222 | abort('timeout') 1223 | }, options.timeout) 1224 | 1225 | return xhr 1226 | } 1227 | 1228 | $.ajaxSettings = { 1229 | // Default type of request 1230 | type: 'GET', 1231 | // Callback that is executed before request 1232 | beforeSend: empty, 1233 | // Callback that is executed if the request succeeds 1234 | success: empty, 1235 | // Callback that is executed the the server drops error 1236 | error: empty, 1237 | // Callback that is executed on request complete (both: error and success) 1238 | complete: empty, 1239 | // The context for the callbacks 1240 | context: null, 1241 | // Whether to trigger "global" Ajax events 1242 | global: true, 1243 | // Transport 1244 | xhr: function () { 1245 | return new window.XMLHttpRequest() 1246 | }, 1247 | // MIME types mapping 1248 | accepts: { 1249 | script: 'text/javascript, application/javascript', 1250 | json: jsonType, 1251 | xml: 'application/xml, text/xml', 1252 | html: htmlType, 1253 | text: 'text/plain' 1254 | }, 1255 | // Whether the request is to another domain 1256 | crossDomain: false, 1257 | // Default timeout 1258 | timeout: 0, 1259 | // Whether data should be serialized to string 1260 | processData: true, 1261 | // Whether the browser should be allowed to cache GET responses 1262 | cache: true, 1263 | } 1264 | 1265 | function mimeToDataType(mime) { 1266 | if (mime) mime = mime.split(';', 2)[0] 1267 | return mime && ( mime == htmlType ? 'html' : 1268 | mime == jsonType ? 'json' : 1269 | scriptTypeRE.test(mime) ? 'script' : 1270 | xmlTypeRE.test(mime) && 'xml' ) || 'text' 1271 | } 1272 | 1273 | function appendQuery(url, query) { 1274 | return (url + '&' + query).replace(/[&?]{1,2}/, '?') 1275 | } 1276 | 1277 | // serialize payload and append it to the URL for GET requests 1278 | function serializeData(options) { 1279 | if (options.processData && options.data && $.type(options.data) != "string") 1280 | options.data = $.param(options.data, options.traditional) 1281 | if (options.data && (!options.type || options.type.toUpperCase() == 'GET')) 1282 | options.url = appendQuery(options.url, options.data) 1283 | } 1284 | 1285 | $.ajax = function(options){ 1286 | var settings = $.extend({}, options || {}) 1287 | for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key] 1288 | 1289 | ajaxStart(settings) 1290 | 1291 | if (!settings.crossDomain) settings.crossDomain = /^([\w-]+:)?\/\/([^\/]+)/.test(settings.url) && 1292 | RegExp.$2 != window.location.host 1293 | 1294 | if (!settings.url) settings.url = window.location.toString() 1295 | serializeData(settings) 1296 | if (settings.cache === false) settings.url = appendQuery(settings.url, '_=' + Date.now()) 1297 | 1298 | var dataType = settings.dataType, hasPlaceholder = /=\?/.test(settings.url) 1299 | if (dataType == 'jsonp' || hasPlaceholder) { 1300 | if (!hasPlaceholder) settings.url = appendQuery(settings.url, 'callback=?') 1301 | return $.ajaxJSONP(settings) 1302 | } 1303 | 1304 | var mime = settings.accepts[dataType], 1305 | baseHeaders = { }, 1306 | protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol, 1307 | xhr = settings.xhr(), abortTimeout 1308 | 1309 | if (!settings.crossDomain) baseHeaders['X-Requested-With'] = 'XMLHttpRequest' 1310 | if (mime) { 1311 | baseHeaders['Accept'] = mime 1312 | if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0] 1313 | xhr.overrideMimeType && xhr.overrideMimeType(mime) 1314 | } 1315 | if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET')) 1316 | baseHeaders['Content-Type'] = (settings.contentType || 'application/x-www-form-urlencoded') 1317 | settings.headers = $.extend(baseHeaders, settings.headers || {}) 1318 | 1319 | xhr.onreadystatechange = function(){ 1320 | if (xhr.readyState == 4) { 1321 | xhr.onreadystatechange = empty; 1322 | clearTimeout(abortTimeout) 1323 | var result, error = false 1324 | if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) { 1325 | dataType = dataType || mimeToDataType(xhr.getResponseHeader('content-type')) 1326 | result = xhr.responseText 1327 | 1328 | try { 1329 | // http://perfectionkills.com/global-eval-what-are-the-options/ 1330 | if (dataType == 'script') (1,eval)(result) 1331 | else if (dataType == 'xml') result = xhr.responseXML 1332 | else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result) 1333 | } catch (e) { error = e } 1334 | 1335 | if (error) ajaxError(error, 'parsererror', xhr, settings) 1336 | else ajaxSuccess(result, xhr, settings) 1337 | } else { 1338 | ajaxError(null, xhr.status ? 'error' : 'abort', xhr, settings) 1339 | } 1340 | } 1341 | } 1342 | 1343 | var async = 'async' in settings ? settings.async : true 1344 | xhr.open(settings.type, settings.url, async) 1345 | 1346 | for (name in settings.headers) xhr.setRequestHeader(name, settings.headers[name]) 1347 | 1348 | if (ajaxBeforeSend(xhr, settings) === false) { 1349 | xhr.abort() 1350 | return false 1351 | } 1352 | 1353 | if (settings.timeout > 0) abortTimeout = setTimeout(function(){ 1354 | xhr.onreadystatechange = empty 1355 | xhr.abort() 1356 | ajaxError(null, 'timeout', xhr, settings) 1357 | }, settings.timeout) 1358 | 1359 | // avoid sending empty string (#319) 1360 | xhr.send(settings.data ? settings.data : null) 1361 | return xhr 1362 | } 1363 | 1364 | // handle optional data/success arguments 1365 | function parseArguments(url, data, success, dataType) { 1366 | var hasData = !$.isFunction(data) 1367 | return { 1368 | url: url, 1369 | data: hasData ? data : undefined, 1370 | success: !hasData ? data : $.isFunction(success) ? success : undefined, 1371 | dataType: hasData ? dataType || success : success 1372 | } 1373 | } 1374 | 1375 | $.get = function(url, data, success, dataType){ 1376 | return $.ajax(parseArguments.apply(null, arguments)) 1377 | } 1378 | 1379 | $.post = function(url, data, success, dataType){ 1380 | var options = parseArguments.apply(null, arguments) 1381 | options.type = 'POST' 1382 | return $.ajax(options) 1383 | } 1384 | 1385 | $.getJSON = function(url, data, success){ 1386 | var options = parseArguments.apply(null, arguments) 1387 | options.dataType = 'json' 1388 | return $.ajax(options) 1389 | } 1390 | 1391 | $.fn.load = function(url, data, success){ 1392 | if (!this.length) return this 1393 | var self = this, parts = url.split(/\s/), selector, 1394 | options = parseArguments(url, data, success), 1395 | callback = options.success 1396 | if (parts.length > 1) options.url = parts[0], selector = parts[1] 1397 | options.success = function(response){ 1398 | self.html(selector ? 1399 | $('
').html(response.replace(rscript, "")).find(selector) 1400 | : response) 1401 | callback && callback.apply(self, arguments) 1402 | } 1403 | $.ajax(options) 1404 | return this 1405 | } 1406 | 1407 | var escape = encodeURIComponent 1408 | 1409 | function serialize(params, obj, traditional, scope){ 1410 | var type, array = $.isArray(obj) 1411 | $.each(obj, function(key, value) { 1412 | type = $.type(value) 1413 | if (scope) key = traditional ? scope : scope + '[' + (array ? '' : key) + ']' 1414 | // handle data in serializeArray() format 1415 | if (!scope && array) params.add(value.name, value.value) 1416 | // recurse into nested objects 1417 | else if (type == "array" || (!traditional && type == "object")) 1418 | serialize(params, value, traditional, key) 1419 | else params.add(key, value) 1420 | }) 1421 | } 1422 | 1423 | $.param = function(obj, traditional){ 1424 | var params = [] 1425 | params.add = function(k, v){ this.push(escape(k) + '=' + escape(v)) } 1426 | serialize(params, obj, traditional) 1427 | return params.join('&').replace(/%20/g, '+') 1428 | } 1429 | })(Zepto) 1430 | 1431 | ;(function ($) { 1432 | $.fn.serializeArray = function () { 1433 | var result = [], el 1434 | $( Array.prototype.slice.call(this.get(0).elements) ).each(function () { 1435 | el = $(this) 1436 | var type = el.attr('type') 1437 | if (this.nodeName.toLowerCase() != 'fieldset' && 1438 | !this.disabled && type != 'submit' && type != 'reset' && type != 'button' && 1439 | ((type != 'radio' && type != 'checkbox') || this.checked)) 1440 | result.push({ 1441 | name: el.attr('name'), 1442 | value: el.val() 1443 | }) 1444 | }) 1445 | return result 1446 | } 1447 | 1448 | $.fn.serialize = function () { 1449 | var result = [] 1450 | this.serializeArray().forEach(function (elm) { 1451 | result.push( encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value) ) 1452 | }) 1453 | return result.join('&') 1454 | } 1455 | 1456 | $.fn.submit = function (callback) { 1457 | if (callback) this.bind('submit', callback) 1458 | else if (this.length) { 1459 | var event = $.Event('submit') 1460 | this.eq(0).trigger(event) 1461 | if (!event.defaultPrevented) this.get(0).submit() 1462 | } 1463 | return this 1464 | } 1465 | 1466 | })(Zepto) 1467 | 1468 | ;(function($, undefined){ 1469 | var prefix = '', eventPrefix, endEventName, endAnimationName, 1470 | vendors = { Webkit: 'webkit', Moz: '', O: 'o', ms: 'MS' }, 1471 | document = window.document, testEl = document.createElement('div'), 1472 | supportedTransforms = /^((translate|rotate|scale)(X|Y|Z|3d)?|matrix(3d)?|perspective|skew(X|Y)?)$/i, 1473 | transform, 1474 | transitionProperty, transitionDuration, transitionTiming, 1475 | animationName, animationDuration, animationTiming, 1476 | cssReset = {} 1477 | 1478 | function dasherize(str) { return downcase(str.replace(/([a-z])([A-Z])/, '$1-$2')) } 1479 | function downcase(str) { return str.toLowerCase() } 1480 | function normalizeEvent(name) { return eventPrefix ? eventPrefix + name : downcase(name) } 1481 | 1482 | $.each(vendors, function(vendor, event){ 1483 | if (testEl.style[vendor + 'TransitionProperty'] !== undefined) { 1484 | prefix = '-' + downcase(vendor) + '-' 1485 | eventPrefix = event 1486 | return false 1487 | } 1488 | }) 1489 | 1490 | transform = prefix + 'transform' 1491 | cssReset[transitionProperty = prefix + 'transition-property'] = 1492 | cssReset[transitionDuration = prefix + 'transition-duration'] = 1493 | cssReset[transitionTiming = prefix + 'transition-timing-function'] = 1494 | cssReset[animationName = prefix + 'animation-name'] = 1495 | cssReset[animationDuration = prefix + 'animation-duration'] = 1496 | cssReset[animationTiming = prefix + 'animation-timing-function'] = '' 1497 | 1498 | $.fx = { 1499 | off: (eventPrefix === undefined && testEl.style.transitionProperty === undefined), 1500 | speeds: { _default: 400, fast: 200, slow: 600 }, 1501 | cssPrefix: prefix, 1502 | transitionEnd: normalizeEvent('TransitionEnd'), 1503 | animationEnd: normalizeEvent('AnimationEnd') 1504 | } 1505 | 1506 | $.fn.animate = function(properties, duration, ease, callback){ 1507 | if ($.isPlainObject(duration)) 1508 | ease = duration.easing, callback = duration.complete, duration = duration.duration 1509 | if (duration) duration = (typeof duration == 'number' ? duration : 1510 | ($.fx.speeds[duration] || $.fx.speeds._default)) / 1000 1511 | return this.anim(properties, duration, ease, callback) 1512 | } 1513 | 1514 | $.fn.anim = function(properties, duration, ease, callback){ 1515 | var key, cssValues = {}, cssProperties, transforms = '', 1516 | that = this, wrappedCallback, endEvent = $.fx.transitionEnd 1517 | 1518 | if (duration === undefined) duration = 0.4 1519 | if ($.fx.off) duration = 0 1520 | 1521 | if (typeof properties == 'string') { 1522 | // keyframe animation 1523 | cssValues[animationName] = properties 1524 | cssValues[animationDuration] = duration + 's' 1525 | cssValues[animationTiming] = (ease || 'linear') 1526 | endEvent = $.fx.animationEnd 1527 | } else { 1528 | cssProperties = [] 1529 | // CSS transitions 1530 | for (key in properties) 1531 | if (supportedTransforms.test(key)) transforms += key + '(' + properties[key] + ') ' 1532 | else cssValues[key] = properties[key], cssProperties.push(dasherize(key)) 1533 | 1534 | if (transforms) cssValues[transform] = transforms, cssProperties.push(transform) 1535 | if (duration > 0 && typeof properties === 'object') { 1536 | cssValues[transitionProperty] = cssProperties.join(', ') 1537 | cssValues[transitionDuration] = duration + 's' 1538 | cssValues[transitionTiming] = (ease || 'linear') 1539 | } 1540 | } 1541 | 1542 | wrappedCallback = function(event){ 1543 | if (typeof event !== 'undefined') { 1544 | if (event.target !== event.currentTarget) return // makes sure the event didn't bubble from "below" 1545 | $(event.target).unbind(endEvent, wrappedCallback) 1546 | } 1547 | $(this).css(cssReset) 1548 | callback && callback.call(this) 1549 | } 1550 | if (duration > 0) this.bind(endEvent, wrappedCallback) 1551 | 1552 | // trigger page reflow so new elements can animate 1553 | this.size() && this.get(0).clientLeft 1554 | 1555 | this.css(cssValues) 1556 | 1557 | if (duration <= 0) setTimeout(function() { 1558 | that.each(function(){ wrappedCallback.call(this) }) 1559 | }, 0) 1560 | 1561 | return this 1562 | } 1563 | 1564 | testEl = null 1565 | })(Zepto) 1566 | -------------------------------------------------------------------------------- /vendor/zepto-1.1.6.js: -------------------------------------------------------------------------------- 1 | /* Zepto v1.1.6 - zepto event ajax form ie - zeptojs.com/license */ 2 | 3 | var Zepto = (function() { 4 | var undefined, key, $, classList, emptyArray = [], slice = emptyArray.slice, filter = emptyArray.filter, 5 | document = window.document, 6 | elementDisplay = {}, classCache = {}, 7 | cssNumber = { 'column-count': 1, 'columns': 1, 'font-weight': 1, 'line-height': 1,'opacity': 1, 'z-index': 1, 'zoom': 1 }, 8 | fragmentRE = /^\s*<(\w+|!)[^>]*>/, 9 | singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/, 10 | tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, 11 | rootNodeRE = /^(?:body|html)$/i, 12 | capitalRE = /([A-Z])/g, 13 | 14 | // special attributes that should be get/set via method calls 15 | methodAttributes = ['val', 'css', 'html', 'text', 'data', 'width', 'height', 'offset'], 16 | 17 | adjacencyOperators = [ 'after', 'prepend', 'before', 'append' ], 18 | table = document.createElement('table'), 19 | tableRow = document.createElement('tr'), 20 | containers = { 21 | 'tr': document.createElement('tbody'), 22 | 'tbody': table, 'thead': table, 'tfoot': table, 23 | 'td': tableRow, 'th': tableRow, 24 | '*': document.createElement('div') 25 | }, 26 | readyRE = /complete|loaded|interactive/, 27 | simpleSelectorRE = /^[\w-]*$/, 28 | class2type = {}, 29 | toString = class2type.toString, 30 | zepto = {}, 31 | camelize, uniq, 32 | tempParent = document.createElement('div'), 33 | propMap = { 34 | 'tabindex': 'tabIndex', 35 | 'readonly': 'readOnly', 36 | 'for': 'htmlFor', 37 | 'class': 'className', 38 | 'maxlength': 'maxLength', 39 | 'cellspacing': 'cellSpacing', 40 | 'cellpadding': 'cellPadding', 41 | 'rowspan': 'rowSpan', 42 | 'colspan': 'colSpan', 43 | 'usemap': 'useMap', 44 | 'frameborder': 'frameBorder', 45 | 'contenteditable': 'contentEditable' 46 | }, 47 | isArray = Array.isArray || 48 | function(object){ return object instanceof Array } 49 | 50 | zepto.matches = function(element, selector) { 51 | if (!selector || !element || element.nodeType !== 1) return false 52 | var matchesSelector = element.webkitMatchesSelector || element.mozMatchesSelector || 53 | element.oMatchesSelector || element.matchesSelector 54 | if (matchesSelector) return matchesSelector.call(element, selector) 55 | // fall back to performing a selector: 56 | var match, parent = element.parentNode, temp = !parent 57 | if (temp) (parent = tempParent).appendChild(element) 58 | match = ~zepto.qsa(parent, selector).indexOf(element) 59 | temp && tempParent.removeChild(element) 60 | return match 61 | } 62 | 63 | function type(obj) { 64 | return obj == null ? String(obj) : 65 | class2type[toString.call(obj)] || "object" 66 | } 67 | 68 | function isFunction(value) { return type(value) == "function" } 69 | function isWindow(obj) { return obj != null && obj == obj.window } 70 | function isDocument(obj) { return obj != null && obj.nodeType == obj.DOCUMENT_NODE } 71 | function isObject(obj) { return type(obj) == "object" } 72 | function isPlainObject(obj) { 73 | return isObject(obj) && !isWindow(obj) && Object.getPrototypeOf(obj) == Object.prototype 74 | } 75 | function likeArray(obj) { return typeof obj.length == 'number' } 76 | 77 | function compact(array) { return filter.call(array, function(item){ return item != null }) } 78 | function flatten(array) { return array.length > 0 ? $.fn.concat.apply([], array) : array } 79 | camelize = function(str){ return str.replace(/-+(.)?/g, function(match, chr){ return chr ? chr.toUpperCase() : '' }) } 80 | function dasherize(str) { 81 | return str.replace(/::/g, '/') 82 | .replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2') 83 | .replace(/([a-z\d])([A-Z])/g, '$1_$2') 84 | .replace(/_/g, '-') 85 | .toLowerCase() 86 | } 87 | uniq = function(array){ return filter.call(array, function(item, idx){ return array.indexOf(item) == idx }) } 88 | 89 | function classRE(name) { 90 | return name in classCache ? 91 | classCache[name] : (classCache[name] = new RegExp('(^|\\s)' + name + '(\\s|$)')) 92 | } 93 | 94 | function maybeAddPx(name, value) { 95 | return (typeof value == "number" && !cssNumber[dasherize(name)]) ? value + "px" : value 96 | } 97 | 98 | function defaultDisplay(nodeName) { 99 | var element, display 100 | if (!elementDisplay[nodeName]) { 101 | element = document.createElement(nodeName) 102 | document.body.appendChild(element) 103 | display = getComputedStyle(element, '').getPropertyValue("display") 104 | element.parentNode.removeChild(element) 105 | display == "none" && (display = "block") 106 | elementDisplay[nodeName] = display 107 | } 108 | return elementDisplay[nodeName] 109 | } 110 | 111 | function children(element) { 112 | return 'children' in element ? 113 | slice.call(element.children) : 114 | $.map(element.childNodes, function(node){ if (node.nodeType == 1) return node }) 115 | } 116 | 117 | // `$.zepto.fragment` takes a html string and an optional tag name 118 | // to generate DOM nodes nodes from the given html string. 119 | // The generated DOM nodes are returned as an array. 120 | // This function can be overriden in plugins for example to make 121 | // it compatible with browsers that don't support the DOM fully. 122 | zepto.fragment = function(html, name, properties) { 123 | var dom, nodes, container 124 | 125 | // A special case optimization for a single tag 126 | if (singleTagRE.test(html)) dom = $(document.createElement(RegExp.$1)) 127 | 128 | if (!dom) { 129 | if (html.replace) html = html.replace(tagExpanderRE, "<$1>") 130 | if (name === undefined) name = fragmentRE.test(html) && RegExp.$1 131 | if (!(name in containers)) name = '*' 132 | 133 | container = containers[name] 134 | container.innerHTML = '' + html 135 | dom = $.each(slice.call(container.childNodes), function(){ 136 | container.removeChild(this) 137 | }) 138 | } 139 | 140 | if (isPlainObject(properties)) { 141 | nodes = $(dom) 142 | $.each(properties, function(key, value) { 143 | if (methodAttributes.indexOf(key) > -1) nodes[key](value) 144 | else nodes.attr(key, value) 145 | }) 146 | } 147 | 148 | return dom 149 | } 150 | 151 | // `$.zepto.Z` swaps out the prototype of the given `dom` array 152 | // of nodes with `$.fn` and thus supplying all the Zepto functions 153 | // to the array. Note that `__proto__` is not supported on Internet 154 | // Explorer. This method can be overriden in plugins. 155 | zepto.Z = function(dom, selector) { 156 | dom = dom || [] 157 | dom.__proto__ = $.fn 158 | dom.selector = selector || '' 159 | return dom 160 | } 161 | 162 | // `$.zepto.isZ` should return `true` if the given object is a Zepto 163 | // collection. This method can be overriden in plugins. 164 | zepto.isZ = function(object) { 165 | return object instanceof zepto.Z 166 | } 167 | 168 | // `$.zepto.init` is Zepto's counterpart to jQuery's `$.fn.init` and 169 | // takes a CSS selector and an optional context (and handles various 170 | // special cases). 171 | // This method can be overriden in plugins. 172 | zepto.init = function(selector, context) { 173 | var dom 174 | // If nothing given, return an empty Zepto collection 175 | if (!selector) return zepto.Z() 176 | // Optimize for string selectors 177 | else if (typeof selector == 'string') { 178 | selector = selector.trim() 179 | // If it's a html fragment, create nodes from it 180 | // Note: In both Chrome 21 and Firefox 15, DOM error 12 181 | // is thrown if the fragment doesn't begin with < 182 | if (selector[0] == '<' && fragmentRE.test(selector)) 183 | dom = zepto.fragment(selector, RegExp.$1, context), selector = null 184 | // If there's a context, create a collection on that context first, and select 185 | // nodes from there 186 | else if (context !== undefined) return $(context).find(selector) 187 | // If it's a CSS selector, use it to select nodes. 188 | else dom = zepto.qsa(document, selector) 189 | } 190 | // If a function is given, call it when the DOM is ready 191 | else if (isFunction(selector)) return $(document).ready(selector) 192 | // If a Zepto collection is given, just return it 193 | else if (zepto.isZ(selector)) return selector 194 | else { 195 | // normalize array if an array of nodes is given 196 | if (isArray(selector)) dom = compact(selector) 197 | // Wrap DOM nodes. 198 | else if (isObject(selector)) 199 | dom = [selector], selector = null 200 | // If it's a html fragment, create nodes from it 201 | else if (fragmentRE.test(selector)) 202 | dom = zepto.fragment(selector.trim(), RegExp.$1, context), selector = null 203 | // If there's a context, create a collection on that context first, and select 204 | // nodes from there 205 | else if (context !== undefined) return $(context).find(selector) 206 | // And last but no least, if it's a CSS selector, use it to select nodes. 207 | else dom = zepto.qsa(document, selector) 208 | } 209 | // create a new Zepto collection from the nodes found 210 | return zepto.Z(dom, selector) 211 | } 212 | 213 | // `$` will be the base `Zepto` object. When calling this 214 | // function just call `$.zepto.init, which makes the implementation 215 | // details of selecting nodes and creating Zepto collections 216 | // patchable in plugins. 217 | $ = function(selector, context){ 218 | return zepto.init(selector, context) 219 | } 220 | 221 | function extend(target, source, deep) { 222 | for (key in source) 223 | if (deep && (isPlainObject(source[key]) || isArray(source[key]))) { 224 | if (isPlainObject(source[key]) && !isPlainObject(target[key])) 225 | target[key] = {} 226 | if (isArray(source[key]) && !isArray(target[key])) 227 | target[key] = [] 228 | extend(target[key], source[key], deep) 229 | } 230 | else if (source[key] !== undefined) target[key] = source[key] 231 | } 232 | 233 | // Copy all but undefined properties from one or more 234 | // objects to the `target` object. 235 | $.extend = function(target){ 236 | var deep, args = slice.call(arguments, 1) 237 | if (typeof target == 'boolean') { 238 | deep = target 239 | target = args.shift() 240 | } 241 | args.forEach(function(arg){ extend(target, arg, deep) }) 242 | return target 243 | } 244 | 245 | // `$.zepto.qsa` is Zepto's CSS selector implementation which 246 | // uses `document.querySelectorAll` and optimizes for some special cases, like `#id`. 247 | // This method can be overriden in plugins. 248 | zepto.qsa = function(element, selector){ 249 | var found, 250 | maybeID = selector[0] == '#', 251 | maybeClass = !maybeID && selector[0] == '.', 252 | nameOnly = maybeID || maybeClass ? selector.slice(1) : selector, // Ensure that a 1 char tag name still gets checked 253 | isSimple = simpleSelectorRE.test(nameOnly) 254 | return (isDocument(element) && isSimple && maybeID) ? 255 | ( (found = element.getElementById(nameOnly)) ? [found] : [] ) : 256 | (element.nodeType !== 1 && element.nodeType !== 9) ? [] : 257 | slice.call( 258 | isSimple && !maybeID ? 259 | maybeClass ? element.getElementsByClassName(nameOnly) : // If it's simple, it could be a class 260 | element.getElementsByTagName(selector) : // Or a tag 261 | element.querySelectorAll(selector) // Or it's not simple, and we need to query all 262 | ) 263 | } 264 | 265 | function filtered(nodes, selector) { 266 | return selector == null ? $(nodes) : $(nodes).filter(selector) 267 | } 268 | 269 | $.contains = document.documentElement.contains ? 270 | function(parent, node) { 271 | return parent !== node && parent.contains(node) 272 | } : 273 | function(parent, node) { 274 | while (node && (node = node.parentNode)) 275 | if (node === parent) return true 276 | return false 277 | } 278 | 279 | function funcArg(context, arg, idx, payload) { 280 | return isFunction(arg) ? arg.call(context, idx, payload) : arg 281 | } 282 | 283 | function setAttribute(node, name, value) { 284 | value == null ? node.removeAttribute(name) : node.setAttribute(name, value) 285 | } 286 | 287 | // access className property while respecting SVGAnimatedString 288 | function className(node, value){ 289 | var klass = node.className || '', 290 | svg = klass && klass.baseVal !== undefined 291 | 292 | if (value === undefined) return svg ? klass.baseVal : klass 293 | svg ? (klass.baseVal = value) : (node.className = value) 294 | } 295 | 296 | // "true" => true 297 | // "false" => false 298 | // "null" => null 299 | // "42" => 42 300 | // "42.5" => 42.5 301 | // "08" => "08" 302 | // JSON => parse if valid 303 | // String => self 304 | function deserializeValue(value) { 305 | try { 306 | return value ? 307 | value == "true" || 308 | ( value == "false" ? false : 309 | value == "null" ? null : 310 | +value + "" == value ? +value : 311 | /^[\[\{]/.test(value) ? $.parseJSON(value) : 312 | value ) 313 | : value 314 | } catch(e) { 315 | return value 316 | } 317 | } 318 | 319 | $.type = type 320 | $.isFunction = isFunction 321 | $.isWindow = isWindow 322 | $.isArray = isArray 323 | $.isPlainObject = isPlainObject 324 | 325 | $.isEmptyObject = function(obj) { 326 | var name 327 | for (name in obj) return false 328 | return true 329 | } 330 | 331 | $.inArray = function(elem, array, i){ 332 | return emptyArray.indexOf.call(array, elem, i) 333 | } 334 | 335 | $.camelCase = camelize 336 | $.trim = function(str) { 337 | return str == null ? "" : String.prototype.trim.call(str) 338 | } 339 | 340 | // plugin compatibility 341 | $.uuid = 0 342 | $.support = { } 343 | $.expr = { } 344 | 345 | $.map = function(elements, callback){ 346 | var value, values = [], i, key 347 | if (likeArray(elements)) 348 | for (i = 0; i < elements.length; i++) { 349 | value = callback(elements[i], i) 350 | if (value != null) values.push(value) 351 | } 352 | else 353 | for (key in elements) { 354 | value = callback(elements[key], key) 355 | if (value != null) values.push(value) 356 | } 357 | return flatten(values) 358 | } 359 | 360 | $.each = function(elements, callback){ 361 | var i, key 362 | if (likeArray(elements)) { 363 | for (i = 0; i < elements.length; i++) 364 | if (callback.call(elements[i], i, elements[i]) === false) return elements 365 | } else { 366 | for (key in elements) 367 | if (callback.call(elements[key], key, elements[key]) === false) return elements 368 | } 369 | 370 | return elements 371 | } 372 | 373 | $.grep = function(elements, callback){ 374 | return filter.call(elements, callback) 375 | } 376 | 377 | if (window.JSON) $.parseJSON = JSON.parse 378 | 379 | // Populate the class2type map 380 | $.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { 381 | class2type[ "[object " + name + "]" ] = name.toLowerCase() 382 | }) 383 | 384 | // Define methods that will be available on all 385 | // Zepto collections 386 | $.fn = { 387 | // Because a collection acts like an array 388 | // copy over these useful array functions. 389 | forEach: emptyArray.forEach, 390 | reduce: emptyArray.reduce, 391 | push: emptyArray.push, 392 | sort: emptyArray.sort, 393 | indexOf: emptyArray.indexOf, 394 | concat: emptyArray.concat, 395 | 396 | // `map` and `slice` in the jQuery API work differently 397 | // from their array counterparts 398 | map: function(fn){ 399 | return $($.map(this, function(el, i){ return fn.call(el, i, el) })) 400 | }, 401 | slice: function(){ 402 | return $(slice.apply(this, arguments)) 403 | }, 404 | 405 | ready: function(callback){ 406 | // need to check if document.body exists for IE as that browser reports 407 | // document ready when it hasn't yet created the body element 408 | if (readyRE.test(document.readyState) && document.body) callback($) 409 | else document.addEventListener('DOMContentLoaded', function(){ callback($) }, false) 410 | return this 411 | }, 412 | get: function(idx){ 413 | return idx === undefined ? slice.call(this) : this[idx >= 0 ? idx : idx + this.length] 414 | }, 415 | toArray: function(){ return this.get() }, 416 | size: function(){ 417 | return this.length 418 | }, 419 | remove: function(){ 420 | return this.each(function(){ 421 | if (this.parentNode != null) 422 | this.parentNode.removeChild(this) 423 | }) 424 | }, 425 | each: function(callback){ 426 | emptyArray.every.call(this, function(el, idx){ 427 | return callback.call(el, idx, el) !== false 428 | }) 429 | return this 430 | }, 431 | filter: function(selector){ 432 | if (isFunction(selector)) return this.not(this.not(selector)) 433 | return $(filter.call(this, function(element){ 434 | return zepto.matches(element, selector) 435 | })) 436 | }, 437 | add: function(selector,context){ 438 | return $(uniq(this.concat($(selector,context)))) 439 | }, 440 | is: function(selector){ 441 | return this.length > 0 && zepto.matches(this[0], selector) 442 | }, 443 | not: function(selector){ 444 | var nodes=[] 445 | if (isFunction(selector) && selector.call !== undefined) 446 | this.each(function(idx){ 447 | if (!selector.call(this,idx)) nodes.push(this) 448 | }) 449 | else { 450 | var excludes = typeof selector == 'string' ? this.filter(selector) : 451 | (likeArray(selector) && isFunction(selector.item)) ? slice.call(selector) : $(selector) 452 | this.forEach(function(el){ 453 | if (excludes.indexOf(el) < 0) nodes.push(el) 454 | }) 455 | } 456 | return $(nodes) 457 | }, 458 | has: function(selector){ 459 | return this.filter(function(){ 460 | return isObject(selector) ? 461 | $.contains(this, selector) : 462 | $(this).find(selector).size() 463 | }) 464 | }, 465 | eq: function(idx){ 466 | return idx === -1 ? this.slice(idx) : this.slice(idx, + idx + 1) 467 | }, 468 | first: function(){ 469 | var el = this[0] 470 | return el && !isObject(el) ? el : $(el) 471 | }, 472 | last: function(){ 473 | var el = this[this.length - 1] 474 | return el && !isObject(el) ? el : $(el) 475 | }, 476 | find: function(selector){ 477 | var result, $this = this 478 | if (!selector) result = $() 479 | else if (typeof selector == 'object') 480 | result = $(selector).filter(function(){ 481 | var node = this 482 | return emptyArray.some.call($this, function(parent){ 483 | return $.contains(parent, node) 484 | }) 485 | }) 486 | else if (this.length == 1) result = $(zepto.qsa(this[0], selector)) 487 | else result = this.map(function(){ return zepto.qsa(this, selector) }) 488 | return result 489 | }, 490 | closest: function(selector, context){ 491 | var node = this[0], collection = false 492 | if (typeof selector == 'object') collection = $(selector) 493 | while (node && !(collection ? collection.indexOf(node) >= 0 : zepto.matches(node, selector))) 494 | node = node !== context && !isDocument(node) && node.parentNode 495 | return $(node) 496 | }, 497 | parents: function(selector){ 498 | var ancestors = [], nodes = this 499 | while (nodes.length > 0) 500 | nodes = $.map(nodes, function(node){ 501 | if ((node = node.parentNode) && !isDocument(node) && ancestors.indexOf(node) < 0) { 502 | ancestors.push(node) 503 | return node 504 | } 505 | }) 506 | return filtered(ancestors, selector) 507 | }, 508 | parent: function(selector){ 509 | return filtered(uniq(this.pluck('parentNode')), selector) 510 | }, 511 | children: function(selector){ 512 | return filtered(this.map(function(){ return children(this) }), selector) 513 | }, 514 | contents: function() { 515 | return this.map(function() { return slice.call(this.childNodes) }) 516 | }, 517 | siblings: function(selector){ 518 | return filtered(this.map(function(i, el){ 519 | return filter.call(children(el.parentNode), function(child){ return child!==el }) 520 | }), selector) 521 | }, 522 | empty: function(){ 523 | return this.each(function(){ this.innerHTML = '' }) 524 | }, 525 | // `pluck` is borrowed from Prototype.js 526 | pluck: function(property){ 527 | return $.map(this, function(el){ return el[property] }) 528 | }, 529 | show: function(){ 530 | return this.each(function(){ 531 | this.style.display == "none" && (this.style.display = '') 532 | if (getComputedStyle(this, '').getPropertyValue("display") == "none") 533 | this.style.display = defaultDisplay(this.nodeName) 534 | }) 535 | }, 536 | replaceWith: function(newContent){ 537 | return this.before(newContent).remove() 538 | }, 539 | wrap: function(structure){ 540 | var func = isFunction(structure) 541 | if (this[0] && !func) 542 | var dom = $(structure).get(0), 543 | clone = dom.parentNode || this.length > 1 544 | 545 | return this.each(function(index){ 546 | $(this).wrapAll( 547 | func ? structure.call(this, index) : 548 | clone ? dom.cloneNode(true) : dom 549 | ) 550 | }) 551 | }, 552 | wrapAll: function(structure){ 553 | if (this[0]) { 554 | $(this[0]).before(structure = $(structure)) 555 | var children 556 | // drill down to the inmost element 557 | while ((children = structure.children()).length) structure = children.first() 558 | $(structure).append(this) 559 | } 560 | return this 561 | }, 562 | wrapInner: function(structure){ 563 | var func = isFunction(structure) 564 | return this.each(function(index){ 565 | var self = $(this), contents = self.contents(), 566 | dom = func ? structure.call(this, index) : structure 567 | contents.length ? contents.wrapAll(dom) : self.append(dom) 568 | }) 569 | }, 570 | unwrap: function(){ 571 | this.parent().each(function(){ 572 | $(this).replaceWith($(this).children()) 573 | }) 574 | return this 575 | }, 576 | clone: function(){ 577 | return this.map(function(){ return this.cloneNode(true) }) 578 | }, 579 | hide: function(){ 580 | return this.css("display", "none") 581 | }, 582 | toggle: function(setting){ 583 | return this.each(function(){ 584 | var el = $(this) 585 | ;(setting === undefined ? el.css("display") == "none" : setting) ? el.show() : el.hide() 586 | }) 587 | }, 588 | prev: function(selector){ return $(this.pluck('previousElementSibling')).filter(selector || '*') }, 589 | next: function(selector){ return $(this.pluck('nextElementSibling')).filter(selector || '*') }, 590 | html: function(html){ 591 | return 0 in arguments ? 592 | this.each(function(idx){ 593 | var originHtml = this.innerHTML 594 | $(this).empty().append( funcArg(this, html, idx, originHtml) ) 595 | }) : 596 | (0 in this ? this[0].innerHTML : null) 597 | }, 598 | text: function(text){ 599 | return 0 in arguments ? 600 | this.each(function(idx){ 601 | var newText = funcArg(this, text, idx, this.textContent) 602 | this.textContent = newText == null ? '' : ''+newText 603 | }) : 604 | (0 in this ? this[0].textContent : null) 605 | }, 606 | attr: function(name, value){ 607 | var result 608 | return (typeof name == 'string' && !(1 in arguments)) ? 609 | (!this.length || this[0].nodeType !== 1 ? undefined : 610 | (!(result = this[0].getAttribute(name)) && name in this[0]) ? this[0][name] : result 611 | ) : 612 | this.each(function(idx){ 613 | if (this.nodeType !== 1) return 614 | if (isObject(name)) for (key in name) setAttribute(this, key, name[key]) 615 | else setAttribute(this, name, funcArg(this, value, idx, this.getAttribute(name))) 616 | }) 617 | }, 618 | removeAttr: function(name){ 619 | return this.each(function(){ this.nodeType === 1 && name.split(' ').forEach(function(attribute){ 620 | setAttribute(this, attribute) 621 | }, this)}) 622 | }, 623 | prop: function(name, value){ 624 | name = propMap[name] || name 625 | return (1 in arguments) ? 626 | this.each(function(idx){ 627 | this[name] = funcArg(this, value, idx, this[name]) 628 | }) : 629 | (this[0] && this[0][name]) 630 | }, 631 | data: function(name, value){ 632 | var attrName = 'data-' + name.replace(capitalRE, '-$1').toLowerCase() 633 | 634 | var data = (1 in arguments) ? 635 | this.attr(attrName, value) : 636 | this.attr(attrName) 637 | 638 | return data !== null ? deserializeValue(data) : undefined 639 | }, 640 | val: function(value){ 641 | return 0 in arguments ? 642 | this.each(function(idx){ 643 | this.value = funcArg(this, value, idx, this.value) 644 | }) : 645 | (this[0] && (this[0].multiple ? 646 | $(this[0]).find('option').filter(function(){ return this.selected }).pluck('value') : 647 | this[0].value) 648 | ) 649 | }, 650 | offset: function(coordinates){ 651 | if (coordinates) return this.each(function(index){ 652 | var $this = $(this), 653 | coords = funcArg(this, coordinates, index, $this.offset()), 654 | parentOffset = $this.offsetParent().offset(), 655 | props = { 656 | top: coords.top - parentOffset.top, 657 | left: coords.left - parentOffset.left 658 | } 659 | 660 | if ($this.css('position') == 'static') props['position'] = 'relative' 661 | $this.css(props) 662 | }) 663 | if (!this.length) return null 664 | var obj = this[0].getBoundingClientRect() 665 | return { 666 | left: obj.left + window.pageXOffset, 667 | top: obj.top + window.pageYOffset, 668 | width: Math.round(obj.width), 669 | height: Math.round(obj.height) 670 | } 671 | }, 672 | css: function(property, value){ 673 | if (arguments.length < 2) { 674 | var computedStyle, element = this[0] 675 | if(!element) return 676 | computedStyle = getComputedStyle(element, '') 677 | if (typeof property == 'string') 678 | return element.style[camelize(property)] || computedStyle.getPropertyValue(property) 679 | else if (isArray(property)) { 680 | var props = {} 681 | $.each(property, function(_, prop){ 682 | props[prop] = (element.style[camelize(prop)] || computedStyle.getPropertyValue(prop)) 683 | }) 684 | return props 685 | } 686 | } 687 | 688 | var css = '' 689 | if (type(property) == 'string') { 690 | if (!value && value !== 0) 691 | this.each(function(){ this.style.removeProperty(dasherize(property)) }) 692 | else 693 | css = dasherize(property) + ":" + maybeAddPx(property, value) 694 | } else { 695 | for (key in property) 696 | if (!property[key] && property[key] !== 0) 697 | this.each(function(){ this.style.removeProperty(dasherize(key)) }) 698 | else 699 | css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';' 700 | } 701 | 702 | return this.each(function(){ this.style.cssText += ';' + css }) 703 | }, 704 | index: function(element){ 705 | return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0]) 706 | }, 707 | hasClass: function(name){ 708 | if (!name) return false 709 | return emptyArray.some.call(this, function(el){ 710 | return this.test(className(el)) 711 | }, classRE(name)) 712 | }, 713 | addClass: function(name){ 714 | if (!name) return this 715 | return this.each(function(idx){ 716 | if (!('className' in this)) return 717 | classList = [] 718 | var cls = className(this), newName = funcArg(this, name, idx, cls) 719 | newName.split(/\s+/g).forEach(function(klass){ 720 | if (!$(this).hasClass(klass)) classList.push(klass) 721 | }, this) 722 | classList.length && className(this, cls + (cls ? " " : "") + classList.join(" ")) 723 | }) 724 | }, 725 | removeClass: function(name){ 726 | return this.each(function(idx){ 727 | if (!('className' in this)) return 728 | if (name === undefined) return className(this, '') 729 | classList = className(this) 730 | funcArg(this, name, idx, classList).split(/\s+/g).forEach(function(klass){ 731 | classList = classList.replace(classRE(klass), " ") 732 | }) 733 | className(this, classList.trim()) 734 | }) 735 | }, 736 | toggleClass: function(name, when){ 737 | if (!name) return this 738 | return this.each(function(idx){ 739 | var $this = $(this), names = funcArg(this, name, idx, className(this)) 740 | names.split(/\s+/g).forEach(function(klass){ 741 | (when === undefined ? !$this.hasClass(klass) : when) ? 742 | $this.addClass(klass) : $this.removeClass(klass) 743 | }) 744 | }) 745 | }, 746 | scrollTop: function(value){ 747 | if (!this.length) return 748 | var hasScrollTop = 'scrollTop' in this[0] 749 | if (value === undefined) return hasScrollTop ? this[0].scrollTop : this[0].pageYOffset 750 | return this.each(hasScrollTop ? 751 | function(){ this.scrollTop = value } : 752 | function(){ this.scrollTo(this.scrollX, value) }) 753 | }, 754 | scrollLeft: function(value){ 755 | if (!this.length) return 756 | var hasScrollLeft = 'scrollLeft' in this[0] 757 | if (value === undefined) return hasScrollLeft ? this[0].scrollLeft : this[0].pageXOffset 758 | return this.each(hasScrollLeft ? 759 | function(){ this.scrollLeft = value } : 760 | function(){ this.scrollTo(value, this.scrollY) }) 761 | }, 762 | position: function() { 763 | if (!this.length) return 764 | 765 | var elem = this[0], 766 | // Get *real* offsetParent 767 | offsetParent = this.offsetParent(), 768 | // Get correct offsets 769 | offset = this.offset(), 770 | parentOffset = rootNodeRE.test(offsetParent[0].nodeName) ? { top: 0, left: 0 } : offsetParent.offset() 771 | 772 | // Subtract element margins 773 | // note: when an element has margin: auto the offsetLeft and marginLeft 774 | // are the same in Safari causing offset.left to incorrectly be 0 775 | offset.top -= parseFloat( $(elem).css('margin-top') ) || 0 776 | offset.left -= parseFloat( $(elem).css('margin-left') ) || 0 777 | 778 | // Add offsetParent borders 779 | parentOffset.top += parseFloat( $(offsetParent[0]).css('border-top-width') ) || 0 780 | parentOffset.left += parseFloat( $(offsetParent[0]).css('border-left-width') ) || 0 781 | 782 | // Subtract the two offsets 783 | return { 784 | top: offset.top - parentOffset.top, 785 | left: offset.left - parentOffset.left 786 | } 787 | }, 788 | offsetParent: function() { 789 | return this.map(function(){ 790 | var parent = this.offsetParent || document.body 791 | while (parent && !rootNodeRE.test(parent.nodeName) && $(parent).css("position") == "static") 792 | parent = parent.offsetParent 793 | return parent 794 | }) 795 | } 796 | } 797 | 798 | // for now 799 | $.fn.detach = $.fn.remove 800 | 801 | // Generate the `width` and `height` functions 802 | ;['width', 'height'].forEach(function(dimension){ 803 | var dimensionProperty = 804 | dimension.replace(/./, function(m){ return m[0].toUpperCase() }) 805 | 806 | $.fn[dimension] = function(value){ 807 | var offset, el = this[0] 808 | if (value === undefined) return isWindow(el) ? el['inner' + dimensionProperty] : 809 | isDocument(el) ? el.documentElement['scroll' + dimensionProperty] : 810 | (offset = this.offset()) && offset[dimension] 811 | else return this.each(function(idx){ 812 | el = $(this) 813 | el.css(dimension, funcArg(this, value, idx, el[dimension]())) 814 | }) 815 | } 816 | }) 817 | 818 | function traverseNode(node, fun) { 819 | fun(node) 820 | for (var i = 0, len = node.childNodes.length; i < len; i++) 821 | traverseNode(node.childNodes[i], fun) 822 | } 823 | 824 | // Generate the `after`, `prepend`, `before`, `append`, 825 | // `insertAfter`, `insertBefore`, `appendTo`, and `prependTo` methods. 826 | adjacencyOperators.forEach(function(operator, operatorIndex) { 827 | var inside = operatorIndex % 2 //=> prepend, append 828 | 829 | $.fn[operator] = function(){ 830 | // arguments can be nodes, arrays of nodes, Zepto objects and HTML strings 831 | var argType, nodes = $.map(arguments, function(arg) { 832 | argType = type(arg) 833 | return argType == "object" || argType == "array" || arg == null ? 834 | arg : zepto.fragment(arg) 835 | }), 836 | parent, copyByClone = this.length > 1 837 | if (nodes.length < 1) return this 838 | 839 | return this.each(function(_, target){ 840 | parent = inside ? target : target.parentNode 841 | 842 | // convert all methods to a "before" operation 843 | target = operatorIndex == 0 ? target.nextSibling : 844 | operatorIndex == 1 ? target.firstChild : 845 | operatorIndex == 2 ? target : 846 | null 847 | 848 | var parentInDocument = $.contains(document.documentElement, parent) 849 | 850 | nodes.forEach(function(node){ 851 | if (copyByClone) node = node.cloneNode(true) 852 | else if (!parent) return $(node).remove() 853 | 854 | parent.insertBefore(node, target) 855 | if (parentInDocument) traverseNode(node, function(el){ 856 | if (el.nodeName != null && el.nodeName.toUpperCase() === 'SCRIPT' && 857 | (!el.type || el.type === 'text/javascript') && !el.src) 858 | window['eval'].call(window, el.innerHTML) 859 | }) 860 | }) 861 | }) 862 | } 863 | 864 | // after => insertAfter 865 | // prepend => prependTo 866 | // before => insertBefore 867 | // append => appendTo 868 | $.fn[inside ? operator+'To' : 'insert'+(operatorIndex ? 'Before' : 'After')] = function(html){ 869 | $(html)[operator](this) 870 | return this 871 | } 872 | }) 873 | 874 | zepto.Z.prototype = $.fn 875 | 876 | // Export internal API functions in the `$.zepto` namespace 877 | zepto.uniq = uniq 878 | zepto.deserializeValue = deserializeValue 879 | $.zepto = zepto 880 | 881 | return $ 882 | })() 883 | 884 | window.Zepto = Zepto 885 | window.$ === undefined && (window.$ = Zepto) 886 | 887 | ;(function($){ 888 | var _zid = 1, undefined, 889 | slice = Array.prototype.slice, 890 | isFunction = $.isFunction, 891 | isString = function(obj){ return typeof obj == 'string' }, 892 | handlers = {}, 893 | specialEvents={}, 894 | focusinSupported = 'onfocusin' in window, 895 | focus = { focus: 'focusin', blur: 'focusout' }, 896 | hover = { mouseenter: 'mouseover', mouseleave: 'mouseout' } 897 | 898 | specialEvents.click = specialEvents.mousedown = specialEvents.mouseup = specialEvents.mousemove = 'MouseEvents' 899 | 900 | function zid(element) { 901 | return element._zid || (element._zid = _zid++) 902 | } 903 | function findHandlers(element, event, fn, selector) { 904 | event = parse(event) 905 | if (event.ns) var matcher = matcherFor(event.ns) 906 | return (handlers[zid(element)] || []).filter(function(handler) { 907 | return handler 908 | && (!event.e || handler.e == event.e) 909 | && (!event.ns || matcher.test(handler.ns)) 910 | && (!fn || zid(handler.fn) === zid(fn)) 911 | && (!selector || handler.sel == selector) 912 | }) 913 | } 914 | function parse(event) { 915 | var parts = ('' + event).split('.') 916 | return {e: parts[0], ns: parts.slice(1).sort().join(' ')} 917 | } 918 | function matcherFor(ns) { 919 | return new RegExp('(?:^| )' + ns.replace(' ', ' .* ?') + '(?: |$)') 920 | } 921 | 922 | function eventCapture(handler, captureSetting) { 923 | return handler.del && 924 | (!focusinSupported && (handler.e in focus)) || 925 | !!captureSetting 926 | } 927 | 928 | function realEvent(type) { 929 | return hover[type] || (focusinSupported && focus[type]) || type 930 | } 931 | 932 | function add(element, events, fn, data, selector, delegator, capture){ 933 | var id = zid(element), set = (handlers[id] || (handlers[id] = [])) 934 | events.split(/\s/).forEach(function(event){ 935 | if (event == 'ready') return $(document).ready(fn) 936 | var handler = parse(event) 937 | handler.fn = fn 938 | handler.sel = selector 939 | // emulate mouseenter, mouseleave 940 | if (handler.e in hover) fn = function(e){ 941 | var related = e.relatedTarget 942 | if (!related || (related !== this && !$.contains(this, related))) 943 | return handler.fn.apply(this, arguments) 944 | } 945 | handler.del = delegator 946 | var callback = delegator || fn 947 | handler.proxy = function(e){ 948 | e = compatible(e) 949 | if (e.isImmediatePropagationStopped()) return 950 | e.data = data 951 | var result = callback.apply(element, e._args == undefined ? [e] : [e].concat(e._args)) 952 | if (result === false) e.preventDefault(), e.stopPropagation() 953 | return result 954 | } 955 | handler.i = set.length 956 | set.push(handler) 957 | if ('addEventListener' in element) 958 | element.addEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 959 | }) 960 | } 961 | function remove(element, events, fn, selector, capture){ 962 | var id = zid(element) 963 | ;(events || '').split(/\s/).forEach(function(event){ 964 | findHandlers(element, event, fn, selector).forEach(function(handler){ 965 | delete handlers[id][handler.i] 966 | if ('removeEventListener' in element) 967 | element.removeEventListener(realEvent(handler.e), handler.proxy, eventCapture(handler, capture)) 968 | }) 969 | }) 970 | } 971 | 972 | $.event = { add: add, remove: remove } 973 | 974 | $.proxy = function(fn, context) { 975 | var args = (2 in arguments) && slice.call(arguments, 2) 976 | if (isFunction(fn)) { 977 | var proxyFn = function(){ return fn.apply(context, args ? args.concat(slice.call(arguments)) : arguments) } 978 | proxyFn._zid = zid(fn) 979 | return proxyFn 980 | } else if (isString(context)) { 981 | if (args) { 982 | args.unshift(fn[context], fn) 983 | return $.proxy.apply(null, args) 984 | } else { 985 | return $.proxy(fn[context], fn) 986 | } 987 | } else { 988 | throw new TypeError("expected function") 989 | } 990 | } 991 | 992 | $.fn.bind = function(event, data, callback){ 993 | return this.on(event, data, callback) 994 | } 995 | $.fn.unbind = function(event, callback){ 996 | return this.off(event, callback) 997 | } 998 | $.fn.one = function(event, selector, data, callback){ 999 | return this.on(event, selector, data, callback, 1) 1000 | } 1001 | 1002 | var returnTrue = function(){return true}, 1003 | returnFalse = function(){return false}, 1004 | ignoreProperties = /^([A-Z]|returnValue$|layer[XY]$)/, 1005 | eventMethods = { 1006 | preventDefault: 'isDefaultPrevented', 1007 | stopImmediatePropagation: 'isImmediatePropagationStopped', 1008 | stopPropagation: 'isPropagationStopped' 1009 | } 1010 | 1011 | function compatible(event, source) { 1012 | if (source || !event.isDefaultPrevented) { 1013 | source || (source = event) 1014 | 1015 | $.each(eventMethods, function(name, predicate) { 1016 | var sourceMethod = source[name] 1017 | event[name] = function(){ 1018 | this[predicate] = returnTrue 1019 | return sourceMethod && sourceMethod.apply(source, arguments) 1020 | } 1021 | event[predicate] = returnFalse 1022 | }) 1023 | 1024 | if (source.defaultPrevented !== undefined ? source.defaultPrevented : 1025 | 'returnValue' in source ? source.returnValue === false : 1026 | source.getPreventDefault && source.getPreventDefault()) 1027 | event.isDefaultPrevented = returnTrue 1028 | } 1029 | return event 1030 | } 1031 | 1032 | function createProxy(event) { 1033 | var key, proxy = { originalEvent: event } 1034 | for (key in event) 1035 | if (!ignoreProperties.test(key) && event[key] !== undefined) proxy[key] = event[key] 1036 | 1037 | return compatible(proxy, event) 1038 | } 1039 | 1040 | $.fn.delegate = function(selector, event, callback){ 1041 | return this.on(event, selector, callback) 1042 | } 1043 | $.fn.undelegate = function(selector, event, callback){ 1044 | return this.off(event, selector, callback) 1045 | } 1046 | 1047 | $.fn.live = function(event, callback){ 1048 | $(document.body).delegate(this.selector, event, callback) 1049 | return this 1050 | } 1051 | $.fn.die = function(event, callback){ 1052 | $(document.body).undelegate(this.selector, event, callback) 1053 | return this 1054 | } 1055 | 1056 | $.fn.on = function(event, selector, data, callback, one){ 1057 | var autoRemove, delegator, $this = this 1058 | if (event && !isString(event)) { 1059 | $.each(event, function(type, fn){ 1060 | $this.on(type, selector, data, fn, one) 1061 | }) 1062 | return $this 1063 | } 1064 | 1065 | if (!isString(selector) && !isFunction(callback) && callback !== false) 1066 | callback = data, data = selector, selector = undefined 1067 | if (isFunction(data) || data === false) 1068 | callback = data, data = undefined 1069 | 1070 | if (callback === false) callback = returnFalse 1071 | 1072 | return $this.each(function(_, element){ 1073 | if (one) autoRemove = function(e){ 1074 | remove(element, e.type, callback) 1075 | return callback.apply(this, arguments) 1076 | } 1077 | 1078 | if (selector) delegator = function(e){ 1079 | var evt, match = $(e.target).closest(selector, element).get(0) 1080 | if (match && match !== element) { 1081 | evt = $.extend(createProxy(e), {currentTarget: match, liveFired: element}) 1082 | return (autoRemove || callback).apply(match, [evt].concat(slice.call(arguments, 1))) 1083 | } 1084 | } 1085 | 1086 | add(element, event, callback, data, selector, delegator || autoRemove) 1087 | }) 1088 | } 1089 | $.fn.off = function(event, selector, callback){ 1090 | var $this = this 1091 | if (event && !isString(event)) { 1092 | $.each(event, function(type, fn){ 1093 | $this.off(type, selector, fn) 1094 | }) 1095 | return $this 1096 | } 1097 | 1098 | if (!isString(selector) && !isFunction(callback) && callback !== false) 1099 | callback = selector, selector = undefined 1100 | 1101 | if (callback === false) callback = returnFalse 1102 | 1103 | return $this.each(function(){ 1104 | remove(this, event, callback, selector) 1105 | }) 1106 | } 1107 | 1108 | $.fn.trigger = function(event, args){ 1109 | event = (isString(event) || $.isPlainObject(event)) ? $.Event(event) : compatible(event) 1110 | event._args = args 1111 | return this.each(function(){ 1112 | // handle focus(), blur() by calling them directly 1113 | if (event.type in focus && typeof this[event.type] == "function") this[event.type]() 1114 | // items in the collection might not be DOM elements 1115 | else if ('dispatchEvent' in this) this.dispatchEvent(event) 1116 | else $(this).triggerHandler(event, args) 1117 | }) 1118 | } 1119 | 1120 | // triggers event handlers on current element just as if an event occurred, 1121 | // doesn't trigger an actual event, doesn't bubble 1122 | $.fn.triggerHandler = function(event, args){ 1123 | var e, result 1124 | this.each(function(i, element){ 1125 | e = createProxy(isString(event) ? $.Event(event) : event) 1126 | e._args = args 1127 | e.target = element 1128 | $.each(findHandlers(element, event.type || event), function(i, handler){ 1129 | result = handler.proxy(e) 1130 | if (e.isImmediatePropagationStopped()) return false 1131 | }) 1132 | }) 1133 | return result 1134 | } 1135 | 1136 | // shortcut methods for `.bind(event, fn)` for each event type 1137 | ;('focusin focusout focus blur load resize scroll unload click dblclick '+ 1138 | 'mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave '+ 1139 | 'change select keydown keypress keyup error').split(' ').forEach(function(event) { 1140 | $.fn[event] = function(callback) { 1141 | return (0 in arguments) ? 1142 | this.bind(event, callback) : 1143 | this.trigger(event) 1144 | } 1145 | }) 1146 | 1147 | $.Event = function(type, props) { 1148 | if (!isString(type)) props = type, type = props.type 1149 | var event = document.createEvent(specialEvents[type] || 'Events'), bubbles = true 1150 | if (props) for (var name in props) (name == 'bubbles') ? (bubbles = !!props[name]) : (event[name] = props[name]) 1151 | event.initEvent(type, bubbles, true) 1152 | return compatible(event) 1153 | } 1154 | 1155 | })(Zepto) 1156 | 1157 | ;(function($){ 1158 | var jsonpID = 0, 1159 | document = window.document, 1160 | key, 1161 | name, 1162 | rscript = /)<[^<]*)*<\/script>/gi, 1163 | scriptTypeRE = /^(?:text|application)\/javascript/i, 1164 | xmlTypeRE = /^(?:text|application)\/xml/i, 1165 | jsonType = 'application/json', 1166 | htmlType = 'text/html', 1167 | blankRE = /^\s*$/, 1168 | originAnchor = document.createElement('a') 1169 | 1170 | originAnchor.href = window.location.href 1171 | 1172 | // trigger a custom event and return false if it was cancelled 1173 | function triggerAndReturn(context, eventName, data) { 1174 | var event = $.Event(eventName) 1175 | $(context).trigger(event, data) 1176 | return !event.isDefaultPrevented() 1177 | } 1178 | 1179 | // trigger an Ajax "global" event 1180 | function triggerGlobal(settings, context, eventName, data) { 1181 | if (settings.global) return triggerAndReturn(context || document, eventName, data) 1182 | } 1183 | 1184 | // Number of active Ajax requests 1185 | $.active = 0 1186 | 1187 | function ajaxStart(settings) { 1188 | if (settings.global && $.active++ === 0) triggerGlobal(settings, null, 'ajaxStart') 1189 | } 1190 | function ajaxStop(settings) { 1191 | if (settings.global && !(--$.active)) triggerGlobal(settings, null, 'ajaxStop') 1192 | } 1193 | 1194 | // triggers an extra global event "ajaxBeforeSend" that's like "ajaxSend" but cancelable 1195 | function ajaxBeforeSend(xhr, settings) { 1196 | var context = settings.context 1197 | if (settings.beforeSend.call(context, xhr, settings) === false || 1198 | triggerGlobal(settings, context, 'ajaxBeforeSend', [xhr, settings]) === false) 1199 | return false 1200 | 1201 | triggerGlobal(settings, context, 'ajaxSend', [xhr, settings]) 1202 | } 1203 | function ajaxSuccess(data, xhr, settings, deferred) { 1204 | var context = settings.context, status = 'success' 1205 | settings.success.call(context, data, status, xhr) 1206 | if (deferred) deferred.resolveWith(context, [data, status, xhr]) 1207 | triggerGlobal(settings, context, 'ajaxSuccess', [xhr, settings, data]) 1208 | ajaxComplete(status, xhr, settings) 1209 | } 1210 | // type: "timeout", "error", "abort", "parsererror" 1211 | function ajaxError(error, type, xhr, settings, deferred) { 1212 | var context = settings.context 1213 | settings.error.call(context, xhr, type, error) 1214 | if (deferred) deferred.rejectWith(context, [xhr, type, error]) 1215 | triggerGlobal(settings, context, 'ajaxError', [xhr, settings, error || type]) 1216 | ajaxComplete(type, xhr, settings) 1217 | } 1218 | // status: "success", "notmodified", "error", "timeout", "abort", "parsererror" 1219 | function ajaxComplete(status, xhr, settings) { 1220 | var context = settings.context 1221 | settings.complete.call(context, xhr, status) 1222 | triggerGlobal(settings, context, 'ajaxComplete', [xhr, settings]) 1223 | ajaxStop(settings) 1224 | } 1225 | 1226 | // Empty function, used as default callback 1227 | function empty() {} 1228 | 1229 | $.ajaxJSONP = function(options, deferred){ 1230 | if (!('type' in options)) return $.ajax(options) 1231 | 1232 | var _callbackName = options.jsonpCallback, 1233 | callbackName = ($.isFunction(_callbackName) ? 1234 | _callbackName() : _callbackName) || ('jsonp' + (++jsonpID)), 1235 | script = document.createElement('script'), 1236 | originalCallback = window[callbackName], 1237 | responseData, 1238 | abort = function(errorType) { 1239 | $(script).triggerHandler('error', errorType || 'abort') 1240 | }, 1241 | xhr = { abort: abort }, abortTimeout 1242 | 1243 | if (deferred) deferred.promise(xhr) 1244 | 1245 | $(script).on('load error', function(e, errorType){ 1246 | clearTimeout(abortTimeout) 1247 | $(script).off().remove() 1248 | 1249 | if (e.type == 'error' || !responseData) { 1250 | ajaxError(null, errorType || 'error', xhr, options, deferred) 1251 | } else { 1252 | ajaxSuccess(responseData[0], xhr, options, deferred) 1253 | } 1254 | 1255 | window[callbackName] = originalCallback 1256 | if (responseData && $.isFunction(originalCallback)) 1257 | originalCallback(responseData[0]) 1258 | 1259 | originalCallback = responseData = undefined 1260 | }) 1261 | 1262 | if (ajaxBeforeSend(xhr, options) === false) { 1263 | abort('abort') 1264 | return xhr 1265 | } 1266 | 1267 | window[callbackName] = function(){ 1268 | responseData = arguments 1269 | } 1270 | 1271 | script.src = options.url.replace(/\?(.+)=\?/, '?$1=' + callbackName) 1272 | document.head.appendChild(script) 1273 | 1274 | if (options.timeout > 0) abortTimeout = setTimeout(function(){ 1275 | abort('timeout') 1276 | }, options.timeout) 1277 | 1278 | return xhr 1279 | } 1280 | 1281 | $.ajaxSettings = { 1282 | // Default type of request 1283 | type: 'GET', 1284 | // Callback that is executed before request 1285 | beforeSend: empty, 1286 | // Callback that is executed if the request succeeds 1287 | success: empty, 1288 | // Callback that is executed the the server drops error 1289 | error: empty, 1290 | // Callback that is executed on request complete (both: error and success) 1291 | complete: empty, 1292 | // The context for the callbacks 1293 | context: null, 1294 | // Whether to trigger "global" Ajax events 1295 | global: true, 1296 | // Transport 1297 | xhr: function () { 1298 | return new window.XMLHttpRequest() 1299 | }, 1300 | // MIME types mapping 1301 | // IIS returns Javascript as "application/x-javascript" 1302 | accepts: { 1303 | script: 'text/javascript, application/javascript, application/x-javascript', 1304 | json: jsonType, 1305 | xml: 'application/xml, text/xml', 1306 | html: htmlType, 1307 | text: 'text/plain' 1308 | }, 1309 | // Whether the request is to another domain 1310 | crossDomain: false, 1311 | // Default timeout 1312 | timeout: 0, 1313 | // Whether data should be serialized to string 1314 | processData: true, 1315 | // Whether the browser should be allowed to cache GET responses 1316 | cache: true 1317 | } 1318 | 1319 | function mimeToDataType(mime) { 1320 | if (mime) mime = mime.split(';', 2)[0] 1321 | return mime && ( mime == htmlType ? 'html' : 1322 | mime == jsonType ? 'json' : 1323 | scriptTypeRE.test(mime) ? 'script' : 1324 | xmlTypeRE.test(mime) && 'xml' ) || 'text' 1325 | } 1326 | 1327 | function appendQuery(url, query) { 1328 | if (query == '') return url 1329 | return (url + '&' + query).replace(/[&?]{1,2}/, '?') 1330 | } 1331 | 1332 | // serialize payload and append it to the URL for GET requests 1333 | function serializeData(options) { 1334 | if (options.processData && options.data && $.type(options.data) != "string") 1335 | options.data = $.param(options.data, options.traditional) 1336 | if (options.data && (!options.type || options.type.toUpperCase() == 'GET')) 1337 | options.url = appendQuery(options.url, options.data), options.data = undefined 1338 | } 1339 | 1340 | $.ajax = function(options){ 1341 | var settings = $.extend({}, options || {}), 1342 | deferred = $.Deferred && $.Deferred(), 1343 | urlAnchor 1344 | for (key in $.ajaxSettings) if (settings[key] === undefined) settings[key] = $.ajaxSettings[key] 1345 | 1346 | ajaxStart(settings) 1347 | 1348 | if (!settings.crossDomain) { 1349 | urlAnchor = document.createElement('a') 1350 | urlAnchor.href = settings.url 1351 | urlAnchor.href = urlAnchor.href 1352 | settings.crossDomain = (originAnchor.protocol + '//' + originAnchor.host) !== (urlAnchor.protocol + '//' + urlAnchor.host) 1353 | } 1354 | 1355 | if (!settings.url) settings.url = window.location.toString() 1356 | serializeData(settings) 1357 | 1358 | var dataType = settings.dataType, hasPlaceholder = /\?.+=\?/.test(settings.url) 1359 | if (hasPlaceholder) dataType = 'jsonp' 1360 | 1361 | if (settings.cache === false || ( 1362 | (!options || options.cache !== true) && 1363 | ('script' == dataType || 'jsonp' == dataType) 1364 | )) 1365 | settings.url = appendQuery(settings.url, '_=' + Date.now()) 1366 | 1367 | if ('jsonp' == dataType) { 1368 | if (!hasPlaceholder) 1369 | settings.url = appendQuery(settings.url, 1370 | settings.jsonp ? (settings.jsonp + '=?') : settings.jsonp === false ? '' : 'callback=?') 1371 | return $.ajaxJSONP(settings, deferred) 1372 | } 1373 | 1374 | var mime = settings.accepts[dataType], 1375 | headers = { }, 1376 | setHeader = function(name, value) { headers[name.toLowerCase()] = [name, value] }, 1377 | protocol = /^([\w-]+:)\/\//.test(settings.url) ? RegExp.$1 : window.location.protocol, 1378 | xhr = settings.xhr(), 1379 | nativeSetHeader = xhr.setRequestHeader, 1380 | abortTimeout 1381 | 1382 | if (deferred) deferred.promise(xhr) 1383 | 1384 | if (!settings.crossDomain) setHeader('X-Requested-With', 'XMLHttpRequest') 1385 | setHeader('Accept', mime || '*/*') 1386 | if (mime = settings.mimeType || mime) { 1387 | if (mime.indexOf(',') > -1) mime = mime.split(',', 2)[0] 1388 | xhr.overrideMimeType && xhr.overrideMimeType(mime) 1389 | } 1390 | if (settings.contentType || (settings.contentType !== false && settings.data && settings.type.toUpperCase() != 'GET')) 1391 | setHeader('Content-Type', settings.contentType || 'application/x-www-form-urlencoded') 1392 | 1393 | if (settings.headers) for (name in settings.headers) setHeader(name, settings.headers[name]) 1394 | xhr.setRequestHeader = setHeader 1395 | 1396 | xhr.onreadystatechange = function(){ 1397 | if (xhr.readyState == 4) { 1398 | xhr.onreadystatechange = empty 1399 | clearTimeout(abortTimeout) 1400 | var result, error = false 1401 | if ((xhr.status >= 200 && xhr.status < 300) || xhr.status == 304 || (xhr.status == 0 && protocol == 'file:')) { 1402 | dataType = dataType || mimeToDataType(settings.mimeType || xhr.getResponseHeader('content-type')) 1403 | result = xhr.responseText 1404 | 1405 | try { 1406 | // http://perfectionkills.com/global-eval-what-are-the-options/ 1407 | if (dataType == 'script') (1,eval)(result) 1408 | else if (dataType == 'xml') result = xhr.responseXML 1409 | else if (dataType == 'json') result = blankRE.test(result) ? null : $.parseJSON(result) 1410 | } catch (e) { error = e } 1411 | 1412 | if (error) ajaxError(error, 'parsererror', xhr, settings, deferred) 1413 | else ajaxSuccess(result, xhr, settings, deferred) 1414 | } else { 1415 | ajaxError(xhr.statusText || null, xhr.status ? 'error' : 'abort', xhr, settings, deferred) 1416 | } 1417 | } 1418 | } 1419 | 1420 | if (ajaxBeforeSend(xhr, settings) === false) { 1421 | xhr.abort() 1422 | ajaxError(null, 'abort', xhr, settings, deferred) 1423 | return xhr 1424 | } 1425 | 1426 | if (settings.xhrFields) for (name in settings.xhrFields) xhr[name] = settings.xhrFields[name] 1427 | 1428 | var async = 'async' in settings ? settings.async : true 1429 | xhr.open(settings.type, settings.url, async, settings.username, settings.password) 1430 | 1431 | for (name in headers) nativeSetHeader.apply(xhr, headers[name]) 1432 | 1433 | if (settings.timeout > 0) abortTimeout = setTimeout(function(){ 1434 | xhr.onreadystatechange = empty 1435 | xhr.abort() 1436 | ajaxError(null, 'timeout', xhr, settings, deferred) 1437 | }, settings.timeout) 1438 | 1439 | // avoid sending empty string (#319) 1440 | xhr.send(settings.data ? settings.data : null) 1441 | return xhr 1442 | } 1443 | 1444 | // handle optional data/success arguments 1445 | function parseArguments(url, data, success, dataType) { 1446 | if ($.isFunction(data)) dataType = success, success = data, data = undefined 1447 | if (!$.isFunction(success)) dataType = success, success = undefined 1448 | return { 1449 | url: url 1450 | , data: data 1451 | , success: success 1452 | , dataType: dataType 1453 | } 1454 | } 1455 | 1456 | $.get = function(/* url, data, success, dataType */){ 1457 | return $.ajax(parseArguments.apply(null, arguments)) 1458 | } 1459 | 1460 | $.post = function(/* url, data, success, dataType */){ 1461 | var options = parseArguments.apply(null, arguments) 1462 | options.type = 'POST' 1463 | return $.ajax(options) 1464 | } 1465 | 1466 | $.getJSON = function(/* url, data, success */){ 1467 | var options = parseArguments.apply(null, arguments) 1468 | options.dataType = 'json' 1469 | return $.ajax(options) 1470 | } 1471 | 1472 | $.fn.load = function(url, data, success){ 1473 | if (!this.length) return this 1474 | var self = this, parts = url.split(/\s/), selector, 1475 | options = parseArguments(url, data, success), 1476 | callback = options.success 1477 | if (parts.length > 1) options.url = parts[0], selector = parts[1] 1478 | options.success = function(response){ 1479 | self.html(selector ? 1480 | $('
').html(response.replace(rscript, "")).find(selector) 1481 | : response) 1482 | callback && callback.apply(self, arguments) 1483 | } 1484 | $.ajax(options) 1485 | return this 1486 | } 1487 | 1488 | var escape = encodeURIComponent 1489 | 1490 | function serialize(params, obj, traditional, scope){ 1491 | var type, array = $.isArray(obj), hash = $.isPlainObject(obj) 1492 | $.each(obj, function(key, value) { 1493 | type = $.type(value) 1494 | if (scope) key = traditional ? scope : 1495 | scope + '[' + (hash || type == 'object' || type == 'array' ? key : '') + ']' 1496 | // handle data in serializeArray() format 1497 | if (!scope && array) params.add(value.name, value.value) 1498 | // recurse into nested objects 1499 | else if (type == "array" || (!traditional && type == "object")) 1500 | serialize(params, value, traditional, key) 1501 | else params.add(key, value) 1502 | }) 1503 | } 1504 | 1505 | $.param = function(obj, traditional){ 1506 | var params = [] 1507 | params.add = function(key, value) { 1508 | if ($.isFunction(value)) value = value() 1509 | if (value == null) value = "" 1510 | this.push(escape(key) + '=' + escape(value)) 1511 | } 1512 | serialize(params, obj, traditional) 1513 | return params.join('&').replace(/%20/g, '+') 1514 | } 1515 | })(Zepto) 1516 | 1517 | ;(function($){ 1518 | $.fn.serializeArray = function() { 1519 | var name, type, result = [], 1520 | add = function(value) { 1521 | if (value.forEach) return value.forEach(add) 1522 | result.push({ name: name, value: value }) 1523 | } 1524 | if (this[0]) $.each(this[0].elements, function(_, field){ 1525 | type = field.type, name = field.name 1526 | if (name && field.nodeName.toLowerCase() != 'fieldset' && 1527 | !field.disabled && type != 'submit' && type != 'reset' && type != 'button' && type != 'file' && 1528 | ((type != 'radio' && type != 'checkbox') || field.checked)) 1529 | add($(field).val()) 1530 | }) 1531 | return result 1532 | } 1533 | 1534 | $.fn.serialize = function(){ 1535 | var result = [] 1536 | this.serializeArray().forEach(function(elm){ 1537 | result.push(encodeURIComponent(elm.name) + '=' + encodeURIComponent(elm.value)) 1538 | }) 1539 | return result.join('&') 1540 | } 1541 | 1542 | $.fn.submit = function(callback) { 1543 | if (0 in arguments) this.bind('submit', callback) 1544 | else if (this.length) { 1545 | var event = $.Event('submit') 1546 | this.eq(0).trigger(event) 1547 | if (!event.isDefaultPrevented()) this.get(0).submit() 1548 | } 1549 | return this 1550 | } 1551 | 1552 | })(Zepto) 1553 | 1554 | ;(function($){ 1555 | // __proto__ doesn't exist on IE<11, so redefine 1556 | // the Z function to use object extension instead 1557 | if (!('__proto__' in {})) { 1558 | $.extend($.zepto, { 1559 | Z: function(dom, selector){ 1560 | dom = dom || [] 1561 | $.extend(dom, $.fn) 1562 | dom.selector = selector || '' 1563 | dom.__Z = true 1564 | return dom 1565 | }, 1566 | // this is a kludge but works 1567 | isZ: function(object){ 1568 | return $.type(object) === 'array' && '__Z' in object 1569 | } 1570 | }) 1571 | } 1572 | 1573 | // getComputedStyle shouldn't freak out when called 1574 | // without a valid element as argument 1575 | try { 1576 | getComputedStyle(undefined) 1577 | } catch(e) { 1578 | var nativeGetComputedStyle = getComputedStyle; 1579 | window.getComputedStyle = function(element){ 1580 | try { 1581 | return nativeGetComputedStyle(element) 1582 | } catch(e) { 1583 | return null 1584 | } 1585 | } 1586 | } 1587 | })(Zepto) 1588 | --------------------------------------------------------------------------------