stylish 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +7 -10
- data/ARCHITECTURE.md +96 -0
- data/Gemfile +8 -0
- data/README.md +25 -29
- data/Rakefile +24 -0
- data/bin/stylish +33 -0
- data/lib/stylish.rb +36 -1
- data/lib/stylish/configuration.rb +37 -0
- data/lib/stylish/core_ext.rb +20 -0
- data/lib/stylish/developer.rb +13 -0
- data/lib/stylish/developer/config.rb +19 -0
- data/lib/stylish/developer/environment.rb +75 -0
- data/lib/stylish/developer/listing.rb +85 -0
- data/lib/stylish/developer/model_delegator.rb +51 -0
- data/lib/stylish/developer/modification.rb +139 -0
- data/lib/stylish/developer/path.rb +168 -0
- data/lib/stylish/developer/route.rb +97 -0
- data/lib/stylish/developer/server.rb +40 -0
- data/lib/stylish/engine.rb +12 -0
- data/lib/stylish/fs.rb +59 -0
- data/lib/stylish/manifest.rb +100 -0
- data/lib/stylish/models.rb +119 -0
- data/lib/stylish/models/component.rb +19 -0
- data/lib/stylish/models/layout.rb +19 -0
- data/lib/stylish/models/library.rb +134 -0
- data/lib/stylish/models/package.rb +156 -0
- data/lib/stylish/models/script.rb +10 -0
- data/lib/stylish/models/stylesheet.rb +9 -0
- data/lib/stylish/models/template.rb +9 -0
- data/lib/stylish/models/theme.rb +8 -0
- data/lib/stylish/util.rb +20 -0
- data/lib/stylish/version.rb +1 -1
- data/library/config.json +4 -0
- data/library/second-theme/manifest.json +8 -0
- data/library/second-theme/manifest.yml +6 -0
- data/library/second-theme/templates/footers/footer-01.html +3 -0
- data/library/second-theme/templates/footers/footer-02.html +3 -0
- data/library/second-theme/templates/headers/header-01.html +3 -0
- data/library/second-theme/templates/headers/header-02.html +3 -0
- data/library/second-theme/templates/landing-page-blocks/landing-page-block-01.html +3 -0
- data/library/second-theme/templates/landing-page-blocks/landing-page-block-02.html +3 -0
- data/library/test-theme/components/footers/footer-01.json +5 -0
- data/library/test-theme/components/footers/footer-02.json +5 -0
- data/library/test-theme/components/headers/header-01.json +5 -0
- data/library/test-theme/components/headers/header-02.json +5 -0
- data/library/test-theme/components/landing-page-blocks/landing-page-01.json +5 -0
- data/library/test-theme/components/landing-page-blocks/landing-page-02.json +5 -0
- data/library/test-theme/manifest.json +8 -0
- data/library/test-theme/manifest.yml +6 -0
- data/library/test-theme/pages/page-01.json +11 -0
- data/library/test-theme/templates/footers/footer-01.html +3 -0
- data/library/test-theme/templates/footers/footer-02.html +3 -0
- data/library/test-theme/templates/headers/header-01.html +3 -0
- data/library/test-theme/templates/headers/header-02.html +3 -0
- data/library/test-theme/templates/landing-page-blocks/landing-page-block-01.html +3 -0
- data/library/test-theme/templates/landing-page-blocks/landing-page-block-02.html +3 -0
- data/library/test-theme/templates/layouts/standard-layout.html +10 -0
- data/spec/acceptance/listing_assets_spec.rb +20 -0
- data/spec/acceptance/model_browsing_spec.rb +21 -0
- data/spec/acceptance/model_creation_spec.rb +16 -0
- data/spec/acceptance/model_deleting_spec.rb +10 -0
- data/spec/acceptance/model_updating_spec.rb +12 -0
- data/spec/acceptance/modifying_assets_spec.rb +50 -0
- data/spec/acceptance/server_info_spec.rb +10 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/test.coffee +4 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/assets/stylesheets/test.css.scss +6 -0
- data/spec/dummy/app/assets/stylesheets/writable/existing.scss.css +0 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +30 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +82 -0
- data/spec/dummy/config/environments/test.rb +39 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/migrate/20140822065900_create_books.rb +11 -0
- data/spec/dummy/db/migrate/20140822065916_create_authors.rb +9 -0
- data/spec/dummy/db/migrate/20140824215902_create_users.rb +10 -0
- data/spec/dummy/db/migrate/20140826193259_create_libraries.rb +10 -0
- data/spec/dummy/db/schema.rb +37 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/fixtures/config.json +3 -0
- data/spec/fixtures/test-theme/components/footers/footer-01.json +5 -0
- data/spec/fixtures/test-theme/components/footers/footer-02.json +5 -0
- data/spec/fixtures/test-theme/components/headers/header-01.json +5 -0
- data/spec/fixtures/test-theme/components/headers/header-02.json +5 -0
- data/spec/fixtures/test-theme/components/landing-page-blocks/landing-page-01.json +5 -0
- data/spec/fixtures/test-theme/components/landing-page-blocks/landing-page-02.json +5 -0
- data/spec/fixtures/test-theme/manifest.json +8 -0
- data/spec/fixtures/test-theme/manifest.yml +6 -0
- data/spec/fixtures/test-theme/pages/page-01.json +11 -0
- data/spec/fixtures/test-theme/templates/footers/footer-01.html +3 -0
- data/spec/fixtures/test-theme/templates/footers/footer-02.html +3 -0
- data/spec/fixtures/test-theme/templates/headers/header-01.html +3 -0
- data/spec/fixtures/test-theme/templates/headers/header-02.html +3 -0
- data/spec/fixtures/test-theme/templates/landing-page-blocks/landing-page-block-01.html +3 -0
- data/spec/fixtures/test-theme/templates/landing-page-blocks/landing-page-block-02.html +3 -0
- data/spec/fixtures/test-theme/templates/layouts/standard-01.html +9 -0
- data/spec/lib/stylish/configuration_spec.rb +8 -0
- data/spec/lib/stylish/developer/path_spec.rb +36 -0
- data/spec/lib/stylish/developer/route_spec.rb +5 -0
- data/spec/lib/stylish/manifest_spec.rb +48 -0
- data/spec/lib/stylish/models/library_spec.rb +38 -0
- data/spec/lib/stylish/models/package_spec.rb +35 -0
- data/spec/lib/stylish/models_spec.rb +12 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/json_helper.rb +7 -0
- data/spec/test.css.scss +6 -0
- data/stylish.gemspec +17 -2
- data/support/editor-app/.gitignore +2 -0
- data/support/editor-app/development/bower.json +9 -0
- data/support/editor-app/development/package.json +28 -0
- data/support/editor-app/development/semantic/components/accordion.css +257 -0
- data/support/editor-app/development/semantic/components/accordion.js +558 -0
- data/support/editor-app/development/semantic/components/accordion.min.css +11 -0
- data/support/editor-app/development/semantic/components/accordion.min.js +11 -0
- data/support/editor-app/development/semantic/components/ad.css +277 -0
- data/support/editor-app/development/semantic/components/ad.min.css +11 -0
- data/support/editor-app/development/semantic/components/api.js +851 -0
- data/support/editor-app/development/semantic/components/api.min.js +11 -0
- data/support/editor-app/development/semantic/components/breadcrumb.css +125 -0
- data/support/editor-app/development/semantic/components/breadcrumb.min.css +11 -0
- data/support/editor-app/development/semantic/components/button.css +2391 -0
- data/support/editor-app/development/semantic/components/button.min.css +11 -0
- data/support/editor-app/development/semantic/components/card.css +758 -0
- data/support/editor-app/development/semantic/components/card.min.css +11 -0
- data/support/editor-app/development/semantic/components/checkbox.css +514 -0
- data/support/editor-app/development/semantic/components/checkbox.js +507 -0
- data/support/editor-app/development/semantic/components/checkbox.min.css +11 -0
- data/support/editor-app/development/semantic/components/checkbox.min.js +11 -0
- data/support/editor-app/development/semantic/components/comment.css +260 -0
- data/support/editor-app/development/semantic/components/comment.min.css +11 -0
- data/support/editor-app/development/semantic/components/dimmer.css +187 -0
- data/support/editor-app/development/semantic/components/dimmer.js +627 -0
- data/support/editor-app/development/semantic/components/dimmer.min.css +11 -0
- data/support/editor-app/development/semantic/components/dimmer.min.js +11 -0
- data/support/editor-app/development/semantic/components/divider.css +244 -0
- data/support/editor-app/development/semantic/components/divider.min.css +11 -0
- data/support/editor-app/development/semantic/components/dropdown.css +1085 -0
- data/support/editor-app/development/semantic/components/dropdown.js +1757 -0
- data/support/editor-app/development/semantic/components/dropdown.min.css +11 -0
- data/support/editor-app/development/semantic/components/dropdown.min.js +11 -0
- data/support/editor-app/development/semantic/components/feed.css +277 -0
- data/support/editor-app/development/semantic/components/feed.min.css +11 -0
- data/support/editor-app/development/semantic/components/flag.css +1017 -0
- data/support/editor-app/development/semantic/components/flag.min.css +11 -0
- data/support/editor-app/development/semantic/components/form.css +875 -0
- data/support/editor-app/development/semantic/components/form.js +1039 -0
- data/support/editor-app/development/semantic/components/form.min.css +11 -0
- data/support/editor-app/development/semantic/components/form.min.js +11 -0
- data/support/editor-app/development/semantic/components/grid.css +1816 -0
- data/support/editor-app/development/semantic/components/grid.min.css +11 -0
- data/support/editor-app/development/semantic/components/header.css +572 -0
- data/support/editor-app/development/semantic/components/header.min.css +11 -0
- data/support/editor-app/development/semantic/components/icon.css +2127 -0
- data/support/editor-app/development/semantic/components/icon.min.css +11 -0
- data/support/editor-app/development/semantic/components/image.css +275 -0
- data/support/editor-app/development/semantic/components/image.min.css +11 -0
- data/support/editor-app/development/semantic/components/input.css +455 -0
- data/support/editor-app/development/semantic/components/input.min.css +11 -0
- data/support/editor-app/development/semantic/components/item.css +458 -0
- data/support/editor-app/development/semantic/components/item.min.css +11 -0
- data/support/editor-app/development/semantic/components/label.css +930 -0
- data/support/editor-app/development/semantic/components/label.min.css +11 -0
- data/support/editor-app/development/semantic/components/list.css +879 -0
- data/support/editor-app/development/semantic/components/list.min.css +11 -0
- data/support/editor-app/development/semantic/components/loader.css +279 -0
- data/support/editor-app/development/semantic/components/loader.min.css +11 -0
- data/support/editor-app/development/semantic/components/menu.css +1596 -0
- data/support/editor-app/development/semantic/components/menu.min.css +11 -0
- data/support/editor-app/development/semantic/components/message.css +422 -0
- data/support/editor-app/development/semantic/components/message.min.css +11 -0
- data/support/editor-app/development/semantic/components/modal.css +431 -0
- data/support/editor-app/development/semantic/components/modal.js +860 -0
- data/support/editor-app/development/semantic/components/modal.min.css +11 -0
- data/support/editor-app/development/semantic/components/modal.min.js +11 -0
- data/support/editor-app/development/semantic/components/nag.css +149 -0
- data/support/editor-app/development/semantic/components/nag.js +477 -0
- data/support/editor-app/development/semantic/components/nag.min.css +11 -0
- data/support/editor-app/development/semantic/components/nag.min.js +11 -0
- data/support/editor-app/development/semantic/components/popup.css +294 -0
- data/support/editor-app/development/semantic/components/popup.js +1187 -0
- data/support/editor-app/development/semantic/components/popup.min.css +11 -0
- data/support/editor-app/development/semantic/components/popup.min.js +11 -0
- data/support/editor-app/development/semantic/components/progress.css +449 -0
- data/support/editor-app/development/semantic/components/progress.js +785 -0
- data/support/editor-app/development/semantic/components/progress.min.css +11 -0
- data/support/editor-app/development/semantic/components/progress.min.js +11 -0
- data/support/editor-app/development/semantic/components/rail.css +125 -0
- data/support/editor-app/development/semantic/components/rail.min.css +11 -0
- data/support/editor-app/development/semantic/components/rating.css +262 -0
- data/support/editor-app/development/semantic/components/rating.js +451 -0
- data/support/editor-app/development/semantic/components/rating.min.css +11 -0
- data/support/editor-app/development/semantic/components/rating.min.js +11 -0
- data/support/editor-app/development/semantic/components/reset.css +430 -0
- data/support/editor-app/development/semantic/components/reset.min.css +11 -0
- data/support/editor-app/development/semantic/components/reveal.css +294 -0
- data/support/editor-app/development/semantic/components/reveal.min.css +11 -0
- data/support/editor-app/development/semantic/components/search.css +330 -0
- data/support/editor-app/development/semantic/components/search.js +1055 -0
- data/support/editor-app/development/semantic/components/search.min.css +11 -0
- data/support/editor-app/development/semantic/components/search.min.js +11 -0
- data/support/editor-app/development/semantic/components/segment.css +590 -0
- data/support/editor-app/development/semantic/components/segment.min.css +11 -0
- data/support/editor-app/development/semantic/components/shape.css +155 -0
- data/support/editor-app/development/semantic/components/shape.js +830 -0
- data/support/editor-app/development/semantic/components/shape.min.css +11 -0
- data/support/editor-app/development/semantic/components/shape.min.js +11 -0
- data/support/editor-app/development/semantic/components/sidebar.css +621 -0
- data/support/editor-app/development/semantic/components/sidebar.js +1084 -0
- data/support/editor-app/development/semantic/components/sidebar.min.css +11 -0
- data/support/editor-app/development/semantic/components/sidebar.min.js +11 -0
- data/support/editor-app/development/semantic/components/site.css +147 -0
- data/support/editor-app/development/semantic/components/site.js +487 -0
- data/support/editor-app/development/semantic/components/site.min.css +11 -0
- data/support/editor-app/development/semantic/components/site.min.js +11 -0
- data/support/editor-app/development/semantic/components/state.js +690 -0
- data/support/editor-app/development/semantic/components/state.min.js +11 -0
- data/support/editor-app/development/semantic/components/statistic.css +410 -0
- data/support/editor-app/development/semantic/components/statistic.min.css +11 -0
- data/support/editor-app/development/semantic/components/step.css +433 -0
- data/support/editor-app/development/semantic/components/step.min.css +11 -0
- data/support/editor-app/development/semantic/components/sticky.css +80 -0
- data/support/editor-app/development/semantic/components/sticky.js +775 -0
- data/support/editor-app/development/semantic/components/sticky.min.css +11 -0
- data/support/editor-app/development/semantic/components/sticky.min.js +11 -0
- data/support/editor-app/development/semantic/components/tab.css +93 -0
- data/support/editor-app/development/semantic/components/tab.js +787 -0
- data/support/editor-app/development/semantic/components/tab.min.css +11 -0
- data/support/editor-app/development/semantic/components/tab.min.js +11 -0
- data/support/editor-app/development/semantic/components/table.css +999 -0
- data/support/editor-app/development/semantic/components/table.min.css +11 -0
- data/support/editor-app/development/semantic/components/transition.css +2152 -0
- data/support/editor-app/development/semantic/components/transition.js +936 -0
- data/support/editor-app/development/semantic/components/transition.min.css +11 -0
- data/support/editor-app/development/semantic/components/transition.min.js +11 -0
- data/support/editor-app/development/semantic/components/video.css +126 -0
- data/support/editor-app/development/semantic/components/video.js +540 -0
- data/support/editor-app/development/semantic/components/video.min.css +11 -0
- data/support/editor-app/development/semantic/components/video.min.js +11 -0
- data/support/editor-app/development/semantic/components/visibility.js +970 -0
- data/support/editor-app/development/semantic/components/visibility.min.js +11 -0
- data/support/editor-app/development/semantic/semantic.css +31768 -0
- data/support/editor-app/development/semantic/semantic.js +18317 -0
- data/support/editor-app/development/semantic/semantic.min.css +11 -0
- data/support/editor-app/development/semantic/semantic.min.js +17 -0
- data/support/editor-app/development/semantic/themes/basic/assets/fonts/icons.eot +0 -0
- data/support/editor-app/development/semantic/themes/basic/assets/fonts/icons.svg +450 -0
- data/support/editor-app/development/semantic/themes/basic/assets/fonts/icons.ttf +0 -0
- data/support/editor-app/development/semantic/themes/basic/assets/fonts/icons.woff +0 -0
- data/support/editor-app/development/semantic/themes/default/assets/fonts/icons.eot +0 -0
- data/support/editor-app/development/semantic/themes/default/assets/fonts/icons.otf +0 -0
- data/support/editor-app/development/semantic/themes/default/assets/fonts/icons.svg +504 -0
- data/support/editor-app/development/semantic/themes/default/assets/fonts/icons.ttf +0 -0
- data/support/editor-app/development/semantic/themes/default/assets/fonts/icons.woff +0 -0
- data/support/editor-app/development/semantic/themes/default/assets/images/flags.png +0 -0
- data/support/editor-app/development/src/apis/index.coffee +35 -0
- data/support/editor-app/development/src/components/editor.cjsx +58 -0
- data/support/editor-app/development/src/components/editor_drawer.cjsx +7 -0
- data/support/editor-app/development/src/components/header.cjsx +12 -0
- data/support/editor-app/development/src/components/index.coffee +9 -0
- data/support/editor-app/development/src/components/menus/icon_grid.cjsx +0 -0
- data/support/editor-app/development/src/components/sidebar.cjsx +24 -0
- data/support/editor-app/development/src/components/tiled_grid.cjsx +35 -0
- data/support/editor-app/development/src/index.cjsx +82 -0
- data/support/editor-app/development/src/lib/util.coffee +48 -0
- data/support/editor-app/development/src/pages/home.cjsx +46 -0
- data/support/editor-app/development/src/pages/index.coffee +6 -0
- data/support/editor-app/development/src/pages/package_details.cjsx +55 -0
- data/support/editor-app/development/src/registry.coffee +35 -0
- data/support/editor-app/development/src/styles/components/tiled_grid.css.scss +5 -0
- data/support/editor-app/development/src/styles/index.css.scss +240 -0
- data/support/editor-app/development/src/sugar.cjsx +126 -0
- data/support/editor-app/development/webpack.config.js +53 -0
- data/support/editor-app/dist/base.css +0 -0
- data/support/editor-app/dist/toolit.js +62 -0
- data/support/editor-app/dist/toolkit.js +44573 -0
- data/support/editor-app/index.html +50 -0
- data/support/editor-app/package.json +15 -0
- data/support/editor-app/semantic/components/accordion.css +257 -0
- data/support/editor-app/semantic/components/accordion.js +558 -0
- data/support/editor-app/semantic/components/accordion.min.css +11 -0
- data/support/editor-app/semantic/components/accordion.min.js +11 -0
- data/support/editor-app/semantic/components/ad.css +277 -0
- data/support/editor-app/semantic/components/ad.min.css +11 -0
- data/support/editor-app/semantic/components/api.js +851 -0
- data/support/editor-app/semantic/components/api.min.js +11 -0
- data/support/editor-app/semantic/components/breadcrumb.css +125 -0
- data/support/editor-app/semantic/components/breadcrumb.min.css +11 -0
- data/support/editor-app/semantic/components/button.css +2391 -0
- data/support/editor-app/semantic/components/button.min.css +11 -0
- data/support/editor-app/semantic/components/card.css +758 -0
- data/support/editor-app/semantic/components/card.min.css +11 -0
- data/support/editor-app/semantic/components/checkbox.css +514 -0
- data/support/editor-app/semantic/components/checkbox.js +507 -0
- data/support/editor-app/semantic/components/checkbox.min.css +11 -0
- data/support/editor-app/semantic/components/checkbox.min.js +11 -0
- data/support/editor-app/semantic/components/comment.css +260 -0
- data/support/editor-app/semantic/components/comment.min.css +11 -0
- data/support/editor-app/semantic/components/dimmer.css +187 -0
- data/support/editor-app/semantic/components/dimmer.js +627 -0
- data/support/editor-app/semantic/components/dimmer.min.css +11 -0
- data/support/editor-app/semantic/components/dimmer.min.js +11 -0
- data/support/editor-app/semantic/components/divider.css +244 -0
- data/support/editor-app/semantic/components/divider.min.css +11 -0
- data/support/editor-app/semantic/components/dropdown.css +1085 -0
- data/support/editor-app/semantic/components/dropdown.js +1757 -0
- data/support/editor-app/semantic/components/dropdown.min.css +11 -0
- data/support/editor-app/semantic/components/dropdown.min.js +11 -0
- data/support/editor-app/semantic/components/feed.css +277 -0
- data/support/editor-app/semantic/components/feed.min.css +11 -0
- data/support/editor-app/semantic/components/flag.css +1017 -0
- data/support/editor-app/semantic/components/flag.min.css +11 -0
- data/support/editor-app/semantic/components/form.css +875 -0
- data/support/editor-app/semantic/components/form.js +1039 -0
- data/support/editor-app/semantic/components/form.min.css +11 -0
- data/support/editor-app/semantic/components/form.min.js +11 -0
- data/support/editor-app/semantic/components/grid.css +1816 -0
- data/support/editor-app/semantic/components/grid.min.css +11 -0
- data/support/editor-app/semantic/components/header.css +572 -0
- data/support/editor-app/semantic/components/header.min.css +11 -0
- data/support/editor-app/semantic/components/icon.css +2127 -0
- data/support/editor-app/semantic/components/icon.min.css +11 -0
- data/support/editor-app/semantic/components/image.css +275 -0
- data/support/editor-app/semantic/components/image.min.css +11 -0
- data/support/editor-app/semantic/components/input.css +455 -0
- data/support/editor-app/semantic/components/input.min.css +11 -0
- data/support/editor-app/semantic/components/item.css +458 -0
- data/support/editor-app/semantic/components/item.min.css +11 -0
- data/support/editor-app/semantic/components/label.css +930 -0
- data/support/editor-app/semantic/components/label.min.css +11 -0
- data/support/editor-app/semantic/components/list.css +879 -0
- data/support/editor-app/semantic/components/list.min.css +11 -0
- data/support/editor-app/semantic/components/loader.css +279 -0
- data/support/editor-app/semantic/components/loader.min.css +11 -0
- data/support/editor-app/semantic/components/menu.css +1596 -0
- data/support/editor-app/semantic/components/menu.min.css +11 -0
- data/support/editor-app/semantic/components/message.css +422 -0
- data/support/editor-app/semantic/components/message.min.css +11 -0
- data/support/editor-app/semantic/components/modal.css +431 -0
- data/support/editor-app/semantic/components/modal.js +860 -0
- data/support/editor-app/semantic/components/modal.min.css +11 -0
- data/support/editor-app/semantic/components/modal.min.js +11 -0
- data/support/editor-app/semantic/components/nag.css +149 -0
- data/support/editor-app/semantic/components/nag.js +477 -0
- data/support/editor-app/semantic/components/nag.min.css +11 -0
- data/support/editor-app/semantic/components/nag.min.js +11 -0
- data/support/editor-app/semantic/components/popup.css +294 -0
- data/support/editor-app/semantic/components/popup.js +1187 -0
- data/support/editor-app/semantic/components/popup.min.css +11 -0
- data/support/editor-app/semantic/components/popup.min.js +11 -0
- data/support/editor-app/semantic/components/progress.css +449 -0
- data/support/editor-app/semantic/components/progress.js +785 -0
- data/support/editor-app/semantic/components/progress.min.css +11 -0
- data/support/editor-app/semantic/components/progress.min.js +11 -0
- data/support/editor-app/semantic/components/rail.css +125 -0
- data/support/editor-app/semantic/components/rail.min.css +11 -0
- data/support/editor-app/semantic/components/rating.css +262 -0
- data/support/editor-app/semantic/components/rating.js +451 -0
- data/support/editor-app/semantic/components/rating.min.css +11 -0
- data/support/editor-app/semantic/components/rating.min.js +11 -0
- data/support/editor-app/semantic/components/reset.css +430 -0
- data/support/editor-app/semantic/components/reset.min.css +11 -0
- data/support/editor-app/semantic/components/reveal.css +294 -0
- data/support/editor-app/semantic/components/reveal.min.css +11 -0
- data/support/editor-app/semantic/components/search.css +330 -0
- data/support/editor-app/semantic/components/search.js +1055 -0
- data/support/editor-app/semantic/components/search.min.css +11 -0
- data/support/editor-app/semantic/components/search.min.js +11 -0
- data/support/editor-app/semantic/components/segment.css +590 -0
- data/support/editor-app/semantic/components/segment.min.css +11 -0
- data/support/editor-app/semantic/components/shape.css +155 -0
- data/support/editor-app/semantic/components/shape.js +830 -0
- data/support/editor-app/semantic/components/shape.min.css +11 -0
- data/support/editor-app/semantic/components/shape.min.js +11 -0
- data/support/editor-app/semantic/components/sidebar.css +621 -0
- data/support/editor-app/semantic/components/sidebar.js +1084 -0
- data/support/editor-app/semantic/components/sidebar.min.css +11 -0
- data/support/editor-app/semantic/components/sidebar.min.js +11 -0
- data/support/editor-app/semantic/components/site.css +147 -0
- data/support/editor-app/semantic/components/site.js +487 -0
- data/support/editor-app/semantic/components/site.min.css +11 -0
- data/support/editor-app/semantic/components/site.min.js +11 -0
- data/support/editor-app/semantic/components/state.js +690 -0
- data/support/editor-app/semantic/components/state.min.js +11 -0
- data/support/editor-app/semantic/components/statistic.css +410 -0
- data/support/editor-app/semantic/components/statistic.min.css +11 -0
- data/support/editor-app/semantic/components/step.css +433 -0
- data/support/editor-app/semantic/components/step.min.css +11 -0
- data/support/editor-app/semantic/components/sticky.css +80 -0
- data/support/editor-app/semantic/components/sticky.js +775 -0
- data/support/editor-app/semantic/components/sticky.min.css +11 -0
- data/support/editor-app/semantic/components/sticky.min.js +11 -0
- data/support/editor-app/semantic/components/tab.css +93 -0
- data/support/editor-app/semantic/components/tab.js +787 -0
- data/support/editor-app/semantic/components/tab.min.css +11 -0
- data/support/editor-app/semantic/components/tab.min.js +11 -0
- data/support/editor-app/semantic/components/table.css +999 -0
- data/support/editor-app/semantic/components/table.min.css +11 -0
- data/support/editor-app/semantic/components/transition.css +2152 -0
- data/support/editor-app/semantic/components/transition.js +936 -0
- data/support/editor-app/semantic/components/transition.min.css +11 -0
- data/support/editor-app/semantic/components/transition.min.js +11 -0
- data/support/editor-app/semantic/components/video.css +126 -0
- data/support/editor-app/semantic/components/video.js +540 -0
- data/support/editor-app/semantic/components/video.min.css +11 -0
- data/support/editor-app/semantic/components/video.min.js +11 -0
- data/support/editor-app/semantic/components/visibility.js +970 -0
- data/support/editor-app/semantic/components/visibility.min.js +11 -0
- data/support/editor-app/semantic/semantic.css +31768 -0
- data/support/editor-app/semantic/semantic.js +18317 -0
- data/support/editor-app/semantic/semantic.min.css +11 -0
- data/support/editor-app/semantic/semantic.min.js +17 -0
- data/support/editor-app/semantic/themes/basic/assets/fonts/icons.eot +0 -0
- data/support/editor-app/semantic/themes/basic/assets/fonts/icons.svg +450 -0
- data/support/editor-app/semantic/themes/basic/assets/fonts/icons.ttf +0 -0
- data/support/editor-app/semantic/themes/basic/assets/fonts/icons.woff +0 -0
- data/support/editor-app/semantic/themes/default/assets/fonts/icons.eot +0 -0
- data/support/editor-app/semantic/themes/default/assets/fonts/icons.otf +0 -0
- data/support/editor-app/semantic/themes/default/assets/fonts/icons.svg +504 -0
- data/support/editor-app/semantic/themes/default/assets/fonts/icons.ttf +0 -0
- data/support/editor-app/semantic/themes/default/assets/fonts/icons.woff +0 -0
- data/support/editor-app/semantic/themes/default/assets/images/flags.png +0 -0
- data/support/editor-app/vendor/jquery.js +8829 -0
- data/support/library-server/Gemfile +0 -0
- data/support/library-server/config.ru +4 -0
- metadata +740 -7
@@ -0,0 +1,1039 @@
|
|
1
|
+
/*
|
2
|
+
* # Semantic - Form Validation
|
3
|
+
* http://github.com/semantic-org/semantic-ui/
|
4
|
+
*
|
5
|
+
*
|
6
|
+
* Copyright 2014 Contributor
|
7
|
+
* Released under the MIT license
|
8
|
+
* http://opensource.org/licenses/MIT
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
|
12
|
+
;(function ( $, window, document, undefined ) {
|
13
|
+
|
14
|
+
$.fn.form = function(fields, parameters) {
|
15
|
+
var
|
16
|
+
$allModules = $(this),
|
17
|
+
|
18
|
+
settings = $.extend(true, {}, $.fn.form.settings, parameters),
|
19
|
+
validation = $.extend({}, $.fn.form.settings.defaults, fields),
|
20
|
+
|
21
|
+
namespace = settings.namespace,
|
22
|
+
metadata = settings.metadata,
|
23
|
+
selector = settings.selector,
|
24
|
+
className = settings.className,
|
25
|
+
error = settings.error,
|
26
|
+
|
27
|
+
eventNamespace = '.' + namespace,
|
28
|
+
moduleNamespace = 'module-' + namespace,
|
29
|
+
|
30
|
+
moduleSelector = $allModules.selector || '',
|
31
|
+
|
32
|
+
time = new Date().getTime(),
|
33
|
+
performance = [],
|
34
|
+
|
35
|
+
query = arguments[0],
|
36
|
+
methodInvoked = (typeof query == 'string'),
|
37
|
+
queryArguments = [].slice.call(arguments, 1),
|
38
|
+
returnedValue
|
39
|
+
;
|
40
|
+
$allModules
|
41
|
+
.each(function() {
|
42
|
+
var
|
43
|
+
$module = $(this),
|
44
|
+
$field = $(this).find(selector.field),
|
45
|
+
$group = $(this).find(selector.group),
|
46
|
+
$message = $(this).find(selector.message),
|
47
|
+
$prompt = $(this).find(selector.prompt),
|
48
|
+
|
49
|
+
$submit = $(this).find(selector.submit),
|
50
|
+
$clear = $(this).find(selector.clear),
|
51
|
+
$reset = $(this).find(selector.reset),
|
52
|
+
|
53
|
+
formErrors = [],
|
54
|
+
keyHeldDown = false,
|
55
|
+
|
56
|
+
element = this,
|
57
|
+
instance = $module.data(moduleNamespace),
|
58
|
+
module
|
59
|
+
;
|
60
|
+
|
61
|
+
module = {
|
62
|
+
|
63
|
+
initialize: function() {
|
64
|
+
module.verbose('Initializing form validation', $module, validation, settings);
|
65
|
+
module.bindEvents();
|
66
|
+
module.set.defaults();
|
67
|
+
module.instantiate();
|
68
|
+
},
|
69
|
+
|
70
|
+
instantiate: function() {
|
71
|
+
module.verbose('Storing instance of module', module);
|
72
|
+
instance = module;
|
73
|
+
$module
|
74
|
+
.data(moduleNamespace, module)
|
75
|
+
;
|
76
|
+
},
|
77
|
+
|
78
|
+
destroy: function() {
|
79
|
+
module.verbose('Destroying previous module', instance);
|
80
|
+
module.removeEvents();
|
81
|
+
$module
|
82
|
+
.removeData(moduleNamespace)
|
83
|
+
;
|
84
|
+
},
|
85
|
+
|
86
|
+
refresh: function() {
|
87
|
+
module.verbose('Refreshing selector cache');
|
88
|
+
$field = $module.find(selector.field);
|
89
|
+
},
|
90
|
+
|
91
|
+
submit: function() {
|
92
|
+
module.verbose('Submitting form', $module);
|
93
|
+
$module
|
94
|
+
.submit()
|
95
|
+
;
|
96
|
+
},
|
97
|
+
|
98
|
+
attachEvents: function(selector, action) {
|
99
|
+
action = action || 'submit';
|
100
|
+
$(selector)
|
101
|
+
.on('click', function(event) {
|
102
|
+
module[action]();
|
103
|
+
event.preventDefault();
|
104
|
+
})
|
105
|
+
;
|
106
|
+
},
|
107
|
+
|
108
|
+
bindEvents: function() {
|
109
|
+
if(settings.keyboardShortcuts) {
|
110
|
+
$field
|
111
|
+
.on('keydown' + eventNamespace, module.event.field.keydown)
|
112
|
+
;
|
113
|
+
}
|
114
|
+
$module
|
115
|
+
.on('submit' + eventNamespace, module.validate.form)
|
116
|
+
;
|
117
|
+
$field
|
118
|
+
.on('blur' + eventNamespace, module.event.field.blur)
|
119
|
+
;
|
120
|
+
|
121
|
+
// attach events to common elements
|
122
|
+
module.attachEvents($submit, 'submit');
|
123
|
+
module.attachEvents($reset, 'reset');
|
124
|
+
module.attachEvents($clear, 'clear');
|
125
|
+
|
126
|
+
$field
|
127
|
+
.each(function() {
|
128
|
+
var
|
129
|
+
type = $(this).prop('type'),
|
130
|
+
inputEvent = module.get.changeEvent(type)
|
131
|
+
;
|
132
|
+
$(this)
|
133
|
+
.on(inputEvent + eventNamespace, module.event.field.change)
|
134
|
+
;
|
135
|
+
})
|
136
|
+
;
|
137
|
+
},
|
138
|
+
|
139
|
+
clear: function() {
|
140
|
+
$field
|
141
|
+
.each(function () {
|
142
|
+
var
|
143
|
+
$field = $(this),
|
144
|
+
$element = $field.parent(),
|
145
|
+
$fieldGroup = $field.closest($group),
|
146
|
+
$prompt = $fieldGroup.find(selector.prompt),
|
147
|
+
defaultValue = $field.data(metadata.defaultValue) || '',
|
148
|
+
isCheckbox = $element.is(selector.uiCheckbox),
|
149
|
+
isDropdown = $element.is(selector.uiDropdown),
|
150
|
+
isErrored = $fieldGroup.hasClass(className.error)
|
151
|
+
;
|
152
|
+
if(isErrored) {
|
153
|
+
module.verbose('Resetting error on field', $fieldGroup);
|
154
|
+
$fieldGroup.removeClass(className.error);
|
155
|
+
$prompt.remove();
|
156
|
+
}
|
157
|
+
if(isDropdown) {
|
158
|
+
module.verbose('Resetting dropdown value', $element, defaultValue);
|
159
|
+
$element.dropdown('clear');
|
160
|
+
}
|
161
|
+
else if(isCheckbox) {
|
162
|
+
$element.checkbox('uncheck');
|
163
|
+
}
|
164
|
+
else {
|
165
|
+
module.verbose('Resetting field value', $field, defaultValue);
|
166
|
+
$field.val('');
|
167
|
+
}
|
168
|
+
})
|
169
|
+
;
|
170
|
+
},
|
171
|
+
|
172
|
+
reset: function() {
|
173
|
+
$field
|
174
|
+
.each(function () {
|
175
|
+
var
|
176
|
+
$field = $(this),
|
177
|
+
$element = $field.parent(),
|
178
|
+
$fieldGroup = $field.closest($group),
|
179
|
+
$prompt = $fieldGroup.find(selector.prompt),
|
180
|
+
defaultValue = $field.data(metadata.defaultValue) || '',
|
181
|
+
isCheckbox = $element.is(selector.uiCheckbox),
|
182
|
+
isDropdown = $element.is(selector.uiDropdown),
|
183
|
+
isErrored = $fieldGroup.hasClass(className.error)
|
184
|
+
;
|
185
|
+
if(isErrored) {
|
186
|
+
module.verbose('Resetting error on field', $fieldGroup);
|
187
|
+
$fieldGroup.removeClass(className.error);
|
188
|
+
$prompt.remove();
|
189
|
+
}
|
190
|
+
if(isDropdown) {
|
191
|
+
module.verbose('Resetting dropdown value', $element, defaultValue);
|
192
|
+
$element.dropdown('restore defaults');
|
193
|
+
}
|
194
|
+
else if(isCheckbox) {
|
195
|
+
module.verbose('Resetting checkbox value', $element, defaultValue);
|
196
|
+
if(defaultValue === true) {
|
197
|
+
$element.checkbox('check');
|
198
|
+
}
|
199
|
+
else {
|
200
|
+
$element.checkbox('uncheck');
|
201
|
+
}
|
202
|
+
}
|
203
|
+
else {
|
204
|
+
module.verbose('Resetting field value', $field, defaultValue);
|
205
|
+
$field.val(defaultValue);
|
206
|
+
}
|
207
|
+
})
|
208
|
+
;
|
209
|
+
},
|
210
|
+
|
211
|
+
removeEvents: function() {
|
212
|
+
$module
|
213
|
+
.off(eventNamespace)
|
214
|
+
;
|
215
|
+
$field
|
216
|
+
.off(eventNamespace)
|
217
|
+
;
|
218
|
+
$submit
|
219
|
+
.off(eventNamespace)
|
220
|
+
;
|
221
|
+
$field
|
222
|
+
.off(eventNamespace)
|
223
|
+
;
|
224
|
+
},
|
225
|
+
|
226
|
+
event: {
|
227
|
+
field: {
|
228
|
+
keydown: function(event) {
|
229
|
+
var
|
230
|
+
$field = $(this),
|
231
|
+
key = event.which,
|
232
|
+
keyCode = {
|
233
|
+
enter : 13,
|
234
|
+
escape : 27
|
235
|
+
}
|
236
|
+
;
|
237
|
+
if( key == keyCode.escape) {
|
238
|
+
module.verbose('Escape key pressed blurring field');
|
239
|
+
$field
|
240
|
+
.blur()
|
241
|
+
;
|
242
|
+
}
|
243
|
+
if(!event.ctrlKey && key == keyCode.enter && $field.is(selector.input) && $field.not(selector.checkbox).length > 0 ) {
|
244
|
+
$submit
|
245
|
+
.addClass(className.pressed)
|
246
|
+
;
|
247
|
+
if(!keyHeldDown) {
|
248
|
+
$field
|
249
|
+
.one('keyup' + eventNamespace, module.event.field.keyup)
|
250
|
+
;
|
251
|
+
module.submit();
|
252
|
+
module.debug('Enter pressed on input submitting form');
|
253
|
+
}
|
254
|
+
keyHeldDown = true;
|
255
|
+
}
|
256
|
+
},
|
257
|
+
keyup: function() {
|
258
|
+
keyHeldDown = false;
|
259
|
+
$submit.removeClass(className.pressed);
|
260
|
+
},
|
261
|
+
blur: function() {
|
262
|
+
var
|
263
|
+
$field = $(this),
|
264
|
+
$fieldGroup = $field.closest($group)
|
265
|
+
;
|
266
|
+
if( $fieldGroup.hasClass(className.error) ) {
|
267
|
+
module.debug('Revalidating field', $field, module.get.validation($field));
|
268
|
+
module.validate.field( module.get.validation($field) );
|
269
|
+
}
|
270
|
+
else if(settings.on == 'blur' || settings.on == 'change') {
|
271
|
+
module.validate.field( module.get.validation($field) );
|
272
|
+
}
|
273
|
+
},
|
274
|
+
change: function() {
|
275
|
+
var
|
276
|
+
$field = $(this),
|
277
|
+
$fieldGroup = $field.closest($group)
|
278
|
+
;
|
279
|
+
if(settings.on == 'change' || ( $fieldGroup.hasClass(className.error) && settings.revalidate) ) {
|
280
|
+
clearTimeout(module.timer);
|
281
|
+
module.timer = setTimeout(function() {
|
282
|
+
module.debug('Revalidating field', $field, module.get.validation($field));
|
283
|
+
module.validate.field( module.get.validation($field) );
|
284
|
+
}, settings.delay);
|
285
|
+
}
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
},
|
290
|
+
|
291
|
+
get: {
|
292
|
+
changeEvent: function(type) {
|
293
|
+
if(type == 'checkbox' || type == 'radio' || type == 'hidden') {
|
294
|
+
return 'change';
|
295
|
+
}
|
296
|
+
else {
|
297
|
+
return module.get.inputEvent();
|
298
|
+
}
|
299
|
+
},
|
300
|
+
inputEvent: function() {
|
301
|
+
return (document.createElement('input').oninput !== undefined)
|
302
|
+
? 'input'
|
303
|
+
: (document.createElement('input').onpropertychange !== undefined)
|
304
|
+
? 'propertychange'
|
305
|
+
: 'keyup'
|
306
|
+
;
|
307
|
+
},
|
308
|
+
field: function(identifier) {
|
309
|
+
module.verbose('Finding field with identifier', identifier);
|
310
|
+
if( $field.filter('#' + identifier).length > 0 ) {
|
311
|
+
return $field.filter('#' + identifier);
|
312
|
+
}
|
313
|
+
else if( $field.filter('[name="' + identifier +'"]').length > 0 ) {
|
314
|
+
return $field.filter('[name="' + identifier +'"]');
|
315
|
+
}
|
316
|
+
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').length > 0 ) {
|
317
|
+
return $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]');
|
318
|
+
}
|
319
|
+
return $('<input/>');
|
320
|
+
},
|
321
|
+
validation: function($field) {
|
322
|
+
var
|
323
|
+
rules
|
324
|
+
;
|
325
|
+
$.each(validation, function(fieldName, field) {
|
326
|
+
if( module.get.field(field.identifier).get(0) == $field.get(0) ) {
|
327
|
+
rules = field;
|
328
|
+
}
|
329
|
+
});
|
330
|
+
return rules || false;
|
331
|
+
},
|
332
|
+
value: function (field) {
|
333
|
+
var
|
334
|
+
fields = [],
|
335
|
+
results
|
336
|
+
;
|
337
|
+
fields.push(field);
|
338
|
+
results = module.get.values.call(element, fields);
|
339
|
+
return results[field];
|
340
|
+
},
|
341
|
+
values: function (fields) {
|
342
|
+
var
|
343
|
+
values = {}
|
344
|
+
;
|
345
|
+
// return all fields if no parameters
|
346
|
+
if(!$.isArray(fields)) {
|
347
|
+
fields = $field;
|
348
|
+
}
|
349
|
+
$.each(fields, function(index, field) {
|
350
|
+
var
|
351
|
+
$field = (typeof field === 'string')
|
352
|
+
? module.get.field(field)
|
353
|
+
: $(field),
|
354
|
+
type = $field.prop('type'),
|
355
|
+
name = $field.prop('name'),
|
356
|
+
value = $field.val(),
|
357
|
+
isCheckbox = $field.is(selector.checkbox),
|
358
|
+
isRadio = $field.is(selector.radio),
|
359
|
+
isChecked = (isCheckbox)
|
360
|
+
? $field.is(':checked')
|
361
|
+
: false
|
362
|
+
;
|
363
|
+
if(name) {
|
364
|
+
if(isRadio) {
|
365
|
+
if(isChecked) {
|
366
|
+
values[name] = value;
|
367
|
+
}
|
368
|
+
}
|
369
|
+
else if(isCheckbox) {
|
370
|
+
if(isChecked) {
|
371
|
+
values[name] = true;
|
372
|
+
}
|
373
|
+
else {
|
374
|
+
module.debug('Omitted unchecked checkbox', $field);
|
375
|
+
return true;
|
376
|
+
}
|
377
|
+
}
|
378
|
+
else {
|
379
|
+
values[name] = value;
|
380
|
+
}
|
381
|
+
}
|
382
|
+
});
|
383
|
+
return values;
|
384
|
+
}
|
385
|
+
},
|
386
|
+
|
387
|
+
has: {
|
388
|
+
|
389
|
+
field: function(identifier) {
|
390
|
+
module.verbose('Checking for existence of a field with identifier', identifier);
|
391
|
+
if( $field.filter('#' + identifier).length > 0 ) {
|
392
|
+
return true;
|
393
|
+
}
|
394
|
+
else if( $field.filter('[name="' + identifier +'"]').length > 0 ) {
|
395
|
+
return true;
|
396
|
+
}
|
397
|
+
else if( $field.filter('[data-' + metadata.validate + '="'+ identifier +'"]').length > 0 ) {
|
398
|
+
return true;
|
399
|
+
}
|
400
|
+
return false;
|
401
|
+
}
|
402
|
+
|
403
|
+
},
|
404
|
+
|
405
|
+
add: {
|
406
|
+
prompt: function(identifier, errors) {
|
407
|
+
var
|
408
|
+
$field = module.get.field(identifier),
|
409
|
+
$fieldGroup = $field.closest($group),
|
410
|
+
$prompt = $fieldGroup.children(selector.prompt),
|
411
|
+
promptExists = ($prompt.length !== 0)
|
412
|
+
;
|
413
|
+
errors = (typeof errors == 'string')
|
414
|
+
? [errors]
|
415
|
+
: errors
|
416
|
+
;
|
417
|
+
module.verbose('Adding field error state', identifier);
|
418
|
+
$fieldGroup
|
419
|
+
.addClass(className.error)
|
420
|
+
;
|
421
|
+
if(settings.inline) {
|
422
|
+
if(!promptExists) {
|
423
|
+
$prompt = settings.templates.prompt(errors);
|
424
|
+
$prompt
|
425
|
+
.appendTo($fieldGroup)
|
426
|
+
;
|
427
|
+
}
|
428
|
+
$prompt
|
429
|
+
.html(errors[0])
|
430
|
+
;
|
431
|
+
if(!promptExists) {
|
432
|
+
if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
|
433
|
+
module.verbose('Displaying error with css transition', settings.transition);
|
434
|
+
$prompt.transition(settings.transition + ' in', settings.duration);
|
435
|
+
}
|
436
|
+
else {
|
437
|
+
module.verbose('Displaying error with fallback javascript animation');
|
438
|
+
$prompt
|
439
|
+
.fadeIn(settings.duration)
|
440
|
+
;
|
441
|
+
}
|
442
|
+
}
|
443
|
+
else {
|
444
|
+
module.verbose('Inline errors are disabled, no inline error added', identifier);
|
445
|
+
}
|
446
|
+
}
|
447
|
+
},
|
448
|
+
errors: function(errors) {
|
449
|
+
module.debug('Adding form error messages', errors);
|
450
|
+
$message
|
451
|
+
.html( settings.templates.error(errors) )
|
452
|
+
;
|
453
|
+
}
|
454
|
+
},
|
455
|
+
|
456
|
+
remove: {
|
457
|
+
prompt: function(field) {
|
458
|
+
var
|
459
|
+
$field = module.get.field(field.identifier),
|
460
|
+
$fieldGroup = $field.closest($group),
|
461
|
+
$prompt = $fieldGroup.children(selector.prompt)
|
462
|
+
;
|
463
|
+
$fieldGroup
|
464
|
+
.removeClass(className.error)
|
465
|
+
;
|
466
|
+
if(settings.inline && $prompt.is(':visible')) {
|
467
|
+
module.verbose('Removing prompt for field', field);
|
468
|
+
if(settings.transition && $.fn.transition !== undefined && $module.transition('is supported')) {
|
469
|
+
$prompt.transition(settings.transition + ' out', settings.duration, function() {
|
470
|
+
$prompt.remove();
|
471
|
+
});
|
472
|
+
}
|
473
|
+
else {
|
474
|
+
$prompt
|
475
|
+
.fadeOut(settings.duration, function(){
|
476
|
+
$prompt.remove();
|
477
|
+
})
|
478
|
+
;
|
479
|
+
}
|
480
|
+
}
|
481
|
+
}
|
482
|
+
},
|
483
|
+
|
484
|
+
set: {
|
485
|
+
success: function() {
|
486
|
+
$module
|
487
|
+
.removeClass(className.error)
|
488
|
+
.addClass(className.success)
|
489
|
+
;
|
490
|
+
},
|
491
|
+
defaults: function () {
|
492
|
+
$field
|
493
|
+
.each(function () {
|
494
|
+
var
|
495
|
+
$field = $(this),
|
496
|
+
isCheckbox = ($field.filter(selector.checkbox).length > 0),
|
497
|
+
value = (isCheckbox)
|
498
|
+
? $field.is(':checked')
|
499
|
+
: $field.val()
|
500
|
+
;
|
501
|
+
$field.data(metadata.defaultValue, value);
|
502
|
+
})
|
503
|
+
;
|
504
|
+
},
|
505
|
+
error: function() {
|
506
|
+
$module
|
507
|
+
.removeClass(className.success)
|
508
|
+
.addClass(className.error)
|
509
|
+
;
|
510
|
+
},
|
511
|
+
value: function (field, value) {
|
512
|
+
var
|
513
|
+
fields = {}
|
514
|
+
;
|
515
|
+
fields[field] = value;
|
516
|
+
return module.set.values.call(element, fields);
|
517
|
+
},
|
518
|
+
values: function (fields) {
|
519
|
+
if($.isEmptyObject(fields)) {
|
520
|
+
return;
|
521
|
+
}
|
522
|
+
$.each(fields, function(key, value) {
|
523
|
+
var
|
524
|
+
$field = module.get.field(key),
|
525
|
+
$element = $field.parent(),
|
526
|
+
isCheckbox = $element.is(selector.uiCheckbox),
|
527
|
+
isDropdown = $element.is(selector.uiDropdown),
|
528
|
+
isRadio = $field.is(selector.radio),
|
529
|
+
fieldExists = ($field.length > 0)
|
530
|
+
;
|
531
|
+
if(fieldExists) {
|
532
|
+
if(isRadio && isCheckbox) {
|
533
|
+
module.verbose('Selecting radio value', value, $field);
|
534
|
+
$field.filter('[value="' + value + '"]')
|
535
|
+
.parent(selector.uiCheckbox)
|
536
|
+
.checkbox('check')
|
537
|
+
;
|
538
|
+
}
|
539
|
+
else if(isCheckbox) {
|
540
|
+
module.verbose('Setting checkbox value', value, $element);
|
541
|
+
if(value === true) {
|
542
|
+
$element.checkbox('check');
|
543
|
+
}
|
544
|
+
else {
|
545
|
+
$element.checkbox('uncheck');
|
546
|
+
}
|
547
|
+
}
|
548
|
+
else if(isDropdown) {
|
549
|
+
module.verbose('Setting dropdown value', value, $element);
|
550
|
+
$element.dropdown('set selected', value);
|
551
|
+
}
|
552
|
+
else {
|
553
|
+
module.verbose('Setting field value', value, $field);
|
554
|
+
$field.val(value);
|
555
|
+
}
|
556
|
+
}
|
557
|
+
});
|
558
|
+
module.validate.form();
|
559
|
+
}
|
560
|
+
},
|
561
|
+
|
562
|
+
validate: {
|
563
|
+
|
564
|
+
form: function(event) {
|
565
|
+
var
|
566
|
+
allValid = true,
|
567
|
+
apiRequest
|
568
|
+
;
|
569
|
+
|
570
|
+
// input keydown event will fire submit repeatedly by browser default
|
571
|
+
if(keyHeldDown) {
|
572
|
+
return false;
|
573
|
+
}
|
574
|
+
|
575
|
+
// reset errors
|
576
|
+
formErrors = [];
|
577
|
+
$.each(validation, function(fieldName, field) {
|
578
|
+
if( !( module.validate.field(field) ) ) {
|
579
|
+
allValid = false;
|
580
|
+
}
|
581
|
+
});
|
582
|
+
if(allValid) {
|
583
|
+
module.debug('Form has no validation errors, submitting');
|
584
|
+
module.set.success();
|
585
|
+
return settings.onSuccess.call(element, event);
|
586
|
+
}
|
587
|
+
else {
|
588
|
+
module.debug('Form has errors');
|
589
|
+
module.set.error();
|
590
|
+
if(!settings.inline) {
|
591
|
+
module.add.errors(formErrors);
|
592
|
+
}
|
593
|
+
// prevent ajax submit
|
594
|
+
if($module.data('moduleApi') !== undefined) {
|
595
|
+
event.stopImmediatePropagation();
|
596
|
+
}
|
597
|
+
return settings.onFailure.call(element, formErrors);
|
598
|
+
}
|
599
|
+
},
|
600
|
+
|
601
|
+
// takes a validation object and returns whether field passes validation
|
602
|
+
field: function(field) {
|
603
|
+
var
|
604
|
+
$field = module.get.field(field.identifier),
|
605
|
+
fieldValid = true,
|
606
|
+
fieldErrors = []
|
607
|
+
;
|
608
|
+
if($field.prop('disabled')) {
|
609
|
+
module.debug('Field is disabled. Skipping', field.identifier);
|
610
|
+
fieldValid = true;
|
611
|
+
}
|
612
|
+
else if(field.optional && $.trim($field.val()) === ''){
|
613
|
+
module.debug('Field is optional and empty. Skipping', field.identifier);
|
614
|
+
fieldValid = true;
|
615
|
+
}
|
616
|
+
else if(field.rules !== undefined) {
|
617
|
+
$.each(field.rules, function(index, rule) {
|
618
|
+
if( module.has.field(field.identifier) && !( module.validate.rule(field, rule) ) ) {
|
619
|
+
module.debug('Field is invalid', field.identifier, rule.type);
|
620
|
+
fieldErrors.push(rule.prompt);
|
621
|
+
fieldValid = false;
|
622
|
+
}
|
623
|
+
});
|
624
|
+
}
|
625
|
+
if(fieldValid) {
|
626
|
+
module.remove.prompt(field, fieldErrors);
|
627
|
+
settings.onValid.call($field);
|
628
|
+
}
|
629
|
+
else {
|
630
|
+
formErrors = formErrors.concat(fieldErrors);
|
631
|
+
module.add.prompt(field.identifier, fieldErrors);
|
632
|
+
settings.onInvalid.call($field, fieldErrors);
|
633
|
+
return false;
|
634
|
+
}
|
635
|
+
return true;
|
636
|
+
},
|
637
|
+
|
638
|
+
// takes validation rule and returns whether field passes rule
|
639
|
+
rule: function(field, validation) {
|
640
|
+
var
|
641
|
+
$field = module.get.field(field.identifier),
|
642
|
+
type = validation.type,
|
643
|
+
value = $.trim($field.val() + ''),
|
644
|
+
|
645
|
+
bracketRegExp = /\[(.*)\]/i,
|
646
|
+
bracket = bracketRegExp.exec(type),
|
647
|
+
isValid = true,
|
648
|
+
ancillary,
|
649
|
+
functionType
|
650
|
+
;
|
651
|
+
// if bracket notation is used, pass in extra parameters
|
652
|
+
if(bracket !== undefined && bracket !== null) {
|
653
|
+
ancillary = '' + bracket[1];
|
654
|
+
functionType = type.replace(bracket[0], '');
|
655
|
+
isValid = settings.rules[functionType].call(element, value, ancillary);
|
656
|
+
}
|
657
|
+
// normal notation
|
658
|
+
else {
|
659
|
+
isValid = settings.rules[type].call($field, value);
|
660
|
+
}
|
661
|
+
return isValid;
|
662
|
+
}
|
663
|
+
},
|
664
|
+
|
665
|
+
setting: function(name, value) {
|
666
|
+
if( $.isPlainObject(name) ) {
|
667
|
+
$.extend(true, settings, name);
|
668
|
+
}
|
669
|
+
else if(value !== undefined) {
|
670
|
+
settings[name] = value;
|
671
|
+
}
|
672
|
+
else {
|
673
|
+
return settings[name];
|
674
|
+
}
|
675
|
+
},
|
676
|
+
internal: function(name, value) {
|
677
|
+
if( $.isPlainObject(name) ) {
|
678
|
+
$.extend(true, module, name);
|
679
|
+
}
|
680
|
+
else if(value !== undefined) {
|
681
|
+
module[name] = value;
|
682
|
+
}
|
683
|
+
else {
|
684
|
+
return module[name];
|
685
|
+
}
|
686
|
+
},
|
687
|
+
debug: function() {
|
688
|
+
if(settings.debug) {
|
689
|
+
if(settings.performance) {
|
690
|
+
module.performance.log(arguments);
|
691
|
+
}
|
692
|
+
else {
|
693
|
+
module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
694
|
+
module.debug.apply(console, arguments);
|
695
|
+
}
|
696
|
+
}
|
697
|
+
},
|
698
|
+
verbose: function() {
|
699
|
+
if(settings.verbose && settings.debug) {
|
700
|
+
if(settings.performance) {
|
701
|
+
module.performance.log(arguments);
|
702
|
+
}
|
703
|
+
else {
|
704
|
+
module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':');
|
705
|
+
module.verbose.apply(console, arguments);
|
706
|
+
}
|
707
|
+
}
|
708
|
+
},
|
709
|
+
error: function() {
|
710
|
+
module.error = Function.prototype.bind.call(console.error, console, settings.name + ':');
|
711
|
+
module.error.apply(console, arguments);
|
712
|
+
},
|
713
|
+
performance: {
|
714
|
+
log: function(message) {
|
715
|
+
var
|
716
|
+
currentTime,
|
717
|
+
executionTime,
|
718
|
+
previousTime
|
719
|
+
;
|
720
|
+
if(settings.performance) {
|
721
|
+
currentTime = new Date().getTime();
|
722
|
+
previousTime = time || currentTime;
|
723
|
+
executionTime = currentTime - previousTime;
|
724
|
+
time = currentTime;
|
725
|
+
performance.push({
|
726
|
+
'Name' : message[0],
|
727
|
+
'Arguments' : [].slice.call(message, 1) || '',
|
728
|
+
'Element' : element,
|
729
|
+
'Execution Time' : executionTime
|
730
|
+
});
|
731
|
+
}
|
732
|
+
clearTimeout(module.performance.timer);
|
733
|
+
module.performance.timer = setTimeout(module.performance.display, 100);
|
734
|
+
},
|
735
|
+
display: function() {
|
736
|
+
var
|
737
|
+
title = settings.name + ':',
|
738
|
+
totalTime = 0
|
739
|
+
;
|
740
|
+
time = false;
|
741
|
+
clearTimeout(module.performance.timer);
|
742
|
+
$.each(performance, function(index, data) {
|
743
|
+
totalTime += data['Execution Time'];
|
744
|
+
});
|
745
|
+
title += ' ' + totalTime + 'ms';
|
746
|
+
if(moduleSelector) {
|
747
|
+
title += ' \'' + moduleSelector + '\'';
|
748
|
+
}
|
749
|
+
if($allModules.length > 1) {
|
750
|
+
title += ' ' + '(' + $allModules.length + ')';
|
751
|
+
}
|
752
|
+
if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) {
|
753
|
+
console.groupCollapsed(title);
|
754
|
+
if(console.table) {
|
755
|
+
console.table(performance);
|
756
|
+
}
|
757
|
+
else {
|
758
|
+
$.each(performance, function(index, data) {
|
759
|
+
console.log(data['Name'] + ': ' + data['Execution Time']+'ms');
|
760
|
+
});
|
761
|
+
}
|
762
|
+
console.groupEnd();
|
763
|
+
}
|
764
|
+
performance = [];
|
765
|
+
}
|
766
|
+
},
|
767
|
+
invoke: function(query, passedArguments, context) {
|
768
|
+
var
|
769
|
+
object = instance,
|
770
|
+
maxDepth,
|
771
|
+
found,
|
772
|
+
response
|
773
|
+
;
|
774
|
+
passedArguments = passedArguments || queryArguments;
|
775
|
+
context = element || context;
|
776
|
+
if(typeof query == 'string' && object !== undefined) {
|
777
|
+
query = query.split(/[\. ]/);
|
778
|
+
maxDepth = query.length - 1;
|
779
|
+
$.each(query, function(depth, value) {
|
780
|
+
var camelCaseValue = (depth != maxDepth)
|
781
|
+
? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1)
|
782
|
+
: query
|
783
|
+
;
|
784
|
+
if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) {
|
785
|
+
object = object[camelCaseValue];
|
786
|
+
}
|
787
|
+
else if( object[camelCaseValue] !== undefined ) {
|
788
|
+
found = object[camelCaseValue];
|
789
|
+
return false;
|
790
|
+
}
|
791
|
+
else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) {
|
792
|
+
object = object[value];
|
793
|
+
}
|
794
|
+
else if( object[value] !== undefined ) {
|
795
|
+
found = object[value];
|
796
|
+
return false;
|
797
|
+
}
|
798
|
+
else {
|
799
|
+
return false;
|
800
|
+
}
|
801
|
+
});
|
802
|
+
}
|
803
|
+
if( $.isFunction( found ) ) {
|
804
|
+
response = found.apply(context, passedArguments);
|
805
|
+
}
|
806
|
+
else if(found !== undefined) {
|
807
|
+
response = found;
|
808
|
+
}
|
809
|
+
if($.isArray(returnedValue)) {
|
810
|
+
returnedValue.push(response);
|
811
|
+
}
|
812
|
+
else if(returnedValue !== undefined) {
|
813
|
+
returnedValue = [returnedValue, response];
|
814
|
+
}
|
815
|
+
else if(response !== undefined) {
|
816
|
+
returnedValue = response;
|
817
|
+
}
|
818
|
+
return found;
|
819
|
+
}
|
820
|
+
};
|
821
|
+
if(methodInvoked) {
|
822
|
+
if(instance === undefined) {
|
823
|
+
module.initialize();
|
824
|
+
}
|
825
|
+
module.invoke(query);
|
826
|
+
}
|
827
|
+
else {
|
828
|
+
if(instance !== undefined) {
|
829
|
+
module.destroy();
|
830
|
+
}
|
831
|
+
module.initialize();
|
832
|
+
}
|
833
|
+
|
834
|
+
})
|
835
|
+
;
|
836
|
+
|
837
|
+
return (returnedValue !== undefined)
|
838
|
+
? returnedValue
|
839
|
+
: this
|
840
|
+
;
|
841
|
+
};
|
842
|
+
|
843
|
+
$.fn.form.settings = {
|
844
|
+
|
845
|
+
name : 'Form',
|
846
|
+
namespace : 'form',
|
847
|
+
|
848
|
+
debug : false,
|
849
|
+
verbose : true,
|
850
|
+
performance : true,
|
851
|
+
|
852
|
+
|
853
|
+
keyboardShortcuts : true,
|
854
|
+
on : 'submit',
|
855
|
+
inline : false,
|
856
|
+
|
857
|
+
delay : 200,
|
858
|
+
revalidate : true,
|
859
|
+
|
860
|
+
transition : 'scale',
|
861
|
+
duration : 200,
|
862
|
+
|
863
|
+
onValid : function() {},
|
864
|
+
onInvalid : function() {},
|
865
|
+
onSuccess : function() { return true; },
|
866
|
+
onFailure : function() { return false; },
|
867
|
+
|
868
|
+
metadata : {
|
869
|
+
defaultValue : 'default',
|
870
|
+
validate : 'validate'
|
871
|
+
},
|
872
|
+
|
873
|
+
selector : {
|
874
|
+
checkbox : 'input[type="checkbox"], input[type="radio"]',
|
875
|
+
clear : '.clear',
|
876
|
+
field : 'input, textarea, select',
|
877
|
+
group : '.field',
|
878
|
+
input : 'input',
|
879
|
+
message : '.error.message',
|
880
|
+
prompt : '.prompt.label',
|
881
|
+
radio : 'input[type="radio"]',
|
882
|
+
reset : '.reset',
|
883
|
+
submit : '.submit',
|
884
|
+
uiCheckbox : '.ui.checkbox',
|
885
|
+
uiDropdown : '.ui.dropdown'
|
886
|
+
},
|
887
|
+
|
888
|
+
className : {
|
889
|
+
error : 'error',
|
890
|
+
label : 'ui prompt label',
|
891
|
+
pressed : 'down',
|
892
|
+
success : 'success'
|
893
|
+
},
|
894
|
+
|
895
|
+
error: {
|
896
|
+
method : 'The method you called is not defined.'
|
897
|
+
},
|
898
|
+
|
899
|
+
templates: {
|
900
|
+
|
901
|
+
// template that produces error message
|
902
|
+
error: function(errors) {
|
903
|
+
var
|
904
|
+
html = '<ul class="list">'
|
905
|
+
;
|
906
|
+
$.each(errors, function(index, value) {
|
907
|
+
html += '<li>' + value + '</li>';
|
908
|
+
});
|
909
|
+
html += '</ul>';
|
910
|
+
return $(html);
|
911
|
+
},
|
912
|
+
|
913
|
+
// template that produces label
|
914
|
+
prompt: function(errors) {
|
915
|
+
return $('<div/>')
|
916
|
+
.addClass('ui red pointing prompt label')
|
917
|
+
.html(errors[0])
|
918
|
+
;
|
919
|
+
}
|
920
|
+
},
|
921
|
+
|
922
|
+
rules: {
|
923
|
+
|
924
|
+
// checkbox checked
|
925
|
+
checked: function() {
|
926
|
+
return ($(this).filter(':checked').length > 0);
|
927
|
+
},
|
928
|
+
|
929
|
+
// value contains (text)
|
930
|
+
contains: function(value, text) {
|
931
|
+
text = text.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
|
932
|
+
return (value.search(text) !== -1);
|
933
|
+
},
|
934
|
+
|
935
|
+
// is most likely an email
|
936
|
+
email: function(value){
|
937
|
+
var
|
938
|
+
emailRegExp = new RegExp("[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", "i")
|
939
|
+
;
|
940
|
+
return emailRegExp.test(value);
|
941
|
+
},
|
942
|
+
|
943
|
+
// is not empty or blank string
|
944
|
+
empty: function(value) {
|
945
|
+
return !(value === undefined || '' === value);
|
946
|
+
},
|
947
|
+
|
948
|
+
// is valid integer
|
949
|
+
integer: function(value, range) {
|
950
|
+
var
|
951
|
+
intRegExp = /^\-?\d+$/,
|
952
|
+
min,
|
953
|
+
max,
|
954
|
+
parts
|
955
|
+
;
|
956
|
+
if(range === undefined || range === '' || range === '..') {
|
957
|
+
// do nothing
|
958
|
+
}
|
959
|
+
else if(range.indexOf('..') == -1) {
|
960
|
+
if(intRegExp.test(range)) {
|
961
|
+
min = max = range - 0;
|
962
|
+
}
|
963
|
+
}
|
964
|
+
else {
|
965
|
+
parts = range.split('..', 2);
|
966
|
+
if(intRegExp.test(parts[0])) {
|
967
|
+
min = parts[0] - 0;
|
968
|
+
}
|
969
|
+
if(intRegExp.test(parts[1])) {
|
970
|
+
max = parts[1] - 0;
|
971
|
+
}
|
972
|
+
}
|
973
|
+
return (
|
974
|
+
intRegExp.test(value) &&
|
975
|
+
(min === undefined || value >= min) &&
|
976
|
+
(max === undefined || value <= max)
|
977
|
+
);
|
978
|
+
},
|
979
|
+
|
980
|
+
// is exactly value
|
981
|
+
is: function(value, text) {
|
982
|
+
return (value == text);
|
983
|
+
},
|
984
|
+
|
985
|
+
// is at least string length
|
986
|
+
length: function(value, requiredLength) {
|
987
|
+
return (value !== undefined)
|
988
|
+
? (value.length >= requiredLength)
|
989
|
+
: false
|
990
|
+
;
|
991
|
+
},
|
992
|
+
|
993
|
+
// matches another field
|
994
|
+
match: function(value, fieldIdentifier) {
|
995
|
+
// use either id or name of field
|
996
|
+
var
|
997
|
+
$form = $(this),
|
998
|
+
matchingValue
|
999
|
+
;
|
1000
|
+
if($form.find('#' + fieldIdentifier).length > 0) {
|
1001
|
+
matchingValue = $form.find('#' + fieldIdentifier).val();
|
1002
|
+
}
|
1003
|
+
else if($form.find('[name="' + fieldIdentifier +'"]').length > 0) {
|
1004
|
+
matchingValue = $form.find('[name="' + fieldIdentifier + '"]').val();
|
1005
|
+
}
|
1006
|
+
else if( $form.find('[data-validate="'+ fieldIdentifier +'"]').length > 0 ) {
|
1007
|
+
matchingValue = $form.find('[data-validate="'+ fieldIdentifier +'"]').val();
|
1008
|
+
}
|
1009
|
+
return (matchingValue !== undefined)
|
1010
|
+
? ( value.toString() == matchingValue.toString() )
|
1011
|
+
: false
|
1012
|
+
;
|
1013
|
+
},
|
1014
|
+
|
1015
|
+
// string length is less than max length
|
1016
|
+
maxLength: function(value, maxLength) {
|
1017
|
+
return (value !== undefined)
|
1018
|
+
? (value.length <= maxLength)
|
1019
|
+
: false
|
1020
|
+
;
|
1021
|
+
},
|
1022
|
+
|
1023
|
+
// value is not exactly notValue
|
1024
|
+
not: function(value, notValue) {
|
1025
|
+
return (value != notValue);
|
1026
|
+
},
|
1027
|
+
|
1028
|
+
// value is most likely url
|
1029
|
+
url: function(value) {
|
1030
|
+
var
|
1031
|
+
urlRegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
|
1032
|
+
;
|
1033
|
+
return urlRegExp.test(value);
|
1034
|
+
}
|
1035
|
+
}
|
1036
|
+
|
1037
|
+
};
|
1038
|
+
|
1039
|
+
})( jQuery, window , document );
|