Version Description
- Added a "bbPress override" option that prevents bbPress from resetting all changes that are made to dynamic bbPress roles. Enabling this option allows you to edit bbPress roles with any role editing plugin.
- Fixed a conflict that caused some hidden Simple Calendars menu items to show up when Admin Menu Editor was activated.
- Fixed a bug where menu items that had special characters like "&" and "/" in the slug could stop working if they were moved to a different submenu or to the top level.
- Fixed a bug where changing the menu icon to an external image (like a URL pointing to a PNG file) could result in the old and the new icon being displayed at once, either side by side or one below the other. This only affected menu items that had an icon set in CSS by using a
::before
pseudo-element. - Fixed many jQuery deprecation warnings.
- Fixed a bug where some menu settings would not loaded from the database when another plugin triggered a filter that caused the menu configuration to be loaded before AME loaded its modules.
- Fixed bug that could cause an obscure conflict with plugins that change the admin URL, like "WP Hide & Security Enhancer". When a user tried to open "Dashboard -> Home", the plugin could incorrectly apply the permisssions of a another menu item to the "Home" item. If the other menu item was configured to be inaccessible, the user would get an error message when logging in (they were still successfully logged in).
- Improved error reporting in situations where the plugin can't parse menu data.
Download this release
Release Info
Developer | whiteshadow |
Plugin | Admin Menu Editor |
Version | 1.9.8 |
Comparing to | |
See all releases |
Code changes from version 1.9.7 to 1.9.8
- css/admin.css +11 -0
- includes/bbpress-role-override.php +56 -0
- includes/menu-editor-core.php +65 -9
- includes/menu-item.php +4 -1
- includes/menu.php +7 -2
- includes/settings-page.php +21 -0
- js/actor-manager.js +1 -1
- js/admin-helpers.js +2 -2
- js/jquery.form.js +1533 -1270
- js/menu-editor.js +63 -63
- menu-editor.php +1 -1
- modules/access-editor/access-editor.js +1 -1
- readme.txt +11 -1
css/admin.css
CHANGED
@@ -57,6 +57,17 @@ hr.ws-submenu-separator {
|
|
57 |
margin-left: 0;
|
58 |
}
|
59 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
|
61 |
/*
|
62 |
* Submenu icons.
|
57 |
margin-left: 0;
|
58 |
}
|
59 |
|
60 |
+
/*
|
61 |
+
* Override third-party menu icons with image icons selected by the user.
|
62 |
+
*
|
63 |
+
* Some plugins use CSS to put their menu icon in a ::before pseudo-element, like WordPress does with Dashicons.
|
64 |
+
* When the user assigns a custom icon URL to the menu item (e.g. "https://example.com/icon.png"), the ::before
|
65 |
+
* element will still be there, and it will push the custom icon out of place. To prevent that, let's forcibly
|
66 |
+
* hide the ::before element (note: don't do this when the user has selected a custom Dashicon/other icon fonts!).
|
67 |
+
*/
|
68 |
+
#adminmenu a.ame-has-custom-image-url > .wp-menu-image::before {
|
69 |
+
display: none !important;
|
70 |
+
}
|
71 |
|
72 |
/*
|
73 |
* Submenu icons.
|
includes/bbpress-role-override.php
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class ameBBPressRoleOverride {
|
3 |
+
private $customRoleSettings = array();
|
4 |
+
private $propertiesToSave = array('roles', 'role_objects', 'role_names');
|
5 |
+
|
6 |
+
public function __construct() {
|
7 |
+
//Save a local copy of bbPress roles before bbPress overwrites them, then restore that saved copy later.
|
8 |
+
//Note that the priority number here must be higher than the priority of the bbPress::roles_init() callback
|
9 |
+
//and lower than the priority of the bbp_add_forums_roles() callback.
|
10 |
+
add_action('bbp_roles_init', array($this, 'maybePreserveCustomSettings'), 6);
|
11 |
+
}
|
12 |
+
|
13 |
+
public function maybePreserveCustomSettings($wp_roles = null) {
|
14 |
+
$priority = has_action('bbp_roles_init', 'bbp_add_forums_roles');
|
15 |
+
if ( ($priority === false) || !function_exists('bbp_get_dynamic_roles') || (empty($wp_roles)) ) {
|
16 |
+
//bbPress is not active or the current bbPress version is not supported.
|
17 |
+
return $wp_roles;
|
18 |
+
}
|
19 |
+
|
20 |
+
$bbPressRoles = bbp_get_dynamic_roles();
|
21 |
+
if ( !is_array($bbPressRoles) || empty($bbPressRoles) ) {
|
22 |
+
return $wp_roles;
|
23 |
+
}
|
24 |
+
|
25 |
+
foreach (array_keys($bbPressRoles) as $id) {
|
26 |
+
$settings = array();
|
27 |
+
foreach ($this->propertiesToSave as $property) {
|
28 |
+
if ( isset($wp_roles->$property[$id]) ) {
|
29 |
+
$settings[$property] = $wp_roles->$property[$id];
|
30 |
+
}
|
31 |
+
}
|
32 |
+
if ( !empty($settings) ) {
|
33 |
+
$this->customRoleSettings[$id] = $settings;
|
34 |
+
}
|
35 |
+
}
|
36 |
+
|
37 |
+
if ( !empty($this->customRoleSettings) ) {
|
38 |
+
add_action('bbp_roles_init', array($this, 'restoreCustomSettings'), $priority + 5);
|
39 |
+
}
|
40 |
+
|
41 |
+
return $wp_roles;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function restoreCustomSettings($wp_roles = null) {
|
45 |
+
if ( empty($wp_roles) ) {
|
46 |
+
return $wp_roles;
|
47 |
+
}
|
48 |
+
foreach ($this->customRoleSettings as $id => $properties) {
|
49 |
+
foreach ($properties as $property => $value) {
|
50 |
+
$wp_roles->$property[$id] = $value;
|
51 |
+
}
|
52 |
+
}
|
53 |
+
$this->customRoleSettings = array();
|
54 |
+
return $wp_roles;
|
55 |
+
}
|
56 |
+
}
|
includes/menu-editor-core.php
CHANGED
@@ -106,6 +106,7 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
106 |
* @var ameModule[] List of modules that were loaded for the current request.
|
107 |
*/
|
108 |
private $loaded_modules = array();
|
|
|
109 |
|
110 |
/**
|
111 |
* @var array List of capabilities that are used in the default admin menu. Used to detect meta capabilities.
|
@@ -187,6 +188,9 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
187 |
//Make custom menu and page titles translatable with WPML. They will appear in the "Strings" section.
|
188 |
//This only applies to custom (i.e. changed) titles.
|
189 |
'wpml_support_enabled' => true,
|
|
|
|
|
|
|
190 |
|
191 |
//Which modules are active or inactive. Format: ['module-id' => true/false].
|
192 |
'is_active_module' => array(
|
@@ -301,6 +305,10 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
301 |
'options-general.php?page=wyr-fakes-settings' => true,
|
302 |
//WP-Job-Manager 1.34.1
|
303 |
'index.php?page=job-manager-setup' => true,
|
|
|
|
|
|
|
|
|
304 |
);
|
305 |
|
306 |
//AJAXify screen options
|
@@ -417,6 +425,12 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
417 |
//Compatibility fix for MailPoet 3.
|
418 |
$this->apply_mailpoet_compat_fix();
|
419 |
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
if ( did_action('plugins_loaded') ) {
|
421 |
$this->load_modules();
|
422 |
} else {
|
@@ -425,15 +439,22 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
425 |
}
|
426 |
|
427 |
public function load_modules() {
|
428 |
-
//
|
429 |
-
foreach($this->get_active_modules() as $module) {
|
|
|
|
|
|
|
|
|
430 |
/** @noinspection PhpIncludeInspection */
|
431 |
include ($module['path']);
|
432 |
if ( !empty($module['className']) ) {
|
433 |
$instance = new $module['className']($this);
|
434 |
-
$this->loaded_modules[] = $instance;
|
|
|
|
|
435 |
}
|
436 |
}
|
|
|
437 |
|
438 |
//Set up the tabs for the menu editor page. Many tabs are provided by modules.
|
439 |
$firstTabs = array('editor' => 'Admin Menu');
|
@@ -1339,6 +1360,13 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
1339 |
return $this->cached_custom_menu;
|
1340 |
}
|
1341 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1342 |
$this->loaded_menu_config_id = $config_id;
|
1343 |
|
1344 |
if ( $this->is_access_test ) {
|
@@ -2085,7 +2113,8 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
2085 |
//Menus that have both a custom icon URL and a "menu-icon-*" class will get two overlapping icons.
|
2086 |
//Fix this by automatically removing the class. The user can set a custom class attr. to override.
|
2087 |
$hasCustomIconUrl = !ameMenuItem::is_default($item, 'icon_url');
|
2088 |
-
$
|
|
|
2089 |
if (
|
2090 |
ameMenuItem::is_default($item, 'css_class')
|
2091 |
&& $hasCustomIconUrl
|
@@ -2097,8 +2126,14 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
2097 |
}
|
2098 |
}
|
2099 |
|
2100 |
-
if ( $hasCustomIconUrl
|
2101 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
2102 |
}
|
2103 |
|
2104 |
//WPML support: Translate only custom titles. See further below.
|
@@ -2614,6 +2649,9 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
2614 |
//WPML support.
|
2615 |
$this->options['wpml_support_enabled'] = !empty($this->post['wpml_support_enabled']);
|
2616 |
|
|
|
|
|
|
|
2617 |
//Active modules.
|
2618 |
$activeModules = isset($this->post['active_modules']) ? (array)$this->post['active_modules'] : array();
|
2619 |
$activeModules = array_fill_keys(array_map('strval', $activeModules), true);
|
@@ -3434,9 +3472,27 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
3434 |
}
|
3435 |
|
3436 |
// "/wp-admin/index.php" should match "/wp-admin/".
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3437 |
if (
|
3438 |
-
($this->endsWith($path1, '
|
3439 |
-
|| ($this->endsWith($path2, '
|
3440 |
) {
|
3441 |
return true;
|
3442 |
}
|
@@ -3591,7 +3647,7 @@ class WPMenuEditor extends MenuEd_ShadowPluginFramework {
|
|
3591 |
'ame-helper-style',
|
3592 |
plugins_url('css/admin.css', $this->plugin_file),
|
3593 |
array(),
|
3594 |
-
'
|
3595 |
);
|
3596 |
|
3597 |
if ( $this->options['force_custom_dashicons'] ) {
|
106 |
* @var ameModule[] List of modules that were loaded for the current request.
|
107 |
*/
|
108 |
private $loaded_modules = array();
|
109 |
+
private $are_modules_loaded = false;
|
110 |
|
111 |
/**
|
112 |
* @var array List of capabilities that are used in the default admin menu. Used to detect meta capabilities.
|
188 |
//Make custom menu and page titles translatable with WPML. They will appear in the "Strings" section.
|
189 |
//This only applies to custom (i.e. changed) titles.
|
190 |
'wpml_support_enabled' => true,
|
191 |
+
//Prevent bbPress from resetting its own roles. This should allow the user to edit bbPress roles
|
192 |
+
//with any role editing plugin. Disabled by default due to risk of conflicts and the performance impact.
|
193 |
+
'bbpress_override_enabled' => false,
|
194 |
|
195 |
//Which modules are active or inactive. Format: ['module-id' => true/false].
|
196 |
'is_active_module' => array(
|
305 |
'options-general.php?page=wyr-fakes-settings' => true,
|
306 |
//WP-Job-Manager 1.34.1
|
307 |
'index.php?page=job-manager-setup' => true,
|
308 |
+
//Simple Calendar 3.1.33
|
309 |
+
'index.php?page=simple-calendar_about' => true,
|
310 |
+
'index.php?page=simple-calendar_credits' => true,
|
311 |
+
'index.php?page=simple-calendar_translators' => true,
|
312 |
);
|
313 |
|
314 |
//AJAXify screen options
|
425 |
//Compatibility fix for MailPoet 3.
|
426 |
$this->apply_mailpoet_compat_fix();
|
427 |
|
428 |
+
//bbPress role override.
|
429 |
+
if ( !empty($this->options['bbpress_override_enabled']) ) {
|
430 |
+
require_once __DIR__ . '/bbpress-role-override.php';
|
431 |
+
new ameBBPressRoleOverride();
|
432 |
+
}
|
433 |
+
|
434 |
if ( did_action('plugins_loaded') ) {
|
435 |
$this->load_modules();
|
436 |
} else {
|
439 |
}
|
440 |
|
441 |
public function load_modules() {
|
442 |
+
//Load any active modules that haven't been loaded yet.
|
443 |
+
foreach($this->get_active_modules() as $id => $module) {
|
444 |
+
if ( array_key_exists($id, $this->loaded_modules) ) {
|
445 |
+
continue;
|
446 |
+
}
|
447 |
+
|
448 |
/** @noinspection PhpIncludeInspection */
|
449 |
include ($module['path']);
|
450 |
if ( !empty($module['className']) ) {
|
451 |
$instance = new $module['className']($this);
|
452 |
+
$this->loaded_modules[$id] = $instance;
|
453 |
+
} else {
|
454 |
+
$this->loaded_modules[$id] = true;
|
455 |
}
|
456 |
}
|
457 |
+
$this->are_modules_loaded = true;
|
458 |
|
459 |
//Set up the tabs for the menu editor page. Many tabs are provided by modules.
|
460 |
$firstTabs = array('editor' => 'Admin Menu');
|
1360 |
return $this->cached_custom_menu;
|
1361 |
}
|
1362 |
|
1363 |
+
//Modules may include custom hooks that change how menu settings are loaded, so we need to load active modules
|
1364 |
+
//before we load the menu configuration. Usually that happens automatically, but there are some plugins that
|
1365 |
+
//trigger AME filters that need menu data before modules would normally be loaded.
|
1366 |
+
if ( !$this->are_modules_loaded ) {
|
1367 |
+
$this->load_modules();
|
1368 |
+
}
|
1369 |
+
|
1370 |
$this->loaded_menu_config_id = $config_id;
|
1371 |
|
1372 |
if ( $this->is_access_test ) {
|
2113 |
//Menus that have both a custom icon URL and a "menu-icon-*" class will get two overlapping icons.
|
2114 |
//Fix this by automatically removing the class. The user can set a custom class attr. to override.
|
2115 |
$hasCustomIconUrl = !ameMenuItem::is_default($item, 'icon_url');
|
2116 |
+
$tempIconUrl = ameMenuItem::get($item, 'icon_url', '');
|
2117 |
+
$hasIcon = !in_array($tempIconUrl, array('', 'none', 'div'));
|
2118 |
if (
|
2119 |
ameMenuItem::is_default($item, 'css_class')
|
2120 |
&& $hasCustomIconUrl
|
2126 |
}
|
2127 |
}
|
2128 |
|
2129 |
+
if ( $hasCustomIconUrl ) {
|
2130 |
+
//Is it a Dashicon?
|
2131 |
+
if ( (strpos($tempIconUrl, 'dashicons-') === 0) ) {
|
2132 |
+
$item['css_class'] = ameMenuItem::get($item, 'css_class', '') . ' ame-has-custom-dashicon';
|
2133 |
+
//Is it a URL-looking thing and not an inline image?
|
2134 |
+
} else if ( (strpos($tempIconUrl, '/') !== false) && (strpos($tempIconUrl, 'data:image') === false) ) {
|
2135 |
+
$item['css_class'] = ameMenuItem::get($item, 'css_class', '') . ' ame-has-custom-image-url';
|
2136 |
+
}
|
2137 |
}
|
2138 |
|
2139 |
//WPML support: Translate only custom titles. See further below.
|
2649 |
//WPML support.
|
2650 |
$this->options['wpml_support_enabled'] = !empty($this->post['wpml_support_enabled']);
|
2651 |
|
2652 |
+
//bbPress override support.
|
2653 |
+
$this->options['bbpress_override_enabled'] = !empty($this->post['bbpress_override_enabled']);
|
2654 |
+
|
2655 |
//Active modules.
|
2656 |
$activeModules = isset($this->post['active_modules']) ? (array)$this->post['active_modules'] : array();
|
2657 |
$activeModules = array_fill_keys(array_map('strval', $activeModules), true);
|
3472 |
}
|
3473 |
|
3474 |
// "/wp-admin/index.php" should match "/wp-admin/".
|
3475 |
+
static $wpAdminDir = null;
|
3476 |
+
if ( $wpAdminDir === null ) {
|
3477 |
+
$wpAdminDir = '/wp-admin/';
|
3478 |
+
if ( has_filter('admin_url') ) {
|
3479 |
+
//Detect modified admin base URLs. For example, some security and branding plugins
|
3480 |
+
//replace "wp-admin" with "something-else".
|
3481 |
+
$suffix = 'ame-4425-admin-path-test';
|
3482 |
+
$testUrl = self_admin_url($suffix);
|
3483 |
+
$lastSlash = strrpos($testUrl, '/', -strlen($suffix) + 1);
|
3484 |
+
if ( $lastSlash !== false ) {
|
3485 |
+
$firstSlash = strrpos($testUrl, '/', -strlen($suffix) - 2);
|
3486 |
+
if ( ($firstSlash !== false) && ($firstSlash !== $lastSlash) ) {
|
3487 |
+
$wpAdminDir = substr($testUrl, $firstSlash, $lastSlash - $firstSlash + 1);
|
3488 |
+
}
|
3489 |
+
}
|
3490 |
+
}
|
3491 |
+
}
|
3492 |
+
|
3493 |
if (
|
3494 |
+
($this->endsWith($path1, $wpAdminDir . 'index.php') && $this->endsWith($path2, $wpAdminDir))
|
3495 |
+
|| ($this->endsWith($path2, $wpAdminDir . 'index.php') && $this->endsWith($path1, $wpAdminDir))
|
3496 |
) {
|
3497 |
return true;
|
3498 |
}
|
3647 |
'ame-helper-style',
|
3648 |
plugins_url('css/admin.css', $this->plugin_file),
|
3649 |
array(),
|
3650 |
+
'20201031'
|
3651 |
);
|
3652 |
|
3653 |
if ( $this->options['force_custom_dashicons'] ) {
|
includes/menu-item.php
CHANGED
@@ -525,7 +525,10 @@ abstract class ameMenuItem {
|
|
525 |
//add_query_arg() might be more robust, but it's significantly slower.
|
526 |
$url = $base_file
|
527 |
. ((strpos($base_file, '?') === false) ? '?' : '&')
|
528 |
-
. 'page=' .
|
|
|
|
|
|
|
529 |
} else {
|
530 |
$url = $menu_url;
|
531 |
}
|
525 |
//add_query_arg() might be more robust, but it's significantly slower.
|
526 |
$url = $base_file
|
527 |
. ((strpos($base_file, '?') === false) ? '?' : '&')
|
528 |
+
. 'page=' . $menu_url;
|
529 |
+
//Surprisingly, WordPress does NOT encode the menu slug when using it in a query parameter ("?page=slug").
|
530 |
+
//This allows plugins to use tricks like passing additional query parameters by simply appending them
|
531 |
+
//to the slug. For example, this works: "something¶m=foo".
|
532 |
} else {
|
533 |
$url = $menu_url;
|
534 |
}
|
includes/menu.php
CHANGED
@@ -17,9 +17,13 @@ abstract class ameMenu {
|
|
17 |
* @return array
|
18 |
*/
|
19 |
public static function load_json($json, $assume_correct_format = false, $always_normalize = false) {
|
20 |
-
$arr = json_decode($json, true);
|
21 |
if ( !is_array($arr) ) {
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
}
|
24 |
return self::load_array($arr, $assume_correct_format, $always_normalize);
|
25 |
}
|
@@ -85,6 +89,7 @@ abstract class ameMenu {
|
|
85 |
if ( isset($arr['color_css']) && is_string($arr['color_css']) ) {
|
86 |
$menu['color_css'] = $arr['color_css'];
|
87 |
$menu['color_css_modified'] = isset($arr['color_css_modified']) ? intval($arr['color_css_modified']) : 0;
|
|
|
88 |
}
|
89 |
|
90 |
//Sanitize color presets.
|
17 |
* @return array
|
18 |
*/
|
19 |
public static function load_json($json, $assume_correct_format = false, $always_normalize = false) {
|
20 |
+
$arr = json_decode($json, true); //TODO: Consider ignoring or substituting invalid UTF-8 characters.
|
21 |
if ( !is_array($arr) ) {
|
22 |
+
$message = 'The input is not a valid JSON-encoded admin menu.';
|
23 |
+
if ( function_exists('json_last_error_msg') ) {
|
24 |
+
$message .= ' ' . json_last_error_msg();
|
25 |
+
}
|
26 |
+
throw new InvalidMenuException($message);
|
27 |
}
|
28 |
return self::load_array($arr, $assume_correct_format, $always_normalize);
|
29 |
}
|
89 |
if ( isset($arr['color_css']) && is_string($arr['color_css']) ) {
|
90 |
$menu['color_css'] = $arr['color_css'];
|
91 |
$menu['color_css_modified'] = isset($arr['color_css_modified']) ? intval($arr['color_css_modified']) : 0;
|
92 |
+
$menu['icon_color_overrides'] = isset($arr['icon_color_overrides']) ? $arr['icon_color_overrides'] : null;
|
93 |
}
|
94 |
|
95 |
//Sanitize color presets.
|
includes/settings-page.php
CHANGED
@@ -375,6 +375,27 @@ $isProVersion = apply_filters('admin_menu_editor_is_pro', false);
|
|
375 |
</td>
|
376 |
</tr>
|
377 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
<tr>
|
379 |
<th scope="row">Error verbosity level</th>
|
380 |
<td>
|
375 |
</td>
|
376 |
</tr>
|
377 |
|
378 |
+
<tr>
|
379 |
+
<th scope="row">
|
380 |
+
bbPress override
|
381 |
+
</th>
|
382 |
+
<td>
|
383 |
+
<p>
|
384 |
+
<label>
|
385 |
+
<input type="checkbox" name="bbpress_override_enabled"
|
386 |
+
<?php checked($settings['bbpress_override_enabled']); ?>>
|
387 |
+
Prevent bbPress from resetting role capabilities
|
388 |
+
|
389 |
+
<br><span class="description">
|
390 |
+
By default, bbPress will automatically undo any changes that are made to dynamic
|
391 |
+
bbPress roles. Enable this option to override that behaviour and make it possible
|
392 |
+
to change bbPress role capabilities.
|
393 |
+
</span>
|
394 |
+
</label>
|
395 |
+
</p>
|
396 |
+
</td>
|
397 |
+
</tr>
|
398 |
+
|
399 |
<tr>
|
400 |
<th scope="row">Error verbosity level</th>
|
401 |
<td>
|
js/actor-manager.js
CHANGED
@@ -5,7 +5,7 @@ var __extends = (this && this.__extends) || (function () {
|
|
5 |
var extendStatics = function (d, b) {
|
6 |
extendStatics = Object.setPrototypeOf ||
|
7 |
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
8 |
-
function (d, b) { for (var p in b) if (
|
9 |
return extendStatics(d, b);
|
10 |
};
|
11 |
return function (d, b) {
|
5 |
var extendStatics = function (d, b) {
|
6 |
extendStatics = Object.setPrototypeOf ||
|
7 |
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
8 |
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
9 |
return extendStatics(d, b);
|
10 |
};
|
11 |
return function (d, b) {
|
js/admin-helpers.js
CHANGED
@@ -20,7 +20,7 @@
|
|
20 |
//Menu separators shouldn't be clickable and should have a custom class.
|
21 |
adminMenu
|
22 |
.find('.ws-submenu-separator')
|
23 |
-
.closest('a').click
|
24 |
return false;
|
25 |
})
|
26 |
.closest('li').addClass('ws-submenu-separator-wrap');
|
@@ -30,7 +30,7 @@
|
|
30 |
.find(
|
31 |
'a.menu-top.ame-unclickable-menu-item, ul.wp-submenu > li > a[href^="#ame-unclickable-menu-item"]'
|
32 |
)
|
33 |
-
.click
|
34 |
//Exception: At small viewport sizes, WordPress changes how top level menus work: clicking a menu
|
35 |
//now expands its submenu. We must not ignore that click or it will be impossible to expand the menu.
|
36 |
var viewportWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
|
20 |
//Menu separators shouldn't be clickable and should have a custom class.
|
21 |
adminMenu
|
22 |
.find('.ws-submenu-separator')
|
23 |
+
.closest('a').on('click', function() {
|
24 |
return false;
|
25 |
})
|
26 |
.closest('li').addClass('ws-submenu-separator-wrap');
|
30 |
.find(
|
31 |
'a.menu-top.ame-unclickable-menu-item, ul.wp-submenu > li > a[href^="#ame-unclickable-menu-item"]'
|
32 |
)
|
33 |
+
.on('click', function() {
|
34 |
//Exception: At small viewport sizes, WordPress changes how top level menus work: clicking a menu
|
35 |
//now expands its submenu. We must not ignore that click or it will be impossible to expand the menu.
|
36 |
var viewportWidth = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
|
js/jquery.form.js
CHANGED
@@ -1,1277 +1,1540 @@
|
|
1 |
/*!
|
2 |
* jQuery Form Plugin
|
3 |
-
* version: 3.
|
4 |
-
* Requires jQuery v1.
|
5 |
-
*
|
6 |
-
|
7 |
-
*
|
8 |
-
*
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
*/
|
11 |
-
/*global ActiveXObject */
|
12 |
|
13 |
-
|
14 |
(function (factory) {
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
(
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
var len = serialized.length;
|
275 |
-
var result = [];
|
276 |
-
var i, part;
|
277 |
-
for (i=0; i < len; i++) {
|
278 |
-
// #252; undo param space replacement
|
279 |
-
serialized[i] = serialized[i].replace(/\+/g,' ');
|
280 |
-
part = serialized[i].split('=');
|
281 |
-
// #278; use array instead of object storage, favoring array serializations
|
282 |
-
result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]);
|
283 |
-
}
|
284 |
-
return result;
|
285 |
-
}
|
286 |
-
|
287 |
-
// XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
|
288 |
-
function fileUploadXhr(a) {
|
289 |
-
var formdata = new FormData();
|
290 |
-
|
291 |
-
for (var i=0; i < a.length; i++) {
|
292 |
-
formdata.append(a[i].name, a[i].value);
|
293 |
-
}
|
294 |
-
|
295 |
-
if (options.extraData) {
|
296 |
-
var serializedData = deepSerialize(options.extraData);
|
297 |
-
for (i=0; i < serializedData.length; i++) {
|
298 |
-
if (serializedData[i]) {
|
299 |
-
formdata.append(serializedData[i][0], serializedData[i][1]);
|
300 |
-
}
|
301 |
-
}
|
302 |
-
}
|
303 |
-
|
304 |
-
options.data = null;
|
305 |
-
|
306 |
-
var s = $.extend(true, {}, $.ajaxSettings, options, {
|
307 |
-
contentType: false,
|
308 |
-
processData: false,
|
309 |
-
cache: false,
|
310 |
-
type: method || 'POST'
|
311 |
-
});
|
312 |
-
|
313 |
-
if (options.uploadProgress) {
|
314 |
-
// workaround because jqXHR does not expose upload property
|
315 |
-
s.xhr = function() {
|
316 |
-
var xhr = $.ajaxSettings.xhr();
|
317 |
-
if (xhr.upload) {
|
318 |
-
xhr.upload.addEventListener('progress', function(event) {
|
319 |
-
var percent = 0;
|
320 |
-
var position = event.loaded || event.position; /*event.position is deprecated*/
|
321 |
-
var total = event.total;
|
322 |
-
if (event.lengthComputable) {
|
323 |
-
percent = Math.ceil(position / total * 100);
|
324 |
-
}
|
325 |
-
options.uploadProgress(event, position, total, percent);
|
326 |
-
}, false);
|
327 |
-
}
|
328 |
-
return xhr;
|
329 |
-
};
|
330 |
-
}
|
331 |
-
|
332 |
-
s.data = null;
|
333 |
-
var beforeSend = s.beforeSend;
|
334 |
-
s.beforeSend = function(xhr, o) {
|
335 |
-
//Send FormData() provided by user
|
336 |
-
if (options.formData) {
|
337 |
-
o.data = options.formData;
|
338 |
-
}
|
339 |
-
else {
|
340 |
-
o.data = formdata;
|
341 |
-
}
|
342 |
-
if(beforeSend) {
|
343 |
-
beforeSend.call(this, xhr, o);
|
344 |
-
}
|
345 |
-
};
|
346 |
-
return $.ajax(s);
|
347 |
-
}
|
348 |
-
|
349 |
-
// private function for handling file uploads (hat tip to YAHOO!)
|
350 |
-
function fileUploadIframe(a) {
|
351 |
-
var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
|
352 |
-
var deferred = $.Deferred();
|
353 |
-
|
354 |
-
// #341
|
355 |
-
deferred.abort = function(status) {
|
356 |
-
xhr.abort(status);
|
357 |
-
};
|
358 |
-
|
359 |
-
if (a) {
|
360 |
-
// ensure that every serialized input is still enabled
|
361 |
-
for (i=0; i < elements.length; i++) {
|
362 |
-
el = $(elements[i]);
|
363 |
-
if ( hasProp ) {
|
364 |
-
el.prop('disabled', false);
|
365 |
-
}
|
366 |
-
else {
|
367 |
-
el.removeAttr('disabled');
|
368 |
-
}
|
369 |
-
}
|
370 |
-
}
|
371 |
-
|
372 |
-
s = $.extend(true, {}, $.ajaxSettings, options);
|
373 |
-
s.context = s.context || s;
|
374 |
-
id = 'jqFormIO' + (new Date().getTime());
|
375 |
-
if (s.iframeTarget) {
|
376 |
-
$io = $(s.iframeTarget);
|
377 |
-
n = $io.attr2('name');
|
378 |
-
if (!n) {
|
379 |
-
$io.attr2('name', id);
|
380 |
-
}
|
381 |
-
else {
|
382 |
-
id = n;
|
383 |
-
}
|
384 |
-
}
|
385 |
-
else {
|
386 |
-
$io = $('<iframe name="' + id + '" src="'+ s.iframeSrc +'" />');
|
387 |
-
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
|
388 |
-
}
|
389 |
-
io = $io[0];
|
390 |
-
|
391 |
-
|
392 |
-
xhr = { // mock object
|
393 |
-
aborted: 0,
|
394 |
-
responseText: null,
|
395 |
-
responseXML: null,
|
396 |
-
status: 0,
|
397 |
-
statusText: 'n/a',
|
398 |
-
getAllResponseHeaders: function() {},
|
399 |
-
getResponseHeader: function() {},
|
400 |
-
setRequestHeader: function() {},
|
401 |
-
abort: function(status) {
|
402 |
-
var e = (status === 'timeout' ? 'timeout' : 'aborted');
|
403 |
-
log('aborting upload... ' + e);
|
404 |
-
this.aborted = 1;
|
405 |
-
|
406 |
-
try { // #214, #257
|
407 |
-
if (io.contentWindow.document.execCommand) {
|
408 |
-
io.contentWindow.document.execCommand('Stop');
|
409 |
-
}
|
410 |
-
}
|
411 |
-
catch(ignore) {}
|
412 |
-
|
413 |
-
$io.attr('src', s.iframeSrc); // abort op in progress
|
414 |
-
xhr.error = e;
|
415 |
-
if (s.error) {
|
416 |
-
s.error.call(s.context, xhr, e, status);
|
417 |
-
}
|
418 |
-
if (g) {
|
419 |
-
$.event.trigger("ajaxError", [xhr, s, e]);
|
420 |
-
}
|
421 |
-
if (s.complete) {
|
422 |
-
s.complete.call(s.context, xhr, e);
|
423 |
-
}
|
424 |
-
}
|
425 |
-
};
|
426 |
-
|
427 |
-
g = s.global;
|
428 |
-
// trigger ajax global events so that activity/block indicators work like normal
|
429 |
-
if (g && 0 === $.active++) {
|
430 |
-
$.event.trigger("ajaxStart");
|
431 |
-
}
|
432 |
-
if (g) {
|
433 |
-
$.event.trigger("ajaxSend", [xhr, s]);
|
434 |
-
}
|
435 |
-
|
436 |
-
if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
|
437 |
-
if (s.global) {
|
438 |
-
$.active--;
|
439 |
-
}
|
440 |
-
deferred.reject();
|
441 |
-
return deferred;
|
442 |
-
}
|
443 |
-
if (xhr.aborted) {
|
444 |
-
deferred.reject();
|
445 |
-
return deferred;
|
446 |
-
}
|
447 |
-
|
448 |
-
// add submitting element to data if we know it
|
449 |
-
sub = form.clk;
|
450 |
-
if (sub) {
|
451 |
-
n = sub.name;
|
452 |
-
if (n && !sub.disabled) {
|
453 |
-
s.extraData = s.extraData || {};
|
454 |
-
s.extraData[n] = sub.value;
|
455 |
-
if (sub.type == "image") {
|
456 |
-
s.extraData[n+'.x'] = form.clk_x;
|
457 |
-
s.extraData[n+'.y'] = form.clk_y;
|
458 |
-
}
|
459 |
-
}
|
460 |
-
}
|
461 |
-
|
462 |
-
var CLIENT_TIMEOUT_ABORT = 1;
|
463 |
-
var SERVER_ABORT = 2;
|
464 |
-
|
465 |
-
function getDoc(frame) {
|
466 |
-
/* it looks like contentWindow or contentDocument do not
|
467 |
-
* carry the protocol property in ie8, when running under ssl
|
468 |
-
* frame.document is the only valid response document, since
|
469 |
-
* the protocol is know but not on the other two objects. strange?
|
470 |
-
* "Same origin policy" http://en.wikipedia.org/wiki/Same_origin_policy
|
471 |
-
*/
|
472 |
-
|
473 |
-
var doc = null;
|
474 |
-
|
475 |
-
// IE8 cascading access check
|
476 |
-
try {
|
477 |
-
if (frame.contentWindow) {
|
478 |
-
doc = frame.contentWindow.document;
|
479 |
-
}
|
480 |
-
} catch(err) {
|
481 |
-
// IE8 access denied under ssl & missing protocol
|
482 |
-
log('cannot get iframe.contentWindow document: ' + err);
|
483 |
-
}
|
484 |
-
|
485 |
-
if (doc) { // successful getting content
|
486 |
-
return doc;
|
487 |
-
}
|
488 |
-
|
489 |
-
try { // simply checking may throw in ie8 under ssl or mismatched protocol
|
490 |
-
doc = frame.contentDocument ? frame.contentDocument : frame.document;
|
491 |
-
} catch(err) {
|
492 |
-
// last attempt
|
493 |
-
log('cannot get iframe.contentDocument: ' + err);
|
494 |
-
doc = frame.document;
|
495 |
-
}
|
496 |
-
return doc;
|
497 |
-
}
|
498 |
-
|
499 |
-
// Rails CSRF hack (thanks to Yvan Barthelemy)
|
500 |
-
var csrf_token = $('meta[name=csrf-token]').attr('content');
|
501 |
-
var csrf_param = $('meta[name=csrf-param]').attr('content');
|
502 |
-
if (csrf_param && csrf_token) {
|
503 |
-
s.extraData = s.extraData || {};
|
504 |
-
s.extraData[csrf_param] = csrf_token;
|
505 |
-
}
|
506 |
-
|
507 |
-
// take a breath so that pending repaints get some cpu time before the upload starts
|
508 |
-
function doSubmit() {
|
509 |
-
// make sure form attrs are set
|
510 |
-
var t = $form.attr2('target'),
|
511 |
-
a = $form.attr2('action'),
|
512 |
-
mp = 'multipart/form-data',
|
513 |
-
et = $form.attr('enctype') || $form.attr('encoding') || mp;
|
514 |
-
|
515 |
-
// update form attrs in IE friendly way
|
516 |
-
form.setAttribute('target',id);
|
517 |
-
if (!method || /post/i.test(method) ) {
|
518 |
-
form.setAttribute('method', 'POST');
|
519 |
-
}
|
520 |
-
if (a != s.url) {
|
521 |
-
form.setAttribute('action', s.url);
|
522 |
-
}
|
523 |
-
|
524 |
-
// ie borks in some cases when setting encoding
|
525 |
-
if (! s.skipEncodingOverride && (!method || /post/i.test(method))) {
|
526 |
-
$form.attr({
|
527 |
-
encoding: 'multipart/form-data',
|
528 |
-
enctype: 'multipart/form-data'
|
529 |
-
});
|
530 |
-
}
|
531 |
-
|
532 |
-
// support timout
|
533 |
-
if (s.timeout) {
|
534 |
-
timeoutHandle = setTimeout(function() { timedOut = true; cb(CLIENT_TIMEOUT_ABORT); }, s.timeout);
|
535 |
-
}
|
536 |
-
|
537 |
-
// look for server aborts
|
538 |
-
function checkState() {
|
539 |
-
try {
|
540 |
-
var state = getDoc(io).readyState;
|
541 |
-
log('state = ' + state);
|
542 |
-
if (state && state.toLowerCase() == 'uninitialized') {
|
543 |
-
setTimeout(checkState,50);
|
544 |
-
}
|
545 |
-
}
|
546 |
-
catch(e) {
|
547 |
-
log('Server abort: ' , e, ' (', e.name, ')');
|
548 |
-
cb(SERVER_ABORT);
|
549 |
-
if (timeoutHandle) {
|
550 |
-
clearTimeout(timeoutHandle);
|
551 |
-
}
|
552 |
-
timeoutHandle = undefined;
|
553 |
-
}
|
554 |
-
}
|
555 |
-
|
556 |
-
// add "extra" data to form if provided in options
|
557 |
-
var extraInputs = [];
|
558 |
-
try {
|
559 |
-
if (s.extraData) {
|
560 |
-
for (var n in s.extraData) {
|
561 |
-
if (s.extraData.hasOwnProperty(n)) {
|
562 |
-
// if using the $.param format that allows for multiple values with the same name
|
563 |
-
if($.isPlainObject(s.extraData[n]) && s.extraData[n].hasOwnProperty('name') && s.extraData[n].hasOwnProperty('value')) {
|
564 |
-
extraInputs.push(
|
565 |
-
$('<input type="hidden" name="'+s.extraData[n].name+'">').val(s.extraData[n].value)
|
566 |
-
.appendTo(form)[0]);
|
567 |
-
} else {
|
568 |
-
extraInputs.push(
|
569 |
-
$('<input type="hidden" name="'+n+'">').val(s.extraData[n])
|
570 |
-
.appendTo(form)[0]);
|
571 |
-
}
|
572 |
-
}
|
573 |
-
}
|
574 |
-
}
|
575 |
-
|
576 |
-
if (!s.iframeTarget) {
|
577 |
-
// add iframe to doc and submit the form
|
578 |
-
$io.appendTo('body');
|
579 |
-
}
|
580 |
-
if (io.attachEvent) {
|
581 |
-
io.attachEvent('onload', cb);
|
582 |
-
}
|
583 |
-
else {
|
584 |
-
io.addEventListener('load', cb, false);
|
585 |
-
}
|
586 |
-
setTimeout(checkState,15);
|
587 |
-
|
588 |
-
try {
|
589 |
-
form.submit();
|
590 |
-
} catch(err) {
|
591 |
-
// just in case form has element with name/id of 'submit'
|
592 |
-
var submitFn = document.createElement('form').submit;
|
593 |
-
submitFn.apply(form);
|
594 |
-
}
|
595 |
-
}
|
596 |
-
finally {
|
597 |
-
// reset attrs and remove "extra" input elements
|
598 |
-
form.setAttribute('action',a);
|
599 |
-
form.setAttribute('enctype', et); // #380
|
600 |
-
if(t) {
|
601 |
-
form.setAttribute('target', t);
|
602 |
-
} else {
|
603 |
-
$form.removeAttr('target');
|
604 |
-
}
|
605 |
-
$(extraInputs).remove();
|
606 |
-
}
|
607 |
-
}
|
608 |
-
|
609 |
-
if (s.forceSync) {
|
610 |
-
doSubmit();
|
611 |
-
}
|
612 |
-
else {
|
613 |
-
setTimeout(doSubmit, 10); // this lets dom updates render
|
614 |
-
}
|
615 |
-
|
616 |
-
var data, doc, domCheckCount = 50, callbackProcessed;
|
617 |
-
|
618 |
-
function cb(e) {
|
619 |
-
if (xhr.aborted || callbackProcessed) {
|
620 |
-
return;
|
621 |
-
}
|
622 |
-
|
623 |
-
doc = getDoc(io);
|
624 |
-
if(!doc) {
|
625 |
-
log('cannot access response document');
|
626 |
-
e = SERVER_ABORT;
|
627 |
-
}
|
628 |
-
if (e === CLIENT_TIMEOUT_ABORT && xhr) {
|
629 |
-
xhr.abort('timeout');
|
630 |
-
deferred.reject(xhr, 'timeout');
|
631 |
-
return;
|
632 |
-
}
|
633 |
-
else if (e == SERVER_ABORT && xhr) {
|
634 |
-
xhr.abort('server abort');
|
635 |
-
deferred.reject(xhr, 'error', 'server abort');
|
636 |
-
return;
|
637 |
-
}
|
638 |
-
|
639 |
-
if (!doc || doc.location.href == s.iframeSrc) {
|
640 |
-
// response not received yet
|
641 |
-
if (!timedOut) {
|
642 |
-
return;
|
643 |
-
}
|
644 |
-
}
|
645 |
-
if (io.detachEvent) {
|
646 |
-
io.detachEvent('onload', cb);
|
647 |
-
}
|
648 |
-
else {
|
649 |
-
io.removeEventListener('load', cb, false);
|
650 |
-
}
|
651 |
-
|
652 |
-
var status = 'success', errMsg;
|
653 |
-
try {
|
654 |
-
if (timedOut) {
|
655 |
-
throw 'timeout';
|
656 |
-
}
|
657 |
-
|
658 |
-
var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
|
659 |
-
log('isXml='+isXml);
|
660 |
-
if (!isXml && window.opera && (doc.body === null || !doc.body.innerHTML)) {
|
661 |
-
if (--domCheckCount) {
|
662 |
-
// in some browsers (Opera) the iframe DOM is not always traversable when
|
663 |
-
// the onload callback fires, so we loop a bit to accommodate
|
664 |
-
log('requeing onLoad callback, DOM not available');
|
665 |
-
setTimeout(cb, 250);
|
666 |
-
return;
|
667 |
-
}
|
668 |
-
// let this fall through because server response could be an empty document
|
669 |
-
//log('Could not access iframe DOM after mutiple tries.');
|
670 |
-
//throw 'DOMException: not available';
|
671 |
-
}
|
672 |
-
|
673 |
-
//log('response detected');
|
674 |
-
var docRoot = doc.body ? doc.body : doc.documentElement;
|
675 |
-
xhr.responseText = docRoot ? docRoot.innerHTML : null;
|
676 |
-
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
677 |
-
if (isXml) {
|
678 |
-
s.dataType = 'xml';
|
679 |
-
}
|
680 |
-
xhr.getResponseHeader = function(header){
|
681 |
-
var headers = {'content-type': s.dataType};
|
682 |
-
return headers[header.toLowerCase()];
|
683 |
-
};
|
684 |
-
// support for XHR 'status' & 'statusText' emulation :
|
685 |
-
if (docRoot) {
|
686 |
-
xhr.status = Number( docRoot.getAttribute('status') ) || xhr.status;
|
687 |
-
xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
|
688 |
-
}
|
689 |
-
|
690 |
-
var dt = (s.dataType || '').toLowerCase();
|
691 |
-
var scr = /(json|script|text)/.test(dt);
|
692 |
-
if (scr || s.textarea) {
|
693 |
-
// see if user embedded response in textarea
|
694 |
-
var ta = doc.getElementsByTagName('textarea')[0];
|
695 |
-
if (ta) {
|
696 |
-
xhr.responseText = ta.value;
|
697 |
-
// support for XHR 'status' & 'statusText' emulation :
|
698 |
-
xhr.status = Number( ta.getAttribute('status') ) || xhr.status;
|
699 |
-
xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
|
700 |
-
}
|
701 |
-
else if (scr) {
|
702 |
-
// account for browsers injecting pre around json response
|
703 |
-
var pre = doc.getElementsByTagName('pre')[0];
|
704 |
-
var b = doc.getElementsByTagName('body')[0];
|
705 |
-
if (pre) {
|
706 |
-
xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
|
707 |
-
}
|
708 |
-
else if (b) {
|
709 |
-
xhr.responseText = b.textContent ? b.textContent : b.innerText;
|
710 |
-
}
|
711 |
-
}
|
712 |
-
}
|
713 |
-
else if (dt == 'xml' && !xhr.responseXML && xhr.responseText) {
|
714 |
-
xhr.responseXML = toXml(xhr.responseText);
|
715 |
-
}
|
716 |
-
|
717 |
-
try {
|
718 |
-
data = httpData(xhr, dt, s);
|
719 |
-
}
|
720 |
-
catch (err) {
|
721 |
-
status = 'parsererror';
|
722 |
-
xhr.error = errMsg = (err || status);
|
723 |
-
}
|
724 |
-
}
|
725 |
-
catch (err) {
|
726 |
-
log('error caught: ',err);
|
727 |
-
status = 'error';
|
728 |
-
xhr.error = errMsg = (err || status);
|
729 |
-
}
|
730 |
-
|
731 |
-
if (xhr.aborted) {
|
732 |
-
log('upload aborted');
|
733 |
-
status = null;
|
734 |
-
}
|
735 |
-
|
736 |
-
if (xhr.status) { // we've set xhr.status
|
737 |
-
status = (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) ? 'success' : 'error';
|
738 |
-
}
|
739 |
-
|
740 |
-
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
741 |
-
if (status === 'success') {
|
742 |
-
if (s.success) {
|
743 |
-
s.success.call(s.context, data, 'success', xhr);
|
744 |
-
}
|
745 |
-
deferred.resolve(xhr.responseText, 'success', xhr);
|
746 |
-
if (g) {
|
747 |
-
$.event.trigger("ajaxSuccess", [xhr, s]);
|
748 |
-
}
|
749 |
-
}
|
750 |
-
else if (status) {
|
751 |
-
if (errMsg === undefined) {
|
752 |
-
errMsg = xhr.statusText;
|
753 |
-
}
|
754 |
-
if (s.error) {
|
755 |
-
s.error.call(s.context, xhr, status, errMsg);
|
756 |
-
}
|
757 |
-
deferred.reject(xhr, 'error', errMsg);
|
758 |
-
if (g) {
|
759 |
-
$.event.trigger("ajaxError", [xhr, s, errMsg]);
|
760 |
-
}
|
761 |
-
}
|
762 |
-
|
763 |
-
if (g) {
|
764 |
-
$.event.trigger("ajaxComplete", [xhr, s]);
|
765 |
-
}
|
766 |
-
|
767 |
-
if (g && ! --$.active) {
|
768 |
-
$.event.trigger("ajaxStop");
|
769 |
-
}
|
770 |
-
|
771 |
-
if (s.complete) {
|
772 |
-
s.complete.call(s.context, xhr, status);
|
773 |
-
}
|
774 |
-
|
775 |
-
callbackProcessed = true;
|
776 |
-
if (s.timeout) {
|
777 |
-
clearTimeout(timeoutHandle);
|
778 |
-
}
|
779 |
-
|
780 |
-
// clean up
|
781 |
-
setTimeout(function() {
|
782 |
-
if (!s.iframeTarget) {
|
783 |
-
$io.remove();
|
784 |
-
}
|
785 |
-
else { //adding else to clean up existing iframe response.
|
786 |
-
$io.attr('src', s.iframeSrc);
|
787 |
-
}
|
788 |
-
xhr.responseXML = null;
|
789 |
-
}, 100);
|
790 |
-
}
|
791 |
-
|
792 |
-
var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
|
793 |
-
if (window.ActiveXObject) {
|
794 |
-
doc = new ActiveXObject('Microsoft.XMLDOM');
|
795 |
-
doc.async = 'false';
|
796 |
-
doc.loadXML(s);
|
797 |
-
}
|
798 |
-
else {
|
799 |
-
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
800 |
-
}
|
801 |
-
return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
|
802 |
-
};
|
803 |
-
var parseJSON = $.parseJSON || function(s) {
|
804 |
-
/*jslint evil:true */
|
805 |
-
return window['eval']('(' + s + ')');
|
806 |
-
};
|
807 |
-
|
808 |
-
var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
|
809 |
-
|
810 |
-
var ct = xhr.getResponseHeader('content-type') || '',
|
811 |
-
xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
|
812 |
-
data = xml ? xhr.responseXML : xhr.responseText;
|
813 |
-
|
814 |
-
if (xml && data.documentElement.nodeName === 'parsererror') {
|
815 |
-
if ($.error) {
|
816 |
-
$.error('parsererror');
|
817 |
-
}
|
818 |
-
}
|
819 |
-
if (s && s.dataFilter) {
|
820 |
-
data = s.dataFilter(data, type);
|
821 |
-
}
|
822 |
-
if (typeof data === 'string') {
|
823 |
-
if (type === 'json' || !type && ct.indexOf('json') >= 0) {
|
824 |
-
data = parseJSON(data);
|
825 |
-
} else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
|
826 |
-
$.globalEval(data);
|
827 |
-
}
|
828 |
-
}
|
829 |
-
return data;
|
830 |
-
};
|
831 |
-
|
832 |
-
return deferred;
|
833 |
-
}
|
834 |
-
};
|
835 |
-
|
836 |
-
/**
|
837 |
-
* ajaxForm() provides a mechanism for fully automating form submission.
|
838 |
-
*
|
839 |
-
* The advantages of using this method instead of ajaxSubmit() are:
|
840 |
-
*
|
841 |
-
* 1: This method will include coordinates for <input type="image" /> elements (if the element
|
842 |
-
* is used to submit the form).
|
843 |
-
* 2. This method will include the submit element's name/value data (for the element that was
|
844 |
-
* used to submit the form).
|
845 |
-
* 3. This method binds the submit() method to the form for you.
|
846 |
-
*
|
847 |
-
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
|
848 |
-
* passes the options argument along after properly binding events for submit elements and
|
849 |
-
* the form itself.
|
850 |
-
*/
|
851 |
-
$.fn.ajaxForm = function(options) {
|
852 |
-
options = options || {};
|
853 |
-
options.delegation = options.delegation && $.isFunction($.fn.on);
|
854 |
-
|
855 |
-
// in jQuery 1.3+ we can fix mistakes with the ready state
|
856 |
-
if (!options.delegation && this.length === 0) {
|
857 |
-
var o = { s: this.selector, c: this.context };
|
858 |
-
if (!$.isReady && o.s) {
|
859 |
-
log('DOM not ready, queuing ajaxForm');
|
860 |
-
$(function() {
|
861 |
-
$(o.s,o.c).ajaxForm(options);
|
862 |
-
});
|
863 |
-
return this;
|
864 |
-
}
|
865 |
-
// is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
|
866 |
-
log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
|
867 |
-
return this;
|
868 |
-
}
|
869 |
-
|
870 |
-
if ( options.delegation ) {
|
871 |
-
$(document)
|
872 |
-
.off('submit.form-plugin', this.selector, doAjaxSubmit)
|
873 |
-
.off('click.form-plugin', this.selector, captureSubmittingElement)
|
874 |
-
.on('submit.form-plugin', this.selector, options, doAjaxSubmit)
|
875 |
-
.on('click.form-plugin', this.selector, options, captureSubmittingElement);
|
876 |
-
return this;
|
877 |
-
}
|
878 |
-
|
879 |
-
return this.ajaxFormUnbind()
|
880 |
-
.bind('submit.form-plugin', options, doAjaxSubmit)
|
881 |
-
.bind('click.form-plugin', options, captureSubmittingElement);
|
882 |
-
};
|
883 |
-
|
884 |
-
// private event handlers
|
885 |
-
function doAjaxSubmit(e) {
|
886 |
-
/*jshint validthis:true */
|
887 |
-
var options = e.data;
|
888 |
-
if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
|
889 |
-
e.preventDefault();
|
890 |
-
$(e.target).ajaxSubmit(options); // #365
|
891 |
-
}
|
892 |
-
}
|
893 |
-
|
894 |
-
function captureSubmittingElement(e) {
|
895 |
-
/*jshint validthis:true */
|
896 |
-
var target = e.target;
|
897 |
-
var $el = $(target);
|
898 |
-
if (!($el.is("[type=submit],[type=image]"))) {
|
899 |
-
// is this a child element of the submit el? (ex: a span within a button)
|
900 |
-
var t = $el.closest('[type=submit]');
|
901 |
-
if (t.length === 0) {
|
902 |
-
return;
|
903 |
-
}
|
904 |
-
target = t[0];
|
905 |
-
}
|
906 |
-
var form = this;
|
907 |
-
form.clk = target;
|
908 |
-
if (target.type == 'image') {
|
909 |
-
if (e.offsetX !== undefined) {
|
910 |
-
form.clk_x = e.offsetX;
|
911 |
-
form.clk_y = e.offsetY;
|
912 |
-
} else if (typeof $.fn.offset == 'function') {
|
913 |
-
var offset = $el.offset();
|
914 |
-
form.clk_x = e.pageX - offset.left;
|
915 |
-
form.clk_y = e.pageY - offset.top;
|
916 |
-
} else {
|
917 |
-
form.clk_x = e.pageX - target.offsetLeft;
|
918 |
-
form.clk_y = e.pageY - target.offsetTop;
|
919 |
-
}
|
920 |
-
}
|
921 |
-
// clear form vars
|
922 |
-
setTimeout(function() { form.clk = form.clk_x = form.clk_y = null; }, 100);
|
923 |
-
}
|
924 |
-
|
925 |
-
|
926 |
-
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
|
927 |
-
$.fn.ajaxFormUnbind = function() {
|
928 |
-
return this.unbind('submit.form-plugin click.form-plugin');
|
929 |
-
};
|
930 |
-
|
931 |
-
/**
|
932 |
-
* formToArray() gathers form element data into an array of objects that can
|
933 |
-
* be passed to any of the following ajax functions: $.get, $.post, or load.
|
934 |
-
* Each object in the array has both a 'name' and 'value' property. An example of
|
935 |
-
* an array for a simple login form might be:
|
936 |
-
*
|
937 |
-
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
|
938 |
-
*
|
939 |
-
* It is this array that is passed to pre-submit callback functions provided to the
|
940 |
-
* ajaxSubmit() and ajaxForm() methods.
|
941 |
-
*/
|
942 |
-
$.fn.formToArray = function(semantic, elements) {
|
943 |
-
var a = [];
|
944 |
-
if (this.length === 0) {
|
945 |
-
return a;
|
946 |
-
}
|
947 |
-
|
948 |
-
var form = this[0];
|
949 |
-
var formId = this.attr('id');
|
950 |
-
var els = semantic ? form.getElementsByTagName('*') : form.elements;
|
951 |
-
var els2;
|
952 |
-
|
953 |
-
if (els && !/MSIE [678]/.test(navigator.userAgent)) { // #390
|
954 |
-
els = $(els).get(); // convert to standard array
|
955 |
-
}
|
956 |
-
|
957 |
-
// #386; account for inputs outside the form which use the 'form' attribute
|
958 |
-
if ( formId ) {
|
959 |
-
els2 = $(':input[form="' + formId + '"]').get(); // hat tip @thet
|
960 |
-
if ( els2.length ) {
|
961 |
-
els = (els || []).concat(els2);
|
962 |
-
}
|
963 |
-
}
|
964 |
-
|
965 |
-
if (!els || !els.length) {
|
966 |
-
return a;
|
967 |
-
}
|
968 |
-
|
969 |
-
var i,j,n,v,el,max,jmax;
|
970 |
-
for(i=0, max=els.length; i < max; i++) {
|
971 |
-
el = els[i];
|
972 |
-
n = el.name;
|
973 |
-
if (!n || el.disabled) {
|
974 |
-
continue;
|
975 |
-
}
|
976 |
-
|
977 |
-
if (semantic && form.clk && el.type == "image") {
|
978 |
-
// handle image inputs on the fly when semantic == true
|
979 |
-
if(form.clk == el) {
|
980 |
-
a.push({name: n, value: $(el).val(), type: el.type });
|
981 |
-
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
982 |
-
}
|
983 |
-
continue;
|
984 |
-
}
|
985 |
-
|
986 |
-
v = $.fieldValue(el, true);
|
987 |
-
if (v && v.constructor == Array) {
|
988 |
-
if (elements) {
|
989 |
-
elements.push(el);
|
990 |
-
}
|
991 |
-
for(j=0, jmax=v.length; j < jmax; j++) {
|
992 |
-
a.push({name: n, value: v[j]});
|
993 |
-
}
|
994 |
-
}
|
995 |
-
else if (feature.fileapi && el.type == 'file') {
|
996 |
-
if (elements) {
|
997 |
-
elements.push(el);
|
998 |
-
}
|
999 |
-
var files = el.files;
|
1000 |
-
if (files.length) {
|
1001 |
-
for (j=0; j < files.length; j++) {
|
1002 |
-
a.push({name: n, value: files[j], type: el.type});
|
1003 |
-
}
|
1004 |
-
}
|
1005 |
-
else {
|
1006 |
-
// #180
|
1007 |
-
a.push({ name: n, value: '', type: el.type });
|
1008 |
-
}
|
1009 |
-
}
|
1010 |
-
else if (v !== null && typeof v != 'undefined') {
|
1011 |
-
if (elements) {
|
1012 |
-
elements.push(el);
|
1013 |
-
}
|
1014 |
-
a.push({name: n, value: v, type: el.type, required: el.required});
|
1015 |
-
}
|
1016 |
-
}
|
1017 |
-
|
1018 |
-
if (!semantic && form.clk) {
|
1019 |
-
// input type=='image' are not found in elements array! handle it here
|
1020 |
-
var $input = $(form.clk), input = $input[0];
|
1021 |
-
n = input.name;
|
1022 |
-
if (n && !input.disabled && input.type == 'image') {
|
1023 |
-
a.push({name: n, value: $input.val()});
|
1024 |
-
a.push({name: n+'.x', value: form.clk_x}, {name: n+'.y', value: form.clk_y});
|
1025 |
-
}
|
1026 |
-
}
|
1027 |
-
return a;
|
1028 |
-
};
|
1029 |
-
|
1030 |
-
/**
|
1031 |
-
* Serializes form data into a 'submittable' string. This method will return a string
|
1032 |
-
* in the format: name1=value1&name2=value2
|
1033 |
-
*/
|
1034 |
-
$.fn.formSerialize = function(semantic) {
|
1035 |
-
//hand off to jQuery.param for proper encoding
|
1036 |
-
return $.param(this.formToArray(semantic));
|
1037 |
-
};
|
1038 |
-
|
1039 |
-
/**
|
1040 |
-
* Serializes all field elements in the jQuery object into a query string.
|
1041 |
-
* This method will return a string in the format: name1=value1&name2=value2
|
1042 |
-
*/
|
1043 |
-
$.fn.fieldSerialize = function(successful) {
|
1044 |
-
var a = [];
|
1045 |
-
this.each(function() {
|
1046 |
-
var n = this.name;
|
1047 |
-
if (!n) {
|
1048 |
-
return;
|
1049 |
-
}
|
1050 |
-
var v = $.fieldValue(this, successful);
|
1051 |
-
if (v && v.constructor == Array) {
|
1052 |
-
for (var i=0,max=v.length; i < max; i++) {
|
1053 |
-
a.push({name: n, value: v[i]});
|
1054 |
-
}
|
1055 |
-
}
|
1056 |
-
else if (v !== null && typeof v != 'undefined') {
|
1057 |
-
a.push({name: this.name, value: v});
|
1058 |
-
}
|
1059 |
-
});
|
1060 |
-
//hand off to jQuery.param for proper encoding
|
1061 |
-
return $.param(a);
|
1062 |
-
};
|
1063 |
-
|
1064 |
-
/**
|
1065 |
-
* Returns the value(s) of the element in the matched set. For example, consider the following form:
|
1066 |
-
*
|
1067 |
-
* <form><fieldset>
|
1068 |
-
* <input name="A" type="text" />
|
1069 |
-
* <input name="A" type="text" />
|
1070 |
-
* <input name="B" type="checkbox" value="B1" />
|
1071 |
-
* <input name="B" type="checkbox" value="B2"/>
|
1072 |
-
* <input name="C" type="radio" value="C1" />
|
1073 |
-
* <input name="C" type="radio" value="C2" />
|
1074 |
-
* </fieldset></form>
|
1075 |
-
*
|
1076 |
-
* var v = $('input[type=text]').fieldValue();
|
1077 |
-
* // if no values are entered into the text inputs
|
1078 |
-
* v == ['','']
|
1079 |
-
* // if values entered into the text inputs are 'foo' and 'bar'
|
1080 |
-
* v == ['foo','bar']
|
1081 |
-
*
|
1082 |
-
* var v = $('input[type=checkbox]').fieldValue();
|
1083 |
-
* // if neither checkbox is checked
|
1084 |
-
* v === undefined
|
1085 |
-
* // if both checkboxes are checked
|
1086 |
-
* v == ['B1', 'B2']
|
1087 |
-
*
|
1088 |
-
* var v = $('input[type=radio]').fieldValue();
|
1089 |
-
* // if neither radio is checked
|
1090 |
-
* v === undefined
|
1091 |
-
* // if first radio is checked
|
1092 |
-
* v == ['C1']
|
1093 |
-
*
|
1094 |
-
* The successful argument controls whether or not the field element must be 'successful'
|
1095 |
-
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
1096 |
-
* The default value of the successful argument is true. If this value is false the value(s)
|
1097 |
-
* for each element is returned.
|
1098 |
-
*
|
1099 |
-
* Note: This method *always* returns an array. If no valid value can be determined the
|
1100 |
-
* array will be empty, otherwise it will contain one or more values.
|
1101 |
-
*/
|
1102 |
-
$.fn.fieldValue = function(successful) {
|
1103 |
-
for (var val=[], i=0, max=this.length; i < max; i++) {
|
1104 |
-
var el = this[i];
|
1105 |
-
var v = $.fieldValue(el, successful);
|
1106 |
-
if (v === null || typeof v == 'undefined' || (v.constructor == Array && !v.length)) {
|
1107 |
-
continue;
|
1108 |
-
}
|
1109 |
-
if (v.constructor == Array) {
|
1110 |
-
$.merge(val, v);
|
1111 |
-
}
|
1112 |
-
else {
|
1113 |
-
val.push(v);
|
1114 |
-
}
|
1115 |
-
}
|
1116 |
-
return val;
|
1117 |
-
};
|
1118 |
-
|
1119 |
-
/**
|
1120 |
-
* Returns the value of the field element.
|
1121 |
-
*/
|
1122 |
-
$.fieldValue = function(el, successful) {
|
1123 |
-
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
|
1124 |
-
if (successful === undefined) {
|
1125 |
-
successful = true;
|
1126 |
-
}
|
1127 |
-
|
1128 |
-
if (successful && (!n || el.disabled || t == 'reset' || t == 'button' ||
|
1129 |
-
(t == 'checkbox' || t == 'radio') && !el.checked ||
|
1130 |
-
(t == 'submit' || t == 'image') && el.form && el.form.clk != el ||
|
1131 |
-
tag == 'select' && el.selectedIndex == -1)) {
|
1132 |
-
return null;
|
1133 |
-
}
|
1134 |
-
|
1135 |
-
if (tag == 'select') {
|
1136 |
-
var index = el.selectedIndex;
|
1137 |
-
if (index < 0) {
|
1138 |
-
return null;
|
1139 |
-
}
|
1140 |
-
var a = [], ops = el.options;
|
1141 |
-
var one = (t == 'select-one');
|
1142 |
-
var max = (one ? index+1 : ops.length);
|
1143 |
-
for(var i=(one ? index : 0); i < max; i++) {
|
1144 |
-
var op = ops[i];
|
1145 |
-
if (op.selected) {
|
1146 |
-
var v = op.value;
|
1147 |
-
if (!v) { // extra pain for IE...
|
1148 |
-
v = (op.attributes && op.attributes.value && !(op.attributes.value.specified)) ? op.text : op.value;
|
1149 |
-
}
|
1150 |
-
if (one) {
|
1151 |
-
return v;
|
1152 |
-
}
|
1153 |
-
a.push(v);
|
1154 |
-
}
|
1155 |
-
}
|
1156 |
-
return a;
|
1157 |
-
}
|
1158 |
-
return $(el).val();
|
1159 |
-
};
|
1160 |
-
|
1161 |
-
/**
|
1162 |
-
* Clears the form data. Takes the following actions on the form's input fields:
|
1163 |
-
* - input text fields will have their 'value' property set to the empty string
|
1164 |
-
* - select elements will have their 'selectedIndex' property set to -1
|
1165 |
-
* - checkbox and radio inputs will have their 'checked' property set to false
|
1166 |
-
* - inputs of type submit, button, reset, and hidden will *not* be effected
|
1167 |
-
* - button elements will *not* be effected
|
1168 |
-
*/
|
1169 |
-
$.fn.clearForm = function(includeHidden) {
|
1170 |
-
return this.each(function() {
|
1171 |
-
$('input,select,textarea', this).clearFields(includeHidden);
|
1172 |
-
});
|
1173 |
-
};
|
1174 |
-
|
1175 |
-
/**
|
1176 |
-
* Clears the selected form elements.
|
1177 |
-
*/
|
1178 |
-
$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
|
1179 |
-
var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
|
1180 |
-
return this.each(function() {
|
1181 |
-
var t = this.type, tag = this.tagName.toLowerCase();
|
1182 |
-
if (re.test(t) || tag == 'textarea') {
|
1183 |
-
this.value = '';
|
1184 |
-
}
|
1185 |
-
else if (t == 'checkbox' || t == 'radio') {
|
1186 |
-
this.checked = false;
|
1187 |
-
}
|
1188 |
-
else if (tag == 'select') {
|
1189 |
-
this.selectedIndex = -1;
|
1190 |
-
}
|
1191 |
-
else if (t == "file") {
|
1192 |
-
if (/MSIE/.test(navigator.userAgent)) {
|
1193 |
-
$(this).replaceWith($(this).clone(true));
|
1194 |
-
} else {
|
1195 |
-
$(this).val('');
|
1196 |
-
}
|
1197 |
-
}
|
1198 |
-
else if (includeHidden) {
|
1199 |
-
// includeHidden can be the value true, or it can be a selector string
|
1200 |
-
// indicating a special test; for example:
|
1201 |
-
// $('#myForm').clearForm('.special:hidden')
|
1202 |
-
// the above would clean hidden inputs that have the class of 'special'
|
1203 |
-
if ( (includeHidden === true && /hidden/.test(t)) ||
|
1204 |
-
(typeof includeHidden == 'string' && $(this).is(includeHidden)) ) {
|
1205 |
-
this.value = '';
|
1206 |
-
}
|
1207 |
-
}
|
1208 |
-
});
|
1209 |
-
};
|
1210 |
-
|
1211 |
-
/**
|
1212 |
-
* Resets the form data. Causes all form elements to be reset to their original value.
|
1213 |
-
*/
|
1214 |
-
$.fn.resetForm = function() {
|
1215 |
-
return this.each(function() {
|
1216 |
-
// guard against an input with the name of 'reset'
|
1217 |
-
// note that IE reports the reset function as an 'object'
|
1218 |
-
if (typeof this.reset == 'function' || (typeof this.reset == 'object' && !this.reset.nodeType)) {
|
1219 |
-
this.reset();
|
1220 |
-
}
|
1221 |
-
});
|
1222 |
-
};
|
1223 |
-
|
1224 |
-
/**
|
1225 |
-
* Enables or disables any matching elements.
|
1226 |
-
*/
|
1227 |
-
$.fn.enable = function(b) {
|
1228 |
-
if (b === undefined) {
|
1229 |
-
b = true;
|
1230 |
-
}
|
1231 |
-
return this.each(function() {
|
1232 |
-
this.disabled = !b;
|
1233 |
-
});
|
1234 |
-
};
|
1235 |
-
|
1236 |
-
/**
|
1237 |
-
* Checks/unchecks any matching checkboxes or radio buttons and
|
1238 |
-
* selects/deselects and matching option elements.
|
1239 |
-
*/
|
1240 |
-
$.fn.selected = function(select) {
|
1241 |
-
if (select === undefined) {
|
1242 |
-
select = true;
|
1243 |
-
}
|
1244 |
-
return this.each(function() {
|
1245 |
-
var t = this.type;
|
1246 |
-
if (t == 'checkbox' || t == 'radio') {
|
1247 |
-
this.checked = select;
|
1248 |
-
}
|
1249 |
-
else if (this.tagName.toLowerCase() == 'option') {
|
1250 |
-
var $sel = $(this).parent('select');
|
1251 |
-
if (select && $sel[0] && $sel[0].type == 'select-one') {
|
1252 |
-
// deselect all other options
|
1253 |
-
$sel.find('option').selected(false);
|
1254 |
-
}
|
1255 |
-
this.selected = select;
|
1256 |
-
}
|
1257 |
-
});
|
1258 |
-
};
|
1259 |
-
|
1260 |
-
// expose debug var
|
1261 |
-
$.fn.ajaxSubmit.debug = false;
|
1262 |
-
|
1263 |
-
// helper fn for console logging
|
1264 |
-
function log() {
|
1265 |
-
if (!$.fn.ajaxSubmit.debug) {
|
1266 |
-
return;
|
1267 |
-
}
|
1268 |
-
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments,'');
|
1269 |
-
if (window.console && window.console.log) {
|
1270 |
-
window.console.log(msg);
|
1271 |
-
}
|
1272 |
-
else if (window.opera && window.opera.postError) {
|
1273 |
-
window.opera.postError(msg);
|
1274 |
-
}
|
1275 |
-
}
|
1276 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1277 |
}));
|
1 |
/*!
|
2 |
* jQuery Form Plugin
|
3 |
+
* version: 4.3.0
|
4 |
+
* Requires jQuery v1.7.2 or later
|
5 |
+
* Project repository: https://github.com/jquery-form/form
|
6 |
+
|
7 |
+
* Copyright 2017 Kevin Morris
|
8 |
+
* Copyright 2006 M. Alsup
|
9 |
+
|
10 |
+
* Dual licensed under the LGPL-2.1+ or MIT licenses
|
11 |
+
* https://github.com/jquery-form/form#license
|
12 |
+
|
13 |
+
* This library is free software; you can redistribute it and/or
|
14 |
+
* modify it under the terms of the GNU Lesser General Public
|
15 |
+
* License as published by the Free Software Foundation; either
|
16 |
+
* version 2.1 of the License, or (at your option) any later version.
|
17 |
+
* This library is distributed in the hope that it will be useful,
|
18 |
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
19 |
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
20 |
+
* Lesser General Public License for more details.
|
21 |
*/
|
22 |
+
/* global ActiveXObject */
|
23 |
|
24 |
+
/* eslint-disable */
|
25 |
(function (factory) {
|
26 |
+
if (typeof define === 'function' && define.amd) {
|
27 |
+
// AMD. Register as an anonymous module.
|
28 |
+
define(['jquery'], factory);
|
29 |
+
} else if (typeof module === 'object' && module.exports) {
|
30 |
+
// Node/CommonJS
|
31 |
+
module.exports = function( root, jQuery ) {
|
32 |
+
if (typeof jQuery === 'undefined') {
|
33 |
+
// require('jQuery') returns a factory that requires window to build a jQuery instance, we normalize how we use modules
|
34 |
+
// that require this pattern but the window provided is a noop if it's defined (how jquery works)
|
35 |
+
if (typeof window !== 'undefined') {
|
36 |
+
jQuery = require('jquery');
|
37 |
+
}
|
38 |
+
else {
|
39 |
+
jQuery = require('jquery')(root);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
factory(jQuery);
|
43 |
+
return jQuery;
|
44 |
+
};
|
45 |
+
} else {
|
46 |
+
// Browser globals
|
47 |
+
factory(jQuery);
|
48 |
+
}
|
49 |
+
|
50 |
+
}(function ($) {
|
51 |
+
/* eslint-enable */
|
52 |
+
'use strict';
|
53 |
+
|
54 |
+
/*
|
55 |
+
Usage Note:
|
56 |
+
-----------
|
57 |
+
Do not use both ajaxSubmit and ajaxForm on the same form. These
|
58 |
+
functions are mutually exclusive. Use ajaxSubmit if you want
|
59 |
+
to bind your own submit handler to the form. For example,
|
60 |
+
|
61 |
+
$(document).ready(function() {
|
62 |
+
$('#myForm').on('submit', function(e) {
|
63 |
+
e.preventDefault(); // <-- important
|
64 |
+
$(this).ajaxSubmit({
|
65 |
+
target: '#output'
|
66 |
+
});
|
67 |
+
});
|
68 |
+
});
|
69 |
+
|
70 |
+
Use ajaxForm when you want the plugin to manage all the event binding
|
71 |
+
for you. For example,
|
72 |
+
|
73 |
+
$(document).ready(function() {
|
74 |
+
$('#myForm').ajaxForm({
|
75 |
+
target: '#output'
|
76 |
+
});
|
77 |
+
});
|
78 |
+
|
79 |
+
You can also use ajaxForm with delegation (requires jQuery v1.7+), so the
|
80 |
+
form does not have to exist when you invoke ajaxForm:
|
81 |
+
|
82 |
+
$('#myForm').ajaxForm({
|
83 |
+
delegation: true,
|
84 |
+
target: '#output'
|
85 |
+
});
|
86 |
+
|
87 |
+
When using ajaxForm, the ajaxSubmit function will be invoked for you
|
88 |
+
at the appropriate time.
|
89 |
+
*/
|
90 |
+
|
91 |
+
var rCRLF = /\r?\n/g;
|
92 |
+
|
93 |
+
/**
|
94 |
+
* Feature detection
|
95 |
+
*/
|
96 |
+
var feature = {};
|
97 |
+
|
98 |
+
feature.fileapi = $('<input type="file">').get(0).files !== undefined;
|
99 |
+
feature.formdata = (typeof window.FormData !== 'undefined');
|
100 |
+
|
101 |
+
var hasProp = !!$.fn.prop;
|
102 |
+
|
103 |
+
// attr2 uses prop when it can but checks the return type for
|
104 |
+
// an expected string. This accounts for the case where a form
|
105 |
+
// contains inputs with names like "action" or "method"; in those
|
106 |
+
// cases "prop" returns the element
|
107 |
+
$.fn.attr2 = function() {
|
108 |
+
if (!hasProp) {
|
109 |
+
return this.attr.apply(this, arguments);
|
110 |
+
}
|
111 |
+
|
112 |
+
var val = this.prop.apply(this, arguments);
|
113 |
+
|
114 |
+
if ((val && val.jquery) || typeof val === 'string') {
|
115 |
+
return val;
|
116 |
+
}
|
117 |
+
|
118 |
+
return this.attr.apply(this, arguments);
|
119 |
+
};
|
120 |
+
|
121 |
+
/**
|
122 |
+
* ajaxSubmit() provides a mechanism for immediately submitting
|
123 |
+
* an HTML form using AJAX.
|
124 |
+
*
|
125 |
+
* @param {object|string} options jquery.form.js parameters or custom url for submission
|
126 |
+
* @param {object} data extraData
|
127 |
+
* @param {string} dataType ajax dataType
|
128 |
+
* @param {function} onSuccess ajax success callback function
|
129 |
+
*/
|
130 |
+
$.fn.ajaxSubmit = function(options, data, dataType, onSuccess) {
|
131 |
+
// fast fail if nothing selected (http://dev.jquery.com/ticket/2752)
|
132 |
+
if (!this.length) {
|
133 |
+
log('ajaxSubmit: skipping submit process - no element selected');
|
134 |
+
|
135 |
+
return this;
|
136 |
+
}
|
137 |
+
|
138 |
+
/* eslint consistent-this: ["error", "$form"] */
|
139 |
+
var method, action, url, isMsie, iframeSrc, $form = this;
|
140 |
+
|
141 |
+
if (typeof options === 'function') {
|
142 |
+
options = {success: options};
|
143 |
+
|
144 |
+
} else if (typeof options === 'string' || (options === false && arguments.length > 0)) {
|
145 |
+
options = {
|
146 |
+
'url' : options,
|
147 |
+
'data' : data,
|
148 |
+
'dataType' : dataType
|
149 |
+
};
|
150 |
+
|
151 |
+
if (typeof onSuccess === 'function') {
|
152 |
+
options.success = onSuccess;
|
153 |
+
}
|
154 |
+
|
155 |
+
} else if (typeof options === 'undefined') {
|
156 |
+
options = {};
|
157 |
+
}
|
158 |
+
|
159 |
+
method = options.method || options.type || this.attr2('method');
|
160 |
+
action = options.url || this.attr2('action');
|
161 |
+
|
162 |
+
url = (typeof action === 'string') ? $.trim(action) : '';
|
163 |
+
url = url || window.location.href || '';
|
164 |
+
if (url) {
|
165 |
+
// clean url (don't include hash vaue)
|
166 |
+
url = (url.match(/^([^#]+)/) || [])[1];
|
167 |
+
}
|
168 |
+
// IE requires javascript:false in https, but this breaks chrome >83 and goes against spec.
|
169 |
+
// Instead of using javascript:false always, let's only apply it for IE.
|
170 |
+
isMsie = /(MSIE|Trident)/.test(navigator.userAgent || '');
|
171 |
+
iframeSrc = (isMsie && /^https/i.test(window.location.href || '')) ? 'javascript:false' : 'about:blank'; // eslint-disable-line no-script-url
|
172 |
+
|
173 |
+
options = $.extend(true, {
|
174 |
+
url : url,
|
175 |
+
success : $.ajaxSettings.success,
|
176 |
+
type : method || $.ajaxSettings.type,
|
177 |
+
iframeSrc : iframeSrc
|
178 |
+
}, options);
|
179 |
+
|
180 |
+
// hook for manipulating the form data before it is extracted;
|
181 |
+
// convenient for use with rich editors like tinyMCE or FCKEditor
|
182 |
+
var veto = {};
|
183 |
+
|
184 |
+
this.trigger('form-pre-serialize', [this, options, veto]);
|
185 |
+
|
186 |
+
if (veto.veto) {
|
187 |
+
log('ajaxSubmit: submit vetoed via form-pre-serialize trigger');
|
188 |
+
|
189 |
+
return this;
|
190 |
+
}
|
191 |
+
|
192 |
+
// provide opportunity to alter form data before it is serialized
|
193 |
+
if (options.beforeSerialize && options.beforeSerialize(this, options) === false) {
|
194 |
+
log('ajaxSubmit: submit aborted via beforeSerialize callback');
|
195 |
+
|
196 |
+
return this;
|
197 |
+
}
|
198 |
+
|
199 |
+
var traditional = options.traditional;
|
200 |
+
|
201 |
+
if (typeof traditional === 'undefined') {
|
202 |
+
traditional = $.ajaxSettings.traditional;
|
203 |
+
}
|
204 |
+
|
205 |
+
var elements = [];
|
206 |
+
var qx, a = this.formToArray(options.semantic, elements, options.filtering);
|
207 |
+
|
208 |
+
if (options.data) {
|
209 |
+
var optionsData = $.isFunction(options.data) ? options.data(a) : options.data;
|
210 |
+
|
211 |
+
options.extraData = optionsData;
|
212 |
+
qx = $.param(optionsData, traditional);
|
213 |
+
}
|
214 |
+
|
215 |
+
// give pre-submit callback an opportunity to abort the submit
|
216 |
+
if (options.beforeSubmit && options.beforeSubmit(a, this, options) === false) {
|
217 |
+
log('ajaxSubmit: submit aborted via beforeSubmit callback');
|
218 |
+
|
219 |
+
return this;
|
220 |
+
}
|
221 |
+
|
222 |
+
// fire vetoable 'validate' event
|
223 |
+
this.trigger('form-submit-validate', [a, this, options, veto]);
|
224 |
+
if (veto.veto) {
|
225 |
+
log('ajaxSubmit: submit vetoed via form-submit-validate trigger');
|
226 |
+
|
227 |
+
return this;
|
228 |
+
}
|
229 |
+
|
230 |
+
var q = $.param(a, traditional);
|
231 |
+
|
232 |
+
if (qx) {
|
233 |
+
q = (q ? (q + '&' + qx) : qx);
|
234 |
+
}
|
235 |
+
|
236 |
+
if (options.type.toUpperCase() === 'GET') {
|
237 |
+
options.url += (options.url.indexOf('?') >= 0 ? '&' : '?') + q;
|
238 |
+
options.data = null; // data is null for 'get'
|
239 |
+
} else {
|
240 |
+
options.data = q; // data is the query string for 'post'
|
241 |
+
}
|
242 |
+
|
243 |
+
var callbacks = [];
|
244 |
+
|
245 |
+
if (options.resetForm) {
|
246 |
+
callbacks.push(function() {
|
247 |
+
$form.resetForm();
|
248 |
+
});
|
249 |
+
}
|
250 |
+
|
251 |
+
if (options.clearForm) {
|
252 |
+
callbacks.push(function() {
|
253 |
+
$form.clearForm(options.includeHidden);
|
254 |
+
});
|
255 |
+
}
|
256 |
+
|
257 |
+
// perform a load on the target only if dataType is not provided
|
258 |
+
if (!options.dataType && options.target) {
|
259 |
+
var oldSuccess = options.success || function(){};
|
260 |
+
|
261 |
+
callbacks.push(function(data, textStatus, jqXHR) {
|
262 |
+
var successArguments = arguments,
|
263 |
+
fn = options.replaceTarget ? 'replaceWith' : 'html';
|
264 |
+
|
265 |
+
$(options.target)[fn](data).each(function(){
|
266 |
+
oldSuccess.apply(this, successArguments);
|
267 |
+
});
|
268 |
+
});
|
269 |
+
|
270 |
+
} else if (options.success) {
|
271 |
+
if ($.isArray(options.success)) {
|
272 |
+
$.merge(callbacks, options.success);
|
273 |
+
} else {
|
274 |
+
callbacks.push(options.success);
|
275 |
+
}
|
276 |
+
}
|
277 |
+
|
278 |
+
options.success = function(data, status, xhr) { // jQuery 1.4+ passes xhr as 3rd arg
|
279 |
+
var context = options.context || this; // jQuery 1.4+ supports scope context
|
280 |
+
|
281 |
+
for (var i = 0, max = callbacks.length; i < max; i++) {
|
282 |
+
callbacks[i].apply(context, [data, status, xhr || $form, $form]);
|
283 |
+
}
|
284 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
285 |
|
286 |
+
if (options.error) {
|
287 |
+
var oldError = options.error;
|
288 |
+
|
289 |
+
options.error = function(xhr, status, error) {
|
290 |
+
var context = options.context || this;
|
291 |
+
|
292 |
+
oldError.apply(context, [xhr, status, error, $form]);
|
293 |
+
};
|
294 |
+
}
|
295 |
+
|
296 |
+
if (options.complete) {
|
297 |
+
var oldComplete = options.complete;
|
298 |
+
|
299 |
+
options.complete = function(xhr, status) {
|
300 |
+
var context = options.context || this;
|
301 |
+
|
302 |
+
oldComplete.apply(context, [xhr, status, $form]);
|
303 |
+
};
|
304 |
+
}
|
305 |
+
|
306 |
+
// are there files to upload?
|
307 |
+
|
308 |
+
// [value] (issue #113), also see comment:
|
309 |
+
// https://github.com/malsup/form/commit/588306aedba1de01388032d5f42a60159eea9228#commitcomment-2180219
|
310 |
+
var fileInputs = $('input[type=file]:enabled', this).filter(function() {
|
311 |
+
return $(this).val() !== '';
|
312 |
+
});
|
313 |
+
var hasFileInputs = fileInputs.length > 0;
|
314 |
+
var mp = 'multipart/form-data';
|
315 |
+
var multipart = ($form.attr('enctype') === mp || $form.attr('encoding') === mp);
|
316 |
+
var fileAPI = feature.fileapi && feature.formdata;
|
317 |
+
|
318 |
+
log('fileAPI :' + fileAPI);
|
319 |
+
|
320 |
+
var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
|
321 |
+
var jqxhr;
|
322 |
+
|
323 |
+
// options.iframe allows user to force iframe mode
|
324 |
+
// 06-NOV-09: now defaulting to iframe mode if file input is detected
|
325 |
+
if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
|
326 |
+
// hack to fix Safari hang (thanks to Tim Molendijk for this)
|
327 |
+
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
|
328 |
+
if (options.closeKeepAlive) {
|
329 |
+
$.get(options.closeKeepAlive, function() {
|
330 |
+
jqxhr = fileUploadIframe(a);
|
331 |
+
});
|
332 |
+
|
333 |
+
} else {
|
334 |
+
jqxhr = fileUploadIframe(a);
|
335 |
+
}
|
336 |
+
|
337 |
+
} else if ((hasFileInputs || multipart) && fileAPI) {
|
338 |
+
jqxhr = fileUploadXhr(a);
|
339 |
+
|
340 |
+
} else {
|
341 |
+
jqxhr = $.ajax(options);
|
342 |
+
}
|
343 |
+
|
344 |
+
$form.removeData('jqxhr').data('jqxhr', jqxhr);
|
345 |
+
|
346 |
+
// clear element array
|
347 |
+
for (var k = 0; k < elements.length; k++) {
|
348 |
+
elements[k] = null;
|
349 |
+
}
|
350 |
+
|
351 |
+
// fire 'notify' event
|
352 |
+
this.trigger('form-submit-notify', [this, options]);
|
353 |
+
|
354 |
+
return this;
|
355 |
+
|
356 |
+
// utility fn for deep serialization
|
357 |
+
function deepSerialize(extraData) {
|
358 |
+
var serialized = $.param(extraData, options.traditional).split('&');
|
359 |
+
var len = serialized.length;
|
360 |
+
var result = [];
|
361 |
+
var i, part;
|
362 |
+
|
363 |
+
for (i = 0; i < len; i++) {
|
364 |
+
// #252; undo param space replacement
|
365 |
+
serialized[i] = serialized[i].replace(/\+/g, ' ');
|
366 |
+
part = serialized[i].split('=');
|
367 |
+
// #278; use array instead of object storage, favoring array serializations
|
368 |
+
result.push([decodeURIComponent(part[0]), decodeURIComponent(part[1])]);
|
369 |
+
}
|
370 |
+
|
371 |
+
return result;
|
372 |
+
}
|
373 |
+
|
374 |
+
// XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
|
375 |
+
function fileUploadXhr(a) {
|
376 |
+
var formdata = new FormData();
|
377 |
+
|
378 |
+
for (var i = 0; i < a.length; i++) {
|
379 |
+
formdata.append(a[i].name, a[i].value);
|
380 |
+
}
|
381 |
+
|
382 |
+
if (options.extraData) {
|
383 |
+
var serializedData = deepSerialize(options.extraData);
|
384 |
+
|
385 |
+
for (i = 0; i < serializedData.length; i++) {
|
386 |
+
if (serializedData[i]) {
|
387 |
+
formdata.append(serializedData[i][0], serializedData[i][1]);
|
388 |
+
}
|
389 |
+
}
|
390 |
+
}
|
391 |
+
|
392 |
+
options.data = null;
|
393 |
+
|
394 |
+
var s = $.extend(true, {}, $.ajaxSettings, options, {
|
395 |
+
contentType : false,
|
396 |
+
processData : false,
|
397 |
+
cache : false,
|
398 |
+
type : method || 'POST'
|
399 |
+
});
|
400 |
+
|
401 |
+
if (options.uploadProgress) {
|
402 |
+
// workaround because jqXHR does not expose upload property
|
403 |
+
s.xhr = function() {
|
404 |
+
var xhr = $.ajaxSettings.xhr();
|
405 |
+
|
406 |
+
if (xhr.upload) {
|
407 |
+
xhr.upload.addEventListener('progress', function(event) {
|
408 |
+
var percent = 0;
|
409 |
+
var position = event.loaded || event.position; /* event.position is deprecated */
|
410 |
+
var total = event.total;
|
411 |
+
|
412 |
+
if (event.lengthComputable) {
|
413 |
+
percent = Math.ceil(position / total * 100);
|
414 |
+
}
|
415 |
+
|
416 |
+
options.uploadProgress(event, position, total, percent);
|
417 |
+
}, false);
|
418 |
+
}
|
419 |
+
|
420 |
+
return xhr;
|
421 |
+
};
|
422 |
+
}
|
423 |
+
|
424 |
+
s.data = null;
|
425 |
+
|
426 |
+
var beforeSend = s.beforeSend;
|
427 |
+
|
428 |
+
s.beforeSend = function(xhr, o) {
|
429 |
+
// Send FormData() provided by user
|
430 |
+
if (options.formData) {
|
431 |
+
o.data = options.formData;
|
432 |
+
} else {
|
433 |
+
o.data = formdata;
|
434 |
+
}
|
435 |
+
|
436 |
+
if (beforeSend) {
|
437 |
+
beforeSend.call(this, xhr, o);
|
438 |
+
}
|
439 |
+
};
|
440 |
+
|
441 |
+
return $.ajax(s);
|
442 |
+
}
|
443 |
+
|
444 |
+
// private function for handling file uploads (hat tip to YAHOO!)
|
445 |
+
function fileUploadIframe(a) {
|
446 |
+
var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
|
447 |
+
var deferred = $.Deferred();
|
448 |
+
|
449 |
+
// #341
|
450 |
+
deferred.abort = function(status) {
|
451 |
+
xhr.abort(status);
|
452 |
+
};
|
453 |
+
|
454 |
+
if (a) {
|
455 |
+
// ensure that every serialized input is still enabled
|
456 |
+
for (i = 0; i < elements.length; i++) {
|
457 |
+
el = $(elements[i]);
|
458 |
+
if (hasProp) {
|
459 |
+
el.prop('disabled', false);
|
460 |
+
} else {
|
461 |
+
el.removeAttr('disabled');
|
462 |
+
}
|
463 |
+
}
|
464 |
+
}
|
465 |
+
|
466 |
+
s = $.extend(true, {}, $.ajaxSettings, options);
|
467 |
+
s.context = s.context || s;
|
468 |
+
id = 'jqFormIO' + new Date().getTime();
|
469 |
+
var ownerDocument = form.ownerDocument;
|
470 |
+
var $body = $form.closest('body');
|
471 |
+
|
472 |
+
if (s.iframeTarget) {
|
473 |
+
$io = $(s.iframeTarget, ownerDocument);
|
474 |
+
n = $io.attr2('name');
|
475 |
+
if (!n) {
|
476 |
+
$io.attr2('name', id);
|
477 |
+
} else {
|
478 |
+
id = n;
|
479 |
+
}
|
480 |
+
|
481 |
+
} else {
|
482 |
+
$io = $('<iframe name="' + id + '" src="' + s.iframeSrc + '" />', ownerDocument);
|
483 |
+
$io.css({position: 'absolute', top: '-1000px', left: '-1000px'});
|
484 |
+
}
|
485 |
+
io = $io[0];
|
486 |
+
|
487 |
+
|
488 |
+
xhr = { // mock object
|
489 |
+
aborted : 0,
|
490 |
+
responseText : null,
|
491 |
+
responseXML : null,
|
492 |
+
status : 0,
|
493 |
+
statusText : 'n/a',
|
494 |
+
getAllResponseHeaders : function() {},
|
495 |
+
getResponseHeader : function() {},
|
496 |
+
setRequestHeader : function() {},
|
497 |
+
abort : function(status) {
|
498 |
+
var e = (status === 'timeout' ? 'timeout' : 'aborted');
|
499 |
+
|
500 |
+
log('aborting upload... ' + e);
|
501 |
+
this.aborted = 1;
|
502 |
+
|
503 |
+
try { // #214, #257
|
504 |
+
if (io.contentWindow.document.execCommand) {
|
505 |
+
io.contentWindow.document.execCommand('Stop');
|
506 |
+
}
|
507 |
+
} catch (ignore) {}
|
508 |
+
|
509 |
+
$io.attr('src', s.iframeSrc); // abort op in progress
|
510 |
+
xhr.error = e;
|
511 |
+
if (s.error) {
|
512 |
+
s.error.call(s.context, xhr, e, status);
|
513 |
+
}
|
514 |
+
|
515 |
+
if (g) {
|
516 |
+
$.event.trigger('ajaxError', [xhr, s, e]);
|
517 |
+
}
|
518 |
+
|
519 |
+
if (s.complete) {
|
520 |
+
s.complete.call(s.context, xhr, e);
|
521 |
+
}
|
522 |
+
}
|
523 |
+
};
|
524 |
+
|
525 |
+
g = s.global;
|
526 |
+
// trigger ajax global events so that activity/block indicators work like normal
|
527 |
+
if (g && $.active++ === 0) {
|
528 |
+
$.event.trigger('ajaxStart');
|
529 |
+
}
|
530 |
+
if (g) {
|
531 |
+
$.event.trigger('ajaxSend', [xhr, s]);
|
532 |
+
}
|
533 |
+
|
534 |
+
if (s.beforeSend && s.beforeSend.call(s.context, xhr, s) === false) {
|
535 |
+
if (s.global) {
|
536 |
+
$.active--;
|
537 |
+
}
|
538 |
+
deferred.reject();
|
539 |
+
|
540 |
+
return deferred;
|
541 |
+
}
|
542 |
+
|
543 |
+
if (xhr.aborted) {
|
544 |
+
deferred.reject();
|
545 |
+
|
546 |
+
return deferred;
|
547 |
+
}
|
548 |
+
|
549 |
+
// add submitting element to data if we know it
|
550 |
+
sub = form.clk;
|
551 |
+
if (sub) {
|
552 |
+
n = sub.name;
|
553 |
+
if (n && !sub.disabled) {
|
554 |
+
s.extraData = s.extraData || {};
|
555 |
+
s.extraData[n] = sub.value;
|
556 |
+
if (sub.type === 'image') {
|
557 |
+
s.extraData[n + '.x'] = form.clk_x;
|
558 |
+
s.extraData[n + '.y'] = form.clk_y;
|
559 |
+
}
|
560 |
+
}
|
561 |
+
}
|
562 |
+
|
563 |
+
var CLIENT_TIMEOUT_ABORT = 1;
|
564 |
+
var SERVER_ABORT = 2;
|
565 |
+
|
566 |
+
function getDoc(frame) {
|
567 |
+
/* it looks like contentWindow or contentDocument do not
|
568 |
+
* carry the protocol property in ie8, when running under ssl
|
569 |
+
* frame.document is the only valid response document, since
|
570 |
+
* the protocol is know but not on the other two objects. strange?
|
571 |
+
* "Same origin policy" http://en.wikipedia.org/wiki/Same_origin_policy
|
572 |
+
*/
|
573 |
+
|
574 |
+
var doc = null;
|
575 |
+
|
576 |
+
// IE8 cascading access check
|
577 |
+
try {
|
578 |
+
if (frame.contentWindow) {
|
579 |
+
doc = frame.contentWindow.document;
|
580 |
+
}
|
581 |
+
} catch (err) {
|
582 |
+
// IE8 access denied under ssl & missing protocol
|
583 |
+
log('cannot get iframe.contentWindow document: ' + err);
|
584 |
+
}
|
585 |
+
|
586 |
+
if (doc) { // successful getting content
|
587 |
+
return doc;
|
588 |
+
}
|
589 |
+
|
590 |
+
try { // simply checking may throw in ie8 under ssl or mismatched protocol
|
591 |
+
doc = frame.contentDocument ? frame.contentDocument : frame.document;
|
592 |
+
} catch (err) {
|
593 |
+
// last attempt
|
594 |
+
log('cannot get iframe.contentDocument: ' + err);
|
595 |
+
doc = frame.document;
|
596 |
+
}
|
597 |
+
|
598 |
+
return doc;
|
599 |
+
}
|
600 |
+
|
601 |
+
// Rails CSRF hack (thanks to Yvan Barthelemy)
|
602 |
+
var csrf_token = $('meta[name=csrf-token]').attr('content');
|
603 |
+
var csrf_param = $('meta[name=csrf-param]').attr('content');
|
604 |
+
|
605 |
+
if (csrf_param && csrf_token) {
|
606 |
+
s.extraData = s.extraData || {};
|
607 |
+
s.extraData[csrf_param] = csrf_token;
|
608 |
+
}
|
609 |
+
|
610 |
+
// take a breath so that pending repaints get some cpu time before the upload starts
|
611 |
+
function doSubmit() {
|
612 |
+
// make sure form attrs are set
|
613 |
+
var t = $form.attr2('target'),
|
614 |
+
a = $form.attr2('action'),
|
615 |
+
mp = 'multipart/form-data',
|
616 |
+
et = $form.attr('enctype') || $form.attr('encoding') || mp;
|
617 |
+
|
618 |
+
// update form attrs in IE friendly way
|
619 |
+
form.setAttribute('target', id);
|
620 |
+
if (!method || /post/i.test(method)) {
|
621 |
+
form.setAttribute('method', 'POST');
|
622 |
+
}
|
623 |
+
if (a !== s.url) {
|
624 |
+
form.setAttribute('action', s.url);
|
625 |
+
}
|
626 |
+
|
627 |
+
// ie borks in some cases when setting encoding
|
628 |
+
if (!s.skipEncodingOverride && (!method || /post/i.test(method))) {
|
629 |
+
$form.attr({
|
630 |
+
encoding : 'multipart/form-data',
|
631 |
+
enctype : 'multipart/form-data'
|
632 |
+
});
|
633 |
+
}
|
634 |
+
|
635 |
+
// support timout
|
636 |
+
if (s.timeout) {
|
637 |
+
timeoutHandle = setTimeout(function() {
|
638 |
+
timedOut = true; cb(CLIENT_TIMEOUT_ABORT);
|
639 |
+
}, s.timeout);
|
640 |
+
}
|
641 |
+
|
642 |
+
// look for server aborts
|
643 |
+
function checkState() {
|
644 |
+
try {
|
645 |
+
var state = getDoc(io).readyState;
|
646 |
+
|
647 |
+
log('state = ' + state);
|
648 |
+
if (state && state.toLowerCase() === 'uninitialized') {
|
649 |
+
setTimeout(checkState, 50);
|
650 |
+
}
|
651 |
+
|
652 |
+
} catch (e) {
|
653 |
+
log('Server abort: ', e, ' (', e.name, ')');
|
654 |
+
cb(SERVER_ABORT); // eslint-disable-line callback-return
|
655 |
+
if (timeoutHandle) {
|
656 |
+
clearTimeout(timeoutHandle);
|
657 |
+
}
|
658 |
+
timeoutHandle = undefined;
|
659 |
+
}
|
660 |
+
}
|
661 |
+
|
662 |
+
// add "extra" data to form if provided in options
|
663 |
+
var extraInputs = [];
|
664 |
+
|
665 |
+
try {
|
666 |
+
if (s.extraData) {
|
667 |
+
for (var n in s.extraData) {
|
668 |
+
if (s.extraData.hasOwnProperty(n)) {
|
669 |
+
// if using the $.param format that allows for multiple values with the same name
|
670 |
+
if ($.isPlainObject(s.extraData[n]) && s.extraData[n].hasOwnProperty('name') && s.extraData[n].hasOwnProperty('value')) {
|
671 |
+
extraInputs.push(
|
672 |
+
$('<input type="hidden" name="' + s.extraData[n].name + '">', ownerDocument).val(s.extraData[n].value)
|
673 |
+
.appendTo(form)[0]);
|
674 |
+
} else {
|
675 |
+
extraInputs.push(
|
676 |
+
$('<input type="hidden" name="' + n + '">', ownerDocument).val(s.extraData[n])
|
677 |
+
.appendTo(form)[0]);
|
678 |
+
}
|
679 |
+
}
|
680 |
+
}
|
681 |
+
}
|
682 |
+
|
683 |
+
if (!s.iframeTarget) {
|
684 |
+
// add iframe to doc and submit the form
|
685 |
+
$io.appendTo($body);
|
686 |
+
}
|
687 |
+
|
688 |
+
if (io.attachEvent) {
|
689 |
+
io.attachEvent('onload', cb);
|
690 |
+
} else {
|
691 |
+
io.addEventListener('load', cb, false);
|
692 |
+
}
|
693 |
+
|
694 |
+
setTimeout(checkState, 15);
|
695 |
+
|
696 |
+
try {
|
697 |
+
form.submit();
|
698 |
+
|
699 |
+
} catch (err) {
|
700 |
+
// just in case form has element with name/id of 'submit'
|
701 |
+
var submitFn = document.createElement('form').submit;
|
702 |
+
|
703 |
+
submitFn.apply(form);
|
704 |
+
}
|
705 |
+
|
706 |
+
} finally {
|
707 |
+
// reset attrs and remove "extra" input elements
|
708 |
+
form.setAttribute('action', a);
|
709 |
+
form.setAttribute('enctype', et); // #380
|
710 |
+
if (t) {
|
711 |
+
form.setAttribute('target', t);
|
712 |
+
} else {
|
713 |
+
$form.removeAttr('target');
|
714 |
+
}
|
715 |
+
$(extraInputs).remove();
|
716 |
+
}
|
717 |
+
}
|
718 |
+
|
719 |
+
if (s.forceSync) {
|
720 |
+
doSubmit();
|
721 |
+
} else {
|
722 |
+
setTimeout(doSubmit, 10); // this lets dom updates render
|
723 |
+
}
|
724 |
+
|
725 |
+
var data, doc, domCheckCount = 50, callbackProcessed;
|
726 |
+
|
727 |
+
function cb(e) {
|
728 |
+
if (xhr.aborted || callbackProcessed) {
|
729 |
+
return;
|
730 |
+
}
|
731 |
+
|
732 |
+
doc = getDoc(io);
|
733 |
+
if (!doc) {
|
734 |
+
log('cannot access response document');
|
735 |
+
e = SERVER_ABORT;
|
736 |
+
}
|
737 |
+
if (e === CLIENT_TIMEOUT_ABORT && xhr) {
|
738 |
+
xhr.abort('timeout');
|
739 |
+
deferred.reject(xhr, 'timeout');
|
740 |
+
|
741 |
+
return;
|
742 |
+
|
743 |
+
}
|
744 |
+
if (e === SERVER_ABORT && xhr) {
|
745 |
+
xhr.abort('server abort');
|
746 |
+
deferred.reject(xhr, 'error', 'server abort');
|
747 |
+
|
748 |
+
return;
|
749 |
+
}
|
750 |
+
|
751 |
+
if (!doc || doc.location.href === s.iframeSrc) {
|
752 |
+
// response not received yet
|
753 |
+
if (!timedOut) {
|
754 |
+
return;
|
755 |
+
}
|
756 |
+
}
|
757 |
+
|
758 |
+
if (io.detachEvent) {
|
759 |
+
io.detachEvent('onload', cb);
|
760 |
+
} else {
|
761 |
+
io.removeEventListener('load', cb, false);
|
762 |
+
}
|
763 |
+
|
764 |
+
var status = 'success', errMsg;
|
765 |
+
|
766 |
+
try {
|
767 |
+
if (timedOut) {
|
768 |
+
throw 'timeout';
|
769 |
+
}
|
770 |
+
|
771 |
+
var isXml = s.dataType === 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
|
772 |
+
|
773 |
+
log('isXml=' + isXml);
|
774 |
+
|
775 |
+
if (!isXml && window.opera && (doc.body === null || !doc.body.innerHTML)) {
|
776 |
+
if (--domCheckCount) {
|
777 |
+
// in some browsers (Opera) the iframe DOM is not always traversable when
|
778 |
+
// the onload callback fires, so we loop a bit to accommodate
|
779 |
+
log('requeing onLoad callback, DOM not available');
|
780 |
+
setTimeout(cb, 250);
|
781 |
+
|
782 |
+
return;
|
783 |
+
}
|
784 |
+
// let this fall through because server response could be an empty document
|
785 |
+
// log('Could not access iframe DOM after mutiple tries.');
|
786 |
+
// throw 'DOMException: not available';
|
787 |
+
}
|
788 |
+
|
789 |
+
// log('response detected');
|
790 |
+
var docRoot = doc.body ? doc.body : doc.documentElement;
|
791 |
+
|
792 |
+
xhr.responseText = docRoot ? docRoot.innerHTML : null;
|
793 |
+
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
794 |
+
if (isXml) {
|
795 |
+
s.dataType = 'xml';
|
796 |
+
}
|
797 |
+
xhr.getResponseHeader = function(header){
|
798 |
+
var headers = {'content-type': s.dataType};
|
799 |
+
|
800 |
+
return headers[header.toLowerCase()];
|
801 |
+
};
|
802 |
+
// support for XHR 'status' & 'statusText' emulation :
|
803 |
+
if (docRoot) {
|
804 |
+
xhr.status = Number(docRoot.getAttribute('status')) || xhr.status;
|
805 |
+
xhr.statusText = docRoot.getAttribute('statusText') || xhr.statusText;
|
806 |
+
}
|
807 |
+
|
808 |
+
var dt = (s.dataType || '').toLowerCase();
|
809 |
+
var scr = /(json|script|text)/.test(dt);
|
810 |
+
|
811 |
+
if (scr || s.textarea) {
|
812 |
+
// see if user embedded response in textarea
|
813 |
+
var ta = doc.getElementsByTagName('textarea')[0];
|
814 |
+
|
815 |
+
if (ta) {
|
816 |
+
xhr.responseText = ta.value;
|
817 |
+
// support for XHR 'status' & 'statusText' emulation :
|
818 |
+
xhr.status = Number(ta.getAttribute('status')) || xhr.status;
|
819 |
+
xhr.statusText = ta.getAttribute('statusText') || xhr.statusText;
|
820 |
+
|
821 |
+
} else if (scr) {
|
822 |
+
// account for browsers injecting pre around json response
|
823 |
+
var pre = doc.getElementsByTagName('pre')[0];
|
824 |
+
var b = doc.getElementsByTagName('body')[0];
|
825 |
+
|
826 |
+
if (pre) {
|
827 |
+
xhr.responseText = pre.textContent ? pre.textContent : pre.innerText;
|
828 |
+
} else if (b) {
|
829 |
+
xhr.responseText = b.textContent ? b.textContent : b.innerText;
|
830 |
+
}
|
831 |
+
}
|
832 |
+
|
833 |
+
} else if (dt === 'xml' && !xhr.responseXML && xhr.responseText) {
|
834 |
+
xhr.responseXML = toXml(xhr.responseText); // eslint-disable-line no-use-before-define
|
835 |
+
}
|
836 |
+
|
837 |
+
try {
|
838 |
+
data = httpData(xhr, dt, s); // eslint-disable-line no-use-before-define
|
839 |
+
|
840 |
+
} catch (err) {
|
841 |
+
status = 'parsererror';
|
842 |
+
xhr.error = errMsg = (err || status);
|
843 |
+
}
|
844 |
+
|
845 |
+
} catch (err) {
|
846 |
+
log('error caught: ', err);
|
847 |
+
status = 'error';
|
848 |
+
xhr.error = errMsg = (err || status);
|
849 |
+
}
|
850 |
+
|
851 |
+
if (xhr.aborted) {
|
852 |
+
log('upload aborted');
|
853 |
+
status = null;
|
854 |
+
}
|
855 |
+
|
856 |
+
if (xhr.status) { // we've set xhr.status
|
857 |
+
status = ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) ? 'success' : 'error';
|
858 |
+
}
|
859 |
+
|
860 |
+
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
861 |
+
if (status === 'success') {
|
862 |
+
if (s.success) {
|
863 |
+
s.success.call(s.context, data, 'success', xhr);
|
864 |
+
}
|
865 |
+
|
866 |
+
deferred.resolve(xhr.responseText, 'success', xhr);
|
867 |
+
|
868 |
+
if (g) {
|
869 |
+
$.event.trigger('ajaxSuccess', [xhr, s]);
|
870 |
+
}
|
871 |
+
|
872 |
+
} else if (status) {
|
873 |
+
if (typeof errMsg === 'undefined') {
|
874 |
+
errMsg = xhr.statusText;
|
875 |
+
}
|
876 |
+
if (s.error) {
|
877 |
+
s.error.call(s.context, xhr, status, errMsg);
|
878 |
+
}
|
879 |
+
deferred.reject(xhr, 'error', errMsg);
|
880 |
+
if (g) {
|
881 |
+
$.event.trigger('ajaxError', [xhr, s, errMsg]);
|
882 |
+
}
|
883 |
+
}
|
884 |
+
|
885 |
+
if (g) {
|
886 |
+
$.event.trigger('ajaxComplete', [xhr, s]);
|
887 |
+
}
|
888 |
+
|
889 |
+
if (g && !--$.active) {
|
890 |
+
$.event.trigger('ajaxStop');
|
891 |
+
}
|
892 |
+
|
893 |
+
if (s.complete) {
|
894 |
+
s.complete.call(s.context, xhr, status);
|
895 |
+
}
|
896 |
+
|
897 |
+
callbackProcessed = true;
|
898 |
+
if (s.timeout) {
|
899 |
+
clearTimeout(timeoutHandle);
|
900 |
+
}
|
901 |
+
|
902 |
+
// clean up
|
903 |
+
setTimeout(function() {
|
904 |
+
if (!s.iframeTarget) {
|
905 |
+
$io.remove();
|
906 |
+
} else { // adding else to clean up existing iframe response.
|
907 |
+
$io.attr('src', s.iframeSrc);
|
908 |
+
}
|
909 |
+
xhr.responseXML = null;
|
910 |
+
}, 100);
|
911 |
+
}
|
912 |
+
|
913 |
+
var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
|
914 |
+
if (window.ActiveXObject) {
|
915 |
+
doc = new ActiveXObject('Microsoft.XMLDOM');
|
916 |
+
doc.async = 'false';
|
917 |
+
doc.loadXML(s);
|
918 |
+
|
919 |
+
} else {
|
920 |
+
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
921 |
+
}
|
922 |
+
|
923 |
+
return (doc && doc.documentElement && doc.documentElement.nodeName !== 'parsererror') ? doc : null;
|
924 |
+
};
|
925 |
+
var parseJSON = $.parseJSON || function(s) {
|
926 |
+
/* jslint evil:true */
|
927 |
+
return window['eval']('(' + s + ')'); // eslint-disable-line dot-notation
|
928 |
+
};
|
929 |
+
|
930 |
+
var httpData = function(xhr, type, s) { // mostly lifted from jq1.4.4
|
931 |
+
|
932 |
+
var ct = xhr.getResponseHeader('content-type') || '',
|
933 |
+
xml = ((type === 'xml' || !type) && ct.indexOf('xml') >= 0),
|
934 |
+
data = xml ? xhr.responseXML : xhr.responseText;
|
935 |
+
|
936 |
+
if (xml && data.documentElement.nodeName === 'parsererror') {
|
937 |
+
if ($.error) {
|
938 |
+
$.error('parsererror');
|
939 |
+
}
|
940 |
+
}
|
941 |
+
if (s && s.dataFilter) {
|
942 |
+
data = s.dataFilter(data, type);
|
943 |
+
}
|
944 |
+
if (typeof data === 'string') {
|
945 |
+
if ((type === 'json' || !type) && ct.indexOf('json') >= 0) {
|
946 |
+
data = parseJSON(data);
|
947 |
+
} else if ((type === 'script' || !type) && ct.indexOf('javascript') >= 0) {
|
948 |
+
$.globalEval(data);
|
949 |
+
}
|
950 |
+
}
|
951 |
+
|
952 |
+
return data;
|
953 |
+
};
|
954 |
+
|
955 |
+
return deferred;
|
956 |
+
}
|
957 |
+
};
|
958 |
+
|
959 |
+
/**
|
960 |
+
* ajaxForm() provides a mechanism for fully automating form submission.
|
961 |
+
*
|
962 |
+
* The advantages of using this method instead of ajaxSubmit() are:
|
963 |
+
*
|
964 |
+
* 1: This method will include coordinates for <input type="image"> elements (if the element
|
965 |
+
* is used to submit the form).
|
966 |
+
* 2. This method will include the submit element's name/value data (for the element that was
|
967 |
+
* used to submit the form).
|
968 |
+
* 3. This method binds the submit() method to the form for you.
|
969 |
+
*
|
970 |
+
* The options argument for ajaxForm works exactly as it does for ajaxSubmit. ajaxForm merely
|
971 |
+
* passes the options argument along after properly binding events for submit elements and
|
972 |
+
* the form itself.
|
973 |
+
*/
|
974 |
+
$.fn.ajaxForm = function(options, data, dataType, onSuccess) {
|
975 |
+
if (typeof options === 'string' || (options === false && arguments.length > 0)) {
|
976 |
+
options = {
|
977 |
+
'url' : options,
|
978 |
+
'data' : data,
|
979 |
+
'dataType' : dataType
|
980 |
+
};
|
981 |
+
|
982 |
+
if (typeof onSuccess === 'function') {
|
983 |
+
options.success = onSuccess;
|
984 |
+
}
|
985 |
+
}
|
986 |
+
|
987 |
+
options = options || {};
|
988 |
+
options.delegation = options.delegation && $.isFunction($.fn.on);
|
989 |
+
|
990 |
+
// in jQuery 1.3+ we can fix mistakes with the ready state
|
991 |
+
if (!options.delegation && this.length === 0) {
|
992 |
+
var o = {s: this.selector, c: this.context};
|
993 |
+
|
994 |
+
if (!$.isReady && o.s) {
|
995 |
+
log('DOM not ready, queuing ajaxForm');
|
996 |
+
$(function() {
|
997 |
+
$(o.s, o.c).ajaxForm(options);
|
998 |
+
});
|
999 |
+
|
1000 |
+
return this;
|
1001 |
+
}
|
1002 |
+
|
1003 |
+
// is your DOM ready? http://docs.jquery.com/Tutorials:Introducing_$(document).ready()
|
1004 |
+
log('terminating; zero elements found by selector' + ($.isReady ? '' : ' (DOM not ready)'));
|
1005 |
+
|
1006 |
+
return this;
|
1007 |
+
}
|
1008 |
+
|
1009 |
+
if (options.delegation) {
|
1010 |
+
$(document)
|
1011 |
+
.off('submit.form-plugin', this.selector, doAjaxSubmit)
|
1012 |
+
.off('click.form-plugin', this.selector, captureSubmittingElement)
|
1013 |
+
.on('submit.form-plugin', this.selector, options, doAjaxSubmit)
|
1014 |
+
.on('click.form-plugin', this.selector, options, captureSubmittingElement);
|
1015 |
+
|
1016 |
+
return this;
|
1017 |
+
}
|
1018 |
+
|
1019 |
+
if (options.beforeFormUnbind) {
|
1020 |
+
options.beforeFormUnbind(this, options);
|
1021 |
+
}
|
1022 |
+
|
1023 |
+
return this.ajaxFormUnbind()
|
1024 |
+
.on('submit.form-plugin', options, doAjaxSubmit)
|
1025 |
+
.on('click.form-plugin', options, captureSubmittingElement);
|
1026 |
+
};
|
1027 |
+
|
1028 |
+
// private event handlers
|
1029 |
+
function doAjaxSubmit(e) {
|
1030 |
+
/* jshint validthis:true */
|
1031 |
+
var options = e.data;
|
1032 |
+
|
1033 |
+
if (!e.isDefaultPrevented()) { // if event has been canceled, don't proceed
|
1034 |
+
e.preventDefault();
|
1035 |
+
$(e.target).closest('form').ajaxSubmit(options); // #365
|
1036 |
+
}
|
1037 |
+
}
|
1038 |
+
|
1039 |
+
function captureSubmittingElement(e) {
|
1040 |
+
/* jshint validthis:true */
|
1041 |
+
var target = e.target;
|
1042 |
+
var $el = $(target);
|
1043 |
+
|
1044 |
+
if (!$el.is('[type=submit],[type=image]')) {
|
1045 |
+
// is this a child element of the submit el? (ex: a span within a button)
|
1046 |
+
var t = $el.closest('[type=submit]');
|
1047 |
+
|
1048 |
+
if (t.length === 0) {
|
1049 |
+
return;
|
1050 |
+
}
|
1051 |
+
target = t[0];
|
1052 |
+
}
|
1053 |
+
|
1054 |
+
var form = target.form;
|
1055 |
+
|
1056 |
+
form.clk = target;
|
1057 |
+
|
1058 |
+
if (target.type === 'image') {
|
1059 |
+
if (typeof e.offsetX !== 'undefined') {
|
1060 |
+
form.clk_x = e.offsetX;
|
1061 |
+
form.clk_y = e.offsetY;
|
1062 |
+
|
1063 |
+
} else if (typeof $.fn.offset === 'function') {
|
1064 |
+
var offset = $el.offset();
|
1065 |
+
|
1066 |
+
form.clk_x = e.pageX - offset.left;
|
1067 |
+
form.clk_y = e.pageY - offset.top;
|
1068 |
+
|
1069 |
+
} else {
|
1070 |
+
form.clk_x = e.pageX - target.offsetLeft;
|
1071 |
+
form.clk_y = e.pageY - target.offsetTop;
|
1072 |
+
}
|
1073 |
+
}
|
1074 |
+
// clear form vars
|
1075 |
+
setTimeout(function() {
|
1076 |
+
form.clk = form.clk_x = form.clk_y = null;
|
1077 |
+
}, 100);
|
1078 |
+
}
|
1079 |
+
|
1080 |
+
|
1081 |
+
// ajaxFormUnbind unbinds the event handlers that were bound by ajaxForm
|
1082 |
+
$.fn.ajaxFormUnbind = function() {
|
1083 |
+
return this.off('submit.form-plugin click.form-plugin');
|
1084 |
+
};
|
1085 |
+
|
1086 |
+
/**
|
1087 |
+
* formToArray() gathers form element data into an array of objects that can
|
1088 |
+
* be passed to any of the following ajax functions: $.get, $.post, or load.
|
1089 |
+
* Each object in the array has both a 'name' and 'value' property. An example of
|
1090 |
+
* an array for a simple login form might be:
|
1091 |
+
*
|
1092 |
+
* [ { name: 'username', value: 'jresig' }, { name: 'password', value: 'secret' } ]
|
1093 |
+
*
|
1094 |
+
* It is this array that is passed to pre-submit callback functions provided to the
|
1095 |
+
* ajaxSubmit() and ajaxForm() methods.
|
1096 |
+
*/
|
1097 |
+
$.fn.formToArray = function(semantic, elements, filtering) {
|
1098 |
+
var a = [];
|
1099 |
+
|
1100 |
+
if (this.length === 0) {
|
1101 |
+
return a;
|
1102 |
+
}
|
1103 |
+
|
1104 |
+
var form = this[0];
|
1105 |
+
var formId = this.attr('id');
|
1106 |
+
var els = (semantic || typeof form.elements === 'undefined') ? form.getElementsByTagName('*') : form.elements;
|
1107 |
+
var els2;
|
1108 |
+
|
1109 |
+
if (els) {
|
1110 |
+
els = $.makeArray(els); // convert to standard array
|
1111 |
+
}
|
1112 |
+
|
1113 |
+
// #386; account for inputs outside the form which use the 'form' attribute
|
1114 |
+
// FinesseRus: in non-IE browsers outside fields are already included in form.elements.
|
1115 |
+
if (formId && (semantic || /(Edge|Trident)\//.test(navigator.userAgent))) {
|
1116 |
+
els2 = $(':input[form="' + formId + '"]').get(); // hat tip @thet
|
1117 |
+
if (els2.length) {
|
1118 |
+
els = (els || []).concat(els2);
|
1119 |
+
}
|
1120 |
+
}
|
1121 |
+
|
1122 |
+
if (!els || !els.length) {
|
1123 |
+
return a;
|
1124 |
+
}
|
1125 |
+
|
1126 |
+
if ($.isFunction(filtering)) {
|
1127 |
+
els = $.map(els, filtering);
|
1128 |
+
}
|
1129 |
+
|
1130 |
+
var i, j, n, v, el, max, jmax;
|
1131 |
+
|
1132 |
+
for (i = 0, max = els.length; i < max; i++) {
|
1133 |
+
el = els[i];
|
1134 |
+
n = el.name;
|
1135 |
+
if (!n || el.disabled) {
|
1136 |
+
continue;
|
1137 |
+
}
|
1138 |
+
|
1139 |
+
if (semantic && form.clk && el.type === 'image') {
|
1140 |
+
// handle image inputs on the fly when semantic == true
|
1141 |
+
if (form.clk === el) {
|
1142 |
+
a.push({name: n, value: $(el).val(), type: el.type});
|
1143 |
+
a.push({name: n + '.x', value: form.clk_x}, {name: n + '.y', value: form.clk_y});
|
1144 |
+
}
|
1145 |
+
continue;
|
1146 |
+
}
|
1147 |
+
|
1148 |
+
v = $.fieldValue(el, true);
|
1149 |
+
if (v && v.constructor === Array) {
|
1150 |
+
if (elements) {
|
1151 |
+
elements.push(el);
|
1152 |
+
}
|
1153 |
+
for (j = 0, jmax = v.length; j < jmax; j++) {
|
1154 |
+
a.push({name: n, value: v[j]});
|
1155 |
+
}
|
1156 |
+
|
1157 |
+
} else if (feature.fileapi && el.type === 'file') {
|
1158 |
+
if (elements) {
|
1159 |
+
elements.push(el);
|
1160 |
+
}
|
1161 |
+
|
1162 |
+
var files = el.files;
|
1163 |
+
|
1164 |
+
if (files.length) {
|
1165 |
+
for (j = 0; j < files.length; j++) {
|
1166 |
+
a.push({name: n, value: files[j], type: el.type});
|
1167 |
+
}
|
1168 |
+
} else {
|
1169 |
+
// #180
|
1170 |
+
a.push({name: n, value: '', type: el.type});
|
1171 |
+
}
|
1172 |
+
|
1173 |
+
} else if (v !== null && typeof v !== 'undefined') {
|
1174 |
+
if (elements) {
|
1175 |
+
elements.push(el);
|
1176 |
+
}
|
1177 |
+
a.push({name: n, value: v, type: el.type, required: el.required});
|
1178 |
+
}
|
1179 |
+
}
|
1180 |
+
|
1181 |
+
if (!semantic && form.clk) {
|
1182 |
+
// input type=='image' are not found in elements array! handle it here
|
1183 |
+
var $input = $(form.clk), input = $input[0];
|
1184 |
+
|
1185 |
+
n = input.name;
|
1186 |
+
|
1187 |
+
if (n && !input.disabled && input.type === 'image') {
|
1188 |
+
a.push({name: n, value: $input.val()});
|
1189 |
+
a.push({name: n + '.x', value: form.clk_x}, {name: n + '.y', value: form.clk_y});
|
1190 |
+
}
|
1191 |
+
}
|
1192 |
+
|
1193 |
+
return a;
|
1194 |
+
};
|
1195 |
+
|
1196 |
+
/**
|
1197 |
+
* Serializes form data into a 'submittable' string. This method will return a string
|
1198 |
+
* in the format: name1=value1&name2=value2
|
1199 |
+
*/
|
1200 |
+
$.fn.formSerialize = function(semantic) {
|
1201 |
+
// hand off to jQuery.param for proper encoding
|
1202 |
+
return $.param(this.formToArray(semantic));
|
1203 |
+
};
|
1204 |
+
|
1205 |
+
/**
|
1206 |
+
* Serializes all field elements in the jQuery object into a query string.
|
1207 |
+
* This method will return a string in the format: name1=value1&name2=value2
|
1208 |
+
*/
|
1209 |
+
$.fn.fieldSerialize = function(successful) {
|
1210 |
+
var a = [];
|
1211 |
+
|
1212 |
+
this.each(function() {
|
1213 |
+
var n = this.name;
|
1214 |
+
|
1215 |
+
if (!n) {
|
1216 |
+
return;
|
1217 |
+
}
|
1218 |
+
|
1219 |
+
var v = $.fieldValue(this, successful);
|
1220 |
+
|
1221 |
+
if (v && v.constructor === Array) {
|
1222 |
+
for (var i = 0, max = v.length; i < max; i++) {
|
1223 |
+
a.push({name: n, value: v[i]});
|
1224 |
+
}
|
1225 |
+
|
1226 |
+
} else if (v !== null && typeof v !== 'undefined') {
|
1227 |
+
a.push({name: this.name, value: v});
|
1228 |
+
}
|
1229 |
+
});
|
1230 |
+
|
1231 |
+
// hand off to jQuery.param for proper encoding
|
1232 |
+
return $.param(a);
|
1233 |
+
};
|
1234 |
+
|
1235 |
+
/**
|
1236 |
+
* Returns the value(s) of the element in the matched set. For example, consider the following form:
|
1237 |
+
*
|
1238 |
+
* <form><fieldset>
|
1239 |
+
* <input name="A" type="text">
|
1240 |
+
* <input name="A" type="text">
|
1241 |
+
* <input name="B" type="checkbox" value="B1">
|
1242 |
+
* <input name="B" type="checkbox" value="B2">
|
1243 |
+
* <input name="C" type="radio" value="C1">
|
1244 |
+
* <input name="C" type="radio" value="C2">
|
1245 |
+
* </fieldset></form>
|
1246 |
+
*
|
1247 |
+
* var v = $('input[type=text]').fieldValue();
|
1248 |
+
* // if no values are entered into the text inputs
|
1249 |
+
* v === ['','']
|
1250 |
+
* // if values entered into the text inputs are 'foo' and 'bar'
|
1251 |
+
* v === ['foo','bar']
|
1252 |
+
*
|
1253 |
+
* var v = $('input[type=checkbox]').fieldValue();
|
1254 |
+
* // if neither checkbox is checked
|
1255 |
+
* v === undefined
|
1256 |
+
* // if both checkboxes are checked
|
1257 |
+
* v === ['B1', 'B2']
|
1258 |
+
*
|
1259 |
+
* var v = $('input[type=radio]').fieldValue();
|
1260 |
+
* // if neither radio is checked
|
1261 |
+
* v === undefined
|
1262 |
+
* // if first radio is checked
|
1263 |
+
* v === ['C1']
|
1264 |
+
*
|
1265 |
+
* The successful argument controls whether or not the field element must be 'successful'
|
1266 |
+
* (per http://www.w3.org/TR/html4/interact/forms.html#successful-controls).
|
1267 |
+
* The default value of the successful argument is true. If this value is false the value(s)
|
1268 |
+
* for each element is returned.
|
1269 |
+
*
|
1270 |
+
* Note: This method *always* returns an array. If no valid value can be determined the
|
1271 |
+
* array will be empty, otherwise it will contain one or more values.
|
1272 |
+
*/
|
1273 |
+
$.fn.fieldValue = function(successful) {
|
1274 |
+
for (var val = [], i = 0, max = this.length; i < max; i++) {
|
1275 |
+
var el = this[i];
|
1276 |
+
var v = $.fieldValue(el, successful);
|
1277 |
+
|
1278 |
+
if (v === null || typeof v === 'undefined' || (v.constructor === Array && !v.length)) {
|
1279 |
+
continue;
|
1280 |
+
}
|
1281 |
+
|
1282 |
+
if (v.constructor === Array) {
|
1283 |
+
$.merge(val, v);
|
1284 |
+
} else {
|
1285 |
+
val.push(v);
|
1286 |
+
}
|
1287 |
+
}
|
1288 |
+
|
1289 |
+
return val;
|
1290 |
+
};
|
1291 |
+
|
1292 |
+
/**
|
1293 |
+
* Returns the value of the field element.
|
1294 |
+
*/
|
1295 |
+
$.fieldValue = function(el, successful) {
|
1296 |
+
var n = el.name, t = el.type, tag = el.tagName.toLowerCase();
|
1297 |
+
|
1298 |
+
if (typeof successful === 'undefined') {
|
1299 |
+
successful = true;
|
1300 |
+
}
|
1301 |
+
|
1302 |
+
/* eslint-disable no-mixed-operators */
|
1303 |
+
if (successful && (!n || el.disabled || t === 'reset' || t === 'button' ||
|
1304 |
+
(t === 'checkbox' || t === 'radio') && !el.checked ||
|
1305 |
+
(t === 'submit' || t === 'image') && el.form && el.form.clk !== el ||
|
1306 |
+
tag === 'select' && el.selectedIndex === -1)) {
|
1307 |
+
/* eslint-enable no-mixed-operators */
|
1308 |
+
return null;
|
1309 |
+
}
|
1310 |
+
|
1311 |
+
if (tag === 'select') {
|
1312 |
+
var index = el.selectedIndex;
|
1313 |
+
|
1314 |
+
if (index < 0) {
|
1315 |
+
return null;
|
1316 |
+
}
|
1317 |
+
|
1318 |
+
var a = [], ops = el.options;
|
1319 |
+
var one = (t === 'select-one');
|
1320 |
+
var max = (one ? index + 1 : ops.length);
|
1321 |
+
|
1322 |
+
for (var i = (one ? index : 0); i < max; i++) {
|
1323 |
+
var op = ops[i];
|
1324 |
+
|
1325 |
+
if (op.selected && !op.disabled) {
|
1326 |
+
var v = op.value;
|
1327 |
+
|
1328 |
+
if (!v) { // extra pain for IE...
|
1329 |
+
v = (op.attributes && op.attributes.value && !(op.attributes.value.specified)) ? op.text : op.value;
|
1330 |
+
}
|
1331 |
+
|
1332 |
+
if (one) {
|
1333 |
+
return v;
|
1334 |
+
}
|
1335 |
+
|
1336 |
+
a.push(v);
|
1337 |
+
}
|
1338 |
+
}
|
1339 |
+
|
1340 |
+
return a;
|
1341 |
+
}
|
1342 |
+
|
1343 |
+
return $(el).val().replace(rCRLF, '\r\n');
|
1344 |
+
};
|
1345 |
+
|
1346 |
+
/**
|
1347 |
+
* Clears the form data. Takes the following actions on the form's input fields:
|
1348 |
+
* - input text fields will have their 'value' property set to the empty string
|
1349 |
+
* - select elements will have their 'selectedIndex' property set to -1
|
1350 |
+
* - checkbox and radio inputs will have their 'checked' property set to false
|
1351 |
+
* - inputs of type submit, button, reset, and hidden will *not* be effected
|
1352 |
+
* - button elements will *not* be effected
|
1353 |
+
*/
|
1354 |
+
$.fn.clearForm = function(includeHidden) {
|
1355 |
+
return this.each(function() {
|
1356 |
+
$('input,select,textarea', this).clearFields(includeHidden);
|
1357 |
+
});
|
1358 |
+
};
|
1359 |
+
|
1360 |
+
/**
|
1361 |
+
* Clears the selected form elements.
|
1362 |
+
*/
|
1363 |
+
$.fn.clearFields = $.fn.clearInputs = function(includeHidden) {
|
1364 |
+
var re = /^(?:color|date|datetime|email|month|number|password|range|search|tel|text|time|url|week)$/i; // 'hidden' is not in this list
|
1365 |
+
|
1366 |
+
return this.each(function() {
|
1367 |
+
var t = this.type, tag = this.tagName.toLowerCase();
|
1368 |
+
|
1369 |
+
if (re.test(t) || tag === 'textarea') {
|
1370 |
+
this.value = '';
|
1371 |
+
|
1372 |
+
} else if (t === 'checkbox' || t === 'radio') {
|
1373 |
+
this.checked = false;
|
1374 |
+
|
1375 |
+
} else if (tag === 'select') {
|
1376 |
+
this.selectedIndex = -1;
|
1377 |
+
|
1378 |
+
} else if (t === 'file') {
|
1379 |
+
if (/MSIE/.test(navigator.userAgent)) {
|
1380 |
+
$(this).replaceWith($(this).clone(true));
|
1381 |
+
} else {
|
1382 |
+
$(this).val('');
|
1383 |
+
}
|
1384 |
+
|
1385 |
+
} else if (includeHidden) {
|
1386 |
+
// includeHidden can be the value true, or it can be a selector string
|
1387 |
+
// indicating a special test; for example:
|
1388 |
+
// $('#myForm').clearForm('.special:hidden')
|
1389 |
+
// the above would clean hidden inputs that have the class of 'special'
|
1390 |
+
if ((includeHidden === true && /hidden/.test(t)) ||
|
1391 |
+
(typeof includeHidden === 'string' && $(this).is(includeHidden))) {
|
1392 |
+
this.value = '';
|
1393 |
+
}
|
1394 |
+
}
|
1395 |
+
});
|
1396 |
+
};
|
1397 |
+
|
1398 |
+
|
1399 |
+
/**
|
1400 |
+
* Resets the form data or individual elements. Takes the following actions
|
1401 |
+
* on the selected tags:
|
1402 |
+
* - all fields within form elements will be reset to their original value
|
1403 |
+
* - input / textarea / select fields will be reset to their original value
|
1404 |
+
* - option / optgroup fields (for multi-selects) will defaulted individually
|
1405 |
+
* - non-multiple options will find the right select to default
|
1406 |
+
* - label elements will be searched against its 'for' attribute
|
1407 |
+
* - all others will be searched for appropriate children to default
|
1408 |
+
*/
|
1409 |
+
$.fn.resetForm = function() {
|
1410 |
+
return this.each(function() {
|
1411 |
+
var el = $(this);
|
1412 |
+
var tag = this.tagName.toLowerCase();
|
1413 |
+
|
1414 |
+
switch (tag) {
|
1415 |
+
case 'input':
|
1416 |
+
this.checked = this.defaultChecked;
|
1417 |
+
// fall through
|
1418 |
+
|
1419 |
+
case 'textarea':
|
1420 |
+
this.value = this.defaultValue;
|
1421 |
+
|
1422 |
+
return true;
|
1423 |
+
|
1424 |
+
case 'option':
|
1425 |
+
case 'optgroup':
|
1426 |
+
var select = el.parents('select');
|
1427 |
+
|
1428 |
+
if (select.length && select[0].multiple) {
|
1429 |
+
if (tag === 'option') {
|
1430 |
+
this.selected = this.defaultSelected;
|
1431 |
+
} else {
|
1432 |
+
el.find('option').resetForm();
|
1433 |
+
}
|
1434 |
+
} else {
|
1435 |
+
select.resetForm();
|
1436 |
+
}
|
1437 |
+
|
1438 |
+
return true;
|
1439 |
+
|
1440 |
+
case 'select':
|
1441 |
+
el.find('option').each(function(i) { // eslint-disable-line consistent-return
|
1442 |
+
this.selected = this.defaultSelected;
|
1443 |
+
if (this.defaultSelected && !el[0].multiple) {
|
1444 |
+
el[0].selectedIndex = i;
|
1445 |
+
|
1446 |
+
return false;
|
1447 |
+
}
|
1448 |
+
});
|
1449 |
+
|
1450 |
+
return true;
|
1451 |
+
|
1452 |
+
case 'label':
|
1453 |
+
var forEl = $(el.attr('for'));
|
1454 |
+
var list = el.find('input,select,textarea');
|
1455 |
+
|
1456 |
+
if (forEl[0]) {
|
1457 |
+
list.unshift(forEl[0]);
|
1458 |
+
}
|
1459 |
+
|
1460 |
+
list.resetForm();
|
1461 |
+
|
1462 |
+
return true;
|
1463 |
+
|
1464 |
+
case 'form':
|
1465 |
+
// guard against an input with the name of 'reset'
|
1466 |
+
// note that IE reports the reset function as an 'object'
|
1467 |
+
if (typeof this.reset === 'function' || (typeof this.reset === 'object' && !this.reset.nodeType)) {
|
1468 |
+
this.reset();
|
1469 |
+
}
|
1470 |
+
|
1471 |
+
return true;
|
1472 |
+
|
1473 |
+
default:
|
1474 |
+
el.find('form,input,label,select,textarea').resetForm();
|
1475 |
+
|
1476 |
+
return true;
|
1477 |
+
}
|
1478 |
+
});
|
1479 |
+
};
|
1480 |
+
|
1481 |
+
/**
|
1482 |
+
* Enables or disables any matching elements.
|
1483 |
+
*/
|
1484 |
+
$.fn.enable = function(b) {
|
1485 |
+
if (typeof b === 'undefined') {
|
1486 |
+
b = true;
|
1487 |
+
}
|
1488 |
+
|
1489 |
+
return this.each(function() {
|
1490 |
+
this.disabled = !b;
|
1491 |
+
});
|
1492 |
+
};
|
1493 |
+
|
1494 |
+
/**
|
1495 |
+
* Checks/unchecks any matching checkboxes or radio buttons and
|
1496 |
+
* selects/deselects and matching option elements.
|
1497 |
+
*/
|
1498 |
+
$.fn.selected = function(select) {
|
1499 |
+
if (typeof select === 'undefined') {
|
1500 |
+
select = true;
|
1501 |
+
}
|
1502 |
+
|
1503 |
+
return this.each(function() {
|
1504 |
+
var t = this.type;
|
1505 |
+
|
1506 |
+
if (t === 'checkbox' || t === 'radio') {
|
1507 |
+
this.checked = select;
|
1508 |
+
|
1509 |
+
} else if (this.tagName.toLowerCase() === 'option') {
|
1510 |
+
var $sel = $(this).parent('select');
|
1511 |
+
|
1512 |
+
if (select && $sel[0] && $sel[0].type === 'select-one') {
|
1513 |
+
// deselect all other options
|
1514 |
+
$sel.find('option').selected(false);
|
1515 |
+
}
|
1516 |
+
|
1517 |
+
this.selected = select;
|
1518 |
+
}
|
1519 |
+
});
|
1520 |
+
};
|
1521 |
+
|
1522 |
+
// expose debug var
|
1523 |
+
$.fn.ajaxSubmit.debug = false;
|
1524 |
+
|
1525 |
+
// helper fn for console logging
|
1526 |
+
function log() {
|
1527 |
+
if (!$.fn.ajaxSubmit.debug) {
|
1528 |
+
return;
|
1529 |
+
}
|
1530 |
+
|
1531 |
+
var msg = '[jquery.form] ' + Array.prototype.join.call(arguments, '');
|
1532 |
+
|
1533 |
+
if (window.console && window.console.log) {
|
1534 |
+
window.console.log(msg);
|
1535 |
+
|
1536 |
+
} else if (window.opera && window.opera.postError) {
|
1537 |
+
window.opera.postError(msg);
|
1538 |
+
}
|
1539 |
+
}
|
1540 |
}));
|
js/menu-editor.js
CHANGED
@@ -258,7 +258,7 @@ function outputWpMenu(menu){
|
|
258 |
}
|
259 |
|
260 |
//Automatically select the first top-level menu
|
261 |
-
menuBox.find('.ws_menu:first').click
|
262 |
}
|
263 |
|
264 |
/**
|
@@ -668,10 +668,10 @@ var knownMenuFields = {
|
|
668 |
// field is usually set to a page slug or plugin filename for plugin/hook pages,
|
669 |
// we display the dynamically generated "url" field here (i.e. the actual URL) instead.
|
670 |
if (menuItem.template_id !== '') {
|
671 |
-
input.
|
672 |
displayValue = itemTemplates.getDefaultValue(menuItem.template_id, 'url');
|
673 |
} else {
|
674 |
-
input.
|
675 |
}
|
676 |
return displayValue;
|
677 |
},
|
@@ -1558,7 +1558,7 @@ AmeEditorApi.selectMenuItemByUrl = function(boxSelector, url, expandProperties)
|
|
1558 |
if (expandProperties !== null) {
|
1559 |
var expandLink = containerNode.find('.ws_edit_link').first();
|
1560 |
if (expandLink.hasClass('ws_edit_link_expanded') !== expandProperties) {
|
1561 |
-
expandLink.click
|
1562 |
}
|
1563 |
}
|
1564 |
}
|
@@ -2358,7 +2358,7 @@ function ameOnDomReady() {
|
|
2358 |
permissionConfirmationDialog.dialog('open');
|
2359 |
}
|
2360 |
|
2361 |
-
$('#ws_confirm_menu_hiding, #ws_cancel_menu_hiding').click
|
2362 |
var confirmed = $(this).is('#ws_confirm_menu_hiding');
|
2363 |
var dontShowAgain = permissionConfirmationDialog.find('.ws_dont_show_again input[type="checkbox"]').is(':checked');
|
2364 |
|
@@ -2546,7 +2546,7 @@ function ameOnDomReady() {
|
|
2546 |
//Also show it when the user presses the down arrow in the input field (doesn't work in Opera).
|
2547 |
$('#ws_extra_capability').bind('keyup', function(event){
|
2548 |
if ( event.which === 40 ){
|
2549 |
-
$('#ws_trigger_capability_dropdown').click
|
2550 |
}
|
2551 |
});
|
2552 |
|
@@ -2560,13 +2560,13 @@ function ameOnDomReady() {
|
|
2560 |
var dropdownNodes = $('.ws_dropdown');
|
2561 |
|
2562 |
// Hide capability drop-down when it loses focus.
|
2563 |
-
dropdownNodes.blur
|
2564 |
if (!isSuggestionClick) {
|
2565 |
hideCapSelector();
|
2566 |
}
|
2567 |
});
|
2568 |
|
2569 |
-
dropdownNodes.keydown
|
2570 |
|
2571 |
//Hide it when the user presses Esc
|
2572 |
if ( event.which === 27 ){
|
@@ -2591,7 +2591,7 @@ function ameOnDomReady() {
|
|
2591 |
});
|
2592 |
|
2593 |
//Eat Tab keys to prevent focus theft. Required to make the "select item on Tab" thing work.
|
2594 |
-
dropdownNodes.keyup
|
2595 |
if ( event.which === 9 ){
|
2596 |
event.preventDefault();
|
2597 |
}
|
@@ -2599,7 +2599,7 @@ function ameOnDomReady() {
|
|
2599 |
|
2600 |
|
2601 |
//Update the input & hide the list when an option is clicked
|
2602 |
-
dropdownNodes.click
|
2603 |
if (capSelectorDropdown.val()){
|
2604 |
hideCapSelector();
|
2605 |
if (currentDropdownOwner) {
|
@@ -2609,7 +2609,7 @@ function ameOnDomReady() {
|
|
2609 |
});
|
2610 |
|
2611 |
//Highlight an option when the user mouses over it (doesn't work in IE)
|
2612 |
-
dropdownNodes.mousemove
|
2613 |
if ( !event.target ){
|
2614 |
return;
|
2615 |
}
|
@@ -2890,7 +2890,7 @@ function ameOnDomReady() {
|
|
2890 |
//Alternatively, use the WordPress media uploader to select a custom icon.
|
2891 |
//This code is based on the header selection script in /wp-admin/js/custom-header.js.
|
2892 |
var mediaFrame = null;
|
2893 |
-
$('#ws_choose_icon_from_media').click
|
2894 |
event.preventDefault();
|
2895 |
|
2896 |
//This option is not usable on the demo site since the filesystem is usually read-only.
|
@@ -3217,7 +3217,7 @@ function ameOnDomReady() {
|
|
3217 |
|
3218 |
//Show only the primary color settings by default.
|
3219 |
var showAdvancedColors = false;
|
3220 |
-
$('#ws-ame-show-advanced-colors').click
|
3221 |
showAdvancedColors = !showAdvancedColors;
|
3222 |
$('#ws-ame-menu-color-settings').find('.ame-advanced-menu-color').toggle(showAdvancedColors);
|
3223 |
$(this).text(showAdvancedColors ? 'Hide advanced options' : 'Show advanced options');
|
@@ -3281,7 +3281,7 @@ function ameOnDomReady() {
|
|
3281 |
});
|
3282 |
|
3283 |
//The "Colors" button in the main sidebar.
|
3284 |
-
$('#ws_edit_global_colors').click
|
3285 |
colorDialogState.editingGlobalColors = true;
|
3286 |
colorDialogState.menuItem = null;
|
3287 |
colorDialogState.containerNode = null;
|
@@ -3327,7 +3327,7 @@ function ameOnDomReady() {
|
|
3327 |
$('#ame-color-' + name).wpColorPicker('color', value);
|
3328 |
customColorCount++;
|
3329 |
} else {
|
3330 |
-
$('#ame-color-' + name).closest('.wp-picker-container').find('.wp-picker-clear').click
|
3331 |
}
|
3332 |
}
|
3333 |
|
@@ -3336,7 +3336,7 @@ function ameOnDomReady() {
|
|
3336 |
}
|
3337 |
|
3338 |
//The "Save Changes" button in the color dialog.
|
3339 |
-
$('#ws-ame-save-menu-colors').click
|
3340 |
menuColorDialog.dialog('close');
|
3341 |
var colors = getColorSettingsFromDialog();
|
3342 |
|
@@ -3363,7 +3363,7 @@ function ameOnDomReady() {
|
|
3363 |
});
|
3364 |
|
3365 |
//The "Apply to All" button in the same dialog.
|
3366 |
-
$('#ws-ame-apply-colors-to-all').click
|
3367 |
if (!confirm('Apply these color settings to ALL top level menus?')) {
|
3368 |
return;
|
3369 |
}
|
@@ -3439,7 +3439,7 @@ function ameOnDomReady() {
|
|
3439 |
}
|
3440 |
}
|
3441 |
|
3442 |
-
colorPresetDropdown.change
|
3443 |
var dropdown = $(this),
|
3444 |
presetName = dropdown.val();
|
3445 |
|
@@ -3468,7 +3468,7 @@ function ameOnDomReady() {
|
|
3468 |
}
|
3469 |
});
|
3470 |
|
3471 |
-
colorPresetDeleteButton.click
|
3472 |
var presetName = $('#ame-menu-color-presets').val();
|
3473 |
if ( _.includes(['[save_preset]', '[global]', '', null], presetName) ) {
|
3474 |
return false;
|
@@ -3489,7 +3489,7 @@ function ameOnDomReady() {
|
|
3489 |
}
|
3490 |
|
3491 |
//Show/Hide menu
|
3492 |
-
$('#ws_hide_menu').click
|
3493 |
event.preventDefault();
|
3494 |
|
3495 |
//Get the selected menu
|
@@ -3563,7 +3563,7 @@ function ameOnDomReady() {
|
|
3563 |
|
3564 |
} else {
|
3565 |
//Just toggle the checkbox.
|
3566 |
-
selection.find('input.ws_actor_access_checkbox').click
|
3567 |
}
|
3568 |
});
|
3569 |
|
@@ -3638,16 +3638,16 @@ function ameOnDomReady() {
|
|
3638 |
};
|
3639 |
|
3640 |
//Callbacks for each of the dialog buttons.
|
3641 |
-
$('#ws_cancel_menu_deletion').click
|
3642 |
menuDeletionCallback(false);
|
3643 |
});
|
3644 |
-
$('#ws_hide_menu_from_everyone').click
|
3645 |
menuDeletionCallback('all');
|
3646 |
});
|
3647 |
-
$('#ws_hide_menu_except_current_user').click
|
3648 |
menuDeletionCallback('except_current_user');
|
3649 |
});
|
3650 |
-
$('#ws_hide_menu_except_administrator').click
|
3651 |
menuDeletionCallback('except_administrator');
|
3652 |
});
|
3653 |
|
@@ -3735,7 +3735,7 @@ function ameOnDomReady() {
|
|
3735 |
}
|
3736 |
|
3737 |
//Delete menu
|
3738 |
-
$('#ws_delete_menu').click
|
3739 |
event.preventDefault();
|
3740 |
|
3741 |
//Get the selected menu
|
@@ -3748,7 +3748,7 @@ function ameOnDomReady() {
|
|
3748 |
});
|
3749 |
|
3750 |
//Copy menu
|
3751 |
-
$('#ws_copy_menu').click
|
3752 |
event.preventDefault();
|
3753 |
|
3754 |
//Get the selected menu
|
@@ -3762,7 +3762,7 @@ function ameOnDomReady() {
|
|
3762 |
});
|
3763 |
|
3764 |
//Cut menu
|
3765 |
-
$('#ws_cut_menu').click
|
3766 |
event.preventDefault();
|
3767 |
|
3768 |
//Get the selected menu
|
@@ -3806,7 +3806,7 @@ function ameOnDomReady() {
|
|
3806 |
}
|
3807 |
}
|
3808 |
|
3809 |
-
$('#ws_paste_menu').click
|
3810 |
event.preventDefault();
|
3811 |
|
3812 |
//Check if anything has been copied/cut
|
@@ -3823,7 +3823,7 @@ function ameOnDomReady() {
|
|
3823 |
});
|
3824 |
|
3825 |
//New menu
|
3826 |
-
$('#ws_new_menu').click
|
3827 |
event.preventDefault();
|
3828 |
|
3829 |
ws_paste_count++;
|
@@ -3849,11 +3849,11 @@ function ameOnDomReady() {
|
|
3849 |
var result = outputTopMenu(menu, (selection.length > 0) ? selection : null);
|
3850 |
|
3851 |
//The menus's editbox is always open
|
3852 |
-
result.menu.find('.ws_edit_link').click
|
3853 |
});
|
3854 |
|
3855 |
//New separator
|
3856 |
-
$('#ws_new_separator, #ws_new_submenu_separator').click
|
3857 |
event.preventDefault();
|
3858 |
|
3859 |
ws_paste_count++;
|
@@ -3884,7 +3884,7 @@ function ameOnDomReady() {
|
|
3884 |
});
|
3885 |
|
3886 |
//Toggle all menus for the currently selected actor
|
3887 |
-
$('#ws_toggle_all_menus').click
|
3888 |
event.preventDefault();
|
3889 |
|
3890 |
if ( actorSelectorWidget.selectedActor === null ) {
|
@@ -3913,7 +3913,7 @@ function ameOnDomReady() {
|
|
3913 |
var sourceActorList = $('#ame-copy-source-actor'), destinationActorList = $('#ame-copy-destination-actor');
|
3914 |
|
3915 |
//The "Copy permissions" toolbar button.
|
3916 |
-
$('#ws_copy_role_permissions').click
|
3917 |
event.preventDefault();
|
3918 |
|
3919 |
var previousSource = sourceActorList.val();
|
@@ -3948,7 +3948,7 @@ function ameOnDomReady() {
|
|
3948 |
|
3949 |
//Actually copy the permissions when the user click the confirmation button.
|
3950 |
var copyConfirmationButton = $('#ws-ame-confirm-copy-permissions');
|
3951 |
-
copyConfirmationButton.click
|
3952 |
var sourceActor = sourceActorList.val();
|
3953 |
var destinationActor = destinationActorList.val();
|
3954 |
|
@@ -3990,7 +3990,7 @@ function ameOnDomReady() {
|
|
3990 |
|
3991 |
//Only enable the copy button when the user selects a valid source and destination.
|
3992 |
copyConfirmationButton.prop('disabled', true);
|
3993 |
-
sourceActorList.add(destinationActorList).click
|
3994 |
var sourceActor = sourceActorList.val();
|
3995 |
var destinationActor = destinationActorList.val();
|
3996 |
|
@@ -4074,7 +4074,7 @@ function ameOnDomReady() {
|
|
4074 |
}
|
4075 |
|
4076 |
//Toggle the second row of toolbar buttons.
|
4077 |
-
$('#ws_toggle_toolbar').click
|
4078 |
var visible = menuEditorNode.find('.ws_second_toolbar_row').toggle().is(':visible');
|
4079 |
if (typeof $['cookie'] !== 'undefined') {
|
4080 |
$.cookie('ame-show-second-toolbar', visible ? '1' : '0', {expires: 90});
|
@@ -4090,7 +4090,7 @@ function ameOnDomReady() {
|
|
4090 |
}
|
4091 |
|
4092 |
//Show/Hide item
|
4093 |
-
$('#ws_hide_item').click
|
4094 |
event.preventDefault();
|
4095 |
|
4096 |
//Get the selected item
|
@@ -4104,7 +4104,7 @@ function ameOnDomReady() {
|
|
4104 |
});
|
4105 |
|
4106 |
//Delete item
|
4107 |
-
$('#ws_delete_item').click
|
4108 |
event.preventDefault();
|
4109 |
|
4110 |
var selection = getSelectedSubmenuItem();
|
@@ -4116,7 +4116,7 @@ function ameOnDomReady() {
|
|
4116 |
});
|
4117 |
|
4118 |
//Copy item
|
4119 |
-
$('#ws_copy_item').click
|
4120 |
event.preventDefault();
|
4121 |
|
4122 |
//Get the selected item
|
@@ -4130,7 +4130,7 @@ function ameOnDomReady() {
|
|
4130 |
});
|
4131 |
|
4132 |
//Cut item
|
4133 |
-
$('#ws_cut_item').click
|
4134 |
event.preventDefault();
|
4135 |
|
4136 |
//Get the selected item
|
@@ -4182,7 +4182,7 @@ function ameOnDomReady() {
|
|
4182 |
updateParentAccessUi(targetSubmenu);
|
4183 |
}
|
4184 |
|
4185 |
-
$('#ws_paste_item').click
|
4186 |
event.preventDefault();
|
4187 |
|
4188 |
//Check if anything has been copied/cut
|
@@ -4201,7 +4201,7 @@ function ameOnDomReady() {
|
|
4201 |
});
|
4202 |
|
4203 |
//New item
|
4204 |
-
$('#ws_new_item').click
|
4205 |
event.preventDefault();
|
4206 |
|
4207 |
if ($('.ws_submenu:visible').length < 1) {
|
@@ -4237,7 +4237,7 @@ function ameOnDomReady() {
|
|
4237 |
updateItemEditor(menu);
|
4238 |
|
4239 |
//The items's editbox is always open
|
4240 |
-
menu.find('.ws_edit_link').click
|
4241 |
|
4242 |
updateParentAccessUi(menu);
|
4243 |
});
|
@@ -4247,7 +4247,7 @@ function ameOnDomReady() {
|
|
4247 |
//==============================================
|
4248 |
|
4249 |
//Save Changes - encode the current menu as JSON and save
|
4250 |
-
$('#ws_save_menu').click
|
4251 |
try {
|
4252 |
var tree = readMenuTreeState();
|
4253 |
} catch (error) {
|
@@ -4318,18 +4318,18 @@ function ameOnDomReady() {
|
|
4318 |
}
|
4319 |
}
|
4320 |
|
4321 |
-
$('#ws_main_form').submit
|
4322 |
});
|
4323 |
|
4324 |
//Load default menu - load the default WordPress menu
|
4325 |
-
$('#ws_load_menu').click
|
4326 |
if (confirm('Are you sure you want to load the default WordPress menu?')){
|
4327 |
loadMenuConfiguration(defaultMenu);
|
4328 |
}
|
4329 |
});
|
4330 |
|
4331 |
//Reset menu - re-load the custom menu. Discards any changes made by user.
|
4332 |
-
$('#ws_reset_menu').click
|
4333 |
if (confirm('Undo all changes made in the current editing session?')){
|
4334 |
loadMenuConfiguration(customMenu);
|
4335 |
}
|
@@ -4342,7 +4342,7 @@ function ameOnDomReady() {
|
|
4342 |
});
|
4343 |
$('#ws_load_menu, #ws_reset_menu').prop('disabled', actorSelectorWidget.selectedActor !== null);
|
4344 |
|
4345 |
-
$('#ws_toggle_editor_layout').click
|
4346 |
var isCompactLayoutEnabled = menuEditorNode.toggleClass('ws_compact_layout').hasClass('ws_compact_layout');
|
4347 |
if (typeof $['cookie'] !== 'undefined') {
|
4348 |
$.cookie('ame-compact-layout', isCompactLayoutEnabled ? '1' : '0', {expires: 90});
|
@@ -4366,7 +4366,7 @@ function ameOnDomReady() {
|
|
4366 |
minHeight: 100
|
4367 |
});
|
4368 |
|
4369 |
-
$('#ws_export_menu').click
|
4370 |
var button = $(this);
|
4371 |
button.prop('disabled', true);
|
4372 |
button.val('Exporting...');
|
@@ -4419,11 +4419,11 @@ function ameOnDomReady() {
|
|
4419 |
);
|
4420 |
});
|
4421 |
|
4422 |
-
$('#ws_cancel_export').click
|
4423 |
$('#export_dialog').dialog('close');
|
4424 |
});
|
4425 |
|
4426 |
-
$('#download_menu_button').click
|
4427 |
$('#export_dialog').dialog('close');
|
4428 |
});
|
4429 |
|
@@ -4434,11 +4434,11 @@ function ameOnDomReady() {
|
|
4434 |
modal: true
|
4435 |
});
|
4436 |
|
4437 |
-
$('#ws_cancel_import').click
|
4438 |
$('#import_dialog').dialog('close');
|
4439 |
});
|
4440 |
|
4441 |
-
$('#ws_import_menu').click
|
4442 |
$('#import_progress_notice, #import_progress_notice2, #import_complete_notice, #ws_import_error').hide();
|
4443 |
$('#ws_import_panel').show();
|
4444 |
$('#import_menu_form').resetForm();
|
@@ -4450,7 +4450,7 @@ function ameOnDomReady() {
|
|
4450 |
importDialog.dialog('open');
|
4451 |
});
|
4452 |
|
4453 |
-
$('#import_file_selector').change
|
4454 |
$('#ws_start_import').prop('disabled', ! $(this).val() );
|
4455 |
});
|
4456 |
|
@@ -4674,14 +4674,14 @@ function ameOnDomReady() {
|
|
4674 |
};
|
4675 |
|
4676 |
if ($generalVisBox.length > 0) {
|
4677 |
-
$showAdminMenu.click
|
4678 |
AmeEditorApi.setComponentVisibility(
|
4679 |
'adminMenu',
|
4680 |
actorSelectorWidget.selectedActor,
|
4681 |
$(this).is(':checked')
|
4682 |
);
|
4683 |
});
|
4684 |
-
$showWpToolbar.click
|
4685 |
AmeEditorApi.setComponentVisibility(
|
4686 |
'toolbar',
|
4687 |
actorSelectorWidget.selectedActor,
|
@@ -4689,7 +4689,7 @@ function ameOnDomReady() {
|
|
4689 |
);
|
4690 |
});
|
4691 |
|
4692 |
-
$generalVisBox.find('.handlediv').click
|
4693 |
$generalVisBox.toggleClass('closed');
|
4694 |
if (typeof $['cookie'] !== 'undefined') {
|
4695 |
$.cookie(
|
@@ -4805,7 +4805,7 @@ function ameOnDomReady() {
|
|
4805 |
});
|
4806 |
|
4807 |
//Flag closed hints as hidden by sending the appropriate AJAX request to the backend.
|
4808 |
-
$('.ws_hint_close').click
|
4809 |
var hint = $(this).parents('.ws_hint').first();
|
4810 |
hint.hide();
|
4811 |
wsEditorData.showHints[hint.attr('id')] = false;
|
@@ -4820,7 +4820,7 @@ function ameOnDomReady() {
|
|
4820 |
|
4821 |
//Expand/collapse the "How To" box.
|
4822 |
var $howToBox = $("#ws_ame_how_to_box");
|
4823 |
-
$howToBox.find(".handlediv").click
|
4824 |
$howToBox.toggleClass('closed');
|
4825 |
if (typeof $['cookie'] !== 'undefined') {
|
4826 |
$.cookie(
|
@@ -4875,7 +4875,7 @@ function ameOnDomReady() {
|
|
4875 |
testProgress = $('#ws_ame_test_progress'),
|
4876 |
testProgressText = $('#ws_ame_test_progress_text');
|
4877 |
|
4878 |
-
$('#ws_test_access').click
|
4879 |
testConfig = readMenuTreeState();
|
4880 |
|
4881 |
var selectedMenuContainer = getSelectedMenu(),
|
@@ -4946,7 +4946,7 @@ function ameOnDomReady() {
|
|
4946 |
testAccessDialog.dialog('open');
|
4947 |
});
|
4948 |
|
4949 |
-
testAccessButton.click
|
4950 |
testAccessButton.prop('disabled', true);
|
4951 |
testProgress.show();
|
4952 |
testProgressText.text('Sending menu settings...');
|
@@ -5086,7 +5086,7 @@ jQuery(function($){
|
|
5086 |
hideSettingsCheckbox.prop('checked', wsEditorData.hideAdvancedSettings);
|
5087 |
|
5088 |
//Update editor state when settings change
|
5089 |
-
$('#ws-hide-advanced-settings').click
|
5090 |
wsEditorData.hideAdvancedSettings = hideSettingsCheckbox.prop('checked');
|
5091 |
|
5092 |
//Show/hide advanced settings dynamically as the user changes the setting.
|
258 |
}
|
259 |
|
260 |
//Automatically select the first top-level menu
|
261 |
+
menuBox.find('.ws_menu:first').trigger('click');
|
262 |
}
|
263 |
|
264 |
/**
|
668 |
// field is usually set to a page slug or plugin filename for plugin/hook pages,
|
669 |
// we display the dynamically generated "url" field here (i.e. the actual URL) instead.
|
670 |
if (menuItem.template_id !== '') {
|
671 |
+
input.prop('readonly', true);
|
672 |
displayValue = itemTemplates.getDefaultValue(menuItem.template_id, 'url');
|
673 |
} else {
|
674 |
+
input.prop('readonly', false);
|
675 |
}
|
676 |
return displayValue;
|
677 |
},
|
1558 |
if (expandProperties !== null) {
|
1559 |
var expandLink = containerNode.find('.ws_edit_link').first();
|
1560 |
if (expandLink.hasClass('ws_edit_link_expanded') !== expandProperties) {
|
1561 |
+
expandLink.trigger('click');
|
1562 |
}
|
1563 |
}
|
1564 |
}
|
2358 |
permissionConfirmationDialog.dialog('open');
|
2359 |
}
|
2360 |
|
2361 |
+
$('#ws_confirm_menu_hiding, #ws_cancel_menu_hiding').on('click', function() {
|
2362 |
var confirmed = $(this).is('#ws_confirm_menu_hiding');
|
2363 |
var dontShowAgain = permissionConfirmationDialog.find('.ws_dont_show_again input[type="checkbox"]').is(':checked');
|
2364 |
|
2546 |
//Also show it when the user presses the down arrow in the input field (doesn't work in Opera).
|
2547 |
$('#ws_extra_capability').bind('keyup', function(event){
|
2548 |
if ( event.which === 40 ){
|
2549 |
+
$('#ws_trigger_capability_dropdown').trigger('click');
|
2550 |
}
|
2551 |
});
|
2552 |
|
2560 |
var dropdownNodes = $('.ws_dropdown');
|
2561 |
|
2562 |
// Hide capability drop-down when it loses focus.
|
2563 |
+
dropdownNodes.on('blur', function(){
|
2564 |
if (!isSuggestionClick) {
|
2565 |
hideCapSelector();
|
2566 |
}
|
2567 |
});
|
2568 |
|
2569 |
+
dropdownNodes.on('keydown', function(event){
|
2570 |
|
2571 |
//Hide it when the user presses Esc
|
2572 |
if ( event.which === 27 ){
|
2591 |
});
|
2592 |
|
2593 |
//Eat Tab keys to prevent focus theft. Required to make the "select item on Tab" thing work.
|
2594 |
+
dropdownNodes.on('keyup', function(event){
|
2595 |
if ( event.which === 9 ){
|
2596 |
event.preventDefault();
|
2597 |
}
|
2599 |
|
2600 |
|
2601 |
//Update the input & hide the list when an option is clicked
|
2602 |
+
dropdownNodes.on('click', function(){
|
2603 |
if (capSelectorDropdown.val()){
|
2604 |
hideCapSelector();
|
2605 |
if (currentDropdownOwner) {
|
2609 |
});
|
2610 |
|
2611 |
//Highlight an option when the user mouses over it (doesn't work in IE)
|
2612 |
+
dropdownNodes.on('mousemove', function(event){
|
2613 |
if ( !event.target ){
|
2614 |
return;
|
2615 |
}
|
2890 |
//Alternatively, use the WordPress media uploader to select a custom icon.
|
2891 |
//This code is based on the header selection script in /wp-admin/js/custom-header.js.
|
2892 |
var mediaFrame = null;
|
2893 |
+
$('#ws_choose_icon_from_media').on('click', function(event) {
|
2894 |
event.preventDefault();
|
2895 |
|
2896 |
//This option is not usable on the demo site since the filesystem is usually read-only.
|
3217 |
|
3218 |
//Show only the primary color settings by default.
|
3219 |
var showAdvancedColors = false;
|
3220 |
+
$('#ws-ame-show-advanced-colors').on('click', function() {
|
3221 |
showAdvancedColors = !showAdvancedColors;
|
3222 |
$('#ws-ame-menu-color-settings').find('.ame-advanced-menu-color').toggle(showAdvancedColors);
|
3223 |
$(this).text(showAdvancedColors ? 'Hide advanced options' : 'Show advanced options');
|
3281 |
});
|
3282 |
|
3283 |
//The "Colors" button in the main sidebar.
|
3284 |
+
$('#ws_edit_global_colors').on('click', function() {
|
3285 |
colorDialogState.editingGlobalColors = true;
|
3286 |
colorDialogState.menuItem = null;
|
3287 |
colorDialogState.containerNode = null;
|
3327 |
$('#ame-color-' + name).wpColorPicker('color', value);
|
3328 |
customColorCount++;
|
3329 |
} else {
|
3330 |
+
$('#ame-color-' + name).closest('.wp-picker-container').find('.wp-picker-clear').trigger('click');
|
3331 |
}
|
3332 |
}
|
3333 |
|
3336 |
}
|
3337 |
|
3338 |
//The "Save Changes" button in the color dialog.
|
3339 |
+
$('#ws-ame-save-menu-colors').on('click', function() {
|
3340 |
menuColorDialog.dialog('close');
|
3341 |
var colors = getColorSettingsFromDialog();
|
3342 |
|
3363 |
});
|
3364 |
|
3365 |
//The "Apply to All" button in the same dialog.
|
3366 |
+
$('#ws-ame-apply-colors-to-all').on('click', function() {
|
3367 |
if (!confirm('Apply these color settings to ALL top level menus?')) {
|
3368 |
return;
|
3369 |
}
|
3439 |
}
|
3440 |
}
|
3441 |
|
3442 |
+
colorPresetDropdown.on('change', function() {
|
3443 |
var dropdown = $(this),
|
3444 |
presetName = dropdown.val();
|
3445 |
|
3468 |
}
|
3469 |
});
|
3470 |
|
3471 |
+
colorPresetDeleteButton.on('click', function() {
|
3472 |
var presetName = $('#ame-menu-color-presets').val();
|
3473 |
if ( _.includes(['[save_preset]', '[global]', '', null], presetName) ) {
|
3474 |
return false;
|
3489 |
}
|
3490 |
|
3491 |
//Show/Hide menu
|
3492 |
+
$('#ws_hide_menu').on('click', function (event) {
|
3493 |
event.preventDefault();
|
3494 |
|
3495 |
//Get the selected menu
|
3563 |
|
3564 |
} else {
|
3565 |
//Just toggle the checkbox.
|
3566 |
+
selection.find('input.ws_actor_access_checkbox').trigger('click');
|
3567 |
}
|
3568 |
});
|
3569 |
|
3638 |
};
|
3639 |
|
3640 |
//Callbacks for each of the dialog buttons.
|
3641 |
+
$('#ws_cancel_menu_deletion').on('click', function() {
|
3642 |
menuDeletionCallback(false);
|
3643 |
});
|
3644 |
+
$('#ws_hide_menu_from_everyone').on('click', function() {
|
3645 |
menuDeletionCallback('all');
|
3646 |
});
|
3647 |
+
$('#ws_hide_menu_except_current_user').on('click', function() {
|
3648 |
menuDeletionCallback('except_current_user');
|
3649 |
});
|
3650 |
+
$('#ws_hide_menu_except_administrator').on('click', function() {
|
3651 |
menuDeletionCallback('except_administrator');
|
3652 |
});
|
3653 |
|
3735 |
}
|
3736 |
|
3737 |
//Delete menu
|
3738 |
+
$('#ws_delete_menu').on('click', function (event) {
|
3739 |
event.preventDefault();
|
3740 |
|
3741 |
//Get the selected menu
|
3748 |
});
|
3749 |
|
3750 |
//Copy menu
|
3751 |
+
$('#ws_copy_menu').on('click', function (event) {
|
3752 |
event.preventDefault();
|
3753 |
|
3754 |
//Get the selected menu
|
3762 |
});
|
3763 |
|
3764 |
//Cut menu
|
3765 |
+
$('#ws_cut_menu').on('click', function (event) {
|
3766 |
event.preventDefault();
|
3767 |
|
3768 |
//Get the selected menu
|
3806 |
}
|
3807 |
}
|
3808 |
|
3809 |
+
$('#ws_paste_menu').on('click', function (event) {
|
3810 |
event.preventDefault();
|
3811 |
|
3812 |
//Check if anything has been copied/cut
|
3823 |
});
|
3824 |
|
3825 |
//New menu
|
3826 |
+
$('#ws_new_menu').on('click', function (event) {
|
3827 |
event.preventDefault();
|
3828 |
|
3829 |
ws_paste_count++;
|
3849 |
var result = outputTopMenu(menu, (selection.length > 0) ? selection : null);
|
3850 |
|
3851 |
//The menus's editbox is always open
|
3852 |
+
result.menu.find('.ws_edit_link').trigger('click');
|
3853 |
});
|
3854 |
|
3855 |
//New separator
|
3856 |
+
$('#ws_new_separator, #ws_new_submenu_separator').on('click', function (event) {
|
3857 |
event.preventDefault();
|
3858 |
|
3859 |
ws_paste_count++;
|
3884 |
});
|
3885 |
|
3886 |
//Toggle all menus for the currently selected actor
|
3887 |
+
$('#ws_toggle_all_menus').on('click', function(event) {
|
3888 |
event.preventDefault();
|
3889 |
|
3890 |
if ( actorSelectorWidget.selectedActor === null ) {
|
3913 |
var sourceActorList = $('#ame-copy-source-actor'), destinationActorList = $('#ame-copy-destination-actor');
|
3914 |
|
3915 |
//The "Copy permissions" toolbar button.
|
3916 |
+
$('#ws_copy_role_permissions').on('click', function(event) {
|
3917 |
event.preventDefault();
|
3918 |
|
3919 |
var previousSource = sourceActorList.val();
|
3948 |
|
3949 |
//Actually copy the permissions when the user click the confirmation button.
|
3950 |
var copyConfirmationButton = $('#ws-ame-confirm-copy-permissions');
|
3951 |
+
copyConfirmationButton.on('click', function() {
|
3952 |
var sourceActor = sourceActorList.val();
|
3953 |
var destinationActor = destinationActorList.val();
|
3954 |
|
3990 |
|
3991 |
//Only enable the copy button when the user selects a valid source and destination.
|
3992 |
copyConfirmationButton.prop('disabled', true);
|
3993 |
+
sourceActorList.add(destinationActorList).on('click', function() {
|
3994 |
var sourceActor = sourceActorList.val();
|
3995 |
var destinationActor = destinationActorList.val();
|
3996 |
|
4074 |
}
|
4075 |
|
4076 |
//Toggle the second row of toolbar buttons.
|
4077 |
+
$('#ws_toggle_toolbar').on('click', function() {
|
4078 |
var visible = menuEditorNode.find('.ws_second_toolbar_row').toggle().is(':visible');
|
4079 |
if (typeof $['cookie'] !== 'undefined') {
|
4080 |
$.cookie('ame-show-second-toolbar', visible ? '1' : '0', {expires: 90});
|
4090 |
}
|
4091 |
|
4092 |
//Show/Hide item
|
4093 |
+
$('#ws_hide_item').on('click', function (event) {
|
4094 |
event.preventDefault();
|
4095 |
|
4096 |
//Get the selected item
|
4104 |
});
|
4105 |
|
4106 |
//Delete item
|
4107 |
+
$('#ws_delete_item').on('click', function (event) {
|
4108 |
event.preventDefault();
|
4109 |
|
4110 |
var selection = getSelectedSubmenuItem();
|
4116 |
});
|
4117 |
|
4118 |
//Copy item
|
4119 |
+
$('#ws_copy_item').on('click', function (event) {
|
4120 |
event.preventDefault();
|
4121 |
|
4122 |
//Get the selected item
|
4130 |
});
|
4131 |
|
4132 |
//Cut item
|
4133 |
+
$('#ws_cut_item').on('click', function (event) {
|
4134 |
event.preventDefault();
|
4135 |
|
4136 |
//Get the selected item
|
4182 |
updateParentAccessUi(targetSubmenu);
|
4183 |
}
|
4184 |
|
4185 |
+
$('#ws_paste_item').on('click', function (event) {
|
4186 |
event.preventDefault();
|
4187 |
|
4188 |
//Check if anything has been copied/cut
|
4201 |
});
|
4202 |
|
4203 |
//New item
|
4204 |
+
$('#ws_new_item').on('click', function (event) {
|
4205 |
event.preventDefault();
|
4206 |
|
4207 |
if ($('.ws_submenu:visible').length < 1) {
|
4237 |
updateItemEditor(menu);
|
4238 |
|
4239 |
//The items's editbox is always open
|
4240 |
+
menu.find('.ws_edit_link').trigger('click');
|
4241 |
|
4242 |
updateParentAccessUi(menu);
|
4243 |
});
|
4247 |
//==============================================
|
4248 |
|
4249 |
//Save Changes - encode the current menu as JSON and save
|
4250 |
+
$('#ws_save_menu').on('click', function () {
|
4251 |
try {
|
4252 |
var tree = readMenuTreeState();
|
4253 |
} catch (error) {
|
4318 |
}
|
4319 |
}
|
4320 |
|
4321 |
+
$('#ws_main_form').trigger('submit');
|
4322 |
});
|
4323 |
|
4324 |
//Load default menu - load the default WordPress menu
|
4325 |
+
$('#ws_load_menu').on('click', function () {
|
4326 |
if (confirm('Are you sure you want to load the default WordPress menu?')){
|
4327 |
loadMenuConfiguration(defaultMenu);
|
4328 |
}
|
4329 |
});
|
4330 |
|
4331 |
//Reset menu - re-load the custom menu. Discards any changes made by user.
|
4332 |
+
$('#ws_reset_menu').on('click', function () {
|
4333 |
if (confirm('Undo all changes made in the current editing session?')){
|
4334 |
loadMenuConfiguration(customMenu);
|
4335 |
}
|
4342 |
});
|
4343 |
$('#ws_load_menu, #ws_reset_menu').prop('disabled', actorSelectorWidget.selectedActor !== null);
|
4344 |
|
4345 |
+
$('#ws_toggle_editor_layout').on('click', function () {
|
4346 |
var isCompactLayoutEnabled = menuEditorNode.toggleClass('ws_compact_layout').hasClass('ws_compact_layout');
|
4347 |
if (typeof $['cookie'] !== 'undefined') {
|
4348 |
$.cookie('ame-compact-layout', isCompactLayoutEnabled ? '1' : '0', {expires: 90});
|
4366 |
minHeight: 100
|
4367 |
});
|
4368 |
|
4369 |
+
$('#ws_export_menu').on('click', function(){
|
4370 |
var button = $(this);
|
4371 |
button.prop('disabled', true);
|
4372 |
button.val('Exporting...');
|
4419 |
);
|
4420 |
});
|
4421 |
|
4422 |
+
$('#ws_cancel_export').on('click', function(){
|
4423 |
$('#export_dialog').dialog('close');
|
4424 |
});
|
4425 |
|
4426 |
+
$('#download_menu_button').on('click', function(){
|
4427 |
$('#export_dialog').dialog('close');
|
4428 |
});
|
4429 |
|
4434 |
modal: true
|
4435 |
});
|
4436 |
|
4437 |
+
$('#ws_cancel_import').on('click', function(){
|
4438 |
$('#import_dialog').dialog('close');
|
4439 |
});
|
4440 |
|
4441 |
+
$('#ws_import_menu').on('click', function(){
|
4442 |
$('#import_progress_notice, #import_progress_notice2, #import_complete_notice, #ws_import_error').hide();
|
4443 |
$('#ws_import_panel').show();
|
4444 |
$('#import_menu_form').resetForm();
|
4450 |
importDialog.dialog('open');
|
4451 |
});
|
4452 |
|
4453 |
+
$('#import_file_selector').on('change', function(){
|
4454 |
$('#ws_start_import').prop('disabled', ! $(this).val() );
|
4455 |
});
|
4456 |
|
4674 |
};
|
4675 |
|
4676 |
if ($generalVisBox.length > 0) {
|
4677 |
+
$showAdminMenu.on('click', function() {
|
4678 |
AmeEditorApi.setComponentVisibility(
|
4679 |
'adminMenu',
|
4680 |
actorSelectorWidget.selectedActor,
|
4681 |
$(this).is(':checked')
|
4682 |
);
|
4683 |
});
|
4684 |
+
$showWpToolbar.on('click', function () {
|
4685 |
AmeEditorApi.setComponentVisibility(
|
4686 |
'toolbar',
|
4687 |
actorSelectorWidget.selectedActor,
|
4689 |
);
|
4690 |
});
|
4691 |
|
4692 |
+
$generalVisBox.find('.handlediv').on('click', function() {
|
4693 |
$generalVisBox.toggleClass('closed');
|
4694 |
if (typeof $['cookie'] !== 'undefined') {
|
4695 |
$.cookie(
|
4805 |
});
|
4806 |
|
4807 |
//Flag closed hints as hidden by sending the appropriate AJAX request to the backend.
|
4808 |
+
$('.ws_hint_close').on('click', function() {
|
4809 |
var hint = $(this).parents('.ws_hint').first();
|
4810 |
hint.hide();
|
4811 |
wsEditorData.showHints[hint.attr('id')] = false;
|
4820 |
|
4821 |
//Expand/collapse the "How To" box.
|
4822 |
var $howToBox = $("#ws_ame_how_to_box");
|
4823 |
+
$howToBox.find(".handlediv").on('click', function() {
|
4824 |
$howToBox.toggleClass('closed');
|
4825 |
if (typeof $['cookie'] !== 'undefined') {
|
4826 |
$.cookie(
|
4875 |
testProgress = $('#ws_ame_test_progress'),
|
4876 |
testProgressText = $('#ws_ame_test_progress_text');
|
4877 |
|
4878 |
+
$('#ws_test_access').on('click', function () {
|
4879 |
testConfig = readMenuTreeState();
|
4880 |
|
4881 |
var selectedMenuContainer = getSelectedMenu(),
|
4946 |
testAccessDialog.dialog('open');
|
4947 |
});
|
4948 |
|
4949 |
+
testAccessButton.on('click', function () {
|
4950 |
testAccessButton.prop('disabled', true);
|
4951 |
testProgress.show();
|
4952 |
testProgressText.text('Sending menu settings...');
|
5086 |
hideSettingsCheckbox.prop('checked', wsEditorData.hideAdvancedSettings);
|
5087 |
|
5088 |
//Update editor state when settings change
|
5089 |
+
$('#ws-hide-advanced-settings').on('click', function(){
|
5090 |
wsEditorData.hideAdvancedSettings = hideSettingsCheckbox.prop('checked');
|
5091 |
|
5092 |
//Show/hide advanced settings dynamically as the user changes the setting.
|
menu-editor.php
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
Plugin Name: Admin Menu Editor
|
4 |
Plugin URI: http://w-shadow.com/blog/2008/12/20/admin-menu-editor-for-wordpress/
|
5 |
Description: Lets you directly edit the WordPress admin menu. You can re-order, hide or rename existing menus, add custom menus and more.
|
6 |
-
Version: 1.9.
|
7 |
Author: Janis Elsts
|
8 |
Author URI: http://w-shadow.com/blog/
|
9 |
*/
|
3 |
Plugin Name: Admin Menu Editor
|
4 |
Plugin URI: http://w-shadow.com/blog/2008/12/20/admin-menu-editor-for-wordpress/
|
5 |
Description: Lets you directly edit the WordPress admin menu. You can re-order, hide or rename existing menus, add custom menus and more.
|
6 |
+
Version: 1.9.8
|
7 |
Author: Janis Elsts
|
8 |
Author URI: http://w-shadow.com/blog/
|
9 |
*/
|
modules/access-editor/access-editor.js
CHANGED
@@ -292,7 +292,7 @@ window.AmeItemAccessEditor = (function ($) {
|
|
292 |
});
|
293 |
|
294 |
//The "Save Changes" button.
|
295 |
-
$editor.find('#ws_save_access_settings').click
|
296 |
//Read the new settings from the form.
|
297 |
var extraCapability, restrictAccessToItems, grantAccess;
|
298 |
|
292 |
});
|
293 |
|
294 |
//The "Save Changes" button.
|
295 |
+
$editor.find('#ws_save_access_settings').on('click', function() {
|
296 |
//Read the new settings from the form.
|
297 |
var extraCapability, restrictAccessToItems, grantAccess;
|
298 |
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
|
|
4 |
Tags: admin, dashboard, menu, security, wpmu
|
5 |
Requires at least: 4.1
|
6 |
Tested up to: 5.6
|
7 |
-
Stable tag: 1.9.
|
8 |
|
9 |
Lets you edit the WordPress admin menu. You can re-order, hide or rename menus, add custom menus and more.
|
10 |
|
@@ -63,6 +63,16 @@ Plugins installed in the `mu-plugins` directory are treated as "always on", so y
|
|
63 |
|
64 |
== Changelog ==
|
65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
= 1.9.7 =
|
67 |
* Fixed a conflict with Elementor 3.0.0-beta that caused the "Theme Builder" menu item to have the wrong URL.
|
68 |
* Minor performance optimization.
|
4 |
Tags: admin, dashboard, menu, security, wpmu
|
5 |
Requires at least: 4.1
|
6 |
Tested up to: 5.6
|
7 |
+
Stable tag: 1.9.8
|
8 |
|
9 |
Lets you edit the WordPress admin menu. You can re-order, hide or rename menus, add custom menus and more.
|
10 |
|
63 |
|
64 |
== Changelog ==
|
65 |
|
66 |
+
= 1.9.8 =
|
67 |
+
* Added a "bbPress override" option that prevents bbPress from resetting all changes that are made to dynamic bbPress roles. Enabling this option allows you to edit bbPress roles with any role editing plugin.
|
68 |
+
* Fixed a conflict that caused some hidden Simple Calendars menu items to show up when Admin Menu Editor was activated.
|
69 |
+
* Fixed a bug where menu items that had special characters like "&" and "/" in the slug could stop working if they were moved to a different submenu or to the top level.
|
70 |
+
* Fixed a bug where changing the menu icon to an external image (like a URL pointing to a PNG file) could result in the old and the new icon being displayed at once, either side by side or one below the other. This only affected menu items that had an icon set in CSS by using a `::before` pseudo-element.
|
71 |
+
* Fixed many jQuery deprecation warnings.
|
72 |
+
* Fixed a bug where some menu settings would not loaded from the database when another plugin triggered a filter that caused the menu configuration to be loaded before AME loaded its modules.
|
73 |
+
* Fixed bug that could cause an obscure conflict with plugins that change the admin URL, like "WP Hide & Security Enhancer". When a user tried to open "Dashboard -> Home", the plugin could incorrectly apply the permisssions of a another menu item to the "Home" item. If the other menu item was configured to be inaccessible, the user would get an error message when logging in (they were still successfully logged in).
|
74 |
+
* Improved error reporting in situations where the plugin can't parse menu data.
|
75 |
+
|
76 |
= 1.9.7 =
|
77 |
* Fixed a conflict with Elementor 3.0.0-beta that caused the "Theme Builder" menu item to have the wrong URL.
|
78 |
* Minor performance optimization.
|