nimbleshop_core 0.0.1.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +13 -0
- data/Rakefile +15 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/american_express.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/authorize_net_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/authorizedotnet_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/discover.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/mastercard.png +0 -0
- data/app/assets/images/engines/nimbleshop_authorizedotnet/visa.png +0 -0
- data/app/assets/images/engines/nimbleshop_cod/cod_small.png +0 -0
- data/app/assets/images/engines/nimbleshop_paypalwp/paypal_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_paypalwp/paypal_small.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable_big.png +0 -0
- data/app/assets/images/engines/nimbleshop_splitable/splitable_small.png +0 -0
- data/app/assets/javascripts/admin/products/edit.js.coffee +19 -0
- data/app/assets/javascripts/admin/shipping_methods/edit.js.coffee +6 -0
- data/app/assets/javascripts/admin.js +25 -0
- data/app/assets/javascripts/fadeout_success.js.coffee +2 -0
- data/app/assets/javascripts/payment_method.js.coffee +19 -0
- data/app/assets/javascripts/product-group-condition.js.coffee +33 -0
- data/app/assets/javascripts/remove_deletion_of_product_pictures.js.coffee +5 -0
- data/app/assets/javascripts/shipit.js.coffee +10 -0
- data/app/assets/javascripts/twitter_bootstrap.js.coffee +4 -0
- data/app/assets/stylesheets/admin.css +9 -0
- data/app/assets/stylesheets/admin_bootstrap_and_overrides.css.less +38 -0
- data/app/assets/stylesheets/admin_custom.css +104 -0
- data/app/assets/twitter/bootstrap/glyphicons-halflings-white.png +0 -0
- data/app/assets/twitter/bootstrap/glyphicons-halflings.png +0 -0
- data/app/controllers/admin/custom_fields_controller.rb +56 -0
- data/app/controllers/admin/link_groups_controller.rb +76 -0
- data/app/controllers/admin/main_controller.rb +9 -0
- data/app/controllers/admin/navigations_controller.rb +49 -0
- data/app/controllers/admin/orders_controller.rb +47 -0
- data/app/controllers/admin/payment_methods_controller.rb +26 -0
- data/app/controllers/admin/product_groups_controller.rb +70 -0
- data/app/controllers/admin/products_controller.rb +71 -0
- data/app/controllers/admin/shipments_controller.rb +19 -0
- data/app/controllers/admin/shipping_methods_controller.rb +93 -0
- data/app/controllers/admin/shipping_zones_controller.rb +62 -0
- data/app/controllers/admin/shops_controller.rb +33 -0
- data/app/controllers/admin_controller.rb +38 -0
- data/app/helpers/admin_helper.rb +83 -0
- data/app/helpers/nimbleshop_helper.rb +43 -0
- data/app/helpers/payment_method_helper.rb +52 -0
- data/app/mailers/admin_mailer.rb +22 -0
- data/app/mailers/mailer.rb +31 -0
- data/app/models/address.rb +69 -0
- data/app/models/country_shipping_zone.rb +36 -0
- data/app/models/creditcard.rb +95 -0
- data/app/models/custom_field.rb +8 -0
- data/app/models/custom_field_answer/field.rb +101 -0
- data/app/models/custom_field_answer.rb +17 -0
- data/app/models/line_item.rb +48 -0
- data/app/models/link.rb +3 -0
- data/app/models/link_group.rb +8 -0
- data/app/models/navigation.rb +7 -0
- data/app/models/order.rb +158 -0
- data/app/models/payment_method.rb +20 -0
- data/app/models/payment_transaction.rb +11 -0
- data/app/models/picture.rb +30 -0
- data/app/models/product.rb +76 -0
- data/app/models/product_group.rb +65 -0
- data/app/models/product_group_condition.rb +8 -0
- data/app/models/regional_shipping_zone.rb +25 -0
- data/app/models/shipment.rb +19 -0
- data/app/models/shipment_carrier.rb +3 -0
- data/app/models/shipping_cost_calculator.rb +9 -0
- data/app/models/shipping_method.rb +103 -0
- data/app/models/shipping_zone.rb +9 -0
- data/app/models/shop.rb +26 -0
- data/app/models/tax_calculator.rb +18 -0
- data/app/observers/order_observer.rb +53 -0
- data/app/uploaders/picture_uploader.rb +65 -0
- data/app/views/admin/custom_fields/_form.html.erb +45 -0
- data/app/views/admin/custom_fields/edit.html.erb +7 -0
- data/app/views/admin/custom_fields/index.html.erb +31 -0
- data/app/views/admin/custom_fields/new.html.erb +7 -0
- data/app/views/admin/link_groups/_form.html.erb +31 -0
- data/app/views/admin/link_groups/_link_group.html.erb +50 -0
- data/app/views/admin/link_groups/_link_group_title.html.erb +5 -0
- data/app/views/admin/link_groups/edit.html.erb +8 -0
- data/app/views/admin/link_groups/index.html.erb +29 -0
- data/app/views/admin/link_groups/new.html.erb +9 -0
- data/app/views/admin/mailer/new_order_notification.text.erb +31 -0
- data/app/views/admin/main/index.html.erb +5 -0
- data/app/views/admin/navigations/new.html.erb +29 -0
- data/app/views/admin/orders/_line_item.html.erb +11 -0
- data/app/views/admin/orders/_line_items.html.erb +39 -0
- data/app/views/admin/orders/_payment_info.html.erb +20 -0
- data/app/views/admin/orders/_shipping_info.html.erb +40 -0
- data/app/views/admin/orders/index.html.erb +33 -0
- data/app/views/admin/orders/show.html.erb +40 -0
- data/app/views/admin/payment_methods/index.html.erb +6 -0
- data/app/views/admin/product_groups/_condition.html.mustache +20 -0
- data/app/views/admin/product_groups/_form.html.erb +72 -0
- data/app/views/admin/product_groups/edit.html.erb +7 -0
- data/app/views/admin/product_groups/index.html.erb +30 -0
- data/app/views/admin/product_groups/new.html.erb +7 -0
- data/app/views/admin/product_groups/show.html.erb +9 -0
- data/app/views/admin/products/_custom_field_answer.html.erb +9 -0
- data/app/views/admin/products/_form.html.erb +69 -0
- data/app/views/admin/products/_handle_pictures.html.erb +32 -0
- data/app/views/admin/products/_pictures.html.erb +33 -0
- data/app/views/admin/products/edit.html.erb +26 -0
- data/app/views/admin/products/index.html.erb +34 -0
- data/app/views/admin/products/new.html.erb +9 -0
- data/app/views/admin/shipping_methods/_form.html.erb +58 -0
- data/app/views/admin/shipping_methods/_shipping_method.html.erb +31 -0
- data/app/views/admin/shipping_methods/edit.html.erb +18 -0
- data/app/views/admin/shipping_methods/new.html.erb +7 -0
- data/app/views/admin/shipping_zones/_form.html.erb +31 -0
- data/app/views/admin/shipping_zones/_shipping_method.html.erb +13 -0
- data/app/views/admin/shipping_zones/_shipping_zone.html.erb +47 -0
- data/app/views/admin/shipping_zones/edit.html.erb +8 -0
- data/app/views/admin/shipping_zones/index.html.erb +16 -0
- data/app/views/admin/shipping_zones/new.html.erb +8 -0
- data/app/views/admin/shops/edit.html.erb +119 -0
- data/app/views/layouts/_admin_footer.html.erb +23 -0
- data/app/views/layouts/_admin_sidebar.html.erb +0 -0
- data/app/views/layouts/_container.html.erb +33 -0
- data/app/views/layouts/_top_nav_bar.html.erb +30 -0
- data/app/views/layouts/admin.html.erb +35 -0
- data/app/views/layouts/payment_method.html.erb +12 -0
- data/app/views/mailer/order_notification_to_buyer.text.erb +31 -0
- data/app/views/mailer/shipment_notification_to_buyer.text.erb +34 -0
- data/config/initializers/001_settings_application.rb +10 -0
- data/config/initializers/002_load_core_extensions.rb +8 -0
- data/config/initializers/field_with_error.rb +2 -0
- data/config/initializers/strip_and_nullify.rb +13 -0
- data/config/initializers/time_formats.rb +1 -0
- data/config/locales/en.yml +61 -0
- data/config/routes.rb +56 -0
- data/db/development.sqlite3 +0 -0
- data/db/migrate/20111022144421_create_product_groups.rb +12 -0
- data/db/migrate/20111022144426_create_products.rb +16 -0
- data/db/migrate/20111022144653_create_orders.rb +21 -0
- data/db/migrate/20111022144725_create_line_items.rb +15 -0
- data/db/migrate/20111022234951_create_shops.rb +20 -0
- data/db/migrate/20111026193227_create_link_groups.rb +12 -0
- data/db/migrate/20111026193435_create_navigations.rb +10 -0
- data/db/migrate/20111031135810_create_links.rb +10 -0
- data/db/migrate/20111106193938_create_custom_fields.rb +10 -0
- data/db/migrate/20111106195112_create_custom_field_answers.rb +14 -0
- data/db/migrate/20111106201548_create_product_group_conditions.rb +12 -0
- data/db/migrate/20111107035350_create_creditcard_transactions.rb +15 -0
- data/db/migrate/20111109190754_create_addresses.rb +24 -0
- data/db/migrate/20111125173344_create_pictures.rb +16 -0
- data/db/migrate/20111201024408_create_shipping_methods.rb +16 -0
- data/db/migrate/20111202143154_create_shipping_zones.rb +17 -0
- data/db/migrate/20111203034020_create_payment_methods.rb +14 -0
- data/db/migrate/20111221190000_create_preferences.rb +14 -0
- data/db/migrate/20120105234047_create_shipments.rb +11 -0
- data/db/migrate/20120105234553_create_shipment_carriers.rb +11 -0
- data/db/migrate/20120606165355_create_delayed_jobs.rb +22 -0
- data/db/production.sqlite3 +0 -0
- data/db/schema.rb +265 -0
- data/db/seeds.rb +1 -0
- data/db/test.sqlite3 +0 -0
- data/lib/assets/javascripts/loading_state_for_buttons.js.coffee +3 -0
- data/lib/assets/javascripts/show_help_on_hover.js.coffee +2 -0
- data/lib/assets/javascripts/utils/autoresize.js.coffee +3 -0
- data/lib/assets/javascripts/utils/focus.js.coffee +3 -0
- data/lib/assets/javascripts/utils/formatNumber.js.coffee +25 -0
- data/lib/assets/javascripts/utils/formatPrice.js.coffee +24 -0
- data/lib/generators/nimbleshop/app/app_generator.rb +84 -0
- data/lib/generators/nimbleshop/app/templates/config/application.yml +61 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/airbrake.rb +3 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/cache_images.rb +4 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/carrierwave.rb +36 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/delayed_job.rb +15 -0
- data/lib/generators/nimbleshop/app/templates/config/initializers/setup_email.rb +24 -0
- data/lib/nimbleshop/core_ext/activerecord_base.rb +18 -0
- data/lib/nimbleshop/core_ext/filelessio.rb +4 -0
- data/lib/nimbleshop/core_ext/force_ssl.rb +26 -0
- data/lib/nimbleshop/core_ext/mustache_templater_handler.rb +10 -0
- data/lib/nimbleshop/engine.rb +23 -0
- data/lib/nimbleshop/permalink/builder.rb +46 -0
- data/lib/nimbleshop/processor/base.rb +51 -0
- data/lib/nimbleshop/processor.rb +3 -0
- data/lib/nimbleshop/product_group_search/base_field.rb +19 -0
- data/lib/nimbleshop/product_group_search/core_field_strategy.rb +31 -0
- data/lib/nimbleshop/product_group_search/custom_field_strategy.rb +39 -0
- data/lib/nimbleshop/product_group_search/date_field.rb +16 -0
- data/lib/nimbleshop/product_group_search/extension.rb +46 -0
- data/lib/nimbleshop/product_group_search/number_field.rb +17 -0
- data/lib/nimbleshop/product_group_search/text_field.rb +33 -0
- data/lib/nimbleshop/product_group_search.rb +74 -0
- data/lib/nimbleshop/sampledata/data.rb +246 -0
- data/lib/nimbleshop/sampledata/pictures/product1/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product2/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product2/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product3/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product4/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product4/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product5/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product5/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic10.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic11.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic12.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic13.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic14.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic15.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic16.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic17.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic6.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic7.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic8.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product6/pic9.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product7/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic2.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic3.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic4.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic5.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic6.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic7.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product8/pic8.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product9/pic1.jpg +0 -0
- data/lib/nimbleshop/sampledata/pictures/product9/pic2.jpg +0 -0
- data/lib/nimbleshop/util.rb +60 -0
- data/lib/nimbleshop/version.rb +18 -0
- data/lib/nimbleshop_core.rb +23 -0
- data/lib/tasks/localhost2public.rake +8 -0
- data/lib/tasks/setup.rake +26 -0
- data/test/factories/address_factory.rb +31 -0
- data/test/factories/creditcard_factory.rb +30 -0
- data/test/factories/custom_field_answer_factory.rb +6 -0
- data/test/factories/custom_field_factory.rb +21 -0
- data/test/factories/line_item_factory.rb +7 -0
- data/test/factories/link_factory.rb +6 -0
- data/test/factories/link_group_factory.rb +5 -0
- data/test/factories/navigation_factory.rb +6 -0
- data/test/factories/order_factory.rb +49 -0
- data/test/factories/payment_method_factory.rb +6 -0
- data/test/factories/payment_transaction_factory.rb +42 -0
- data/test/factories/picture_factory.rb +11 -0
- data/test/factories/product_group_condition_factory.rb +40 -0
- data/test/factories/product_group_factory.rb +5 -0
- data/test/factories/products_factory.rb +11 -0
- data/test/factories/shipment_carrier_factory.rb +6 -0
- data/test/factories/shipment_factory.rb +6 -0
- data/test/factories/shipping_method_factory.rb +15 -0
- data/test/factories/shipping_zone_factory.rb +5 -0
- data/test/factories/shop_factory.rb +8 -0
- data/test/fixtures/files/avatar.png +0 -0
- data/test/fixtures/link_groups.yml +13 -0
- data/test/fixtures/payment_methods.yml +39 -0
- data/test/fixtures/shops.yml +15 -0
- data/test/helpers/admin_helper_test.rb +37 -0
- data/test/helpers/nimbleshop_helper_test.rb +17 -0
- data/test/integration/admin/link_groups_acceptance_test.rb +39 -0
- data/test/integration/admin/orders_acceptance_test.rb +63 -0
- data/test/integration/admin/payment_methods_acceptance_test.rb +13 -0
- data/test/integration/admin/product_groups_acceptance_test.rb +89 -0
- data/test/integration/admin/products_acceptance_test.rb +105 -0
- data/test/integration/admin/shipping_methods_acceptance_test.rb +63 -0
- data/test/integration/admin/shipping_zones_acceptance_test.rb +16 -0
- data/test/integration/admin/shops_acceptance_test.rb +44 -0
- data/test/integration/checkout/cart_acceptance_test.rb +113 -0
- data/test/integration/checkout/payment_confirmation_acceptance_test.rb +24 -0
- data/test/integration/checkout/paypal_acceptance_test.rb +34 -0
- data/test/integration/checkout/shipping_address_acceptance_test.rb +91 -0
- data/test/integration/checkout/shipping_method_acceptance_test.rb +51 -0
- data/test/integration/homepage_acceptance_test.rb +24 -0
- data/test/integration/products_acceptance_test.rb +12 -0
- data/test/integration/static_pages_acceptance_test.rb +13 -0
- data/test/mailers/mailer_test.rb +25 -0
- data/test/rails_app/Gemfile +27 -0
- data/test/rails_app/Gemfile.lock +218 -0
- data/test/rails_app/Rakefile +10 -0
- data/test/rails_app/app/controllers/application_controller.rb +6 -0
- data/test/rails_app/app/helpers/application_helper.rb +3 -0
- data/test/rails_app/app/views/layouts/application.html.erb +10 -0
- data/test/rails_app/config/application.rb +25 -0
- data/test/rails_app/config/application.yml +61 -0
- data/test/rails_app/config/boot.rb +5 -0
- data/test/rails_app/config/database.yml +18 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +18 -0
- data/test/rails_app/config/environments/production.rb +33 -0
- data/test/rails_app/config/environments/test.rb +33 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/inflections.rb +2 -0
- data/test/rails_app/config/initializers/secret_token.rb +2 -0
- data/test/rails_app/config/routes.rb +10 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/development.sqlite3 +0 -0
- data/test/rails_app/db/migrate/20100401102949_create_tables.rb +74 -0
- data/test/rails_app/db/schema.rb +52 -0
- data/test/rails_app/log/development.log +94 -0
- data/test/rails_app/log/test.log +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/script/rails +10 -0
- data/test/support/address_test_helper.rb +24 -0
- data/test/support/checkout_test_helper.rb +40 -0
- data/test/support/dbify_sql_helper.rb +12 -0
- data/test/support/images/cookware.jpg +0 -0
- data/test/support/must_be_like.rb +24 -0
- data/test/support/shipping_method_test_helper.rb +5 -0
- data/test/support/wait_for_ajax.rb +4 -0
- data/test/test_helper.rb +65 -0
- data/test/unit/address_test.rb +33 -0
- data/test/unit/country_shipping_zone_test.rb +17 -0
- data/test/unit/creditcard_test.rb +33 -0
- data/test/unit/custom_field_answer/field_test.rb +93 -0
- data/test/unit/order_test.rb +70 -0
- data/test/unit/payment_method/authorizedotnet_test.rb +21 -0
- data/test/unit/payment_method/paypalwp_test.rb +17 -0
- data/test/unit/payment_method/splitable_test.rb +18 -0
- data/test/unit/picture_test.rb +24 -0
- data/test/unit/processor/authorize_net_test.rb +236 -0
- data/test/unit/processor/paypal_test.rb +40 -0
- data/test/unit/processor/splitable_test.rb +123 -0
- data/test/unit/product_group_condition_test.rb +188 -0
- data/test/unit/product_group_test.rb +109 -0
- data/test/unit/product_test.rb +60 -0
- data/test/unit/shipping_cost_calculator_test.rb +19 -0
- data/test/unit/shipping_method_test.rb +197 -0
- data/test/unit/shop_test.rb +11 -0
- data/test/unit/tax_calculator_test.rb +13 -0
- data/test/vcr_cassettes/authorize_net/authorize-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/authorize-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/capture-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/capture-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/purchase-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/purchase-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/refund-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/refund-success.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-authorize.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-failure.yml +38 -0
- data/test/vcr_cassettes/authorize_net/void-success.yml +38 -0
- data/test/vcr_cassettes/splitable/split-create-failure.yml +48 -0
- data/test/vcr_cassettes/splitable/split-create-success.yml +50 -0
- data/test/vcr_cassettes/splitable/split-draft-create-failure.yml +50 -0
- data/test/vcr_cassettes/splitable/split-draft-create-success.yml +50 -0
- data/vendor/assets/javascripts/accounting.js +406 -0
- data/vendor/assets/javascripts/autoresize.js +275 -0
- data/vendor/assets/javascripts/jquery-1.7.1.js +9267 -0
- data/vendor/assets/javascripts/jquery-form.js +980 -0
- data/vendor/assets/javascripts/jquery-json.js +193 -0
- data/vendor/assets/javascripts/jquery-ui-1.8.16.js +11768 -0
- data/vendor/assets/javascripts/jquery-ujs.js +374 -0
- data/vendor/assets/javascripts/mustache.js +436 -0
- data/vendor/assets/javascripts/nested_form.js +51 -0
- metadata +740 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* accounting.js javascript library v0.3.0
|
|
3
|
+
* http://josscrowcroft.github.com/accounting.js/
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2011 by Joss Crowcroft
|
|
6
|
+
* Licensed under GPL v3 | http://www.gnu.org/licenses/gpl-3.0.txt
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
(function(root, undefined) {
|
|
10
|
+
|
|
11
|
+
/* --- Setup --- */
|
|
12
|
+
|
|
13
|
+
// Create the local library object, to be exported or referenced globally later
|
|
14
|
+
var lib = {};
|
|
15
|
+
|
|
16
|
+
// Current version
|
|
17
|
+
lib.version = '0.3.0';
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
/* --- Exposed settings --- */
|
|
21
|
+
|
|
22
|
+
// The library's settings configuration object. Contains default parameters for
|
|
23
|
+
// currency and number formatting
|
|
24
|
+
lib.settings = {
|
|
25
|
+
currency: {
|
|
26
|
+
symbol : "$", // default currency symbol is '$'
|
|
27
|
+
format : "%s%v", // controls output: %s = symbol, %v = value (can be object, see docs)
|
|
28
|
+
decimal : ".", // decimal point separator
|
|
29
|
+
thousand : ",", // thousands separator
|
|
30
|
+
precision : 2, // decimal places
|
|
31
|
+
grouping : 3 // digit grouping (not implemented yet)
|
|
32
|
+
},
|
|
33
|
+
number: {
|
|
34
|
+
precision : 0, // default precision on numbers is 0
|
|
35
|
+
grouping : 3, // digit grouping (not implemented yet)
|
|
36
|
+
thousand : ",",
|
|
37
|
+
decimal : "."
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
/* --- Internal Helper Methods --- */
|
|
43
|
+
|
|
44
|
+
// Store reference to possibly-available ECMAScript 5 methods for later
|
|
45
|
+
var nativeMap = Array.prototype.map,
|
|
46
|
+
nativeIsArray = Array.isArray,
|
|
47
|
+
toString = Object.prototype.toString;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Tests whether supplied parameter is a string
|
|
51
|
+
* from underscore.js
|
|
52
|
+
*/
|
|
53
|
+
function isString(obj) {
|
|
54
|
+
return !!(obj === '' || (obj && obj.charCodeAt && obj.substr));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Tests whether supplied parameter is a string
|
|
59
|
+
* from underscore.js, delegates to ECMA5's native Array.isArray
|
|
60
|
+
*/
|
|
61
|
+
function isArray(obj) {
|
|
62
|
+
return nativeIsArray ? nativeIsArray(obj) : toString.call(obj) === '[object Array]';
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Tests whether supplied parameter is a true object
|
|
67
|
+
*/
|
|
68
|
+
function isObject(obj) {
|
|
69
|
+
return toString.call(obj) === '[object Object]';
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Extends an object with a defaults object, similar to underscore's _.defaults
|
|
74
|
+
*
|
|
75
|
+
* Used for abstracting parameter handling from API methods
|
|
76
|
+
*/
|
|
77
|
+
function defaults(object, defs) {
|
|
78
|
+
var key;
|
|
79
|
+
object = object || {};
|
|
80
|
+
defs = defs || {};
|
|
81
|
+
// Iterate over object non-prototype properties:
|
|
82
|
+
for (key in defs) {
|
|
83
|
+
if (defs.hasOwnProperty(key)) {
|
|
84
|
+
// Replace values with defaults only if undefined (allow empty/zero values):
|
|
85
|
+
if (object[key] == null) object[key] = defs[key];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return object;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Implementation of `Array.map()` for iteration loops
|
|
93
|
+
*
|
|
94
|
+
* Returns a new Array as a result of calling `iterator` on each array value.
|
|
95
|
+
* Defers to native Array.map if available
|
|
96
|
+
*/
|
|
97
|
+
function map(obj, iterator, context) {
|
|
98
|
+
var results = [], i, j;
|
|
99
|
+
|
|
100
|
+
if (!obj) return results;
|
|
101
|
+
|
|
102
|
+
// Use native .map method if it exists:
|
|
103
|
+
if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context);
|
|
104
|
+
|
|
105
|
+
// Fallback for native .map:
|
|
106
|
+
for (i = 0, j = obj.length; i < j; i++ ) {
|
|
107
|
+
results[i] = iterator.call(context, obj[i], i, obj);
|
|
108
|
+
}
|
|
109
|
+
return results;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Check and normalise the value of precision (must be positive integer)
|
|
114
|
+
*/
|
|
115
|
+
function checkPrecision(val, base) {
|
|
116
|
+
val = Math.round(Math.abs(val));
|
|
117
|
+
return isNaN(val)? base : val;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Parses a format string or object and returns format obj for use in rendering
|
|
123
|
+
*
|
|
124
|
+
* `format` is either a string with the default (positive) format, or object
|
|
125
|
+
* containing `pos` (required), `neg` and `zero` values (or a function returning
|
|
126
|
+
* either a string or object)
|
|
127
|
+
*
|
|
128
|
+
* Either string or format.pos must contain "%v" (value) to be valid
|
|
129
|
+
*/
|
|
130
|
+
function checkCurrencyFormat(format) {
|
|
131
|
+
var defaults = lib.settings.currency.format;
|
|
132
|
+
|
|
133
|
+
// Allow function as format parameter (should return string or object):
|
|
134
|
+
if ( typeof format === "function" ) format = format();
|
|
135
|
+
|
|
136
|
+
// Format can be a string, in which case `value` ("%v") must be present:
|
|
137
|
+
if ( isString( format ) && format.match("%v") ) {
|
|
138
|
+
|
|
139
|
+
// Create and return positive, negative and zero formats:
|
|
140
|
+
return {
|
|
141
|
+
pos : format,
|
|
142
|
+
neg : format.replace("-", "").replace("%v", "-%v"),
|
|
143
|
+
zero : format
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// If no format, or object is missing valid positive value, use defaults:
|
|
147
|
+
} else if ( !format || !format.pos || !format.pos.match("%v") ) {
|
|
148
|
+
|
|
149
|
+
// If defaults is a string, casts it to an object for faster checking next time:
|
|
150
|
+
return ( !isString( defaults ) ) ? defaults : lib.settings.currency.format = {
|
|
151
|
+
pos : defaults,
|
|
152
|
+
neg : defaults.replace("%v", "-%v"),
|
|
153
|
+
zero : defaults
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
}
|
|
157
|
+
// Otherwise, assume format was fine:
|
|
158
|
+
return format;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
/* --- API Methods --- */
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Takes a string/array of strings, removes all formatting/cruft and returns the raw float value
|
|
166
|
+
* alias: accounting.`parse(string)`
|
|
167
|
+
*
|
|
168
|
+
* Decimal must be included in the regular expression to match floats (default: "."), so if the number
|
|
169
|
+
* uses a non-standard decimal separator, provide it as the second argument.
|
|
170
|
+
*
|
|
171
|
+
* Also matches bracketed negatives (eg. "$ (1.99)" => -1.99)
|
|
172
|
+
*
|
|
173
|
+
* Doesn't throw any errors (`NaN`s become 0) but this may change in future
|
|
174
|
+
*/
|
|
175
|
+
var unformat = lib.unformat = lib.parse = function(value, decimal) {
|
|
176
|
+
// Recursively unformat arrays:
|
|
177
|
+
if (isArray(value)) {
|
|
178
|
+
return map(value, function(val) {
|
|
179
|
+
return unformat(val, decimal);
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// Fails silently (need decent errors):
|
|
184
|
+
value = value || 0;
|
|
185
|
+
|
|
186
|
+
// Return the value as-is if it's already a number:
|
|
187
|
+
if (typeof value === "number") return value;
|
|
188
|
+
|
|
189
|
+
// Default decimal point is "." but could be set to eg. "," in opts:
|
|
190
|
+
decimal = decimal || ".";
|
|
191
|
+
|
|
192
|
+
// Build regex to strip out everything except digits, decimal point and minus sign:
|
|
193
|
+
var regex = new RegExp("[^0-9-" + decimal + "]", ["g"]),
|
|
194
|
+
unformatted = parseFloat(
|
|
195
|
+
("" + value)
|
|
196
|
+
.replace(/\((.*)\)/, "-$1") // replace bracketed values with negatives
|
|
197
|
+
.replace(regex, '') // strip out any cruft
|
|
198
|
+
.replace(decimal, '.') // make sure decimal point is standard
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
// This will fail silently which may cause trouble, let's wait and see:
|
|
202
|
+
return !isNaN(unformatted) ? unformatted : 0;
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Implementation of toFixed() that treats floats more like decimals
|
|
208
|
+
*
|
|
209
|
+
* Fixes binary rounding issues (eg. (0.615).toFixed(2) === "0.61") that present
|
|
210
|
+
* problems for accounting- and finance-related software.
|
|
211
|
+
*/
|
|
212
|
+
var toFixed = lib.toFixed = function(value, precision) {
|
|
213
|
+
precision = checkPrecision(precision, lib.settings.number.precision);
|
|
214
|
+
var power = Math.pow(10, precision);
|
|
215
|
+
|
|
216
|
+
// Multiply up by precision, round accurately, then divide and use native toFixed():
|
|
217
|
+
return (Math.round(lib.unformat(value) * power) / power).toFixed(precision);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Format a number, with comma-separated thousands and custom precision/decimal places
|
|
223
|
+
*
|
|
224
|
+
* Localise by overriding the precision and thousand / decimal separators
|
|
225
|
+
* 2nd parameter `precision` can be an object matching `settings.number`
|
|
226
|
+
*/
|
|
227
|
+
var formatNumber = lib.formatNumber = function(number, precision, thousand, decimal) {
|
|
228
|
+
// Resursively format arrays:
|
|
229
|
+
if (isArray(number)) {
|
|
230
|
+
return map(number, function(val) {
|
|
231
|
+
return formatNumber(val, precision, thousand, decimal);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// Clean up number:
|
|
236
|
+
number = unformat(number);
|
|
237
|
+
|
|
238
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
|
239
|
+
var opts = defaults(
|
|
240
|
+
(isObject(precision) ? precision : {
|
|
241
|
+
precision : precision,
|
|
242
|
+
thousand : thousand,
|
|
243
|
+
decimal : decimal
|
|
244
|
+
}),
|
|
245
|
+
lib.settings.number
|
|
246
|
+
),
|
|
247
|
+
|
|
248
|
+
// Clean up precision
|
|
249
|
+
usePrecision = checkPrecision(opts.precision),
|
|
250
|
+
|
|
251
|
+
// Do some calc:
|
|
252
|
+
negative = number < 0 ? "-" : "",
|
|
253
|
+
base = parseInt(toFixed(Math.abs(number || 0), usePrecision), 10) + "",
|
|
254
|
+
mod = base.length > 3 ? base.length % 3 : 0;
|
|
255
|
+
|
|
256
|
+
// Format the number:
|
|
257
|
+
return negative + (mod ? base.substr(0, mod) + opts.thousand : "") + base.substr(mod).replace(/(\d{3})(?=\d)/g, "$1" + opts.thousand) + (usePrecision ? opts.decimal + toFixed(Math.abs(number), usePrecision).split('.')[1] : "");
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Format a number into currency
|
|
263
|
+
*
|
|
264
|
+
* Usage: accounting.formatMoney(number, precision, symbol, thousandsSep, decimalSep, format)
|
|
265
|
+
* defaults: (0, 2, "$", ",", ".", "%s%v")
|
|
266
|
+
*
|
|
267
|
+
* Localise by overriding the symbol, precision, thousand / decimal separators and format
|
|
268
|
+
* Second param can be an object matching `settings.currency` which is the easiest way.
|
|
269
|
+
*
|
|
270
|
+
* To do: tidy up the parameters
|
|
271
|
+
*/
|
|
272
|
+
var formatMoney = lib.formatMoney = function(number, symbol, precision, thousand, decimal, format) {
|
|
273
|
+
// Resursively format arrays:
|
|
274
|
+
if (isArray(number)) {
|
|
275
|
+
return map(number, function(val){
|
|
276
|
+
return formatMoney(val, symbol, precision, thousand, decimal, format);
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Clean up number:
|
|
281
|
+
number = unformat(number);
|
|
282
|
+
|
|
283
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
|
284
|
+
var opts = defaults(
|
|
285
|
+
(isObject(symbol) ? symbol : {
|
|
286
|
+
symbol : symbol,
|
|
287
|
+
precision : precision,
|
|
288
|
+
thousand : thousand,
|
|
289
|
+
decimal : decimal,
|
|
290
|
+
format : format
|
|
291
|
+
}),
|
|
292
|
+
lib.settings.currency
|
|
293
|
+
),
|
|
294
|
+
|
|
295
|
+
// Check format (returns object with pos, neg and zero):
|
|
296
|
+
formats = checkCurrencyFormat(opts.format),
|
|
297
|
+
|
|
298
|
+
// Choose which format to use for this value:
|
|
299
|
+
useFormat = number > 0 ? formats.pos : number < 0 ? formats.neg : formats.zero;
|
|
300
|
+
|
|
301
|
+
// Return with currency symbol added:
|
|
302
|
+
return useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(number), checkPrecision(opts.precision), opts.thousand, opts.decimal));
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Format a list of numbers into an accounting column, padding with whitespace
|
|
308
|
+
* to line up currency symbols, thousand separators and decimals places
|
|
309
|
+
*
|
|
310
|
+
* List should be an array of numbers
|
|
311
|
+
* Second parameter can be an object containing keys that match the params
|
|
312
|
+
*
|
|
313
|
+
* Returns array of accouting-formatted number strings of same length
|
|
314
|
+
*
|
|
315
|
+
* NB: `white-space:pre` CSS rule is required on the list container to prevent
|
|
316
|
+
* browsers from collapsing the whitespace in the output strings.
|
|
317
|
+
*/
|
|
318
|
+
lib.formatColumn = function(list, symbol, precision, thousand, decimal, format) {
|
|
319
|
+
if (!list) return [];
|
|
320
|
+
|
|
321
|
+
// Build options object from second param (if object) or all params, extending defaults:
|
|
322
|
+
var opts = defaults(
|
|
323
|
+
(isObject(symbol) ? symbol : {
|
|
324
|
+
symbol : symbol,
|
|
325
|
+
precision : precision,
|
|
326
|
+
thousand : thousand,
|
|
327
|
+
decimal : decimal,
|
|
328
|
+
format : format
|
|
329
|
+
}),
|
|
330
|
+
lib.settings.currency
|
|
331
|
+
),
|
|
332
|
+
|
|
333
|
+
// Check format (returns object with pos, neg and zero), only need pos for now:
|
|
334
|
+
formats = checkCurrencyFormat(opts.format),
|
|
335
|
+
|
|
336
|
+
// Whether to pad at start of string or after currency symbol:
|
|
337
|
+
padAfterSymbol = formats.pos.indexOf("%s") < formats.pos.indexOf("%v") ? true : false,
|
|
338
|
+
|
|
339
|
+
// Store value for the length of the longest string in the column:
|
|
340
|
+
maxLength = 0,
|
|
341
|
+
|
|
342
|
+
// Format the list according to options, store the length of the longest string:
|
|
343
|
+
formatted = map(list, function(val, i) {
|
|
344
|
+
if (isArray(val)) {
|
|
345
|
+
// Recursively format columns if list is a multi-dimensional array:
|
|
346
|
+
return lib.formatColumn(val, opts);
|
|
347
|
+
} else {
|
|
348
|
+
// Clean up the value
|
|
349
|
+
val = unformat(val);
|
|
350
|
+
|
|
351
|
+
// Choose which format to use for this value (pos, neg or zero):
|
|
352
|
+
var useFormat = val > 0 ? formats.pos : val < 0 ? formats.neg : formats.zero,
|
|
353
|
+
|
|
354
|
+
// Format this value, push into formatted list and save the length:
|
|
355
|
+
fVal = useFormat.replace('%s', opts.symbol).replace('%v', formatNumber(Math.abs(val), checkPrecision(opts.precision), opts.thousand, opts.decimal));
|
|
356
|
+
|
|
357
|
+
if (fVal.length > maxLength) maxLength = fVal.length;
|
|
358
|
+
return fVal;
|
|
359
|
+
}
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// Pad each number in the list and send back the column of numbers:
|
|
363
|
+
return map(formatted, function(val, i) {
|
|
364
|
+
// Only if this is a string (not a nested array, which would have already been padded):
|
|
365
|
+
if (isString(val) && val.length < maxLength) {
|
|
366
|
+
// Depending on symbol position, pad after symbol or at index 0:
|
|
367
|
+
return padAfterSymbol ? val.replace(opts.symbol, opts.symbol+(new Array(maxLength - val.length + 1).join(" "))) : (new Array(maxLength - val.length + 1).join(" ")) + val;
|
|
368
|
+
}
|
|
369
|
+
return val;
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
/* --- Module Definition --- */
|
|
375
|
+
|
|
376
|
+
// Export accounting for CommonJS. If being loaded as an AMD module, define it as such.
|
|
377
|
+
// Otherwise, just add `accounting` to the global object
|
|
378
|
+
if (typeof module !== 'undefined' && module.exports) {
|
|
379
|
+
module.exports = lib;
|
|
380
|
+
lib.accounting = lib;
|
|
381
|
+
} else if (typeof define === 'function' && define.amd) {
|
|
382
|
+
// Return the library as an AMD module:
|
|
383
|
+
define([], function() {
|
|
384
|
+
return lib;
|
|
385
|
+
});
|
|
386
|
+
} else {
|
|
387
|
+
// Use accounting.noConflict to restore `accounting` back to its original value.
|
|
388
|
+
// Returns a reference to the library's `accounting` object;
|
|
389
|
+
// e.g. `var numbers = accounting.noConflict();`
|
|
390
|
+
lib.noConflict = (function(oldAccounting) {
|
|
391
|
+
return function() {
|
|
392
|
+
// Reset the value of the root's `accounting` variable:
|
|
393
|
+
root.accounting = oldAccounting;
|
|
394
|
+
// Delete the noConflict method:
|
|
395
|
+
lib.noConflict = undefined;
|
|
396
|
+
// Return reference to the library to re-assign it:
|
|
397
|
+
return lib;
|
|
398
|
+
};
|
|
399
|
+
})(root.accounting);
|
|
400
|
+
|
|
401
|
+
// Declare `fx` on the root (global/window) object:
|
|
402
|
+
root['accounting'] = lib;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// Root will be `window` in browser or `global` on the server:
|
|
406
|
+
}(this));
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* jQuery.fn.autoResize 1.14
|
|
3
|
+
* --
|
|
4
|
+
* https://github.com/padolsey/jQuery.fn.autoResize
|
|
5
|
+
* --
|
|
6
|
+
* This program is free software. It comes without any warranty, to
|
|
7
|
+
* the extent permitted by applicable law. You can redistribute it
|
|
8
|
+
* and/or modify it under the terms of the Do What The Fuck You Want
|
|
9
|
+
* To Public License, Version 2, as published by Sam Hocevar. See
|
|
10
|
+
* http://sam.zoy.org/wtfpl/COPYING for more details. */
|
|
11
|
+
|
|
12
|
+
(function($){
|
|
13
|
+
|
|
14
|
+
var uid = 'ar' + +new Date,
|
|
15
|
+
|
|
16
|
+
defaults = autoResize.defaults = {
|
|
17
|
+
onResize: function(){},
|
|
18
|
+
onBeforeResize: function(){return 123},
|
|
19
|
+
onAfterResize: function(){return 555},
|
|
20
|
+
animate: {
|
|
21
|
+
duration: 200,
|
|
22
|
+
complete: function(){}
|
|
23
|
+
},
|
|
24
|
+
extraSpace: 50,
|
|
25
|
+
minHeight: 'original',
|
|
26
|
+
maxHeight: 500,
|
|
27
|
+
minWidth: 'original',
|
|
28
|
+
maxWidth: 500
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
autoResize.cloneCSSProperties = [
|
|
32
|
+
'lineHeight', 'textDecoration', 'letterSpacing',
|
|
33
|
+
'fontSize', 'fontFamily', 'fontStyle', 'fontWeight',
|
|
34
|
+
'textTransform', 'textAlign', 'direction', 'wordSpacing', 'fontSizeAdjust',
|
|
35
|
+
'paddingTop', 'paddingLeft', 'paddingBottom', 'paddingRight', 'width'
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
autoResize.cloneCSSValues = {
|
|
39
|
+
position: 'absolute',
|
|
40
|
+
top: -9999,
|
|
41
|
+
left: -9999,
|
|
42
|
+
opacity: 0,
|
|
43
|
+
overflow: 'hidden'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
autoResize.resizableFilterSelector = [
|
|
47
|
+
'textarea:not(textarea.' + uid + ')',
|
|
48
|
+
'input:not(input[type])',
|
|
49
|
+
'input[type=text]',
|
|
50
|
+
'input[type=password]',
|
|
51
|
+
'input[type=email]',
|
|
52
|
+
'input[type=url]'
|
|
53
|
+
].join(',');
|
|
54
|
+
|
|
55
|
+
autoResize.AutoResizer = AutoResizer;
|
|
56
|
+
|
|
57
|
+
$.fn.autoResize = autoResize;
|
|
58
|
+
|
|
59
|
+
function autoResize(config) {
|
|
60
|
+
this.filter(autoResize.resizableFilterSelector).each(function(){
|
|
61
|
+
new AutoResizer( $(this), config );
|
|
62
|
+
});
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function AutoResizer(el, config) {
|
|
67
|
+
|
|
68
|
+
if (el.data('AutoResizer')) {
|
|
69
|
+
el.data('AutoResizer').destroy();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
config = this.config = $.extend(true, {}, autoResize.defaults, config);
|
|
73
|
+
this.el = el;
|
|
74
|
+
|
|
75
|
+
this.nodeName = el[0].nodeName.toLowerCase();
|
|
76
|
+
|
|
77
|
+
this.originalHeight = el.height();
|
|
78
|
+
this.previousScrollTop = null;
|
|
79
|
+
|
|
80
|
+
this.value = el.val();
|
|
81
|
+
|
|
82
|
+
if (config.maxWidth === 'original') config.maxWidth = el.width();
|
|
83
|
+
if (config.minWidth === 'original') config.minWidth = el.width();
|
|
84
|
+
if (config.maxHeight === 'original') config.maxHeight = el.height();
|
|
85
|
+
if (config.minHeight === 'original') config.minHeight = el.height();
|
|
86
|
+
|
|
87
|
+
if (this.nodeName === 'textarea') {
|
|
88
|
+
el.css({
|
|
89
|
+
resize: 'none',
|
|
90
|
+
overflowY: 'hidden'
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
el.data('AutoResizer', this);
|
|
95
|
+
|
|
96
|
+
// Make sure onAfterResize is called upon animation completion
|
|
97
|
+
config.animate.complete = (function(f){
|
|
98
|
+
return function() {
|
|
99
|
+
config.onAfterResize.call(el);
|
|
100
|
+
return f.apply(this, arguments);
|
|
101
|
+
};
|
|
102
|
+
}(config.animate.complete));
|
|
103
|
+
|
|
104
|
+
this.bind();
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
AutoResizer.prototype = {
|
|
109
|
+
|
|
110
|
+
bind: function() {
|
|
111
|
+
|
|
112
|
+
var check = $.proxy(function(){
|
|
113
|
+
this.check();
|
|
114
|
+
return true;
|
|
115
|
+
}, this);
|
|
116
|
+
|
|
117
|
+
this.unbind();
|
|
118
|
+
|
|
119
|
+
this.el
|
|
120
|
+
.bind('keyup.autoResize', check)
|
|
121
|
+
//.bind('keydown.autoResize', check)
|
|
122
|
+
.bind('change.autoResize', check)
|
|
123
|
+
.bind('paste.autoResize', function() {
|
|
124
|
+
setTimeout(function() { check(); }, 0);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
if (!this.el.is(':hidden')) {
|
|
128
|
+
this.check(null, true);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
unbind: function() {
|
|
134
|
+
this.el.unbind('.autoResize');
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
createClone: function() {
|
|
138
|
+
|
|
139
|
+
var el = this.el,
|
|
140
|
+
clone = this.nodeName === 'textarea' ? el.clone() : $('<span/>');
|
|
141
|
+
|
|
142
|
+
this.clone = clone;
|
|
143
|
+
|
|
144
|
+
$.each(autoResize.cloneCSSProperties, function(i, p){
|
|
145
|
+
clone[0].style[p] = el.css(p);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
clone
|
|
149
|
+
.removeAttr('name')
|
|
150
|
+
.removeAttr('id')
|
|
151
|
+
.addClass(uid)
|
|
152
|
+
.attr('tabIndex', -1)
|
|
153
|
+
.css(autoResize.cloneCSSValues);
|
|
154
|
+
|
|
155
|
+
if (this.nodeName === 'textarea') {
|
|
156
|
+
clone.height('auto');
|
|
157
|
+
} else {
|
|
158
|
+
clone.width('auto').css({
|
|
159
|
+
whiteSpace: 'nowrap'
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
},
|
|
164
|
+
|
|
165
|
+
check: function(e, immediate) {
|
|
166
|
+
|
|
167
|
+
if (!this.clone) {
|
|
168
|
+
this.createClone();
|
|
169
|
+
this.injectClone();
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var config = this.config,
|
|
173
|
+
clone = this.clone,
|
|
174
|
+
el = this.el,
|
|
175
|
+
value = el.val();
|
|
176
|
+
|
|
177
|
+
// Do nothing if value hasn't changed
|
|
178
|
+
if (value === this.prevValue) { return true; }
|
|
179
|
+
this.prevValue = value;
|
|
180
|
+
|
|
181
|
+
if (this.nodeName === 'input') {
|
|
182
|
+
|
|
183
|
+
clone.text(value);
|
|
184
|
+
|
|
185
|
+
// Calculate new width + whether to change
|
|
186
|
+
var cloneWidth = clone.width(),
|
|
187
|
+
newWidth = (cloneWidth + config.extraSpace) >= config.minWidth ?
|
|
188
|
+
cloneWidth + config.extraSpace : config.minWidth,
|
|
189
|
+
currentWidth = el.width();
|
|
190
|
+
|
|
191
|
+
newWidth = Math.min(newWidth, config.maxWidth);
|
|
192
|
+
|
|
193
|
+
if (
|
|
194
|
+
(newWidth < currentWidth && newWidth >= config.minWidth) ||
|
|
195
|
+
(newWidth >= config.minWidth && newWidth <= config.maxWidth)
|
|
196
|
+
) {
|
|
197
|
+
|
|
198
|
+
config.onBeforeResize.call(el);
|
|
199
|
+
config.onResize.call(el);
|
|
200
|
+
|
|
201
|
+
el.scrollLeft(0);
|
|
202
|
+
|
|
203
|
+
if (config.animate && !immediate) {
|
|
204
|
+
el.stop(1,1).animate({
|
|
205
|
+
width: newWidth
|
|
206
|
+
}, config.animate);
|
|
207
|
+
} else {
|
|
208
|
+
el.width(newWidth);
|
|
209
|
+
config.onAfterResize.call(el);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return;
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// TEXTAREA
|
|
219
|
+
|
|
220
|
+
clone.width(el.width()).height(0).val(value).scrollTop(10000);
|
|
221
|
+
|
|
222
|
+
var scrollTop = clone[0].scrollTop;
|
|
223
|
+
|
|
224
|
+
// Don't do anything if scrollTop hasen't changed:
|
|
225
|
+
if (this.previousScrollTop === scrollTop) {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
this.previousScrollTop = scrollTop;
|
|
230
|
+
|
|
231
|
+
if (scrollTop + config.extraSpace >= config.maxHeight) {
|
|
232
|
+
el.css('overflowY', '');
|
|
233
|
+
scrollTop = config.maxHeight;
|
|
234
|
+
immediate = true;
|
|
235
|
+
} else if (scrollTop <= config.minHeight) {
|
|
236
|
+
scrollTop = config.minHeight;
|
|
237
|
+
} else {
|
|
238
|
+
el.css('overflowY', 'hidden');
|
|
239
|
+
scrollTop += config.extraSpace;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
config.onBeforeResize.call(el);
|
|
243
|
+
config.onResize.call(el);
|
|
244
|
+
|
|
245
|
+
// Either animate or directly apply height:
|
|
246
|
+
if (config.animate && !immediate) {
|
|
247
|
+
el.stop(1,1).animate({
|
|
248
|
+
height: scrollTop
|
|
249
|
+
}, config.animate);
|
|
250
|
+
} else {
|
|
251
|
+
el.height(scrollTop);
|
|
252
|
+
config.onAfterResize.call(el);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
destroy: function() {
|
|
258
|
+
this.unbind();
|
|
259
|
+
this.el.removeData('AutoResizer');
|
|
260
|
+
this.clone.remove();
|
|
261
|
+
delete this.el;
|
|
262
|
+
delete this.clone;
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
injectClone: function() {
|
|
266
|
+
(
|
|
267
|
+
autoResize.cloneContainer ||
|
|
268
|
+
(autoResize.cloneContainer = $('<arclones/>').appendTo('body'))
|
|
269
|
+
).append(this.clone);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
})(jQuery);
|
|
275
|
+
|