actionpack 1.13.6 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +1400 -20
- data/MIT-LICENSE +1 -1
- data/README +5 -5
- data/RUNNING_UNIT_TESTS +4 -5
- data/Rakefile +5 -6
- data/install.rb +2 -2
- data/lib/action_controller.rb +11 -15
- data/lib/action_controller/assertions.rb +12 -25
- data/lib/action_controller/assertions/dom_assertions.rb +18 -4
- data/lib/action_controller/assertions/model_assertions.rb +8 -1
- data/lib/action_controller/assertions/response_assertions.rb +35 -12
- data/lib/action_controller/assertions/routing_assertions.rb +56 -12
- data/lib/action_controller/assertions/selector_assertions.rb +105 -38
- data/lib/action_controller/assertions/tag_assertions.rb +28 -15
- data/lib/action_controller/base.rb +318 -250
- data/lib/action_controller/benchmarking.rb +33 -29
- data/lib/action_controller/caching.rb +130 -64
- data/lib/action_controller/cgi_ext.rb +16 -0
- data/lib/action_controller/cgi_ext/{cookie_performance_fix.rb → cookie.rb} +25 -40
- data/lib/action_controller/cgi_ext/query_extension.rb +22 -0
- data/lib/action_controller/cgi_ext/session.rb +73 -0
- data/lib/action_controller/cgi_ext/stdinput.rb +23 -0
- data/lib/action_controller/cgi_process.rb +34 -57
- data/lib/action_controller/components.rb +19 -36
- data/lib/action_controller/cookies.rb +10 -9
- data/lib/action_controller/dispatcher.rb +195 -0
- data/lib/action_controller/filters.rb +35 -34
- data/lib/action_controller/flash.rb +30 -35
- data/lib/action_controller/helpers.rb +121 -47
- data/lib/action_controller/http_authentication.rb +126 -0
- data/lib/action_controller/integration.rb +105 -101
- data/lib/action_controller/layout.rb +59 -47
- data/lib/action_controller/mime_responds.rb +57 -68
- data/lib/action_controller/mime_type.rb +43 -80
- data/lib/action_controller/mime_types.rb +20 -0
- data/lib/action_controller/polymorphic_routes.rb +88 -0
- data/lib/action_controller/record_identifier.rb +91 -0
- data/lib/action_controller/request.rb +553 -88
- data/lib/action_controller/request_forgery_protection.rb +126 -0
- data/lib/action_controller/request_profiler.rb +138 -0
- data/lib/action_controller/rescue.rb +185 -69
- data/lib/action_controller/resources.rb +211 -172
- data/lib/action_controller/response.rb +49 -8
- data/lib/action_controller/routing.rb +359 -236
- data/lib/action_controller/routing_optimisation.rb +119 -0
- data/lib/action_controller/session/active_record_store.rb +3 -2
- data/lib/action_controller/session/cookie_store.rb +161 -0
- data/lib/action_controller/session/mem_cache_store.rb +9 -16
- data/lib/action_controller/session_management.rb +17 -8
- data/lib/action_controller/streaming.rb +6 -3
- data/lib/action_controller/templates/rescues/_request_and_response.erb +24 -0
- data/lib/action_controller/templates/rescues/{_trace.rhtml → _trace.erb} +0 -0
- data/lib/action_controller/templates/rescues/{diagnostics.rhtml → diagnostics.erb} +2 -2
- data/lib/action_controller/templates/rescues/{layout.rhtml → layout.erb} +0 -0
- data/lib/action_controller/templates/rescues/{missing_template.rhtml → missing_template.erb} +0 -0
- data/lib/action_controller/templates/rescues/{routing_error.rhtml → routing_error.erb} +0 -0
- data/lib/action_controller/templates/rescues/{template_error.rhtml → template_error.erb} +2 -2
- data/lib/action_controller/templates/rescues/{unknown_action.rhtml → unknown_action.erb} +0 -0
- data/lib/action_controller/test_case.rb +53 -0
- data/lib/action_controller/test_process.rb +59 -46
- data/lib/action_controller/url_rewriter.rb +48 -24
- data/lib/action_controller/vendor/html-scanner/html/document.rb +7 -4
- data/lib/action_controller/vendor/html-scanner/html/sanitizer.rb +173 -0
- data/lib/action_controller/vendor/html-scanner/html/selector.rb +11 -6
- data/lib/action_controller/verification.rb +27 -21
- data/lib/action_pack.rb +1 -1
- data/lib/action_pack/version.rb +4 -4
- data/lib/action_view.rb +2 -3
- data/lib/action_view/base.rb +218 -63
- data/lib/action_view/compiled_templates.rb +1 -2
- data/lib/action_view/helpers/active_record_helper.rb +35 -17
- data/lib/action_view/helpers/asset_tag_helper.rb +395 -87
- data/lib/action_view/helpers/atom_feed_helper.rb +111 -0
- data/lib/action_view/helpers/benchmark_helper.rb +12 -5
- data/lib/action_view/helpers/cache_helper.rb +29 -0
- data/lib/action_view/helpers/capture_helper.rb +97 -63
- data/lib/action_view/helpers/date_helper.rb +295 -35
- data/lib/action_view/helpers/debug_helper.rb +6 -2
- data/lib/action_view/helpers/form_helper.rb +354 -111
- data/lib/action_view/helpers/form_options_helper.rb +171 -109
- data/lib/action_view/helpers/form_tag_helper.rb +332 -76
- data/lib/action_view/helpers/javascript_helper.rb +35 -11
- data/lib/action_view/helpers/javascripts/controls.js +484 -354
- data/lib/action_view/helpers/javascripts/dragdrop.js +88 -58
- data/lib/action_view/helpers/javascripts/effects.js +396 -364
- data/lib/action_view/helpers/javascripts/prototype.js +2817 -1107
- data/lib/action_view/helpers/number_helper.rb +84 -60
- data/lib/action_view/helpers/prototype_helper.rb +419 -43
- data/lib/action_view/helpers/record_identification_helper.rb +20 -0
- data/lib/action_view/helpers/record_tag_helper.rb +59 -0
- data/lib/action_view/helpers/sanitize_helper.rb +223 -0
- data/lib/action_view/helpers/scriptaculous_helper.rb +63 -4
- data/lib/action_view/helpers/tag_helper.rb +69 -39
- data/lib/action_view/helpers/text_helper.rb +221 -148
- data/lib/action_view/helpers/url_helper.rb +283 -165
- data/lib/action_view/partials.rb +134 -62
- data/lib/action_view/template_error.rb +4 -12
- data/lib/actionpack.rb +1 -0
- data/test/abstract_unit.rb +21 -1
- data/test/action_view_test.rb +26 -0
- data/test/active_record_unit.rb +12 -20
- data/test/activerecord/active_record_store_test.rb +2 -2
- data/test/activerecord/render_partial_with_record_identification_test.rb +74 -0
- data/test/controller/action_pack_assertions_test.rb +21 -152
- data/test/controller/addresses_render_test.rb +2 -7
- data/test/controller/assert_select_test.rb +120 -14
- data/test/controller/base_test.rb +11 -13
- data/test/controller/caching_test.rb +125 -5
- data/test/controller/capture_test.rb +23 -16
- data/test/controller/cgi_test.rb +66 -391
- data/test/controller/components_test.rb +31 -42
- data/test/controller/content_type_test.rb +1 -1
- data/test/controller/cookie_test.rb +42 -14
- data/test/controller/deprecation/deprecated_base_methods_test.rb +1 -42
- data/test/controller/dispatcher_test.rb +123 -0
- data/test/controller/fake_models.rb +5 -0
- data/test/controller/filters_test.rb +44 -7
- data/test/controller/flash_test.rb +46 -2
- data/test/controller/fragment_store_setting_test.rb +10 -8
- data/test/controller/helper_test.rb +19 -2
- data/test/controller/html-scanner/document_test.rb +124 -0
- data/test/controller/html-scanner/node_test.rb +69 -0
- data/test/controller/html-scanner/sanitizer_test.rb +250 -0
- data/test/controller/html-scanner/tag_node_test.rb +239 -0
- data/test/controller/html-scanner/text_node_test.rb +51 -0
- data/test/controller/html-scanner/tokenizer_test.rb +125 -0
- data/test/controller/http_authentication_test.rb +54 -0
- data/test/controller/integration_test.rb +12 -26
- data/test/controller/layout_test.rb +64 -12
- data/test/controller/mime_responds_test.rb +193 -38
- data/test/controller/mime_type_test.rb +30 -8
- data/test/controller/new_render_test.rb +104 -22
- data/test/controller/polymorphic_routes_test.rb +98 -0
- data/test/controller/record_identifier_test.rb +103 -0
- data/test/controller/redirect_test.rb +120 -18
- data/test/controller/render_test.rb +195 -45
- data/test/controller/request_forgery_protection_test.rb +217 -0
- data/test/controller/request_test.rb +545 -27
- data/test/controller/rescue_test.rb +501 -0
- data/test/controller/resources_test.rb +258 -132
- data/test/controller/routing_test.rb +502 -106
- data/test/controller/selector_test.rb +5 -5
- data/test/controller/send_file_test.rb +17 -7
- data/test/controller/session/cookie_store_test.rb +246 -0
- data/test/controller/session/mem_cache_store_test.rb +182 -0
- data/test/controller/session_fixation_test.rb +8 -11
- data/test/controller/session_management_test.rb +7 -7
- data/test/controller/test_test.rb +150 -38
- data/test/controller/url_rewriter_test.rb +87 -12
- data/test/controller/verification_test.rb +11 -0
- data/test/controller/view_paths_test.rb +137 -0
- data/test/controller/webservice_test.rb +11 -75
- data/test/fixtures/addresses/{list.rhtml → list.erb} +0 -0
- data/test/fixtures/db_definitions/sqlite.sql +2 -1
- data/test/fixtures/developer.rb +2 -0
- data/test/fixtures/fun/games/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/helpers/fun/pdf_helper.rb +1 -1
- data/test/fixtures/layout_tests/alt/hello.rhtml +1 -0
- data/test/fixtures/layout_tests/layouts/multiple_extensions.html.erb +1 -0
- data/test/fixtures/layouts/{builder.rxml → builder.builder} +0 -0
- data/test/fixtures/layouts/{standard.rhtml → standard.erb} +0 -0
- data/test/fixtures/layouts/{talk_from_action.rhtml → talk_from_action.erb} +0 -0
- data/test/fixtures/layouts/{yield.rhtml → yield.erb} +0 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/bracketed_param +5 -0
- data/test/fixtures/override/test/hello_world.erb +1 -0
- data/test/fixtures/override2/layouts/test/sub.erb +1 -0
- data/test/fixtures/post_test/layouts/post.html.erb +1 -0
- data/test/fixtures/post_test/layouts/super_post.iphone.erb +1 -0
- data/test/fixtures/post_test/post/index.html.erb +1 -0
- data/test/fixtures/post_test/post/index.iphone.erb +1 -0
- data/test/fixtures/post_test/super_post/index.html.erb +1 -0
- data/test/fixtures/post_test/super_post/index.iphone.erb +1 -0
- data/test/fixtures/public/404.html +1 -0
- data/test/fixtures/public/500.html +1 -0
- data/test/fixtures/public/javascripts/application.js +0 -1
- data/test/fixtures/public/javascripts/bank.js +1 -0
- data/test/fixtures/public/javascripts/robber.js +1 -0
- data/test/fixtures/public/stylesheets/bank.css +1 -0
- data/test/fixtures/public/stylesheets/robber.css +1 -0
- data/test/fixtures/replies.yml +2 -0
- data/test/fixtures/reply.rb +2 -1
- data/test/fixtures/respond_to/{all_types_with_layout.rhtml → all_types_with_layout.html.erb} +0 -0
- data/test/fixtures/respond_to/{all_types_with_layout.rjs → all_types_with_layout.js.rjs} +0 -0
- data/test/fixtures/respond_to/custom_constant_handling_without_block.mobile.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.html.erb +1 -0
- data/test/fixtures/respond_to/iphone_with_html_response_type.iphone.erb +1 -0
- data/test/fixtures/respond_to/layouts/missing.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.html.erb +1 -0
- data/test/fixtures/respond_to/layouts/standard.iphone.erb +1 -0
- data/test/fixtures/respond_to/{using_defaults.rhtml → using_defaults.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rjs → using_defaults.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults.rxml → using_defaults.xml.builder} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rhtml → using_defaults_with_type_list.html.erb} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rjs → using_defaults_with_type_list.js.rjs} +0 -0
- data/test/fixtures/respond_to/{using_defaults_with_type_list.rxml → using_defaults_with_type_list.xml.builder} +0 -0
- data/test/fixtures/scope/test/{modgreet.rhtml → modgreet.erb} +0 -0
- data/test/fixtures/test/{_customer.rhtml → _customer.erb} +0 -0
- data/test/fixtures/test/{_customer_greeting.rhtml → _customer_greeting.erb} +0 -0
- data/test/fixtures/test/_hash_greeting.erb +1 -0
- data/test/fixtures/test/_hash_object.erb +2 -0
- data/test/fixtures/test/{_hello.rxml → _hello.builder} +0 -0
- data/test/fixtures/test/_layout_for_partial.html.erb +3 -0
- data/test/fixtures/test/_partial.erb +1 -0
- data/test/fixtures/test/_partial.html.erb +1 -0
- data/test/fixtures/test/_partial.js.erb +1 -0
- data/test/fixtures/test/_partial_for_use_in_layout.html.erb +1 -0
- data/test/fixtures/test/{_partial_only.rhtml → _partial_only.erb} +0 -0
- data/test/fixtures/test/{_person.rhtml → _person.erb} +0 -0
- data/test/fixtures/test/{action_talk_to_layout.rhtml → action_talk_to_layout.erb} +0 -0
- data/test/fixtures/test/{block_content_for.rhtml → block_content_for.erb} +0 -0
- data/test/fixtures/test/calling_partial_with_layout.html.erb +1 -0
- data/test/fixtures/test/{capturing.rhtml → capturing.erb} +0 -0
- data/test/fixtures/test/{content_for.rhtml → content_for.erb} +0 -0
- data/test/fixtures/test/content_for_concatenated.erb +3 -0
- data/test/fixtures/test/content_for_with_parameter.erb +2 -0
- data/test/fixtures/test/dot.directory/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{erb_content_for.rhtml → erb_content_for.erb} +0 -0
- data/test/fixtures/test/formatted_html_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.builder +1 -0
- data/test/fixtures/test/formatted_xml_erb.html.erb +1 -0
- data/test/fixtures/test/formatted_xml_erb.xml.erb +1 -0
- data/test/fixtures/test/{greeting.rhtml → greeting.erb} +0 -0
- data/test/fixtures/test/{hello.rxml → hello.builder} +0 -0
- data/test/fixtures/test/{hello_world.rxml → hello_world.builder} +0 -0
- data/test/fixtures/test/{hello_world.rhtml → hello_world.erb} +0 -0
- data/test/fixtures/test/{hello_world_container.rxml → hello_world_container.builder} +0 -0
- data/test/fixtures/test/{hello_world_with_layout_false.rhtml → hello_world_with_layout_false.erb} +0 -0
- data/test/fixtures/test/{hello_xml_world.rxml → hello_xml_world.builder} +0 -0
- data/test/fixtures/test/list.erb +1 -0
- data/test/fixtures/test/{non_erb_block_content_for.rxml → non_erb_block_content_for.builder} +0 -0
- data/test/fixtures/test/{potential_conflicts.rhtml → potential_conflicts.erb} +0 -0
- data/test/fixtures/test/{render_file_with_ivar.rhtml → render_file_with_ivar.erb} +0 -0
- data/test/fixtures/test/{render_file_with_locals.rhtml → render_file_with_locals.erb} +0 -0
- data/test/fixtures/test/{render_to_string_test.rhtml → render_to_string_test.erb} +0 -0
- data/test/fixtures/test/{update_element_with_capture.rhtml → update_element_with_capture.erb} +0 -0
- data/test/fixtures/test/using_layout_around_block.html.erb +1 -0
- data/test/fixtures/topic.rb +1 -1
- data/test/template/active_record_helper_test.rb +67 -20
- data/test/template/asset_tag_helper_test.rb +222 -54
- data/test/template/atom_feed_helper_test.rb +101 -0
- data/test/template/benchmark_helper_test.rb +2 -2
- data/test/template/compiled_templates_test.rb +76 -32
- data/test/template/date_helper_test.rb +125 -9
- data/test/template/form_helper_test.rb +326 -33
- data/test/template/form_options_helper_test.rb +822 -15
- data/test/template/form_tag_helper_test.rb +96 -30
- data/test/template/javascript_helper_test.rb +61 -13
- data/test/template/number_helper_test.rb +12 -11
- data/test/template/prototype_helper_test.rb +185 -24
- data/test/template/sanitize_helper_test.rb +49 -0
- data/test/template/scriptaculous_helper_test.rb +9 -3
- data/test/template/tag_helper_test.rb +13 -2
- data/test/template/text_helper_test.rb +38 -52
- data/test/template/url_helper_test.rb +216 -46
- metadata +144 -116
- data/examples/.htaccess +0 -24
- data/examples/address_book/index.rhtml +0 -33
- data/examples/address_book/layout.rhtml +0 -8
- data/examples/address_book_controller.cgi +0 -9
- data/examples/address_book_controller.fcgi +0 -6
- data/examples/address_book_controller.rb +0 -52
- data/examples/address_book_controller.rbx +0 -4
- data/examples/benchmark.rb +0 -52
- data/examples/benchmark_with_ar.fcgi +0 -89
- data/examples/blog_controller.cgi +0 -53
- data/examples/debate/index.rhtml +0 -14
- data/examples/debate/new_topic.rhtml +0 -22
- data/examples/debate/topic.rhtml +0 -32
- data/examples/debate_controller.cgi +0 -57
- data/lib/action_controller/assertions/deprecated_assertions.rb +0 -228
- data/lib/action_controller/cgi_ext/cgi_ext.rb +0 -36
- data/lib/action_controller/cgi_ext/cgi_methods.rb +0 -211
- data/lib/action_controller/cgi_ext/pstore_performance_fix.rb +0 -30
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +0 -95
- data/lib/action_controller/cgi_ext/session_performance_fix.rb +0 -30
- data/lib/action_controller/deprecated_dependencies.rb +0 -65
- data/lib/action_controller/deprecated_redirects.rb +0 -17
- data/lib/action_controller/deprecated_request_methods.rb +0 -34
- data/lib/action_controller/macros/auto_complete.rb +0 -53
- data/lib/action_controller/macros/in_place_editing.rb +0 -33
- data/lib/action_controller/pagination.rb +0 -408
- data/lib/action_controller/scaffolding.rb +0 -189
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -44
- data/lib/action_controller/templates/scaffolds/edit.rhtml +0 -7
- data/lib/action_controller/templates/scaffolds/layout.rhtml +0 -69
- data/lib/action_controller/templates/scaffolds/list.rhtml +0 -27
- data/lib/action_controller/templates/scaffolds/new.rhtml +0 -6
- data/lib/action_controller/templates/scaffolds/show.rhtml +0 -9
- data/lib/action_controller/vendor/xml_node.rb +0 -97
- data/lib/action_view/helpers/deprecated_helper.rb +0 -37
- data/lib/action_view/helpers/java_script_macros_helper.rb +0 -233
- data/lib/action_view/helpers/pagination_helper.rb +0 -86
- data/test/activerecord/active_record_assertions_test.rb +0 -92
- data/test/activerecord/pagination_test.rb +0 -165
- data/test/controller/deprecated_instance_variables_test.rb +0 -48
- data/test/controller/raw_post_test.rb +0 -68
- data/test/fixtures/deprecated_instance_variables/_cookies_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_cookies_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_flash_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_headers_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_params_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_request_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_response_method.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_ivar.rhtml +0 -1
- data/test/fixtures/deprecated_instance_variables/_session_method.rhtml +0 -1
- data/test/fixtures/respond_to/layouts/standard.rhtml +0 -1
- data/test/fixtures/test/_hash_object.rhtml +0 -1
- data/test/fixtures/test/list.rhtml +0 -1
- data/test/template/deprecated_helper_test.rb +0 -36
- data/test/template/deprecated_instance_variables_test.rb +0 -43
- data/test/template/java_script_macros_helper_test.rb +0 -109
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'action_view/helpers/tag_helper'
|
2
|
+
require 'action_view/helpers/prototype_helper'
|
3
3
|
|
4
4
|
module ActionView
|
5
5
|
module Helpers
|
@@ -80,7 +80,7 @@ module ActionView
|
|
80
80
|
# return false;">Show me more</a>
|
81
81
|
#
|
82
82
|
def link_to_function(name, *args, &block)
|
83
|
-
html_options = args.
|
83
|
+
html_options = args.extract_options!
|
84
84
|
function = args[0] || ''
|
85
85
|
|
86
86
|
html_options.symbolize_keys!
|
@@ -111,7 +111,7 @@ module ActionView
|
|
111
111
|
# page[:details].visual_effect :toggle_slide
|
112
112
|
# end
|
113
113
|
def button_to_function(name, *args, &block)
|
114
|
-
html_options = args.
|
114
|
+
html_options = args.extract_options!
|
115
115
|
function = args[0] || ''
|
116
116
|
|
117
117
|
html_options.symbolize_keys!
|
@@ -132,7 +132,7 @@ module ActionView
|
|
132
132
|
# public/javascripts/ directory, and use +javascript_include_tag+ to
|
133
133
|
# create remote <script> links.
|
134
134
|
def define_javascript_functions
|
135
|
-
javascript =
|
135
|
+
javascript = "<script type=\"#{Mime::JS}\">"
|
136
136
|
|
137
137
|
# load prototype.js and its extensions first
|
138
138
|
prototype_libs = Dir.glob(File.join(JAVASCRIPT_PATH, 'prototype*')).sort.reverse
|
@@ -140,7 +140,7 @@ module ActionView
|
|
140
140
|
javascript << "\n" << IO.read(filename)
|
141
141
|
end
|
142
142
|
|
143
|
-
# load other
|
143
|
+
# load other libraries
|
144
144
|
(Dir.glob(File.join(JAVASCRIPT_PATH, '*')) - prototype_libs).each do |filename|
|
145
145
|
javascript << "\n" << IO.read(filename)
|
146
146
|
end
|
@@ -149,14 +149,13 @@ module ActionView
|
|
149
149
|
|
150
150
|
# Escape carrier returns and single and double quotes for JavaScript segments.
|
151
151
|
def escape_javascript(javascript)
|
152
|
-
(javascript || '').gsub('\\','\0\0').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
|
152
|
+
(javascript || '').gsub('\\','\0\0').gsub('</','<\/').gsub(/\r\n|\n|\r/, "\\n").gsub(/["']/) { |m| "\\#{m}" }
|
153
153
|
end
|
154
154
|
|
155
155
|
# Returns a JavaScript tag with the +content+ inside. Example:
|
156
156
|
# javascript_tag "alert('All is good')"
|
157
157
|
#
|
158
158
|
# Returns:
|
159
|
-
#
|
160
159
|
# <script type="text/javascript">
|
161
160
|
# //<![CDATA[
|
162
161
|
# alert('All is good')
|
@@ -164,9 +163,29 @@ module ActionView
|
|
164
163
|
# </script>
|
165
164
|
#
|
166
165
|
# +html_options+ may be a hash of attributes for the <script> tag. Example:
|
167
|
-
# javascript_tag "alert('All is good')", :defer => '
|
168
|
-
|
169
|
-
|
166
|
+
# javascript_tag "alert('All is good')", :defer => 'defer'
|
167
|
+
# # => <script defer="defer" type="text/javascript">alert('All is good')</script>
|
168
|
+
#
|
169
|
+
# Instead of passing the content as an argument, you can also use a block
|
170
|
+
# in which case, you pass your +html_options+ as the first parameter.
|
171
|
+
# <% javascript_tag :defer => 'defer' do -%>
|
172
|
+
# alert('All is good')
|
173
|
+
# <% end -%>
|
174
|
+
def javascript_tag(content_or_options_with_block = nil, html_options = {}, &block)
|
175
|
+
if block_given?
|
176
|
+
html_options = content_or_options_with_block if content_or_options_with_block.is_a?(Hash)
|
177
|
+
content = capture(&block)
|
178
|
+
else
|
179
|
+
content = content_or_options_with_block
|
180
|
+
end
|
181
|
+
|
182
|
+
javascript_tag = content_tag("script", javascript_cdata_section(content), html_options.merge(:type => Mime::JS))
|
183
|
+
|
184
|
+
if block_given? && block_is_within_action_view?(block)
|
185
|
+
concat(javascript_tag, block.binding)
|
186
|
+
else
|
187
|
+
javascript_tag
|
188
|
+
end
|
170
189
|
end
|
171
190
|
|
172
191
|
def javascript_cdata_section(content) #:nodoc:
|
@@ -186,6 +205,11 @@ module ActionView
|
|
186
205
|
end
|
187
206
|
js_option
|
188
207
|
end
|
208
|
+
|
209
|
+
private
|
210
|
+
def block_is_within_action_view?(block)
|
211
|
+
eval("defined? _erbout", block.binding)
|
212
|
+
end
|
189
213
|
end
|
190
214
|
|
191
215
|
JavascriptHelper = JavaScriptHelper unless const_defined? :JavascriptHelper
|
@@ -1,6 +1,6 @@
|
|
1
|
-
// Copyright (c) 2005
|
2
|
-
// (c) 2005
|
3
|
-
// (c) 2005
|
1
|
+
// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
2
|
+
// (c) 2005-2007 Ivan Krstic (http://blogs.law.harvard.edu/ivan)
|
3
|
+
// (c) 2005-2007 Jon Tirsen (http://www.tirsen.com)
|
4
4
|
// Contributors:
|
5
5
|
// Richard Livsey
|
6
6
|
// Rahul Bhargava
|
@@ -37,22 +37,23 @@
|
|
37
37
|
if(typeof Effect == 'undefined')
|
38
38
|
throw("controls.js requires including script.aculo.us' effects.js library");
|
39
39
|
|
40
|
-
var Autocompleter = {}
|
41
|
-
Autocompleter.Base =
|
42
|
-
Autocompleter.Base.prototype = {
|
40
|
+
var Autocompleter = { }
|
41
|
+
Autocompleter.Base = Class.create({
|
43
42
|
baseInitialize: function(element, update, options) {
|
44
|
-
|
43
|
+
element = $(element)
|
44
|
+
this.element = element;
|
45
45
|
this.update = $(update);
|
46
46
|
this.hasFocus = false;
|
47
47
|
this.changed = false;
|
48
48
|
this.active = false;
|
49
49
|
this.index = 0;
|
50
50
|
this.entryCount = 0;
|
51
|
+
this.oldElementValue = this.element.value;
|
51
52
|
|
52
53
|
if(this.setOptions)
|
53
54
|
this.setOptions(options);
|
54
55
|
else
|
55
|
-
this.options = options || {};
|
56
|
+
this.options = options || { };
|
56
57
|
|
57
58
|
this.options.paramName = this.options.paramName || this.element.name;
|
58
59
|
this.options.tokens = this.options.tokens || [];
|
@@ -74,6 +75,9 @@ Autocompleter.Base.prototype = {
|
|
74
75
|
|
75
76
|
if(typeof(this.options.tokens) == 'string')
|
76
77
|
this.options.tokens = new Array(this.options.tokens);
|
78
|
+
// Force carriage returns as token delimiters anyway
|
79
|
+
if (!this.options.tokens.include('\n'))
|
80
|
+
this.options.tokens.push('\n');
|
77
81
|
|
78
82
|
this.observer = null;
|
79
83
|
|
@@ -81,15 +85,14 @@ Autocompleter.Base.prototype = {
|
|
81
85
|
|
82
86
|
Element.hide(this.update);
|
83
87
|
|
84
|
-
Event.observe(this.element,
|
85
|
-
Event.observe(this.element,
|
88
|
+
Event.observe(this.element, 'blur', this.onBlur.bindAsEventListener(this));
|
89
|
+
Event.observe(this.element, 'keydown', this.onKeyPress.bindAsEventListener(this));
|
86
90
|
},
|
87
91
|
|
88
92
|
show: function() {
|
89
93
|
if(Element.getStyle(this.update, 'display')=='none') this.options.onShow(this.element, this.update);
|
90
94
|
if(!this.iefix &&
|
91
|
-
(
|
92
|
-
(navigator.userAgent.indexOf('Opera')<0) &&
|
95
|
+
(Prototype.Browser.IE) &&
|
93
96
|
(Element.getStyle(this.update, 'position')=='absolute')) {
|
94
97
|
new Insertion.After(this.update,
|
95
98
|
'<iframe id="' + this.update.id + '_iefix" '+
|
@@ -139,17 +142,17 @@ Autocompleter.Base.prototype = {
|
|
139
142
|
case Event.KEY_UP:
|
140
143
|
this.markPrevious();
|
141
144
|
this.render();
|
142
|
-
|
145
|
+
Event.stop(event);
|
143
146
|
return;
|
144
147
|
case Event.KEY_DOWN:
|
145
148
|
this.markNext();
|
146
149
|
this.render();
|
147
|
-
|
150
|
+
Event.stop(event);
|
148
151
|
return;
|
149
152
|
}
|
150
153
|
else
|
151
154
|
if(event.keyCode==Event.KEY_TAB || event.keyCode==Event.KEY_RETURN ||
|
152
|
-
(
|
155
|
+
(Prototype.Browser.WebKit > 0 && event.keyCode == 0)) return;
|
153
156
|
|
154
157
|
this.changed = true;
|
155
158
|
this.hasFocus = true;
|
@@ -195,7 +198,6 @@ Autocompleter.Base.prototype = {
|
|
195
198
|
this.index==i ?
|
196
199
|
Element.addClassName(this.getEntry(i),"selected") :
|
197
200
|
Element.removeClassName(this.getEntry(i),"selected");
|
198
|
-
|
199
201
|
if(this.hasFocus) {
|
200
202
|
this.show();
|
201
203
|
this.active = true;
|
@@ -238,21 +240,22 @@ Autocompleter.Base.prototype = {
|
|
238
240
|
}
|
239
241
|
var value = '';
|
240
242
|
if (this.options.select) {
|
241
|
-
var nodes =
|
243
|
+
var nodes = $(selectedElement).select('.' + this.options.select) || [];
|
242
244
|
if(nodes.length>0) value = Element.collectTextNodes(nodes[0], this.options.select);
|
243
245
|
} else
|
244
246
|
value = Element.collectTextNodesIgnoreClass(selectedElement, 'informal');
|
245
247
|
|
246
|
-
var
|
247
|
-
if (
|
248
|
-
var newValue = this.element.value.substr(0,
|
249
|
-
var whitespace = this.element.value.substr(
|
248
|
+
var bounds = this.getTokenBounds();
|
249
|
+
if (bounds[0] != -1) {
|
250
|
+
var newValue = this.element.value.substr(0, bounds[0]);
|
251
|
+
var whitespace = this.element.value.substr(bounds[0]).match(/^\s+/);
|
250
252
|
if (whitespace)
|
251
253
|
newValue += whitespace[0];
|
252
|
-
this.element.value = newValue + value;
|
254
|
+
this.element.value = newValue + value + this.element.value.substr(bounds[1]);
|
253
255
|
} else {
|
254
256
|
this.element.value = value;
|
255
257
|
}
|
258
|
+
this.oldElementValue = this.element.value;
|
256
259
|
this.element.focus();
|
257
260
|
|
258
261
|
if (this.options.afterUpdateElement)
|
@@ -296,39 +299,48 @@ Autocompleter.Base.prototype = {
|
|
296
299
|
|
297
300
|
onObserverEvent: function() {
|
298
301
|
this.changed = false;
|
302
|
+
this.tokenBounds = null;
|
299
303
|
if(this.getToken().length>=this.options.minChars) {
|
300
|
-
this.startIndicator();
|
301
304
|
this.getUpdatedChoices();
|
302
305
|
} else {
|
303
306
|
this.active = false;
|
304
307
|
this.hide();
|
305
308
|
}
|
309
|
+
this.oldElementValue = this.element.value;
|
306
310
|
},
|
307
311
|
|
308
312
|
getToken: function() {
|
309
|
-
var
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
var
|
320
|
-
|
321
|
-
for (var
|
322
|
-
|
323
|
-
if (
|
324
|
-
|
313
|
+
var bounds = this.getTokenBounds();
|
314
|
+
return this.element.value.substring(bounds[0], bounds[1]).strip();
|
315
|
+
},
|
316
|
+
|
317
|
+
getTokenBounds: function() {
|
318
|
+
if (null != this.tokenBounds) return this.tokenBounds;
|
319
|
+
var value = this.element.value;
|
320
|
+
if (value.strip().empty()) return [-1, 0];
|
321
|
+
var diff = arguments.callee.getFirstDifferencePos(value, this.oldElementValue);
|
322
|
+
var offset = (diff == this.oldElementValue.length ? 1 : 0);
|
323
|
+
var prevTokenPos = -1, nextTokenPos = value.length;
|
324
|
+
var tp;
|
325
|
+
for (var index = 0, l = this.options.tokens.length; index < l; ++index) {
|
326
|
+
tp = value.lastIndexOf(this.options.tokens[index], diff + offset - 1);
|
327
|
+
if (tp > prevTokenPos) prevTokenPos = tp;
|
328
|
+
tp = value.indexOf(this.options.tokens[index], diff + offset);
|
329
|
+
if (-1 != tp && tp < nextTokenPos) nextTokenPos = tp;
|
325
330
|
}
|
326
|
-
return
|
331
|
+
return (this.tokenBounds = [prevTokenPos + 1, nextTokenPos]);
|
327
332
|
}
|
328
|
-
}
|
333
|
+
});
|
334
|
+
|
335
|
+
Autocompleter.Base.prototype.getTokenBounds.getFirstDifferencePos = function(newS, oldS) {
|
336
|
+
var boundary = Math.min(newS.length, oldS.length);
|
337
|
+
for (var index = 0; index < boundary; ++index)
|
338
|
+
if (newS[index] != oldS[index])
|
339
|
+
return index;
|
340
|
+
return boundary;
|
341
|
+
};
|
329
342
|
|
330
|
-
Ajax.Autocompleter = Class.create(
|
331
|
-
Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.prototype), {
|
343
|
+
Ajax.Autocompleter = Class.create(Autocompleter.Base, {
|
332
344
|
initialize: function(element, update, url, options) {
|
333
345
|
this.baseInitialize(element, update, options);
|
334
346
|
this.options.asynchronous = true;
|
@@ -338,7 +350,9 @@ Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.pro
|
|
338
350
|
},
|
339
351
|
|
340
352
|
getUpdatedChoices: function() {
|
341
|
-
|
353
|
+
this.startIndicator();
|
354
|
+
|
355
|
+
var entry = encodeURIComponent(this.options.paramName) + '=' +
|
342
356
|
encodeURIComponent(this.getToken());
|
343
357
|
|
344
358
|
this.options.parameters = this.options.callback ?
|
@@ -346,14 +360,13 @@ Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.pro
|
|
346
360
|
|
347
361
|
if(this.options.defaultParams)
|
348
362
|
this.options.parameters += '&' + this.options.defaultParams;
|
349
|
-
|
363
|
+
|
350
364
|
new Ajax.Request(this.url, this.options);
|
351
365
|
},
|
352
366
|
|
353
367
|
onComplete: function(request) {
|
354
368
|
this.updateChoices(request.responseText);
|
355
369
|
}
|
356
|
-
|
357
370
|
});
|
358
371
|
|
359
372
|
// The local array autocompleter. Used when you'd prefer to
|
@@ -391,8 +404,7 @@ Object.extend(Object.extend(Ajax.Autocompleter.prototype, Autocompleter.Base.pro
|
|
391
404
|
// In that case, the other options above will not apply unless
|
392
405
|
// you support them.
|
393
406
|
|
394
|
-
Autocompleter.Local = Class.create(
|
395
|
-
Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
|
407
|
+
Autocompleter.Local = Class.create(Autocompleter.Base, {
|
396
408
|
initialize: function(element, update, array, options) {
|
397
409
|
this.baseInitialize(element, update, options);
|
398
410
|
this.options.array = array;
|
@@ -448,13 +460,12 @@ Autocompleter.Local.prototype = Object.extend(new Autocompleter.Base(), {
|
|
448
460
|
ret = ret.concat(partial.slice(0, instance.options.choices - ret.length))
|
449
461
|
return "<ul>" + ret.join('') + "</ul>";
|
450
462
|
}
|
451
|
-
}, options || {});
|
463
|
+
}, options || { });
|
452
464
|
}
|
453
465
|
});
|
454
466
|
|
455
|
-
// AJAX in-place editor
|
456
|
-
//
|
457
|
-
// see documentation on http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor
|
467
|
+
// AJAX in-place editor and collection editor
|
468
|
+
// Full rewrite by Christophe Porteneuve <tdd@tddsworld.com> (April 2007).
|
458
469
|
|
459
470
|
// Use this if you notice weird scrolling problems on some browsers,
|
460
471
|
// the DOM might be a bit confused when this gets called so do this
|
@@ -465,353 +476,472 @@ Field.scrollFreeActivate = function(field) {
|
|
465
476
|
}, 1);
|
466
477
|
}
|
467
478
|
|
468
|
-
Ajax.InPlaceEditor = Class.create(
|
469
|
-
Ajax.InPlaceEditor.defaultHighlightColor = "#FFFF99";
|
470
|
-
Ajax.InPlaceEditor.prototype = {
|
479
|
+
Ajax.InPlaceEditor = Class.create({
|
471
480
|
initialize: function(element, url, options) {
|
472
481
|
this.url = url;
|
473
|
-
this.element = $(element);
|
474
|
-
|
475
|
-
this.
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
clickToEditText: "Click to edit",
|
483
|
-
okText: "ok",
|
484
|
-
rows: 1,
|
485
|
-
onComplete: function(transport, element) {
|
486
|
-
new Effect.Highlight(element, {startcolor: this.options.highlightcolor});
|
487
|
-
},
|
488
|
-
onFailure: function(transport) {
|
489
|
-
alert("Error communicating with the server: " + transport.responseText.stripTags());
|
490
|
-
},
|
491
|
-
callback: function(form) {
|
492
|
-
return Form.serialize(form);
|
493
|
-
},
|
494
|
-
handleLineBreaks: true,
|
495
|
-
loadingText: 'Loading...',
|
496
|
-
savingClassName: 'inplaceeditor-saving',
|
497
|
-
loadingClassName: 'inplaceeditor-loading',
|
498
|
-
formClassName: 'inplaceeditor-form',
|
499
|
-
highlightcolor: Ajax.InPlaceEditor.defaultHighlightColor,
|
500
|
-
highlightendcolor: "#FFFFFF",
|
501
|
-
externalControl: null,
|
502
|
-
submitOnBlur: false,
|
503
|
-
ajaxOptions: {},
|
504
|
-
evalScripts: false
|
505
|
-
}, options || {});
|
506
|
-
|
507
|
-
if(!this.options.formId && this.element.id) {
|
508
|
-
this.options.formId = this.element.id + "-inplaceeditor";
|
509
|
-
if ($(this.options.formId)) {
|
510
|
-
// there's already a form with that name, don't specify an id
|
511
|
-
this.options.formId = null;
|
512
|
-
}
|
482
|
+
this.element = element = $(element);
|
483
|
+
this.prepareOptions();
|
484
|
+
this._controls = { };
|
485
|
+
arguments.callee.dealWithDeprecatedOptions(options); // DEPRECATION LAYER!!!
|
486
|
+
Object.extend(this.options, options || { });
|
487
|
+
if (!this.options.formId && this.element.id) {
|
488
|
+
this.options.formId = this.element.id + '-inplaceeditor';
|
489
|
+
if ($(this.options.formId))
|
490
|
+
this.options.formId = '';
|
513
491
|
}
|
514
|
-
|
515
|
-
if (this.options.externalControl) {
|
492
|
+
if (this.options.externalControl)
|
516
493
|
this.options.externalControl = $(this.options.externalControl);
|
517
|
-
|
518
|
-
|
519
|
-
this.
|
520
|
-
if (!this.originalBackground) {
|
521
|
-
this.originalBackground = "transparent";
|
522
|
-
}
|
523
|
-
|
494
|
+
if (!this.options.externalControl)
|
495
|
+
this.options.externalControlOnly = false;
|
496
|
+
this._originalBackground = this.element.getStyle('background-color') || 'transparent';
|
524
497
|
this.element.title = this.options.clickToEditText;
|
525
|
-
|
526
|
-
this.
|
527
|
-
this.
|
528
|
-
this.
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
498
|
+
this._boundCancelHandler = this.handleFormCancellation.bind(this);
|
499
|
+
this._boundComplete = (this.options.onComplete || Prototype.emptyFunction).bind(this);
|
500
|
+
this._boundFailureHandler = this.handleAJAXFailure.bind(this);
|
501
|
+
this._boundSubmitHandler = this.handleFormSubmission.bind(this);
|
502
|
+
this._boundWrapperHandler = this.wrapUp.bind(this);
|
503
|
+
this.registerListeners();
|
504
|
+
},
|
505
|
+
checkForEscapeOrReturn: function(e) {
|
506
|
+
if (!this._editing || e.ctrlKey || e.altKey || e.shiftKey) return;
|
507
|
+
if (Event.KEY_ESC == e.keyCode)
|
508
|
+
this.handleFormCancellation(e);
|
509
|
+
else if (Event.KEY_RETURN == e.keyCode)
|
510
|
+
this.handleFormSubmission(e);
|
511
|
+
},
|
512
|
+
createControl: function(mode, handler, extraClasses) {
|
513
|
+
var control = this.options[mode + 'Control'];
|
514
|
+
var text = this.options[mode + 'Text'];
|
515
|
+
if ('button' == control) {
|
516
|
+
var btn = document.createElement('input');
|
517
|
+
btn.type = 'submit';
|
518
|
+
btn.value = text;
|
519
|
+
btn.className = 'editor_' + mode + '_button';
|
520
|
+
if ('cancel' == mode)
|
521
|
+
btn.onclick = this._boundCancelHandler;
|
522
|
+
this._form.appendChild(btn);
|
523
|
+
this._controls[mode] = btn;
|
524
|
+
} else if ('link' == control) {
|
525
|
+
var link = document.createElement('a');
|
526
|
+
link.href = '#';
|
527
|
+
link.appendChild(document.createTextNode(text));
|
528
|
+
link.onclick = 'cancel' == mode ? this._boundCancelHandler : this._boundSubmitHandler;
|
529
|
+
link.className = 'editor_' + mode + '_link';
|
530
|
+
if (extraClasses)
|
531
|
+
link.className += ' ' + extraClasses;
|
532
|
+
this._form.appendChild(link);
|
533
|
+
this._controls[mode] = link;
|
536
534
|
}
|
537
535
|
},
|
538
|
-
enterEditMode: function(evt) {
|
539
|
-
if (this.saving) return;
|
540
|
-
if (this.editing) return;
|
541
|
-
this.editing = true;
|
542
|
-
this.onEnterEditMode();
|
543
|
-
if (this.options.externalControl) {
|
544
|
-
Element.hide(this.options.externalControl);
|
545
|
-
}
|
546
|
-
Element.hide(this.element);
|
547
|
-
this.createForm();
|
548
|
-
this.element.parentNode.insertBefore(this.form, this.element);
|
549
|
-
if (!this.options.loadTextURL) Field.scrollFreeActivate(this.editField);
|
550
|
-
// stop the event to avoid a page refresh in Safari
|
551
|
-
if (evt) {
|
552
|
-
Event.stop(evt);
|
553
|
-
}
|
554
|
-
return false;
|
555
|
-
},
|
556
|
-
createForm: function() {
|
557
|
-
this.form = document.createElement("form");
|
558
|
-
this.form.id = this.options.formId;
|
559
|
-
Element.addClassName(this.form, this.options.formClassName)
|
560
|
-
this.form.onsubmit = this.onSubmit.bind(this);
|
561
|
-
|
562
|
-
this.createEditField();
|
563
|
-
|
564
|
-
if (this.options.textarea) {
|
565
|
-
var br = document.createElement("br");
|
566
|
-
this.form.appendChild(br);
|
567
|
-
}
|
568
|
-
|
569
|
-
if (this.options.okButton) {
|
570
|
-
okButton = document.createElement("input");
|
571
|
-
okButton.type = "submit";
|
572
|
-
okButton.value = this.options.okText;
|
573
|
-
okButton.className = 'editor_ok_button';
|
574
|
-
this.form.appendChild(okButton);
|
575
|
-
}
|
576
|
-
|
577
|
-
if (this.options.cancelLink) {
|
578
|
-
cancelLink = document.createElement("a");
|
579
|
-
cancelLink.href = "#";
|
580
|
-
cancelLink.appendChild(document.createTextNode(this.options.cancelText));
|
581
|
-
cancelLink.onclick = this.onclickCancel.bind(this);
|
582
|
-
cancelLink.className = 'editor_cancel';
|
583
|
-
this.form.appendChild(cancelLink);
|
584
|
-
}
|
585
|
-
},
|
586
|
-
hasHTMLLineBreaks: function(string) {
|
587
|
-
if (!this.options.handleLineBreaks) return false;
|
588
|
-
return string.match(/<br/i) || string.match(/<p>/i);
|
589
|
-
},
|
590
|
-
convertHTMLLineBreaks: function(string) {
|
591
|
-
return string.replace(/<br>/gi, "\n").replace(/<br\/>/gi, "\n").replace(/<\/p>/gi, "\n").replace(/<p>/gi, "");
|
592
|
-
},
|
593
536
|
createEditField: function() {
|
594
|
-
var text;
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
}
|
600
|
-
|
601
|
-
var obj = this;
|
602
|
-
|
603
|
-
if (this.options.rows == 1 && !this.hasHTMLLineBreaks(text)) {
|
604
|
-
this.options.textarea = false;
|
605
|
-
var textField = document.createElement("input");
|
606
|
-
textField.obj = this;
|
607
|
-
textField.type = "text";
|
608
|
-
textField.name = this.options.paramName;
|
609
|
-
textField.value = text;
|
610
|
-
textField.style.backgroundColor = this.options.highlightcolor;
|
611
|
-
textField.className = 'editor_field';
|
537
|
+
var text = (this.options.loadTextURL ? this.options.loadingText : this.getText());
|
538
|
+
var fld;
|
539
|
+
if (1 >= this.options.rows && !/\r|\n/.test(this.getText())) {
|
540
|
+
fld = document.createElement('input');
|
541
|
+
fld.type = 'text';
|
612
542
|
var size = this.options.size || this.options.cols || 0;
|
613
|
-
if (
|
614
|
-
if (this.options.submitOnBlur)
|
615
|
-
textField.onblur = this.onSubmit.bind(this);
|
616
|
-
this.editField = textField;
|
543
|
+
if (0 < size) fld.size = size;
|
617
544
|
} else {
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
textArea.name = this.options.paramName;
|
622
|
-
textArea.value = this.convertHTMLLineBreaks(text);
|
623
|
-
textArea.rows = this.options.rows;
|
624
|
-
textArea.cols = this.options.cols || 40;
|
625
|
-
textArea.className = 'editor_field';
|
626
|
-
if (this.options.submitOnBlur)
|
627
|
-
textArea.onblur = this.onSubmit.bind(this);
|
628
|
-
this.editField = textArea;
|
545
|
+
fld = document.createElement('textarea');
|
546
|
+
fld.rows = (1 >= this.options.rows ? this.options.autoRows : this.options.rows);
|
547
|
+
fld.cols = this.options.cols || 40;
|
629
548
|
}
|
630
|
-
|
631
|
-
|
549
|
+
fld.name = this.options.paramName;
|
550
|
+
fld.value = text; // No HTML breaks conversion anymore
|
551
|
+
fld.className = 'editor_field';
|
552
|
+
if (this.options.submitOnBlur)
|
553
|
+
fld.onblur = this._boundSubmitHandler;
|
554
|
+
this._controls.editor = fld;
|
555
|
+
if (this.options.loadTextURL)
|
632
556
|
this.loadExternalText();
|
633
|
-
|
634
|
-
|
557
|
+
this._form.appendChild(this._controls.editor);
|
558
|
+
},
|
559
|
+
createForm: function() {
|
560
|
+
var ipe = this;
|
561
|
+
function addText(mode, condition) {
|
562
|
+
var text = ipe.options['text' + mode + 'Controls'];
|
563
|
+
if (!text || condition === false) return;
|
564
|
+
ipe._form.appendChild(document.createTextNode(text));
|
565
|
+
};
|
566
|
+
this._form = $(document.createElement('form'));
|
567
|
+
this._form.id = this.options.formId;
|
568
|
+
this._form.addClassName(this.options.formClassName);
|
569
|
+
this._form.onsubmit = this._boundSubmitHandler;
|
570
|
+
this.createEditField();
|
571
|
+
if ('textarea' == this._controls.editor.tagName.toLowerCase())
|
572
|
+
this._form.appendChild(document.createElement('br'));
|
573
|
+
if (this.options.onFormCustomization)
|
574
|
+
this.options.onFormCustomization(this, this._form);
|
575
|
+
addText('Before', this.options.okControl || this.options.cancelControl);
|
576
|
+
this.createControl('ok', this._boundSubmitHandler);
|
577
|
+
addText('Between', this.options.okControl && this.options.cancelControl);
|
578
|
+
this.createControl('cancel', this._boundCancelHandler, 'editor_cancel');
|
579
|
+
addText('After', this.options.okControl || this.options.cancelControl);
|
580
|
+
},
|
581
|
+
destroy: function() {
|
582
|
+
if (this._oldInnerHTML)
|
583
|
+
this.element.innerHTML = this._oldInnerHTML;
|
584
|
+
this.leaveEditMode();
|
585
|
+
this.unregisterListeners();
|
586
|
+
},
|
587
|
+
enterEditMode: function(e) {
|
588
|
+
if (this._saving || this._editing) return;
|
589
|
+
this._editing = true;
|
590
|
+
this.triggerCallback('onEnterEditMode');
|
591
|
+
if (this.options.externalControl)
|
592
|
+
this.options.externalControl.hide();
|
593
|
+
this.element.hide();
|
594
|
+
this.createForm();
|
595
|
+
this.element.parentNode.insertBefore(this._form, this.element);
|
596
|
+
if (!this.options.loadTextURL)
|
597
|
+
this.postProcessEditField();
|
598
|
+
if (e) Event.stop(e);
|
599
|
+
},
|
600
|
+
enterHover: function(e) {
|
601
|
+
if (this.options.hoverClassName)
|
602
|
+
this.element.addClassName(this.options.hoverClassName);
|
603
|
+
if (this._saving) return;
|
604
|
+
this.triggerCallback('onEnterHover');
|
635
605
|
},
|
636
606
|
getText: function() {
|
637
607
|
return this.element.innerHTML;
|
638
608
|
},
|
639
|
-
|
640
|
-
|
641
|
-
this.
|
642
|
-
|
643
|
-
this.
|
644
|
-
Object.extend({
|
645
|
-
asynchronous: true,
|
646
|
-
onComplete: this.onLoadedExternalText.bind(this)
|
647
|
-
}, this.options.ajaxOptions)
|
648
|
-
);
|
649
|
-
},
|
650
|
-
onLoadedExternalText: function(transport) {
|
651
|
-
Element.removeClassName(this.form, this.options.loadingClassName);
|
652
|
-
this.editField.disabled = false;
|
653
|
-
this.editField.value = transport.responseText.stripTags();
|
654
|
-
Field.scrollFreeActivate(this.editField);
|
655
|
-
},
|
656
|
-
onclickCancel: function() {
|
657
|
-
this.onComplete();
|
658
|
-
this.leaveEditMode();
|
659
|
-
return false;
|
660
|
-
},
|
661
|
-
onFailure: function(transport) {
|
662
|
-
this.options.onFailure(transport);
|
663
|
-
if (this.oldInnerHTML) {
|
664
|
-
this.element.innerHTML = this.oldInnerHTML;
|
665
|
-
this.oldInnerHTML = null;
|
609
|
+
handleAJAXFailure: function(transport) {
|
610
|
+
this.triggerCallback('onFailure', transport);
|
611
|
+
if (this._oldInnerHTML) {
|
612
|
+
this.element.innerHTML = this._oldInnerHTML;
|
613
|
+
this._oldInnerHTML = null;
|
666
614
|
}
|
667
|
-
return false;
|
668
615
|
},
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
this.
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
this.
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
}, this.options.ajaxOptions));
|
698
|
-
}
|
699
|
-
// stop the event to avoid a page refresh in Safari
|
700
|
-
if (arguments.length > 1) {
|
701
|
-
Event.stop(arguments[0]);
|
616
|
+
handleFormCancellation: function(e) {
|
617
|
+
this.wrapUp();
|
618
|
+
if (e) Event.stop(e);
|
619
|
+
},
|
620
|
+
handleFormSubmission: function(e) {
|
621
|
+
var form = this._form;
|
622
|
+
var value = $F(this._controls.editor);
|
623
|
+
this.prepareSubmission();
|
624
|
+
var params = this.options.callback(form, value) || '';
|
625
|
+
if (Object.isString(params))
|
626
|
+
params = params.toQueryParams();
|
627
|
+
params.editorId = this.element.id;
|
628
|
+
if (this.options.htmlResponse) {
|
629
|
+
var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
|
630
|
+
Object.extend(options, {
|
631
|
+
parameters: params,
|
632
|
+
onComplete: this._boundWrapperHandler,
|
633
|
+
onFailure: this._boundFailureHandler
|
634
|
+
});
|
635
|
+
new Ajax.Updater({ success: this.element }, this.url, options);
|
636
|
+
} else {
|
637
|
+
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
|
638
|
+
Object.extend(options, {
|
639
|
+
parameters: params,
|
640
|
+
onComplete: this._boundWrapperHandler,
|
641
|
+
onFailure: this._boundFailureHandler
|
642
|
+
});
|
643
|
+
new Ajax.Request(this.url, options);
|
702
644
|
}
|
703
|
-
|
645
|
+
if (e) Event.stop(e);
|
646
|
+
},
|
647
|
+
leaveEditMode: function() {
|
648
|
+
this.element.removeClassName(this.options.savingClassName);
|
649
|
+
this.removeForm();
|
650
|
+
this.leaveHover();
|
651
|
+
this.element.style.backgroundColor = this._originalBackground;
|
652
|
+
this.element.show();
|
653
|
+
if (this.options.externalControl)
|
654
|
+
this.options.externalControl.show();
|
655
|
+
this._saving = false;
|
656
|
+
this._editing = false;
|
657
|
+
this._oldInnerHTML = null;
|
658
|
+
this.triggerCallback('onLeaveEditMode');
|
659
|
+
},
|
660
|
+
leaveHover: function(e) {
|
661
|
+
if (this.options.hoverClassName)
|
662
|
+
this.element.removeClassName(this.options.hoverClassName);
|
663
|
+
if (this._saving) return;
|
664
|
+
this.triggerCallback('onLeaveHover');
|
704
665
|
},
|
705
|
-
|
706
|
-
this.
|
666
|
+
loadExternalText: function() {
|
667
|
+
this._form.addClassName(this.options.loadingClassName);
|
668
|
+
this._controls.editor.disabled = true;
|
669
|
+
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
|
670
|
+
Object.extend(options, {
|
671
|
+
parameters: 'editorId=' + encodeURIComponent(this.element.id),
|
672
|
+
onComplete: Prototype.emptyFunction,
|
673
|
+
onSuccess: function(transport) {
|
674
|
+
this._form.removeClassName(this.options.loadingClassName);
|
675
|
+
var text = transport.responseText;
|
676
|
+
if (this.options.stripLoadedTextTags)
|
677
|
+
text = text.stripTags();
|
678
|
+
this._controls.editor.value = text;
|
679
|
+
this._controls.editor.disabled = false;
|
680
|
+
this.postProcessEditField();
|
681
|
+
}.bind(this),
|
682
|
+
onFailure: this._boundFailureHandler
|
683
|
+
});
|
684
|
+
new Ajax.Request(this.options.loadTextURL, options);
|
685
|
+
},
|
686
|
+
postProcessEditField: function() {
|
687
|
+
var fpc = this.options.fieldPostCreation;
|
688
|
+
if (fpc)
|
689
|
+
$(this._controls.editor)['focus' == fpc ? 'focus' : 'activate']();
|
690
|
+
},
|
691
|
+
prepareOptions: function() {
|
692
|
+
this.options = Object.clone(Ajax.InPlaceEditor.DefaultOptions);
|
693
|
+
Object.extend(this.options, Ajax.InPlaceEditor.DefaultCallbacks);
|
694
|
+
[this._extraDefaultOptions].flatten().compact().each(function(defs) {
|
695
|
+
Object.extend(this.options, defs);
|
696
|
+
}.bind(this));
|
697
|
+
},
|
698
|
+
prepareSubmission: function() {
|
699
|
+
this._saving = true;
|
707
700
|
this.removeForm();
|
708
701
|
this.leaveHover();
|
709
702
|
this.showSaving();
|
710
703
|
},
|
704
|
+
registerListeners: function() {
|
705
|
+
this._listeners = { };
|
706
|
+
var listener;
|
707
|
+
$H(Ajax.InPlaceEditor.Listeners).each(function(pair) {
|
708
|
+
listener = this[pair.value].bind(this);
|
709
|
+
this._listeners[pair.key] = listener;
|
710
|
+
if (!this.options.externalControlOnly)
|
711
|
+
this.element.observe(pair.key, listener);
|
712
|
+
if (this.options.externalControl)
|
713
|
+
this.options.externalControl.observe(pair.key, listener);
|
714
|
+
}.bind(this));
|
715
|
+
},
|
716
|
+
removeForm: function() {
|
717
|
+
if (!this._form) return;
|
718
|
+
this._form.remove();
|
719
|
+
this._form = null;
|
720
|
+
this._controls = { };
|
721
|
+
},
|
711
722
|
showSaving: function() {
|
712
|
-
this.
|
723
|
+
this._oldInnerHTML = this.element.innerHTML;
|
713
724
|
this.element.innerHTML = this.options.savingText;
|
714
|
-
|
715
|
-
this.element.style.backgroundColor = this.
|
716
|
-
|
725
|
+
this.element.addClassName(this.options.savingClassName);
|
726
|
+
this.element.style.backgroundColor = this._originalBackground;
|
727
|
+
this.element.show();
|
717
728
|
},
|
718
|
-
|
719
|
-
if(this.
|
720
|
-
|
721
|
-
this.form = null;
|
729
|
+
triggerCallback: function(cbName, arg) {
|
730
|
+
if ('function' == typeof this.options[cbName]) {
|
731
|
+
this.options[cbName](this, arg);
|
722
732
|
}
|
723
733
|
},
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
this.
|
729
|
-
|
730
|
-
|
734
|
+
unregisterListeners: function() {
|
735
|
+
$H(this._listeners).each(function(pair) {
|
736
|
+
if (!this.options.externalControlOnly)
|
737
|
+
this.element.stopObserving(pair.key, pair.value);
|
738
|
+
if (this.options.externalControl)
|
739
|
+
this.options.externalControl.stopObserving(pair.key, pair.value);
|
740
|
+
}.bind(this));
|
731
741
|
},
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
+
wrapUp: function(transport) {
|
743
|
+
this.leaveEditMode();
|
744
|
+
// Can't use triggerCallback due to backward compatibility: requires
|
745
|
+
// binding + direct element
|
746
|
+
this._boundComplete(transport, this.element);
|
747
|
+
}
|
748
|
+
});
|
749
|
+
|
750
|
+
Object.extend(Ajax.InPlaceEditor.prototype, {
|
751
|
+
dispose: Ajax.InPlaceEditor.prototype.destroy
|
752
|
+
});
|
753
|
+
|
754
|
+
Ajax.InPlaceCollectionEditor = Class.create(Ajax.InPlaceEditor, {
|
755
|
+
initialize: function($super, element, url, options) {
|
756
|
+
this._extraDefaultOptions = Ajax.InPlaceCollectionEditor.DefaultOptions;
|
757
|
+
$super(element, url, options);
|
758
|
+
},
|
759
|
+
|
760
|
+
createEditField: function() {
|
761
|
+
var list = document.createElement('select');
|
762
|
+
list.name = this.options.paramName;
|
763
|
+
list.size = 1;
|
764
|
+
this._controls.editor = list;
|
765
|
+
this._collection = this.options.collection || [];
|
766
|
+
if (this.options.loadCollectionURL)
|
767
|
+
this.loadCollection();
|
768
|
+
else
|
769
|
+
this.checkForExternalText();
|
770
|
+
this._form.appendChild(this._controls.editor);
|
771
|
+
},
|
772
|
+
|
773
|
+
loadCollection: function() {
|
774
|
+
this._form.addClassName(this.options.loadingClassName);
|
775
|
+
this.showLoadingText(this.options.loadingCollectionText);
|
776
|
+
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
|
777
|
+
Object.extend(options, {
|
778
|
+
parameters: 'editorId=' + encodeURIComponent(this.element.id),
|
779
|
+
onComplete: Prototype.emptyFunction,
|
780
|
+
onSuccess: function(transport) {
|
781
|
+
var js = transport.responseText.strip();
|
782
|
+
if (!/^\[.*\]$/.test(js)) // TODO: improve sanity check
|
783
|
+
throw 'Server returned an invalid collection representation.';
|
784
|
+
this._collection = eval(js);
|
785
|
+
this.checkForExternalText();
|
786
|
+
}.bind(this),
|
787
|
+
onFailure: this.onFailure
|
742
788
|
});
|
789
|
+
new Ajax.Request(this.options.loadCollectionURL, options);
|
743
790
|
},
|
744
|
-
|
745
|
-
|
746
|
-
this.
|
747
|
-
this.
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
791
|
+
|
792
|
+
showLoadingText: function(text) {
|
793
|
+
this._controls.editor.disabled = true;
|
794
|
+
var tempOption = this._controls.editor.firstChild;
|
795
|
+
if (!tempOption) {
|
796
|
+
tempOption = document.createElement('option');
|
797
|
+
tempOption.value = '';
|
798
|
+
this._controls.editor.appendChild(tempOption);
|
799
|
+
tempOption.selected = true;
|
752
800
|
}
|
753
|
-
|
754
|
-
this.saving = false;
|
755
|
-
this.oldInnerHTML = null;
|
756
|
-
this.onLeaveEditMode();
|
801
|
+
tempOption.update((text || '').stripScripts().stripTags());
|
757
802
|
},
|
758
|
-
|
759
|
-
|
760
|
-
this.
|
803
|
+
|
804
|
+
checkForExternalText: function() {
|
805
|
+
this._text = this.getText();
|
806
|
+
if (this.options.loadTextURL)
|
807
|
+
this.loadExternalText();
|
808
|
+
else
|
809
|
+
this.buildOptionList();
|
761
810
|
},
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
811
|
+
|
812
|
+
loadExternalText: function() {
|
813
|
+
this.showLoadingText(this.options.loadingText);
|
814
|
+
var options = Object.extend({ method: 'get' }, this.options.ajaxOptions);
|
815
|
+
Object.extend(options, {
|
816
|
+
parameters: 'editorId=' + encodeURIComponent(this.element.id),
|
817
|
+
onComplete: Prototype.emptyFunction,
|
818
|
+
onSuccess: function(transport) {
|
819
|
+
this._text = transport.responseText.strip();
|
820
|
+
this.buildOptionList();
|
821
|
+
}.bind(this),
|
822
|
+
onFailure: this.onFailure
|
823
|
+
});
|
824
|
+
new Ajax.Request(this.options.loadTextURL, options);
|
825
|
+
},
|
826
|
+
|
827
|
+
buildOptionList: function() {
|
828
|
+
this._form.removeClassName(this.options.loadingClassName);
|
829
|
+
this._collection = this._collection.map(function(entry) {
|
830
|
+
return 2 === entry.length ? entry : [entry, entry].flatten();
|
831
|
+
});
|
832
|
+
var marker = ('value' in this.options) ? this.options.value : this._text;
|
833
|
+
var textFound = this._collection.any(function(entry) {
|
834
|
+
return entry[0] == marker;
|
835
|
+
}.bind(this));
|
836
|
+
this._controls.editor.update('');
|
837
|
+
var option;
|
838
|
+
this._collection.each(function(entry, index) {
|
839
|
+
option = document.createElement('option');
|
840
|
+
option.value = entry[0];
|
841
|
+
option.selected = textFound ? entry[0] == marker : 0 == index;
|
842
|
+
option.appendChild(document.createTextNode(entry[1]));
|
843
|
+
this._controls.editor.appendChild(option);
|
844
|
+
}.bind(this));
|
845
|
+
this._controls.editor.disabled = false;
|
846
|
+
Field.scrollFreeActivate(this._controls.editor);
|
777
847
|
}
|
778
|
-
};
|
848
|
+
});
|
779
849
|
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
}
|
850
|
+
//**** DEPRECATION LAYER FOR InPlace[Collection]Editor! ****
|
851
|
+
//**** This only exists for a while, in order to let ****
|
852
|
+
//**** users adapt to the new API. Read up on the new ****
|
853
|
+
//**** API and convert your code to it ASAP! ****
|
854
|
+
|
855
|
+
Ajax.InPlaceEditor.prototype.initialize.dealWithDeprecatedOptions = function(options) {
|
856
|
+
if (!options) return;
|
857
|
+
function fallback(name, expr) {
|
858
|
+
if (name in options || expr === undefined) return;
|
859
|
+
options[name] = expr;
|
860
|
+
};
|
861
|
+
fallback('cancelControl', (options.cancelLink ? 'link' : (options.cancelButton ? 'button' :
|
862
|
+
options.cancelLink == options.cancelButton == false ? false : undefined)));
|
863
|
+
fallback('okControl', (options.okLink ? 'link' : (options.okButton ? 'button' :
|
864
|
+
options.okLink == options.okButton == false ? false : undefined)));
|
865
|
+
fallback('highlightColor', options.highlightcolor);
|
866
|
+
fallback('highlightEndColor', options.highlightendcolor);
|
867
|
+
};
|
799
868
|
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
869
|
+
Object.extend(Ajax.InPlaceEditor, {
|
870
|
+
DefaultOptions: {
|
871
|
+
ajaxOptions: { },
|
872
|
+
autoRows: 3, // Use when multi-line w/ rows == 1
|
873
|
+
cancelControl: 'link', // 'link'|'button'|false
|
874
|
+
cancelText: 'cancel',
|
875
|
+
clickToEditText: 'Click to edit',
|
876
|
+
externalControl: null, // id|elt
|
877
|
+
externalControlOnly: false,
|
878
|
+
fieldPostCreation: 'activate', // 'activate'|'focus'|false
|
879
|
+
formClassName: 'inplaceeditor-form',
|
880
|
+
formId: null, // id|elt
|
881
|
+
highlightColor: '#ffff99',
|
882
|
+
highlightEndColor: '#ffffff',
|
883
|
+
hoverClassName: '',
|
884
|
+
htmlResponse: true,
|
885
|
+
loadingClassName: 'inplaceeditor-loading',
|
886
|
+
loadingText: 'Loading...',
|
887
|
+
okControl: 'button', // 'link'|'button'|false
|
888
|
+
okText: 'ok',
|
889
|
+
paramName: 'value',
|
890
|
+
rows: 1, // If 1 and multi-line, uses autoRows
|
891
|
+
savingClassName: 'inplaceeditor-saving',
|
892
|
+
savingText: 'Saving...',
|
893
|
+
size: 0,
|
894
|
+
stripLoadedTextTags: false,
|
895
|
+
submitOnBlur: false,
|
896
|
+
textAfterControls: '',
|
897
|
+
textBeforeControls: '',
|
898
|
+
textBetweenControls: ''
|
899
|
+
},
|
900
|
+
DefaultCallbacks: {
|
901
|
+
callback: function(form) {
|
902
|
+
return Form.serialize(form);
|
903
|
+
},
|
904
|
+
onComplete: function(transport, element) {
|
905
|
+
// For backward compatibility, this one is bound to the IPE, and passes
|
906
|
+
// the element directly. It was too often customized, so we don't break it.
|
907
|
+
new Effect.Highlight(element, {
|
908
|
+
startcolor: this.options.highlightColor, keepBackgroundImage: true });
|
909
|
+
},
|
910
|
+
onEnterEditMode: null,
|
911
|
+
onEnterHover: function(ipe) {
|
912
|
+
ipe.element.style.backgroundColor = ipe.options.highlightColor;
|
913
|
+
if (ipe._effect)
|
914
|
+
ipe._effect.cancel();
|
915
|
+
},
|
916
|
+
onFailure: function(transport, ipe) {
|
917
|
+
alert('Error communication with the server: ' + transport.responseText.stripTags());
|
918
|
+
},
|
919
|
+
onFormCustomization: null, // Takes the IPE and its generated form, after editor, before controls.
|
920
|
+
onLeaveEditMode: null,
|
921
|
+
onLeaveHover: function(ipe) {
|
922
|
+
ipe._effect = new Effect.Highlight(ipe.element, {
|
923
|
+
startcolor: ipe.options.highlightColor, endcolor: ipe.options.highlightEndColor,
|
924
|
+
restorecolor: ipe._originalBackground, keepBackgroundImage: true
|
925
|
+
});
|
805
926
|
}
|
927
|
+
},
|
928
|
+
Listeners: {
|
929
|
+
click: 'enterEditMode',
|
930
|
+
keydown: 'checkForEscapeOrReturn',
|
931
|
+
mouseover: 'enterHover',
|
932
|
+
mouseout: 'leaveHover'
|
806
933
|
}
|
807
934
|
});
|
808
935
|
|
936
|
+
Ajax.InPlaceCollectionEditor.DefaultOptions = {
|
937
|
+
loadingCollectionText: 'Loading options...'
|
938
|
+
};
|
939
|
+
|
809
940
|
// Delayed observer, like Form.Element.Observer,
|
810
941
|
// but waits for delay after last key input
|
811
942
|
// Ideal for live-search fields
|
812
943
|
|
813
|
-
Form.Element.DelayedObserver = Class.create(
|
814
|
-
Form.Element.DelayedObserver.prototype = {
|
944
|
+
Form.Element.DelayedObserver = Class.create({
|
815
945
|
initialize: function(element, delay, callback) {
|
816
946
|
this.delay = delay || 0.5;
|
817
947
|
this.element = $(element);
|
@@ -830,4 +960,4 @@ Form.Element.DelayedObserver.prototype = {
|
|
830
960
|
this.timer = null;
|
831
961
|
this.callback(this.element, $F(this.element));
|
832
962
|
}
|
833
|
-
};
|
963
|
+
});
|