kms 0.9.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{vendor/assets/bower_components/Responsive-Dashboard/src/img → app/assets/images}/avatar.jpg +0 -0
- data/app/assets/javascripts/kms/application.js +3 -0
- data/app/assets/javascripts/kms/application/controllers/assets_controller.coffee.erb +14 -7
- data/app/assets/javascripts/kms/application/controllers/pages_controller.coffee.erb +11 -3
- data/app/assets/javascripts/kms/application/controllers/snippets_controller.coffee.erb +3 -0
- data/app/assets/javascripts/kms/application/controllers/templates_controller.coffee.erb +3 -0
- data/app/assets/javascripts/kms/application/controllers/users_controller.coffee +4 -4
- data/app/assets/javascripts/kms/application/routes.coffee.erb +1 -1
- data/app/assets/javascripts/kms/application/services/transliteration_service.js +160 -0
- data/app/assets/javascripts/templates/assets/edit.html.slim +24 -2
- data/app/assets/javascripts/templates/assets/form.html.slim +23 -0
- data/app/assets/javascripts/templates/assets/index.html.slim +13 -12
- data/app/assets/javascripts/templates/assets/new.html.slim +1 -15
- data/app/assets/javascripts/templates/help.html.slim +1 -1
- data/app/assets/javascripts/templates/pages/index.html.slim +16 -5
- data/app/assets/javascripts/templates/snippets/index.html.slim +16 -5
- data/app/assets/javascripts/templates/templates/index.html.slim +16 -6
- data/app/assets/stylesheets/kms/application.css +2 -2
- data/app/assets/stylesheets/kms/custom.css.scss +38 -0
- data/app/controllers/kms/assets_controller.rb +8 -9
- data/app/controllers/kms/pages_controller.rb +10 -11
- data/app/controllers/kms/public/pages_controller.rb +5 -4
- data/app/controllers/kms/public/search_controller.rb +2 -0
- data/app/controllers/kms/settings_controller.rb +1 -1
- data/app/controllers/kms/snippets_controller.rb +2 -1
- data/app/controllers/kms/templates_controller.rb +6 -5
- data/app/controllers/kms/users_controller.rb +11 -8
- data/app/models/ability.rb +1 -0
- data/app/models/concerns/kms/permalinkable.rb +1 -1
- data/app/models/kms/page.rb +13 -4
- data/app/serializers/kms/asset_serializer.rb +6 -0
- data/app/serializers/kms/page_serializer.rb +5 -0
- data/app/serializers/kms/template_serializer.rb +5 -0
- data/app/serializers/kms/user_serializer.rb +5 -0
- data/app/services/kms/page_fetcher.rb +30 -0
- data/app/services/kms/search_service.rb +28 -3
- data/app/services/kms/template_processor.rb +19 -0
- data/app/views/devise/passwords/edit.html.erb +1 -1
- data/app/views/devise/passwords/new.html.erb +1 -1
- data/app/views/devise/registrations/new.html.erb +1 -1
- data/app/views/devise/sessions/new.html.erb +1 -1
- data/app/views/layouts/kms/devise.html.erb +1 -1
- data/app/views/layouts/kms/kms.html.erb +47 -18
- data/config/initializers/externals.rb +6 -32
- data/config/initializers/search.rb +1 -0
- data/config/locales/en.yml +17 -1
- data/config/locales/ru.yml +17 -1
- data/config/routes.rb +7 -6
- data/lib/kms/dependencies.rb +1 -4
- data/lib/kms/engine.rb +1 -2
- data/lib/kms/search_item.rb +18 -0
- data/lib/kms/version.rb +1 -1
- data/spec/controllers/kms/assets_controller_spec.rb +51 -0
- data/spec/controllers/kms/pages_controller_spec.rb +82 -0
- data/spec/controllers/kms/public/pages_controller_spec.rb +30 -0
- data/spec/controllers/kms/snippets_controller_spec.rb +61 -47
- data/spec/controllers/kms/templates_controller_spec.rb +51 -0
- data/spec/controllers/kms/users_controller_spec.rb +56 -0
- data/spec/factories/assets.rb +8 -0
- data/spec/factories/pages.rb +33 -0
- data/spec/factories/templates.rb +20 -0
- data/spec/factories/users.rb +9 -4
- data/spec/internal/config/routes.rb +12 -1
- data/spec/internal/log/test.log +81239 -0
- data/spec/internal/public/404.html +67 -0
- data/spec/internal/public/avatar.jpg +0 -0
- data/spec/internal/public/style.css +1 -0
- data/spec/internal/public/uploads/kms/asset/file/1/avatar.jpg +0 -0
- data/spec/internal/public/uploads/kms/asset/file/2/avatar.jpg +0 -0
- data/spec/internal/public/uploads/kms/asset/file/2/style.css +1 -0
- data/spec/internal/public/uploads/kms/asset/file/3/style.css +1 -0
- data/spec/internal/public/uploads/kms/asset/file/4/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500976987-41025-0002-0883/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977082-41195-0002-6495/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977109-41364-0002-4518/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977152-41405-0002-2345/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977327-41694-0002-5448/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977376-41732-0002-7916/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977392-41759-0002-7593/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977410-42259-0002-7527/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977429-42306-0002-5937/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500977437-42324-0002-5880/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500983228-53594-0002-4559/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500983284-53632-0002-6590/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500983360-53784-0002-7289/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500983469-54321-0002-0386/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500983469-54321-0004-5691/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500983511-54352-0002-5720/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500983511-54352-0004-1399/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500983610-54507-0002-4280/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500983610-54507-0004-9758/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500984466-57012-0002-4146/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500984466-57012-0004-5895/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500984509-57158-0002-9657/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500984509-57158-0004-5003/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500984616-57697-0002-7201/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500984616-57697-0004-6255/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500985257-58947-0002-3629/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500985257-58947-0004-5338/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500985407-58947-0006-5929/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500985473-59264-0002-0397/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500985473-59264-0004-6493/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500985475-59264-0007-8674/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500985538-59468-0002-9206/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500985538-59468-0004-2586/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500985538-59468-0007-6200/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988358-65877-0002-4528/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500988358-65877-0004-5904/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988358-65877-0007-7320/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988407-65916-0002-3138/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500988407-65916-0004-5400/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988407-65916-0007-1655/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988421-65950-0002-9415/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500988421-65950-0004-7130/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988421-65950-0007-9886/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988435-65981-0002-3228/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500988435-65981-0004-3682/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988435-65981-0007-1582/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988475-66122-0002-9516/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500988475-66122-0004-5634/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988530-66122-0007-2272/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988554-66315-0002-6262/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500988554-66315-0004-6099/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500988554-66315-0007-1632/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500991751-73722-0002-9937/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1500991751-73722-0004-8034/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1500991751-73722-0007-7763/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1501233238-34385-0002-3210/avatar.jpg +0 -0
- data/spec/internal/public/uploads/tmp/1501233238-34385-0004-5881/style.css +1 -0
- data/spec/internal/public/uploads/tmp/1501233238-34385-0007-6280/style.css +1 -0
- data/spec/models/kms/page_spec.rb +31 -0
- data/spec/models/kms/template_spec.rb +15 -0
- data/spec/services/kms/page_fetcher_spec.rb +36 -0
- data/spec/services/kms/search_service_spec.rb +53 -0
- data/spec/services/kms/template_processor_spec.rb +20 -0
- data/spec/support/controller_macros.rb +9 -1
- data/vendor/assets/bower.json +3 -2
- data/vendor/assets/bower_components/angular-ui-select/CHANGELOG.md +169 -0
- data/vendor/assets/bower_components/angular-ui-select/CONTRIBUTING.md +161 -0
- data/vendor/assets/bower_components/angular-ui-select/README.md +27 -13
- data/vendor/assets/bower_components/angular-ui-select/bower.json +6 -3
- data/vendor/assets/bower_components/angular-ui-select/composer.json +29 -0
- data/vendor/assets/bower_components/angular-ui-select/deploy-docs.sh +31 -0
- data/vendor/assets/bower_components/angular-ui-select/dist/select.css +48 -2
- data/vendor/assets/bower_components/angular-ui-select/dist/select.js +454 -111
- data/vendor/assets/bower_components/angular-ui-select/dist/select.min.css +2 -2
- data/vendor/assets/bower_components/angular-ui-select/dist/select.min.js +2 -2
- data/vendor/assets/bower_components/angular-ui-select/docs/assets/app.js +1 -0
- data/vendor/assets/bower_components/angular-ui-select/docs/assets/demo.js +461 -0
- data/vendor/assets/bower_components/angular-ui-select/docs/assets/docs.css +339 -0
- data/vendor/assets/bower_components/angular-ui-select/docs/assets/plunkr.js +110 -0
- data/vendor/assets/bower_components/angular-ui-select/docs/index.html +191 -0
- data/vendor/assets/bower_components/angular-ui-select/docs/partials/_footer.html +2 -0
- data/vendor/assets/bower_components/angular-ui-select/docs/partials/_header.html +64 -0
- data/vendor/assets/bower_components/angular-ui-select/index.js +2 -0
- data/vendor/assets/bower_components/angular-ui-select/package.json +36 -15
- data/vendor/assets/bower_components/bootstrap/CHANGELOG.md +5 -0
- data/vendor/assets/bower_components/bootstrap/Gemfile +6 -0
- data/vendor/assets/bower_components/bootstrap/Gemfile.lock +43 -0
- data/vendor/assets/bower_components/bootstrap/Gruntfile.js +176 -145
- data/vendor/assets/bower_components/bootstrap/ISSUE_TEMPLATE.md +22 -0
- data/vendor/assets/bower_components/bootstrap/LICENSE +1 -1
- data/vendor/assets/bower_components/bootstrap/README.md +55 -40
- data/vendor/assets/bower_components/bootstrap/bower.json +5 -9
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap-theme.css +204 -59
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap-theme.css.map +1 -1
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap-theme.min.css +4 -3
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap-theme.min.css.map +1 -0
- data/vendor/assets/bower_components/bootstrap/dist/css/{bootstrap.less → bootstrap.css} +881 -327
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap.css.map +1 -1
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap.min.css +6 -0
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap.min.css.map +1 -0
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot +0 -0
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg +272 -213
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff +0 -0
- data/vendor/assets/bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/vendor/assets/bower_components/bootstrap/dist/js/bootstrap.js +549 -286
- data/vendor/assets/bower_components/bootstrap/dist/js/bootstrap.min.js +5 -4
- data/vendor/assets/bower_components/bootstrap/dist/js/npm.js +13 -0
- data/vendor/assets/bower_components/bootstrap/fonts/glyphicons-halflings-regular.eot +0 -0
- data/vendor/assets/bower_components/bootstrap/fonts/glyphicons-halflings-regular.svg +272 -213
- data/vendor/assets/bower_components/bootstrap/fonts/glyphicons-halflings-regular.ttf +0 -0
- data/vendor/assets/bower_components/bootstrap/fonts/glyphicons-halflings-regular.woff +0 -0
- data/vendor/assets/bower_components/bootstrap/fonts/glyphicons-halflings-regular.woff2 +0 -0
- data/vendor/assets/bower_components/bootstrap/grunt/bs-commonjs-generator.js +30 -0
- data/vendor/assets/bower_components/bootstrap/grunt/bs-glyphicons-data-generator.js +5 -4
- data/vendor/assets/bower_components/bootstrap/grunt/bs-lessdoc-parser.js +13 -12
- data/vendor/assets/bower_components/bootstrap/grunt/bs-raw-files-generator.js +6 -8
- data/vendor/assets/bower_components/bootstrap/grunt/change-version.js +109 -0
- data/vendor/assets/bower_components/bootstrap/grunt/configBridge.json +46 -0
- data/vendor/assets/bower_components/bootstrap/grunt/npm-shrinkwrap.json +2679 -0
- data/vendor/assets/bower_components/bootstrap/grunt/sauce_browsers.yml +5 -5
- data/vendor/assets/bower_components/bootstrap/js/affix.js +46 -26
- data/vendor/assets/bower_components/bootstrap/js/alert.js +8 -6
- data/vendor/assets/bower_components/bootstrap/js/button.js +34 -19
- data/vendor/assets/bower_components/bootstrap/js/carousel.js +35 -21
- data/vendor/assets/bower_components/bootstrap/js/collapse.js +69 -27
- data/vendor/assets/bower_components/bootstrap/js/dropdown.js +55 -41
- data/vendor/assets/bower_components/bootstrap/js/modal.js +91 -32
- data/vendor/assets/bower_components/bootstrap/js/popover.js +5 -10
- data/vendor/assets/bower_components/bootstrap/js/scrollspy.js +28 -26
- data/vendor/assets/bower_components/bootstrap/js/tab.js +45 -18
- data/vendor/assets/bower_components/bootstrap/js/tooltip.js +117 -54
- data/vendor/assets/bower_components/bootstrap/js/transition.js +2 -2
- data/vendor/assets/bower_components/bootstrap/less/alerts.less +5 -0
- data/vendor/assets/bower_components/bootstrap/less/badges.less +14 -3
- data/vendor/assets/bower_components/bootstrap/less/bootstrap.less +6 -0
- data/vendor/assets/bower_components/bootstrap/less/button-groups.less +22 -18
- data/vendor/assets/bower_components/bootstrap/less/buttons.less +19 -10
- data/vendor/assets/bower_components/bootstrap/less/carousel.less +34 -7
- data/vendor/assets/bower_components/bootstrap/less/close.less +1 -0
- data/vendor/assets/bower_components/bootstrap/less/code.less +1 -0
- data/vendor/assets/bower_components/bootstrap/less/component-animations.less +3 -1
- data/vendor/assets/bower_components/bootstrap/less/dropdowns.less +9 -8
- data/vendor/assets/bower_components/bootstrap/less/forms.less +123 -50
- data/vendor/assets/bower_components/bootstrap/less/glyphicons.less +75 -3
- data/vendor/assets/bower_components/bootstrap/less/input-groups.less +8 -3
- data/vendor/assets/bower_components/bootstrap/less/jumbotron.less +10 -4
- data/vendor/assets/bower_components/bootstrap/less/list-group.less +10 -11
- data/vendor/assets/bower_components/bootstrap/less/media.less +40 -30
- data/vendor/assets/bower_components/bootstrap/less/mixins.less +1 -0
- data/vendor/assets/bower_components/bootstrap/less/mixins/background-variant.less +2 -1
- data/vendor/assets/bower_components/bootstrap/less/mixins/buttons.less +19 -4
- data/vendor/assets/bower_components/bootstrap/less/mixins/forms.less +5 -1
- data/vendor/assets/bower_components/bootstrap/less/mixins/grid-framework.less +4 -4
- data/vendor/assets/bower_components/bootstrap/less/mixins/grid.less +4 -4
- data/vendor/assets/bower_components/bootstrap/less/mixins/hide-text.less +2 -2
- data/vendor/assets/bower_components/bootstrap/less/mixins/image.less +0 -1
- data/vendor/assets/bower_components/bootstrap/less/mixins/labels.less +1 -1
- data/vendor/assets/bower_components/bootstrap/less/mixins/list-group.less +2 -1
- data/vendor/assets/bower_components/bootstrap/less/mixins/pagination.less +2 -1
- data/vendor/assets/bower_components/bootstrap/less/mixins/reset-text.less +18 -0
- data/vendor/assets/bower_components/bootstrap/less/mixins/responsive-visibility.less +1 -1
- data/vendor/assets/bower_components/bootstrap/less/mixins/tab-focus.less +3 -3
- data/vendor/assets/bower_components/bootstrap/less/mixins/text-emphasis.less +2 -1
- data/vendor/assets/bower_components/bootstrap/less/mixins/vendor-prefixes.less +8 -5
- data/vendor/assets/bower_components/bootstrap/less/modals.less +3 -3
- data/vendor/assets/bower_components/bootstrap/less/navbar.less +30 -25
- data/vendor/assets/bower_components/bootstrap/less/navs.less +1 -1
- data/vendor/assets/bower_components/bootstrap/less/normalize.less +12 -13
- data/vendor/assets/bower_components/bootstrap/less/pager.less +1 -2
- data/vendor/assets/bower_components/bootstrap/less/pagination.less +5 -4
- data/vendor/assets/bower_components/bootstrap/less/panels.less +33 -5
- data/vendor/assets/bower_components/bootstrap/less/popovers.less +5 -7
- data/vendor/assets/bower_components/bootstrap/less/print.less +96 -96
- data/vendor/assets/bower_components/bootstrap/less/progress-bars.less +1 -19
- data/vendor/assets/bower_components/bootstrap/less/responsive-embed.less +10 -9
- data/vendor/assets/bower_components/bootstrap/less/scaffolding.less +13 -2
- data/vendor/assets/bower_components/bootstrap/less/tables.less +14 -13
- data/vendor/assets/bower_components/bootstrap/less/theme.less +49 -16
- data/vendor/assets/bower_components/bootstrap/less/thumbnails.less +1 -1
- data/vendor/assets/bower_components/bootstrap/less/tooltip.less +13 -7
- data/vendor/assets/bower_components/bootstrap/less/type.less +2 -13
- data/vendor/assets/bower_components/bootstrap/less/utilities.less +0 -2
- data/vendor/assets/bower_components/bootstrap/less/variables.less +45 -22
- data/vendor/assets/bower_components/bootstrap/nuget/MyGet.ps1 +8 -0
- data/vendor/assets/bower_components/bootstrap/nuget/bootstrap.less.nuspec +28 -0
- data/vendor/assets/bower_components/bootstrap/nuget/bootstrap.nuspec +28 -0
- data/vendor/assets/bower_components/bootstrap/package.js +32 -0
- data/vendor/assets/bower_components/bootstrap/package.json +49 -41
- data/vendor/assets/bower_components/flow.js/README.md +79 -64
- data/vendor/assets/bower_components/flow.js/bower.json +6 -2
- data/vendor/assets/bower_components/flow.js/dist/flow.js +1635 -1532
- data/vendor/assets/bower_components/flow.js/dist/flow.min.js +2 -2
- data/vendor/assets/bower_components/flow.js/package.js +24 -0
- data/vendor/assets/bower_components/flow.js/travis.sh +19 -0
- data/vendor/assets/bower_components/font-awesome/scss/_path.scss +5 -5
- data/vendor/assets/bower_components/font-awesome/scss/_variables.scss +1 -2
- data/vendor/assets/bower_components/ng-flow/bower.json +1 -1
- data/vendor/assets/bower_components/ng-flow/dist/ng-flow-standalone.js +1655 -1542
- data/vendor/assets/bower_components/ng-flow/dist/ng-flow-standalone.min.js +2 -2
- data/vendor/assets/bower_components/ng-flow/dist/ng-flow.js +19 -9
- data/vendor/assets/bower_components/ng-flow/dist/ng-flow.min.js +2 -2
- data/vendor/assets/bower_components/ng-flow/index.js +3 -0
- data/vendor/assets/bower_components/ng-flow/package.js +25 -0
- data/vendor/assets/bower_components/ng-flow/src/directives/drag-events.js +2 -1
- data/vendor/assets/bower_components/ng-flow/src/directives/events.js +2 -1
- data/vendor/assets/bower_components/ng-flow/src/directives/init.js +7 -1
- data/vendor/assets/bower_components/ng-flow/travis.sh +19 -0
- data/vendor/assets/bower_components/{Responsive-Dashboard → rdash-ui}/LICENSE +21 -21
- data/vendor/assets/bower_components/rdash-ui/README.md +55 -0
- data/vendor/assets/bower_components/rdash-ui/bower.json +33 -0
- data/vendor/assets/bower_components/rdash-ui/dist/css/rdash.min.css +1 -0
- data/vendor/assets/bower_components/rdash-ui/dist/css/rdash.scss +489 -0
- data/vendor/assets/bower_components/{Responsive-Dashboard/src → rdash-ui/dist}/fonts/montserrat-regular-webfont.eot +0 -0
- data/vendor/assets/bower_components/{Responsive-Dashboard/src → rdash-ui/dist}/fonts/montserrat-regular-webfont.svg +1316 -1316
- data/vendor/assets/bower_components/{Responsive-Dashboard/src → rdash-ui/dist}/fonts/montserrat-regular-webfont.ttf +0 -0
- data/vendor/assets/bower_components/{Responsive-Dashboard/src → rdash-ui/dist}/fonts/montserrat-regular-webfont.woff +0 -0
- metadata +227 -180
- data/config/initializers/bower_rails.rb +0 -16
- data/vendor/assets/bower_components/Responsive-Dashboard/CONTRIBUTING.md +0 -21
- data/vendor/assets/bower_components/Responsive-Dashboard/README.md +0 -119
- data/vendor/assets/bower_components/Responsive-Dashboard/bower.json +0 -32
- data/vendor/assets/bower_components/Responsive-Dashboard/gulpfile.js +0 -81
- data/vendor/assets/bower_components/Responsive-Dashboard/package.json +0 -21
- data/vendor/assets/bower_components/Responsive-Dashboard/src/index.html +0 -413
- data/vendor/assets/bower_components/Responsive-Dashboard/src/js/dashboard/controllers/alerts-ctrl.js +0 -19
- data/vendor/assets/bower_components/Responsive-Dashboard/src/js/dashboard/controllers/master-ctrl.js +0 -51
- data/vendor/assets/bower_components/Responsive-Dashboard/src/js/dashboard/directives/loading.js +0 -13
- data/vendor/assets/bower_components/Responsive-Dashboard/src/js/dashboard/directives/widget-body.js +0 -16
- data/vendor/assets/bower_components/Responsive-Dashboard/src/js/dashboard/directives/widget-header.js +0 -17
- data/vendor/assets/bower_components/Responsive-Dashboard/src/js/dashboard/directives/widget.js +0 -16
- data/vendor/assets/bower_components/Responsive-Dashboard/src/js/dashboard/module.js +0 -1
- data/vendor/assets/bower_components/Responsive-Dashboard/src/js/dashboard/routes.js +0 -22
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/content.less +0 -19
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/hamburg.less +0 -29
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/header.less +0 -92
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/loading.less +0 -40
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/main.less +0 -73
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/mixins.less +0 -5
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/sidebar.less +0 -122
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/variables.less +0 -10
- data/vendor/assets/bower_components/Responsive-Dashboard/src/less/dashboard/widgets.less +0 -95
- data/vendor/assets/bower_components/bootstrap/dist/css/bootstrap.min.css.erb +0 -5
- data/vendor/assets/bower_components/flow.js/CHANGELOG.md +0 -37
- data/vendor/assets/bower_components/flow.js/Gruntfile.js +0 -132
- data/vendor/assets/bower_components/flow.js/karma.conf.js +0 -114
- data/vendor/assets/bower_components/flow.js/package.json +0 -50
- data/vendor/assets/bower_components/flow.js/src/flow.js +0 -1532
- data/vendor/assets/bower_components/jquery/MIT-LICENSE.txt +0 -21
- data/vendor/assets/bower_components/jquery/bower.json +0 -27
- data/vendor/assets/bower_components/jquery/dist/jquery.js +0 -9190
- data/vendor/assets/bower_components/jquery/dist/jquery.min.js +0 -5
- data/vendor/assets/bower_components/jquery/dist/jquery.min.map +0 -1
- data/vendor/assets/bower_components/jquery/src/ajax.js +0 -806
- data/vendor/assets/bower_components/jquery/src/ajax/jsonp.js +0 -89
- data/vendor/assets/bower_components/jquery/src/ajax/load.js +0 -75
- data/vendor/assets/bower_components/jquery/src/ajax/parseJSON.js +0 -13
- data/vendor/assets/bower_components/jquery/src/ajax/parseXML.js +0 -28
- data/vendor/assets/bower_components/jquery/src/ajax/script.js +0 -64
- data/vendor/assets/bower_components/jquery/src/ajax/var/nonce.js +0 -5
- data/vendor/assets/bower_components/jquery/src/ajax/var/rquery.js +0 -3
- data/vendor/assets/bower_components/jquery/src/ajax/xhr.js +0 -135
- data/vendor/assets/bower_components/jquery/src/attributes.js +0 -11
- data/vendor/assets/bower_components/jquery/src/attributes/attr.js +0 -143
- data/vendor/assets/bower_components/jquery/src/attributes/classes.js +0 -158
- data/vendor/assets/bower_components/jquery/src/attributes/prop.js +0 -96
- data/vendor/assets/bower_components/jquery/src/attributes/support.js +0 -35
- data/vendor/assets/bower_components/jquery/src/attributes/val.js +0 -163
- data/vendor/assets/bower_components/jquery/src/callbacks.js +0 -205
- data/vendor/assets/bower_components/jquery/src/core.js +0 -498
- data/vendor/assets/bower_components/jquery/src/core/access.js +0 -60
- data/vendor/assets/bower_components/jquery/src/core/init.js +0 -123
- data/vendor/assets/bower_components/jquery/src/core/parseHTML.js +0 -39
- data/vendor/assets/bower_components/jquery/src/core/ready.js +0 -97
- data/vendor/assets/bower_components/jquery/src/core/var/rsingleTag.js +0 -4
- data/vendor/assets/bower_components/jquery/src/css.js +0 -451
- data/vendor/assets/bower_components/jquery/src/css/addGetHookIf.js +0 -24
- data/vendor/assets/bower_components/jquery/src/css/curCSS.js +0 -57
- data/vendor/assets/bower_components/jquery/src/css/defaultDisplay.js +0 -70
- data/vendor/assets/bower_components/jquery/src/css/hiddenVisibleSelectors.js +0 -15
- data/vendor/assets/bower_components/jquery/src/css/support.js +0 -91
- data/vendor/assets/bower_components/jquery/src/css/swap.js +0 -28
- data/vendor/assets/bower_components/jquery/src/css/var/cssExpand.js +0 -3
- data/vendor/assets/bower_components/jquery/src/css/var/getStyles.js +0 -5
- data/vendor/assets/bower_components/jquery/src/css/var/isHidden.js +0 -13
- data/vendor/assets/bower_components/jquery/src/css/var/rmargin.js +0 -3
- data/vendor/assets/bower_components/jquery/src/css/var/rnumnonpx.js +0 -5
- data/vendor/assets/bower_components/jquery/src/data.js +0 -179
- data/vendor/assets/bower_components/jquery/src/data/Data.js +0 -181
- data/vendor/assets/bower_components/jquery/src/data/accepts.js +0 -20
- data/vendor/assets/bower_components/jquery/src/data/var/data_priv.js +0 -5
- data/vendor/assets/bower_components/jquery/src/data/var/data_user.js +0 -5
- data/vendor/assets/bower_components/jquery/src/deferred.js +0 -149
- data/vendor/assets/bower_components/jquery/src/deprecated.js +0 -13
- data/vendor/assets/bower_components/jquery/src/dimensions.js +0 -50
- data/vendor/assets/bower_components/jquery/src/effects.js +0 -649
- data/vendor/assets/bower_components/jquery/src/effects/Tween.js +0 -114
- data/vendor/assets/bower_components/jquery/src/effects/animatedSelector.js +0 -13
- data/vendor/assets/bower_components/jquery/src/event.js +0 -868
- data/vendor/assets/bower_components/jquery/src/event/alias.js +0 -39
- data/vendor/assets/bower_components/jquery/src/event/support.js +0 -9
- data/vendor/assets/bower_components/jquery/src/exports/amd.js +0 -24
- data/vendor/assets/bower_components/jquery/src/exports/global.js +0 -32
- data/vendor/assets/bower_components/jquery/src/intro.js +0 -44
- data/vendor/assets/bower_components/jquery/src/jquery.js +0 -36
- data/vendor/assets/bower_components/jquery/src/manipulation.js +0 -582
- data/vendor/assets/bower_components/jquery/src/manipulation/_evalUrl.js +0 -18
- data/vendor/assets/bower_components/jquery/src/manipulation/support.js +0 -31
- data/vendor/assets/bower_components/jquery/src/manipulation/var/rcheckableType.js +0 -3
- data/vendor/assets/bower_components/jquery/src/offset.js +0 -204
- data/vendor/assets/bower_components/jquery/src/outro.js +0 -1
- data/vendor/assets/bower_components/jquery/src/queue.js +0 -142
- data/vendor/assets/bower_components/jquery/src/queue/delay.js +0 -22
- data/vendor/assets/bower_components/jquery/src/selector-native.js +0 -172
- data/vendor/assets/bower_components/jquery/src/selector-sizzle.js +0 -14
- data/vendor/assets/bower_components/jquery/src/selector.js +0 -1
- data/vendor/assets/bower_components/jquery/src/serialize.js +0 -111
- data/vendor/assets/bower_components/jquery/src/sizzle/dist/sizzle.js +0 -2044
- data/vendor/assets/bower_components/jquery/src/sizzle/dist/sizzle.min.js +0 -3
- data/vendor/assets/bower_components/jquery/src/sizzle/dist/sizzle.min.map +0 -1
- data/vendor/assets/bower_components/jquery/src/traversing.js +0 -200
- data/vendor/assets/bower_components/jquery/src/traversing/findFilter.js +0 -100
- data/vendor/assets/bower_components/jquery/src/traversing/var/rneedsContext.js +0 -6
- data/vendor/assets/bower_components/jquery/src/var/arr.js +0 -3
- data/vendor/assets/bower_components/jquery/src/var/class2type.js +0 -4
- data/vendor/assets/bower_components/jquery/src/var/concat.js +0 -5
- data/vendor/assets/bower_components/jquery/src/var/hasOwn.js +0 -5
- data/vendor/assets/bower_components/jquery/src/var/indexOf.js +0 -5
- data/vendor/assets/bower_components/jquery/src/var/pnum.js +0 -3
- data/vendor/assets/bower_components/jquery/src/var/push.js +0 -5
- data/vendor/assets/bower_components/jquery/src/var/rnotwhite.js +0 -3
- data/vendor/assets/bower_components/jquery/src/var/slice.js +0 -5
- data/vendor/assets/bower_components/jquery/src/var/strundefined.js +0 -3
- data/vendor/assets/bower_components/jquery/src/var/support.js +0 -4
- data/vendor/assets/bower_components/jquery/src/var/toString.js +0 -5
- data/vendor/assets/bower_components/jquery/src/wrap.js +0 -78
@@ -1,6 +1,5 @@
|
|
1
1
|
{
|
2
2
|
"name": "flow.js",
|
3
|
-
"version": "2.6.2",
|
4
3
|
"main": "./dist/flow.js",
|
5
4
|
"ignore": [
|
6
5
|
"**/.*",
|
@@ -8,6 +7,11 @@
|
|
8
7
|
"bower_components",
|
9
8
|
"test",
|
10
9
|
"tests",
|
11
|
-
"samples"
|
10
|
+
"samples",
|
11
|
+
"CHANGELOG.md",
|
12
|
+
"karma.conf.js",
|
13
|
+
"package.json",
|
14
|
+
"src/*",
|
15
|
+
"Gruntfile.js"
|
12
16
|
]
|
13
17
|
}
|
@@ -1,1532 +1,1635 @@
|
|
1
|
-
/**
|
2
|
-
* @license MIT
|
3
|
-
*/
|
4
|
-
(function(window, document, undefined) {'use strict';
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
*
|
9
|
-
*
|
10
|
-
* @param
|
11
|
-
* @param {
|
12
|
-
* @param {
|
13
|
-
* @param {
|
14
|
-
* @param {
|
15
|
-
* @param {
|
16
|
-
* @param {number} [opts.
|
17
|
-
* @param {
|
18
|
-
* @param {Object|Function} [opts.
|
19
|
-
* @param {
|
20
|
-
* @param {
|
21
|
-
* @param {
|
22
|
-
* @param {
|
23
|
-
* @param {string|Function} [opts.
|
24
|
-
* @param {
|
25
|
-
* @param {
|
26
|
-
* @param {
|
27
|
-
* @param {Function} [opts.
|
28
|
-
* @
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
*
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
*
|
107
|
-
* @
|
108
|
-
*/
|
109
|
-
this.
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
*
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
*
|
143
|
-
*
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
*
|
161
|
-
*
|
162
|
-
*
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
*
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
var
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
//
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
}
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
if (
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
this.
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
*
|
543
|
-
* @
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
*
|
553
|
-
*
|
554
|
-
* @
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
*
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
if (
|
589
|
-
this.
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
*
|
613
|
-
* @
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
*
|
627
|
-
* @
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
*
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
*
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
*
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
*
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
*
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
*
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
*
|
745
|
-
* @
|
746
|
-
*/
|
747
|
-
this.
|
748
|
-
|
749
|
-
/**
|
750
|
-
*
|
751
|
-
* @type {
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
*
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
/**
|
768
|
-
*
|
769
|
-
* @
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
*
|
788
|
-
* @
|
789
|
-
* @
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
|
834
|
-
|
835
|
-
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
*
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
|
886
|
-
|
887
|
-
|
888
|
-
|
889
|
-
|
890
|
-
|
891
|
-
|
892
|
-
this.
|
893
|
-
var
|
894
|
-
|
895
|
-
|
896
|
-
|
897
|
-
|
898
|
-
|
899
|
-
|
900
|
-
|
901
|
-
|
902
|
-
|
903
|
-
|
904
|
-
|
905
|
-
|
906
|
-
*
|
907
|
-
* @
|
908
|
-
*/
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
var
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
*
|
948
|
-
* @
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
}
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
973
|
-
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
return
|
1002
|
-
},
|
1003
|
-
|
1004
|
-
/**
|
1005
|
-
*
|
1006
|
-
* @function
|
1007
|
-
* @returns {
|
1008
|
-
*/
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
|
1037
|
-
/**
|
1038
|
-
*
|
1039
|
-
* @
|
1040
|
-
|
1041
|
-
|
1042
|
-
|
1043
|
-
|
1044
|
-
|
1045
|
-
|
1046
|
-
|
1047
|
-
|
1048
|
-
|
1049
|
-
|
1050
|
-
|
1051
|
-
|
1052
|
-
|
1053
|
-
|
1054
|
-
|
1055
|
-
|
1056
|
-
|
1057
|
-
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1061
|
-
|
1062
|
-
|
1063
|
-
|
1064
|
-
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1068
|
-
|
1069
|
-
|
1070
|
-
|
1071
|
-
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
|
1084
|
-
|
1085
|
-
|
1086
|
-
|
1087
|
-
*
|
1088
|
-
|
1089
|
-
|
1090
|
-
|
1091
|
-
|
1092
|
-
|
1093
|
-
*
|
1094
|
-
|
1095
|
-
|
1096
|
-
|
1097
|
-
|
1098
|
-
|
1099
|
-
*
|
1100
|
-
|
1101
|
-
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
*
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1109
|
-
|
1110
|
-
|
1111
|
-
*
|
1112
|
-
|
1113
|
-
|
1114
|
-
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
*
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
*
|
1155
|
-
|
1156
|
-
|
1157
|
-
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
|
1162
|
-
|
1163
|
-
|
1164
|
-
|
1165
|
-
|
1166
|
-
|
1167
|
-
|
1168
|
-
|
1169
|
-
|
1170
|
-
|
1171
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
/**
|
1180
|
-
*
|
1181
|
-
* @
|
1182
|
-
*/
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
*
|
1199
|
-
* @param
|
1200
|
-
|
1201
|
-
|
1202
|
-
|
1203
|
-
|
1204
|
-
|
1205
|
-
}
|
1206
|
-
|
1207
|
-
|
1208
|
-
|
1209
|
-
|
1210
|
-
|
1211
|
-
|
1212
|
-
|
1213
|
-
|
1214
|
-
|
1215
|
-
|
1216
|
-
|
1217
|
-
|
1218
|
-
|
1219
|
-
|
1220
|
-
|
1221
|
-
|
1222
|
-
|
1223
|
-
|
1224
|
-
|
1225
|
-
|
1226
|
-
|
1227
|
-
|
1228
|
-
|
1229
|
-
|
1230
|
-
|
1231
|
-
|
1232
|
-
|
1233
|
-
|
1234
|
-
|
1235
|
-
|
1236
|
-
|
1237
|
-
|
1238
|
-
|
1239
|
-
|
1240
|
-
|
1241
|
-
|
1242
|
-
|
1243
|
-
|
1244
|
-
|
1245
|
-
|
1246
|
-
|
1247
|
-
|
1248
|
-
|
1249
|
-
|
1250
|
-
|
1251
|
-
|
1252
|
-
|
1253
|
-
}
|
1254
|
-
|
1255
|
-
|
1256
|
-
|
1257
|
-
|
1258
|
-
|
1259
|
-
|
1260
|
-
|
1261
|
-
|
1262
|
-
|
1263
|
-
|
1264
|
-
|
1265
|
-
|
1266
|
-
|
1267
|
-
|
1268
|
-
|
1269
|
-
|
1270
|
-
|
1271
|
-
|
1272
|
-
|
1273
|
-
},
|
1274
|
-
|
1275
|
-
/**
|
1276
|
-
*
|
1277
|
-
* @function
|
1278
|
-
|
1279
|
-
|
1280
|
-
|
1281
|
-
|
1282
|
-
|
1283
|
-
|
1284
|
-
|
1285
|
-
|
1286
|
-
|
1287
|
-
|
1288
|
-
|
1289
|
-
|
1290
|
-
|
1291
|
-
*
|
1292
|
-
|
1293
|
-
|
1294
|
-
|
1295
|
-
|
1296
|
-
|
1297
|
-
|
1298
|
-
|
1299
|
-
|
1300
|
-
|
1301
|
-
|
1302
|
-
|
1303
|
-
|
1304
|
-
|
1305
|
-
|
1306
|
-
|
1307
|
-
|
1308
|
-
|
1309
|
-
|
1310
|
-
|
1311
|
-
|
1312
|
-
|
1313
|
-
|
1314
|
-
|
1315
|
-
|
1316
|
-
|
1317
|
-
|
1318
|
-
|
1319
|
-
|
1320
|
-
|
1321
|
-
|
1322
|
-
|
1323
|
-
|
1324
|
-
|
1325
|
-
|
1326
|
-
|
1327
|
-
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1331
|
-
*
|
1332
|
-
|
1333
|
-
|
1334
|
-
|
1335
|
-
|
1336
|
-
if (
|
1337
|
-
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
|
1342
|
-
|
1343
|
-
|
1344
|
-
|
1345
|
-
|
1346
|
-
|
1347
|
-
|
1348
|
-
|
1349
|
-
|
1350
|
-
|
1351
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
1360
|
-
|
1361
|
-
|
1362
|
-
|
1363
|
-
|
1364
|
-
|
1365
|
-
|
1366
|
-
|
1367
|
-
|
1368
|
-
|
1369
|
-
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
|
1375
|
-
|
1376
|
-
|
1377
|
-
|
1378
|
-
|
1379
|
-
|
1380
|
-
|
1381
|
-
|
1382
|
-
|
1383
|
-
|
1384
|
-
|
1385
|
-
|
1386
|
-
|
1387
|
-
|
1388
|
-
|
1389
|
-
|
1390
|
-
|
1391
|
-
|
1392
|
-
|
1393
|
-
|
1394
|
-
|
1395
|
-
this.
|
1396
|
-
|
1397
|
-
|
1398
|
-
|
1399
|
-
|
1400
|
-
|
1401
|
-
}
|
1402
|
-
|
1403
|
-
|
1404
|
-
|
1405
|
-
|
1406
|
-
|
1407
|
-
|
1408
|
-
|
1409
|
-
|
1410
|
-
|
1411
|
-
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1415
|
-
|
1416
|
-
|
1417
|
-
|
1418
|
-
|
1419
|
-
|
1420
|
-
|
1421
|
-
|
1422
|
-
|
1423
|
-
|
1424
|
-
|
1425
|
-
|
1426
|
-
|
1427
|
-
|
1428
|
-
|
1429
|
-
|
1430
|
-
}
|
1431
|
-
|
1432
|
-
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
1445
|
-
|
1446
|
-
|
1447
|
-
|
1448
|
-
|
1449
|
-
|
1450
|
-
|
1451
|
-
|
1452
|
-
|
1453
|
-
|
1454
|
-
|
1455
|
-
|
1456
|
-
|
1457
|
-
|
1458
|
-
|
1459
|
-
|
1460
|
-
|
1461
|
-
|
1462
|
-
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
|
1467
|
-
|
1468
|
-
|
1469
|
-
|
1470
|
-
|
1471
|
-
|
1472
|
-
|
1473
|
-
|
1474
|
-
|
1475
|
-
|
1476
|
-
|
1477
|
-
|
1478
|
-
|
1479
|
-
|
1480
|
-
|
1481
|
-
|
1482
|
-
|
1483
|
-
|
1484
|
-
|
1485
|
-
|
1486
|
-
|
1487
|
-
|
1488
|
-
}
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
|
1515
|
-
|
1516
|
-
|
1517
|
-
|
1518
|
-
|
1519
|
-
|
1520
|
-
|
1521
|
-
|
1522
|
-
|
1523
|
-
|
1524
|
-
|
1525
|
-
|
1526
|
-
|
1527
|
-
|
1528
|
-
if (
|
1529
|
-
|
1530
|
-
|
1531
|
-
|
1532
|
-
}
|
1
|
+
/**
|
2
|
+
* @license MIT
|
3
|
+
*/
|
4
|
+
(function(window, document, undefined) {'use strict';
|
5
|
+
// ie10+
|
6
|
+
var ie10plus = window.navigator.msPointerEnabled;
|
7
|
+
/**
|
8
|
+
* Flow.js is a library providing multiple simultaneous, stable and
|
9
|
+
* resumable uploads via the HTML5 File API.
|
10
|
+
* @param [opts]
|
11
|
+
* @param {number} [opts.chunkSize]
|
12
|
+
* @param {bool} [opts.forceChunkSize]
|
13
|
+
* @param {number} [opts.simultaneousUploads]
|
14
|
+
* @param {bool} [opts.singleFile]
|
15
|
+
* @param {string} [opts.fileParameterName]
|
16
|
+
* @param {number} [opts.progressCallbacksInterval]
|
17
|
+
* @param {number} [opts.speedSmoothingFactor]
|
18
|
+
* @param {Object|Function} [opts.query]
|
19
|
+
* @param {Object|Function} [opts.headers]
|
20
|
+
* @param {bool} [opts.withCredentials]
|
21
|
+
* @param {Function} [opts.preprocess]
|
22
|
+
* @param {string} [opts.method]
|
23
|
+
* @param {string|Function} [opts.testMethod]
|
24
|
+
* @param {string|Function} [opts.uploadMethod]
|
25
|
+
* @param {bool} [opts.prioritizeFirstAndLastChunk]
|
26
|
+
* @param {bool} [opts.allowDuplicateUploads]
|
27
|
+
* @param {string|Function} [opts.target]
|
28
|
+
* @param {number} [opts.maxChunkRetries]
|
29
|
+
* @param {number} [opts.chunkRetryInterval]
|
30
|
+
* @param {Array.<number>} [opts.permanentErrors]
|
31
|
+
* @param {Array.<number>} [opts.successStatuses]
|
32
|
+
* @param {Function} [opts.initFileFn]
|
33
|
+
* @param {Function} [opts.readFileFn]
|
34
|
+
* @param {Function} [opts.generateUniqueIdentifier]
|
35
|
+
* @constructor
|
36
|
+
*/
|
37
|
+
function Flow(opts) {
|
38
|
+
/**
|
39
|
+
* Supported by browser?
|
40
|
+
* @type {boolean}
|
41
|
+
*/
|
42
|
+
this.support = (
|
43
|
+
typeof File !== 'undefined' &&
|
44
|
+
typeof Blob !== 'undefined' &&
|
45
|
+
typeof FileList !== 'undefined' &&
|
46
|
+
(
|
47
|
+
!!Blob.prototype.slice || !!Blob.prototype.webkitSlice || !!Blob.prototype.mozSlice ||
|
48
|
+
false
|
49
|
+
) // slicing files support
|
50
|
+
);
|
51
|
+
|
52
|
+
if (!this.support) {
|
53
|
+
return ;
|
54
|
+
}
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Check if directory upload is supported
|
58
|
+
* @type {boolean}
|
59
|
+
*/
|
60
|
+
this.supportDirectory = (
|
61
|
+
/Chrome/.test(window.navigator.userAgent) ||
|
62
|
+
/Firefox/.test(window.navigator.userAgent) ||
|
63
|
+
/Edge/.test(window.navigator.userAgent)
|
64
|
+
);
|
65
|
+
|
66
|
+
/**
|
67
|
+
* List of FlowFile objects
|
68
|
+
* @type {Array.<FlowFile>}
|
69
|
+
*/
|
70
|
+
this.files = [];
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Default options for flow.js
|
74
|
+
* @type {Object}
|
75
|
+
*/
|
76
|
+
this.defaults = {
|
77
|
+
chunkSize: 1024 * 1024,
|
78
|
+
forceChunkSize: false,
|
79
|
+
simultaneousUploads: 3,
|
80
|
+
singleFile: false,
|
81
|
+
fileParameterName: 'file',
|
82
|
+
progressCallbacksInterval: 500,
|
83
|
+
speedSmoothingFactor: 0.1,
|
84
|
+
query: {},
|
85
|
+
headers: {},
|
86
|
+
withCredentials: false,
|
87
|
+
preprocess: null,
|
88
|
+
method: 'multipart',
|
89
|
+
testMethod: 'GET',
|
90
|
+
uploadMethod: 'POST',
|
91
|
+
prioritizeFirstAndLastChunk: false,
|
92
|
+
allowDuplicateUploads: false,
|
93
|
+
target: '/',
|
94
|
+
testChunks: true,
|
95
|
+
generateUniqueIdentifier: null,
|
96
|
+
maxChunkRetries: 0,
|
97
|
+
chunkRetryInterval: null,
|
98
|
+
permanentErrors: [404, 413, 415, 500, 501],
|
99
|
+
successStatuses: [200, 201, 202],
|
100
|
+
onDropStopPropagation: false,
|
101
|
+
initFileFn: null,
|
102
|
+
readFileFn: webAPIFileRead
|
103
|
+
};
|
104
|
+
|
105
|
+
/**
|
106
|
+
* Current options
|
107
|
+
* @type {Object}
|
108
|
+
*/
|
109
|
+
this.opts = {};
|
110
|
+
|
111
|
+
/**
|
112
|
+
* List of events:
|
113
|
+
* key stands for event name
|
114
|
+
* value array list of callbacks
|
115
|
+
* @type {}
|
116
|
+
*/
|
117
|
+
this.events = {};
|
118
|
+
|
119
|
+
var $ = this;
|
120
|
+
|
121
|
+
/**
|
122
|
+
* On drop event
|
123
|
+
* @function
|
124
|
+
* @param {MouseEvent} event
|
125
|
+
*/
|
126
|
+
this.onDrop = function (event) {
|
127
|
+
if ($.opts.onDropStopPropagation) {
|
128
|
+
event.stopPropagation();
|
129
|
+
}
|
130
|
+
event.preventDefault();
|
131
|
+
var dataTransfer = event.dataTransfer;
|
132
|
+
if (dataTransfer.items && dataTransfer.items[0] &&
|
133
|
+
dataTransfer.items[0].webkitGetAsEntry) {
|
134
|
+
$.webkitReadDataTransfer(event);
|
135
|
+
} else {
|
136
|
+
$.addFiles(dataTransfer.files, event);
|
137
|
+
}
|
138
|
+
};
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Prevent default
|
142
|
+
* @function
|
143
|
+
* @param {MouseEvent} event
|
144
|
+
*/
|
145
|
+
this.preventEvent = function (event) {
|
146
|
+
event.preventDefault();
|
147
|
+
};
|
148
|
+
|
149
|
+
|
150
|
+
/**
|
151
|
+
* Current options
|
152
|
+
* @type {Object}
|
153
|
+
*/
|
154
|
+
this.opts = Flow.extend({}, this.defaults, opts || {});
|
155
|
+
|
156
|
+
}
|
157
|
+
|
158
|
+
Flow.prototype = {
|
159
|
+
/**
|
160
|
+
* Set a callback for an event, possible events:
|
161
|
+
* fileSuccess(file), fileProgress(file), fileAdded(file, event),
|
162
|
+
* fileRemoved(file), fileRetry(file), fileError(file, message),
|
163
|
+
* complete(), progress(), error(message, file), pause()
|
164
|
+
* @function
|
165
|
+
* @param {string} event
|
166
|
+
* @param {Function} callback
|
167
|
+
*/
|
168
|
+
on: function (event, callback) {
|
169
|
+
event = event.toLowerCase();
|
170
|
+
if (!this.events.hasOwnProperty(event)) {
|
171
|
+
this.events[event] = [];
|
172
|
+
}
|
173
|
+
this.events[event].push(callback);
|
174
|
+
},
|
175
|
+
|
176
|
+
/**
|
177
|
+
* Remove event callback
|
178
|
+
* @function
|
179
|
+
* @param {string} [event] removes all events if not specified
|
180
|
+
* @param {Function} [fn] removes all callbacks of event if not specified
|
181
|
+
*/
|
182
|
+
off: function (event, fn) {
|
183
|
+
if (event !== undefined) {
|
184
|
+
event = event.toLowerCase();
|
185
|
+
if (fn !== undefined) {
|
186
|
+
if (this.events.hasOwnProperty(event)) {
|
187
|
+
arrayRemove(this.events[event], fn);
|
188
|
+
}
|
189
|
+
} else {
|
190
|
+
delete this.events[event];
|
191
|
+
}
|
192
|
+
} else {
|
193
|
+
this.events = {};
|
194
|
+
}
|
195
|
+
},
|
196
|
+
|
197
|
+
/**
|
198
|
+
* Fire an event
|
199
|
+
* @function
|
200
|
+
* @param {string} event event name
|
201
|
+
* @param {...} args arguments of a callback
|
202
|
+
* @return {bool} value is false if at least one of the event handlers which handled this event
|
203
|
+
* returned false. Otherwise it returns true.
|
204
|
+
*/
|
205
|
+
fire: function (event, args) {
|
206
|
+
// `arguments` is an object, not array, in FF, so:
|
207
|
+
args = Array.prototype.slice.call(arguments);
|
208
|
+
event = event.toLowerCase();
|
209
|
+
var preventDefault = false;
|
210
|
+
if (this.events.hasOwnProperty(event)) {
|
211
|
+
each(this.events[event], function (callback) {
|
212
|
+
preventDefault = callback.apply(this, args.slice(1)) === false || preventDefault;
|
213
|
+
}, this);
|
214
|
+
}
|
215
|
+
if (event != 'catchall') {
|
216
|
+
args.unshift('catchAll');
|
217
|
+
preventDefault = this.fire.apply(this, args) === false || preventDefault;
|
218
|
+
}
|
219
|
+
return !preventDefault;
|
220
|
+
},
|
221
|
+
|
222
|
+
/**
|
223
|
+
* Read webkit dataTransfer object
|
224
|
+
* @param event
|
225
|
+
*/
|
226
|
+
webkitReadDataTransfer: function (event) {
|
227
|
+
var $ = this;
|
228
|
+
var queue = event.dataTransfer.items.length;
|
229
|
+
var files = [];
|
230
|
+
each(event.dataTransfer.items, function (item) {
|
231
|
+
var entry = item.webkitGetAsEntry();
|
232
|
+
if (!entry) {
|
233
|
+
decrement();
|
234
|
+
return ;
|
235
|
+
}
|
236
|
+
if (entry.isFile) {
|
237
|
+
// due to a bug in Chrome's File System API impl - #149735
|
238
|
+
fileReadSuccess(item.getAsFile(), entry.fullPath);
|
239
|
+
} else {
|
240
|
+
readDirectory(entry.createReader());
|
241
|
+
}
|
242
|
+
});
|
243
|
+
function readDirectory(reader) {
|
244
|
+
reader.readEntries(function (entries) {
|
245
|
+
if (entries.length) {
|
246
|
+
queue += entries.length;
|
247
|
+
each(entries, function(entry) {
|
248
|
+
if (entry.isFile) {
|
249
|
+
var fullPath = entry.fullPath;
|
250
|
+
entry.file(function (file) {
|
251
|
+
fileReadSuccess(file, fullPath);
|
252
|
+
}, readError);
|
253
|
+
} else if (entry.isDirectory) {
|
254
|
+
readDirectory(entry.createReader());
|
255
|
+
}
|
256
|
+
});
|
257
|
+
readDirectory(reader);
|
258
|
+
} else {
|
259
|
+
decrement();
|
260
|
+
}
|
261
|
+
}, readError);
|
262
|
+
}
|
263
|
+
function fileReadSuccess(file, fullPath) {
|
264
|
+
// relative path should not start with "/"
|
265
|
+
file.relativePath = fullPath.substring(1);
|
266
|
+
files.push(file);
|
267
|
+
decrement();
|
268
|
+
}
|
269
|
+
function readError(fileError) {
|
270
|
+
throw fileError;
|
271
|
+
}
|
272
|
+
function decrement() {
|
273
|
+
if (--queue == 0) {
|
274
|
+
$.addFiles(files, event);
|
275
|
+
}
|
276
|
+
}
|
277
|
+
},
|
278
|
+
|
279
|
+
/**
|
280
|
+
* Generate unique identifier for a file
|
281
|
+
* @function
|
282
|
+
* @param {FlowFile} file
|
283
|
+
* @returns {string}
|
284
|
+
*/
|
285
|
+
generateUniqueIdentifier: function (file) {
|
286
|
+
var custom = this.opts.generateUniqueIdentifier;
|
287
|
+
if (typeof custom === 'function') {
|
288
|
+
return custom(file);
|
289
|
+
}
|
290
|
+
// Some confusion in different versions of Firefox
|
291
|
+
var relativePath = file.relativePath || file.webkitRelativePath || file.fileName || file.name;
|
292
|
+
return file.size + '-' + relativePath.replace(/[^0-9a-zA-Z_-]/img, '');
|
293
|
+
},
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Upload next chunk from the queue
|
297
|
+
* @function
|
298
|
+
* @returns {boolean}
|
299
|
+
* @private
|
300
|
+
*/
|
301
|
+
uploadNextChunk: function (preventEvents) {
|
302
|
+
// In some cases (such as videos) it's really handy to upload the first
|
303
|
+
// and last chunk of a file quickly; this let's the server check the file's
|
304
|
+
// metadata and determine if there's even a point in continuing.
|
305
|
+
var found = false;
|
306
|
+
if (this.opts.prioritizeFirstAndLastChunk) {
|
307
|
+
each(this.files, function (file) {
|
308
|
+
if (!file.paused && file.chunks.length &&
|
309
|
+
file.chunks[0].status() === 'pending') {
|
310
|
+
file.chunks[0].send();
|
311
|
+
found = true;
|
312
|
+
return false;
|
313
|
+
}
|
314
|
+
if (!file.paused && file.chunks.length > 1 &&
|
315
|
+
file.chunks[file.chunks.length - 1].status() === 'pending') {
|
316
|
+
file.chunks[file.chunks.length - 1].send();
|
317
|
+
found = true;
|
318
|
+
return false;
|
319
|
+
}
|
320
|
+
});
|
321
|
+
if (found) {
|
322
|
+
return found;
|
323
|
+
}
|
324
|
+
}
|
325
|
+
|
326
|
+
// Now, simply look for the next, best thing to upload
|
327
|
+
each(this.files, function (file) {
|
328
|
+
if (!file.paused) {
|
329
|
+
each(file.chunks, function (chunk) {
|
330
|
+
if (chunk.status() === 'pending') {
|
331
|
+
chunk.send();
|
332
|
+
found = true;
|
333
|
+
return false;
|
334
|
+
}
|
335
|
+
});
|
336
|
+
}
|
337
|
+
if (found) {
|
338
|
+
return false;
|
339
|
+
}
|
340
|
+
});
|
341
|
+
if (found) {
|
342
|
+
return true;
|
343
|
+
}
|
344
|
+
|
345
|
+
// The are no more outstanding chunks to upload, check is everything is done
|
346
|
+
var outstanding = false;
|
347
|
+
each(this.files, function (file) {
|
348
|
+
if (!file.isComplete()) {
|
349
|
+
outstanding = true;
|
350
|
+
return false;
|
351
|
+
}
|
352
|
+
});
|
353
|
+
if (!outstanding && !preventEvents) {
|
354
|
+
// All chunks have been uploaded, complete
|
355
|
+
async(function () {
|
356
|
+
this.fire('complete');
|
357
|
+
}, this);
|
358
|
+
}
|
359
|
+
return false;
|
360
|
+
},
|
361
|
+
|
362
|
+
|
363
|
+
/**
|
364
|
+
* Assign a browse action to one or more DOM nodes.
|
365
|
+
* @function
|
366
|
+
* @param {Element|Array.<Element>} domNodes
|
367
|
+
* @param {boolean} isDirectory Pass in true to allow directories to
|
368
|
+
* @param {boolean} singleFile prevent multi file upload
|
369
|
+
* @param {Object} attributes set custom attributes:
|
370
|
+
* http://www.w3.org/TR/html-markup/input.file.html#input.file-attributes
|
371
|
+
* eg: accept: 'image/*'
|
372
|
+
* be selected (Chrome only).
|
373
|
+
*/
|
374
|
+
assignBrowse: function (domNodes, isDirectory, singleFile, attributes) {
|
375
|
+
if (domNodes instanceof Element) {
|
376
|
+
domNodes = [domNodes];
|
377
|
+
}
|
378
|
+
|
379
|
+
each(domNodes, function (domNode) {
|
380
|
+
var input;
|
381
|
+
if (domNode.tagName === 'INPUT' && domNode.type === 'file') {
|
382
|
+
input = domNode;
|
383
|
+
} else {
|
384
|
+
input = document.createElement('input');
|
385
|
+
input.setAttribute('type', 'file');
|
386
|
+
// display:none - not working in opera 12
|
387
|
+
extend(input.style, {
|
388
|
+
visibility: 'hidden',
|
389
|
+
position: 'absolute',
|
390
|
+
width: '1px',
|
391
|
+
height: '1px'
|
392
|
+
});
|
393
|
+
// for opera 12 browser, input must be assigned to a document
|
394
|
+
domNode.appendChild(input);
|
395
|
+
// https://developer.mozilla.org/en/using_files_from_web_applications)
|
396
|
+
// event listener is executed two times
|
397
|
+
// first one - original mouse click event
|
398
|
+
// second - input.click(), input is inside domNode
|
399
|
+
domNode.addEventListener('click', function() {
|
400
|
+
input.click();
|
401
|
+
}, false);
|
402
|
+
}
|
403
|
+
if (!this.opts.singleFile && !singleFile) {
|
404
|
+
input.setAttribute('multiple', 'multiple');
|
405
|
+
}
|
406
|
+
if (isDirectory) {
|
407
|
+
input.setAttribute('webkitdirectory', 'webkitdirectory');
|
408
|
+
}
|
409
|
+
each(attributes, function (value, key) {
|
410
|
+
input.setAttribute(key, value);
|
411
|
+
});
|
412
|
+
// When new files are added, simply append them to the overall list
|
413
|
+
var $ = this;
|
414
|
+
input.addEventListener('change', function (e) {
|
415
|
+
if (e.target.value) {
|
416
|
+
$.addFiles(e.target.files, e);
|
417
|
+
e.target.value = '';
|
418
|
+
}
|
419
|
+
}, false);
|
420
|
+
}, this);
|
421
|
+
},
|
422
|
+
|
423
|
+
/**
|
424
|
+
* Assign one or more DOM nodes as a drop target.
|
425
|
+
* @function
|
426
|
+
* @param {Element|Array.<Element>} domNodes
|
427
|
+
*/
|
428
|
+
assignDrop: function (domNodes) {
|
429
|
+
if (typeof domNodes.length === 'undefined') {
|
430
|
+
domNodes = [domNodes];
|
431
|
+
}
|
432
|
+
each(domNodes, function (domNode) {
|
433
|
+
domNode.addEventListener('dragover', this.preventEvent, false);
|
434
|
+
domNode.addEventListener('dragenter', this.preventEvent, false);
|
435
|
+
domNode.addEventListener('drop', this.onDrop, false);
|
436
|
+
}, this);
|
437
|
+
},
|
438
|
+
|
439
|
+
/**
|
440
|
+
* Un-assign drop event from DOM nodes
|
441
|
+
* @function
|
442
|
+
* @param domNodes
|
443
|
+
*/
|
444
|
+
unAssignDrop: function (domNodes) {
|
445
|
+
if (typeof domNodes.length === 'undefined') {
|
446
|
+
domNodes = [domNodes];
|
447
|
+
}
|
448
|
+
each(domNodes, function (domNode) {
|
449
|
+
domNode.removeEventListener('dragover', this.preventEvent);
|
450
|
+
domNode.removeEventListener('dragenter', this.preventEvent);
|
451
|
+
domNode.removeEventListener('drop', this.onDrop);
|
452
|
+
}, this);
|
453
|
+
},
|
454
|
+
|
455
|
+
/**
|
456
|
+
* Returns a boolean indicating whether or not the instance is currently
|
457
|
+
* uploading anything.
|
458
|
+
* @function
|
459
|
+
* @returns {boolean}
|
460
|
+
*/
|
461
|
+
isUploading: function () {
|
462
|
+
var uploading = false;
|
463
|
+
each(this.files, function (file) {
|
464
|
+
if (file.isUploading()) {
|
465
|
+
uploading = true;
|
466
|
+
return false;
|
467
|
+
}
|
468
|
+
});
|
469
|
+
return uploading;
|
470
|
+
},
|
471
|
+
|
472
|
+
/**
|
473
|
+
* should upload next chunk
|
474
|
+
* @function
|
475
|
+
* @returns {boolean|number}
|
476
|
+
*/
|
477
|
+
_shouldUploadNext: function () {
|
478
|
+
var num = 0;
|
479
|
+
var should = true;
|
480
|
+
var simultaneousUploads = this.opts.simultaneousUploads;
|
481
|
+
each(this.files, function (file) {
|
482
|
+
each(file.chunks, function(chunk) {
|
483
|
+
if (chunk.status() === 'uploading') {
|
484
|
+
num++;
|
485
|
+
if (num >= simultaneousUploads) {
|
486
|
+
should = false;
|
487
|
+
return false;
|
488
|
+
}
|
489
|
+
}
|
490
|
+
});
|
491
|
+
});
|
492
|
+
// if should is true then return uploading chunks's length
|
493
|
+
return should && num;
|
494
|
+
},
|
495
|
+
|
496
|
+
/**
|
497
|
+
* Start or resume uploading.
|
498
|
+
* @function
|
499
|
+
*/
|
500
|
+
upload: function () {
|
501
|
+
// Make sure we don't start too many uploads at once
|
502
|
+
var ret = this._shouldUploadNext();
|
503
|
+
if (ret === false) {
|
504
|
+
return;
|
505
|
+
}
|
506
|
+
// Kick off the queue
|
507
|
+
this.fire('uploadStart');
|
508
|
+
var started = false;
|
509
|
+
for (var num = 1; num <= this.opts.simultaneousUploads - ret; num++) {
|
510
|
+
started = this.uploadNextChunk(true) || started;
|
511
|
+
}
|
512
|
+
if (!started) {
|
513
|
+
async(function () {
|
514
|
+
this.fire('complete');
|
515
|
+
}, this);
|
516
|
+
}
|
517
|
+
},
|
518
|
+
|
519
|
+
/**
|
520
|
+
* Resume uploading.
|
521
|
+
* @function
|
522
|
+
*/
|
523
|
+
resume: function () {
|
524
|
+
each(this.files, function (file) {
|
525
|
+
if (!file.isComplete()) {
|
526
|
+
file.resume();
|
527
|
+
}
|
528
|
+
});
|
529
|
+
},
|
530
|
+
|
531
|
+
/**
|
532
|
+
* Pause uploading.
|
533
|
+
* @function
|
534
|
+
*/
|
535
|
+
pause: function () {
|
536
|
+
each(this.files, function (file) {
|
537
|
+
file.pause();
|
538
|
+
});
|
539
|
+
},
|
540
|
+
|
541
|
+
/**
|
542
|
+
* Cancel upload of all FlowFile objects and remove them from the list.
|
543
|
+
* @function
|
544
|
+
*/
|
545
|
+
cancel: function () {
|
546
|
+
for (var i = this.files.length - 1; i >= 0; i--) {
|
547
|
+
this.files[i].cancel();
|
548
|
+
}
|
549
|
+
},
|
550
|
+
|
551
|
+
/**
|
552
|
+
* Returns a number between 0 and 1 indicating the current upload progress
|
553
|
+
* of all files.
|
554
|
+
* @function
|
555
|
+
* @returns {number}
|
556
|
+
*/
|
557
|
+
progress: function () {
|
558
|
+
var totalDone = 0;
|
559
|
+
var totalSize = 0;
|
560
|
+
// Resume all chunks currently being uploaded
|
561
|
+
each(this.files, function (file) {
|
562
|
+
totalDone += file.progress() * file.size;
|
563
|
+
totalSize += file.size;
|
564
|
+
});
|
565
|
+
return totalSize > 0 ? totalDone / totalSize : 0;
|
566
|
+
},
|
567
|
+
|
568
|
+
/**
|
569
|
+
* Add a HTML5 File object to the list of files.
|
570
|
+
* @function
|
571
|
+
* @param {File} file
|
572
|
+
* @param {Event} [event] event is optional
|
573
|
+
*/
|
574
|
+
addFile: function (file, event) {
|
575
|
+
this.addFiles([file], event);
|
576
|
+
},
|
577
|
+
|
578
|
+
/**
|
579
|
+
* Add a HTML5 File object to the list of files.
|
580
|
+
* @function
|
581
|
+
* @param {FileList|Array} fileList
|
582
|
+
* @param {Event} [event] event is optional
|
583
|
+
*/
|
584
|
+
addFiles: function (fileList, event) {
|
585
|
+
var files = [];
|
586
|
+
each(fileList, function (file) {
|
587
|
+
// https://github.com/flowjs/flow.js/issues/55
|
588
|
+
if ((!ie10plus || ie10plus && file.size > 0) && !(file.size % 4096 === 0 && (file.name === '.' || file.fileName === '.'))) {
|
589
|
+
var uniqueIdentifier = this.generateUniqueIdentifier(file);
|
590
|
+
if (this.opts.allowDuplicateUploads || !this.getFromUniqueIdentifier(uniqueIdentifier)) {
|
591
|
+
var f = new FlowFile(this, file, uniqueIdentifier);
|
592
|
+
if (this.fire('fileAdded', f, event)) {
|
593
|
+
files.push(f);
|
594
|
+
}
|
595
|
+
}
|
596
|
+
}
|
597
|
+
}, this);
|
598
|
+
if (this.fire('filesAdded', files, event)) {
|
599
|
+
each(files, function (file) {
|
600
|
+
if (this.opts.singleFile && this.files.length > 0) {
|
601
|
+
this.removeFile(this.files[0]);
|
602
|
+
}
|
603
|
+
this.files.push(file);
|
604
|
+
}, this);
|
605
|
+
this.fire('filesSubmitted', files, event);
|
606
|
+
}
|
607
|
+
},
|
608
|
+
|
609
|
+
|
610
|
+
/**
|
611
|
+
* Cancel upload of a specific FlowFile object from the list.
|
612
|
+
* @function
|
613
|
+
* @param {FlowFile} file
|
614
|
+
*/
|
615
|
+
removeFile: function (file) {
|
616
|
+
for (var i = this.files.length - 1; i >= 0; i--) {
|
617
|
+
if (this.files[i] === file) {
|
618
|
+
this.files.splice(i, 1);
|
619
|
+
file.abort();
|
620
|
+
this.fire('fileRemoved', file);
|
621
|
+
}
|
622
|
+
}
|
623
|
+
},
|
624
|
+
|
625
|
+
/**
|
626
|
+
* Look up a FlowFile object by its unique identifier.
|
627
|
+
* @function
|
628
|
+
* @param {string} uniqueIdentifier
|
629
|
+
* @returns {boolean|FlowFile} false if file was not found
|
630
|
+
*/
|
631
|
+
getFromUniqueIdentifier: function (uniqueIdentifier) {
|
632
|
+
var ret = false;
|
633
|
+
each(this.files, function (file) {
|
634
|
+
if (file.uniqueIdentifier === uniqueIdentifier) {
|
635
|
+
ret = file;
|
636
|
+
}
|
637
|
+
});
|
638
|
+
return ret;
|
639
|
+
},
|
640
|
+
|
641
|
+
/**
|
642
|
+
* Returns the total size of all files in bytes.
|
643
|
+
* @function
|
644
|
+
* @returns {number}
|
645
|
+
*/
|
646
|
+
getSize: function () {
|
647
|
+
var totalSize = 0;
|
648
|
+
each(this.files, function (file) {
|
649
|
+
totalSize += file.size;
|
650
|
+
});
|
651
|
+
return totalSize;
|
652
|
+
},
|
653
|
+
|
654
|
+
/**
|
655
|
+
* Returns the total size uploaded of all files in bytes.
|
656
|
+
* @function
|
657
|
+
* @returns {number}
|
658
|
+
*/
|
659
|
+
sizeUploaded: function () {
|
660
|
+
var size = 0;
|
661
|
+
each(this.files, function (file) {
|
662
|
+
size += file.sizeUploaded();
|
663
|
+
});
|
664
|
+
return size;
|
665
|
+
},
|
666
|
+
|
667
|
+
/**
|
668
|
+
* Returns remaining time to upload all files in seconds. Accuracy is based on average speed.
|
669
|
+
* If speed is zero, time remaining will be equal to positive infinity `Number.POSITIVE_INFINITY`
|
670
|
+
* @function
|
671
|
+
* @returns {number}
|
672
|
+
*/
|
673
|
+
timeRemaining: function () {
|
674
|
+
var sizeDelta = 0;
|
675
|
+
var averageSpeed = 0;
|
676
|
+
each(this.files, function (file) {
|
677
|
+
if (!file.paused && !file.error) {
|
678
|
+
sizeDelta += file.size - file.sizeUploaded();
|
679
|
+
averageSpeed += file.averageSpeed;
|
680
|
+
}
|
681
|
+
});
|
682
|
+
if (sizeDelta && !averageSpeed) {
|
683
|
+
return Number.POSITIVE_INFINITY;
|
684
|
+
}
|
685
|
+
if (!sizeDelta && !averageSpeed) {
|
686
|
+
return 0;
|
687
|
+
}
|
688
|
+
return Math.floor(sizeDelta / averageSpeed);
|
689
|
+
}
|
690
|
+
};
|
691
|
+
|
692
|
+
|
693
|
+
|
694
|
+
|
695
|
+
|
696
|
+
|
697
|
+
/**
|
698
|
+
* FlowFile class
|
699
|
+
* @name FlowFile
|
700
|
+
* @param {Flow} flowObj
|
701
|
+
* @param {File} file
|
702
|
+
* @param {string} uniqueIdentifier
|
703
|
+
* @constructor
|
704
|
+
*/
|
705
|
+
function FlowFile(flowObj, file, uniqueIdentifier) {
|
706
|
+
|
707
|
+
/**
|
708
|
+
* Reference to parent Flow instance
|
709
|
+
* @type {Flow}
|
710
|
+
*/
|
711
|
+
this.flowObj = flowObj;
|
712
|
+
|
713
|
+
/**
|
714
|
+
* Used to store the bytes read
|
715
|
+
* @type {Blob|string}
|
716
|
+
*/
|
717
|
+
this.bytes = null;
|
718
|
+
|
719
|
+
/**
|
720
|
+
* Reference to file
|
721
|
+
* @type {File}
|
722
|
+
*/
|
723
|
+
this.file = file;
|
724
|
+
|
725
|
+
/**
|
726
|
+
* File name. Some confusion in different versions of Firefox
|
727
|
+
* @type {string}
|
728
|
+
*/
|
729
|
+
this.name = file.fileName || file.name;
|
730
|
+
|
731
|
+
/**
|
732
|
+
* File size
|
733
|
+
* @type {number}
|
734
|
+
*/
|
735
|
+
this.size = file.size;
|
736
|
+
|
737
|
+
/**
|
738
|
+
* Relative file path
|
739
|
+
* @type {string}
|
740
|
+
*/
|
741
|
+
this.relativePath = file.relativePath || file.webkitRelativePath || this.name;
|
742
|
+
|
743
|
+
/**
|
744
|
+
* File unique identifier
|
745
|
+
* @type {string}
|
746
|
+
*/
|
747
|
+
this.uniqueIdentifier = (uniqueIdentifier === undefined ? flowObj.generateUniqueIdentifier(file) : uniqueIdentifier);
|
748
|
+
|
749
|
+
/**
|
750
|
+
* List of chunks
|
751
|
+
* @type {Array.<FlowChunk>}
|
752
|
+
*/
|
753
|
+
this.chunks = [];
|
754
|
+
|
755
|
+
/**
|
756
|
+
* Indicated if file is paused
|
757
|
+
* @type {boolean}
|
758
|
+
*/
|
759
|
+
this.paused = false;
|
760
|
+
|
761
|
+
/**
|
762
|
+
* Indicated if file has encountered an error
|
763
|
+
* @type {boolean}
|
764
|
+
*/
|
765
|
+
this.error = false;
|
766
|
+
|
767
|
+
/**
|
768
|
+
* Average upload speed
|
769
|
+
* @type {number}
|
770
|
+
*/
|
771
|
+
this.averageSpeed = 0;
|
772
|
+
|
773
|
+
/**
|
774
|
+
* Current upload speed
|
775
|
+
* @type {number}
|
776
|
+
*/
|
777
|
+
this.currentSpeed = 0;
|
778
|
+
|
779
|
+
/**
|
780
|
+
* Date then progress was called last time
|
781
|
+
* @type {number}
|
782
|
+
* @private
|
783
|
+
*/
|
784
|
+
this._lastProgressCallback = Date.now();
|
785
|
+
|
786
|
+
/**
|
787
|
+
* Previously uploaded file size
|
788
|
+
* @type {number}
|
789
|
+
* @private
|
790
|
+
*/
|
791
|
+
this._prevUploadedSize = 0;
|
792
|
+
|
793
|
+
/**
|
794
|
+
* Holds previous progress
|
795
|
+
* @type {number}
|
796
|
+
* @private
|
797
|
+
*/
|
798
|
+
this._prevProgress = 0;
|
799
|
+
|
800
|
+
this.bootstrap();
|
801
|
+
}
|
802
|
+
|
803
|
+
FlowFile.prototype = {
|
804
|
+
/**
|
805
|
+
* Update speed parameters
|
806
|
+
* @link http://stackoverflow.com/questions/2779600/how-to-estimate-download-time-remaining-accurately
|
807
|
+
* @function
|
808
|
+
*/
|
809
|
+
measureSpeed: function () {
|
810
|
+
var timeSpan = Date.now() - this._lastProgressCallback;
|
811
|
+
if (!timeSpan) {
|
812
|
+
return ;
|
813
|
+
}
|
814
|
+
var smoothingFactor = this.flowObj.opts.speedSmoothingFactor;
|
815
|
+
var uploaded = this.sizeUploaded();
|
816
|
+
// Prevent negative upload speed after file upload resume
|
817
|
+
this.currentSpeed = Math.max((uploaded - this._prevUploadedSize) / timeSpan * 1000, 0);
|
818
|
+
this.averageSpeed = smoothingFactor * this.currentSpeed + (1 - smoothingFactor) * this.averageSpeed;
|
819
|
+
this._prevUploadedSize = uploaded;
|
820
|
+
},
|
821
|
+
|
822
|
+
/**
|
823
|
+
* For internal usage only.
|
824
|
+
* Callback when something happens within the chunk.
|
825
|
+
* @function
|
826
|
+
* @param {FlowChunk} chunk
|
827
|
+
* @param {string} event can be 'progress', 'success', 'error' or 'retry'
|
828
|
+
* @param {string} [message]
|
829
|
+
*/
|
830
|
+
chunkEvent: function (chunk, event, message) {
|
831
|
+
switch (event) {
|
832
|
+
case 'progress':
|
833
|
+
if (Date.now() - this._lastProgressCallback <
|
834
|
+
this.flowObj.opts.progressCallbacksInterval) {
|
835
|
+
break;
|
836
|
+
}
|
837
|
+
this.measureSpeed();
|
838
|
+
this.flowObj.fire('fileProgress', this, chunk);
|
839
|
+
this.flowObj.fire('progress');
|
840
|
+
this._lastProgressCallback = Date.now();
|
841
|
+
break;
|
842
|
+
case 'error':
|
843
|
+
this.error = true;
|
844
|
+
this.abort(true);
|
845
|
+
this.flowObj.fire('fileError', this, message, chunk);
|
846
|
+
this.flowObj.fire('error', message, this, chunk);
|
847
|
+
break;
|
848
|
+
case 'success':
|
849
|
+
if (this.error) {
|
850
|
+
return;
|
851
|
+
}
|
852
|
+
this.measureSpeed();
|
853
|
+
this.flowObj.fire('fileProgress', this, chunk);
|
854
|
+
this.flowObj.fire('progress');
|
855
|
+
this._lastProgressCallback = Date.now();
|
856
|
+
if (this.isComplete()) {
|
857
|
+
this.currentSpeed = 0;
|
858
|
+
this.averageSpeed = 0;
|
859
|
+
this.flowObj.fire('fileSuccess', this, message, chunk);
|
860
|
+
}
|
861
|
+
break;
|
862
|
+
case 'retry':
|
863
|
+
this.flowObj.fire('fileRetry', this, chunk);
|
864
|
+
break;
|
865
|
+
}
|
866
|
+
},
|
867
|
+
|
868
|
+
/**
|
869
|
+
* Pause file upload
|
870
|
+
* @function
|
871
|
+
*/
|
872
|
+
pause: function() {
|
873
|
+
this.paused = true;
|
874
|
+
this.abort();
|
875
|
+
},
|
876
|
+
|
877
|
+
/**
|
878
|
+
* Resume file upload
|
879
|
+
* @function
|
880
|
+
*/
|
881
|
+
resume: function() {
|
882
|
+
this.paused = false;
|
883
|
+
this.flowObj.upload();
|
884
|
+
},
|
885
|
+
|
886
|
+
/**
|
887
|
+
* Abort current upload
|
888
|
+
* @function
|
889
|
+
*/
|
890
|
+
abort: function (reset) {
|
891
|
+
this.currentSpeed = 0;
|
892
|
+
this.averageSpeed = 0;
|
893
|
+
var chunks = this.chunks;
|
894
|
+
if (reset) {
|
895
|
+
this.chunks = [];
|
896
|
+
}
|
897
|
+
each(chunks, function (c) {
|
898
|
+
if (c.status() === 'uploading') {
|
899
|
+
c.abort();
|
900
|
+
this.flowObj.uploadNextChunk();
|
901
|
+
}
|
902
|
+
}, this);
|
903
|
+
},
|
904
|
+
|
905
|
+
/**
|
906
|
+
* Cancel current upload and remove from a list
|
907
|
+
* @function
|
908
|
+
*/
|
909
|
+
cancel: function () {
|
910
|
+
this.flowObj.removeFile(this);
|
911
|
+
},
|
912
|
+
|
913
|
+
/**
|
914
|
+
* Retry aborted file upload
|
915
|
+
* @function
|
916
|
+
*/
|
917
|
+
retry: function () {
|
918
|
+
this.bootstrap();
|
919
|
+
this.flowObj.upload();
|
920
|
+
},
|
921
|
+
|
922
|
+
/**
|
923
|
+
* Clear current chunks and slice file again
|
924
|
+
* @function
|
925
|
+
*/
|
926
|
+
bootstrap: function () {
|
927
|
+
if (typeof this.flowObj.opts.initFileFn === "function") {
|
928
|
+
this.flowObj.opts.initFileFn(this);
|
929
|
+
}
|
930
|
+
|
931
|
+
this.abort(true);
|
932
|
+
this.error = false;
|
933
|
+
// Rebuild stack of chunks from file
|
934
|
+
this._prevProgress = 0;
|
935
|
+
var round = this.flowObj.opts.forceChunkSize ? Math.ceil : Math.floor;
|
936
|
+
var chunks = Math.max(
|
937
|
+
round(this.size / this.flowObj.opts.chunkSize), 1
|
938
|
+
);
|
939
|
+
for (var offset = 0; offset < chunks; offset++) {
|
940
|
+
this.chunks.push(
|
941
|
+
new FlowChunk(this.flowObj, this, offset)
|
942
|
+
);
|
943
|
+
}
|
944
|
+
},
|
945
|
+
|
946
|
+
/**
|
947
|
+
* Get current upload progress status
|
948
|
+
* @function
|
949
|
+
* @returns {number} from 0 to 1
|
950
|
+
*/
|
951
|
+
progress: function () {
|
952
|
+
if (this.error) {
|
953
|
+
return 1;
|
954
|
+
}
|
955
|
+
if (this.chunks.length === 1) {
|
956
|
+
this._prevProgress = Math.max(this._prevProgress, this.chunks[0].progress());
|
957
|
+
return this._prevProgress;
|
958
|
+
}
|
959
|
+
// Sum up progress across everything
|
960
|
+
var bytesLoaded = 0;
|
961
|
+
each(this.chunks, function (c) {
|
962
|
+
// get chunk progress relative to entire file
|
963
|
+
bytesLoaded += c.progress() * (c.endByte - c.startByte);
|
964
|
+
});
|
965
|
+
var percent = bytesLoaded / this.size;
|
966
|
+
// We don't want to lose percentages when an upload is paused
|
967
|
+
this._prevProgress = Math.max(this._prevProgress, percent > 0.9999 ? 1 : percent);
|
968
|
+
return this._prevProgress;
|
969
|
+
},
|
970
|
+
|
971
|
+
/**
|
972
|
+
* Indicates if file is being uploaded at the moment
|
973
|
+
* @function
|
974
|
+
* @returns {boolean}
|
975
|
+
*/
|
976
|
+
isUploading: function () {
|
977
|
+
var uploading = false;
|
978
|
+
each(this.chunks, function (chunk) {
|
979
|
+
if (chunk.status() === 'uploading') {
|
980
|
+
uploading = true;
|
981
|
+
return false;
|
982
|
+
}
|
983
|
+
});
|
984
|
+
return uploading;
|
985
|
+
},
|
986
|
+
|
987
|
+
/**
|
988
|
+
* Indicates if file is has finished uploading and received a response
|
989
|
+
* @function
|
990
|
+
* @returns {boolean}
|
991
|
+
*/
|
992
|
+
isComplete: function () {
|
993
|
+
var outstanding = false;
|
994
|
+
each(this.chunks, function (chunk) {
|
995
|
+
var status = chunk.status();
|
996
|
+
if (status === 'pending' || status === 'uploading' || status === 'reading' || chunk.preprocessState === 1 || chunk.readState === 1) {
|
997
|
+
outstanding = true;
|
998
|
+
return false;
|
999
|
+
}
|
1000
|
+
});
|
1001
|
+
return !outstanding;
|
1002
|
+
},
|
1003
|
+
|
1004
|
+
/**
|
1005
|
+
* Count total size uploaded
|
1006
|
+
* @function
|
1007
|
+
* @returns {number}
|
1008
|
+
*/
|
1009
|
+
sizeUploaded: function () {
|
1010
|
+
var size = 0;
|
1011
|
+
each(this.chunks, function (chunk) {
|
1012
|
+
size += chunk.sizeUploaded();
|
1013
|
+
});
|
1014
|
+
return size;
|
1015
|
+
},
|
1016
|
+
|
1017
|
+
/**
|
1018
|
+
* Returns remaining time to finish upload file in seconds. Accuracy is based on average speed.
|
1019
|
+
* If speed is zero, time remaining will be equal to positive infinity `Number.POSITIVE_INFINITY`
|
1020
|
+
* @function
|
1021
|
+
* @returns {number}
|
1022
|
+
*/
|
1023
|
+
timeRemaining: function () {
|
1024
|
+
if (this.paused || this.error) {
|
1025
|
+
return 0;
|
1026
|
+
}
|
1027
|
+
var delta = this.size - this.sizeUploaded();
|
1028
|
+
if (delta && !this.averageSpeed) {
|
1029
|
+
return Number.POSITIVE_INFINITY;
|
1030
|
+
}
|
1031
|
+
if (!delta && !this.averageSpeed) {
|
1032
|
+
return 0;
|
1033
|
+
}
|
1034
|
+
return Math.floor(delta / this.averageSpeed);
|
1035
|
+
},
|
1036
|
+
|
1037
|
+
/**
|
1038
|
+
* Get file type
|
1039
|
+
* @function
|
1040
|
+
* @returns {string}
|
1041
|
+
*/
|
1042
|
+
getType: function () {
|
1043
|
+
return this.file.type && this.file.type.split('/')[1];
|
1044
|
+
},
|
1045
|
+
|
1046
|
+
/**
|
1047
|
+
* Get file extension
|
1048
|
+
* @function
|
1049
|
+
* @returns {string}
|
1050
|
+
*/
|
1051
|
+
getExtension: function () {
|
1052
|
+
return this.name.substr((~-this.name.lastIndexOf(".") >>> 0) + 2).toLowerCase();
|
1053
|
+
}
|
1054
|
+
};
|
1055
|
+
|
1056
|
+
/**
|
1057
|
+
* Default read function using the webAPI
|
1058
|
+
*
|
1059
|
+
* @function webAPIFileRead(fileObj, startByte, endByte, fileType, chunk)
|
1060
|
+
*
|
1061
|
+
*/
|
1062
|
+
function webAPIFileRead(fileObj, startByte, endByte, fileType, chunk) {
|
1063
|
+
var function_name = 'slice';
|
1064
|
+
|
1065
|
+
if (fileObj.file.slice)
|
1066
|
+
function_name = 'slice';
|
1067
|
+
else if (fileObj.file.mozSlice)
|
1068
|
+
function_name = 'mozSlice';
|
1069
|
+
else if (fileObj.file.webkitSlice)
|
1070
|
+
function_name = 'webkitSlice';
|
1071
|
+
|
1072
|
+
chunk.readFinished(fileObj.file[function_name](startByte, endByte, fileType));
|
1073
|
+
}
|
1074
|
+
|
1075
|
+
|
1076
|
+
/**
|
1077
|
+
* Class for storing a single chunk
|
1078
|
+
* @name FlowChunk
|
1079
|
+
* @param {Flow} flowObj
|
1080
|
+
* @param {FlowFile} fileObj
|
1081
|
+
* @param {number} offset
|
1082
|
+
* @constructor
|
1083
|
+
*/
|
1084
|
+
function FlowChunk(flowObj, fileObj, offset) {
|
1085
|
+
|
1086
|
+
/**
|
1087
|
+
* Reference to parent flow object
|
1088
|
+
* @type {Flow}
|
1089
|
+
*/
|
1090
|
+
this.flowObj = flowObj;
|
1091
|
+
|
1092
|
+
/**
|
1093
|
+
* Reference to parent FlowFile object
|
1094
|
+
* @type {FlowFile}
|
1095
|
+
*/
|
1096
|
+
this.fileObj = fileObj;
|
1097
|
+
|
1098
|
+
/**
|
1099
|
+
* File offset
|
1100
|
+
* @type {number}
|
1101
|
+
*/
|
1102
|
+
this.offset = offset;
|
1103
|
+
|
1104
|
+
/**
|
1105
|
+
* Indicates if chunk existence was checked on the server
|
1106
|
+
* @type {boolean}
|
1107
|
+
*/
|
1108
|
+
this.tested = false;
|
1109
|
+
|
1110
|
+
/**
|
1111
|
+
* Number of retries performed
|
1112
|
+
* @type {number}
|
1113
|
+
*/
|
1114
|
+
this.retries = 0;
|
1115
|
+
|
1116
|
+
/**
|
1117
|
+
* Pending retry
|
1118
|
+
* @type {boolean}
|
1119
|
+
*/
|
1120
|
+
this.pendingRetry = false;
|
1121
|
+
|
1122
|
+
/**
|
1123
|
+
* Preprocess state
|
1124
|
+
* @type {number} 0 = unprocessed, 1 = processing, 2 = finished
|
1125
|
+
*/
|
1126
|
+
this.preprocessState = 0;
|
1127
|
+
|
1128
|
+
/**
|
1129
|
+
* Read state
|
1130
|
+
* @type {number} 0 = not read, 1 = reading, 2 = finished
|
1131
|
+
*/
|
1132
|
+
this.readState = 0;
|
1133
|
+
|
1134
|
+
|
1135
|
+
/**
|
1136
|
+
* Bytes transferred from total request size
|
1137
|
+
* @type {number}
|
1138
|
+
*/
|
1139
|
+
this.loaded = 0;
|
1140
|
+
|
1141
|
+
/**
|
1142
|
+
* Total request size
|
1143
|
+
* @type {number}
|
1144
|
+
*/
|
1145
|
+
this.total = 0;
|
1146
|
+
|
1147
|
+
/**
|
1148
|
+
* Size of a chunk
|
1149
|
+
* @type {number}
|
1150
|
+
*/
|
1151
|
+
this.chunkSize = this.flowObj.opts.chunkSize;
|
1152
|
+
|
1153
|
+
/**
|
1154
|
+
* Chunk start byte in a file
|
1155
|
+
* @type {number}
|
1156
|
+
*/
|
1157
|
+
this.startByte = this.offset * this.chunkSize;
|
1158
|
+
|
1159
|
+
/**
|
1160
|
+
* Compute the endbyte in a file
|
1161
|
+
*
|
1162
|
+
*/
|
1163
|
+
this.computeEndByte = function() {
|
1164
|
+
var endByte = Math.min(this.fileObj.size, (this.offset + 1) * this.chunkSize);
|
1165
|
+
if (this.fileObj.size - endByte < this.chunkSize && !this.flowObj.opts.forceChunkSize) {
|
1166
|
+
// The last chunk will be bigger than the chunk size,
|
1167
|
+
// but less than 2 * this.chunkSize
|
1168
|
+
endByte = this.fileObj.size;
|
1169
|
+
}
|
1170
|
+
return endByte;
|
1171
|
+
}
|
1172
|
+
|
1173
|
+
/**
|
1174
|
+
* Chunk end byte in a file
|
1175
|
+
* @type {number}
|
1176
|
+
*/
|
1177
|
+
this.endByte = this.computeEndByte();
|
1178
|
+
|
1179
|
+
/**
|
1180
|
+
* XMLHttpRequest
|
1181
|
+
* @type {XMLHttpRequest}
|
1182
|
+
*/
|
1183
|
+
this.xhr = null;
|
1184
|
+
|
1185
|
+
var $ = this;
|
1186
|
+
|
1187
|
+
/**
|
1188
|
+
* Send chunk event
|
1189
|
+
* @param event
|
1190
|
+
* @param {...} args arguments of a callback
|
1191
|
+
*/
|
1192
|
+
this.event = function (event, args) {
|
1193
|
+
args = Array.prototype.slice.call(arguments);
|
1194
|
+
args.unshift($);
|
1195
|
+
$.fileObj.chunkEvent.apply($.fileObj, args);
|
1196
|
+
};
|
1197
|
+
/**
|
1198
|
+
* Catch progress event
|
1199
|
+
* @param {ProgressEvent} event
|
1200
|
+
*/
|
1201
|
+
this.progressHandler = function(event) {
|
1202
|
+
if (event.lengthComputable) {
|
1203
|
+
$.loaded = event.loaded ;
|
1204
|
+
$.total = event.total;
|
1205
|
+
}
|
1206
|
+
$.event('progress', event);
|
1207
|
+
};
|
1208
|
+
|
1209
|
+
/**
|
1210
|
+
* Catch test event
|
1211
|
+
* @param {Event} event
|
1212
|
+
*/
|
1213
|
+
this.testHandler = function(event) {
|
1214
|
+
var status = $.status(true);
|
1215
|
+
if (status === 'error') {
|
1216
|
+
$.event(status, $.message());
|
1217
|
+
$.flowObj.uploadNextChunk();
|
1218
|
+
} else if (status === 'success') {
|
1219
|
+
$.tested = true;
|
1220
|
+
$.event(status, $.message());
|
1221
|
+
$.flowObj.uploadNextChunk();
|
1222
|
+
} else if (!$.fileObj.paused) {
|
1223
|
+
// Error might be caused by file pause method
|
1224
|
+
// Chunks does not exist on the server side
|
1225
|
+
$.tested = true;
|
1226
|
+
$.send();
|
1227
|
+
}
|
1228
|
+
};
|
1229
|
+
|
1230
|
+
/**
|
1231
|
+
* Upload has stopped
|
1232
|
+
* @param {Event} event
|
1233
|
+
*/
|
1234
|
+
this.doneHandler = function(event) {
|
1235
|
+
var status = $.status();
|
1236
|
+
if (status === 'success' || status === 'error') {
|
1237
|
+
delete this.data;
|
1238
|
+
$.event(status, $.message());
|
1239
|
+
$.flowObj.uploadNextChunk();
|
1240
|
+
} else {
|
1241
|
+
$.event('retry', $.message());
|
1242
|
+
$.pendingRetry = true;
|
1243
|
+
$.abort();
|
1244
|
+
$.retries++;
|
1245
|
+
var retryInterval = $.flowObj.opts.chunkRetryInterval;
|
1246
|
+
if (retryInterval !== null) {
|
1247
|
+
setTimeout(function () {
|
1248
|
+
$.send();
|
1249
|
+
}, retryInterval);
|
1250
|
+
} else {
|
1251
|
+
$.send();
|
1252
|
+
}
|
1253
|
+
}
|
1254
|
+
};
|
1255
|
+
}
|
1256
|
+
|
1257
|
+
FlowChunk.prototype = {
|
1258
|
+
/**
|
1259
|
+
* Get params for a request
|
1260
|
+
* @function
|
1261
|
+
*/
|
1262
|
+
getParams: function () {
|
1263
|
+
return {
|
1264
|
+
flowChunkNumber: this.offset + 1,
|
1265
|
+
flowChunkSize: this.flowObj.opts.chunkSize,
|
1266
|
+
flowCurrentChunkSize: this.endByte - this.startByte,
|
1267
|
+
flowTotalSize: this.fileObj.size,
|
1268
|
+
flowIdentifier: this.fileObj.uniqueIdentifier,
|
1269
|
+
flowFilename: this.fileObj.name,
|
1270
|
+
flowRelativePath: this.fileObj.relativePath,
|
1271
|
+
flowTotalChunks: this.fileObj.chunks.length
|
1272
|
+
};
|
1273
|
+
},
|
1274
|
+
|
1275
|
+
/**
|
1276
|
+
* Get target option with query params
|
1277
|
+
* @function
|
1278
|
+
* @param params
|
1279
|
+
* @returns {string}
|
1280
|
+
*/
|
1281
|
+
getTarget: function(target, params){
|
1282
|
+
if(target.indexOf('?') < 0) {
|
1283
|
+
target += '?';
|
1284
|
+
} else {
|
1285
|
+
target += '&';
|
1286
|
+
}
|
1287
|
+
return target + params.join('&');
|
1288
|
+
},
|
1289
|
+
|
1290
|
+
/**
|
1291
|
+
* Makes a GET request without any data to see if the chunk has already
|
1292
|
+
* been uploaded in a previous session
|
1293
|
+
* @function
|
1294
|
+
*/
|
1295
|
+
test: function () {
|
1296
|
+
// Set up request and listen for event
|
1297
|
+
this.xhr = new XMLHttpRequest();
|
1298
|
+
this.xhr.addEventListener("load", this.testHandler, false);
|
1299
|
+
this.xhr.addEventListener("error", this.testHandler, false);
|
1300
|
+
var testMethod = evalOpts(this.flowObj.opts.testMethod, this.fileObj, this);
|
1301
|
+
var data = this.prepareXhrRequest(testMethod, true);
|
1302
|
+
this.xhr.send(data);
|
1303
|
+
},
|
1304
|
+
|
1305
|
+
/**
|
1306
|
+
* Finish preprocess state
|
1307
|
+
* @function
|
1308
|
+
*/
|
1309
|
+
preprocessFinished: function () {
|
1310
|
+
// Re-compute the endByte after the preprocess function to allow an
|
1311
|
+
// implementer of preprocess to set the fileObj size
|
1312
|
+
this.endByte = this.computeEndByte();
|
1313
|
+
|
1314
|
+
this.preprocessState = 2;
|
1315
|
+
this.send();
|
1316
|
+
},
|
1317
|
+
|
1318
|
+
/**
|
1319
|
+
* Finish read state
|
1320
|
+
* @function
|
1321
|
+
*/
|
1322
|
+
readFinished: function (bytes) {
|
1323
|
+
this.readState = 2;
|
1324
|
+
this.bytes = bytes;
|
1325
|
+
this.send();
|
1326
|
+
},
|
1327
|
+
|
1328
|
+
|
1329
|
+
/**
|
1330
|
+
* Uploads the actual data in a POST call
|
1331
|
+
* @function
|
1332
|
+
*/
|
1333
|
+
send: function () {
|
1334
|
+
var preprocess = this.flowObj.opts.preprocess;
|
1335
|
+
var read = this.flowObj.opts.readFileFn;
|
1336
|
+
if (typeof preprocess === 'function') {
|
1337
|
+
switch (this.preprocessState) {
|
1338
|
+
case 0:
|
1339
|
+
this.preprocessState = 1;
|
1340
|
+
preprocess(this);
|
1341
|
+
return;
|
1342
|
+
case 1:
|
1343
|
+
return;
|
1344
|
+
}
|
1345
|
+
}
|
1346
|
+
switch (this.readState) {
|
1347
|
+
case 0:
|
1348
|
+
this.readState = 1;
|
1349
|
+
read(this.fileObj, this.startByte, this.endByte, this.fileObj.file.type, this);
|
1350
|
+
return;
|
1351
|
+
case 1:
|
1352
|
+
return;
|
1353
|
+
}
|
1354
|
+
if (this.flowObj.opts.testChunks && !this.tested) {
|
1355
|
+
this.test();
|
1356
|
+
return;
|
1357
|
+
}
|
1358
|
+
|
1359
|
+
this.loaded = 0;
|
1360
|
+
this.total = 0;
|
1361
|
+
this.pendingRetry = false;
|
1362
|
+
|
1363
|
+
// Set up request and listen for event
|
1364
|
+
this.xhr = new XMLHttpRequest();
|
1365
|
+
this.xhr.upload.addEventListener('progress', this.progressHandler, false);
|
1366
|
+
this.xhr.addEventListener("load", this.doneHandler, false);
|
1367
|
+
this.xhr.addEventListener("error", this.doneHandler, false);
|
1368
|
+
|
1369
|
+
var uploadMethod = evalOpts(this.flowObj.opts.uploadMethod, this.fileObj, this);
|
1370
|
+
var data = this.prepareXhrRequest(uploadMethod, false, this.flowObj.opts.method, this.bytes);
|
1371
|
+
this.xhr.send(data);
|
1372
|
+
},
|
1373
|
+
|
1374
|
+
/**
|
1375
|
+
* Abort current xhr request
|
1376
|
+
* @function
|
1377
|
+
*/
|
1378
|
+
abort: function () {
|
1379
|
+
// Abort and reset
|
1380
|
+
var xhr = this.xhr;
|
1381
|
+
this.xhr = null;
|
1382
|
+
if (xhr) {
|
1383
|
+
xhr.abort();
|
1384
|
+
}
|
1385
|
+
},
|
1386
|
+
|
1387
|
+
/**
|
1388
|
+
* Retrieve current chunk upload status
|
1389
|
+
* @function
|
1390
|
+
* @returns {string} 'pending', 'uploading', 'success', 'error'
|
1391
|
+
*/
|
1392
|
+
status: function (isTest) {
|
1393
|
+
if (this.readState === 1) {
|
1394
|
+
return 'reading';
|
1395
|
+
} else if (this.pendingRetry || this.preprocessState === 1) {
|
1396
|
+
// if pending retry then that's effectively the same as actively uploading,
|
1397
|
+
// there might just be a slight delay before the retry starts
|
1398
|
+
return 'uploading';
|
1399
|
+
} else if (!this.xhr) {
|
1400
|
+
return 'pending';
|
1401
|
+
} else if (this.xhr.readyState < 4) {
|
1402
|
+
// Status is really 'OPENED', 'HEADERS_RECEIVED'
|
1403
|
+
// or 'LOADING' - meaning that stuff is happening
|
1404
|
+
return 'uploading';
|
1405
|
+
} else {
|
1406
|
+
if (this.flowObj.opts.successStatuses.indexOf(this.xhr.status) > -1) {
|
1407
|
+
// HTTP 200, perfect
|
1408
|
+
// HTTP 202 Accepted - The request has been accepted for processing, but the processing has not been completed.
|
1409
|
+
return 'success';
|
1410
|
+
} else if (this.flowObj.opts.permanentErrors.indexOf(this.xhr.status) > -1 ||
|
1411
|
+
!isTest && this.retries >= this.flowObj.opts.maxChunkRetries) {
|
1412
|
+
// HTTP 413/415/500/501, permanent error
|
1413
|
+
return 'error';
|
1414
|
+
} else {
|
1415
|
+
// this should never happen, but we'll reset and queue a retry
|
1416
|
+
// a likely case for this would be 503 service unavailable
|
1417
|
+
this.abort();
|
1418
|
+
return 'pending';
|
1419
|
+
}
|
1420
|
+
}
|
1421
|
+
},
|
1422
|
+
|
1423
|
+
/**
|
1424
|
+
* Get response from xhr request
|
1425
|
+
* @function
|
1426
|
+
* @returns {String}
|
1427
|
+
*/
|
1428
|
+
message: function () {
|
1429
|
+
return this.xhr ? this.xhr.responseText : '';
|
1430
|
+
},
|
1431
|
+
|
1432
|
+
/**
|
1433
|
+
* Get upload progress
|
1434
|
+
* @function
|
1435
|
+
* @returns {number}
|
1436
|
+
*/
|
1437
|
+
progress: function () {
|
1438
|
+
if (this.pendingRetry) {
|
1439
|
+
return 0;
|
1440
|
+
}
|
1441
|
+
var s = this.status();
|
1442
|
+
if (s === 'success' || s === 'error') {
|
1443
|
+
return 1;
|
1444
|
+
} else if (s === 'pending') {
|
1445
|
+
return 0;
|
1446
|
+
} else {
|
1447
|
+
return this.total > 0 ? this.loaded / this.total : 0;
|
1448
|
+
}
|
1449
|
+
},
|
1450
|
+
|
1451
|
+
/**
|
1452
|
+
* Count total size uploaded
|
1453
|
+
* @function
|
1454
|
+
* @returns {number}
|
1455
|
+
*/
|
1456
|
+
sizeUploaded: function () {
|
1457
|
+
var size = this.endByte - this.startByte;
|
1458
|
+
// can't return only chunk.loaded value, because it is bigger than chunk size
|
1459
|
+
if (this.status() !== 'success') {
|
1460
|
+
size = this.progress() * size;
|
1461
|
+
}
|
1462
|
+
return size;
|
1463
|
+
},
|
1464
|
+
|
1465
|
+
/**
|
1466
|
+
* Prepare Xhr request. Set query, headers and data
|
1467
|
+
* @param {string} method GET or POST
|
1468
|
+
* @param {bool} isTest is this a test request
|
1469
|
+
* @param {string} [paramsMethod] octet or form
|
1470
|
+
* @param {Blob} [blob] to send
|
1471
|
+
* @returns {FormData|Blob|Null} data to send
|
1472
|
+
*/
|
1473
|
+
prepareXhrRequest: function(method, isTest, paramsMethod, blob) {
|
1474
|
+
// Add data from the query options
|
1475
|
+
var query = evalOpts(this.flowObj.opts.query, this.fileObj, this, isTest);
|
1476
|
+
query = extend(query, this.getParams());
|
1477
|
+
|
1478
|
+
var target = evalOpts(this.flowObj.opts.target, this.fileObj, this, isTest);
|
1479
|
+
var data = null;
|
1480
|
+
if (method === 'GET' || paramsMethod === 'octet') {
|
1481
|
+
// Add data from the query options
|
1482
|
+
var params = [];
|
1483
|
+
each(query, function (v, k) {
|
1484
|
+
params.push([encodeURIComponent(k), encodeURIComponent(v)].join('='));
|
1485
|
+
});
|
1486
|
+
target = this.getTarget(target, params);
|
1487
|
+
data = blob || null;
|
1488
|
+
} else {
|
1489
|
+
// Add data from the query options
|
1490
|
+
data = new FormData();
|
1491
|
+
each(query, function (v, k) {
|
1492
|
+
data.append(k, v);
|
1493
|
+
});
|
1494
|
+
if (typeof blob !== "undefined") data.append(this.flowObj.opts.fileParameterName, blob, this.fileObj.file.name);
|
1495
|
+
}
|
1496
|
+
|
1497
|
+
this.xhr.open(method, target, true);
|
1498
|
+
this.xhr.withCredentials = this.flowObj.opts.withCredentials;
|
1499
|
+
|
1500
|
+
// Add data from header options
|
1501
|
+
each(evalOpts(this.flowObj.opts.headers, this.fileObj, this, isTest), function (v, k) {
|
1502
|
+
this.xhr.setRequestHeader(k, v);
|
1503
|
+
}, this);
|
1504
|
+
|
1505
|
+
return data;
|
1506
|
+
}
|
1507
|
+
};
|
1508
|
+
|
1509
|
+
/**
|
1510
|
+
* Remove value from array
|
1511
|
+
* @param array
|
1512
|
+
* @param value
|
1513
|
+
*/
|
1514
|
+
function arrayRemove(array, value) {
|
1515
|
+
var index = array.indexOf(value);
|
1516
|
+
if (index > -1) {
|
1517
|
+
array.splice(index, 1);
|
1518
|
+
}
|
1519
|
+
}
|
1520
|
+
|
1521
|
+
/**
|
1522
|
+
* If option is a function, evaluate it with given params
|
1523
|
+
* @param {*} data
|
1524
|
+
* @param {...} args arguments of a callback
|
1525
|
+
* @returns {*}
|
1526
|
+
*/
|
1527
|
+
function evalOpts(data, args) {
|
1528
|
+
if (typeof data === "function") {
|
1529
|
+
// `arguments` is an object, not array, in FF, so:
|
1530
|
+
args = Array.prototype.slice.call(arguments);
|
1531
|
+
data = data.apply(null, args.slice(1));
|
1532
|
+
}
|
1533
|
+
return data;
|
1534
|
+
}
|
1535
|
+
Flow.evalOpts = evalOpts;
|
1536
|
+
|
1537
|
+
/**
|
1538
|
+
* Execute function asynchronously
|
1539
|
+
* @param fn
|
1540
|
+
* @param context
|
1541
|
+
*/
|
1542
|
+
function async(fn, context) {
|
1543
|
+
setTimeout(fn.bind(context), 0);
|
1544
|
+
}
|
1545
|
+
|
1546
|
+
/**
|
1547
|
+
* Extends the destination object `dst` by copying all of the properties from
|
1548
|
+
* the `src` object(s) to `dst`. You can specify multiple `src` objects.
|
1549
|
+
* @function
|
1550
|
+
* @param {Object} dst Destination object.
|
1551
|
+
* @param {...Object} src Source object(s).
|
1552
|
+
* @returns {Object} Reference to `dst`.
|
1553
|
+
*/
|
1554
|
+
function extend(dst, src) {
|
1555
|
+
each(arguments, function(obj) {
|
1556
|
+
if (obj !== dst) {
|
1557
|
+
each(obj, function(value, key){
|
1558
|
+
dst[key] = value;
|
1559
|
+
});
|
1560
|
+
}
|
1561
|
+
});
|
1562
|
+
return dst;
|
1563
|
+
}
|
1564
|
+
Flow.extend = extend;
|
1565
|
+
|
1566
|
+
/**
|
1567
|
+
* Iterate each element of an object
|
1568
|
+
* @function
|
1569
|
+
* @param {Array|Object} obj object or an array to iterate
|
1570
|
+
* @param {Function} callback first argument is a value and second is a key.
|
1571
|
+
* @param {Object=} context Object to become context (`this`) for the iterator function.
|
1572
|
+
*/
|
1573
|
+
function each(obj, callback, context) {
|
1574
|
+
if (!obj) {
|
1575
|
+
return ;
|
1576
|
+
}
|
1577
|
+
var key;
|
1578
|
+
// Is Array?
|
1579
|
+
// Array.isArray won't work, not only arrays can be iterated by index https://github.com/flowjs/ng-flow/issues/236#
|
1580
|
+
if (typeof(obj.length) !== 'undefined') {
|
1581
|
+
for (key = 0; key < obj.length; key++) {
|
1582
|
+
if (callback.call(context, obj[key], key) === false) {
|
1583
|
+
return ;
|
1584
|
+
}
|
1585
|
+
}
|
1586
|
+
} else {
|
1587
|
+
for (key in obj) {
|
1588
|
+
if (obj.hasOwnProperty(key) && callback.call(context, obj[key], key) === false) {
|
1589
|
+
return ;
|
1590
|
+
}
|
1591
|
+
}
|
1592
|
+
}
|
1593
|
+
}
|
1594
|
+
Flow.each = each;
|
1595
|
+
|
1596
|
+
/**
|
1597
|
+
* FlowFile constructor
|
1598
|
+
* @type {FlowFile}
|
1599
|
+
*/
|
1600
|
+
Flow.FlowFile = FlowFile;
|
1601
|
+
|
1602
|
+
/**
|
1603
|
+
* FlowFile constructor
|
1604
|
+
* @type {FlowChunk}
|
1605
|
+
*/
|
1606
|
+
Flow.FlowChunk = FlowChunk;
|
1607
|
+
|
1608
|
+
/**
|
1609
|
+
* Library version
|
1610
|
+
* @type {string}
|
1611
|
+
*/
|
1612
|
+
Flow.version = '2.13.0';
|
1613
|
+
|
1614
|
+
if ( typeof module === "object" && module && typeof module.exports === "object" ) {
|
1615
|
+
// Expose Flow as module.exports in loaders that implement the Node
|
1616
|
+
// module pattern (including browserify). Do not create the global, since
|
1617
|
+
// the user will be storing it themselves locally, and globals are frowned
|
1618
|
+
// upon in the Node module world.
|
1619
|
+
module.exports = Flow;
|
1620
|
+
} else {
|
1621
|
+
// Otherwise expose Flow to the global object as usual
|
1622
|
+
window.Flow = Flow;
|
1623
|
+
|
1624
|
+
// Register as a named AMD module, since Flow can be concatenated with other
|
1625
|
+
// files that may use define, but not via a proper concatenation script that
|
1626
|
+
// understands anonymous AMD modules. A named AMD is safest and most robust
|
1627
|
+
// way to register. Lowercase flow is used because AMD module names are
|
1628
|
+
// derived from file names, and Flow is normally delivered in a lowercase
|
1629
|
+
// file name. Do this after creating the global so that if an AMD module wants
|
1630
|
+
// to call noConflict to hide this version of Flow, it will work.
|
1631
|
+
if ( typeof define === "function" && define.amd ) {
|
1632
|
+
define( "flow", [], function () { return Flow; } );
|
1633
|
+
}
|
1634
|
+
}
|
1635
|
+
})(window, document);
|