├── README.md ├── crystal_video ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── settings.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── wsgi.cpython-38.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── db.sqlite3 ├── home ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-38.pyc │ ├── admin.cpython-38.pyc │ ├── apps.cpython-38.pyc │ ├── models.cpython-38.pyc │ ├── urls.cpython-38.pyc │ └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── migrations │ ├── __init__.py │ └── __pycache__ │ │ └── __init__.cpython-38.pyc ├── models.py ├── tests.py ├── urls.py └── views.py ├── manage.py ├── media ├── chunked_uploads │ └── 2020 │ │ └── 10 │ │ ├── 23 │ │ ├── 042e48e837c74247bc65429447205002.part │ │ ├── 547351e7a1634286bcf64b62ff6e0daf.part │ │ ├── 6a9a515df6f94868b2f4c4ff39c03060.part │ │ ├── 74f371258c474d02b59262a9c2bb9bab.part │ │ ├── 7b79ab1d76fc4a6b8dc0ae5e799177e4.part │ │ └── a3437cb25eb244228e5d3f9a8c17d52e.part │ │ └── 24 │ │ ├── 2dc77bc267134a3eb160dc2fbca720d8.part │ │ └── f24e7d95835a4c3389411d79b7cc87c1.part └── post_videos │ ├── funny_dog.mp4 │ ├── video1.mp4 │ ├── video2.mp4 │ └── video3.mp4 ├── static ├── css │ └── demo.css └── js │ ├── jquery.fileupload.js │ ├── jquery.iframe-transport.js │ ├── jquery.js │ ├── jquery.ui.widget.js │ └── spark-md5.js ├── stream_server.js ├── templates ├── chunked_upload_demo.html └── home_page.html └── uploader ├── __init__.py ├── __pycache__ ├── __init__.cpython-38.pyc ├── admin.cpython-38.pyc ├── apps.cpython-38.pyc ├── models.cpython-38.pyc ├── urls.cpython-38.pyc ├── utils.cpython-38.pyc └── views.cpython-38.pyc ├── admin.py ├── apps.py ├── migrations ├── 0001_initial.py ├── 0002_remove_videos_identifier.py ├── __init__.py └── __pycache__ │ ├── 0001_initial.cpython-38.pyc │ ├── 0002_remove_videos_identifier.cpython-38.pyc │ └── __init__.cpython-38.pyc ├── models.py ├── tests.py ├── urls.py └── views.py /README.md: -------------------------------------------------------------------------------- 1 | # Crystal_Video 2 | Upload and Stream Video Files to Server (Djano + NodeJS) 3 | 4 | Requirements: 5 | 6 | 1. Django ( https://pypi.org/project/Django/ ) 7 | 2. Django-Chunked-Upload ( https://pypi.org/project/django-chunked-upload/ ) 8 | 3. Node JS ( https://nodejs.org/en/ ) 9 | 10 | 11 | Acknowledgements: 12 | 13 | 1. Chunk-Uplad Demo ( https://github.com/juliomalegria/django-chunked-upload-demo ) 14 | 2. gfs-blogs Stream-Video ( https://github.com/varaprasadh/gfg-blogs ) 15 | 16 | Watch a demonstration (Video) of this work at: 17 | https://youtu.be/PcDcHVq7IIw 18 | -------------------------------------------------------------------------------- /crystal_video/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/crystal_video/__init__.py -------------------------------------------------------------------------------- /crystal_video/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/crystal_video/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /crystal_video/__pycache__/settings.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/crystal_video/__pycache__/settings.cpython-38.pyc -------------------------------------------------------------------------------- /crystal_video/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/crystal_video/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /crystal_video/__pycache__/wsgi.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/crystal_video/__pycache__/wsgi.cpython-38.pyc -------------------------------------------------------------------------------- /crystal_video/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for crystal_video project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crystal_video.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /crystal_video/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for crystal_video project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.0.8. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = '5-kq1)4%53_zoauw0t)3cztpq&7r^fv%b=wa3_4=)p39&o4s=x' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'chunked_upload', 41 | 'home.apps.HomeConfig', 42 | 'uploader.apps.UploaderConfig' 43 | ] 44 | 45 | MIDDLEWARE = [ 46 | 'django.middleware.security.SecurityMiddleware', 47 | 'django.contrib.sessions.middleware.SessionMiddleware', 48 | 'django.middleware.common.CommonMiddleware', 49 | 'django.middleware.csrf.CsrfViewMiddleware', 50 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 51 | 'django.contrib.messages.middleware.MessageMiddleware', 52 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 53 | ] 54 | 55 | ROOT_URLCONF = 'crystal_video.urls' 56 | 57 | TEMPLATES = [ 58 | { 59 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 60 | 'DIRS': [os.path.join(BASE_DIR,'templates')], 61 | 'APP_DIRS': True, 62 | 'OPTIONS': { 63 | 'context_processors': [ 64 | 'django.template.context_processors.debug', 65 | 'django.template.context_processors.request', 66 | 'django.contrib.auth.context_processors.auth', 67 | 'django.contrib.messages.context_processors.messages', 68 | ], 69 | }, 70 | }, 71 | ] 72 | 73 | WSGI_APPLICATION = 'crystal_video.wsgi.application' 74 | 75 | 76 | # Database 77 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 78 | 79 | DATABASES = { 80 | 'default': { 81 | 'ENGINE': 'django.db.backends.sqlite3', 82 | 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 83 | } 84 | } 85 | 86 | 87 | # Password validation 88 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 89 | 90 | AUTH_PASSWORD_VALIDATORS = [ 91 | { 92 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 93 | }, 94 | { 95 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 96 | }, 97 | { 98 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 99 | }, 100 | { 101 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 102 | }, 103 | ] 104 | 105 | 106 | # Internationalization 107 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 108 | 109 | LANGUAGE_CODE = 'en-us' 110 | 111 | TIME_ZONE = 'UTC' 112 | 113 | USE_I18N = True 114 | 115 | USE_L10N = True 116 | 117 | USE_TZ = True 118 | 119 | 120 | # Static files (CSS, JavaScript, Images) 121 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 122 | 123 | STATIC_URL = '/static/' 124 | STATICFILES_DIRS = [ 125 | os.path.join(BASE_DIR, 'static') 126 | ] 127 | 128 | # Dynamic media 129 | 130 | MEDIA_URL = '/media/' 131 | MEDIA_ROOT = os.path.join(BASE_DIR,'media') 132 | 133 | -------------------------------------------------------------------------------- /crystal_video/urls.py: -------------------------------------------------------------------------------- 1 | """crystal_video URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | from django.conf.urls.static import static 19 | from django.conf import settings 20 | 21 | urlpatterns = [ 22 | path('admin/', admin.site.urls), 23 | path('', include('home.urls')), 24 | path('uploader/', include('uploader.urls')) 25 | ] 26 | 27 | urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) 28 | 29 | -------------------------------------------------------------------------------- /crystal_video/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for crystal_video project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crystal_video.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/db.sqlite3 -------------------------------------------------------------------------------- /home/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/__init__.py -------------------------------------------------------------------------------- /home/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /home/__pycache__/admin.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/__pycache__/admin.cpython-38.pyc -------------------------------------------------------------------------------- /home/__pycache__/apps.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/__pycache__/apps.cpython-38.pyc -------------------------------------------------------------------------------- /home/__pycache__/models.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/__pycache__/models.cpython-38.pyc -------------------------------------------------------------------------------- /home/__pycache__/urls.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/__pycache__/urls.cpython-38.pyc -------------------------------------------------------------------------------- /home/__pycache__/views.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/__pycache__/views.cpython-38.pyc -------------------------------------------------------------------------------- /home/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /home/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class HomeConfig(AppConfig): 5 | name = 'home' 6 | -------------------------------------------------------------------------------- /home/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/migrations/__init__.py -------------------------------------------------------------------------------- /home/migrations/__pycache__/__init__.cpython-38.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/home/migrations/__pycache__/__init__.cpython-38.pyc -------------------------------------------------------------------------------- /home/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | -------------------------------------------------------------------------------- /home/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /home/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.home, name = 'home') 6 | ] 7 | -------------------------------------------------------------------------------- /home/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | from django.http import HttpResponse 3 | from uploader.models import Videos 4 | 5 | def home(request): 6 | videos = Videos.objects.all() 7 | return render(request, 'home_page.html', {'videos': videos[::-1]}) 8 | 9 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'crystal_video.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /media/chunked_uploads/2020/10/23/042e48e837c74247bc65429447205002.part: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/chunked_uploads/2020/10/23/042e48e837c74247bc65429447205002.part -------------------------------------------------------------------------------- /media/chunked_uploads/2020/10/23/547351e7a1634286bcf64b62ff6e0daf.part: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/chunked_uploads/2020/10/23/547351e7a1634286bcf64b62ff6e0daf.part -------------------------------------------------------------------------------- /media/chunked_uploads/2020/10/23/6a9a515df6f94868b2f4c4ff39c03060.part: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/chunked_uploads/2020/10/23/6a9a515df6f94868b2f4c4ff39c03060.part -------------------------------------------------------------------------------- /media/chunked_uploads/2020/10/23/74f371258c474d02b59262a9c2bb9bab.part: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/chunked_uploads/2020/10/23/74f371258c474d02b59262a9c2bb9bab.part -------------------------------------------------------------------------------- /media/chunked_uploads/2020/10/23/7b79ab1d76fc4a6b8dc0ae5e799177e4.part: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/chunked_uploads/2020/10/23/7b79ab1d76fc4a6b8dc0ae5e799177e4.part -------------------------------------------------------------------------------- /media/chunked_uploads/2020/10/23/a3437cb25eb244228e5d3f9a8c17d52e.part: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/chunked_uploads/2020/10/23/a3437cb25eb244228e5d3f9a8c17d52e.part -------------------------------------------------------------------------------- /media/chunked_uploads/2020/10/24/2dc77bc267134a3eb160dc2fbca720d8.part: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/chunked_uploads/2020/10/24/2dc77bc267134a3eb160dc2fbca720d8.part -------------------------------------------------------------------------------- /media/chunked_uploads/2020/10/24/f24e7d95835a4c3389411d79b7cc87c1.part: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/chunked_uploads/2020/10/24/f24e7d95835a4c3389411d79b7cc87c1.part -------------------------------------------------------------------------------- /media/post_videos/funny_dog.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/post_videos/funny_dog.mp4 -------------------------------------------------------------------------------- /media/post_videos/video1.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/post_videos/video1.mp4 -------------------------------------------------------------------------------- /media/post_videos/video2.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/post_videos/video2.mp4 -------------------------------------------------------------------------------- /media/post_videos/video3.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SIVGOS/Crystal_Video/76462587eae8dc3e8188b8fa191d28fbaaa76e3c/media/post_videos/video3.mp4 -------------------------------------------------------------------------------- /static/css/demo.css: -------------------------------------------------------------------------------- 1 | html { 2 | margin: 0 auto; 3 | max-width: 1000px; 4 | } 5 | body { 6 | color: #5A5A5A; 7 | font-family: monospace; 8 | font-size: 14px; 9 | } 10 | .title { 11 | text-align: center; 12 | } 13 | -------------------------------------------------------------------------------- /static/js/jquery.fileupload.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery File Upload Plugin 5.42.2 3 | * https://github.com/blueimp/jQuery-File-Upload 4 | * 5 | * Copyright 2010, Sebastian Tschan 6 | * https://blueimp.net 7 | * 8 | * Licensed under the MIT license: 9 | * http://www.opensource.org/licenses/MIT 10 | */ 11 | 12 | /* jshint nomen:false */ 13 | /* global define, require, window, document, location, Blob, FormData */ 14 | 15 | (function (factory) { 16 | 'use strict'; 17 | if (typeof define === 'function' && define.amd) { 18 | // Register as an anonymous AMD module: 19 | define([ 20 | 'jquery', 21 | 'jquery.ui.widget' 22 | ], factory); 23 | } else if (typeof exports === 'object') { 24 | // Node/CommonJS: 25 | factory( 26 | require('jquery'), 27 | require('./vendor/jquery.ui.widget') 28 | ); 29 | } else { 30 | // Browser globals: 31 | factory(window.jQuery); 32 | } 33 | }(function ($) { 34 | 'use strict'; 35 | 36 | // Detect file input support, based on 37 | // http://viljamis.com/blog/2012/file-upload-support-on-mobile/ 38 | $.support.fileInput = !(new RegExp( 39 | // Handle devices which give false positives for the feature detection: 40 | '(Android (1\\.[0156]|2\\.[01]))' + 41 | '|(Windows Phone (OS 7|8\\.0))|(XBLWP)|(ZuneWP)|(WPDesktop)' + 42 | '|(w(eb)?OSBrowser)|(webOS)' + 43 | '|(Kindle/(1\\.0|2\\.[05]|3\\.0))' 44 | ).test(window.navigator.userAgent) || 45 | // Feature detection for all other devices: 46 | $('').prop('disabled')); 47 | 48 | // The FileReader API is not actually used, but works as feature detection, 49 | // as some Safari versions (5?) support XHR file uploads via the FormData API, 50 | // but not non-multipart XHR file uploads. 51 | // window.XMLHttpRequestUpload is not available on IE10, so we check for 52 | // window.ProgressEvent instead to detect XHR2 file upload capability: 53 | $.support.xhrFileUpload = !!(window.ProgressEvent && window.FileReader); 54 | $.support.xhrFormDataFileUpload = !!window.FormData; 55 | 56 | // Detect support for Blob slicing (required for chunked uploads): 57 | $.support.blobSlice = window.Blob && (Blob.prototype.slice || 58 | Blob.prototype.webkitSlice || Blob.prototype.mozSlice); 59 | 60 | // Helper function to create drag handlers for dragover/dragenter/dragleave: 61 | function getDragHandler(type) { 62 | var isDragOver = type === 'dragover'; 63 | return function (e) { 64 | e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; 65 | var dataTransfer = e.dataTransfer; 66 | if (dataTransfer && $.inArray('Files', dataTransfer.types) !== -1 && 67 | this._trigger( 68 | type, 69 | $.Event(type, {delegatedEvent: e}) 70 | ) !== false) { 71 | e.preventDefault(); 72 | if (isDragOver) { 73 | dataTransfer.dropEffect = 'copy'; 74 | } 75 | } 76 | }; 77 | } 78 | 79 | // The fileupload widget listens for change events on file input fields defined 80 | // via fileInput setting and paste or drop events of the given dropZone. 81 | // In addition to the default jQuery Widget methods, the fileupload widget 82 | // exposes the "add" and "send" methods, to add or directly send files using 83 | // the fileupload API. 84 | // By default, files added via file input selection, paste, drag & drop or 85 | // "add" method are uploaded immediately, but it is possible to override 86 | // the "add" callback option to queue file uploads. 87 | $.widget('blueimp.fileupload', { 88 | 89 | options: { 90 | // The drop target element(s), by the default the complete document. 91 | // Set to null to disable drag & drop support: 92 | dropZone: $(document), 93 | // The paste target element(s), by the default undefined. 94 | // Set to a DOM node or jQuery object to enable file pasting: 95 | pasteZone: undefined, 96 | // The file input field(s), that are listened to for change events. 97 | // If undefined, it is set to the file input fields inside 98 | // of the widget element on plugin initialization. 99 | // Set to null to disable the change listener. 100 | fileInput: undefined, 101 | // By default, the file input field is replaced with a clone after 102 | // each input field change event. This is required for iframe transport 103 | // queues and allows change events to be fired for the same file 104 | // selection, but can be disabled by setting the following option to false: 105 | replaceFileInput: true, 106 | // The parameter name for the file form data (the request argument name). 107 | // If undefined or empty, the name property of the file input field is 108 | // used, or "files[]" if the file input name property is also empty, 109 | // can be a string or an array of strings: 110 | paramName: undefined, 111 | // By default, each file of a selection is uploaded using an individual 112 | // request for XHR type uploads. Set to false to upload file 113 | // selections in one request each: 114 | singleFileUploads: true, 115 | // To limit the number of files uploaded with one XHR request, 116 | // set the following option to an integer greater than 0: 117 | limitMultiFileUploads: undefined, 118 | // The following option limits the number of files uploaded with one 119 | // XHR request to keep the request size under or equal to the defined 120 | // limit in bytes: 121 | limitMultiFileUploadSize: undefined, 122 | // Multipart file uploads add a number of bytes to each uploaded file, 123 | // therefore the following option adds an overhead for each file used 124 | // in the limitMultiFileUploadSize configuration: 125 | limitMultiFileUploadSizeOverhead: 512, 126 | // Set the following option to true to issue all file upload requests 127 | // in a sequential order: 128 | sequentialUploads: false, 129 | // To limit the number of concurrent uploads, 130 | // set the following option to an integer greater than 0: 131 | limitConcurrentUploads: undefined, 132 | // Set the following option to true to force iframe transport uploads: 133 | forceIframeTransport: false, 134 | // Set the following option to the location of a redirect url on the 135 | // origin server, for cross-domain iframe transport uploads: 136 | redirect: undefined, 137 | // The parameter name for the redirect url, sent as part of the form 138 | // data and set to 'redirect' if this option is empty: 139 | redirectParamName: undefined, 140 | // Set the following option to the location of a postMessage window, 141 | // to enable postMessage transport uploads: 142 | postMessage: undefined, 143 | // By default, XHR file uploads are sent as multipart/form-data. 144 | // The iframe transport is always using multipart/form-data. 145 | // Set to false to enable non-multipart XHR uploads: 146 | multipart: true, 147 | // To upload large files in smaller chunks, set the following option 148 | // to a preferred maximum chunk size. If set to 0, null or undefined, 149 | // or the browser does not support the required Blob API, files will 150 | // be uploaded as a whole. 151 | maxChunkSize: undefined, 152 | // When a non-multipart upload or a chunked multipart upload has been 153 | // aborted, this option can be used to resume the upload by setting 154 | // it to the size of the already uploaded bytes. This option is most 155 | // useful when modifying the options object inside of the "add" or 156 | // "send" callbacks, as the options are cloned for each file upload. 157 | uploadedBytes: undefined, 158 | // By default, failed (abort or error) file uploads are removed from the 159 | // global progress calculation. Set the following option to false to 160 | // prevent recalculating the global progress data: 161 | recalculateProgress: true, 162 | // Interval in milliseconds to calculate and trigger progress events: 163 | progressInterval: 100, 164 | // Interval in milliseconds to calculate progress bitrate: 165 | bitrateInterval: 500, 166 | // By default, uploads are started automatically when adding files: 167 | autoUpload: true, 168 | 169 | // Error and info messages: 170 | messages: { 171 | uploadedBytes: 'Uploaded bytes exceed file size' 172 | }, 173 | 174 | // Translation function, gets the message key to be translated 175 | // and an object with context specific data as arguments: 176 | i18n: function (message, context) { 177 | message = this.messages[message] || message.toString(); 178 | if (context) { 179 | $.each(context, function (key, value) { 180 | message = message.replace('{' + key + '}', value); 181 | }); 182 | } 183 | return message; 184 | }, 185 | 186 | // Additional form data to be sent along with the file uploads can be set 187 | // using this option, which accepts an array of objects with name and 188 | // value properties, a function returning such an array, a FormData 189 | // object (for XHR file uploads), or a simple object. 190 | // The form of the first fileInput is given as parameter to the function: 191 | formData: function (form) { 192 | return form.serializeArray(); 193 | }, 194 | 195 | // The add callback is invoked as soon as files are added to the fileupload 196 | // widget (via file input selection, drag & drop, paste or add API call). 197 | // If the singleFileUploads option is enabled, this callback will be 198 | // called once for each file in the selection for XHR file uploads, else 199 | // once for each file selection. 200 | // 201 | // The upload starts when the submit method is invoked on the data parameter. 202 | // The data object contains a files property holding the added files 203 | // and allows you to override plugin options as well as define ajax settings. 204 | // 205 | // Listeners for this callback can also be bound the following way: 206 | // .bind('fileuploadadd', func); 207 | // 208 | // data.submit() returns a Promise object and allows to attach additional 209 | // handlers using jQuery's Deferred callbacks: 210 | // data.submit().done(func).fail(func).always(func); 211 | add: function (e, data) { 212 | if (e.isDefaultPrevented()) { 213 | return false; 214 | } 215 | if (data.autoUpload || (data.autoUpload !== false && 216 | $(this).fileupload('option', 'autoUpload'))) { 217 | data.process().done(function () { 218 | data.submit(); 219 | }); 220 | } 221 | }, 222 | 223 | // Other callbacks: 224 | 225 | // Callback for the submit event of each file upload: 226 | // submit: function (e, data) {}, // .bind('fileuploadsubmit', func); 227 | 228 | // Callback for the start of each file upload request: 229 | // send: function (e, data) {}, // .bind('fileuploadsend', func); 230 | 231 | // Callback for successful uploads: 232 | // done: function (e, data) {}, // .bind('fileuploaddone', func); 233 | 234 | // Callback for failed (abort or error) uploads: 235 | // fail: function (e, data) {}, // .bind('fileuploadfail', func); 236 | 237 | // Callback for completed (success, abort or error) requests: 238 | // always: function (e, data) {}, // .bind('fileuploadalways', func); 239 | 240 | // Callback for upload progress events: 241 | // progress: function (e, data) {}, // .bind('fileuploadprogress', func); 242 | 243 | // Callback for global upload progress events: 244 | // progressall: function (e, data) {}, // .bind('fileuploadprogressall', func); 245 | 246 | // Callback for uploads start, equivalent to the global ajaxStart event: 247 | // start: function (e) {}, // .bind('fileuploadstart', func); 248 | 249 | // Callback for uploads stop, equivalent to the global ajaxStop event: 250 | // stop: function (e) {}, // .bind('fileuploadstop', func); 251 | 252 | // Callback for change events of the fileInput(s): 253 | // change: function (e, data) {}, // .bind('fileuploadchange', func); 254 | 255 | // Callback for paste events to the pasteZone(s): 256 | // paste: function (e, data) {}, // .bind('fileuploadpaste', func); 257 | 258 | // Callback for drop events of the dropZone(s): 259 | // drop: function (e, data) {}, // .bind('fileuploaddrop', func); 260 | 261 | // Callback for dragover events of the dropZone(s): 262 | // dragover: function (e) {}, // .bind('fileuploaddragover', func); 263 | 264 | // Callback for the start of each chunk upload request: 265 | // chunksend: function (e, data) {}, // .bind('fileuploadchunksend', func); 266 | 267 | // Callback for successful chunk uploads: 268 | // chunkdone: function (e, data) {}, // .bind('fileuploadchunkdone', func); 269 | 270 | // Callback for failed (abort or error) chunk uploads: 271 | // chunkfail: function (e, data) {}, // .bind('fileuploadchunkfail', func); 272 | 273 | // Callback for completed (success, abort or error) chunk upload requests: 274 | // chunkalways: function (e, data) {}, // .bind('fileuploadchunkalways', func); 275 | 276 | // The plugin options are used as settings object for the ajax calls. 277 | // The following are jQuery ajax settings required for the file uploads: 278 | processData: false, 279 | contentType: false, 280 | cache: false 281 | }, 282 | 283 | // A list of options that require reinitializing event listeners and/or 284 | // special initialization code: 285 | _specialOptions: [ 286 | 'fileInput', 287 | 'dropZone', 288 | 'pasteZone', 289 | 'multipart', 290 | 'forceIframeTransport' 291 | ], 292 | 293 | _blobSlice: $.support.blobSlice && function () { 294 | var slice = this.slice || this.webkitSlice || this.mozSlice; 295 | return slice.apply(this, arguments); 296 | }, 297 | 298 | _BitrateTimer: function () { 299 | this.timestamp = ((Date.now) ? Date.now() : (new Date()).getTime()); 300 | this.loaded = 0; 301 | this.bitrate = 0; 302 | this.getBitrate = function (now, loaded, interval) { 303 | var timeDiff = now - this.timestamp; 304 | if (!this.bitrate || !interval || timeDiff > interval) { 305 | this.bitrate = (loaded - this.loaded) * (1000 / timeDiff) * 8; 306 | this.loaded = loaded; 307 | this.timestamp = now; 308 | } 309 | return this.bitrate; 310 | }; 311 | }, 312 | 313 | _isXHRUpload: function (options) { 314 | return !options.forceIframeTransport && 315 | ((!options.multipart && $.support.xhrFileUpload) || 316 | $.support.xhrFormDataFileUpload); 317 | }, 318 | 319 | _getFormData: function (options) { 320 | var formData; 321 | if ($.type(options.formData) === 'function') { 322 | return options.formData(options.form); 323 | } 324 | if ($.isArray(options.formData)) { 325 | return options.formData; 326 | } 327 | if ($.type(options.formData) === 'object') { 328 | formData = []; 329 | $.each(options.formData, function (name, value) { 330 | formData.push({name: name, value: value}); 331 | }); 332 | return formData; 333 | } 334 | return []; 335 | }, 336 | 337 | _getTotal: function (files) { 338 | var total = 0; 339 | $.each(files, function (index, file) { 340 | total += file.size || 1; 341 | }); 342 | return total; 343 | }, 344 | 345 | _initProgressObject: function (obj) { 346 | var progress = { 347 | loaded: 0, 348 | total: 0, 349 | bitrate: 0 350 | }; 351 | if (obj._progress) { 352 | $.extend(obj._progress, progress); 353 | } else { 354 | obj._progress = progress; 355 | } 356 | }, 357 | 358 | _initResponseObject: function (obj) { 359 | var prop; 360 | if (obj._response) { 361 | for (prop in obj._response) { 362 | if (obj._response.hasOwnProperty(prop)) { 363 | delete obj._response[prop]; 364 | } 365 | } 366 | } else { 367 | obj._response = {}; 368 | } 369 | }, 370 | 371 | _onProgress: function (e, data) { 372 | if (e.lengthComputable) { 373 | var now = ((Date.now) ? Date.now() : (new Date()).getTime()), 374 | loaded; 375 | if (data._time && data.progressInterval && 376 | (now - data._time < data.progressInterval) && 377 | e.loaded !== e.total) { 378 | return; 379 | } 380 | data._time = now; 381 | loaded = Math.floor( 382 | e.loaded / e.total * (data.chunkSize || data._progress.total) 383 | ) + (data.uploadedBytes || 0); 384 | // Add the difference from the previously loaded state 385 | // to the global loaded counter: 386 | this._progress.loaded += (loaded - data._progress.loaded); 387 | this._progress.bitrate = this._bitrateTimer.getBitrate( 388 | now, 389 | this._progress.loaded, 390 | data.bitrateInterval 391 | ); 392 | data._progress.loaded = data.loaded = loaded; 393 | data._progress.bitrate = data.bitrate = data._bitrateTimer.getBitrate( 394 | now, 395 | loaded, 396 | data.bitrateInterval 397 | ); 398 | // Trigger a custom progress event with a total data property set 399 | // to the file size(s) of the current upload and a loaded data 400 | // property calculated accordingly: 401 | this._trigger( 402 | 'progress', 403 | $.Event('progress', {delegatedEvent: e}), 404 | data 405 | ); 406 | // Trigger a global progress event for all current file uploads, 407 | // including ajax calls queued for sequential file uploads: 408 | this._trigger( 409 | 'progressall', 410 | $.Event('progressall', {delegatedEvent: e}), 411 | this._progress 412 | ); 413 | } 414 | }, 415 | 416 | _initProgressListener: function (options) { 417 | var that = this, 418 | xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr(); 419 | // Accesss to the native XHR object is required to add event listeners 420 | // for the upload progress event: 421 | if (xhr.upload) { 422 | $(xhr.upload).bind('progress', function (e) { 423 | var oe = e.originalEvent; 424 | // Make sure the progress event properties get copied over: 425 | e.lengthComputable = oe.lengthComputable; 426 | e.loaded = oe.loaded; 427 | e.total = oe.total; 428 | that._onProgress(e, options); 429 | }); 430 | options.xhr = function () { 431 | return xhr; 432 | }; 433 | } 434 | }, 435 | 436 | _isInstanceOf: function (type, obj) { 437 | // Cross-frame instanceof check 438 | return Object.prototype.toString.call(obj) === '[object ' + type + ']'; 439 | }, 440 | 441 | _initXHRData: function (options) { 442 | var that = this, 443 | formData, 444 | file = options.files[0], 445 | // Ignore non-multipart setting if not supported: 446 | multipart = options.multipart || !$.support.xhrFileUpload, 447 | paramName = $.type(options.paramName) === 'array' ? 448 | options.paramName[0] : options.paramName; 449 | options.headers = $.extend({}, options.headers); 450 | if (options.contentRange) { 451 | options.headers['Content-Range'] = options.contentRange; 452 | } 453 | if (!multipart || options.blob || !this._isInstanceOf('File', file)) { 454 | options.headers['Content-Disposition'] = 'attachment; filename="' + 455 | encodeURI(file.name) + '"'; 456 | } 457 | if (!multipart) { 458 | options.contentType = file.type || 'application/octet-stream'; 459 | options.data = options.blob || file; 460 | } else if ($.support.xhrFormDataFileUpload) { 461 | if (options.postMessage) { 462 | // window.postMessage does not allow sending FormData 463 | // objects, so we just add the File/Blob objects to 464 | // the formData array and let the postMessage window 465 | // create the FormData object out of this array: 466 | formData = this._getFormData(options); 467 | if (options.blob) { 468 | formData.push({ 469 | name: paramName, 470 | value: options.blob 471 | }); 472 | } else { 473 | $.each(options.files, function (index, file) { 474 | formData.push({ 475 | name: ($.type(options.paramName) === 'array' && 476 | options.paramName[index]) || paramName, 477 | value: file 478 | }); 479 | }); 480 | } 481 | } else { 482 | if (that._isInstanceOf('FormData', options.formData)) { 483 | formData = options.formData; 484 | } else { 485 | formData = new FormData(); 486 | $.each(this._getFormData(options), function (index, field) { 487 | formData.append(field.name, field.value); 488 | }); 489 | } 490 | if (options.blob) { 491 | formData.append(paramName, options.blob, file.name); 492 | } else { 493 | $.each(options.files, function (index, file) { 494 | // This check allows the tests to run with 495 | // dummy objects: 496 | if (that._isInstanceOf('File', file) || 497 | that._isInstanceOf('Blob', file)) { 498 | formData.append( 499 | ($.type(options.paramName) === 'array' && 500 | options.paramName[index]) || paramName, 501 | file, 502 | file.uploadName || file.name 503 | ); 504 | } 505 | }); 506 | } 507 | } 508 | options.data = formData; 509 | } 510 | // Blob reference is not needed anymore, free memory: 511 | options.blob = null; 512 | }, 513 | 514 | _initIframeSettings: function (options) { 515 | var targetHost = $('').prop('href', options.url).prop('host'); 516 | // Setting the dataType to iframe enables the iframe transport: 517 | options.dataType = 'iframe ' + (options.dataType || ''); 518 | // The iframe transport accepts a serialized array as form data: 519 | options.formData = this._getFormData(options); 520 | // Add redirect url to form data on cross-domain uploads: 521 | if (options.redirect && targetHost && targetHost !== location.host) { 522 | options.formData.push({ 523 | name: options.redirectParamName || 'redirect', 524 | value: options.redirect 525 | }); 526 | } 527 | }, 528 | 529 | _initDataSettings: function (options) { 530 | if (this._isXHRUpload(options)) { 531 | if (!this._chunkedUpload(options, true)) { 532 | if (!options.data) { 533 | this._initXHRData(options); 534 | } 535 | this._initProgressListener(options); 536 | } 537 | if (options.postMessage) { 538 | // Setting the dataType to postmessage enables the 539 | // postMessage transport: 540 | options.dataType = 'postmessage ' + (options.dataType || ''); 541 | } 542 | } else { 543 | this._initIframeSettings(options); 544 | } 545 | }, 546 | 547 | _getParamName: function (options) { 548 | var fileInput = $(options.fileInput), 549 | paramName = options.paramName; 550 | if (!paramName) { 551 | paramName = []; 552 | fileInput.each(function () { 553 | var input = $(this), 554 | name = input.prop('name') || 'files[]', 555 | i = (input.prop('files') || [1]).length; 556 | while (i) { 557 | paramName.push(name); 558 | i -= 1; 559 | } 560 | }); 561 | if (!paramName.length) { 562 | paramName = [fileInput.prop('name') || 'files[]']; 563 | } 564 | } else if (!$.isArray(paramName)) { 565 | paramName = [paramName]; 566 | } 567 | return paramName; 568 | }, 569 | 570 | _initFormSettings: function (options) { 571 | // Retrieve missing options from the input field and the 572 | // associated form, if available: 573 | if (!options.form || !options.form.length) { 574 | options.form = $(options.fileInput.prop('form')); 575 | // If the given file input doesn't have an associated form, 576 | // use the default widget file input's form: 577 | if (!options.form.length) { 578 | options.form = $(this.options.fileInput.prop('form')); 579 | } 580 | } 581 | options.paramName = this._getParamName(options); 582 | if (!options.url) { 583 | options.url = options.form.prop('action') || location.href; 584 | } 585 | // The HTTP request method must be "POST" or "PUT": 586 | options.type = (options.type || 587 | ($.type(options.form.prop('method')) === 'string' && 588 | options.form.prop('method')) || '' 589 | ).toUpperCase(); 590 | if (options.type !== 'POST' && options.type !== 'PUT' && 591 | options.type !== 'PATCH') { 592 | options.type = 'POST'; 593 | } 594 | if (!options.formAcceptCharset) { 595 | options.formAcceptCharset = options.form.attr('accept-charset'); 596 | } 597 | }, 598 | 599 | _getAJAXSettings: function (data) { 600 | var options = $.extend({}, this.options, data); 601 | this._initFormSettings(options); 602 | this._initDataSettings(options); 603 | return options; 604 | }, 605 | 606 | // jQuery 1.6 doesn't provide .state(), 607 | // while jQuery 1.8+ removed .isRejected() and .isResolved(): 608 | _getDeferredState: function (deferred) { 609 | if (deferred.state) { 610 | return deferred.state(); 611 | } 612 | if (deferred.isResolved()) { 613 | return 'resolved'; 614 | } 615 | if (deferred.isRejected()) { 616 | return 'rejected'; 617 | } 618 | return 'pending'; 619 | }, 620 | 621 | // Maps jqXHR callbacks to the equivalent 622 | // methods of the given Promise object: 623 | _enhancePromise: function (promise) { 624 | promise.success = promise.done; 625 | promise.error = promise.fail; 626 | promise.complete = promise.always; 627 | return promise; 628 | }, 629 | 630 | // Creates and returns a Promise object enhanced with 631 | // the jqXHR methods abort, success, error and complete: 632 | _getXHRPromise: function (resolveOrReject, context, args) { 633 | var dfd = $.Deferred(), 634 | promise = dfd.promise(); 635 | context = context || this.options.context || promise; 636 | if (resolveOrReject === true) { 637 | dfd.resolveWith(context, args); 638 | } else if (resolveOrReject === false) { 639 | dfd.rejectWith(context, args); 640 | } 641 | promise.abort = dfd.promise; 642 | return this._enhancePromise(promise); 643 | }, 644 | 645 | // Adds convenience methods to the data callback argument: 646 | _addConvenienceMethods: function (e, data) { 647 | var that = this, 648 | getPromise = function (args) { 649 | return $.Deferred().resolveWith(that, args).promise(); 650 | }; 651 | data.process = function (resolveFunc, rejectFunc) { 652 | if (resolveFunc || rejectFunc) { 653 | data._processQueue = this._processQueue = 654 | (this._processQueue || getPromise([this])).pipe( 655 | function () { 656 | if (data.errorThrown) { 657 | return $.Deferred() 658 | .rejectWith(that, [data]).promise(); 659 | } 660 | return getPromise(arguments); 661 | } 662 | ).pipe(resolveFunc, rejectFunc); 663 | } 664 | return this._processQueue || getPromise([this]); 665 | }; 666 | data.submit = function () { 667 | if (this.state() !== 'pending') { 668 | data.jqXHR = this.jqXHR = 669 | (that._trigger( 670 | 'submit', 671 | $.Event('submit', {delegatedEvent: e}), 672 | this 673 | ) !== false) && that._onSend(e, this); 674 | } 675 | return this.jqXHR || that._getXHRPromise(); 676 | }; 677 | data.abort = function () { 678 | if (this.jqXHR) { 679 | return this.jqXHR.abort(); 680 | } 681 | this.errorThrown = 'abort'; 682 | that._trigger('fail', null, this); 683 | return that._getXHRPromise(false); 684 | }; 685 | data.state = function () { 686 | if (this.jqXHR) { 687 | return that._getDeferredState(this.jqXHR); 688 | } 689 | if (this._processQueue) { 690 | return that._getDeferredState(this._processQueue); 691 | } 692 | }; 693 | data.processing = function () { 694 | return !this.jqXHR && this._processQueue && that 695 | ._getDeferredState(this._processQueue) === 'pending'; 696 | }; 697 | data.progress = function () { 698 | return this._progress; 699 | }; 700 | data.response = function () { 701 | return this._response; 702 | }; 703 | }, 704 | 705 | // Parses the Range header from the server response 706 | // and returns the uploaded bytes: 707 | _getUploadedBytes: function (jqXHR) { 708 | var range = jqXHR.getResponseHeader('Range'), 709 | parts = range && range.split('-'), 710 | upperBytesPos = parts && parts.length > 1 && 711 | parseInt(parts[1], 10); 712 | return upperBytesPos && upperBytesPos + 1; 713 | }, 714 | 715 | // Uploads a file in multiple, sequential requests 716 | // by splitting the file up in multiple blob chunks. 717 | // If the second parameter is true, only tests if the file 718 | // should be uploaded in chunks, but does not invoke any 719 | // upload requests: 720 | _chunkedUpload: function (options, testOnly) { 721 | options.uploadedBytes = options.uploadedBytes || 0; 722 | var that = this, 723 | file = options.files[0], 724 | fs = file.size, 725 | ub = options.uploadedBytes, 726 | mcs = options.maxChunkSize || fs, 727 | slice = this._blobSlice, 728 | dfd = $.Deferred(), 729 | promise = dfd.promise(), 730 | jqXHR, 731 | upload; 732 | if (!(this._isXHRUpload(options) && slice && (ub || mcs < fs)) || 733 | options.data) { 734 | return false; 735 | } 736 | if (testOnly) { 737 | return true; 738 | } 739 | if (ub >= fs) { 740 | file.error = options.i18n('uploadedBytes'); 741 | return this._getXHRPromise( 742 | false, 743 | options.context, 744 | [null, 'error', file.error] 745 | ); 746 | } 747 | // The chunk upload method: 748 | upload = function () { 749 | // Clone the options object for each chunk upload: 750 | var o = $.extend({}, options), 751 | currentLoaded = o._progress.loaded; 752 | o.blob = slice.call( 753 | file, 754 | ub, 755 | ub + mcs, 756 | file.type 757 | ); 758 | // Store the current chunk size, as the blob itself 759 | // will be dereferenced after data processing: 760 | o.chunkSize = o.blob.size; 761 | // Expose the chunk bytes position range: 762 | o.contentRange = 'bytes ' + ub + '-' + 763 | (ub + o.chunkSize - 1) + '/' + fs; 764 | // Process the upload data (the blob and potential form data): 765 | that._initXHRData(o); 766 | // Add progress listeners for this chunk upload: 767 | that._initProgressListener(o); 768 | jqXHR = ((that._trigger('chunksend', null, o) !== false && $.ajax(o)) || 769 | that._getXHRPromise(false, o.context)) 770 | .done(function (result, textStatus, jqXHR) { 771 | ub = that._getUploadedBytes(jqXHR) || 772 | (ub + o.chunkSize); 773 | // Create a progress event if no final progress event 774 | // with loaded equaling total has been triggered 775 | // for this chunk: 776 | if (currentLoaded + o.chunkSize - o._progress.loaded) { 777 | that._onProgress($.Event('progress', { 778 | lengthComputable: true, 779 | loaded: ub - o.uploadedBytes, 780 | total: ub - o.uploadedBytes 781 | }), o); 782 | } 783 | options.uploadedBytes = o.uploadedBytes = ub; 784 | o.result = result; 785 | o.textStatus = textStatus; 786 | o.jqXHR = jqXHR; 787 | that._trigger('chunkdone', null, o); 788 | that._trigger('chunkalways', null, o); 789 | if (ub < fs) { 790 | // File upload not yet complete, 791 | // continue with the next chunk: 792 | upload(); 793 | } else { 794 | dfd.resolveWith( 795 | o.context, 796 | [result, textStatus, jqXHR] 797 | ); 798 | } 799 | }) 800 | .fail(function (jqXHR, textStatus, errorThrown) { 801 | o.jqXHR = jqXHR; 802 | o.textStatus = textStatus; 803 | o.errorThrown = errorThrown; 804 | that._trigger('chunkfail', null, o); 805 | that._trigger('chunkalways', null, o); 806 | dfd.rejectWith( 807 | o.context, 808 | [jqXHR, textStatus, errorThrown] 809 | ); 810 | }); 811 | }; 812 | this._enhancePromise(promise); 813 | promise.abort = function () { 814 | return jqXHR.abort(); 815 | }; 816 | upload(); 817 | return promise; 818 | }, 819 | 820 | _beforeSend: function (e, data) { 821 | if (this._active === 0) { 822 | // the start callback is triggered when an upload starts 823 | // and no other uploads are currently running, 824 | // equivalent to the global ajaxStart event: 825 | this._trigger('start'); 826 | // Set timer for global bitrate progress calculation: 827 | this._bitrateTimer = new this._BitrateTimer(); 828 | // Reset the global progress values: 829 | this._progress.loaded = this._progress.total = 0; 830 | this._progress.bitrate = 0; 831 | } 832 | // Make sure the container objects for the .response() and 833 | // .progress() methods on the data object are available 834 | // and reset to their initial state: 835 | this._initResponseObject(data); 836 | this._initProgressObject(data); 837 | data._progress.loaded = data.loaded = data.uploadedBytes || 0; 838 | data._progress.total = data.total = this._getTotal(data.files) || 1; 839 | data._progress.bitrate = data.bitrate = 0; 840 | this._active += 1; 841 | // Initialize the global progress values: 842 | this._progress.loaded += data.loaded; 843 | this._progress.total += data.total; 844 | }, 845 | 846 | _onDone: function (result, textStatus, jqXHR, options) { 847 | var total = options._progress.total, 848 | response = options._response; 849 | if (options._progress.loaded < total) { 850 | // Create a progress event if no final progress event 851 | // with loaded equaling total has been triggered: 852 | this._onProgress($.Event('progress', { 853 | lengthComputable: true, 854 | loaded: total, 855 | total: total 856 | }), options); 857 | } 858 | response.result = options.result = result; 859 | response.textStatus = options.textStatus = textStatus; 860 | response.jqXHR = options.jqXHR = jqXHR; 861 | this._trigger('done', null, options); 862 | }, 863 | 864 | _onFail: function (jqXHR, textStatus, errorThrown, options) { 865 | var response = options._response; 866 | if (options.recalculateProgress) { 867 | // Remove the failed (error or abort) file upload from 868 | // the global progress calculation: 869 | this._progress.loaded -= options._progress.loaded; 870 | this._progress.total -= options._progress.total; 871 | } 872 | response.jqXHR = options.jqXHR = jqXHR; 873 | response.textStatus = options.textStatus = textStatus; 874 | response.errorThrown = options.errorThrown = errorThrown; 875 | this._trigger('fail', null, options); 876 | }, 877 | 878 | _onAlways: function (jqXHRorResult, textStatus, jqXHRorError, options) { 879 | // jqXHRorResult, textStatus and jqXHRorError are added to the 880 | // options object via done and fail callbacks 881 | this._trigger('always', null, options); 882 | }, 883 | 884 | _onSend: function (e, data) { 885 | if (!data.submit) { 886 | this._addConvenienceMethods(e, data); 887 | } 888 | var that = this, 889 | jqXHR, 890 | aborted, 891 | slot, 892 | pipe, 893 | options = that._getAJAXSettings(data), 894 | send = function () { 895 | that._sending += 1; 896 | // Set timer for bitrate progress calculation: 897 | options._bitrateTimer = new that._BitrateTimer(); 898 | jqXHR = jqXHR || ( 899 | ((aborted || that._trigger( 900 | 'send', 901 | $.Event('send', {delegatedEvent: e}), 902 | options 903 | ) === false) && 904 | that._getXHRPromise(false, options.context, aborted)) || 905 | that._chunkedUpload(options) || $.ajax(options) 906 | ).done(function (result, textStatus, jqXHR) { 907 | that._onDone(result, textStatus, jqXHR, options); 908 | }).fail(function (jqXHR, textStatus, errorThrown) { 909 | that._onFail(jqXHR, textStatus, errorThrown, options); 910 | }).always(function (jqXHRorResult, textStatus, jqXHRorError) { 911 | that._onAlways( 912 | jqXHRorResult, 913 | textStatus, 914 | jqXHRorError, 915 | options 916 | ); 917 | that._sending -= 1; 918 | that._active -= 1; 919 | if (options.limitConcurrentUploads && 920 | options.limitConcurrentUploads > that._sending) { 921 | // Start the next queued upload, 922 | // that has not been aborted: 923 | var nextSlot = that._slots.shift(); 924 | while (nextSlot) { 925 | if (that._getDeferredState(nextSlot) === 'pending') { 926 | nextSlot.resolve(); 927 | break; 928 | } 929 | nextSlot = that._slots.shift(); 930 | } 931 | } 932 | if (that._active === 0) { 933 | // The stop callback is triggered when all uploads have 934 | // been completed, equivalent to the global ajaxStop event: 935 | that._trigger('stop'); 936 | } 937 | }); 938 | return jqXHR; 939 | }; 940 | this._beforeSend(e, options); 941 | if (this.options.sequentialUploads || 942 | (this.options.limitConcurrentUploads && 943 | this.options.limitConcurrentUploads <= this._sending)) { 944 | if (this.options.limitConcurrentUploads > 1) { 945 | slot = $.Deferred(); 946 | this._slots.push(slot); 947 | pipe = slot.pipe(send); 948 | } else { 949 | this._sequence = this._sequence.pipe(send, send); 950 | pipe = this._sequence; 951 | } 952 | // Return the piped Promise object, enhanced with an abort method, 953 | // which is delegated to the jqXHR object of the current upload, 954 | // and jqXHR callbacks mapped to the equivalent Promise methods: 955 | pipe.abort = function () { 956 | aborted = [undefined, 'abort', 'abort']; 957 | if (!jqXHR) { 958 | if (slot) { 959 | slot.rejectWith(options.context, aborted); 960 | } 961 | return send(); 962 | } 963 | return jqXHR.abort(); 964 | }; 965 | return this._enhancePromise(pipe); 966 | } 967 | return send(); 968 | }, 969 | 970 | _onAdd: function (e, data) { 971 | var that = this, 972 | result = true, 973 | options = $.extend({}, this.options, data), 974 | files = data.files, 975 | filesLength = files.length, 976 | limit = options.limitMultiFileUploads, 977 | limitSize = options.limitMultiFileUploadSize, 978 | overhead = options.limitMultiFileUploadSizeOverhead, 979 | batchSize = 0, 980 | paramName = this._getParamName(options), 981 | paramNameSet, 982 | paramNameSlice, 983 | fileSet, 984 | i, 985 | j = 0; 986 | if (limitSize && (!filesLength || files[0].size === undefined)) { 987 | limitSize = undefined; 988 | } 989 | if (!(options.singleFileUploads || limit || limitSize) || 990 | !this._isXHRUpload(options)) { 991 | fileSet = [files]; 992 | paramNameSet = [paramName]; 993 | } else if (!(options.singleFileUploads || limitSize) && limit) { 994 | fileSet = []; 995 | paramNameSet = []; 996 | for (i = 0; i < filesLength; i += limit) { 997 | fileSet.push(files.slice(i, i + limit)); 998 | paramNameSlice = paramName.slice(i, i + limit); 999 | if (!paramNameSlice.length) { 1000 | paramNameSlice = paramName; 1001 | } 1002 | paramNameSet.push(paramNameSlice); 1003 | } 1004 | } else if (!options.singleFileUploads && limitSize) { 1005 | fileSet = []; 1006 | paramNameSet = []; 1007 | for (i = 0; i < filesLength; i = i + 1) { 1008 | batchSize += files[i].size + overhead; 1009 | if (i + 1 === filesLength || 1010 | ((batchSize + files[i + 1].size + overhead) > limitSize) || 1011 | (limit && i + 1 - j >= limit)) { 1012 | fileSet.push(files.slice(j, i + 1)); 1013 | paramNameSlice = paramName.slice(j, i + 1); 1014 | if (!paramNameSlice.length) { 1015 | paramNameSlice = paramName; 1016 | } 1017 | paramNameSet.push(paramNameSlice); 1018 | j = i + 1; 1019 | batchSize = 0; 1020 | } 1021 | } 1022 | } else { 1023 | paramNameSet = paramName; 1024 | } 1025 | data.originalFiles = files; 1026 | $.each(fileSet || files, function (index, element) { 1027 | var newData = $.extend({}, data); 1028 | newData.files = fileSet ? element : [element]; 1029 | newData.paramName = paramNameSet[index]; 1030 | that._initResponseObject(newData); 1031 | that._initProgressObject(newData); 1032 | that._addConvenienceMethods(e, newData); 1033 | result = that._trigger( 1034 | 'add', 1035 | $.Event('add', {delegatedEvent: e}), 1036 | newData 1037 | ); 1038 | return result; 1039 | }); 1040 | return result; 1041 | }, 1042 | 1043 | _replaceFileInput: function (data) { 1044 | var input = data.fileInput, 1045 | inputClone = input.clone(true); 1046 | // Add a reference for the new cloned file input to the data argument: 1047 | data.fileInputClone = inputClone; 1048 | $('
').append(inputClone)[0].reset(); 1049 | // Detaching allows to insert the fileInput on another form 1050 | // without loosing the file input value: 1051 | input.after(inputClone).detach(); 1052 | // Avoid memory leaks with the detached file input: 1053 | $.cleanData(input.unbind('remove')); 1054 | // Replace the original file input element in the fileInput 1055 | // elements set with the clone, which has been copied including 1056 | // event handlers: 1057 | this.options.fileInput = this.options.fileInput.map(function (i, el) { 1058 | if (el === input[0]) { 1059 | return inputClone[0]; 1060 | } 1061 | return el; 1062 | }); 1063 | // If the widget has been initialized on the file input itself, 1064 | // override this.element with the file input clone: 1065 | if (input[0] === this.element[0]) { 1066 | this.element = inputClone; 1067 | } 1068 | }, 1069 | 1070 | _handleFileTreeEntry: function (entry, path) { 1071 | var that = this, 1072 | dfd = $.Deferred(), 1073 | errorHandler = function (e) { 1074 | if (e && !e.entry) { 1075 | e.entry = entry; 1076 | } 1077 | // Since $.when returns immediately if one 1078 | // Deferred is rejected, we use resolve instead. 1079 | // This allows valid files and invalid items 1080 | // to be returned together in one set: 1081 | dfd.resolve([e]); 1082 | }, 1083 | successHandler = function (entries) { 1084 | that._handleFileTreeEntries( 1085 | entries, 1086 | path + entry.name + '/' 1087 | ).done(function (files) { 1088 | dfd.resolve(files); 1089 | }).fail(errorHandler); 1090 | }, 1091 | readEntries = function () { 1092 | dirReader.readEntries(function (results) { 1093 | if (!results.length) { 1094 | successHandler(entries); 1095 | } else { 1096 | entries = entries.concat(results); 1097 | readEntries(); 1098 | } 1099 | }, errorHandler); 1100 | }, 1101 | dirReader, entries = []; 1102 | path = path || ''; 1103 | if (entry.isFile) { 1104 | if (entry._file) { 1105 | // Workaround for Chrome bug #149735 1106 | entry._file.relativePath = path; 1107 | dfd.resolve(entry._file); 1108 | } else { 1109 | entry.file(function (file) { 1110 | file.relativePath = path; 1111 | dfd.resolve(file); 1112 | }, errorHandler); 1113 | } 1114 | } else if (entry.isDirectory) { 1115 | dirReader = entry.createReader(); 1116 | readEntries(); 1117 | } else { 1118 | // Return an empy list for file system items 1119 | // other than files or directories: 1120 | dfd.resolve([]); 1121 | } 1122 | return dfd.promise(); 1123 | }, 1124 | 1125 | _handleFileTreeEntries: function (entries, path) { 1126 | var that = this; 1127 | return $.when.apply( 1128 | $, 1129 | $.map(entries, function (entry) { 1130 | return that._handleFileTreeEntry(entry, path); 1131 | }) 1132 | ).pipe(function () { 1133 | return Array.prototype.concat.apply( 1134 | [], 1135 | arguments 1136 | ); 1137 | }); 1138 | }, 1139 | 1140 | _getDroppedFiles: function (dataTransfer) { 1141 | dataTransfer = dataTransfer || {}; 1142 | var items = dataTransfer.items; 1143 | if (items && items.length && (items[0].webkitGetAsEntry || 1144 | items[0].getAsEntry)) { 1145 | return this._handleFileTreeEntries( 1146 | $.map(items, function (item) { 1147 | var entry; 1148 | if (item.webkitGetAsEntry) { 1149 | entry = item.webkitGetAsEntry(); 1150 | if (entry) { 1151 | // Workaround for Chrome bug #149735: 1152 | entry._file = item.getAsFile(); 1153 | } 1154 | return entry; 1155 | } 1156 | return item.getAsEntry(); 1157 | }) 1158 | ); 1159 | } 1160 | return $.Deferred().resolve( 1161 | $.makeArray(dataTransfer.files) 1162 | ).promise(); 1163 | }, 1164 | 1165 | _getSingleFileInputFiles: function (fileInput) { 1166 | fileInput = $(fileInput); 1167 | var entries = fileInput.prop('webkitEntries') || 1168 | fileInput.prop('entries'), 1169 | files, 1170 | value; 1171 | if (entries && entries.length) { 1172 | return this._handleFileTreeEntries(entries); 1173 | } 1174 | files = $.makeArray(fileInput.prop('files')); 1175 | if (!files.length) { 1176 | value = fileInput.prop('value'); 1177 | if (!value) { 1178 | return $.Deferred().resolve([]).promise(); 1179 | } 1180 | // If the files property is not available, the browser does not 1181 | // support the File API and we add a pseudo File object with 1182 | // the input value as name with path information removed: 1183 | files = [{name: value.replace(/^.*\\/, '')}]; 1184 | } else if (files[0].name === undefined && files[0].fileName) { 1185 | // File normalization for Safari 4 and Firefox 3: 1186 | $.each(files, function (index, file) { 1187 | file.name = file.fileName; 1188 | file.size = file.fileSize; 1189 | }); 1190 | } 1191 | return $.Deferred().resolve(files).promise(); 1192 | }, 1193 | 1194 | _getFileInputFiles: function (fileInput) { 1195 | if (!(fileInput instanceof $) || fileInput.length === 1) { 1196 | return this._getSingleFileInputFiles(fileInput); 1197 | } 1198 | return $.when.apply( 1199 | $, 1200 | $.map(fileInput, this._getSingleFileInputFiles) 1201 | ).pipe(function () { 1202 | return Array.prototype.concat.apply( 1203 | [], 1204 | arguments 1205 | ); 1206 | }); 1207 | }, 1208 | 1209 | _onChange: function (e) { 1210 | var that = this, 1211 | data = { 1212 | fileInput: $(e.target), 1213 | form: $(e.target.form) 1214 | }; 1215 | this._getFileInputFiles(data.fileInput).always(function (files) { 1216 | data.files = files; 1217 | if (that.options.replaceFileInput) { 1218 | that._replaceFileInput(data); 1219 | } 1220 | if (that._trigger( 1221 | 'change', 1222 | $.Event('change', {delegatedEvent: e}), 1223 | data 1224 | ) !== false) { 1225 | that._onAdd(e, data); 1226 | } 1227 | }); 1228 | }, 1229 | 1230 | _onPaste: function (e) { 1231 | var items = e.originalEvent && e.originalEvent.clipboardData && 1232 | e.originalEvent.clipboardData.items, 1233 | data = {files: []}; 1234 | if (items && items.length) { 1235 | $.each(items, function (index, item) { 1236 | var file = item.getAsFile && item.getAsFile(); 1237 | if (file) { 1238 | data.files.push(file); 1239 | } 1240 | }); 1241 | if (this._trigger( 1242 | 'paste', 1243 | $.Event('paste', {delegatedEvent: e}), 1244 | data 1245 | ) !== false) { 1246 | this._onAdd(e, data); 1247 | } 1248 | } 1249 | }, 1250 | 1251 | _onDrop: function (e) { 1252 | e.dataTransfer = e.originalEvent && e.originalEvent.dataTransfer; 1253 | var that = this, 1254 | dataTransfer = e.dataTransfer, 1255 | data = {}; 1256 | if (dataTransfer && dataTransfer.files && dataTransfer.files.length) { 1257 | e.preventDefault(); 1258 | this._getDroppedFiles(dataTransfer).always(function (files) { 1259 | data.files = files; 1260 | if (that._trigger( 1261 | 'drop', 1262 | $.Event('drop', {delegatedEvent: e}), 1263 | data 1264 | ) !== false) { 1265 | that._onAdd(e, data); 1266 | } 1267 | }); 1268 | } 1269 | }, 1270 | 1271 | _onDragOver: getDragHandler('dragover'), 1272 | 1273 | _onDragEnter: getDragHandler('dragenter'), 1274 | 1275 | _onDragLeave: getDragHandler('dragleave'), 1276 | 1277 | _initEventHandlers: function () { 1278 | if (this._isXHRUpload(this.options)) { 1279 | this._on(this.options.dropZone, { 1280 | dragover: this._onDragOver, 1281 | drop: this._onDrop, 1282 | // event.preventDefault() on dragenter is required for IE10+: 1283 | dragenter: this._onDragEnter, 1284 | // dragleave is not required, but added for completeness: 1285 | dragleave: this._onDragLeave 1286 | }); 1287 | this._on(this.options.pasteZone, { 1288 | paste: this._onPaste 1289 | }); 1290 | } 1291 | if ($.support.fileInput) { 1292 | this._on(this.options.fileInput, { 1293 | change: this._onChange 1294 | }); 1295 | } 1296 | }, 1297 | 1298 | _destroyEventHandlers: function () { 1299 | this._off(this.options.dropZone, 'dragenter dragleave dragover drop'); 1300 | this._off(this.options.pasteZone, 'paste'); 1301 | this._off(this.options.fileInput, 'change'); 1302 | }, 1303 | 1304 | _setOption: function (key, value) { 1305 | var reinit = $.inArray(key, this._specialOptions) !== -1; 1306 | if (reinit) { 1307 | this._destroyEventHandlers(); 1308 | } 1309 | this._super(key, value); 1310 | if (reinit) { 1311 | this._initSpecialOptions(); 1312 | this._initEventHandlers(); 1313 | } 1314 | }, 1315 | 1316 | _initSpecialOptions: function () { 1317 | var options = this.options; 1318 | if (options.fileInput === undefined) { 1319 | options.fileInput = this.element.is('input[type="file"]') ? 1320 | this.element : this.element.find('input[type="file"]'); 1321 | } else if (!(options.fileInput instanceof $)) { 1322 | options.fileInput = $(options.fileInput); 1323 | } 1324 | if (!(options.dropZone instanceof $)) { 1325 | options.dropZone = $(options.dropZone); 1326 | } 1327 | if (!(options.pasteZone instanceof $)) { 1328 | options.pasteZone = $(options.pasteZone); 1329 | } 1330 | }, 1331 | 1332 | _getRegExp: function (str) { 1333 | var parts = str.split('/'), 1334 | modifiers = parts.pop(); 1335 | parts.shift(); 1336 | return new RegExp(parts.join('/'), modifiers); 1337 | }, 1338 | 1339 | _isRegExpOption: function (key, value) { 1340 | return key !== 'url' && $.type(value) === 'string' && 1341 | /^\/.*\/[igm]{0,3}$/.test(value); 1342 | }, 1343 | 1344 | _initDataAttributes: function () { 1345 | var that = this, 1346 | options = this.options, 1347 | clone = $(this.element[0].cloneNode(false)), 1348 | data = clone.data(); 1349 | // Avoid memory leaks: 1350 | clone.remove(); 1351 | // Initialize options set via HTML5 data-attributes: 1352 | $.each( 1353 | data, 1354 | function (key, value) { 1355 | var dataAttributeName = 'data-' + 1356 | // Convert camelCase to hyphen-ated key: 1357 | key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase(); 1358 | if (clone.attr(dataAttributeName)) { 1359 | if (that._isRegExpOption(key, value)) { 1360 | value = that._getRegExp(value); 1361 | } 1362 | options[key] = value; 1363 | } 1364 | } 1365 | ); 1366 | }, 1367 | 1368 | _create: function () { 1369 | this._initDataAttributes(); 1370 | this._initSpecialOptions(); 1371 | this._slots = []; 1372 | this._sequence = this._getXHRPromise(true); 1373 | this._sending = this._active = 0; 1374 | this._initProgressObject(this); 1375 | this._initEventHandlers(); 1376 | }, 1377 | 1378 | // This method is exposed to the widget API and allows to query 1379 | // the number of active uploads: 1380 | active: function () { 1381 | return this._active; 1382 | }, 1383 | 1384 | // This method is exposed to the widget API and allows to query 1385 | // the widget upload progress. 1386 | // It returns an object with loaded, total and bitrate properties 1387 | // for the running uploads: 1388 | progress: function () { 1389 | return this._progress; 1390 | }, 1391 | 1392 | // This method is exposed to the widget API and allows adding files 1393 | // using the fileupload API. The data parameter accepts an object which 1394 | // must have a files property and can contain additional options: 1395 | // .fileupload('add', {files: filesList}); 1396 | add: function (data) { 1397 | var that = this; 1398 | if (!data || this.options.disabled) { 1399 | return; 1400 | } 1401 | if (data.fileInput && !data.files) { 1402 | this._getFileInputFiles(data.fileInput).always(function (files) { 1403 | data.files = files; 1404 | that._onAdd(null, data); 1405 | }); 1406 | } else { 1407 | data.files = $.makeArray(data.files); 1408 | this._onAdd(null, data); 1409 | } 1410 | }, 1411 | 1412 | // This method is exposed to the widget API and allows sending files 1413 | // using the fileupload API. The data parameter accepts an object which 1414 | // must have a files or fileInput property and can contain additional options: 1415 | // .fileupload('send', {files: filesList}); 1416 | // The method returns a Promise object for the file upload call. 1417 | send: function (data) { 1418 | if (data && !this.options.disabled) { 1419 | if (data.fileInput && !data.files) { 1420 | var that = this, 1421 | dfd = $.Deferred(), 1422 | promise = dfd.promise(), 1423 | jqXHR, 1424 | aborted; 1425 | promise.abort = function () { 1426 | aborted = true; 1427 | if (jqXHR) { 1428 | return jqXHR.abort(); 1429 | } 1430 | dfd.reject(null, 'abort', 'abort'); 1431 | return promise; 1432 | }; 1433 | this._getFileInputFiles(data.fileInput).always( 1434 | function (files) { 1435 | if (aborted) { 1436 | return; 1437 | } 1438 | if (!files.length) { 1439 | dfd.reject(); 1440 | return; 1441 | } 1442 | data.files = files; 1443 | jqXHR = that._onSend(null, data); 1444 | jqXHR.then( 1445 | function (result, textStatus, jqXHR) { 1446 | dfd.resolve(result, textStatus, jqXHR); 1447 | }, 1448 | function (jqXHR, textStatus, errorThrown) { 1449 | dfd.reject(jqXHR, textStatus, errorThrown); 1450 | } 1451 | ); 1452 | } 1453 | ); 1454 | return this._enhancePromise(promise); 1455 | } 1456 | data.files = $.makeArray(data.files); 1457 | if (data.files.length) { 1458 | return this._onSend(null, data); 1459 | } 1460 | } 1461 | return this._getXHRPromise(false, data && data.context); 1462 | } 1463 | 1464 | }); 1465 | 1466 | })); 1467 | -------------------------------------------------------------------------------- /static/js/jquery.iframe-transport.js: -------------------------------------------------------------------------------- 1 | /* 2 | * jQuery Iframe Transport Plugin 1.8.3 3 | * https://github.com/blueimp/jQuery-File-Upload 4 | * 5 | * Copyright 2011, Sebastian Tschan 6 | * https://blueimp.net 7 | * 8 | * Licensed under the MIT license: 9 | * http://www.opensource.org/licenses/MIT 10 | */ 11 | 12 | /* global define, require, window, document */ 13 | 14 | (function (factory) { 15 | 'use strict'; 16 | if (typeof define === 'function' && define.amd) { 17 | // Register as an anonymous AMD module: 18 | define(['jquery'], factory); 19 | } else if (typeof exports === 'object') { 20 | // Node/CommonJS: 21 | factory(require('jquery')); 22 | } else { 23 | // Browser globals: 24 | factory(window.jQuery); 25 | } 26 | }(function ($) { 27 | 'use strict'; 28 | 29 | // Helper variable to create unique names for the transport iframes: 30 | var counter = 0; 31 | 32 | // The iframe transport accepts four additional options: 33 | // options.fileInput: a jQuery collection of file input fields 34 | // options.paramName: the parameter name for the file form data, 35 | // overrides the name property of the file input field(s), 36 | // can be a string or an array of strings. 37 | // options.formData: an array of objects with name and value properties, 38 | // equivalent to the return data of .serializeArray(), e.g.: 39 | // [{name: 'a', value: 1}, {name: 'b', value: 2}] 40 | // options.initialIframeSrc: the URL of the initial iframe src, 41 | // by default set to "javascript:false;" 42 | $.ajaxTransport('iframe', function (options) { 43 | if (options.async) { 44 | // javascript:false as initial iframe src 45 | // prevents warning popups on HTTPS in IE6: 46 | /*jshint scripturl: true */ 47 | var initialIframeSrc = options.initialIframeSrc || 'javascript:false;', 48 | /*jshint scripturl: false */ 49 | form, 50 | iframe, 51 | addParamChar; 52 | return { 53 | send: function (_, completeCallback) { 54 | form = $(''); 55 | form.attr('accept-charset', options.formAcceptCharset); 56 | addParamChar = /\?/.test(options.url) ? '&' : '?'; 57 | // XDomainRequest only supports GET and POST: 58 | if (options.type === 'DELETE') { 59 | options.url = options.url + addParamChar + '_method=DELETE'; 60 | options.type = 'POST'; 61 | } else if (options.type === 'PUT') { 62 | options.url = options.url + addParamChar + '_method=PUT'; 63 | options.type = 'POST'; 64 | } else if (options.type === 'PATCH') { 65 | options.url = options.url + addParamChar + '_method=PATCH'; 66 | options.type = 'POST'; 67 | } 68 | // IE versions below IE8 cannot set the name property of 69 | // elements that have already been added to the DOM, 70 | // so we set the name along with the iframe HTML markup: 71 | counter += 1; 72 | iframe = $( 73 | '' 75 | ).bind('load', function () { 76 | var fileInputClones, 77 | paramNames = $.isArray(options.paramName) ? 78 | options.paramName : [options.paramName]; 79 | iframe 80 | .unbind('load') 81 | .bind('load', function () { 82 | var response; 83 | // Wrap in a try/catch block to catch exceptions thrown 84 | // when trying to access cross-domain iframe contents: 85 | try { 86 | response = iframe.contents(); 87 | // Google Chrome and Firefox do not throw an 88 | // exception when calling iframe.contents() on 89 | // cross-domain requests, so we unify the response: 90 | if (!response.length || !response[0].firstChild) { 91 | throw new Error(); 92 | } 93 | } catch (e) { 94 | response = undefined; 95 | } 96 | // The complete callback returns the 97 | // iframe content document as response object: 98 | completeCallback( 99 | 200, 100 | 'success', 101 | {'iframe': response} 102 | ); 103 | // Fix for IE endless progress bar activity bug 104 | // (happens on form submits to iframe targets): 105 | $('') 106 | .appendTo(form); 107 | window.setTimeout(function () { 108 | // Removing the form in a setTimeout call 109 | // allows Chrome's developer tools to display 110 | // the response result 111 | form.remove(); 112 | }, 0); 113 | }); 114 | form 115 | .prop('target', iframe.prop('name')) 116 | .prop('action', options.url) 117 | .prop('method', options.type); 118 | if (options.formData) { 119 | $.each(options.formData, function (index, field) { 120 | $('') 121 | .prop('name', field.name) 122 | .val(field.value) 123 | .appendTo(form); 124 | }); 125 | } 126 | if (options.fileInput && options.fileInput.length && 127 | options.type === 'POST') { 128 | fileInputClones = options.fileInput.clone(); 129 | // Insert a clone for each file input field: 130 | options.fileInput.after(function (index) { 131 | return fileInputClones[index]; 132 | }); 133 | if (options.paramName) { 134 | options.fileInput.each(function (index) { 135 | $(this).prop( 136 | 'name', 137 | paramNames[index] || options.paramName 138 | ); 139 | }); 140 | } 141 | // Appending the file input fields to the hidden form 142 | // removes them from their original location: 143 | form 144 | .append(options.fileInput) 145 | .prop('enctype', 'multipart/form-data') 146 | // enctype must be set as encoding for IE: 147 | .prop('encoding', 'multipart/form-data'); 148 | // Remove the HTML5 form attribute from the input(s): 149 | options.fileInput.removeAttr('form'); 150 | } 151 | form.submit(); 152 | // Insert the file input fields at their original location 153 | // by replacing the clones with the originals: 154 | if (fileInputClones && fileInputClones.length) { 155 | options.fileInput.each(function (index, input) { 156 | var clone = $(fileInputClones[index]); 157 | // Restore the original name and form properties: 158 | $(input) 159 | .prop('name', clone.prop('name')) 160 | .attr('form', clone.attr('form')); 161 | clone.replaceWith(input); 162 | }); 163 | } 164 | }); 165 | form.append(iframe).appendTo(document.body); 166 | }, 167 | abort: function () { 168 | if (iframe) { 169 | // javascript:false as iframe src aborts the request 170 | // and prevents warning popups on HTTPS in IE6. 171 | // concat is used to avoid the "Script URL" JSLint error: 172 | iframe 173 | .unbind('load') 174 | .prop('src', initialIframeSrc); 175 | } 176 | if (form) { 177 | form.remove(); 178 | } 179 | } 180 | }; 181 | } 182 | }); 183 | 184 | // The iframe transport returns the iframe content document as response. 185 | // The following adds converters from iframe to text, json, html, xml 186 | // and script. 187 | // Please note that the Content-Type for JSON responses has to be text/plain 188 | // or text/html, if the browser doesn't include application/json in the 189 | // Accept header, else IE will show a download dialog. 190 | // The Content-Type for XML responses on the other hand has to be always 191 | // application/xml or text/xml, so IE properly parses the XML response. 192 | // See also 193 | // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation 194 | $.ajaxSetup({ 195 | converters: { 196 | 'iframe text': function (iframe) { 197 | return iframe && $(iframe[0].body).text(); 198 | }, 199 | 'iframe json': function (iframe) { 200 | return iframe && $.parseJSON($(iframe[0].body).text()); 201 | }, 202 | 'iframe html': function (iframe) { 203 | return iframe && $(iframe[0].body).html(); 204 | }, 205 | 'iframe xml': function (iframe) { 206 | var xmlDoc = iframe && iframe[0]; 207 | return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc : 208 | $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) || 209 | $(xmlDoc.body).html()); 210 | }, 211 | 'iframe script': function (iframe) { 212 | return iframe && $.globalEval($(iframe[0].body).text()); 213 | } 214 | } 215 | }); 216 | 217 | })); 218 | -------------------------------------------------------------------------------- /static/js/jquery.js: -------------------------------------------------------------------------------- 1 | /*! jQuery v1.11.2 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ 2 | !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.2",m=function(a,b){return new m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b){return b.toUpperCase()};m.fn=m.prototype={jquery:l,constructor:m,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=m.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return m.each(this,a,b)},map:function(a){return this.pushStack(m.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},m.extend=m.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||m.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&&(j&&c&&(m.isPlainObject(c)||(b=m.isArray(c)))?(b?(b=!1,f=a&&m.isArray(a)?a:[]):f=a&&m.isPlainObject(a)?a:{},g[d]=m.extend(j,f,c)):void 0!==c&&(g[d]=c));return g},m.extend({expando:"jQuery"+(l+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===m.type(a)},isArray:Array.isArray||function(a){return"array"===m.type(a)},isWindow:function(a){return null!=a&&a==a.window},isNumeric:function(a){return!m.isArray(a)&&a-parseFloat(a)+1>=0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},isPlainObject:function(a){var b;if(!a||"object"!==m.type(a)||a.nodeType||m.isWindow(a))return!1;try{if(a.constructor&&!j.call(a,"constructor")&&!j.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}if(k.ownLast)for(b in a)return j.call(a,b);for(b in a);return void 0===b||j.call(a,b)},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(b){b&&m.trim(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(o,"ms-").replace(p,q)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=r(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(n,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(r(Object(a))?m.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){var d;if(b){if(g)return g.call(b,a,c);for(d=b.length,c=c?0>c?Math.max(0,d+c):c:0;d>c;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,b){var c=+b.length,d=0,e=a.length;while(c>d)a[e++]=b[d++];if(c!==c)while(void 0!==b[d])a[e++]=b[d++];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=r(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(f=a[b],b=a,a=f),m.isFunction(a)?(c=d.call(arguments,2),e=function(){return a.apply(b||this,c.concat(d.call(arguments)))},e.guid=a.guid=a.guid||m.guid++,e):void 0},now:function(){return+new Date},support:k}),m.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function r(a){var b=a.length,c=m.type(a);return"function"===c||m.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var s=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+1*new Date,v=a.document,w=0,x=0,y=hb(),z=hb(),A=hb(),B=function(a,b){return a===b&&(l=!0),0},C=1<<31,D={}.hasOwnProperty,E=[],F=E.pop,G=E.push,H=E.push,I=E.slice,J=function(a,b){for(var c=0,d=a.length;d>c;c++)if(a[c]===b)return c;return-1},K="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",L="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",N=M.replace("w","w#"),O="\\["+L+"*("+M+")(?:"+L+"*([*^$|!~]?=)"+L+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+N+"))|)"+L+"*\\]",P=":("+M+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+O+")*)|.*)\\)|)",Q=new RegExp(L+"+","g"),R=new RegExp("^"+L+"+|((?:^|[^\\\\])(?:\\\\.)*)"+L+"+$","g"),S=new RegExp("^"+L+"*,"+L+"*"),T=new RegExp("^"+L+"*([>+~]|"+L+")"+L+"*"),U=new RegExp("="+L+"*([^\\]'\"]*?)"+L+"*\\]","g"),V=new RegExp(P),W=new RegExp("^"+N+"$"),X={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+O),PSEUDO:new RegExp("^"+P),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+L+"*(even|odd|(([+-]|)(\\d*)n|)"+L+"*(?:([+-]|)"+L+"*(\\d+)|))"+L+"*\\)|)","i"),bool:new RegExp("^(?:"+K+")$","i"),needsContext:new RegExp("^"+L+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+L+"*((?:-\\d)?\\d*)"+L+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+L+"?|("+L+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)},eb=function(){m()};try{H.apply(E=I.call(v.childNodes),v.childNodes),E[v.childNodes.length].nodeType}catch(fb){H={apply:E.length?function(a,b){G.apply(a,I.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function gb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],k=b.nodeType,"string"!=typeof a||!a||1!==k&&9!==k&&11!==k)return d;if(!e&&p){if(11!==k&&(f=_.exec(a)))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return H.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName)return H.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=1!==k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+rb(o[l]);w=ab.test(a)&&pb(b.parentNode)||b,x=o.join(",")}if(x)try{return H.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function hb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function ib(a){return a[u]=!0,a}function jb(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function kb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function lb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||C)-(~a.sourceIndex||C);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function nb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function ob(a){return ib(function(b){return b=+b,ib(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function pb(a){return a&&"undefined"!=typeof a.getElementsByTagName&&a}c=gb.support={},f=gb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=gb.setDocument=function(a){var b,e,g=a?a.ownerDocument||a:v;return g!==n&&9===g.nodeType&&g.documentElement?(n=g,o=g.documentElement,e=g.defaultView,e&&e!==e.top&&(e.addEventListener?e.addEventListener("unload",eb,!1):e.attachEvent&&e.attachEvent("onunload",eb)),p=!f(g),c.attributes=jb(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=jb(function(a){return a.appendChild(g.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(g.getElementsByClassName),c.getById=jb(function(a){return o.appendChild(a).id=u,!g.getElementsByName||!g.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if("undefined"!=typeof b.getElementById&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c="undefined"!=typeof a.getAttributeNode&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return"undefined"!=typeof b.getElementsByTagName?b.getElementsByTagName(a):c.qsa?b.querySelectorAll(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(g.querySelectorAll))&&(jb(function(a){o.appendChild(a).innerHTML="",a.querySelectorAll("[msallowcapture^='']").length&&q.push("[*^$]="+L+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+L+"*(?:value|"+K+")"),a.querySelectorAll("[id~="+u+"-]").length||q.push("~="),a.querySelectorAll(":checked").length||q.push(":checked"),a.querySelectorAll("a#"+u+"+*").length||q.push(".#.+[+~]")}),jb(function(a){var b=g.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+L+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&jb(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",P)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===g||a.ownerDocument===v&&t(v,a)?-1:b===g||b.ownerDocument===v&&t(v,b)?1:k?J(k,a)-J(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,e=a.parentNode,f=b.parentNode,h=[a],i=[b];if(!e||!f)return a===g?-1:b===g?1:e?-1:f?1:k?J(k,a)-J(k,b):0;if(e===f)return lb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?lb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},g):n},gb.matches=function(a,b){return gb(a,null,null,b)},gb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return gb(b,n,null,[a]).length>0},gb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},gb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&D.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},gb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},gb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=gb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=gb.selectors={cacheLength:50,createPseudo:ib,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||gb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&gb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+L+")"+a+"("+L+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||"undefined"!=typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=gb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e.replace(Q," ")+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||gb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?ib(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=J(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:ib(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?ib(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),b[0]=null,!c.pop()}}),has:ib(function(a){return function(b){return gb(a,b).length>0}}),contains:ib(function(a){return a=a.replace(cb,db),function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:ib(function(a){return W.test(a||"")||gb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:ob(function(){return[0]}),last:ob(function(a,b){return[b-1]}),eq:ob(function(a,b,c){return[0>c?c+b:c]}),even:ob(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:ob(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:ob(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:ob(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function sb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function tb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function ub(a,b,c){for(var d=0,e=b.length;e>d;d++)gb(a,b[d],c);return c}function vb(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function wb(a,b,c,d,e,f){return d&&!d[u]&&(d=wb(d)),e&&!e[u]&&(e=wb(e,f)),ib(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||ub(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:vb(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=vb(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?J(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=vb(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):H.apply(g,r)})}function xb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=sb(function(a){return a===b},h,!0),l=sb(function(a){return J(b,a)>-1},h,!0),m=[function(a,c,d){var e=!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d));return b=null,e}];f>i;i++)if(c=d.relative[a[i].type])m=[sb(tb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return wb(i>1&&tb(m),i>1&&rb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&xb(a.slice(i,e)),f>e&&xb(a=a.slice(e)),f>e&&rb(a))}m.push(c)}return tb(m)}function yb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=F.call(i));s=vb(s)}H.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&gb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?ib(f):f}return h=gb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=xb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,yb(e,d)),f.selector=a}return f},i=gb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&pb(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&rb(j),!a)return H.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&pb(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=jb(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),jb(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||kb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&jb(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||kb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),jb(function(a){return null==a.getAttribute("disabled")})||kb(K,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),gb}(a);m.find=s,m.expr=s.selectors,m.expr[":"]=m.expr.pseudos,m.unique=s.uniqueSort,m.text=s.getText,m.isXMLDoc=s.isXML,m.contains=s.contains;var t=m.expr.match.needsContext,u=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,v=/^.[^:#\[\.,]*$/;function w(a,b,c){if(m.isFunction(b))return m.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return m.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(v.test(b))return m.filter(b,a,c);b=m.filter(b,a)}return m.grep(a,function(a){return m.inArray(a,b)>=0!==c})}m.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?m.find.matchesSelector(d,a)?[d]:[]:m.find.matches(a,m.grep(b,function(a){return 1===a.nodeType}))},m.fn.extend({find:function(a){var b,c=[],d=this,e=d.length;if("string"!=typeof a)return this.pushStack(m(a).filter(function(){for(b=0;e>b;b++)if(m.contains(d[b],this))return!0}));for(b=0;e>b;b++)m.find(a,d[b],c);return c=this.pushStack(e>1?m.unique(c):c),c.selector=this.selector?this.selector+" "+a:a,c},filter:function(a){return this.pushStack(w(this,a||[],!1))},not:function(a){return this.pushStack(w(this,a||[],!0))},is:function(a){return!!w(this,"string"==typeof a&&t.test(a)?m(a):a||[],!1).length}});var x,y=a.document,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=m.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a.charAt(0)&&">"===a.charAt(a.length-1)&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||x).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof m?b[0]:b,m.merge(this,m.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:y,!0)),u.test(c[1])&&m.isPlainObject(b))for(c in b)m.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}if(d=y.getElementById(c[2]),d&&d.parentNode){if(d.id!==c[2])return x.find(a);this.length=1,this[0]=d}return this.context=y,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):m.isFunction(a)?"undefined"!=typeof x.ready?x.ready(a):a(m):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),m.makeArray(a,this))};A.prototype=m.fn,x=m(y);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};m.extend({dir:function(a,b,c){var d=[],e=a[b];while(e&&9!==e.nodeType&&(void 0===c||1!==e.nodeType||!m(e).is(c)))1===e.nodeType&&d.push(e),e=e[b];return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),m.fn.extend({has:function(a){var b,c=m(a,this),d=c.length;return this.filter(function(){for(b=0;d>b;b++)if(m.contains(this,c[b]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=t.test(a)||"string"!=typeof a?m(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&m.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?m.unique(f):f)},index:function(a){return a?"string"==typeof a?m.inArray(this[0],m(a)):m.inArray(a.jquery?a[0]:a,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(m.unique(m.merge(this.get(),m(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){do a=a[b];while(a&&1!==a.nodeType);return a}m.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return m.dir(a,"parentNode")},parentsUntil:function(a,b,c){return m.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return m.dir(a,"nextSibling")},prevAll:function(a){return m.dir(a,"previousSibling")},nextUntil:function(a,b,c){return m.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return m.dir(a,"previousSibling",c)},siblings:function(a){return m.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return m.sibling(a.firstChild)},contents:function(a){return m.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:m.merge([],a.childNodes)}},function(a,b){m.fn[a]=function(c,d){var e=m.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=m.filter(d,e)),this.length>1&&(C[a]||(e=m.unique(e)),B.test(a)&&(e=e.reverse())),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return m.each(a.match(E)||[],function(a,c){b[c]=!0}),b}m.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):m.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(c=a.memory&&l,d=!0,f=g||0,g=0,e=h.length,b=!0;h&&e>f;f++)if(h[f].apply(l[0],l[1])===!1&&a.stopOnFalse){c=!1;break}b=!1,h&&(i?i.length&&j(i.shift()):c?h=[]:k.disable())},k={add:function(){if(h){var d=h.length;!function f(b){m.each(b,function(b,c){var d=m.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=h.length:c&&(g=d,j(c))}return this},remove:function(){return h&&m.each(arguments,function(a,c){var d;while((d=m.inArray(c,h,d))>-1)h.splice(d,1),b&&(e>=d&&e--,f>=d&&f--)}),this},has:function(a){return a?m.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],e=0,this},disable:function(){return h=i=c=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,c||k.disable(),this},locked:function(){return!i},fireWith:function(a,c){return!h||d&&!i||(c=c||[],c=[a,c.slice?c.slice():c],b?i.push(c):j(c)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!d}};return k},m.extend({Deferred:function(a){var b=[["resolve","done",m.Callbacks("once memory"),"resolved"],["reject","fail",m.Callbacks("once memory"),"rejected"],["notify","progress",m.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return m.Deferred(function(c){m.each(b,function(b,f){var g=m.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&m.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?m.extend(a,d):d}},e={};return d.pipe=d.then,m.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&m.isFunction(a.promise)?e:0,g=1===f?a:m.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&m.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;m.fn.ready=function(a){return m.ready.promise().done(a),this},m.extend({isReady:!1,readyWait:1,holdReady:function(a){a?m.readyWait++:m.ready(!0)},ready:function(a){if(a===!0?!--m.readyWait:!m.isReady){if(!y.body)return setTimeout(m.ready);m.isReady=!0,a!==!0&&--m.readyWait>0||(H.resolveWith(y,[m]),m.fn.triggerHandler&&(m(y).triggerHandler("ready"),m(y).off("ready")))}}});function I(){y.addEventListener?(y.removeEventListener("DOMContentLoaded",J,!1),a.removeEventListener("load",J,!1)):(y.detachEvent("onreadystatechange",J),a.detachEvent("onload",J))}function J(){(y.addEventListener||"load"===event.type||"complete"===y.readyState)&&(I(),m.ready())}m.ready.promise=function(b){if(!H)if(H=m.Deferred(),"complete"===y.readyState)setTimeout(m.ready);else if(y.addEventListener)y.addEventListener("DOMContentLoaded",J,!1),a.addEventListener("load",J,!1);else{y.attachEvent("onreadystatechange",J),a.attachEvent("onload",J);var c=!1;try{c=null==a.frameElement&&y.documentElement}catch(d){}c&&c.doScroll&&!function e(){if(!m.isReady){try{c.doScroll("left")}catch(a){return setTimeout(e,50)}I(),m.ready()}}()}return H.promise(b)};var K="undefined",L;for(L in m(k))break;k.ownLast="0"!==L,k.inlineBlockNeedsLayout=!1,m(function(){var a,b,c,d;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1",k.inlineBlockNeedsLayout=a=3===b.offsetWidth,a&&(c.style.zoom=1)),c.removeChild(d))}),function(){var a=y.createElement("div");if(null==k.deleteExpando){k.deleteExpando=!0;try{delete a.test}catch(b){k.deleteExpando=!1}}a=null}(),m.acceptData=function(a){var b=m.noData[(a.nodeName+" ").toLowerCase()],c=+a.nodeType||1;return 1!==c&&9!==c?!1:!b||b!==!0&&a.getAttribute("classid")===b};var M=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,N=/([A-Z])/g;function O(a,b,c){if(void 0===c&&1===a.nodeType){var d="data-"+b.replace(N,"-$1").toLowerCase();if(c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:M.test(c)?m.parseJSON(c):c}catch(e){}m.data(a,b,c)}else c=void 0}return c}function P(a){var b;for(b in a)if(("data"!==b||!m.isEmptyObject(a[b]))&&"toJSON"!==b)return!1; 3 | return!0}function Q(a,b,d,e){if(m.acceptData(a)){var f,g,h=m.expando,i=a.nodeType,j=i?m.cache:a,k=i?a[h]:a[h]&&h;if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof b||"function"==typeof b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[m.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function R(a,b,c){if(m.acceptData(a)){var d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){m.isArray(b)?b=b.concat(m.map(b,m.camelCase)):b in d?b=[b]:(b=m.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e--)delete d[b[e]];if(c?!P(d):!m.isEmptyObject(d))return}(c||(delete g[h].data,P(g[h])))&&(f?m.cleanData([a],!0):k.deleteExpando||g!=g.window?delete g[h]:g[h]=null)}}}m.extend({cache:{},noData:{"applet ":!0,"embed ":!0,"object ":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(a){return a=a.nodeType?m.cache[a[m.expando]]:a[m.expando],!!a&&!P(a)},data:function(a,b,c){return Q(a,b,c)},removeData:function(a,b){return R(a,b)},_data:function(a,b,c){return Q(a,b,c,!0)},_removeData:function(a,b){return R(a,b,!0)}}),m.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=m.data(f),1===f.nodeType&&!m._data(f,"parsedAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=m.camelCase(d.slice(5)),O(f,d,e[d])));m._data(f,"parsedAttrs",!0)}return e}return"object"==typeof a?this.each(function(){m.data(this,a)}):arguments.length>1?this.each(function(){m.data(this,a,b)}):f?O(f,a,m.data(f,a)):void 0},removeData:function(a){return this.each(function(){m.removeData(this,a)})}}),m.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=m._data(a,b),c&&(!d||m.isArray(c)?d=m._data(a,b,m.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=m.queue(a,b),d=c.length,e=c.shift(),f=m._queueHooks(a,b),g=function(){m.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return m._data(a,c)||m._data(a,c,{empty:m.Callbacks("once memory").add(function(){m._removeData(a,b+"queue"),m._removeData(a,c)})})}}),m.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.length| t |