unpoly-rails 0.62.0 → 2.0.0.pre.rc5
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of unpoly-rails might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.yardopts +1 -1
- data/CHANGELOG.md +66 -1
- data/README.md +3 -11
- data/README_RAILS.md +295 -14
- data/dist/unpoly-bootstrap3.css +9 -14
- data/dist/unpoly-bootstrap3.js +4 -18
- data/dist/unpoly-bootstrap3.min.css +1 -1
- data/dist/unpoly-bootstrap3.min.js +1 -1
- data/dist/unpoly-bootstrap4.css +9 -0
- data/dist/unpoly-bootstrap4.js +16 -0
- data/dist/unpoly-bootstrap4.min.css +1 -0
- data/dist/unpoly-bootstrap4.min.js +1 -0
- data/dist/unpoly-bootstrap5.css +9 -0
- data/dist/unpoly-bootstrap5.js +14 -0
- data/dist/unpoly-bootstrap5.min.css +1 -0
- data/dist/unpoly-bootstrap5.min.js +1 -0
- data/dist/unpoly-migrate.js +1213 -0
- data/dist/unpoly-migrate.min.js +1 -0
- data/dist/unpoly.css +109 -140
- data/dist/unpoly.js +15679 -10537
- data/dist/unpoly.min.css +1 -1
- data/dist/unpoly.min.js +6 -4
- data/lib/unpoly-rails.rb +9 -3
- data/lib/unpoly/rails/change.rb +372 -0
- data/lib/unpoly/rails/change/cache.rb +26 -0
- data/lib/unpoly/rails/change/context.rb +80 -0
- data/lib/unpoly/rails/change/field.rb +117 -0
- data/lib/unpoly/rails/change/field_definition.rb +74 -0
- data/lib/unpoly/rails/change/layer.rb +60 -0
- data/lib/unpoly/rails/controller.rb +47 -0
- data/lib/unpoly/rails/error.rb +5 -0
- data/lib/unpoly/rails/request_echo_headers.rb +2 -2
- data/lib/unpoly/rails/version.rb +1 -1
- data/lib/unpoly/tasks.rb +45 -0
- metadata +43 -313
- data/.gitignore +0 -10
- data/.ruby-version +0 -1
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -45
- data/Rakefile +0 -145
- data/bower.json +0 -27
- data/design/animation-ghosting.txt +0 -72
- data/design/design.txt +0 -34
- data/design/draft.html.erb +0 -48
- data/design/draft.rb +0 -9
- data/design/es6.js +0 -32
- data/design/ghost-debugging.txt +0 -118
- data/design/homepage.txt +0 -236
- data/design/ie11.txt +0 -9
- data/design/measure_import_node.js +0 -330
- data/design/measure_jquery/element_list.js +0 -41
- data/design/measure_jquery/up.on_vs_addEventListener.js +0 -56
- data/design/positioning.txt +0 -28
- data/design/query-params-in-form-actions/cases.html +0 -125
- data/design/rename.txt +0 -0
- data/design/test_rejected_promise.txt +0 -5
- data/design/unpoly errors.txt +0 -19
- data/lib/assets/javascripts/unpoly-bootstrap3.coffee +0 -2
- data/lib/assets/javascripts/unpoly-bootstrap3/feedback-ext.coffee +0 -5
- data/lib/assets/javascripts/unpoly-bootstrap3/form-ext.coffee +0 -1
- data/lib/assets/javascripts/unpoly-bootstrap3/modal-ext.coffee +0 -14
- data/lib/assets/javascripts/unpoly-bootstrap3/viewport-ext.coffee +0 -5
- data/lib/assets/javascripts/unpoly.coffee +0 -28
- data/lib/assets/javascripts/unpoly/browser.coffee.erb +0 -240
- data/lib/assets/javascripts/unpoly/classes/body_shifter.coffee +0 -36
- data/lib/assets/javascripts/unpoly/classes/cache.coffee +0 -127
- data/lib/assets/javascripts/unpoly/classes/compile_pass.coffee +0 -93
- data/lib/assets/javascripts/unpoly/classes/config.coffee +0 -9
- data/lib/assets/javascripts/unpoly/classes/css_transition.coffee +0 -118
- data/lib/assets/javascripts/unpoly/classes/divertible_chain.coffee +0 -39
- data/lib/assets/javascripts/unpoly/classes/event_listener.coffee +0 -116
- data/lib/assets/javascripts/unpoly/classes/extract_cascade.coffee +0 -86
- data/lib/assets/javascripts/unpoly/classes/extract_plan.coffee +0 -111
- data/lib/assets/javascripts/unpoly/classes/field_observer.coffee +0 -80
- data/lib/assets/javascripts/unpoly/classes/focus_follower.coffee +0 -29
- data/lib/assets/javascripts/unpoly/classes/follow_variant.coffee +0 -64
- data/lib/assets/javascripts/unpoly/classes/html_parser.coffee +0 -46
- data/lib/assets/javascripts/unpoly/classes/motion_controller.coffee +0 -157
- data/lib/assets/javascripts/unpoly/classes/params.coffee.erb +0 -543
- data/lib/assets/javascripts/unpoly/classes/record.coffee +0 -22
- data/lib/assets/javascripts/unpoly/classes/rect.js +0 -21
- data/lib/assets/javascripts/unpoly/classes/request.coffee +0 -246
- data/lib/assets/javascripts/unpoly/classes/response.coffee +0 -157
- data/lib/assets/javascripts/unpoly/classes/reveal_motion.coffee +0 -102
- data/lib/assets/javascripts/unpoly/classes/scroll_motion.coffee +0 -67
- data/lib/assets/javascripts/unpoly/classes/selector.coffee +0 -60
- data/lib/assets/javascripts/unpoly/classes/store/memory.coffee +0 -26
- data/lib/assets/javascripts/unpoly/classes/store/session.coffee +0 -59
- data/lib/assets/javascripts/unpoly/classes/tether.coffee +0 -105
- data/lib/assets/javascripts/unpoly/classes/url_set.coffee +0 -32
- data/lib/assets/javascripts/unpoly/cookie.coffee +0 -56
- data/lib/assets/javascripts/unpoly/element.coffee.erb +0 -1126
- data/lib/assets/javascripts/unpoly/event.coffee.erb +0 -445
- data/lib/assets/javascripts/unpoly/feedback.coffee +0 -353
- data/lib/assets/javascripts/unpoly/form.coffee.erb +0 -1069
- data/lib/assets/javascripts/unpoly/fragment.coffee.erb +0 -928
- data/lib/assets/javascripts/unpoly/framework.coffee +0 -67
- data/lib/assets/javascripts/unpoly/history.coffee +0 -268
- data/lib/assets/javascripts/unpoly/legacy.coffee +0 -60
- data/lib/assets/javascripts/unpoly/link.coffee.erb +0 -622
- data/lib/assets/javascripts/unpoly/log.coffee +0 -248
- data/lib/assets/javascripts/unpoly/modal.coffee.erb +0 -826
- data/lib/assets/javascripts/unpoly/motion.coffee.erb +0 -668
- data/lib/assets/javascripts/unpoly/namespace.coffee.erb +0 -5
- data/lib/assets/javascripts/unpoly/popup.coffee.erb +0 -515
- data/lib/assets/javascripts/unpoly/protocol.coffee +0 -298
- data/lib/assets/javascripts/unpoly/proxy.coffee +0 -672
- data/lib/assets/javascripts/unpoly/radio.coffee +0 -60
- data/lib/assets/javascripts/unpoly/rails.coffee +0 -24
- data/lib/assets/javascripts/unpoly/syntax.coffee.erb +0 -477
- data/lib/assets/javascripts/unpoly/toast.coffee +0 -67
- data/lib/assets/javascripts/unpoly/tooltip.coffee +0 -276
- data/lib/assets/javascripts/unpoly/util.coffee.erb +0 -1676
- data/lib/assets/javascripts/unpoly/viewport.coffee.erb +0 -830
- data/lib/assets/stylesheets/unpoly-bootstrap3.sass +0 -1
- data/lib/assets/stylesheets/unpoly-bootstrap3/modal-ext.sass +0 -27
- data/lib/assets/stylesheets/unpoly.sass +0 -1
- data/lib/assets/stylesheets/unpoly/close.sass +0 -2
- data/lib/assets/stylesheets/unpoly/dom.sass +0 -5
- data/lib/assets/stylesheets/unpoly/layout.sass +0 -2
- data/lib/assets/stylesheets/unpoly/link.sass +0 -2
- data/lib/assets/stylesheets/unpoly/modal.sass +0 -116
- data/lib/assets/stylesheets/unpoly/popup.sass +0 -7
- data/lib/assets/stylesheets/unpoly/toast.sass +0 -33
- data/lib/assets/stylesheets/unpoly/tooltip.sass +0 -62
- data/lib/unpoly/rails/inspector.rb +0 -149
- data/lib/unpoly/rails/inspector_accessor.rb +0 -30
- data/package.json +0 -38
- data/spec_app/.firefox-version +0 -1
- data/spec_app/.gitignore +0 -17
- data/spec_app/.rspec +0 -2
- data/spec_app/Gemfile +0 -30
- data/spec_app/Gemfile.lock +0 -229
- data/spec_app/README.rdoc +0 -28
- data/spec_app/Rakefile +0 -6
- data/spec_app/app/assets/images/.keep +0 -0
- data/spec_app/app/assets/images/favicon.png +0 -0
- data/spec_app/app/assets/images/grid.png +0 -0
- data/spec_app/app/assets/javascripts/bootstrap_manifest.coffee +0 -6
- data/spec_app/app/assets/javascripts/integration_test.coffee +0 -6
- data/spec_app/app/assets/javascripts/jasmine_specs.coffee +0 -6
- data/spec_app/app/assets/stylesheets/_helpers.sass +0 -5
- data/spec_app/app/assets/stylesheets/bootstrap_manifest.sass +0 -2
- data/spec_app/app/assets/stylesheets/integration_test.sass +0 -88
- data/spec_app/app/assets/stylesheets/jasmine_specs.sass +0 -20
- data/spec_app/app/controllers/application_controller.rb +0 -14
- data/spec_app/app/controllers/binding_test_controller.rb +0 -51
- data/spec_app/app/controllers/compiler_test_controller.rb +0 -5
- data/spec_app/app/controllers/css_test_controller.rb +0 -5
- data/spec_app/app/controllers/error_test_controller.rb +0 -5
- data/spec_app/app/controllers/form_test/basics_controller.rb +0 -14
- data/spec_app/app/controllers/form_test/redirects_controller.rb +0 -17
- data/spec_app/app/controllers/form_test/uploads_controller.rb +0 -15
- data/spec_app/app/controllers/hash_test_controller.rb +0 -5
- data/spec_app/app/controllers/method_test_controller.rb +0 -16
- data/spec_app/app/controllers/motion_test_controller.rb +0 -5
- data/spec_app/app/controllers/pages_controller.rb +0 -9
- data/spec_app/app/controllers/replace_test_controller.rb +0 -5
- data/spec_app/app/controllers/reveal_test_controller.rb +0 -5
- data/spec_app/app/controllers/scroll_test_controller.rb +0 -5
- data/spec_app/app/helpers/application_helper.rb +0 -2
- data/spec_app/app/mailers/.keep +0 -0
- data/spec_app/app/models/concerns/.keep +0 -0
- data/spec_app/app/views/compiler_test/timestamp.erb +0 -9
- data/spec_app/app/views/css_test/modal.erb +0 -47
- data/spec_app/app/views/css_test/modal_contents.erb +0 -5
- data/spec_app/app/views/css_test/modal_contents_wide.erb +0 -5
- data/spec_app/app/views/css_test/popup.erb +0 -81
- data/spec_app/app/views/css_test/popup_contents.erb +0 -5
- data/spec_app/app/views/css_test/tooltip.erb +0 -48
- data/spec_app/app/views/error_test/trigger.erb +0 -80
- data/spec_app/app/views/error_test/unexpected_response.erb +0 -3
- data/spec_app/app/views/form_test/basics/new.erb +0 -60
- data/spec_app/app/views/form_test/redirects/new.erb +0 -27
- data/spec_app/app/views/form_test/redirects/target.erb +0 -4
- data/spec_app/app/views/form_test/submission_result.erb +0 -30
- data/spec_app/app/views/form_test/uploads/new.erb +0 -44
- data/spec_app/app/views/hash_test/unpoly.erb +0 -30
- data/spec_app/app/views/hash_test/vanilla.erb +0 -13
- data/spec_app/app/views/layouts/integration_test.erb +0 -22
- data/spec_app/app/views/layouts/jasmine_rails/spec_runner.html.erb +0 -20
- data/spec_app/app/views/method_test/form_target.erb +0 -17
- data/spec_app/app/views/method_test/page1.erb +0 -11
- data/spec_app/app/views/method_test/page2.erb +0 -6
- data/spec_app/app/views/motion_test/animations.erb +0 -16
- data/spec_app/app/views/motion_test/transitions.erb +0 -13
- data/spec_app/app/views/pages/start.erb +0 -79
- data/spec_app/app/views/replace_test/_nav.erb +0 -6
- data/spec_app/app/views/replace_test/page1.erb +0 -14
- data/spec_app/app/views/replace_test/page2.erb +0 -14
- data/spec_app/app/views/replace_test/table.erb +0 -16
- data/spec_app/app/views/reveal_test/long1.erb +0 -17
- data/spec_app/app/views/reveal_test/long2.erb +0 -17
- data/spec_app/app/views/reveal_test/within_document_viewport.erb +0 -24
- data/spec_app/app/views/reveal_test/within_overflowing_div_viewport.erb +0 -28
- data/spec_app/app/views/scroll_test/long1.erb +0 -30
- data/spec_app/bin/bundle +0 -3
- data/spec_app/bin/rails +0 -8
- data/spec_app/bin/rake +0 -8
- data/spec_app/bin/setup +0 -29
- data/spec_app/bin/spring +0 -18
- data/spec_app/config.ru +0 -4
- data/spec_app/config/application.rb +0 -28
- data/spec_app/config/boot.rb +0 -3
- data/spec_app/config/database.yml +0 -25
- data/spec_app/config/environment.rb +0 -5
- data/spec_app/config/environments/development.rb +0 -41
- data/spec_app/config/environments/production.rb +0 -79
- data/spec_app/config/environments/test.rb +0 -42
- data/spec_app/config/initializers/assets.rb +0 -19
- data/spec_app/config/initializers/backtrace_silencers.rb +0 -7
- data/spec_app/config/initializers/bower_rails.rb +0 -16
- data/spec_app/config/initializers/cookies_serializer.rb +0 -3
- data/spec_app/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec_app/config/initializers/inflections.rb +0 -16
- data/spec_app/config/initializers/mime_types.rb +0 -4
- data/spec_app/config/initializers/session_store.rb +0 -3
- data/spec_app/config/initializers/wrap_parameters.rb +0 -14
- data/spec_app/config/locales/en.yml +0 -23
- data/spec_app/config/routes.rb +0 -30
- data/spec_app/config/secrets.yml +0 -22
- data/spec_app/db/schema.rb +0 -23
- data/spec_app/db/seeds.rb +0 -7
- data/spec_app/lib/assets/.keep +0 -0
- data/spec_app/lib/tasks/.keep +0 -0
- data/spec_app/lib/tasks/cucumber.rake +0 -65
- data/spec_app/log/.keep +0 -0
- data/spec_app/public/404.html +0 -67
- data/spec_app/public/422.html +0 -67
- data/spec_app/public/500.html +0 -66
- data/spec_app/public/favicon.ico +0 -0
- data/spec_app/public/robots.txt +0 -5
- data/spec_app/script/cucumber +0 -10
- data/spec_app/spec/controllers/binding_test_controller_spec.rb +0 -248
- data/spec_app/spec/javascripts/helpers/agent_detector.coffee +0 -20
- data/spec_app/spec/javascripts/helpers/async_sequence.js.coffee +0 -103
- data/spec_app/spec/javascripts/helpers/browser_switches.js.coffee +0 -21
- data/spec_app/spec/javascripts/helpers/enable_logging.js.coffee +0 -2
- data/spec_app/spec/javascripts/helpers/fixture.js.coffee +0 -25
- data/spec_app/spec/javascripts/helpers/index.js.coffee +0 -1
- data/spec_app/spec/javascripts/helpers/jquery_no_conflict.js +0 -1
- data/spec_app/spec/javascripts/helpers/knife.js.coffee +0 -69
- data/spec_app/spec/javascripts/helpers/last_request.js.coffee +0 -25
- data/spec_app/spec/javascripts/helpers/mock_ajax.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/mock_clock.js.coffee +0 -2
- data/spec_app/spec/javascripts/helpers/parse_form_data.js.coffee +0 -24
- data/spec_app/spec/javascripts/helpers/promise_state.js +0 -18
- data/spec_app/spec/javascripts/helpers/protect_jasmine_runner.coffee +0 -12
- data/spec_app/spec/javascripts/helpers/remove_body_margin.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/reset_history.js.coffee +0 -23
- data/spec_app/spec/javascripts/helpers/reset_knife.js.coffee +0 -2
- data/spec_app/spec/javascripts/helpers/reset_up.js.coffee +0 -25
- data/spec_app/spec/javascripts/helpers/restore_body_scroll.js.coffee +0 -5
- data/spec_app/spec/javascripts/helpers/show_lib_versions.coffee +0 -12
- data/spec_app/spec/javascripts/helpers/spec_util.coffee +0 -47
- data/spec_app/spec/javascripts/helpers/to_be_around.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_be_array.coffee +0 -5
- data/spec_app/spec/javascripts/helpers/to_be_attached.coffee +0 -9
- data/spec_app/spec/javascripts/helpers/to_be_blank.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_be_detached.coffee +0 -9
- data/spec_app/spec/javascripts/helpers/to_be_element.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_be_error.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_be_given.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_be_hidden.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_be_jquery.js.coffee +0 -5
- data/spec_app/spec/javascripts/helpers/to_be_missing.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_be_present.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_be_scrolled_to.coffee +0 -11
- data/spec_app/spec/javascripts/helpers/to_be_visible.js.coffee +0 -9
- data/spec_app/spec/javascripts/helpers/to_contain.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_end_with.js.coffee +0 -11
- data/spec_app/spec/javascripts/helpers/to_equal_jquery.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_equal_node_list.coffee +0 -7
- data/spec_app/spec/javascripts/helpers/to_equal_via_is_equal.js.coffee +0 -7
- data/spec_app/spec/javascripts/helpers/to_have_class.js.coffee +0 -10
- data/spec_app/spec/javascripts/helpers/to_have_descendant.js.coffee +0 -10
- data/spec_app/spec/javascripts/helpers/to_have_length.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_have_opacity.coffee +0 -15
- data/spec_app/spec/javascripts/helpers/to_have_own_property.js.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_have_request_method.js.coffee +0 -16
- data/spec_app/spec/javascripts/helpers/to_have_text.js.coffee +0 -9
- data/spec_app/spec/javascripts/helpers/to_have_unhandled_rejections.coffee +0 -18
- data/spec_app/spec/javascripts/helpers/to_match_list.coffee +0 -14
- data/spec_app/spec/javascripts/helpers/to_match_selector.coffee +0 -8
- data/spec_app/spec/javascripts/helpers/to_match_text.js.coffee +0 -13
- data/spec_app/spec/javascripts/helpers/to_match_url.coffee +0 -14
- data/spec_app/spec/javascripts/helpers/trigger.js.coffee +0 -200
- data/spec_app/spec/javascripts/helpers/wait_until_dom_ready.js.coffee +0 -5
- data/spec_app/spec/javascripts/support/jasmine.yml +0 -51
- data/spec_app/spec/javascripts/up/browser_spec.js.coffee +0 -150
- data/spec_app/spec/javascripts/up/classes/cache_spec.js.coffee +0 -82
- data/spec_app/spec/javascripts/up/classes/config_spec.coffee +0 -24
- data/spec_app/spec/javascripts/up/classes/divertible_chain_spec.coffee +0 -45
- data/spec_app/spec/javascripts/up/classes/focus_tracker_spec.coffee +0 -34
- data/spec_app/spec/javascripts/up/classes/params_spec.coffee +0 -557
- data/spec_app/spec/javascripts/up/classes/request_spec.coffee +0 -50
- data/spec_app/spec/javascripts/up/classes/scroll_motion_spec.js.coffee +0 -51
- data/spec_app/spec/javascripts/up/classes/store/memory_spec.js.coffee +0 -70
- data/spec_app/spec/javascripts/up/classes/store/session_spec.js.coffee +0 -114
- data/spec_app/spec/javascripts/up/element_spec.coffee +0 -897
- data/spec_app/spec/javascripts/up/event_spec.js.coffee +0 -530
- data/spec_app/spec/javascripts/up/feedback_spec.js.coffee +0 -401
- data/spec_app/spec/javascripts/up/form_spec.js.coffee +0 -1527
- data/spec_app/spec/javascripts/up/fragment_spec.js.coffee +0 -2611
- data/spec_app/spec/javascripts/up/history_spec.js.coffee +0 -340
- data/spec_app/spec/javascripts/up/jquery_spec.js.coffee +0 -4
- data/spec_app/spec/javascripts/up/legacy_spec.js.coffee +0 -27
- data/spec_app/spec/javascripts/up/link_spec.js.coffee +0 -1098
- data/spec_app/spec/javascripts/up/log_spec.js.coffee +0 -119
- data/spec_app/spec/javascripts/up/modal_spec.js.coffee +0 -918
- data/spec_app/spec/javascripts/up/motion_spec.js.coffee +0 -582
- data/spec_app/spec/javascripts/up/popup_spec.js.coffee +0 -508
- data/spec_app/spec/javascripts/up/protocol_spec.js.coffee +0 -39
- data/spec_app/spec/javascripts/up/proxy_spec.js.coffee +0 -1137
- data/spec_app/spec/javascripts/up/radio_spec.js.coffee +0 -212
- data/spec_app/spec/javascripts/up/rails_spec.js.coffee +0 -118
- data/spec_app/spec/javascripts/up/spec_spec.js.coffee +0 -9
- data/spec_app/spec/javascripts/up/syntax_spec.js.coffee +0 -304
- data/spec_app/spec/javascripts/up/toast_spec.js.coffee +0 -37
- data/spec_app/spec/javascripts/up/tooltip_spec.js.coffee +0 -163
- data/spec_app/spec/javascripts/up/util_spec.js.coffee +0 -1420
- data/spec_app/spec/javascripts/up/viewport_spec.js.coffee +0 -655
- data/spec_app/spec/spec_helper.rb +0 -62
- data/spec_app/test/controllers/.keep +0 -0
- data/spec_app/test/fixtures/.keep +0 -0
- data/spec_app/test/helpers/.keep +0 -0
- data/spec_app/test/integration/.keep +0 -0
- data/spec_app/test/mailers/.keep +0 -0
- data/spec_app/test/models/.keep +0 -0
- data/spec_app/test/test_helper.rb +0 -10
- data/spec_app/vendor/asset-libs/es6-promise-4.1.6/es6-promise.auto.js +0 -1159
- data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.bower.json +0 -43
- data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.gitignore +0 -6
- data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.npmignore +0 -10
- data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.pairs +0 -6
- data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/.travis.yml +0 -56
- data/spec_app/vendor/asset-libs/jasmine-ajax-3.3.1/jasmine-ajax.js +0 -790
- data/spec_app/vendor/assets/.keep +0 -0
- data/unpoly-rails.gemspec +0 -24
@@ -1,50 +0,0 @@
|
|
1
|
-
u = up.util
|
2
|
-
$ = jQuery
|
3
|
-
|
4
|
-
describe 'up.Request', ->
|
5
|
-
|
6
|
-
describe '#url', ->
|
7
|
-
|
8
|
-
it 'returns the given URL', ->
|
9
|
-
request = new up.Request(url: 'http://host.com/foo')
|
10
|
-
expect(request.url).toEqual('http://host.com/foo')
|
11
|
-
|
12
|
-
it 'does not include a hash anchor of the constructed URL', ->
|
13
|
-
request = new up.Request(url: 'http://host.com/foo#hash')
|
14
|
-
expect(request.url).toEqual('http://host.com/foo')
|
15
|
-
|
16
|
-
it "merges { params } for HTTP methods that don't allow a payload", ->
|
17
|
-
request = new up.Request(url: 'http://host.com/foo?urlKey=urlValue', params: { paramsKey: 'paramsValue' }, method: 'get')
|
18
|
-
expect(request.url).toEqual('http://host.com/foo?urlKey=urlValue¶msKey=paramsValue')
|
19
|
-
|
20
|
-
it 'keeps query params in the URL for HTTP methods that allow a payload', ->
|
21
|
-
request = new up.Request(url: 'http://host.com/foo?key=value', method: 'post')
|
22
|
-
expect(request.url).toEqual('http://host.com/foo?key=value')
|
23
|
-
expect(request.params).toBeBlank()
|
24
|
-
|
25
|
-
describe '#method', ->
|
26
|
-
|
27
|
-
it 'defaults to "GET"', ->
|
28
|
-
request = new up.Request(url: 'http://host.com/foo')
|
29
|
-
expect(request.method).toEqual('GET')
|
30
|
-
|
31
|
-
describe '#hash', ->
|
32
|
-
|
33
|
-
it 'returns the hash anchor from the constructed URL', ->
|
34
|
-
request = new up.Request(url: 'http://host.com/foo#hash')
|
35
|
-
expect(request.hash).toEqual('#hash')
|
36
|
-
|
37
|
-
it 'returns undefined if the constructed URL had no hash anchor', ->
|
38
|
-
request = new up.Request(url: 'http://host.com/foo')
|
39
|
-
expect(request.hash).toBeUndefined()
|
40
|
-
|
41
|
-
describe '#params', ->
|
42
|
-
|
43
|
-
it 'returns the constructed params for HTTP methods that allow a payload', ->
|
44
|
-
params = { key: 'value' }
|
45
|
-
request = new up.Request(url: 'http://host.com/foo', params: params, method: 'post')
|
46
|
-
expect(request.params).toEqual(new up.Params(params))
|
47
|
-
|
48
|
-
it "returns a blank up.Params object for HTTP methods that don't allow a payload", ->
|
49
|
-
request = new up.Request(url: 'http://host.com/foo', params: { key: 'value' }, method: 'get')
|
50
|
-
expect(request.params).toBeBlank()
|
@@ -1,51 +0,0 @@
|
|
1
|
-
u = up.util
|
2
|
-
$ = jQuery
|
3
|
-
|
4
|
-
describe 'up.ScrollMotion', ->
|
5
|
-
|
6
|
-
beforeEach ->
|
7
|
-
@$viewport = $fixture('.viewport').css
|
8
|
-
height: '100px'
|
9
|
-
overflowY: 'scroll'
|
10
|
-
|
11
|
-
@$content = @$viewport.affix('.content').css
|
12
|
-
height: '10000px'
|
13
|
-
|
14
|
-
describe 'constructor', ->
|
15
|
-
|
16
|
-
it 'does not start scrolling', ->
|
17
|
-
motion = new up.ScrollMotion(@$viewport[0], 530)
|
18
|
-
expect(@$viewport.scrollTop()).toEqual(0)
|
19
|
-
|
20
|
-
describe '#start()', ->
|
21
|
-
|
22
|
-
describe '(without { behavior } option)', ->
|
23
|
-
|
24
|
-
it 'abruptly scrolls the given element to the given y-position', ->
|
25
|
-
motion = new up.ScrollMotion(@$viewport[0], 530)
|
26
|
-
|
27
|
-
motion.start()
|
28
|
-
|
29
|
-
expect(@$viewport.scrollTop()).toEqual(530)
|
30
|
-
|
31
|
-
describe '(with { behavior: "scroll" } option)', ->
|
32
|
-
|
33
|
-
it 'animates the scrolling to the given y-position', asyncSpec (next) ->
|
34
|
-
motion = new up.ScrollMotion(@$viewport[0], 2050, { behavior: 'smooth' })
|
35
|
-
|
36
|
-
scrollDone = motion.start()
|
37
|
-
|
38
|
-
next.after 100, =>
|
39
|
-
expect(@$viewport.scrollTop()).toBeAround(1, 500)
|
40
|
-
|
41
|
-
next.await(scrollDone)
|
42
|
-
|
43
|
-
next =>
|
44
|
-
expect(@$viewport.scrollTop())
|
45
|
-
|
46
|
-
it "aborts the scrolling animation if the user or another script changes the viewport's scrollTop during the animation"
|
47
|
-
|
48
|
-
describe '#finish()', ->
|
49
|
-
|
50
|
-
it 'abruptly finishes the scrolling animation by setting the target y-position'
|
51
|
-
|
@@ -1,70 +0,0 @@
|
|
1
|
-
u = up.util
|
2
|
-
$ = jQuery
|
3
|
-
|
4
|
-
describe 'up.store.Memory', ->
|
5
|
-
|
6
|
-
describe '#get', ->
|
7
|
-
|
8
|
-
it 'returns an item that was previously set', ->
|
9
|
-
store = new up.store.Memory()
|
10
|
-
store.set('foo', 'value of foo')
|
11
|
-
store.set('bar', 'value of bar')
|
12
|
-
|
13
|
-
expect(store.get('foo')).toEqual('value of foo')
|
14
|
-
expect(store.get('bar')).toEqual('value of bar')
|
15
|
-
|
16
|
-
it 'returns undefined if no item with that key was set', ->
|
17
|
-
store = new up.store.Memory()
|
18
|
-
store.set('foo', 'value of foo')
|
19
|
-
|
20
|
-
expect(store.get('bar')).toBeUndefined()
|
21
|
-
|
22
|
-
describe '#keys', ->
|
23
|
-
|
24
|
-
it 'returns an array of keys in the store', ->
|
25
|
-
store = new up.store.Memory()
|
26
|
-
store.set('foo', 'value of foo')
|
27
|
-
store.set('bar', 'value of bar')
|
28
|
-
|
29
|
-
expect(store.keys().sort()).toEqual ['bar', 'foo']
|
30
|
-
|
31
|
-
it 'does not return keys for entries that were removed (bugfix)', ->
|
32
|
-
store = new up.store.Memory()
|
33
|
-
store.set('foo', 'value of foo')
|
34
|
-
store.set('bar', 'value of bar')
|
35
|
-
store.remove('bar')
|
36
|
-
|
37
|
-
expect(store.keys().sort()).toEqual ['foo']
|
38
|
-
|
39
|
-
describe '#values', ->
|
40
|
-
|
41
|
-
it 'returns an array of values in the store', ->
|
42
|
-
store = new up.store.Memory()
|
43
|
-
store.set('foo', 'value of foo')
|
44
|
-
store.set('bar', 'value of bar')
|
45
|
-
|
46
|
-
expect(store.values().sort()).toEqual ['value of bar', 'value of foo']
|
47
|
-
|
48
|
-
describe '#clear', ->
|
49
|
-
|
50
|
-
it 'removes all keys from the store', ->
|
51
|
-
store = new up.store.Memory()
|
52
|
-
store.set('foo', 'value of foo')
|
53
|
-
store.set('bar', 'value of bar')
|
54
|
-
|
55
|
-
store.clear()
|
56
|
-
|
57
|
-
expect(store.get('foo')).toBeUndefined()
|
58
|
-
expect(store.get('bar')).toBeUndefined()
|
59
|
-
|
60
|
-
describe '#remove', ->
|
61
|
-
|
62
|
-
it 'removes the given key from the store', ->
|
63
|
-
store = new up.store.Memory()
|
64
|
-
store.set('foo', 'value of foo')
|
65
|
-
store.set('bar', 'value of bar')
|
66
|
-
|
67
|
-
store.remove('foo')
|
68
|
-
|
69
|
-
expect(store.get('foo')).toBeUndefined()
|
70
|
-
expect(store.get('bar')).toEqual('value of bar')
|
@@ -1,114 +0,0 @@
|
|
1
|
-
u = up.util
|
2
|
-
$ = jQuery
|
3
|
-
|
4
|
-
describe 'up.store.Session', ->
|
5
|
-
|
6
|
-
afterEach ->
|
7
|
-
sessionStorage.removeItem('spec')
|
8
|
-
|
9
|
-
describe '#get', ->
|
10
|
-
|
11
|
-
it 'returns an item that was previously set', ->
|
12
|
-
store = new up.store.Session('spec')
|
13
|
-
store.set('foo', 'value of foo')
|
14
|
-
store.set('bar', 'value of bar')
|
15
|
-
|
16
|
-
expect(store.get('foo')).toEqual('value of foo')
|
17
|
-
expect(store.get('bar')).toEqual('value of bar')
|
18
|
-
|
19
|
-
it 'returns undefined if no item with that key was set', ->
|
20
|
-
store = new up.store.Session('spec')
|
21
|
-
store.set('foo', 'value of foo')
|
22
|
-
|
23
|
-
expect(store.get('bar')).toBeUndefined()
|
24
|
-
|
25
|
-
it 'does not read keys from a store with anotther root key', ->
|
26
|
-
store = new up.store.Session('spec.v1')
|
27
|
-
store.set('foo', 'value of foo')
|
28
|
-
expect(store.get('foo')).toEqual('value of foo')
|
29
|
-
|
30
|
-
store = new up.store.Session('spec.v2')
|
31
|
-
expect(store.get('foo')).toBeUndefined()
|
32
|
-
|
33
|
-
describe '#set', ->
|
34
|
-
|
35
|
-
it 'stores the given item in window.sessionStorage where it survives a follow without Unpoly', ->
|
36
|
-
store = new up.store.Session('spec')
|
37
|
-
store.set('foo', 'value of foo')
|
38
|
-
|
39
|
-
expect(window.sessionStorage.getItem('spec')).toContain('foo')
|
40
|
-
|
41
|
-
it 'stores boolean values across sessions', ->
|
42
|
-
store1 = new up.store.Session('spec')
|
43
|
-
store1.set('foo', true)
|
44
|
-
store1.set('bar', false)
|
45
|
-
|
46
|
-
store2 = new up.store.Session('spec')
|
47
|
-
expect(store2.get('foo')).toEqual(true)
|
48
|
-
expect(store2.get('bar')).toEqual(false)
|
49
|
-
|
50
|
-
it 'stores number values across sessions', ->
|
51
|
-
store1 = new up.store.Session('spec')
|
52
|
-
store1.set('foo', 123)
|
53
|
-
|
54
|
-
store2 = new up.store.Session('spec')
|
55
|
-
expect(store2.get('foo')).toEqual(123)
|
56
|
-
|
57
|
-
it 'stores structured values across sessions', ->
|
58
|
-
store1 = new up.store.Session('spec')
|
59
|
-
store1.set('foo', { bar: ['baz', 'bam'] })
|
60
|
-
|
61
|
-
store2 = new up.store.Session('spec')
|
62
|
-
storedValue = store2.get('foo')
|
63
|
-
expect(u.isObject(storedValue)).toBe(true)
|
64
|
-
expect(storedValue).toEqual { bar: ['baz', 'bam'] }
|
65
|
-
|
66
|
-
describe '#keys', ->
|
67
|
-
|
68
|
-
it 'returns an array of keys in the store', ->
|
69
|
-
store = new up.store.Session('spec')
|
70
|
-
store.set('foo', 'value of foo')
|
71
|
-
store.set('bar', 'value of bar')
|
72
|
-
|
73
|
-
expect(store.keys().sort()).toEqual ['bar', 'foo']
|
74
|
-
|
75
|
-
it 'does not return keys for entries that were removed (bugfix)', ->
|
76
|
-
store = new up.store.Session('spec')
|
77
|
-
store.set('foo', 'value of foo')
|
78
|
-
store.set('bar', 'value of bar')
|
79
|
-
store.remove('bar')
|
80
|
-
|
81
|
-
expect(store.keys().sort()).toEqual ['foo']
|
82
|
-
|
83
|
-
describe '#values', ->
|
84
|
-
|
85
|
-
it 'returns an array of values in the store', ->
|
86
|
-
store = new up.store.Session('spec')
|
87
|
-
store.set('foo', 'value of foo')
|
88
|
-
store.set('bar', 'value of bar')
|
89
|
-
|
90
|
-
expect(store.values().sort()).toEqual ['value of bar', 'value of foo']
|
91
|
-
|
92
|
-
describe '#clear', ->
|
93
|
-
|
94
|
-
it 'removes all keys from the store', ->
|
95
|
-
store = new up.store.Session('spec')
|
96
|
-
store.set('foo', 'value of foo')
|
97
|
-
store.set('bar', 'value of bar')
|
98
|
-
|
99
|
-
store.clear()
|
100
|
-
|
101
|
-
expect(store.get('foo')).toBeUndefined()
|
102
|
-
expect(store.get('bar')).toBeUndefined()
|
103
|
-
|
104
|
-
describe '#remove', ->
|
105
|
-
|
106
|
-
it 'removes the given key from the store', ->
|
107
|
-
store = new up.store.Session('spec')
|
108
|
-
store.set('foo', 'value of foo')
|
109
|
-
store.set('bar', 'value of bar')
|
110
|
-
|
111
|
-
store.remove('foo')
|
112
|
-
|
113
|
-
expect(store.get('foo')).toBeUndefined()
|
114
|
-
expect(store.get('bar')).toEqual('value of bar')
|
@@ -1,897 +0,0 @@
|
|
1
|
-
u = up.util
|
2
|
-
$ = jQuery
|
3
|
-
|
4
|
-
describe 'up.element', ->
|
5
|
-
|
6
|
-
describe 'up.element.get()', ->
|
7
|
-
|
8
|
-
it 'returns the given element', ->
|
9
|
-
element = fixture('.element')
|
10
|
-
expect(up.element.get(element)).toBe(element)
|
11
|
-
|
12
|
-
it 'returns the first element in the given jQuery collection', ->
|
13
|
-
$element = $fixture('.element')
|
14
|
-
expect(up.element.get($element)).toBe($element[0])
|
15
|
-
|
16
|
-
it 'throws an error if passed a jQuery collection with multiple elements', ->
|
17
|
-
$element1 = $fixture('.element')
|
18
|
-
$element2 = $fixture('.element')
|
19
|
-
$list = $element1.add($element2)
|
20
|
-
get = -> up.element.get($list)
|
21
|
-
expect(get).toThrowError(/cannot cast/i)
|
22
|
-
|
23
|
-
it 'returns the first element matching the given CSS selector string', ->
|
24
|
-
match = fixture('.match')
|
25
|
-
expect(up.element.get('.match')).toBe(match)
|
26
|
-
|
27
|
-
it 'returns the given document object', ->
|
28
|
-
expect(up.element.get(document)).toBe(document)
|
29
|
-
|
30
|
-
it 'returns the given window object', ->
|
31
|
-
expect(up.element.get(window)).toBe(window)
|
32
|
-
|
33
|
-
it 'returns undefined for undefined', ->
|
34
|
-
expect(up.element.get(undefined)).toBeUndefined()
|
35
|
-
|
36
|
-
it 'returns null for null', ->
|
37
|
-
expect(up.element.get(null)).toBeNull()
|
38
|
-
|
39
|
-
describe 'up.element.first()', ->
|
40
|
-
|
41
|
-
it 'returns the first element matching the given selector', ->
|
42
|
-
match = fixture('.match')
|
43
|
-
otherMatch = fixture('.match')
|
44
|
-
noMatch = fixture('.no-match')
|
45
|
-
result = up.element.first('.match')
|
46
|
-
expect(result).toBe(match)
|
47
|
-
|
48
|
-
it 'supports the custom :has() selector', ->
|
49
|
-
match = fixture('.match')
|
50
|
-
otherMatch = fixture('.match')
|
51
|
-
otherMatchChild = up.element.affix(otherMatch, '.child')
|
52
|
-
|
53
|
-
result = up.element.first('.match:has(.child)')
|
54
|
-
expect(result).toBe(otherMatch)
|
55
|
-
|
56
|
-
describe 'when given a root element for the search', ->
|
57
|
-
|
58
|
-
it 'returns the first descendant of the given root that matches the given selector', ->
|
59
|
-
$element = $fixture('.element')
|
60
|
-
$matchingChild = $element.affix('.child.match')
|
61
|
-
$matchingGrandChild = $matchingChild.affix('.grand-child.match')
|
62
|
-
$otherChild = $element.affix('.child')
|
63
|
-
$otherGrandChild = $otherChild.affix('.grand-child')
|
64
|
-
result = up.element.first($element[0], '.match')
|
65
|
-
expect(result).toEqual $matchingChild[0]
|
66
|
-
|
67
|
-
it 'returns missing if no descendant matches', ->
|
68
|
-
$element = $fixture('.element')
|
69
|
-
$child = $element.affix('.child')
|
70
|
-
$grandChild = $child.affix('.grand-child')
|
71
|
-
result = up.element.first($element[0], '.match')
|
72
|
-
expect(result).toBeMissing()
|
73
|
-
|
74
|
-
it 'does not return the root itself, even if it matches', ->
|
75
|
-
$element = $fixture('.element.match')
|
76
|
-
result = up.element.first($element[0], '.match')
|
77
|
-
expect(result).toBeMissing()
|
78
|
-
|
79
|
-
it 'does not return an ancestor of the root, even if it matches', ->
|
80
|
-
$parent = $fixture('.parent.match')
|
81
|
-
$element = $parent.affix('.element')
|
82
|
-
result = up.element.first($element[0], '.match')
|
83
|
-
expect(result).toBeMissing()
|
84
|
-
|
85
|
-
it 'supports the custom :has() selector', ->
|
86
|
-
$element = $fixture('.element')
|
87
|
-
$childWithSelectorWithChild = $element.affix('.selector')
|
88
|
-
$childWithSelectorWithChild.affix('.match')
|
89
|
-
$childWithSelectorWithoutChild = $element.affix('.selector')
|
90
|
-
$childWithoutSelectorWithChild = $element.affix('.other-selector')
|
91
|
-
$childWithoutSelectorWithChild.affix('.match')
|
92
|
-
$childWithoutSelectorWithoutChild = $fixture('.other-selector')
|
93
|
-
|
94
|
-
result = up.element.first($element[0], '.selector:has(.match)')
|
95
|
-
expect(result).toBe $childWithSelectorWithChild[0]
|
96
|
-
|
97
|
-
it 'supports the custom :has() selector when a previous sibling only matches its own selector, but not the descendant selector (bugfix)', ->
|
98
|
-
$element = $fixture('.element')
|
99
|
-
$childWithSelectorWithoutChild = $element.affix('.selector')
|
100
|
-
$childWithSelectorWithChild = $element.affix('.selector')
|
101
|
-
$childWithSelectorWithChild.affix('.match')
|
102
|
-
|
103
|
-
result = up.element.first($element[0], '.selector:has(.match)')
|
104
|
-
expect(result).toBe $childWithSelectorWithChild[0]
|
105
|
-
|
106
|
-
describe 'up.element.all()', ->
|
107
|
-
|
108
|
-
it 'returns all elements matching the given selector', ->
|
109
|
-
match = fixture('.match')
|
110
|
-
otherMatch = fixture('.match')
|
111
|
-
noMatch = fixture('.no-match')
|
112
|
-
result = up.element.all('.match')
|
113
|
-
expect(result).toMatchList [match, otherMatch]
|
114
|
-
|
115
|
-
it 'supports the custom :has() selector'
|
116
|
-
|
117
|
-
describe 'when given a root element for the search', ->
|
118
|
-
|
119
|
-
it 'returns all descendants of the given root matching the given selector', ->
|
120
|
-
$element = $fixture('.element')
|
121
|
-
$matchingChild = $element.affix('.child.match')
|
122
|
-
$matchingGrandChild = $matchingChild.affix('.grand-child.match')
|
123
|
-
$otherChild = $element.affix('.child')
|
124
|
-
$otherGrandChild = $otherChild.affix('.grand-child')
|
125
|
-
results = up.element.all($element[0], '.match')
|
126
|
-
expect(results).toEqual [$matchingChild[0], $matchingGrandChild[0]]
|
127
|
-
|
128
|
-
it 'returns an empty list if no descendant matches', ->
|
129
|
-
$element = $fixture('.element')
|
130
|
-
$child = $element.affix('.child')
|
131
|
-
$grandChild = $child.affix('.grand-child')
|
132
|
-
results = up.element.all($element[0], '.match')
|
133
|
-
expect(results).toEqual []
|
134
|
-
|
135
|
-
it 'does not return the root itself, even if it matches', ->
|
136
|
-
$element = $fixture('.element.match')
|
137
|
-
results = up.element.all($element[0], '.match')
|
138
|
-
expect(results).toEqual []
|
139
|
-
|
140
|
-
it 'does not return ancestors of the root, even if they match', ->
|
141
|
-
$parent = $fixture('.parent.match')
|
142
|
-
$element = $parent.affix('.element')
|
143
|
-
results = up.element.all($element[0], '.match')
|
144
|
-
expect(results).toEqual []
|
145
|
-
|
146
|
-
it 'supports the custom :has() selector', ->
|
147
|
-
$element = $fixture('.element')
|
148
|
-
$childWithSelectorWithChild = $element.affix('.selector')
|
149
|
-
$childWithSelectorWithChild.affix('.match')
|
150
|
-
$childWithSelectorWithoutChild = $element.affix('.selector')
|
151
|
-
$childWithoutSelectorWithChild = $element.affix('.other-selector')
|
152
|
-
$childWithoutSelectorWithChild.affix('.match')
|
153
|
-
$childWithoutSelectorWithoutChild = $fixture('.other-selector')
|
154
|
-
|
155
|
-
results = up.element.all($element[0], '.selector:has(.match)')
|
156
|
-
expect(results).toEqual [$childWithSelectorWithChild[0]]
|
157
|
-
|
158
|
-
describe 'up.element.list()', ->
|
159
|
-
|
160
|
-
it 'returns the given array of elements', ->
|
161
|
-
array = [document.body]
|
162
|
-
result = up.element.list(array)
|
163
|
-
expect(result).toEqual(array)
|
164
|
-
|
165
|
-
it 'returns an empty list for undefined', ->
|
166
|
-
result = up.element.list(undefined)
|
167
|
-
expect(result).toEqual []
|
168
|
-
|
169
|
-
it 'returns an empty list for null', ->
|
170
|
-
result = up.element.list(null)
|
171
|
-
expect(result).toEqual []
|
172
|
-
|
173
|
-
it 'converts a NodeList to an array', ->
|
174
|
-
nodeList = document.querySelectorAll('body')
|
175
|
-
result = up.element.list(nodeList)
|
176
|
-
expect(u.isArray(result)).toBe(true)
|
177
|
-
expect(result.length).toBe(1)
|
178
|
-
expect(result[0]).toBe(document.body)
|
179
|
-
|
180
|
-
it 'returns a concatenated array from multiple lists and elements', ->
|
181
|
-
div0 = $fixture('div.div0')[0]
|
182
|
-
div1 = $fixture('div.div1')[0]
|
183
|
-
div2 = $fixture('div.div2')[0]
|
184
|
-
div3 = $fixture('div.div3')[0]
|
185
|
-
|
186
|
-
result = up.element.list(div0, [div1, div2], div3)
|
187
|
-
expect(u.isArray(result)).toBe(true)
|
188
|
-
expect(result).toEqual [div0, div1, div2, div3]
|
189
|
-
|
190
|
-
it 'ignores missing values when concatenating arrays', ->
|
191
|
-
div0 = $fixture('div.div0')[0]
|
192
|
-
div1 = $fixture('div.div1')[0]
|
193
|
-
div2 = $fixture('div.div2')[0]
|
194
|
-
div3 = $fixture('div.div3')[0]
|
195
|
-
|
196
|
-
result = up.element.list(null, div0, [div1, div2], undefined, div3)
|
197
|
-
expect(u.isArray(result)).toBe(true)
|
198
|
-
expect(result).toEqual [div0, div1, div2, div3]
|
199
|
-
|
200
|
-
describe 'up.element.subtree()', ->
|
201
|
-
|
202
|
-
it 'returns all descendants of the given root matching the given selector', ->
|
203
|
-
$element = $fixture('.element')
|
204
|
-
$matchingChild = $element.affix('.child.match')
|
205
|
-
$matchingGrandChild = $matchingChild.affix('.grand-child.match')
|
206
|
-
$otherChild = $element.affix('.child')
|
207
|
-
$otherGrandChild = $otherChild.affix('.grand-child')
|
208
|
-
results = up.element.subtree($element[0], '.match')
|
209
|
-
expect(results).toEqual [$matchingChild[0], $matchingGrandChild[0]]
|
210
|
-
|
211
|
-
it 'includes the given root if it matches the selector', ->
|
212
|
-
$element = $fixture('.element.match')
|
213
|
-
$matchingChild = $element.affix('.child.match')
|
214
|
-
$matchingGrandChild = $matchingChild.affix('.grand-child.match')
|
215
|
-
$otherChild = $element.affix('.child')
|
216
|
-
$otherGrandChild = $otherChild.affix('.grand-child')
|
217
|
-
results = up.element.subtree($element[0], '.match')
|
218
|
-
expect(results).toEqual [$element[0], $matchingChild[0], $matchingGrandChild[0]]
|
219
|
-
|
220
|
-
it 'does not return ancestors of the root, even if they match', ->
|
221
|
-
$parent = $fixture('.parent.match')
|
222
|
-
$element = $parent.affix('.element')
|
223
|
-
results = up.element.subtree($element[0], '.match')
|
224
|
-
expect(results).toEqual []
|
225
|
-
|
226
|
-
it 'returns an empty list if neither root nor any descendant matches', ->
|
227
|
-
$element = $fixture('.element')
|
228
|
-
$child = $element.affix('.child')
|
229
|
-
results = up.element.subtree($element[0], '.match')
|
230
|
-
expect(results).toEqual []
|
231
|
-
|
232
|
-
it 'supports the custom :has() selector', ->
|
233
|
-
$element = $fixture('.selector')
|
234
|
-
$childWithSelectorWithChild = $element.affix('.selector')
|
235
|
-
$childWithSelectorWithChild.affix('.match')
|
236
|
-
$childWithSelectorWithoutChild = $element.affix('.selector')
|
237
|
-
$childWithoutSelectorWithChild = $element.affix('.other-selector')
|
238
|
-
$childWithoutSelectorWithChild.affix('.match')
|
239
|
-
$childWithoutSelectorWithoutChild = $fixture('.other-selector')
|
240
|
-
|
241
|
-
results = up.element.subtree($element[0], '.selector:has(.match)')
|
242
|
-
expect(results).toEqual [$element[0], $childWithSelectorWithChild[0]]
|
243
|
-
|
244
|
-
describe 'up.element.closest()', ->
|
245
|
-
|
246
|
-
it 'returns the closest ancestor of the given root that matches the given selector', ->
|
247
|
-
$grandGrandMother = $fixture('.match')
|
248
|
-
$grandMother = $fixture('.match')
|
249
|
-
$mother = $grandMother.affix('.no-match')
|
250
|
-
$element = $mother.affix('.element')
|
251
|
-
|
252
|
-
result = up.element.closest($element[0], '.match')
|
253
|
-
expect(result).toBe($grandMother[0])
|
254
|
-
|
255
|
-
it 'returns the given root if it matches', ->
|
256
|
-
$mother = $fixture('.match')
|
257
|
-
$element = $mother.affix('.match')
|
258
|
-
|
259
|
-
result = up.element.closest($element[0], '.match')
|
260
|
-
expect(result).toBe($element[0])
|
261
|
-
|
262
|
-
it 'does not return descendants of the root, even if they match', ->
|
263
|
-
$element = $fixture('.element')
|
264
|
-
$child = $element.affix('.match')
|
265
|
-
|
266
|
-
result = up.element.closest($element[0], '.match')
|
267
|
-
expect(result).toBeMissing()
|
268
|
-
|
269
|
-
it 'returns missing if neither root nor ancestor matches', ->
|
270
|
-
$mother = $fixture('.no-match')
|
271
|
-
$element = $mother.affix('.no-match')
|
272
|
-
|
273
|
-
result = up.element.closest($element[0], '.match')
|
274
|
-
expect(result).toBeMissing()
|
275
|
-
|
276
|
-
describe 'up.element.ancestor()', ->
|
277
|
-
|
278
|
-
it 'returns the closest ancestor of the given root that matches the given selector', ->
|
279
|
-
$grandGrandMother = $fixture('.match')
|
280
|
-
$grandMother = $fixture('.match')
|
281
|
-
$mother = $grandMother.affix('.no-match')
|
282
|
-
$element = $mother.affix('.element')
|
283
|
-
|
284
|
-
result = up.element.ancestor($element[0], '.match')
|
285
|
-
expect(result).toBe($grandMother[0])
|
286
|
-
|
287
|
-
it 'does not return the given root, even if it matches', ->
|
288
|
-
$element = $fixture('.match')
|
289
|
-
|
290
|
-
result = up.element.ancestor($element[0], '.match')
|
291
|
-
expect(result).toBeMissing()
|
292
|
-
|
293
|
-
it 'does not return descendants of the root, even if they match', ->
|
294
|
-
$element = $fixture('.element')
|
295
|
-
$child = $element.affix('.match')
|
296
|
-
|
297
|
-
result = up.element.ancestor($element[0], '.match')
|
298
|
-
expect(result).toBeMissing()
|
299
|
-
|
300
|
-
it 'returns missing if no ancestor matches', ->
|
301
|
-
$mother = $fixture('.no-match')
|
302
|
-
$element = $mother.affix('.no-match')
|
303
|
-
|
304
|
-
result = up.element.ancestor($element[0], '.match')
|
305
|
-
expect(result).toBeMissing()
|
306
|
-
|
307
|
-
describe 'up.element.emit()', ->
|
308
|
-
|
309
|
-
describe 'up.element.remove()', ->
|
310
|
-
|
311
|
-
it 'removes the given element from the DOM', ->
|
312
|
-
element = fixture('.element')
|
313
|
-
expect(element).toBeAttached()
|
314
|
-
up.element.remove(element)
|
315
|
-
expect(element).toBeDetached()
|
316
|
-
|
317
|
-
describe 'up.element.toggle()', ->
|
318
|
-
|
319
|
-
it 'hides the given element if it is visible', ->
|
320
|
-
element = fixture('.element')
|
321
|
-
up.element.toggle(element)
|
322
|
-
expect(element).toBeHidden()
|
323
|
-
|
324
|
-
it 'shows the given element if it is hidden', ->
|
325
|
-
element = fixture('.element', style: { display: 'none' })
|
326
|
-
up.element.toggle(element)
|
327
|
-
expect(element).toBeVisible()
|
328
|
-
|
329
|
-
it 'hides the given element if the second argument is false', ->
|
330
|
-
element = fixture('.element')
|
331
|
-
expect(element).toBeVisible()
|
332
|
-
up.element.toggle(element, false)
|
333
|
-
expect(element).toBeHidden()
|
334
|
-
|
335
|
-
it 'shows the given element if the second argument is true', ->
|
336
|
-
element = fixture('.element')
|
337
|
-
element.style.display = 'none'
|
338
|
-
expect(element).toBeHidden()
|
339
|
-
up.element.toggle(element, true)
|
340
|
-
expect(element).toBeVisible()
|
341
|
-
|
342
|
-
describe 'up.element.toggleClass()', ->
|
343
|
-
|
344
|
-
it 'removes a class from an element that has that class', ->
|
345
|
-
element = fixture('.klass')
|
346
|
-
up.element.toggleClass(element, 'klass')
|
347
|
-
expect(element).not.toHaveClass('klass')
|
348
|
-
|
349
|
-
it 'adds a class to an element that does not have that class', ->
|
350
|
-
element = fixture('div')
|
351
|
-
up.element.toggleClass(element, 'klass')
|
352
|
-
expect(element).toHaveClass('klass')
|
353
|
-
|
354
|
-
it 'removes a class from the an element if the second argument is false', ->
|
355
|
-
element = fixture('.klass')
|
356
|
-
up.element.toggleClass(element, 'klass', false)
|
357
|
-
expect(element).not.toHaveClass('klass')
|
358
|
-
|
359
|
-
it 'adds a class to an element if the second argument is true', ->
|
360
|
-
element = fixture('div')
|
361
|
-
up.element.toggleClass(element, 'klass', true)
|
362
|
-
expect(element).toHaveClass('klass')
|
363
|
-
|
364
|
-
describe 'up.element.createFromSelector()', ->
|
365
|
-
|
366
|
-
it 'creates an element with a given tag', ->
|
367
|
-
element = up.element.createFromSelector('table')
|
368
|
-
expect(element).toBeElement()
|
369
|
-
expect(element.tagName).toEqual('TABLE')
|
370
|
-
|
371
|
-
it 'creates a custom element with a dash-separated tag name', ->
|
372
|
-
element = up.element.createFromSelector('ta-belle')
|
373
|
-
expect(element).toBeElement()
|
374
|
-
expect(element.tagName).toEqual('TA-BELLE')
|
375
|
-
|
376
|
-
it 'creates an element with a given tag and class', ->
|
377
|
-
element = up.element.createFromSelector('table.foo')
|
378
|
-
expect(element).toBeElement()
|
379
|
-
expect(element.tagName).toEqual('TABLE')
|
380
|
-
expect(element.className).toEqual('foo')
|
381
|
-
|
382
|
-
it 'creates an element with multiple classes', ->
|
383
|
-
element = up.element.createFromSelector('table.foo.bar')
|
384
|
-
expect(element).toBeElement()
|
385
|
-
expect(element.tagName).toEqual('TABLE')
|
386
|
-
expect(element.className).toEqual('foo bar')
|
387
|
-
|
388
|
-
it 'creates an element with a given tag and ID', ->
|
389
|
-
element = up.element.createFromSelector('table#foo')
|
390
|
-
expect(element).toBeElement()
|
391
|
-
expect(element.tagName).toEqual('TABLE')
|
392
|
-
expect(element.id).toEqual('foo')
|
393
|
-
|
394
|
-
it 'creates a <div> if no tag is given', ->
|
395
|
-
element = up.element.createFromSelector('.foo')
|
396
|
-
expect(element).toBeElement()
|
397
|
-
expect(element.tagName).toEqual('DIV')
|
398
|
-
expect(element.className).toEqual('foo')
|
399
|
-
|
400
|
-
it 'creates a hierarchy of elements for a descendant selector, and returns the root element', ->
|
401
|
-
parent = up.element.createFromSelector('ul.foo li.bar')
|
402
|
-
expect(parent).toBeElement()
|
403
|
-
expect(parent.tagName).toEqual('UL')
|
404
|
-
expect(parent.className).toEqual('foo')
|
405
|
-
expect(parent.children.length).toBe(1)
|
406
|
-
expect(parent.firstChild.tagName).toEqual('LI')
|
407
|
-
expect(parent.firstChild.className).toEqual('bar')
|
408
|
-
|
409
|
-
it 'creates a hierarchy of elements for a child selector, and returns the root element', ->
|
410
|
-
parent = up.element.createFromSelector('ul.foo > li.bar')
|
411
|
-
expect(parent).toBeElement()
|
412
|
-
expect(parent.tagName).toEqual('UL')
|
413
|
-
expect(parent.className).toEqual('foo')
|
414
|
-
expect(parent.children.length).toBe(1)
|
415
|
-
expect(parent.firstChild.tagName).toEqual('LI')
|
416
|
-
expect(parent.firstChild.className).toEqual('bar')
|
417
|
-
|
418
|
-
it 'creates an element with an attribute', ->
|
419
|
-
element = up.element.createFromSelector('ul[foo=bar]')
|
420
|
-
expect(element).toBeElement()
|
421
|
-
expect(element.tagName).toEqual('UL')
|
422
|
-
expect(element.getAttribute('foo')).toEqual('bar')
|
423
|
-
|
424
|
-
it 'creates an element with a value-less attribute', ->
|
425
|
-
element = up.element.createFromSelector('ul[foo]')
|
426
|
-
expect(element).toBeElement()
|
427
|
-
expect(element.tagName).toEqual('UL')
|
428
|
-
expect(element.getAttribute('foo')).toEqual('')
|
429
|
-
|
430
|
-
it 'creates an element with multiple attributes', ->
|
431
|
-
element = up.element.createFromSelector('ul[foo=bar][baz=bam]')
|
432
|
-
expect(element).toBeElement()
|
433
|
-
expect(element.tagName).toEqual('UL')
|
434
|
-
expect(element.getAttribute('foo')).toEqual('bar')
|
435
|
-
expect(element.getAttribute('baz')).toEqual('bam')
|
436
|
-
|
437
|
-
it 'allows to quote attribute values with double quotes', ->
|
438
|
-
element = up.element.createFromSelector('ul[foo="bar baz"]')
|
439
|
-
expect(element).toBeElement()
|
440
|
-
expect(element.tagName).toEqual('UL')
|
441
|
-
expect(element.getAttribute('foo')).toEqual('bar baz')
|
442
|
-
|
443
|
-
it 'allows to quote attribute values with single quotes', ->
|
444
|
-
element = up.element.createFromSelector("ul[foo='bar baz']")
|
445
|
-
expect(element).toBeElement()
|
446
|
-
expect(element.tagName).toEqual('UL')
|
447
|
-
expect(element.getAttribute('foo')).toEqual('bar baz')
|
448
|
-
|
449
|
-
it 'throws an error when encountering an unknown selector', ->
|
450
|
-
parse = -> up.element.createFromSelector("ul~baz")
|
451
|
-
expect(parse).toThrowError('Cannot parse selector: ul~baz')
|
452
|
-
|
453
|
-
it 'sets attributes from a second argument', ->
|
454
|
-
element = up.element.createFromSelector('div', foo: 'one', bar: 'two')
|
455
|
-
expect(element.getAttribute('foo')).toEqual('one')
|
456
|
-
expect(element.getAttribute('bar')).toEqual('two')
|
457
|
-
|
458
|
-
it 'sets inline styles from a { style } option', ->
|
459
|
-
element = up.element.createFromSelector('div', style: { fontSize: '100px', marginTop: '200px' })
|
460
|
-
expect(element.style.fontSize).toEqual('100px')
|
461
|
-
expect(element.style.marginTop).toEqual('200px')
|
462
|
-
|
463
|
-
it 'adds an addition class from a { class } option', ->
|
464
|
-
element = up.element.createFromSelector('.foo', class: 'bar')
|
465
|
-
expect(element).toHaveClass('foo')
|
466
|
-
expect(element).toHaveClass('bar')
|
467
|
-
|
468
|
-
it 'sets the element text from a { text } option', ->
|
469
|
-
element = up.element.createFromSelector('.foo', text: 'text')
|
470
|
-
expect(element).toHaveText('text')
|
471
|
-
|
472
|
-
it 'escapes HTML from a { text } option', ->
|
473
|
-
element = up.element.createFromSelector('.foo', text: '<script>alert("foo")</script>')
|
474
|
-
expect(element).toHaveText('<script>alert("foo")</script>')
|
475
|
-
|
476
|
-
describe 'up.element.affix', ->
|
477
|
-
|
478
|
-
it 'creates an element from the given selector and attaches it to the given container', ->
|
479
|
-
container = fixture('.container')
|
480
|
-
element = up.element.affix(container, 'span')
|
481
|
-
expect(element.tagName).toEqual('SPAN')
|
482
|
-
expect(element.parentElement).toBe(container)
|
483
|
-
|
484
|
-
describe 'up.element.toSelector', ->
|
485
|
-
|
486
|
-
it "prefers using the element's 'up-id' attribute to using the element's ID", ->
|
487
|
-
$element = $fixture('div[up-id=up-id-value]#id-value')
|
488
|
-
expect(up.element.toSelector($element)).toBe('[up-id="up-id-value"]')
|
489
|
-
|
490
|
-
it "prefers using the element's ID to using the element's name", ->
|
491
|
-
$element = $fixture('div#id-value[name=name-value]')
|
492
|
-
expect(up.element.toSelector($element)).toBe("#id-value")
|
493
|
-
|
494
|
-
it "selects the ID with an attribute selector if the ID contains a slash", ->
|
495
|
-
$element = $fixture('div').attr(id: 'foo/bar')
|
496
|
-
expect(up.element.toSelector($element)).toBe('[id="foo/bar"]')
|
497
|
-
|
498
|
-
it "selects the ID with an attribute selector if the ID contains a space", ->
|
499
|
-
$element = $fixture('div').attr(id: 'foo bar')
|
500
|
-
expect(up.element.toSelector($element)).toBe('[id="foo bar"]')
|
501
|
-
|
502
|
-
it "selects the ID with an attribute selector if the ID contains a dot", ->
|
503
|
-
$element = $fixture('div').attr(id: 'foo.bar')
|
504
|
-
expect(up.element.toSelector($element)).toBe('[id="foo.bar"]')
|
505
|
-
|
506
|
-
it "selects the ID with an attribute selector if the ID contains a quote", ->
|
507
|
-
$element = $fixture('div').attr(id: 'foo"bar')
|
508
|
-
expect(up.element.toSelector($element)).toBe('[id="foo\\"bar"]')
|
509
|
-
|
510
|
-
it "prefers using the element's tagName + [name] to using the element's classes", ->
|
511
|
-
$element = $fixture('input[name=name-value].class1.class2')
|
512
|
-
expect(up.element.toSelector($element)).toBe('input[name="name-value"]')
|
513
|
-
|
514
|
-
it "prefers using the element's classes to using the element's ARIA label", ->
|
515
|
-
$element = $fixture('div.class1.class2[aria-label="ARIA label value"]')
|
516
|
-
expect(up.element.toSelector($element)).toBe(".class1.class2")
|
517
|
-
|
518
|
-
it 'does not use Unpoly classes to compose a class selector', ->
|
519
|
-
$element = $fixture('div.class1.up-current.class2')
|
520
|
-
expect(up.element.toSelector($element)).toBe(".class1.class2")
|
521
|
-
|
522
|
-
it "prefers using the element's ARIA label to using the element's tag name", ->
|
523
|
-
$element = $fixture('div[aria-label="ARIA label value"]')
|
524
|
-
expect(up.element.toSelector($element)).toBe('[aria-label="ARIA label value"]')
|
525
|
-
|
526
|
-
it "uses the element's tag name if no better description is available", ->
|
527
|
-
$element = $fixture('div')
|
528
|
-
expect(up.element.toSelector($element)).toBe("div")
|
529
|
-
|
530
|
-
it 'escapes quotes in attribute selector values', ->
|
531
|
-
$element = $fixture('div')
|
532
|
-
$element.attr('aria-label', 'foo"bar')
|
533
|
-
expect(up.element.toSelector($element)).toBe('[aria-label="foo\\"bar"]')
|
534
|
-
|
535
|
-
describe 'up.element.createDocumentFromHtml', ->
|
536
|
-
|
537
|
-
it 'parses a string that contains a serialized HTML document', ->
|
538
|
-
string = """
|
539
|
-
<html lang="foo">
|
540
|
-
<head>
|
541
|
-
<title>document title</title>
|
542
|
-
</head>
|
543
|
-
<body data-env='production'>
|
544
|
-
<div>line 1</div>
|
545
|
-
<div>line 2</div>
|
546
|
-
</body>
|
547
|
-
</html>
|
548
|
-
"""
|
549
|
-
|
550
|
-
element = up.element.createDocumentFromHtml(string)
|
551
|
-
|
552
|
-
expect(element.querySelector('head title').textContent).toEqual('document title')
|
553
|
-
expect(element.querySelector('body').getAttribute('data-env')).toEqual('production')
|
554
|
-
expect(element.querySelectorAll('body div').length).toBe(2)
|
555
|
-
expect(element.querySelectorAll('body div')[0].textContent).toEqual('line 1')
|
556
|
-
expect(element.querySelectorAll('body div')[1].textContent).toEqual('line 2')
|
557
|
-
|
558
|
-
it 'parses a string that contains carriage returns (bugfix)', ->
|
559
|
-
string = """
|
560
|
-
<html>\r
|
561
|
-
<body>\r
|
562
|
-
<div>line</div>\r
|
563
|
-
</body>\r
|
564
|
-
</html>\r
|
565
|
-
"""
|
566
|
-
|
567
|
-
$element = up.element.createDocumentFromHtml(string)
|
568
|
-
expect($element.querySelector('body')).toBeGiven()
|
569
|
-
expect($element.querySelector('body div').textContent).toEqual('line')
|
570
|
-
|
571
|
-
it 'does not run forever if a page has a <head> without a <title> (bugfix)', ->
|
572
|
-
html = """
|
573
|
-
<!doctype html>
|
574
|
-
<html>
|
575
|
-
<head>
|
576
|
-
<meta charset="utf-8" />
|
577
|
-
<meta name="format-detection" content="telephone=no">
|
578
|
-
<link href='/images/favicon.png' rel='shortcut icon' type='image/png'>
|
579
|
-
<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1'>
|
580
|
-
|
581
|
-
<base href="/examples/update-fragment/" />
|
582
|
-
<link href='http://fonts.googleapis.com/css?family=Orbitron:400|Ubuntu+Mono:400,700|Source+Sans+Pro:300,400,700,400italic,700italic' rel='stylesheet' type='text/css'>
|
583
|
-
<link href="//netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
|
584
|
-
<link href="/stylesheets/example/all.css" rel="stylesheet" />
|
585
|
-
<script src="/javascripts/example.js"></script>
|
586
|
-
</head>
|
587
|
-
<body>
|
588
|
-
<div class="page">
|
589
|
-
<div class="story">
|
590
|
-
|
591
|
-
<h1>Full story</h1>
|
592
|
-
<p>Lorem ipsum dolor sit amet.</p>
|
593
|
-
|
594
|
-
<a href="preview.html" up-target=".story">
|
595
|
-
Read summary
|
596
|
-
</a>
|
597
|
-
</div>
|
598
|
-
|
599
|
-
</div>
|
600
|
-
</body>
|
601
|
-
</html>
|
602
|
-
"""
|
603
|
-
element = up.element.createDocumentFromHtml(html)
|
604
|
-
expect(element.querySelector("title")).toBeMissing()
|
605
|
-
expect(element.querySelector("h1").textContent).toEqual('Full story')
|
606
|
-
|
607
|
-
it 'can parse HTML without a <head>', ->
|
608
|
-
html = """
|
609
|
-
<html>
|
610
|
-
<body>
|
611
|
-
<h1>Full story</h1>
|
612
|
-
</body>
|
613
|
-
</html>
|
614
|
-
"""
|
615
|
-
element = up.element.createDocumentFromHtml(html)
|
616
|
-
expect(element.querySelector("title")).toBeMissing()
|
617
|
-
expect(element.querySelector("h1").textContent).toEqual('Full story')
|
618
|
-
|
619
|
-
it 'can parse a HTML fragment without a <body>', ->
|
620
|
-
html = """
|
621
|
-
<h1>Full story</h1>
|
622
|
-
"""
|
623
|
-
element = up.element.createDocumentFromHtml(html)
|
624
|
-
expect(element.querySelector("title")).toBeMissing()
|
625
|
-
expect(element.querySelector("h1").textContent).toEqual('Full story')
|
626
|
-
|
627
|
-
describe 'up.element.createFromHtml', ->
|
628
|
-
|
629
|
-
it 'creates an element from the given HTML fragment', ->
|
630
|
-
html = """
|
631
|
-
<h1>Full story</h1>
|
632
|
-
"""
|
633
|
-
element = up.element.createFromHtml(html)
|
634
|
-
expect(element.tagName).toEqual('H1')
|
635
|
-
expect(element.textContent).toEqual('Full story')
|
636
|
-
|
637
|
-
describe 'up.element.fixedToAbsolute', ->
|
638
|
-
|
639
|
-
it "changes the given element's position from fixed to absolute, without changing its rendered position", ->
|
640
|
-
$container = $fixture('.container').css
|
641
|
-
position: 'absolute'
|
642
|
-
left: '100px'
|
643
|
-
top: '100px'
|
644
|
-
backgroundColor: 'yellow'
|
645
|
-
|
646
|
-
$element = $container.affix('.element').text('element').css
|
647
|
-
position: 'fixed',
|
648
|
-
left: '70px'
|
649
|
-
top: '30px'
|
650
|
-
backgroundColor: 'red'
|
651
|
-
|
652
|
-
oldRect = up.Rect.fromElement($element[0])
|
653
|
-
|
654
|
-
up.element.fixedToAbsolute($element[0])
|
655
|
-
|
656
|
-
expect($element.css('position')).toEqual('absolute')
|
657
|
-
newRect = up.Rect.fromElement($element[0])
|
658
|
-
expect(newRect).toEqual(oldRect)
|
659
|
-
|
660
|
-
it 'correctly positions an element with margins', ->
|
661
|
-
$container = $fixture('.container').css
|
662
|
-
position: 'absolute'
|
663
|
-
left: '20px'
|
664
|
-
top: '20px'
|
665
|
-
backgroundColor: 'yellow'
|
666
|
-
|
667
|
-
$element = $container.affix('.element').text('element').css
|
668
|
-
position: 'fixed',
|
669
|
-
left: '40px'
|
670
|
-
top: '60px'
|
671
|
-
backgroundColor: 'red'
|
672
|
-
margin: '15px'
|
673
|
-
|
674
|
-
oldRect = up.Rect.fromElement($element[0])
|
675
|
-
|
676
|
-
up.element.fixedToAbsolute($element[0])
|
677
|
-
|
678
|
-
expect($element.css('position')).toEqual('absolute')
|
679
|
-
newRect = up.Rect.fromElement($element[0])
|
680
|
-
expect(newRect).toEqual(oldRect)
|
681
|
-
|
682
|
-
it 'correctly positions an element when its new offset parent has margins', ->
|
683
|
-
$container = $fixture('.container').css
|
684
|
-
position: 'absolute'
|
685
|
-
left: '100px'
|
686
|
-
top: '100px'
|
687
|
-
margin: '15px',
|
688
|
-
backgroundColor: 'yellow'
|
689
|
-
|
690
|
-
$element = $container.affix('.element').text('element').css
|
691
|
-
position: 'fixed',
|
692
|
-
left: '70px'
|
693
|
-
top: '30px'
|
694
|
-
backgroundColor: 'red'
|
695
|
-
|
696
|
-
oldRect = up.Rect.fromElement($element[0])
|
697
|
-
|
698
|
-
up.element.fixedToAbsolute($element[0])
|
699
|
-
|
700
|
-
expect($element.css('position')).toEqual('absolute')
|
701
|
-
newRect = up.Rect.fromElement($element[0])
|
702
|
-
expect(newRect).toEqual(oldRect)
|
703
|
-
|
704
|
-
it 'correctly positions an element when the new offset parent is scrolled', ->
|
705
|
-
$container = $fixture('.container').css
|
706
|
-
position: 'absolute'
|
707
|
-
left: '100px'
|
708
|
-
top: '100px'
|
709
|
-
margin: '15px',
|
710
|
-
backgroundColor: 'yellow'
|
711
|
-
overflowY: 'scroll'
|
712
|
-
|
713
|
-
$staticContainerContent = $container.affix('.content').css(height: '3000px').scrollTop(100)
|
714
|
-
|
715
|
-
$element = $container.affix('.element').text('element').css
|
716
|
-
position: 'fixed',
|
717
|
-
left: '70px'
|
718
|
-
top: '30px'
|
719
|
-
backgroundColor: 'red'
|
720
|
-
|
721
|
-
oldRect = up.Rect.fromElement($element[0])
|
722
|
-
|
723
|
-
up.element.fixedToAbsolute($element[0])
|
724
|
-
|
725
|
-
expect($element.css('position')).toEqual('absolute')
|
726
|
-
newRect = up.Rect.fromElement($element[0])
|
727
|
-
expect(newRect).toEqual(oldRect)
|
728
|
-
|
729
|
-
describe 'up.element.booleanAttr', ->
|
730
|
-
|
731
|
-
it 'returns true if the attribute value is the string "true"', ->
|
732
|
-
element = fixture('div[foo=true]')
|
733
|
-
expect(up.element.booleanAttr(element, 'foo')).toBe(true)
|
734
|
-
|
735
|
-
it 'returns true if the attribute value is the name of the attribute', ->
|
736
|
-
element = fixture('div[foo=foo]')
|
737
|
-
expect(up.element.booleanAttr(element, 'foo')).toBe(true)
|
738
|
-
|
739
|
-
it 'returns false if the attribute value is the string "false"', ->
|
740
|
-
element = fixture('div[foo=false]')
|
741
|
-
expect(up.element.booleanAttr(element, 'foo')).toBe(false)
|
742
|
-
|
743
|
-
it 'returns a missing value if the element has no such attribute', ->
|
744
|
-
element = fixture('div')
|
745
|
-
expect(up.element.booleanAttr(element, 'foo')).toBeMissing()
|
746
|
-
|
747
|
-
it 'returns undefined if the attribute value cannot be cast to a boolean', ->
|
748
|
-
element = fixture('div[foo="some text"]')
|
749
|
-
expect(up.element.booleanAttr(element, 'foo')).toBeUndefined()
|
750
|
-
|
751
|
-
describe 'up.element.setTemporaryStyle', ->
|
752
|
-
|
753
|
-
it "sets the given inline styles and returns a function that will restore the previous inline styles", ->
|
754
|
-
div = fixture('div[style="color: red"]')
|
755
|
-
restore = up.element.setTemporaryStyle(div, { color: 'blue' })
|
756
|
-
expect(div.getAttribute('style')).toContain('color: blue')
|
757
|
-
expect(div.getAttribute('style')).not.toContain('color: red')
|
758
|
-
restore()
|
759
|
-
expect(div.getAttribute('style')).not.toContain('color: blue')
|
760
|
-
expect(div.getAttribute('style')).toContain('color: red')
|
761
|
-
|
762
|
-
it "does not restore inherited styles", ->
|
763
|
-
div = fixture('div[class="red-background"]')
|
764
|
-
restore = up.element.setTemporaryStyle(div, { backgroundColor: 'blue' })
|
765
|
-
expect(div.getAttribute('style')).toContain('background-color: blue')
|
766
|
-
restore()
|
767
|
-
expect(div.getAttribute('style')).not.toContain('background-color')
|
768
|
-
|
769
|
-
describe 'up.element.inlineStyle', ->
|
770
|
-
|
771
|
-
describe 'with a string as second argument', ->
|
772
|
-
|
773
|
-
it 'returns a CSS value string from an inline [style] attribute', ->
|
774
|
-
div = $fixture('div').attr('style', 'background-color: #ff0000')[0]
|
775
|
-
style = up.element.inlineStyle(div, 'backgroundColor')
|
776
|
-
# Browsers convert colors to rgb() values, even IE11
|
777
|
-
expect(style).toEqual('rgb(255, 0, 0)')
|
778
|
-
|
779
|
-
it 'returns a blank value if the element does not have the given property in the [style] attribute', ->
|
780
|
-
div = $fixture('div').attr('style', 'background-color: red')[0]
|
781
|
-
style = up.element.inlineStyle(div, 'color')
|
782
|
-
expect(style).toBeBlank()
|
783
|
-
|
784
|
-
it 'returns a blank value the given property is a computed property, but not in the [style] attribute', ->
|
785
|
-
div = $fixture('div[class="red-background"]')[0]
|
786
|
-
inlineStyle = up.element.inlineStyle(div, 'backgroundColor')
|
787
|
-
computedStyle = up.element.style(div, 'backgroundColor')
|
788
|
-
expect(computedStyle).toEqual('rgb(255, 0, 0)')
|
789
|
-
expect(inlineStyle).toBeBlank()
|
790
|
-
|
791
|
-
describe 'with an array as second argument', ->
|
792
|
-
|
793
|
-
it 'returns an object with the given inline [style] properties', ->
|
794
|
-
div = $fixture('div').attr('style', 'background-color: #ff0000; color: #0000ff')[0]
|
795
|
-
style = up.element.inlineStyle(div, ['backgroundColor', 'color'])
|
796
|
-
expect(style).toEqual
|
797
|
-
backgroundColor: 'rgb(255, 0, 0)'
|
798
|
-
color: 'rgb(0, 0, 255)'
|
799
|
-
|
800
|
-
it 'returns blank keys if the element does not have the given property in the [style] attribute', ->
|
801
|
-
div = $fixture('div').attr('style', 'background-color: #ff0000')[0]
|
802
|
-
style = up.element.inlineStyle(div, ['backgroundColor', 'color'])
|
803
|
-
expect(style).toHaveOwnProperty('color')
|
804
|
-
expect(style.color).toBeBlank()
|
805
|
-
|
806
|
-
it 'returns a blank value the given property is a computed property, but not in the [style] attribute', ->
|
807
|
-
div = fixture('div[class="red-background"]')
|
808
|
-
inlineStyleHash = up.element.inlineStyle(div, ['backgroundColor'])
|
809
|
-
computedBackground = up.element.style(div, 'backgroundColor')
|
810
|
-
expect(computedBackground).toEqual('rgb(255, 0, 0)')
|
811
|
-
expect(inlineStyleHash).toHaveOwnProperty('backgroundColor')
|
812
|
-
expect(inlineStyleHash.backgroundColor).toBeBlank()
|
813
|
-
|
814
|
-
describe 'up.element.setStyle', ->
|
815
|
-
|
816
|
-
it "sets the given style properties as the given element's [style] attribute", ->
|
817
|
-
div = fixture('div')
|
818
|
-
up.element.setStyle(div, { color: 'red', 'background-color': 'blue' })
|
819
|
-
style = div.getAttribute('style')
|
820
|
-
expect(style).toContain('color: red')
|
821
|
-
expect(style).toContain('background-color: blue')
|
822
|
-
|
823
|
-
it "merges the given style properties into the given element's existing [style] value", ->
|
824
|
-
div = fixture('div[style="color: red"]')
|
825
|
-
up.element.setStyle(div, { 'background-color': 'blue' })
|
826
|
-
style = div.getAttribute('style')
|
827
|
-
expect(style).toContain('color: red')
|
828
|
-
expect(style).toContain('background-color: blue')
|
829
|
-
|
830
|
-
it "converts the values of known length properties to px values automatically (with kebab-case)", ->
|
831
|
-
div = fixture('div')
|
832
|
-
up.element.setStyle(div, { 'padding-top': 100 })
|
833
|
-
style = div.getAttribute('style')
|
834
|
-
expect(style).toContain('padding-top: 100px')
|
835
|
-
|
836
|
-
it "converts the values of known length properties to px values automatically (with camelCase)", ->
|
837
|
-
div = fixture('div')
|
838
|
-
up.element.setStyle(div, { 'paddingTop': 100 })
|
839
|
-
style = div.getAttribute('style')
|
840
|
-
expect(style).toContain('padding-top: 100px')
|
841
|
-
|
842
|
-
it "accepts CSS property names in camelCase", ->
|
843
|
-
div = fixture('div')
|
844
|
-
up.element.setStyle(div, { 'backgroundColor': 'blue' })
|
845
|
-
style = div.getAttribute('style')
|
846
|
-
expect(style).toContain('background-color: blue')
|
847
|
-
|
848
|
-
describe 'up.element.style', ->
|
849
|
-
|
850
|
-
it 'returns the computed style for the given CSS property in kebab-case', ->
|
851
|
-
div = fixture('div')
|
852
|
-
div.style.paddingTop = '10px'
|
853
|
-
value = up.element.style(div, 'padding-top')
|
854
|
-
expect(value).toEqual('10px')
|
855
|
-
|
856
|
-
it 'returns the computed style for the given CSS property in camelCase', ->
|
857
|
-
div = fixture('div')
|
858
|
-
div.style.paddingTop = '10px'
|
859
|
-
value = up.element.style(div, 'paddingTop')
|
860
|
-
expect(value).toEqual('10px')
|
861
|
-
|
862
|
-
it 'returns the computed style for multiple CSS properties in kebab-case', ->
|
863
|
-
div = fixture('div')
|
864
|
-
div.style.paddingTop = '10px'
|
865
|
-
div.style.paddingBottom = '20px'
|
866
|
-
value = up.element.style(div, ['padding-top', 'padding-bottom'])
|
867
|
-
expect(value).toEqual { 'padding-top': '10px', 'padding-bottom': '20px' }
|
868
|
-
|
869
|
-
it 'returns the computed style for multiple CSS properties in camelCase', ->
|
870
|
-
div = fixture('div')
|
871
|
-
div.style.paddingTop = '10px'
|
872
|
-
div.style.paddingBottom = '20px'
|
873
|
-
value = up.element.style(div, ['paddingTop', 'paddingBottom'])
|
874
|
-
expect(value).toEqual { 'paddingTop': '10px', 'paddingBottom': '20px' }
|
875
|
-
|
876
|
-
describe 'up.element.isVisible', ->
|
877
|
-
|
878
|
-
it 'returns true for an attached element', ->
|
879
|
-
element = fixture('.element', text: 'content')
|
880
|
-
expect(up.element.isVisible(element)).toBe(true)
|
881
|
-
|
882
|
-
it 'returns true for an attached block element without content', ->
|
883
|
-
element = fixture('div.element')
|
884
|
-
expect(up.element.isVisible(element)).toBe(true)
|
885
|
-
|
886
|
-
it 'returns true for an attached inline element without content', ->
|
887
|
-
element = fixture('span.element')
|
888
|
-
expect(up.element.isVisible(element)).toBe(true)
|
889
|
-
|
890
|
-
it 'returns false for a detached element', ->
|
891
|
-
element = document.createElement('text')
|
892
|
-
element.innerText = 'content'
|
893
|
-
expect(up.element.isVisible(element)).toBe(false)
|
894
|
-
|
895
|
-
it 'returns false for an attached element with { display: none }', ->
|
896
|
-
element = fixture('.element', text: 'content', style: { display: 'none' })
|
897
|
-
expect(up.element.isVisible(element)).toBe(false)
|