backlog 0.37.2 → 0.41.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +128 -0
- data/README.txt +4 -2
- data/bin/backlog +1 -1
- data/lib/array_helper.rb +4 -4
- data/{vendor/plugins → lib}/backlog_jira/README +0 -0
- data/{vendor/plugins → lib}/backlog_jira/Rakefile +0 -0
- data/{vendor/plugins → lib}/backlog_jira/generators/backlog_jira/backlog_jira_generator.rb +0 -0
- data/{vendor/plugins → lib}/backlog_jira/generators/backlog_jira/templates/migration.rb +0 -0
- data/{vendor/plugins → lib}/backlog_jira/generators/history_model/history_model_generator.rb +0 -0
- data/{vendor/plugins → lib}/backlog_jira/generators/history_model/templates/fixtures.yml +0 -0
- data/{vendor/plugins → lib}/backlog_jira/generators/history_model/templates/functional_test.rb +0 -0
- data/{vendor/plugins → lib}/backlog_jira/generators/history_model/templates/model.rb +0 -0
- data/{vendor/plugins → lib}/backlog_jira/generators/history_model/templates/unit_test.rb +0 -0
- data/lib/backlog_jira/init.rb +66 -0
- data/{vendor/plugins → lib}/backlog_jira/install.rb +0 -0
- data/{vendor/plugins → lib}/backlog_jira/lib/backlog_jira.rb +0 -0
- data/{vendor/plugins → lib}/backlog_jira/lib/tasks/backlog_jira_tasks.rake +0 -0
- data/{vendor/plugins → lib}/backlog_jira/test/backlog_jira_test.rb +0 -0
- data/{vendor/plugins → lib}/backlog_jira/uninstall.rb +0 -0
- data/lib/big_decimal_yaml_fix.rb +16 -25
- data/lib/tasks/backup.rake +18 -18
- data/lib/time_extras.rb +6 -6
- data/lib/user_system.rb +41 -38
- data/lib/version_from_history.rb +2 -2
- metadata +196 -749
- data/Capfile +0 -2
- data/Gemfile +0 -34
- data/Gemfile.lock +0 -139
- data/MODIFICATIONS.txt +0 -13
- data/Manifest.txt +0 -0
- data/README_LOGIN_SUGAR +0 -194
- data/Rakefile +0 -73
- data/Rakefile~ +0 -73
- data/Screenshot.png +0 -0
- data/app/controllers/absences_controller.rb +0 -67
- data/app/controllers/application_controller.rb +0 -185
- data/app/controllers/application_controller.rb.rails2 +0 -186
- data/app/controllers/customers_controller.rb +0 -51
- data/app/controllers/dashboard_controller.rb +0 -17
- data/app/controllers/estimates_controller.rb +0 -49
- data/app/controllers/groups_controller.rb +0 -65
- data/app/controllers/parties_controller.rb +0 -33
- data/app/controllers/periods_controller.rb +0 -242
- data/app/controllers/projects_controller.rb +0 -185
- data/app/controllers/public_holidays_controller.rb +0 -70
- data/app/controllers/search_controller.rb +0 -15
- data/app/controllers/task_files_controller.rb +0 -19
- data/app/controllers/tasks_controller.rb +0 -305
- data/app/controllers/user_controller.rb +0 -251
- data/app/controllers/welcome_controller.rb +0 -29
- data/app/controllers/work_locks_controller.rb +0 -88
- data/app/controllers/works_controller.rb +0 -383
- data/app/helpers/absences_helper.rb +0 -2
- data/app/helpers/application_helper.rb +0 -119
- data/app/helpers/application_helper.rb.rails2 +0 -118
- data/app/helpers/customers_helper.rb +0 -2
- data/app/helpers/dashboard_helper.rb +0 -2
- data/app/helpers/estimates_helper.rb +0 -2
- data/app/helpers/groups_helper.rb +0 -2
- data/app/helpers/parties_helper.rb +0 -2
- data/app/helpers/periods_helper.rb +0 -57
- data/app/helpers/projects_helper.rb +0 -74
- data/app/helpers/public_holidays_helper.rb +0 -2
- data/app/helpers/search_helper.rb +0 -2
- data/app/helpers/task_files_helper.rb +0 -2
- data/app/helpers/tasks_helper.rb +0 -2
- data/app/helpers/user_helper.rb +0 -53
- data/app/helpers/welcome_helper.rb +0 -2
- data/app/helpers/work_locks_helper.rb +0 -2
- data/app/helpers/works_helper.rb +0 -5
- data/app/mailers/user_notify.rb +0 -76
- data/app/models/absence.rb +0 -27
- data/app/models/chart.rb +0 -5
- data/app/models/clock.rb +0 -14
- data/app/models/configuration.rb +0 -2
- data/app/models/customer.rb +0 -2
- data/app/models/estimate.rb +0 -17
- data/app/models/group.rb +0 -16
- data/app/models/party.rb +0 -27
- data/app/models/period.rb +0 -251
- data/app/models/project.rb +0 -49
- data/app/models/public_holiday.rb +0 -13
- data/app/models/report_filter.rb +0 -29
- data/app/models/search_result.rb +0 -8
- data/app/models/sidebar.rb +0 -41
- data/app/models/task.rb +0 -425
- data/app/models/task_file.rb +0 -7
- data/app/models/task_notify.rb +0 -27
- data/app/models/user.rb +0 -146
- data/app/models/work.rb +0 -191
- data/app/models/work_lock.rb +0 -11
- data/app/models/work_lock_nagger.rb +0 -60
- data/app/models/work_lock_notify.rb +0 -43
- data/app/models/works_report_filter.rb +0 -27
- data/app/views/absences/_form.rhtml +0 -10
- data/app/views/absences/edit.rhtml +0 -9
- data/app/views/absences/list.rhtml +0 -25
- data/app/views/absences/new.rhtml +0 -8
- data/app/views/absences/show.rhtml +0 -8
- data/app/views/customers/_form.rhtml +0 -7
- data/app/views/customers/_name_list.rhtml +0 -5
- data/app/views/customers/edit.rhtml +0 -9
- data/app/views/customers/list.rhtml +0 -28
- data/app/views/customers/new.rhtml +0 -8
- data/app/views/customers/show.rhtml +0 -8
- data/app/views/dashboard/show.rhtml +0 -24
- data/app/views/display_notice.rjs +0 -1
- data/app/views/groups/_form.rhtml +0 -7
- data/app/views/groups/edit.rhtml +0 -57
- data/app/views/groups/list.rhtml +0 -26
- data/app/views/groups/new.rhtml +0 -7
- data/app/views/groups/set_member.rjs +0 -1
- data/app/views/layouts/_headers.rhtml +0 -24
- data/app/views/layouts/_left_top.rhtml +0 -33
- data/app/views/layouts/_notice.rhtml +0 -12
- data/app/views/layouts/_shortcuts.rhtml +0 -22
- data/app/views/layouts/_shortcuts_js.rhtml +0 -19
- data/app/views/layouts/mwrt002.html.erb +0 -44
- data/app/views/layouts/wide.rhtml +0 -23
- data/app/views/periods/_burn_down_chart.rhtml +0 -9
- data/app/views/periods/_form.rhtml +0 -74
- data/app/views/periods/_link.rhtml +0 -3
- data/app/views/periods/_show_active.rhtml +0 -61
- data/app/views/periods/_sidebar_block.rhtml +0 -11
- data/app/views/periods/_title.rhtml +0 -18
- data/app/views/periods/edit.rhtml +0 -10
- data/app/views/periods/finish_task.rjs +0 -4
- data/app/views/periods/move_task_to_period.rjs +0 -4
- data/app/views/periods/new.rhtml +0 -9
- data/app/views/periods/order.rjs +0 -0
- data/app/views/periods/reopen_task.rjs +0 -6
- data/app/views/periods/show.rhtml +0 -56
- data/app/views/projects/_buttons.rhtml +0 -4
- data/app/views/projects/_form.rhtml +0 -44
- data/app/views/projects/_name_list.rhtml +0 -5
- data/app/views/projects/edit.rhtml +0 -14
- data/app/views/projects/finish_task.rjs +0 -3
- data/app/views/projects/list.rhtml +0 -16
- data/app/views/projects/move_task_to_period.rjs +0 -3
- data/app/views/projects/new.rhtml +0 -11
- data/app/views/projects/reopen_task.rjs +0 -3
- data/app/views/projects/show.rhtml +0 -39
- data/app/views/public_holidays/_form.rhtml +0 -7
- data/app/views/public_holidays/edit.rhtml +0 -9
- data/app/views/public_holidays/list.rhtml +0 -25
- data/app/views/public_holidays/new.rhtml +0 -8
- data/app/views/public_holidays/show.rhtml +0 -8
- data/app/views/redirect.rjs +0 -1
- data/app/views/search/results.rhtml +0 -40
- data/app/views/task_notify/invite.en.html.erb +0 -13
- data/app/views/task_notify/invite.no.html.erb +0 -13
- data/app/views/tasks/_backlog_header.rhtml +0 -17
- data/app/views/tasks/_completed.rhtml +0 -18
- data/app/views/tasks/_fields_header.rhtml +0 -13
- data/app/views/tasks/_form.rhtml +0 -125
- data/app/views/tasks/_invite.rjs +0 -1
- data/app/views/tasks/_period_header.rhtml +0 -1
- data/app/views/tasks/_task.rhtml +0 -116
- data/app/views/tasks/_update.rjs +0 -2
- data/app/views/tasks/edit.rhtml +0 -81
- data/app/views/tasks/grab.rhtml +0 -9
- data/app/views/tasks/invite.rhtml +0 -9
- data/app/views/tasks/list.rhtml +0 -77
- data/app/views/tasks/list_started.rhtml +0 -62
- data/app/views/tasks/new.rhtml +0 -10
- data/app/views/tasks/notes.rhtml +0 -12
- data/app/views/tasks/start_work.rjs +0 -1
- data/app/views/tasks/update_estimate.rjs +0 -3
- data/app/views/user/_edit.rhtml +0 -31
- data/app/views/user/_password.rhtml +0 -21
- data/app/views/user/change_password.rhtml +0 -19
- data/app/views/user/delete.rhtml +0 -14
- data/app/views/user/edit.rhtml +0 -154
- data/app/views/user/forgot_password.rhtml +0 -19
- data/app/views/user/login.rhtml +0 -33
- data/app/views/user/logout.rhtml +0 -8
- data/app/views/user/set_group.rjs +0 -1
- data/app/views/user/signup.rhtml +0 -15
- data/app/views/user/toggle_work_lock_monitoring.rjs +0 -2
- data/app/views/user/welcome.rhtml +0 -8
- data/app/views/user_notify/change_password.en.html.erb +0 -10
- data/app/views/user_notify/change_password.no.html.erb +0 -10
- data/app/views/user_notify/forgot_password.en.html.erb +0 -11
- data/app/views/user_notify/forgot_password.no.html.erb +0 -11
- data/app/views/user_notify/monitoring.en.html.erb +0 -3
- data/app/views/user_notify/monitoring.no.html.erb +0 -3
- data/app/views/user_notify/monitoring_invitation.en.html.erb +0 -7
- data/app/views/user_notify/monitoring_invitation.no.html.erb +0 -7
- data/app/views/user_notify/signup.en.html.erb +0 -12
- data/app/views/user_notify/signup.no.html.erb +0 -12
- data/app/views/work_lock_notify/lock.en.html.erb +0 -7
- data/app/views/work_lock_notify/lock.no.html.erb +0 -7
- data/app/views/work_lock_notify/nag.en.html.erb +0 -6
- data/app/views/work_lock_notify/nag.no.html.erb +0 -7
- data/app/views/work_locks/_form.rhtml +0 -10
- data/app/views/work_locks/edit.rhtml +0 -9
- data/app/views/work_locks/list.rhtml +0 -25
- data/app/views/work_locks/new.rhtml +0 -8
- data/app/views/work_locks/show.rhtml +0 -8
- data/app/views/works/_buttons.rhtml +0 -2
- data/app/views/works/_description_list.rhtml +0 -5
- data/app/views/works/_form.rhtml +0 -107
- data/app/views/works/_new_row.rhtml +0 -141
- data/app/views/works/_row.rhtml +0 -115
- data/app/views/works/_row_field.rhtml +0 -17
- data/app/views/works/_task_id_list.rhtml +0 -5
- data/app/views/works/_weekly_work_sheet_buttons.rhtml +0 -22
- data/app/views/works/daily_work_sheet.rhtml +0 -108
- data/app/views/works/edit.rhtml +0 -11
- data/app/views/works/list.rhtml +0 -148
- data/app/views/works/list_excel.rhtml +0 -114
- data/app/views/works/new.rhtml +0 -12
- data/app/views/works/show.rhtml +0 -10
- data/app/views/works/timeliste.rhtml +0 -884
- data/app/views/works/update_new_row.rjs +0 -28
- data/app/views/works/update_row.rjs +0 -18
- data/app/views/works/update_time.rjs +0 -3
- data/app/views/works/weekly_work_sheet.rhtml +0 -64
- data/app/views/works/weekly_work_sheet_details.rhtml +0 -102
- data/backlog.gemspec +0 -44
- data/config.ru +0 -4
- data/config/application.rb +0 -11
- data/config/boot.rb +0 -13
- data/config/database.yml +0 -15
- data/config/database.yml~ +0 -17
- data/config/environment.rb +0 -100
- data/config/environments/development.rb +0 -30
- data/config/environments/development.rb.rails2 +0 -26
- data/config/environments/production.rb +0 -33
- data/config/environments/test.rb +0 -24
- data/config/environments/user_environment.rb +0 -21
- data/config/initializers/backtrace_silencers.rb +0 -7
- data/config/initializers/inflections.rb +0 -10
- data/config/initializers/jdbc.rb +0 -7
- data/config/initializers/mime_types.rb +0 -5
- data/config/initializers/secret_token.rb +0 -7
- data/config/initializers/session_store.rb +0 -8
- data/config/locales/en.yml +0 -200
- data/config/locales/no.yml +0 -193
- data/config/mime_types.yaml +0 -1
- data/config/routes.rb +0 -5
- data/config/war.rb +0 -27
- data/config/warble.rb +0 -84
- data/cruise_build.sh +0 -14
- data/cruise_config.rb +0 -5
- data/db/migrate/001_create_tasks.rb +0 -22
- data/db/migrate/003_add_estimation_points.rb +0 -16
- data/db/migrate/004_add_period.rb +0 -63
- data/db/migrate/005_add_field_work_started_at.rb +0 -9
- data/db/migrate/006_works_data_fix.rb +0 -13
- data/db/migrate/007_add_task_created_at.rb +0 -23
- data/db/migrate/008_add_backlog_options.rb +0 -13
- data/db/migrate/009_add_subtasks.rb +0 -29
- data/db/migrate/010_add_work_start.rb +0 -9
- data/db/migrate/011_login_sugar.rb +0 -21
- data/db/migrate/012_add_resolution.rb +0 -12
- data/db/migrate/013_create_estimates.rb +0 -20
- data/db/migrate/014_add_customer_option.rb +0 -11
- data/db/migrate/015_add_user_option.rb +0 -33
- data/db/migrate/016_add_invoicable_flag.rb +0 -11
- data/db/migrate/017_increase_backlog_name_limit.rb +0 -10
- data/db/migrate/018_create_groups.rb +0 -118
- data/db/migrate/019_remove_unique_index_for_period_position.rb +0 -9
- data/db/migrate/020_create_task_files.rb +0 -17
- data/db/migrate/021_create_work_accounts.rb +0 -111
- data/db/migrate/022_remove_track_done_flag.rb +0 -9
- data/db/migrate/023_add_indices_for_burn_down_chart.rb +0 -13
- data/db/migrate/024_add_sprint_option.rb +0 -10
- data/db/migrate/025_add_simple_auditing_of_tasks.rb +0 -11
- data/db/migrate/026_add_users_to_tasks.rb +0 -14
- data/db/migrate/027_create_work_locks.rb +0 -25
- data/db/migrate/028_create_absences.rb +0 -34
- data/db/migrate/029_add_work_comments.rb +0 -9
- data/db/migrate/030_create_public_holidays.rb +0 -11
- data/db/migrate/031_expand_work_done_precision.rb +0 -9
- data/db/migrate/20100720124707_merge_work_account_into_backlog.rb +0 -74
- data/db/migrate/20101006092700_rename_backlogs_to_projects.rb +0 -22
- data/db/migrate/20101006092700_rename_backlogs_to_projects.rb~ +0 -22
- data/db/schema.rb +0 -159
- data/db/seeds.rb +0 -7
- data/db/test.db +0 -0
- data/etc/backlog.conf +0 -32
- data/ext/mkrf_conf.rb +0 -26
- data/lib/class_table_inheritance.rb +0 -224
- data/lib/postgresql-8.2-504.jdbc4.jar +0 -0
- data/lib/tasks/jdbc.rake +0 -8
- data/lib/url_for_fix.rb +0 -30
- data/nbproject/private/config.properties +0 -0
- data/nbproject/private/private.properties +0 -1
- data/nbproject/private/private.xml +0 -4
- data/nbproject/private/rake-t.txt +0 -95
- data/nbproject/project.properties +0 -4
- data/nbproject/project.xml +0 -9
- data/public/404.html +0 -26
- data/public/422.html +0 -26
- data/public/500.html +0 -26
- data/public/Frav/303/246rsskjema.xls +0 -0
- data/public/applets/bsf.jar +0 -0
- data/public/applets/jruby.jar +0 -0
- data/public/favicon.ico +0 -0
- data/public/images/add.png +0 -0
- data/public/images/add.svg +0 -70
- data/public/images/ajax-loading.gif +0 -0
- data/public/images/appunti_architetto_franc_01.svg +0 -92
- data/public/images/arrow-down.gif +0 -0
- data/public/images/arrow-up.gif +0 -0
- data/public/images/arrow07_2.png +0 -0
- data/public/images/arrow07_4.png +0 -0
- data/public/images/arrow_down.png +0 -0
- data/public/images/arrow_down.svg +0 -59
- data/public/images/arrow_left.png +0 -0
- data/public/images/arrow_left.svg +0 -59
- data/public/images/arrow_right.png +0 -0
- data/public/images/arrow_right.svg +0 -59
- data/public/images/arrow_up.png +0 -0
- data/public/images/arrow_up.svg +0 -59
- data/public/images/black-70.png +0 -0
- data/public/images/black.png +0 -0
- data/public/images/blank.jpg +0 -0
- data/public/images/blank.png +0 -0
- data/public/images/cestino_pieno_architetto_01.svg +0 -470
- data/public/images/checkmark.png +0 -0
- data/public/images/checkmark_org.png +0 -0
- data/public/images/clipboard.png +0 -0
- data/public/images/clipboard.svg +0 -62
- data/public/images/construction_hammer_jon__01.svg +0 -116
- data/public/images/delete.png +0 -0
- data/public/images/email.png +0 -0
- data/public/images/email_grey.png +0 -0
- data/public/images/eraser.png +0 -0
- data/public/images/eraser_org.png +0 -0
- data/public/images/ernes_stop.png +0 -0
- data/public/images/ernes_stop_org.png +0 -0
- data/public/images/flag_red.png +0 -0
- data/public/images/flag_yellow.png +0 -0
- data/public/images/grab.png +0 -0
- data/public/images/grab_gray.png +0 -0
- data/public/images/group.png +0 -0
- data/public/images/hammer.png +0 -0
- data/public/images/header.jpg +0 -0
- data/public/images/nextlabel.gif +0 -0
- data/public/images/pagebak.jpg +0 -0
- data/public/images/paper3.svg +0 -54
- data/public/images/period.png +0 -0
- data/public/images/period_org.png +0 -0
- data/public/images/person.org.png +0 -0
- data/public/images/prevlabel.gif +0 -0
- data/public/images/question.svg +0 -56
- data/public/images/rails.png +0 -0
- data/public/images/refresh.png +0 -0
- data/public/images/rmagick.gif +0 -0
- data/public/images/rmagick_270.gif +0 -0
- data/public/images/tabella_architetto_franc_01.svg +0 -105
- data/public/images/task.png +0 -0
- data/public/images/text-x-generic.png +0 -0
- data/public/images/user group.png +0 -0
- data/public/images/user.png +0 -0
- data/public/images/view_fullscreen.png +0 -0
- data/public/images/work_account.png +0 -0
- data/public/javascripts/application.js +0 -2
- data/public/javascripts/builder.js +0 -136
- data/public/javascripts/controls.js +0 -965
- data/public/javascripts/dragdrop.js +0 -974
- data/public/javascripts/effects.js +0 -1123
- data/public/javascripts/lightwindow.js +0 -1921
- data/public/javascripts/prototype.js +0 -6001
- data/public/javascripts/rails.js +0 -175
- data/public/javascripts/ruby.js +0 -46
- data/public/javascripts/scriptaculous.js +0 -58
- data/public/javascripts/slider.js +0 -275
- data/public/javascripts/sound.js +0 -55
- data/public/javascripts/unittest.js +0 -568
- data/public/javascripts/zapatec/utils/transport.js +0 -2217
- data/public/javascripts/zapatec/utils/utils.js +0 -1799
- data/public/javascripts/zapatec/utils/zapatec.js +0 -90
- data/public/javascripts/zapatec/utils/zpeventdriven.js +0 -212
- data/public/javascripts/zapatec/utils/zpwidget.js +0 -729
- data/public/javascripts/zapatec/zpcal/lang/calendar-no.js +0 -124
- data/public/javascripts/zapatec/zpcal/src/calendar-core.js +0 -2878
- data/public/javascripts/zapatec/zpcal/src/calendar-date-core.js +0 -348
- data/public/javascripts/zapatec/zpcal/src/calendar-setup.js +0 -360
- data/public/javascripts/zapatec/zpcal/src/calendar.js +0 -35
- data/public/robots.txt +0 -5
- data/public/stylesheets/backlog.css +0 -135
- data/public/stylesheets/lightwindow.css +0 -376
- data/public/stylesheets/mwrt002.css +0 -54
- data/public/stylesheets/mwrt002MAC.css +0 -3
- data/public/stylesheets/mwrt002NN.css +0 -3
- data/public/stylesheets/scaffold.css +0 -74
- data/public/stylesheets/user.css +0 -74
- data/public/stylesheets/zpcal/themes/green.css +0 -153
- data/public/stylesheets/zpcal/themes/layouts/layout-2d.css +0 -134
- data/public/stylesheets/zpcal/themes/layouts/layout-common.css +0 -74
- data/public/stylesheets/zpcal/themes/menuarrow.gif +0 -0
- data/public/stylesheets/zpcal/themes/scroller-down.gif +0 -0
- data/public/stylesheets/zpcal/themes/scroller-up.gif +0 -0
- data/script/rails +0 -6
- data/test/client/login.rb +0 -23
- data/test/client/login_test.rb +0 -64
- data/test/client/setup.rb +0 -25
- data/test/fixtures/absences.yml +0 -11
- data/test/fixtures/configurations.yml +0 -5
- data/test/fixtures/customers.yml +0 -7
- data/test/fixtures/estimates.yml +0 -10
- data/test/fixtures/groups.yml +0 -6
- data/test/fixtures/groups_users.yml +0 -3
- data/test/fixtures/parties.yml +0 -32
- data/test/fixtures/periods.yml +0 -24
- data/test/fixtures/projects.yml +0 -8
- data/test/fixtures/public_holidays.yml +0 -7
- data/test/fixtures/task_files.yml +0 -13
- data/test/fixtures/tasks.yml +0 -82
- data/test/fixtures/users.yml +0 -59
- data/test/fixtures/work_lock_subscriptions.yml +0 -7
- data/test/fixtures/work_locks.yml +0 -11
- data/test/fixtures/works.yml +0 -47
- data/test/functional/absences_controller_test.rb +0 -93
- data/test/functional/customers_controller_test.rb +0 -93
- data/test/functional/dashboard_controller_test.rb +0 -18
- data/test/functional/estimates_controller_test.rb +0 -40
- data/test/functional/groups_controller_test.rb +0 -120
- data/test/functional/parties_controller_test.rb +0 -35
- data/test/functional/periods_controller_test.rb +0 -297
- data/test/functional/projects_controller_test.rb +0 -152
- data/test/functional/public_holidays_controller_test.rb +0 -93
- data/test/functional/search_controller_test.rb +0 -24
- data/test/functional/task_files_controller_test.rb +0 -29
- data/test/functional/tasks_controller_test.rb +0 -229
- data/test/functional/user_controller_test.rb +0 -261
- data/test/functional/welcome_controller_test.rb +0 -62
- data/test/functional/work_locks_controller_test.rb +0 -93
- data/test/functional/works_controller_test.rb +0 -220
- data/test/integration/user_system_test.rb +0 -95
- data/test/mocks/test/clock.rb +0 -14
- data/test/performance/browsing_test.rb +0 -9
- data/test/performance/common.rb +0 -91
- data/test/performance/jetty_test.rb +0 -15
- data/test/performance/server_test.rb +0 -17
- data/test/test_helper.rb +0 -119
- data/test/test_helper.rb~ +0 -121
- data/test/unit/absence_test.rb +0 -29
- data/test/unit/big_decimal_yaml_fix_test.rb +0 -15
- data/test/unit/configuration_test.rb +0 -10
- data/test/unit/customer_test.rb +0 -10
- data/test/unit/estimate_test.rb +0 -10
- data/test/unit/group_test.rb +0 -10
- data/test/unit/party_test.rb +0 -10
- data/test/unit/period_test.rb +0 -9
- data/test/unit/public_holiday_test.rb +0 -10
- data/test/unit/task_file_test.rb +0 -10
- data/test/unit/task_test.rb +0 -73
- data/test/unit/time_of_day_test.rb +0 -23
- data/test/unit/user_test.rb +0 -148
- data/test/unit/work_lock_subscription_test.rb +0 -10
- data/test/unit/work_lock_test.rb +0 -10
- data/test/unit/work_test.rb +0 -81
- data/vendor/plugins/acts_as_list/README +0 -23
- data/vendor/plugins/acts_as_list/init.rb +0 -3
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +0 -256
- data/vendor/plugins/acts_as_list/test/list_test.rb +0 -332
- data/vendor/plugins/acts_as_tree/README +0 -26
- data/vendor/plugins/acts_as_tree/Rakefile +0 -22
- data/vendor/plugins/acts_as_tree/init.rb +0 -1
- data/vendor/plugins/acts_as_tree/lib/active_record/acts/tree.rb +0 -96
- data/vendor/plugins/acts_as_tree/test/abstract_unit.rb +0 -0
- data/vendor/plugins/acts_as_tree/test/acts_as_tree_test.rb +0 -219
- data/vendor/plugins/acts_as_tree/test/database.yml +0 -0
- data/vendor/plugins/acts_as_tree/test/fixtures/mixin.rb +0 -0
- data/vendor/plugins/acts_as_tree/test/fixtures/mixins.yml +0 -0
- data/vendor/plugins/acts_as_tree/test/schema.rb +0 -0
- data/vendor/plugins/assert_cookie/MIT-LICENSE +0 -7
- data/vendor/plugins/assert_cookie/README +0 -6
- data/vendor/plugins/assert_cookie/Rakefile +0 -21
- data/vendor/plugins/assert_cookie/init.rb +0 -1
- data/vendor/plugins/assert_cookie/lib/assert_cookie.rb +0 -73
- data/vendor/plugins/assert_cookie/meta.yml +0 -7
- data/vendor/plugins/assert_cookie/test/test_assert_cookie.rb +0 -124
- data/vendor/plugins/assert_cookie/test/test_helper.rb +0 -31
- data/vendor/plugins/auto_complete/README +0 -23
- data/vendor/plugins/auto_complete/Rakefile +0 -22
- data/vendor/plugins/auto_complete/init.rb +0 -2
- data/vendor/plugins/auto_complete/lib/auto_complete.rb +0 -47
- data/vendor/plugins/auto_complete/lib/auto_complete_macros_helper.rb +0 -143
- data/vendor/plugins/auto_complete/test/auto_complete_test.rb +0 -67
- data/vendor/plugins/backlog_jira/init.rb +0 -66
- data/vendor/plugins/dynamic_form/MIT-LICENSE +0 -20
- data/vendor/plugins/dynamic_form/README +0 -13
- data/vendor/plugins/dynamic_form/Rakefile +0 -10
- data/vendor/plugins/dynamic_form/dynamic_form.gemspec +0 -12
- data/vendor/plugins/dynamic_form/init.rb +0 -1
- data/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +0 -300
- data/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +0 -8
- data/vendor/plugins/dynamic_form/lib/dynamic_form.rb +0 -5
- data/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +0 -42
- data/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +0 -370
- data/vendor/plugins/dynamic_form/test/test_helper.rb +0 -9
- data/vendor/plugins/has_history/README +0 -12
- data/vendor/plugins/has_history/Rakefile +0 -22
- data/vendor/plugins/has_history/generators/history_migration/history_migration_generator.rb +0 -30
- data/vendor/plugins/has_history/generators/history_migration/templates/migration.rb +0 -14
- data/vendor/plugins/has_history/generators/history_model/history_model_generator.rb +0 -39
- data/vendor/plugins/has_history/generators/history_model/templates/fixtures.yml +0 -17
- data/vendor/plugins/has_history/generators/history_model/templates/functional_test.rb +0 -129
- data/vendor/plugins/has_history/generators/history_model/templates/migration.rb +0 -14
- data/vendor/plugins/has_history/generators/history_model/templates/model.rb +0 -4
- data/vendor/plugins/has_history/generators/history_model/templates/unit_test.rb +0 -75
- data/vendor/plugins/has_history/init.rb +0 -5
- data/vendor/plugins/has_history/install.rb +0 -1
- data/vendor/plugins/has_history/lib/has_history.rb +0 -178
- data/vendor/plugins/has_history/lib/tasks/has_history_tasks.rake +0 -4
- data/vendor/plugins/has_history/test/has_history_test.rb +0 -31
- data/vendor/plugins/has_history/test/ignorant_master.rb +0 -3
- data/vendor/plugins/has_history/test/ignorant_master_history.rb +0 -4
- data/vendor/plugins/has_history/test/lone_master.rb +0 -42
- data/vendor/plugins/has_history/test/paired_master.rb +0 -5
- data/vendor/plugins/has_history/test/paired_master_history.rb +0 -5
- data/vendor/plugins/has_history/test/test_helper.rb +0 -154
- data/vendor/plugins/has_history/uninstall.rb +0 -1
- data/vendor/plugins/prototype_legacy_helper/lib/prototype_legacy_helper.rb +0 -432
- data/vendor/plugins/prototype_legacy_helper/test/test_prototype_helper.rb +0 -297
- data/vendor/plugins/rails_time/MIT-LICENSE +0 -20
- data/vendor/plugins/rails_time/README +0 -28
- data/vendor/plugins/rails_time/init.rb +0 -2
- data/vendor/plugins/rails_time/lib/activerecord_time_extension.rb +0 -28
- data/vendor/plugins/rails_time/lib/time_of_day.rb +0 -88
- data/vendor/plugins/rails_time/test/database.yml +0 -18
- data/vendor/plugins/rails_time/test/debug.log +0 -1
- data/vendor/plugins/rails_time/test/rails_time_test.rb +0 -122
- data/vendor/plugins/rails_time/test/schema.rb +0 -10
- data/vendor/plugins/rails_time/test/test_helper.rb +0 -17
- data/vendor/plugins/verification/MIT-LICENSE +0 -20
- data/vendor/plugins/verification/README +0 -34
- data/vendor/plugins/verification/Rakefile +0 -22
- data/vendor/plugins/verification/init.rb +0 -3
- data/vendor/plugins/verification/lib/action_controller/verification.rb +0 -132
- data/vendor/plugins/verification/test/test_helper.rb +0 -18
- data/vendor/plugins/verification/test/verification_test.rb +0 -270
- data/vendor/plugins/will_paginate/LICENSE +0 -18
- data/vendor/plugins/will_paginate/README +0 -138
- data/vendor/plugins/will_paginate/Rakefile +0 -27
- data/vendor/plugins/will_paginate/init.rb +0 -4
- data/vendor/plugins/will_paginate/lib/will_paginate.rb +0 -61
- data/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +0 -132
- data/vendor/plugins/will_paginate/lib/will_paginate/core_ext.rb +0 -80
- data/vendor/plugins/will_paginate/lib/will_paginate/finder.rb +0 -181
- data/vendor/plugins/will_paginate/lib/will_paginate/view_helpers.rb +0 -206
- data/vendor/plugins/will_paginate/test/array_pagination_test.rb +0 -131
- data/vendor/plugins/will_paginate/test/boot.rb +0 -23
- data/vendor/plugins/will_paginate/test/console +0 -9
- data/vendor/plugins/will_paginate/test/finder_test.rb +0 -290
- data/vendor/plugins/will_paginate/test/fixtures/admin.rb +0 -3
- data/vendor/plugins/will_paginate/test/fixtures/developer.rb +0 -11
- data/vendor/plugins/will_paginate/test/fixtures/developers_projects.yml +0 -13
- data/vendor/plugins/will_paginate/test/fixtures/project.rb +0 -15
- data/vendor/plugins/will_paginate/test/fixtures/projects.yml +0 -7
- data/vendor/plugins/will_paginate/test/fixtures/replies.yml +0 -34
- data/vendor/plugins/will_paginate/test/fixtures/reply.rb +0 -5
- data/vendor/plugins/will_paginate/test/fixtures/schema.rb +0 -38
- data/vendor/plugins/will_paginate/test/fixtures/topic.rb +0 -4
- data/vendor/plugins/will_paginate/test/fixtures/topics.yml +0 -30
- data/vendor/plugins/will_paginate/test/fixtures/user.rb +0 -2
- data/vendor/plugins/will_paginate/test/fixtures/users.yml +0 -35
- data/vendor/plugins/will_paginate/test/helper.rb +0 -25
- data/vendor/plugins/will_paginate/test/lib/activerecord_test_case.rb +0 -23
- data/vendor/plugins/will_paginate/test/lib/activerecord_test_connector.rb +0 -67
- data/vendor/plugins/will_paginate/test/lib/load_fixtures.rb +0 -13
- data/vendor/plugins/will_paginate/test/pagination_test.rb +0 -240
@@ -1,2217 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @fileoverview Zapatec Transport library. Used to fetch data from the server,
|
3
|
-
* parse and serialize XML and JSON data.
|
4
|
-
*
|
5
|
-
* <pre>
|
6
|
-
* Copyright (c) 2004-2006 by Zapatec, Inc.
|
7
|
-
* http://www.zapatec.com
|
8
|
-
* 1700 MLK Way, Berkeley, California,
|
9
|
-
* 94709, U.S.A.
|
10
|
-
* All rights reserved.
|
11
|
-
* </pre>
|
12
|
-
*/
|
13
|
-
|
14
|
-
// $Id: transport.js 4976 2006-11-02 00:10:50Z alex $
|
15
|
-
|
16
|
-
if (typeof Zapatec == 'undefined') {
|
17
|
-
/**
|
18
|
-
* Namespace definition.
|
19
|
-
* @constructor
|
20
|
-
*/
|
21
|
-
Zapatec = function() {};
|
22
|
-
}
|
23
|
-
|
24
|
-
/**
|
25
|
-
* @constructor
|
26
|
-
*/
|
27
|
-
Zapatec.Transport = function() {};
|
28
|
-
|
29
|
-
// Determine most current versions of ActiveX objects available
|
30
|
-
if (typeof ActiveXObject != 'undefined') {
|
31
|
-
|
32
|
-
/**
|
33
|
-
* String variable with most current version of XMLDOM ActiveX object name
|
34
|
-
* available.
|
35
|
-
* @private
|
36
|
-
*/
|
37
|
-
Zapatec.Transport.XMLDOM = null;
|
38
|
-
|
39
|
-
/**
|
40
|
-
* String variable with Most current version of XMLHTTP ActiveX object name
|
41
|
-
* available.
|
42
|
-
* @private
|
43
|
-
*/
|
44
|
-
Zapatec.Transport.XMLHTTP = null;
|
45
|
-
|
46
|
-
/**
|
47
|
-
* @ignore
|
48
|
-
* Returns first available ActiveX object name from the given list.
|
49
|
-
*
|
50
|
-
* @param {object} arrVersions List of ActiveX object names to test
|
51
|
-
* @return First available ActiveX object name or null
|
52
|
-
* @type string
|
53
|
-
*/
|
54
|
-
Zapatec.Transport.pickActiveXVersion = function(arrVersions) {
|
55
|
-
for (var iVn = 0; iVn < arrVersions.length; iVn++) {
|
56
|
-
try {
|
57
|
-
var objDocument = new ActiveXObject(arrVersions[iVn]);
|
58
|
-
// If it gets to this point, the string worked
|
59
|
-
return arrVersions[iVn];
|
60
|
-
} catch (objException) {};
|
61
|
-
}
|
62
|
-
return null;
|
63
|
-
};
|
64
|
-
|
65
|
-
/**
|
66
|
-
* Most current version of XMLDOM ActiveX object.
|
67
|
-
* @private
|
68
|
-
*/
|
69
|
-
Zapatec.Transport.XMLDOM = Zapatec.Transport.pickActiveXVersion([
|
70
|
-
'Msxml2.DOMDocument.4.0',
|
71
|
-
'Msxml2.DOMDocument.3.0',
|
72
|
-
'MSXML2.DOMDocument',
|
73
|
-
'MSXML.DOMDocument',
|
74
|
-
'Microsoft.XMLDOM'
|
75
|
-
]);
|
76
|
-
|
77
|
-
/**
|
78
|
-
* Most current version of XMLHTTP ActiveX object.
|
79
|
-
* @private
|
80
|
-
*/
|
81
|
-
Zapatec.Transport.XMLHTTP = Zapatec.Transport.pickActiveXVersion([
|
82
|
-
'Msxml2.XMLHTTP.4.0',
|
83
|
-
'MSXML2.XMLHTTP.3.0',
|
84
|
-
'MSXML2.XMLHTTP',
|
85
|
-
'Microsoft.XMLHTTP'
|
86
|
-
]);
|
87
|
-
|
88
|
-
// We don't need this any more
|
89
|
-
Zapatec.Transport.pickActiveXVersion = null;
|
90
|
-
|
91
|
-
}
|
92
|
-
|
93
|
-
/**
|
94
|
-
* Creates cross browser XMLHttpRequest object.
|
95
|
-
*
|
96
|
-
* @return New XMLHttpRequest object.
|
97
|
-
* @type object
|
98
|
-
*/
|
99
|
-
Zapatec.Transport.createXmlHttpRequest = function() {
|
100
|
-
if (typeof ActiveXObject != 'undefined') {
|
101
|
-
try {
|
102
|
-
return new ActiveXObject(Zapatec.Transport.XMLHTTP);
|
103
|
-
} catch (objException) {};
|
104
|
-
}
|
105
|
-
if (typeof XMLHttpRequest != 'undefined') {
|
106
|
-
return new XMLHttpRequest();
|
107
|
-
}
|
108
|
-
return null;
|
109
|
-
};
|
110
|
-
|
111
|
-
/**
|
112
|
-
* Checks if animated GIF is already displayed in the specified div.
|
113
|
-
*
|
114
|
-
* <pre>
|
115
|
-
* Arguments object format:
|
116
|
-
* {
|
117
|
-
* busyContainer: [object or string] element where to put animated GIF,
|
118
|
-
* busyImage: [string, optional] image name
|
119
|
-
* }
|
120
|
-
* </pre>
|
121
|
-
*
|
122
|
-
* @private
|
123
|
-
* @param {object} objArgs Arguments object
|
124
|
-
* @return True if image is displayed
|
125
|
-
* @type boolean
|
126
|
-
*/
|
127
|
-
Zapatec.Transport.isBusy = function(objArgs) {
|
128
|
-
// Get container
|
129
|
-
var objContainer = objArgs.busyContainer;
|
130
|
-
if (typeof objContainer == 'string') {
|
131
|
-
objContainer = document.getElementById(objContainer);
|
132
|
-
}
|
133
|
-
if (!objContainer) {
|
134
|
-
return;
|
135
|
-
}
|
136
|
-
// Get image name
|
137
|
-
var strImage = objArgs.busyImage;
|
138
|
-
if (typeof strImage != 'string') {
|
139
|
-
strImage = '';
|
140
|
-
}
|
141
|
-
strImage = strImage.split('/').pop();
|
142
|
-
if (!strImage.length) {
|
143
|
-
strImage = 'zpbusy.gif';
|
144
|
-
}
|
145
|
-
// Check if image is displayed
|
146
|
-
var objFC = objContainer.firstChild;
|
147
|
-
if (objFC) {
|
148
|
-
objFC = objFC.firstChild;
|
149
|
-
if (objFC) {
|
150
|
-
objFC = objFC.firstChild;
|
151
|
-
if (objFC && objFC.tagName && objFC.tagName.toLowerCase() == 'img') {
|
152
|
-
var strSrc = objFC.getAttribute('src');
|
153
|
-
if (typeof strSrc == 'string' && strSrc.length) {
|
154
|
-
// Get last token
|
155
|
-
strSrc = strSrc.split('/').pop();
|
156
|
-
if (strSrc == strImage) {
|
157
|
-
return true;
|
158
|
-
}
|
159
|
-
}
|
160
|
-
}
|
161
|
-
}
|
162
|
-
}
|
163
|
-
return false;
|
164
|
-
};
|
165
|
-
|
166
|
-
/**
|
167
|
-
* Shows animated GIF in the specified div.
|
168
|
-
*
|
169
|
-
* <pre>
|
170
|
-
* Arguments object format:
|
171
|
-
* {
|
172
|
-
* busyContainer: [object or string] element where to put animated GIF,
|
173
|
-
* busyImage: [string, optional] image name,
|
174
|
-
* busyImageWidth: [number or string, optional] image width,
|
175
|
-
* busyImageHeight: [number or string, optional] image height
|
176
|
-
* }
|
177
|
-
* </pre>
|
178
|
-
*
|
179
|
-
* @private
|
180
|
-
* @param {object} objArgs Arguments object
|
181
|
-
*/
|
182
|
-
Zapatec.Transport.showBusy = function(objArgs) {
|
183
|
-
// Make sure image is not displayed yet
|
184
|
-
if (Zapatec.Transport.isBusy(objArgs)) {
|
185
|
-
return;
|
186
|
-
}
|
187
|
-
// Get container
|
188
|
-
var objContainer = objArgs.busyContainer;
|
189
|
-
if (typeof objContainer == 'string') {
|
190
|
-
objContainer = document.getElementById(objContainer);
|
191
|
-
}
|
192
|
-
if (!objContainer) {
|
193
|
-
return;
|
194
|
-
}
|
195
|
-
// Get image name and dimensions
|
196
|
-
var strImage = objArgs.busyImage;
|
197
|
-
var strImageWidth = objArgs.busyImageWidth;
|
198
|
-
var strImageHeight = objArgs.busyImageHeight;
|
199
|
-
if (typeof strImage != 'string' || !strImage.length) {
|
200
|
-
strImage = 'zpbusy.gif';
|
201
|
-
} else {
|
202
|
-
if (typeof strImageWidth == 'number' ||
|
203
|
-
(typeof strImageWidth == 'string' && /\d$/.test(strImageWidth))) {
|
204
|
-
strImageWidth += 'px';
|
205
|
-
}
|
206
|
-
if (typeof strImageHeight == 'number' ||
|
207
|
-
(typeof strImageHeight == 'string' && /\d$/.test(strImageHeight))) {
|
208
|
-
strImageHeight += 'px';
|
209
|
-
}
|
210
|
-
}
|
211
|
-
if (!strImageWidth) {
|
212
|
-
strImageWidth = '65px';
|
213
|
-
}
|
214
|
-
if (!strImageHeight) {
|
215
|
-
strImageHeight = '35px';
|
216
|
-
}
|
217
|
-
// Get path
|
218
|
-
var strPath = '';
|
219
|
-
// Check if path is specified
|
220
|
-
if (strImage.indexOf('/') < 0) {
|
221
|
-
// Use default path
|
222
|
-
strPath = Zapatec.Transport.getPath('transport.js');
|
223
|
-
}
|
224
|
-
// Form tag
|
225
|
-
var arrImgTag = [];
|
226
|
-
arrImgTag.push('<img src="');
|
227
|
-
arrImgTag.push(strPath);
|
228
|
-
arrImgTag.push(strImage);
|
229
|
-
arrImgTag.push('"');
|
230
|
-
if (strImageWidth || strImageHeight) {
|
231
|
-
arrImgTag.push(' style="');
|
232
|
-
if (strImageWidth) {
|
233
|
-
arrImgTag.push('width:');
|
234
|
-
arrImgTag.push(strImageWidth);
|
235
|
-
arrImgTag.push(';');
|
236
|
-
}
|
237
|
-
if (strImageHeight) {
|
238
|
-
arrImgTag.push('height:');
|
239
|
-
arrImgTag.push(strImageHeight);
|
240
|
-
}
|
241
|
-
arrImgTag.push('"');
|
242
|
-
}
|
243
|
-
arrImgTag.push(' />');
|
244
|
-
strImgTag = arrImgTag.join('');
|
245
|
-
// Get container dimensions
|
246
|
-
var iContainerWidth = objContainer.offsetWidth;
|
247
|
-
var iContainerHeight = objContainer.offsetHeight;
|
248
|
-
// Display image
|
249
|
-
var objBusyContainer = Zapatec.Utils.createElement('div');
|
250
|
-
objBusyContainer.style.position = 'relative';
|
251
|
-
objBusyContainer.style.zIndex = 2147483583;
|
252
|
-
var objBusy = Zapatec.Utils.createElement('div', objBusyContainer);
|
253
|
-
objBusy.style.position = 'absolute';
|
254
|
-
objBusy.innerHTML = strImgTag;
|
255
|
-
if (objContainer.firstChild) {
|
256
|
-
objContainer.insertBefore(objBusyContainer, objContainer.firstChild);
|
257
|
-
} else {
|
258
|
-
objContainer.appendChild(objBusyContainer);
|
259
|
-
}
|
260
|
-
// Move to the center of container
|
261
|
-
var iBusyWidth = objBusy.offsetWidth;
|
262
|
-
var iBusyHeight = objBusy.offsetHeight;
|
263
|
-
if (iContainerWidth > iBusyWidth) {
|
264
|
-
objBusy.style.left = objContainer.scrollLeft +
|
265
|
-
(iContainerWidth - iBusyWidth) / 2 + 'px';
|
266
|
-
}
|
267
|
-
if (iContainerHeight > iBusyHeight) {
|
268
|
-
objBusy.style.top = objContainer.scrollTop +
|
269
|
-
(iContainerHeight - iBusyHeight) / 2 + 'px';
|
270
|
-
}
|
271
|
-
};
|
272
|
-
|
273
|
-
/**
|
274
|
-
* Removes animated GIF which was put by {@link Zapatec.Transport#showBusyGif}
|
275
|
-
* from the specified div.
|
276
|
-
*
|
277
|
-
* <pre>
|
278
|
-
* Arguments object format:
|
279
|
-
* {
|
280
|
-
* busyContainer: [object or string] element where to put animated GIF,
|
281
|
-
* busyImage: [string, optional] image name
|
282
|
-
* }
|
283
|
-
* </pre>
|
284
|
-
*
|
285
|
-
* @private
|
286
|
-
* @param {object} objArgs Arguments object
|
287
|
-
*/
|
288
|
-
Zapatec.Transport.removeBusy = function(objArgs) {
|
289
|
-
// Get container
|
290
|
-
var objContainer = objArgs.busyContainer;
|
291
|
-
if (typeof objContainer == 'string') {
|
292
|
-
objContainer = document.getElementById(objContainer);
|
293
|
-
}
|
294
|
-
if (!objContainer) {
|
295
|
-
return;
|
296
|
-
}
|
297
|
-
// Make sure image is displayed
|
298
|
-
if (Zapatec.Transport.isBusy(objArgs)) {
|
299
|
-
// Remove image
|
300
|
-
objContainer.removeChild(objContainer.firstChild);
|
301
|
-
}
|
302
|
-
};
|
303
|
-
|
304
|
-
/**
|
305
|
-
* Fetches specified URL using new XMLHttpRequest object.
|
306
|
-
*
|
307
|
-
* <pre>
|
308
|
-
* Asynchronous mode is recommended because it is safer and there is no risk of
|
309
|
-
* having your script hang in case of network problem. Synchronous mode means
|
310
|
-
* that the code will hang until a response comes back.
|
311
|
-
*
|
312
|
-
* When request is completed, one of provided callback functions is called:
|
313
|
-
* onLoad on success or onError on error. In synchronous mode onLoad callback
|
314
|
-
* can be omitted. Instead use returned object.
|
315
|
-
*
|
316
|
-
* onLoad callback function receives XMLHttpRequest object as argument and may
|
317
|
-
* use its various properties like responseText, responseXML, etc.
|
318
|
-
*
|
319
|
-
* onError callback function receives following object:
|
320
|
-
* {
|
321
|
-
* errorCode: server status number (404, etc.) [number],
|
322
|
-
* errorDescription: human readable error description [string]
|
323
|
-
* }
|
324
|
-
*
|
325
|
-
* Note: Some browsers implement caching for GET requests. Caching can be
|
326
|
-
* prevented by adding 'r=' + Math.random() parameter to URL.
|
327
|
-
*
|
328
|
-
* If you use POST method, content argument should be something like
|
329
|
-
* 'var1=value1&var2=value2' with urlencoded values. If you wish to send other
|
330
|
-
* content, set appropriate contentType. E.g. 'multipart/form-data', 'text/xml',
|
331
|
-
* etc.
|
332
|
-
*
|
333
|
-
* If server response contains non-ASCII characters, server must send
|
334
|
-
* corresponding content-type header. E.g.
|
335
|
-
* "Content-type: text/plain; charset=utf-8" or
|
336
|
-
* "Content-type: text/plain; charset=windows-1251".
|
337
|
-
*
|
338
|
-
* Arguments object format:
|
339
|
-
* {
|
340
|
-
* url: [string] relative or absolute URL to fetch,
|
341
|
-
* method: [string, optional] method ('GET', 'POST', 'HEAD', 'PUT'),
|
342
|
-
* async: [boolean, optional] use asynchronous mode (default: true),
|
343
|
-
* contentType: [string, optional] content type when using POST,
|
344
|
-
* content: [string or object, optional] postable string or DOM object data
|
345
|
-
* when using POST,
|
346
|
-
* onLoad: [function, optional] function reference to call on success,
|
347
|
-
* onError: [function, optional] function reference to call on error,
|
348
|
-
* username: [string, optional] username,
|
349
|
-
* password: [string, optional] password,
|
350
|
-
* busyContainer: [object or string, optional] element or id of element where
|
351
|
-
* to put "Busy" animated GIF,
|
352
|
-
* busyImage: [string, optional] image name,
|
353
|
-
* busyImageWidth: [number or string, optional] image width,
|
354
|
-
* busyImageHeight: [number or string, optional] image height
|
355
|
-
* }
|
356
|
-
* </pre>
|
357
|
-
*
|
358
|
-
* @param {object} objArgs Arguments object
|
359
|
-
* @return In synchronous mode XMLHttpRequest object or null. In asynchronous
|
360
|
-
* mode always null.
|
361
|
-
* @type object
|
362
|
-
*/
|
363
|
-
Zapatec.Transport.fetch = function(objArgs) {
|
364
|
-
// Check arguments
|
365
|
-
if (objArgs == null || typeof objArgs != 'object') {
|
366
|
-
return null;
|
367
|
-
}
|
368
|
-
if (!objArgs.url) {
|
369
|
-
return null;
|
370
|
-
}
|
371
|
-
if (!objArgs.method) {
|
372
|
-
objArgs.method = 'GET';
|
373
|
-
}
|
374
|
-
if (typeof objArgs.async == 'undefined') {
|
375
|
-
objArgs.async = true;
|
376
|
-
}
|
377
|
-
if (!objArgs.contentType && objArgs.method.toUpperCase() == 'POST') {
|
378
|
-
objArgs.contentType = 'application/x-www-form-urlencoded';
|
379
|
-
}
|
380
|
-
if (!objArgs.content) {
|
381
|
-
objArgs.content = null;
|
382
|
-
}
|
383
|
-
if (!objArgs.onLoad) {
|
384
|
-
objArgs.onLoad = null;
|
385
|
-
}
|
386
|
-
if (!objArgs.onError) {
|
387
|
-
objArgs.onError = null;
|
388
|
-
}
|
389
|
-
// Request URL
|
390
|
-
var objRequest = Zapatec.Transport.createXmlHttpRequest();
|
391
|
-
if (objRequest == null) {
|
392
|
-
return null;
|
393
|
-
}
|
394
|
-
// Show "Busy" animated GIF
|
395
|
-
Zapatec.Transport.showBusy(objArgs);
|
396
|
-
// IE 6 calls onreadystatechange and then raises exception if local file was
|
397
|
-
// not found. This flag is used to prevent duplicate onError calls.
|
398
|
-
var boolErrorDisplayed = false;
|
399
|
-
// Onready handler
|
400
|
-
var funcOnReady = function () {
|
401
|
-
// Remove "Busy" animated GIF
|
402
|
-
Zapatec.Transport.removeBusy(objArgs);
|
403
|
-
// Process response
|
404
|
-
try {
|
405
|
-
if (objRequest.status == 200 || objRequest.status == 304 ||
|
406
|
-
(location.protocol == 'file:' && !objRequest.status)) {
|
407
|
-
// OK or found, but determined unchanged and loaded from cache
|
408
|
-
if (typeof objArgs.onLoad == 'function') {
|
409
|
-
objArgs.onLoad(objRequest);
|
410
|
-
}
|
411
|
-
} else if (!boolErrorDisplayed) {
|
412
|
-
boolErrorDisplayed = true;
|
413
|
-
// 404 Not found, etc.
|
414
|
-
Zapatec.Transport.displayError(objRequest.status,
|
415
|
-
"Error: Can't fetch " + objArgs.url + '.\n' +
|
416
|
-
(objRequest.statusText || ''),
|
417
|
-
objArgs.onError);
|
418
|
-
}
|
419
|
-
} catch (objException) {
|
420
|
-
// Firefox 1.5 raises exception on attempt to access any property of
|
421
|
-
// objRequest if URL was not found
|
422
|
-
if (!boolErrorDisplayed) {
|
423
|
-
boolErrorDisplayed = true;
|
424
|
-
if (objException.name &&
|
425
|
-
objException.name == 'NS_ERROR_NOT_AVAILABLE') {
|
426
|
-
Zapatec.Transport.displayError(0,
|
427
|
-
"Error: Can't fetch " + objArgs.url + '.\nFile not found.',
|
428
|
-
objArgs.onError);
|
429
|
-
} else {
|
430
|
-
Zapatec.Transport.displayError(0,
|
431
|
-
"Error: Can't fetch " + objArgs.url + '.\n' +
|
432
|
-
(objException.message || ''),
|
433
|
-
objArgs.onError);
|
434
|
-
}
|
435
|
-
}
|
436
|
-
};
|
437
|
-
};
|
438
|
-
try {
|
439
|
-
// Open request
|
440
|
-
if (typeof objArgs.username != 'undefined' &&
|
441
|
-
typeof objArgs.password != 'undefined') {
|
442
|
-
objRequest.open(objArgs.method, objArgs.url, objArgs.async,
|
443
|
-
objArgs.username, objArgs.password);
|
444
|
-
} else {
|
445
|
-
objRequest.open(objArgs.method, objArgs.url, objArgs.async);
|
446
|
-
}
|
447
|
-
// Prevent duplicate funcOnReady call in synchronous mode
|
448
|
-
if (objArgs.async) {
|
449
|
-
// Set onreadystatechange handler
|
450
|
-
objRequest.onreadystatechange = function () {
|
451
|
-
if (objRequest.readyState == 4) {
|
452
|
-
// Request complete
|
453
|
-
funcOnReady();
|
454
|
-
// Prevent memory leak
|
455
|
-
objRequest.onreadystatechange = {};
|
456
|
-
}
|
457
|
-
};
|
458
|
-
}
|
459
|
-
// Set content type if needed
|
460
|
-
if (objArgs.contentType) {
|
461
|
-
objRequest.setRequestHeader('Content-Type', objArgs.contentType);
|
462
|
-
}
|
463
|
-
// Send request
|
464
|
-
objRequest.send(objArgs.content);
|
465
|
-
// In synchronous mode the result is ready on the next line
|
466
|
-
if (!objArgs.async) {
|
467
|
-
funcOnReady();
|
468
|
-
return objRequest;
|
469
|
-
}
|
470
|
-
} catch (objException) {
|
471
|
-
// Remove "Busy" animated GIF
|
472
|
-
Zapatec.Transport.removeBusy(objArgs);
|
473
|
-
// Process error
|
474
|
-
if (!boolErrorDisplayed) {
|
475
|
-
boolErrorDisplayed = true;
|
476
|
-
if (objException.name &&
|
477
|
-
objException.name == 'NS_ERROR_FILE_NOT_FOUND') {
|
478
|
-
Zapatec.Transport.displayError(0,
|
479
|
-
"Error: Can't fetch " + objArgs.url + '.\nFile not found.',
|
480
|
-
objArgs.onError);
|
481
|
-
} else {
|
482
|
-
Zapatec.Transport.displayError(0,
|
483
|
-
"Error: Can't fetch " + objArgs.url + '.\n' +
|
484
|
-
(objException.message || ''),
|
485
|
-
objArgs.onError);
|
486
|
-
}
|
487
|
-
}
|
488
|
-
};
|
489
|
-
return null;
|
490
|
-
};
|
491
|
-
|
492
|
-
/**
|
493
|
-
* Parses HTML fragment into HTMLElement object.
|
494
|
-
*
|
495
|
-
* @param {string} strHtml HTML fragment
|
496
|
-
* @return Div element which contains parsed HTML fragment
|
497
|
-
* @type object
|
498
|
-
*/
|
499
|
-
Zapatec.Transport.parseHtml = function(strHtml) {
|
500
|
-
// Convert to string
|
501
|
-
strHtml += '';
|
502
|
-
// Remove leading whitespace characters because Firefox and Opera don't parse
|
503
|
-
// fragment that starts from whitespace character
|
504
|
-
strHtml = strHtml.replace(/^\s+/g, '');
|
505
|
-
// Create temporaty container
|
506
|
-
var objTempContainer = null;
|
507
|
-
if (document.createElementNS) {
|
508
|
-
// use the XHTML namespace
|
509
|
-
objTempContainer =
|
510
|
-
document.createElementNS('http://www.w3.org/1999/xhtml', 'div');
|
511
|
-
} else {
|
512
|
-
objTempContainer = document.createElement('div');
|
513
|
-
}
|
514
|
-
// Parse HTML fragment
|
515
|
-
objTempContainer.innerHTML = strHtml;
|
516
|
-
// Return container element
|
517
|
-
return objTempContainer;
|
518
|
-
};
|
519
|
-
|
520
|
-
/**
|
521
|
-
* Evaluates javascript in global scope.
|
522
|
-
*
|
523
|
-
* <p><b>
|
524
|
-
* Note: Global variables must be declared without "var" keyword. Otherwise
|
525
|
-
* they will be ignored by Safari.
|
526
|
-
* </b></p>
|
527
|
-
*
|
528
|
-
* @param {string} strScript Script to evaluate
|
529
|
-
*/
|
530
|
-
Zapatec.Transport.evalGlobalScope = function(strScript) {
|
531
|
-
if (typeof strScript != 'string' || !strScript.match(/\S/)) {
|
532
|
-
return;
|
533
|
-
}
|
534
|
-
if (window.execScript) {
|
535
|
-
// IE
|
536
|
-
window.execScript(strScript, 'javascript');
|
537
|
-
} else if (window.eval) {
|
538
|
-
// Others
|
539
|
-
window.eval(strScript);
|
540
|
-
/*
|
541
|
-
This should never be reached
|
542
|
-
} else {
|
543
|
-
var funcScript = new Function(strScript);
|
544
|
-
funcScript.call(window);
|
545
|
-
*/
|
546
|
-
}
|
547
|
-
};
|
548
|
-
|
549
|
-
/**
|
550
|
-
* Assigns passed HTML fragment to the specified element's innerHTML property
|
551
|
-
* and evaluates in global scope javascripts found in the fragment.
|
552
|
-
*
|
553
|
-
* <pre>
|
554
|
-
* Arguments object format:
|
555
|
-
* {
|
556
|
-
* html: [string] HTML fragment,
|
557
|
-
* container: [object or string, optional] element or id of element to put
|
558
|
-
* HTML fragment into
|
559
|
-
* }
|
560
|
-
* </pre>
|
561
|
-
*
|
562
|
-
* <p><b>
|
563
|
-
* Note: Scripts are executed after HTML fragment is assigned to innerHTML.
|
564
|
-
* If external scripts are used, they are loaded asynchronously and execution
|
565
|
-
* sequence is not preserved.
|
566
|
-
* </b></p>
|
567
|
-
*
|
568
|
-
* <p><b>
|
569
|
-
* Note: Global variables must be declared without "var" keyword. Otherwise
|
570
|
-
* they will be ignored by Safari.
|
571
|
-
* </b></p>
|
572
|
-
*
|
573
|
-
* @param {object} objArgs Arguments object
|
574
|
-
*/
|
575
|
-
Zapatec.Transport.setInnerHtml = function(objArgs) {
|
576
|
-
// Check arguments
|
577
|
-
if (!objArgs || typeof objArgs.html != 'string') {
|
578
|
-
return;
|
579
|
-
}
|
580
|
-
var strHtml = objArgs.html;
|
581
|
-
// Get container
|
582
|
-
var objContainer = null;
|
583
|
-
if (typeof objArgs.container == 'string') {
|
584
|
-
objContainer = document.getElementById(objArgs.container);
|
585
|
-
} else if (typeof objArgs.container == 'object') {
|
586
|
-
objContainer = objArgs.container;
|
587
|
-
}
|
588
|
-
// Extract javascripts
|
589
|
-
var arrScripts = [];
|
590
|
-
if (strHtml.match(/<\s*\/\s*script\s*>/i)) {
|
591
|
-
// Split whole string by </script>
|
592
|
-
var arrTokens = strHtml.split(/<\s*\/\s*script\s*>/i);
|
593
|
-
var arrHtml = [];
|
594
|
-
for (var iToken = arrTokens.length - 1; iToken >= 0; iToken--) {
|
595
|
-
var strToken = arrTokens[iToken];
|
596
|
-
if (strToken.match(/\S/)) {
|
597
|
-
// Search <script ... > in the middle of each token
|
598
|
-
var arrMatch = strToken.match(/<\s*script([^>]*)>/i);
|
599
|
-
if (arrMatch) {
|
600
|
-
// Separate HTML from javascript
|
601
|
-
var arrCouple = strToken.split(/<\s*script[^>]*>/i);
|
602
|
-
// IE doesn't put empty tokens into the array
|
603
|
-
while (arrCouple.length < 2) {
|
604
|
-
if (strToken.match(/^<\s*script[^>]*>/i)) {
|
605
|
-
// HTML part is absent
|
606
|
-
arrCouple.unshift('');
|
607
|
-
} else {
|
608
|
-
// javascript part is absent
|
609
|
-
arrCouple.push('');
|
610
|
-
}
|
611
|
-
}
|
612
|
-
// Save HTML fragment
|
613
|
-
arrHtml.unshift(arrCouple[0]);
|
614
|
-
// Get script attributes
|
615
|
-
var strAttrs = arrMatch[1];
|
616
|
-
// Get script text
|
617
|
-
var srtScript = arrCouple[1];
|
618
|
-
// Ignore script text if "src" attribute is present
|
619
|
-
if (strAttrs.match(/\s+src\s*=/i)) {
|
620
|
-
srtScript = '';
|
621
|
-
} else {
|
622
|
-
// Fix functions: function aaa() -> aaa = function()
|
623
|
-
srtScript = srtScript.replace(/function\s+([^(]+)/g, '$1=function');
|
624
|
-
}
|
625
|
-
arrScripts.push([strAttrs, srtScript]);
|
626
|
-
} else if (iToken < arrTokens.length - 1) {
|
627
|
-
// On error assume this token is a part of previous token
|
628
|
-
arrTokens[iToken - 1] += '</script>' + strToken;
|
629
|
-
} else {
|
630
|
-
// If this is last token, assume it is HTML fragment
|
631
|
-
arrHtml.unshift(strToken);
|
632
|
-
}
|
633
|
-
} else {
|
634
|
-
// Empty token
|
635
|
-
arrHtml.unshift(strToken);
|
636
|
-
}
|
637
|
-
}
|
638
|
-
// Get HTML part
|
639
|
-
strHtml = arrHtml.join('');
|
640
|
-
}
|
641
|
-
// Set inner HTML
|
642
|
-
if (objContainer) {
|
643
|
-
// Opera hack
|
644
|
-
if (window.opera) {
|
645
|
-
// Without this line Opera will not form correct DOM structure if HTML
|
646
|
-
// fragment contains forms
|
647
|
-
objContainer.innerHTML = '<form></form>';
|
648
|
-
}
|
649
|
-
objContainer.innerHTML = strHtml;
|
650
|
-
}
|
651
|
-
// Evaluate javascripts
|
652
|
-
for (var iScript = 0; iScript < arrScripts.length; iScript++) {
|
653
|
-
if (arrScripts[iScript][1].length) {
|
654
|
-
// Evaluate in global scope
|
655
|
-
Zapatec.Transport.evalGlobalScope(arrScripts[iScript][1]);
|
656
|
-
}
|
657
|
-
// Load external script
|
658
|
-
var strAttrs = arrScripts[iScript][0];
|
659
|
-
strAttrs = strAttrs.replace(/\s+/g, ' ').replace(/^\s/, '')
|
660
|
-
.replace(/\s$/, '').replace(/ = /g, '=');
|
661
|
-
if (strAttrs.indexOf('src=') >= 0) {
|
662
|
-
// Get container
|
663
|
-
var objContainer = document.body;
|
664
|
-
if (!objContainer) {
|
665
|
-
objContainer = document.getElementsByTagName('head')[0];
|
666
|
-
if (!objContainer) {
|
667
|
-
objContainer = document;
|
668
|
-
}
|
669
|
-
}
|
670
|
-
// Get attributes
|
671
|
-
var arrAttrs = strAttrs.split(' ');
|
672
|
-
// Load script
|
673
|
-
var objScript = Zapatec.Utils.createElement('script');
|
674
|
-
for (var iAttr = 0; iAttr < arrAttrs.length; iAttr++) {
|
675
|
-
var arrAttr = arrAttrs[iAttr].split('=');
|
676
|
-
if (arrAttr.length > 1) {
|
677
|
-
objScript.setAttribute(arrAttr[0],
|
678
|
-
arrAttr[1].match(/^[\s|"|']*([\s|\S]*[^'|"])[\s|"|']*$/)[1]);
|
679
|
-
} else {
|
680
|
-
objScript.setAttribute(arrAttr[0], arrAttr[0]);
|
681
|
-
}
|
682
|
-
}
|
683
|
-
// It's important for Safari to assign attributes before appending
|
684
|
-
objContainer.appendChild(objScript);
|
685
|
-
}
|
686
|
-
}
|
687
|
-
};
|
688
|
-
|
689
|
-
/**
|
690
|
-
* Fetches and parses XML document from the specified URL.
|
691
|
-
*
|
692
|
-
* <pre>
|
693
|
-
* When XML document is fetched and parsed, one of provided callback functions
|
694
|
-
* is called: onLoad on success or onError on error. In synchronous mode onLoad
|
695
|
-
* callback can be omitted. Instead use returned object.
|
696
|
-
*
|
697
|
-
* onLoad callback function receives XMLDocument object as argument and may use
|
698
|
-
* its documentElement and other properties.
|
699
|
-
*
|
700
|
-
* onError callback function receives following object:
|
701
|
-
* {
|
702
|
-
* errorCode: error code [number],
|
703
|
-
* errorDescription: human readable error description [string]
|
704
|
-
* }
|
705
|
-
* Error code will be 0 unless Zapatec.Transport.fetch was used to fetch URL
|
706
|
-
* and there was a problem during fetching.
|
707
|
-
*
|
708
|
-
* If method argument is not defined, more efficient XMLDOM in IE and
|
709
|
-
* document.implementation.createDocument in Mozilla will be used to fetch
|
710
|
-
* and parse document. Otherwise Zapatec.Transport.fetch will be used to fetch
|
711
|
-
* document and Zapatec.Transport.parseXml to parse.
|
712
|
-
*
|
713
|
-
* Note: Some browsers implement caching for GET requests. Caching can be
|
714
|
-
* prevented by adding 'r=' + Math.random() parameter to URL.
|
715
|
-
*
|
716
|
-
* If you use POST method, content argument should be something like
|
717
|
-
* 'var1=value1&var2=value'. If you wish to send other content, set appropriate
|
718
|
-
* contentType. E.g. to send XML string, you should set contentType: 'text/xml'.
|
719
|
-
*
|
720
|
-
* If server response contains non-ASCII characters, encoding must be specified.
|
721
|
-
* E.g. <?xml version="1.0" encoding="utf-8"?> or
|
722
|
-
* <?xml version="1.0" encoding="windows-1251"?>.
|
723
|
-
*
|
724
|
-
* If server response contains non-ASCII characters, server must send
|
725
|
-
* corresponding content-type header. E.g.
|
726
|
-
* "Content-type: text/xml; charset=utf-8" or
|
727
|
-
* "Content-type: text/xml; charset=windows-1251".
|
728
|
-
*
|
729
|
-
* Arguments object format:
|
730
|
-
* {
|
731
|
-
* url: [string] relative or absolute URL to fetch,
|
732
|
-
* method: [string, optional] method ('GET', 'POST', 'HEAD', 'PUT'),
|
733
|
-
* async: [boolean, optional] use asynchronous mode (default: true),
|
734
|
-
* contentType: [string, optional] content type when using POST,
|
735
|
-
* content: [string or object, optional] postable string or DOM object data
|
736
|
-
* when using POST,
|
737
|
-
* onLoad: [function, optional] function reference to call on success,
|
738
|
-
* onError: [function, optional] function reference to call on error,
|
739
|
-
* username: [string, optional] username,
|
740
|
-
* password: [string, optional] password,
|
741
|
-
* busyContainer: [object or string, optional] element or id of element where
|
742
|
-
* to put "Busy" animated GIF,
|
743
|
-
* busyImage: [string, optional] image name,
|
744
|
-
* busyImageWidth: [number or string, optional] image width,
|
745
|
-
* busyImageHeight: [number or string, optional] image height
|
746
|
-
* }
|
747
|
-
* </pre>
|
748
|
-
*
|
749
|
-
* @param {object} objArgs Arguments object
|
750
|
-
* @return In synchronous mode XMLDocument object or null. In asynchronous mode
|
751
|
-
* always null.
|
752
|
-
* @type object
|
753
|
-
*/
|
754
|
-
Zapatec.Transport.fetchXmlDoc = function(objArgs) {
|
755
|
-
// Check arguments
|
756
|
-
if (objArgs == null || typeof objArgs != 'object') {
|
757
|
-
return null;
|
758
|
-
}
|
759
|
-
if (!objArgs.url) {
|
760
|
-
return null;
|
761
|
-
}
|
762
|
-
if (typeof objArgs.async == 'undefined') {
|
763
|
-
objArgs.async = true;
|
764
|
-
}
|
765
|
-
if (!objArgs.onLoad) {
|
766
|
-
objArgs.onLoad = null;
|
767
|
-
}
|
768
|
-
if (!objArgs.onError) {
|
769
|
-
objArgs.onError = null;
|
770
|
-
}
|
771
|
-
// Try more efficient methods first
|
772
|
-
if (!objArgs.method && typeof objArgs.username == 'undefined' &&
|
773
|
-
typeof objArgs.password == 'undefined') {
|
774
|
-
if (document.implementation && document.implementation.createDocument) {
|
775
|
-
// Mozilla
|
776
|
-
var objDocument = null;
|
777
|
-
|
778
|
-
if (!objArgs.reliable) {
|
779
|
-
objArgs.reliable = false;
|
780
|
-
}
|
781
|
-
// Form argument for fetch
|
782
|
-
var objFetchArgs = {};
|
783
|
-
for (var strKey in objArgs) {
|
784
|
-
objFetchArgs[strKey] = objArgs[strKey];
|
785
|
-
}
|
786
|
-
// Prevent duplicate parseXml call in synchronous mode
|
787
|
-
if (objArgs.async) {
|
788
|
-
objFetchArgs.onLoad = function(objRequest) {
|
789
|
-
// Prevent onload being called more than once
|
790
|
-
objFetchArgs.onLoad = null;
|
791
|
-
|
792
|
-
// Parse xml response string
|
793
|
-
var parser = new DOMParser();
|
794
|
-
objDocument = parser.parseFromString(objRequest.responseText, "text/xml");
|
795
|
-
|
796
|
-
// Remove "Busy" animated GIF
|
797
|
-
Zapatec.Transport.removeBusy(objArgs);
|
798
|
-
// Process response
|
799
|
-
Zapatec.Transport.onXmlDocLoad(objDocument, objArgs.onLoad,
|
800
|
-
objArgs.onError);
|
801
|
-
};
|
802
|
-
} else {
|
803
|
-
objFetchArgs.onLoad = null;
|
804
|
-
}
|
805
|
-
// Fetch URL
|
806
|
-
var objRequest = Zapatec.Transport.fetch(objFetchArgs);
|
807
|
-
// In synchronous mode the result is ready on the next line
|
808
|
-
if (!objArgs.async && objRequest) {
|
809
|
-
// Parse xml response string
|
810
|
-
var parser = new DOMParser();
|
811
|
-
objDocument = parser.parseFromString(objRequest.responseText, "text/xml");
|
812
|
-
|
813
|
-
// Remove "Busy" animated GIF
|
814
|
-
Zapatec.Transport.removeBusy(objArgs);
|
815
|
-
// Process response
|
816
|
-
Zapatec.Transport.onXmlDocLoad(objDocument, objArgs.onLoad,
|
817
|
-
objArgs.onError);
|
818
|
-
|
819
|
-
return objDocument;
|
820
|
-
}
|
821
|
-
}
|
822
|
-
if (typeof ActiveXObject != 'undefined') {
|
823
|
-
// IE
|
824
|
-
// Show "Busy" animated GIF
|
825
|
-
Zapatec.Transport.showBusy(objArgs);
|
826
|
-
// Load document
|
827
|
-
try {
|
828
|
-
var objDocument = new ActiveXObject(Zapatec.Transport.XMLDOM);
|
829
|
-
objDocument.async = objArgs.async;
|
830
|
-
// Prevent duplicate onXmlDocLoad call in synchronous mode
|
831
|
-
if (objArgs.async) {
|
832
|
-
objDocument.onreadystatechange = function () {
|
833
|
-
if (objDocument.readyState == 4) {
|
834
|
-
// Remove "Busy" animated GIF
|
835
|
-
Zapatec.Transport.removeBusy(objArgs);
|
836
|
-
// Process response
|
837
|
-
Zapatec.Transport.onXmlDocLoad(objDocument, objArgs.onLoad,
|
838
|
-
objArgs.onError);
|
839
|
-
// Prevent memory leak
|
840
|
-
objDocument.onreadystatechange = {};
|
841
|
-
}
|
842
|
-
};
|
843
|
-
}
|
844
|
-
objDocument.load(objArgs.url);
|
845
|
-
// In synchronous mode the result is ready on the next line
|
846
|
-
if (!objArgs.async) {
|
847
|
-
// Remove "Busy" animated GIF
|
848
|
-
Zapatec.Transport.removeBusy(objArgs);
|
849
|
-
// Process response
|
850
|
-
Zapatec.Transport.onXmlDocLoad(objDocument, objArgs.onLoad,
|
851
|
-
objArgs.onError);
|
852
|
-
return objDocument;
|
853
|
-
}
|
854
|
-
return null;
|
855
|
-
} catch (objException) {
|
856
|
-
// Remove "Busy" animated GIF
|
857
|
-
Zapatec.Transport.removeBusy(objArgs);
|
858
|
-
};
|
859
|
-
}
|
860
|
-
}
|
861
|
-
// Try XMLHttpRequest
|
862
|
-
// Form argument for fetch
|
863
|
-
var objFetchArgs = {};
|
864
|
-
for (var strKey in objArgs) {
|
865
|
-
objFetchArgs[strKey] = objArgs[strKey];
|
866
|
-
}
|
867
|
-
// Prevent duplicate parseXml call in synchronous mode
|
868
|
-
if (objArgs.async) {
|
869
|
-
objFetchArgs.onLoad = function(objRequest) {
|
870
|
-
Zapatec.Transport.parseXml({
|
871
|
-
strXml: objRequest.responseText,
|
872
|
-
onLoad: objArgs.onLoad,
|
873
|
-
onError: objArgs.onError
|
874
|
-
});
|
875
|
-
};
|
876
|
-
} else {
|
877
|
-
objFetchArgs.onLoad = null;
|
878
|
-
}
|
879
|
-
// Fetch URL
|
880
|
-
var objRequest = Zapatec.Transport.fetch(objFetchArgs);
|
881
|
-
// In synchronous mode the result is ready on the next line
|
882
|
-
if (!objArgs.async && objRequest) {
|
883
|
-
return Zapatec.Transport.parseXml({
|
884
|
-
strXml: objRequest.responseText,
|
885
|
-
onLoad: objArgs.onLoad,
|
886
|
-
onError: objArgs.onError
|
887
|
-
});
|
888
|
-
}
|
889
|
-
return null;
|
890
|
-
};
|
891
|
-
|
892
|
-
/**
|
893
|
-
* Parses XML string into XMLDocument object.
|
894
|
-
*
|
895
|
-
* <pre>
|
896
|
-
* When XML string is parsed, one of provided callback functions is called:
|
897
|
-
* onLoad on success or onError on error. In synchronous mode onLoad callback
|
898
|
-
* can be omitted. Instead use returned object.
|
899
|
-
*
|
900
|
-
* onLoad callback function receives XMLDocument object as argument and may use
|
901
|
-
* its documentElement and other properties.
|
902
|
-
*
|
903
|
-
* onError callback function receives following object:
|
904
|
-
* {
|
905
|
-
* errorCode: error code [number],
|
906
|
-
* errorDescription: human readable error description [string]
|
907
|
-
* }
|
908
|
-
* Error code will be always 0.
|
909
|
-
*
|
910
|
-
* Returns XMLDocument object, so onLoad callback function is optional.
|
911
|
-
* Returned value and its documentElement property should be checked before
|
912
|
-
* use because they can be null or undefined.
|
913
|
-
*
|
914
|
-
* If XML string contains non-ASCII characters, encoding must be specified.
|
915
|
-
* E.g. <?xml version="1.0" encoding="utf-8"?> or
|
916
|
-
* <?xml version="1.0" encoding="windows-1251"?>.
|
917
|
-
*
|
918
|
-
* Arguments object format:
|
919
|
-
* {
|
920
|
-
* strXml: XML string to parse [string],
|
921
|
-
* onLoad: function reference to call on success [function] (optional),
|
922
|
-
* onError: function reference to call on error [function] (optional)
|
923
|
-
* }
|
924
|
-
* </pre>
|
925
|
-
*
|
926
|
-
* @param {object} objArgs Arguments object
|
927
|
-
* @return XMLDocument object or null
|
928
|
-
* @type object
|
929
|
-
*/
|
930
|
-
Zapatec.Transport.parseXml = function(objArgs) {
|
931
|
-
if (objArgs == null || typeof objArgs != 'object') {
|
932
|
-
return null;
|
933
|
-
}
|
934
|
-
if (!objArgs.strXml) {
|
935
|
-
return null;
|
936
|
-
}
|
937
|
-
if (!objArgs.onLoad) {
|
938
|
-
objArgs.onLoad = null;
|
939
|
-
}
|
940
|
-
if (!objArgs.onError) {
|
941
|
-
objArgs.onError = null;
|
942
|
-
}
|
943
|
-
if (window.DOMParser) {
|
944
|
-
// Mozilla
|
945
|
-
try {
|
946
|
-
var objDocument = (new DOMParser()).parseFromString(objArgs.strXml,
|
947
|
-
'text/xml');
|
948
|
-
Zapatec.Transport.onXmlDocLoad(objDocument, objArgs.onLoad,
|
949
|
-
objArgs.onError);
|
950
|
-
return objDocument;
|
951
|
-
} catch (objException) {
|
952
|
-
Zapatec.Transport.displayError(0,
|
953
|
-
"Error: Can't parse.\n" +
|
954
|
-
'String does not appear to be a valid XML fragment.',
|
955
|
-
objArgs.onError);
|
956
|
-
};
|
957
|
-
return null;
|
958
|
-
}
|
959
|
-
if (typeof ActiveXObject != 'undefined') {
|
960
|
-
// IE
|
961
|
-
try {
|
962
|
-
var objDocument = new ActiveXObject(Zapatec.Transport.XMLDOM);
|
963
|
-
objDocument.loadXML(objArgs.strXml);
|
964
|
-
Zapatec.Transport.onXmlDocLoad(objDocument, objArgs.onLoad,
|
965
|
-
objArgs.onError);
|
966
|
-
return objDocument;
|
967
|
-
} catch (objException) {};
|
968
|
-
}
|
969
|
-
return null;
|
970
|
-
};
|
971
|
-
|
972
|
-
/**
|
973
|
-
* Checks if there were errors during XML document fetching and parsing and
|
974
|
-
* calls onLoad or onError callback function correspondingly.
|
975
|
-
*
|
976
|
-
* @private
|
977
|
-
* @param {object} objDocument XMLDocument object
|
978
|
-
* @param {function} onLoad Callback function provided by user
|
979
|
-
* @param {function} onError Callback function provided by user
|
980
|
-
*/
|
981
|
-
Zapatec.Transport.onXmlDocLoad = function(objDocument, onLoad, onError) {
|
982
|
-
var strError = null;
|
983
|
-
if (objDocument.parseError) {
|
984
|
-
// Parsing error in IE
|
985
|
-
strError = objDocument.parseError.reason;
|
986
|
-
if (objDocument.parseError.srcText) {
|
987
|
-
strError += 'Location: ' + objDocument.parseError.url +
|
988
|
-
'\nLine number ' + objDocument.parseError.line + ', column ' +
|
989
|
-
objDocument.parseError.linepos + ':\n' +
|
990
|
-
objDocument.parseError.srcText + '\n';
|
991
|
-
}
|
992
|
-
} else if (objDocument.documentElement &&
|
993
|
-
objDocument.documentElement.tagName == 'parsererror') {
|
994
|
-
// If an error is caused while parsing, Mozilla doesn't throw an exception.
|
995
|
-
// Instead, it creates an XML string containing the details of the error:
|
996
|
-
// <parsererror xmlns="http://www.w3.org/1999/xhtml">XML Parsing Error: ...
|
997
|
-
// Check if strings has been generated.
|
998
|
-
strError = objDocument.documentElement.firstChild.data + '\n' +
|
999
|
-
objDocument.documentElement.firstChild.nextSibling.firstChild.data;
|
1000
|
-
} else if (!objDocument.documentElement) {
|
1001
|
-
strError = 'String does not appear to be a valid XML fragment.';
|
1002
|
-
}
|
1003
|
-
if (strError) {
|
1004
|
-
// Parsing error
|
1005
|
-
Zapatec.Transport.displayError(0,
|
1006
|
-
"Error: Can't parse.\n" + strError,
|
1007
|
-
onError);
|
1008
|
-
} else {
|
1009
|
-
// Success
|
1010
|
-
if (typeof onLoad == 'function') {
|
1011
|
-
onLoad(objDocument);
|
1012
|
-
}
|
1013
|
-
}
|
1014
|
-
};
|
1015
|
-
|
1016
|
-
/**
|
1017
|
-
* Serializes XMLDocument object into XML string.
|
1018
|
-
*
|
1019
|
-
* @param {object} objDocument XMLDocument object
|
1020
|
-
* @return XML string
|
1021
|
-
* @type string
|
1022
|
-
*/
|
1023
|
-
Zapatec.Transport.serializeXmlDoc = function(objDocument) {
|
1024
|
-
if (window.XMLSerializer) {
|
1025
|
-
// Mozilla
|
1026
|
-
return (new XMLSerializer).serializeToString(objDocument);
|
1027
|
-
}
|
1028
|
-
if (objDocument.xml) {
|
1029
|
-
// IE
|
1030
|
-
return objDocument.xml;
|
1031
|
-
}
|
1032
|
-
};
|
1033
|
-
|
1034
|
-
/**
|
1035
|
-
* Fetches and parses JSON object from the specified URL.
|
1036
|
-
*
|
1037
|
-
* <pre>
|
1038
|
-
* When JSON object is fetched and parsed, one of provided callback functions
|
1039
|
-
* is called: onLoad on success or onError on error. In synchronous mode onLoad
|
1040
|
-
* callback can be omitted. Instead use returned object.
|
1041
|
-
*
|
1042
|
-
* onLoad callback function receives JSON object as argument.
|
1043
|
-
*
|
1044
|
-
* onError callback function receives following object:
|
1045
|
-
* {
|
1046
|
-
* errorCode: error code [number],
|
1047
|
-
* errorDescription: human readable error description [string]
|
1048
|
-
* }
|
1049
|
-
* Error code will be 0 unless there was a problem during fetching.
|
1050
|
-
*
|
1051
|
-
* Note: Some browsers implement caching for GET requests. Caching can be
|
1052
|
-
* prevented by adding 'r=' + Math.random() parameter to URL.
|
1053
|
-
*
|
1054
|
-
* If you use POST method, content argument should be something like
|
1055
|
-
* 'var1=value1&var2=value'. If you wish to send other content, set appropriate
|
1056
|
-
* contentType. E.g. to send XML string, you should set contentType: 'text/xml'.
|
1057
|
-
*
|
1058
|
-
* If server response contains non-ASCII characters, server must send
|
1059
|
-
* corresponding content-type header. E.g.
|
1060
|
-
* "Content-type: text/plain; charset=utf-8" or
|
1061
|
-
* "Content-type: text/plain; charset=windows-1251".
|
1062
|
-
*
|
1063
|
-
* Arguments object format:
|
1064
|
-
* {
|
1065
|
-
* url: [string] relative or absolute URL to fetch,
|
1066
|
-
* reliable: [boolean, optional] false (string will be parsed) or true
|
1067
|
-
* (evaluated) (default: false),
|
1068
|
-
* method: [string, optional] method ('GET', 'POST', 'HEAD', 'PUT'),
|
1069
|
-
* async: [boolean, optional] use asynchronous mode (default: true),
|
1070
|
-
* contentType: [string, optional] content type when using POST,
|
1071
|
-
* content: [string or object, optional] postable string or DOM object data
|
1072
|
-
* when using POST,
|
1073
|
-
* onLoad: [function, optional] function reference to call on success,
|
1074
|
-
* onError: [function, optional] function reference to call on error,
|
1075
|
-
* username: [string, optional] username,
|
1076
|
-
* password: [string, optional] password,
|
1077
|
-
* busyContainer: [object or string, optional] element or id of element where
|
1078
|
-
* to put "Busy" animated GIF,
|
1079
|
-
* busyImage: [string, optional] image name,
|
1080
|
-
* busyImageWidth: [number or string, optional] image width,
|
1081
|
-
* busyImageHeight: [number or string, optional] image height
|
1082
|
-
* }
|
1083
|
-
* </pre>
|
1084
|
-
*
|
1085
|
-
* @param {object} objArgs Arguments object
|
1086
|
-
* @return In synchronous mode JSON object or null. In asynchronous mode always
|
1087
|
-
* null.
|
1088
|
-
* @type object
|
1089
|
-
*/
|
1090
|
-
Zapatec.Transport.fetchJsonObj = function(objArgs) {
|
1091
|
-
// Check arguments
|
1092
|
-
if (objArgs == null || typeof objArgs != 'object') {
|
1093
|
-
return null;
|
1094
|
-
}
|
1095
|
-
if (!objArgs.url) {
|
1096
|
-
return null;
|
1097
|
-
}
|
1098
|
-
if (typeof objArgs.async == 'undefined') {
|
1099
|
-
objArgs.async = true;
|
1100
|
-
}
|
1101
|
-
if (!objArgs.reliable) {
|
1102
|
-
objArgs.reliable = false;
|
1103
|
-
}
|
1104
|
-
// Form argument for fetch
|
1105
|
-
var objFetchArgs = {};
|
1106
|
-
for (var strKey in objArgs) {
|
1107
|
-
objFetchArgs[strKey] = objArgs[strKey];
|
1108
|
-
}
|
1109
|
-
// Prevent duplicate parseXml call in synchronous mode
|
1110
|
-
if (objArgs.async) {
|
1111
|
-
objFetchArgs.onLoad = function(objRequest) {
|
1112
|
-
Zapatec.Transport.parseJson({
|
1113
|
-
strJson: objRequest.responseText,
|
1114
|
-
reliable: objArgs.reliable,
|
1115
|
-
onLoad: objArgs.onLoad,
|
1116
|
-
onError: objArgs.onError
|
1117
|
-
});
|
1118
|
-
};
|
1119
|
-
} else {
|
1120
|
-
objFetchArgs.onLoad = null;
|
1121
|
-
}
|
1122
|
-
// Fetch URL
|
1123
|
-
var objRequest = Zapatec.Transport.fetch(objFetchArgs);
|
1124
|
-
// In synchronous mode the result is ready on the next line
|
1125
|
-
if (!objArgs.async && objRequest) {
|
1126
|
-
return Zapatec.Transport.parseJson({
|
1127
|
-
strJson: objRequest.responseText,
|
1128
|
-
reliable: objArgs.reliable,
|
1129
|
-
onLoad: objArgs.onLoad,
|
1130
|
-
onError: objArgs.onError
|
1131
|
-
});
|
1132
|
-
}
|
1133
|
-
return null;
|
1134
|
-
};
|
1135
|
-
|
1136
|
-
/**
|
1137
|
-
* Parses JSON string into object.
|
1138
|
-
*
|
1139
|
-
* <pre>
|
1140
|
-
* When JSON string is parsed, one of provided callback functions is called:
|
1141
|
-
* onLoad on success or onError on error.
|
1142
|
-
*
|
1143
|
-
* onLoad callback function receives JSON object as argument.
|
1144
|
-
*
|
1145
|
-
* onError callback function receives following object:
|
1146
|
-
* {
|
1147
|
-
* errorCode: error code [number],
|
1148
|
-
* errorDescription: human readable error description [string]
|
1149
|
-
* }
|
1150
|
-
* Error code will be always 0.
|
1151
|
-
*
|
1152
|
-
* Returns JSON object, so onLoad callback function is optional.
|
1153
|
-
* Returned value should be checked before use because it can be null.
|
1154
|
-
*
|
1155
|
-
* Arguments object format:
|
1156
|
-
* {
|
1157
|
-
* strJson: JSON string to parse [string],
|
1158
|
-
* reliable: false (string will be parsed) or true (evaluated) [boolean]
|
1159
|
-
* (optional, false by default),
|
1160
|
-
* onLoad: function reference to call on success [function] (optional),
|
1161
|
-
* onError: function reference to call on error [function] (optional)
|
1162
|
-
* }
|
1163
|
-
* </pre>
|
1164
|
-
*
|
1165
|
-
* @param {object} objArgs Arguments object
|
1166
|
-
* @return JSON object or null
|
1167
|
-
* @type object
|
1168
|
-
*/
|
1169
|
-
Zapatec.Transport.parseJson = function(objArgs) {
|
1170
|
-
if (objArgs == null || typeof objArgs != 'object') {
|
1171
|
-
return null;
|
1172
|
-
}
|
1173
|
-
if (!objArgs.reliable) {
|
1174
|
-
objArgs.reliable = false;
|
1175
|
-
}
|
1176
|
-
if (!objArgs.onLoad) {
|
1177
|
-
objArgs.onLoad = null;
|
1178
|
-
}
|
1179
|
-
if (!objArgs.onError) {
|
1180
|
-
objArgs.onError = null;
|
1181
|
-
}
|
1182
|
-
var objJson = null;
|
1183
|
-
try {
|
1184
|
-
if (objArgs.reliable) {
|
1185
|
-
if (objArgs.strJson) {
|
1186
|
-
objJson = eval('(' + objArgs.strJson + ')');
|
1187
|
-
}
|
1188
|
-
} else {
|
1189
|
-
objJson = Zapatec.Transport.parseJsonStr(objArgs.strJson);
|
1190
|
-
}
|
1191
|
-
} catch (objException) {
|
1192
|
-
var strError =
|
1193
|
-
"Error: Can't parse.\nString doesn't appear to be a valid JSON fragment: ";
|
1194
|
-
strError += objException.message;
|
1195
|
-
if (typeof objException.text != 'undefined' && objException.text.length) {
|
1196
|
-
strError += '\n' + objException.text;
|
1197
|
-
}
|
1198
|
-
strError += '\n' + objArgs.strJson;
|
1199
|
-
Zapatec.Transport.displayError(0, strError, objArgs.onError);
|
1200
|
-
};
|
1201
|
-
if (typeof objArgs.onLoad == 'function') {
|
1202
|
-
objArgs.onLoad(objJson);
|
1203
|
-
}
|
1204
|
-
return objJson;
|
1205
|
-
};
|
1206
|
-
|
1207
|
-
/**
|
1208
|
-
* Parses JSON string into object.
|
1209
|
-
*
|
1210
|
-
* <pre>
|
1211
|
-
* Was taken with changes from http://json.org/json.js.
|
1212
|
-
*
|
1213
|
-
* Throws exception if parsing error occurs.
|
1214
|
-
*
|
1215
|
-
* JSON format is described at http://json.org/js.html.
|
1216
|
-
* </pre>
|
1217
|
-
*
|
1218
|
-
* @private
|
1219
|
-
* @param {string} text JSON string to parse
|
1220
|
-
* @return JSON object
|
1221
|
-
* @type object
|
1222
|
-
*/
|
1223
|
-
Zapatec.Transport.parseJsonStr = function(text) {
|
1224
|
-
var p = /^\s*(([,:{}\[\]])|"(\\.|[^\x00-\x1f"\\])*"|-?\d+(\.\d*)?([eE][+-]?\d+)?|true|false|null)\s*/,
|
1225
|
-
token,
|
1226
|
-
operator;
|
1227
|
-
function error(m, t) {
|
1228
|
-
throw {
|
1229
|
-
name: 'JSONError',
|
1230
|
-
message: m,
|
1231
|
-
text: t || operator || token
|
1232
|
-
};
|
1233
|
-
}
|
1234
|
-
function next(b) {
|
1235
|
-
if (b && b != operator) {
|
1236
|
-
error("Expected '" + b + "'");
|
1237
|
-
}
|
1238
|
-
if (text) {
|
1239
|
-
var t = p.exec(text);
|
1240
|
-
if (t) {
|
1241
|
-
if (t[2]) {
|
1242
|
-
token = null;
|
1243
|
-
operator = t[2];
|
1244
|
-
} else {
|
1245
|
-
operator = null;
|
1246
|
-
try {
|
1247
|
-
token = eval(t[1]);
|
1248
|
-
} catch (e) {
|
1249
|
-
error("Bad token", t[1]);
|
1250
|
-
}
|
1251
|
-
}
|
1252
|
-
text = text.substring(t[0].length);
|
1253
|
-
} else {
|
1254
|
-
error("Unrecognized token", text);
|
1255
|
-
}
|
1256
|
-
} else {
|
1257
|
-
// undefined changed to null because it is not supported in IE 5.0
|
1258
|
-
token = operator = null;
|
1259
|
-
}
|
1260
|
-
}
|
1261
|
-
function val() {
|
1262
|
-
var k, o;
|
1263
|
-
switch (operator) {
|
1264
|
-
case '{':
|
1265
|
-
next('{');
|
1266
|
-
o = {};
|
1267
|
-
if (operator != '}') {
|
1268
|
-
for (;;) {
|
1269
|
-
if (operator || typeof token != 'string') {
|
1270
|
-
error("Missing key");
|
1271
|
-
}
|
1272
|
-
k = token;
|
1273
|
-
next();
|
1274
|
-
next(':');
|
1275
|
-
o[k] = val();
|
1276
|
-
if (operator != ',') {
|
1277
|
-
break;
|
1278
|
-
}
|
1279
|
-
next(',');
|
1280
|
-
}
|
1281
|
-
}
|
1282
|
-
next('}');
|
1283
|
-
return o;
|
1284
|
-
case '[':
|
1285
|
-
next('[');
|
1286
|
-
o = [];
|
1287
|
-
if (operator != ']') {
|
1288
|
-
for (;;) {
|
1289
|
-
o.push(val());
|
1290
|
-
if (operator != ',') {
|
1291
|
-
break;
|
1292
|
-
}
|
1293
|
-
next(',');
|
1294
|
-
}
|
1295
|
-
}
|
1296
|
-
next(']');
|
1297
|
-
return o;
|
1298
|
-
default:
|
1299
|
-
if (operator !== null) {
|
1300
|
-
error("Missing value");
|
1301
|
-
}
|
1302
|
-
k = token;
|
1303
|
-
next();
|
1304
|
-
return k;
|
1305
|
-
}
|
1306
|
-
}
|
1307
|
-
next();
|
1308
|
-
return val();
|
1309
|
-
};
|
1310
|
-
|
1311
|
-
/**
|
1312
|
-
* Serializes JSON object into JSON string.
|
1313
|
-
*
|
1314
|
-
* Was taken with changes from http://json.org/json.js.
|
1315
|
-
*
|
1316
|
-
* @param {object} v JSON object
|
1317
|
-
* @return JSON string
|
1318
|
-
* @type string
|
1319
|
-
*/
|
1320
|
-
Zapatec.Transport.serializeJsonObj = function(v) {
|
1321
|
-
var a = [];
|
1322
|
-
/*
|
1323
|
-
Emit a string.
|
1324
|
-
*/
|
1325
|
-
function e(s) {
|
1326
|
-
a[a.length] = s;
|
1327
|
-
}
|
1328
|
-
/*
|
1329
|
-
Convert a value.
|
1330
|
-
*/
|
1331
|
-
function g(x) {
|
1332
|
-
var c, i, l, v;
|
1333
|
-
switch (typeof x) {
|
1334
|
-
case 'object':
|
1335
|
-
if (x) {
|
1336
|
-
if (x instanceof Array) {
|
1337
|
-
e('[');
|
1338
|
-
l = a.length;
|
1339
|
-
for (i = 0; i < x.length; i += 1) {
|
1340
|
-
v = x[i];
|
1341
|
-
if (typeof v != 'undefined' &&
|
1342
|
-
typeof v != 'function') {
|
1343
|
-
if (l < a.length) {
|
1344
|
-
e(',');
|
1345
|
-
}
|
1346
|
-
g(v);
|
1347
|
-
}
|
1348
|
-
}
|
1349
|
-
e(']');
|
1350
|
-
return;
|
1351
|
-
} else if (typeof x.toString != 'undefined') {
|
1352
|
-
e('{');
|
1353
|
-
l = a.length;
|
1354
|
-
for (i in x) {
|
1355
|
-
v = x[i];
|
1356
|
-
if (x.hasOwnProperty(i) &&
|
1357
|
-
typeof v != 'undefined' &&
|
1358
|
-
typeof v != 'function') {
|
1359
|
-
if (l < a.length) {
|
1360
|
-
e(',');
|
1361
|
-
}
|
1362
|
-
g(i);
|
1363
|
-
e(':');
|
1364
|
-
g(v);
|
1365
|
-
}
|
1366
|
-
}
|
1367
|
-
return e('}');
|
1368
|
-
}
|
1369
|
-
}
|
1370
|
-
e('null');
|
1371
|
-
return;
|
1372
|
-
case 'number':
|
1373
|
-
e(isFinite(x) ? +x : 'null');
|
1374
|
-
return;
|
1375
|
-
case 'string':
|
1376
|
-
l = x.length;
|
1377
|
-
e('"');
|
1378
|
-
for (i = 0; i < l; i += 1) {
|
1379
|
-
c = x.charAt(i);
|
1380
|
-
if (c >= ' ') {
|
1381
|
-
if (c == '\\' || c == '"') {
|
1382
|
-
e('\\');
|
1383
|
-
}
|
1384
|
-
e(c);
|
1385
|
-
} else {
|
1386
|
-
switch (c) {
|
1387
|
-
case '\b':
|
1388
|
-
e('\\b');
|
1389
|
-
break;
|
1390
|
-
case '\f':
|
1391
|
-
e('\\f');
|
1392
|
-
break;
|
1393
|
-
case '\n':
|
1394
|
-
e('\\n');
|
1395
|
-
break;
|
1396
|
-
case '\r':
|
1397
|
-
e('\\r');
|
1398
|
-
break;
|
1399
|
-
case '\t':
|
1400
|
-
e('\\t');
|
1401
|
-
break;
|
1402
|
-
default:
|
1403
|
-
c = c.charCodeAt();
|
1404
|
-
e('\\u00' + Math.floor(c / 16).toString(16) +
|
1405
|
-
(c % 16).toString(16));
|
1406
|
-
}
|
1407
|
-
}
|
1408
|
-
}
|
1409
|
-
e('"');
|
1410
|
-
return;
|
1411
|
-
case 'boolean':
|
1412
|
-
e(String(x));
|
1413
|
-
return;
|
1414
|
-
default:
|
1415
|
-
e('null');
|
1416
|
-
return;
|
1417
|
-
}
|
1418
|
-
}
|
1419
|
-
g(v);
|
1420
|
-
return a.join('');
|
1421
|
-
};
|
1422
|
-
|
1423
|
-
/**
|
1424
|
-
* Displays error message.
|
1425
|
-
*
|
1426
|
-
* <pre>
|
1427
|
-
* Calls onError callback function provided by user. If there is no onError
|
1428
|
-
* callback function, displays alert with human readable error description.
|
1429
|
-
* onError callback function receives following object:
|
1430
|
-
* {
|
1431
|
-
* errorCode: error code [number],
|
1432
|
-
* errorDescription: human readable error description [string]
|
1433
|
-
* }
|
1434
|
-
* </pre>
|
1435
|
-
*
|
1436
|
-
* @private
|
1437
|
-
* @param {number} iErrCode Error code
|
1438
|
-
* @param {string} strError Human readable error description
|
1439
|
-
* @param {function} onError Callback function provided by user
|
1440
|
-
*/
|
1441
|
-
Zapatec.Transport.displayError = function(iErrCode, strError, onError) {
|
1442
|
-
if (typeof onError == 'function') {
|
1443
|
-
onError({
|
1444
|
-
errorCode: iErrCode,
|
1445
|
-
errorDescription: strError
|
1446
|
-
});
|
1447
|
-
} else {
|
1448
|
-
alert(strError);
|
1449
|
-
}
|
1450
|
-
};
|
1451
|
-
|
1452
|
-
/**
|
1453
|
-
* Translates a URL to the URL relative to the specified or to absolute URL.
|
1454
|
-
*
|
1455
|
-
* <pre>
|
1456
|
-
* Arguments object format:
|
1457
|
-
* {
|
1458
|
-
* url: absolute or relative URL to translate [string] (if absolute, will be
|
1459
|
-
* returned as is),
|
1460
|
-
* relativeTo: "url" will be translated to the URL relative to this absolute
|
1461
|
-
* or relative URL [string] (optional, current page URL by default)
|
1462
|
-
* }
|
1463
|
-
* </pre>
|
1464
|
-
*
|
1465
|
-
* @param {object} objArgs Arguments object
|
1466
|
-
* @return Translated URL
|
1467
|
-
* @type string
|
1468
|
-
*/
|
1469
|
-
Zapatec.Transport.translateUrl = function(objArgs) {
|
1470
|
-
if (!objArgs || !objArgs.url) {
|
1471
|
-
return null;
|
1472
|
-
}
|
1473
|
-
// Cut arguments part from url
|
1474
|
-
var arrFullUrl = objArgs.url.split('?', 2);
|
1475
|
-
var strUrl = arrFullUrl[0];
|
1476
|
-
// Check url
|
1477
|
-
if (strUrl.charAt(0) == '/' || strUrl.indexOf(':') >= 0) {
|
1478
|
-
// Return absolute URL as is
|
1479
|
-
return objArgs.url;
|
1480
|
-
}
|
1481
|
-
// Get relativeTo
|
1482
|
-
var strRelativeTo;
|
1483
|
-
if (typeof objArgs.relativeTo != 'string') {
|
1484
|
-
// By default relative to current page URL
|
1485
|
-
strRelativeTo = document.location.toString().split('?', 2)[0];
|
1486
|
-
} else {
|
1487
|
-
// Remove arguments from relativeTo
|
1488
|
-
strRelativeTo = objArgs.relativeTo.split('?', 2)[0];
|
1489
|
-
// Check relativeTo
|
1490
|
-
if (strRelativeTo.indexOf('/') < 0) {
|
1491
|
-
// Relative to current page URL
|
1492
|
-
strRelativeTo = document.location.toString().split('?', 2)[0];
|
1493
|
-
} else if (strRelativeTo.charAt(0) != '/' &&
|
1494
|
-
strRelativeTo.indexOf(':') < 0) {
|
1495
|
-
// Transform relativeTo to absolute URL to be able to translate URLs
|
1496
|
-
// starting from ../
|
1497
|
-
strRelativeTo = Zapatec.Transport.translateUrl({
|
1498
|
-
url: strRelativeTo
|
1499
|
-
});
|
1500
|
-
}
|
1501
|
-
}
|
1502
|
-
// Split URLs
|
1503
|
-
var arrUrl = strUrl.split('/');
|
1504
|
-
var arrRelativeTo = strRelativeTo.split('/');
|
1505
|
-
// Remove file name
|
1506
|
-
arrRelativeTo.pop();
|
1507
|
-
// Form new URL
|
1508
|
-
for (var iToken = 0; iToken < arrUrl.length; iToken++) {
|
1509
|
-
var strToken = arrUrl[iToken];
|
1510
|
-
if (strToken == '..') {
|
1511
|
-
arrRelativeTo.pop();
|
1512
|
-
} else if (strToken != '.') {
|
1513
|
-
arrRelativeTo.push(strToken);
|
1514
|
-
}
|
1515
|
-
}
|
1516
|
-
arrFullUrl[0] = arrRelativeTo.join('/');
|
1517
|
-
// Restore arguments part
|
1518
|
-
return arrFullUrl.join('?');
|
1519
|
-
};
|
1520
|
-
|
1521
|
-
/**
|
1522
|
-
* Holds currently loading URLs to prevent duplicate loads.
|
1523
|
-
* @private
|
1524
|
-
*/
|
1525
|
-
Zapatec.Transport.loading = {};
|
1526
|
-
|
1527
|
-
/**
|
1528
|
-
* Prevents duplicate loads of the same URL when second request is done before
|
1529
|
-
* first request is completed.
|
1530
|
-
*
|
1531
|
-
* <pre>
|
1532
|
-
* Arguments object format:
|
1533
|
-
* {
|
1534
|
-
* url: [string] absolute URL,
|
1535
|
-
* force: [boolean, optional] force reload if it is already loaded,
|
1536
|
-
* onLoad: [function, optional] function reference to call on success,
|
1537
|
-
* onError: [function, optional] function reference to call on error
|
1538
|
-
* }
|
1539
|
-
*
|
1540
|
-
* Returned object format:
|
1541
|
-
*
|
1542
|
-
* If this URL is already loading by another process:
|
1543
|
-
* {
|
1544
|
-
* loading: [boolean] always true
|
1545
|
-
* }
|
1546
|
-
*
|
1547
|
-
* Otherwise:
|
1548
|
-
* {
|
1549
|
-
* onLoad: [function, optional] replacement for function to call on success,
|
1550
|
-
* onError: [function, optional] replacement for function to call on error
|
1551
|
-
* }
|
1552
|
-
* </pre>
|
1553
|
-
*
|
1554
|
-
* @private
|
1555
|
-
* @param {object} objArgs Arguments object
|
1556
|
-
* @return Returned object
|
1557
|
-
* @type object
|
1558
|
-
*/
|
1559
|
-
Zapatec.Transport.setupEvents = function(objArgs) {
|
1560
|
-
// Check arguments
|
1561
|
-
if (!objArgs) {
|
1562
|
-
return {};
|
1563
|
-
}
|
1564
|
-
// If loading is forced, we don't need to check if it is already loading
|
1565
|
-
// If EventDriven is not available, operate as in older versions
|
1566
|
-
// Check if URL is passed
|
1567
|
-
if (objArgs.force || !Zapatec.EventDriven || !objArgs.url) {
|
1568
|
-
return {
|
1569
|
-
onLoad: objArgs.onLoad,
|
1570
|
-
onError: objArgs.onError
|
1571
|
-
};
|
1572
|
-
}
|
1573
|
-
var strUrl = objArgs.url;
|
1574
|
-
// Add onLoad listener
|
1575
|
-
if (typeof objArgs.onLoad == 'function') {
|
1576
|
-
Zapatec.EventDriven.addEventListener('zpTransportOnLoad' + strUrl,
|
1577
|
-
objArgs.onLoad);
|
1578
|
-
}
|
1579
|
-
// Add onError listener
|
1580
|
-
if (typeof objArgs.onError == 'function') {
|
1581
|
-
Zapatec.EventDriven.addEventListener('zpTransportOnError' + strUrl,
|
1582
|
-
objArgs.onError);
|
1583
|
-
}
|
1584
|
-
// Check if it is already loading
|
1585
|
-
if (Zapatec.Transport.loading[strUrl]) {
|
1586
|
-
return {
|
1587
|
-
loading: true
|
1588
|
-
};
|
1589
|
-
} else {
|
1590
|
-
// Flag
|
1591
|
-
Zapatec.Transport.loading[strUrl] = true;
|
1592
|
-
// Replace original callbacks
|
1593
|
-
return {
|
1594
|
-
onLoad: new Function("\
|
1595
|
-
Zapatec.EventDriven.fireEvent('zpTransportOnLoad" + strUrl + "');\
|
1596
|
-
Zapatec.EventDriven.removeEvent('zpTransportOnLoad" + strUrl + "');\
|
1597
|
-
Zapatec.EventDriven.removeEvent('zpTransportOnError" + strUrl + "');\
|
1598
|
-
Zapatec.Transport.loading['" + strUrl + "'] = false;\
|
1599
|
-
"),
|
1600
|
-
onError: new Function('objError', "\
|
1601
|
-
Zapatec.EventDriven.fireEvent('zpTransportOnError" + strUrl + "',\
|
1602
|
-
objError);\
|
1603
|
-
Zapatec.EventDriven.removeEvent('zpTransportOnLoad" + strUrl + "');\
|
1604
|
-
Zapatec.EventDriven.removeEvent('zpTransportOnError" + strUrl + "');\
|
1605
|
-
Zapatec.Transport.loading['" + strUrl + "'] = false;\
|
1606
|
-
")
|
1607
|
-
};
|
1608
|
-
}
|
1609
|
-
};
|
1610
|
-
|
1611
|
-
/**
|
1612
|
-
* Holds URLs of already loaded JS files to prevent duplicate loads.
|
1613
|
-
* @private
|
1614
|
-
*/
|
1615
|
-
Zapatec.Transport.loadedJS = {};
|
1616
|
-
|
1617
|
-
/**
|
1618
|
-
* Checks if specified JS file is already loaded.
|
1619
|
-
*
|
1620
|
-
* @private
|
1621
|
-
* @param {string} strUrl Absolute or relative URL of JS file
|
1622
|
-
* @param {string} strAbsoluteUrl Optional. Absolute URL of JS file
|
1623
|
-
* @return Loaded or not
|
1624
|
-
* @type boolean
|
1625
|
-
*/
|
1626
|
-
Zapatec.Transport.isLoadedJS = function(strUrl, strAbsoluteUrl) {
|
1627
|
-
// Get absolute URL of the JS file
|
1628
|
-
if (typeof strAbsoluteUrl == 'undefined') {
|
1629
|
-
strAbsoluteUrl = Zapatec.Transport.translateUrl({url: strUrl});
|
1630
|
-
}
|
1631
|
-
// Check in the list of loaded
|
1632
|
-
if (Zapatec.Transport.loadedJS[strAbsoluteUrl]) {
|
1633
|
-
return true;
|
1634
|
-
}
|
1635
|
-
// Try to find script tag
|
1636
|
-
var arrScripts = document.getElementsByTagName('script');
|
1637
|
-
for (var iScript = 0; iScript < arrScripts.length; iScript++) {
|
1638
|
-
var strSrc = arrScripts[iScript].getAttribute('src') || '';
|
1639
|
-
if (strSrc == strUrl) {
|
1640
|
-
// Add this URL to the list of loaded
|
1641
|
-
Zapatec.Transport.loadedJS[strAbsoluteUrl] = true;
|
1642
|
-
return true;
|
1643
|
-
}
|
1644
|
-
}
|
1645
|
-
// Not found
|
1646
|
-
return false;
|
1647
|
-
};
|
1648
|
-
|
1649
|
-
/**
|
1650
|
-
* Returns path to the specified js file. Iterates over all loaded script
|
1651
|
-
* elements starting from the end. Finds specified js file in src attribute of
|
1652
|
-
* the script element. Splits src attribute value and returns path without js
|
1653
|
-
* file name.
|
1654
|
-
*
|
1655
|
-
* @param {string} strScriptFileName Script file name, e.g. 'zpmywidget.js'
|
1656
|
-
* @return Path to the script, e.g. '../src/' or '' if path is not found
|
1657
|
-
* @type string
|
1658
|
-
*/
|
1659
|
-
Zapatec.Transport.getPath = function(strScriptFileName) {
|
1660
|
-
// Get all script elements
|
1661
|
-
var arrScripts = document.getElementsByTagName('script');
|
1662
|
-
// Find the script in the list
|
1663
|
-
for (var iScript = arrScripts.length - 1; iScript >= 0; iScript--) {
|
1664
|
-
var strSrc = arrScripts[iScript].getAttribute('src') || '';
|
1665
|
-
var arrTokens = strSrc.split('/');
|
1666
|
-
// Remove last token
|
1667
|
-
var strLastToken = arrTokens.pop();
|
1668
|
-
if (strLastToken == strScriptFileName) {
|
1669
|
-
return arrTokens.length ? arrTokens.join('/') + '/' : '';
|
1670
|
-
}
|
1671
|
-
}
|
1672
|
-
// Search in loaded JS files
|
1673
|
-
for (var strSrc in Zapatec.Transport.loadedJS) {
|
1674
|
-
var arrTokens = strSrc.split('/');
|
1675
|
-
// Remove last token
|
1676
|
-
var strLastToken = arrTokens.pop();
|
1677
|
-
if (strLastToken == strScriptFileName) {
|
1678
|
-
return arrTokens.length ? arrTokens.join('/') + '/' : '';
|
1679
|
-
}
|
1680
|
-
}
|
1681
|
-
// Not found
|
1682
|
-
return '';
|
1683
|
-
};
|
1684
|
-
|
1685
|
-
/**
|
1686
|
-
* Writes script tag to the document. Checks if specified JS file is already
|
1687
|
-
* loaded unless boolForce argument is true.
|
1688
|
-
*
|
1689
|
-
* <pre>
|
1690
|
-
* Note: This function must be invoked during page load because it uses
|
1691
|
-
* document.write method.
|
1692
|
-
*
|
1693
|
-
* If special Zapatec.doNotInclude flag is set, this function does nothing.
|
1694
|
-
* </pre>
|
1695
|
-
*
|
1696
|
-
* @param {string} strSrc Src attribute value of the script element
|
1697
|
-
* @param {string} strId Optional. Id of the script element
|
1698
|
-
* @param {boolean} boolForce Optional. Force reload if it is already loaded
|
1699
|
-
*/
|
1700
|
-
Zapatec.Transport.include = function(strSrc, strId, boolForce) {
|
1701
|
-
// Check flag
|
1702
|
-
if (Zapatec.doNotInclude) {
|
1703
|
-
return;
|
1704
|
-
}
|
1705
|
-
// Get absolute URL of the JS file
|
1706
|
-
var strAbsoluteUrl = Zapatec.Transport.translateUrl({url: strSrc});
|
1707
|
-
// Check if it is already loaded
|
1708
|
-
if (!boolForce && Zapatec.Transport.isLoadedJS(strSrc, strAbsoluteUrl)) {
|
1709
|
-
return;
|
1710
|
-
}
|
1711
|
-
// Include file
|
1712
|
-
document.write('<script type="text/javascript" src="' + strSrc +
|
1713
|
-
(typeof strId == 'string' ? '" id="' + strId : '') + '"></script>');
|
1714
|
-
// Add this URL to the list of loaded
|
1715
|
-
Zapatec.Transport.loadedJS[strAbsoluteUrl] = true;
|
1716
|
-
};
|
1717
|
-
|
1718
|
-
/**
|
1719
|
-
* Shortcut. The same as Zapatec.Transport#include.
|
1720
|
-
*/
|
1721
|
-
Zapatec.include = Zapatec.Transport.include;
|
1722
|
-
|
1723
|
-
/**
|
1724
|
-
* Includes JS file into the page. Allows URLs from foreign domains. Doesn't
|
1725
|
-
* check if the JS file is already included. File is loaded asynchronously.
|
1726
|
-
*
|
1727
|
-
* <pre>
|
1728
|
-
* If special Zapatec.doNotInclude flag is set, this function does nothing.
|
1729
|
-
* </pre>
|
1730
|
-
*
|
1731
|
-
* @param {string} strSrc Src attribute value of the script element
|
1732
|
-
* @param {string} strId Optional. Id of the script element
|
1733
|
-
*/
|
1734
|
-
Zapatec.Transport.includeJS = function(strSrc, strId) {
|
1735
|
-
// Check flag
|
1736
|
-
if (Zapatec.doNotInclude) {
|
1737
|
-
return;
|
1738
|
-
}
|
1739
|
-
// Include file
|
1740
|
-
var objContainer = document.body;
|
1741
|
-
if (!objContainer) {
|
1742
|
-
objContainer = document.getElementsByTagName('head')[0];
|
1743
|
-
if (!objContainer) {
|
1744
|
-
objContainer = document;
|
1745
|
-
}
|
1746
|
-
}
|
1747
|
-
var objScript = document.createElement('script');
|
1748
|
-
objScript.type = 'text/javascript';
|
1749
|
-
objScript.src = strSrc;
|
1750
|
-
if (typeof strId == 'string') {
|
1751
|
-
objScript.id = strId;
|
1752
|
-
}
|
1753
|
-
// This is important for Safari to assign attributes before appending
|
1754
|
-
objContainer.appendChild(objScript);
|
1755
|
-
};
|
1756
|
-
|
1757
|
-
/**
|
1758
|
-
* Fetches JS file using fetch and evaluates it in local scope.
|
1759
|
-
*
|
1760
|
-
* <pre>
|
1761
|
-
* When JS file is loaded successfully, onLoad callback function is called
|
1762
|
-
* without arguments. URL is added into Zapatec.Transport.loadedJS array
|
1763
|
-
* and will not be fetched again on next function call unless force argument is
|
1764
|
-
* set to true.
|
1765
|
-
*
|
1766
|
-
* onError callback function receives following object:
|
1767
|
-
* {
|
1768
|
-
* errorCode: [number] server status number (404, etc.),
|
1769
|
-
* errorDescription: [string] human readable error description
|
1770
|
-
* }
|
1771
|
-
*
|
1772
|
-
* One of the arguments: module or url is required. When url is passed,
|
1773
|
-
* module argument is ignored.
|
1774
|
-
*
|
1775
|
-
* If module argument is used, function gets all "script" elements using
|
1776
|
-
* getElementsByTagName and searches for the first element having "src"
|
1777
|
-
* attribute value ending with (relativeModule + ".js") (default relativeModule
|
1778
|
-
* value is "transport"). Path to the module is taken from that src attribute
|
1779
|
-
* value and will be the same as path to relativeModule file.
|
1780
|
-
*
|
1781
|
-
* Arguments object format:
|
1782
|
-
* {
|
1783
|
-
* url: [string, optional] absolute or relative URL of JS file,
|
1784
|
-
* module: [string, optional] module name (file name without .js extension);
|
1785
|
-
* ignored when "url" is defined,
|
1786
|
-
* path: [string, optional] path where to search "module" (default is
|
1787
|
-
* Zapatec.zapatecPath if it is defined); ignored when "url" is defined,
|
1788
|
-
* async: [boolean, optional] use asynchronous mode (default: true),
|
1789
|
-
* force: [boolean, optional] force reload if it is already loaded,
|
1790
|
-
* onLoad: [function, optional] function reference to call on success,
|
1791
|
-
* onError: [function, optional] function reference to call on error
|
1792
|
-
* }
|
1793
|
-
*
|
1794
|
-
* Note: If "force" is used, you should add 'r=' + Math.random() parameter to
|
1795
|
-
* URL to prevent loading from browser cache.
|
1796
|
-
*
|
1797
|
-
* If special Zapatec.doNotInclude flag is set, this function just calls onLoad
|
1798
|
-
* callback function.
|
1799
|
-
* </pre>
|
1800
|
-
*
|
1801
|
-
* @param {object} objArgs Arguments object
|
1802
|
-
*/
|
1803
|
-
Zapatec.Transport.loadJS = function(objArgs) {
|
1804
|
-
// Check arguments
|
1805
|
-
if (!(objArgs instanceof Object)) {
|
1806
|
-
return;
|
1807
|
-
}
|
1808
|
-
if (typeof objArgs.async == 'undefined') {
|
1809
|
-
objArgs.async = true;
|
1810
|
-
}
|
1811
|
-
// Get URL of JS file
|
1812
|
-
var strUrl = null;
|
1813
|
-
if (objArgs.url) {
|
1814
|
-
strUrl = objArgs.url;
|
1815
|
-
} else if (objArgs.module) {
|
1816
|
-
var strPath = '';
|
1817
|
-
if (typeof objArgs.path != 'undefined') {
|
1818
|
-
strPath = objArgs.path;
|
1819
|
-
} else if (typeof Zapatec.zapatecPath != 'undefined') {
|
1820
|
-
strPath = Zapatec.zapatecPath;
|
1821
|
-
}
|
1822
|
-
strUrl = strPath + objArgs.module + '.js';
|
1823
|
-
} else {
|
1824
|
-
return;
|
1825
|
-
}
|
1826
|
-
// Get absolute URL of the JS file
|
1827
|
-
var strAbsUrl = Zapatec.Transport.translateUrl({url: strUrl});
|
1828
|
-
// Check arguments
|
1829
|
-
if (!objArgs.onLoad) {
|
1830
|
-
objArgs.onLoad = null;
|
1831
|
-
}
|
1832
|
-
if (!objArgs.onError) {
|
1833
|
-
objArgs.onError = null;
|
1834
|
-
}
|
1835
|
-
// Check if it is already loaded
|
1836
|
-
if (Zapatec.doNotInclude ||
|
1837
|
-
(!objArgs.force && Zapatec.Transport.isLoadedJS(strUrl, strAbsUrl))) {
|
1838
|
-
// onLoad callback
|
1839
|
-
if (typeof objArgs.onLoad == 'function') {
|
1840
|
-
objArgs.onLoad();
|
1841
|
-
}
|
1842
|
-
return;
|
1843
|
-
}
|
1844
|
-
// Setup onLoad and onError events
|
1845
|
-
var objHandlers = Zapatec.Transport.setupEvents({
|
1846
|
-
url: strAbsUrl,
|
1847
|
-
force: objArgs.force,
|
1848
|
-
onLoad: objArgs.onLoad,
|
1849
|
-
onError: objArgs.onError
|
1850
|
-
});
|
1851
|
-
// Don't need to continue if this url is already loading by another process
|
1852
|
-
if (objHandlers.loading) {
|
1853
|
-
return;
|
1854
|
-
}
|
1855
|
-
// Load JS file
|
1856
|
-
Zapatec.Transport.fetch({
|
1857
|
-
url: strUrl,
|
1858
|
-
async: objArgs.async,
|
1859
|
-
onLoad: function(objRequest) {
|
1860
|
-
// Can be loaded in two processes simultaneously
|
1861
|
-
if (objArgs.force || !Zapatec.Transport.loadedJS[strAbsUrl]) {
|
1862
|
-
var arrTokens = strUrl.split('/');
|
1863
|
-
// Remove last token
|
1864
|
-
var strLastToken = arrTokens.pop();
|
1865
|
-
// Store path to current module
|
1866
|
-
Zapatec.lastLoadedModule = arrTokens.join('/') + '/';
|
1867
|
-
// Evaluate code in global scope
|
1868
|
-
Zapatec.Transport.evalGlobalScope(objRequest.responseText);
|
1869
|
-
// clear path to last loaded module
|
1870
|
-
Zapatec.lastLoadedModule = null;
|
1871
|
-
// Add this URL to the list of loaded
|
1872
|
-
Zapatec.Transport.loadedJS[strAbsUrl] = true;
|
1873
|
-
}
|
1874
|
-
// onLoad callback
|
1875
|
-
if (typeof objHandlers.onLoad == 'function') {
|
1876
|
-
objHandlers.onLoad();
|
1877
|
-
}
|
1878
|
-
},
|
1879
|
-
onError: objHandlers.onError
|
1880
|
-
});
|
1881
|
-
};
|
1882
|
-
|
1883
|
-
/**
|
1884
|
-
* Includes CSS file into the page. Allows URLs from foreign domains. Doesn't
|
1885
|
-
* check if the CSS file is already included. File is loaded asynchronously.
|
1886
|
-
* Requires that head section of the page already exists because link tag
|
1887
|
-
* may appear only inside head.
|
1888
|
-
*
|
1889
|
-
* @param {string} strHref Href attribute value of the link element
|
1890
|
-
*/
|
1891
|
-
Zapatec.Transport.includeCSS = function(strHref) {
|
1892
|
-
// May appear only inside head
|
1893
|
-
var objContainer = document.getElementsByTagName('head')[0];
|
1894
|
-
if (!objContainer) {
|
1895
|
-
return;
|
1896
|
-
}
|
1897
|
-
var objLink = document.createElement('link');
|
1898
|
-
objLink.setAttribute('rel', 'stylesheet');
|
1899
|
-
objLink.setAttribute('type', 'text/css');
|
1900
|
-
objLink.setAttribute('href', strHref);
|
1901
|
-
objContainer.appendChild(objLink);
|
1902
|
-
};
|
1903
|
-
|
1904
|
-
/**
|
1905
|
-
* Holds URLs of already loaded CSS files to prevent duplicate loads.
|
1906
|
-
* @private
|
1907
|
-
*/
|
1908
|
-
Zapatec.Transport.loadedCss = {};
|
1909
|
-
|
1910
|
-
/**
|
1911
|
-
* Fetches style sheet using fetch and loads it into the document.
|
1912
|
-
*
|
1913
|
-
* <pre>
|
1914
|
-
* When stylesheet is loaded successfully, onLoad callback function is called
|
1915
|
-
* without arguments. URL is added into Zapatec.Transport.loadedCss array
|
1916
|
-
* and will not be fetched again on next function call unless force argument is
|
1917
|
-
* set to true.
|
1918
|
-
*
|
1919
|
-
* onError callback function receives following object:
|
1920
|
-
* {
|
1921
|
-
* errorCode: server status number (404, etc.) [number],
|
1922
|
-
* errorDescription: human readable error description [string]
|
1923
|
-
* }
|
1924
|
-
*
|
1925
|
-
* Arguments object format:
|
1926
|
-
* {
|
1927
|
-
* url: absolute or relative URL of CSS file [string],
|
1928
|
-
* async: [boolean, optional] use asynchronous mode (default: true),
|
1929
|
-
* force: [boolean, optional] force reload if it is already loaded,
|
1930
|
-
* onLoad: [function, optional] function reference to call on success,
|
1931
|
-
* onError: [function, optional] function reference to call on error
|
1932
|
-
* }
|
1933
|
-
*
|
1934
|
-
* Note: If "force" is used, you should add 'r=' + Math.random() parameter to
|
1935
|
-
* URL to prevent loading from browser cache.
|
1936
|
-
* </pre>
|
1937
|
-
*
|
1938
|
-
* @param {object} objArgs Arguments object
|
1939
|
-
*/
|
1940
|
-
Zapatec.Transport.loadCss = function(objArgs) {
|
1941
|
-
if (Zapatec.StyleSheet) {
|
1942
|
-
Zapatec.Transport.loadCssWithStyleSheet(objArgs);
|
1943
|
-
} else {
|
1944
|
-
// Load Zapatec.StyleSheet class
|
1945
|
-
Zapatec.Transport.loadJS({
|
1946
|
-
module: 'stylesheet',
|
1947
|
-
async: objArgs.async,
|
1948
|
-
onLoad: function() {
|
1949
|
-
Zapatec.Transport.loadCssWithStyleSheet(objArgs);
|
1950
|
-
}
|
1951
|
-
});
|
1952
|
-
}
|
1953
|
-
};
|
1954
|
-
|
1955
|
-
/**
|
1956
|
-
* Fetches style sheet using fetch and loads it into the document.
|
1957
|
-
* Zapatec.StyleSheet must exist.
|
1958
|
-
*
|
1959
|
-
* @private
|
1960
|
-
* @param {object} objArgs Arguments object see
|
1961
|
-
* {@link Zapatec.Transport#loadCss}
|
1962
|
-
*/
|
1963
|
-
Zapatec.Transport.loadCssWithStyleSheet = function(objArgs) {
|
1964
|
-
// Check arguments
|
1965
|
-
if (!(objArgs instanceof Object)) {
|
1966
|
-
return;
|
1967
|
-
}
|
1968
|
-
if (!objArgs.url) {
|
1969
|
-
return;
|
1970
|
-
}
|
1971
|
-
if (typeof objArgs.async == 'undefined') {
|
1972
|
-
objArgs.async = true;
|
1973
|
-
}
|
1974
|
-
// Get absolute URL of the CSS file
|
1975
|
-
var strAbsUrl = Zapatec.Transport.translateUrl({url: objArgs.url});
|
1976
|
-
// Check if it is already loaded
|
1977
|
-
if (!objArgs.force) {
|
1978
|
-
if (Zapatec.Transport.loadedCss[strAbsUrl]) {
|
1979
|
-
// onLoad callback
|
1980
|
-
if (typeof objArgs.onLoad == 'function') {
|
1981
|
-
objArgs.onLoad();
|
1982
|
-
}
|
1983
|
-
return;
|
1984
|
-
}
|
1985
|
-
var arrLinks = document.getElementsByTagName('link');
|
1986
|
-
for (var iLnk = 0; iLnk < arrLinks.length; iLnk++) {
|
1987
|
-
var strHref = arrLinks[iLnk].getAttribute('href') || '';
|
1988
|
-
// Make it absolute
|
1989
|
-
strHref = Zapatec.Transport.translateUrl({url: strHref});
|
1990
|
-
if (strHref == strAbsUrl) {
|
1991
|
-
// Add this url to the list of loaded
|
1992
|
-
Zapatec.Transport.loadedCss[strAbsUrl] = true;
|
1993
|
-
// onLoad callback
|
1994
|
-
if (typeof objArgs.onLoad == 'function') {
|
1995
|
-
objArgs.onLoad();
|
1996
|
-
}
|
1997
|
-
return;
|
1998
|
-
}
|
1999
|
-
}
|
2000
|
-
}
|
2001
|
-
// Setup onLoad and onError events
|
2002
|
-
var objHandlers = Zapatec.Transport.setupEvents({
|
2003
|
-
url: strAbsUrl,
|
2004
|
-
force: objArgs.force,
|
2005
|
-
onLoad: objArgs.onLoad,
|
2006
|
-
onError: objArgs.onError
|
2007
|
-
});
|
2008
|
-
// Don't need to continue if this url is already loading by another process
|
2009
|
-
if (objHandlers.loading) {
|
2010
|
-
return;
|
2011
|
-
}
|
2012
|
-
// Load CSS file
|
2013
|
-
Zapatec.Transport.fetch({
|
2014
|
-
url: objArgs.url,
|
2015
|
-
async: objArgs.async,
|
2016
|
-
onLoad: function(objRequest) {
|
2017
|
-
// Parse CSS file.
|
2018
|
-
// Find URLs and translate them to absolute.
|
2019
|
-
// Find @import rules and load corresponding CSS files.
|
2020
|
-
var strCss = objRequest.responseText;
|
2021
|
-
var arrResultCss = [];
|
2022
|
-
// Will hold image URLs to preload
|
2023
|
-
var arrImgUrls = [];
|
2024
|
-
// Will hold CSS URLs to load
|
2025
|
-
var arrCssUrls = [];
|
2026
|
-
// Move first cursor to the beginning of the string
|
2027
|
-
var iPos = 0;
|
2028
|
-
// Move second cursor to the pattern
|
2029
|
-
var iNextPos = strCss.indexOf('url(', iPos);
|
2030
|
-
while (iNextPos >= 0) {
|
2031
|
-
// Move first cursor to the URL
|
2032
|
-
iNextPos += 4;
|
2033
|
-
// Check if this is @import rule
|
2034
|
-
var strToken = strCss.substring(iPos, iNextPos);
|
2035
|
-
var boolIsImport = /@import\s+url\($/.test(strToken);
|
2036
|
-
// Add part of the string before URL
|
2037
|
-
arrResultCss.push(strToken);
|
2038
|
-
// Move second cursor to the new location to start the search from
|
2039
|
-
iPos = iNextPos;
|
2040
|
-
// Search the end of URL
|
2041
|
-
iNextPos = strCss.indexOf(')', iPos);
|
2042
|
-
if (iNextPos >= 0) {
|
2043
|
-
// Remove quotes
|
2044
|
-
var strImgUrl = strCss.substring(iPos, iNextPos);
|
2045
|
-
strImgUrl = strImgUrl.replace(/['"]/g, '');
|
2046
|
-
// Translate image URL relative to CSS file URL
|
2047
|
-
strImgUrl = Zapatec.Transport.translateUrl({
|
2048
|
-
url: strImgUrl,
|
2049
|
-
relativeTo: objArgs.url
|
2050
|
-
});
|
2051
|
-
// Convert to absolute URL
|
2052
|
-
strImgUrl = Zapatec.Transport.translateUrl({
|
2053
|
-
url: strImgUrl
|
2054
|
-
});
|
2055
|
-
// Add translated URL
|
2056
|
-
arrResultCss.push(strImgUrl);
|
2057
|
-
// Add URL to the list
|
2058
|
-
if (boolIsImport) {
|
2059
|
-
// Add CSS URL to load list
|
2060
|
-
arrCssUrls.push(strImgUrl);
|
2061
|
-
} else {
|
2062
|
-
// Add image URL to preload list
|
2063
|
-
arrImgUrls.push(strImgUrl);
|
2064
|
-
}
|
2065
|
-
// Move second cursor to the new location to start the search from
|
2066
|
-
iPos = iNextPos;
|
2067
|
-
// Search next pattern
|
2068
|
-
iNextPos = strCss.indexOf('url(', iPos);
|
2069
|
-
}
|
2070
|
-
}
|
2071
|
-
// Add the rest of string
|
2072
|
-
arrResultCss.push(strCss.substr(iPos));
|
2073
|
-
// Get translated CSS text
|
2074
|
-
strCss = arrResultCss.join('');
|
2075
|
-
// Load CSS files
|
2076
|
-
Zapatec.Transport.loadCssList({
|
2077
|
-
urls: arrCssUrls,
|
2078
|
-
async: objArgs.async,
|
2079
|
-
onLoad: function() {
|
2080
|
-
// Add style sheet rules into the page
|
2081
|
-
var objStyleSheet = new Zapatec.StyleSheet();
|
2082
|
-
objStyleSheet.addParse(strCss);
|
2083
|
-
// Fire event
|
2084
|
-
if (typeof objHandlers.onLoad == 'function') {
|
2085
|
-
objHandlers.onLoad();
|
2086
|
-
}
|
2087
|
-
}
|
2088
|
-
});
|
2089
|
-
// Add this URL to the list of loaded
|
2090
|
-
Zapatec.Transport.loadedCss[strAbsUrl] = true;
|
2091
|
-
// Preload images
|
2092
|
-
Zapatec.Transport.preloadImages({
|
2093
|
-
urls: arrImgUrls,
|
2094
|
-
timeout: 60000 // 1 minute
|
2095
|
-
});
|
2096
|
-
},
|
2097
|
-
onError: objHandlers.onError
|
2098
|
-
});
|
2099
|
-
};
|
2100
|
-
|
2101
|
-
/**
|
2102
|
-
* Loads several CSS files one by one it into the document.
|
2103
|
-
*
|
2104
|
-
* <pre>
|
2105
|
-
* This function behaves differently from other Zapatec.Transport functions.
|
2106
|
-
* onLoad callback function will be called in any case, even if errors occured
|
2107
|
-
* during loading. If there are multiple errors, onError callback function will
|
2108
|
-
* be called once for every passed URL that wasn't loaded successfully.
|
2109
|
-
*
|
2110
|
-
* onLoad callback function is called without arguments.
|
2111
|
-
*
|
2112
|
-
* onError callback function receives following object:
|
2113
|
-
* {
|
2114
|
-
* errorCode: server status number (404, etc.) [number],
|
2115
|
-
* errorDescription: human readable error description [string]
|
2116
|
-
* }
|
2117
|
-
*
|
2118
|
-
* Arguments object format:
|
2119
|
-
* {
|
2120
|
-
* urls: array of absolute or relative URLs of CSS files to load [object]
|
2121
|
-
* (files will be loaded in order they appear in the array),
|
2122
|
-
* async: [boolean, optional] use asynchronous mode (default: true),
|
2123
|
-
* force: [boolean, optional] force reload if it is already loaded,
|
2124
|
-
* onLoad: function reference to call on completion [function] (optional),
|
2125
|
-
* onError: function reference to call on error [function] (optional)
|
2126
|
-
* }
|
2127
|
-
*
|
2128
|
-
* Note: If "force" is used, you should add 'r=' + Math.random() parameter to
|
2129
|
-
* URL to prevent loading from browser cache.
|
2130
|
-
* </pre>
|
2131
|
-
*
|
2132
|
-
* @param {object} objArgs Arguments object
|
2133
|
-
*/
|
2134
|
-
Zapatec.Transport.loadCssList = function(objArgs) {
|
2135
|
-
// Check arguments
|
2136
|
-
if (!(objArgs instanceof Object)) {
|
2137
|
-
return;
|
2138
|
-
}
|
2139
|
-
if (typeof objArgs.async == 'undefined') {
|
2140
|
-
objArgs.async = true;
|
2141
|
-
}
|
2142
|
-
if (!objArgs.onLoad) {
|
2143
|
-
objArgs.onLoad = null;
|
2144
|
-
}
|
2145
|
-
if (!objArgs.onError) {
|
2146
|
-
objArgs.onError = null;
|
2147
|
-
}
|
2148
|
-
if (!objArgs.urls || !objArgs.urls.length) {
|
2149
|
-
// onLoad callback
|
2150
|
-
if (typeof objArgs.onLoad == 'function') {
|
2151
|
-
objArgs.onLoad();
|
2152
|
-
}
|
2153
|
-
return;
|
2154
|
-
}
|
2155
|
-
// Get first URL in the array
|
2156
|
-
var strUrl = objArgs.urls.shift();
|
2157
|
-
// CSS file onLoad handler
|
2158
|
-
var funcOnLoad = function() {
|
2159
|
-
// Load the rest of URLs
|
2160
|
-
Zapatec.Transport.loadCssList({
|
2161
|
-
urls: objArgs.urls,
|
2162
|
-
async: objArgs.async,
|
2163
|
-
force: objArgs.force,
|
2164
|
-
onLoad: objArgs.onLoad,
|
2165
|
-
onError: objArgs.onError
|
2166
|
-
});
|
2167
|
-
};
|
2168
|
-
// Load CSS file
|
2169
|
-
Zapatec.Transport.loadCss({
|
2170
|
-
url: strUrl,
|
2171
|
-
async: objArgs.async,
|
2172
|
-
force: objArgs.force,
|
2173
|
-
onLoad: funcOnLoad,
|
2174
|
-
onError: function(objError) {
|
2175
|
-
Zapatec.Transport.displayError(objError.errorCode,
|
2176
|
-
objError.errorDescription, objArgs.onError);
|
2177
|
-
funcOnLoad();
|
2178
|
-
}
|
2179
|
-
});
|
2180
|
-
};
|
2181
|
-
|
2182
|
-
/**
|
2183
|
-
* Holds image preloads.
|
2184
|
-
* @private
|
2185
|
-
*/
|
2186
|
-
Zapatec.Transport.imagePreloads = [];
|
2187
|
-
|
2188
|
-
/**
|
2189
|
-
* Preloads one or several images at once. See Zapatec.PreloadImages class
|
2190
|
-
* (utils/preloadimages.js) for details.
|
2191
|
-
*
|
2192
|
-
* <pre>
|
2193
|
-
* Arguments object format:
|
2194
|
-
* {
|
2195
|
-
* urls: [object] array of absolute or relative image URLs to preload,
|
2196
|
-
* onLoad: [function, optional] onload event handler,
|
2197
|
-
* timeout: [number, optional] number of milliseconds to wait for onload
|
2198
|
-
* event before forcing it
|
2199
|
-
* }
|
2200
|
-
* </pre>
|
2201
|
-
*
|
2202
|
-
* @param {object} objArgs Arguments object
|
2203
|
-
*/
|
2204
|
-
Zapatec.Transport.preloadImages = function(objArgs) {
|
2205
|
-
if (Zapatec.PreloadImages) {
|
2206
|
-
Zapatec.Transport.imagePreloads.push(new Zapatec.PreloadImages(objArgs));
|
2207
|
-
} else {
|
2208
|
-
// Load preloadimages.js module
|
2209
|
-
Zapatec.Transport.loadJS({
|
2210
|
-
module: 'preloadimages',
|
2211
|
-
onLoad: function() {
|
2212
|
-
Zapatec.Transport.imagePreloads.push(
|
2213
|
-
new Zapatec.PreloadImages(objArgs));
|
2214
|
-
}
|
2215
|
-
});
|
2216
|
-
}
|
2217
|
-
};
|