Version Description
- security improvement
- bug fix: encoded ampersand showing in 'Confirm & Run' text
- improvement: UI enhancements
- improvement: use CodeMirror library from WordPress Core.
- improvement: only check Scheduling Service connectivity if a Scheduling license has been saved
Download this release
Release Info
Developer | soflyy |
Plugin | Export WordPress data to XML/CSV |
Version | 1.3.6 |
Comparing to | |
See all releases |
Code changes from version 1.3.5 to 1.3.6
- actions/wp_ajax_scheduling_dialog_content.php +4 -2
- controllers/admin/export.php +9 -8
- controllers/admin/manage.php +16 -10
- controllers/admin/settings.php +5 -3
- controllers/controller/admin.php +12 -11
- dist/app.js +10960 -10999
actions/wp_ajax_scheduling_dialog_content.php
CHANGED
@@ -653,8 +653,10 @@ function pmxe_wp_ajax_scheduling_dialog_content()
|
|
653 |
<span class="connection-icon" style="margin-left: 8px; height: 16px;">
|
654 |
<?php include __DIR__ . '/../src/Scheduling/views/ConnectionIcon.php'; ?>
|
655 |
</span>
|
656 |
-
<?php if
|
657 |
-
|
|
|
|
|
658 |
<?php } ?>
|
659 |
</h4>
|
660 |
</label>
|
653 |
<span class="connection-icon" style="margin-left: 8px; height: 16px;">
|
654 |
<?php include __DIR__ . '/../src/Scheduling/views/ConnectionIcon.php'; ?>
|
655 |
</span>
|
656 |
+
<?php if($post['scheduling_enable'] == 1) { ?>
|
657 |
+
<?php if (!$scheduling->checkConnection()) { ?>
|
658 |
+
<span class="wpai-license" style="margin-left: 8px; font-weight: normal; font-weight: normal; <?php if(!$hasActiveLicense) { ?> display: none; <?php }?>"><span class="unable-to-connect">Unable to connect, please contact support.</span></span>
|
659 |
+
<?php } ?>
|
660 |
<?php } ?>
|
661 |
</h4>
|
662 |
</label>
|
controllers/admin/export.php
CHANGED
@@ -19,7 +19,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin
|
|
19 |
$id = $this->input->get('id');
|
20 |
$this->data['export'] = $export = new PMXE_Export_Record();
|
21 |
if (!$id or $export->getById($id)->isEmpty()) { // specified import is not found
|
22 |
-
wp_redirect(add_query_arg('page', 'pmxe-admin-manage', admin_url('admin.php')));
|
23 |
die();
|
24 |
}
|
25 |
$this->isWizard = false;
|
@@ -30,7 +30,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin
|
|
30 |
}
|
31 |
|
32 |
// preserve id parameter as part of baseUrl
|
33 |
-
$id = $this->input->get('id') and $this->baseUrl = add_query_arg('id', $id, $this->baseUrl);
|
34 |
|
35 |
}
|
36 |
|
@@ -155,10 +155,10 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin
|
|
155 |
PMXE_Plugin::$session->save_data();
|
156 |
|
157 |
if (!empty($post['auto_generate'])) {
|
158 |
-
wp_redirect(add_query_arg('action', 'options', $this->baseUrl));
|
159 |
die();
|
160 |
} else {
|
161 |
-
wp_redirect(add_query_arg('action', 'template', $this->baseUrl));
|
162 |
die();
|
163 |
}
|
164 |
|
@@ -301,7 +301,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin
|
|
301 |
PMXE_Plugin::$session->set($key, $value);
|
302 |
}
|
303 |
PMXE_Plugin::$session->save_data();
|
304 |
-
wp_redirect(add_query_arg('action', 'options', $this->baseUrl));
|
305 |
die();
|
306 |
} else {
|
307 |
$this->data['export']->set(array('options' => $post, 'settings_update_on' => date('Y-m-d H:i:s')))->save();
|
@@ -310,7 +310,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin
|
|
310 |
$this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => (($post['is_scheduled']) ? $post['scheduled_period'] : '')))->save();
|
311 |
}
|
312 |
|
313 |
-
wp_redirect(add_query_arg(array('page' => 'pmxe-admin-manage', 'pmxe_nt' => urlencode(__('Options updated', 'pmxi_plugin'))) + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php')));
|
314 |
die();
|
315 |
}
|
316 |
}
|
@@ -379,6 +379,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin
|
|
379 |
'options' => $post,
|
380 |
'friendly_name' => $this->getFriendlyName($post),
|
381 |
'last_activity' => date('Y-m-d H:i:s')
|
|
|
382 |
)
|
383 |
)->save();
|
384 |
|
@@ -434,7 +435,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin
|
|
434 |
PMXE_Plugin::$session->set($key, $value);
|
435 |
}
|
436 |
PMXE_Plugin::$session->save_data();
|
437 |
-
wp_redirect(add_query_arg('action', 'process', $this->baseUrl));
|
438 |
die();
|
439 |
}
|
440 |
} else {
|
@@ -444,7 +445,7 @@ class PMXE_Admin_Export extends PMXE_Controller_Admin
|
|
444 |
if (!empty($post['friendly_name'])) {
|
445 |
$this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => (($post['is_scheduled']) ? $post['scheduled_period'] : '')))->save();
|
446 |
}
|
447 |
-
wp_redirect(add_query_arg(array('page' => 'pmxe-admin-manage', 'pmxe_nt' => urlencode(__('Options updated', 'wp_all_export_plugin'))) + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php')));
|
448 |
die();
|
449 |
}
|
450 |
}
|
19 |
$id = $this->input->get('id');
|
20 |
$this->data['export'] = $export = new PMXE_Export_Record();
|
21 |
if (!$id or $export->getById($id)->isEmpty()) { // specified import is not found
|
22 |
+
wp_redirect(esc_url_raw(add_query_arg('page', 'pmxe-admin-manage', admin_url('admin.php'))));
|
23 |
die();
|
24 |
}
|
25 |
$this->isWizard = false;
|
30 |
}
|
31 |
|
32 |
// preserve id parameter as part of baseUrl
|
33 |
+
$id = $this->input->get('id') and $this->baseUrl = esc_url_raw(add_query_arg('id', $id, $this->baseUrl));
|
34 |
|
35 |
}
|
36 |
|
155 |
PMXE_Plugin::$session->save_data();
|
156 |
|
157 |
if (!empty($post['auto_generate'])) {
|
158 |
+
wp_redirect(esc_url_raw(add_query_arg('action', 'options', $this->baseUrl)));
|
159 |
die();
|
160 |
} else {
|
161 |
+
wp_redirect(esc_url_raw(add_query_arg('action', 'template', $this->baseUrl)));
|
162 |
die();
|
163 |
}
|
164 |
|
301 |
PMXE_Plugin::$session->set($key, $value);
|
302 |
}
|
303 |
PMXE_Plugin::$session->save_data();
|
304 |
+
wp_redirect(esc_url_raw(add_query_arg('action', 'options', $this->baseUrl)));
|
305 |
die();
|
306 |
} else {
|
307 |
$this->data['export']->set(array('options' => $post, 'settings_update_on' => date('Y-m-d H:i:s')))->save();
|
310 |
$this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => (($post['is_scheduled']) ? $post['scheduled_period'] : '')))->save();
|
311 |
}
|
312 |
|
313 |
+
wp_redirect(esc_url_raw(add_query_arg(array('page' => 'pmxe-admin-manage', 'pmxe_nt' => urlencode(__('Options updated', 'pmxi_plugin'))) + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php'))));
|
314 |
die();
|
315 |
}
|
316 |
}
|
379 |
'options' => $post,
|
380 |
'friendly_name' => $this->getFriendlyName($post),
|
381 |
'last_activity' => date('Y-m-d H:i:s')
|
382 |
+
|
383 |
)
|
384 |
)->save();
|
385 |
|
435 |
PMXE_Plugin::$session->set($key, $value);
|
436 |
}
|
437 |
PMXE_Plugin::$session->save_data();
|
438 |
+
wp_redirect(esc_url_raw(add_query_arg('action', 'process', $this->baseUrl)));
|
439 |
die();
|
440 |
}
|
441 |
} else {
|
445 |
if (!empty($post['friendly_name'])) {
|
446 |
$this->data['export']->set(array('friendly_name' => $post['friendly_name'], 'scheduled' => (($post['is_scheduled']) ? $post['scheduled_period'] : '')))->save();
|
447 |
}
|
448 |
+
wp_redirect(esc_url_raw(add_query_arg(array('page' => 'pmxe-admin-manage', 'pmxe_nt' => urlencode(__('Options updated', 'wp_all_export_plugin'))) + array_intersect_key($_GET, array_flip($this->baseUrlParamNames)), admin_url('admin.php'))));
|
449 |
die();
|
450 |
}
|
451 |
}
|
controllers/admin/manage.php
CHANGED
@@ -50,7 +50,7 @@ class PMXE_Admin_Manage extends PMXE_Controller_Admin {
|
|
50 |
)->getBy($by, "$order_by $order", $pagenum, $perPage, $list->getTable() . '.id');
|
51 |
|
52 |
$this->data['page_links'] = paginate_links(array(
|
53 |
-
'base' => add_query_arg('pagenum', '%#%', $this->baseUrl),
|
54 |
'add_args' => array('page' => 'pmxe-admin-manage'),
|
55 |
'format' => '',
|
56 |
'prev_text' => __('«', 'PMXE_plugin'),
|
@@ -162,7 +162,8 @@ class PMXE_Admin_Manage extends PMXE_Controller_Admin {
|
|
162 |
'canceled_on' => date('Y-m-d H:i:s')
|
163 |
))->update();
|
164 |
|
165 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('Export canceled', 'wp_all_import_plugin')), $this->baseUrl))
|
|
|
166 |
}
|
167 |
|
168 |
/**
|
@@ -230,7 +231,7 @@ class PMXE_Admin_Manage extends PMXE_Controller_Admin {
|
|
230 |
|
231 |
$this->errors->remove('count-validation');
|
232 |
if ( ! $this->errors->get_error_codes()) {
|
233 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('Options updated', 'wp_all_export_plugin')), $this->baseUrl));
|
234 |
die();
|
235 |
}
|
236 |
|
@@ -260,7 +261,7 @@ class PMXE_Admin_Manage extends PMXE_Controller_Admin {
|
|
260 |
$scheduling = \Wpae\Scheduling\Scheduling::create();
|
261 |
$scheduling->deleteScheduleIfExists($id);
|
262 |
|
263 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('Export deleted', 'wp_all_export_plugin')), $this->baseUrl)); die();
|
264 |
}
|
265 |
|
266 |
$this->render();
|
@@ -291,7 +292,8 @@ class PMXE_Admin_Manage extends PMXE_Controller_Admin {
|
|
291 |
$scheduling = \Wpae\Scheduling\Scheduling::create();
|
292 |
$scheduling->deleteScheduleIfExists($item->id);
|
293 |
}
|
294 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(sprintf(__('%d %s deleted', 'wp_all_export_plugin'), $items->count(), _n('export', 'exports', $items->count(), 'wp_all_export_plugin'))), $this->baseUrl))
|
|
|
295 |
}
|
296 |
$this->render();
|
297 |
}
|
@@ -358,12 +360,13 @@ class PMXE_Admin_Manage extends PMXE_Controller_Admin {
|
|
358 |
}
|
359 |
else
|
360 |
{
|
361 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('The exported bundle is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp_all_export_plugin')), $this->baseUrl))
|
|
|
362 |
}
|
363 |
}
|
364 |
else
|
365 |
{
|
366 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('This export doesn\'t exist.', 'wp_all_export_plugin')), $this->baseUrl)); die();
|
367 |
}
|
368 |
}
|
369 |
}
|
@@ -469,18 +472,21 @@ class PMXE_Admin_Manage extends PMXE_Controller_Admin {
|
|
469 |
}
|
470 |
break;
|
471 |
default:
|
472 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('File format not supported', 'wp_all_export_plugin')), $this->baseUrl))
|
|
|
473 |
break;
|
474 |
}
|
475 |
}
|
476 |
else
|
477 |
{
|
478 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('The exported file is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp_all_export_plugin')), $this->baseUrl))
|
|
|
479 |
}
|
480 |
}
|
481 |
else
|
482 |
{
|
483 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('The exported file is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp_all_export_plugin')), $this->baseUrl))
|
|
|
484 |
}
|
485 |
}
|
486 |
}
|
50 |
)->getBy($by, "$order_by $order", $pagenum, $perPage, $list->getTable() . '.id');
|
51 |
|
52 |
$this->data['page_links'] = paginate_links(array(
|
53 |
+
'base' => esc_url_raw(add_query_arg('pagenum', '%#%', $this->baseUrl)),
|
54 |
'add_args' => array('page' => 'pmxe-admin-manage'),
|
55 |
'format' => '',
|
56 |
'prev_text' => __('«', 'PMXE_plugin'),
|
162 |
'canceled_on' => date('Y-m-d H:i:s')
|
163 |
))->update();
|
164 |
|
165 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Export canceled', 'wp_all_import_plugin')), $this->baseUrl)));
|
166 |
+
die();
|
167 |
}
|
168 |
|
169 |
/**
|
231 |
|
232 |
$this->errors->remove('count-validation');
|
233 |
if ( ! $this->errors->get_error_codes()) {
|
234 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Options updated', 'wp_all_export_plugin')), $this->baseUrl)));
|
235 |
die();
|
236 |
}
|
237 |
|
261 |
$scheduling = \Wpae\Scheduling\Scheduling::create();
|
262 |
$scheduling->deleteScheduleIfExists($id);
|
263 |
|
264 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Export deleted', 'wp_all_export_plugin')), $this->baseUrl))); die();
|
265 |
}
|
266 |
|
267 |
$this->render();
|
292 |
$scheduling = \Wpae\Scheduling\Scheduling::create();
|
293 |
$scheduling->deleteScheduleIfExists($item->id);
|
294 |
}
|
295 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(sprintf(__('%d %s deleted', 'wp_all_export_plugin'), $items->count(), _n('export', 'exports', $items->count(), 'wp_all_export_plugin'))), $this->baseUrl)));
|
296 |
+
die();
|
297 |
}
|
298 |
$this->render();
|
299 |
}
|
360 |
}
|
361 |
else
|
362 |
{
|
363 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('The exported bundle is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp_all_export_plugin')), $this->baseUrl)));
|
364 |
+
die();
|
365 |
}
|
366 |
}
|
367 |
else
|
368 |
{
|
369 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('This export doesn\'t exist.', 'wp_all_export_plugin')), $this->baseUrl))); die();
|
370 |
}
|
371 |
}
|
372 |
}
|
472 |
}
|
473 |
break;
|
474 |
default:
|
475 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('File format not supported', 'wp_all_export_plugin')), $this->baseUrl)));
|
476 |
+
die();
|
477 |
break;
|
478 |
}
|
479 |
}
|
480 |
else
|
481 |
{
|
482 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('The exported file is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp_all_export_plugin')), $this->baseUrl)));
|
483 |
+
die();
|
484 |
}
|
485 |
}
|
486 |
else
|
487 |
{
|
488 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('The exported file is missing and can\'t be downloaded. Please re-run your export to re-generate it.', 'wp_all_export_plugin')), $this->baseUrl)));
|
489 |
+
die();
|
490 |
}
|
491 |
}
|
492 |
}
|
controllers/admin/settings.php
CHANGED
@@ -30,7 +30,8 @@ class PMXE_Admin_Settings extends PMXE_Controller_Admin {
|
|
30 |
|
31 |
PMXE_Plugin::getInstance()->updateOption($post);
|
32 |
|
33 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(__('Settings saved', 'wp_all_export_plugin')), $this->baseUrl))
|
|
|
34 |
}
|
35 |
}
|
36 |
|
@@ -109,7 +110,7 @@ class PMXE_Admin_Settings extends PMXE_Controller_Admin {
|
|
109 |
unset($template_data['id']);
|
110 |
$template->clear()->set($template_data)->insert();
|
111 |
}
|
112 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(sprintf(_n('%d template imported', '%d templates imported', count($templates_data), 'wp_all_export_plugin'), count($templates_data))), $this->baseUrl));
|
113 |
die();
|
114 |
}
|
115 |
}
|
@@ -136,7 +137,8 @@ class PMXE_Admin_Settings extends PMXE_Controller_Admin {
|
|
136 |
foreach ($templates_ids as $template_id) {
|
137 |
$template->clear()->set('id', $template_id)->delete();
|
138 |
}
|
139 |
-
wp_redirect(add_query_arg('pmxe_nt', urlencode(sprintf(_n('%d template deleted', '%d templates deleted', count($templates_ids), 'wp_all_export_plugin'), count($templates_ids))), $this->baseUrl))
|
|
|
140 |
}
|
141 |
if ($this->input->post('export_templates')){
|
142 |
$export_data = array();
|
30 |
|
31 |
PMXE_Plugin::getInstance()->updateOption($post);
|
32 |
|
33 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(__('Settings saved', 'wp_all_export_plugin')), $this->baseUrl)));
|
34 |
+
die();
|
35 |
}
|
36 |
}
|
37 |
|
110 |
unset($template_data['id']);
|
111 |
$template->clear()->set($template_data)->insert();
|
112 |
}
|
113 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(sprintf(_n('%d template imported', '%d templates imported', count($templates_data), 'wp_all_export_plugin'), count($templates_data))), $this->baseUrl)));
|
114 |
die();
|
115 |
}
|
116 |
}
|
137 |
foreach ($templates_ids as $template_id) {
|
138 |
$template->clear()->set('id', $template_id)->delete();
|
139 |
}
|
140 |
+
wp_redirect(esc_url_raw(add_query_arg('pmxe_nt', urlencode(sprintf(_n('%d template deleted', '%d templates deleted', count($templates_ids), 'wp_all_export_plugin'), count($templates_ids))), $this->baseUrl)));
|
141 |
+
die();
|
142 |
}
|
143 |
if ($this->input->post('export_templates')){
|
144 |
$export_data = array();
|
controllers/controller/admin.php
CHANGED
@@ -27,7 +27,7 @@ abstract class PMXE_Controller_Admin extends PMXE_Controller {
|
|
27 |
|
28 |
$remove = array_diff(array_keys($_GET), $this->baseUrlParamNames);
|
29 |
if ($remove) {
|
30 |
-
$this->baseUrl = remove_query_arg($remove);
|
31 |
} else {
|
32 |
$this->baseUrl = $_SERVER['REQUEST_URI'];
|
33 |
}
|
@@ -52,6 +52,7 @@ abstract class PMXE_Controller_Admin extends PMXE_Controller {
|
|
52 |
wp_enqueue_style('jquery-codemirror', PMXE_ROOT_URL . '/static/codemirror/codemirror.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
53 |
wp_enqueue_style('jquery-timepicker', PMXE_ROOT_URL . '/static/js/jquery/css/timepicker/jquery.timepicker.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
54 |
wp_enqueue_style('pmxe-angular-scss', PMXE_ROOT_URL . '/dist/styles.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
|
|
55 |
|
56 |
$wp_styles->add_data('pmxe-admin-style-ie', 'conditional', 'lte IE 7');
|
57 |
wp_enqueue_style('wp-pointer');
|
@@ -69,22 +70,15 @@ abstract class PMXE_Controller_Admin extends PMXE_Controller {
|
|
69 |
wp_enqueue_style('pmxe-admin-style-color', PMXE_ROOT_URL . '/static/css/admin-colors-' . $scheme_color . '.css', array('media-views'));
|
70 |
}
|
71 |
|
72 |
-
wp_deregister_script('wp-codemirror');
|
73 |
-
|
74 |
wp_enqueue_script('jquery-ui-datepicker', PMXE_ROOT_URL . '/static/js/jquery/ui.datepicker.js', 'jquery-ui-core');
|
75 |
wp_enqueue_script('tipsy', PMXE_ROOT_URL . '/static/js/jquery/jquery.tipsy.js', 'jquery', PMXE_VERSION.PMXE_ASSETS_VERSION);
|
76 |
wp_enqueue_script('jquery-pmxe-nestable', PMXE_ROOT_URL . '/static/js/jquery/jquery.mjs.pmxe_nestedSortable.js', array('jquery', 'jquery-ui-dialog', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-tabs', 'jquery-ui-progressbar'));
|
77 |
wp_enqueue_script('jquery-select2', PMXE_ROOT_URL . '/static/js/jquery/select2.min.js', 'jquery');
|
78 |
wp_enqueue_script('jquery-ddslick', PMXE_ROOT_URL . '/static/js/jquery/jquery.ddslick.min.js', 'jquery');
|
79 |
wp_enqueue_script('jquery-chosen', PMXE_ROOT_URL . '/static/js/jquery/chosen.jquery.js', 'jquery');
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
wp_enqueue_script('jquery-codemirror-xml', PMXE_ROOT_URL . '/static/codemirror/xml.js', array('jquery-codemirror-htmlmixed'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
84 |
-
wp_enqueue_script('jquery-codemirror-javascript', PMXE_ROOT_URL . '/static/codemirror/javascript.js', array('jquery-codemirror-xml'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
85 |
-
wp_enqueue_script('jquery-codemirror-clike', PMXE_ROOT_URL . '/static/codemirror/clike.js', array('jquery-codemirror-javascript'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
86 |
-
wp_enqueue_script('jquery-codemirror-php', PMXE_ROOT_URL . '/static/codemirror/php.js', array('jquery-codemirror-clike'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
87 |
-
wp_enqueue_script('jquery-codemirror-autorefresh', PMXE_ROOT_URL . '/static/codemirror/autorefresh.js', array('jquery-codemirror'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
88 |
wp_enqueue_script('jquery-timepicker', PMXE_ROOT_URL . '/static/js/jquery/jquery.timepicker.js', array('jquery'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
89 |
|
90 |
wp_enqueue_script('wp-pointer');
|
@@ -100,6 +94,13 @@ abstract class PMXE_Controller_Admin extends PMXE_Controller {
|
|
100 |
wp_enqueue_script('pmxe-angular-app', PMXE_ROOT_URL . '/dist/app.min.js', array('jquery'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
101 |
}
|
102 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
/**
|
105 |
* @see Controller::render()
|
27 |
|
28 |
$remove = array_diff(array_keys($_GET), $this->baseUrlParamNames);
|
29 |
if ($remove) {
|
30 |
+
$this->baseUrl = esc_url_raw(remove_query_arg($remove));
|
31 |
} else {
|
32 |
$this->baseUrl = $_SERVER['REQUEST_URI'];
|
33 |
}
|
52 |
wp_enqueue_style('jquery-codemirror', PMXE_ROOT_URL . '/static/codemirror/codemirror.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
53 |
wp_enqueue_style('jquery-timepicker', PMXE_ROOT_URL . '/static/js/jquery/css/timepicker/jquery.timepicker.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
54 |
wp_enqueue_style('pmxe-angular-scss', PMXE_ROOT_URL . '/dist/styles.css', array('media-views'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
55 |
+
wp_enqueue_style('jquery-codemirror', PMXE_ROOT_URL . '/static/css/codemirror.css', array(), PMXE_VERSION);
|
56 |
|
57 |
$wp_styles->add_data('pmxe-admin-style-ie', 'conditional', 'lte IE 7');
|
58 |
wp_enqueue_style('wp-pointer');
|
70 |
wp_enqueue_style('pmxe-admin-style-color', PMXE_ROOT_URL . '/static/css/admin-colors-' . $scheme_color . '.css', array('media-views'));
|
71 |
}
|
72 |
|
|
|
|
|
73 |
wp_enqueue_script('jquery-ui-datepicker', PMXE_ROOT_URL . '/static/js/jquery/ui.datepicker.js', 'jquery-ui-core');
|
74 |
wp_enqueue_script('tipsy', PMXE_ROOT_URL . '/static/js/jquery/jquery.tipsy.js', 'jquery', PMXE_VERSION.PMXE_ASSETS_VERSION);
|
75 |
wp_enqueue_script('jquery-pmxe-nestable', PMXE_ROOT_URL . '/static/js/jquery/jquery.mjs.pmxe_nestedSortable.js', array('jquery', 'jquery-ui-dialog', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-tabs', 'jquery-ui-progressbar'));
|
76 |
wp_enqueue_script('jquery-select2', PMXE_ROOT_URL . '/static/js/jquery/select2.min.js', 'jquery');
|
77 |
wp_enqueue_script('jquery-ddslick', PMXE_ROOT_URL . '/static/js/jquery/jquery.ddslick.min.js', 'jquery');
|
78 |
wp_enqueue_script('jquery-chosen', PMXE_ROOT_URL . '/static/js/jquery/chosen.jquery.js', 'jquery');
|
79 |
+
|
80 |
+
add_action("admin_enqueue_scripts", [$this, 'add_admin_scripts']);
|
81 |
+
|
|
|
|
|
|
|
|
|
|
|
82 |
wp_enqueue_script('jquery-timepicker', PMXE_ROOT_URL . '/static/js/jquery/jquery.timepicker.js', array('jquery'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
83 |
|
84 |
wp_enqueue_script('wp-pointer');
|
94 |
wp_enqueue_script('pmxe-angular-app', PMXE_ROOT_URL . '/dist/app.min.js', array('jquery'), PMXE_VERSION.PMXE_ASSETS_VERSION);
|
95 |
}
|
96 |
}
|
97 |
+
|
98 |
+
public function add_admin_scripts() {
|
99 |
+
|
100 |
+
$cm_settings['codeEditor'] = wp_enqueue_code_editor(['type' => 'php']);
|
101 |
+
wp_localize_script('jquery', 'wpae_cm_settings', $cm_settings);
|
102 |
+
|
103 |
+
}
|
104 |
|
105 |
/**
|
106 |
* @see Controller::render()
|
dist/app.js
CHANGED
@@ -5,142 +5,142 @@
|
|
5 |
*/
|
6 |
(function(window) {'use strict';
|
7 |
|
8 |
-
|
9 |
minErrConfig,
|
10 |
errorHandlingConfig,
|
11 |
isValidObjectMaxDepth
|
12 |
*/
|
13 |
|
14 |
-
|
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 |
-
if (isDefined(config.urlErrorParamsEnabled) && isBoolean(config.urlErrorParamsEnabled)) {
|
52 |
-
minErrConfig.urlErrorParamsEnabled = config.urlErrorParamsEnabled;
|
53 |
-
}
|
54 |
-
} else {
|
55 |
-
return minErrConfig;
|
56 |
-
}
|
57 |
}
|
58 |
-
|
59 |
-
|
60 |
-
* @private
|
61 |
-
* @param {Number} maxDepth
|
62 |
-
* @return {boolean}
|
63 |
-
*/
|
64 |
-
function isValidObjectMaxDepth(maxDepth) {
|
65 |
-
return isNumber(maxDepth) && maxDepth > 0;
|
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 |
-
// A minErr message has two parts: the message itself and the url that contains the
|
116 |
-
// encoded message.
|
117 |
-
// The message's parameters can contain other error messages which also include error urls.
|
118 |
-
// To prevent the messages from getting too long, we strip the error urls from the parameters.
|
119 |
-
|
120 |
-
message += template.replace(/\{\d+\}/g, function(match) {
|
121 |
-
var index = +match.slice(1, -1);
|
122 |
-
|
123 |
-
if (index < templateArgs.length) {
|
124 |
-
return templateArgs[index].replace(errRegExp, '');
|
125 |
-
}
|
126 |
|
127 |
-
|
128 |
-
|
|
|
|
|
129 |
|
130 |
-
|
|
|
131 |
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
}
|
136 |
-
}
|
137 |
|
138 |
-
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
}
|
141 |
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
144 |
angular,
|
145 |
msie,
|
146 |
jqLite,
|
@@ -243,727 +243,727 @@
|
|
243 |
|
244 |
////////////////////////////////////
|
245 |
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
|
260 |
-
|
261 |
|
262 |
// The name of a form control's ValidityState property.
|
263 |
// This is used so that it's possible for internal tests to create mock ValidityStates.
|
264 |
-
|
265 |
|
266 |
|
267 |
-
|
268 |
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
|
287 |
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
|
304 |
// Support: IE 9-11 only
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
|
311 |
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
|
320 |
-
|
321 |
-
|
322 |
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
|
337 |
-
|
338 |
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
var values = {name: 'misko', gender: 'male'};
|
361 |
var log = [];
|
362 |
angular.forEach(values, function(value, key) {
|
363 |
this.push(key + ': ' + value);
|
364 |
}, log);
|
365 |
expect(log).toEqual(['name: misko', 'gender: male']);
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
}
|
382 |
-
}
|
383 |
-
} else if (isArray(obj) || isArrayLike(obj)) {
|
384 |
-
var isPrimitive = typeof obj !== 'object';
|
385 |
-
for (key = 0, length = obj.length; key < length; key++) {
|
386 |
-
if (isPrimitive || key in obj) {
|
387 |
-
iterator.call(context, obj[key], key, obj);
|
388 |
-
}
|
389 |
-
}
|
390 |
-
} else if (obj.forEach && obj.forEach !== forEach) {
|
391 |
-
obj.forEach(iterator, context, obj);
|
392 |
-
} else if (isBlankObject(obj)) {
|
393 |
-
// createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
|
394 |
-
for (key in obj) {
|
395 |
-
iterator.call(context, obj[key], key, obj);
|
396 |
-
}
|
397 |
-
} else if (typeof obj.hasOwnProperty === 'function') {
|
398 |
-
// Slow path for objects inheriting Object.prototype, hasOwnProperty check needed
|
399 |
-
for (key in obj) {
|
400 |
-
if (obj.hasOwnProperty(key)) {
|
401 |
-
iterator.call(context, obj[key], key, obj);
|
402 |
-
}
|
403 |
-
}
|
404 |
-
} else {
|
405 |
-
// Slow path for objects which do not have a method `hasOwnProperty`
|
406 |
-
for (key in obj) {
|
407 |
-
if (hasOwnProperty.call(obj, key)) {
|
408 |
-
iterator.call(context, obj[key], key, obj);
|
409 |
-
}
|
410 |
-
}
|
411 |
-
}
|
412 |
}
|
413 |
-
|
414 |
-
}
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
420 |
}
|
421 |
-
|
422 |
}
|
|
|
|
|
|
|
423 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
424 |
|
425 |
-
/**
|
426 |
-
* when using forEach the params are value, key, but it is often useful to have key, value.
|
427 |
-
* @param {function(string, *)} iteratorFn
|
428 |
-
* @returns {function(*, string)}
|
429 |
-
*/
|
430 |
-
function reverseParams(iteratorFn) {
|
431 |
-
return function(value, key) {iteratorFn(key, value);};
|
432 |
-
}
|
433 |
-
|
434 |
-
/**
|
435 |
-
* A consistent way of creating unique IDs in angular.
|
436 |
-
*
|
437 |
-
* Using simple numbers allows us to generate 28.6 million unique ids per second for 10 years before
|
438 |
-
* we hit number precision issues in JavaScript.
|
439 |
-
*
|
440 |
-
* Math.pow(2,53) / 60 / 60 / 24 / 365 / 10 = 28.6M
|
441 |
-
*
|
442 |
-
* @returns {number} an unique alpha-numeric string
|
443 |
-
*/
|
444 |
-
function nextUid() {
|
445 |
-
return ++uid;
|
446 |
-
}
|
447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
448 |
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
|
|
461 |
|
462 |
|
463 |
-
|
464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
|
466 |
-
for (var i = 0, ii = objs.length; i < ii; ++i) {
|
467 |
-
var obj = objs[i];
|
468 |
-
if (!isObject(obj) && !isFunction(obj)) continue;
|
469 |
-
var keys = Object.keys(obj);
|
470 |
-
for (var j = 0, jj = keys.length; j < jj; j++) {
|
471 |
-
var key = keys[j];
|
472 |
-
var src = obj[key];
|
473 |
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
491 |
}
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
}
|
|
|
496 |
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
* @module ng
|
501 |
-
* @kind function
|
502 |
-
*
|
503 |
-
* @description
|
504 |
-
* Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
|
505 |
-
* to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
|
506 |
-
* by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`.
|
507 |
-
*
|
508 |
-
* **Note:** Keep in mind that `angular.extend` does not support recursive merge (deep copy). Use
|
509 |
-
* {@link angular.merge} for this.
|
510 |
-
*
|
511 |
-
* @param {Object} dst Destination object.
|
512 |
-
* @param {...Object} src Source object(s).
|
513 |
-
* @returns {Object} Reference to `dst`.
|
514 |
-
*/
|
515 |
-
function extend(dst) {
|
516 |
-
return baseExtend(dst, slice.call(arguments, 1), false);
|
517 |
-
}
|
518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
|
520 |
-
/**
|
521 |
-
* @ngdoc function
|
522 |
-
* @name angular.merge
|
523 |
-
* @module ng
|
524 |
-
* @kind function
|
525 |
-
*
|
526 |
-
* @description
|
527 |
-
* Deeply extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
|
528 |
-
* to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
|
529 |
-
* by passing an empty object as the target: `var object = angular.merge({}, object1, object2)`.
|
530 |
-
*
|
531 |
-
* Unlike {@link angular.extend extend()}, `merge()` recursively descends into object properties of source
|
532 |
-
* objects, performing a deep copy.
|
533 |
-
*
|
534 |
-
* @deprecated
|
535 |
-
* sinceVersion="1.6.5"
|
536 |
-
* This function is deprecated, but will not be removed in the 1.x lifecycle.
|
537 |
-
* There are edge cases (see {@link angular.merge#known-issues known issues}) that are not
|
538 |
-
* supported by this function. We suggest
|
539 |
-
* using [lodash's merge()](https://lodash.com/docs/4.17.4#merge) instead.
|
540 |
-
*
|
541 |
-
* @knownIssue
|
542 |
-
* This is a list of (known) object types that are not handled correctly by this function:
|
543 |
-
* - [`Blob`](https://developer.mozilla.org/docs/Web/API/Blob)
|
544 |
-
* - [`MediaStream`](https://developer.mozilla.org/docs/Web/API/MediaStream)
|
545 |
-
* - [`CanvasGradient`](https://developer.mozilla.org/docs/Web/API/CanvasGradient)
|
546 |
-
* - AngularJS {@link $rootScope.Scope scopes};
|
547 |
-
*
|
548 |
-
* @param {Object} dst Destination object.
|
549 |
-
* @param {...Object} src Source object(s).
|
550 |
-
* @returns {Object} Reference to `dst`.
|
551 |
-
*/
|
552 |
-
function merge(dst) {
|
553 |
-
return baseExtend(dst, slice.call(arguments, 1), true);
|
554 |
-
}
|
555 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
556 |
|
557 |
|
558 |
-
function toInt(str) {
|
559 |
-
return parseInt(str, 10);
|
560 |
-
}
|
561 |
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
};
|
566 |
|
|
|
|
|
|
|
|
|
567 |
|
568 |
-
function inherit(parent, extra) {
|
569 |
-
return extend(Object.create(parent), extra);
|
570 |
-
}
|
571 |
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
|
|
|
|
|
|
|
|
582 |
function foo(callback) {
|
583 |
var result = calculateResult();
|
584 |
(callback || angular.noop)(result);
|
585 |
}
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
|
591 |
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
return (transformationFn || angular.identity)(value);
|
605 |
};
|
606 |
|
607 |
-
|
608 |
-
|
609 |
return (fn || angular.identity)(input);
|
610 |
};
|
611 |
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
|
623 |
|
624 |
-
|
625 |
|
626 |
-
|
627 |
-
|
628 |
-
|
629 |
|
630 |
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
|
645 |
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
|
660 |
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
|
679 |
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
|
689 |
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
|
704 |
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
|
725 |
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
|
742 |
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
|
791 |
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
|
803 |
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
|
815 |
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
|
820 |
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
|
825 |
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
|
830 |
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
|
835 |
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
|
840 |
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
|
845 |
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
|
855 |
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
|
860 |
// Copied from:
|
861 |
// http://docs.closure-library.googlecode.com/git/local_closure_goog_string_string.js.source.html#line1021
|
862 |
// Prereq: s is a string.
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
|
870 |
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
|
901 |
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
$scope.leader = {};
|
968 |
|
969 |
$scope.reset = function() {
|
@@ -978,440 +978,440 @@
|
|
978 |
|
979 |
$scope.reset();
|
980 |
}]);
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
if (destination) {
|
990 |
-
if (isTypedArray(destination) || isArrayBuffer(destination)) {
|
991 |
-
throw ngMinErr('cpta', 'Can\'t copy! TypedArray destination cannot be mutated.');
|
992 |
-
}
|
993 |
-
if (source === destination) {
|
994 |
-
throw ngMinErr('cpi', 'Can\'t copy! Source and destination are identical.');
|
995 |
-
}
|
996 |
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
}
|
1005 |
-
});
|
1006 |
-
}
|
1007 |
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
|
|
|
|
|
|
|
|
1011 |
}
|
|
|
|
|
1012 |
|
1013 |
-
|
|
|
|
|
|
|
1014 |
|
1015 |
-
|
1016 |
-
maxDepth--;
|
1017 |
-
if (maxDepth < 0) {
|
1018 |
-
return '...';
|
1019 |
-
}
|
1020 |
-
var h = destination.$$hashKey;
|
1021 |
-
var key;
|
1022 |
-
if (isArray(source)) {
|
1023 |
-
for (var i = 0, ii = source.length; i < ii; i++) {
|
1024 |
-
destination.push(copyElement(source[i], maxDepth));
|
1025 |
-
}
|
1026 |
-
} else if (isBlankObject(source)) {
|
1027 |
-
// createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
|
1028 |
-
for (key in source) {
|
1029 |
-
destination[key] = copyElement(source[key], maxDepth);
|
1030 |
-
}
|
1031 |
-
} else if (source && typeof source.hasOwnProperty === 'function') {
|
1032 |
-
// Slow path, which must rely on hasOwnProperty
|
1033 |
-
for (key in source) {
|
1034 |
-
if (source.hasOwnProperty(key)) {
|
1035 |
-
destination[key] = copyElement(source[key], maxDepth);
|
1036 |
-
}
|
1037 |
-
}
|
1038 |
-
} else {
|
1039 |
-
// Slowest path --- hasOwnProperty can't be called as a method
|
1040 |
-
for (key in source) {
|
1041 |
-
if (hasOwnProperty.call(source, key)) {
|
1042 |
-
destination[key] = copyElement(source[key], maxDepth);
|
1043 |
-
}
|
1044 |
-
}
|
1045 |
-
}
|
1046 |
-
setHashKey(destination, h);
|
1047 |
-
return destination;
|
1048 |
-
}
|
1049 |
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1055 |
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
|
|
1066 |
|
1067 |
-
|
1068 |
-
|
|
|
|
|
1069 |
|
1070 |
-
|
1071 |
-
|
1072 |
-
needsRecurse = true;
|
1073 |
-
}
|
1074 |
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
? copyRecurse(source, destination, maxDepth)
|
1080 |
-
: destination;
|
1081 |
-
}
|
1082 |
-
|
1083 |
-
function copyType(source) {
|
1084 |
-
switch (toString.call(source)) {
|
1085 |
-
case '[object Int8Array]':
|
1086 |
-
case '[object Int16Array]':
|
1087 |
-
case '[object Int32Array]':
|
1088 |
-
case '[object Float32Array]':
|
1089 |
-
case '[object Float64Array]':
|
1090 |
-
case '[object Uint8Array]':
|
1091 |
-
case '[object Uint8ClampedArray]':
|
1092 |
-
case '[object Uint16Array]':
|
1093 |
-
case '[object Uint32Array]':
|
1094 |
-
return new source.constructor(copyElement(source.buffer), source.byteOffset, source.length);
|
1095 |
-
|
1096 |
-
case '[object ArrayBuffer]':
|
1097 |
-
// Support: IE10
|
1098 |
-
if (!source.slice) {
|
1099 |
-
// If we're in this case we know the environment supports ArrayBuffer
|
1100 |
-
/* eslint-disable no-undef */
|
1101 |
-
var copied = new ArrayBuffer(source.byteLength);
|
1102 |
-
new Uint8Array(copied).set(new Uint8Array(source));
|
1103 |
-
/* eslint-enable */
|
1104 |
-
return copied;
|
1105 |
-
}
|
1106 |
-
return source.slice(0);
|
1107 |
|
1108 |
-
|
1109 |
-
|
1110 |
-
case '[object String]':
|
1111 |
-
case '[object Date]':
|
1112 |
-
return new source.constructor(source.valueOf());
|
1113 |
|
1114 |
-
|
1115 |
-
|
1116 |
-
|
1117 |
-
|
1118 |
|
1119 |
-
|
1120 |
-
|
1121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1122 |
|
1123 |
-
|
1124 |
-
|
1125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1126 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1127 |
}
|
|
|
|
|
1128 |
|
1129 |
|
1130 |
// eslint-disable-next-line no-self-compare
|
1131 |
-
|
1132 |
|
1133 |
|
1134 |
-
|
1135 |
-
|
1136 |
-
|
1137 |
-
|
1138 |
-
|
1139 |
-
|
1140 |
-
|
1141 |
-
|
1142 |
-
|
1143 |
-
|
1144 |
-
|
1145 |
-
|
1146 |
-
|
1147 |
-
|
1148 |
-
|
1149 |
-
|
1150 |
-
|
1151 |
-
|
1152 |
-
|
1153 |
-
|
1154 |
-
|
1155 |
-
|
1156 |
-
|
1157 |
-
|
1158 |
-
|
1159 |
-
|
1160 |
-
|
1161 |
-
|
1162 |
-
|
1163 |
-
|
1164 |
-
|
1165 |
<file name="index.html">
|
1166 |
-
|
1167 |
-
|
1168 |
-
|
1169 |
-
|
1170 |
-
|
1171 |
-
|
1172 |
-
|
1173 |
-
|
1174 |
-
|
1175 |
-
|
1176 |
-
|
1177 |
-
|
1178 |
-
|
1179 |
-
|
1180 |
-
|
1181 |
-
|
1182 |
-
|
1183 |
-
|
1184 |
-
|
1185 |
-
|
1186 |
-
|
1187 |
-
|
1188 |
$scope.user1 = {};
|
1189 |
$scope.user2 = {};
|
1190 |
$scope.compare = function() {
|
1191 |
$scope.result = angular.equals($scope.user1, $scope.user2);
|
1192 |
};
|
1193 |
}]);
|
1194 |
-
|
1195 |
-
|
1196 |
-
|
1197 |
-
|
1198 |
-
|
1199 |
-
|
1200 |
-
|
1201 |
-
|
1202 |
-
|
1203 |
-
|
1204 |
-
|
1205 |
-
|
1206 |
-
|
1207 |
-
|
1208 |
-
|
1209 |
-
}
|
1210 |
-
return true;
|
1211 |
-
}
|
1212 |
-
} else if (isDate(o1)) {
|
1213 |
-
if (!isDate(o2)) return false;
|
1214 |
-
return simpleCompare(o1.getTime(), o2.getTime());
|
1215 |
-
} else if (isRegExp(o1)) {
|
1216 |
-
if (!isRegExp(o2)) return false;
|
1217 |
-
return o1.toString() === o2.toString();
|
1218 |
-
} else {
|
1219 |
-
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) ||
|
1220 |
-
isArray(o2) || isDate(o2) || isRegExp(o2)) return false;
|
1221 |
-
keySet = createMap();
|
1222 |
-
for (key in o1) {
|
1223 |
-
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
|
1224 |
-
if (!equals(o1[key], o2[key])) return false;
|
1225 |
-
keySet[key] = true;
|
1226 |
-
}
|
1227 |
-
for (key in o2) {
|
1228 |
-
if (!(key in keySet) &&
|
1229 |
-
key.charAt(0) !== '$' &&
|
1230 |
-
isDefined(o2[key]) &&
|
1231 |
-
!isFunction(o2[key])) return false;
|
1232 |
-
}
|
1233 |
-
return true;
|
1234 |
-
}
|
1235 |
}
|
1236 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1237 |
}
|
|
|
|
|
|
|
1238 |
|
1239 |
-
|
1240 |
-
|
1241 |
|
1242 |
|
1243 |
-
|
1244 |
-
|
1245 |
|
1246 |
-
|
1247 |
-
|
1248 |
ngCspElement.getAttribute('data-ng-csp');
|
1249 |
-
|
1250 |
-
|
1251 |
-
|
1252 |
-
|
1253 |
-
|
1254 |
-
|
1255 |
-
|
1256 |
-
|
1257 |
-
|
1258 |
-
|
1259 |
-
|
1260 |
-
|
1261 |
-
return csp.rules;
|
1262 |
-
|
1263 |
-
function noUnsafeEval() {
|
1264 |
-
try {
|
1265 |
-
// eslint-disable-next-line no-new, no-new-func
|
1266 |
-
new Function('');
|
1267 |
-
return false;
|
1268 |
-
} catch (e) {
|
1269 |
-
return true;
|
1270 |
-
}
|
1271 |
-
}
|
1272 |
-
};
|
1273 |
-
|
1274 |
-
/**
|
1275 |
-
* @ngdoc directive
|
1276 |
-
* @module ng
|
1277 |
-
* @name ngJq
|
1278 |
-
*
|
1279 |
-
* @element ANY
|
1280 |
-
* @param {string=} ngJq the name of the library available under `window`
|
1281 |
-
* to be used for angular.element
|
1282 |
-
* @description
|
1283 |
-
* Use this directive to force the angular.element library. This should be
|
1284 |
-
* used to force either jqLite by leaving ng-jq blank or setting the name of
|
1285 |
-
* the jquery variable under window (eg. jQuery).
|
1286 |
-
*
|
1287 |
-
* Since AngularJS looks for this directive when it is loaded (doesn't wait for the
|
1288 |
-
* DOMContentLoaded event), it must be placed on an element that comes before the script
|
1289 |
-
* which loads angular. Also, only the first instance of `ng-jq` will be used and all
|
1290 |
-
* others ignored.
|
1291 |
-
*
|
1292 |
-
* @example
|
1293 |
-
* This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
|
1294 |
-
```html
|
1295 |
-
<!doctype html>
|
1296 |
-
<html ng-app ng-jq>
|
1297 |
-
...
|
1298 |
-
...
|
1299 |
-
</html>
|
1300 |
-
```
|
1301 |
-
* @example
|
1302 |
-
* This example shows how to use a jQuery based library of a different name.
|
1303 |
-
* The library name must be available at the top most 'window'.
|
1304 |
-
```html
|
1305 |
-
<!doctype html>
|
1306 |
-
<html ng-app ng-jq="jQueryLib">
|
1307 |
-
...
|
1308 |
-
...
|
1309 |
-
</html>
|
1310 |
-
```
|
1311 |
-
*/
|
1312 |
-
var jq = function() {
|
1313 |
-
if (isDefined(jq.name_)) return jq.name_;
|
1314 |
-
var el;
|
1315 |
-
var i, ii = ngAttrPrefixes.length, prefix, name;
|
1316 |
-
for (i = 0; i < ii; ++i) {
|
1317 |
-
prefix = ngAttrPrefixes[i];
|
1318 |
-
el = window.document.querySelector('[' + prefix.replace(':', '\\:') + 'jq]');
|
1319 |
-
if (el) {
|
1320 |
-
name = el.getAttribute(prefix + 'jq');
|
1321 |
-
break;
|
1322 |
-
}
|
1323 |
-
}
|
1324 |
|
1325 |
-
|
1326 |
-
};
|
1327 |
|
1328 |
-
|
1329 |
-
|
|
|
|
|
|
|
|
|
|
|
1330 |
}
|
|
|
|
|
1331 |
|
1332 |
-
|
1333 |
-
|
1334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1335 |
|
|
|
|
|
|
|
1336 |
|
1337 |
-
|
1338 |
-
|
1339 |
-
|
1340 |
-
|
1341 |
-
|
1342 |
-
|
1343 |
-
|
1344 |
-
|
1345 |
-
|
1346 |
-
|
1347 |
-
|
1348 |
-
|
1349 |
-
|
1350 |
-
|
1351 |
-
|
1352 |
-
|
1353 |
-
|
1354 |
-
|
1355 |
-
|
1356 |
-
|
1357 |
-
|
1358 |
-
|
1359 |
-
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
|
1366 |
-
|
1367 |
-
|
1368 |
-
}
|
1369 |
-
|
1370 |
-
|
1371 |
-
|
1372 |
-
|
|
|
1373 |
|
1374 |
|
1375 |
-
|
1376 |
-
|
1377 |
|
1378 |
-
|
1379 |
-
|
1380 |
-
|
1381 |
-
|
1382 |
-
|
1383 |
-
|
1384 |
-
|
1385 |
-
|
1386 |
-
|
1387 |
|
1388 |
-
|
1389 |
-
|
1390 |
|
1391 |
|
1392 |
-
|
1393 |
-
|
1394 |
-
|
1395 |
-
|
1396 |
-
|
1397 |
-
|
1398 |
-
|
1399 |
-
|
1400 |
-
|
1401 |
-
|
1402 |
-
|
1403 |
-
|
1404 |
-
|
1405 |
-
|
1406 |
-
|
1407 |
-
|
1408 |
-
|
1409 |
-
|
1410 |
-
|
1411 |
-
|
1412 |
-
|
1413 |
-
|
1414 |
-
|
1415 |
* try {
|
1416 |
* return _DatetoJSON.call(this);
|
1417 |
* } catch(e) {
|
@@ -1421,355 +1421,355 @@
|
|
1421 |
* throw e;
|
1422 |
* }
|
1423 |
* };
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
|
1436 |
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
1449 |
-
|
1450 |
-
|
1451 |
-
|
1452 |
-
|
1453 |
-
|
1454 |
|
1455 |
|
1456 |
-
|
1457 |
-
|
1458 |
-
|
1459 |
-
|
1460 |
-
|
1461 |
-
|
1462 |
-
|
1463 |
-
|
1464 |
|
1465 |
|
1466 |
-
|
1467 |
-
|
1468 |
-
|
1469 |
-
|
1470 |
-
|
1471 |
|
1472 |
|
1473 |
-
|
1474 |
-
|
1475 |
-
|
1476 |
-
|
1477 |
-
|
1478 |
-
|
1479 |
|
1480 |
|
1481 |
-
|
1482 |
-
|
1483 |
-
|
1484 |
-
|
1485 |
-
|
1486 |
-
|
1487 |
-
|
1488 |
-
|
1489 |
-
|
1490 |
-
|
1491 |
-
|
1492 |
-
|
1493 |
-
|
1494 |
-
|
1495 |
|
1496 |
-
|
1497 |
|
1498 |
|
1499 |
/////////////////////////////////////////////////
|
1500 |
|
1501 |
-
|
1502 |
-
|
1503 |
-
|
1504 |
-
|
1505 |
-
|
1506 |
-
|
1507 |
-
|
1508 |
-
|
1509 |
-
|
1510 |
-
|
1511 |
-
|
1512 |
-
|
1513 |
-
|
1514 |
-
|
1515 |
-
|
1516 |
|
1517 |
|
1518 |
-
|
1519 |
-
|
1520 |
-
|
1521 |
-
|
1522 |
-
|
1523 |
-
|
1524 |
-
|
1525 |
-
|
1526 |
-
|
1527 |
-
|
1528 |
-
|
1529 |
-
|
1530 |
-
|
1531 |
-
|
1532 |
-
|
1533 |
-
|
1534 |
-
|
1535 |
-
|
1536 |
-
|
1537 |
-
|
1538 |
-
|
1539 |
-
|
1540 |
-
|
1541 |
-
|
1542 |
-
|
1543 |
-
|
1544 |
-
}
|
1545 |
-
});
|
1546 |
-
return obj;
|
1547 |
}
|
|
|
|
|
|
|
1548 |
|
1549 |
-
|
1550 |
-
|
1551 |
-
|
1552 |
-
|
1553 |
-
|
1554 |
-
|
1555 |
-
|
1556 |
-
|
1557 |
-
|
1558 |
-
|
1559 |
-
|
1560 |
-
}
|
1561 |
-
});
|
1562 |
-
return parts.length ? parts.join('&') : '';
|
1563 |
}
|
|
|
|
|
|
|
1564 |
|
1565 |
|
1566 |
-
|
1567 |
-
|
1568 |
-
|
1569 |
-
|
1570 |
-
|
1571 |
-
|
1572 |
-
|
1573 |
-
|
1574 |
-
|
1575 |
-
|
1576 |
-
|
1577 |
-
|
1578 |
-
|
1579 |
-
|
1580 |
-
|
1581 |
-
|
1582 |
-
|
1583 |
|
1584 |
|
1585 |
-
|
1586 |
-
|
1587 |
-
|
1588 |
-
|
1589 |
-
|
1590 |
-
|
1591 |
-
|
1592 |
-
|
1593 |
-
|
1594 |
-
|
1595 |
-
|
1596 |
-
|
1597 |
-
|
1598 |
-
|
1599 |
-
|
1600 |
-
|
1601 |
-
|
1602 |
-
|
1603 |
-
|
1604 |
-
|
1605 |
-
|
1606 |
-
|
1607 |
-
|
1608 |
-
|
1609 |
-
|
1610 |
-
|
1611 |
-
|
1612 |
-
|
1613 |
-
|
1614 |
-
}
|
1615 |
-
}
|
1616 |
-
return null;
|
1617 |
}
|
|
|
|
|
|
|
1618 |
|
1619 |
-
|
1620 |
-
|
1621 |
|
1622 |
-
|
1623 |
-
|
1624 |
-
|
1625 |
-
|
1626 |
-
|
1627 |
|
1628 |
-
|
1629 |
-
|
1630 |
-
|
1631 |
-
|
1632 |
|
1633 |
-
|
1634 |
-
|
1635 |
|
1636 |
-
|
1637 |
-
|
1638 |
-
|
1639 |
-
|
1640 |
-
|
1641 |
-
|
1642 |
-
|
1643 |
|
1644 |
-
|
1645 |
-
|
1646 |
|
1647 |
-
|
1648 |
-
|
1649 |
-
|
1650 |
-
|
1651 |
-
|
1652 |
-
|
1653 |
-
|
1654 |
-
|
1655 |
-
|
1656 |
-
|
1657 |
-
|
1658 |
-
|
1659 |
-
|
1660 |
-
|
1661 |
-
|
1662 |
-
|
1663 |
-
|
1664 |
-
}
|
1665 |
-
});
|
1666 |
}
|
|
|
|
|
1667 |
|
1668 |
// Cached as it has to run during loading so that document.currentScript is available.
|
1669 |
-
|
1670 |
|
1671 |
-
|
1672 |
-
|
1673 |
-
|
1674 |
-
|
1675 |
-
|
1676 |
-
|
1677 |
-
|
1678 |
-
|
1679 |
-
|
1680 |
-
|
1681 |
-
|
1682 |
-
|
1683 |
-
|
1684 |
-
|
1685 |
-
|
1686 |
-
|
1687 |
-
|
1688 |
-
|
1689 |
-
|
1690 |
-
|
1691 |
-
|
1692 |
-
|
1693 |
-
|
1694 |
-
|
1695 |
-
|
1696 |
-
|
1697 |
-
|
1698 |
-
|
1699 |
-
|
1700 |
-
|
1701 |
-
|
1702 |
-
|
1703 |
-
|
1704 |
-
|
1705 |
-
|
1706 |
-
|
1707 |
-
|
1708 |
-
|
1709 |
-
|
1710 |
-
|
1711 |
-
|
1712 |
-
|
1713 |
-
|
1714 |
-
|
1715 |
-
|
1716 |
-
|
1717 |
-
|
1718 |
-
|
1719 |
-
|
1720 |
-
|
1721 |
I can add: {{a}} + {{b}} = {{ a+b }}
|
1722 |
-
|
1723 |
-
|
1724 |
-
|
1725 |
-
|
1726 |
$scope.a = 1;
|
1727 |
$scope.b = 2;
|
1728 |
});
|
1729 |
-
|
1730 |
-
|
1731 |
-
|
1732 |
-
|
1733 |
-
|
1734 |
-
|
1735 |
-
|
1736 |
-
|
1737 |
-
|
1738 |
-
|
1739 |
-
|
1740 |
-
|
1741 |
-
|
1742 |
-
|
1743 |
-
|
1744 |
-
|
1745 |
-
|
1746 |
-
|
1747 |
-
|
1748 |
-
|
1749 |
-
|
1750 |
-
|
1751 |
-
|
1752 |
-
|
1753 |
-
|
1754 |
-
|
1755 |
-
|
1756 |
-
|
1757 |
-
|
1758 |
-
|
1759 |
-
|
1760 |
-
|
1761 |
-
|
1762 |
-
|
1763 |
-
|
1764 |
-
|
1765 |
-
|
1766 |
-
|
1767 |
-
|
1768 |
-
|
1769 |
-
|
1770 |
-
|
1771 |
-
|
1772 |
-
|
1773 |
// BadController will fail to instantiate, due to relying on automatic function annotation,
|
1774 |
// rather than an explicit annotation
|
1775 |
.controller('BadController', function($scope) {
|
@@ -1787,671 +1787,671 @@
|
|
1787 |
$scope.name = 'World';
|
1788 |
}
|
1789 |
GoodController2.$inject = ['$scope'];
|
1790 |
-
|
1791 |
-
|
1792 |
-
|
1793 |
margin-bottom: 1em;
|
1794 |
-webkit-border-radius: 4px;
|
1795 |
border-radius: 4px;
|
1796 |
border: 1px solid;
|
1797 |
padding: .5em;
|
1798 |
}
|
1799 |
-
|
1800 |
border-color: #d6e9c6;
|
1801 |
background-color: #dff0d8;
|
1802 |
color: #3c763d;
|
1803 |
}
|
1804 |
-
|
1805 |
border-color: #ebccd1;
|
1806 |
background-color: #f2dede;
|
1807 |
color: #a94442;
|
1808 |
margin-bottom: 0;
|
1809 |
}
|
1810 |
-
|
1811 |
-
|
1812 |
-
|
1813 |
-
|
1814 |
-
|
1815 |
-
|
1816 |
-
|
1817 |
-
|
1818 |
-
// The element `element` has priority over any other element.
|
1819 |
-
forEach(ngAttrPrefixes, function(prefix) {
|
1820 |
-
var name = prefix + 'app';
|
1821 |
-
|
1822 |
-
if (!appElement && element.hasAttribute && element.hasAttribute(name)) {
|
1823 |
-
appElement = element;
|
1824 |
-
module = element.getAttribute(name);
|
1825 |
-
}
|
1826 |
-
});
|
1827 |
-
forEach(ngAttrPrefixes, function(prefix) {
|
1828 |
-
var name = prefix + 'app';
|
1829 |
-
var candidate;
|
1830 |
|
1831 |
-
|
1832 |
-
|
1833 |
-
|
1834 |
-
|
1835 |
-
|
1836 |
-
|
1837 |
-
|
1838 |
-
window.console.error('AngularJS: disabling automatic bootstrap. <script> protocol indicates ' +
|
1839 |
-
'an extension, document.location.href does not match.');
|
1840 |
-
return;
|
1841 |
-
}
|
1842 |
-
config.strictDi = getNgAttribute(appElement, 'strict-di') !== null;
|
1843 |
-
bootstrap(appElement, module ? [module] : [], config);
|
1844 |
-
}
|
1845 |
}
|
|
|
|
|
|
|
|
|
1846 |
|
1847 |
-
|
1848 |
-
|
1849 |
-
|
1850 |
-
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
|
1857 |
-
|
1858 |
-
|
1859 |
-
|
1860 |
-
|
1861 |
-
|
1862 |
-
|
1863 |
-
|
1864 |
-
|
1865 |
-
|
1866 |
-
|
1867 |
-
|
1868 |
-
|
1869 |
-
|
1870 |
-
|
1871 |
-
|
1872 |
-
|
1873 |
-
|
1874 |
-
|
1875 |
-
|
1876 |
-
|
1877 |
-
|
1878 |
-
|
1879 |
-
|
1880 |
-
|
1881 |
-
|
1882 |
-
|
1883 |
-
|
1884 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1885 |
* $scope.greeting = 'Welcome!';
|
1886 |
* });
|
1887 |
-
|
1888 |
-
|
1889 |
-
|
1890 |
-
|
1891 |
-
|
1892 |
-
|
1893 |
-
|
1894 |
-
|
1895 |
-
|
1896 |
-
|
1897 |
-
|
1898 |
-
|
1899 |
-
|
1900 |
-
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
|
1909 |
-
|
1910 |
-
|
1911 |
-
|
1912 |
-
|
1913 |
-
|
1914 |
-
|
1915 |
-
|
1916 |
-
|
1917 |
-
|
1918 |
-
|
1919 |
-
|
1920 |
-
|
1921 |
-
|
1922 |
-
|
|
|
|
|
|
|
|
|
|
|
1923 |
|
1924 |
-
|
1925 |
-
|
1926 |
-
|
1927 |
-
|
|
|
|
|
1928 |
|
1929 |
-
|
1930 |
-
|
1931 |
-
|
1932 |
-
|
1933 |
-
|
1934 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1935 |
|
1936 |
-
|
1937 |
-
|
1938 |
-
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
|
1939 |
-
function bootstrapApply(scope, element, compile, injector) {
|
1940 |
-
scope.$apply(function() {
|
1941 |
-
element.data('$injector', injector);
|
1942 |
-
compile(element)(scope);
|
1943 |
-
});
|
1944 |
-
}]
|
1945 |
-
);
|
1946 |
-
return injector;
|
1947 |
-
};
|
1948 |
|
1949 |
-
|
1950 |
-
|
|
|
|
|
1951 |
|
1952 |
-
|
1953 |
-
|
1954 |
-
|
1955 |
-
}
|
1956 |
|
1957 |
-
|
1958 |
-
|
1959 |
-
|
|
|
|
|
|
|
|
|
1960 |
|
1961 |
-
|
1962 |
-
|
1963 |
-
|
1964 |
-
|
1965 |
-
});
|
1966 |
-
return doBootstrap();
|
1967 |
-
};
|
1968 |
|
1969 |
-
|
1970 |
-
|
1971 |
-
|
1972 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1973 |
|
1974 |
-
|
1975 |
-
|
1976 |
-
|
1977 |
-
|
1978 |
-
|
1979 |
-
|
1980 |
-
|
1981 |
-
|
1982 |
-
|
1983 |
-
|
1984 |
-
|
1985 |
-
|
1986 |
-
|
1987 |
-
|
|
|
|
|
1988 |
|
1989 |
-
|
1990 |
-
|
1991 |
-
|
1992 |
-
|
1993 |
-
|
1994 |
-
|
1995 |
-
|
1996 |
-
*/
|
1997 |
-
function getTestability(rootElement) {
|
1998 |
-
var injector = angular.element(rootElement).injector();
|
1999 |
-
if (!injector) {
|
2000 |
-
throw ngMinErr('test',
|
2001 |
-
'no injector found for element argument to getTestability');
|
2002 |
-
}
|
2003 |
-
return injector.get('$$testability');
|
2004 |
-
}
|
2005 |
|
2006 |
-
|
2007 |
-
|
2008 |
-
|
2009 |
-
|
2010 |
-
|
2011 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2012 |
}
|
|
|
|
|
2013 |
|
2014 |
-
|
2015 |
-
function bindJQuery() {
|
2016 |
-
var originalCleanData;
|
2017 |
|
2018 |
-
|
2019 |
-
|
2020 |
-
|
2021 |
|
2022 |
-
|
2023 |
-
|
2024 |
-
|
2025 |
-
|
2026 |
-
|
2027 |
-
|
2028 |
-
|
2029 |
-
|
2030 |
-
|
2031 |
-
// versions. It will not work for sure with jQuery <1.7, though.
|
2032 |
-
if (jQuery && jQuery.fn.on) {
|
2033 |
-
jqLite = jQuery;
|
2034 |
-
extend(jQuery.fn, {
|
2035 |
-
scope: JQLitePrototype.scope,
|
2036 |
-
isolateScope: JQLitePrototype.isolateScope,
|
2037 |
-
controller: /** @type {?} */ (JQLitePrototype).controller,
|
2038 |
-
injector: JQLitePrototype.injector,
|
2039 |
-
inheritedData: JQLitePrototype.inheritedData
|
2040 |
-
});
|
2041 |
-
} else {
|
2042 |
-
jqLite = JQLite;
|
2043 |
-
}
|
2044 |
-
|
2045 |
-
// All nodes removed from the DOM via various jqLite/jQuery APIs like .remove()
|
2046 |
-
// are passed through jqLite/jQuery.cleanData. Monkey-patch this method to fire
|
2047 |
-
// the $destroy event on all removed nodes.
|
2048 |
-
originalCleanData = jqLite.cleanData;
|
2049 |
-
jqLite.cleanData = function(elems) {
|
2050 |
-
var events;
|
2051 |
-
for (var i = 0, elem; (elem = elems[i]) != null; i++) {
|
2052 |
-
events = (jqLite._data(elem) || {}).events;
|
2053 |
-
if (events && events.$destroy) {
|
2054 |
-
jqLite(elem).triggerHandler('$destroy');
|
2055 |
-
}
|
2056 |
-
}
|
2057 |
-
originalCleanData(elems);
|
2058 |
-
};
|
2059 |
|
2060 |
-
|
|
|
|
|
|
|
2061 |
|
2062 |
-
|
2063 |
-
|
2064 |
-
|
|
|
2065 |
|
2066 |
-
|
2067 |
-
|
2068 |
-
|
2069 |
-
|
2070 |
-
|
2071 |
-
|
2072 |
-
|
2073 |
-
|
2074 |
-
|
|
|
2075 |
|
2076 |
-
|
2077 |
-
|
2078 |
-
|
2079 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2080 |
|
2081 |
-
|
2082 |
-
|
2083 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2084 |
}
|
|
|
2085 |
|
2086 |
-
|
2087 |
-
|
2088 |
-
* @param {String} name the name to test
|
2089 |
-
* @param {String} context the context in which the name is used, such as module or directive
|
2090 |
-
*/
|
2091 |
-
function assertNotHasOwnProperty(name, context) {
|
2092 |
-
if (name === 'hasOwnProperty') {
|
2093 |
-
throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
|
2094 |
-
}
|
2095 |
-
}
|
2096 |
|
2097 |
-
/**
|
2098 |
-
* Return the value accessible from the object by path. Any undefined traversals are ignored
|
2099 |
-
* @param {Object} obj starting object
|
2100 |
-
* @param {String} path path to traverse
|
2101 |
-
* @param {boolean} [bindFnToScope=true]
|
2102 |
-
* @returns {Object} value as accessible by path
|
2103 |
-
*/
|
2104 |
-
//TODO(misko): this function needs to be removed
|
2105 |
-
function getter(obj, path, bindFnToScope) {
|
2106 |
-
if (!path) return obj;
|
2107 |
-
var keys = path.split('.');
|
2108 |
-
var key;
|
2109 |
-
var lastInstance = obj;
|
2110 |
-
var len = keys.length;
|
2111 |
-
|
2112 |
-
for (var i = 0; i < len; i++) {
|
2113 |
-
key = keys[i];
|
2114 |
-
if (obj) {
|
2115 |
-
obj = (lastInstance = obj)[key];
|
2116 |
-
}
|
2117 |
-
}
|
2118 |
-
if (!bindFnToScope && isFunction(obj)) {
|
2119 |
-
return bind(lastInstance, obj);
|
2120 |
-
}
|
2121 |
-
return obj;
|
2122 |
-
}
|
2123 |
|
2124 |
-
|
2125 |
-
|
2126 |
-
|
2127 |
-
|
2128 |
-
|
2129 |
-
|
2130 |
-
|
2131 |
-
|
2132 |
-
|
2133 |
-
|
2134 |
-
|
2135 |
-
|
2136 |
-
|
2137 |
-
|
2138 |
-
blockNodes = jqLite(slice.call(nodes, 0, i));
|
2139 |
-
}
|
2140 |
-
blockNodes.push(node);
|
2141 |
-
}
|
2142 |
-
}
|
2143 |
|
2144 |
-
|
2145 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2146 |
|
|
|
|
|
2147 |
|
2148 |
-
|
2149 |
-
|
2150 |
-
|
2151 |
-
|
2152 |
-
|
2153 |
-
|
2154 |
-
* - http://jsperf.com/proto-map-lookup/2
|
2155 |
-
* - http://jsperf.com/for-in-vs-object-keys2
|
2156 |
-
*
|
2157 |
-
* @returns {Object}
|
2158 |
-
*/
|
2159 |
-
function createMap() {
|
2160 |
-
return Object.create(null);
|
2161 |
-
}
|
2162 |
-
|
2163 |
-
function stringify(value) {
|
2164 |
-
if (value == null) { // null || undefined
|
2165 |
-
return '';
|
2166 |
-
}
|
2167 |
-
switch (typeof value) {
|
2168 |
-
case 'string':
|
2169 |
-
break;
|
2170 |
-
case 'number':
|
2171 |
-
value = '' + value;
|
2172 |
-
break;
|
2173 |
-
default:
|
2174 |
-
if (hasCustomToString(value) && !isArray(value) && !isDate(value)) {
|
2175 |
-
value = value.toString();
|
2176 |
-
} else {
|
2177 |
-
value = toJson(value);
|
2178 |
-
}
|
2179 |
-
}
|
2180 |
|
2181 |
-
|
2182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2183 |
|
2184 |
-
|
2185 |
-
|
2186 |
-
|
2187 |
-
|
2188 |
-
|
2189 |
-
|
|
|
|
|
2190 |
|
2191 |
/**
|
2192 |
-
* @ngdoc
|
2193 |
-
* @name angular.
|
2194 |
* @module ng
|
2195 |
* @description
|
2196 |
*
|
2197 |
-
*
|
2198 |
-
|
2199 |
-
|
2200 |
-
|
2201 |
-
|
2202 |
-
|
2203 |
-
|
2204 |
-
|
2205 |
-
|
2206 |
-
|
2207 |
-
|
2208 |
-
|
2209 |
-
|
2210 |
-
|
2211 |
-
|
2212 |
-
|
2213 |
-
|
2214 |
-
|
2215 |
-
|
2216 |
-
|
2217 |
-
|
2218 |
-
|
2219 |
-
|
2220 |
-
* @name angular.module
|
2221 |
-
* @module ng
|
2222 |
-
* @description
|
2223 |
-
*
|
2224 |
-
* The `angular.module` is a global place for creating, registering and retrieving AngularJS
|
2225 |
-
* modules.
|
2226 |
-
* All modules (AngularJS core or 3rd party) that should be available to an application must be
|
2227 |
-
* registered using this mechanism.
|
2228 |
-
*
|
2229 |
-
* Passing one argument retrieves an existing {@link angular.Module},
|
2230 |
-
* whereas passing more than one argument creates a new {@link angular.Module}
|
2231 |
-
*
|
2232 |
-
*
|
2233 |
-
* # Module
|
2234 |
-
*
|
2235 |
-
* A module is a collection of services, directives, controllers, filters, and configuration information.
|
2236 |
-
* `angular.module` is used to configure the {@link auto.$injector $injector}.
|
2237 |
-
*
|
2238 |
-
* ```js
|
2239 |
-
* // Create a new module
|
2240 |
-
* var myModule = angular.module('myModule', []);
|
2241 |
-
*
|
2242 |
-
* // register a new service
|
2243 |
-
* myModule.value('appName', 'MyCoolApp');
|
2244 |
-
*
|
2245 |
-
* // configure existing services inside initialization blocks.
|
2246 |
-
* myModule.config(['$locationProvider', function($locationProvider) {
|
2247 |
* // Configure existing providers
|
2248 |
* $locationProvider.hashPrefix('!');
|
2249 |
* }]);
|
2250 |
-
|
2251 |
-
|
2252 |
-
|
2253 |
-
|
2254 |
-
|
2255 |
-
|
2256 |
-
|
2257 |
-
|
2258 |
-
|
2259 |
-
|
2260 |
-
|
2261 |
-
|
2262 |
-
|
2263 |
-
|
2264 |
-
|
2265 |
-
|
2266 |
-
|
2267 |
-
|
2268 |
-
|
2269 |
-
|
2270 |
-
|
2271 |
-
var info = {};
|
2272 |
-
|
2273 |
-
var assertNotHasOwnProperty = function(name, context) {
|
2274 |
-
if (name === 'hasOwnProperty') {
|
2275 |
-
throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
|
2276 |
-
}
|
2277 |
-
};
|
2278 |
|
2279 |
-
|
2280 |
-
if (requires && modules.hasOwnProperty(name)) {
|
2281 |
-
modules[name] = null;
|
2282 |
-
}
|
2283 |
-
return ensure(modules, name, function() {
|
2284 |
-
if (!requires) {
|
2285 |
-
throw $injectorMinErr('nomod', 'Module \'{0}\' is not available! You either misspelled ' +
|
2286 |
-
'the module name or forgot to load it. If registering a module ensure that you ' +
|
2287 |
-
'specify the dependencies as the second argument.', name);
|
2288 |
-
}
|
2289 |
|
2290 |
-
|
2291 |
-
|
2292 |
-
|
2293 |
-
|
2294 |
-
|
2295 |
-
|
2296 |
-
|
2297 |
-
|
2298 |
-
|
2299 |
-
|
2300 |
-
|
2301 |
-
|
2302 |
-
|
2303 |
-
|
2304 |
-
|
2305 |
-
|
2306 |
-
|
2307 |
-
|
2308 |
-
|
2309 |
-
|
2310 |
-
|
2311 |
-
|
2312 |
-
|
2313 |
-
|
2314 |
-
|
2315 |
-
|
2316 |
-
|
2317 |
-
|
2318 |
-
|
2319 |
-
|
2320 |
-
|
2321 |
-
|
2322 |
-
|
2323 |
-
|
2324 |
-
|
2325 |
-
|
2326 |
-
|
2327 |
-
|
2328 |
-
|
2329 |
-
|
2330 |
-
|
2331 |
-
|
2332 |
-
|
2333 |
-
|
2334 |
-
|
2335 |
-
|
2336 |
-
|
2337 |
-
|
2338 |
-
|
2339 |
-
|
2340 |
-
|
2341 |
-
|
2342 |
-
|
2343 |
-
|
2344 |
-
|
2345 |
-
|
2346 |
-
|
2347 |
-
|
2348 |
-
|
2349 |
-
|
2350 |
-
|
2351 |
-
|
2352 |
-
|
2353 |
-
|
2354 |
-
|
2355 |
-
|
2356 |
-
|
2357 |
-
|
2358 |
-
|
2359 |
-
|
2360 |
-
|
2361 |
-
|
2362 |
-
|
2363 |
-
|
2364 |
-
|
2365 |
-
|
2366 |
-
|
2367 |
-
|
2368 |
-
|
2369 |
-
|
2370 |
-
|
2371 |
-
|
2372 |
-
|
2373 |
-
|
2374 |
-
|
2375 |
-
|
2376 |
-
|
2377 |
-
|
2378 |
-
|
2379 |
-
|
2380 |
-
|
2381 |
-
|
2382 |
-
|
2383 |
-
|
2384 |
-
|
2385 |
-
|
2386 |
-
|
2387 |
-
|
2388 |
-
|
2389 |
-
|
2390 |
-
|
2391 |
-
|
2392 |
-
|
2393 |
-
|
2394 |
-
|
2395 |
-
|
2396 |
-
|
2397 |
-
|
2398 |
-
|
2399 |
-
|
2400 |
-
|
2401 |
-
|
2402 |
-
|
2403 |
-
|
2404 |
-
|
2405 |
-
|
2406 |
-
|
2407 |
-
|
2408 |
-
|
2409 |
-
|
2410 |
-
|
2411 |
-
|
2412 |
-
|
2413 |
-
|
2414 |
-
|
2415 |
-
|
2416 |
-
|
2417 |
-
|
2418 |
-
|
2419 |
-
|
2420 |
-
|
2421 |
-
|
2422 |
-
|
2423 |
-
|
2424 |
-
|
2425 |
-
|
2426 |
-
|
2427 |
-
|
2428 |
-
|
2429 |
-
|
2430 |
-
|
2431 |
-
|
2432 |
-
|
2433 |
-
|
2434 |
-
|
2435 |
-
|
2436 |
-
|
2437 |
-
|
2438 |
-
|
2439 |
-
|
2440 |
-
|
2441 |
-
|
2442 |
-
|
2443 |
-
|
2444 |
-
|
2445 |
-
|
2446 |
-
|
2447 |
-
|
2448 |
-
|
2449 |
-
|
2450 |
-
|
2451 |
-
|
2452 |
-
|
2453 |
-
|
2454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2455 |
* return {
|
2456 |
* eventName : function(element, done) {
|
2457 |
* //code to run the animation
|
@@ -2462,208 +2462,208 @@
|
|
2462 |
* }
|
2463 |
* }
|
2464 |
* })
|
2465 |
-
|
2466 |
-
|
2467 |
-
|
2468 |
-
|
2469 |
-
|
2470 |
-
|
2471 |
-
|
2472 |
-
|
2473 |
-
|
2474 |
-
|
2475 |
-
|
2476 |
-
|
2477 |
-
|
2478 |
-
|
2479 |
-
|
2480 |
-
|
2481 |
-
|
2482 |
-
|
2483 |
-
|
2484 |
-
|
2485 |
-
|
2486 |
-
|
2487 |
-
|
2488 |
-
|
2489 |
-
|
2490 |
-
|
2491 |
-
|
2492 |
-
|
2493 |
-
|
2494 |
-
|
2495 |
-
|
2496 |
-
|
2497 |
-
|
2498 |
-
|
2499 |
-
|
2500 |
-
|
2501 |
-
|
2502 |
-
|
2503 |
-
|
2504 |
-
|
2505 |
-
|
2506 |
-
|
2507 |
-
|
2508 |
-
|
2509 |
-
|
2510 |
-
|
2511 |
-
|
2512 |
-
|
2513 |
-
|
2514 |
-
|
2515 |
-
|
2516 |
-
|
2517 |
-
|
2518 |
-
|
2519 |
-
|
2520 |
-
|
2521 |
-
|
2522 |
-
|
2523 |
-
|
2524 |
-
|
2525 |
-
|
2526 |
-
|
2527 |
-
|
2528 |
-
|
2529 |
-
|
2530 |
-
|
2531 |
-
|
2532 |
-
|
2533 |
-
|
2534 |
-
|
2535 |
-
|
2536 |
-
|
2537 |
-
|
2538 |
-
|
2539 |
-
|
2540 |
-
|
2541 |
-
|
2542 |
-
|
2543 |
-
|
2544 |
-
|
2545 |
-
|
2546 |
-
|
2547 |
-
|
2548 |
-
|
2549 |
-
|
2550 |
-
|
2551 |
-
|
2552 |
-
|
2553 |
-
|
2554 |
-
|
2555 |
-
|
2556 |
-
|
2557 |
-
|
2558 |
-
|
2559 |
-
|
2560 |
-
|
2561 |
-
|
2562 |
-
|
2563 |
|
2564 |
-
|
2565 |
-
|
2566 |
-
|
2567 |
|
2568 |
-
|
2569 |
|
2570 |
-
|
2571 |
-
|
2572 |
-
|
2573 |
-
|
2574 |
-
|
2575 |
-
|
2576 |
-
|
2577 |
-
|
2578 |
-
|
2579 |
-
|
2580 |
-
|
2581 |
-
|
2582 |
-
|
2583 |
|
2584 |
-
|
2585 |
-
|
2586 |
-
|
2587 |
-
|
2588 |
-
|
2589 |
-
|
2590 |
-
|
2591 |
-
|
2592 |
-
|
2593 |
-
|
2594 |
-
|
2595 |
-
|
2596 |
-
|
2597 |
-
|
2598 |
-
|
2599 |
-
|
2600 |
|
2601 |
-
|
2602 |
|
2603 |
-
|
2604 |
|
2605 |
-
|
2606 |
-
|
2607 |
-
|
2608 |
-
|
2609 |
-
|
2610 |
-
|
2611 |
-
|
2612 |
-
|
2613 |
|
2614 |
-
|
2615 |
-
|
2616 |
-
|
2617 |
-
|
2618 |
-
|
2619 |
|
2620 |
-
|
2621 |
-
|
2622 |
-
|
2623 |
-
|
2624 |
-
}
|
2625 |
-
}
|
2626 |
-
|
2627 |
-
return dst || src;
|
2628 |
}
|
|
|
2629 |
|
2630 |
-
|
|
|
2631 |
|
2632 |
-
|
2633 |
-
var seen = [];
|
2634 |
|
2635 |
-
|
2636 |
-
|
2637 |
-
// based on this specific depth and then stringify it.
|
2638 |
-
if (isValidObjectMaxDepth(maxDepth)) {
|
2639 |
-
// This file is also included in `angular-loader`, so `copy()` might not always be available in
|
2640 |
-
// the closure. Therefore, it is lazily retrieved as `angular.copy()` when needed.
|
2641 |
-
obj = angular.copy(obj, null, maxDepth);
|
2642 |
-
}
|
2643 |
-
return JSON.stringify(obj, function(key, val) {
|
2644 |
-
val = toJsonReplacer(key, val);
|
2645 |
-
if (isObject(val)) {
|
2646 |
|
2647 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2648 |
|
2649 |
-
|
2650 |
-
}
|
2651 |
-
return val;
|
2652 |
-
});
|
2653 |
-
}
|
2654 |
|
2655 |
-
|
2656 |
-
if (typeof obj === 'function') {
|
2657 |
-
return obj.toString().replace(/ \{[\s\S]*$/, '');
|
2658 |
-
} else if (isUndefined(obj)) {
|
2659 |
-
return 'undefined';
|
2660 |
-
} else if (typeof obj !== 'string') {
|
2661 |
-
return serializeObject(obj, maxDepth);
|
2662 |
-
}
|
2663 |
-
return obj;
|
2664 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2665 |
|
2666 |
-
|
2667 |
version: true,
|
2668 |
|
2669 |
$CompileProvider,
|
@@ -2764,182 +2764,182 @@
|
|
2764 |
*/
|
2765 |
|
2766 |
|
2767 |
-
|
2768 |
-
|
2769 |
-
|
2770 |
-
|
2771 |
-
|
2772 |
-
|
2773 |
-
|
2774 |
-
|
2775 |
-
|
2776 |
-
|
2777 |
-
|
2778 |
-
|
2779 |
-
|
2780 |
-
|
2781 |
-
|
2782 |
-
|
2783 |
-
|
2784 |
-
|
2785 |
-
|
2786 |
-
|
2787 |
-
|
2788 |
-
|
2789 |
-
|
2790 |
-
|
2791 |
-
|
2792 |
-
|
2793 |
-
|
2794 |
-
|
2795 |
-
|
2796 |
-
|
2797 |
-
|
2798 |
-
|
2799 |
-
|
2800 |
-
|
2801 |
-
|
2802 |
-
|
2803 |
-
|
2804 |
-
|
2805 |
-
|
2806 |
-
|
2807 |
-
|
2808 |
-
|
2809 |
-
|
2810 |
-
|
2811 |
-
|
2812 |
-
|
2813 |
-
|
2814 |
-
|
2815 |
-
|
2816 |
-
|
2817 |
-
|
2818 |
-
|
2819 |
-
|
2820 |
-
|
2821 |
-
|
2822 |
-
|
2823 |
-
|
2824 |
-
|
2825 |
-
|
2826 |
-
|
2827 |
-
|
2828 |
-
|
2829 |
-
|
2830 |
|
2831 |
-
|
2832 |
|
2833 |
-
|
2834 |
-
|
2835 |
-
|
2836 |
-
|
2837 |
-
|
2838 |
-
|
2839 |
-
|
2840 |
-
|
2841 |
-
|
2842 |
-
|
2843 |
-
|
2844 |
-
|
2845 |
-
|
2846 |
-
|
2847 |
-
|
2848 |
-
|
2849 |
-
|
2850 |
-
|
2851 |
-
|
2852 |
-
|
2853 |
-
|
2854 |
-
|
2855 |
-
|
2856 |
-
|
2857 |
-
|
2858 |
-
|
2859 |
-
|
2860 |
-
|
2861 |
-
|
2862 |
-
|
2863 |
-
|
2864 |
-
|
2865 |
-
|
2866 |
-
|
2867 |
-
|
2868 |
-
|
2869 |
-
|
2870 |
-
|
2871 |
-
|
2872 |
-
|
2873 |
-
|
2874 |
-
|
2875 |
-
|
2876 |
-
|
2877 |
-
|
2878 |
-
|
2879 |
-
|
2880 |
-
|
2881 |
-
|
2882 |
-
|
2883 |
-
|
2884 |
-
|
2885 |
-
|
2886 |
-
|
2887 |
-
|
2888 |
-
|
2889 |
-
|
2890 |
-
|
2891 |
-
|
2892 |
-
|
2893 |
-
|
2894 |
-
|
2895 |
-
|
2896 |
-
|
2897 |
-
|
2898 |
-
|
2899 |
-
|
2900 |
-
|
2901 |
-
|
2902 |
-
|
2903 |
-
|
2904 |
-
|
2905 |
-
|
2906 |
-
|
2907 |
-
|
2908 |
-
|
2909 |
-
|
2910 |
-
|
2911 |
-
|
2912 |
-
|
2913 |
-
|
2914 |
-
|
2915 |
-
|
2916 |
-
|
2917 |
-
|
2918 |
-
|
2919 |
-
|
2920 |
-
|
2921 |
-
|
2922 |
-
|
2923 |
-
|
2924 |
-
|
2925 |
-
|
2926 |
-
|
2927 |
-
|
2928 |
-
|
2929 |
-
|
2930 |
-
|
2931 |
-
|
2932 |
-
|
2933 |
-
|
2934 |
-
|
2935 |
-
|
2936 |
-
|
2937 |
-
}
|
2938 |
-
])
|
2939 |
-
.info({ angularVersion: '1.7.6' });
|
2940 |
}
|
|
|
|
|
|
|
2941 |
|
2942 |
-
|
2943 |
* Any commits to this file should be reviewed with security in mind. *
|
2944 |
* Changes to this file can potentially create security vulnerabilities. *
|
2945 |
* An approval from 2 Core members with history of modifying *
|
@@ -2950,7 +2950,7 @@
|
|
2950 |
* Or gives undesired access to variables likes document or window? *
|
2951 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2952 |
|
2953 |
-
|
2954 |
JQLitePrototype: true,
|
2955 |
BOOLEAN_ATTR: true,
|
2956 |
ALIASED_ATTR: true
|
@@ -2960,1682 +2960,1682 @@
|
|
2960 |
//JQLite
|
2961 |
//////////////////////////////////
|
2962 |
|
2963 |
-
|
2964 |
-
|
2965 |
-
|
2966 |
-
|
2967 |
-
|
2968 |
-
|
2969 |
-
|
2970 |
-
|
2971 |
-
|
2972 |
-
|
2973 |
-
|
2974 |
-
|
2975 |
-
|
2976 |
-
|
2977 |
-
|
2978 |
-
|
2979 |
-
|
2980 |
-
|
2981 |
-
|
2982 |
-
|
2983 |
-
|
2984 |
-
|
2985 |
-
|
2986 |
-
|
2987 |
-
|
2988 |
-
|
2989 |
-
|
2990 |
-
|
2991 |
-
|
2992 |
-
|
2993 |
-
|
2994 |
-
|
2995 |
-
|
2996 |
-
|
2997 |
-
|
2998 |
-
|
2999 |
-
|
3000 |
-
|
3001 |
-
|
3002 |
-
|
3003 |
-
|
3004 |
-
|
3005 |
-
|
3006 |
-
|
3007 |
-
|
3008 |
-
|
3009 |
-
|
3010 |
-
|
3011 |
-
|
3012 |
-
|
3013 |
-
|
3014 |
-
|
3015 |
-
|
3016 |
-
|
3017 |
-
|
3018 |
-
|
3019 |
-
|
3020 |
-
|
3021 |
-
|
3022 |
-
|
3023 |
-
|
3024 |
-
|
3025 |
-
|
3026 |
-
|
3027 |
-
|
3028 |
-
|
3029 |
-
|
3030 |
-
|
3031 |
-
|
3032 |
-
|
3033 |
-
|
3034 |
-
|
3035 |
-
|
3036 |
-
|
3037 |
-
|
3038 |
-
|
3039 |
-
|
3040 |
-
|
3041 |
-
|
3042 |
-
|
3043 |
-
|
3044 |
-
|
3045 |
-
|
3046 |
-
|
3047 |
-
|
3048 |
-
|
3049 |
-
|
3050 |
-
|
3051 |
-
|
3052 |
-
|
3053 |
-
|
3054 |
-
|
3055 |
-
|
3056 |
-
|
3057 |
-
|
3058 |
-
|
3059 |
-
|
3060 |
-
|
3061 |
-
|
3062 |
|
3063 |
-
|
3064 |
|
3065 |
-
|
3066 |
-
|
3067 |
|
3068 |
-
|
3069 |
* !!! This is an undocumented "private" function !!!
|
3070 |
*/
|
3071 |
-
|
3072 |
-
|
3073 |
-
|
3074 |
-
|
3075 |
-
|
3076 |
-
function jqNextId() { return ++jqId; }
|
3077 |
-
|
3078 |
-
|
3079 |
-
var DASH_LOWERCASE_REGEXP = /-([a-z])/g;
|
3080 |
-
var MS_HACK_REGEXP = /^-ms-/;
|
3081 |
-
var MOUSE_EVENT_MAP = { mouseleave: 'mouseout', mouseenter: 'mouseover' };
|
3082 |
-
var jqLiteMinErr = minErr('jqLite');
|
3083 |
-
|
3084 |
-
/**
|
3085 |
-
* Converts kebab-case to camelCase.
|
3086 |
-
* There is also a special case for the ms prefix starting with a lowercase letter.
|
3087 |
-
* @param name Name to normalize
|
3088 |
-
*/
|
3089 |
-
function cssKebabToCamel(name) {
|
3090 |
-
return kebabToCamel(name.replace(MS_HACK_REGEXP, 'ms-'));
|
3091 |
-
}
|
3092 |
|
3093 |
-
|
3094 |
-
return letter.toUpperCase();
|
3095 |
-
}
|
3096 |
|
3097 |
-
/**
|
3098 |
-
* Converts kebab-case to camelCase.
|
3099 |
-
* @param name Name to normalize
|
3100 |
-
*/
|
3101 |
-
function kebabToCamel(name) {
|
3102 |
-
return name
|
3103 |
-
.replace(DASH_LOWERCASE_REGEXP, fnCamelCaseReplace);
|
3104 |
-
}
|
3105 |
|
3106 |
-
|
3107 |
-
|
3108 |
-
|
3109 |
-
|
3110 |
|
3111 |
-
|
3112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
3113 |
|
3114 |
-
|
3115 |
-
|
3116 |
-
|
3117 |
-
'td': [3, '<table><tbody><tr>', '</tr></tbody></table>'],
|
3118 |
-
'_default': [0, '', '']
|
3119 |
-
};
|
3120 |
|
3121 |
-
|
3122 |
-
|
3123 |
-
|
|
|
|
|
|
|
|
|
|
|
3124 |
|
|
|
|
|
|
|
|
|
3125 |
|
3126 |
-
|
3127 |
-
|
3128 |
-
}
|
3129 |
|
3130 |
-
|
3131 |
-
|
3132 |
-
|
3133 |
-
|
3134 |
-
|
3135 |
-
|
3136 |
|
3137 |
-
|
3138 |
-
|
3139 |
-
|
3140 |
-
}
|
3141 |
-
return false;
|
3142 |
-
}
|
3143 |
|
3144 |
-
function jqLiteBuildFragment(html, context) {
|
3145 |
-
var tmp, tag, wrap,
|
3146 |
-
fragment = context.createDocumentFragment(),
|
3147 |
-
nodes = [], i;
|
3148 |
|
3149 |
-
|
3150 |
-
|
3151 |
-
|
3152 |
-
} else {
|
3153 |
-
// Convert html into DOM nodes
|
3154 |
-
tmp = fragment.appendChild(context.createElement('div'));
|
3155 |
-
tag = (TAG_NAME_REGEXP.exec(html) || ['', ''])[1].toLowerCase();
|
3156 |
-
wrap = wrapMap[tag] || wrapMap._default;
|
3157 |
-
tmp.innerHTML = wrap[1] + html.replace(XHTML_TAG_REGEXP, '<$1></$2>') + wrap[2];
|
3158 |
-
|
3159 |
-
// Descend through wrappers to the right content
|
3160 |
-
i = wrap[0];
|
3161 |
-
while (i--) {
|
3162 |
-
tmp = tmp.lastChild;
|
3163 |
-
}
|
3164 |
|
3165 |
-
|
|
|
|
|
|
|
|
|
|
|
3166 |
|
3167 |
-
|
3168 |
-
|
3169 |
-
|
|
|
|
|
|
|
3170 |
|
3171 |
-
|
3172 |
-
|
3173 |
-
|
3174 |
-
|
3175 |
-
|
3176 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3177 |
|
3178 |
-
|
3179 |
-
|
3180 |
|
3181 |
-
|
3182 |
-
|
3183 |
-
|
3184 |
|
3185 |
-
|
3186 |
-
|
3187 |
-
|
3188 |
|
3189 |
-
|
3190 |
-
|
3191 |
-
|
3192 |
|
3193 |
-
|
3194 |
-
|
3195 |
|
3196 |
-
|
3197 |
-
|
3198 |
|
3199 |
-
|
3200 |
-
|
3201 |
-
|
3202 |
|
3203 |
-
|
3204 |
-
|
3205 |
|
3206 |
|
3207 |
// IE9-11 has no method "contains" in SVG element and in Node.prototype. Bug #10259.
|
3208 |
-
|
3209 |
-
|
3210 |
-
|
3211 |
-
|
3212 |
|
3213 |
/////////////////////////////////////////////
|
3214 |
-
|
3215 |
-
|
3216 |
-
|
3217 |
-
|
3218 |
-
|
3219 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3220 |
|
3221 |
-
|
3222 |
-
|
3223 |
-
|
3224 |
-
}
|
3225 |
-
if (!(this instanceof JQLite)) {
|
3226 |
-
if (argIsString && element.charAt(0) !== '<') {
|
3227 |
-
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
|
3228 |
-
}
|
3229 |
-
return new JQLite(element);
|
3230 |
-
}
|
3231 |
|
3232 |
-
|
3233 |
-
|
3234 |
-
} else if (isFunction(element)) {
|
3235 |
-
jqLiteReady(element);
|
3236 |
-
} else {
|
3237 |
-
jqLiteAddNodes(this, element);
|
3238 |
-
}
|
3239 |
-
}
|
3240 |
|
3241 |
-
|
3242 |
-
|
3243 |
-
|
|
|
3244 |
|
3245 |
-
|
3246 |
-
|
3247 |
|
3248 |
-
|
3249 |
-
|
3250 |
-
|
3251 |
-
|
|
|
3252 |
|
3253 |
-
|
3254 |
-
|
|
|
3255 |
|
3256 |
-
|
3257 |
-
|
3258 |
-
}
|
3259 |
-
return true;
|
3260 |
-
}
|
3261 |
|
3262 |
-
|
3263 |
-
|
3264 |
-
|
|
|
|
|
3265 |
|
3266 |
-
|
3267 |
-
|
3268 |
|
3269 |
-
|
3270 |
-
|
3271 |
-
|
3272 |
-
}
|
3273 |
-
}
|
3274 |
|
3275 |
-
|
3276 |
-
if (isDefined(unsupported)) throw jqLiteMinErr('offargs', 'jqLite#off() does not support the `selector` argument');
|
3277 |
|
3278 |
-
|
3279 |
-
|
3280 |
-
|
|
|
|
|
|
|
|
|
|
|
3281 |
|
3282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3283 |
|
3284 |
-
|
3285 |
-
|
3286 |
-
|
3287 |
-
|
3288 |
-
|
3289 |
-
|
3290 |
-
|
3291 |
-
} else {
|
3292 |
|
3293 |
-
|
3294 |
-
|
3295 |
-
if (isDefined(fn)) {
|
3296 |
-
arrayRemove(listenerFns || [], fn);
|
3297 |
-
}
|
3298 |
-
if (!(isDefined(fn) && listenerFns && listenerFns.length > 0)) {
|
3299 |
-
element.removeEventListener(type, handle);
|
3300 |
-
delete events[type];
|
3301 |
-
}
|
3302 |
-
};
|
3303 |
|
3304 |
-
|
3305 |
-
|
3306 |
-
|
3307 |
-
removeHandler(MOUSE_EVENT_MAP[type]);
|
3308 |
-
}
|
3309 |
-
});
|
3310 |
-
}
|
3311 |
|
3312 |
-
|
|
|
|
|
|
|
|
|
3313 |
}
|
3314 |
|
3315 |
-
|
3316 |
-
|
3317 |
-
|
3318 |
-
|
3319 |
-
if (expandoStore) {
|
3320 |
-
if (name) {
|
3321 |
-
delete expandoStore.data[name];
|
3322 |
-
} else {
|
3323 |
-
expandoStore.data = {};
|
3324 |
-
}
|
3325 |
-
|
3326 |
-
removeIfEmptyData(element);
|
3327 |
-
}
|
3328 |
-
}
|
3329 |
|
3330 |
|
3331 |
-
|
3332 |
-
|
3333 |
-
|
3334 |
|
3335 |
-
|
3336 |
-
|
3337 |
-
|
3338 |
-
|
3339 |
|
3340 |
-
|
3341 |
-
|
3342 |
|
3343 |
|
3344 |
-
|
3345 |
-
|
3346 |
-
|
3347 |
|
3348 |
-
|
3349 |
-
|
3350 |
-
|
3351 |
-
|
3352 |
-
|
3353 |
|
3354 |
-
|
3355 |
-
|
3356 |
-
|
3357 |
-
|
3358 |
-
|
3359 |
-
|
3360 |
-
|
3361 |
-
|
3362 |
-
|
3363 |
-
|
3364 |
-
|
3365 |
-
|
3366 |
-
|
3367 |
-
}
|
3368 |
-
}
|
3369 |
-
}
|
3370 |
}
|
|
|
3371 |
}
|
|
|
|
|
3372 |
|
3373 |
-
|
3374 |
-
|
3375 |
-
|
3376 |
-
|
3377 |
-
|
3378 |
|
3379 |
-
|
3380 |
-
|
3381 |
-
|
3382 |
-
|
3383 |
-
|
3384 |
|
3385 |
-
|
3386 |
-
|
3387 |
-
|
3388 |
-
|
3389 |
|
3390 |
-
|
3391 |
-
|
3392 |
-
}
|
3393 |
-
}
|
3394 |
}
|
|
|
|
|
3395 |
|
3396 |
-
|
3397 |
-
|
3398 |
-
|
3399 |
-
|
3400 |
-
|
3401 |
|
3402 |
-
|
3403 |
-
|
3404 |
-
|
3405 |
-
|
3406 |
-
|
3407 |
-
|
3408 |
|
3409 |
-
|
3410 |
-
|
3411 |
-
}
|
3412 |
-
}
|
3413 |
}
|
|
|
|
|
3414 |
|
3415 |
|
3416 |
-
|
3417 |
-
|
3418 |
|
3419 |
-
|
3420 |
|
3421 |
-
|
3422 |
-
|
3423 |
-
|
3424 |
-
|
3425 |
-
|
3426 |
|
3427 |
-
|
3428 |
-
|
3429 |
-
|
3430 |
-
|
3431 |
-
|
3432 |
-
|
3433 |
-
}
|
3434 |
-
} else {
|
3435 |
-
root[root.length++] = elements;
|
3436 |
-
}
|
3437 |
-
}
|
3438 |
}
|
|
|
|
|
|
|
3439 |
}
|
|
|
|
|
3440 |
|
3441 |
|
3442 |
-
|
3443 |
-
|
3444 |
-
|
3445 |
-
|
3446 |
-
function jqLiteInheritedData(element, name, value) {
|
3447 |
-
// if element is the document object work with the html element instead
|
3448 |
-
// this makes $(document).scope() possible
|
3449 |
-
if (element.nodeType === NODE_TYPE_DOCUMENT) {
|
3450 |
-
element = element.documentElement;
|
3451 |
-
}
|
3452 |
-
var names = isArray(name) ? name : [name];
|
3453 |
-
|
3454 |
-
while (element) {
|
3455 |
-
for (var i = 0, ii = names.length; i < ii; i++) {
|
3456 |
-
if (isDefined(value = jqLite.data(element, names[i]))) return value;
|
3457 |
-
}
|
3458 |
-
|
3459 |
-
// If dealing with a document fragment node with a host element, and no parent, use the host
|
3460 |
-
// element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
|
3461 |
-
// to lookup parent controllers.
|
3462 |
-
element = element.parentNode || (element.nodeType === NODE_TYPE_DOCUMENT_FRAGMENT && element.host);
|
3463 |
-
}
|
3464 |
-
}
|
3465 |
|
3466 |
-
|
3467 |
-
|
3468 |
-
|
3469 |
-
|
3470 |
-
|
3471 |
-
|
|
|
3472 |
|
3473 |
-
|
3474 |
-
|
3475 |
-
|
3476 |
-
if (parent) parent.removeChild(element);
|
3477 |
}
|
3478 |
|
|
|
|
|
|
|
|
|
|
|
|
|
3479 |
|
3480 |
-
|
3481 |
-
|
3482 |
-
|
3483 |
-
|
3484 |
-
|
3485 |
-
|
3486 |
-
win.setTimeout(action);
|
3487 |
-
} else {
|
3488 |
-
// No need to unbind this handler as load is only ever called once
|
3489 |
-
jqLite(win).on('load', action);
|
3490 |
-
}
|
3491 |
-
}
|
3492 |
|
3493 |
-
|
3494 |
-
|
3495 |
-
|
3496 |
-
|
3497 |
-
|
3498 |
-
}
|
3499 |
|
3500 |
-
// check if document is already loaded
|
3501 |
-
if (window.document.readyState === 'complete') {
|
3502 |
-
window.setTimeout(fn);
|
3503 |
-
} else {
|
3504 |
-
// We can not use jqLite since we are not done loading and jQuery could be loaded later.
|
3505 |
|
3506 |
-
|
3507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3508 |
|
3509 |
-
|
3510 |
-
|
3511 |
-
|
3512 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3513 |
|
3514 |
//////////////////////////////////////////
|
3515 |
// Functions which are declared directly.
|
3516 |
//////////////////////////////////////////
|
3517 |
-
|
3518 |
-
|
3519 |
-
|
3520 |
-
|
3521 |
-
|
3522 |
-
|
3523 |
-
|
3524 |
-
|
3525 |
-
|
3526 |
-
|
3527 |
-
|
3528 |
-
|
3529 |
-
|
3530 |
-
|
3531 |
-
|
3532 |
-
|
3533 |
-
|
3534 |
|
3535 |
//////////////////////////////////////////
|
3536 |
// Functions iterating getter/setters.
|
3537 |
// these functions return self on setter and
|
3538 |
// value on get.
|
3539 |
//////////////////////////////////////////
|
3540 |
-
|
3541 |
-
|
3542 |
-
|
3543 |
-
|
3544 |
-
|
3545 |
-
|
3546 |
-
|
3547 |
-
|
3548 |
-
|
3549 |
-
|
3550 |
-
|
3551 |
-
|
3552 |
-
|
3553 |
-
|
3554 |
-
|
3555 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3556 |
|
3557 |
-
|
3558 |
-
|
3559 |
-
|
3560 |
|
3561 |
-
|
3562 |
-
|
3563 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3564 |
|
3565 |
-
|
3566 |
-
|
3567 |
-
|
3568 |
|
3569 |
-
|
3570 |
-
|
3571 |
-
|
3572 |
-
|
3573 |
-
cleanData: function jqLiteCleanData(nodes) {
|
3574 |
-
for (var i = 0, ii = nodes.length; i < ii; i++) {
|
3575 |
-
jqLiteRemoveData(nodes[i]);
|
3576 |
-
jqLiteOff(nodes[i]);
|
3577 |
-
}
|
3578 |
-
}
|
3579 |
-
}, function(fn, name) {
|
3580 |
-
JQLite[name] = fn;
|
3581 |
-
});
|
3582 |
|
3583 |
-
|
3584 |
-
|
3585 |
-
|
|
|
3586 |
|
3587 |
-
|
3588 |
-
// Can't use jqLiteData here directly so we stay compatible with jQuery!
|
3589 |
-
return jqLite.data(element, '$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']);
|
3590 |
-
},
|
3591 |
|
3592 |
-
|
3593 |
-
|
3594 |
-
|
3595 |
-
},
|
3596 |
|
3597 |
-
|
|
|
|
|
3598 |
|
3599 |
-
|
3600 |
-
return jqLiteInheritedData(element, '$injector');
|
3601 |
-
},
|
3602 |
|
3603 |
-
|
3604 |
-
|
3605 |
-
},
|
3606 |
|
3607 |
-
|
|
|
|
|
|
|
|
|
|
|
3608 |
|
3609 |
-
|
3610 |
-
|
|
|
|
|
|
|
|
|
|
|
3611 |
|
3612 |
-
|
3613 |
-
|
3614 |
-
} else {
|
3615 |
-
return element.style[name];
|
3616 |
-
}
|
3617 |
-
},
|
3618 |
|
3619 |
-
|
3620 |
-
|
3621 |
-
var nodeType = element.nodeType;
|
3622 |
-
if (nodeType === NODE_TYPE_TEXT || nodeType === NODE_TYPE_ATTRIBUTE || nodeType === NODE_TYPE_COMMENT ||
|
3623 |
-
!element.getAttribute) {
|
3624 |
-
return;
|
3625 |
-
}
|
3626 |
|
3627 |
-
|
3628 |
-
|
|
|
|
|
|
|
|
|
|
|
3629 |
|
3630 |
-
|
3631 |
-
// setter
|
3632 |
|
3633 |
-
|
3634 |
-
|
3635 |
-
|
3636 |
-
|
3637 |
-
|
3638 |
-
|
3639 |
-
|
3640 |
|
3641 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
3642 |
|
3643 |
-
|
3644 |
-
|
3645 |
-
|
3646 |
-
// Normalize non-existing attributes to undefined (as jQuery).
|
3647 |
-
return ret === null ? undefined : ret;
|
3648 |
-
}
|
3649 |
-
},
|
3650 |
|
3651 |
-
|
3652 |
-
|
3653 |
-
|
3654 |
-
|
3655 |
-
|
3656 |
-
|
3657 |
-
|
3658 |
-
|
3659 |
-
text: (function() {
|
3660 |
-
getText.$dv = '';
|
3661 |
-
return getText;
|
3662 |
|
3663 |
-
|
3664 |
-
|
3665 |
-
|
3666 |
-
|
3667 |
-
|
3668 |
-
|
3669 |
-
|
3670 |
-
|
3671 |
-
|
3672 |
-
|
3673 |
-
|
3674 |
-
|
3675 |
-
|
3676 |
-
|
3677 |
-
|
3678 |
-
result.push(option.value || option.text);
|
3679 |
-
}
|
3680 |
-
});
|
3681 |
-
return result;
|
3682 |
-
}
|
3683 |
-
return element.value;
|
3684 |
-
}
|
3685 |
-
element.value = value;
|
3686 |
-
},
|
3687 |
|
3688 |
-
|
3689 |
-
|
3690 |
-
|
3691 |
-
|
3692 |
-
|
3693 |
-
|
3694 |
-
|
3695 |
|
3696 |
-
|
3697 |
-
|
3698 |
-
|
3699 |
-
|
3700 |
-
|
3701 |
-
|
3702 |
-
|
3703 |
-
|
3704 |
-
|
3705 |
-
|
3706 |
-
|
3707 |
-
|
3708 |
-
|
3709 |
-
|
3710 |
-
|
3711 |
-
|
3712 |
-
|
3713 |
-
|
3714 |
-
|
3715 |
-
|
3716 |
-
|
3717 |
-
|
3718 |
-
|
3719 |
-
|
3720 |
-
}
|
3721 |
-
}
|
3722 |
-
}
|
3723 |
-
// return self for chaining
|
3724 |
-
return this;
|
3725 |
-
} else {
|
3726 |
-
// we are a read, so read the first child.
|
3727 |
-
// TODO: do we still need this?
|
3728 |
-
var value = fn.$dv;
|
3729 |
-
// Only if we have $dv do we iterate over all, otherwise it is just the first element.
|
3730 |
-
var jj = (isUndefined(value)) ? Math.min(nodeCount, 1) : nodeCount;
|
3731 |
-
for (var j = 0; j < jj; j++) {
|
3732 |
-
var nodeValue = fn(this[j], arg1, arg2);
|
3733 |
-
value = value ? value + nodeValue : nodeValue;
|
3734 |
-
}
|
3735 |
-
return value;
|
3736 |
-
}
|
3737 |
-
} else {
|
3738 |
-
// we are a write, so apply to all children
|
3739 |
-
for (i = 0; i < nodeCount; i++) {
|
3740 |
-
fn(this[i], arg1, arg2);
|
3741 |
-
}
|
3742 |
-
// return self for chaining
|
3743 |
-
return this;
|
3744 |
}
|
3745 |
-
|
3746 |
-
|
3747 |
-
|
3748 |
-
|
3749 |
-
|
3750 |
-
|
3751 |
-
|
3752 |
-
|
3753 |
-
|
3754 |
-
|
3755 |
-
|
3756 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3757 |
|
3758 |
-
|
|
|
|
|
|
|
|
|
|
|
3759 |
|
3760 |
-
|
3761 |
-
|
3762 |
-
event.stopImmediatePropagation = function() {
|
3763 |
-
event.immediatePropagationStopped = true;
|
3764 |
|
3765 |
-
|
3766 |
-
event.stopPropagation();
|
3767 |
-
}
|
3768 |
|
3769 |
-
|
3770 |
-
|
3771 |
-
|
3772 |
-
|
3773 |
-
}
|
3774 |
|
3775 |
-
|
3776 |
-
|
3777 |
-
|
3778 |
|
3779 |
-
|
3780 |
-
|
|
|
|
|
|
|
3781 |
|
3782 |
-
|
3783 |
-
|
3784 |
-
|
3785 |
-
}
|
3786 |
|
3787 |
-
|
3788 |
-
|
3789 |
-
handlerWrapper(element, event, eventFns[i]);
|
3790 |
-
}
|
3791 |
-
}
|
3792 |
-
};
|
3793 |
|
3794 |
-
|
3795 |
-
|
3796 |
-
|
3797 |
-
return eventHandler;
|
3798 |
}
|
3799 |
|
3800 |
-
|
3801 |
-
|
|
|
|
|
3802 |
}
|
|
|
3803 |
|
3804 |
-
|
3805 |
-
|
3806 |
-
|
3807 |
-
|
3808 |
-
|
3809 |
-
|
3810 |
-
|
3811 |
-
|
3812 |
-
|
3813 |
-
|
3814 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3815 |
|
3816 |
//////////////////////////////////////////
|
3817 |
// Functions iterating traversal.
|
3818 |
// These functions chain results into a single
|
3819 |
// selector.
|
3820 |
//////////////////////////////////////////
|
3821 |
-
|
3822 |
-
|
3823 |
-
|
3824 |
-
on: function jqLiteOn(element, type, fn, unsupported) {
|
3825 |
-
if (isDefined(unsupported)) throw jqLiteMinErr('onargs', 'jqLite#on() does not support the `selector` or `eventData` parameters');
|
3826 |
-
|
3827 |
-
// Do not add event handlers to non-elements because they will not be cleaned up.
|
3828 |
-
if (!jqLiteAcceptsData(element)) {
|
3829 |
-
return;
|
3830 |
-
}
|
3831 |
|
3832 |
-
|
3833 |
-
|
3834 |
-
var handle = expandoStore.handle;
|
3835 |
-
|
3836 |
-
if (!handle) {
|
3837 |
-
handle = expandoStore.handle = createEventHandler(element, events);
|
3838 |
-
}
|
3839 |
|
3840 |
-
|
3841 |
-
|
3842 |
-
|
|
|
3843 |
|
3844 |
-
|
3845 |
-
|
|
|
3846 |
|
3847 |
-
|
3848 |
-
|
3849 |
-
|
3850 |
-
if (type !== '$destroy' && !noEventListener) {
|
3851 |
-
element.addEventListener(type, handle);
|
3852 |
-
}
|
3853 |
-
}
|
3854 |
|
3855 |
-
|
3856 |
-
|
|
|
3857 |
|
3858 |
-
|
3859 |
-
|
3860 |
-
if (MOUSE_EVENT_MAP[type]) {
|
3861 |
-
addHandler(MOUSE_EVENT_MAP[type], specialMouseHandlerWrapper);
|
3862 |
-
addHandler(type, undefined, true);
|
3863 |
-
} else {
|
3864 |
-
addHandler(type);
|
3865 |
-
}
|
3866 |
-
}
|
3867 |
-
},
|
3868 |
|
3869 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
3870 |
|
3871 |
-
|
3872 |
-
|
3873 |
|
3874 |
-
|
3875 |
-
|
3876 |
-
|
3877 |
-
|
3878 |
-
|
3879 |
-
|
3880 |
-
|
3881 |
-
|
3882 |
-
|
|
|
3883 |
|
3884 |
-
|
3885 |
-
var index, parent = element.parentNode;
|
3886 |
-
jqLiteDealoc(element);
|
3887 |
-
forEach(new JQLite(replaceNode), function(node) {
|
3888 |
-
if (index) {
|
3889 |
-
parent.insertBefore(node, index.nextSibling);
|
3890 |
-
} else {
|
3891 |
-
parent.replaceChild(node, element);
|
3892 |
-
}
|
3893 |
-
index = node;
|
3894 |
-
});
|
3895 |
-
},
|
3896 |
|
3897 |
-
|
3898 |
-
|
3899 |
-
forEach(element.childNodes, function(element) {
|
3900 |
-
if (element.nodeType === NODE_TYPE_ELEMENT) {
|
3901 |
-
children.push(element);
|
3902 |
-
}
|
3903 |
-
});
|
3904 |
-
return children;
|
3905 |
-
},
|
3906 |
|
3907 |
-
|
3908 |
-
|
3909 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3910 |
|
3911 |
-
|
3912 |
-
|
3913 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
3914 |
|
3915 |
-
|
|
|
|
|
3916 |
|
3917 |
-
|
3918 |
-
|
3919 |
-
|
3920 |
-
}
|
3921 |
-
},
|
3922 |
|
3923 |
-
|
3924 |
-
if (element.nodeType === NODE_TYPE_ELEMENT) {
|
3925 |
-
var index = element.firstChild;
|
3926 |
-
forEach(new JQLite(node), function(child) {
|
3927 |
-
element.insertBefore(child, index);
|
3928 |
-
});
|
3929 |
-
}
|
3930 |
-
},
|
3931 |
|
3932 |
-
|
3933 |
-
|
3934 |
-
|
|
|
|
|
3935 |
|
3936 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3937 |
|
3938 |
-
|
3939 |
-
|
3940 |
-
|
3941 |
|
3942 |
-
|
3943 |
-
var index = element, parent = element.parentNode;
|
3944 |
|
3945 |
-
|
3946 |
-
|
|
|
3947 |
|
3948 |
-
|
3949 |
-
|
3950 |
-
parent.insertBefore(node, index.nextSibling);
|
3951 |
-
index = node;
|
3952 |
-
}
|
3953 |
-
}
|
3954 |
-
},
|
3955 |
|
3956 |
-
|
3957 |
-
|
3958 |
|
3959 |
-
|
3960 |
-
|
3961 |
-
|
3962 |
-
|
3963 |
-
|
3964 |
-
|
3965 |
-
|
3966 |
-
(classCondition ? jqLiteAddClass : jqLiteRemoveClass)(element, className);
|
3967 |
-
});
|
3968 |
-
}
|
3969 |
-
},
|
3970 |
|
3971 |
-
|
3972 |
-
|
3973 |
-
return parent && parent.nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT ? parent : null;
|
3974 |
-
},
|
3975 |
|
3976 |
-
|
3977 |
-
|
3978 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3979 |
|
3980 |
-
|
3981 |
-
|
3982 |
-
|
3983 |
-
|
3984 |
-
return [];
|
3985 |
-
}
|
3986 |
-
},
|
3987 |
|
3988 |
-
|
3989 |
-
|
3990 |
-
|
3991 |
-
|
3992 |
-
var dummyEvent, eventFnsCopy, handlerArgs;
|
3993 |
-
var eventName = event.type || event;
|
3994 |
-
var expandoStore = jqLiteExpandoStore(element);
|
3995 |
-
var events = expandoStore && expandoStore.events;
|
3996 |
-
var eventFns = events && events[eventName];
|
3997 |
-
|
3998 |
-
if (eventFns) {
|
3999 |
-
// Create a dummy event to pass to the handlers
|
4000 |
-
dummyEvent = {
|
4001 |
-
preventDefault: function() { this.defaultPrevented = true; },
|
4002 |
-
isDefaultPrevented: function() { return this.defaultPrevented === true; },
|
4003 |
-
stopImmediatePropagation: function() { this.immediatePropagationStopped = true; },
|
4004 |
-
isImmediatePropagationStopped: function() { return this.immediatePropagationStopped === true; },
|
4005 |
-
stopPropagation: noop,
|
4006 |
-
type: eventName,
|
4007 |
-
target: element
|
4008 |
-
};
|
4009 |
|
4010 |
-
|
4011 |
-
|
4012 |
-
|
4013 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4014 |
|
4015 |
-
|
4016 |
-
|
4017 |
-
|
4018 |
|
4019 |
-
|
4020 |
-
|
4021 |
-
|
4022 |
-
}
|
4023 |
-
});
|
4024 |
-
}
|
4025 |
}
|
4026 |
-
|
4027 |
-
|
4028 |
-
|
4029 |
-
|
4030 |
-
|
4031 |
-
|
4032 |
-
|
4033 |
-
|
4034 |
-
|
4035 |
-
|
4036 |
-
|
4037 |
-
|
4038 |
-
|
4039 |
-
|
4040 |
-
|
4041 |
-
|
4042 |
-
|
4043 |
-
|
4044 |
-
|
4045 |
-
|
4046 |
-
}
|
|
|
|
|
|
|
4047 |
|
4048 |
// bind legacy bind/unbind to on/off
|
4049 |
-
|
4050 |
-
|
4051 |
|
4052 |
|
4053 |
// Provider for private $$jqLite service
|
4054 |
-
|
4055 |
-
|
4056 |
-
|
4057 |
-
|
4058 |
-
|
4059 |
-
|
4060 |
-
|
4061 |
-
|
4062 |
-
|
4063 |
-
|
4064 |
-
|
4065 |
-
|
4066 |
-
|
4067 |
-
|
4068 |
-
|
4069 |
-
|
4070 |
-
|
4071 |
-
|
4072 |
-
|
4073 |
|
4074 |
-
|
4075 |
-
|
4076 |
-
|
4077 |
-
|
4078 |
-
|
4079 |
-
|
4080 |
-
|
4081 |
-
|
4082 |
-
|
4083 |
-
|
4084 |
-
|
4085 |
-
|
4086 |
-
|
4087 |
-
|
4088 |
|
4089 |
-
|
4090 |
-
|
4091 |
-
|
4092 |
-
|
4093 |
-
|
4094 |
-
|
4095 |
|
4096 |
-
|
4097 |
-
|
4098 |
-
|
4099 |
-
|
4100 |
-
|
4101 |
-
|
4102 |
|
4103 |
-
|
4104 |
-
|
4105 |
|
4106 |
// A minimal ES2015 Map implementation.
|
4107 |
// Should be bug/feature equivalent to the native implementations of supported browsers
|
4108 |
// (for the features required in Angular).
|
4109 |
// See https://kangax.github.io/compat-table/es6/#test-Map
|
4110 |
-
|
4111 |
-
|
4112 |
-
|
4113 |
-
|
4114 |
-
|
4115 |
-
|
4116 |
-
|
4117 |
-
|
4118 |
-
|
4119 |
-
|
4120 |
-
|
4121 |
-
|
4122 |
-
|
4123 |
-
|
4124 |
-
|
4125 |
-
|
4126 |
-
|
4127 |
-
|
4128 |
-
|
4129 |
-
|
4130 |
-
|
4131 |
-
|
4132 |
-
|
4133 |
-
|
4134 |
-
|
4135 |
-
|
4136 |
-
|
4137 |
-
|
4138 |
-
|
4139 |
-
|
4140 |
-
|
4141 |
-
|
4142 |
-
|
4143 |
-
|
4144 |
-
|
4145 |
-
|
4146 |
-
|
4147 |
-
|
4148 |
-
|
4149 |
-
|
4150 |
-
|
4151 |
-
|
4152 |
-
|
4153 |
-
|
4154 |
-
|
4155 |
-
|
4156 |
-
|
4157 |
-
|
4158 |
-
|
4159 |
-
|
4160 |
-
|
4161 |
-
|
4162 |
-
|
4163 |
-
|
4164 |
-
|
4165 |
|
4166 |
// For now, always use `NgMapShim`, even if `window.Map` is available. Some native implementations
|
4167 |
// are still buggy (often in subtle ways) and can cause hard-to-debug failures. When native `Map`
|
4168 |
// implementations get more stable, we can reconsider switching to `window.Map` (when available).
|
4169 |
-
|
4170 |
|
4171 |
-
|
4172 |
-
|
4173 |
-
|
4174 |
-
|
4175 |
-
|
4176 |
|
4177 |
-
|
4178 |
-
|
4179 |
-
|
4180 |
-
|
4181 |
-
|
4182 |
-
|
4183 |
-
|
4184 |
-
|
4185 |
-
|
4186 |
-
|
4187 |
-
|
4188 |
-
|
4189 |
-
|
4190 |
-
|
4191 |
-
|
4192 |
-
|
4193 |
-
|
4194 |
-
|
4195 |
-
|
4196 |
-
|
4197 |
-
|
4198 |
-
|
4199 |
-
|
4200 |
-
|
4201 |
-
|
4202 |
* $compile($document)($rootScope);
|
4203 |
* $rootScope.$digest();
|
4204 |
* });
|
4205 |
-
|
4206 |
-
|
4207 |
-
|
4208 |
-
|
4209 |
-
|
4210 |
-
|
4211 |
-
|
4212 |
-
|
4213 |
-
|
4214 |
-
|
4215 |
-
|
4216 |
-
|
4217 |
-
|
4218 |
-
|
4219 |
-
|
4220 |
-
|
4221 |
-
|
4222 |
-
|
4223 |
-
|
4224 |
* var scope = angular.element($div).scope();
|
4225 |
* $compile($div)(scope);
|
4226 |
* });
|
4227 |
-
|
4228 |
-
|
4229 |
-
|
4230 |
|
4231 |
-
/**
|
4232 |
-
* @ngdoc module
|
4233 |
-
* @name auto
|
4234 |
-
* @installation
|
4235 |
-
* @description
|
4236 |
-
*
|
4237 |
-
* Implicit module which gets automatically added to each {@link auto.$injector $injector}.
|
4238 |
-
*/
|
4239 |
|
4240 |
-
|
4241 |
-
|
4242 |
-
|
4243 |
-
|
4244 |
-
|
4245 |
-
|
|
|
|
|
4246 |
|
4247 |
-
|
4248 |
-
|
4249 |
-
|
|
|
|
|
|
|
4250 |
|
4251 |
-
|
4252 |
-
|
4253 |
-
|
4254 |
-
return args;
|
4255 |
-
}
|
4256 |
|
4257 |
-
|
4258 |
-
|
4259 |
-
|
4260 |
-
|
4261 |
-
|
4262 |
-
return 'function(' + (args[1] || '').replace(/[\s\r\n]+/, ' ') + ')';
|
4263 |
-
}
|
4264 |
-
return 'fn';
|
4265 |
-
}
|
4266 |
|
4267 |
-
|
4268 |
-
|
4269 |
-
|
4270 |
-
|
|
|
|
|
|
|
|
|
|
|
4271 |
|
4272 |
-
|
4273 |
-
|
4274 |
-
|
4275 |
-
|
4276 |
-
|
4277 |
-
|
4278 |
-
|
4279 |
-
|
4280 |
-
|
4281 |
-
|
4282 |
-
|
4283 |
-
|
4284 |
-
|
4285 |
-
|
4286 |
-
|
4287 |
-
});
|
4288 |
-
});
|
4289 |
-
}
|
4290 |
-
fn.$inject = $inject;
|
4291 |
-
}
|
4292 |
-
} else if (isArray(fn)) {
|
4293 |
-
last = fn.length - 1;
|
4294 |
-
assertArgFn(fn[last], 'fn');
|
4295 |
-
$inject = fn.slice(0, last);
|
4296 |
-
} else {
|
4297 |
-
assertArgFn(fn, 'fn', true);
|
4298 |
}
|
4299 |
-
|
4300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4301 |
|
4302 |
///////////////////////////////////////
|
4303 |
|
4304 |
-
|
4305 |
-
|
4306 |
-
|
4307 |
-
|
4308 |
-
|
4309 |
-
|
4310 |
-
|
4311 |
-
|
4312 |
-
|
4313 |
-
|
4314 |
-
|
4315 |
-
|
4316 |
-
|
4317 |
-
|
4318 |
-
|
4319 |
-
|
4320 |
* return $injector;
|
4321 |
* })).toBe($injector);
|
4322 |
-
|
4323 |
-
|
4324 |
-
|
4325 |
-
|
4326 |
-
|
4327 |
-
|
4328 |
-
|
4329 |
-
|
4330 |
-
|
4331 |
-
|
4332 |
-
|
4333 |
-
|
4334 |
-
|
4335 |
-
|
4336 |
-
|
4337 |
-
|
4338 |
-
|
4339 |
-
|
4340 |
-
|
4341 |
-
|
4342 |
-
|
4343 |
-
|
4344 |
-
|
4345 |
-
|
4346 |
-
|
4347 |
-
|
4348 |
-
|
4349 |
-
|
4350 |
-
|
4351 |
-
|
4352 |
-
|
4353 |
-
|
4354 |
-
|
4355 |
-
|
4356 |
|
4357 |
-
|
4358 |
-
|
4359 |
-
|
4360 |
-
|
4361 |
-
|
4362 |
-
|
4363 |
-
|
4364 |
-
|
4365 |
-
|
4366 |
-
|
4367 |
-
|
4368 |
-
|
4369 |
-
|
4370 |
-
|
4371 |
-
|
4372 |
-
|
4373 |
-
|
4374 |
-
|
4375 |
-
|
4376 |
-
|
4377 |
|
4378 |
|
4379 |
-
|
4380 |
-
|
4381 |
-
|
4382 |
-
|
4383 |
-
|
4384 |
-
|
4385 |
-
|
4386 |
-
|
4387 |
-
|
4388 |
-
|
4389 |
-
|
4390 |
|
4391 |
-
|
4392 |
-
|
4393 |
-
|
4394 |
-
|
4395 |
-
|
4396 |
-
|
4397 |
-
|
4398 |
-
|
4399 |
-
|
4400 |
-
|
4401 |
-
|
4402 |
-
|
4403 |
-
|
4404 |
-
|
4405 |
|
4406 |
-
|
4407 |
-
|
4408 |
-
|
4409 |
-
|
4410 |
-
|
4411 |
-
|
4412 |
-
|
4413 |
-
|
4414 |
-
|
4415 |
-
|
4416 |
|
4417 |
-
|
4418 |
-
|
4419 |
-
|
4420 |
-
|
4421 |
-
|
4422 |
-
|
4423 |
-
|
4424 |
-
|
4425 |
-
|
4426 |
-
|
4427 |
-
|
4428 |
-
|
4429 |
-
|
4430 |
|
4431 |
-
|
4432 |
-
|
4433 |
-
|
4434 |
-
|
4435 |
-
|
4436 |
-
|
4437 |
-
|
4438 |
-
|
4439 |
-
|
4440 |
-
|
4441 |
-
|
4442 |
-
|
4443 |
-
|
4444 |
-
|
4445 |
-
|
4446 |
-
|
4447 |
-
|
4448 |
-
|
4449 |
* // ...
|
4450 |
* }
|
4451 |
-
|
4452 |
-
|
4453 |
-
|
4454 |
-
|
4455 |
-
|
4456 |
-
|
4457 |
-
|
4458 |
-
|
4459 |
-
|
4460 |
-
|
4461 |
-
|
4462 |
-
|
4463 |
-
|
4464 |
-
|
4465 |
-
|
4466 |
-
|
4467 |
-
|
4468 |
* // ...
|
4469 |
* }
|
4470 |
-
|
4471 |
-
|
4472 |
-
|
4473 |
-
|
4474 |
-
|
4475 |
-
|
4476 |
-
|
4477 |
-
|
4478 |
-
|
4479 |
-
|
4480 |
-
|
4481 |
-
|
4482 |
-
|
4483 |
-
|
4484 |
-
|
4485 |
-
|
4486 |
* // ...
|
4487 |
* });
|
4488 |
-
|
4489 |
-
|
4490 |
-
|
4491 |
* // ...
|
4492 |
* };
|
4493 |
-
|
4494 |
-
|
4495 |
-
|
4496 |
-
|
4497 |
-
|
4498 |
* // ...
|
4499 |
* }]);
|
4500 |
-
|
4501 |
-
|
4502 |
-
|
4503 |
-
|
4504 |
-
|
4505 |
-
|
4506 |
-
|
4507 |
-
|
4508 |
-
|
4509 |
-
|
4510 |
-
|
4511 |
-
|
4512 |
-
|
4513 |
-
|
4514 |
-
|
4515 |
-
|
4516 |
-
|
4517 |
-
|
4518 |
-
|
4519 |
-
|
4520 |
-
|
4521 |
-
|
4522 |
-
|
4523 |
-
|
4524 |
-
|
4525 |
-
|
4526 |
-
|
4527 |
-
|
4528 |
-
|
4529 |
-
|
4530 |
-
|
4531 |
-
|
4532 |
-
|
4533 |
-
|
4534 |
-
|
4535 |
-
|
4536 |
-
|
4537 |
-
|
4538 |
-
|
4539 |
-
|
4540 |
-
|
4541 |
-
|
4542 |
* return function loadModule(moduleName, bundleUrl) {
|
4543 |
* return getScript(bundleUrl).then(function() { $injector.loadNewModules([moduleName]); });
|
4544 |
* };
|
4545 |
* })
|
4546 |
-
|
4547 |
-
|
4548 |
-
|
4549 |
-
|
4550 |
-
|
4551 |
-
|
4552 |
-
|
4553 |
|
4554 |
|
4555 |
-
|
4556 |
-
|
4557 |
-
|
4558 |
-
|
4559 |
-
|
4560 |
-
|
4561 |
-
|
4562 |
-
|
4563 |
-
|
4564 |
-
|
4565 |
-
|
4566 |
-
|
4567 |
-
|
4568 |
-
|
4569 |
-
|
4570 |
-
|
4571 |
-
|
4572 |
-
|
4573 |
-
|
4574 |
-
|
4575 |
-
|
4576 |
-
|
4577 |
-
|
4578 |
-
|
4579 |
-
|
4580 |
-
|
4581 |
-
|
4582 |
-
|
4583 |
-
|
4584 |
-
|
4585 |
-
|
4586 |
-
|
4587 |
-
|
4588 |
-
|
4589 |
-
|
4590 |
-
|
4591 |
-
|
4592 |
-
|
4593 |
-
|
4594 |
-
|
4595 |
-
|
4596 |
|
4597 |
-
|
4598 |
-
|
4599 |
-
|
4600 |
-
|
4601 |
-
|
4602 |
-
|
4603 |
-
|
4604 |
-
|
4605 |
-
|
4606 |
-
|
4607 |
-
|
4608 |
-
|
4609 |
-
|
4610 |
-
|
4611 |
-
|
4612 |
-
|
4613 |
-
|
4614 |
-
|
4615 |
-
|
4616 |
-
|
4617 |
-
|
4618 |
-
|
4619 |
-
|
4620 |
-
|
4621 |
-
|
4622 |
-
|
4623 |
-
|
4624 |
-
|
4625 |
-
|
4626 |
-
|
4627 |
-
|
4628 |
-
|
4629 |
-
|
4630 |
|
4631 |
-
|
4632 |
-
|
4633 |
-
|
4634 |
-
|
4635 |
-
|
4636 |
-
|
4637 |
-
|
4638 |
-
|
4639 |
* var trackingUrl = '/track';
|
4640 |
*
|
4641 |
* // A provider method for configuring where the tracked events should been saved
|
@@ -4661,8 +4661,8 @@
|
|
4661 |
* };
|
4662 |
* }];
|
4663 |
* }
|
4664 |
-
|
4665 |
-
|
4666 |
* var postSpy;
|
4667 |
*
|
4668 |
* beforeEach(module(function($provide) {
|
@@ -4690,550 +4690,550 @@
|
|
4690 |
* expect(postSpy.mostRecentCall.args[1]).toEqual({ 'login': 1 });
|
4691 |
* }));
|
4692 |
* });
|
4693 |
-
|
4694 |
-
|
4695 |
|
4696 |
-
|
4697 |
-
|
4698 |
-
|
4699 |
-
|
4700 |
-
|
4701 |
-
|
4702 |
-
|
4703 |
-
|
4704 |
-
|
4705 |
-
|
4706 |
-
|
4707 |
-
|
4708 |
-
|
4709 |
-
|
4710 |
-
|
4711 |
-
|
4712 |
-
|
4713 |
-
|
4714 |
-
|
4715 |
-
|
4716 |
* return function ping() {
|
4717 |
* return $http.send('/ping');
|
4718 |
* };
|
4719 |
* }]);
|
4720 |
-
|
4721 |
-
|
4722 |
-
|
4723 |
-
|
4724 |
* ping();
|
4725 |
* }]);
|
4726 |
-
|
4727 |
-
|
4728 |
|
4729 |
|
4730 |
-
|
4731 |
-
|
4732 |
-
|
4733 |
-
|
4734 |
-
|
4735 |
-
|
4736 |
-
|
4737 |
-
|
4738 |
-
|
4739 |
-
|
4740 |
-
|
4741 |
-
|
4742 |
-
|
4743 |
-
|
4744 |
-
|
4745 |
* $get: function() {
|
4746 |
* return $injector.instantiate(constructor);
|
4747 |
* }
|
4748 |
* }
|
4749 |
-
|
4750 |
-
|
4751 |
-
|
4752 |
-
|
4753 |
-
|
4754 |
-
|
4755 |
-
|
4756 |
-
|
4757 |
-
|
4758 |
-
|
4759 |
-
|
4760 |
-
|
4761 |
-
|
4762 |
-
|
4763 |
-
|
4764 |
-
|
4765 |
* this.$http = $http;
|
4766 |
* };
|
4767 |
-
|
4768 |
-
|
4769 |
-
|
4770 |
-
|
4771 |
* return this.$http.get('/ping');
|
4772 |
* };
|
4773 |
-
|
4774 |
-
|
4775 |
-
|
4776 |
-
|
4777 |
-
|
4778 |
* ping.send();
|
4779 |
* }]);
|
4780 |
-
|
4781 |
-
|
4782 |
|
4783 |
|
4784 |
-
|
4785 |
-
|
4786 |
-
|
4787 |
-
|
4788 |
-
|
4789 |
-
|
4790 |
-
|
4791 |
-
|
4792 |
-
|
4793 |
-
|
4794 |
-
|
4795 |
-
|
4796 |
-
|
4797 |
-
|
4798 |
-
|
4799 |
-
|
4800 |
-
|
4801 |
-
|
4802 |
-
|
4803 |
-
|
4804 |
-
|
4805 |
-
|
4806 |
-
|
4807 |
-
|
4808 |
-
|
4809 |
-
|
4810 |
* return value / 2;
|
4811 |
* });
|
4812 |
-
|
4813 |
-
|
4814 |
|
4815 |
|
4816 |
-
|
4817 |
-
|
4818 |
-
|
4819 |
-
|
4820 |
-
|
4821 |
-
|
4822 |
-
|
4823 |
-
|
4824 |
-
|
4825 |
-
|
4826 |
-
|
4827 |
-
|
4828 |
-
|
4829 |
-
|
4830 |
-
|
4831 |
-
|
4832 |
-
|
4833 |
-
|
4834 |
-
|
4835 |
-
|
4836 |
-
|
4837 |
-
|
4838 |
-
|
4839 |
-
|
4840 |
-
|
4841 |
* return value * 2;
|
4842 |
* });
|
4843 |
-
|
4844 |
-
|
4845 |
|
4846 |
|
4847 |
-
|
4848 |
-
|
4849 |
-
|
4850 |
-
|
4851 |
-
|
4852 |
-
|
4853 |
-
|
4854 |
-
|
4855 |
-
|
4856 |
-
|
4857 |
-
|
4858 |
-
|
4859 |
-
|
4860 |
-
|
4861 |
-
|
4862 |
-
|
4863 |
-
|
4864 |
-
|
4865 |
-
|
4866 |
-
|
4867 |
-
|
4868 |
-
|
4869 |
-
|
4870 |
-
|
4871 |
-
|
4872 |
-
|
4873 |
* $delegate.warn = $delegate.error;
|
4874 |
* return $delegate;
|
4875 |
* }]);
|
4876 |
-
|
4877 |
-
|
4878 |
|
4879 |
|
4880 |
-
|
4881 |
-
|
4882 |
-
|
4883 |
-
|
4884 |
-
|
4885 |
-
|
4886 |
-
|
4887 |
-
|
4888 |
-
|
4889 |
-
|
4890 |
-
|
4891 |
-
|
4892 |
-
|
4893 |
-
|
4894 |
-
|
4895 |
-
|
4896 |
-
|
4897 |
-
|
4898 |
-
|
4899 |
-
|
4900 |
-
|
4901 |
-
|
4902 |
-
|
4903 |
-
|
4904 |
-
|
4905 |
-
|
4906 |
-
|
4907 |
-
|
4908 |
-
|
4909 |
-
|
4910 |
-
|
4911 |
-
|
4912 |
-
|
4913 |
-
|
4914 |
-
|
4915 |
-
|
4916 |
-
|
4917 |
-
|
4918 |
-
|
4919 |
-
|
4920 |
-
|
4921 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4922 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4923 |
|
4924 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4925 |
|
4926 |
-
|
4927 |
-
|
4928 |
-
|
|
|
|
|
4929 |
|
4930 |
-
|
4931 |
-
|
4932 |
-
|
4933 |
-
|
4934 |
-
|
4935 |
-
return delegate(key, value);
|
4936 |
-
}
|
4937 |
-
};
|
4938 |
-
}
|
4939 |
|
4940 |
-
|
4941 |
-
assertNotHasOwnProperty(name, 'service');
|
4942 |
-
if (isFunction(provider_) || isArray(provider_)) {
|
4943 |
-
provider_ = providerInjector.instantiate(provider_);
|
4944 |
-
}
|
4945 |
-
if (!provider_.$get) {
|
4946 |
-
throw $injectorMinErr('pget', 'Provider \'{0}\' must define $get factory method.', name);
|
4947 |
-
}
|
4948 |
-
return (providerCache[name + providerSuffix] = provider_);
|
4949 |
-
}
|
4950 |
|
4951 |
-
|
4952 |
-
|
4953 |
-
|
4954 |
-
|
4955 |
-
|
4956 |
-
}
|
4957 |
-
return result;
|
4958 |
-
};
|
4959 |
-
}
|
4960 |
|
4961 |
-
|
4962 |
-
|
4963 |
-
|
4964 |
-
});
|
4965 |
-
}
|
4966 |
|
4967 |
-
|
4968 |
-
|
4969 |
-
|
4970 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4971 |
}
|
|
|
4972 |
|
4973 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4974 |
|
4975 |
-
|
4976 |
-
|
4977 |
-
|
4978 |
-
instanceCache[name] = value;
|
4979 |
-
}
|
4980 |
|
4981 |
-
|
4982 |
-
var origProvider = providerInjector.get(serviceName + providerSuffix),
|
4983 |
-
orig$get = origProvider.$get;
|
4984 |
|
4985 |
-
|
4986 |
-
|
4987 |
-
|
4988 |
-
|
|
|
4989 |
}
|
4990 |
-
|
4991 |
-
|
4992 |
-
|
4993 |
-
|
4994 |
-
|
4995 |
-
|
4996 |
-
|
4997 |
-
|
4998 |
-
|
4999 |
-
|
5000 |
-
|
5001 |
-
|
5002 |
-
|
5003 |
-
|
5004 |
-
var invokeArgs = queue[i],
|
5005 |
-
provider = providerInjector.get(invokeArgs[0]);
|
5006 |
-
|
5007 |
-
provider[invokeArgs[1]].apply(provider, invokeArgs[2]);
|
5008 |
-
}
|
5009 |
-
}
|
5010 |
-
|
5011 |
-
try {
|
5012 |
-
if (isString(module)) {
|
5013 |
-
moduleFn = angularModule(module);
|
5014 |
-
instanceInjector.modules[module] = moduleFn;
|
5015 |
-
runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks);
|
5016 |
-
runInvokeQueue(moduleFn._invokeQueue);
|
5017 |
-
runInvokeQueue(moduleFn._configBlocks);
|
5018 |
-
} else if (isFunction(module)) {
|
5019 |
-
runBlocks.push(providerInjector.invoke(module));
|
5020 |
-
} else if (isArray(module)) {
|
5021 |
-
runBlocks.push(providerInjector.invoke(module));
|
5022 |
-
} else {
|
5023 |
-
assertArgFn(module, 'module');
|
5024 |
-
}
|
5025 |
-
} catch (e) {
|
5026 |
-
if (isArray(module)) {
|
5027 |
-
module = module[module.length - 1];
|
5028 |
-
}
|
5029 |
-
if (e.message && e.stack && e.stack.indexOf(e.message) === -1) {
|
5030 |
-
// Safari & FF's stack traces don't contain error.message content
|
5031 |
-
// unlike those of Chrome and IE
|
5032 |
-
// So if stack doesn't contain message, we create a new string that contains both.
|
5033 |
-
// Since error.stack is read-only in Safari, I'm overriding e and not e.stack here.
|
5034 |
-
// eslint-disable-next-line no-ex-assign
|
5035 |
-
e = e.message + '\n' + e.stack;
|
5036 |
-
}
|
5037 |
-
throw $injectorMinErr('modulerr', 'Failed to instantiate module {0} due to:\n{1}',
|
5038 |
-
module, e.stack || e.message || e);
|
5039 |
-
}
|
5040 |
-
});
|
5041 |
-
return runBlocks;
|
5042 |
}
|
|
|
|
|
5043 |
|
5044 |
-
////////////////////////////////////
|
5045 |
-
// internal Injector
|
5046 |
-
////////////////////////////////////
|
5047 |
-
|
5048 |
-
function createInternalInjector(cache, factory) {
|
5049 |
-
|
5050 |
-
function getService(serviceName, caller) {
|
5051 |
-
if (cache.hasOwnProperty(serviceName)) {
|
5052 |
-
if (cache[serviceName] === INSTANTIATING) {
|
5053 |
-
throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
|
5054 |
-
serviceName + ' <- ' + path.join(' <- '));
|
5055 |
-
}
|
5056 |
-
return cache[serviceName];
|
5057 |
-
} else {
|
5058 |
-
try {
|
5059 |
-
path.unshift(serviceName);
|
5060 |
-
cache[serviceName] = INSTANTIATING;
|
5061 |
-
cache[serviceName] = factory(serviceName, caller);
|
5062 |
-
return cache[serviceName];
|
5063 |
-
} catch (err) {
|
5064 |
-
if (cache[serviceName] === INSTANTIATING) {
|
5065 |
-
delete cache[serviceName];
|
5066 |
-
}
|
5067 |
-
throw err;
|
5068 |
-
} finally {
|
5069 |
-
path.shift();
|
5070 |
-
}
|
5071 |
-
}
|
5072 |
-
}
|
5073 |
-
|
5074 |
-
|
5075 |
-
function injectionArgs(fn, locals, serviceName) {
|
5076 |
-
var args = [],
|
5077 |
-
$inject = createInjector.$$annotate(fn, strictDi, serviceName);
|
5078 |
-
|
5079 |
-
for (var i = 0, length = $inject.length; i < length; i++) {
|
5080 |
-
var key = $inject[i];
|
5081 |
-
if (typeof key !== 'string') {
|
5082 |
-
throw $injectorMinErr('itkn',
|
5083 |
-
'Incorrect injection token! Expected service name as string, got {0}', key);
|
5084 |
-
}
|
5085 |
-
args.push(locals && locals.hasOwnProperty(key) ? locals[key] :
|
5086 |
-
getService(key, serviceName));
|
5087 |
-
}
|
5088 |
-
return args;
|
5089 |
-
}
|
5090 |
|
5091 |
-
|
5092 |
-
|
5093 |
-
|
5094 |
-
if (msie || typeof func !== 'function') {
|
5095 |
-
return false;
|
5096 |
-
}
|
5097 |
-
var result = func.$$ngIsClass;
|
5098 |
-
if (!isBoolean(result)) {
|
5099 |
-
result = func.$$ngIsClass = /^class\b/.test(stringifyFn(func));
|
5100 |
-
}
|
5101 |
-
return result;
|
5102 |
-
}
|
5103 |
|
5104 |
-
|
5105 |
-
|
5106 |
-
|
5107 |
-
|
5108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
5109 |
|
5110 |
-
|
5111 |
-
|
5112 |
-
|
5113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5114 |
|
5115 |
-
|
5116 |
-
|
5117 |
-
|
5118 |
-
|
5119 |
-
|
5120 |
-
args.unshift(null);
|
5121 |
-
return new (Function.prototype.bind.apply(fn, args))();
|
5122 |
-
}
|
5123 |
-
}
|
5124 |
|
|
|
|
|
|
|
|
|
5125 |
|
5126 |
-
|
5127 |
-
|
5128 |
-
|
5129 |
-
|
5130 |
-
|
5131 |
-
|
5132 |
-
|
5133 |
-
|
5134 |
-
|
5135 |
|
5136 |
|
5137 |
-
|
5138 |
-
|
5139 |
-
|
5140 |
-
|
5141 |
-
|
5142 |
-
|
5143 |
-
|
5144 |
-
|
5145 |
-
};
|
5146 |
-
}
|
5147 |
}
|
5148 |
|
5149 |
-
createInjector.$$annotate = annotate;
|
5150 |
|
5151 |
-
|
5152 |
-
|
5153 |
-
|
5154 |
-
|
5155 |
-
|
5156 |
-
|
5157 |
-
|
5158 |
-
|
5159 |
-
|
5160 |
-
|
|
|
5161 |
|
5162 |
-
|
5163 |
|
5164 |
-
|
5165 |
-
|
5166 |
-
|
5167 |
-
|
5168 |
-
|
5169 |
-
|
5170 |
-
|
5171 |
-
|
5172 |
-
|
5173 |
-
|
5174 |
-
* {@link ng.$anchorScroll $anchorScroll()} in order to scroll to the element related to the
|
5175 |
-
* current hash.
|
5176 |
-
*/
|
5177 |
-
this.disableAutoScrolling = function() {
|
5178 |
-
autoScrollingEnabled = false;
|
5179 |
-
};
|
5180 |
|
5181 |
-
|
5182 |
-
|
5183 |
-
|
5184 |
-
|
5185 |
-
|
5186 |
-
|
5187 |
-
|
5188 |
-
|
5189 |
-
|
5190 |
-
|
5191 |
-
|
5192 |
-
|
5193 |
-
|
5194 |
-
|
5195 |
-
|
5196 |
-
|
5197 |
-
|
5198 |
-
|
5199 |
-
|
5200 |
-
|
5201 |
-
|
5202 |
-
|
5203 |
-
|
5204 |
-
|
5205 |
-
|
5206 |
-
|
5207 |
-
|
5208 |
-
|
5209 |
-
|
5210 |
-
|
5211 |
-
|
5212 |
-
|
5213 |
-
|
5214 |
-
|
5215 |
-
|
5216 |
-
|
5217 |
-
|
5218 |
-
|
5219 |
-
|
5220 |
-
|
5221 |
-
|
5222 |
-
|
5223 |
-
|
5224 |
-
|
5225 |
-
|
5226 |
-
|
5227 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5228 |
<div id="scrollArea" ng-controller="ScrollController">
|
5229 |
-
|
5230 |
-
|
5231 |
</div>
|
5232 |
-
|
5233 |
-
|
5234 |
angular.module('anchorScrollExample', [])
|
5235 |
-
|
5236 |
-
|
5237 |
$scope.gotoBottom = function() {
|
5238 |
// set the location.hash to the id of
|
5239 |
// the element you wish to scroll to.
|
@@ -5243,8 +5243,8 @@
|
|
5243 |
$anchorScroll();
|
5244 |
};
|
5245 |
}]);
|
5246 |
-
|
5247 |
-
|
5248 |
#scrollArea {
|
5249 |
height: 280px;
|
5250 |
overflow: auto;
|
@@ -5254,32 +5254,32 @@
|
|
5254 |
display: block;
|
5255 |
margin-top: 2000px;
|
5256 |
}
|
5257 |
-
|
5258 |
-
|
5259 |
-
|
5260 |
-
|
5261 |
-
|
5262 |
-
|
5263 |
-
|
5264 |
-
|
5265 |
-
|
5266 |
-
|
5267 |
<div class="fixed-header" ng-controller="headerCtrl">
|
5268 |
-
|
5269 |
-
|
5270 |
-
|
5271 |
</div>
|
5272 |
<div id="anchor{{x}}" class="anchor" ng-repeat="x in [1,2,3,4,5]">
|
5273 |
-
|
5274 |
</div>
|
5275 |
-
|
5276 |
-
|
5277 |
angular.module('anchorScrollOffsetExample', [])
|
5278 |
-
|
5279 |
$anchorScroll.yOffset = 50; // always scroll by 50 extra pixels
|
5280 |
}])
|
5281 |
-
|
5282 |
-
|
5283 |
$scope.gotoAnchor = function(x) {
|
5284 |
var newHash = 'anchor' + x;
|
5285 |
if ($location.hash() !== newHash) {
|
@@ -5293,9 +5293,9 @@
|
|
5293 |
}
|
5294 |
};
|
5295 |
}
|
5296 |
-
|
5297 |
-
|
5298 |
-
|
5299 |
body {
|
5300 |
padding-top: 50px;
|
5301 |
}
|
@@ -5316,150 +5316,150 @@
|
|
5316 |
display: inline-block;
|
5317 |
margin: 5px 15px;
|
5318 |
}
|
5319 |
-
|
5320 |
-
|
5321 |
-
|
5322 |
-
|
5323 |
-
|
5324 |
-
|
5325 |
-
|
5326 |
-
|
5327 |
-
|
5328 |
-
|
5329 |
-
|
5330 |
-
|
5331 |
-
|
5332 |
-
|
5333 |
-
|
5334 |
-
|
5335 |
-
|
5336 |
-
|
5337 |
-
|
5338 |
-
|
5339 |
-
function getYOffset() {
|
5340 |
-
|
5341 |
-
var offset = scroll.yOffset;
|
5342 |
|
5343 |
-
|
5344 |
-
offset = offset();
|
5345 |
-
} else if (isElement(offset)) {
|
5346 |
-
var elem = offset[0];
|
5347 |
-
var style = $window.getComputedStyle(elem);
|
5348 |
-
if (style.position !== 'fixed') {
|
5349 |
-
offset = 0;
|
5350 |
-
} else {
|
5351 |
-
offset = elem.getBoundingClientRect().bottom;
|
5352 |
-
}
|
5353 |
-
} else if (!isNumber(offset)) {
|
5354 |
-
offset = 0;
|
5355 |
-
}
|
5356 |
|
5357 |
-
|
5358 |
-
}
|
5359 |
|
5360 |
-
|
5361 |
-
|
5362 |
-
|
5363 |
-
|
5364 |
-
|
5365 |
-
|
5366 |
-
|
5367 |
-
|
5368 |
-
|
5369 |
-
|
5370 |
-
|
5371 |
-
|
5372 |
-
|
5373 |
-
// way down the page.
|
5374 |
-
//
|
5375 |
-
// This is often the case for elements near the bottom of the page.
|
5376 |
-
//
|
5377 |
-
// In such cases we do not need to scroll the whole `offset` up, just the difference between
|
5378 |
-
// the top of the element and the offset, which is enough to align the top of `elem` at the
|
5379 |
-
// desired position.
|
5380 |
-
var elemTop = elem.getBoundingClientRect().top;
|
5381 |
-
$window.scrollBy(0, elemTop - offset);
|
5382 |
-
}
|
5383 |
-
} else {
|
5384 |
-
$window.scrollTo(0, 0);
|
5385 |
-
}
|
5386 |
-
}
|
5387 |
|
5388 |
-
|
5389 |
-
|
5390 |
-
|
5391 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5392 |
|
5393 |
-
|
5394 |
-
|
|
|
|
|
5395 |
|
5396 |
-
|
5397 |
-
|
5398 |
|
5399 |
-
|
5400 |
-
|
5401 |
|
5402 |
-
|
5403 |
-
|
5404 |
-
}
|
5405 |
|
5406 |
-
|
5407 |
-
|
5408 |
-
|
5409 |
-
$rootScope.$watch(function autoScrollWatch() {return $location.hash();},
|
5410 |
-
function autoScrollWatchAction(newVal, oldVal) {
|
5411 |
-
// skip the initial scroll if $location.hash is empty
|
5412 |
-
if (newVal === oldVal && newVal === '') return;
|
5413 |
|
5414 |
-
|
5415 |
-
|
5416 |
-
|
5417 |
-
|
5418 |
-
|
|
|
|
|
5419 |
|
5420 |
-
|
5421 |
-
|
|
|
|
|
5422 |
}
|
5423 |
|
5424 |
-
|
5425 |
-
|
5426 |
-
|
5427 |
|
5428 |
-
|
5429 |
-
|
5430 |
-
|
5431 |
-
|
5432 |
-
|
5433 |
-
|
5434 |
-
|
5435 |
-
|
|
|
|
|
|
|
|
|
5436 |
|
5437 |
-
|
5438 |
-
|
5439 |
-
|
5440 |
-
|
5441 |
-
|
5442 |
-
}
|
5443 |
-
}
|
5444 |
}
|
|
|
|
|
5445 |
|
5446 |
-
|
5447 |
-
|
5448 |
-
|
5449 |
-
|
5450 |
|
5451 |
-
|
5452 |
-
|
5453 |
-
|
5454 |
-
|
5455 |
-
|
5456 |
-
|
5457 |
-
|
5458 |
-
|
5459 |
-
}
|
5460 |
-
});
|
5461 |
-
return obj;
|
5462 |
}
|
|
|
|
|
|
|
5463 |
|
5464 |
// if any other type of options value besides an Object value is
|
5465 |
// passed into the $animate.method() animation then this helper code
|
@@ -5468,167 +5468,167 @@
|
|
5468 |
// $animate to either call the callback (< 1.2) or return a promise
|
5469 |
// that can be changed. This helper function ensures that the options
|
5470 |
// are wiped clean incase a callback function is provided.
|
5471 |
-
|
5472 |
-
|
5473 |
-
|
5474 |
-
|
5475 |
-
|
5476 |
|
5477 |
-
|
5478 |
-
|
5479 |
-
|
5480 |
|
5481 |
// this is prefixed with Core since it conflicts with
|
5482 |
// the animateQueueProvider defined in ngAnimate/animateQueue.js
|
5483 |
-
|
5484 |
-
|
5485 |
-
|
5486 |
-
|
5487 |
-
this.$get = ['$$AnimateRunner', '$rootScope',
|
5488 |
-
function($$AnimateRunner, $rootScope) {
|
5489 |
-
return {
|
5490 |
-
enabled: noop,
|
5491 |
-
on: noop,
|
5492 |
-
off: noop,
|
5493 |
-
pin: noop,
|
5494 |
-
|
5495 |
-
push: function(element, event, options, domOperation) {
|
5496 |
-
if (domOperation) {
|
5497 |
-
domOperation();
|
5498 |
-
}
|
5499 |
|
5500 |
-
|
5501 |
-
|
5502 |
-
|
5503 |
-
|
5504 |
-
|
5505 |
-
|
5506 |
-
|
5507 |
|
5508 |
-
|
5509 |
-
|
5510 |
-
|
|
|
5511 |
|
5512 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
5513 |
|
5514 |
-
|
5515 |
-
|
5516 |
-
|
5517 |
-
return runner;
|
5518 |
-
}
|
5519 |
-
};
|
5520 |
|
|
|
5521 |
|
5522 |
-
|
5523 |
-
|
5524 |
-
|
5525 |
-
|
5526 |
-
|
5527 |
-
|
5528 |
-
if (className) {
|
5529 |
-
changed = true;
|
5530 |
-
data[className] = value;
|
5531 |
-
}
|
5532 |
-
});
|
5533 |
-
}
|
5534 |
-
return changed;
|
5535 |
-
}
|
5536 |
|
5537 |
-
function handleCSSClassChanges() {
|
5538 |
-
forEach(postDigestElements, function(element) {
|
5539 |
-
var data = postDigestQueue.get(element);
|
5540 |
-
if (data) {
|
5541 |
-
var existing = splitClasses(element.attr('class'));
|
5542 |
-
var toAdd = '';
|
5543 |
-
var toRemove = '';
|
5544 |
-
forEach(data, function(status, className) {
|
5545 |
-
var hasClass = !!existing[className];
|
5546 |
-
if (status !== hasClass) {
|
5547 |
-
if (status) {
|
5548 |
-
toAdd += (toAdd.length ? ' ' : '') + className;
|
5549 |
-
} else {
|
5550 |
-
toRemove += (toRemove.length ? ' ' : '') + className;
|
5551 |
-
}
|
5552 |
-
}
|
5553 |
-
});
|
5554 |
|
5555 |
-
|
5556 |
-
|
5557 |
-
|
5558 |
-
|
5559 |
-
|
5560 |
-
|
5561 |
-
|
5562 |
-
|
5563 |
-
|
5564 |
-
|
5565 |
-
|
5566 |
-
|
5567 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5568 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5569 |
|
5570 |
-
function addRemoveClassesPostDigest(element, add, remove) {
|
5571 |
-
var data = postDigestQueue.get(element) || {};
|
5572 |
|
5573 |
-
|
5574 |
-
|
5575 |
|
5576 |
-
|
|
|
5577 |
|
5578 |
-
|
5579 |
-
postDigestElements.push(element);
|
5580 |
|
5581 |
-
|
5582 |
-
|
5583 |
-
}
|
5584 |
-
}
|
5585 |
-
}
|
5586 |
-
}];
|
5587 |
-
};
|
5588 |
|
5589 |
-
|
5590 |
-
|
5591 |
-
|
5592 |
-
|
5593 |
-
|
5594 |
-
|
5595 |
-
|
5596 |
-
*
|
5597 |
-
* In order to enable animations the `ngAnimate` module has to be loaded.
|
5598 |
-
*
|
5599 |
-
* To see the functional implementation check out `src/ngAnimate/animate.js`.
|
5600 |
-
*/
|
5601 |
-
var $AnimateProvider = ['$provide', /** @this */ function($provide) {
|
5602 |
-
var provider = this;
|
5603 |
-
var classNameFilter = null;
|
5604 |
-
var customFilter = null;
|
5605 |
|
5606 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5607 |
|
5608 |
-
|
5609 |
-
|
5610 |
-
|
5611 |
-
|
5612 |
-
|
5613 |
-
|
5614 |
-
|
5615 |
-
|
5616 |
-
|
5617 |
-
|
5618 |
-
|
5619 |
-
|
5620 |
-
|
5621 |
-
|
5622 |
-
|
5623 |
-
|
5624 |
-
|
5625 |
-
|
5626 |
-
|
5627 |
-
|
5628 |
-
|
5629 |
-
|
5630 |
-
|
5631 |
-
|
|
|
|
|
5632 |
* //enter, leave, move signature
|
5633 |
* eventFn : function(element, done, options) {
|
5634 |
* //code to run the animation
|
@@ -5638,288 +5638,288 @@
|
|
5638 |
* }
|
5639 |
* }
|
5640 |
* }
|
5641 |
-
|
5642 |
-
|
5643 |
-
|
5644 |
-
|
5645 |
-
|
5646 |
-
|
5647 |
-
|
5648 |
-
|
5649 |
-
|
5650 |
-
|
5651 |
|
5652 |
-
|
5653 |
-
|
5654 |
-
|
5655 |
-
|
5656 |
|
5657 |
-
|
5658 |
-
|
5659 |
-
|
5660 |
-
|
5661 |
-
|
5662 |
-
|
5663 |
-
|
5664 |
-
|
5665 |
-
|
5666 |
-
|
5667 |
-
|
5668 |
-
|
5669 |
-
|
5670 |
-
|
5671 |
-
|
5672 |
-
|
5673 |
-
|
5674 |
-
|
5675 |
-
|
5676 |
-
|
5677 |
-
|
5678 |
-
|
5679 |
-
|
5680 |
-
|
5681 |
-
|
5682 |
-
|
5683 |
-
|
5684 |
-
|
5685 |
-
|
5686 |
-
|
5687 |
-
|
5688 |
-
|
5689 |
-
|
5690 |
-
|
5691 |
-
|
5692 |
-
|
5693 |
-
|
5694 |
-
|
5695 |
-
|
5696 |
-
|
5697 |
-
|
5698 |
|
5699 |
-
|
5700 |
-
|
5701 |
|
5702 |
-
|
5703 |
-
|
5704 |
-
|
5705 |
-
|
5706 |
-
|
5707 |
-
|
5708 |
-
|
5709 |
-
|
5710 |
-
|
5711 |
-
|
5712 |
-
|
5713 |
-
|
5714 |
-
|
5715 |
-
|
5716 |
-
|
5717 |
-
|
5718 |
-
|
5719 |
-
|
5720 |
-
|
5721 |
-
|
5722 |
-
|
5723 |
-
|
5724 |
-
|
5725 |
-
|
5726 |
-
|
5727 |
-
|
5728 |
-
|
5729 |
-
|
5730 |
-
|
5731 |
-
|
5732 |
-
|
5733 |
-
|
5734 |
|
5735 |
-
|
5736 |
-
|
5737 |
-
|
5738 |
-
|
5739 |
-
|
5740 |
-
|
5741 |
-
|
5742 |
-
|
5743 |
-
|
5744 |
-
|
5745 |
-
|
5746 |
-
|
5747 |
-
|
5748 |
-
|
5749 |
-
|
5750 |
-
|
5751 |
-
|
5752 |
|
5753 |
-
|
5754 |
-
|
5755 |
-
|
5756 |
-
|
5757 |
-
|
5758 |
-
|
5759 |
-
|
5760 |
-
|
5761 |
-
|
5762 |
-
|
5763 |
-
|
5764 |
-
|
5765 |
-
|
5766 |
-
|
5767 |
-
|
5768 |
-
|
5769 |
-
|
5770 |
-
|
5771 |
-
|
5772 |
-
|
5773 |
-
|
5774 |
-
|
5775 |
-
|
5776 |
-
|
5777 |
-
|
5778 |
-
|
5779 |
-
|
5780 |
-
|
5781 |
-
|
5782 |
-
|
5783 |
-
|
5784 |
-
|
5785 |
-
|
5786 |
-
|
5787 |
-
|
5788 |
* // cool we detected an enter animation within the container
|
5789 |
* }
|
5790 |
-
|
5791 |
-
|
5792 |
-
|
5793 |
-
|
5794 |
-
|
5795 |
-
|
5796 |
-
|
5797 |
-
|
5798 |
-
|
5799 |
-
|
5800 |
-
|
5801 |
-
|
5802 |
-
|
5803 |
-
|
5804 |
-
|
5805 |
-
|
5806 |
-
|
5807 |
-
|
5808 |
-
|
5809 |
-
|
5810 |
-
|
5811 |
-
|
5812 |
-
|
5813 |
-
|
5814 |
-
|
5815 |
-
|
5816 |
-
|
5817 |
-
|
5818 |
-
|
5819 |
-
|
5820 |
-
|
5821 |
-
|
5822 |
-
|
5823 |
-
|
5824 |
-
|
5825 |
-
|
5826 |
-
|
5827 |
-
|
5828 |
-
|
5829 |
-
|
5830 |
-
|
5831 |
-
|
5832 |
-
|
5833 |
-
|
5834 |
-
|
5835 |
-
|
5836 |
-
|
5837 |
-
|
5838 |
-
|
5839 |
-
|
5840 |
-
|
5841 |
-
|
5842 |
-
|
5843 |
-
|
5844 |
-
|
5845 |
-
|
5846 |
-
|
5847 |
-
|
5848 |
-
|
5849 |
-
|
5850 |
-
|
5851 |
-
|
5852 |
-
|
5853 |
-
|
5854 |
-
|
5855 |
-
|
5856 |
-
|
5857 |
-
|
5858 |
-
|
5859 |
-
|
5860 |
-
|
5861 |
-
|
5862 |
-
|
5863 |
-
|
5864 |
-
|
5865 |
-
|
5866 |
-
|
5867 |
-
|
5868 |
-
|
5869 |
-
|
5870 |
-
|
5871 |
-
|
5872 |
-
|
5873 |
-
|
5874 |
-
|
5875 |
-
|
5876 |
-
|
5877 |
-
|
5878 |
-
|
5879 |
-
|
5880 |
-
|
5881 |
-
|
5882 |
-
|
5883 |
-
|
5884 |
-
|
5885 |
-
|
5886 |
-
|
5887 |
-
|
5888 |
-
|
5889 |
-
|
5890 |
-
|
5891 |
-
|
5892 |
-
|
5893 |
-
|
5894 |
-
|
5895 |
-
|
5896 |
-
|
5897 |
-
|
5898 |
-
|
5899 |
-
|
5900 |
-
|
5901 |
-
|
5902 |
-
|
5903 |
-
|
5904 |
-
|
5905 |
-
|
5906 |
-
|
5907 |
-
|
5908 |
-
|
5909 |
-
|
5910 |
-
|
5911 |
-
|
5912 |
-
|
5913 |
-
|
5914 |
-
|
5915 |
-
|
5916 |
-
|
5917 |
-
|
5918 |
-
|
5919 |
-
|
5920 |
-
|
5921 |
-
|
5922 |
-
|
5923 |
templateUrl: 'template.html',
|
5924 |
controller: function($element, $animate) {
|
5925 |
this.runner = null;
|
@@ -5945,239 +5945,239 @@
|
|
5945 |
};
|
5946 |
}
|
5947 |
});
|
5948 |
-
|
5949 |
-
|
5950 |
-
|
5951 |
-
|
5952 |
-
|
5953 |
-
|
5954 |
-
|
5955 |
-
|
5956 |
-
|
5957 |
-
|
5958 |
-
|
5959 |
-
|
5960 |
-
|
5961 |
-
|
5962 |
-
|
5963 |
-
|
5964 |
transition: all 4s cubic-bezier(0.250, 0.460, 0.450, 0.940);
|
5965 |
}
|
5966 |
|
5967 |
-
|
5968 |
-
|
5969 |
color: #FF0000;
|
5970 |
font-size: 40px;
|
5971 |
}
|
5972 |
|
5973 |
-
|
5974 |
font-size: 10px;
|
5975 |
color: black;
|
5976 |
}
|
5977 |
|
5978 |
-
|
5979 |
-
|
5980 |
-
|
5981 |
-
|
5982 |
-
|
5983 |
-
|
5984 |
-
|
5985 |
-
|
5986 |
|
5987 |
-
|
5988 |
-
|
5989 |
-
|
5990 |
-
|
5991 |
-
|
5992 |
-
|
5993 |
-
|
5994 |
-
|
5995 |
-
|
5996 |
-
|
5997 |
-
|
5998 |
-
|
5999 |
-
|
6000 |
-
|
6001 |
-
|
6002 |
-
|
6003 |
-
|
6004 |
-
|
6005 |
-
|
6006 |
-
|
6007 |
-
|
6008 |
-
|
6009 |
-
|
6010 |
-
|
6011 |
-
|
6012 |
-
|
6013 |
-
|
6014 |
-
|
6015 |
-
|
6016 |
-
|
6017 |
-
|
6018 |
|
6019 |
-
|
6020 |
-
|
6021 |
-
|
6022 |
-
|
6023 |
-
|
6024 |
-
|
6025 |
-
|
6026 |
-
|
6027 |
-
|
6028 |
-
|
6029 |
-
|
6030 |
-
|
6031 |
-
|
6032 |
-
|
6033 |
-
|
6034 |
-
|
6035 |
-
|
6036 |
-
|
6037 |
-
|
6038 |
-
|
6039 |
-
|
6040 |
-
|
6041 |
-
|
6042 |
-
|
6043 |
-
|
6044 |
-
|
6045 |
-
|
6046 |
-
|
6047 |
-
|
6048 |
-
|
6049 |
-
|
6050 |
|
6051 |
-
|
6052 |
-
|
6053 |
-
|
6054 |
-
|
6055 |
-
|
6056 |
-
|
6057 |
-
|
6058 |
-
|
6059 |
-
|
6060 |
-
|
6061 |
-
|
6062 |
-
|
6063 |
-
|
6064 |
-
|
6065 |
-
|
6066 |
-
|
6067 |
-
|
6068 |
-
|
6069 |
-
|
6070 |
-
|
6071 |
-
|
6072 |
-
|
6073 |
-
|
6074 |
-
|
6075 |
|
6076 |
-
|
6077 |
-
|
6078 |
-
|
6079 |
-
|
6080 |
-
|
6081 |
-
|
6082 |
-
|
6083 |
-
|
6084 |
-
|
6085 |
-
|
6086 |
-
|
6087 |
-
|
6088 |
-
|
6089 |
-
|
6090 |
-
|
6091 |
-
|
6092 |
-
|
6093 |
-
|
6094 |
-
|
6095 |
-
|
6096 |
-
|
6097 |
-
|
6098 |
-
|
6099 |
-
|
6100 |
-
|
6101 |
-
|
6102 |
-
|
6103 |
-
|
6104 |
|
6105 |
-
|
6106 |
-
|
6107 |
-
|
6108 |
-
|
6109 |
-
|
6110 |
-
|
6111 |
-
|
6112 |
-
|
6113 |
-
|
6114 |
-
|
6115 |
-
|
6116 |
-
|
6117 |
-
|
6118 |
-
|
6119 |
-
|
6120 |
-
|
6121 |
-
|
6122 |
-
|
6123 |
-
|
6124 |
-
|
6125 |
-
|
6126 |
-
|
6127 |
-
|
6128 |
-
|
6129 |
-
|
6130 |
-
|
6131 |
-
|
6132 |
-
|
6133 |
|
6134 |
-
|
6135 |
-
|
6136 |
-
|
6137 |
-
|
6138 |
-
|
6139 |
-
|
6140 |
-
|
6141 |
-
|
6142 |
-
|
6143 |
-
|
6144 |
-
|
6145 |
-
|
6146 |
-
|
6147 |
-
|
6148 |
-
|
6149 |
-
|
6150 |
-
|
6151 |
-
|
6152 |
-
|
6153 |
-
|
6154 |
-
|
6155 |
-
|
6156 |
-
|
6157 |
-
|
6158 |
-
|
6159 |
-
|
6160 |
-
|
6161 |
-
|
6162 |
-
|
6163 |
-
|
6164 |
-
|
6165 |
|
6166 |
-
|
6167 |
-
|
6168 |
-
|
6169 |
-
|
6170 |
-
|
6171 |
-
|
6172 |
-
|
6173 |
-
|
6174 |
-
|
6175 |
-
|
6176 |
-
|
6177 |
-
|
6178 |
-
|
6179 |
-
|
6180 |
-
|
6181 |
* return {
|
6182 |
* animate : function(element, from, to, done, options) {
|
6183 |
* //animation
|
@@ -6185,711 +6185,711 @@
|
|
6185 |
* }
|
6186 |
* }
|
6187 |
* });
|
6188 |
-
|
6189 |
-
|
6190 |
-
|
6191 |
-
|
6192 |
-
|
6193 |
-
|
6194 |
-
|
6195 |
-
|
6196 |
-
|
6197 |
-
|
6198 |
-
|
6199 |
-
|
6200 |
-
|
6201 |
-
|
6202 |
-
|
6203 |
-
|
6204 |
-
|
6205 |
-
|
6206 |
-
|
6207 |
-
|
6208 |
-
|
6209 |
-
|
6210 |
-
|
6211 |
-
|
6212 |
-
|
6213 |
-
|
6214 |
-
|
6215 |
-
|
6216 |
-
|
6217 |
-
|
6218 |
|
6219 |
-
|
6220 |
-
|
6221 |
-
|
6222 |
|
6223 |
-
|
6224 |
-
|
6225 |
-
|
6226 |
-
|
6227 |
-
|
6228 |
-
|
6229 |
-
|
6230 |
-
|
6231 |
-
|
6232 |
-
|
6233 |
|
6234 |
-
|
6235 |
-
|
6236 |
-
|
6237 |
-
|
6238 |
-
|
6239 |
-
|
6240 |
-
|
6241 |
-
|
6242 |
-
|
6243 |
-
|
6244 |
-
|
6245 |
-
|
6246 |
-
};
|
6247 |
-
}];
|
6248 |
};
|
|
|
|
|
6249 |
|
6250 |
-
|
6251 |
-
|
6252 |
-
|
6253 |
|
6254 |
-
|
6255 |
-
|
6256 |
-
|
6257 |
|
6258 |
-
|
6259 |
-
|
6260 |
|
6261 |
-
|
6262 |
-
|
6263 |
-
|
6264 |
-
|
6265 |
-
|
6266 |
-
|
6267 |
|
6268 |
-
|
6269 |
-
|
6270 |
-
|
6271 |
-
|
6272 |
-
|
6273 |
-
|
6274 |
-
|
6275 |
-
|
6276 |
-
|
6277 |
-
|
6278 |
|
6279 |
-
|
6280 |
-
|
6281 |
-
|
6282 |
-
|
6283 |
-
|
6284 |
-
|
6285 |
|
6286 |
-
|
6287 |
-
|
6288 |
-
|
6289 |
-
|
6290 |
-
|
6291 |
-
|
6292 |
-
|
6293 |
|
6294 |
-
|
6295 |
-
|
6296 |
|
6297 |
-
|
6298 |
-
|
6299 |
-
|
6300 |
-
|
6301 |
|
6302 |
-
|
6303 |
-
|
6304 |
-
|
6305 |
-
|
6306 |
-
|
6307 |
-
|
6308 |
-
|
6309 |
-
|
6310 |
-
|
6311 |
-
|
6312 |
|
6313 |
-
|
6314 |
-
|
6315 |
-
|
6316 |
-
|
6317 |
|
6318 |
-
|
6319 |
-
|
6320 |
-
|
6321 |
-
|
6322 |
-
|
6323 |
-
|
6324 |
-
|
6325 |
-
|
6326 |
-
progress: noop,
|
6327 |
-
|
6328 |
-
getPromise: function() {
|
6329 |
-
if (!this.promise) {
|
6330 |
-
var self = this;
|
6331 |
-
this.promise = $q(function(resolve, reject) {
|
6332 |
-
self.done(function(status) {
|
6333 |
-
if (status === false) {
|
6334 |
-
reject();
|
6335 |
-
} else {
|
6336 |
-
resolve();
|
6337 |
-
}
|
6338 |
-
});
|
6339 |
-
});
|
6340 |
-
}
|
6341 |
-
return this.promise;
|
6342 |
-
},
|
6343 |
|
6344 |
-
|
6345 |
-
|
6346 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6347 |
|
6348 |
-
|
6349 |
-
|
6350 |
-
|
6351 |
|
6352 |
-
|
6353 |
-
|
6354 |
-
|
6355 |
-
|
6356 |
-
pause: function() {
|
6357 |
-
if (this.host.pause) {
|
6358 |
-
this.host.pause();
|
6359 |
-
}
|
6360 |
-
},
|
6361 |
-
|
6362 |
-
resume: function() {
|
6363 |
-
if (this.host.resume) {
|
6364 |
-
this.host.resume();
|
6365 |
-
}
|
6366 |
-
},
|
6367 |
-
|
6368 |
-
end: function() {
|
6369 |
-
if (this.host.end) {
|
6370 |
-
this.host.end();
|
6371 |
-
}
|
6372 |
-
this._resolve(true);
|
6373 |
-
},
|
6374 |
-
|
6375 |
-
cancel: function() {
|
6376 |
-
if (this.host.cancel) {
|
6377 |
-
this.host.cancel();
|
6378 |
-
}
|
6379 |
-
this._resolve(false);
|
6380 |
-
},
|
6381 |
-
|
6382 |
-
complete: function(response) {
|
6383 |
-
var self = this;
|
6384 |
-
if (self._state === INITIAL_STATE) {
|
6385 |
-
self._state = DONE_PENDING_STATE;
|
6386 |
-
self._tick(function() {
|
6387 |
-
self._resolve(response);
|
6388 |
-
});
|
6389 |
-
}
|
6390 |
-
},
|
6391 |
-
|
6392 |
-
_resolve: function(response) {
|
6393 |
-
if (this._state !== DONE_COMPLETE_STATE) {
|
6394 |
-
forEach(this._doneCallbacks, function(fn) {
|
6395 |
-
fn(response);
|
6396 |
-
});
|
6397 |
-
this._doneCallbacks.length = 0;
|
6398 |
-
this._state = DONE_COMPLETE_STATE;
|
6399 |
-
}
|
6400 |
-
}
|
6401 |
-
};
|
6402 |
-
|
6403 |
-
return AnimateRunner;
|
6404 |
-
}];
|
6405 |
-
};
|
6406 |
|
6407 |
-
|
|
|
|
|
6408 |
|
6409 |
-
|
6410 |
-
|
6411 |
-
|
6412 |
-
|
6413 |
-
|
6414 |
-
*
|
6415 |
-
* @description
|
6416 |
-
* This is the core version of `$animateCss`. By default, only when the `ngAnimate` is included,
|
6417 |
-
* then the `$animateCss` service will actually perform animations.
|
6418 |
-
*
|
6419 |
-
* Click here {@link ngAnimate.$animateCss to read the documentation for $animateCss}.
|
6420 |
-
*/
|
6421 |
-
var $CoreAnimateCssProvider = function() {
|
6422 |
-
this.$get = ['$$rAF', '$q', '$$AnimateRunner', function($$rAF, $q, $$AnimateRunner) {
|
6423 |
-
|
6424 |
-
return function(element, initialOptions) {
|
6425 |
-
// all of the animation functions should create
|
6426 |
-
// a copy of the options data, however, if a
|
6427 |
-
// parent service has already created a copy then
|
6428 |
-
// we should stick to using that
|
6429 |
-
var options = initialOptions || {};
|
6430 |
-
if (!options.$$prepared) {
|
6431 |
-
options = copy(options);
|
6432 |
-
}
|
6433 |
|
6434 |
-
|
6435 |
-
|
6436 |
-
|
6437 |
-
|
6438 |
-
|
6439 |
-
}
|
6440 |
|
6441 |
-
|
6442 |
-
|
6443 |
-
|
6444 |
-
|
|
|
|
|
6445 |
|
6446 |
-
|
6447 |
-
|
6448 |
-
|
6449 |
-
|
6450 |
-
|
|
|
6451 |
|
6452 |
-
|
6453 |
-
|
6454 |
-
|
6455 |
-
|
6456 |
-
|
6457 |
-
|
6458 |
-
|
6459 |
-
|
6460 |
-
|
6461 |
-
}
|
6462 |
|
6463 |
-
|
6464 |
-
|
6465 |
-
|
6466 |
-
|
6467 |
-
|
6468 |
-
|
6469 |
-
|
6470 |
-
|
6471 |
-
|
6472 |
-
if (options.to) {
|
6473 |
-
element.css(options.to);
|
6474 |
-
options.to = null;
|
6475 |
-
}
|
6476 |
-
}
|
6477 |
-
};
|
6478 |
-
}];
|
6479 |
};
|
6480 |
|
6481 |
-
|
|
|
|
|
6482 |
|
6483 |
-
|
6484 |
-
var index = url.indexOf('#');
|
6485 |
-
return index === -1 ? '' : url.substr(index);
|
6486 |
-
}
|
6487 |
|
6488 |
-
|
6489 |
-
|
6490 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6491 |
|
6492 |
-
|
6493 |
-
|
6494 |
-
|
6495 |
-
|
6496 |
-
|
6497 |
-
|
6498 |
-
* This object has two goals:
|
6499 |
-
*
|
6500 |
-
* - hide all the global state in the browser caused by the window object
|
6501 |
-
* - abstract away all the browser specific features and inconsistencies
|
6502 |
-
*
|
6503 |
-
* For tests we provide {@link ngMock.$browser mock implementation} of the `$browser`
|
6504 |
-
* service, which can be used for convenient testing of the application without the interaction with
|
6505 |
-
* the real browser apis.
|
6506 |
-
*/
|
6507 |
-
/**
|
6508 |
-
* @param {object} window The global window object.
|
6509 |
-
* @param {object} document jQuery wrapped document.
|
6510 |
-
* @param {object} $log window.console or an object with the same interface.
|
6511 |
-
* @param {object} $sniffer $sniffer service
|
6512 |
-
*/
|
6513 |
-
function Browser(window, document, $log, $sniffer, $$taskTrackerFactory) {
|
6514 |
-
var self = this,
|
6515 |
-
location = window.location,
|
6516 |
-
history = window.history,
|
6517 |
-
setTimeout = window.setTimeout,
|
6518 |
-
clearTimeout = window.clearTimeout,
|
6519 |
-
pendingDeferIds = {},
|
6520 |
-
taskTracker = $$taskTrackerFactory($log);
|
6521 |
-
|
6522 |
-
self.isMock = false;
|
6523 |
-
|
6524 |
-
//////////////////////////////////////////////////////////////
|
6525 |
-
// Task-tracking API
|
6526 |
-
//////////////////////////////////////////////////////////////
|
6527 |
-
|
6528 |
-
// TODO(vojta): remove this temporary api
|
6529 |
-
self.$$completeOutstandingRequest = taskTracker.completeTask;
|
6530 |
-
self.$$incOutstandingRequestCount = taskTracker.incTaskCount;
|
6531 |
-
|
6532 |
-
// TODO(vojta): prefix this method with $$ ?
|
6533 |
-
self.notifyWhenNoOutstandingRequests = taskTracker.notifyWhenNoPendingTasks;
|
6534 |
-
|
6535 |
-
//////////////////////////////////////////////////////////////
|
6536 |
-
// URL API
|
6537 |
-
//////////////////////////////////////////////////////////////
|
6538 |
-
|
6539 |
-
var cachedState, lastHistoryState,
|
6540 |
-
lastBrowserUrl = location.href,
|
6541 |
-
baseElement = document.find('base'),
|
6542 |
-
pendingLocation = null,
|
6543 |
-
getCurrentState = !$sniffer.history ? noop : function getCurrentState() {
|
6544 |
-
try {
|
6545 |
-
return history.state;
|
6546 |
-
} catch (e) {
|
6547 |
-
// MSIE can reportedly throw when there is no state (UNCONFIRMED).
|
6548 |
-
}
|
6549 |
-
};
|
6550 |
|
6551 |
-
|
|
|
|
|
|
|
6552 |
|
6553 |
-
|
6554 |
-
|
6555 |
-
|
6556 |
-
|
6557 |
-
|
6558 |
-
|
6559 |
-
|
6560 |
-
|
6561 |
-
|
6562 |
-
|
6563 |
-
|
6564 |
-
|
6565 |
-
|
6566 |
-
|
6567 |
-
|
6568 |
-
|
6569 |
-
*
|
6570 |
-
* @param {string} url New url (when used as setter)
|
6571 |
-
* @param {boolean=} replace Should new url replace current history record?
|
6572 |
-
* @param {object=} state State object to use with `pushState`/`replaceState`
|
6573 |
-
*/
|
6574 |
-
self.url = function(url, replace, state) {
|
6575 |
-
// In modern browsers `history.state` is `null` by default; treating it separately
|
6576 |
-
// from `undefined` would cause `$browser.url('/foo')` to change `history.state`
|
6577 |
-
// to undefined via `pushState`. Instead, let's change `undefined` to `null` here.
|
6578 |
-
if (isUndefined(state)) {
|
6579 |
-
state = null;
|
6580 |
-
}
|
6581 |
|
6582 |
-
|
6583 |
-
|
6584 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6585 |
|
6586 |
-
|
6587 |
-
if (url) {
|
6588 |
-
var sameState = lastHistoryState === state;
|
6589 |
|
6590 |
-
|
6591 |
-
|
|
|
|
|
6592 |
|
6593 |
-
|
6594 |
-
|
6595 |
-
|
6596 |
-
if (lastBrowserUrl === url && (!$sniffer.history || sameState)) {
|
6597 |
-
return self;
|
6598 |
-
}
|
6599 |
-
var sameBase = lastBrowserUrl && stripHash(lastBrowserUrl) === stripHash(url);
|
6600 |
-
lastBrowserUrl = url;
|
6601 |
-
lastHistoryState = state;
|
6602 |
-
// Don't use history API if only the hash changed
|
6603 |
-
// due to a bug in IE10/IE11 which leads
|
6604 |
-
// to not firing a `hashchange` nor `popstate` event
|
6605 |
-
// in some cases (see #9143).
|
6606 |
-
if ($sniffer.history && (!sameBase || !sameState)) {
|
6607 |
-
history[replace ? 'replaceState' : 'pushState'](state, '', url);
|
6608 |
-
cacheState();
|
6609 |
-
} else {
|
6610 |
-
if (!sameBase) {
|
6611 |
-
pendingLocation = url;
|
6612 |
-
}
|
6613 |
-
if (replace) {
|
6614 |
-
location.replace(url);
|
6615 |
-
} else if (!sameBase) {
|
6616 |
-
location.href = url;
|
6617 |
-
} else {
|
6618 |
-
location.hash = getHash(url);
|
6619 |
-
}
|
6620 |
-
if (location.href !== url) {
|
6621 |
-
pendingLocation = url;
|
6622 |
-
}
|
6623 |
-
}
|
6624 |
-
if (pendingLocation) {
|
6625 |
-
pendingLocation = url;
|
6626 |
-
}
|
6627 |
-
return self;
|
6628 |
-
// getter
|
6629 |
-
} else {
|
6630 |
-
// - pendingLocation is needed as browsers don't allow to read out
|
6631 |
-
// the new location.href if a reload happened or if there is a bug like in iOS 9 (see
|
6632 |
-
// https://openradar.appspot.com/22186109).
|
6633 |
-
return trimEmptyHash(pendingLocation || location.href);
|
6634 |
-
}
|
6635 |
-
};
|
6636 |
|
6637 |
-
|
6638 |
-
|
6639 |
-
|
6640 |
-
|
6641 |
-
|
6642 |
-
|
6643 |
-
|
6644 |
-
|
6645 |
-
|
6646 |
-
|
6647 |
-
|
6648 |
-
|
6649 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6650 |
|
6651 |
-
|
6652 |
-
urlChangeInit = false;
|
6653 |
|
6654 |
-
|
6655 |
-
|
6656 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6657 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6658 |
|
6659 |
-
|
6660 |
-
|
6661 |
-
|
6662 |
-
|
6663 |
-
|
6664 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6665 |
|
6666 |
-
|
6667 |
-
|
6668 |
-
cachedState = lastCachedState;
|
6669 |
-
}
|
6670 |
|
6671 |
-
|
6672 |
-
|
6673 |
-
|
|
|
6674 |
|
6675 |
-
|
6676 |
-
|
6677 |
-
|
|
|
|
|
|
|
6678 |
|
6679 |
-
|
6680 |
-
|
6681 |
-
|
|
|
6682 |
|
6683 |
-
|
6684 |
-
|
6685 |
-
|
6686 |
-
listener(self.url(), cachedState);
|
6687 |
-
});
|
6688 |
-
}
|
6689 |
|
6690 |
-
|
6691 |
-
|
6692 |
-
|
6693 |
-
* @description
|
6694 |
-
* Register callback function that will be called, when url changes.
|
6695 |
-
*
|
6696 |
-
* It's only called when the url is changed from outside of AngularJS:
|
6697 |
-
* - user types different url into address bar
|
6698 |
-
* - user clicks on history (forward/back) button
|
6699 |
-
* - user clicks on a link
|
6700 |
-
*
|
6701 |
-
* It's not called when url is changed by $browser.url() method
|
6702 |
-
*
|
6703 |
-
* The listener gets called with new url as parameter.
|
6704 |
-
*
|
6705 |
-
* NOTE: this api is intended for use only by the $location service. Please use the
|
6706 |
-
* {@link ng.$location $location service} to monitor url changes in AngularJS apps.
|
6707 |
-
*
|
6708 |
-
* @param {function(string)} listener Listener function to be called when url changes.
|
6709 |
-
* @return {function(string)} Returns the registered listener fn - handy if the fn is anonymous.
|
6710 |
-
*/
|
6711 |
-
self.onUrlChange = function(callback) {
|
6712 |
-
// TODO(vojta): refactor to use node's syntax for events
|
6713 |
-
if (!urlChangeInit) {
|
6714 |
-
// We listen on both (hashchange/popstate) when available, as some browsers don't
|
6715 |
-
// fire popstate when user changes the address bar and don't fire hashchange when url
|
6716 |
-
// changed by push/replaceState
|
6717 |
-
|
6718 |
-
// html5 history api - popstate event
|
6719 |
-
if ($sniffer.history) jqLite(window).on('popstate', cacheStateAndFireUrlChange);
|
6720 |
-
// hashchange event
|
6721 |
-
jqLite(window).on('hashchange', cacheStateAndFireUrlChange);
|
6722 |
-
|
6723 |
-
urlChangeInit = true;
|
6724 |
-
}
|
6725 |
|
6726 |
-
|
6727 |
-
|
6728 |
-
|
6729 |
|
6730 |
-
|
6731 |
-
|
6732 |
-
|
6733 |
-
|
6734 |
-
|
6735 |
-
|
6736 |
-
self.$$applicationDestroyed = function() {
|
6737 |
-
jqLite(window).off('hashchange popstate', cacheStateAndFireUrlChange);
|
6738 |
-
};
|
6739 |
|
6740 |
-
|
6741 |
-
|
6742 |
-
|
6743 |
-
|
6744 |
-
|
6745 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6746 |
|
6747 |
-
|
6748 |
-
|
6749 |
-
|
|
|
6750 |
|
6751 |
-
|
6752 |
-
|
6753 |
-
*
|
6754 |
-
* @description
|
6755 |
-
* Returns current <base href>
|
6756 |
-
* (always relative - without domain)
|
6757 |
-
*
|
6758 |
-
* @returns {string} The current base href
|
6759 |
-
*/
|
6760 |
-
self.baseHref = function() {
|
6761 |
-
var href = baseElement.attr('href');
|
6762 |
-
return href ? href.replace(/^(https?:)?\/\/[^/]*/, '') : '';
|
6763 |
-
};
|
6764 |
|
6765 |
-
|
6766 |
-
|
6767 |
-
|
6768 |
-
* @param {number=} [delay=0] Number of milliseconds to defer the function execution.
|
6769 |
-
* @param {string=} [taskType=DEFAULT_TASK_TYPE] The type of task that is deferred.
|
6770 |
-
* @returns {*} DeferId that can be used to cancel the task via `$browser.defer.cancel()`.
|
6771 |
-
*
|
6772 |
-
* @description
|
6773 |
-
* Executes a fn asynchronously via `setTimeout(fn, delay)`.
|
6774 |
-
*
|
6775 |
-
* Unlike when calling `setTimeout` directly, in test this function is mocked and instead of using
|
6776 |
-
* `setTimeout` in tests, the fns are queued in an array, which can be programmatically flushed
|
6777 |
-
* via `$browser.defer.flush()`.
|
6778 |
-
*
|
6779 |
-
*/
|
6780 |
-
self.defer = function(fn, delay, taskType) {
|
6781 |
-
var timeoutId;
|
6782 |
|
6783 |
-
|
6784 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6785 |
|
6786 |
-
|
6787 |
-
|
6788 |
-
|
6789 |
-
taskTracker.completeTask(fn, taskType);
|
6790 |
-
}, delay);
|
6791 |
-
pendingDeferIds[timeoutId] = taskType;
|
6792 |
|
6793 |
-
|
6794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6795 |
|
|
|
|
|
6796 |
|
6797 |
-
|
6798 |
-
|
6799 |
-
|
6800 |
-
|
6801 |
-
|
6802 |
-
|
6803 |
-
|
6804 |
-
|
6805 |
-
|
6806 |
-
*/
|
6807 |
-
self.defer.cancel = function(deferId) {
|
6808 |
-
if (pendingDeferIds.hasOwnProperty(deferId)) {
|
6809 |
-
var taskType = pendingDeferIds[deferId];
|
6810 |
-
delete pendingDeferIds[deferId];
|
6811 |
-
clearTimeout(deferId);
|
6812 |
-
taskTracker.completeTask(noop, taskType);
|
6813 |
-
return true;
|
6814 |
-
}
|
6815 |
-
return false;
|
6816 |
-
};
|
6817 |
|
6818 |
-
}
|
6819 |
|
6820 |
-
|
6821 |
-
|
6822 |
-
|
6823 |
-
|
6824 |
-
|
6825 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6826 |
}
|
|
|
|
|
6827 |
|
6828 |
-
|
6829 |
-
|
6830 |
-
|
6831 |
-
|
6832 |
-
|
6833 |
-
|
6834 |
-
|
6835 |
-
|
6836 |
-
|
6837 |
-
|
6838 |
-
|
6839 |
-
|
6840 |
-
|
6841 |
-
|
6842 |
-
|
6843 |
-
|
6844 |
-
|
6845 |
-
|
6846 |
-
|
6847 |
-
|
6848 |
-
|
6849 |
-
|
6850 |
-
|
6851 |
-
|
6852 |
-
|
6853 |
-
|
6854 |
-
|
6855 |
-
|
6856 |
-
|
6857 |
-
|
6858 |
-
|
6859 |
-
|
6860 |
-
|
6861 |
-
|
6862 |
-
|
6863 |
-
|
6864 |
-
|
6865 |
-
|
6866 |
-
|
6867 |
-
|
6868 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6869 |
<file name="index.html">
|
6870 |
-
|
6871 |
-
|
6872 |
-
|
6873 |
-
|
6874 |
-
|
6875 |
-
|
6876 |
-
|
6877 |
-
|
6878 |
-
|
6879 |
-
|
6880 |
-
|
6881 |
|
6882 |
-
|
6883 |
-
|
6884 |
-
|
6885 |
-
|
6886 |
-
|
6887 |
-
|
6888 |
-
|
6889 |
</file>
|
6890 |
<file name="script.js">
|
6891 |
-
|
6892 |
-
|
6893 |
$scope.keys = [];
|
6894 |
$scope.cache = $cacheFactory('cacheId');
|
6895 |
$scope.put = function(key, value) {
|
@@ -6901,52 +6901,52 @@
|
|
6901 |
}]);
|
6902 |
</file>
|
6903 |
<file name="style.css">
|
6904 |
-
|
6905 |
margin: 10px 0 3px;
|
6906 |
}
|
6907 |
</file>
|
6908 |
-
|
6909 |
-
|
6910 |
-
|
6911 |
|
6912 |
-
|
6913 |
-
|
6914 |
|
6915 |
-
|
6916 |
-
|
6917 |
-
|
6918 |
-
|
6919 |
|
6920 |
-
|
6921 |
-
|
6922 |
-
|
6923 |
-
|
6924 |
-
|
6925 |
-
|
6926 |
-
|
6927 |
-
|
6928 |
-
|
6929 |
-
|
6930 |
-
|
6931 |
-
|
6932 |
-
|
6933 |
-
|
6934 |
-
|
6935 |
-
|
6936 |
-
|
6937 |
-
|
6938 |
-
|
6939 |
-
|
6940 |
* return $cacheFactory('super-cache');
|
6941 |
* }]);
|
6942 |
-
|
6943 |
-
|
6944 |
-
|
6945 |
-
|
6946 |
-
|
6947 |
-
|
6948 |
-
* superCache.put('key', 'value');
|
6949 |
-
* superCache.put('another key', 'another value');
|
6950 |
*
|
6951 |
* expect(superCache.info()).toEqual({
|
6952 |
* id: 'super-cache',
|
@@ -6962,277 +6962,277 @@
|
|
6962 |
* size: 0
|
6963 |
* });
|
6964 |
* }));
|
6965 |
-
|
6966 |
-
|
6967 |
-
|
6968 |
|
6969 |
-
|
6970 |
-
|
6971 |
-
|
6972 |
-
|
6973 |
-
|
6974 |
-
|
6975 |
-
|
6976 |
-
|
6977 |
-
|
6978 |
-
|
6979 |
-
|
6980 |
-
|
6981 |
-
|
6982 |
-
|
6983 |
-
|
6984 |
-
|
6985 |
-
|
6986 |
-
|
6987 |
-
|
6988 |
-
|
6989 |
-
|
6990 |
-
|
6991 |
-
|
6992 |
-
refresh(lruEntry);
|
6993 |
-
}
|
6994 |
|
6995 |
-
|
6996 |
-
|
6997 |
|
6998 |
-
|
6999 |
-
|
7000 |
-
}
|
7001 |
|
7002 |
-
|
7003 |
-
|
|
|
7004 |
|
7005 |
-
|
7006 |
-
|
7007 |
-
* @name $cacheFactory.Cache#get
|
7008 |
-
* @kind function
|
7009 |
-
*
|
7010 |
-
* @description
|
7011 |
-
* Retrieves named data stored in the {@link $cacheFactory.Cache Cache} object.
|
7012 |
-
*
|
7013 |
-
* @param {string} key the key of the data to be retrieved
|
7014 |
-
* @returns {*} the value stored.
|
7015 |
-
*/
|
7016 |
-
get: function(key) {
|
7017 |
-
if (capacity < Number.MAX_VALUE) {
|
7018 |
-
var lruEntry = lruHash[key];
|
7019 |
-
|
7020 |
-
if (!lruEntry) return;
|
7021 |
-
|
7022 |
-
refresh(lruEntry);
|
7023 |
-
}
|
7024 |
|
7025 |
-
|
7026 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7027 |
|
|
|
7028 |
|
7029 |
-
|
7030 |
-
|
7031 |
-
* @name $cacheFactory.Cache#remove
|
7032 |
-
* @kind function
|
7033 |
-
*
|
7034 |
-
* @description
|
7035 |
-
* Removes an entry from the {@link $cacheFactory.Cache Cache} object.
|
7036 |
-
*
|
7037 |
-
* @param {string} key the key of the entry to be removed
|
7038 |
-
*/
|
7039 |
-
remove: function(key) {
|
7040 |
-
if (capacity < Number.MAX_VALUE) {
|
7041 |
-
var lruEntry = lruHash[key];
|
7042 |
-
|
7043 |
-
if (!lruEntry) return;
|
7044 |
-
|
7045 |
-
if (lruEntry === freshEnd) freshEnd = lruEntry.p;
|
7046 |
-
if (lruEntry === staleEnd) staleEnd = lruEntry.n;
|
7047 |
-
link(lruEntry.n,lruEntry.p);
|
7048 |
-
|
7049 |
-
delete lruHash[key];
|
7050 |
-
}
|
7051 |
|
7052 |
-
|
|
|
7053 |
|
7054 |
-
delete data[key];
|
7055 |
-
size--;
|
7056 |
-
},
|
7057 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7058 |
|
7059 |
-
|
7060 |
-
* @ngdoc method
|
7061 |
-
* @name $cacheFactory.Cache#removeAll
|
7062 |
-
* @kind function
|
7063 |
-
*
|
7064 |
-
* @description
|
7065 |
-
* Clears the cache object of any entries.
|
7066 |
-
*/
|
7067 |
-
removeAll: function() {
|
7068 |
-
data = createMap();
|
7069 |
-
size = 0;
|
7070 |
-
lruHash = createMap();
|
7071 |
-
freshEnd = staleEnd = null;
|
7072 |
-
},
|
7073 |
|
|
|
|
|
|
|
7074 |
|
7075 |
-
|
7076 |
-
|
7077 |
-
* @name $cacheFactory.Cache#destroy
|
7078 |
-
* @kind function
|
7079 |
-
*
|
7080 |
-
* @description
|
7081 |
-
* Destroys the {@link $cacheFactory.Cache Cache} object entirely,
|
7082 |
-
* removing it from the {@link $cacheFactory $cacheFactory} set.
|
7083 |
-
*/
|
7084 |
-
destroy: function() {
|
7085 |
-
data = null;
|
7086 |
-
stats = null;
|
7087 |
-
lruHash = null;
|
7088 |
-
delete caches[cacheId];
|
7089 |
-
},
|
7090 |
|
|
|
7091 |
|
7092 |
-
|
7093 |
-
|
7094 |
-
|
7095 |
-
* @kind function
|
7096 |
-
*
|
7097 |
-
* @description
|
7098 |
-
* Retrieve information regarding a particular {@link $cacheFactory.Cache Cache}.
|
7099 |
-
*
|
7100 |
-
* @returns {object} an object with the following properties:
|
7101 |
-
* <ul>
|
7102 |
-
* <li>**id**: the id of the cache instance</li>
|
7103 |
-
* <li>**size**: the number of entries kept in the cache instance</li>
|
7104 |
-
* <li>**...**: any additional properties from the options object when creating the
|
7105 |
-
* cache.</li>
|
7106 |
-
* </ul>
|
7107 |
-
*/
|
7108 |
-
info: function() {
|
7109 |
-
return extend({}, stats, {size: size});
|
7110 |
-
}
|
7111 |
-
});
|
7112 |
|
7113 |
|
7114 |
-
|
7115 |
-
|
7116 |
-
|
7117 |
-
|
7118 |
-
|
7119 |
-
|
7120 |
-
|
7121 |
-
|
7122 |
-
|
7123 |
-
|
|
|
|
|
|
|
|
|
7124 |
|
7125 |
-
link(entry.n, entry.p);
|
7126 |
-
link(entry, freshEnd);
|
7127 |
-
freshEnd = entry;
|
7128 |
-
freshEnd.n = null;
|
7129 |
-
}
|
7130 |
-
}
|
7131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7132 |
|
7133 |
-
/**
|
7134 |
-
* bidirectionally links two entries of the LRU linked list
|
7135 |
-
*/
|
7136 |
-
function link(nextEntry, prevEntry) {
|
7137 |
-
if (nextEntry !== prevEntry) {
|
7138 |
-
if (nextEntry) nextEntry.p = prevEntry; //p stands for previous, 'prev' didn't minify
|
7139 |
-
if (prevEntry) prevEntry.n = nextEntry; //n stands for next, 'next' didn't minify
|
7140 |
-
}
|
7141 |
-
}
|
7142 |
-
}
|
7143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7144 |
|
7145 |
-
/**
|
7146 |
-
* @ngdoc method
|
7147 |
-
* @name $cacheFactory#info
|
7148 |
-
*
|
7149 |
-
* @description
|
7150 |
-
* Get information about all the caches that have been created
|
7151 |
-
*
|
7152 |
-
* @returns {Object} - key-value map of `cacheId` to the result of calling `cache#info`
|
7153 |
-
*/
|
7154 |
-
cacheFactory.info = function() {
|
7155 |
-
var info = {};
|
7156 |
-
forEach(caches, function(cache, cacheId) {
|
7157 |
-
info[cacheId] = cache.info();
|
7158 |
-
});
|
7159 |
-
return info;
|
7160 |
-
};
|
7161 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7162 |
|
7163 |
-
|
7164 |
-
|
7165 |
-
|
7166 |
-
|
7167 |
-
|
7168 |
-
|
7169 |
-
*
|
7170 |
-
* @param {string} cacheId Name or id of a cache to access.
|
7171 |
-
* @returns {object} Cache object identified by the cacheId or undefined if no such cache.
|
7172 |
-
*/
|
7173 |
-
cacheFactory.get = function(cacheId) {
|
7174 |
-
return caches[cacheId];
|
7175 |
-
};
|
7176 |
|
7177 |
|
7178 |
-
|
7179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7180 |
}
|
7181 |
|
7182 |
-
|
7183 |
-
|
7184 |
-
|
7185 |
-
|
7186 |
-
|
7187 |
-
|
7188 |
-
|
7189 |
-
|
7190 |
-
|
7191 |
-
|
7192 |
-
|
7193 |
-
|
7194 |
-
|
7195 |
-
|
7196 |
-
|
7197 |
-
|
7198 |
-
|
7199 |
-
|
7200 |
-
|
7201 |
-
|
7202 |
-
|
7203 |
-
|
7204 |
-
|
7205 |
-
|
7206 |
-
|
7207 |
-
|
7208 |
-
|
7209 |
-
|
7210 |
-
|
7211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7212 |
* $templateCache.put('templateId.html', 'This is the content of the template');
|
7213 |
* });
|
7214 |
-
|
7215 |
-
|
7216 |
-
|
7217 |
-
|
7218 |
-
|
7219 |
* templateUrl: 'templateId.html'
|
7220 |
* });
|
7221 |
-
|
7222 |
-
|
7223 |
-
|
7224 |
-
|
7225 |
-
|
7226 |
-
|
7227 |
-
|
7228 |
-
|
7229 |
-
|
7230 |
-
|
7231 |
-
|
7232 |
-
|
7233 |
-
|
7234 |
|
7235 |
-
|
7236 |
* Any commits to this file should be reviewed with security in mind. *
|
7237 |
* Changes to this file can potentially create security vulnerabilities. *
|
7238 |
* An approval from 2 Core members with history of modifying *
|
@@ -7243,7 +7243,7 @@
|
|
7243 |
* Or gives undesired access to variables like document or window? *
|
7244 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
7245 |
|
7246 |
-
|
7247 |
*
|
7248 |
* DOM-related variables:
|
7249 |
*
|
@@ -7261,43 +7261,43 @@
|
|
7261 |
*/
|
7262 |
|
7263 |
|
7264 |
-
|
7265 |
-
|
7266 |
-
|
7267 |
-
|
7268 |
-
|
7269 |
-
|
7270 |
-
|
7271 |
-
|
7272 |
-
|
7273 |
-
|
7274 |
-
|
7275 |
-
|
7276 |
-
|
7277 |
-
|
7278 |
-
|
7279 |
-
|
7280 |
-
|
7281 |
-
|
7282 |
-
|
7283 |
-
|
7284 |
-
|
7285 |
-
|
7286 |
-
|
7287 |
-
|
7288 |
-
|
7289 |
-
|
7290 |
-
|
7291 |
-
|
7292 |
-
|
7293 |
-
|
7294 |
-
|
7295 |
-
|
7296 |
-
|
7297 |
-
|
7298 |
-
|
7299 |
-
|
7300 |
-
|
7301 |
* var directiveDefinitionObject = {
|
7302 |
* {@link $compile#-priority- priority}: 0,
|
7303 |
* {@link $compile#-template- template}: '<div></div>', // or // function(tElement, tAttrs) { ... },
|
@@ -7330,18 +7330,18 @@
|
|
7330 |
* };
|
7331 |
* return directiveDefinitionObject;
|
7332 |
* });
|
7333 |
-
|
7334 |
-
|
7335 |
-
|
7336 |
-
|
7337 |
-
|
7338 |
-
|
7339 |
-
|
7340 |
-
|
7341 |
-
|
7342 |
-
|
7343 |
-
|
7344 |
-
|
7345 |
* var directiveDefinitionObject = {
|
7346 |
* link: function postLink(scope, iElement, iAttrs) { ... }
|
7347 |
* };
|
@@ -7349,58 +7349,58 @@
|
|
7349 |
* // or
|
7350 |
* // return function postLink(scope, iElement, iAttrs) { ... }
|
7351 |
* });
|
7352 |
-
|
7353 |
-
|
7354 |
-
|
7355 |
-
|
7356 |
-
|
7357 |
-
|
7358 |
-
|
7359 |
-
|
7360 |
-
|
7361 |
-
|
7362 |
-
|
7363 |
-
|
7364 |
-
|
7365 |
-
|
7366 |
-
|
7367 |
-
|
7368 |
-
|
7369 |
-
|
7370 |
-
|
7371 |
-
|
7372 |
-
|
7373 |
-
|
7374 |
-
|
7375 |
-
|
7376 |
-
|
7377 |
-
|
7378 |
-
|
7379 |
-
|
7380 |
-
|
7381 |
-
|
7382 |
-
|
7383 |
-
|
7384 |
-
|
7385 |
-
|
7386 |
-
|
7387 |
-
|
7388 |
-
|
7389 |
-
|
7390 |
-
|
7391 |
-
|
7392 |
-
|
7393 |
-
|
7394 |
-
|
7395 |
-
|
7396 |
-
|
7397 |
-
|
7398 |
-
|
7399 |
-
|
7400 |
-
|
7401 |
-
|
7402 |
-
|
7403 |
-
|
7404 |
* template:
|
7405 |
* 'Month: <input ng-model="$ctrl.month" ng-change="$ctrl.updateDate()">' +
|
7406 |
* 'Date: {{ $ctrl.date }}' +
|
@@ -7413,7 +7413,7 @@
|
|
7413 |
* };
|
7414 |
* }
|
7415 |
* })
|
7416 |
-
|
7417 |
* bindings: { date: '<' },
|
7418 |
* template:
|
7419 |
* '<pre>{{ $ctrl.log | json }}</pre>',
|
@@ -7429,28 +7429,28 @@
|
|
7429 |
* };
|
7430 |
* }
|
7431 |
* });
|
7432 |
-
|
7433 |
-
|
7434 |
-
|
7435 |
-
|
7436 |
-
|
7437 |
-
|
7438 |
-
|
7439 |
-
|
7440 |
-
|
7441 |
-
|
7442 |
-
|
7443 |
-
|
7444 |
-
|
7445 |
-
|
7446 |
-
|
7447 |
-
|
7448 |
-
|
7449 |
-
|
7450 |
-
|
7451 |
-
|
7452 |
-
|
7453 |
-
|
7454 |
* bindings: { items: '<' },
|
7455 |
* template:
|
7456 |
* '<pre>{{ $ctrl.log | json }}</pre>',
|
@@ -7469,133 +7469,133 @@
|
|
7469 |
* };
|
7470 |
* }
|
7471 |
* });
|
7472 |
-
|
7473 |
-
|
7474 |
-
|
7475 |
-
|
7476 |
-
|
7477 |
-
|
7478 |
-
|
7479 |
* compiler}. The attributes are:
|
7480 |
-
|
7481 |
-
|
7482 |
-
|
7483 |
-
|
7484 |
-
|
7485 |
-
|
7486 |
-
|
7487 |
-
|
7488 |
-
|
7489 |
-
|
7490 |
-
|
7491 |
-
|
7492 |
-
|
7493 |
-
|
7494 |
-
|
7495 |
-
|
7496 |
-
|
7497 |
-
|
7498 |
-
|
7499 |
-
|
7500 |
-
|
7501 |
-
|
7502 |
-
|
7503 |
-
|
7504 |
-
|
7505 |
-
|
7506 |
-
|
7507 |
-
|
7508 |
-
|
7509 |
-
|
7510 |
-
|
7511 |
-
|
7512 |
-
|
7513 |
-
|
7514 |
-
|
7515 |
-
|
7516 |
-
|
7517 |
-
|
7518 |
-
|
7519 |
-
|
7520 |
-
|
7521 |
-
|
7522 |
-
|
7523 |
-
|
7524 |
-
|
7525 |
-
|
7526 |
-
|
7527 |
-
|
7528 |
-
|
7529 |
-
|
7530 |
-
|
7531 |
-
|
7532 |
-
|
7533 |
-
|
7534 |
-
|
7535 |
-
|
7536 |
* localModel: '=myAttr' }`, the property `localModel` on the directive's scope will reflect the
|
7537 |
-
|
7538 |
-
|
7539 |
-
|
7540 |
-
|
7541 |
-
|
7542 |
-
|
7543 |
-
|
7544 |
-
|
7545 |
-
|
7546 |
-
|
7547 |
-
|
7548 |
* `$watchCollection`}: use `=*` or `=*attr`
|
7549 |
-
|
7550 |
-
|
7551 |
-
|
7552 |
-
|
7553 |
-
|
7554 |
-
|
7555 |
-
|
7556 |
-
|
7557 |
-
|
7558 |
-
|
7559 |
-
|
7560 |
-
|
7561 |
-
|
7562 |
-
|
7563 |
-
|
7564 |
-
|
7565 |
-
|
7566 |
-
|
7567 |
-
|
7568 |
-
|
7569 |
-
|
7570 |
-
|
7571 |
-
|
7572 |
-
|
7573 |
-
|
7574 |
-
|
7575 |
-
|
7576 |
-
|
7577 |
-
|
7578 |
-
|
7579 |
-
|
7580 |
-
|
7581 |
-
|
7582 |
* localFn:'&myAttr' }`, the isolate scope property `localFn` will point to a function wrapper for
|
7583 |
-
|
7584 |
-
|
7585 |
-
|
7586 |
-
|
7587 |
-
|
7588 |
-
|
7589 |
-
|
7590 |
-
|
7591 |
-
|
7592 |
-
|
7593 |
-
|
7594 |
-
|
7595 |
-
|
7596 |
-
|
7597 |
-
|
7598 |
-
|
7599 |
return {
|
7600 |
scope: {
|
7601 |
notoptional: '=',
|
@@ -7610,459 +7610,459 @@
|
|
7610 |
}
|
7611 |
}
|
7612 |
})
|
7613 |
-
|
7614 |
-
|
7615 |
-
|
7616 |
-
|
7617 |
-
|
7618 |
-
|
7619 |
-
|
7620 |
-
|
7621 |
-
|
7622 |
-
|
7623 |
-
|
7624 |
-
|
7625 |
-
|
7626 |
-
|
7627 |
-
|
7628 |
-
|
7629 |
-
|
7630 |
-
|
7631 |
-
|
7632 |
-
|
7633 |
-
|
7634 |
-
|
7635 |
-
|
7636 |
-
|
7637 |
-
|
7638 |
-
|
7639 |
-
|
7640 |
-
|
7641 |
-
|
7642 |
-
|
7643 |
-
|
7644 |
-
|
7645 |
-
|
7646 |
-
|
7647 |
-
|
7648 |
-
|
7649 |
-
|
7650 |
-
|
7651 |
-
|
7652 |
-
|
7653 |
-
|
7654 |
-
|
7655 |
-
|
7656 |
-
|
7657 |
-
|
7658 |
-
|
7659 |
-
|
7660 |
-
|
7661 |
-
|
7662 |
-
|
7663 |
-
|
7664 |
-
|
7665 |
-
|
7666 |
-
|
7667 |
-
|
7668 |
-
|
7669 |
-
|
7670 |
-
|
7671 |
-
|
7672 |
-
|
7673 |
-
|
7674 |
-
|
7675 |
-
|
7676 |
-
|
7677 |
-
|
7678 |
-
|
7679 |
-
|
7680 |
-
|
7681 |
-
|
7682 |
-
|
7683 |
-
|
7684 |
-
|
7685 |
-
|
7686 |
-
|
7687 |
-
|
7688 |
-
|
7689 |
-
|
7690 |
-
|
7691 |
-
|
7692 |
-
|
7693 |
-
|
7694 |
-
|
7695 |
-
|
7696 |
-
|
7697 |
-
|
7698 |
-
|
7699 |
-
|
7700 |
-
|
7701 |
-
|
7702 |
-
|
7703 |
-
|
7704 |
-
|
7705 |
-
|
7706 |
-
|
7707 |
-
|
7708 |
-
|
7709 |
-
|
7710 |
-
|
7711 |
-
|
7712 |
-
|
7713 |
-
|
7714 |
-
|
7715 |
-
|
7716 |
-
|
7717 |
-
|
7718 |
-
|
7719 |
-
|
7720 |
-
|
7721 |
-
|
7722 |
-
|
7723 |
-
|
7724 |
-
|
7725 |
-
|
7726 |
-
|
7727 |
-
|
7728 |
-
|
7729 |
-
|
7730 |
-
|
7731 |
-
|
7732 |
-
|
7733 |
-
|
7734 |
-
|
7735 |
-
|
7736 |
-
|
7737 |
-
|
7738 |
-
|
7739 |
-
|
7740 |
-
|
7741 |
-
|
7742 |
-
|
7743 |
-
|
7744 |
-
|
7745 |
-
|
7746 |
-
|
7747 |
-
|
7748 |
-
|
7749 |
-
|
7750 |
-
|
7751 |
-
|
7752 |
-
|
7753 |
-
|
7754 |
-
|
7755 |
-
|
7756 |
-
|
7757 |
-
|
7758 |
-
|
7759 |
-
|
7760 |
-
|
7761 |
-
|
7762 |
-
|
7763 |
-
|
7764 |
-
|
7765 |
-
|
7766 |
-
|
7767 |
-
|
7768 |
-
|
7769 |
-
|
7770 |
-
|
7771 |
-
|
7772 |
-
|
7773 |
-
|
7774 |
-
|
7775 |
-
|
7776 |
-
|
7777 |
-
|
7778 |
-
|
7779 |
-
|
7780 |
-
|
7781 |
-
|
7782 |
-
|
7783 |
-
* Directives Guide} for an example.
|
7784 |
-
|
7785 |
-
|
7786 |
-
|
7787 |
-
|
7788 |
-
|
7789 |
-
|
7790 |
-
|
7791 |
-
|
7792 |
-
|
7793 |
-
|
7794 |
-
|
7795 |
-
|
7796 |
-
|
7797 |
-
|
7798 |
-
|
7799 |
-
|
7800 |
-
|
7801 |
-
|
7802 |
-
|
7803 |
-
|
7804 |
-
|
7805 |
-
|
7806 |
-
|
7807 |
-
|
7808 |
-
|
7809 |
-
|
7810 |
-
|
7811 |
-
|
7812 |
-
|
7813 |
-
|
7814 |
-
|
7815 |
-
|
7816 |
-
|
7817 |
-
|
7818 |
-
|
7819 |
-
|
7820 |
-
|
7821 |
-
|
7822 |
-
|
7823 |
-
|
7824 |
-
|
7825 |
-
|
7826 |
-
|
7827 |
-
|
7828 |
-
|
7829 |
-
|
7830 |
-
|
7831 |
-
|
7832 |
-
|
7833 |
-
|
7834 |
-
|
7835 |
-
|
7836 |
-
|
7837 |
-
|
7838 |
-
|
7839 |
-
|
7840 |
-
|
7841 |
-
|
7842 |
-
|
7843 |
-
|
7844 |
-
|
7845 |
-
|
7846 |
-
|
7847 |
-
|
7848 |
-
|
7849 |
-
|
7850 |
-
|
7851 |
-
|
7852 |
-
|
7853 |
-
|
7854 |
-
|
7855 |
-
|
7856 |
-
|
7857 |
-
|
7858 |
-
|
7859 |
-
|
7860 |
-
|
7861 |
-
|
7862 |
-
|
7863 |
-
|
7864 |
-
|
7865 |
-
|
7866 |
-
|
7867 |
-
|
7868 |
-
|
7869 |
-
|
7870 |
-
|
7871 |
-
|
7872 |
-
|
7873 |
-
|
7874 |
-
|
7875 |
-
|
7876 |
-
|
7877 |
-
|
7878 |
-
|
7879 |
-
|
7880 |
-
|
7881 |
-
|
7882 |
-
|
7883 |
-
|
7884 |
-
|
7885 |
-
|
7886 |
-
|
7887 |
-
|
7888 |
-
|
7889 |
-
|
7890 |
-
|
7891 |
-
|
7892 |
-
|
7893 |
-
|
7894 |
-
|
7895 |
-
|
7896 |
-
|
7897 |
-
|
7898 |
-
|
7899 |
-
|
7900 |
-
|
7901 |
-
|
7902 |
-
|
7903 |
-
|
7904 |
-
|
7905 |
-
|
7906 |
-
|
7907 |
-
|
7908 |
-
|
7909 |
-
|
7910 |
-
|
7911 |
-
|
7912 |
-
|
7913 |
-
|
7914 |
-
|
7915 |
-
|
7916 |
-
|
7917 |
-
|
7918 |
-
|
7919 |
-
|
7920 |
* Testing Transclusion Directives}.
|
7921 |
-
|
7922 |
-
|
7923 |
-
|
7924 |
-
|
7925 |
-
|
7926 |
-
|
7927 |
-
|
7928 |
-
|
7929 |
-
|
7930 |
-
|
7931 |
-
|
7932 |
-
|
7933 |
-
|
7934 |
-
|
7935 |
-
|
7936 |
-
|
7937 |
-
|
7938 |
-
|
7939 |
-
|
7940 |
-
|
7941 |
-
|
7942 |
-
|
7943 |
-
|
7944 |
-
|
7945 |
-
|
7946 |
-
|
7947 |
-
|
7948 |
-
|
7949 |
-
|
7950 |
-
|
7951 |
-
|
7952 |
-
|
7953 |
-
|
7954 |
-
|
7955 |
-
|
7956 |
-
|
7957 |
-
|
7958 |
-
|
7959 |
-
|
7960 |
-
|
7961 |
-
|
7962 |
-
|
7963 |
-
|
7964 |
-
|
7965 |
-
|
7966 |
-
|
7967 |
-
|
7968 |
-
|
7969 |
-
|
7970 |
-
|
7971 |
-
|
7972 |
-
|
7973 |
-
|
7974 |
-
|
7975 |
-
|
7976 |
-
|
7977 |
-
|
7978 |
-
|
7979 |
-
|
7980 |
-
|
7981 |
-
|
7982 |
* element.append(clone);
|
7983 |
* transcludedContent = clone;
|
7984 |
* transclusionScope = scope;
|
7985 |
* });
|
7986 |
-
|
7987 |
-
|
7988 |
-
|
7989 |
-
|
7990 |
-
|
7991 |
-
|
7992 |
-
|
7993 |
-
|
7994 |
-
|
7995 |
-
|
7996 |
-
|
7997 |
-
|
7998 |
-
|
7999 |
-
|
8000 |
-
|
8001 |
-
|
8002 |
-
|
8003 |
-
|
8004 |
-
|
8005 |
-
|
8006 |
-
|
8007 |
-
|
8008 |
-
|
8009 |
-
|
8010 |
-
|
8011 |
-
|
8012 |
-
|
8013 |
-
|
8014 |
-
|
8015 |
-
|
8016 |
-
|
8017 |
-
|
8018 |
-
|
8019 |
-
|
8020 |
-
|
8021 |
-
|
8022 |
-
|
8023 |
-
|
8024 |
-
|
8025 |
-
|
8026 |
-
|
8027 |
-
|
8028 |
-
|
8029 |
-
|
8030 |
- isolate
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8031 |
- transclusion
|
8032 |
-
|
8033 |
-
|
8034 |
-
|
8035 |
-
|
8036 |
-
|
8037 |
-
|
8038 |
-
|
8039 |
-
|
8040 |
-
|
8041 |
-
|
8042 |
-
|
8043 |
-
|
8044 |
-
|
8045 |
-
|
8046 |
-
|
8047 |
-
|
8048 |
-
|
8049 |
-
|
8050 |
-
|
8051 |
-
|
8052 |
-
|
8053 |
-
|
8054 |
-
|
8055 |
-
|
8056 |
-
|
8057 |
-
|
8058 |
-
|
8059 |
-
* * *Observing interpolated attributes:* Use `$observe` to observe the value changes of attributes
|
8060 |
-
* that contain interpolation (e.g. `src="{{bar}}"`). Not only is this very efficient but it's also
|
8061 |
-
* the only way to easily get the actual value because during the linking phase the interpolation
|
8062 |
-
* hasn't been evaluated yet and so the value is at this time set to `undefined`.
|
8063 |
-
*
|
8064 |
-
* ```js
|
8065 |
-
* function linkingFn(scope, elm, attrs, ctrl) {
|
8066 |
* // get the attribute value
|
8067 |
* console.log(attrs.ngModel);
|
8068 |
*
|
@@ -8074,19 +8074,19 @@
|
|
8074 |
* console.log('ngModel has changed value to ' + value);
|
8075 |
* });
|
8076 |
* }
|
8077 |
-
|
8078 |
-
|
8079 |
-
|
8080 |
-
|
8081 |
-
|
8082 |
-
|
8083 |
-
|
8084 |
-
|
8085 |
-
|
8086 |
-
|
8087 |
-
|
8088 |
-
|
8089 |
-
|
8090 |
// configure new 'compile' directive by passing a directive
|
8091 |
// factory function. The factory function injects the '$compile'
|
8092 |
$compileProvider.directive('compile', function($compile) {
|
@@ -8112,18 +8112,18 @@
|
|
8112 |
};
|
8113 |
});
|
8114 |
})
|
8115 |
-
|
8116 |
$scope.name = 'AngularJS';
|
8117 |
$scope.html = 'Hello {{name}}';
|
8118 |
}]);
|
8119 |
-
|
8120 |
-
|
8121 |
-
|
8122 |
-
|
8123 |
-
|
8124 |
-
|
8125 |
-
|
8126 |
-
|
8127 |
it('should auto compile', function() {
|
8128 |
var textarea = $('textarea');
|
8129 |
var output = $('div[compile]');
|
@@ -8133,230 +8133,230 @@
|
|
8133 |
textarea.sendKeys('{{name}}!');
|
8134 |
expect(output.getText()).toBe('AngularJS!');
|
8135 |
});
|
8136 |
-
|
8137 |
-
|
8138 |
|
8139 |
-
|
8140 |
-
|
8141 |
-
|
8142 |
-
|
8143 |
-
|
8144 |
-
|
8145 |
-
|
8146 |
-
|
8147 |
-
|
8148 |
-
|
8149 |
-
|
8150 |
-
|
8151 |
-
|
8152 |
-
|
8153 |
-
|
8154 |
-
|
8155 |
-
|
8156 |
-
|
8157 |
-
|
8158 |
-
|
8159 |
-
|
8160 |
-
|
8161 |
-
|
8162 |
-
|
8163 |
-
|
8164 |
-
|
8165 |
-
|
8166 |
-
|
8167 |
-
|
8168 |
-
|
8169 |
-
|
8170 |
-
|
8171 |
-
|
8172 |
-
|
8173 |
-
|
8174 |
-
|
8175 |
* parent: {
|
8176 |
* instance: parentControllerInstance
|
8177 |
* }
|
8178 |
* }
|
8179 |
-
|
8180 |
-
|
8181 |
-
|
8182 |
-
|
8183 |
-
|
8184 |
-
|
8185 |
-
|
8186 |
-
|
8187 |
-
|
8188 |
-
|
8189 |
-
|
8190 |
-
|
8191 |
-
|
8192 |
-
|
8193 |
-
|
8194 |
-
|
8195 |
-
|
8196 |
-
|
8197 |
-
|
8198 |
-
|
8199 |
-
|
8200 |
-
|
8201 |
-
|
8202 |
-
|
8203 |
-
|
8204 |
-
|
8205 |
-
|
8206 |
* //attach the clone to DOM document at the right place
|
8207 |
* });
|
8208 |
-
|
8209 |
-
|
8210 |
-
|
8211 |
-
|
8212 |
-
|
8213 |
-
|
8214 |
-
|
8215 |
-
|
8216 |
-
|
8217 |
-
|
8218 |
-
|
8219 |
-
|
8220 |
-
|
8221 |
-
|
8222 |
-
|
8223 |
section on double compilation} for an in-depth explanation and ways to avoid it.
|
8224 |
|
8225 |
-
|
8226 |
|
8227 |
-
|
8228 |
-
|
8229 |
-
|
8230 |
-
|
8231 |
-
|
8232 |
-
|
8233 |
-
|
8234 |
-
|
8235 |
-
|
8236 |
-
|
8237 |
-
|
8238 |
-
|
8239 |
-
|
8240 |
-
|
8241 |
-
|
8242 |
-
|
8243 |
-
|
8244 |
-
|
8245 |
-
|
8246 |
-
|
8247 |
-
|
8248 |
-
|
8249 |
-
|
8250 |
-
|
8251 |
-
|
8252 |
-
|
8253 |
-
|
8254 |
-
|
8255 |
-
|
8256 |
-
|
8257 |
-
|
8258 |
-
|
8259 |
-
|
8260 |
-
|
8261 |
-
|
8262 |
-
|
8263 |
-
|
8264 |
-
|
8265 |
-
|
8266 |
-
|
8267 |
-
|
8268 |
-
|
8269 |
-
|
8270 |
-
|
8271 |
-
|
8272 |
-
|
8273 |
-
|
8274 |
-
|
8275 |
-
|
8276 |
-
|
8277 |
-
|
8278 |
|
8279 |
-
|
8280 |
-
|
8281 |
-
|
8282 |
-
|
8283 |
-
|
8284 |
-
|
8285 |
-
|
8286 |
-
|
8287 |
-
|
8288 |
-
|
8289 |
-
|
8290 |
-
|
8291 |
-
|
8292 |
-
|
8293 |
-
|
8294 |
-
|
8295 |
-
|
8296 |
-
|
8297 |
-
|
8298 |
-
|
8299 |
-
|
8300 |
-
|
8301 |
-
|
8302 |
-
|
8303 |
-
|
8304 |
-
|
8305 |
-
|
8306 |
-
|
8307 |
-
|
8308 |
-
|
8309 |
-
|
8310 |
-
|
8311 |
-
|
8312 |
-
|
8313 |
-
|
8314 |
-
|
8315 |
-
|
8316 |
-
|
8317 |
-
|
8318 |
-
|
8319 |
-
|
8320 |
-
|
8321 |
-
|
8322 |
-
|
8323 |
-
|
8324 |
-
|
8325 |
-
|
8326 |
-
|
8327 |
-
|
8328 |
-
|
8329 |
-
|
8330 |
-
|
8331 |
-
|
8332 |
-
|
8333 |
-
|
8334 |
-
|
8335 |
-
|
8336 |
-
|
8337 |
-
|
8338 |
-
|
8339 |
-
|
8340 |
-
|
8341 |
-
|
8342 |
-
|
8343 |
-
|
8344 |
-
|
8345 |
-
|
8346 |
-
|
8347 |
-
|
8348 |
-
|
8349 |
-
|
8350 |
-
|
8351 |
-
|
8352 |
-
|
8353 |
-
|
8354 |
-
|
8355 |
-
|
8356 |
-
|
8357 |
-
|
8358 |
-
|
8359 |
-
|
8360 |
* templateUrl: 'main.html',
|
8361 |
* controller: function($sce) {
|
8362 |
* this.safeContent = '<strong>Safe content</strong>';
|
@@ -8364,61 +8364,61 @@
|
|
8364 |
* this.trustedUnsafeContent = $sce.trustAsHtml(this.unsafeContent);
|
8365 |
* }
|
8366 |
* });
|
8367 |
-
|
8368 |
-
|
8369 |
-
|
8370 |
-
|
8371 |
-
|
8372 |
-
|
8373 |
-
|
8374 |
-
|
8375 |
-
|
8376 |
-
|
8377 |
-
|
8378 |
-
|
8379 |
-
|
8380 |
-
|
8381 |
-
|
8382 |
-
|
8383 |
-
|
8384 |
-
|
8385 |
-
|
8386 |
-
|
8387 |
-
|
8388 |
-
|
8389 |
-
|
8390 |
-
|
8391 |
-
|
8392 |
-
|
8393 |
-
|
8394 |
-
|
8395 |
-
|
8396 |
-
|
8397 |
-
|
8398 |
-
|
8399 |
-
|
8400 |
* margin-bottom: 10px;
|
8401 |
* }
|
8402 |
-
|
8403 |
-
|
8404 |
* min-height: 30px;
|
8405 |
* border: 1px solid blue;
|
8406 |
* }
|
8407 |
-
|
8408 |
-
|
8409 |
* font-family: Monospace;
|
8410 |
* }
|
8411 |
-
|
8412 |
-
|
8413 |
-
|
8414 |
-
|
8415 |
-
|
8416 |
-
|
8417 |
-
|
8418 |
-
|
8419 |
-
|
8420 |
-
|
8421 |
-
|
8422 |
* templateUrl: 'main.html',
|
8423 |
* controller: function($sce) {
|
8424 |
* this.safeContent = '<strong>Safe content</strong>';
|
@@ -8426,100 +8426,100 @@
|
|
8426 |
* this.trustedUnsafeContent = $sce.trustAsHtml(this.unsafeContent);
|
8427 |
* }
|
8428 |
* });
|
8429 |
-
|
8430 |
-
|
8431 |
-
|
8432 |
-
|
8433 |
-
|
8434 |
-
|
8435 |
-
|
8436 |
-
|
8437 |
-
|
8438 |
-
|
8439 |
-
|
8440 |
-
|
8441 |
-
|
8442 |
-
|
8443 |
-
|
8444 |
-
|
8445 |
-
|
8446 |
-
|
8447 |
-
|
8448 |
-
|
8449 |
-
|
8450 |
-
|
8451 |
-
|
8452 |
-
|
8453 |
-
|
8454 |
-
|
8455 |
-
|
8456 |
* margin-bottom: 10px;
|
8457 |
* }
|
8458 |
-
|
8459 |
-
|
8460 |
* min-height: 30px;
|
8461 |
* border: 1px solid blue;
|
8462 |
* }
|
8463 |
-
|
8464 |
-
|
8465 |
* font-family: Monospace;
|
8466 |
* }
|
8467 |
-
|
8468 |
-
|
8469 |
-
|
8470 |
-
|
8471 |
|
8472 |
-
|
8473 |
-
|
8474 |
-
|
8475 |
-
|
8476 |
-
|
8477 |
-
|
8478 |
-
|
8479 |
-
|
8480 |
-
|
8481 |
-
|
8482 |
-
|
8483 |
-
|
8484 |
-
|
8485 |
-
|
8486 |
-
|
8487 |
-
|
8488 |
-
|
8489 |
-
|
8490 |
-
|
8491 |
-
|
8492 |
-
|
8493 |
-
|
8494 |
-
|
8495 |
-
|
8496 |
-
|
8497 |
-
|
8498 |
-
|
8499 |
-
|
8500 |
-
|
8501 |
-
|
8502 |
-
|
8503 |
-
|
8504 |
-
|
8505 |
-
|
8506 |
-
|
8507 |
-
|
8508 |
-
|
8509 |
-
|
8510 |
-
|
8511 |
-
|
8512 |
-
|
8513 |
-
|
8514 |
-
|
8515 |
-
|
8516 |
-
|
8517 |
-
|
8518 |
-
|
8519 |
-
|
8520 |
-
|
8521 |
-
|
8522 |
-
|
8523 |
* templateUrl: 'main.html',
|
8524 |
* controller: function() {
|
8525 |
* this.clickCount = 0;
|
@@ -8528,40 +8528,40 @@
|
|
8528 |
* this.loadingState = 0;
|
8529 |
* }
|
8530 |
* });
|
8531 |
-
|
8532 |
-
|
8533 |
-
|
8534 |
-
|
8535 |
-
|
8536 |
-
|
8537 |
-
|
8538 |
-
|
8539 |
-
|
8540 |
-
|
8541 |
-
|
8542 |
-
|
8543 |
-
|
8544 |
-
|
8545 |
-
|
8546 |
-
|
8547 |
-
|
8548 |
-
|
8549 |
-
|
8550 |
-
|
8551 |
-
|
8552 |
-
|
8553 |
-
|
8554 |
-
|
8555 |
-
|
8556 |
-
|
8557 |
-
|
8558 |
-
|
8559 |
-
|
8560 |
-
|
8561 |
-
|
8562 |
-
|
8563 |
-
|
8564 |
-
|
8565 |
* templateUrl: 'main.html',
|
8566 |
* controller: function() {
|
8567 |
* this.eventLog = '';
|
@@ -8571,7 +8571,7 @@
|
|
8571 |
* };
|
8572 |
* }
|
8573 |
* })
|
8574 |
-
|
8575 |
* templateUrl: 'child.html',
|
8576 |
* controller: function($element) {
|
8577 |
* this.fireEvent = function() {
|
@@ -8581,593 +8581,593 @@
|
|
8581 |
* };
|
8582 |
* }
|
8583 |
* });
|
8584 |
-
|
8585 |
-
|
8586 |
-
|
8587 |
-
|
8588 |
-
|
8589 |
-
|
8590 |
-
|
8591 |
-
|
8592 |
-
|
8593 |
-
|
8594 |
-
|
8595 |
-
|
8596 |
-
|
8597 |
-
|
8598 |
-
var $compileMinErr = minErr('$compile');
|
8599 |
|
8600 |
-
|
8601 |
-
var _UNINITIALIZED_VALUE = new UNINITIALIZED_VALUE();
|
8602 |
|
8603 |
-
|
8604 |
-
|
8605 |
-
* @name $compileProvider
|
8606 |
-
*
|
8607 |
-
* @description
|
8608 |
-
*/
|
8609 |
-
$CompileProvider.$inject = ['$provide', '$$sanitizeUriProvider'];
|
8610 |
-
/** @this */
|
8611 |
-
function $CompileProvider($provide, $$sanitizeUriProvider) {
|
8612 |
-
var hasDirectives = {},
|
8613 |
-
Suffix = 'Directive',
|
8614 |
-
COMMENT_DIRECTIVE_REGEXP = /^\s*directive:\s*([\w-]+)\s+(.*)$/,
|
8615 |
-
CLASS_DIRECTIVE_REGEXP = /(([\w-]+)(?::([^;]+))?;?)/,
|
8616 |
-
ALL_OR_NOTHING_ATTRS = makeMap('ngSrc,ngSrcset,src,srcset'),
|
8617 |
-
REQUIRE_PREFIX_REGEXP = /^(?:(\^\^?)?(\?)?(\^\^?)?)?/;
|
8618 |
-
|
8619 |
-
// Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes
|
8620 |
-
// The assumption is that future DOM event attribute names will begin with
|
8621 |
-
// 'on' and be composed of only English letters.
|
8622 |
-
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/;
|
8623 |
-
var bindingCache = createMap();
|
8624 |
-
|
8625 |
-
function parseIsolateBindings(scope, directiveName, isController) {
|
8626 |
-
var LOCAL_REGEXP = /^([@&]|[=<](\*?))(\??)\s*([\w$]*)$/;
|
8627 |
-
|
8628 |
-
var bindings = createMap();
|
8629 |
-
|
8630 |
-
forEach(scope, function(definition, scopeName) {
|
8631 |
-
definition = definition.trim();
|
8632 |
-
|
8633 |
-
if (definition in bindingCache) {
|
8634 |
-
bindings[scopeName] = bindingCache[definition];
|
8635 |
-
return;
|
8636 |
-
}
|
8637 |
-
var match = definition.match(LOCAL_REGEXP);
|
8638 |
-
|
8639 |
-
if (!match) {
|
8640 |
-
throw $compileMinErr('iscp',
|
8641 |
-
'Invalid {3} for directive \'{0}\'.' +
|
8642 |
-
' Definition: {... {1}: \'{2}\' ...}',
|
8643 |
-
directiveName, scopeName, definition,
|
8644 |
-
(isController ? 'controller bindings definition' :
|
8645 |
-
'isolate scope definition'));
|
8646 |
-
}
|
8647 |
|
8648 |
-
|
8649 |
-
|
8650 |
-
|
8651 |
-
|
8652 |
-
|
8653 |
-
|
8654 |
-
|
8655 |
-
|
8656 |
-
|
8657 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8658 |
|
8659 |
-
|
8660 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8661 |
|
8662 |
-
|
8663 |
-
|
8664 |
-
isolateScope: null,
|
8665 |
-
bindToController: null
|
8666 |
-
};
|
8667 |
-
if (isObject(directive.scope)) {
|
8668 |
-
if (directive.bindToController === true) {
|
8669 |
-
bindings.bindToController = parseIsolateBindings(directive.scope,
|
8670 |
-
directiveName, true);
|
8671 |
-
bindings.isolateScope = {};
|
8672 |
-
} else {
|
8673 |
-
bindings.isolateScope = parseIsolateBindings(directive.scope,
|
8674 |
-
directiveName, false);
|
8675 |
-
}
|
8676 |
-
}
|
8677 |
-
if (isObject(directive.bindToController)) {
|
8678 |
-
bindings.bindToController =
|
8679 |
-
parseIsolateBindings(directive.bindToController, directiveName, true);
|
8680 |
-
}
|
8681 |
-
if (bindings.bindToController && !directive.controller) {
|
8682 |
-
// There is no controller
|
8683 |
-
throw $compileMinErr('noctrl',
|
8684 |
-
'Cannot bind to controller without directive \'{0}\'s controller.',
|
8685 |
-
directiveName);
|
8686 |
-
}
|
8687 |
-
return bindings;
|
8688 |
-
}
|
8689 |
|
8690 |
-
|
8691 |
-
|
8692 |
-
|
8693 |
-
|
8694 |
-
|
8695 |
-
|
8696 |
-
|
8697 |
-
|
8698 |
-
|
8699 |
-
|
8700 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8701 |
|
8702 |
-
|
8703 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8704 |
|
8705 |
-
|
8706 |
-
|
8707 |
-
var match = value.match(REQUIRE_PREFIX_REGEXP);
|
8708 |
-
var name = value.substring(match[0].length);
|
8709 |
-
if (!name) require[key] = match[0] + key;
|
8710 |
-
});
|
8711 |
-
}
|
8712 |
|
8713 |
-
|
8714 |
-
|
|
|
|
|
|
|
|
|
|
|
8715 |
|
8716 |
-
|
8717 |
-
|
8718 |
-
throw $compileMinErr('badrestrict',
|
8719 |
-
'Restrict property \'{0}\' of directive \'{1}\' is invalid',
|
8720 |
-
restrict,
|
8721 |
-
name);
|
8722 |
-
}
|
8723 |
|
8724 |
-
|
8725 |
-
|
|
|
|
|
|
|
|
|
|
|
8726 |
|
8727 |
-
|
8728 |
-
|
8729 |
-
* @name $compileProvider#directive
|
8730 |
-
* @kind function
|
8731 |
-
*
|
8732 |
-
* @description
|
8733 |
-
* Register a new directive with the compiler.
|
8734 |
-
*
|
8735 |
-
* @param {string|Object} name Name of the directive in camel-case (i.e. <code>ngBind</code> which
|
8736 |
-
* will match as <code>ng-bind</code>), or an object map of directives where the keys are the
|
8737 |
-
* names and the values are the factories.
|
8738 |
-
* @param {Function|Array} directiveFactory An injectable directive factory function. See the
|
8739 |
-
* {@link guide/directive directive guide} and the {@link $compile compile API} for more info.
|
8740 |
-
* @returns {ng.$compileProvider} Self for chaining.
|
8741 |
-
*/
|
8742 |
-
this.directive = function registerDirective(name, directiveFactory) {
|
8743 |
-
assertArg(name, 'name');
|
8744 |
-
assertNotHasOwnProperty(name, 'directive');
|
8745 |
-
if (isString(name)) {
|
8746 |
-
assertValidDirectiveName(name);
|
8747 |
-
assertArg(directiveFactory, 'directiveFactory');
|
8748 |
-
if (!hasDirectives.hasOwnProperty(name)) {
|
8749 |
-
hasDirectives[name] = [];
|
8750 |
-
$provide.factory(name + Suffix, ['$injector', '$exceptionHandler',
|
8751 |
-
function($injector, $exceptionHandler) {
|
8752 |
-
var directives = [];
|
8753 |
-
forEach(hasDirectives[name], function(directiveFactory, index) {
|
8754 |
-
try {
|
8755 |
-
var directive = $injector.invoke(directiveFactory);
|
8756 |
-
if (isFunction(directive)) {
|
8757 |
-
directive = { compile: valueFn(directive) };
|
8758 |
-
} else if (!directive.compile && directive.link) {
|
8759 |
-
directive.compile = valueFn(directive.link);
|
8760 |
-
}
|
8761 |
-
directive.priority = directive.priority || 0;
|
8762 |
-
directive.index = index;
|
8763 |
-
directive.name = directive.name || name;
|
8764 |
-
directive.require = getDirectiveRequire(directive);
|
8765 |
-
directive.restrict = getDirectiveRestrict(directive.restrict, name);
|
8766 |
-
directive.$$moduleName = directiveFactory.$$moduleName;
|
8767 |
-
directives.push(directive);
|
8768 |
-
} catch (e) {
|
8769 |
-
$exceptionHandler(e);
|
8770 |
-
}
|
8771 |
-
});
|
8772 |
-
return directives;
|
8773 |
-
}]);
|
8774 |
-
}
|
8775 |
-
hasDirectives[name].push(directiveFactory);
|
8776 |
-
} else {
|
8777 |
-
forEach(name, reverseParams(registerDirective));
|
8778 |
-
}
|
8779 |
-
return this;
|
8780 |
-
};
|
8781 |
|
8782 |
-
|
8783 |
-
|
8784 |
-
|
8785 |
-
|
8786 |
-
|
8787 |
-
|
8788 |
-
|
8789 |
-
|
8790 |
-
|
8791 |
-
|
8792 |
-
|
8793 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8794 |
* registered controller} if passed as a string. An empty `noop` function by default.
|
8795 |
-
|
8796 |
-
|
8797 |
-
|
8798 |
-
|
8799 |
-
|
8800 |
-
|
8801 |
-
|
8802 |
-
|
8803 |
-
|
8804 |
-
|
8805 |
-
|
8806 |
-
|
8807 |
-
|
8808 |
-
|
8809 |
-
|
8810 |
-
|
8811 |
-
|
8812 |
-
|
8813 |
-
|
8814 |
-
|
8815 |
-
|
8816 |
-
|
8817 |
-
|
8818 |
-
|
8819 |
-
|
8820 |
-
|
8821 |
-
|
8822 |
-
|
8823 |
-
|
8824 |
-
|
8825 |
-
|
8826 |
-
|
8827 |
-
|
8828 |
-
|
8829 |
-
|
8830 |
-
|
8831 |
-
|
8832 |
-
|
8833 |
-
|
8834 |
-
|
8835 |
-
|
8836 |
-
|
8837 |
-
|
8838 |
-
|
8839 |
-
|
8840 |
-
|
8841 |
-
|
8842 |
-
|
8843 |
-
|
8844 |
-
|
8845 |
* template: '<div>My name is {{$ctrl.name}}</div>',
|
8846 |
* controller: function() {
|
8847 |
* this.name = 'shahar';
|
8848 |
* }
|
8849 |
* });
|
8850 |
-
|
8851 |
-
|
8852 |
* template: '<div>My name is {{$ctrl.name}}</div>',
|
8853 |
* bindings: {name: '@'}
|
8854 |
* });
|
8855 |
-
|
8856 |
-
|
8857 |
* templateUrl: 'views/my-comp.html',
|
8858 |
* controller: 'MyCtrl',
|
8859 |
* controllerAs: 'ctrl',
|
8860 |
* bindings: {name: '@'}
|
8861 |
* });
|
8862 |
-
|
8863 |
-
|
8864 |
-
|
8865 |
-
|
8866 |
-
|
8867 |
-
|
8868 |
-
|
8869 |
-
|
8870 |
-
|
8871 |
-
|
8872 |
-
|
8873 |
-
|
8874 |
-
|
8875 |
-
var controller = options.controller || function() {};
|
8876 |
-
|
8877 |
-
function factory($injector) {
|
8878 |
-
function makeInjectable(fn) {
|
8879 |
-
if (isFunction(fn) || isArray(fn)) {
|
8880 |
-
return /** @this */ function(tElement, tAttrs) {
|
8881 |
-
return $injector.invoke(fn, this, {$element: tElement, $attrs: tAttrs});
|
8882 |
-
};
|
8883 |
-
} else {
|
8884 |
-
return fn;
|
8885 |
-
}
|
8886 |
-
}
|
8887 |
|
8888 |
-
|
8889 |
-
var ddo = {
|
8890 |
-
controller: controller,
|
8891 |
-
controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
|
8892 |
-
template: makeInjectable(template),
|
8893 |
-
templateUrl: makeInjectable(options.templateUrl),
|
8894 |
-
transclude: options.transclude,
|
8895 |
-
scope: {},
|
8896 |
-
bindToController: options.bindings || {},
|
8897 |
-
restrict: 'E',
|
8898 |
-
require: options.require
|
8899 |
-
};
|
8900 |
|
8901 |
-
|
8902 |
-
|
8903 |
-
|
8904 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8905 |
|
8906 |
-
|
8907 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8908 |
|
8909 |
-
|
8910 |
-
|
8911 |
-
|
8912 |
-
|
8913 |
-
|
8914 |
-
// Copy any annotation properties (starting with $) over to the factory and controller constructor functions
|
8915 |
-
// These could be used by libraries such as the new component router
|
8916 |
-
forEach(options, function(val, key) {
|
8917 |
-
if (key.charAt(0) === '$') {
|
8918 |
-
factory[key] = val;
|
8919 |
-
// Don't try to copy over annotations to named controller
|
8920 |
-
if (isFunction(controller)) controller[key] = val;
|
8921 |
-
}
|
8922 |
-
});
|
8923 |
|
8924 |
-
|
|
|
8925 |
|
8926 |
-
|
8927 |
-
|
|
|
|
|
8928 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8929 |
|
8930 |
-
|
8931 |
-
* @ngdoc method
|
8932 |
-
* @name $compileProvider#aHrefSanitizationWhitelist
|
8933 |
-
* @kind function
|
8934 |
-
*
|
8935 |
-
* @description
|
8936 |
-
* Retrieves or overrides the default regular expression that is used for whitelisting of safe
|
8937 |
-
* urls during a[href] sanitization.
|
8938 |
-
*
|
8939 |
-
* The sanitization is a security measure aimed at preventing XSS attacks via html links.
|
8940 |
-
*
|
8941 |
-
* Any url about to be assigned to a[href] via data-binding is first normalized and turned into
|
8942 |
-
* an absolute url. Afterwards, the url is matched against the `aHrefSanitizationWhitelist`
|
8943 |
-
* regular expression. If a match is found, the original url is written into the dom. Otherwise,
|
8944 |
-
* the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
|
8945 |
-
*
|
8946 |
-
* @param {RegExp=} regexp New regexp to whitelist urls with.
|
8947 |
-
* @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
|
8948 |
-
* chaining otherwise.
|
8949 |
-
*/
|
8950 |
-
this.aHrefSanitizationWhitelist = function(regexp) {
|
8951 |
-
if (isDefined(regexp)) {
|
8952 |
-
$$sanitizeUriProvider.aHrefSanitizationWhitelist(regexp);
|
8953 |
-
return this;
|
8954 |
-
} else {
|
8955 |
-
return $$sanitizeUriProvider.aHrefSanitizationWhitelist();
|
8956 |
-
}
|
8957 |
-
};
|
8958 |
|
|
|
|
|
8959 |
|
8960 |
-
/**
|
8961 |
-
* @ngdoc method
|
8962 |
-
* @name $compileProvider#imgSrcSanitizationWhitelist
|
8963 |
-
* @kind function
|
8964 |
-
*
|
8965 |
-
* @description
|
8966 |
-
* Retrieves or overrides the default regular expression that is used for whitelisting of safe
|
8967 |
-
* urls during img[src] sanitization.
|
8968 |
-
*
|
8969 |
-
* The sanitization is a security measure aimed at prevent XSS attacks via html links.
|
8970 |
-
*
|
8971 |
-
* Any url about to be assigned to img[src] via data-binding is first normalized and turned into
|
8972 |
-
* an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationWhitelist`
|
8973 |
-
* regular expression. If a match is found, the original url is written into the dom. Otherwise,
|
8974 |
-
* the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
|
8975 |
-
*
|
8976 |
-
* @param {RegExp=} regexp New regexp to whitelist urls with.
|
8977 |
-
* @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
|
8978 |
-
* chaining otherwise.
|
8979 |
-
*/
|
8980 |
-
this.imgSrcSanitizationWhitelist = function(regexp) {
|
8981 |
-
if (isDefined(regexp)) {
|
8982 |
-
$$sanitizeUriProvider.imgSrcSanitizationWhitelist(regexp);
|
8983 |
-
return this;
|
8984 |
-
} else {
|
8985 |
-
return $$sanitizeUriProvider.imgSrcSanitizationWhitelist();
|
8986 |
-
}
|
8987 |
-
};
|
8988 |
|
8989 |
-
|
8990 |
-
|
8991 |
-
|
8992 |
-
|
8993 |
-
|
8994 |
-
|
8995 |
-
|
8996 |
-
|
8997 |
-
|
8998 |
-
|
8999 |
-
|
9000 |
-
|
9001 |
-
|
9002 |
-
|
9003 |
-
|
9004 |
-
|
9005 |
-
|
9006 |
-
|
9007 |
-
|
9008 |
-
|
9009 |
-
|
9010 |
-
|
9011 |
-
|
9012 |
-
|
9013 |
-
|
9014 |
-
|
9015 |
-
|
9016 |
-
|
9017 |
-
this.debugInfoEnabled = function(enabled) {
|
9018 |
-
if (isDefined(enabled)) {
|
9019 |
-
debugInfoEnabled = enabled;
|
9020 |
-
return this;
|
9021 |
-
}
|
9022 |
-
return debugInfoEnabled;
|
9023 |
-
};
|
9024 |
|
9025 |
-
/**
|
9026 |
-
* @ngdoc method
|
9027 |
-
* @name $compileProvider#strictComponentBindingsEnabled
|
9028 |
-
*
|
9029 |
-
* @param {boolean=} enabled update the strictComponentBindingsEnabled state if provided,
|
9030 |
-
* otherwise return the current strictComponentBindingsEnabled state.
|
9031 |
-
* @returns {*} current value if used as getter or itself (chaining) if used as setter
|
9032 |
-
*
|
9033 |
-
* @kind function
|
9034 |
-
*
|
9035 |
-
* @description
|
9036 |
-
* Call this method to enable / disable the strict component bindings check. If enabled, the
|
9037 |
-
* compiler will enforce that all scope / controller bindings of a
|
9038 |
-
* {@link $compileProvider#directive directive} / {@link $compileProvider#component component}
|
9039 |
-
* that are not set as optional with `?`, must be provided when the directive is instantiated.
|
9040 |
-
* If not provided, the compiler will throw the
|
9041 |
-
* {@link error/$compile/missingattr $compile:missingattr error}.
|
9042 |
-
*
|
9043 |
-
* The default value is false.
|
9044 |
-
*/
|
9045 |
-
var strictComponentBindingsEnabled = false;
|
9046 |
-
this.strictComponentBindingsEnabled = function(enabled) {
|
9047 |
-
if (isDefined(enabled)) {
|
9048 |
-
strictComponentBindingsEnabled = enabled;
|
9049 |
-
return this;
|
9050 |
-
}
|
9051 |
-
return strictComponentBindingsEnabled;
|
9052 |
-
};
|
9053 |
|
9054 |
-
|
9055 |
-
|
9056 |
-
|
9057 |
-
|
9058 |
-
|
9059 |
-
|
9060 |
-
|
9061 |
-
|
9062 |
-
|
9063 |
-
|
9064 |
-
|
9065 |
-
|
9066 |
-
|
9067 |
-
|
9068 |
-
|
9069 |
-
|
9070 |
-
|
9071 |
-
|
9072 |
-
|
9073 |
-
|
9074 |
-
|
9075 |
-
|
9076 |
-
|
9077 |
-
|
9078 |
-
|
9079 |
-
|
9080 |
-
|
9081 |
-
|
9082 |
|
9083 |
-
|
9084 |
-
|
9085 |
-
|
9086 |
-
|
9087 |
-
|
9088 |
-
|
9089 |
-
|
9090 |
-
|
9091 |
-
|
9092 |
-
|
9093 |
-
|
9094 |
-
|
9095 |
-
|
9096 |
-
|
9097 |
-
|
9098 |
-
|
9099 |
-
|
9100 |
-
|
9101 |
-
|
9102 |
-
|
9103 |
-
|
9104 |
-
|
9105 |
-
|
9106 |
-
|
9107 |
-
|
9108 |
-
|
9109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9110 |
|
9111 |
|
9112 |
-
|
9113 |
-
|
9114 |
-
|
9115 |
-
|
9116 |
-
|
9117 |
-
|
9118 |
-
|
9119 |
-
|
9120 |
-
|
9121 |
-
|
9122 |
-
|
9123 |
-
|
9124 |
-
|
9125 |
-
|
9126 |
-
|
9127 |
-
|
9128 |
-
|
9129 |
-
|
9130 |
-
|
9131 |
-
|
9132 |
-
|
9133 |
-
|
9134 |
-
|
9135 |
-
|
9136 |
-
|
9137 |
-
|
9138 |
-
|
9139 |
|
9140 |
|
9141 |
-
|
9142 |
-
|
9143 |
-
|
9144 |
-
|
9145 |
-
|
9146 |
|
9147 |
-
|
9148 |
-
|
9149 |
-
|
9150 |
-
|
9151 |
-
|
9152 |
-
|
9153 |
-
|
9154 |
-
|
9155 |
-
|
9156 |
-
|
9157 |
-
|
9158 |
-
|
9159 |
-
|
9160 |
-
|
9161 |
|
9162 |
-
|
9163 |
-
|
9164 |
-
|
9165 |
|
9166 |
-
|
9167 |
-
|
9168 |
-
|
9169 |
|
9170 |
-
|
9171 |
*
|
9172 |
* Copy of https://github.com/angular/angular/blob/6.0.6/packages/compiler/src/schema/dom_security_schema.ts#L31-L58
|
9173 |
* Changing:
|
@@ -9176,3169 +9176,3169 @@
|
|
9176 |
* - various URL => MEDIA_URL
|
9177 |
* - *|formAction, form|action URL => RESOURCE_URL (like the attribute)
|
9178 |
*/
|
9179 |
-
|
9180 |
-
|
9181 |
-
|
9182 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9183 |
|
9184 |
-
|
9185 |
-
|
9186 |
-
'*|innerHTML',
|
9187 |
-
'*|outerHTML'
|
9188 |
-
]);
|
9189 |
-
registerContext(SCE_CONTEXTS.CSS, ['*|style']);
|
9190 |
-
registerContext(SCE_CONTEXTS.URL, [
|
9191 |
-
'area|href', 'area|ping',
|
9192 |
-
'a|href', 'a|ping',
|
9193 |
-
'blockquote|cite',
|
9194 |
-
'body|background',
|
9195 |
-
'del|cite',
|
9196 |
-
'input|src',
|
9197 |
-
'ins|cite',
|
9198 |
-
'q|cite'
|
9199 |
-
]);
|
9200 |
-
registerContext(SCE_CONTEXTS.MEDIA_URL, [
|
9201 |
-
'audio|src',
|
9202 |
-
'img|src', 'img|srcset',
|
9203 |
-
'source|src', 'source|srcset',
|
9204 |
-
'track|src',
|
9205 |
-
'video|src', 'video|poster'
|
9206 |
-
]);
|
9207 |
-
registerContext(SCE_CONTEXTS.RESOURCE_URL, [
|
9208 |
-
'*|formAction',
|
9209 |
-
'applet|code', 'applet|codebase',
|
9210 |
-
'base|href',
|
9211 |
-
'embed|src',
|
9212 |
-
'frame|src',
|
9213 |
-
'form|action',
|
9214 |
-
'head|profile',
|
9215 |
-
'html|manifest',
|
9216 |
-
'iframe|src',
|
9217 |
-
'link|href',
|
9218 |
-
'media|src',
|
9219 |
-
'object|codebase', 'object|data',
|
9220 |
-
'script|src'
|
9221 |
-
]);
|
9222 |
-
})();
|
9223 |
-
|
9224 |
-
|
9225 |
-
this.$get = [
|
9226 |
'$injector', '$interpolate', '$exceptionHandler', '$templateRequest', '$parse',
|
9227 |
'$controller', '$rootScope', '$sce', '$animate',
|
9228 |
-
|
9229 |
-
|
9230 |
|
9231 |
-
|
9232 |
-
|
9233 |
|
9234 |
|
9235 |
-
|
9236 |
-
|
9237 |
|
9238 |
|
9239 |
-
|
9240 |
-
|
9241 |
-
|
9242 |
-
|
9243 |
|
9244 |
-
|
9245 |
-
|
9246 |
-
|
9247 |
-
|
9248 |
-
|
9249 |
-
|
9250 |
-
|
9251 |
-
|
9252 |
-
|
9253 |
-
|
9254 |
-
|
9255 |
-
|
9256 |
-
|
9257 |
-
|
9258 |
-
|
9259 |
-
|
9260 |
-
|
9261 |
-
|
9262 |
-
|
9263 |
-
|
9264 |
-
|
9265 |
-
|
9266 |
-
|
9267 |
-
|
9268 |
|
9269 |
|
9270 |
-
|
9271 |
-
|
9272 |
-
|
9273 |
-
|
9274 |
-
|
9275 |
-
|
9276 |
-
|
9277 |
|
9278 |
-
|
9279 |
-
|
9280 |
-
|
9281 |
-
|
9282 |
-
|
9283 |
-
|
9284 |
-
|
9285 |
-
|
9286 |
-
|
9287 |
-
|
9288 |
-
|
9289 |
-
|
9290 |
-
|
9291 |
-
|
9292 |
-
|
9293 |
-
|
9294 |
-
|
9295 |
-
|
9296 |
-
|
9297 |
-
|
9298 |
-
|
9299 |
-
|
9300 |
-
|
9301 |
-
|
9302 |
-
|
9303 |
-
|
9304 |
-
|
9305 |
-
|
9306 |
|
9307 |
-
|
9308 |
-
|
9309 |
|
9310 |
-
|
9311 |
-
|
9312 |
|
9313 |
-
|
9314 |
-
|
9315 |
-
|
9316 |
-
|
9317 |
-
|
9318 |
-
|
9319 |
|
9320 |
|
9321 |
-
|
9322 |
-
|
9323 |
-
|
9324 |
-
|
9325 |
|
9326 |
-
|
9327 |
-
|
9328 |
-
|
9329 |
-
|
9330 |
-
|
9331 |
-
|
9332 |
-
|
9333 |
|
9334 |
-
|
9335 |
-
|
9336 |
|
9337 |
-
|
9338 |
-
|
9339 |
-
|
9340 |
-
|
9341 |
-
|
9342 |
-
|
9343 |
-
|
9344 |
-
|
9345 |
-
|
9346 |
-
|
9347 |
-
|
9348 |
-
|
9349 |
-
|
9350 |
-
|
9351 |
-
|
9352 |
-
|
9353 |
-
|
9354 |
|
9355 |
|
9356 |
-
|
9357 |
-
|
9358 |
-
|
9359 |
-
|
9360 |
-
|
9361 |
-
|
9362 |
-
|
9363 |
-
|
9364 |
-
|
9365 |
-
|
9366 |
-
|
9367 |
-
|
9368 |
-
|
9369 |
-
|
9370 |
-
|
9371 |
-
|
9372 |
|
9373 |
-
|
9374 |
-
|
9375 |
-
|
9376 |
-
|
9377 |
-
|
9378 |
-
|
9379 |
-
|
9380 |
-
|
9381 |
-
|
9382 |
-
|
9383 |
-
|
9384 |
-
|
9385 |
-
|
9386 |
-
|
9387 |
-
|
9388 |
-
|
9389 |
|
9390 |
-
|
9391 |
-
|
9392 |
-
|
9393 |
-
|
9394 |
-
|
9395 |
-
|
9396 |
-
|
9397 |
-
|
9398 |
-
|
9399 |
-
|
9400 |
-
|
9401 |
-
|
9402 |
-
|
9403 |
-
|
9404 |
-
|
9405 |
-
|
9406 |
-
|
9407 |
|
9408 |
-
|
9409 |
-
|
9410 |
-
|
9411 |
-
|
9412 |
-
|
9413 |
|
9414 |
-
|
9415 |
-
|
9416 |
-
|
9417 |
-
|
9418 |
-
|
9419 |
-
|
9420 |
-
|
9421 |
-
|
9422 |
-
|
9423 |
-
|
9424 |
-
|
9425 |
-
|
9426 |
-
|
9427 |
-
|
9428 |
-
|
9429 |
-
|
9430 |
-
|
9431 |
-
|
9432 |
-
|
9433 |
-
|
9434 |
-
|
9435 |
-
|
9436 |
-
|
9437 |
-
|
9438 |
-
|
9439 |
-
|
9440 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9441 |
|
9442 |
-
|
9443 |
|
9444 |
-
|
9445 |
-
|
9446 |
-
|
9447 |
-
|
9448 |
-
attrName = this.$attr[key];
|
9449 |
-
if (!attrName) {
|
9450 |
-
this.$attr[key] = attrName = snake_case(key, '-');
|
9451 |
-
}
|
9452 |
-
}
|
9453 |
|
9454 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9455 |
|
9456 |
-
|
9457 |
-
|
9458 |
-
|
9459 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9460 |
|
9461 |
-
if (writeAttr !== false) {
|
9462 |
-
if (value === null || isUndefined(value)) {
|
9463 |
-
this.$$element.removeAttr(attrName);
|
9464 |
-
} else {
|
9465 |
-
if (SIMPLE_ATTR_NAME.test(attrName)) {
|
9466 |
-
// jQuery skips special boolean attrs treatment in XML nodes for
|
9467 |
-
// historical reasons and hence AngularJS cannot freely call
|
9468 |
-
// `.attr(attrName, false) with such attributes. To avoid issues
|
9469 |
-
// in XHTML, call `removeAttr` in such cases instead.
|
9470 |
-
// See https://github.com/jquery/jquery/issues/4249
|
9471 |
-
if (booleanKey && value === false) {
|
9472 |
-
this.$$element.removeAttr(attrName);
|
9473 |
-
} else {
|
9474 |
-
this.$$element.attr(attrName, value);
|
9475 |
-
}
|
9476 |
-
} else {
|
9477 |
-
setSpecialAttr(this.$$element[0], attrName, value);
|
9478 |
-
}
|
9479 |
-
}
|
9480 |
-
}
|
9481 |
|
9482 |
-
|
9483 |
-
|
9484 |
-
|
9485 |
-
|
9486 |
-
|
9487 |
-
|
9488 |
-
|
9489 |
-
|
9490 |
-
|
9491 |
-
|
9492 |
-
|
9493 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9494 |
|
|
|
|
|
|
|
|
|
|
|
9495 |
|
9496 |
-
|
9497 |
-
|
9498 |
-
|
9499 |
-
|
9500 |
-
|
9501 |
-
|
9502 |
-
|
9503 |
-
|
9504 |
-
|
9505 |
-
|
9506 |
-
|
9507 |
-
|
9508 |
-
|
9509 |
-
|
9510 |
-
|
9511 |
-
|
9512 |
-
|
9513 |
-
|
9514 |
-
|
9515 |
-
|
9516 |
-
|
9517 |
-
$$observers = (attrs.$$observers || (attrs.$$observers = createMap())),
|
9518 |
-
listeners = ($$observers[key] || ($$observers[key] = []));
|
9519 |
-
|
9520 |
-
listeners.push(fn);
|
9521 |
-
$rootScope.$evalAsync(function() {
|
9522 |
-
if (!listeners.$$inter && attrs.hasOwnProperty(key) && !isUndefined(attrs[key])) {
|
9523 |
-
// no one registered attribute interpolation function, so lets call it manually
|
9524 |
-
fn(attrs[key]);
|
9525 |
-
}
|
9526 |
-
});
|
9527 |
|
9528 |
-
return function() {
|
9529 |
-
arrayRemove(listeners, fn);
|
9530 |
-
};
|
9531 |
-
}
|
9532 |
-
};
|
9533 |
|
9534 |
-
|
9535 |
-
|
9536 |
-
|
9537 |
-
|
9538 |
-
|
9539 |
-
|
9540 |
-
|
9541 |
-
|
9542 |
-
|
9543 |
-
attribute.value = value;
|
9544 |
-
element.attributes.setNamedItem(attribute);
|
9545 |
-
}
|
9546 |
-
|
9547 |
-
function safeAddClass($element, className) {
|
9548 |
-
try {
|
9549 |
-
$element.addClass(className);
|
9550 |
-
} catch (e) {
|
9551 |
-
// ignore, since it means that we are trying to set class on
|
9552 |
-
// SVG element, where class name is read-only.
|
9553 |
-
}
|
9554 |
-
}
|
9555 |
|
|
|
|
|
9556 |
|
9557 |
-
|
9558 |
-
|
9559 |
-
|
9560 |
-
|
9561 |
-
|
9562 |
-
return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
|
9563 |
-
},
|
9564 |
-
NG_PREFIX_BINDING = /^ng(Attr|Prop|On)([A-Z].*)$/;
|
9565 |
-
var MULTI_ELEMENT_DIR_RE = /^(.+)Start$/;
|
9566 |
|
9567 |
-
|
9568 |
-
|
9569 |
|
9570 |
-
|
9571 |
-
|
9572 |
-
|
9573 |
-
bindings.push(binding);
|
9574 |
-
}
|
9575 |
|
9576 |
-
|
9577 |
-
|
|
|
|
|
9578 |
|
9579 |
-
|
9580 |
-
|
9581 |
-
|
9582 |
|
9583 |
-
|
9584 |
-
|
9585 |
-
|
9586 |
-
|
|
|
|
|
|
|
|
|
9587 |
|
9588 |
-
|
9589 |
-
safeAddClass($element, isolated ? 'ng-isolate-scope' : 'ng-scope');
|
9590 |
-
} : noop;
|
9591 |
|
9592 |
-
|
9593 |
-
var content = '';
|
9594 |
-
if (debugInfoEnabled) {
|
9595 |
-
content = ' ' + (directiveName || '') + ': ';
|
9596 |
-
if (comment) content += comment + ' ';
|
9597 |
-
}
|
9598 |
-
return window.document.createComment(content);
|
9599 |
-
};
|
9600 |
|
9601 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9602 |
|
9603 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
9604 |
|
9605 |
-
|
9606 |
-
|
9607 |
-
|
9608 |
-
|
9609 |
-
|
9610 |
-
|
9611 |
-
|
9612 |
-
|
9613 |
-
|
9614 |
-
|
9615 |
-
|
9616 |
-
|
9617 |
-
|
9618 |
-
|
9619 |
-
|
9620 |
-
|
9621 |
-
|
9622 |
-
|
9623 |
-
|
9624 |
-
|
9625 |
-
|
9626 |
-
|
9627 |
-
|
9628 |
-
|
9629 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9630 |
|
9631 |
-
|
9632 |
-
|
9633 |
-
|
9634 |
-
|
9635 |
-
|
9636 |
-
// When `parentBoundTranscludeFn` is passed, it is a
|
9637 |
-
// `controllersBoundTransclude` function (it was previously passed
|
9638 |
-
// as `transclude` to directive.link) so we must unwrap it to get
|
9639 |
-
// its `boundTranscludeFn`
|
9640 |
-
if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) {
|
9641 |
-
parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude;
|
9642 |
-
}
|
9643 |
|
9644 |
-
|
9645 |
-
namespace = detectNamespaceForChildElements(futureParentElement);
|
9646 |
-
}
|
9647 |
-
var $linkNode;
|
9648 |
-
if (namespace !== 'html') {
|
9649 |
-
// When using a directive with replace:true and templateUrl the $compileNodes
|
9650 |
-
// (or a child element inside of them)
|
9651 |
-
// might change, so we need to recreate the namespace adapted compileNodes
|
9652 |
-
// for call to the link function.
|
9653 |
-
// Note: This will already clone the nodes...
|
9654 |
-
$linkNode = jqLite(
|
9655 |
-
wrapTemplate(namespace, jqLite('<div></div>').append($compileNodes).html())
|
9656 |
-
);
|
9657 |
-
} else if (cloneConnectFn) {
|
9658 |
-
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
|
9659 |
-
// and sometimes changes the structure of the DOM.
|
9660 |
-
$linkNode = JQLitePrototype.clone.call($compileNodes);
|
9661 |
-
} else {
|
9662 |
-
$linkNode = $compileNodes;
|
9663 |
-
}
|
9664 |
|
9665 |
-
|
9666 |
-
|
9667 |
-
$linkNode.data('$' + controllerName + 'Controller', transcludeControllers[controllerName].instance);
|
9668 |
-
}
|
9669 |
-
}
|
9670 |
|
9671 |
-
|
|
|
|
|
|
|
|
|
|
|
9672 |
|
9673 |
-
|
9674 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9675 |
|
9676 |
-
|
9677 |
-
|
9678 |
-
|
9679 |
-
|
9680 |
-
|
9681 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9682 |
|
9683 |
-
function detectNamespaceForChildElements(parentElement) {
|
9684 |
-
// TODO: Make this detect MathML as well...
|
9685 |
-
var node = parentElement && parentElement[0];
|
9686 |
-
if (!node) {
|
9687 |
-
return 'html';
|
9688 |
-
} else {
|
9689 |
-
return nodeName_(node) !== 'foreignobject' && toString.call(node).match(/SVG/) ? 'svg' : 'html';
|
9690 |
-
}
|
9691 |
-
}
|
9692 |
|
9693 |
-
|
9694 |
-
|
9695 |
-
* for a particular node are collected their compile functions are executed. The compile
|
9696 |
-
* functions return values - the linking functions - are combined into a composite linking
|
9697 |
-
* function, which is the a linking function for the node.
|
9698 |
-
*
|
9699 |
-
* @param {NodeList} nodeList an array of nodes or NodeList to compile
|
9700 |
-
* @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
|
9701 |
-
* scope argument is auto-generated to the new child of the transcluded parent scope.
|
9702 |
-
* @param {DOMElement=} $rootElement If the nodeList is the root of the compilation tree then
|
9703 |
-
* the rootElement must be set the jqLite collection of the compile root. This is
|
9704 |
-
* needed so that the jqLite collection items can be replaced with widgets.
|
9705 |
-
* @param {number=} maxPriority Max directive priority.
|
9706 |
-
* @returns {Function} A composite linking function of all of the matched directives or null.
|
9707 |
-
*/
|
9708 |
-
function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective,
|
9709 |
-
previousCompileContext) {
|
9710 |
-
var linkFns = [],
|
9711 |
-
// `nodeList` can be either an element's `.childNodes` (live NodeList)
|
9712 |
-
// or a jqLite/jQuery collection or an array
|
9713 |
-
notLiveList = isArray(nodeList) || (nodeList instanceof jqLite),
|
9714 |
-
attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound;
|
9715 |
-
|
9716 |
-
|
9717 |
-
for (var i = 0; i < nodeList.length; i++) {
|
9718 |
-
attrs = new Attributes();
|
9719 |
-
|
9720 |
-
// Support: IE 11 only
|
9721 |
-
// Workaround for #11781 and #14924
|
9722 |
-
if (msie === 11) {
|
9723 |
-
mergeConsecutiveTextNodes(nodeList, i, notLiveList);
|
9724 |
-
}
|
9725 |
|
9726 |
-
|
9727 |
-
|
9728 |
-
|
9729 |
-
|
|
|
9730 |
|
9731 |
-
|
9732 |
-
|
9733 |
-
|
9734 |
-
|
9735 |
|
9736 |
-
|
9737 |
-
|
9738 |
-
|
|
|
9739 |
|
9740 |
-
|
9741 |
-
|
9742 |
-
|
9743 |
-
? null
|
9744 |
-
: compileNodes(childNodes,
|
9745 |
-
nodeLinkFn ? (
|
9746 |
-
(nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement)
|
9747 |
-
&& nodeLinkFn.transclude) : transcludeFn);
|
9748 |
-
|
9749 |
-
if (nodeLinkFn || childLinkFn) {
|
9750 |
-
linkFns.push(i, nodeLinkFn, childLinkFn);
|
9751 |
-
linkFnFound = true;
|
9752 |
-
nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn;
|
9753 |
-
}
|
9754 |
|
9755 |
-
|
9756 |
-
|
9757 |
-
|
|
|
|
|
|
|
|
|
|
|
9758 |
|
9759 |
-
|
9760 |
-
|
|
|
|
|
|
|
9761 |
|
9762 |
-
|
9763 |
-
|
9764 |
-
|
9765 |
|
|
|
|
|
9766 |
|
9767 |
-
|
9768 |
-
|
9769 |
-
|
9770 |
-
var nodeListLength = nodeList.length;
|
9771 |
-
stableNodeList = new Array(nodeListLength);
|
9772 |
|
9773 |
-
// create a sparse array by only copying the elements which have a linkFn
|
9774 |
-
for (i = 0; i < linkFns.length; i += 3) {
|
9775 |
-
idx = linkFns[i];
|
9776 |
-
stableNodeList[idx] = nodeList[idx];
|
9777 |
-
}
|
9778 |
-
} else {
|
9779 |
-
stableNodeList = nodeList;
|
9780 |
-
}
|
9781 |
|
9782 |
-
|
9783 |
-
|
9784 |
-
|
9785 |
-
|
9786 |
-
|
9787 |
-
if (nodeLinkFn) {
|
9788 |
-
if (nodeLinkFn.scope) {
|
9789 |
-
childScope = scope.$new();
|
9790 |
-
compile.$$addScopeInfo(jqLite(node), childScope);
|
9791 |
-
} else {
|
9792 |
-
childScope = scope;
|
9793 |
-
}
|
9794 |
|
9795 |
-
|
9796 |
-
|
9797 |
-
|
|
|
|
|
|
|
|
|
|
|
9798 |
|
9799 |
-
|
9800 |
-
|
|
|
|
|
9801 |
|
9802 |
-
|
9803 |
-
|
|
|
|
|
|
|
|
|
|
|
9804 |
|
9805 |
-
|
9806 |
-
|
9807 |
-
|
9808 |
|
9809 |
-
|
|
|
9810 |
|
9811 |
-
|
9812 |
-
|
9813 |
-
}
|
9814 |
-
}
|
9815 |
-
}
|
9816 |
-
}
|
9817 |
|
9818 |
-
|
9819 |
-
|
9820 |
-
|
9821 |
-
var sibling;
|
9822 |
|
9823 |
-
|
9824 |
-
return;
|
9825 |
-
}
|
9826 |
|
9827 |
-
|
9828 |
-
|
9829 |
-
|
9830 |
-
|
9831 |
-
|
|
|
9832 |
|
9833 |
-
|
|
|
|
|
|
|
9834 |
|
9835 |
-
|
9836 |
-
|
9837 |
-
|
9838 |
-
if (notLiveList && sibling === nodeList[idx + 1]) {
|
9839 |
-
nodeList.splice(idx + 1, 1);
|
9840 |
-
}
|
9841 |
-
}
|
9842 |
-
}
|
9843 |
|
9844 |
-
|
9845 |
-
|
|
|
|
|
|
|
9846 |
|
9847 |
-
|
9848 |
-
transcludedScope = scope.$new(false, containingScope);
|
9849 |
-
transcludedScope.$$transcluded = true;
|
9850 |
-
}
|
9851 |
|
9852 |
-
|
9853 |
-
|
9854 |
-
|
9855 |
-
|
9856 |
-
|
9857 |
-
|
|
|
|
|
9858 |
|
9859 |
-
|
9860 |
-
|
9861 |
-
var boundSlots = boundTranscludeFn.$$slots = createMap();
|
9862 |
-
for (var slotName in transcludeFn.$$slots) {
|
9863 |
-
if (transcludeFn.$$slots[slotName]) {
|
9864 |
-
boundSlots[slotName] = createBoundTranscludeFn(scope, transcludeFn.$$slots[slotName], previousBoundTranscludeFn);
|
9865 |
-
} else {
|
9866 |
-
boundSlots[slotName] = null;
|
9867 |
-
}
|
9868 |
-
}
|
9869 |
|
9870 |
-
|
9871 |
-
|
|
|
|
|
9872 |
|
9873 |
-
|
9874 |
-
|
9875 |
-
|
9876 |
-
|
9877 |
-
|
9878 |
-
|
9879 |
-
* the function returns.
|
9880 |
-
* @param attrs The shared attrs object which is used to populate the normalized attributes.
|
9881 |
-
* @param {number=} maxPriority Max directive priority.
|
9882 |
-
*/
|
9883 |
-
function collectDirectives(node, directives, attrs, maxPriority, ignoreDirective) {
|
9884 |
-
var nodeType = node.nodeType,
|
9885 |
-
attrsMap = attrs.$attr,
|
9886 |
-
match,
|
9887 |
-
nodeName,
|
9888 |
-
className;
|
9889 |
-
|
9890 |
-
switch (nodeType) {
|
9891 |
-
case NODE_TYPE_ELEMENT: /* Element */
|
9892 |
-
|
9893 |
-
nodeName = nodeName_(node);
|
9894 |
-
|
9895 |
-
// use the node name: <directive>
|
9896 |
-
addDirective(directives,
|
9897 |
-
directiveNormalize(nodeName), 'E', maxPriority, ignoreDirective);
|
9898 |
-
|
9899 |
-
// iterate over the attributes
|
9900 |
-
for (var attr, name, nName, value, ngPrefixMatch, nAttrs = node.attributes,
|
9901 |
-
j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {
|
9902 |
-
var attrStartName = false;
|
9903 |
-
var attrEndName = false;
|
9904 |
-
|
9905 |
-
var isNgAttr = false, isNgProp = false, isNgEvent = false;
|
9906 |
-
var multiElementMatch;
|
9907 |
-
|
9908 |
-
attr = nAttrs[j];
|
9909 |
-
name = attr.name;
|
9910 |
-
value = attr.value;
|
9911 |
-
|
9912 |
-
nName = directiveNormalize(name.toLowerCase());
|
9913 |
-
|
9914 |
-
// Support ng-attr-*, ng-prop-* and ng-on-*
|
9915 |
-
if ((ngPrefixMatch = nName.match(NG_PREFIX_BINDING))) {
|
9916 |
-
isNgAttr = ngPrefixMatch[1] === 'Attr';
|
9917 |
-
isNgProp = ngPrefixMatch[1] === 'Prop';
|
9918 |
-
isNgEvent = ngPrefixMatch[1] === 'On';
|
9919 |
-
|
9920 |
-
// Normalize the non-prefixed name
|
9921 |
-
name = name.replace(PREFIX_REGEXP, '')
|
9922 |
-
.toLowerCase()
|
9923 |
-
.substr(4 + ngPrefixMatch[1].length).replace(/_(.)/g, function(match, letter) {
|
9924 |
-
return letter.toUpperCase();
|
9925 |
-
});
|
9926 |
|
9927 |
-
|
9928 |
-
|
9929 |
-
|
9930 |
-
|
9931 |
-
|
9932 |
-
|
|
|
|
|
|
|
|
|
9933 |
|
9934 |
-
|
9935 |
-
|
9936 |
-
attrsMap[nName] = attr.name;
|
9937 |
|
9938 |
-
|
9939 |
-
|
9940 |
-
|
9941 |
-
|
9942 |
-
|
9943 |
-
|
9944 |
-
|
9945 |
-
|
9946 |
-
|
9947 |
-
|
9948 |
-
|
9949 |
-
|
9950 |
-
|
9951 |
-
|
9952 |
-
|
9953 |
-
|
9954 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9955 |
|
9956 |
-
|
9957 |
-
|
9958 |
-
|
9959 |
-
|
9960 |
-
|
|
|
9961 |
|
9962 |
-
|
9963 |
-
|
9964 |
-
|
9965 |
-
node.setAttribute('autocomplete', 'off');
|
9966 |
-
}
|
9967 |
|
9968 |
-
|
9969 |
-
|
9970 |
-
|
9971 |
-
|
9972 |
-
|
9973 |
-
|
9974 |
-
|
9975 |
-
|
9976 |
-
|
9977 |
-
|
9978 |
-
if (addDirective(directives, nName, 'C', maxPriority, ignoreDirective)) {
|
9979 |
-
attrs[nName] = trim(match[3]);
|
9980 |
-
}
|
9981 |
-
className = className.substr(match.index + match[0].length);
|
9982 |
-
}
|
9983 |
-
}
|
9984 |
-
break;
|
9985 |
-
case NODE_TYPE_TEXT: /* Text Node */
|
9986 |
-
addTextInterpolateDirective(directives, node.nodeValue);
|
9987 |
-
break;
|
9988 |
-
case NODE_TYPE_COMMENT: /* Comment */
|
9989 |
-
if (!commentDirectivesEnabled) break;
|
9990 |
-
collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective);
|
9991 |
-
break;
|
9992 |
-
}
|
9993 |
|
9994 |
-
|
9995 |
-
|
|
|
|
|
9996 |
}
|
|
|
9997 |
|
9998 |
-
|
9999 |
-
|
10000 |
-
|
10001 |
-
|
10002 |
-
|
10003 |
-
if (match) {
|
10004 |
-
var nName = directiveNormalize(match[1]);
|
10005 |
-
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
|
10006 |
-
attrs[nName] = trim(match[2]);
|
10007 |
-
}
|
10008 |
-
}
|
10009 |
-
} catch (e) {
|
10010 |
-
// turns out that under some circumstances IE9 throws errors when one attempts to read
|
10011 |
-
// comment's node value.
|
10012 |
-
// Just ignore it and continue. (Can't seem to reproduce in test case.)
|
10013 |
-
}
|
10014 |
-
}
|
10015 |
|
10016 |
-
|
10017 |
-
|
10018 |
-
|
10019 |
-
|
10020 |
-
|
10021 |
-
* @param attrEnd
|
10022 |
-
* @returns {*}
|
10023 |
-
*/
|
10024 |
-
function groupScan(node, attrStart, attrEnd) {
|
10025 |
-
var nodes = [];
|
10026 |
-
var depth = 0;
|
10027 |
-
if (attrStart && node.hasAttribute && node.hasAttribute(attrStart)) {
|
10028 |
-
do {
|
10029 |
-
if (!node) {
|
10030 |
-
throw $compileMinErr('uterdir',
|
10031 |
-
'Unterminated attribute, found \'{0}\' but no matching \'{1}\' found.',
|
10032 |
-
attrStart, attrEnd);
|
10033 |
-
}
|
10034 |
-
if (node.nodeType === NODE_TYPE_ELEMENT) {
|
10035 |
-
if (node.hasAttribute(attrStart)) depth++;
|
10036 |
-
if (node.hasAttribute(attrEnd)) depth--;
|
10037 |
-
}
|
10038 |
-
nodes.push(node);
|
10039 |
-
node = node.nextSibling;
|
10040 |
-
} while (depth > 0);
|
10041 |
-
} else {
|
10042 |
-
nodes.push(node);
|
10043 |
-
}
|
10044 |
|
10045 |
-
|
10046 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10047 |
|
10048 |
-
|
10049 |
-
|
10050 |
-
|
10051 |
-
* @param linkFn
|
10052 |
-
* @param attrStart
|
10053 |
-
* @param attrEnd
|
10054 |
-
* @returns {Function}
|
10055 |
-
*/
|
10056 |
-
function groupElementsLinkFnWrapper(linkFn, attrStart, attrEnd) {
|
10057 |
-
return function groupedElementsLink(scope, element, attrs, controllers, transcludeFn) {
|
10058 |
-
element = groupScan(element[0], attrStart, attrEnd);
|
10059 |
-
return linkFn(scope, element, attrs, controllers, transcludeFn);
|
10060 |
-
};
|
10061 |
-
}
|
10062 |
|
10063 |
-
|
10064 |
-
|
10065 |
-
|
10066 |
-
|
10067 |
-
|
10068 |
-
|
10069 |
-
|
10070 |
-
|
10071 |
-
|
10072 |
-
|
10073 |
-
|
10074 |
-
|
10075 |
-
|
10076 |
-
|
10077 |
-
|
10078 |
-
|
10079 |
-
|
10080 |
-
return /** @this */ function lazyCompilation() {
|
10081 |
-
if (!compiled) {
|
10082 |
-
compiled = compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext);
|
10083 |
|
10084 |
-
|
10085 |
-
|
10086 |
-
|
10087 |
-
|
10088 |
-
|
10089 |
-
|
10090 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10091 |
|
10092 |
-
|
10093 |
-
|
10094 |
-
* is responsible for inlining directive templates as well as terminating the application
|
10095 |
-
* of the directives if the terminal directive has been reached.
|
10096 |
-
*
|
10097 |
-
* @param {Array} directives Array of collected directives to execute their compile function.
|
10098 |
-
* this needs to be pre-sorted by priority order.
|
10099 |
-
* @param {Node} compileNode The raw DOM node to apply the compile functions to
|
10100 |
-
* @param {Object} templateAttrs The shared attribute function
|
10101 |
-
* @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
|
10102 |
-
* scope argument is auto-generated to the new
|
10103 |
-
* child of the transcluded parent scope.
|
10104 |
-
* @param {JQLite} jqCollection If we are working on the root of the compile tree then this
|
10105 |
-
* argument has the root jqLite array so that we can replace nodes
|
10106 |
-
* on it.
|
10107 |
-
* @param {Object=} originalReplaceDirective An optional directive that will be ignored when
|
10108 |
-
* compiling the transclusion.
|
10109 |
-
* @param {Array.<Function>} preLinkFns
|
10110 |
-
* @param {Array.<Function>} postLinkFns
|
10111 |
-
* @param {Object} previousCompileContext Context used for previous compilation of the current
|
10112 |
-
* node
|
10113 |
-
* @returns {Function} linkFn
|
10114 |
-
*/
|
10115 |
-
function applyDirectivesToNode(directives, compileNode, templateAttrs, transcludeFn,
|
10116 |
-
jqCollection, originalReplaceDirective, preLinkFns, postLinkFns,
|
10117 |
-
previousCompileContext) {
|
10118 |
-
previousCompileContext = previousCompileContext || {};
|
10119 |
-
|
10120 |
-
var terminalPriority = -Number.MAX_VALUE,
|
10121 |
-
newScopeDirective = previousCompileContext.newScopeDirective,
|
10122 |
-
controllerDirectives = previousCompileContext.controllerDirectives,
|
10123 |
-
newIsolateScopeDirective = previousCompileContext.newIsolateScopeDirective,
|
10124 |
-
templateDirective = previousCompileContext.templateDirective,
|
10125 |
-
nonTlbTranscludeDirective = previousCompileContext.nonTlbTranscludeDirective,
|
10126 |
-
hasTranscludeDirective = false,
|
10127 |
-
hasTemplate = false,
|
10128 |
-
hasElementTranscludeDirective = previousCompileContext.hasElementTranscludeDirective,
|
10129 |
-
$compileNode = templateAttrs.$$element = jqLite(compileNode),
|
10130 |
-
directive,
|
10131 |
-
directiveName,
|
10132 |
-
$template,
|
10133 |
-
replaceDirective = originalReplaceDirective,
|
10134 |
-
childTranscludeFn = transcludeFn,
|
10135 |
-
linkFn,
|
10136 |
-
didScanForMultipleTransclusion = false,
|
10137 |
-
mightHaveMultipleTransclusionError = false,
|
10138 |
-
directiveValue;
|
10139 |
-
|
10140 |
-
// executes all directives on the current element
|
10141 |
-
for (var i = 0, ii = directives.length; i < ii; i++) {
|
10142 |
-
directive = directives[i];
|
10143 |
-
var attrStart = directive.$$start;
|
10144 |
-
var attrEnd = directive.$$end;
|
10145 |
-
|
10146 |
-
// collect multiblock sections
|
10147 |
-
if (attrStart) {
|
10148 |
-
$compileNode = groupScan(compileNode, attrStart, attrEnd);
|
10149 |
-
}
|
10150 |
-
$template = undefined;
|
10151 |
|
10152 |
-
|
10153 |
-
|
10154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10155 |
|
10156 |
-
|
10157 |
-
|
10158 |
-
|
10159 |
-
|
10160 |
-
|
10161 |
-
|
10162 |
-
|
10163 |
-
|
10164 |
-
|
10165 |
-
|
10166 |
-
|
10167 |
-
|
10168 |
-
|
10169 |
-
} else {
|
10170 |
-
// This directive is trying to add a child scope.
|
10171 |
-
// Check that there is no isolated scope already
|
10172 |
-
assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive,
|
10173 |
-
$compileNode);
|
10174 |
-
}
|
10175 |
-
}
|
10176 |
|
10177 |
-
|
10178 |
-
|
|
|
|
|
|
|
|
|
10179 |
|
10180 |
-
|
10181 |
-
|
10182 |
-
|
10183 |
-
|
10184 |
-
|
10185 |
-
|
10186 |
-
|
10187 |
-
// exceptions at the correct time
|
10188 |
-
if (!didScanForMultipleTransclusion && ((directive.replace && (directive.templateUrl || directive.template))
|
10189 |
-
|| (directive.transclude && !directive.$$tlb))) {
|
10190 |
-
var candidateDirective;
|
10191 |
-
|
10192 |
-
for (var scanningIndex = i + 1; (candidateDirective = directives[scanningIndex++]);) {
|
10193 |
-
if ((candidateDirective.transclude && !candidateDirective.$$tlb)
|
10194 |
-
|| (candidateDirective.replace && (candidateDirective.templateUrl || candidateDirective.template))) {
|
10195 |
-
mightHaveMultipleTransclusionError = true;
|
10196 |
-
break;
|
10197 |
-
}
|
10198 |
-
}
|
10199 |
|
10200 |
-
|
10201 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10202 |
|
10203 |
-
|
10204 |
-
|
10205 |
-
assertNoDuplicate('\'' + directiveName + '\' controller',
|
10206 |
-
controllerDirectives[directiveName], directive, $compileNode);
|
10207 |
-
controllerDirectives[directiveName] = directive;
|
10208 |
-
}
|
10209 |
|
10210 |
-
|
10211 |
|
10212 |
-
|
10213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10214 |
|
10215 |
-
|
10216 |
-
|
10217 |
-
|
10218 |
-
|
10219 |
-
|
10220 |
-
|
10221 |
-
|
10222 |
|
10223 |
-
|
10224 |
-
|
10225 |
-
terminalPriority = directive.priority;
|
10226 |
-
$template = $compileNode;
|
10227 |
-
$compileNode = templateAttrs.$$element =
|
10228 |
-
jqLite(compile.$$createComment(directiveName, templateAttrs[directiveName]));
|
10229 |
-
compileNode = $compileNode[0];
|
10230 |
-
replaceWith(jqCollection, sliceArgs($template), compileNode);
|
10231 |
-
|
10232 |
-
childTranscludeFn = compilationGenerator(mightHaveMultipleTransclusionError, $template, transcludeFn, terminalPriority,
|
10233 |
-
replaceDirective && replaceDirective.name, {
|
10234 |
-
// Don't pass in:
|
10235 |
-
// - controllerDirectives - otherwise we'll create duplicates controllers
|
10236 |
-
// - newIsolateScopeDirective or templateDirective - combining templates with
|
10237 |
-
// element transclusion doesn't make sense.
|
10238 |
-
//
|
10239 |
-
// We need only nonTlbTranscludeDirective so that we prevent putting transclusion
|
10240 |
-
// on the same element more than once.
|
10241 |
-
nonTlbTranscludeDirective: nonTlbTranscludeDirective
|
10242 |
-
});
|
10243 |
-
} else {
|
10244 |
-
|
10245 |
-
var slots = createMap();
|
10246 |
-
|
10247 |
-
if (!isObject(directiveValue)) {
|
10248 |
-
$template = jqLite(jqLiteClone(compileNode)).contents();
|
10249 |
-
} else {
|
10250 |
-
|
10251 |
-
// We have transclusion slots,
|
10252 |
-
// collect them up, compile them and store their transclusion functions
|
10253 |
-
$template = window.document.createDocumentFragment();
|
10254 |
-
|
10255 |
-
var slotMap = createMap();
|
10256 |
-
var filledSlots = createMap();
|
10257 |
-
|
10258 |
-
// Parse the element selectors
|
10259 |
-
forEach(directiveValue, function(elementSelector, slotName) {
|
10260 |
-
// If an element selector starts with a ? then it is optional
|
10261 |
-
var optional = (elementSelector.charAt(0) === '?');
|
10262 |
-
elementSelector = optional ? elementSelector.substring(1) : elementSelector;
|
10263 |
-
|
10264 |
-
slotMap[elementSelector] = slotName;
|
10265 |
-
|
10266 |
-
// We explicitly assign `null` since this implies that a slot was defined but not filled.
|
10267 |
-
// Later when calling boundTransclusion functions with a slot name we only error if the
|
10268 |
-
// slot is `undefined`
|
10269 |
-
slots[slotName] = null;
|
10270 |
-
|
10271 |
-
// filledSlots contains `true` for all slots that are either optional or have been
|
10272 |
-
// filled. This is used to check that we have not missed any required slots
|
10273 |
-
filledSlots[slotName] = optional;
|
10274 |
-
});
|
10275 |
-
|
10276 |
-
// Add the matching elements into their slot
|
10277 |
-
forEach($compileNode.contents(), function(node) {
|
10278 |
-
var slotName = slotMap[directiveNormalize(nodeName_(node))];
|
10279 |
-
if (slotName) {
|
10280 |
-
filledSlots[slotName] = true;
|
10281 |
-
slots[slotName] = slots[slotName] || window.document.createDocumentFragment();
|
10282 |
-
slots[slotName].appendChild(node);
|
10283 |
-
} else {
|
10284 |
-
$template.appendChild(node);
|
10285 |
-
}
|
10286 |
-
});
|
10287 |
-
|
10288 |
-
// Check for required slots that were not filled
|
10289 |
-
forEach(filledSlots, function(filled, slotName) {
|
10290 |
-
if (!filled) {
|
10291 |
-
throw $compileMinErr('reqslot', 'Required transclusion slot `{0}` was not filled.', slotName);
|
10292 |
-
}
|
10293 |
-
});
|
10294 |
-
|
10295 |
-
for (var slotName in slots) {
|
10296 |
-
if (slots[slotName]) {
|
10297 |
-
// Only define a transclusion function if the slot was filled
|
10298 |
-
var slotCompileNodes = jqLite(slots[slotName].childNodes);
|
10299 |
-
slots[slotName] = compilationGenerator(mightHaveMultipleTransclusionError, slotCompileNodes, transcludeFn);
|
10300 |
-
}
|
10301 |
-
}
|
10302 |
|
10303 |
-
|
10304 |
-
|
|
|
|
|
|
|
|
|
10305 |
|
10306 |
-
|
10307 |
-
childTranscludeFn = compilationGenerator(mightHaveMultipleTransclusionError, $template, transcludeFn, undefined,
|
10308 |
-
undefined, { needsNewScope: directive.$$isolateScope || directive.$$newScope});
|
10309 |
-
childTranscludeFn.$$slots = slots;
|
10310 |
-
}
|
10311 |
-
}
|
10312 |
|
10313 |
-
|
10314 |
-
|
10315 |
-
assertNoDuplicate('template', templateDirective, directive, $compileNode);
|
10316 |
-
templateDirective = directive;
|
10317 |
|
10318 |
-
|
10319 |
-
|
10320 |
-
|
|
|
|
|
|
|
|
|
10321 |
|
10322 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10323 |
|
10324 |
-
|
10325 |
-
replaceDirective = directive;
|
10326 |
-
if (jqLiteIsTextNode(directiveValue)) {
|
10327 |
-
$template = [];
|
10328 |
-
} else {
|
10329 |
-
$template = removeComments(wrapTemplate(directive.templateNamespace, trim(directiveValue)));
|
10330 |
-
}
|
10331 |
-
compileNode = $template[0];
|
10332 |
|
10333 |
-
|
10334 |
-
|
10335 |
-
|
10336 |
-
directiveName, '');
|
10337 |
-
}
|
10338 |
|
10339 |
-
|
|
|
|
|
10340 |
|
10341 |
-
|
|
|
10342 |
|
10343 |
-
|
10344 |
-
|
10345 |
-
|
10346 |
-
|
10347 |
-
|
10348 |
-
var templateDirectives = collectDirectives(compileNode, [], newTemplateAttrs);
|
10349 |
-
var unprocessedDirectives = directives.splice(i + 1, directives.length - (i + 1));
|
10350 |
|
10351 |
-
|
10352 |
-
// The original directive caused the current element to be replaced but this element
|
10353 |
-
// also needs to have a new scope, so we need to tell the template directives
|
10354 |
-
// that they would need to get their scope from further up, if they require transclusion
|
10355 |
-
markDirectiveScope(templateDirectives, newIsolateScopeDirective, newScopeDirective);
|
10356 |
-
}
|
10357 |
-
directives = directives.concat(templateDirectives).concat(unprocessedDirectives);
|
10358 |
-
mergeTemplateAttributes(templateAttrs, newTemplateAttrs);
|
10359 |
|
10360 |
-
|
10361 |
-
|
10362 |
-
|
10363 |
-
|
10364 |
-
}
|
10365 |
|
10366 |
-
|
10367 |
-
|
10368 |
-
|
10369 |
-
|
10370 |
|
10371 |
-
|
10372 |
-
|
10373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10374 |
|
10375 |
-
|
10376 |
-
|
10377 |
-
|
10378 |
-
|
10379 |
-
|
10380 |
-
|
10381 |
-
templateDirective: templateDirective,
|
10382 |
-
nonTlbTranscludeDirective: nonTlbTranscludeDirective
|
10383 |
-
});
|
10384 |
-
ii = directives.length;
|
10385 |
-
} else if (directive.compile) {
|
10386 |
-
try {
|
10387 |
-
linkFn = directive.compile($compileNode, templateAttrs, childTranscludeFn);
|
10388 |
-
var context = directive.$$originalDirective || directive;
|
10389 |
-
if (isFunction(linkFn)) {
|
10390 |
-
addLinkFns(null, bind(context, linkFn), attrStart, attrEnd);
|
10391 |
-
} else if (linkFn) {
|
10392 |
-
addLinkFns(bind(context, linkFn.pre), bind(context, linkFn.post), attrStart, attrEnd);
|
10393 |
-
}
|
10394 |
-
} catch (e) {
|
10395 |
-
$exceptionHandler(e, startingTag($compileNode));
|
10396 |
-
}
|
10397 |
-
}
|
10398 |
|
10399 |
-
|
10400 |
-
|
10401 |
-
|
10402 |
-
|
|
|
|
|
|
|
10403 |
|
10404 |
-
|
|
|
10405 |
|
10406 |
-
|
10407 |
-
|
10408 |
-
|
10409 |
-
|
|
|
|
|
10410 |
|
10411 |
-
|
|
|
|
|
|
|
10412 |
|
10413 |
-
|
10414 |
-
|
|
|
10415 |
|
10416 |
-
|
10417 |
|
10418 |
-
|
10419 |
-
|
10420 |
-
|
10421 |
-
|
10422 |
-
|
10423 |
-
|
10424 |
-
|
10425 |
-
|
10426 |
-
preLinkFns.push(pre);
|
10427 |
-
}
|
10428 |
-
if (post) {
|
10429 |
-
if (attrStart) post = groupElementsLinkFnWrapper(post, attrStart, attrEnd);
|
10430 |
-
post.require = directive.require;
|
10431 |
-
post.directiveName = directiveName;
|
10432 |
-
if (newIsolateScopeDirective === directive || directive.$$isolateScope) {
|
10433 |
-
post = cloneAndAnnotateFn(post, {isolateScope: true});
|
10434 |
-
}
|
10435 |
-
postLinkFns.push(post);
|
10436 |
-
}
|
10437 |
-
}
|
10438 |
|
10439 |
-
|
10440 |
-
|
10441 |
-
|
|
|
|
|
10442 |
|
10443 |
-
|
10444 |
-
attrs = templateAttrs;
|
10445 |
-
$element = templateAttrs.$$element;
|
10446 |
-
} else {
|
10447 |
-
$element = jqLite(linkNode);
|
10448 |
-
attrs = new Attributes($element, templateAttrs);
|
10449 |
-
}
|
10450 |
|
10451 |
-
|
10452 |
-
if (newIsolateScopeDirective) {
|
10453 |
-
isolateScope = scope.$new(true);
|
10454 |
-
} else if (newScopeDirective) {
|
10455 |
-
controllerScope = scope.$parent;
|
10456 |
-
}
|
10457 |
|
10458 |
-
|
10459 |
-
|
10460 |
-
|
10461 |
-
|
10462 |
-
|
10463 |
-
|
10464 |
-
|
10465 |
-
return !!boundTranscludeFn.$$slots[slotName];
|
10466 |
-
};
|
10467 |
-
}
|
10468 |
|
10469 |
-
|
10470 |
-
|
10471 |
-
|
|
|
|
|
|
|
|
|
|
|
10472 |
|
10473 |
-
|
10474 |
-
|
10475 |
-
|
10476 |
-
|
10477 |
-
|
10478 |
-
isolateScope.$$isolateBindings =
|
10479 |
-
newIsolateScopeDirective.$$isolateBindings;
|
10480 |
-
scopeBindingInfo = initializeDirectiveBindings(scope, attrs, isolateScope,
|
10481 |
-
isolateScope.$$isolateBindings,
|
10482 |
-
newIsolateScopeDirective);
|
10483 |
-
if (scopeBindingInfo.removeWatches) {
|
10484 |
-
isolateScope.$on('$destroy', scopeBindingInfo.removeWatches);
|
10485 |
-
}
|
10486 |
-
}
|
10487 |
|
10488 |
-
|
10489 |
-
|
10490 |
-
|
10491 |
-
|
10492 |
-
var bindings = controllerDirective.$$bindings.bindToController;
|
10493 |
|
10494 |
-
|
10495 |
-
|
10496 |
-
|
10497 |
-
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
|
10498 |
-
}
|
10499 |
|
10500 |
-
|
10501 |
-
|
10502 |
-
|
10503 |
-
|
10504 |
-
|
10505 |
-
|
10506 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10507 |
|
10508 |
-
|
10509 |
-
|
10510 |
-
|
10511 |
-
|
10512 |
-
try {
|
10513 |
-
controllerInstance.$onChanges(controller.bindingInfo.initialChanges);
|
10514 |
-
} catch (e) {
|
10515 |
-
$exceptionHandler(e);
|
10516 |
-
}
|
10517 |
-
}
|
10518 |
-
if (isFunction(controllerInstance.$onInit)) {
|
10519 |
-
try {
|
10520 |
-
controllerInstance.$onInit();
|
10521 |
-
} catch (e) {
|
10522 |
-
$exceptionHandler(e);
|
10523 |
-
}
|
10524 |
-
}
|
10525 |
-
if (isFunction(controllerInstance.$doCheck)) {
|
10526 |
-
controllerScope.$watch(function() { controllerInstance.$doCheck(); });
|
10527 |
-
controllerInstance.$doCheck();
|
10528 |
-
}
|
10529 |
-
if (isFunction(controllerInstance.$onDestroy)) {
|
10530 |
-
controllerScope.$on('$destroy', function callOnDestroyHook() {
|
10531 |
-
controllerInstance.$onDestroy();
|
10532 |
-
});
|
10533 |
-
}
|
10534 |
-
});
|
10535 |
|
10536 |
-
|
10537 |
-
for (i = 0, ii = preLinkFns.length; i < ii; i++) {
|
10538 |
-
linkFn = preLinkFns[i];
|
10539 |
-
invokeLinkFn(linkFn,
|
10540 |
-
linkFn.isolateScope ? isolateScope : scope,
|
10541 |
-
$element,
|
10542 |
-
attrs,
|
10543 |
-
linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),
|
10544 |
-
transcludeFn
|
10545 |
-
);
|
10546 |
-
}
|
10547 |
|
10548 |
-
|
10549 |
-
|
10550 |
-
|
10551 |
-
|
10552 |
-
if (newIsolateScopeDirective && (newIsolateScopeDirective.template || newIsolateScopeDirective.templateUrl === null)) {
|
10553 |
-
scopeToChild = isolateScope;
|
10554 |
-
}
|
10555 |
-
if (childLinkFn) {
|
10556 |
-
childLinkFn(scopeToChild, linkNode.childNodes, undefined, boundTranscludeFn);
|
10557 |
-
}
|
10558 |
|
10559 |
-
|
10560 |
-
for (i = postLinkFns.length - 1; i >= 0; i--) {
|
10561 |
-
linkFn = postLinkFns[i];
|
10562 |
-
invokeLinkFn(linkFn,
|
10563 |
-
linkFn.isolateScope ? isolateScope : scope,
|
10564 |
-
$element,
|
10565 |
-
attrs,
|
10566 |
-
linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),
|
10567 |
-
transcludeFn
|
10568 |
-
);
|
10569 |
-
}
|
10570 |
|
10571 |
-
|
10572 |
-
|
10573 |
-
var controllerInstance = controller.instance;
|
10574 |
-
if (isFunction(controllerInstance.$postLink)) {
|
10575 |
-
controllerInstance.$postLink();
|
10576 |
-
}
|
10577 |
-
});
|
10578 |
|
10579 |
-
|
10580 |
-
// Note: all arguments are optional!
|
10581 |
-
function controllersBoundTransclude(scope, cloneAttachFn, futureParentElement, slotName) {
|
10582 |
-
var transcludeControllers;
|
10583 |
-
// No scope passed in:
|
10584 |
-
if (!isScope(scope)) {
|
10585 |
-
slotName = futureParentElement;
|
10586 |
-
futureParentElement = cloneAttachFn;
|
10587 |
-
cloneAttachFn = scope;
|
10588 |
-
scope = undefined;
|
10589 |
-
}
|
10590 |
|
10591 |
-
|
10592 |
-
|
10593 |
-
|
10594 |
-
|
10595 |
-
|
10596 |
-
|
10597 |
-
|
10598 |
-
|
10599 |
-
|
10600 |
-
|
10601 |
-
|
10602 |
-
|
10603 |
-
|
10604 |
-
|
10605 |
-
|
10606 |
-
|
10607 |
-
|
10608 |
-
|
10609 |
-
|
10610 |
-
|
10611 |
-
} else {
|
10612 |
-
return boundTranscludeFn(scope, cloneAttachFn, transcludeControllers, futureParentElement, scopeToChild);
|
10613 |
-
}
|
10614 |
-
}
|
10615 |
-
}
|
10616 |
-
}
|
10617 |
|
10618 |
-
|
10619 |
-
|
10620 |
-
|
10621 |
-
if (isString(require)) {
|
10622 |
-
var match = require.match(REQUIRE_PREFIX_REGEXP);
|
10623 |
-
var name = require.substring(match[0].length);
|
10624 |
-
var inheritType = match[1] || match[3];
|
10625 |
-
var optional = match[2] === '?';
|
10626 |
-
|
10627 |
-
//If only parents then start at the parent element
|
10628 |
-
if (inheritType === '^^') {
|
10629 |
-
$element = $element.parent();
|
10630 |
-
//Otherwise attempt getting the controller from elementControllers in case
|
10631 |
-
//the element is transcluded (and has no data) and to avoid .data if possible
|
10632 |
-
} else {
|
10633 |
-
value = elementControllers && elementControllers[name];
|
10634 |
-
value = value && value.instance;
|
10635 |
-
}
|
10636 |
|
10637 |
-
|
10638 |
-
|
|
|
|
|
|
|
|
|
|
|
10639 |
|
10640 |
-
|
10641 |
-
|
10642 |
-
|
10643 |
-
|
10644 |
-
|
10645 |
-
|
10646 |
-
}
|
10647 |
-
}
|
10648 |
|
10649 |
-
|
10650 |
-
|
10651 |
-
|
10652 |
-
|
10653 |
-
|
10654 |
-
|
10655 |
-
|
10656 |
-
|
10657 |
-
|
10658 |
-
|
10659 |
-
} else if (isObject(require)) {
|
10660 |
-
value = {};
|
10661 |
-
forEach(require, function(controller, property) {
|
10662 |
-
value[property] = getControllers(directiveName, controller, $element, elementControllers);
|
10663 |
-
});
|
10664 |
-
}
|
10665 |
|
10666 |
-
|
10667 |
-
|
|
|
10668 |
|
10669 |
-
|
10670 |
-
|
10671 |
-
|
10672 |
-
|
10673 |
-
|
10674 |
-
|
10675 |
-
|
10676 |
-
|
10677 |
-
|
10678 |
-
|
10679 |
-
|
10680 |
-
|
10681 |
-
|
10682 |
-
|
10683 |
-
}
|
10684 |
|
10685 |
-
|
|
|
|
|
|
|
|
|
10686 |
|
10687 |
-
|
10688 |
-
|
10689 |
-
|
10690 |
-
|
10691 |
-
|
10692 |
-
$element.data('$' + directive.name + 'Controller', controllerInstance.instance);
|
10693 |
-
}
|
10694 |
-
return elementControllers;
|
10695 |
-
}
|
10696 |
|
10697 |
-
|
10698 |
-
|
10699 |
-
|
10700 |
-
|
10701 |
-
|
10702 |
-
|
10703 |
-
|
10704 |
-
for (var j = 0, jj = directives.length; j < jj; j++) {
|
10705 |
-
directives[j] = inherit(directives[j], {$$isolateScope: isolateScope, $$newScope: newScope});
|
10706 |
-
}
|
10707 |
-
}
|
10708 |
|
10709 |
-
|
10710 |
-
|
10711 |
-
|
10712 |
-
|
10713 |
-
|
10714 |
-
|
10715 |
-
|
10716 |
-
|
10717 |
-
|
10718 |
-
|
10719 |
-
|
10720 |
-
|
10721 |
-
|
10722 |
-
|
10723 |
-
|
10724 |
-
|
10725 |
-
|
10726 |
-
|
10727 |
-
|
10728 |
-
|
10729 |
-
|
10730 |
-
|
10731 |
-
|
10732 |
-
|
10733 |
-
|
10734 |
-
|
10735 |
-
|
10736 |
-
if (!directive.$$bindings) {
|
10737 |
-
var bindings = directive.$$bindings =
|
10738 |
-
parseDirectiveBindings(directive, directive.name);
|
10739 |
-
if (isObject(bindings.isolateScope)) {
|
10740 |
-
directive.$$isolateBindings = bindings.isolateScope;
|
10741 |
-
}
|
10742 |
-
}
|
10743 |
-
tDirectives.push(directive);
|
10744 |
-
match = directive;
|
10745 |
-
}
|
10746 |
-
}
|
10747 |
-
}
|
10748 |
-
return match;
|
10749 |
-
}
|
10750 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10751 |
|
10752 |
-
|
10753 |
-
|
10754 |
-
|
10755 |
-
|
10756 |
-
|
10757 |
-
|
10758 |
-
|
10759 |
-
|
10760 |
-
|
10761 |
-
|
10762 |
-
|
10763 |
-
i = 0, ii = directives.length; i < ii; i++) {
|
10764 |
-
directive = directives[i];
|
10765 |
-
if (directive.multiElement) {
|
10766 |
-
return true;
|
10767 |
-
}
|
10768 |
-
}
|
10769 |
-
}
|
10770 |
-
return false;
|
10771 |
-
}
|
10772 |
|
10773 |
-
|
10774 |
-
|
10775 |
-
|
10776 |
-
|
10777 |
-
|
10778 |
-
|
10779 |
-
|
10780 |
-
|
10781 |
-
|
10782 |
-
|
10783 |
-
|
10784 |
-
|
10785 |
-
|
10786 |
-
|
10787 |
-
|
10788 |
-
|
10789 |
-
|
10790 |
-
|
10791 |
-
|
10792 |
-
|
10793 |
-
|
10794 |
-
|
10795 |
-
|
10796 |
-
|
10797 |
-
|
|
|
10798 |
|
10799 |
-
|
10800 |
-
|
10801 |
-
// Check if we already set this attribute in the loop above.
|
10802 |
-
// `dst` will never contain hasOwnProperty as DOM parser won't let it.
|
10803 |
-
// You will get an "InvalidCharacterError: DOM Exception 5" error if you
|
10804 |
-
// have an attribute like "has-own-property" or "data-has-own-property", etc.
|
10805 |
-
if (!dst.hasOwnProperty(key) && key.charAt(0) !== '$') {
|
10806 |
-
dst[key] = value;
|
10807 |
-
|
10808 |
-
if (key !== 'class' && key !== 'style') {
|
10809 |
-
dstAttr[key] = srcAttr[key];
|
10810 |
-
}
|
10811 |
-
}
|
10812 |
-
});
|
10813 |
-
}
|
10814 |
|
|
|
|
|
|
|
|
|
|
|
10815 |
|
10816 |
-
|
10817 |
-
|
10818 |
-
|
10819 |
-
|
10820 |
-
|
10821 |
-
|
10822 |
-
|
10823 |
-
|
10824 |
-
|
10825 |
-
}),
|
10826 |
-
templateUrl = (isFunction(origAsyncDirective.templateUrl))
|
10827 |
-
? origAsyncDirective.templateUrl($compileNode, tAttrs)
|
10828 |
-
: origAsyncDirective.templateUrl,
|
10829 |
-
templateNamespace = origAsyncDirective.templateNamespace;
|
10830 |
-
|
10831 |
-
$compileNode.empty();
|
10832 |
-
|
10833 |
-
$templateRequest(templateUrl)
|
10834 |
-
.then(function(content) {
|
10835 |
-
var compileNode, tempTemplateAttrs, $template, childBoundTranscludeFn;
|
10836 |
-
|
10837 |
-
content = denormalizeTemplate(content);
|
10838 |
-
|
10839 |
-
if (origAsyncDirective.replace) {
|
10840 |
-
if (jqLiteIsTextNode(content)) {
|
10841 |
-
$template = [];
|
10842 |
-
} else {
|
10843 |
-
$template = removeComments(wrapTemplate(templateNamespace, trim(content)));
|
10844 |
-
}
|
10845 |
-
compileNode = $template[0];
|
10846 |
|
10847 |
-
|
10848 |
-
|
10849 |
-
'Template for directive \'{0}\' must have exactly one root element. {1}',
|
10850 |
-
origAsyncDirective.name, templateUrl);
|
10851 |
-
}
|
10852 |
|
10853 |
-
|
10854 |
-
|
10855 |
-
|
|
|
|
|
|
|
|
|
|
|
10856 |
|
10857 |
-
|
10858 |
-
|
10859 |
-
|
10860 |
-
|
10861 |
-
|
10862 |
-
|
10863 |
-
|
10864 |
-
|
10865 |
-
|
10866 |
-
|
10867 |
-
|
|
|
|
|
|
|
|
|
|
|
10868 |
|
10869 |
-
|
|
|
10870 |
|
10871 |
-
|
10872 |
-
|
10873 |
-
|
10874 |
-
|
10875 |
-
|
10876 |
-
|
10877 |
-
|
10878 |
-
|
10879 |
-
|
|
|
10880 |
|
10881 |
-
|
10882 |
-
|
10883 |
-
|
10884 |
-
|
10885 |
-
boundTranscludeFn = linkQueue.shift(),
|
10886 |
-
linkNode = $compileNode[0];
|
10887 |
|
10888 |
-
|
10889 |
|
10890 |
-
|
10891 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10892 |
|
10893 |
-
|
10894 |
-
|
10895 |
-
|
10896 |
-
|
10897 |
-
|
10898 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10899 |
|
10900 |
-
// Copy in CSS classes from original node
|
10901 |
-
safeAddClass(jqLite(linkNode), oldClasses);
|
10902 |
-
}
|
10903 |
-
if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
|
10904 |
-
childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);
|
10905 |
-
} else {
|
10906 |
-
childBoundTranscludeFn = boundTranscludeFn;
|
10907 |
-
}
|
10908 |
-
afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement,
|
10909 |
-
childBoundTranscludeFn);
|
10910 |
-
}
|
10911 |
-
linkQueue = null;
|
10912 |
-
}).catch(function(error) {
|
10913 |
-
if (isError(error)) {
|
10914 |
-
$exceptionHandler(error);
|
10915 |
-
}
|
10916 |
-
});
|
10917 |
|
10918 |
-
|
10919 |
-
|
10920 |
-
|
10921 |
-
|
10922 |
-
|
10923 |
-
|
10924 |
-
|
10925 |
-
|
10926 |
-
|
10927 |
-
|
10928 |
-
|
10929 |
-
|
10930 |
-
|
10931 |
-
|
10932 |
-
|
10933 |
-
|
|
|
|
|
|
|
|
|
10934 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10935 |
|
10936 |
-
|
10937 |
-
|
10938 |
-
|
10939 |
-
|
10940 |
-
|
10941 |
-
|
10942 |
-
|
10943 |
-
|
10944 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
10945 |
|
10946 |
-
function assertNoDuplicate(what, previousDirective, directive, element) {
|
10947 |
|
10948 |
-
|
10949 |
-
|
10950 |
-
|
10951 |
-
|
10952 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10953 |
|
10954 |
-
|
10955 |
-
throw $compileMinErr('multidir', 'Multiple directives [{0}{1}, {2}{3}] asking for {4} on: {5}',
|
10956 |
-
previousDirective.name, wrapModuleNameIfDefined(previousDirective.$$moduleName),
|
10957 |
-
directive.name, wrapModuleNameIfDefined(directive.$$moduleName), what, startingTag(element));
|
10958 |
-
}
|
10959 |
-
}
|
10960 |
|
|
|
|
|
|
|
10961 |
|
10962 |
-
|
10963 |
-
var interpolateFn = $interpolate(text, true);
|
10964 |
-
if (interpolateFn) {
|
10965 |
-
directives.push({
|
10966 |
-
priority: 0,
|
10967 |
-
compile: function textInterpolateCompileFn(templateNode) {
|
10968 |
-
var templateNodeParent = templateNode.parent(),
|
10969 |
-
hasCompileParent = !!templateNodeParent.length;
|
10970 |
-
|
10971 |
-
// When transcluding a template that has bindings in the root
|
10972 |
-
// we don't have a parent and thus need to add the class during linking fn.
|
10973 |
-
if (hasCompileParent) compile.$$addBindingClass(templateNodeParent);
|
10974 |
-
|
10975 |
-
return function textInterpolateLinkFn(scope, node) {
|
10976 |
-
var parent = node.parent();
|
10977 |
-
if (!hasCompileParent) compile.$$addBindingClass(parent);
|
10978 |
-
compile.$$addBindingInfo(parent, interpolateFn.expressions);
|
10979 |
-
scope.$watch(interpolateFn, function interpolateFnWatchAction(value) {
|
10980 |
-
node[0].nodeValue = value;
|
10981 |
-
});
|
10982 |
-
};
|
10983 |
-
}
|
10984 |
-
});
|
10985 |
-
}
|
10986 |
-
}
|
10987 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10988 |
|
10989 |
-
|
10990 |
-
|
10991 |
-
|
10992 |
-
|
10993 |
-
|
10994 |
-
var wrapper = window.document.createElement('div');
|
10995 |
-
wrapper.innerHTML = '<' + type + '>' + template + '</' + type + '>';
|
10996 |
-
return wrapper.childNodes[0].childNodes;
|
10997 |
-
default:
|
10998 |
-
return template;
|
10999 |
-
}
|
11000 |
-
}
|
11001 |
|
|
|
|
|
|
|
11002 |
|
11003 |
-
|
11004 |
-
|
11005 |
-
|
11006 |
-
|
11007 |
-
|
11008 |
-
|
11009 |
-
|
11010 |
-
|
11011 |
-
|
11012 |
-
|
11013 |
-
|
11014 |
-
} else if (attrNormalizedName === 'xlinkHref') {
|
11015 |
-
// Some xlink:href are okay, most aren't
|
11016 |
-
if (nodeName === 'image') return $sce.MEDIA_URL;
|
11017 |
-
if (nodeName === 'a') return $sce.URL;
|
11018 |
-
return $sce.RESOURCE_URL;
|
11019 |
-
} else if (
|
11020 |
-
// Formaction
|
11021 |
-
(nodeName === 'form' && attrNormalizedName === 'action') ||
|
11022 |
-
// If relative URLs can go where they are not expected to, then
|
11023 |
-
// all sorts of trust issues can arise.
|
11024 |
-
(nodeName === 'base' && attrNormalizedName === 'href') ||
|
11025 |
-
// links can be stylesheets or imports, which can run script in the current origin
|
11026 |
-
(nodeName === 'link' && attrNormalizedName === 'href')
|
11027 |
-
) {
|
11028 |
-
return $sce.RESOURCE_URL;
|
11029 |
-
} else if (nodeName === 'a' && (attrNormalizedName === 'href' ||
|
11030 |
-
attrNormalizedName === 'ngHref')) {
|
11031 |
-
return $sce.URL;
|
11032 |
-
}
|
11033 |
-
}
|
11034 |
|
11035 |
-
|
11036 |
-
var prop = propNormalizedName.toLowerCase();
|
11037 |
-
return PROP_CONTEXTS[nodeName + '|' + prop] || PROP_CONTEXTS['*|' + prop];
|
11038 |
-
}
|
11039 |
|
11040 |
-
|
11041 |
-
|
11042 |
-
|
11043 |
-
|
11044 |
-
|
11045 |
-
|
11046 |
-
|
|
|
|
|
11047 |
|
11048 |
-
|
11049 |
-
|
|
|
|
|
|
|
|
|
11050 |
|
11051 |
-
|
11052 |
-
// Sanitize img[srcset] + source[srcset] values.
|
11053 |
-
if (propName === 'srcset' && (nodeName === 'img' || nodeName === 'source')) {
|
11054 |
-
sanitizer = sanitizeSrcsetPropertyValue;
|
11055 |
-
} else if (trustedContext) {
|
11056 |
-
sanitizer = $sce.getTrusted.bind($sce, trustedContext);
|
11057 |
-
}
|
11058 |
|
11059 |
-
|
11060 |
-
|
11061 |
-
compile: function ngPropCompileFn(_, attr) {
|
11062 |
-
var ngPropGetter = $parse(attr[attrName]);
|
11063 |
-
var ngPropWatch = $parse(attr[attrName], function sceValueOf(val) {
|
11064 |
-
// Unwrap the value to compare the actual inner safe value, not the wrapper object.
|
11065 |
-
return $sce.valueOf(val);
|
11066 |
-
});
|
11067 |
-
|
11068 |
-
return {
|
11069 |
-
pre: function ngPropPreLinkFn(scope, $element) {
|
11070 |
-
function applyPropValue() {
|
11071 |
-
var propValue = ngPropGetter(scope);
|
11072 |
-
$element[0][propName] = sanitizer(propValue);
|
11073 |
-
}
|
11074 |
|
11075 |
-
|
11076 |
-
|
11077 |
-
|
11078 |
-
|
11079 |
-
|
11080 |
-
|
11081 |
-
}
|
11082 |
|
11083 |
-
|
11084 |
-
|
11085 |
-
|
11086 |
-
|
11087 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11088 |
|
11089 |
-
|
11090 |
-
|
11091 |
-
|
11092 |
-
|
11093 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11094 |
|
11095 |
-
var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing);
|
11096 |
|
11097 |
-
|
11098 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11099 |
|
11100 |
-
|
11101 |
-
throw $compileMinErr('selmulti',
|
11102 |
-
'Binding to the \'multiple\' attribute is not supported. Element: {0}',
|
11103 |
-
startingTag(node));
|
11104 |
-
}
|
11105 |
|
11106 |
-
|
11107 |
-
|
11108 |
-
|
|
|
|
|
11109 |
|
11110 |
-
|
11111 |
-
|
11112 |
-
|
11113 |
-
|
11114 |
-
|
11115 |
-
|
11116 |
-
|
11117 |
-
// If the attribute has changed since last $interpolate()ed
|
11118 |
-
var newValue = attr[name];
|
11119 |
-
if (newValue !== value) {
|
11120 |
-
// we need to interpolate again since the attribute value has been updated
|
11121 |
-
// (e.g. by another directive's compile function)
|
11122 |
-
// ensure unset/empty values make interpolateFn falsy
|
11123 |
-
interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);
|
11124 |
-
value = newValue;
|
11125 |
-
}
|
11126 |
|
11127 |
-
// if attribute was updated so that there is no interpolation going on we don't want to
|
11128 |
-
// register any observers
|
11129 |
-
if (!interpolateFn) return;
|
11130 |
-
|
11131 |
-
// initialize attr object so that it's ready in case we need the value for isolate
|
11132 |
-
// scope initialization, otherwise the value would not be available from isolate
|
11133 |
-
// directive's linking fn during linking phase
|
11134 |
-
attr[name] = interpolateFn(scope);
|
11135 |
-
|
11136 |
-
($$observers[name] || ($$observers[name] = [])).$$inter = true;
|
11137 |
-
(attr.$$observers && attr.$$observers[name].$$scope || scope).
|
11138 |
-
$watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {
|
11139 |
-
//special case for class attribute addition + removal
|
11140 |
-
//so that class changes can tap into the animation
|
11141 |
-
//hooks provided by the $animate service. Be sure to
|
11142 |
-
//skip animations when the first digest occurs (when
|
11143 |
-
//both the new and the old values are the same) since
|
11144 |
-
//the CSS classes are the non-interpolated values
|
11145 |
-
if (name === 'class' && newValue !== oldValue) {
|
11146 |
-
attr.$updateClass(newValue, oldValue);
|
11147 |
-
} else {
|
11148 |
-
attr.$set(name, newValue);
|
11149 |
-
}
|
11150 |
-
});
|
11151 |
-
}
|
11152 |
-
};
|
11153 |
-
}
|
11154 |
-
});
|
11155 |
-
}
|
11156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11157 |
|
11158 |
-
|
11159 |
-
|
11160 |
-
|
11161 |
-
*
|
11162 |
-
* @param {JqLite=} $rootElement The root of the compile tree. Used so that we can replace nodes
|
11163 |
-
* in the root of the tree.
|
11164 |
-
* @param {JqLite} elementsToRemove The jqLite element which we are going to replace. We keep
|
11165 |
-
* the shell, but replace its DOM node reference.
|
11166 |
-
* @param {Node} newNode The new DOM node.
|
11167 |
-
*/
|
11168 |
-
function replaceWith($rootElement, elementsToRemove, newNode) {
|
11169 |
-
var firstElementToRemove = elementsToRemove[0],
|
11170 |
-
removeCount = elementsToRemove.length,
|
11171 |
-
parent = firstElementToRemove.parentNode,
|
11172 |
-
i, ii;
|
11173 |
-
|
11174 |
-
if ($rootElement) {
|
11175 |
-
for (i = 0, ii = $rootElement.length; i < ii; i++) {
|
11176 |
-
if ($rootElement[i] === firstElementToRemove) {
|
11177 |
-
$rootElement[i++] = newNode;
|
11178 |
-
for (var j = i, j2 = j + removeCount - 1,
|
11179 |
-
jj = $rootElement.length;
|
11180 |
-
j < jj; j++, j2++) {
|
11181 |
-
if (j2 < jj) {
|
11182 |
-
$rootElement[j] = $rootElement[j2];
|
11183 |
-
} else {
|
11184 |
-
delete $rootElement[j];
|
11185 |
-
}
|
11186 |
-
}
|
11187 |
-
$rootElement.length -= removeCount - 1;
|
11188 |
|
11189 |
-
|
11190 |
-
|
11191 |
-
|
11192 |
-
|
11193 |
-
|
11194 |
-
|
11195 |
-
|
11196 |
-
|
11197 |
-
|
11198 |
-
|
|
|
|
|
11199 |
|
11200 |
-
if (parent) {
|
11201 |
-
parent.replaceChild(newNode, firstElementToRemove);
|
11202 |
-
}
|
11203 |
|
11204 |
-
|
11205 |
-
|
11206 |
-
|
11207 |
-
|
11208 |
-
|
11209 |
-
|
11210 |
-
|
11211 |
-
|
|
|
|
|
|
|
|
|
11212 |
|
11213 |
-
if (jqLite.hasData(firstElementToRemove)) {
|
11214 |
-
// Copy over user data (that includes AngularJS's $scope etc.). Don't copy private
|
11215 |
-
// data here because there's no public interface in jQuery to do that and copying over
|
11216 |
-
// event listeners (which is the main use of private data) wouldn't work anyway.
|
11217 |
-
jqLite.data(newNode, jqLite.data(firstElementToRemove));
|
11218 |
|
11219 |
-
|
11220 |
-
|
11221 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11222 |
|
11223 |
-
|
11224 |
-
|
11225 |
-
|
|
|
11226 |
|
11227 |
-
|
11228 |
-
|
11229 |
-
|
11230 |
-
|
11231 |
-
|
11232 |
-
|
11233 |
-
|
11234 |
|
|
|
|
|
11235 |
|
11236 |
-
|
11237 |
-
|
11238 |
-
|
|
|
|
|
|
|
|
|
11239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11240 |
|
11241 |
-
|
11242 |
-
|
11243 |
-
|
11244 |
-
|
11245 |
-
|
11246 |
-
|
11247 |
-
}
|
11248 |
|
11249 |
-
|
11250 |
-
|
11251 |
-
|
11252 |
-
|
11253 |
-
|
11254 |
-
|
11255 |
-
|
11256 |
|
11257 |
-
|
11258 |
-
|
11259 |
-
|
11260 |
-
|
11261 |
-
|
11262 |
|
11263 |
-
|
11264 |
-
|
11265 |
-
|
11266 |
-
|
11267 |
-
|
11268 |
-
parentGet, parentSet, compare, removeWatch;
|
11269 |
|
11270 |
-
|
11271 |
|
11272 |
-
|
11273 |
-
|
11274 |
-
strictBindingsCheck(attrName, directive.name);
|
11275 |
-
destination[scopeName] = attrs[attrName] = undefined;
|
11276 |
|
11277 |
-
|
11278 |
-
|
11279 |
-
|
11280 |
-
|
11281 |
-
|
11282 |
-
destination[scopeName] = value;
|
11283 |
-
}
|
11284 |
-
});
|
11285 |
-
attrs.$$observers[attrName].$$scope = scope;
|
11286 |
-
lastValue = attrs[attrName];
|
11287 |
-
if (isString(lastValue)) {
|
11288 |
-
// If the attribute has been provided then we trigger an interpolation to ensure
|
11289 |
-
// the value is there for use in the link fn
|
11290 |
-
destination[scopeName] = $interpolate(lastValue)(scope);
|
11291 |
-
} else if (isBoolean(lastValue)) {
|
11292 |
-
// If the attributes is one of the BOOLEAN_ATTR then AngularJS will have converted
|
11293 |
-
// the value to boolean rather than a string, so we special case this situation
|
11294 |
-
destination[scopeName] = lastValue;
|
11295 |
-
}
|
11296 |
-
initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);
|
11297 |
-
removeWatchCollection.push(removeWatch);
|
11298 |
-
break;
|
11299 |
-
|
11300 |
-
case '=':
|
11301 |
-
if (!hasOwnProperty.call(attrs, attrName)) {
|
11302 |
-
if (optional) break;
|
11303 |
-
strictBindingsCheck(attrName, directive.name);
|
11304 |
-
attrs[attrName] = undefined;
|
11305 |
-
}
|
11306 |
-
if (optional && !attrs[attrName]) break;
|
11307 |
|
11308 |
-
|
11309 |
-
|
11310 |
-
|
11311 |
-
} else {
|
11312 |
-
compare = simpleCompare;
|
11313 |
-
}
|
11314 |
-
parentSet = parentGet.assign || function() {
|
11315 |
-
// reset the change, or we will throw this exception on every $digest
|
11316 |
-
lastValue = destination[scopeName] = parentGet(scope);
|
11317 |
-
throw $compileMinErr('nonassign',
|
11318 |
-
'Expression \'{0}\' in attribute \'{1}\' used with directive \'{2}\' is non-assignable!',
|
11319 |
-
attrs[attrName], attrName, directive.name);
|
11320 |
-
};
|
11321 |
-
lastValue = destination[scopeName] = parentGet(scope);
|
11322 |
-
var parentValueWatch = function parentValueWatch(parentValue) {
|
11323 |
-
if (!compare(parentValue, destination[scopeName])) {
|
11324 |
-
// we are out of sync and need to copy
|
11325 |
-
if (!compare(parentValue, lastValue)) {
|
11326 |
-
// parent changed and it has precedence
|
11327 |
-
destination[scopeName] = parentValue;
|
11328 |
-
} else {
|
11329 |
-
// if the parent can be assigned then do so
|
11330 |
-
parentSet(scope, parentValue = destination[scopeName]);
|
11331 |
-
}
|
11332 |
-
}
|
11333 |
-
lastValue = parentValue;
|
11334 |
-
return lastValue;
|
11335 |
-
};
|
11336 |
-
parentValueWatch.$stateful = true;
|
11337 |
-
if (definition.collection) {
|
11338 |
-
removeWatch = scope.$watchCollection(attrs[attrName], parentValueWatch);
|
11339 |
-
} else {
|
11340 |
-
removeWatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal);
|
11341 |
-
}
|
11342 |
-
removeWatchCollection.push(removeWatch);
|
11343 |
-
break;
|
11344 |
-
|
11345 |
-
case '<':
|
11346 |
-
if (!hasOwnProperty.call(attrs, attrName)) {
|
11347 |
-
if (optional) break;
|
11348 |
-
strictBindingsCheck(attrName, directive.name);
|
11349 |
-
attrs[attrName] = undefined;
|
11350 |
-
}
|
11351 |
-
if (optional && !attrs[attrName]) break;
|
11352 |
|
11353 |
-
|
11354 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11355 |
|
11356 |
-
var initialValue = destination[scopeName] = parentGet(scope);
|
11357 |
-
initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);
|
11358 |
|
11359 |
-
|
11360 |
-
|
11361 |
-
|
11362 |
-
|
11363 |
-
|
11364 |
-
|
11365 |
-
|
11366 |
-
|
11367 |
-
|
11368 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11369 |
|
11370 |
-
|
11371 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11372 |
|
11373 |
-
|
11374 |
-
|
11375 |
-
|
11376 |
-
}
|
11377 |
-
// Don't assign Object.prototype method to scope
|
11378 |
-
parentGet = attrs.hasOwnProperty(attrName) ? $parse(attrs[attrName]) : noop;
|
11379 |
|
11380 |
-
|
11381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
11382 |
|
11383 |
-
|
11384 |
-
|
11385 |
-
|
11386 |
-
|
11387 |
-
|
11388 |
-
});
|
11389 |
|
11390 |
-
|
11391 |
-
|
11392 |
-
|
11393 |
-
if (!onChangesQueue) {
|
11394 |
-
scope.$$postDigest(flushOnChangesQueue);
|
11395 |
-
onChangesQueue = [];
|
11396 |
-
}
|
11397 |
-
// If we have not already queued a trigger of onChanges for this controller then do so now
|
11398 |
-
if (!changes) {
|
11399 |
-
changes = {};
|
11400 |
-
onChangesQueue.push(triggerOnChangesHook);
|
11401 |
-
}
|
11402 |
-
// If the has been a change on this property already then we need to reuse the previous value
|
11403 |
-
if (changes[key]) {
|
11404 |
-
previousValue = changes[key].previousValue;
|
11405 |
-
}
|
11406 |
-
// Store this change
|
11407 |
-
changes[key] = new SimpleChange(previousValue, currentValue);
|
11408 |
-
}
|
11409 |
-
}
|
11410 |
|
11411 |
-
|
11412 |
-
|
11413 |
-
|
11414 |
-
changes = undefined;
|
11415 |
-
}
|
11416 |
|
11417 |
-
|
11418 |
-
|
11419 |
-
|
11420 |
-
|
11421 |
-
|
11422 |
-
|
11423 |
-
}
|
11424 |
-
};
|
11425 |
-
}
|
11426 |
-
}];
|
11427 |
}
|
11428 |
|
11429 |
-
|
11430 |
-
|
11431 |
-
|
11432 |
}
|
11433 |
-
SimpleChange.prototype.isFirstChange = function() { return this.previousValue === _UNINITIALIZED_VALUE; };
|
11434 |
|
11435 |
|
11436 |
-
|
11437 |
-
|
|
|
|
|
|
|
|
|
|
|
11438 |
|
11439 |
-
|
11440 |
-
|
11441 |
-
|
11442 |
-
|
11443 |
-
|
11444 |
-
|
11445 |
-
.replace(PREFIX_REGEXP, '')
|
11446 |
-
.replace(SPECIAL_CHARS_REGEXP, function(_, letter, offset) {
|
11447 |
-
return offset ? letter.toUpperCase() : letter;
|
11448 |
-
});
|
11449 |
}
|
11450 |
|
11451 |
-
|
11452 |
-
|
11453 |
-
|
11454 |
-
|
11455 |
-
|
11456 |
-
* A shared object between directive compile / linking functions which contains normalized DOM
|
11457 |
-
* element attributes. The values reflect current binding state `{{ }}`. The normalization is
|
11458 |
-
* needed since all of these are treated as equivalent in AngularJS:
|
11459 |
-
*
|
11460 |
-
* ```
|
11461 |
-
* <span ng:bind="a" ng-bind="a" data-ng-bind="a" x-ng-bind="a">
|
11462 |
-
* ```
|
11463 |
-
*/
|
11464 |
|
11465 |
-
|
11466 |
-
|
11467 |
-
|
11468 |
-
|
11469 |
-
|
11470 |
-
|
11471 |
-
* needed to do reverse lookup from normalized name back to actual name.
|
11472 |
-
*/
|
11473 |
|
|
|
11474 |
|
11475 |
-
|
11476 |
-
|
11477 |
-
|
11478 |
-
|
11479 |
-
*
|
11480 |
-
* @description
|
11481 |
-
* Set DOM element attribute value.
|
11482 |
-
*
|
11483 |
-
*
|
11484 |
-
* @param {string} name Normalized element attribute name of the property to modify. The name is
|
11485 |
-
* reverse-translated using the {@link ng.$compile.directive.Attributes#$attr $attr}
|
11486 |
-
* property to the original name.
|
11487 |
-
* @param {string} value Value to set the attribute to. The value can be an interpolated string.
|
11488 |
-
*/
|
11489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11490 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11491 |
|
11492 |
-
|
11493 |
-
|
11494 |
-
*/
|
11495 |
|
11496 |
-
|
11497 |
-
|
11498 |
-
|
11499 |
-
|
11500 |
-
|
11501 |
-
|
11502 |
-
|
11503 |
-
function directiveLinkingFn(
|
11504 |
-
/* nodesetLinkingFn */ nodesetLinkingFn,
|
11505 |
-
/* angular.Scope */ scope,
|
11506 |
-
/* Node */ node,
|
11507 |
-
/* Element */ rootElement,
|
11508 |
-
/* function(Function) */ boundTranscludeFn
|
11509 |
-
) {}
|
11510 |
-
|
11511 |
-
function tokenDifference(str1, str2) {
|
11512 |
-
var values = '',
|
11513 |
-
tokens1 = str1.split(/\s+/),
|
11514 |
-
tokens2 = str2.split(/\s+/);
|
11515 |
-
|
11516 |
-
outer:
|
11517 |
-
for (var i = 0; i < tokens1.length; i++) {
|
11518 |
-
var token = tokens1[i];
|
11519 |
-
for (var j = 0; j < tokens2.length; j++) {
|
11520 |
-
if (token === tokens2[j]) continue outer;
|
11521 |
}
|
11522 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11523 |
}
|
11524 |
-
|
11525 |
-
|
11526 |
|
11527 |
-
|
11528 |
-
|
11529 |
-
var i = jqNodes.length;
|
11530 |
|
11531 |
-
|
11532 |
-
|
|
|
|
|
11533 |
}
|
|
|
11534 |
|
11535 |
-
|
11536 |
-
|
11537 |
-
|
11538 |
-
|
11539 |
-
|
11540 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11541 |
}
|
11542 |
-
|
11543 |
-
}
|
11544 |
-
|
11545 |
-
var $controllerMinErr = minErr('$controller');
|
11546 |
|
|
|
|
|
|
|
|
|
|
|
11547 |
|
11548 |
-
|
11549 |
-
|
11550 |
-
|
11551 |
-
|
11552 |
-
|
11553 |
-
|
11554 |
}
|
|
|
11555 |
}
|
|
|
|
|
11556 |
|
|
|
|
|
|
|
|
|
|
|
11557 |
|
11558 |
-
/**
|
11559 |
-
* @ngdoc provider
|
11560 |
-
* @name $controllerProvider
|
11561 |
-
* @this
|
11562 |
-
*
|
11563 |
-
* @description
|
11564 |
-
* The {@link ng.$controller $controller service} is used by AngularJS to create new
|
11565 |
-
* controllers.
|
11566 |
-
*
|
11567 |
-
* This provider allows controller registration via the
|
11568 |
-
* {@link ng.$controllerProvider#register register} method.
|
11569 |
-
*/
|
11570 |
-
function $ControllerProvider() {
|
11571 |
-
var controllers = {};
|
11572 |
|
11573 |
-
|
11574 |
-
|
11575 |
-
* @name $controllerProvider#has
|
11576 |
-
* @param {string} name Controller name to check.
|
11577 |
-
*/
|
11578 |
-
this.has = function(name) {
|
11579 |
-
return controllers.hasOwnProperty(name);
|
11580 |
-
};
|
11581 |
|
11582 |
-
|
11583 |
-
|
11584 |
-
|
11585 |
-
|
11586 |
-
|
11587 |
-
|
11588 |
-
|
11589 |
-
|
11590 |
-
|
11591 |
-
|
11592 |
-
|
11593 |
-
extend(controllers, name);
|
11594 |
-
} else {
|
11595 |
-
controllers[name] = constructor;
|
11596 |
-
}
|
11597 |
-
};
|
11598 |
|
11599 |
-
|
11600 |
-
|
11601 |
-
|
11602 |
-
|
11603 |
-
|
11604 |
-
|
11605 |
-
|
11606 |
-
|
11607 |
-
|
11608 |
-
|
11609 |
-
|
11610 |
-
|
11611 |
-
|
11612 |
-
*
|
11613 |
-
* The string can use the `controller as property` syntax, where the controller instance is published
|
11614 |
-
* as the specified property on the `scope`; the `scope` must be injected into `locals` param for this
|
11615 |
-
* to work correctly.
|
11616 |
-
*
|
11617 |
-
* @param {Object} locals Injection locals for Controller.
|
11618 |
-
* @return {Object} Instance of given controller.
|
11619 |
-
*
|
11620 |
-
* @description
|
11621 |
-
* `$controller` service is responsible for instantiating controllers.
|
11622 |
-
*
|
11623 |
-
* It's just a simple call to {@link auto.$injector $injector}, but extracted into
|
11624 |
-
* a service, so that one can override this service with [BC version](https://gist.github.com/1649788).
|
11625 |
-
*/
|
11626 |
-
return function $controller(expression, locals, later, ident) {
|
11627 |
-
// PRIVATE API:
|
11628 |
-
// param `later` --- indicates that the controller's constructor is invoked at a later time.
|
11629 |
-
// If true, $controller will allocate the object with the correct
|
11630 |
-
// prototype chain, but will not invoke the controller until a returned
|
11631 |
-
// callback is invoked.
|
11632 |
-
// param `ident` --- An optional label which overrides the label parsed from the controller
|
11633 |
-
// expression, if any.
|
11634 |
-
var instance, match, constructor, identifier;
|
11635 |
-
later = later === true;
|
11636 |
-
if (ident && isString(ident)) {
|
11637 |
-
identifier = ident;
|
11638 |
-
}
|
11639 |
|
11640 |
-
|
11641 |
-
|
11642 |
-
|
11643 |
-
|
11644 |
-
|
11645 |
-
|
11646 |
-
|
11647 |
-
|
11648 |
-
identifier = identifier || match[3];
|
11649 |
-
expression = controllers.hasOwnProperty(constructor)
|
11650 |
-
? controllers[constructor]
|
11651 |
-
: getter(locals.$scope, constructor, true);
|
11652 |
-
|
11653 |
-
if (!expression) {
|
11654 |
-
throw $controllerMinErr('ctrlreg',
|
11655 |
-
'The controller with the name \'{0}\' is not registered.', constructor);
|
11656 |
-
}
|
11657 |
|
11658 |
-
assertArgFn(expression, constructor, true);
|
11659 |
-
}
|
11660 |
|
11661 |
-
|
11662 |
-
|
11663 |
-
|
11664 |
-
|
11665 |
-
|
11666 |
-
|
11667 |
-
|
11668 |
-
|
11669 |
-
|
11670 |
-
|
11671 |
-
|
11672 |
-
|
11673 |
-
|
11674 |
-
|
11675 |
-
|
11676 |
-
if (identifier) {
|
11677 |
-
addIdentifier(locals, identifier, instance, constructor || expression.name);
|
11678 |
-
}
|
11679 |
|
11680 |
-
return extend(function $controllerInit() {
|
11681 |
-
var result = $injector.invoke(expression, instance, locals, constructor);
|
11682 |
-
if (result !== instance && (isObject(result) || isFunction(result))) {
|
11683 |
-
instance = result;
|
11684 |
-
if (identifier) {
|
11685 |
-
// If result changed, re-assign controllerAs value to scope.
|
11686 |
-
addIdentifier(locals, identifier, instance, constructor || expression.name);
|
11687 |
-
}
|
11688 |
-
}
|
11689 |
-
return instance;
|
11690 |
-
}, {
|
11691 |
-
instance: instance,
|
11692 |
-
identifier: identifier
|
11693 |
-
});
|
11694 |
-
}
|
11695 |
|
11696 |
-
instance = $injector.instantiate(expression, locals, constructor);
|
11697 |
|
11698 |
-
|
11699 |
-
|
11700 |
-
|
11701 |
|
11702 |
-
|
11703 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11704 |
|
11705 |
-
|
11706 |
-
|
11707 |
-
|
11708 |
-
'Cannot export controller \'{0}\' as \'{1}\'! No $scope object provided via `locals`.',
|
11709 |
-
name, identifier);
|
11710 |
-
}
|
11711 |
|
11712 |
-
|
11713 |
-
|
11714 |
-
|
11715 |
-
}
|
11716 |
|
11717 |
-
|
11718 |
-
|
11719 |
-
|
11720 |
-
|
11721 |
-
|
11722 |
-
*
|
11723 |
-
* @description
|
11724 |
-
* A {@link angular.element jQuery or jqLite} wrapper for the browser's `window.document` object.
|
11725 |
-
*
|
11726 |
-
* @example
|
11727 |
-
<example module="documentExample" name="document">
|
11728 |
-
<file name="index.html">
|
11729 |
-
<div ng-controller="ExampleController">
|
11730 |
-
<p>$document title: <b ng-bind="title"></b></p>
|
11731 |
-
<p>window.document title: <b ng-bind="windowTitle"></b></p>
|
11732 |
-
</div>
|
11733 |
-
</file>
|
11734 |
-
<file name="script.js">
|
11735 |
-
angular.module('documentExample', [])
|
11736 |
-
.controller('ExampleController', ['$scope', '$document', function($scope, $document) {
|
11737 |
-
$scope.title = $document[0].title;
|
11738 |
-
$scope.windowTitle = angular.element(window.document)[0].title;
|
11739 |
-
}]);
|
11740 |
-
</file>
|
11741 |
-
</example>
|
11742 |
-
*/
|
11743 |
-
function $DocumentProvider() {
|
11744 |
-
this.$get = ['$window', function(window) {
|
11745 |
-
return jqLite(window.document);
|
11746 |
-
}];
|
11747 |
}
|
|
|
|
|
|
|
11748 |
|
|
|
11749 |
|
11750 |
-
/**
|
11751 |
-
* @private
|
11752 |
-
* @this
|
11753 |
-
* Listens for document visibility change and makes the current status accessible.
|
11754 |
-
*/
|
11755 |
-
function $$IsDocumentHiddenProvider() {
|
11756 |
-
this.$get = ['$document', '$rootScope', function($document, $rootScope) {
|
11757 |
-
var doc = $document[0];
|
11758 |
-
var hidden = doc && doc.hidden;
|
11759 |
|
11760 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11761 |
|
11762 |
-
$rootScope.$on('$destroy', function() {
|
11763 |
-
$document.off('visibilitychange', changeListener);
|
11764 |
-
});
|
11765 |
|
11766 |
-
|
11767 |
-
|
11768 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11769 |
|
11770 |
-
|
11771 |
-
|
11772 |
-
|
11773 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11774 |
}
|
|
|
|
|
|
|
11775 |
|
11776 |
/**
|
11777 |
* @ngdoc service
|
11778 |
-
* @name $
|
11779 |
-
* @requires
|
11780 |
-
* @this
|
11781 |
-
*
|
11782 |
-
* @description
|
11783 |
-
* Any uncaught exception in AngularJS expressions is delegated to this service.
|
11784 |
-
* The default implementation simply delegates to `$log.error` which logs it into
|
11785 |
-
* the browser console.
|
11786 |
-
*
|
11787 |
-
* In unit tests, if `angular-mocks.js` is loaded, this service is overridden by
|
11788 |
-
* {@link ngMock.$exceptionHandler mock $exceptionHandler} which aids in testing.
|
11789 |
*
|
11790 |
-
*
|
|
|
|
|
11791 |
*
|
11792 |
-
*
|
11793 |
-
*
|
11794 |
-
* of `$log.error()`.
|
11795 |
-
*
|
11796 |
-
* ```js
|
11797 |
-
* angular.
|
11798 |
-
* module('exceptionOverwrite', []).
|
11799 |
-
* factory('$exceptionHandler', ['$log', 'logErrorsToBackend', function($log, logErrorsToBackend) {
|
11800 |
-
* return function myExceptionHandler(exception, cause) {
|
11801 |
-
* logErrorsToBackend(exception, cause);
|
11802 |
-
* $log.warn(exception, cause);
|
11803 |
-
* };
|
11804 |
-
* }]);
|
11805 |
-
* ```
|
11806 |
*
|
11807 |
-
*
|
11808 |
-
*
|
11809 |
-
*
|
11810 |
-
* (unless executed during a digest).
|
11811 |
*
|
11812 |
-
*
|
11813 |
-
*
|
11814 |
*
|
11815 |
-
* @
|
11816 |
-
*
|
11817 |
-
* the error was thrown.
|
11818 |
*
|
|
|
|
|
11819 |
*/
|
11820 |
-
function $
|
11821 |
-
|
11822 |
-
|
11823 |
-
|
11824 |
-
|
11825 |
-
|
11826 |
-
|
11827 |
-
|
11828 |
-
|
11829 |
-
|
11830 |
-
|
11831 |
-
|
11832 |
-
|
11833 |
-
//be properly updated and drawn on screen. This is required to
|
11834 |
-
//ensure that the preparation animation is properly flushed so that
|
11835 |
-
//the active state picks up from there. DO NOT REMOVE THIS LINE.
|
11836 |
-
//DO NOT OPTIMIZE THIS LINE. THE MINIFIER WILL REMOVE IT OTHERWISE WHICH
|
11837 |
-
//WILL RESULT IN AN UNPREDICTABLE BUG THAT IS VERY HARD TO TRACK DOWN AND
|
11838 |
-
//WILL TAKE YEARS AWAY FROM YOUR LIFE.
|
11839 |
-
if (domNode) {
|
11840 |
-
if (!domNode.nodeType && domNode instanceof jqLite) {
|
11841 |
-
domNode = domNode[0];
|
11842 |
-
}
|
11843 |
-
} else {
|
11844 |
-
domNode = $document[0].body;
|
11845 |
-
}
|
11846 |
-
return domNode.offsetWidth + 1;
|
11847 |
-
};
|
11848 |
-
}];
|
11849 |
-
};
|
11850 |
-
|
11851 |
-
var APPLICATION_JSON = 'application/json';
|
11852 |
-
var CONTENT_TYPE_APPLICATION_JSON = {'Content-Type': APPLICATION_JSON + ';charset=utf-8'};
|
11853 |
-
var JSON_START = /^\[|^\{(?!\{)/;
|
11854 |
-
var JSON_ENDS = {
|
11855 |
-
'[': /]$/,
|
11856 |
-
'{': /}$/
|
11857 |
-
};
|
11858 |
-
var JSON_PROTECTION_PREFIX = /^\)]\}',?\n/;
|
11859 |
-
var $httpMinErr = minErr('$http');
|
11860 |
|
11861 |
-
|
11862 |
-
|
11863 |
-
|
|
|
|
|
|
|
11864 |
}
|
11865 |
-
|
11866 |
-
|
|
|
|
|
|
|
11867 |
|
|
|
|
|
|
|
|
|
11868 |
|
11869 |
-
|
11870 |
-
|
11871 |
-
/**
|
11872 |
-
* @ngdoc service
|
11873 |
-
* @name $httpParamSerializer
|
11874 |
-
* @description
|
11875 |
-
*
|
11876 |
-
* Default {@link $http `$http`} params serializer that converts objects to strings
|
11877 |
-
* according to the following rules:
|
11878 |
-
*
|
11879 |
-
* * `{'foo': 'bar'}` results in `foo=bar`
|
11880 |
-
* * `{'foo': Date.now()}` results in `foo=2015-04-01T09%3A50%3A49.262Z` (`toISOString()` and encoded representation of a Date object)
|
11881 |
-
* * `{'foo': ['bar', 'baz']}` results in `foo=bar&foo=baz` (repeated key for each array element)
|
11882 |
-
* * `{'foo': {'bar':'baz'}}` results in `foo=%7B%22bar%22%3A%22baz%22%7D` (stringified and encoded representation of an object)
|
11883 |
-
*
|
11884 |
-
* Note that serializer will sort the request parameters alphabetically.
|
11885 |
-
*/
|
11886 |
|
11887 |
-
|
11888 |
-
|
11889 |
-
|
11890 |
-
|
11891 |
-
|
11892 |
-
|
11893 |
-
|
11894 |
-
|
11895 |
-
|
11896 |
-
|
11897 |
-
|
11898 |
-
|
11899 |
-
|
11900 |
-
|
11901 |
|
11902 |
-
|
11903 |
-
|
11904 |
-
}
|
11905 |
-
}
|
11906 |
|
11907 |
-
|
11908 |
-
|
11909 |
-
|
11910 |
-
|
11911 |
-
|
11912 |
-
|
11913 |
-
|
11914 |
-
|
11915 |
-
|
11916 |
-
|
11917 |
-
|
11918 |
-
|
11919 |
-
|
11920 |
-
|
11921 |
-
|
11922 |
-
* $http({
|
11923 |
-
* url: myUrl,
|
11924 |
-
* method: 'GET',
|
11925 |
-
* params: myParams,
|
11926 |
-
* paramSerializer: '$httpParamSerializerJQLike'
|
11927 |
-
* });
|
11928 |
-
* ```
|
11929 |
-
*
|
11930 |
-
* It is also possible to set it as the default `paramSerializer` in the
|
11931 |
-
* {@link $httpProvider#defaults `$httpProvider`}.
|
11932 |
-
*
|
11933 |
-
* Additionally, you can inject the serializer and use it explicitly, for example to serialize
|
11934 |
-
* form data for submission:
|
11935 |
-
*
|
11936 |
-
* ```js
|
11937 |
-
* .controller(function($http, $httpParamSerializerJQLike) {
|
11938 |
-
* //...
|
11939 |
-
*
|
11940 |
-
* $http({
|
11941 |
-
* url: myUrl,
|
11942 |
-
* method: 'POST',
|
11943 |
-
* data: $httpParamSerializerJQLike(myData),
|
11944 |
-
* headers: {
|
11945 |
-
* 'Content-Type': 'application/x-www-form-urlencoded'
|
11946 |
-
* }
|
11947 |
-
* });
|
11948 |
-
*
|
11949 |
-
* });
|
11950 |
-
* ```
|
11951 |
-
*
|
11952 |
-
*/
|
11953 |
-
this.$get = function() {
|
11954 |
-
return function jQueryLikeParamSerializer(params) {
|
11955 |
-
if (!params) return '';
|
11956 |
-
var parts = [];
|
11957 |
-
serialize(params, '', true);
|
11958 |
-
return parts.join('&');
|
11959 |
-
|
11960 |
-
function serialize(toSerialize, prefix, topLevel) {
|
11961 |
-
if (isArray(toSerialize)) {
|
11962 |
-
forEach(toSerialize, function(value, index) {
|
11963 |
-
serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
|
11964 |
-
});
|
11965 |
-
} else if (isObject(toSerialize) && !isDate(toSerialize)) {
|
11966 |
-
forEachSorted(toSerialize, function(value, key) {
|
11967 |
-
serialize(value, prefix +
|
11968 |
-
(topLevel ? '' : '[') +
|
11969 |
-
key +
|
11970 |
-
(topLevel ? '' : ']'));
|
11971 |
-
});
|
11972 |
-
} else {
|
11973 |
-
if (isFunction(toSerialize)) {
|
11974 |
-
toSerialize = toSerialize();
|
11975 |
-
}
|
11976 |
-
parts.push(encodeUriQuery(prefix) + '=' +
|
11977 |
-
(toSerialize == null ? '' : encodeUriQuery(serializeValue(toSerialize))));
|
11978 |
-
}
|
11979 |
-
}
|
11980 |
-
};
|
11981 |
-
};
|
11982 |
-
}
|
11983 |
|
11984 |
-
|
11985 |
-
if (isString(data)) {
|
11986 |
-
// Strip json vulnerability protection prefix and trim whitespace
|
11987 |
-
var tempData = data.replace(JSON_PROTECTION_PREFIX, '').trim();
|
11988 |
|
11989 |
-
|
11990 |
-
|
11991 |
-
|
11992 |
|
11993 |
-
|
11994 |
-
|
11995 |
-
data = fromJson(tempData);
|
11996 |
-
} catch (e) {
|
11997 |
-
if (!hasJsonContentType) {
|
11998 |
-
return data;
|
11999 |
-
}
|
12000 |
-
throw $httpMinErr('baddata', 'Data must be a valid JSON object. Received: "{0}". ' +
|
12001 |
-
'Parse error: "{1}"', data, e);
|
12002 |
-
}
|
12003 |
-
}
|
12004 |
-
}
|
12005 |
-
}
|
12006 |
|
12007 |
-
|
12008 |
-
|
|
|
|
|
|
|
|
|
12009 |
|
12010 |
-
|
12011 |
-
var jsonStart = str.match(JSON_START);
|
12012 |
-
return jsonStart && JSON_ENDS[jsonStart[0]].test(str);
|
12013 |
}
|
|
|
|
|
12014 |
|
12015 |
-
|
12016 |
-
|
12017 |
-
|
12018 |
-
|
12019 |
-
|
12020 |
-
|
12021 |
-
|
12022 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12023 |
|
12024 |
-
function fillInParsed(key, val) {
|
12025 |
-
if (key) {
|
12026 |
-
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
12027 |
-
}
|
12028 |
-
}
|
12029 |
|
12030 |
-
|
12031 |
-
|
12032 |
-
|
12033 |
-
|
12034 |
-
|
12035 |
-
|
12036 |
-
|
12037 |
-
|
12038 |
-
|
12039 |
-
}
|
12040 |
|
12041 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12042 |
}
|
12043 |
|
|
|
|
|
|
|
|
|
|
|
12044 |
|
12045 |
-
|
12046 |
-
|
12047 |
-
|
12048 |
-
|
12049 |
-
|
12050 |
-
|
12051 |
-
|
12052 |
-
|
12053 |
-
|
12054 |
-
|
12055 |
-
|
12056 |
-
|
12057 |
-
|
12058 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12059 |
|
12060 |
-
|
12061 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12062 |
|
12063 |
-
if (name) {
|
12064 |
-
var value = headersObj[lowercase(name)];
|
12065 |
-
if (value === undefined) {
|
12066 |
-
value = null;
|
12067 |
-
}
|
12068 |
-
return value;
|
12069 |
-
}
|
12070 |
|
12071 |
-
|
12072 |
-
|
12073 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12074 |
|
|
|
|
|
|
|
|
|
12075 |
|
12076 |
-
|
12077 |
-
|
12078 |
-
|
12079 |
-
|
12080 |
-
|
12081 |
-
|
12082 |
-
|
12083 |
-
|
12084 |
-
|
12085 |
-
|
12086 |
-
|
12087 |
-
|
12088 |
-
|
12089 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12090 |
}
|
|
|
|
|
|
|
|
|
12091 |
|
12092 |
-
|
12093 |
-
|
12094 |
-
|
|
|
12095 |
|
12096 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12097 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12098 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12099 |
|
12100 |
-
|
12101 |
-
|
|
|
12102 |
}
|
|
|
12103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12104 |
|
12105 |
-
|
12106 |
-
|
12107 |
-
* @name $httpProvider
|
12108 |
-
* @this
|
12109 |
-
*
|
12110 |
-
* @description
|
12111 |
-
* Use `$httpProvider` to change the default behavior of the {@link ng.$http $http} service.
|
12112 |
-
*/
|
12113 |
-
function $HttpProvider() {
|
12114 |
-
/**
|
12115 |
-
* @ngdoc property
|
12116 |
-
* @name $httpProvider#defaults
|
12117 |
-
* @description
|
12118 |
-
*
|
12119 |
-
* Object containing default values for all {@link ng.$http $http} requests.
|
12120 |
-
*
|
12121 |
-
* - **`defaults.cache`** - {boolean|Object} - A boolean value or object created with
|
12122 |
-
* {@link ng.$cacheFactory `$cacheFactory`} to enable or disable caching of HTTP responses
|
12123 |
-
* by default. See {@link $http#caching $http Caching} for more information.
|
12124 |
-
*
|
12125 |
-
* - **`defaults.headers`** - {Object} - Default headers for all $http requests.
|
12126 |
-
* Refer to {@link ng.$http#setting-http-headers $http} for documentation on
|
12127 |
-
* setting default headers.
|
12128 |
-
* - **`defaults.headers.common`**
|
12129 |
-
* - **`defaults.headers.post`**
|
12130 |
-
* - **`defaults.headers.put`**
|
12131 |
-
* - **`defaults.headers.patch`**
|
12132 |
-
*
|
12133 |
-
* - **`defaults.jsonpCallbackParam`** - `{string}` - the name of the query parameter that passes the name of the
|
12134 |
-
* callback in a JSONP request. The value of this parameter will be replaced with the expression generated by the
|
12135 |
-
* {@link $jsonpCallbacks} service. Defaults to `'callback'`.
|
12136 |
-
*
|
12137 |
-
* - **`defaults.paramSerializer`** - `{string|function(Object<string,string>):string}` - A function
|
12138 |
-
* used to the prepare string representation of request parameters (specified as an object).
|
12139 |
-
* If specified as string, it is interpreted as a function registered with the {@link auto.$injector $injector}.
|
12140 |
-
* Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}.
|
12141 |
-
*
|
12142 |
-
* - **`defaults.transformRequest`** -
|
12143 |
-
* `{Array<function(data, headersGetter)>|function(data, headersGetter)}` -
|
12144 |
-
* An array of functions (or a single function) which are applied to the request data.
|
12145 |
-
* By default, this is an array with one request transformation function:
|
12146 |
-
*
|
12147 |
-
* - If the `data` property of the request configuration object contains an object, serialize it
|
12148 |
-
* into JSON format.
|
12149 |
-
*
|
12150 |
-
* - **`defaults.transformResponse`** -
|
12151 |
-
* `{Array<function(data, headersGetter, status)>|function(data, headersGetter, status)}` -
|
12152 |
-
* An array of functions (or a single function) which are applied to the response data. By default,
|
12153 |
-
* this is an array which applies one response transformation function that does two things:
|
12154 |
-
*
|
12155 |
-
* - If XSRF prefix is detected, strip it
|
12156 |
-
* (see {@link ng.$http#security-considerations Security Considerations in the $http docs}).
|
12157 |
-
* - If the `Content-Type` is `application/json` or the response looks like JSON,
|
12158 |
-
* deserialize it using a JSON parser.
|
12159 |
-
*
|
12160 |
-
* - **`defaults.xsrfCookieName`** - {string} - Name of cookie containing the XSRF token.
|
12161 |
-
* Defaults value is `'XSRF-TOKEN'`.
|
12162 |
-
*
|
12163 |
-
* - **`defaults.xsrfHeaderName`** - {string} - Name of HTTP header to populate with the
|
12164 |
-
* XSRF token. Defaults value is `'X-XSRF-TOKEN'`.
|
12165 |
-
*
|
12166 |
-
*/
|
12167 |
-
var defaults = this.defaults = {
|
12168 |
-
// transform incoming response data
|
12169 |
-
transformResponse: [defaultHttpResponseTransform],
|
12170 |
-
|
12171 |
-
// transform outgoing request data
|
12172 |
-
transformRequest: [function(d) {
|
12173 |
-
return isObject(d) && !isFile(d) && !isBlob(d) && !isFormData(d) ? toJson(d) : d;
|
12174 |
-
}],
|
12175 |
-
|
12176 |
-
// default headers
|
12177 |
-
headers: {
|
12178 |
-
common: {
|
12179 |
-
'Accept': 'application/json, text/plain, */*'
|
12180 |
-
},
|
12181 |
-
post: shallowCopy(CONTENT_TYPE_APPLICATION_JSON),
|
12182 |
-
put: shallowCopy(CONTENT_TYPE_APPLICATION_JSON),
|
12183 |
-
patch: shallowCopy(CONTENT_TYPE_APPLICATION_JSON)
|
12184 |
-
},
|
12185 |
|
12186 |
-
xsrfCookieName: 'XSRF-TOKEN',
|
12187 |
-
xsrfHeaderName: 'X-XSRF-TOKEN',
|
12188 |
|
12189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12190 |
|
12191 |
-
|
12192 |
-
|
12193 |
|
12194 |
-
|
12195 |
-
|
12196 |
-
|
12197 |
-
|
12198 |
-
|
12199 |
-
|
12200 |
-
|
12201 |
-
* the same time via {@link ng.$rootScope.Scope#$applyAsync $rootScope.$applyAsync}. This can result in
|
12202 |
-
* significant performance improvement for bigger applications that make many HTTP requests
|
12203 |
-
* concurrently (common during application bootstrap).
|
12204 |
-
*
|
12205 |
-
* Defaults to false. If no value is specified, returns the current configured value.
|
12206 |
-
*
|
12207 |
-
* @param {boolean=} value If true, when requests are loaded, they will schedule a deferred
|
12208 |
-
* "apply" on the next tick, giving time for subsequent requests in a roughly ~10ms window
|
12209 |
-
* to load and share the same digest cycle.
|
12210 |
-
*
|
12211 |
-
* @returns {boolean|Object} If a value is specified, returns the $httpProvider for chaining.
|
12212 |
-
* otherwise, returns the current configured value.
|
12213 |
-
*/
|
12214 |
-
this.useApplyAsync = function(value) {
|
12215 |
-
if (isDefined(value)) {
|
12216 |
-
useApplyAsync = !!value;
|
12217 |
-
return this;
|
12218 |
-
}
|
12219 |
-
return useApplyAsync;
|
12220 |
-
};
|
12221 |
|
12222 |
-
|
12223 |
-
|
12224 |
-
|
12225 |
-
* @description
|
12226 |
-
*
|
12227 |
-
* Array containing service factories for all synchronous or asynchronous {@link ng.$http $http}
|
12228 |
-
* pre-processing of request or postprocessing of responses.
|
12229 |
-
*
|
12230 |
-
* These service factories are ordered by request, i.e. they are applied in the same order as the
|
12231 |
-
* array, on request, but reverse order, on response.
|
12232 |
-
*
|
12233 |
-
* {@link ng.$http#interceptors Interceptors detailed info}
|
12234 |
-
*/
|
12235 |
-
var interceptorFactories = this.interceptors = [];
|
12236 |
|
12237 |
-
|
12238 |
-
|
12239 |
-
|
12240 |
-
|
12241 |
-
|
12242 |
-
|
12243 |
-
|
12244 |
-
|
12245 |
-
|
12246 |
-
|
12247 |
-
|
12248 |
-
|
12249 |
-
|
12250 |
-
|
12251 |
-
|
12252 |
-
|
12253 |
-
|
12254 |
-
|
12255 |
-
|
12256 |
-
|
12257 |
-
|
12258 |
-
|
12259 |
-
|
12260 |
-
|
12261 |
-
|
12262 |
-
|
12263 |
-
|
12264 |
-
|
12265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12266 |
* $httpProvider.xsrfWhitelistedOrigins.push('https://api.example.com');
|
12267 |
* }]).
|
12268 |
-
|
12269 |
* // The XSRF token will be sent.
|
12270 |
* $http.get('https://api.example.com/preferences').then(...);
|
12271 |
*
|
12272 |
* // The XSRF token will NOT be sent.
|
12273 |
* $http.get('https://stats.example.com/activity').then(...);
|
12274 |
* }]);
|
12275 |
-
|
12276 |
-
|
12277 |
-
|
12278 |
|
12279 |
-
|
12280 |
-
|
12281 |
|
12282 |
-
|
12283 |
|
12284 |
-
|
12285 |
-
|
12286 |
-
|
12287 |
-
|
12288 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12289 |
|
12290 |
-
|
12291 |
-
|
12292 |
-
|
12293 |
-
|
12294 |
-
*/
|
12295 |
-
var reversedInterceptors = [];
|
12296 |
|
12297 |
-
|
12298 |
-
|
12299 |
-
|
12300 |
-
|
12301 |
|
12302 |
-
|
12303 |
-
|
12304 |
-
|
12305 |
-
|
12306 |
-
|
12307 |
-
|
12308 |
-
|
12309 |
-
|
12310 |
-
|
12311 |
-
|
12312 |
-
|
12313 |
-
|
12314 |
-
|
12315 |
-
|
12316 |
-
|
12317 |
-
|
12318 |
-
|
12319 |
-
|
12320 |
-
|
12321 |
-
*
|
12322 |
-
* For unit testing applications that use `$http` service, see
|
12323 |
-
* {@link ngMock.$httpBackend $httpBackend mock}.
|
12324 |
-
*
|
12325 |
-
* For a higher level of abstraction, please check out the {@link ngResource.$resource
|
12326 |
* $resource} service.
|
12327 |
-
|
12328 |
-
|
12329 |
-
|
12330 |
-
|
12331 |
-
|
12332 |
-
|
12333 |
-
|
12334 |
-
|
12335 |
-
|
12336 |
-
|
12337 |
-
|
12338 |
-
|
12339 |
-
|
12340 |
-
|
12341 |
-
|
12342 |
* method: 'GET',
|
12343 |
* url: '/someUrl'
|
12344 |
* }).then(function successCallback(response) {
|
@@ -12348,227 +12348,227 @@
|
|
12348 |
* // called asynchronously if an error occurs
|
12349 |
* // or server returns response with an error status.
|
12350 |
* });
|
12351 |
-
|
12352 |
-
*
|
12353 |
-
*
|
12354 |
-
* ## Shortcut methods
|
12355 |
-
*
|
12356 |
-
* Shortcut methods are also available. All shortcut methods require passing in the URL, and
|
12357 |
-
* request data must be passed in for POST/PUT requests. An optional config can be passed as the
|
12358 |
-
* last argument.
|
12359 |
-
*
|
12360 |
-
* ```js
|
12361 |
-
* $http.get('/someUrl', config).then(successCallback, errorCallback);
|
12362 |
-
* $http.post('/someUrl', data, config).then(successCallback, errorCallback);
|
12363 |
-
* ```
|
12364 |
-
*
|
12365 |
-
* Complete list of shortcut methods:
|
12366 |
-
*
|
12367 |
-
* - {@link ng.$http#get $http.get}
|
12368 |
-
* - {@link ng.$http#head $http.head}
|
12369 |
-
* - {@link ng.$http#post $http.post}
|
12370 |
-
* - {@link ng.$http#put $http.put}
|
12371 |
-
* - {@link ng.$http#delete $http.delete}
|
12372 |
-
* - {@link ng.$http#jsonp $http.jsonp}
|
12373 |
-
* - {@link ng.$http#patch $http.patch}
|
12374 |
-
*
|
12375 |
-
*
|
12376 |
-
* ## Writing Unit Tests that use $http
|
12377 |
-
* When unit testing (using {@link ngMock ngMock}), it is necessary to call
|
12378 |
-
* {@link ngMock.$httpBackend#flush $httpBackend.flush()} to flush each pending
|
12379 |
-
* request using trained responses.
|
12380 |
-
*
|
12381 |
-
* ```
|
12382 |
-
* $httpBackend.expectGET(...);
|
12383 |
-
* $http.get(...);
|
12384 |
-
* $httpBackend.flush();
|
12385 |
-
* ```
|
12386 |
-
*
|
12387 |
-
* ## Setting HTTP Headers
|
12388 |
-
*
|
12389 |
-
* The $http service will automatically add certain HTTP headers to all requests. These defaults
|
12390 |
-
* can be fully configured by accessing the `$httpProvider.defaults.headers` configuration
|
12391 |
-
* object, which currently contains this default configuration:
|
12392 |
-
*
|
12393 |
-
* - `$httpProvider.defaults.headers.common` (headers that are common for all requests):
|
12394 |
-
* - <code>Accept: application/json, text/plain, \*/\*</code>
|
12395 |
-
* - `$httpProvider.defaults.headers.post`: (header defaults for POST requests)
|
12396 |
-
* - `Content-Type: application/json`
|
12397 |
-
* - `$httpProvider.defaults.headers.put` (header defaults for PUT requests)
|
12398 |
-
* - `Content-Type: application/json`
|
12399 |
-
*
|
12400 |
-
* To add or overwrite these defaults, simply add or remove a property from these configuration
|
12401 |
-
* objects. To add headers for an HTTP method other than POST or PUT, simply add a new object
|
12402 |
-
* with the lowercased HTTP method name as the key, e.g.
|
12403 |
-
* `$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }`.
|
12404 |
-
*
|
12405 |
-
* The defaults can also be set at runtime via the `$http.defaults` object in the same
|
12406 |
-
* fashion. For example:
|
12407 |
-
*
|
12408 |
-
* ```
|
12409 |
-
* module.run(function($http) {
|
12410 |
-
* $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
|
12411 |
-
* });
|
12412 |
-
* ```
|
12413 |
-
*
|
12414 |
-
* In addition, you can supply a `headers` property in the config object passed when
|
12415 |
-
* calling `$http(config)`, which overrides the defaults without changing them globally.
|
12416 |
-
*
|
12417 |
-
* To explicitly remove a header automatically added via $httpProvider.defaults.headers on a per request basis,
|
12418 |
-
* Use the `headers` property, setting the desired header to `undefined`. For example:
|
12419 |
-
*
|
12420 |
-
* ```js
|
12421 |
-
* var req = {
|
12422 |
-
* method: 'POST',
|
12423 |
-
* url: 'http://example.com',
|
12424 |
-
* headers: {
|
12425 |
-
* 'Content-Type': undefined
|
12426 |
-
* },
|
12427 |
-
* data: { test: 'test' }
|
12428 |
-
* }
|
12429 |
-
*
|
12430 |
-
* $http(req).then(function(){...}, function(){...});
|
12431 |
-
* ```
|
12432 |
-
*
|
12433 |
-
* ## Transforming Requests and Responses
|
12434 |
-
*
|
12435 |
-
* Both requests and responses can be transformed using transformation functions: `transformRequest`
|
12436 |
-
* and `transformResponse`. These properties can be a single function that returns
|
12437 |
-
* the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions,
|
12438 |
-
* which allows you to `push` or `unshift` a new transformation function into the transformation chain.
|
12439 |
-
*
|
12440 |
-
* <div class="alert alert-warning">
|
12441 |
-
* **Note:** AngularJS does not make a copy of the `data` parameter before it is passed into the `transformRequest` pipeline.
|
12442 |
-
* That means changes to the properties of `data` are not local to the transform function (since Javascript passes objects by reference).
|
12443 |
-
* For example, when calling `$http.get(url, $scope.myObject)`, modifications to the object's properties in a transformRequest
|
12444 |
-
* function will be reflected on the scope and in any templates where the object is data-bound.
|
12445 |
-
* To prevent this, transform functions should have no side-effects.
|
12446 |
-
* If you need to modify properties, it is recommended to make a copy of the data, or create new object to return.
|
12447 |
-
* </div>
|
12448 |
-
*
|
12449 |
-
* ### Default Transformations
|
12450 |
-
*
|
12451 |
-
* The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and
|
12452 |
-
* `defaults.transformResponse` properties. If a request does not provide its own transformations
|
12453 |
-
* then these will be applied.
|
12454 |
-
*
|
12455 |
-
* You can augment or replace the default transformations by modifying these properties by adding to or
|
12456 |
-
* replacing the array.
|
12457 |
-
*
|
12458 |
-
* AngularJS provides the following default transformations:
|
12459 |
-
*
|
12460 |
-
* Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`) is
|
12461 |
-
* an array with one function that does the following:
|
12462 |
-
*
|
12463 |
-
* - If the `data` property of the request configuration object contains an object, serialize it
|
12464 |
-
* into JSON format.
|
12465 |
-
*
|
12466 |
-
* Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`) is
|
12467 |
-
* an array with one function that does the following:
|
12468 |
-
*
|
12469 |
-
* - If XSRF prefix is detected, strip it (see Security Considerations section below).
|
12470 |
-
* - If the `Content-Type` is `application/json` or the response looks like JSON,
|
12471 |
-
* deserialize it using a JSON parser.
|
12472 |
-
*
|
12473 |
-
*
|
12474 |
-
* ### Overriding the Default Transformations Per Request
|
12475 |
-
*
|
12476 |
-
* If you wish to override the request/response transformations only for a single request then provide
|
12477 |
-
* `transformRequest` and/or `transformResponse` properties on the configuration object passed
|
12478 |
-
* into `$http`.
|
12479 |
-
*
|
12480 |
-
* Note that if you provide these properties on the config object the default transformations will be
|
12481 |
-
* overwritten. If you wish to augment the default transformations then you must include them in your
|
12482 |
-
* local transformation array.
|
12483 |
-
*
|
12484 |
-
* The following code demonstrates adding a new response transformation to be run after the default response
|
12485 |
-
* transformations have been run.
|
12486 |
-
*
|
12487 |
-
* ```js
|
12488 |
-
* function appendTransform(defaults, transform) {
|
12489 |
*
|
12490 |
-
* // We can't guarantee that the default transformation is an array
|
12491 |
-
* defaults = angular.isArray(defaults) ? defaults : [defaults];
|
12492 |
*
|
12493 |
-
*
|
12494 |
-
*
|
12495 |
-
*
|
12496 |
-
|
12497 |
-
|
12498 |
-
*
|
12499 |
-
*
|
12500 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12501 |
* return doTransform(value);
|
12502 |
* })
|
12503 |
* });
|
12504 |
-
|
12505 |
-
|
12506 |
-
|
12507 |
-
|
12508 |
-
|
12509 |
-
|
12510 |
-
|
12511 |
-
|
12512 |
-
|
12513 |
-
|
12514 |
-
|
12515 |
-
|
12516 |
-
|
12517 |
-
|
12518 |
-
|
12519 |
-
|
12520 |
-
|
12521 |
-
|
12522 |
-
|
12523 |
-
|
12524 |
-
|
12525 |
-
|
12526 |
-
|
12527 |
-
|
12528 |
-
|
12529 |
-
|
12530 |
-
|
12531 |
-
|
12532 |
-
|
12533 |
-
|
12534 |
-
|
12535 |
-
|
12536 |
-
|
12537 |
-
|
12538 |
-
|
12539 |
-
|
12540 |
-
|
12541 |
-
|
12542 |
-
|
12543 |
-
|
12544 |
-
|
12545 |
-
|
12546 |
-
|
12547 |
-
|
12548 |
-
|
12549 |
* promise APIs} to fulfill this need for both synchronous and asynchronous pre-processing.
|
12550 |
-
|
12551 |
-
|
12552 |
-
|
12553 |
-
|
12554 |
-
|
12555 |
-
|
12556 |
-
|
12557 |
-
|
12558 |
-
|
12559 |
-
|
12560 |
-
|
12561 |
-
|
12562 |
-
|
12563 |
-
|
12564 |
-
|
12565 |
-
|
12566 |
-
|
12567 |
-
|
12568 |
-
|
12569 |
-
|
12570 |
-
|
12571 |
-
|
12572 |
* return {
|
12573 |
* // optional method
|
12574 |
* 'request': function(config) {
|
@@ -12603,12 +12603,12 @@
|
|
12603 |
* }
|
12604 |
* };
|
12605 |
* });
|
12606 |
-
|
12607 |
-
|
12608 |
-
|
12609 |
-
|
12610 |
-
|
12611 |
-
|
12612 |
* return {
|
12613 |
* 'request': function(config) {
|
12614 |
* // same as above
|
@@ -12619,207 +12619,207 @@
|
|
12619 |
* }
|
12620 |
* };
|
12621 |
* });
|
12622 |
-
|
12623 |
-
|
12624 |
-
|
12625 |
-
|
12626 |
-
|
12627 |
-
|
12628 |
-
|
12629 |
-
|
12630 |
-
|
12631 |
-
|
12632 |
-
|
12633 |
-
|
12634 |
-
|
12635 |
-
|
12636 |
-
|
12637 |
-
|
12638 |
-
|
12639 |
-
|
12640 |
-
|
12641 |
-
|
12642 |
-
|
12643 |
-
|
12644 |
-
|
12645 |
-
|
12646 |
-
|
12647 |
-
|
12648 |
-
|
12649 |
-
|
12650 |
-
|
12651 |
-
|
12652 |
-
|
12653 |
-
|
12654 |
-
|
12655 |
-
|
12656 |
-
|
12657 |
-
|
12658 |
-
|
12659 |
-
|
12660 |
-
|
12661 |
-
|
12662 |
-
|
12663 |
-
|
12664 |
-
|
12665 |
-
|
12666 |
-
|
12667 |
-
|
12668 |
-
|
12669 |
-
|
12670 |
-
|
12671 |
-
|
12672 |
-
|
12673 |
-
|
12674 |
-
|
12675 |
-
|
12676 |
-
|
12677 |
-
|
12678 |
-
|
12679 |
-
|
12680 |
-
|
12681 |
-
|
12682 |
-
|
12683 |
-
|
12684 |
-
|
12685 |
-
|
12686 |
-
|
12687 |
-
|
12688 |
-
|
12689 |
-
|
12690 |
-
|
12691 |
-
|
12692 |
-
|
12693 |
-
|
12694 |
-
|
12695 |
-
|
12696 |
-
|
12697 |
-
|
12698 |
-
|
12699 |
-
|
12700 |
-
|
12701 |
-
|
12702 |
-
|
12703 |
-
|
12704 |
-
|
12705 |
-
|
12706 |
-
|
12707 |
-
|
12708 |
-
|
12709 |
-
|
12710 |
-
|
12711 |
-
|
12712 |
-
|
12713 |
-
|
12714 |
-
|
12715 |
-
|
12716 |
-
|
12717 |
-
|
12718 |
-
|
12719 |
-
|
12720 |
-
|
12721 |
-
|
12722 |
-
|
12723 |
-
|
12724 |
-
|
12725 |
* Overriding the Default Transformations}
|
12726 |
-
|
12727 |
-
|
12728 |
-
|
12729 |
-
|
12730 |
-
|
12731 |
* Overriding the Default Transformations}
|
12732 |
-
|
12733 |
-
|
12734 |
-
|
12735 |
-
|
12736 |
-
|
12737 |
-
|
12738 |
-
|
12739 |
-
|
12740 |
-
|
12741 |
-
|
12742 |
-
|
12743 |
-
|
12744 |
-
|
12745 |
-
|
12746 |
-
|
12747 |
-
|
12748 |
-
|
12749 |
-
|
12750 |
-
|
12751 |
-
|
12752 |
-
|
12753 |
-
|
12754 |
-
|
12755 |
-
|
12756 |
-
|
12757 |
-
|
12758 |
-
|
12759 |
-
|
12760 |
-
|
12761 |
-
|
12762 |
-
|
12763 |
-
|
12764 |
-
|
12765 |
-
|
12766 |
-
|
12767 |
-
|
12768 |
-
|
12769 |
-
|
12770 |
-
|
12771 |
-
|
12772 |
-
|
12773 |
-
|
12774 |
-
|
12775 |
-
|
12776 |
-
|
12777 |
-
|
12778 |
-
|
12779 |
-
|
12780 |
-
|
12781 |
-
|
12782 |
-
|
12783 |
-
|
12784 |
-
|
12785 |
-
|
12786 |
-
|
12787 |
-
|
12788 |
-
|
12789 |
-
|
12790 |
-
|
12791 |
-
|
12792 |
-
|
12793 |
-
|
12794 |
-
|
12795 |
-
|
12796 |
-
|
12797 |
-
|
12798 |
-
|
12799 |
-
|
12800 |
-
|
12801 |
-
|
12802 |
-
|
12803 |
-
|
12804 |
-
|
12805 |
-
|
12806 |
-
|
12807 |
-
|
12808 |
-
|
12809 |
-
|
12810 |
-
|
12811 |
-
|
12812 |
-
|
12813 |
-
|
12814 |
-
|
12815 |
// We must whitelist the JSONP endpoint that we are using to show that we trust it
|
12816 |
$sceDelegateProvider.resourceUrlWhitelist([
|
12817 |
'self',
|
12818 |
'https://angularjs.org/**'
|
12819 |
]);
|
12820 |
}])
|
12821 |
-
|
12822 |
-
|
12823 |
$scope.method = 'GET';
|
12824 |
$scope.url = 'http-hello.html';
|
12825 |
|
@@ -12842,26 +12842,26 @@
|
|
12842 |
$scope.url = url;
|
12843 |
};
|
12844 |
}]);
|
12845 |
-
|
12846 |
-
|
12847 |
-
|
12848 |
-
|
12849 |
-
|
12850 |
-
|
12851 |
-
|
12852 |
-
|
12853 |
-
|
12854 |
-
|
12855 |
-
|
12856 |
-
|
12857 |
sampleGetBtn.click();
|
12858 |
fetchBtn.click();
|
12859 |
expect(status.getText()).toMatch('200');
|
12860 |
expect(data.getText()).toMatch(/Hello, \$http!/);
|
12861 |
});
|
12862 |
|
12863 |
-
|
12864 |
-
|
12865 |
// var sampleJsonpBtn = element(by.id('samplejsonpbtn'));
|
12866 |
// sampleJsonpBtn.click();
|
12867 |
// fetchBtn.click();
|
@@ -12869,1222 +12869,1222 @@
|
|
12869 |
// expect(data.getText()).toMatch(/Super Hero!/);
|
12870 |
// });
|
12871 |
|
12872 |
-
|
12873 |
-
|
12874 |
invalidJsonpBtn.click();
|
12875 |
fetchBtn.click();
|
12876 |
expect(status.getText()).toMatch('0');
|
12877 |
expect(data.getText()).toMatch('Request failed');
|
12878 |
});
|
12879 |
-
|
12880 |
-
|
12881 |
-
|
12882 |
-
|
12883 |
|
12884 |
-
|
12885 |
-
|
12886 |
-
|
12887 |
|
12888 |
-
|
12889 |
-
|
12890 |
-
|
12891 |
|
12892 |
-
|
12893 |
-
|
12894 |
-
|
12895 |
-
|
12896 |
-
|
12897 |
-
|
12898 |
-
|
12899 |
-
|
12900 |
-
config.headers = mergeHeaders(requestConfig);
|
12901 |
-
config.method = uppercase(config.method);
|
12902 |
-
config.paramSerializer = isString(config.paramSerializer) ?
|
12903 |
-
$injector.get(config.paramSerializer) : config.paramSerializer;
|
12904 |
-
|
12905 |
-
$browser.$$incOutstandingRequestCount('$http');
|
12906 |
-
|
12907 |
-
var requestInterceptors = [];
|
12908 |
-
var responseInterceptors = [];
|
12909 |
-
var promise = $q.resolve(config);
|
12910 |
-
|
12911 |
-
// apply interceptors
|
12912 |
-
forEach(reversedInterceptors, function(interceptor) {
|
12913 |
-
if (interceptor.request || interceptor.requestError) {
|
12914 |
-
requestInterceptors.unshift(interceptor.request, interceptor.requestError);
|
12915 |
-
}
|
12916 |
-
if (interceptor.response || interceptor.responseError) {
|
12917 |
-
responseInterceptors.push(interceptor.response, interceptor.responseError);
|
12918 |
-
}
|
12919 |
-
});
|
12920 |
|
12921 |
-
|
12922 |
-
|
12923 |
-
|
12924 |
-
|
12925 |
|
12926 |
-
|
12927 |
|
|
|
|
|
|
|
12928 |
|
12929 |
-
|
12930 |
-
|
12931 |
-
|
12932 |
-
|
|
|
|
|
|
|
|
|
|
|
12933 |
|
12934 |
-
|
12935 |
-
|
|
|
|
|
12936 |
|
12937 |
-
|
12938 |
|
12939 |
-
return promise;
|
12940 |
-
}
|
12941 |
|
12942 |
-
|
12943 |
-
|
12944 |
-
|
|
|
12945 |
|
12946 |
-
|
12947 |
-
|
12948 |
|
12949 |
-
|
12950 |
-
if (isFunction(headerFn)) {
|
12951 |
-
headerContent = headerFn(config);
|
12952 |
-
if (headerContent != null) {
|
12953 |
-
processedHeaders[header] = headerContent;
|
12954 |
-
}
|
12955 |
-
} else {
|
12956 |
-
processedHeaders[header] = headerFn;
|
12957 |
-
}
|
12958 |
-
});
|
12959 |
|
12960 |
-
|
12961 |
-
|
12962 |
|
12963 |
-
|
12964 |
-
|
12965 |
-
|
12966 |
-
defHeaderName, lowercaseDefHeaderName, reqHeaderName;
|
12967 |
|
12968 |
-
|
|
|
12969 |
|
12970 |
-
|
12971 |
-
|
12972 |
-
|
12973 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
12974 |
|
12975 |
-
|
12976 |
-
|
12977 |
-
continue defaultHeadersIteration;
|
12978 |
-
}
|
12979 |
-
}
|
12980 |
|
12981 |
-
|
12982 |
-
|
|
|
|
|
12983 |
|
12984 |
-
|
12985 |
-
return executeHeaderFns(reqHeaders, shallowCopy(config));
|
12986 |
-
}
|
12987 |
|
12988 |
-
|
12989 |
-
|
12990 |
-
|
|
|
12991 |
|
12992 |
-
|
12993 |
-
|
12994 |
-
|
12995 |
-
|
12996 |
-
|
12997 |
-
}
|
12998 |
-
});
|
12999 |
-
}
|
13000 |
|
13001 |
-
|
13002 |
-
|
13003 |
-
}
|
13004 |
|
13005 |
-
|
13006 |
-
|
13007 |
-
|
13008 |
|
13009 |
-
|
13010 |
-
|
13011 |
-
|
13012 |
-
resp.data = transformData(response.data, response.headers, response.status,
|
13013 |
-
config.transformResponse);
|
13014 |
-
return (isSuccess(response.status))
|
13015 |
-
? resp
|
13016 |
-
: $q.reject(resp);
|
13017 |
-
}
|
13018 |
-
}
|
13019 |
|
13020 |
-
$http.pendingRequests = [];
|
13021 |
-
|
13022 |
-
/**
|
13023 |
-
* @ngdoc method
|
13024 |
-
* @name $http#get
|
13025 |
-
*
|
13026 |
-
* @description
|
13027 |
-
* Shortcut method to perform `GET` request.
|
13028 |
-
*
|
13029 |
-
* @param {string|TrustedObject} url Absolute or relative URL of the resource that is being requested;
|
13030 |
-
* or an object created by a call to `$sce.trustAsResourceUrl(u
|
5 |
*/
|
6 |
(function(window) {'use strict';
|
7 |
|
8 |
+
/* exported
|
9 |
minErrConfig,
|
10 |
errorHandlingConfig,
|
11 |
isValidObjectMaxDepth
|
12 |
*/
|
13 |
|
14 |
+
var minErrConfig = {
|
15 |
+
objectMaxDepth: 5,
|
16 |
+
urlErrorParamsEnabled: true
|
17 |
+
};
|
18 |
|
19 |
+
/**
|
20 |
+
* @ngdoc function
|
21 |
+
* @name angular.errorHandlingConfig
|
22 |
+
* @module ng
|
23 |
+
* @kind function
|
24 |
+
*
|
25 |
+
* @description
|
26 |
+
* Configure several aspects of error handling in AngularJS if used as a setter or return the
|
27 |
+
* current configuration if used as a getter. The following options are supported:
|
28 |
+
*
|
29 |
+
* - **objectMaxDepth**: The maximum depth to which objects are traversed when stringified for error messages.
|
30 |
+
*
|
31 |
+
* Omitted or undefined options will leave the corresponding configuration values unchanged.
|
32 |
+
*
|
33 |
+
* @param {Object=} config - The configuration object. May only contain the options that need to be
|
34 |
+
* updated. Supported keys:
|
35 |
+
*
|
36 |
+
* * `objectMaxDepth` **{Number}** - The max depth for stringifying objects. Setting to a
|
37 |
+
* non-positive or non-numeric value, removes the max depth limit.
|
38 |
+
* Default: 5
|
39 |
+
*
|
40 |
+
* * `urlErrorParamsEnabled` **{Boolean}** - Specifies wether the generated error url will
|
41 |
+
* contain the parameters of the thrown error. Disabling the parameters can be useful if the
|
42 |
+
* generated error url is very long.
|
43 |
+
*
|
44 |
+
* Default: true. When used without argument, it returns the current value.
|
45 |
+
*/
|
46 |
+
function errorHandlingConfig(config) {
|
47 |
+
if (isObject(config)) {
|
48 |
+
if (isDefined(config.objectMaxDepth)) {
|
49 |
+
minErrConfig.objectMaxDepth = isValidObjectMaxDepth(config.objectMaxDepth) ? config.objectMaxDepth : NaN;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
}
|
51 |
+
if (isDefined(config.urlErrorParamsEnabled) && isBoolean(config.urlErrorParamsEnabled)) {
|
52 |
+
minErrConfig.urlErrorParamsEnabled = config.urlErrorParamsEnabled;
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
}
|
54 |
+
} else {
|
55 |
+
return minErrConfig;
|
56 |
+
}
|
57 |
+
}
|
58 |
+
|
59 |
+
/**
|
60 |
+
* @private
|
61 |
+
* @param {Number} maxDepth
|
62 |
+
* @return {boolean}
|
63 |
+
*/
|
64 |
+
function isValidObjectMaxDepth(maxDepth) {
|
65 |
+
return isNumber(maxDepth) && maxDepth > 0;
|
66 |
+
}
|
67 |
|
68 |
|
69 |
+
/**
|
70 |
+
* @description
|
71 |
+
*
|
72 |
+
* This object provides a utility for producing rich Error messages within
|
73 |
+
* AngularJS. It can be called as follows:
|
74 |
+
*
|
75 |
+
* var exampleMinErr = minErr('example');
|
76 |
+
* throw exampleMinErr('one', 'This {0} is {1}', foo, bar);
|
77 |
+
*
|
78 |
+
* The above creates an instance of minErr in the example namespace. The
|
79 |
+
* resulting error will have a namespaced error code of example.one. The
|
80 |
+
* resulting error will replace {0} with the value of foo, and {1} with the
|
81 |
+
* value of bar. The object is not restricted in the number of arguments it can
|
82 |
+
* take.
|
83 |
+
*
|
84 |
+
* If fewer arguments are specified than necessary for interpolation, the extra
|
85 |
+
* interpolation markers will be preserved in the final string.
|
86 |
+
*
|
87 |
+
* Since data will be parsed statically during a build step, some restrictions
|
88 |
+
* are applied with respect to how minErr instances are created and called.
|
89 |
+
* Instances should have names of the form namespaceMinErr for a minErr created
|
90 |
+
* using minErr('namespace') . Error codes, namespaces and template strings
|
91 |
+
* should all be static strings, not variables or general expressions.
|
92 |
+
*
|
93 |
+
* @param {string} module The namespace to use for the new minErr instance.
|
94 |
+
* @param {function} ErrorConstructor Custom error constructor to be instantiated when returning
|
95 |
+
* error from returned function, for cases when a particular type of error is useful.
|
96 |
+
* @returns {function(code:string, template:string, ...templateArgs): Error} minErr instance
|
97 |
+
*/
|
98 |
|
99 |
+
function minErr(module, ErrorConstructor) {
|
100 |
+
ErrorConstructor = ErrorConstructor || Error;
|
101 |
|
102 |
+
var url = 'https://errors.angularjs.org/1.7.6/';
|
103 |
+
var regex = url.replace('.', '\\.') + '[\\s\\S]*';
|
104 |
+
var errRegExp = new RegExp(regex, 'g');
|
105 |
|
106 |
+
return function() {
|
107 |
+
var code = arguments[0],
|
108 |
+
template = arguments[1],
|
109 |
+
message = '[' + (module ? module + ':' : '') + code + '] ',
|
110 |
+
templateArgs = sliceArgs(arguments, 2).map(function(arg) {
|
111 |
+
return toDebugString(arg, minErrConfig.objectMaxDepth);
|
112 |
+
}),
|
113 |
+
paramPrefix, i;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
+
// A minErr message has two parts: the message itself and the url that contains the
|
116 |
+
// encoded message.
|
117 |
+
// The message's parameters can contain other error messages which also include error urls.
|
118 |
+
// To prevent the messages from getting too long, we strip the error urls from the parameters.
|
119 |
|
120 |
+
message += template.replace(/\{\d+\}/g, function(match) {
|
121 |
+
var index = +match.slice(1, -1);
|
122 |
|
123 |
+
if (index < templateArgs.length) {
|
124 |
+
return templateArgs[index].replace(errRegExp, '');
|
125 |
+
}
|
|
|
|
|
126 |
|
127 |
+
return match;
|
128 |
+
});
|
129 |
+
|
130 |
+
message += '\n' + url + (module ? module + '/' : '') + code;
|
131 |
+
|
132 |
+
if (minErrConfig.urlErrorParamsEnabled) {
|
133 |
+
for (i = 0, paramPrefix = '?'; i < templateArgs.length; i++, paramPrefix = '&') {
|
134 |
+
message += paramPrefix + 'p' + i + '=' + encodeURIComponent(templateArgs[i]);
|
135 |
+
}
|
136 |
}
|
137 |
|
138 |
+
return new ErrorConstructor(message);
|
139 |
+
};
|
140 |
+
}
|
141 |
+
|
142 |
+
/* We need to tell ESLint what variables are being exported */
|
143 |
+
/* exported
|
144 |
angular,
|
145 |
msie,
|
146 |
jqLite,
|
243 |
|
244 |
////////////////////////////////////
|
245 |
|
246 |
+
/**
|
247 |
+
* @ngdoc module
|
248 |
+
* @name ng
|
249 |
+
* @module ng
|
250 |
+
* @installation
|
251 |
+
* @description
|
252 |
+
*
|
253 |
+
* The ng module is loaded by default when an AngularJS application is started. The module itself
|
254 |
+
* contains the essential components for an AngularJS application to function. The table below
|
255 |
+
* lists a high level breakdown of each of the services/factories, filters, directives and testing
|
256 |
+
* components available within this core module.
|
257 |
+
*
|
258 |
+
*/
|
259 |
|
260 |
+
var REGEX_STRING_REGEXP = /^\/(.+)\/([a-z]*)$/;
|
261 |
|
262 |
// The name of a form control's ValidityState property.
|
263 |
// This is used so that it's possible for internal tests to create mock ValidityStates.
|
264 |
+
var VALIDITY_STATE_PROPERTY = 'validity';
|
265 |
|
266 |
|
267 |
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
268 |
|
269 |
+
/**
|
270 |
+
* @private
|
271 |
+
*
|
272 |
+
* @description Converts the specified string to lowercase.
|
273 |
+
* @param {string} string String to be converted to lowercase.
|
274 |
+
* @returns {string} Lowercased string.
|
275 |
+
*/
|
276 |
+
var lowercase = function(string) {return isString(string) ? string.toLowerCase() : string;};
|
277 |
|
278 |
+
/**
|
279 |
+
* @private
|
280 |
+
*
|
281 |
+
* @description Converts the specified string to uppercase.
|
282 |
+
* @param {string} string String to be converted to uppercase.
|
283 |
+
* @returns {string} Uppercased string.
|
284 |
+
*/
|
285 |
+
var uppercase = function(string) {return isString(string) ? string.toUpperCase() : string;};
|
286 |
|
287 |
|
288 |
+
var
|
289 |
+
msie, // holds major version number for IE, or NaN if UA is not IE.
|
290 |
+
jqLite, // delay binding since jQuery could be loaded after us.
|
291 |
+
jQuery, // delay binding
|
292 |
+
slice = [].slice,
|
293 |
+
splice = [].splice,
|
294 |
+
push = [].push,
|
295 |
+
toString = Object.prototype.toString,
|
296 |
+
getPrototypeOf = Object.getPrototypeOf,
|
297 |
+
ngMinErr = minErr('ng'),
|
298 |
|
299 |
+
/** @name angular */
|
300 |
+
angular = window.angular || (window.angular = {}),
|
301 |
+
angularModule,
|
302 |
+
uid = 0;
|
303 |
|
304 |
// Support: IE 9-11 only
|
305 |
+
/**
|
306 |
+
* documentMode is an IE-only property
|
307 |
+
* http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
|
308 |
+
*/
|
309 |
+
msie = window.document.documentMode;
|
310 |
|
311 |
|
312 |
+
/**
|
313 |
+
* @private
|
314 |
+
* @param {*} obj
|
315 |
+
* @return {boolean} Returns true if `obj` is an array or array-like object (NodeList, Arguments,
|
316 |
+
* String ...)
|
317 |
+
*/
|
318 |
+
function isArrayLike(obj) {
|
319 |
|
320 |
+
// `null`, `undefined` and `window` are not array-like
|
321 |
+
if (obj == null || isWindow(obj)) return false;
|
322 |
|
323 |
+
// arrays, strings and jQuery/jqLite objects are array like
|
324 |
+
// * jqLite is either the jQuery or jqLite constructor function
|
325 |
+
// * we have to check the existence of jqLite first as this method is called
|
326 |
+
// via the forEach method when constructing the jqLite object in the first place
|
327 |
+
if (isArray(obj) || isString(obj) || (jqLite && obj instanceof jqLite)) return true;
|
328 |
|
329 |
+
// Support: iOS 8.2 (not reproducible in simulator)
|
330 |
+
// "length" in obj used to prevent JIT error (gh-11508)
|
331 |
+
var length = 'length' in Object(obj) && obj.length;
|
332 |
|
333 |
+
// NodeList objects (with `item` method) and
|
334 |
+
// other objects with suitable length characteristics are array-like
|
335 |
+
return isNumber(length) && (length >= 0 && (length - 1) in obj || typeof obj.item === 'function');
|
336 |
|
337 |
+
}
|
338 |
|
339 |
+
/**
|
340 |
+
* @ngdoc function
|
341 |
+
* @name angular.forEach
|
342 |
+
* @module ng
|
343 |
+
* @kind function
|
344 |
+
*
|
345 |
+
* @description
|
346 |
+
* Invokes the `iterator` function once for each item in `obj` collection, which can be either an
|
347 |
+
* object or an array. The `iterator` function is invoked with `iterator(value, key, obj)`, where `value`
|
348 |
+
* is the value of an object property or an array element, `key` is the object property key or
|
349 |
+
* array element index and obj is the `obj` itself. Specifying a `context` for the function is optional.
|
350 |
+
*
|
351 |
+
* It is worth noting that `.forEach` does not iterate over inherited properties because it filters
|
352 |
+
* using the `hasOwnProperty` method.
|
353 |
+
*
|
354 |
+
* Unlike ES262's
|
355 |
+
* [Array.prototype.forEach](http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.18),
|
356 |
+
* providing 'undefined' or 'null' values for `obj` will not throw a TypeError, but rather just
|
357 |
+
* return the value provided.
|
358 |
+
*
|
359 |
+
```js
|
360 |
var values = {name: 'misko', gender: 'male'};
|
361 |
var log = [];
|
362 |
angular.forEach(values, function(value, key) {
|
363 |
this.push(key + ': ' + value);
|
364 |
}, log);
|
365 |
expect(log).toEqual(['name: misko', 'gender: male']);
|
366 |
+
```
|
367 |
+
*
|
368 |
+
* @param {Object|Array} obj Object to iterate over.
|
369 |
+
* @param {Function} iterator Iterator function.
|
370 |
+
* @param {Object=} context Object to become context (`this`) for the iterator function.
|
371 |
+
* @returns {Object|Array} Reference to `obj`.
|
372 |
+
*/
|
373 |
|
374 |
+
function forEach(obj, iterator, context) {
|
375 |
+
var key, length;
|
376 |
+
if (obj) {
|
377 |
+
if (isFunction(obj)) {
|
378 |
+
for (key in obj) {
|
379 |
+
if (key !== 'prototype' && key !== 'length' && key !== 'name' && obj.hasOwnProperty(key)) {
|
380 |
+
iterator.call(context, obj[key], key, obj);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
}
|
382 |
+
}
|
383 |
+
} else if (isArray(obj) || isArrayLike(obj)) {
|
384 |
+
var isPrimitive = typeof obj !== 'object';
|
385 |
+
for (key = 0, length = obj.length; key < length; key++) {
|
386 |
+
if (isPrimitive || key in obj) {
|
387 |
+
iterator.call(context, obj[key], key, obj);
|
388 |
+
}
|
389 |
+
}
|
390 |
+
} else if (obj.forEach && obj.forEach !== forEach) {
|
391 |
+
obj.forEach(iterator, context, obj);
|
392 |
+
} else if (isBlankObject(obj)) {
|
393 |
+
// createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
|
394 |
+
for (key in obj) {
|
395 |
+
iterator.call(context, obj[key], key, obj);
|
396 |
+
}
|
397 |
+
} else if (typeof obj.hasOwnProperty === 'function') {
|
398 |
+
// Slow path for objects inheriting Object.prototype, hasOwnProperty check needed
|
399 |
+
for (key in obj) {
|
400 |
+
if (obj.hasOwnProperty(key)) {
|
401 |
+
iterator.call(context, obj[key], key, obj);
|
402 |
+
}
|
403 |
+
}
|
404 |
+
} else {
|
405 |
+
// Slow path for objects which do not have a method `hasOwnProperty`
|
406 |
+
for (key in obj) {
|
407 |
+
if (hasOwnProperty.call(obj, key)) {
|
408 |
+
iterator.call(context, obj[key], key, obj);
|
409 |
}
|
410 |
+
}
|
411 |
}
|
412 |
+
}
|
413 |
+
return obj;
|
414 |
+
}
|
415 |
|
416 |
+
function forEachSorted(obj, iterator, context) {
|
417 |
+
var keys = Object.keys(obj).sort();
|
418 |
+
for (var i = 0; i < keys.length; i++) {
|
419 |
+
iterator.call(context, obj[keys[i]], keys[i]);
|
420 |
+
}
|
421 |
+
return keys;
|
422 |
+
}
|
423 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
424 |
|
425 |
+
/**
|
426 |
+
* when using forEach the params are value, key, but it is often useful to have key, value.
|
427 |
+
* @param {function(string, *)} iteratorFn
|
428 |
+
* @returns {function(*, string)}
|
429 |
+
*/
|
430 |
+
function reverseParams(iteratorFn) {
|
431 |
+
return function(value, key) {iteratorFn(key, value);};
|
432 |
+
}
|
433 |
|
434 |
+
/**
|
435 |
+
* A consistent way of creating unique IDs in angular.
|
436 |
+
*
|
437 |
+
* Using simple numbers allows us to generate 28.6 million unique ids per second for 10 years before
|
438 |
+
* we hit number precision issues in JavaScript.
|
439 |
+
*
|
440 |
+
* Math.pow(2,53) / 60 / 60 / 24 / 365 / 10 = 28.6M
|
441 |
+
*
|
442 |
+
* @returns {number} an unique alpha-numeric string
|
443 |
+
*/
|
444 |
+
function nextUid() {
|
445 |
+
return ++uid;
|
446 |
+
}
|
447 |
|
448 |
|
449 |
+
/**
|
450 |
+
* Set or clear the hashkey for an object.
|
451 |
+
* @param obj object
|
452 |
+
* @param h the hashkey (!truthy to delete the hashkey)
|
453 |
+
*/
|
454 |
+
function setHashKey(obj, h) {
|
455 |
+
if (h) {
|
456 |
+
obj.$$hashKey = h;
|
457 |
+
} else {
|
458 |
+
delete obj.$$hashKey;
|
459 |
+
}
|
460 |
+
}
|
461 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
|
463 |
+
function baseExtend(dst, objs, deep) {
|
464 |
+
var h = dst.$$hashKey;
|
465 |
+
|
466 |
+
for (var i = 0, ii = objs.length; i < ii; ++i) {
|
467 |
+
var obj = objs[i];
|
468 |
+
if (!isObject(obj) && !isFunction(obj)) continue;
|
469 |
+
var keys = Object.keys(obj);
|
470 |
+
for (var j = 0, jj = keys.length; j < jj; j++) {
|
471 |
+
var key = keys[j];
|
472 |
+
var src = obj[key];
|
473 |
+
|
474 |
+
if (deep && isObject(src)) {
|
475 |
+
if (isDate(src)) {
|
476 |
+
dst[key] = new Date(src.valueOf());
|
477 |
+
} else if (isRegExp(src)) {
|
478 |
+
dst[key] = new RegExp(src);
|
479 |
+
} else if (src.nodeName) {
|
480 |
+
dst[key] = src.cloneNode(true);
|
481 |
+
} else if (isElement(src)) {
|
482 |
+
dst[key] = src.clone();
|
483 |
+
} else {
|
484 |
+
if (!isObject(dst[key])) dst[key] = isArray(src) ? [] : {};
|
485 |
+
baseExtend(dst[key], [src], true);
|
486 |
}
|
487 |
+
} else {
|
488 |
+
dst[key] = src;
|
489 |
+
}
|
490 |
}
|
491 |
+
}
|
492 |
|
493 |
+
setHashKey(dst, h);
|
494 |
+
return dst;
|
495 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
496 |
|
497 |
+
/**
|
498 |
+
* @ngdoc function
|
499 |
+
* @name angular.extend
|
500 |
+
* @module ng
|
501 |
+
* @kind function
|
502 |
+
*
|
503 |
+
* @description
|
504 |
+
* Extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
|
505 |
+
* to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
|
506 |
+
* by passing an empty object as the target: `var object = angular.extend({}, object1, object2)`.
|
507 |
+
*
|
508 |
+
* **Note:** Keep in mind that `angular.extend` does not support recursive merge (deep copy). Use
|
509 |
+
* {@link angular.merge} for this.
|
510 |
+
*
|
511 |
+
* @param {Object} dst Destination object.
|
512 |
+
* @param {...Object} src Source object(s).
|
513 |
+
* @returns {Object} Reference to `dst`.
|
514 |
+
*/
|
515 |
+
function extend(dst) {
|
516 |
+
return baseExtend(dst, slice.call(arguments, 1), false);
|
517 |
+
}
|
518 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
519 |
|
520 |
+
/**
|
521 |
+
* @ngdoc function
|
522 |
+
* @name angular.merge
|
523 |
+
* @module ng
|
524 |
+
* @kind function
|
525 |
+
*
|
526 |
+
* @description
|
527 |
+
* Deeply extends the destination object `dst` by copying own enumerable properties from the `src` object(s)
|
528 |
+
* to `dst`. You can specify multiple `src` objects. If you want to preserve original objects, you can do so
|
529 |
+
* by passing an empty object as the target: `var object = angular.merge({}, object1, object2)`.
|
530 |
+
*
|
531 |
+
* Unlike {@link angular.extend extend()}, `merge()` recursively descends into object properties of source
|
532 |
+
* objects, performing a deep copy.
|
533 |
+
*
|
534 |
+
* @deprecated
|
535 |
+
* sinceVersion="1.6.5"
|
536 |
+
* This function is deprecated, but will not be removed in the 1.x lifecycle.
|
537 |
+
* There are edge cases (see {@link angular.merge#known-issues known issues}) that are not
|
538 |
+
* supported by this function. We suggest
|
539 |
+
* using [lodash's merge()](https://lodash.com/docs/4.17.4#merge) instead.
|
540 |
+
*
|
541 |
+
* @knownIssue
|
542 |
+
* This is a list of (known) object types that are not handled correctly by this function:
|
543 |
+
* - [`Blob`](https://developer.mozilla.org/docs/Web/API/Blob)
|
544 |
+
* - [`MediaStream`](https://developer.mozilla.org/docs/Web/API/MediaStream)
|
545 |
+
* - [`CanvasGradient`](https://developer.mozilla.org/docs/Web/API/CanvasGradient)
|
546 |
+
* - AngularJS {@link $rootScope.Scope scopes};
|
547 |
+
*
|
548 |
+
* @param {Object} dst Destination object.
|
549 |
+
* @param {...Object} src Source object(s).
|
550 |
+
* @returns {Object} Reference to `dst`.
|
551 |
+
*/
|
552 |
+
function merge(dst) {
|
553 |
+
return baseExtend(dst, slice.call(arguments, 1), true);
|
554 |
+
}
|
555 |
|
556 |
|
|
|
|
|
|
|
557 |
|
558 |
+
function toInt(str) {
|
559 |
+
return parseInt(str, 10);
|
560 |
+
}
|
|
|
561 |
|
562 |
+
var isNumberNaN = Number.isNaN || function isNumberNaN(num) {
|
563 |
+
// eslint-disable-next-line no-self-compare
|
564 |
+
return num !== num;
|
565 |
+
};
|
566 |
|
|
|
|
|
|
|
567 |
|
568 |
+
function inherit(parent, extra) {
|
569 |
+
return extend(Object.create(parent), extra);
|
570 |
+
}
|
571 |
+
|
572 |
+
/**
|
573 |
+
* @ngdoc function
|
574 |
+
* @name angular.noop
|
575 |
+
* @module ng
|
576 |
+
* @kind function
|
577 |
+
*
|
578 |
+
* @description
|
579 |
+
* A function that performs no operations. This function can be useful when writing code in the
|
580 |
+
* functional style.
|
581 |
+
```js
|
582 |
function foo(callback) {
|
583 |
var result = calculateResult();
|
584 |
(callback || angular.noop)(result);
|
585 |
}
|
586 |
+
```
|
587 |
+
*/
|
588 |
+
function noop() {}
|
589 |
+
noop.$inject = [];
|
590 |
|
591 |
|
592 |
+
/**
|
593 |
+
* @ngdoc function
|
594 |
+
* @name angular.identity
|
595 |
+
* @module ng
|
596 |
+
* @kind function
|
597 |
+
*
|
598 |
+
* @description
|
599 |
+
* A function that returns its first argument. This function is useful when writing code in the
|
600 |
+
* functional style.
|
601 |
+
*
|
602 |
+
```js
|
603 |
+
function transformer(transformationFn, value) {
|
604 |
return (transformationFn || angular.identity)(value);
|
605 |
};
|
606 |
|
607 |
+
// E.g.
|
608 |
+
function getResult(fn, input) {
|
609 |
return (fn || angular.identity)(input);
|
610 |
};
|
611 |
|
612 |
+
getResult(function(n) { return n * 2; }, 21); // returns 42
|
613 |
+
getResult(null, 21); // returns 21
|
614 |
+
getResult(undefined, 21); // returns 21
|
615 |
+
```
|
616 |
+
*
|
617 |
+
* @param {*} value to be returned.
|
618 |
+
* @returns {*} the value passed in.
|
619 |
+
*/
|
620 |
+
function identity($) {return $;}
|
621 |
+
identity.$inject = [];
|
622 |
|
623 |
|
624 |
+
function valueFn(value) {return function valueRef() {return value;};}
|
625 |
|
626 |
+
function hasCustomToString(obj) {
|
627 |
+
return isFunction(obj.toString) && obj.toString !== toString;
|
628 |
+
}
|
629 |
|
630 |
|
631 |
+
/**
|
632 |
+
* @ngdoc function
|
633 |
+
* @name angular.isUndefined
|
634 |
+
* @module ng
|
635 |
+
* @kind function
|
636 |
+
*
|
637 |
+
* @description
|
638 |
+
* Determines if a reference is undefined.
|
639 |
+
*
|
640 |
+
* @param {*} value Reference to check.
|
641 |
+
* @returns {boolean} True if `value` is undefined.
|
642 |
+
*/
|
643 |
+
function isUndefined(value) {return typeof value === 'undefined';}
|
644 |
|
645 |
|
646 |
+
/**
|
647 |
+
* @ngdoc function
|
648 |
+
* @name angular.isDefined
|
649 |
+
* @module ng
|
650 |
+
* @kind function
|
651 |
+
*
|
652 |
+
* @description
|
653 |
+
* Determines if a reference is defined.
|
654 |
+
*
|
655 |
+
* @param {*} value Reference to check.
|
656 |
+
* @returns {boolean} True if `value` is defined.
|
657 |
+
*/
|
658 |
+
function isDefined(value) {return typeof value !== 'undefined';}
|
659 |
|
660 |
|
661 |
+
/**
|
662 |
+
* @ngdoc function
|
663 |
+
* @name angular.isObject
|
664 |
+
* @module ng
|
665 |
+
* @kind function
|
666 |
+
*
|
667 |
+
* @description
|
668 |
+
* Determines if a reference is an `Object`. Unlike `typeof` in JavaScript, `null`s are not
|
669 |
+
* considered to be objects. Note that JavaScript arrays are objects.
|
670 |
+
*
|
671 |
+
* @param {*} value Reference to check.
|
672 |
+
* @returns {boolean} True if `value` is an `Object` but not `null`.
|
673 |
+
*/
|
674 |
+
function isObject(value) {
|
675 |
+
// http://jsperf.com/isobject4
|
676 |
+
return value !== null && typeof value === 'object';
|
677 |
+
}
|
678 |
|
679 |
|
680 |
+
/**
|
681 |
+
* Determine if a value is an object with a null prototype
|
682 |
+
*
|
683 |
+
* @returns {boolean} True if `value` is an `Object` with a null prototype
|
684 |
+
*/
|
685 |
+
function isBlankObject(value) {
|
686 |
+
return value !== null && typeof value === 'object' && !getPrototypeOf(value);
|
687 |
+
}
|
688 |
|
689 |
|
690 |
+
/**
|
691 |
+
* @ngdoc function
|
692 |
+
* @name angular.isString
|
693 |
+
* @module ng
|
694 |
+
* @kind function
|
695 |
+
*
|
696 |
+
* @description
|
697 |
+
* Determines if a reference is a `String`.
|
698 |
+
*
|
699 |
+
* @param {*} value Reference to check.
|
700 |
+
* @returns {boolean} True if `value` is a `String`.
|
701 |
+
*/
|
702 |
+
function isString(value) {return typeof value === 'string';}
|
703 |
|
704 |
|
705 |
+
/**
|
706 |
+
* @ngdoc function
|
707 |
+
* @name angular.isNumber
|
708 |
+
* @module ng
|
709 |
+
* @kind function
|
710 |
+
*
|
711 |
+
* @description
|
712 |
+
* Determines if a reference is a `Number`.
|
713 |
+
*
|
714 |
+
* This includes the "special" numbers `NaN`, `+Infinity` and `-Infinity`.
|
715 |
+
*
|
716 |
+
* If you wish to exclude these then you can use the native
|
717 |
+
* [`isFinite'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isFinite)
|
718 |
+
* method.
|
719 |
+
*
|
720 |
+
* @param {*} value Reference to check.
|
721 |
+
* @returns {boolean} True if `value` is a `Number`.
|
722 |
+
*/
|
723 |
+
function isNumber(value) {return typeof value === 'number';}
|
724 |
|
725 |
|
726 |
+
/**
|
727 |
+
* @ngdoc function
|
728 |
+
* @name angular.isDate
|
729 |
+
* @module ng
|
730 |
+
* @kind function
|
731 |
+
*
|
732 |
+
* @description
|
733 |
+
* Determines if a value is a date.
|
734 |
+
*
|
735 |
+
* @param {*} value Reference to check.
|
736 |
+
* @returns {boolean} True if `value` is a `Date`.
|
737 |
+
*/
|
738 |
+
function isDate(value) {
|
739 |
+
return toString.call(value) === '[object Date]';
|
740 |
+
}
|
741 |
|
742 |
|
743 |
+
/**
|
744 |
+
* @ngdoc function
|
745 |
+
* @name angular.isArray
|
746 |
+
* @module ng
|
747 |
+
* @kind function
|
748 |
+
*
|
749 |
+
* @description
|
750 |
+
* Determines if a reference is an `Array`.
|
751 |
+
*
|
752 |
+
* @param {*} value Reference to check.
|
753 |
+
* @returns {boolean} True if `value` is an `Array`.
|
754 |
+
*/
|
755 |
+
function isArray(arr) {
|
756 |
+
return Array.isArray(arr) || arr instanceof Array;
|
757 |
+
}
|
758 |
|
759 |
+
/**
|
760 |
+
* @description
|
761 |
+
* Determines if a reference is an `Error`.
|
762 |
+
* Loosely based on https://www.npmjs.com/package/iserror
|
763 |
+
*
|
764 |
+
* @param {*} value Reference to check.
|
765 |
+
* @returns {boolean} True if `value` is an `Error`.
|
766 |
+
*/
|
767 |
+
function isError(value) {
|
768 |
+
var tag = toString.call(value);
|
769 |
+
switch (tag) {
|
770 |
+
case '[object Error]': return true;
|
771 |
+
case '[object Exception]': return true;
|
772 |
+
case '[object DOMException]': return true;
|
773 |
+
default: return value instanceof Error;
|
774 |
+
}
|
775 |
+
}
|
776 |
|
777 |
+
/**
|
778 |
+
* @ngdoc function
|
779 |
+
* @name angular.isFunction
|
780 |
+
* @module ng
|
781 |
+
* @kind function
|
782 |
+
*
|
783 |
+
* @description
|
784 |
+
* Determines if a reference is a `Function`.
|
785 |
+
*
|
786 |
+
* @param {*} value Reference to check.
|
787 |
+
* @returns {boolean} True if `value` is a `Function`.
|
788 |
+
*/
|
789 |
+
function isFunction(value) {return typeof value === 'function';}
|
790 |
|
791 |
|
792 |
+
/**
|
793 |
+
* Determines if a value is a regular expression object.
|
794 |
+
*
|
795 |
+
* @private
|
796 |
+
* @param {*} value Reference to check.
|
797 |
+
* @returns {boolean} True if `value` is a `RegExp`.
|
798 |
+
*/
|
799 |
+
function isRegExp(value) {
|
800 |
+
return toString.call(value) === '[object RegExp]';
|
801 |
+
}
|
802 |
|
803 |
|
804 |
+
/**
|
805 |
+
* Checks if `obj` is a window object.
|
806 |
+
*
|
807 |
+
* @private
|
808 |
+
* @param {*} obj Object to check
|
809 |
+
* @returns {boolean} True if `obj` is a window obj.
|
810 |
+
*/
|
811 |
+
function isWindow(obj) {
|
812 |
+
return obj && obj.window === obj;
|
813 |
+
}
|
814 |
|
815 |
|
816 |
+
function isScope(obj) {
|
817 |
+
return obj && obj.$evalAsync && obj.$watch;
|
818 |
+
}
|
819 |
|
820 |
|
821 |
+
function isFile(obj) {
|
822 |
+
return toString.call(obj) === '[object File]';
|
823 |
+
}
|
824 |
|
825 |
|
826 |
+
function isFormData(obj) {
|
827 |
+
return toString.call(obj) === '[object FormData]';
|
828 |
+
}
|
829 |
|
830 |
|
831 |
+
function isBlob(obj) {
|
832 |
+
return toString.call(obj) === '[object Blob]';
|
833 |
+
}
|
834 |
|
835 |
|
836 |
+
function isBoolean(value) {
|
837 |
+
return typeof value === 'boolean';
|
838 |
+
}
|
839 |
|
840 |
|
841 |
+
function isPromiseLike(obj) {
|
842 |
+
return obj && isFunction(obj.then);
|
843 |
+
}
|
844 |
|
845 |
|
846 |
+
var TYPED_ARRAY_REGEXP = /^\[object (?:Uint8|Uint8Clamped|Uint16|Uint32|Int8|Int16|Int32|Float32|Float64)Array]$/;
|
847 |
+
function isTypedArray(value) {
|
848 |
+
return value && isNumber(value.length) && TYPED_ARRAY_REGEXP.test(toString.call(value));
|
849 |
+
}
|
850 |
|
851 |
+
function isArrayBuffer(obj) {
|
852 |
+
return toString.call(obj) === '[object ArrayBuffer]';
|
853 |
+
}
|
854 |
|
855 |
|
856 |
+
var trim = function(value) {
|
857 |
+
return isString(value) ? value.trim() : value;
|
858 |
+
};
|
859 |
|
860 |
// Copied from:
|
861 |
// http://docs.closure-library.googlecode.com/git/local_closure_goog_string_string.js.source.html#line1021
|
862 |
// Prereq: s is a string.
|
863 |
+
var escapeForRegexp = function(s) {
|
864 |
+
return s
|
865 |
+
.replace(/([-()[\]{}+?*.$^|,:#<!\\])/g, '\\$1')
|
866 |
+
// eslint-disable-next-line no-control-regex
|
867 |
+
.replace(/\x08/g, '\\x08');
|
868 |
+
};
|
869 |
|
870 |
|
871 |
+
/**
|
872 |
+
* @ngdoc function
|
873 |
+
* @name angular.isElement
|
874 |
+
* @module ng
|
875 |
+
* @kind function
|
876 |
+
*
|
877 |
+
* @description
|
878 |
+
* Determines if a reference is a DOM element (or wrapped jQuery element).
|
879 |
+
*
|
880 |
+
* @param {*} value Reference to check.
|
881 |
+
* @returns {boolean} True if `value` is a DOM element (or wrapped jQuery element).
|
882 |
+
*/
|
883 |
+
function isElement(node) {
|
884 |
+
return !!(node &&
|
885 |
+
(node.nodeName // We are a direct element.
|
886 |
+
|| (node.prop && node.attr && node.find))); // We have an on and find method part of jQuery API.
|
887 |
+
}
|
888 |
|
889 |
+
/**
|
890 |
+
* @param str 'key1,key2,...'
|
891 |
+
* @returns {object} in the form of {key1:true, key2:true, ...}
|
892 |
+
*/
|
893 |
+
function makeMap(str) {
|
894 |
+
var obj = {}, items = str.split(','), i;
|
895 |
+
for (i = 0; i < items.length; i++) {
|
896 |
+
obj[items[i]] = true;
|
897 |
+
}
|
898 |
+
return obj;
|
899 |
+
}
|
900 |
|
901 |
|
902 |
+
function nodeName_(element) {
|
903 |
+
return lowercase(element.nodeName || (element[0] && element[0].nodeName));
|
904 |
+
}
|
905 |
|
906 |
+
function includes(array, obj) {
|
907 |
+
return Array.prototype.indexOf.call(array, obj) !== -1;
|
908 |
+
}
|
909 |
|
910 |
+
function arrayRemove(array, value) {
|
911 |
+
var index = array.indexOf(value);
|
912 |
+
if (index >= 0) {
|
913 |
+
array.splice(index, 1);
|
914 |
+
}
|
915 |
+
return index;
|
916 |
+
}
|
917 |
|
918 |
+
/**
|
919 |
+
* @ngdoc function
|
920 |
+
* @name angular.copy
|
921 |
+
* @module ng
|
922 |
+
* @kind function
|
923 |
+
*
|
924 |
+
* @description
|
925 |
+
* Creates a deep copy of `source`, which should be an object or an array.
|
926 |
+
*
|
927 |
+
* * If no destination is supplied, a copy of the object or array is created.
|
928 |
+
* * If a destination is provided, all of its elements (for arrays) or properties (for objects)
|
929 |
+
* are deleted and then all elements/properties from the source are copied to it.
|
930 |
+
* * If `source` is not an object or array (inc. `null` and `undefined`), `source` is returned.
|
931 |
+
* * If `source` is identical to `destination` an exception will be thrown.
|
932 |
+
*
|
933 |
+
* <br />
|
934 |
+
*
|
935 |
+
* <div class="alert alert-warning">
|
936 |
+
* Only enumerable properties are taken into account. Non-enumerable properties (both on `source`
|
937 |
+
* and on `destination`) will be ignored.
|
938 |
+
* </div>
|
939 |
+
*
|
940 |
+
* @param {*} source The source that will be used to make a copy. Can be any type, including
|
941 |
+
* primitives, `null`, and `undefined`.
|
942 |
+
* @param {(Object|Array)=} destination Destination into which the source is copied. If provided,
|
943 |
+
* must be of the same type as `source`.
|
944 |
+
* @returns {*} The copy or updated `destination`, if `destination` was specified.
|
945 |
+
*
|
946 |
+
* @example
|
947 |
+
<example module="copyExample" name="angular-copy">
|
948 |
+
<file name="index.html">
|
949 |
+
<div ng-controller="ExampleController">
|
950 |
+
<form novalidate class="simple-form">
|
951 |
+
<label>Name: <input type="text" ng-model="user.name" /></label><br />
|
952 |
+
<label>Age: <input type="number" ng-model="user.age" /></label><br />
|
953 |
+
Gender: <label><input type="radio" ng-model="user.gender" value="male" />male</label>
|
954 |
+
<label><input type="radio" ng-model="user.gender" value="female" />female</label><br />
|
955 |
+
<button ng-click="reset()">RESET</button>
|
956 |
+
<button ng-click="update(user)">SAVE</button>
|
957 |
+
</form>
|
958 |
+
<pre>form = {{user | json}}</pre>
|
959 |
+
<pre>leader = {{leader | json}}</pre>
|
960 |
+
</div>
|
961 |
+
</file>
|
962 |
+
<file name="script.js">
|
963 |
+
// Module: copyExample
|
964 |
+
angular.
|
965 |
+
module('copyExample', []).
|
966 |
+
controller('ExampleController', ['$scope', function($scope) {
|
967 |
$scope.leader = {};
|
968 |
|
969 |
$scope.reset = function() {
|
978 |
|
979 |
$scope.reset();
|
980 |
}]);
|
981 |
+
</file>
|
982 |
+
</example>
|
983 |
+
*/
|
984 |
+
function copy(source, destination, maxDepth) {
|
985 |
+
var stackSource = [];
|
986 |
+
var stackDest = [];
|
987 |
+
maxDepth = isValidObjectMaxDepth(maxDepth) ? maxDepth : NaN;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
988 |
|
989 |
+
if (destination) {
|
990 |
+
if (isTypedArray(destination) || isArrayBuffer(destination)) {
|
991 |
+
throw ngMinErr('cpta', 'Can\'t copy! TypedArray destination cannot be mutated.');
|
992 |
+
}
|
993 |
+
if (source === destination) {
|
994 |
+
throw ngMinErr('cpi', 'Can\'t copy! Source and destination are identical.');
|
995 |
+
}
|
|
|
|
|
|
|
996 |
|
997 |
+
// Empty the destination object
|
998 |
+
if (isArray(destination)) {
|
999 |
+
destination.length = 0;
|
1000 |
+
} else {
|
1001 |
+
forEach(destination, function(value, key) {
|
1002 |
+
if (key !== '$$hashKey') {
|
1003 |
+
delete destination[key];
|
1004 |
}
|
1005 |
+
});
|
1006 |
+
}
|
1007 |
|
1008 |
+
stackSource.push(source);
|
1009 |
+
stackDest.push(destination);
|
1010 |
+
return copyRecurse(source, destination, maxDepth);
|
1011 |
+
}
|
1012 |
|
1013 |
+
return copyElement(source, maxDepth);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1014 |
|
1015 |
+
function copyRecurse(source, destination, maxDepth) {
|
1016 |
+
maxDepth--;
|
1017 |
+
if (maxDepth < 0) {
|
1018 |
+
return '...';
|
1019 |
+
}
|
1020 |
+
var h = destination.$$hashKey;
|
1021 |
+
var key;
|
1022 |
+
if (isArray(source)) {
|
1023 |
+
for (var i = 0, ii = source.length; i < ii; i++) {
|
1024 |
+
destination.push(copyElement(source[i], maxDepth));
|
1025 |
+
}
|
1026 |
+
} else if (isBlankObject(source)) {
|
1027 |
+
// createMap() fast path --- Safe to avoid hasOwnProperty check because prototype chain is empty
|
1028 |
+
for (key in source) {
|
1029 |
+
destination[key] = copyElement(source[key], maxDepth);
|
1030 |
+
}
|
1031 |
+
} else if (source && typeof source.hasOwnProperty === 'function') {
|
1032 |
+
// Slow path, which must rely on hasOwnProperty
|
1033 |
+
for (key in source) {
|
1034 |
+
if (source.hasOwnProperty(key)) {
|
1035 |
+
destination[key] = copyElement(source[key], maxDepth);
|
1036 |
+
}
|
1037 |
+
}
|
1038 |
+
} else {
|
1039 |
+
// Slowest path --- hasOwnProperty can't be called as a method
|
1040 |
+
for (key in source) {
|
1041 |
+
if (hasOwnProperty.call(source, key)) {
|
1042 |
+
destination[key] = copyElement(source[key], maxDepth);
|
1043 |
+
}
|
1044 |
+
}
|
1045 |
+
}
|
1046 |
+
setHashKey(destination, h);
|
1047 |
+
return destination;
|
1048 |
+
}
|
1049 |
|
1050 |
+
function copyElement(source, maxDepth) {
|
1051 |
+
// Simple values
|
1052 |
+
if (!isObject(source)) {
|
1053 |
+
return source;
|
1054 |
+
}
|
1055 |
|
1056 |
+
// Already copied values
|
1057 |
+
var index = stackSource.indexOf(source);
|
1058 |
+
if (index !== -1) {
|
1059 |
+
return stackDest[index];
|
1060 |
+
}
|
1061 |
|
1062 |
+
if (isWindow(source) || isScope(source)) {
|
1063 |
+
throw ngMinErr('cpws',
|
1064 |
+
'Can\'t copy! Making copies of Window or Scope instances is not supported.');
|
1065 |
+
}
|
1066 |
|
1067 |
+
var needsRecurse = false;
|
1068 |
+
var destination = copyType(source);
|
|
|
|
|
1069 |
|
1070 |
+
if (destination === undefined) {
|
1071 |
+
destination = isArray(source) ? [] : Object.create(getPrototypeOf(source));
|
1072 |
+
needsRecurse = true;
|
1073 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1074 |
|
1075 |
+
stackSource.push(source);
|
1076 |
+
stackDest.push(destination);
|
|
|
|
|
|
|
1077 |
|
1078 |
+
return needsRecurse
|
1079 |
+
? copyRecurse(source, destination, maxDepth)
|
1080 |
+
: destination;
|
1081 |
+
}
|
1082 |
|
1083 |
+
function copyType(source) {
|
1084 |
+
switch (toString.call(source)) {
|
1085 |
+
case '[object Int8Array]':
|
1086 |
+
case '[object Int16Array]':
|
1087 |
+
case '[object Int32Array]':
|
1088 |
+
case '[object Float32Array]':
|
1089 |
+
case '[object Float64Array]':
|
1090 |
+
case '[object Uint8Array]':
|
1091 |
+
case '[object Uint8ClampedArray]':
|
1092 |
+
case '[object Uint16Array]':
|
1093 |
+
case '[object Uint32Array]':
|
1094 |
+
return new source.constructor(copyElement(source.buffer), source.byteOffset, source.length);
|
1095 |
|
1096 |
+
case '[object ArrayBuffer]':
|
1097 |
+
// Support: IE10
|
1098 |
+
if (!source.slice) {
|
1099 |
+
// If we're in this case we know the environment supports ArrayBuffer
|
1100 |
+
/* eslint-disable no-undef */
|
1101 |
+
var copied = new ArrayBuffer(source.byteLength);
|
1102 |
+
new Uint8Array(copied).set(new Uint8Array(source));
|
1103 |
+
/* eslint-enable */
|
1104 |
+
return copied;
|
1105 |
}
|
1106 |
+
return source.slice(0);
|
1107 |
+
|
1108 |
+
case '[object Boolean]':
|
1109 |
+
case '[object Number]':
|
1110 |
+
case '[object String]':
|
1111 |
+
case '[object Date]':
|
1112 |
+
return new source.constructor(source.valueOf());
|
1113 |
+
|
1114 |
+
case '[object RegExp]':
|
1115 |
+
var re = new RegExp(source.source, source.toString().match(/[^/]*$/)[0]);
|
1116 |
+
re.lastIndex = source.lastIndex;
|
1117 |
+
return re;
|
1118 |
+
|
1119 |
+
case '[object Blob]':
|
1120 |
+
return new source.constructor([source], {type: source.type});
|
1121 |
+
}
|
1122 |
+
|
1123 |
+
if (isFunction(source.cloneNode)) {
|
1124 |
+
return source.cloneNode(true);
|
1125 |
}
|
1126 |
+
}
|
1127 |
+
}
|
1128 |
|
1129 |
|
1130 |
// eslint-disable-next-line no-self-compare
|
1131 |
+
function simpleCompare(a, b) { return a === b || (a !== a && b !== b); }
|
1132 |
|
1133 |
|
1134 |
+
/**
|
1135 |
+
* @ngdoc function
|
1136 |
+
* @name angular.equals
|
1137 |
+
* @module ng
|
1138 |
+
* @kind function
|
1139 |
+
*
|
1140 |
+
* @description
|
1141 |
+
* Determines if two objects or two values are equivalent. Supports value types, regular
|
1142 |
+
* expressions, arrays and objects.
|
1143 |
+
*
|
1144 |
+
* Two objects or values are considered equivalent if at least one of the following is true:
|
1145 |
+
*
|
1146 |
+
* * Both objects or values pass `===` comparison.
|
1147 |
+
* * Both objects or values are of the same type and all of their properties are equal by
|
1148 |
+
* comparing them with `angular.equals`.
|
1149 |
+
* * Both values are NaN. (In JavaScript, NaN == NaN => false. But we consider two NaN as equal)
|
1150 |
+
* * Both values represent the same regular expression (In JavaScript,
|
1151 |
+
* /abc/ == /abc/ => false. But we consider two regular expressions as equal when their textual
|
1152 |
+
* representation matches).
|
1153 |
+
*
|
1154 |
+
* During a property comparison, properties of `function` type and properties with names
|
1155 |
+
* that begin with `$` are ignored.
|
1156 |
+
*
|
1157 |
+
* Scope and DOMWindow objects are being compared only by identify (`===`).
|
1158 |
+
*
|
1159 |
+
* @param {*} o1 Object or value to compare.
|
1160 |
+
* @param {*} o2 Object or value to compare.
|
1161 |
+
* @returns {boolean} True if arguments are equal.
|
1162 |
+
*
|
1163 |
+
* @example
|
1164 |
+
<example module="equalsExample" name="equalsExample">
|
1165 |
<file name="index.html">
|
1166 |
+
<div ng-controller="ExampleController">
|
1167 |
+
<form novalidate>
|
1168 |
+
<h3>User 1</h3>
|
1169 |
+
Name: <input type="text" ng-model="user1.name">
|
1170 |
+
Age: <input type="number" ng-model="user1.age">
|
1171 |
+
|
1172 |
+
<h3>User 2</h3>
|
1173 |
+
Name: <input type="text" ng-model="user2.name">
|
1174 |
+
Age: <input type="number" ng-model="user2.age">
|
1175 |
+
|
1176 |
+
<div>
|
1177 |
+
<br/>
|
1178 |
+
<input type="button" value="Compare" ng-click="compare()">
|
1179 |
+
</div>
|
1180 |
+
User 1: <pre>{{user1 | json}}</pre>
|
1181 |
+
User 2: <pre>{{user2 | json}}</pre>
|
1182 |
+
Equal: <pre>{{result}}</pre>
|
1183 |
+
</form>
|
1184 |
+
</div>
|
1185 |
+
</file>
|
1186 |
+
<file name="script.js">
|
1187 |
+
angular.module('equalsExample', []).controller('ExampleController', ['$scope', function($scope) {
|
1188 |
$scope.user1 = {};
|
1189 |
$scope.user2 = {};
|
1190 |
$scope.compare = function() {
|
1191 |
$scope.result = angular.equals($scope.user1, $scope.user2);
|
1192 |
};
|
1193 |
}]);
|
1194 |
+
</file>
|
1195 |
+
</example>
|
1196 |
+
*/
|
1197 |
+
function equals(o1, o2) {
|
1198 |
+
if (o1 === o2) return true;
|
1199 |
+
if (o1 === null || o2 === null) return false;
|
1200 |
+
// eslint-disable-next-line no-self-compare
|
1201 |
+
if (o1 !== o1 && o2 !== o2) return true; // NaN === NaN
|
1202 |
+
var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
|
1203 |
+
if (t1 === t2 && t1 === 'object') {
|
1204 |
+
if (isArray(o1)) {
|
1205 |
+
if (!isArray(o2)) return false;
|
1206 |
+
if ((length = o1.length) === o2.length) {
|
1207 |
+
for (key = 0; key < length; key++) {
|
1208 |
+
if (!equals(o1[key], o2[key])) return false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1209 |
}
|
1210 |
+
return true;
|
1211 |
+
}
|
1212 |
+
} else if (isDate(o1)) {
|
1213 |
+
if (!isDate(o2)) return false;
|
1214 |
+
return simpleCompare(o1.getTime(), o2.getTime());
|
1215 |
+
} else if (isRegExp(o1)) {
|
1216 |
+
if (!isRegExp(o2)) return false;
|
1217 |
+
return o1.toString() === o2.toString();
|
1218 |
+
} else {
|
1219 |
+
if (isScope(o1) || isScope(o2) || isWindow(o1) || isWindow(o2) ||
|
1220 |
+
isArray(o2) || isDate(o2) || isRegExp(o2)) return false;
|
1221 |
+
keySet = createMap();
|
1222 |
+
for (key in o1) {
|
1223 |
+
if (key.charAt(0) === '$' || isFunction(o1[key])) continue;
|
1224 |
+
if (!equals(o1[key], o2[key])) return false;
|
1225 |
+
keySet[key] = true;
|
1226 |
+
}
|
1227 |
+
for (key in o2) {
|
1228 |
+
if (!(key in keySet) &&
|
1229 |
+
key.charAt(0) !== '$' &&
|
1230 |
+
isDefined(o2[key]) &&
|
1231 |
+
!isFunction(o2[key])) return false;
|
1232 |
+
}
|
1233 |
+
return true;
|
1234 |
}
|
1235 |
+
}
|
1236 |
+
return false;
|
1237 |
+
}
|
1238 |
|
1239 |
+
var csp = function() {
|
1240 |
+
if (!isDefined(csp.rules)) {
|
1241 |
|
1242 |
|
1243 |
+
var ngCspElement = (window.document.querySelector('[ng-csp]') ||
|
1244 |
+
window.document.querySelector('[data-ng-csp]'));
|
1245 |
|
1246 |
+
if (ngCspElement) {
|
1247 |
+
var ngCspAttribute = ngCspElement.getAttribute('ng-csp') ||
|
1248 |
ngCspElement.getAttribute('data-ng-csp');
|
1249 |
+
csp.rules = {
|
1250 |
+
noUnsafeEval: !ngCspAttribute || (ngCspAttribute.indexOf('no-unsafe-eval') !== -1),
|
1251 |
+
noInlineStyle: !ngCspAttribute || (ngCspAttribute.indexOf('no-inline-style') !== -1)
|
1252 |
+
};
|
1253 |
+
} else {
|
1254 |
+
csp.rules = {
|
1255 |
+
noUnsafeEval: noUnsafeEval(),
|
1256 |
+
noInlineStyle: false
|
1257 |
+
};
|
1258 |
+
}
|
1259 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1260 |
|
1261 |
+
return csp.rules;
|
|
|
1262 |
|
1263 |
+
function noUnsafeEval() {
|
1264 |
+
try {
|
1265 |
+
// eslint-disable-next-line no-new, no-new-func
|
1266 |
+
new Function('');
|
1267 |
+
return false;
|
1268 |
+
} catch (e) {
|
1269 |
+
return true;
|
1270 |
}
|
1271 |
+
}
|
1272 |
+
};
|
1273 |
|
1274 |
+
/**
|
1275 |
+
* @ngdoc directive
|
1276 |
+
* @module ng
|
1277 |
+
* @name ngJq
|
1278 |
+
*
|
1279 |
+
* @element ANY
|
1280 |
+
* @param {string=} ngJq the name of the library available under `window`
|
1281 |
+
* to be used for angular.element
|
1282 |
+
* @description
|
1283 |
+
* Use this directive to force the angular.element library. This should be
|
1284 |
+
* used to force either jqLite by leaving ng-jq blank or setting the name of
|
1285 |
+
* the jquery variable under window (eg. jQuery).
|
1286 |
+
*
|
1287 |
+
* Since AngularJS looks for this directive when it is loaded (doesn't wait for the
|
1288 |
+
* DOMContentLoaded event), it must be placed on an element that comes before the script
|
1289 |
+
* which loads angular. Also, only the first instance of `ng-jq` will be used and all
|
1290 |
+
* others ignored.
|
1291 |
+
*
|
1292 |
+
* @example
|
1293 |
+
* This example shows how to force jqLite using the `ngJq` directive to the `html` tag.
|
1294 |
+
```html
|
1295 |
+
<!doctype html>
|
1296 |
+
<html ng-app ng-jq>
|
1297 |
+
...
|
1298 |
+
...
|
1299 |
+
</html>
|
1300 |
+
```
|
1301 |
+
* @example
|
1302 |
+
* This example shows how to use a jQuery based library of a different name.
|
1303 |
+
* The library name must be available at the top most 'window'.
|
1304 |
+
```html
|
1305 |
+
<!doctype html>
|
1306 |
+
<html ng-app ng-jq="jQueryLib">
|
1307 |
+
...
|
1308 |
+
...
|
1309 |
+
</html>
|
1310 |
+
```
|
1311 |
+
*/
|
1312 |
+
var jq = function() {
|
1313 |
+
if (isDefined(jq.name_)) return jq.name_;
|
1314 |
+
var el;
|
1315 |
+
var i, ii = ngAttrPrefixes.length, prefix, name;
|
1316 |
+
for (i = 0; i < ii; ++i) {
|
1317 |
+
prefix = ngAttrPrefixes[i];
|
1318 |
+
el = window.document.querySelector('[' + prefix.replace(':', '\\:') + 'jq]');
|
1319 |
+
if (el) {
|
1320 |
+
name = el.getAttribute(prefix + 'jq');
|
1321 |
+
break;
|
1322 |
+
}
|
1323 |
+
}
|
1324 |
+
|
1325 |
+
return (jq.name_ = name);
|
1326 |
+
};
|
1327 |
+
|
1328 |
+
function concat(array1, array2, index) {
|
1329 |
+
return array1.concat(slice.call(array2, index));
|
1330 |
+
}
|
1331 |
|
1332 |
+
function sliceArgs(args, startIndex) {
|
1333 |
+
return slice.call(args, startIndex || 0);
|
1334 |
+
}
|
1335 |
|
1336 |
+
|
1337 |
+
/**
|
1338 |
+
* @ngdoc function
|
1339 |
+
* @name angular.bind
|
1340 |
+
* @module ng
|
1341 |
+
* @kind function
|
1342 |
+
*
|
1343 |
+
* @description
|
1344 |
+
* Returns a function which calls function `fn` bound to `self` (`self` becomes the `this` for
|
1345 |
+
* `fn`). You can supply optional `args` that are prebound to the function. This feature is also
|
1346 |
+
* known as [partial application](http://en.wikipedia.org/wiki/Partial_application), as
|
1347 |
+
* distinguished from [function currying](http://en.wikipedia.org/wiki/Currying#Contrast_with_partial_function_application).
|
1348 |
+
*
|
1349 |
+
* @param {Object} self Context which `fn` should be evaluated in.
|
1350 |
+
* @param {function()} fn Function to be bound.
|
1351 |
+
* @param {...*} args Optional arguments to be prebound to the `fn` function call.
|
1352 |
+
* @returns {function()} Function that wraps the `fn` with all the specified bindings.
|
1353 |
+
*/
|
1354 |
+
function bind(self, fn) {
|
1355 |
+
var curryArgs = arguments.length > 2 ? sliceArgs(arguments, 2) : [];
|
1356 |
+
if (isFunction(fn) && !(fn instanceof RegExp)) {
|
1357 |
+
return curryArgs.length
|
1358 |
+
? function() {
|
1359 |
+
return arguments.length
|
1360 |
+
? fn.apply(self, concat(curryArgs, arguments, 0))
|
1361 |
+
: fn.apply(self, curryArgs);
|
1362 |
+
}
|
1363 |
+
: function() {
|
1364 |
+
return arguments.length
|
1365 |
+
? fn.apply(self, arguments)
|
1366 |
+
: fn.call(self);
|
1367 |
+
};
|
1368 |
+
} else {
|
1369 |
+
// In IE, native methods are not functions so they cannot be bound (note: they don't need to be).
|
1370 |
+
return fn;
|
1371 |
+
}
|
1372 |
+
}
|
1373 |
|
1374 |
|
1375 |
+
function toJsonReplacer(key, value) {
|
1376 |
+
var val = value;
|
1377 |
|
1378 |
+
if (typeof key === 'string' && key.charAt(0) === '$' && key.charAt(1) === '$') {
|
1379 |
+
val = undefined;
|
1380 |
+
} else if (isWindow(value)) {
|
1381 |
+
val = '$WINDOW';
|
1382 |
+
} else if (value && window.document === value) {
|
1383 |
+
val = '$DOCUMENT';
|
1384 |
+
} else if (isScope(value)) {
|
1385 |
+
val = '$SCOPE';
|
1386 |
+
}
|
1387 |
|
1388 |
+
return val;
|
1389 |
+
}
|
1390 |
|
1391 |
|
1392 |
+
/**
|
1393 |
+
* @ngdoc function
|
1394 |
+
* @name angular.toJson
|
1395 |
+
* @module ng
|
1396 |
+
* @kind function
|
1397 |
+
*
|
1398 |
+
* @description
|
1399 |
+
* Serializes input into a JSON-formatted string. Properties with leading $$ characters will be
|
1400 |
+
* stripped since AngularJS uses this notation internally.
|
1401 |
+
*
|
1402 |
+
* @param {Object|Array|Date|string|number|boolean} obj Input to be serialized into JSON.
|
1403 |
+
* @param {boolean|number} [pretty=2] If set to true, the JSON output will contain newlines and whitespace.
|
1404 |
+
* If set to an integer, the JSON output will contain that many spaces per indentation.
|
1405 |
+
* @returns {string|undefined} JSON-ified string representing `obj`.
|
1406 |
+
* @knownIssue
|
1407 |
+
*
|
1408 |
+
* The Safari browser throws a `RangeError` instead of returning `null` when it tries to stringify a `Date`
|
1409 |
+
* object with an invalid date value. The only reliable way to prevent this is to monkeypatch the
|
1410 |
+
* `Date.prototype.toJSON` method as follows:
|
1411 |
+
*
|
1412 |
+
* ```
|
1413 |
+
* var _DatetoJSON = Date.prototype.toJSON;
|
1414 |
+
* Date.prototype.toJSON = function() {
|
1415 |
* try {
|
1416 |
* return _DatetoJSON.call(this);
|
1417 |
* } catch(e) {
|
1421 |
* throw e;
|
1422 |
* }
|
1423 |
* };
|
1424 |
+
* ```
|
1425 |
+
*
|
1426 |
+
* See https://github.com/angular/angular.js/pull/14221 for more information.
|
1427 |
+
*/
|
1428 |
+
function toJson(obj, pretty) {
|
1429 |
+
if (isUndefined(obj)) return undefined;
|
1430 |
+
if (!isNumber(pretty)) {
|
1431 |
+
pretty = pretty ? 2 : null;
|
1432 |
+
}
|
1433 |
+
return JSON.stringify(obj, toJsonReplacer, pretty);
|
1434 |
+
}
|
1435 |
|
1436 |
|
1437 |
+
/**
|
1438 |
+
* @ngdoc function
|
1439 |
+
* @name angular.fromJson
|
1440 |
+
* @module ng
|
1441 |
+
* @kind function
|
1442 |
+
*
|
1443 |
+
* @description
|
1444 |
+
* Deserializes a JSON string.
|
1445 |
+
*
|
1446 |
+
* @param {string} json JSON string to deserialize.
|
1447 |
+
* @returns {Object|Array|string|number} Deserialized JSON string.
|
1448 |
+
*/
|
1449 |
+
function fromJson(json) {
|
1450 |
+
return isString(json)
|
1451 |
+
? JSON.parse(json)
|
1452 |
+
: json;
|
1453 |
+
}
|
1454 |
|
1455 |
|
1456 |
+
var ALL_COLONS = /:/g;
|
1457 |
+
function timezoneToOffset(timezone, fallback) {
|
1458 |
+
// Support: IE 9-11 only, Edge 13-15+
|
1459 |
+
// IE/Edge do not "understand" colon (`:`) in timezone
|
1460 |
+
timezone = timezone.replace(ALL_COLONS, '');
|
1461 |
+
var requestedTimezoneOffset = Date.parse('Jan 01, 1970 00:00:00 ' + timezone) / 60000;
|
1462 |
+
return isNumberNaN(requestedTimezoneOffset) ? fallback : requestedTimezoneOffset;
|
1463 |
+
}
|
1464 |
|
1465 |
|
1466 |
+
function addDateMinutes(date, minutes) {
|
1467 |
+
date = new Date(date.getTime());
|
1468 |
+
date.setMinutes(date.getMinutes() + minutes);
|
1469 |
+
return date;
|
1470 |
+
}
|
1471 |
|
1472 |
|
1473 |
+
function convertTimezoneToLocal(date, timezone, reverse) {
|
1474 |
+
reverse = reverse ? -1 : 1;
|
1475 |
+
var dateTimezoneOffset = date.getTimezoneOffset();
|
1476 |
+
var timezoneOffset = timezoneToOffset(timezone, dateTimezoneOffset);
|
1477 |
+
return addDateMinutes(date, reverse * (timezoneOffset - dateTimezoneOffset));
|
1478 |
+
}
|
1479 |
|
1480 |
|
1481 |
+
/**
|
1482 |
+
* @returns {string} Returns the string representation of the element.
|
1483 |
+
*/
|
1484 |
+
function startingTag(element) {
|
1485 |
+
element = jqLite(element).clone().empty();
|
1486 |
+
var elemHtml = jqLite('<div></div>').append(element).html();
|
1487 |
+
try {
|
1488 |
+
return element[0].nodeType === NODE_TYPE_TEXT ? lowercase(elemHtml) :
|
1489 |
+
elemHtml.
|
1490 |
+
match(/^(<[^>]+>)/)[1].
|
1491 |
+
replace(/^<([\w-]+)/, function(match, nodeName) {return '<' + lowercase(nodeName);});
|
1492 |
+
} catch (e) {
|
1493 |
+
return lowercase(elemHtml);
|
1494 |
+
}
|
1495 |
|
1496 |
+
}
|
1497 |
|
1498 |
|
1499 |
/////////////////////////////////////////////////
|
1500 |
|
1501 |
+
/**
|
1502 |
+
* Tries to decode the URI component without throwing an exception.
|
1503 |
+
*
|
1504 |
+
* @private
|
1505 |
+
* @param str value potential URI component to check.
|
1506 |
+
* @returns {boolean} True if `value` can be decoded
|
1507 |
+
* with the decodeURIComponent function.
|
1508 |
+
*/
|
1509 |
+
function tryDecodeURIComponent(value) {
|
1510 |
+
try {
|
1511 |
+
return decodeURIComponent(value);
|
1512 |
+
} catch (e) {
|
1513 |
+
// Ignore any invalid uri component.
|
1514 |
+
}
|
1515 |
+
}
|
1516 |
|
1517 |
|
1518 |
+
/**
|
1519 |
+
* Parses an escaped url query string into key-value pairs.
|
1520 |
+
* @returns {Object.<string,boolean|Array>}
|
1521 |
+
*/
|
1522 |
+
function parseKeyValue(/**string*/keyValue) {
|
1523 |
+
var obj = {};
|
1524 |
+
forEach((keyValue || '').split('&'), function(keyValue) {
|
1525 |
+
var splitPoint, key, val;
|
1526 |
+
if (keyValue) {
|
1527 |
+
key = keyValue = keyValue.replace(/\+/g,'%20');
|
1528 |
+
splitPoint = keyValue.indexOf('=');
|
1529 |
+
if (splitPoint !== -1) {
|
1530 |
+
key = keyValue.substring(0, splitPoint);
|
1531 |
+
val = keyValue.substring(splitPoint + 1);
|
1532 |
+
}
|
1533 |
+
key = tryDecodeURIComponent(key);
|
1534 |
+
if (isDefined(key)) {
|
1535 |
+
val = isDefined(val) ? tryDecodeURIComponent(val) : true;
|
1536 |
+
if (!hasOwnProperty.call(obj, key)) {
|
1537 |
+
obj[key] = val;
|
1538 |
+
} else if (isArray(obj[key])) {
|
1539 |
+
obj[key].push(val);
|
1540 |
+
} else {
|
1541 |
+
obj[key] = [obj[key],val];
|
1542 |
+
}
|
1543 |
+
}
|
|
|
|
|
|
|
1544 |
}
|
1545 |
+
});
|
1546 |
+
return obj;
|
1547 |
+
}
|
1548 |
|
1549 |
+
function toKeyValue(obj) {
|
1550 |
+
var parts = [];
|
1551 |
+
forEach(obj, function(value, key) {
|
1552 |
+
if (isArray(value)) {
|
1553 |
+
forEach(value, function(arrayValue) {
|
1554 |
+
parts.push(encodeUriQuery(key, true) +
|
1555 |
+
(arrayValue === true ? '' : '=' + encodeUriQuery(arrayValue, true)));
|
1556 |
+
});
|
1557 |
+
} else {
|
1558 |
+
parts.push(encodeUriQuery(key, true) +
|
1559 |
+
(value === true ? '' : '=' + encodeUriQuery(value, true)));
|
|
|
|
|
|
|
1560 |
}
|
1561 |
+
});
|
1562 |
+
return parts.length ? parts.join('&') : '';
|
1563 |
+
}
|
1564 |
|
1565 |
|
1566 |
+
/**
|
1567 |
+
* We need our custom method because encodeURIComponent is too aggressive and doesn't follow
|
1568 |
+
* http://www.ietf.org/rfc/rfc3986.txt with regards to the character set (pchar) allowed in path
|
1569 |
+
* segments:
|
1570 |
+
* segment = *pchar
|
1571 |
+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
1572 |
+
* pct-encoded = "%" HEXDIG HEXDIG
|
1573 |
+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
1574 |
+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
1575 |
+
* / "*" / "+" / "," / ";" / "="
|
1576 |
+
*/
|
1577 |
+
function encodeUriSegment(val) {
|
1578 |
+
return encodeUriQuery(val, true).
|
1579 |
+
replace(/%26/gi, '&').
|
1580 |
+
replace(/%3D/gi, '=').
|
1581 |
+
replace(/%2B/gi, '+');
|
1582 |
+
}
|
1583 |
|
1584 |
|
1585 |
+
/**
|
1586 |
+
* This method is intended for encoding *key* or *value* parts of query component. We need a custom
|
1587 |
+
* method because encodeURIComponent is too aggressive and encodes stuff that doesn't have to be
|
1588 |
+
* encoded per http://tools.ietf.org/html/rfc3986:
|
1589 |
+
* query = *( pchar / "/" / "?" )
|
1590 |
+
* pchar = unreserved / pct-encoded / sub-delims / ":" / "@"
|
1591 |
+
* unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~"
|
1592 |
+
* pct-encoded = "%" HEXDIG HEXDIG
|
1593 |
+
* sub-delims = "!" / "$" / "&" / "'" / "(" / ")"
|
1594 |
+
* / "*" / "+" / "," / ";" / "="
|
1595 |
+
*/
|
1596 |
+
function encodeUriQuery(val, pctEncodeSpaces) {
|
1597 |
+
return encodeURIComponent(val).
|
1598 |
+
replace(/%40/gi, '@').
|
1599 |
+
replace(/%3A/gi, ':').
|
1600 |
+
replace(/%24/g, '$').
|
1601 |
+
replace(/%2C/gi, ',').
|
1602 |
+
replace(/%3B/gi, ';').
|
1603 |
+
replace(/%20/g, (pctEncodeSpaces ? '%20' : '+'));
|
1604 |
+
}
|
1605 |
+
|
1606 |
+
var ngAttrPrefixes = ['ng-', 'data-ng-', 'ng:', 'x-ng-'];
|
1607 |
+
|
1608 |
+
function getNgAttribute(element, ngAttr) {
|
1609 |
+
var attr, i, ii = ngAttrPrefixes.length;
|
1610 |
+
for (i = 0; i < ii; ++i) {
|
1611 |
+
attr = ngAttrPrefixes[i] + ngAttr;
|
1612 |
+
if (isString(attr = element.getAttribute(attr))) {
|
1613 |
+
return attr;
|
|
|
|
|
|
|
1614 |
}
|
1615 |
+
}
|
1616 |
+
return null;
|
1617 |
+
}
|
1618 |
|
1619 |
+
function allowAutoBootstrap(document) {
|
1620 |
+
var script = document.currentScript;
|
1621 |
|
1622 |
+
if (!script) {
|
1623 |
+
// Support: IE 9-11 only
|
1624 |
+
// IE does not have `document.currentScript`
|
1625 |
+
return true;
|
1626 |
+
}
|
1627 |
|
1628 |
+
// If the `currentScript` property has been clobbered just return false, since this indicates a probable attack
|
1629 |
+
if (!(script instanceof window.HTMLScriptElement || script instanceof window.SVGScriptElement)) {
|
1630 |
+
return false;
|
1631 |
+
}
|
1632 |
|
1633 |
+
var attributes = script.attributes;
|
1634 |
+
var srcs = [attributes.getNamedItem('src'), attributes.getNamedItem('href'), attributes.getNamedItem('xlink:href')];
|
1635 |
|
1636 |
+
return srcs.every(function(src) {
|
1637 |
+
if (!src) {
|
1638 |
+
return true;
|
1639 |
+
}
|
1640 |
+
if (!src.value) {
|
1641 |
+
return false;
|
1642 |
+
}
|
1643 |
|
1644 |
+
var link = document.createElement('a');
|
1645 |
+
link.href = src.value;
|
1646 |
|
1647 |
+
if (document.location.origin === link.origin) {
|
1648 |
+
// Same-origin resources are always allowed, even for non-whitelisted schemes.
|
1649 |
+
return true;
|
1650 |
+
}
|
1651 |
+
// Disabled bootstrapping unless angular.js was loaded from a known scheme used on the web.
|
1652 |
+
// This is to prevent angular.js bundled with browser extensions from being used to bypass the
|
1653 |
+
// content security policy in web pages and other browser extensions.
|
1654 |
+
switch (link.protocol) {
|
1655 |
+
case 'http:':
|
1656 |
+
case 'https:':
|
1657 |
+
case 'ftp:':
|
1658 |
+
case 'blob:':
|
1659 |
+
case 'file:':
|
1660 |
+
case 'data:':
|
1661 |
+
return true;
|
1662 |
+
default:
|
1663 |
+
return false;
|
|
|
|
|
1664 |
}
|
1665 |
+
});
|
1666 |
+
}
|
1667 |
|
1668 |
// Cached as it has to run during loading so that document.currentScript is available.
|
1669 |
+
var isAutoBootstrapAllowed = allowAutoBootstrap(window.document);
|
1670 |
|
1671 |
+
/**
|
1672 |
+
* @ngdoc directive
|
1673 |
+
* @name ngApp
|
1674 |
+
* @module ng
|
1675 |
+
*
|
1676 |
+
* @element ANY
|
1677 |
+
* @param {angular.Module} ngApp an optional application
|
1678 |
+
* {@link angular.module module} name to load.
|
1679 |
+
* @param {boolean=} ngStrictDi if this attribute is present on the app element, the injector will be
|
1680 |
+
* created in "strict-di" mode. This means that the application will fail to invoke functions which
|
1681 |
+
* do not use explicit function annotation (and are thus unsuitable for minification), as described
|
1682 |
+
* in {@link guide/di the Dependency Injection guide}, and useful debugging info will assist in
|
1683 |
+
* tracking down the root of these bugs.
|
1684 |
+
*
|
1685 |
+
* @description
|
1686 |
+
*
|
1687 |
+
* Use this directive to **auto-bootstrap** an AngularJS application. The `ngApp` directive
|
1688 |
+
* designates the **root element** of the application and is typically placed near the root element
|
1689 |
+
* of the page - e.g. on the `<body>` or `<html>` tags.
|
1690 |
+
*
|
1691 |
+
* There are a few things to keep in mind when using `ngApp`:
|
1692 |
+
* - only one AngularJS application can be auto-bootstrapped per HTML document. The first `ngApp`
|
1693 |
+
* found in the document will be used to define the root element to auto-bootstrap as an
|
1694 |
+
* application. To run multiple applications in an HTML document you must manually bootstrap them using
|
1695 |
+
* {@link angular.bootstrap} instead.
|
1696 |
+
* - AngularJS applications cannot be nested within each other.
|
1697 |
+
* - Do not use a directive that uses {@link ng.$compile#transclusion transclusion} on the same element as `ngApp`.
|
1698 |
+
* This includes directives such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and
|
1699 |
+
* {@link ngRoute.ngView `ngView`}.
|
1700 |
+
* Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
|
1701 |
+
* causing animations to stop working and making the injector inaccessible from outside the app.
|
1702 |
+
*
|
1703 |
+
* You can specify an **AngularJS module** to be used as the root module for the application. This
|
1704 |
+
* module will be loaded into the {@link auto.$injector} when the application is bootstrapped. It
|
1705 |
+
* should contain the application code needed or have dependencies on other modules that will
|
1706 |
+
* contain the code. See {@link angular.module} for more information.
|
1707 |
+
*
|
1708 |
+
* In the example below if the `ngApp` directive were not placed on the `html` element then the
|
1709 |
+
* document would not be compiled, the `AppController` would not be instantiated and the `{{ a+b }}`
|
1710 |
+
* would not be resolved to `3`.
|
1711 |
+
*
|
1712 |
+
* @example
|
1713 |
+
*
|
1714 |
+
* ### Simple Usage
|
1715 |
+
*
|
1716 |
+
* `ngApp` is the easiest, and most common way to bootstrap an application.
|
1717 |
+
*
|
1718 |
+
<example module="ngAppDemo" name="ng-app">
|
1719 |
+
<file name="index.html">
|
1720 |
+
<div ng-controller="ngAppDemoController">
|
1721 |
I can add: {{a}} + {{b}} = {{ a+b }}
|
1722 |
+
</div>
|
1723 |
+
</file>
|
1724 |
+
<file name="script.js">
|
1725 |
+
angular.module('ngAppDemo', []).controller('ngAppDemoController', function($scope) {
|
1726 |
$scope.a = 1;
|
1727 |
$scope.b = 2;
|
1728 |
});
|
1729 |
+
</file>
|
1730 |
+
</example>
|
1731 |
+
*
|
1732 |
+
* @example
|
1733 |
+
*
|
1734 |
+
* ### With `ngStrictDi`
|
1735 |
+
*
|
1736 |
+
* Using `ngStrictDi`, you would see something like this:
|
1737 |
+
*
|
1738 |
+
<example ng-app-included="true" name="strict-di">
|
1739 |
+
<file name="index.html">
|
1740 |
+
<div ng-app="ngAppStrictDemo" ng-strict-di>
|
1741 |
+
<div ng-controller="GoodController1">
|
1742 |
+
I can add: {{a}} + {{b}} = {{ a+b }}
|
1743 |
+
|
1744 |
+
<p>This renders because the controller does not fail to
|
1745 |
+
instantiate, by using explicit annotation style (see
|
1746 |
+
script.js for details)
|
1747 |
+
</p>
|
1748 |
+
</div>
|
1749 |
+
|
1750 |
+
<div ng-controller="GoodController2">
|
1751 |
+
Name: <input ng-model="name"><br />
|
1752 |
+
Hello, {{name}}!
|
1753 |
+
|
1754 |
+
<p>This renders because the controller does not fail to
|
1755 |
+
instantiate, by using explicit annotation style
|
1756 |
+
(see script.js for details)
|
1757 |
+
</p>
|
1758 |
+
</div>
|
1759 |
+
|
1760 |
+
<div ng-controller="BadController">
|
1761 |
+
I can add: {{a}} + {{b}} = {{ a+b }}
|
1762 |
+
|
1763 |
+
<p>The controller could not be instantiated, due to relying
|
1764 |
+
on automatic function annotations (which are disabled in
|
1765 |
+
strict mode). As such, the content of this section is not
|
1766 |
+
interpolated, and there should be an error in your web console.
|
1767 |
+
</p>
|
1768 |
+
</div>
|
1769 |
+
</div>
|
1770 |
+
</file>
|
1771 |
+
<file name="script.js">
|
1772 |
+
angular.module('ngAppStrictDemo', [])
|
1773 |
// BadController will fail to instantiate, due to relying on automatic function annotation,
|
1774 |
// rather than an explicit annotation
|
1775 |
.controller('BadController', function($scope) {
|
1787 |
$scope.name = 'World';
|
1788 |
}
|
1789 |
GoodController2.$inject = ['$scope'];
|
1790 |
+
</file>
|
1791 |
+
<file name="style.css">
|
1792 |
+
div[ng-controller] {
|
1793 |
margin-bottom: 1em;
|
1794 |
-webkit-border-radius: 4px;
|
1795 |
border-radius: 4px;
|
1796 |
border: 1px solid;
|
1797 |
padding: .5em;
|
1798 |
}
|
1799 |
+
div[ng-controller^=Good] {
|
1800 |
border-color: #d6e9c6;
|
1801 |
background-color: #dff0d8;
|
1802 |
color: #3c763d;
|
1803 |
}
|
1804 |
+
div[ng-controller^=Bad] {
|
1805 |
border-color: #ebccd1;
|
1806 |
background-color: #f2dede;
|
1807 |
color: #a94442;
|
1808 |
margin-bottom: 0;
|
1809 |
}
|
1810 |
+
</file>
|
1811 |
+
</example>
|
1812 |
+
*/
|
1813 |
+
function angularInit(element, bootstrap) {
|
1814 |
+
var appElement,
|
1815 |
+
module,
|
1816 |
+
config = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1817 |
|
1818 |
+
// The element `element` has priority over any other element.
|
1819 |
+
forEach(ngAttrPrefixes, function(prefix) {
|
1820 |
+
var name = prefix + 'app';
|
1821 |
+
|
1822 |
+
if (!appElement && element.hasAttribute && element.hasAttribute(name)) {
|
1823 |
+
appElement = element;
|
1824 |
+
module = element.getAttribute(name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1825 |
}
|
1826 |
+
});
|
1827 |
+
forEach(ngAttrPrefixes, function(prefix) {
|
1828 |
+
var name = prefix + 'app';
|
1829 |
+
var candidate;
|
1830 |
|
1831 |
+
if (!appElement && (candidate = element.querySelector('[' + name.replace(':', '\\:') + ']'))) {
|
1832 |
+
appElement = candidate;
|
1833 |
+
module = candidate.getAttribute(name);
|
1834 |
+
}
|
1835 |
+
});
|
1836 |
+
if (appElement) {
|
1837 |
+
if (!isAutoBootstrapAllowed) {
|
1838 |
+
window.console.error('AngularJS: disabling automatic bootstrap. <script> protocol indicates ' +
|
1839 |
+
'an extension, document.location.href does not match.');
|
1840 |
+
return;
|
1841 |
+
}
|
1842 |
+
config.strictDi = getNgAttribute(appElement, 'strict-di') !== null;
|
1843 |
+
bootstrap(appElement, module ? [module] : [], config);
|
1844 |
+
}
|
1845 |
+
}
|
1846 |
+
|
1847 |
+
/**
|
1848 |
+
* @ngdoc function
|
1849 |
+
* @name angular.bootstrap
|
1850 |
+
* @module ng
|
1851 |
+
* @description
|
1852 |
+
* Use this function to manually start up AngularJS application.
|
1853 |
+
*
|
1854 |
+
* For more information, see the {@link guide/bootstrap Bootstrap guide}.
|
1855 |
+
*
|
1856 |
+
* AngularJS will detect if it has been loaded into the browser more than once and only allow the
|
1857 |
+
* first loaded script to be bootstrapped and will report a warning to the browser console for
|
1858 |
+
* each of the subsequent scripts. This prevents strange results in applications, where otherwise
|
1859 |
+
* multiple instances of AngularJS try to work on the DOM.
|
1860 |
+
*
|
1861 |
+
* <div class="alert alert-warning">
|
1862 |
+
* **Note:** Protractor based end-to-end tests cannot use this function to bootstrap manually.
|
1863 |
+
* They must use {@link ng.directive:ngApp ngApp}.
|
1864 |
+
* </div>
|
1865 |
+
*
|
1866 |
+
* <div class="alert alert-warning">
|
1867 |
+
* **Note:** Do not bootstrap the app on an element with a directive that uses {@link ng.$compile#transclusion transclusion},
|
1868 |
+
* such as {@link ng.ngIf `ngIf`}, {@link ng.ngInclude `ngInclude`} and {@link ngRoute.ngView `ngView`}.
|
1869 |
+
* Doing this misplaces the app {@link ng.$rootElement `$rootElement`} and the app's {@link auto.$injector injector},
|
1870 |
+
* causing animations to stop working and making the injector inaccessible from outside the app.
|
1871 |
+
* </div>
|
1872 |
+
*
|
1873 |
+
* ```html
|
1874 |
+
* <!doctype html>
|
1875 |
+
* <html>
|
1876 |
+
* <body>
|
1877 |
+
* <div ng-controller="WelcomeController">
|
1878 |
+
* {{greeting}}
|
1879 |
+
* </div>
|
1880 |
+
*
|
1881 |
+
* <script src="angular.js"></script>
|
1882 |
+
* <script>
|
1883 |
+
* var app = angular.module('demo', [])
|
1884 |
+
* .controller('WelcomeController', function($scope) {
|
1885 |
* $scope.greeting = 'Welcome!';
|
1886 |
* });
|
1887 |
+
* angular.bootstrap(document, ['demo']);
|
1888 |
+
* </script>
|
1889 |
+
* </body>
|
1890 |
+
* </html>
|
1891 |
+
* ```
|
1892 |
+
*
|
1893 |
+
* @param {DOMElement} element DOM element which is the root of AngularJS application.
|
1894 |
+
* @param {Array<String|Function|Array>=} modules an array of modules to load into the application.
|
1895 |
+
* Each item in the array should be the name of a predefined module or a (DI annotated)
|
1896 |
+
* function that will be invoked by the injector as a `config` block.
|
1897 |
+
* See: {@link angular.module modules}
|
1898 |
+
* @param {Object=} config an object for defining configuration options for the application. The
|
1899 |
+
* following keys are supported:
|
1900 |
+
*
|
1901 |
+
* * `strictDi` - disable automatic function annotation for the application. This is meant to
|
1902 |
+
* assist in finding bugs which break minified code. Defaults to `false`.
|
1903 |
+
*
|
1904 |
+
* @returns {auto.$injector} Returns the newly created injector for this app.
|
1905 |
+
*/
|
1906 |
+
function bootstrap(element, modules, config) {
|
1907 |
+
if (!isObject(config)) config = {};
|
1908 |
+
var defaultConfig = {
|
1909 |
+
strictDi: false
|
1910 |
+
};
|
1911 |
+
config = extend(defaultConfig, config);
|
1912 |
+
var doBootstrap = function() {
|
1913 |
+
element = jqLite(element);
|
1914 |
+
|
1915 |
+
if (element.injector()) {
|
1916 |
+
var tag = (element[0] === window.document) ? 'document' : startingTag(element);
|
1917 |
+
// Encode angle brackets to prevent input from being sanitized to empty string #8683.
|
1918 |
+
throw ngMinErr(
|
1919 |
+
'btstrpd',
|
1920 |
+
'App already bootstrapped with this element \'{0}\'',
|
1921 |
+
tag.replace(/</,'<').replace(/>/,'>'));
|
1922 |
+
}
|
1923 |
+
|
1924 |
+
modules = modules || [];
|
1925 |
+
modules.unshift(['$provide', function($provide) {
|
1926 |
+
$provide.value('$rootElement', element);
|
1927 |
+
}]);
|
1928 |
|
1929 |
+
if (config.debugInfoEnabled) {
|
1930 |
+
// Pushing so that this overrides `debugInfoEnabled` setting defined in user's `modules`.
|
1931 |
+
modules.push(['$compileProvider', function($compileProvider) {
|
1932 |
+
$compileProvider.debugInfoEnabled(true);
|
1933 |
+
}]);
|
1934 |
+
}
|
1935 |
|
1936 |
+
modules.unshift('ng');
|
1937 |
+
var injector = createInjector(modules, config.strictDi);
|
1938 |
+
injector.invoke(['$rootScope', '$rootElement', '$compile', '$injector',
|
1939 |
+
function bootstrapApply(scope, element, compile, injector) {
|
1940 |
+
scope.$apply(function() {
|
1941 |
+
element.data('$injector', injector);
|
1942 |
+
compile(element)(scope);
|
1943 |
+
});
|
1944 |
+
}]
|
1945 |
+
);
|
1946 |
+
return injector;
|
1947 |
+
};
|
1948 |
|
1949 |
+
var NG_ENABLE_DEBUG_INFO = /^NG_ENABLE_DEBUG_INFO!/;
|
1950 |
+
var NG_DEFER_BOOTSTRAP = /^NG_DEFER_BOOTSTRAP!/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1951 |
|
1952 |
+
if (window && NG_ENABLE_DEBUG_INFO.test(window.name)) {
|
1953 |
+
config.debugInfoEnabled = true;
|
1954 |
+
window.name = window.name.replace(NG_ENABLE_DEBUG_INFO, '');
|
1955 |
+
}
|
1956 |
|
1957 |
+
if (window && !NG_DEFER_BOOTSTRAP.test(window.name)) {
|
1958 |
+
return doBootstrap();
|
1959 |
+
}
|
|
|
1960 |
|
1961 |
+
window.name = window.name.replace(NG_DEFER_BOOTSTRAP, '');
|
1962 |
+
angular.resumeBootstrap = function(extraModules) {
|
1963 |
+
forEach(extraModules, function(module) {
|
1964 |
+
modules.push(module);
|
1965 |
+
});
|
1966 |
+
return doBootstrap();
|
1967 |
+
};
|
1968 |
|
1969 |
+
if (isFunction(angular.resumeDeferredBootstrap)) {
|
1970 |
+
angular.resumeDeferredBootstrap();
|
1971 |
+
}
|
1972 |
+
}
|
|
|
|
|
|
|
1973 |
|
1974 |
+
/**
|
1975 |
+
* @ngdoc function
|
1976 |
+
* @name angular.reloadWithDebugInfo
|
1977 |
+
* @module ng
|
1978 |
+
* @description
|
1979 |
+
* Use this function to reload the current application with debug information turned on.
|
1980 |
+
* This takes precedence over a call to `$compileProvider.debugInfoEnabled(false)`.
|
1981 |
+
*
|
1982 |
+
* See {@link ng.$compileProvider#debugInfoEnabled} for more.
|
1983 |
+
*/
|
1984 |
+
function reloadWithDebugInfo() {
|
1985 |
+
window.name = 'NG_ENABLE_DEBUG_INFO!' + window.name;
|
1986 |
+
window.location.reload();
|
1987 |
+
}
|
1988 |
|
1989 |
+
/**
|
1990 |
+
* @name angular.getTestability
|
1991 |
+
* @module ng
|
1992 |
+
* @description
|
1993 |
+
* Get the testability service for the instance of AngularJS on the given
|
1994 |
+
* element.
|
1995 |
+
* @param {DOMElement} element DOM element which is the root of AngularJS application.
|
1996 |
+
*/
|
1997 |
+
function getTestability(rootElement) {
|
1998 |
+
var injector = angular.element(rootElement).injector();
|
1999 |
+
if (!injector) {
|
2000 |
+
throw ngMinErr('test',
|
2001 |
+
'no injector found for element argument to getTestability');
|
2002 |
+
}
|
2003 |
+
return injector.get('$$testability');
|
2004 |
+
}
|
2005 |
|
2006 |
+
var SNAKE_CASE_REGEXP = /[A-Z]/g;
|
2007 |
+
function snake_case(name, separator) {
|
2008 |
+
separator = separator || '_';
|
2009 |
+
return name.replace(SNAKE_CASE_REGEXP, function(letter, pos) {
|
2010 |
+
return (pos ? separator : '') + letter.toLowerCase();
|
2011 |
+
});
|
2012 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013 |
|
2014 |
+
var bindJQueryFired = false;
|
2015 |
+
function bindJQuery() {
|
2016 |
+
var originalCleanData;
|
2017 |
+
|
2018 |
+
if (bindJQueryFired) {
|
2019 |
+
return;
|
2020 |
+
}
|
2021 |
+
|
2022 |
+
// bind to jQuery if present;
|
2023 |
+
var jqName = jq();
|
2024 |
+
jQuery = isUndefined(jqName) ? window.jQuery : // use jQuery (if present)
|
2025 |
+
!jqName ? undefined : // use jqLite
|
2026 |
+
window[jqName]; // use jQuery specified by `ngJq`
|
2027 |
+
|
2028 |
+
// Use jQuery if it exists with proper functionality, otherwise default to us.
|
2029 |
+
// AngularJS 1.2+ requires jQuery 1.7+ for on()/off() support.
|
2030 |
+
// AngularJS 1.3+ technically requires at least jQuery 2.1+ but it may work with older
|
2031 |
+
// versions. It will not work for sure with jQuery <1.7, though.
|
2032 |
+
if (jQuery && jQuery.fn.on) {
|
2033 |
+
jqLite = jQuery;
|
2034 |
+
extend(jQuery.fn, {
|
2035 |
+
scope: JQLitePrototype.scope,
|
2036 |
+
isolateScope: JQLitePrototype.isolateScope,
|
2037 |
+
controller: /** @type {?} */ (JQLitePrototype).controller,
|
2038 |
+
injector: JQLitePrototype.injector,
|
2039 |
+
inheritedData: JQLitePrototype.inheritedData
|
2040 |
+
});
|
2041 |
+
} else {
|
2042 |
+
jqLite = JQLite;
|
2043 |
+
}
|
2044 |
+
|
2045 |
+
// All nodes removed from the DOM via various jqLite/jQuery APIs like .remove()
|
2046 |
+
// are passed through jqLite/jQuery.cleanData. Monkey-patch this method to fire
|
2047 |
+
// the $destroy event on all removed nodes.
|
2048 |
+
originalCleanData = jqLite.cleanData;
|
2049 |
+
jqLite.cleanData = function(elems) {
|
2050 |
+
var events;
|
2051 |
+
for (var i = 0, elem; (elem = elems[i]) != null; i++) {
|
2052 |
+
events = (jqLite._data(elem) || {}).events;
|
2053 |
+
if (events && events.$destroy) {
|
2054 |
+
jqLite(elem).triggerHandler('$destroy');
|
2055 |
+
}
|
2056 |
}
|
2057 |
+
originalCleanData(elems);
|
2058 |
+
};
|
2059 |
|
2060 |
+
angular.element = jqLite;
|
|
|
|
|
2061 |
|
2062 |
+
// Prevent double-proxying.
|
2063 |
+
bindJQueryFired = true;
|
2064 |
+
}
|
2065 |
|
2066 |
+
/**
|
2067 |
+
* throw error if the argument is falsy.
|
2068 |
+
*/
|
2069 |
+
function assertArg(arg, name, reason) {
|
2070 |
+
if (!arg) {
|
2071 |
+
throw ngMinErr('areq', 'Argument \'{0}\' is {1}', (name || '?'), (reason || 'required'));
|
2072 |
+
}
|
2073 |
+
return arg;
|
2074 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2075 |
|
2076 |
+
function assertArgFn(arg, name, acceptArrayAnnotation) {
|
2077 |
+
if (acceptArrayAnnotation && isArray(arg)) {
|
2078 |
+
arg = arg[arg.length - 1];
|
2079 |
+
}
|
2080 |
|
2081 |
+
assertArg(isFunction(arg), name, 'not a function, got ' +
|
2082 |
+
(arg && typeof arg === 'object' ? arg.constructor.name || 'Object' : typeof arg));
|
2083 |
+
return arg;
|
2084 |
+
}
|
2085 |
|
2086 |
+
/**
|
2087 |
+
* throw error if the name given is hasOwnProperty
|
2088 |
+
* @param {String} name the name to test
|
2089 |
+
* @param {String} context the context in which the name is used, such as module or directive
|
2090 |
+
*/
|
2091 |
+
function assertNotHasOwnProperty(name, context) {
|
2092 |
+
if (name === 'hasOwnProperty') {
|
2093 |
+
throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
|
2094 |
+
}
|
2095 |
+
}
|
2096 |
|
2097 |
+
/**
|
2098 |
+
* Return the value accessible from the object by path. Any undefined traversals are ignored
|
2099 |
+
* @param {Object} obj starting object
|
2100 |
+
* @param {String} path path to traverse
|
2101 |
+
* @param {boolean} [bindFnToScope=true]
|
2102 |
+
* @returns {Object} value as accessible by path
|
2103 |
+
*/
|
2104 |
+
//TODO(misko): this function needs to be removed
|
2105 |
+
function getter(obj, path, bindFnToScope) {
|
2106 |
+
if (!path) return obj;
|
2107 |
+
var keys = path.split('.');
|
2108 |
+
var key;
|
2109 |
+
var lastInstance = obj;
|
2110 |
+
var len = keys.length;
|
2111 |
+
|
2112 |
+
for (var i = 0; i < len; i++) {
|
2113 |
+
key = keys[i];
|
2114 |
+
if (obj) {
|
2115 |
+
obj = (lastInstance = obj)[key];
|
2116 |
+
}
|
2117 |
+
}
|
2118 |
+
if (!bindFnToScope && isFunction(obj)) {
|
2119 |
+
return bind(lastInstance, obj);
|
2120 |
+
}
|
2121 |
+
return obj;
|
2122 |
+
}
|
2123 |
|
2124 |
+
/**
|
2125 |
+
* Return the DOM siblings between the first and last node in the given array.
|
2126 |
+
* @param {Array} array like object
|
2127 |
+
* @returns {Array} the inputted object or a jqLite collection containing the nodes
|
2128 |
+
*/
|
2129 |
+
function getBlockNodes(nodes) {
|
2130 |
+
// TODO(perf): update `nodes` instead of creating a new object?
|
2131 |
+
var node = nodes[0];
|
2132 |
+
var endNode = nodes[nodes.length - 1];
|
2133 |
+
var blockNodes;
|
2134 |
+
|
2135 |
+
for (var i = 1; node !== endNode && (node = node.nextSibling); i++) {
|
2136 |
+
if (blockNodes || nodes[i] !== node) {
|
2137 |
+
if (!blockNodes) {
|
2138 |
+
blockNodes = jqLite(slice.call(nodes, 0, i));
|
2139 |
+
}
|
2140 |
+
blockNodes.push(node);
|
2141 |
}
|
2142 |
+
}
|
2143 |
|
2144 |
+
return blockNodes || nodes;
|
2145 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2147 |
|
2148 |
+
/**
|
2149 |
+
* Creates a new object without a prototype. This object is useful for lookup without having to
|
2150 |
+
* guard against prototypically inherited properties via hasOwnProperty.
|
2151 |
+
*
|
2152 |
+
* Related micro-benchmarks:
|
2153 |
+
* - http://jsperf.com/object-create2
|
2154 |
+
* - http://jsperf.com/proto-map-lookup/2
|
2155 |
+
* - http://jsperf.com/for-in-vs-object-keys2
|
2156 |
+
*
|
2157 |
+
* @returns {Object}
|
2158 |
+
*/
|
2159 |
+
function createMap() {
|
2160 |
+
return Object.create(null);
|
2161 |
+
}
|
|
|
|
|
|
|
|
|
|
|
2162 |
|
2163 |
+
function stringify(value) {
|
2164 |
+
if (value == null) { // null || undefined
|
2165 |
+
return '';
|
2166 |
+
}
|
2167 |
+
switch (typeof value) {
|
2168 |
+
case 'string':
|
2169 |
+
break;
|
2170 |
+
case 'number':
|
2171 |
+
value = '' + value;
|
2172 |
+
break;
|
2173 |
+
default:
|
2174 |
+
if (hasCustomToString(value) && !isArray(value) && !isDate(value)) {
|
2175 |
+
value = value.toString();
|
2176 |
+
} else {
|
2177 |
+
value = toJson(value);
|
2178 |
+
}
|
2179 |
+
}
|
2180 |
|
2181 |
+
return value;
|
2182 |
+
}
|
2183 |
|
2184 |
+
var NODE_TYPE_ELEMENT = 1;
|
2185 |
+
var NODE_TYPE_ATTRIBUTE = 2;
|
2186 |
+
var NODE_TYPE_TEXT = 3;
|
2187 |
+
var NODE_TYPE_COMMENT = 8;
|
2188 |
+
var NODE_TYPE_DOCUMENT = 9;
|
2189 |
+
var NODE_TYPE_DOCUMENT_FRAGMENT = 11;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2190 |
|
2191 |
+
/**
|
2192 |
+
* @ngdoc type
|
2193 |
+
* @name angular.Module
|
2194 |
+
* @module ng
|
2195 |
+
* @description
|
2196 |
+
*
|
2197 |
+
* Interface for configuring AngularJS {@link angular.module modules}.
|
2198 |
+
*/
|
2199 |
+
|
2200 |
+
function setupModuleLoader(window) {
|
2201 |
+
|
2202 |
+
var $injectorMinErr = minErr('$injector');
|
2203 |
+
var ngMinErr = minErr('ng');
|
2204 |
+
|
2205 |
+
function ensure(obj, name, factory) {
|
2206 |
+
return obj[name] || (obj[name] = factory());
|
2207 |
+
}
|
2208 |
|
2209 |
+
var angular = ensure(window, 'angular', Object);
|
2210 |
+
|
2211 |
+
// We need to expose `angular.$$minErr` to modules such as `ngResource` that reference it during bootstrap
|
2212 |
+
angular.$$minErr = angular.$$minErr || minErr;
|
2213 |
+
|
2214 |
+
return ensure(angular, 'module', function() {
|
2215 |
+
/** @type {Object.<string, angular.Module>} */
|
2216 |
+
var modules = {};
|
2217 |
|
2218 |
/**
|
2219 |
+
* @ngdoc function
|
2220 |
+
* @name angular.module
|
2221 |
* @module ng
|
2222 |
* @description
|
2223 |
*
|
2224 |
+
* The `angular.module` is a global place for creating, registering and retrieving AngularJS
|
2225 |
+
* modules.
|
2226 |
+
* All modules (AngularJS core or 3rd party) that should be available to an application must be
|
2227 |
+
* registered using this mechanism.
|
2228 |
+
*
|
2229 |
+
* Passing one argument retrieves an existing {@link angular.Module},
|
2230 |
+
* whereas passing more than one argument creates a new {@link angular.Module}
|
2231 |
+
*
|
2232 |
+
*
|
2233 |
+
* # Module
|
2234 |
+
*
|
2235 |
+
* A module is a collection of services, directives, controllers, filters, and configuration information.
|
2236 |
+
* `angular.module` is used to configure the {@link auto.$injector $injector}.
|
2237 |
+
*
|
2238 |
+
* ```js
|
2239 |
+
* // Create a new module
|
2240 |
+
* var myModule = angular.module('myModule', []);
|
2241 |
+
*
|
2242 |
+
* // register a new service
|
2243 |
+
* myModule.value('appName', 'MyCoolApp');
|
2244 |
+
*
|
2245 |
+
* // configure existing services inside initialization blocks.
|
2246 |
+
* myModule.config(['$locationProvider', function($locationProvider) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2247 |
* // Configure existing providers
|
2248 |
* $locationProvider.hashPrefix('!');
|
2249 |
* }]);
|
2250 |
+
* ```
|
2251 |
+
*
|
2252 |
+
* Then you can create an injector and load your modules like this:
|
2253 |
+
*
|
2254 |
+
* ```js
|
2255 |
+
* var injector = angular.injector(['ng', 'myModule'])
|
2256 |
+
* ```
|
2257 |
+
*
|
2258 |
+
* However it's more likely that you'll just use
|
2259 |
+
* {@link ng.directive:ngApp ngApp} or
|
2260 |
+
* {@link angular.bootstrap} to simplify this process for you.
|
2261 |
+
*
|
2262 |
+
* @param {!string} name The name of the module to create or retrieve.
|
2263 |
+
* @param {!Array.<string>=} requires If specified then new module is being created. If
|
2264 |
+
* unspecified then the module is being retrieved for further configuration.
|
2265 |
+
* @param {Function=} configFn Optional configuration function for the module. Same as
|
2266 |
+
* {@link angular.Module#config Module#config()}.
|
2267 |
+
* @returns {angular.Module} new module with the {@link angular.Module} api.
|
2268 |
+
*/
|
2269 |
+
return function module(name, requires, configFn) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2270 |
|
2271 |
+
var info = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2272 |
|
2273 |
+
var assertNotHasOwnProperty = function(name, context) {
|
2274 |
+
if (name === 'hasOwnProperty') {
|
2275 |
+
throw ngMinErr('badname', 'hasOwnProperty is not a valid {0} name', context);
|
2276 |
+
}
|
2277 |
+
};
|
2278 |
+
|
2279 |
+
assertNotHasOwnProperty(name, 'module');
|
2280 |
+
if (requires && modules.hasOwnProperty(name)) {
|
2281 |
+
modules[name] = null;
|
2282 |
+
}
|
2283 |
+
return ensure(modules, name, function() {
|
2284 |
+
if (!requires) {
|
2285 |
+
throw $injectorMinErr('nomod', 'Module \'{0}\' is not available! You either misspelled ' +
|
2286 |
+
'the module name or forgot to load it. If registering a module ensure that you ' +
|
2287 |
+
'specify the dependencies as the second argument.', name);
|
2288 |
+
}
|
2289 |
+
|
2290 |
+
/** @type {!Array.<Array.<*>>} */
|
2291 |
+
var invokeQueue = [];
|
2292 |
+
|
2293 |
+
/** @type {!Array.<Function>} */
|
2294 |
+
var configBlocks = [];
|
2295 |
+
|
2296 |
+
/** @type {!Array.<Function>} */
|
2297 |
+
var runBlocks = [];
|
2298 |
+
|
2299 |
+
var config = invokeLater('$injector', 'invoke', 'push', configBlocks);
|
2300 |
+
|
2301 |
+
/** @type {angular.Module} */
|
2302 |
+
var moduleInstance = {
|
2303 |
+
// Private state
|
2304 |
+
_invokeQueue: invokeQueue,
|
2305 |
+
_configBlocks: configBlocks,
|
2306 |
+
_runBlocks: runBlocks,
|
2307 |
+
|
2308 |
+
/**
|
2309 |
+
* @ngdoc method
|
2310 |
+
* @name angular.Module#info
|
2311 |
+
* @module ng
|
2312 |
+
*
|
2313 |
+
* @param {Object=} info Information about the module
|
2314 |
+
* @returns {Object|Module} The current info object for this module if called as a getter,
|
2315 |
+
* or `this` if called as a setter.
|
2316 |
+
*
|
2317 |
+
* @description
|
2318 |
+
* Read and write custom information about this module.
|
2319 |
+
* For example you could put the version of the module in here.
|
2320 |
+
*
|
2321 |
+
* ```js
|
2322 |
+
* angular.module('myModule', []).info({ version: '1.0.0' });
|
2323 |
+
* ```
|
2324 |
+
*
|
2325 |
+
* The version could then be read back out by accessing the module elsewhere:
|
2326 |
+
*
|
2327 |
+
* ```
|
2328 |
+
* var version = angular.module('myModule').info().version;
|
2329 |
+
* ```
|
2330 |
+
*
|
2331 |
+
* You can also retrieve this information during runtime via the
|
2332 |
+
* {@link $injector#modules `$injector.modules`} property:
|
2333 |
+
*
|
2334 |
+
* ```js
|
2335 |
+
* var version = $injector.modules['myModule'].info().version;
|
2336 |
+
* ```
|
2337 |
+
*/
|
2338 |
+
info: function(value) {
|
2339 |
+
if (isDefined(value)) {
|
2340 |
+
if (!isObject(value)) throw ngMinErr('aobj', 'Argument \'{0}\' must be an object', 'value');
|
2341 |
+
info = value;
|
2342 |
+
return this;
|
2343 |
+
}
|
2344 |
+
return info;
|
2345 |
+
},
|
2346 |
+
|
2347 |
+
/**
|
2348 |
+
* @ngdoc property
|
2349 |
+
* @name angular.Module#requires
|
2350 |
+
* @module ng
|
2351 |
+
*
|
2352 |
+
* @description
|
2353 |
+
* Holds the list of modules which the injector will load before the current module is
|
2354 |
+
* loaded.
|
2355 |
+
*/
|
2356 |
+
requires: requires,
|
2357 |
+
|
2358 |
+
/**
|
2359 |
+
* @ngdoc property
|
2360 |
+
* @name angular.Module#name
|
2361 |
+
* @module ng
|
2362 |
+
*
|
2363 |
+
* @description
|
2364 |
+
* Name of the module.
|
2365 |
+
*/
|
2366 |
+
name: name,
|
2367 |
+
|
2368 |
+
|
2369 |
+
/**
|
2370 |
+
* @ngdoc method
|
2371 |
+
* @name angular.Module#provider
|
2372 |
+
* @module ng
|
2373 |
+
* @param {string} name service name
|
2374 |
+
* @param {Function} providerType Construction function for creating new instance of the
|
2375 |
+
* service.
|
2376 |
+
* @description
|
2377 |
+
* See {@link auto.$provide#provider $provide.provider()}.
|
2378 |
+
*/
|
2379 |
+
provider: invokeLaterAndSetModuleName('$provide', 'provider'),
|
2380 |
+
|
2381 |
+
/**
|
2382 |
+
* @ngdoc method
|
2383 |
+
* @name angular.Module#factory
|
2384 |
+
* @module ng
|
2385 |
+
* @param {string} name service name
|
2386 |
+
* @param {Function} providerFunction Function for creating new instance of the service.
|
2387 |
+
* @description
|
2388 |
+
* See {@link auto.$provide#factory $provide.factory()}.
|
2389 |
+
*/
|
2390 |
+
factory: invokeLaterAndSetModuleName('$provide', 'factory'),
|
2391 |
+
|
2392 |
+
/**
|
2393 |
+
* @ngdoc method
|
2394 |
+
* @name angular.Module#service
|
2395 |
+
* @module ng
|
2396 |
+
* @param {string} name service name
|
2397 |
+
* @param {Function} constructor A constructor function that will be instantiated.
|
2398 |
+
* @description
|
2399 |
+
* See {@link auto.$provide#service $provide.service()}.
|
2400 |
+
*/
|
2401 |
+
service: invokeLaterAndSetModuleName('$provide', 'service'),
|
2402 |
+
|
2403 |
+
/**
|
2404 |
+
* @ngdoc method
|
2405 |
+
* @name angular.Module#value
|
2406 |
+
* @module ng
|
2407 |
+
* @param {string} name service name
|
2408 |
+
* @param {*} object Service instance object.
|
2409 |
+
* @description
|
2410 |
+
* See {@link auto.$provide#value $provide.value()}.
|
2411 |
+
*/
|
2412 |
+
value: invokeLater('$provide', 'value'),
|
2413 |
+
|
2414 |
+
/**
|
2415 |
+
* @ngdoc method
|
2416 |
+
* @name angular.Module#constant
|
2417 |
+
* @module ng
|
2418 |
+
* @param {string} name constant name
|
2419 |
+
* @param {*} object Constant value.
|
2420 |
+
* @description
|
2421 |
+
* Because the constants are fixed, they get applied before other provide methods.
|
2422 |
+
* See {@link auto.$provide#constant $provide.constant()}.
|
2423 |
+
*/
|
2424 |
+
constant: invokeLater('$provide', 'constant', 'unshift'),
|
2425 |
+
|
2426 |
+
/**
|
2427 |
+
* @ngdoc method
|
2428 |
+
* @name angular.Module#decorator
|
2429 |
+
* @module ng
|
2430 |
+
* @param {string} name The name of the service to decorate.
|
2431 |
+
* @param {Function} decorFn This function will be invoked when the service needs to be
|
2432 |
+
* instantiated and should return the decorated service instance.
|
2433 |
+
* @description
|
2434 |
+
* See {@link auto.$provide#decorator $provide.decorator()}.
|
2435 |
+
*/
|
2436 |
+
decorator: invokeLaterAndSetModuleName('$provide', 'decorator', configBlocks),
|
2437 |
+
|
2438 |
+
/**
|
2439 |
+
* @ngdoc method
|
2440 |
+
* @name angular.Module#animation
|
2441 |
+
* @module ng
|
2442 |
+
* @param {string} name animation name
|
2443 |
+
* @param {Function} animationFactory Factory function for creating new instance of an
|
2444 |
+
* animation.
|
2445 |
+
* @description
|
2446 |
+
*
|
2447 |
+
* **NOTE**: animations take effect only if the **ngAnimate** module is loaded.
|
2448 |
+
*
|
2449 |
+
*
|
2450 |
+
* Defines an animation hook that can be later used with
|
2451 |
+
* {@link $animate $animate} service and directives that use this service.
|
2452 |
+
*
|
2453 |
+
* ```js
|
2454 |
+
* module.animation('.animation-name', function($inject1, $inject2) {
|
2455 |
* return {
|
2456 |
* eventName : function(element, done) {
|
2457 |
* //code to run the animation
|
2462 |
* }
|
2463 |
* }
|
2464 |
* })
|
2465 |
+
* ```
|
2466 |
+
*
|
2467 |
+
* See {@link ng.$animateProvider#register $animateProvider.register()} and
|
2468 |
+
* {@link ngAnimate ngAnimate module} for more information.
|
2469 |
+
*/
|
2470 |
+
animation: invokeLaterAndSetModuleName('$animateProvider', 'register'),
|
2471 |
+
|
2472 |
+
/**
|
2473 |
+
* @ngdoc method
|
2474 |
+
* @name angular.Module#filter
|
2475 |
+
* @module ng
|
2476 |
+
* @param {string} name Filter name - this must be a valid AngularJS expression identifier
|
2477 |
+
* @param {Function} filterFactory Factory function for creating new instance of filter.
|
2478 |
+
* @description
|
2479 |
+
* See {@link ng.$filterProvider#register $filterProvider.register()}.
|
2480 |
+
*
|
2481 |
+
* <div class="alert alert-warning">
|
2482 |
+
* **Note:** Filter names must be valid AngularJS {@link expression} identifiers, such as `uppercase` or `orderBy`.
|
2483 |
+
* Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
|
2484 |
+
* your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores
|
2485 |
+
* (`myapp_subsection_filterx`).
|
2486 |
+
* </div>
|
2487 |
+
*/
|
2488 |
+
filter: invokeLaterAndSetModuleName('$filterProvider', 'register'),
|
2489 |
+
|
2490 |
+
/**
|
2491 |
+
* @ngdoc method
|
2492 |
+
* @name angular.Module#controller
|
2493 |
+
* @module ng
|
2494 |
+
* @param {string|Object} name Controller name, or an object map of controllers where the
|
2495 |
+
* keys are the names and the values are the constructors.
|
2496 |
+
* @param {Function} constructor Controller constructor function.
|
2497 |
+
* @description
|
2498 |
+
* See {@link ng.$controllerProvider#register $controllerProvider.register()}.
|
2499 |
+
*/
|
2500 |
+
controller: invokeLaterAndSetModuleName('$controllerProvider', 'register'),
|
2501 |
+
|
2502 |
+
/**
|
2503 |
+
* @ngdoc method
|
2504 |
+
* @name angular.Module#directive
|
2505 |
+
* @module ng
|
2506 |
+
* @param {string|Object} name Directive name, or an object map of directives where the
|
2507 |
+
* keys are the names and the values are the factories.
|
2508 |
+
* @param {Function} directiveFactory Factory function for creating new instance of
|
2509 |
+
* directives.
|
2510 |
+
* @description
|
2511 |
+
* See {@link ng.$compileProvider#directive $compileProvider.directive()}.
|
2512 |
+
*/
|
2513 |
+
directive: invokeLaterAndSetModuleName('$compileProvider', 'directive'),
|
2514 |
+
|
2515 |
+
/**
|
2516 |
+
* @ngdoc method
|
2517 |
+
* @name angular.Module#component
|
2518 |
+
* @module ng
|
2519 |
+
* @param {string|Object} name Name of the component in camelCase (i.e. `myComp` which will match `<my-comp>`),
|
2520 |
+
* or an object map of components where the keys are the names and the values are the component definition objects.
|
2521 |
+
* @param {Object} options Component definition object (a simplified
|
2522 |
+
* {@link ng.$compile#directive-definition-object directive definition object})
|
2523 |
+
*
|
2524 |
+
* @description
|
2525 |
+
* See {@link ng.$compileProvider#component $compileProvider.component()}.
|
2526 |
+
*/
|
2527 |
+
component: invokeLaterAndSetModuleName('$compileProvider', 'component'),
|
2528 |
+
|
2529 |
+
/**
|
2530 |
+
* @ngdoc method
|
2531 |
+
* @name angular.Module#config
|
2532 |
+
* @module ng
|
2533 |
+
* @param {Function} configFn Execute this function on module load. Useful for service
|
2534 |
+
* configuration.
|
2535 |
+
* @description
|
2536 |
+
* Use this method to configure services by injecting their
|
2537 |
+
* {@link angular.Module#provider `providers`}, e.g. for adding routes to the
|
2538 |
+
* {@link ngRoute.$routeProvider $routeProvider}.
|
2539 |
+
*
|
2540 |
+
* Note that you can only inject {@link angular.Module#provider `providers`} and
|
2541 |
+
* {@link angular.Module#constant `constants`} into this function.
|
2542 |
+
*
|
2543 |
+
* For more about how to configure services, see
|
2544 |
+
* {@link providers#provider-recipe Provider Recipe}.
|
2545 |
+
*/
|
2546 |
+
config: config,
|
2547 |
+
|
2548 |
+
/**
|
2549 |
+
* @ngdoc method
|
2550 |
+
* @name angular.Module#run
|
2551 |
+
* @module ng
|
2552 |
+
* @param {Function} initializationFn Execute this function after injector creation.
|
2553 |
+
* Useful for application initialization.
|
2554 |
+
* @description
|
2555 |
+
* Use this method to register work which should be performed when the injector is done
|
2556 |
+
* loading all modules.
|
2557 |
+
*/
|
2558 |
+
run: function(block) {
|
2559 |
+
runBlocks.push(block);
|
2560 |
+
return this;
|
2561 |
+
}
|
2562 |
+
};
|
2563 |
|
2564 |
+
if (configFn) {
|
2565 |
+
config(configFn);
|
2566 |
+
}
|
2567 |
|
2568 |
+
return moduleInstance;
|
2569 |
|
2570 |
+
/**
|
2571 |
+
* @param {string} provider
|
2572 |
+
* @param {string} method
|
2573 |
+
* @param {String=} insertMethod
|
2574 |
+
* @returns {angular.Module}
|
2575 |
+
*/
|
2576 |
+
function invokeLater(provider, method, insertMethod, queue) {
|
2577 |
+
if (!queue) queue = invokeQueue;
|
2578 |
+
return function() {
|
2579 |
+
queue[insertMethod || 'push']([provider, method, arguments]);
|
2580 |
+
return moduleInstance;
|
2581 |
+
};
|
2582 |
+
}
|
2583 |
|
2584 |
+
/**
|
2585 |
+
* @param {string} provider
|
2586 |
+
* @param {string} method
|
2587 |
+
* @returns {angular.Module}
|
2588 |
+
*/
|
2589 |
+
function invokeLaterAndSetModuleName(provider, method, queue) {
|
2590 |
+
if (!queue) queue = invokeQueue;
|
2591 |
+
return function(recipeName, factoryFunction) {
|
2592 |
+
if (factoryFunction && isFunction(factoryFunction)) factoryFunction.$$moduleName = name;
|
2593 |
+
queue.push([provider, method, arguments]);
|
2594 |
+
return moduleInstance;
|
2595 |
+
};
|
2596 |
+
}
|
2597 |
+
});
|
2598 |
+
};
|
2599 |
+
});
|
2600 |
|
2601 |
+
}
|
2602 |
|
2603 |
+
/* global shallowCopy: true */
|
2604 |
|
2605 |
+
/**
|
2606 |
+
* Creates a shallow copy of an object, an array or a primitive.
|
2607 |
+
*
|
2608 |
+
* Assumes that there are no proto properties for objects.
|
2609 |
+
*/
|
2610 |
+
function shallowCopy(src, dst) {
|
2611 |
+
if (isArray(src)) {
|
2612 |
+
dst = dst || [];
|
2613 |
|
2614 |
+
for (var i = 0, ii = src.length; i < ii; i++) {
|
2615 |
+
dst[i] = src[i];
|
2616 |
+
}
|
2617 |
+
} else if (isObject(src)) {
|
2618 |
+
dst = dst || {};
|
2619 |
|
2620 |
+
for (var key in src) {
|
2621 |
+
if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
|
2622 |
+
dst[key] = src[key];
|
2623 |
+
}
|
|
|
|
|
|
|
|
|
2624 |
}
|
2625 |
+
}
|
2626 |
|
2627 |
+
return dst || src;
|
2628 |
+
}
|
2629 |
|
2630 |
+
/* exported toDebugString */
|
|
|
2631 |
|
2632 |
+
function serializeObject(obj, maxDepth) {
|
2633 |
+
var seen = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2634 |
|
2635 |
+
// There is no direct way to stringify object until reaching a specific depth
|
2636 |
+
// and a very deep object can cause a performance issue, so we copy the object
|
2637 |
+
// based on this specific depth and then stringify it.
|
2638 |
+
if (isValidObjectMaxDepth(maxDepth)) {
|
2639 |
+
// This file is also included in `angular-loader`, so `copy()` might not always be available in
|
2640 |
+
// the closure. Therefore, it is lazily retrieved as `angular.copy()` when needed.
|
2641 |
+
obj = angular.copy(obj, null, maxDepth);
|
2642 |
+
}
|
2643 |
+
return JSON.stringify(obj, function(key, val) {
|
2644 |
+
val = toJsonReplacer(key, val);
|
2645 |
+
if (isObject(val)) {
|
2646 |
|
2647 |
+
if (seen.indexOf(val) >= 0) return '...';
|
|
|
|
|
|
|
|
|
2648 |
|
2649 |
+
seen.push(val);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2650 |
}
|
2651 |
+
return val;
|
2652 |
+
});
|
2653 |
+
}
|
2654 |
+
|
2655 |
+
function toDebugString(obj, maxDepth) {
|
2656 |
+
if (typeof obj === 'function') {
|
2657 |
+
return obj.toString().replace(/ \{[\s\S]*$/, '');
|
2658 |
+
} else if (isUndefined(obj)) {
|
2659 |
+
return 'undefined';
|
2660 |
+
} else if (typeof obj !== 'string') {
|
2661 |
+
return serializeObject(obj, maxDepth);
|
2662 |
+
}
|
2663 |
+
return obj;
|
2664 |
+
}
|
2665 |
|
2666 |
+
/* global angularModule: true,
|
2667 |
version: true,
|
2668 |
|
2669 |
$CompileProvider,
|
2764 |
*/
|
2765 |
|
2766 |
|
2767 |
+
/**
|
2768 |
+
* @ngdoc object
|
2769 |
+
* @name angular.version
|
2770 |
+
* @module ng
|
2771 |
+
* @description
|
2772 |
+
* An object that contains information about the current AngularJS version.
|
2773 |
+
*
|
2774 |
+
* This object has the following properties:
|
2775 |
+
*
|
2776 |
+
* - `full` – `{string}` – Full version string, such as "0.9.18".
|
2777 |
+
* - `major` – `{number}` – Major version number, such as "0".
|
2778 |
+
* - `minor` – `{number}` – Minor version number, such as "9".
|
2779 |
+
* - `dot` – `{number}` – Dot version number, such as "18".
|
2780 |
+
* - `codeName` – `{string}` – Code name of the release, such as "jiggling-armfat".
|
2781 |
+
*/
|
2782 |
+
var version = {
|
2783 |
+
// These placeholder strings will be replaced by grunt's `build` task.
|
2784 |
+
// They need to be double- or single-quoted.
|
2785 |
+
full: '1.7.6',
|
2786 |
+
major: 1,
|
2787 |
+
minor: 7,
|
2788 |
+
dot: 6,
|
2789 |
+
codeName: 'gravity-manipulation'
|
2790 |
+
};
|
2791 |
+
|
2792 |
+
|
2793 |
+
function publishExternalAPI(angular) {
|
2794 |
+
extend(angular, {
|
2795 |
+
'errorHandlingConfig': errorHandlingConfig,
|
2796 |
+
'bootstrap': bootstrap,
|
2797 |
+
'copy': copy,
|
2798 |
+
'extend': extend,
|
2799 |
+
'merge': merge,
|
2800 |
+
'equals': equals,
|
2801 |
+
'element': jqLite,
|
2802 |
+
'forEach': forEach,
|
2803 |
+
'injector': createInjector,
|
2804 |
+
'noop': noop,
|
2805 |
+
'bind': bind,
|
2806 |
+
'toJson': toJson,
|
2807 |
+
'fromJson': fromJson,
|
2808 |
+
'identity': identity,
|
2809 |
+
'isUndefined': isUndefined,
|
2810 |
+
'isDefined': isDefined,
|
2811 |
+
'isString': isString,
|
2812 |
+
'isFunction': isFunction,
|
2813 |
+
'isObject': isObject,
|
2814 |
+
'isNumber': isNumber,
|
2815 |
+
'isElement': isElement,
|
2816 |
+
'isArray': isArray,
|
2817 |
+
'version': version,
|
2818 |
+
'isDate': isDate,
|
2819 |
+
'callbacks': {$$counter: 0},
|
2820 |
+
'getTestability': getTestability,
|
2821 |
+
'reloadWithDebugInfo': reloadWithDebugInfo,
|
2822 |
+
'$$minErr': minErr,
|
2823 |
+
'$$csp': csp,
|
2824 |
+
'$$encodeUriSegment': encodeUriSegment,
|
2825 |
+
'$$encodeUriQuery': encodeUriQuery,
|
2826 |
+
'$$lowercase': lowercase,
|
2827 |
+
'$$stringify': stringify,
|
2828 |
+
'$$uppercase': uppercase
|
2829 |
+
});
|
2830 |
|
2831 |
+
angularModule = setupModuleLoader(window);
|
2832 |
|
2833 |
+
angularModule('ng', ['ngLocale'], ['$provide',
|
2834 |
+
function ngModule($provide) {
|
2835 |
+
// $$sanitizeUriProvider needs to be before $compileProvider as it is used by it.
|
2836 |
+
$provide.provider({
|
2837 |
+
$$sanitizeUri: $$SanitizeUriProvider
|
2838 |
+
});
|
2839 |
+
$provide.provider('$compile', $CompileProvider).
|
2840 |
+
directive({
|
2841 |
+
a: htmlAnchorDirective,
|
2842 |
+
input: inputDirective,
|
2843 |
+
textarea: inputDirective,
|
2844 |
+
form: formDirective,
|
2845 |
+
script: scriptDirective,
|
2846 |
+
select: selectDirective,
|
2847 |
+
option: optionDirective,
|
2848 |
+
ngBind: ngBindDirective,
|
2849 |
+
ngBindHtml: ngBindHtmlDirective,
|
2850 |
+
ngBindTemplate: ngBindTemplateDirective,
|
2851 |
+
ngClass: ngClassDirective,
|
2852 |
+
ngClassEven: ngClassEvenDirective,
|
2853 |
+
ngClassOdd: ngClassOddDirective,
|
2854 |
+
ngCloak: ngCloakDirective,
|
2855 |
+
ngController: ngControllerDirective,
|
2856 |
+
ngForm: ngFormDirective,
|
2857 |
+
ngHide: ngHideDirective,
|
2858 |
+
ngIf: ngIfDirective,
|
2859 |
+
ngInclude: ngIncludeDirective,
|
2860 |
+
ngInit: ngInitDirective,
|
2861 |
+
ngNonBindable: ngNonBindableDirective,
|
2862 |
+
ngPluralize: ngPluralizeDirective,
|
2863 |
+
ngRef: ngRefDirective,
|
2864 |
+
ngRepeat: ngRepeatDirective,
|
2865 |
+
ngShow: ngShowDirective,
|
2866 |
+
ngStyle: ngStyleDirective,
|
2867 |
+
ngSwitch: ngSwitchDirective,
|
2868 |
+
ngSwitchWhen: ngSwitchWhenDirective,
|
2869 |
+
ngSwitchDefault: ngSwitchDefaultDirective,
|
2870 |
+
ngOptions: ngOptionsDirective,
|
2871 |
+
ngTransclude: ngTranscludeDirective,
|
2872 |
+
ngModel: ngModelDirective,
|
2873 |
+
ngList: ngListDirective,
|
2874 |
+
ngChange: ngChangeDirective,
|
2875 |
+
pattern: patternDirective,
|
2876 |
+
ngPattern: patternDirective,
|
2877 |
+
required: requiredDirective,
|
2878 |
+
ngRequired: requiredDirective,
|
2879 |
+
minlength: minlengthDirective,
|
2880 |
+
ngMinlength: minlengthDirective,
|
2881 |
+
maxlength: maxlengthDirective,
|
2882 |
+
ngMaxlength: maxlengthDirective,
|
2883 |
+
ngValue: ngValueDirective,
|
2884 |
+
ngModelOptions: ngModelOptionsDirective
|
2885 |
+
}).
|
2886 |
+
directive({
|
2887 |
+
ngInclude: ngIncludeFillContentDirective,
|
2888 |
+
input: hiddenInputBrowserCacheDirective
|
2889 |
+
}).
|
2890 |
+
directive(ngAttributeAliasDirectives).
|
2891 |
+
directive(ngEventDirectives);
|
2892 |
+
$provide.provider({
|
2893 |
+
$anchorScroll: $AnchorScrollProvider,
|
2894 |
+
$animate: $AnimateProvider,
|
2895 |
+
$animateCss: $CoreAnimateCssProvider,
|
2896 |
+
$$animateJs: $$CoreAnimateJsProvider,
|
2897 |
+
$$animateQueue: $$CoreAnimateQueueProvider,
|
2898 |
+
$$AnimateRunner: $$AnimateRunnerFactoryProvider,
|
2899 |
+
$$animateAsyncRun: $$AnimateAsyncRunFactoryProvider,
|
2900 |
+
$browser: $BrowserProvider,
|
2901 |
+
$cacheFactory: $CacheFactoryProvider,
|
2902 |
+
$controller: $ControllerProvider,
|
2903 |
+
$document: $DocumentProvider,
|
2904 |
+
$$isDocumentHidden: $$IsDocumentHiddenProvider,
|
2905 |
+
$exceptionHandler: $ExceptionHandlerProvider,
|
2906 |
+
$filter: $FilterProvider,
|
2907 |
+
$$forceReflow: $$ForceReflowProvider,
|
2908 |
+
$interpolate: $InterpolateProvider,
|
2909 |
+
$interval: $IntervalProvider,
|
2910 |
+
$$intervalFactory: $$IntervalFactoryProvider,
|
2911 |
+
$http: $HttpProvider,
|
2912 |
+
$httpParamSerializer: $HttpParamSerializerProvider,
|
2913 |
+
$httpParamSerializerJQLike: $HttpParamSerializerJQLikeProvider,
|
2914 |
+
$httpBackend: $HttpBackendProvider,
|
2915 |
+
$xhrFactory: $xhrFactoryProvider,
|
2916 |
+
$jsonpCallbacks: $jsonpCallbacksProvider,
|
2917 |
+
$location: $LocationProvider,
|
2918 |
+
$log: $LogProvider,
|
2919 |
+
$parse: $ParseProvider,
|
2920 |
+
$rootScope: $RootScopeProvider,
|
2921 |
+
$q: $QProvider,
|
2922 |
+
$$q: $$QProvider,
|
2923 |
+
$sce: $SceProvider,
|
2924 |
+
$sceDelegate: $SceDelegateProvider,
|
2925 |
+
$sniffer: $SnifferProvider,
|
2926 |
+
$$taskTrackerFactory: $$TaskTrackerFactoryProvider,
|
2927 |
+
$templateCache: $TemplateCacheProvider,
|
2928 |
+
$templateRequest: $TemplateRequestProvider,
|
2929 |
+
$$testability: $$TestabilityProvider,
|
2930 |
+
$timeout: $TimeoutProvider,
|
2931 |
+
$window: $WindowProvider,
|
2932 |
+
$$rAF: $$RAFProvider,
|
2933 |
+
$$jqLite: $$jqLiteProvider,
|
2934 |
+
$$Map: $$MapProvider,
|
2935 |
+
$$cookieReader: $$CookieReaderProvider
|
2936 |
+
});
|
|
|
|
|
|
|
2937 |
}
|
2938 |
+
])
|
2939 |
+
.info({ angularVersion: '1.7.6' });
|
2940 |
+
}
|
2941 |
|
2942 |
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2943 |
* Any commits to this file should be reviewed with security in mind. *
|
2944 |
* Changes to this file can potentially create security vulnerabilities. *
|
2945 |
* An approval from 2 Core members with history of modifying *
|
2950 |
* Or gives undesired access to variables likes document or window? *
|
2951 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2952 |
|
2953 |
+
/* global
|
2954 |
JQLitePrototype: true,
|
2955 |
BOOLEAN_ATTR: true,
|
2956 |
ALIASED_ATTR: true
|
2960 |
//JQLite
|
2961 |
//////////////////////////////////
|
2962 |
|
2963 |
+
/**
|
2964 |
+
* @ngdoc function
|
2965 |
+
* @name angular.element
|
2966 |
+
* @module ng
|
2967 |
+
* @kind function
|
2968 |
+
*
|
2969 |
+
* @description
|
2970 |
+
* Wraps a raw DOM element or HTML string as a [jQuery](http://jquery.com) element.
|
2971 |
+
*
|
2972 |
+
* If jQuery is available, `angular.element` is an alias for the
|
2973 |
+
* [jQuery](http://api.jquery.com/jQuery/) function. If jQuery is not available, `angular.element`
|
2974 |
+
* delegates to AngularJS's built-in subset of jQuery, called "jQuery lite" or **jqLite**.
|
2975 |
+
*
|
2976 |
+
* jqLite is a tiny, API-compatible subset of jQuery that allows
|
2977 |
+
* AngularJS to manipulate the DOM in a cross-browser compatible way. jqLite implements only the most
|
2978 |
+
* commonly needed functionality with the goal of having a very small footprint.
|
2979 |
+
*
|
2980 |
+
* To use `jQuery`, simply ensure it is loaded before the `angular.js` file. You can also use the
|
2981 |
+
* {@link ngJq `ngJq`} directive to specify that jqlite should be used over jQuery, or to use a
|
2982 |
+
* specific version of jQuery if multiple versions exist on the page.
|
2983 |
+
*
|
2984 |
+
* <div class="alert alert-info">**Note:** All element references in AngularJS are always wrapped with jQuery or
|
2985 |
+
* jqLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.</div>
|
2986 |
+
*
|
2987 |
+
* <div class="alert alert-warning">**Note:** Keep in mind that this function will not find elements
|
2988 |
+
* by tag name / CSS selector. For lookups by tag name, try instead `angular.element(document).find(...)`
|
2989 |
+
* or `$document.find()`, or use the standard DOM APIs, e.g. `document.querySelectorAll()`.</div>
|
2990 |
+
*
|
2991 |
+
* ## AngularJS's jqLite
|
2992 |
+
* jqLite provides only the following jQuery methods:
|
2993 |
+
*
|
2994 |
+
* - [`addClass()`](http://api.jquery.com/addClass/) - Does not support a function as first argument
|
2995 |
+
* - [`after()`](http://api.jquery.com/after/)
|
2996 |
+
* - [`append()`](http://api.jquery.com/append/) - Contrary to jQuery, this doesn't clone elements
|
2997 |
+
* so will not work correctly when invoked on a jqLite object containing more than one DOM node
|
2998 |
+
* - [`attr()`](http://api.jquery.com/attr/) - Does not support functions as parameters
|
2999 |
+
* - [`bind()`](http://api.jquery.com/bind/) (_deprecated_, use [`on()`](http://api.jquery.com/on/)) - Does not support namespaces, selectors or eventData
|
3000 |
+
* - [`children()`](http://api.jquery.com/children/) - Does not support selectors
|
3001 |
+
* - [`clone()`](http://api.jquery.com/clone/)
|
3002 |
+
* - [`contents()`](http://api.jquery.com/contents/)
|
3003 |
+
* - [`css()`](http://api.jquery.com/css/) - Only retrieves inline-styles, does not call `getComputedStyle()`.
|
3004 |
+
* As a setter, does not convert numbers to strings or append 'px', and also does not have automatic property prefixing.
|
3005 |
+
* - [`data()`](http://api.jquery.com/data/)
|
3006 |
+
* - [`detach()`](http://api.jquery.com/detach/)
|
3007 |
+
* - [`empty()`](http://api.jquery.com/empty/)
|
3008 |
+
* - [`eq()`](http://api.jquery.com/eq/)
|
3009 |
+
* - [`find()`](http://api.jquery.com/find/) - Limited to lookups by tag name
|
3010 |
+
* - [`hasClass()`](http://api.jquery.com/hasClass/)
|
3011 |
+
* - [`html()`](http://api.jquery.com/html/)
|
3012 |
+
* - [`next()`](http://api.jquery.com/next/) - Does not support selectors
|
3013 |
+
* - [`on()`](http://api.jquery.com/on/) - Does not support namespaces, selectors or eventData
|
3014 |
+
* - [`off()`](http://api.jquery.com/off/) - Does not support namespaces, selectors or event object as parameter
|
3015 |
+
* - [`one()`](http://api.jquery.com/one/) - Does not support namespaces or selectors
|
3016 |
+
* - [`parent()`](http://api.jquery.com/parent/) - Does not support selectors
|
3017 |
+
* - [`prepend()`](http://api.jquery.com/prepend/)
|
3018 |
+
* - [`prop()`](http://api.jquery.com/prop/)
|
3019 |
+
* - [`ready()`](http://api.jquery.com/ready/) (_deprecated_, use `angular.element(callback)` instead of `angular.element(document).ready(callback)`)
|
3020 |
+
* - [`remove()`](http://api.jquery.com/remove/)
|
3021 |
+
* - [`removeAttr()`](http://api.jquery.com/removeAttr/) - Does not support multiple attributes
|
3022 |
+
* - [`removeClass()`](http://api.jquery.com/removeClass/) - Does not support a function as first argument
|
3023 |
+
* - [`removeData()`](http://api.jquery.com/removeData/)
|
3024 |
+
* - [`replaceWith()`](http://api.jquery.com/replaceWith/)
|
3025 |
+
* - [`text()`](http://api.jquery.com/text/)
|
3026 |
+
* - [`toggleClass()`](http://api.jquery.com/toggleClass/) - Does not support a function as first argument
|
3027 |
+
* - [`triggerHandler()`](http://api.jquery.com/triggerHandler/) - Passes a dummy event object to handlers
|
3028 |
+
* - [`unbind()`](http://api.jquery.com/unbind/) (_deprecated_, use [`off()`](http://api.jquery.com/off/)) - Does not support namespaces or event object as parameter
|
3029 |
+
* - [`val()`](http://api.jquery.com/val/)
|
3030 |
+
* - [`wrap()`](http://api.jquery.com/wrap/)
|
3031 |
+
*
|
3032 |
+
* ## jQuery/jqLite Extras
|
3033 |
+
* AngularJS also provides the following additional methods and events to both jQuery and jqLite:
|
3034 |
+
*
|
3035 |
+
* ### Events
|
3036 |
+
* - `$destroy` - AngularJS intercepts all jqLite/jQuery's DOM destruction apis and fires this event
|
3037 |
+
* on all DOM nodes being removed. This can be used to clean up any 3rd party bindings to the DOM
|
3038 |
+
* element before it is removed.
|
3039 |
+
*
|
3040 |
+
* ### Methods
|
3041 |
+
* - `controller(name)` - retrieves the controller of the current element or its parent. By default
|
3042 |
+
* retrieves controller associated with the `ngController` directive. If `name` is provided as
|
3043 |
+
* camelCase directive name, then the controller for this directive will be retrieved (e.g.
|
3044 |
+
* `'ngModel'`).
|
3045 |
+
* - `injector()` - retrieves the injector of the current element or its parent.
|
3046 |
+
* - `scope()` - retrieves the {@link ng.$rootScope.Scope scope} of the current
|
3047 |
+
* element or its parent. Requires {@link guide/production#disabling-debug-data Debug Data} to
|
3048 |
+
* be enabled.
|
3049 |
+
* - `isolateScope()` - retrieves an isolate {@link ng.$rootScope.Scope scope} if one is attached directly to the
|
3050 |
+
* current element. This getter should be used only on elements that contain a directive which starts a new isolate
|
3051 |
+
* scope. Calling `scope()` on this element always returns the original non-isolate scope.
|
3052 |
+
* Requires {@link guide/production#disabling-debug-data Debug Data} to be enabled.
|
3053 |
+
* - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top
|
3054 |
+
* parent element is reached.
|
3055 |
+
*
|
3056 |
+
* @knownIssue You cannot spy on `angular.element` if you are using Jasmine version 1.x. See
|
3057 |
+
* https://github.com/angular/angular.js/issues/14251 for more information.
|
3058 |
+
*
|
3059 |
+
* @param {string|DOMElement} element HTML string or DOMElement to be wrapped into jQuery.
|
3060 |
+
* @returns {Object} jQuery object.
|
3061 |
+
*/
|
3062 |
|
3063 |
+
JQLite.expando = 'ng339';
|
3064 |
|
3065 |
+
var jqCache = JQLite.cache = {},
|
3066 |
+
jqId = 1;
|
3067 |
|
3068 |
+
/*
|
3069 |
* !!! This is an undocumented "private" function !!!
|
3070 |
*/
|
3071 |
+
JQLite._data = function(node) {
|
3072 |
+
//jQuery always returns an object on cache miss
|
3073 |
+
return this.cache[node[this.expando]] || {};
|
3074 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3075 |
|
3076 |
+
function jqNextId() { return ++jqId; }
|
|
|
|
|
3077 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3078 |
|
3079 |
+
var DASH_LOWERCASE_REGEXP = /-([a-z])/g;
|
3080 |
+
var MS_HACK_REGEXP = /^-ms-/;
|
3081 |
+
var MOUSE_EVENT_MAP = { mouseleave: 'mouseout', mouseenter: 'mouseover' };
|
3082 |
+
var jqLiteMinErr = minErr('jqLite');
|
3083 |
|
3084 |
+
/**
|
3085 |
+
* Converts kebab-case to camelCase.
|
3086 |
+
* There is also a special case for the ms prefix starting with a lowercase letter.
|
3087 |
+
* @param name Name to normalize
|
3088 |
+
*/
|
3089 |
+
function cssKebabToCamel(name) {
|
3090 |
+
return kebabToCamel(name.replace(MS_HACK_REGEXP, 'ms-'));
|
3091 |
+
}
|
3092 |
|
3093 |
+
function fnCamelCaseReplace(all, letter) {
|
3094 |
+
return letter.toUpperCase();
|
3095 |
+
}
|
|
|
|
|
|
|
3096 |
|
3097 |
+
/**
|
3098 |
+
* Converts kebab-case to camelCase.
|
3099 |
+
* @param name Name to normalize
|
3100 |
+
*/
|
3101 |
+
function kebabToCamel(name) {
|
3102 |
+
return name
|
3103 |
+
.replace(DASH_LOWERCASE_REGEXP, fnCamelCaseReplace);
|
3104 |
+
}
|
3105 |
|
3106 |
+
var SINGLE_TAG_REGEXP = /^<([\w-]+)\s*\/?>(?:<\/\1>|)$/;
|
3107 |
+
var HTML_REGEXP = /<|&#?\w+;/;
|
3108 |
+
var TAG_NAME_REGEXP = /<([\w:-]+)/;
|
3109 |
+
var XHTML_TAG_REGEXP = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:-]+)[^>]*)\/>/gi;
|
3110 |
|
3111 |
+
var wrapMap = {
|
3112 |
+
'option': [1, '<select multiple="multiple">', '</select>'],
|
|
|
3113 |
|
3114 |
+
'thead': [1, '<table>', '</table>'],
|
3115 |
+
'col': [2, '<table><colgroup>', '</colgroup></table>'],
|
3116 |
+
'tr': [2, '<table><tbody>', '</tbody></table>'],
|
3117 |
+
'td': [3, '<table><tbody><tr>', '</tr></tbody></table>'],
|
3118 |
+
'_default': [0, '', '']
|
3119 |
+
};
|
3120 |
|
3121 |
+
wrapMap.optgroup = wrapMap.option;
|
3122 |
+
wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
|
3123 |
+
wrapMap.th = wrapMap.td;
|
|
|
|
|
|
|
3124 |
|
|
|
|
|
|
|
|
|
3125 |
|
3126 |
+
function jqLiteIsTextNode(html) {
|
3127 |
+
return !HTML_REGEXP.test(html);
|
3128 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3129 |
|
3130 |
+
function jqLiteAcceptsData(node) {
|
3131 |
+
// The window object can accept data but has no nodeType
|
3132 |
+
// Otherwise we are only interested in elements (1) and documents (9)
|
3133 |
+
var nodeType = node.nodeType;
|
3134 |
+
return nodeType === NODE_TYPE_ELEMENT || !nodeType || nodeType === NODE_TYPE_DOCUMENT;
|
3135 |
+
}
|
3136 |
|
3137 |
+
function jqLiteHasData(node) {
|
3138 |
+
for (var key in jqCache[node.ng339]) {
|
3139 |
+
return true;
|
3140 |
+
}
|
3141 |
+
return false;
|
3142 |
+
}
|
3143 |
|
3144 |
+
function jqLiteBuildFragment(html, context) {
|
3145 |
+
var tmp, tag, wrap,
|
3146 |
+
fragment = context.createDocumentFragment(),
|
3147 |
+
nodes = [], i;
|
3148 |
+
|
3149 |
+
if (jqLiteIsTextNode(html)) {
|
3150 |
+
// Convert non-html into a text node
|
3151 |
+
nodes.push(context.createTextNode(html));
|
3152 |
+
} else {
|
3153 |
+
// Convert html into DOM nodes
|
3154 |
+
tmp = fragment.appendChild(context.createElement('div'));
|
3155 |
+
tag = (TAG_NAME_REGEXP.exec(html) || ['', ''])[1].toLowerCase();
|
3156 |
+
wrap = wrapMap[tag] || wrapMap._default;
|
3157 |
+
tmp.innerHTML = wrap[1] + html.replace(XHTML_TAG_REGEXP, '<$1></$2>') + wrap[2];
|
3158 |
+
|
3159 |
+
// Descend through wrappers to the right content
|
3160 |
+
i = wrap[0];
|
3161 |
+
while (i--) {
|
3162 |
+
tmp = tmp.lastChild;
|
3163 |
+
}
|
3164 |
+
|
3165 |
+
nodes = concat(nodes, tmp.childNodes);
|
3166 |
+
|
3167 |
+
tmp = fragment.firstChild;
|
3168 |
+
tmp.textContent = '';
|
3169 |
+
}
|
3170 |
+
|
3171 |
+
// Remove wrapper from fragment
|
3172 |
+
fragment.textContent = '';
|
3173 |
+
fragment.innerHTML = ''; // Clear inner HTML
|
3174 |
+
forEach(nodes, function(node) {
|
3175 |
+
fragment.appendChild(node);
|
3176 |
+
});
|
3177 |
|
3178 |
+
return fragment;
|
3179 |
+
}
|
3180 |
|
3181 |
+
function jqLiteParseHTML(html, context) {
|
3182 |
+
context = context || window.document;
|
3183 |
+
var parsed;
|
3184 |
|
3185 |
+
if ((parsed = SINGLE_TAG_REGEXP.exec(html))) {
|
3186 |
+
return [context.createElement(parsed[1])];
|
3187 |
+
}
|
3188 |
|
3189 |
+
if ((parsed = jqLiteBuildFragment(html, context))) {
|
3190 |
+
return parsed.childNodes;
|
3191 |
+
}
|
3192 |
|
3193 |
+
return [];
|
3194 |
+
}
|
3195 |
|
3196 |
+
function jqLiteWrapNode(node, wrapper) {
|
3197 |
+
var parent = node.parentNode;
|
3198 |
|
3199 |
+
if (parent) {
|
3200 |
+
parent.replaceChild(wrapper, node);
|
3201 |
+
}
|
3202 |
|
3203 |
+
wrapper.appendChild(node);
|
3204 |
+
}
|
3205 |
|
3206 |
|
3207 |
// IE9-11 has no method "contains" in SVG element and in Node.prototype. Bug #10259.
|
3208 |
+
var jqLiteContains = window.Node.prototype.contains || /** @this */ function(arg) {
|
3209 |
+
// eslint-disable-next-line no-bitwise
|
3210 |
+
return !!(this.compareDocumentPosition(arg) & 16);
|
3211 |
+
};
|
3212 |
|
3213 |
/////////////////////////////////////////////
|
3214 |
+
function JQLite(element) {
|
3215 |
+
if (element instanceof JQLite) {
|
3216 |
+
return element;
|
3217 |
+
}
|
3218 |
+
|
3219 |
+
var argIsString;
|
3220 |
+
|
3221 |
+
if (isString(element)) {
|
3222 |
+
element = trim(element);
|
3223 |
+
argIsString = true;
|
3224 |
+
}
|
3225 |
+
if (!(this instanceof JQLite)) {
|
3226 |
+
if (argIsString && element.charAt(0) !== '<') {
|
3227 |
+
throw jqLiteMinErr('nosel', 'Looking up elements via selectors is not supported by jqLite! See: http://docs.angularjs.org/api/angular.element');
|
3228 |
+
}
|
3229 |
+
return new JQLite(element);
|
3230 |
+
}
|
3231 |
+
|
3232 |
+
if (argIsString) {
|
3233 |
+
jqLiteAddNodes(this, jqLiteParseHTML(element));
|
3234 |
+
} else if (isFunction(element)) {
|
3235 |
+
jqLiteReady(element);
|
3236 |
+
} else {
|
3237 |
+
jqLiteAddNodes(this, element);
|
3238 |
+
}
|
3239 |
+
}
|
3240 |
|
3241 |
+
function jqLiteClone(element) {
|
3242 |
+
return element.cloneNode(true);
|
3243 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3244 |
|
3245 |
+
function jqLiteDealoc(element, onlyDescendants) {
|
3246 |
+
if (!onlyDescendants && jqLiteAcceptsData(element)) jqLite.cleanData([element]);
|
|
|
|
|
|
|
|
|
|
|
|
|
3247 |
|
3248 |
+
if (element.querySelectorAll) {
|
3249 |
+
jqLite.cleanData(element.querySelectorAll('*'));
|
3250 |
+
}
|
3251 |
+
}
|
3252 |
|
3253 |
+
function isEmptyObject(obj) {
|
3254 |
+
var name;
|
3255 |
|
3256 |
+
for (name in obj) {
|
3257 |
+
return false;
|
3258 |
+
}
|
3259 |
+
return true;
|
3260 |
+
}
|
3261 |
|
3262 |
+
function removeIfEmptyData(element) {
|
3263 |
+
var expandoId = element.ng339;
|
3264 |
+
var expandoStore = expandoId && jqCache[expandoId];
|
3265 |
|
3266 |
+
var events = expandoStore && expandoStore.events;
|
3267 |
+
var data = expandoStore && expandoStore.data;
|
|
|
|
|
|
|
3268 |
|
3269 |
+
if ((!data || isEmptyObject(data)) && (!events || isEmptyObject(events))) {
|
3270 |
+
delete jqCache[expandoId];
|
3271 |
+
element.ng339 = undefined; // don't delete DOM expandos. IE and Chrome don't like it
|
3272 |
+
}
|
3273 |
+
}
|
3274 |
|
3275 |
+
function jqLiteOff(element, type, fn, unsupported) {
|
3276 |
+
if (isDefined(unsupported)) throw jqLiteMinErr('offargs', 'jqLite#off() does not support the `selector` argument');
|
3277 |
|
3278 |
+
var expandoStore = jqLiteExpandoStore(element);
|
3279 |
+
var events = expandoStore && expandoStore.events;
|
3280 |
+
var handle = expandoStore && expandoStore.handle;
|
|
|
|
|
3281 |
|
3282 |
+
if (!handle) return; //no listeners registered
|
|
|
3283 |
|
3284 |
+
if (!type) {
|
3285 |
+
for (type in events) {
|
3286 |
+
if (type !== '$destroy') {
|
3287 |
+
element.removeEventListener(type, handle);
|
3288 |
+
}
|
3289 |
+
delete events[type];
|
3290 |
+
}
|
3291 |
+
} else {
|
3292 |
|
3293 |
+
var removeHandler = function(type) {
|
3294 |
+
var listenerFns = events[type];
|
3295 |
+
if (isDefined(fn)) {
|
3296 |
+
arrayRemove(listenerFns || [], fn);
|
3297 |
+
}
|
3298 |
+
if (!(isDefined(fn) && listenerFns && listenerFns.length > 0)) {
|
3299 |
+
element.removeEventListener(type, handle);
|
3300 |
+
delete events[type];
|
3301 |
+
}
|
3302 |
+
};
|
3303 |
|
3304 |
+
forEach(type.split(' '), function(type) {
|
3305 |
+
removeHandler(type);
|
3306 |
+
if (MOUSE_EVENT_MAP[type]) {
|
3307 |
+
removeHandler(MOUSE_EVENT_MAP[type]);
|
3308 |
+
}
|
3309 |
+
});
|
3310 |
+
}
|
|
|
3311 |
|
3312 |
+
removeIfEmptyData(element);
|
3313 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3314 |
|
3315 |
+
function jqLiteRemoveData(element, name) {
|
3316 |
+
var expandoId = element.ng339;
|
3317 |
+
var expandoStore = expandoId && jqCache[expandoId];
|
|
|
|
|
|
|
|
|
3318 |
|
3319 |
+
if (expandoStore) {
|
3320 |
+
if (name) {
|
3321 |
+
delete expandoStore.data[name];
|
3322 |
+
} else {
|
3323 |
+
expandoStore.data = {};
|
3324 |
}
|
3325 |
|
3326 |
+
removeIfEmptyData(element);
|
3327 |
+
}
|
3328 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3329 |
|
3330 |
|
3331 |
+
function jqLiteExpandoStore(element, createIfNecessary) {
|
3332 |
+
var expandoId = element.ng339,
|
3333 |
+
expandoStore = expandoId && jqCache[expandoId];
|
3334 |
|
3335 |
+
if (createIfNecessary && !expandoStore) {
|
3336 |
+
element.ng339 = expandoId = jqNextId();
|
3337 |
+
expandoStore = jqCache[expandoId] = {events: {}, data: {}, handle: undefined};
|
3338 |
+
}
|
3339 |
|
3340 |
+
return expandoStore;
|
3341 |
+
}
|
3342 |
|
3343 |
|
3344 |
+
function jqLiteData(element, key, value) {
|
3345 |
+
if (jqLiteAcceptsData(element)) {
|
3346 |
+
var prop;
|
3347 |
|
3348 |
+
var isSimpleSetter = isDefined(value);
|
3349 |
+
var isSimpleGetter = !isSimpleSetter && key && !isObject(key);
|
3350 |
+
var massGetter = !key;
|
3351 |
+
var expandoStore = jqLiteExpandoStore(element, !isSimpleGetter);
|
3352 |
+
var data = expandoStore && expandoStore.data;
|
3353 |
|
3354 |
+
if (isSimpleSetter) { // data('key', value)
|
3355 |
+
data[kebabToCamel(key)] = value;
|
3356 |
+
} else {
|
3357 |
+
if (massGetter) { // data()
|
3358 |
+
return data;
|
3359 |
+
} else {
|
3360 |
+
if (isSimpleGetter) { // data('key')
|
3361 |
+
// don't force creation of expandoStore if it doesn't exist yet
|
3362 |
+
return data && data[kebabToCamel(key)];
|
3363 |
+
} else { // mass-setter: data({key1: val1, key2: val2})
|
3364 |
+
for (prop in key) {
|
3365 |
+
data[kebabToCamel(prop)] = key[prop];
|
3366 |
+
}
|
|
|
|
|
|
|
3367 |
}
|
3368 |
+
}
|
3369 |
}
|
3370 |
+
}
|
3371 |
+
}
|
3372 |
|
3373 |
+
function jqLiteHasClass(element, selector) {
|
3374 |
+
if (!element.getAttribute) return false;
|
3375 |
+
return ((' ' + (element.getAttribute('class') || '') + ' ').replace(/[\n\t]/g, ' ').
|
3376 |
+
indexOf(' ' + selector + ' ') > -1);
|
3377 |
+
}
|
3378 |
|
3379 |
+
function jqLiteRemoveClass(element, cssClasses) {
|
3380 |
+
if (cssClasses && element.setAttribute) {
|
3381 |
+
var existingClasses = (' ' + (element.getAttribute('class') || '') + ' ')
|
3382 |
+
.replace(/[\n\t]/g, ' ');
|
3383 |
+
var newClasses = existingClasses;
|
3384 |
|
3385 |
+
forEach(cssClasses.split(' '), function(cssClass) {
|
3386 |
+
cssClass = trim(cssClass);
|
3387 |
+
newClasses = newClasses.replace(' ' + cssClass + ' ', ' ');
|
3388 |
+
});
|
3389 |
|
3390 |
+
if (newClasses !== existingClasses) {
|
3391 |
+
element.setAttribute('class', trim(newClasses));
|
|
|
|
|
3392 |
}
|
3393 |
+
}
|
3394 |
+
}
|
3395 |
|
3396 |
+
function jqLiteAddClass(element, cssClasses) {
|
3397 |
+
if (cssClasses && element.setAttribute) {
|
3398 |
+
var existingClasses = (' ' + (element.getAttribute('class') || '') + ' ')
|
3399 |
+
.replace(/[\n\t]/g, ' ');
|
3400 |
+
var newClasses = existingClasses;
|
3401 |
|
3402 |
+
forEach(cssClasses.split(' '), function(cssClass) {
|
3403 |
+
cssClass = trim(cssClass);
|
3404 |
+
if (newClasses.indexOf(' ' + cssClass + ' ') === -1) {
|
3405 |
+
newClasses += cssClass + ' ';
|
3406 |
+
}
|
3407 |
+
});
|
3408 |
|
3409 |
+
if (newClasses !== existingClasses) {
|
3410 |
+
element.setAttribute('class', trim(newClasses));
|
|
|
|
|
3411 |
}
|
3412 |
+
}
|
3413 |
+
}
|
3414 |
|
3415 |
|
3416 |
+
function jqLiteAddNodes(root, elements) {
|
3417 |
+
// THIS CODE IS VERY HOT. Don't make changes without benchmarking.
|
3418 |
|
3419 |
+
if (elements) {
|
3420 |
|
3421 |
+
// if a Node (the most common case)
|
3422 |
+
if (elements.nodeType) {
|
3423 |
+
root[root.length++] = elements;
|
3424 |
+
} else {
|
3425 |
+
var length = elements.length;
|
3426 |
|
3427 |
+
// if an Array or NodeList and not a Window
|
3428 |
+
if (typeof length === 'number' && elements.window !== elements) {
|
3429 |
+
if (length) {
|
3430 |
+
for (var i = 0; i < length; i++) {
|
3431 |
+
root[root.length++] = elements[i];
|
3432 |
+
}
|
|
|
|
|
|
|
|
|
|
|
3433 |
}
|
3434 |
+
} else {
|
3435 |
+
root[root.length++] = elements;
|
3436 |
+
}
|
3437 |
}
|
3438 |
+
}
|
3439 |
+
}
|
3440 |
|
3441 |
|
3442 |
+
function jqLiteController(element, name) {
|
3443 |
+
return jqLiteInheritedData(element, '$' + (name || 'ngController') + 'Controller');
|
3444 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3445 |
|
3446 |
+
function jqLiteInheritedData(element, name, value) {
|
3447 |
+
// if element is the document object work with the html element instead
|
3448 |
+
// this makes $(document).scope() possible
|
3449 |
+
if (element.nodeType === NODE_TYPE_DOCUMENT) {
|
3450 |
+
element = element.documentElement;
|
3451 |
+
}
|
3452 |
+
var names = isArray(name) ? name : [name];
|
3453 |
|
3454 |
+
while (element) {
|
3455 |
+
for (var i = 0, ii = names.length; i < ii; i++) {
|
3456 |
+
if (isDefined(value = jqLite.data(element, names[i]))) return value;
|
|
|
3457 |
}
|
3458 |
|
3459 |
+
// If dealing with a document fragment node with a host element, and no parent, use the host
|
3460 |
+
// element as the parent. This enables directives within a Shadow DOM or polyfilled Shadow DOM
|
3461 |
+
// to lookup parent controllers.
|
3462 |
+
element = element.parentNode || (element.nodeType === NODE_TYPE_DOCUMENT_FRAGMENT && element.host);
|
3463 |
+
}
|
3464 |
+
}
|
3465 |
|
3466 |
+
function jqLiteEmpty(element) {
|
3467 |
+
jqLiteDealoc(element, true);
|
3468 |
+
while (element.firstChild) {
|
3469 |
+
element.removeChild(element.firstChild);
|
3470 |
+
}
|
3471 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
3472 |
|
3473 |
+
function jqLiteRemove(element, keepData) {
|
3474 |
+
if (!keepData) jqLiteDealoc(element);
|
3475 |
+
var parent = element.parentNode;
|
3476 |
+
if (parent) parent.removeChild(element);
|
3477 |
+
}
|
|
|
3478 |
|
|
|
|
|
|
|
|
|
|
|
3479 |
|
3480 |
+
function jqLiteDocumentLoaded(action, win) {
|
3481 |
+
win = win || window;
|
3482 |
+
if (win.document.readyState === 'complete') {
|
3483 |
+
// Force the action to be run async for consistent behavior
|
3484 |
+
// from the action's point of view
|
3485 |
+
// i.e. it will definitely not be in a $apply
|
3486 |
+
win.setTimeout(action);
|
3487 |
+
} else {
|
3488 |
+
// No need to unbind this handler as load is only ever called once
|
3489 |
+
jqLite(win).on('load', action);
|
3490 |
+
}
|
3491 |
+
}
|
3492 |
|
3493 |
+
function jqLiteReady(fn) {
|
3494 |
+
function trigger() {
|
3495 |
+
window.document.removeEventListener('DOMContentLoaded', trigger);
|
3496 |
+
window.removeEventListener('load', trigger);
|
3497 |
+
fn();
|
3498 |
+
}
|
3499 |
+
|
3500 |
+
// check if document is already loaded
|
3501 |
+
if (window.document.readyState === 'complete') {
|
3502 |
+
window.setTimeout(fn);
|
3503 |
+
} else {
|
3504 |
+
// We can not use jqLite since we are not done loading and jQuery could be loaded later.
|
3505 |
+
|
3506 |
+
// Works for modern browsers and IE9
|
3507 |
+
window.document.addEventListener('DOMContentLoaded', trigger);
|
3508 |
+
|
3509 |
+
// Fallback to window.onload for others
|
3510 |
+
window.addEventListener('load', trigger);
|
3511 |
+
}
|
3512 |
+
}
|
3513 |
|
3514 |
//////////////////////////////////////////
|
3515 |
// Functions which are declared directly.
|
3516 |
//////////////////////////////////////////
|
3517 |
+
var JQLitePrototype = JQLite.prototype = {
|
3518 |
+
ready: jqLiteReady,
|
3519 |
+
toString: function() {
|
3520 |
+
var value = [];
|
3521 |
+
forEach(this, function(e) { value.push('' + e);});
|
3522 |
+
return '[' + value.join(', ') + ']';
|
3523 |
+
},
|
3524 |
+
|
3525 |
+
eq: function(index) {
|
3526 |
+
return (index >= 0) ? jqLite(this[index]) : jqLite(this[this.length + index]);
|
3527 |
+
},
|
3528 |
+
|
3529 |
+
length: 0,
|
3530 |
+
push: push,
|
3531 |
+
sort: [].sort,
|
3532 |
+
splice: [].splice
|
3533 |
+
};
|
3534 |
|
3535 |
//////////////////////////////////////////
|
3536 |
// Functions iterating getter/setters.
|
3537 |
// these functions return self on setter and
|
3538 |
// value on get.
|
3539 |
//////////////////////////////////////////
|
3540 |
+
var BOOLEAN_ATTR = {};
|
3541 |
+
forEach('multiple,selected,checked,disabled,readOnly,required,open'.split(','), function(value) {
|
3542 |
+
BOOLEAN_ATTR[lowercase(value)] = value;
|
3543 |
+
});
|
3544 |
+
var BOOLEAN_ELEMENTS = {};
|
3545 |
+
forEach('input,select,option,textarea,button,form,details'.split(','), function(value) {
|
3546 |
+
BOOLEAN_ELEMENTS[value] = true;
|
3547 |
+
});
|
3548 |
+
var ALIASED_ATTR = {
|
3549 |
+
'ngMinlength': 'minlength',
|
3550 |
+
'ngMaxlength': 'maxlength',
|
3551 |
+
'ngMin': 'min',
|
3552 |
+
'ngMax': 'max',
|
3553 |
+
'ngPattern': 'pattern',
|
3554 |
+
'ngStep': 'step'
|
3555 |
+
};
|
3556 |
+
|
3557 |
+
function getBooleanAttrName(element, name) {
|
3558 |
+
// check dom last since we will most likely fail on name
|
3559 |
+
var booleanAttr = BOOLEAN_ATTR[name.toLowerCase()];
|
3560 |
+
|
3561 |
+
// booleanAttr is here twice to minimize DOM access
|
3562 |
+
return booleanAttr && BOOLEAN_ELEMENTS[nodeName_(element)] && booleanAttr;
|
3563 |
+
}
|
3564 |
|
3565 |
+
function getAliasedAttrName(name) {
|
3566 |
+
return ALIASED_ATTR[name];
|
3567 |
+
}
|
3568 |
|
3569 |
+
forEach({
|
3570 |
+
data: jqLiteData,
|
3571 |
+
removeData: jqLiteRemoveData,
|
3572 |
+
hasData: jqLiteHasData,
|
3573 |
+
cleanData: function jqLiteCleanData(nodes) {
|
3574 |
+
for (var i = 0, ii = nodes.length; i < ii; i++) {
|
3575 |
+
jqLiteRemoveData(nodes[i]);
|
3576 |
+
jqLiteOff(nodes[i]);
|
3577 |
+
}
|
3578 |
+
}
|
3579 |
+
}, function(fn, name) {
|
3580 |
+
JQLite[name] = fn;
|
3581 |
+
});
|
3582 |
|
3583 |
+
forEach({
|
3584 |
+
data: jqLiteData,
|
3585 |
+
inheritedData: jqLiteInheritedData,
|
3586 |
|
3587 |
+
scope: function(element) {
|
3588 |
+
// Can't use jqLiteData here directly so we stay compatible with jQuery!
|
3589 |
+
return jqLite.data(element, '$scope') || jqLiteInheritedData(element.parentNode || element, ['$isolateScope', '$scope']);
|
3590 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3591 |
|
3592 |
+
isolateScope: function(element) {
|
3593 |
+
// Can't use jqLiteData here directly so we stay compatible with jQuery!
|
3594 |
+
return jqLite.data(element, '$isolateScope') || jqLite.data(element, '$isolateScopeNoTemplate');
|
3595 |
+
},
|
3596 |
|
3597 |
+
controller: jqLiteController,
|
|
|
|
|
|
|
3598 |
|
3599 |
+
injector: function(element) {
|
3600 |
+
return jqLiteInheritedData(element, '$injector');
|
3601 |
+
},
|
|
|
3602 |
|
3603 |
+
removeAttr: function(element, name) {
|
3604 |
+
element.removeAttribute(name);
|
3605 |
+
},
|
3606 |
|
3607 |
+
hasClass: jqLiteHasClass,
|
|
|
|
|
3608 |
|
3609 |
+
css: function(element, name, value) {
|
3610 |
+
name = cssKebabToCamel(name);
|
|
|
3611 |
|
3612 |
+
if (isDefined(value)) {
|
3613 |
+
element.style[name] = value;
|
3614 |
+
} else {
|
3615 |
+
return element.style[name];
|
3616 |
+
}
|
3617 |
+
},
|
3618 |
|
3619 |
+
attr: function(element, name, value) {
|
3620 |
+
var ret;
|
3621 |
+
var nodeType = element.nodeType;
|
3622 |
+
if (nodeType === NODE_TYPE_TEXT || nodeType === NODE_TYPE_ATTRIBUTE || nodeType === NODE_TYPE_COMMENT ||
|
3623 |
+
!element.getAttribute) {
|
3624 |
+
return;
|
3625 |
+
}
|
3626 |
|
3627 |
+
var lowercasedName = lowercase(name);
|
3628 |
+
var isBooleanAttr = BOOLEAN_ATTR[lowercasedName];
|
|
|
|
|
|
|
|
|
3629 |
|
3630 |
+
if (isDefined(value)) {
|
3631 |
+
// setter
|
|
|
|
|
|
|
|
|
|
|
3632 |
|
3633 |
+
if (value === null || (value === false && isBooleanAttr)) {
|
3634 |
+
element.removeAttribute(name);
|
3635 |
+
} else {
|
3636 |
+
element.setAttribute(name, isBooleanAttr ? lowercasedName : value);
|
3637 |
+
}
|
3638 |
+
} else {
|
3639 |
+
// getter
|
3640 |
|
3641 |
+
ret = element.getAttribute(name);
|
|
|
3642 |
|
3643 |
+
if (isBooleanAttr && ret !== null) {
|
3644 |
+
ret = lowercasedName;
|
3645 |
+
}
|
3646 |
+
// Normalize non-existing attributes to undefined (as jQuery).
|
3647 |
+
return ret === null ? undefined : ret;
|
3648 |
+
}
|
3649 |
+
},
|
3650 |
|
3651 |
+
prop: function(element, name, value) {
|
3652 |
+
if (isDefined(value)) {
|
3653 |
+
element[name] = value;
|
3654 |
+
} else {
|
3655 |
+
return element[name];
|
3656 |
+
}
|
3657 |
+
},
|
3658 |
|
3659 |
+
text: (function() {
|
3660 |
+
getText.$dv = '';
|
3661 |
+
return getText;
|
|
|
|
|
|
|
|
|
3662 |
|
3663 |
+
function getText(element, value) {
|
3664 |
+
if (isUndefined(value)) {
|
3665 |
+
var nodeType = element.nodeType;
|
3666 |
+
return (nodeType === NODE_TYPE_ELEMENT || nodeType === NODE_TYPE_TEXT) ? element.textContent : '';
|
3667 |
+
}
|
3668 |
+
element.textContent = value;
|
3669 |
+
}
|
3670 |
+
})(),
|
|
|
|
|
|
|
3671 |
|
3672 |
+
val: function(element, value) {
|
3673 |
+
if (isUndefined(value)) {
|
3674 |
+
if (element.multiple && nodeName_(element) === 'select') {
|
3675 |
+
var result = [];
|
3676 |
+
forEach(element.options, function(option) {
|
3677 |
+
if (option.selected) {
|
3678 |
+
result.push(option.value || option.text);
|
3679 |
+
}
|
3680 |
+
});
|
3681 |
+
return result;
|
3682 |
+
}
|
3683 |
+
return element.value;
|
3684 |
+
}
|
3685 |
+
element.value = value;
|
3686 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3687 |
|
3688 |
+
html: function(element, value) {
|
3689 |
+
if (isUndefined(value)) {
|
3690 |
+
return element.innerHTML;
|
3691 |
+
}
|
3692 |
+
jqLiteDealoc(element, true);
|
3693 |
+
element.innerHTML = value;
|
3694 |
+
},
|
3695 |
|
3696 |
+
empty: jqLiteEmpty
|
3697 |
+
}, function(fn, name) {
|
3698 |
+
/**
|
3699 |
+
* Properties: writes return selection, reads return first value
|
3700 |
+
*/
|
3701 |
+
JQLite.prototype[name] = function(arg1, arg2) {
|
3702 |
+
var i, key;
|
3703 |
+
var nodeCount = this.length;
|
3704 |
+
|
3705 |
+
// jqLiteHasClass has only two arguments, but is a getter-only fn, so we need to special-case it
|
3706 |
+
// in a way that survives minification.
|
3707 |
+
// jqLiteEmpty takes no arguments but is a setter.
|
3708 |
+
if (fn !== jqLiteEmpty &&
|
3709 |
+
(isUndefined((fn.length === 2 && (fn !== jqLiteHasClass && fn !== jqLiteController)) ? arg1 : arg2))) {
|
3710 |
+
if (isObject(arg1)) {
|
3711 |
+
|
3712 |
+
// we are a write, but the object properties are the key/values
|
3713 |
+
for (i = 0; i < nodeCount; i++) {
|
3714 |
+
if (fn === jqLiteData) {
|
3715 |
+
// data() takes the whole object in jQuery
|
3716 |
+
fn(this[i], arg1);
|
3717 |
+
} else {
|
3718 |
+
for (key in arg1) {
|
3719 |
+
fn(this[i], key, arg1[key]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3720 |
}
|
3721 |
+
}
|
3722 |
+
}
|
3723 |
+
// return self for chaining
|
3724 |
+
return this;
|
3725 |
+
} else {
|
3726 |
+
// we are a read, so read the first child.
|
3727 |
+
// TODO: do we still need this?
|
3728 |
+
var value = fn.$dv;
|
3729 |
+
// Only if we have $dv do we iterate over all, otherwise it is just the first element.
|
3730 |
+
var jj = (isUndefined(value)) ? Math.min(nodeCount, 1) : nodeCount;
|
3731 |
+
for (var j = 0; j < jj; j++) {
|
3732 |
+
var nodeValue = fn(this[j], arg1, arg2);
|
3733 |
+
value = value ? value + nodeValue : nodeValue;
|
3734 |
+
}
|
3735 |
+
return value;
|
3736 |
+
}
|
3737 |
+
} else {
|
3738 |
+
// we are a write, so apply to all children
|
3739 |
+
for (i = 0; i < nodeCount; i++) {
|
3740 |
+
fn(this[i], arg1, arg2);
|
3741 |
+
}
|
3742 |
+
// return self for chaining
|
3743 |
+
return this;
|
3744 |
+
}
|
3745 |
+
};
|
3746 |
+
});
|
3747 |
|
3748 |
+
function createEventHandler(element, events) {
|
3749 |
+
var eventHandler = function(event, type) {
|
3750 |
+
// jQuery specific api
|
3751 |
+
event.isDefaultPrevented = function() {
|
3752 |
+
return event.defaultPrevented;
|
3753 |
+
};
|
3754 |
|
3755 |
+
var eventFns = events[type || event.type];
|
3756 |
+
var eventFnsLength = eventFns ? eventFns.length : 0;
|
|
|
|
|
3757 |
|
3758 |
+
if (!eventFnsLength) return;
|
|
|
|
|
3759 |
|
3760 |
+
if (isUndefined(event.immediatePropagationStopped)) {
|
3761 |
+
var originalStopImmediatePropagation = event.stopImmediatePropagation;
|
3762 |
+
event.stopImmediatePropagation = function() {
|
3763 |
+
event.immediatePropagationStopped = true;
|
|
|
3764 |
|
3765 |
+
if (event.stopPropagation) {
|
3766 |
+
event.stopPropagation();
|
3767 |
+
}
|
3768 |
|
3769 |
+
if (originalStopImmediatePropagation) {
|
3770 |
+
originalStopImmediatePropagation.call(event);
|
3771 |
+
}
|
3772 |
+
};
|
3773 |
+
}
|
3774 |
|
3775 |
+
event.isImmediatePropagationStopped = function() {
|
3776 |
+
return event.immediatePropagationStopped === true;
|
3777 |
+
};
|
|
|
3778 |
|
3779 |
+
// Some events have special handlers that wrap the real handler
|
3780 |
+
var handlerWrapper = eventFns.specialHandlerWrapper || defaultHandlerWrapper;
|
|
|
|
|
|
|
|
|
3781 |
|
3782 |
+
// Copy event handlers in case event handlers array is modified during execution.
|
3783 |
+
if ((eventFnsLength > 1)) {
|
3784 |
+
eventFns = shallowCopy(eventFns);
|
|
|
3785 |
}
|
3786 |
|
3787 |
+
for (var i = 0; i < eventFnsLength; i++) {
|
3788 |
+
if (!event.isImmediatePropagationStopped()) {
|
3789 |
+
handlerWrapper(element, event, eventFns[i]);
|
3790 |
+
}
|
3791 |
}
|
3792 |
+
};
|
3793 |
|
3794 |
+
// TODO: this is a hack for angularMocks/clearDataCache that makes it possible to deregister all
|
3795 |
+
// events on `element`
|
3796 |
+
eventHandler.elem = element;
|
3797 |
+
return eventHandler;
|
3798 |
+
}
|
3799 |
+
|
3800 |
+
function defaultHandlerWrapper(element, event, handler) {
|
3801 |
+
handler.call(element, event);
|
3802 |
+
}
|
3803 |
+
|
3804 |
+
function specialMouseHandlerWrapper(target, event, handler) {
|
3805 |
+
// Refer to jQuery's implementation of mouseenter & mouseleave
|
3806 |
+
// Read about mouseenter and mouseleave:
|
3807 |
+
// http://www.quirksmode.org/js/events_mouse.html#link8
|
3808 |
+
var related = event.relatedTarget;
|
3809 |
+
// For mousenter/leave call the handler if related is outside the target.
|
3810 |
+
// NB: No relatedTarget if the mouse left/entered the browser window
|
3811 |
+
if (!related || (related !== target && !jqLiteContains.call(target, related))) {
|
3812 |
+
handler.call(target, event);
|
3813 |
+
}
|
3814 |
+
}
|
3815 |
|
3816 |
//////////////////////////////////////////
|
3817 |
// Functions iterating traversal.
|
3818 |
// These functions chain results into a single
|
3819 |
// selector.
|
3820 |
//////////////////////////////////////////
|
3821 |
+
forEach({
|
3822 |
+
removeData: jqLiteRemoveData,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3823 |
|
3824 |
+
on: function jqLiteOn(element, type, fn, unsupported) {
|
3825 |
+
if (isDefined(unsupported)) throw jqLiteMinErr('onargs', 'jqLite#on() does not support the `selector` or `eventData` parameters');
|
|
|
|
|
|
|
|
|
|
|
3826 |
|
3827 |
+
// Do not add event handlers to non-elements because they will not be cleaned up.
|
3828 |
+
if (!jqLiteAcceptsData(element)) {
|
3829 |
+
return;
|
3830 |
+
}
|
3831 |
|
3832 |
+
var expandoStore = jqLiteExpandoStore(element, true);
|
3833 |
+
var events = expandoStore.events;
|
3834 |
+
var handle = expandoStore.handle;
|
3835 |
|
3836 |
+
if (!handle) {
|
3837 |
+
handle = expandoStore.handle = createEventHandler(element, events);
|
3838 |
+
}
|
|
|
|
|
|
|
|
|
3839 |
|
3840 |
+
// http://jsperf.com/string-indexof-vs-split
|
3841 |
+
var types = type.indexOf(' ') >= 0 ? type.split(' ') : [type];
|
3842 |
+
var i = types.length;
|
3843 |
|
3844 |
+
var addHandler = function(type, specialHandlerWrapper, noEventListener) {
|
3845 |
+
var eventFns = events[type];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3846 |
|
3847 |
+
if (!eventFns) {
|
3848 |
+
eventFns = events[type] = [];
|
3849 |
+
eventFns.specialHandlerWrapper = specialHandlerWrapper;
|
3850 |
+
if (type !== '$destroy' && !noEventListener) {
|
3851 |
+
element.addEventListener(type, handle);
|
3852 |
+
}
|
3853 |
+
}
|
3854 |
|
3855 |
+
eventFns.push(fn);
|
3856 |
+
};
|
3857 |
|
3858 |
+
while (i--) {
|
3859 |
+
type = types[i];
|
3860 |
+
if (MOUSE_EVENT_MAP[type]) {
|
3861 |
+
addHandler(MOUSE_EVENT_MAP[type], specialMouseHandlerWrapper);
|
3862 |
+
addHandler(type, undefined, true);
|
3863 |
+
} else {
|
3864 |
+
addHandler(type);
|
3865 |
+
}
|
3866 |
+
}
|
3867 |
+
},
|
3868 |
|
3869 |
+
off: jqLiteOff,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3870 |
|
3871 |
+
one: function(element, type, fn) {
|
3872 |
+
element = jqLite(element);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3873 |
|
3874 |
+
//add the listener twice so that when it is called
|
3875 |
+
//you can remove the original function and still be
|
3876 |
+
//able to call element.off(ev, fn) normally
|
3877 |
+
element.on(type, function onFn() {
|
3878 |
+
element.off(type, fn);
|
3879 |
+
element.off(type, onFn);
|
3880 |
+
});
|
3881 |
+
element.on(type, fn);
|
3882 |
+
},
|
3883 |
+
|
3884 |
+
replaceWith: function(element, replaceNode) {
|
3885 |
+
var index, parent = element.parentNode;
|
3886 |
+
jqLiteDealoc(element);
|
3887 |
+
forEach(new JQLite(replaceNode), function(node) {
|
3888 |
+
if (index) {
|
3889 |
+
parent.insertBefore(node, index.nextSibling);
|
3890 |
+
} else {
|
3891 |
+
parent.replaceChild(node, element);
|
3892 |
+
}
|
3893 |
+
index = node;
|
3894 |
+
});
|
3895 |
+
},
|
3896 |
|
3897 |
+
children: function(element) {
|
3898 |
+
var children = [];
|
3899 |
+
forEach(element.childNodes, function(element) {
|
3900 |
+
if (element.nodeType === NODE_TYPE_ELEMENT) {
|
3901 |
+
children.push(element);
|
3902 |
+
}
|
3903 |
+
});
|
3904 |
+
return children;
|
3905 |
+
},
|
3906 |
|
3907 |
+
contents: function(element) {
|
3908 |
+
return element.contentDocument || element.childNodes || [];
|
3909 |
+
},
|
3910 |
|
3911 |
+
append: function(element, node) {
|
3912 |
+
var nodeType = element.nodeType;
|
3913 |
+
if (nodeType !== NODE_TYPE_ELEMENT && nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT) return;
|
|
|
|
|
3914 |
|
3915 |
+
node = new JQLite(node);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3916 |
|
3917 |
+
for (var i = 0, ii = node.length; i < ii; i++) {
|
3918 |
+
var child = node[i];
|
3919 |
+
element.appendChild(child);
|
3920 |
+
}
|
3921 |
+
},
|
3922 |
|
3923 |
+
prepend: function(element, node) {
|
3924 |
+
if (element.nodeType === NODE_TYPE_ELEMENT) {
|
3925 |
+
var index = element.firstChild;
|
3926 |
+
forEach(new JQLite(node), function(child) {
|
3927 |
+
element.insertBefore(child, index);
|
3928 |
+
});
|
3929 |
+
}
|
3930 |
+
},
|
3931 |
|
3932 |
+
wrap: function(element, wrapNode) {
|
3933 |
+
jqLiteWrapNode(element, jqLite(wrapNode).eq(0).clone()[0]);
|
3934 |
+
},
|
3935 |
|
3936 |
+
remove: jqLiteRemove,
|
|
|
3937 |
|
3938 |
+
detach: function(element) {
|
3939 |
+
jqLiteRemove(element, true);
|
3940 |
+
},
|
3941 |
|
3942 |
+
after: function(element, newElement) {
|
3943 |
+
var index = element, parent = element.parentNode;
|
|
|
|
|
|
|
|
|
|
|
3944 |
|
3945 |
+
if (parent) {
|
3946 |
+
newElement = new JQLite(newElement);
|
3947 |
|
3948 |
+
for (var i = 0, ii = newElement.length; i < ii; i++) {
|
3949 |
+
var node = newElement[i];
|
3950 |
+
parent.insertBefore(node, index.nextSibling);
|
3951 |
+
index = node;
|
3952 |
+
}
|
3953 |
+
}
|
3954 |
+
},
|
|
|
|
|
|
|
|
|
3955 |
|
3956 |
+
addClass: jqLiteAddClass,
|
3957 |
+
removeClass: jqLiteRemoveClass,
|
|
|
|
|
3958 |
|
3959 |
+
toggleClass: function(element, selector, condition) {
|
3960 |
+
if (selector) {
|
3961 |
+
forEach(selector.split(' '), function(className) {
|
3962 |
+
var classCondition = condition;
|
3963 |
+
if (isUndefined(classCondition)) {
|
3964 |
+
classCondition = !jqLiteHasClass(element, className);
|
3965 |
+
}
|
3966 |
+
(classCondition ? jqLiteAddClass : jqLiteRemoveClass)(element, className);
|
3967 |
+
});
|
3968 |
+
}
|
3969 |
+
},
|
3970 |
|
3971 |
+
parent: function(element) {
|
3972 |
+
var parent = element.parentNode;
|
3973 |
+
return parent && parent.nodeType !== NODE_TYPE_DOCUMENT_FRAGMENT ? parent : null;
|
3974 |
+
},
|
|
|
|
|
|
|
3975 |
|
3976 |
+
next: function(element) {
|
3977 |
+
return element.nextElementSibling;
|
3978 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3979 |
|
3980 |
+
find: function(element, selector) {
|
3981 |
+
if (element.getElementsByTagName) {
|
3982 |
+
return element.getElementsByTagName(selector);
|
3983 |
+
} else {
|
3984 |
+
return [];
|
3985 |
+
}
|
3986 |
+
},
|
3987 |
+
|
3988 |
+
clone: jqLiteClone,
|
3989 |
+
|
3990 |
+
triggerHandler: function(element, event, extraParameters) {
|
3991 |
+
|
3992 |
+
var dummyEvent, eventFnsCopy, handlerArgs;
|
3993 |
+
var eventName = event.type || event;
|
3994 |
+
var expandoStore = jqLiteExpandoStore(element);
|
3995 |
+
var events = expandoStore && expandoStore.events;
|
3996 |
+
var eventFns = events && events[eventName];
|
3997 |
+
|
3998 |
+
if (eventFns) {
|
3999 |
+
// Create a dummy event to pass to the handlers
|
4000 |
+
dummyEvent = {
|
4001 |
+
preventDefault: function() { this.defaultPrevented = true; },
|
4002 |
+
isDefaultPrevented: function() { return this.defaultPrevented === true; },
|
4003 |
+
stopImmediatePropagation: function() { this.immediatePropagationStopped = true; },
|
4004 |
+
isImmediatePropagationStopped: function() { return this.immediatePropagationStopped === true; },
|
4005 |
+
stopPropagation: noop,
|
4006 |
+
type: eventName,
|
4007 |
+
target: element
|
4008 |
+
};
|
4009 |
+
|
4010 |
+
// If a custom event was provided then extend our dummy event with it
|
4011 |
+
if (event.type) {
|
4012 |
+
dummyEvent = extend(dummyEvent, event);
|
4013 |
+
}
|
4014 |
|
4015 |
+
// Copy event handlers in case event handlers array is modified during execution.
|
4016 |
+
eventFnsCopy = shallowCopy(eventFns);
|
4017 |
+
handlerArgs = extraParameters ? [dummyEvent].concat(extraParameters) : [dummyEvent];
|
4018 |
|
4019 |
+
forEach(eventFnsCopy, function(fn) {
|
4020 |
+
if (!dummyEvent.isImmediatePropagationStopped()) {
|
4021 |
+
fn.apply(element, handlerArgs);
|
|
|
|
|
|
|
4022 |
}
|
4023 |
+
});
|
4024 |
+
}
|
4025 |
+
}
|
4026 |
+
}, function(fn, name) {
|
4027 |
+
/**
|
4028 |
+
* chaining functions
|
4029 |
+
*/
|
4030 |
+
JQLite.prototype[name] = function(arg1, arg2, arg3) {
|
4031 |
+
var value;
|
4032 |
+
|
4033 |
+
for (var i = 0, ii = this.length; i < ii; i++) {
|
4034 |
+
if (isUndefined(value)) {
|
4035 |
+
value = fn(this[i], arg1, arg2, arg3);
|
4036 |
+
if (isDefined(value)) {
|
4037 |
+
// any function which returns a value needs to be wrapped
|
4038 |
+
value = jqLite(value);
|
4039 |
+
}
|
4040 |
+
} else {
|
4041 |
+
jqLiteAddNodes(value, fn(this[i], arg1, arg2, arg3));
|
4042 |
+
}
|
4043 |
+
}
|
4044 |
+
return isDefined(value) ? value : this;
|
4045 |
+
};
|
4046 |
+
});
|
4047 |
|
4048 |
// bind legacy bind/unbind to on/off
|
4049 |
+
JQLite.prototype.bind = JQLite.prototype.on;
|
4050 |
+
JQLite.prototype.unbind = JQLite.prototype.off;
|
4051 |
|
4052 |
|
4053 |
// Provider for private $$jqLite service
|
4054 |
+
/** @this */
|
4055 |
+
function $$jqLiteProvider() {
|
4056 |
+
this.$get = function $$jqLite() {
|
4057 |
+
return extend(JQLite, {
|
4058 |
+
hasClass: function(node, classes) {
|
4059 |
+
if (node.attr) node = node[0];
|
4060 |
+
return jqLiteHasClass(node, classes);
|
4061 |
+
},
|
4062 |
+
addClass: function(node, classes) {
|
4063 |
+
if (node.attr) node = node[0];
|
4064 |
+
return jqLiteAddClass(node, classes);
|
4065 |
+
},
|
4066 |
+
removeClass: function(node, classes) {
|
4067 |
+
if (node.attr) node = node[0];
|
4068 |
+
return jqLiteRemoveClass(node, classes);
|
4069 |
+
}
|
4070 |
+
});
|
4071 |
+
};
|
4072 |
+
}
|
4073 |
|
4074 |
+
/**
|
4075 |
+
* Computes a hash of an 'obj'.
|
4076 |
+
* Hash of a:
|
4077 |
+
* string is string
|
4078 |
+
* number is number as string
|
4079 |
+
* object is either result of calling $$hashKey function on the object or uniquely generated id,
|
4080 |
+
* that is also assigned to the $$hashKey property of the object.
|
4081 |
+
*
|
4082 |
+
* @param obj
|
4083 |
+
* @returns {string} hash string such that the same input will have the same hash string.
|
4084 |
+
* The resulting string key is in 'type:hashKey' format.
|
4085 |
+
*/
|
4086 |
+
function hashKey(obj, nextUidFn) {
|
4087 |
+
var key = obj && obj.$$hashKey;
|
4088 |
|
4089 |
+
if (key) {
|
4090 |
+
if (typeof key === 'function') {
|
4091 |
+
key = obj.$$hashKey();
|
4092 |
+
}
|
4093 |
+
return key;
|
4094 |
+
}
|
4095 |
|
4096 |
+
var objType = typeof obj;
|
4097 |
+
if (objType === 'function' || (objType === 'object' && obj !== null)) {
|
4098 |
+
key = obj.$$hashKey = objType + ':' + (nextUidFn || nextUid)();
|
4099 |
+
} else {
|
4100 |
+
key = objType + ':' + obj;
|
4101 |
+
}
|
4102 |
|
4103 |
+
return key;
|
4104 |
+
}
|
4105 |
|
4106 |
// A minimal ES2015 Map implementation.
|
4107 |
// Should be bug/feature equivalent to the native implementations of supported browsers
|
4108 |
// (for the features required in Angular).
|
4109 |
// See https://kangax.github.io/compat-table/es6/#test-Map
|
4110 |
+
var nanKey = Object.create(null);
|
4111 |
+
function NgMapShim() {
|
4112 |
+
this._keys = [];
|
4113 |
+
this._values = [];
|
4114 |
+
this._lastKey = NaN;
|
4115 |
+
this._lastIndex = -1;
|
4116 |
+
}
|
4117 |
+
NgMapShim.prototype = {
|
4118 |
+
_idx: function(key) {
|
4119 |
+
if (key !== this._lastKey) {
|
4120 |
+
this._lastKey = key;
|
4121 |
+
this._lastIndex = this._keys.indexOf(key);
|
4122 |
+
}
|
4123 |
+
return this._lastIndex;
|
4124 |
+
},
|
4125 |
+
_transformKey: function(key) {
|
4126 |
+
return isNumberNaN(key) ? nanKey : key;
|
4127 |
+
},
|
4128 |
+
get: function(key) {
|
4129 |
+
key = this._transformKey(key);
|
4130 |
+
var idx = this._idx(key);
|
4131 |
+
if (idx !== -1) {
|
4132 |
+
return this._values[idx];
|
4133 |
+
}
|
4134 |
+
},
|
4135 |
+
has: function(key) {
|
4136 |
+
key = this._transformKey(key);
|
4137 |
+
var idx = this._idx(key);
|
4138 |
+
return idx !== -1;
|
4139 |
+
},
|
4140 |
+
set: function(key, value) {
|
4141 |
+
key = this._transformKey(key);
|
4142 |
+
var idx = this._idx(key);
|
4143 |
+
if (idx === -1) {
|
4144 |
+
idx = this._lastIndex = this._keys.length;
|
4145 |
+
}
|
4146 |
+
this._keys[idx] = key;
|
4147 |
+
this._values[idx] = value;
|
4148 |
+
|
4149 |
+
// Support: IE11
|
4150 |
+
// Do not `return this` to simulate the partial IE11 implementation
|
4151 |
+
},
|
4152 |
+
delete: function(key) {
|
4153 |
+
key = this._transformKey(key);
|
4154 |
+
var idx = this._idx(key);
|
4155 |
+
if (idx === -1) {
|
4156 |
+
return false;
|
4157 |
+
}
|
4158 |
+
this._keys.splice(idx, 1);
|
4159 |
+
this._values.splice(idx, 1);
|
4160 |
+
this._lastKey = NaN;
|
4161 |
+
this._lastIndex = -1;
|
4162 |
+
return true;
|
4163 |
+
}
|
4164 |
+
};
|
4165 |
|
4166 |
// For now, always use `NgMapShim`, even if `window.Map` is available. Some native implementations
|
4167 |
// are still buggy (often in subtle ways) and can cause hard-to-debug failures. When native `Map`
|
4168 |
// implementations get more stable, we can reconsider switching to `window.Map` (when available).
|
4169 |
+
var NgMap = NgMapShim;
|
4170 |
|
4171 |
+
var $$MapProvider = [/** @this */function() {
|
4172 |
+
this.$get = [function() {
|
4173 |
+
return NgMap;
|
4174 |
+
}];
|
4175 |
+
}];
|
4176 |
|
4177 |
+
/**
|
4178 |
+
* @ngdoc function
|
4179 |
+
* @module ng
|
4180 |
+
* @name angular.injector
|
4181 |
+
* @kind function
|
4182 |
+
*
|
4183 |
+
* @description
|
4184 |
+
* Creates an injector object that can be used for retrieving services as well as for
|
4185 |
+
* dependency injection (see {@link guide/di dependency injection}).
|
4186 |
+
*
|
4187 |
+
* @param {Array.<string|Function>} modules A list of module functions or their aliases. See
|
4188 |
+
* {@link angular.module}. The `ng` module must be explicitly added.
|
4189 |
+
* @param {boolean=} [strictDi=false] Whether the injector should be in strict mode, which
|
4190 |
+
* disallows argument name annotation inference.
|
4191 |
+
* @returns {injector} Injector object. See {@link auto.$injector $injector}.
|
4192 |
+
*
|
4193 |
+
* @example
|
4194 |
+
* Typical usage
|
4195 |
+
* ```js
|
4196 |
+
* // create an injector
|
4197 |
+
* var $injector = angular.injector(['ng']);
|
4198 |
+
*
|
4199 |
+
* // use the injector to kick off your application
|
4200 |
+
* // use the type inference to auto inject arguments, or use implicit injection
|
4201 |
+
* $injector.invoke(function($rootScope, $compile, $document) {
|
4202 |
* $compile($document)($rootScope);
|
4203 |
* $rootScope.$digest();
|
4204 |
* });
|
4205 |
+
* ```
|
4206 |
+
*
|
4207 |
+
* Sometimes you want to get access to the injector of a currently running AngularJS app
|
4208 |
+
* from outside AngularJS. Perhaps, you want to inject and compile some markup after the
|
4209 |
+
* application has been bootstrapped. You can do this using the extra `injector()` added
|
4210 |
+
* to JQuery/jqLite elements. See {@link angular.element}.
|
4211 |
+
*
|
4212 |
+
* *This is fairly rare but could be the case if a third party library is injecting the
|
4213 |
+
* markup.*
|
4214 |
+
*
|
4215 |
+
* In the following example a new block of HTML containing a `ng-controller`
|
4216 |
+
* directive is added to the end of the document body by JQuery. We then compile and link
|
4217 |
+
* it into the current AngularJS scope.
|
4218 |
+
*
|
4219 |
+
* ```js
|
4220 |
+
* var $div = $('<div ng-controller="MyCtrl">{{content.label}}</div>');
|
4221 |
+
* $(document.body).append($div);
|
4222 |
+
*
|
4223 |
+
* angular.element(document).injector().invoke(function($compile) {
|
4224 |
* var scope = angular.element($div).scope();
|
4225 |
* $compile($div)(scope);
|
4226 |
* });
|
4227 |
+
* ```
|
4228 |
+
*/
|
|
|
4229 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4230 |
|
4231 |
+
/**
|
4232 |
+
* @ngdoc module
|
4233 |
+
* @name auto
|
4234 |
+
* @installation
|
4235 |
+
* @description
|
4236 |
+
*
|
4237 |
+
* Implicit module which gets automatically added to each {@link auto.$injector $injector}.
|
4238 |
+
*/
|
4239 |
|
4240 |
+
var ARROW_ARG = /^([^(]+?)=>/;
|
4241 |
+
var FN_ARGS = /^[^(]*\(\s*([^)]*)\)/m;
|
4242 |
+
var FN_ARG_SPLIT = /,/;
|
4243 |
+
var FN_ARG = /^\s*(_?)(\S+?)\1\s*$/;
|
4244 |
+
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
|
4245 |
+
var $injectorMinErr = minErr('$injector');
|
4246 |
|
4247 |
+
function stringifyFn(fn) {
|
4248 |
+
return Function.prototype.toString.call(fn);
|
4249 |
+
}
|
|
|
|
|
4250 |
|
4251 |
+
function extractArgs(fn) {
|
4252 |
+
var fnText = stringifyFn(fn).replace(STRIP_COMMENTS, ''),
|
4253 |
+
args = fnText.match(ARROW_ARG) || fnText.match(FN_ARGS);
|
4254 |
+
return args;
|
4255 |
+
}
|
|
|
|
|
|
|
|
|
4256 |
|
4257 |
+
function anonFn(fn) {
|
4258 |
+
// For anonymous functions, showing at the very least the function signature can help in
|
4259 |
+
// debugging.
|
4260 |
+
var args = extractArgs(fn);
|
4261 |
+
if (args) {
|
4262 |
+
return 'function(' + (args[1] || '').replace(/[\s\r\n]+/, ' ') + ')';
|
4263 |
+
}
|
4264 |
+
return 'fn';
|
4265 |
+
}
|
4266 |
|
4267 |
+
function annotate(fn, strictDi, name) {
|
4268 |
+
var $inject,
|
4269 |
+
argDecl,
|
4270 |
+
last;
|
4271 |
+
|
4272 |
+
if (typeof fn === 'function') {
|
4273 |
+
if (!($inject = fn.$inject)) {
|
4274 |
+
$inject = [];
|
4275 |
+
if (fn.length) {
|
4276 |
+
if (strictDi) {
|
4277 |
+
if (!isString(name) || !name) {
|
4278 |
+
name = fn.name || anonFn(fn);
|
4279 |
+
}
|
4280 |
+
throw $injectorMinErr('strictdi',
|
4281 |
+
'{0} is not using explicit annotation and cannot be invoked in strict mode', name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4282 |
}
|
4283 |
+
argDecl = extractArgs(fn);
|
4284 |
+
forEach(argDecl[1].split(FN_ARG_SPLIT), function(arg) {
|
4285 |
+
arg.replace(FN_ARG, function(all, underscore, name) {
|
4286 |
+
$inject.push(name);
|
4287 |
+
});
|
4288 |
+
});
|
4289 |
+
}
|
4290 |
+
fn.$inject = $inject;
|
4291 |
+
}
|
4292 |
+
} else if (isArray(fn)) {
|
4293 |
+
last = fn.length - 1;
|
4294 |
+
assertArgFn(fn[last], 'fn');
|
4295 |
+
$inject = fn.slice(0, last);
|
4296 |
+
} else {
|
4297 |
+
assertArgFn(fn, 'fn', true);
|
4298 |
+
}
|
4299 |
+
return $inject;
|
4300 |
+
}
|
4301 |
|
4302 |
///////////////////////////////////////
|
4303 |
|
4304 |
+
/**
|
4305 |
+
* @ngdoc service
|
4306 |
+
* @name $injector
|
4307 |
+
*
|
4308 |
+
* @description
|
4309 |
+
*
|
4310 |
+
* `$injector` is used to retrieve object instances as defined by
|
4311 |
+
* {@link auto.$provide provider}, instantiate types, invoke methods,
|
4312 |
+
* and load modules.
|
4313 |
+
*
|
4314 |
+
* The following always holds true:
|
4315 |
+
*
|
4316 |
+
* ```js
|
4317 |
+
* var $injector = angular.injector();
|
4318 |
+
* expect($injector.get('$injector')).toBe($injector);
|
4319 |
+
* expect($injector.invoke(function($injector) {
|
4320 |
* return $injector;
|
4321 |
* })).toBe($injector);
|
4322 |
+
* ```
|
4323 |
+
*
|
4324 |
+
* ## Injection Function Annotation
|
4325 |
+
*
|
4326 |
+
* JavaScript does not have annotations, and annotations are needed for dependency injection. The
|
4327 |
+
* following are all valid ways of annotating function with injection arguments and are equivalent.
|
4328 |
+
*
|
4329 |
+
* ```js
|
4330 |
+
* // inferred (only works if code not minified/obfuscated)
|
4331 |
+
* $injector.invoke(function(serviceA){});
|
4332 |
+
*
|
4333 |
+
* // annotated
|
4334 |
+
* function explicit(serviceA) {};
|
4335 |
+
* explicit.$inject = ['serviceA'];
|
4336 |
+
* $injector.invoke(explicit);
|
4337 |
+
*
|
4338 |
+
* // inline
|
4339 |
+
* $injector.invoke(['serviceA', function(serviceA){}]);
|
4340 |
+
* ```
|
4341 |
+
*
|
4342 |
+
* ### Inference
|
4343 |
+
*
|
4344 |
+
* In JavaScript calling `toString()` on a function returns the function definition. The definition
|
4345 |
+
* can then be parsed and the function arguments can be extracted. This method of discovering
|
4346 |
+
* annotations is disallowed when the injector is in strict mode.
|
4347 |
+
* *NOTE:* This does not work with minification, and obfuscation tools since these tools change the
|
4348 |
+
* argument names.
|
4349 |
+
*
|
4350 |
+
* ### `$inject` Annotation
|
4351 |
+
* By adding an `$inject` property onto a function the injection parameters can be specified.
|
4352 |
+
*
|
4353 |
+
* ### Inline
|
4354 |
+
* As an array of injection names, where the last item in the array is the function to call.
|
4355 |
+
*/
|
4356 |
|
4357 |
+
/**
|
4358 |
+
* @ngdoc property
|
4359 |
+
* @name $injector#modules
|
4360 |
+
* @type {Object}
|
4361 |
+
* @description
|
4362 |
+
* A hash containing all the modules that have been loaded into the
|
4363 |
+
* $injector.
|
4364 |
+
*
|
4365 |
+
* You can use this property to find out information about a module via the
|
4366 |
+
* {@link angular.Module#info `myModule.info(...)`} method.
|
4367 |
+
*
|
4368 |
+
* For example:
|
4369 |
+
*
|
4370 |
+
* ```
|
4371 |
+
* var info = $injector.modules['ngAnimate'].info();
|
4372 |
+
* ```
|
4373 |
+
*
|
4374 |
+
* **Do not use this property to attempt to modify the modules after the application
|
4375 |
+
* has been bootstrapped.**
|
4376 |
+
*/
|
4377 |
|
4378 |
|
4379 |
+
/**
|
4380 |
+
* @ngdoc method
|
4381 |
+
* @name $injector#get
|
4382 |
+
*
|
4383 |
+
* @description
|
4384 |
+
* Return an instance of the service.
|
4385 |
+
*
|
4386 |
+
* @param {string} name The name of the instance to retrieve.
|
4387 |
+
* @param {string=} caller An optional string to provide the origin of the function call for error messages.
|
4388 |
+
* @return {*} The instance.
|
4389 |
+
*/
|
4390 |
|
4391 |
+
/**
|
4392 |
+
* @ngdoc method
|
4393 |
+
* @name $injector#invoke
|
4394 |
+
*
|
4395 |
+
* @description
|
4396 |
+
* Invoke the method and supply the method arguments from the `$injector`.
|
4397 |
+
*
|
4398 |
+
* @param {Function|Array.<string|Function>} fn The injectable function to invoke. Function parameters are
|
4399 |
+
* injected according to the {@link guide/di $inject Annotation} rules.
|
4400 |
+
* @param {Object=} self The `this` for the invoked method.
|
4401 |
+
* @param {Object=} locals Optional object. If preset then any argument names are read from this
|
4402 |
+
* object first, before the `$injector` is consulted.
|
4403 |
+
* @returns {*} the value returned by the invoked `fn` function.
|
4404 |
+
*/
|
4405 |
|
4406 |
+
/**
|
4407 |
+
* @ngdoc method
|
4408 |
+
* @name $injector#has
|
4409 |
+
*
|
4410 |
+
* @description
|
4411 |
+
* Allows the user to query if the particular service exists.
|
4412 |
+
*
|
4413 |
+
* @param {string} name Name of the service to query.
|
4414 |
+
* @returns {boolean} `true` if injector has given service.
|
4415 |
+
*/
|
4416 |
|
4417 |
+
/**
|
4418 |
+
* @ngdoc method
|
4419 |
+
* @name $injector#instantiate
|
4420 |
+
* @description
|
4421 |
+
* Create a new instance of JS type. The method takes a constructor function, invokes the new
|
4422 |
+
* operator, and supplies all of the arguments to the constructor function as specified by the
|
4423 |
+
* constructor annotation.
|
4424 |
+
*
|
4425 |
+
* @param {Function} Type Annotated constructor function.
|
4426 |
+
* @param {Object=} locals Optional object. If preset then any argument names are read from this
|
4427 |
+
* object first, before the `$injector` is consulted.
|
4428 |
+
* @returns {Object} new instance of `Type`.
|
4429 |
+
*/
|
4430 |
|
4431 |
+
/**
|
4432 |
+
* @ngdoc method
|
4433 |
+
* @name $injector#annotate
|
4434 |
+
*
|
4435 |
+
* @description
|
4436 |
+
* Returns an array of service names which the function is requesting for injection. This API is
|
4437 |
+
* used by the injector to determine which services need to be injected into the function when the
|
4438 |
+
* function is invoked. There are three ways in which the function can be annotated with the needed
|
4439 |
+
* dependencies.
|
4440 |
+
*
|
4441 |
+
* #### Argument names
|
4442 |
+
*
|
4443 |
+
* The simplest form is to extract the dependencies from the arguments of the function. This is done
|
4444 |
+
* by converting the function into a string using `toString()` method and extracting the argument
|
4445 |
+
* names.
|
4446 |
+
* ```js
|
4447 |
+
* // Given
|
4448 |
+
* function MyController($scope, $route) {
|
4449 |
* // ...
|
4450 |
* }
|
4451 |
+
*
|
4452 |
+
* // Then
|
4453 |
+
* expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
|
4454 |
+
* ```
|
4455 |
+
*
|
4456 |
+
* You can disallow this method by using strict injection mode.
|
4457 |
+
*
|
4458 |
+
* This method does not work with code minification / obfuscation. For this reason the following
|
4459 |
+
* annotation strategies are supported.
|
4460 |
+
*
|
4461 |
+
* #### The `$inject` property
|
4462 |
+
*
|
4463 |
+
* If a function has an `$inject` property and its value is an array of strings, then the strings
|
4464 |
+
* represent names of services to be injected into the function.
|
4465 |
+
* ```js
|
4466 |
+
* // Given
|
4467 |
+
* var MyController = function(obfuscatedScope, obfuscatedRoute) {
|
4468 |
* // ...
|
4469 |
* }
|
4470 |
+
* // Define function dependencies
|
4471 |
+
* MyController['$inject'] = ['$scope', '$route'];
|
4472 |
+
*
|
4473 |
+
* // Then
|
4474 |
+
* expect(injector.annotate(MyController)).toEqual(['$scope', '$route']);
|
4475 |
+
* ```
|
4476 |
+
*
|
4477 |
+
* #### The array notation
|
4478 |
+
*
|
4479 |
+
* It is often desirable to inline Injected functions and that's when setting the `$inject` property
|
4480 |
+
* is very inconvenient. In these situations using the array notation to specify the dependencies in
|
4481 |
+
* a way that survives minification is a better choice:
|
4482 |
+
*
|
4483 |
+
* ```js
|
4484 |
+
* // We wish to write this (not minification / obfuscation safe)
|
4485 |
+
* injector.invoke(function($compile, $rootScope) {
|
4486 |
* // ...
|
4487 |
* });
|
4488 |
+
*
|
4489 |
+
* // We are forced to write break inlining
|
4490 |
+
* var tmpFn = function(obfuscatedCompile, obfuscatedRootScope) {
|
4491 |
* // ...
|
4492 |
* };
|
4493 |
+
* tmpFn.$inject = ['$compile', '$rootScope'];
|
4494 |
+
* injector.invoke(tmpFn);
|
4495 |
+
*
|
4496 |
+
* // To better support inline function the inline annotation is supported
|
4497 |
+
* injector.invoke(['$compile', '$rootScope', function(obfCompile, obfRootScope) {
|
4498 |
* // ...
|
4499 |
* }]);
|
4500 |
+
*
|
4501 |
+
* // Therefore
|
4502 |
+
* expect(injector.annotate(
|
4503 |
+
* ['$compile', '$rootScope', function(obfus_$compile, obfus_$rootScope) {}])
|
4504 |
+
* ).toEqual(['$compile', '$rootScope']);
|
4505 |
+
* ```
|
4506 |
+
*
|
4507 |
+
* @param {Function|Array.<string|Function>} fn Function for which dependent service names need to
|
4508 |
+
* be retrieved as described above.
|
4509 |
+
*
|
4510 |
+
* @param {boolean=} [strictDi=false] Disallow argument name annotation inference.
|
4511 |
+
*
|
4512 |
+
* @returns {Array.<string>} The names of the services which the function requires.
|
4513 |
+
*/
|
4514 |
+
/**
|
4515 |
+
* @ngdoc method
|
4516 |
+
* @name $injector#loadNewModules
|
4517 |
+
*
|
4518 |
+
* @description
|
4519 |
+
*
|
4520 |
+
* **This is a dangerous API, which you use at your own risk!**
|
4521 |
+
*
|
4522 |
+
* Add the specified modules to the current injector.
|
4523 |
+
*
|
4524 |
+
* This method will add each of the injectables to the injector and execute all of the config and run
|
4525 |
+
* blocks for each module passed to the method.
|
4526 |
+
*
|
4527 |
+
* If a module has already been loaded into the injector then it will not be loaded again.
|
4528 |
+
*
|
4529 |
+
* * The application developer is responsible for loading the code containing the modules; and for
|
4530 |
+
* ensuring that lazy scripts are not downloaded and executed more often that desired.
|
4531 |
+
* * Previously compiled HTML will not be affected by newly loaded directives, filters and components.
|
4532 |
+
* * Modules cannot be unloaded.
|
4533 |
+
*
|
4534 |
+
* You can use {@link $injector#modules `$injector.modules`} to check whether a module has been loaded
|
4535 |
+
* into the injector, which may indicate whether the script has been executed already.
|
4536 |
+
*
|
4537 |
+
* @example
|
4538 |
+
* Here is an example of loading a bundle of modules, with a utility method called `getScript`:
|
4539 |
+
*
|
4540 |
+
* ```javascript
|
4541 |
+
* app.factory('loadModule', function($injector) {
|
4542 |
* return function loadModule(moduleName, bundleUrl) {
|
4543 |
* return getScript(bundleUrl).then(function() { $injector.loadNewModules([moduleName]); });
|
4544 |
* };
|
4545 |
* })
|
4546 |
+
* ```
|
4547 |
+
*
|
4548 |
+
* @param {Array<String|Function|Array>=} mods an array of modules to load into the application.
|
4549 |
+
* Each item in the array should be the name of a predefined module or a (DI annotated)
|
4550 |
+
* function that will be invoked by the injector as a `config` block.
|
4551 |
+
* See: {@link angular.module modules}
|
4552 |
+
*/
|
4553 |
|
4554 |
|
4555 |
+
/**
|
4556 |
+
* @ngdoc service
|
4557 |
+
* @name $provide
|
4558 |
+
*
|
4559 |
+
* @description
|
4560 |
+
*
|
4561 |
+
* The {@link auto.$provide $provide} service has a number of methods for registering components
|
4562 |
+
* with the {@link auto.$injector $injector}. Many of these functions are also exposed on
|
4563 |
+
* {@link angular.Module}.
|
4564 |
+
*
|
4565 |
+
* An AngularJS **service** is a singleton object created by a **service factory**. These **service
|
4566 |
+
* factories** are functions which, in turn, are created by a **service provider**.
|
4567 |
+
* The **service providers** are constructor functions. When instantiated they must contain a
|
4568 |
+
* property called `$get`, which holds the **service factory** function.
|
4569 |
+
*
|
4570 |
+
* When you request a service, the {@link auto.$injector $injector} is responsible for finding the
|
4571 |
+
* correct **service provider**, instantiating it and then calling its `$get` **service factory**
|
4572 |
+
* function to get the instance of the **service**.
|
4573 |
+
*
|
4574 |
+
* Often services have no configuration options and there is no need to add methods to the service
|
4575 |
+
* provider. The provider will be no more than a constructor function with a `$get` property. For
|
4576 |
+
* these cases the {@link auto.$provide $provide} service has additional helper methods to register
|
4577 |
+
* services without specifying a provider.
|
4578 |
+
*
|
4579 |
+
* * {@link auto.$provide#provider provider(name, provider)} - registers a **service provider** with the
|
4580 |
+
* {@link auto.$injector $injector}
|
4581 |
+
* * {@link auto.$provide#constant constant(name, obj)} - registers a value/object that can be accessed by
|
4582 |
+
* providers and services.
|
4583 |
+
* * {@link auto.$provide#value value(name, obj)} - registers a value/object that can only be accessed by
|
4584 |
+
* services, not providers.
|
4585 |
+
* * {@link auto.$provide#factory factory(name, fn)} - registers a service **factory function**
|
4586 |
+
* that will be wrapped in a **service provider** object, whose `$get` property will contain the
|
4587 |
+
* given factory function.
|
4588 |
+
* * {@link auto.$provide#service service(name, Fn)} - registers a **constructor function**
|
4589 |
+
* that will be wrapped in a **service provider** object, whose `$get` property will instantiate
|
4590 |
+
* a new object using the given constructor function.
|
4591 |
+
* * {@link auto.$provide#decorator decorator(name, decorFn)} - registers a **decorator function** that
|
4592 |
+
* will be able to modify or replace the implementation of another service.
|
4593 |
+
*
|
4594 |
+
* See the individual methods for more information and examples.
|
4595 |
+
*/
|
4596 |
|
4597 |
+
/**
|
4598 |
+
* @ngdoc method
|
4599 |
+
* @name $provide#provider
|
4600 |
+
* @description
|
4601 |
+
*
|
4602 |
+
* Register a **provider function** with the {@link auto.$injector $injector}. Provider functions
|
4603 |
+
* are constructor functions, whose instances are responsible for "providing" a factory for a
|
4604 |
+
* service.
|
4605 |
+
*
|
4606 |
+
* Service provider names start with the name of the service they provide followed by `Provider`.
|
4607 |
+
* For example, the {@link ng.$log $log} service has a provider called
|
4608 |
+
* {@link ng.$logProvider $logProvider}.
|
4609 |
+
*
|
4610 |
+
* Service provider objects can have additional methods which allow configuration of the provider
|
4611 |
+
* and its service. Importantly, you can configure what kind of service is created by the `$get`
|
4612 |
+
* method, or how that service will act. For example, the {@link ng.$logProvider $logProvider} has a
|
4613 |
+
* method {@link ng.$logProvider#debugEnabled debugEnabled}
|
4614 |
+
* which lets you specify whether the {@link ng.$log $log} service will log debug messages to the
|
4615 |
+
* console or not.
|
4616 |
+
*
|
4617 |
+
* It is possible to inject other providers into the provider function,
|
4618 |
+
* but the injected provider must have been defined before the one that requires it.
|
4619 |
+
*
|
4620 |
+
* @param {string} name The name of the instance. NOTE: the provider will be available under `name +
|
4621 |
+
'Provider'` key.
|
4622 |
+
* @param {(Object|function())} provider If the provider is:
|
4623 |
+
*
|
4624 |
+
* - `Object`: then it should have a `$get` method. The `$get` method will be invoked using
|
4625 |
+
* {@link auto.$injector#invoke $injector.invoke()} when an instance needs to be created.
|
4626 |
+
* - `Constructor`: a new instance of the provider will be created using
|
4627 |
+
* {@link auto.$injector#instantiate $injector.instantiate()}, then treated as `object`.
|
4628 |
+
*
|
4629 |
+
* @returns {Object} registered provider instance
|
4630 |
|
4631 |
+
* @example
|
4632 |
+
*
|
4633 |
+
* The following example shows how to create a simple event tracking service and register it using
|
4634 |
+
* {@link auto.$provide#provider $provide.provider()}.
|
4635 |
+
*
|
4636 |
+
* ```js
|
4637 |
+
* // Define the eventTracker provider
|
4638 |
+
* function EventTrackerProvider() {
|
4639 |
* var trackingUrl = '/track';
|
4640 |
*
|
4641 |
* // A provider method for configuring where the tracked events should been saved
|
4661 |
* };
|
4662 |
* }];
|
4663 |
* }
|
4664 |
+
*
|
4665 |
+
* describe('eventTracker', function() {
|
4666 |
* var postSpy;
|
4667 |
*
|
4668 |
* beforeEach(module(function($provide) {
|
4690 |
* expect(postSpy.mostRecentCall.args[1]).toEqual({ 'login': 1 });
|
4691 |
* }));
|
4692 |
* });
|
4693 |
+
* ```
|
4694 |
+
*/
|
4695 |
|
4696 |
+
/**
|
4697 |
+
* @ngdoc method
|
4698 |
+
* @name $provide#factory
|
4699 |
+
* @description
|
4700 |
+
*
|
4701 |
+
* Register a **service factory**, which will be called to return the service instance.
|
4702 |
+
* This is short for registering a service where its provider consists of only a `$get` property,
|
4703 |
+
* which is the given service factory function.
|
4704 |
+
* You should use {@link auto.$provide#factory $provide.factory(getFn)} if you do not need to
|
4705 |
+
* configure your service in a provider.
|
4706 |
+
*
|
4707 |
+
* @param {string} name The name of the instance.
|
4708 |
+
* @param {Function|Array.<string|Function>} $getFn The injectable $getFn for the instance creation.
|
4709 |
+
* Internally this is a short hand for `$provide.provider(name, {$get: $getFn})`.
|
4710 |
+
* @returns {Object} registered provider instance
|
4711 |
+
*
|
4712 |
+
* @example
|
4713 |
+
* Here is an example of registering a service
|
4714 |
+
* ```js
|
4715 |
+
* $provide.factory('ping', ['$http', function($http) {
|
4716 |
* return function ping() {
|
4717 |
* return $http.send('/ping');
|
4718 |
* };
|
4719 |
* }]);
|
4720 |
+
* ```
|
4721 |
+
* You would then inject and use this service like this:
|
4722 |
+
* ```js
|
4723 |
+
* someModule.controller('Ctrl', ['ping', function(ping) {
|
4724 |
* ping();
|
4725 |
* }]);
|
4726 |
+
* ```
|
4727 |
+
*/
|
4728 |
|
4729 |
|
4730 |
+
/**
|
4731 |
+
* @ngdoc method
|
4732 |
+
* @name $provide#service
|
4733 |
+
* @description
|
4734 |
+
*
|
4735 |
+
* Register a **service constructor**, which will be invoked with `new` to create the service
|
4736 |
+
* instance.
|
4737 |
+
* This is short for registering a service where its provider's `$get` property is a factory
|
4738 |
+
* function that returns an instance instantiated by the injector from the service constructor
|
4739 |
+
* function.
|
4740 |
+
*
|
4741 |
+
* Internally it looks a bit like this:
|
4742 |
+
*
|
4743 |
+
* ```
|
4744 |
+
* {
|
4745 |
* $get: function() {
|
4746 |
* return $injector.instantiate(constructor);
|
4747 |
* }
|
4748 |
* }
|
4749 |
+
* ```
|
4750 |
+
*
|
4751 |
+
*
|
4752 |
+
* You should use {@link auto.$provide#service $provide.service(class)} if you define your service
|
4753 |
+
* as a type/class.
|
4754 |
+
*
|
4755 |
+
* @param {string} name The name of the instance.
|
4756 |
+
* @param {Function|Array.<string|Function>} constructor An injectable class (constructor function)
|
4757 |
+
* that will be instantiated.
|
4758 |
+
* @returns {Object} registered provider instance
|
4759 |
+
*
|
4760 |
+
* @example
|
4761 |
+
* Here is an example of registering a service using
|
4762 |
+
* {@link auto.$provide#service $provide.service(class)}.
|
4763 |
+
* ```js
|
4764 |
+
* var Ping = function($http) {
|
4765 |
* this.$http = $http;
|
4766 |
* };
|
4767 |
+
*
|
4768 |
+
* Ping.$inject = ['$http'];
|
4769 |
+
*
|
4770 |
+
* Ping.prototype.send = function() {
|
4771 |
* return this.$http.get('/ping');
|
4772 |
* };
|
4773 |
+
* $provide.service('ping', Ping);
|
4774 |
+
* ```
|
4775 |
+
* You would then inject and use this service like this:
|
4776 |
+
* ```js
|
4777 |
+
* someModule.controller('Ctrl', ['ping', function(ping) {
|
4778 |
* ping.send();
|
4779 |
* }]);
|
4780 |
+
* ```
|
4781 |
+
*/
|
4782 |
|
4783 |
|
4784 |
+
/**
|
4785 |
+
* @ngdoc method
|
4786 |
+
* @name $provide#value
|
4787 |
+
* @description
|
4788 |
+
*
|
4789 |
+
* Register a **value service** with the {@link auto.$injector $injector}, such as a string, a
|
4790 |
+
* number, an array, an object or a function. This is short for registering a service where its
|
4791 |
+
* provider's `$get` property is a factory function that takes no arguments and returns the **value
|
4792 |
+
* service**. That also means it is not possible to inject other services into a value service.
|
4793 |
+
*
|
4794 |
+
* Value services are similar to constant services, except that they cannot be injected into a
|
4795 |
+
* module configuration function (see {@link angular.Module#config}) but they can be overridden by
|
4796 |
+
* an AngularJS {@link auto.$provide#decorator decorator}.
|
4797 |
+
*
|
4798 |
+
* @param {string} name The name of the instance.
|
4799 |
+
* @param {*} value The value.
|
4800 |
+
* @returns {Object} registered provider instance
|
4801 |
+
*
|
4802 |
+
* @example
|
4803 |
+
* Here are some examples of creating value services.
|
4804 |
+
* ```js
|
4805 |
+
* $provide.value('ADMIN_USER', 'admin');
|
4806 |
+
*
|
4807 |
+
* $provide.value('RoleLookup', { admin: 0, writer: 1, reader: 2 });
|
4808 |
+
*
|
4809 |
+
* $provide.value('halfOf', function(value) {
|
4810 |
* return value / 2;
|
4811 |
* });
|
4812 |
+
* ```
|
4813 |
+
*/
|
4814 |
|
4815 |
|
4816 |
+
/**
|
4817 |
+
* @ngdoc method
|
4818 |
+
* @name $provide#constant
|
4819 |
+
* @description
|
4820 |
+
*
|
4821 |
+
* Register a **constant service** with the {@link auto.$injector $injector}, such as a string,
|
4822 |
+
* a number, an array, an object or a function. Like the {@link auto.$provide#value value}, it is not
|
4823 |
+
* possible to inject other services into a constant.
|
4824 |
+
*
|
4825 |
+
* But unlike {@link auto.$provide#value value}, a constant can be
|
4826 |
+
* injected into a module configuration function (see {@link angular.Module#config}) and it cannot
|
4827 |
+
* be overridden by an AngularJS {@link auto.$provide#decorator decorator}.
|
4828 |
+
*
|
4829 |
+
* @param {string} name The name of the constant.
|
4830 |
+
* @param {*} value The constant value.
|
4831 |
+
* @returns {Object} registered instance
|
4832 |
+
*
|
4833 |
+
* @example
|
4834 |
+
* Here a some examples of creating constants:
|
4835 |
+
* ```js
|
4836 |
+
* $provide.constant('SHARD_HEIGHT', 306);
|
4837 |
+
*
|
4838 |
+
* $provide.constant('MY_COLOURS', ['red', 'blue', 'grey']);
|
4839 |
+
*
|
4840 |
+
* $provide.constant('double', function(value) {
|
4841 |
* return value * 2;
|
4842 |
* });
|
4843 |
+
* ```
|
4844 |
+
*/
|
4845 |
|
4846 |
|
4847 |
+
/**
|
4848 |
+
* @ngdoc method
|
4849 |
+
* @name $provide#decorator
|
4850 |
+
* @description
|
4851 |
+
*
|
4852 |
+
* Register a **decorator function** with the {@link auto.$injector $injector}. A decorator function
|
4853 |
+
* intercepts the creation of a service, allowing it to override or modify the behavior of the
|
4854 |
+
* service. The return value of the decorator function may be the original service, or a new service
|
4855 |
+
* that replaces (or wraps and delegates to) the original service.
|
4856 |
+
*
|
4857 |
+
* You can find out more about using decorators in the {@link guide/decorators} guide.
|
4858 |
+
*
|
4859 |
+
* @param {string} name The name of the service to decorate.
|
4860 |
+
* @param {Function|Array.<string|Function>} decorator This function will be invoked when the service needs to be
|
4861 |
+
* provided and should return the decorated service instance. The function is called using
|
4862 |
+
* the {@link auto.$injector#invoke injector.invoke} method and is therefore fully injectable.
|
4863 |
+
* Local injection arguments:
|
4864 |
+
*
|
4865 |
+
* * `$delegate` - The original service instance, which can be replaced, monkey patched, configured,
|
4866 |
+
* decorated or delegated to.
|
4867 |
+
*
|
4868 |
+
* @example
|
4869 |
+
* Here we decorate the {@link ng.$log $log} service to convert warnings to errors by intercepting
|
4870 |
+
* calls to {@link ng.$log#error $log.warn()}.
|
4871 |
+
* ```js
|
4872 |
+
* $provide.decorator('$log', ['$delegate', function($delegate) {
|
4873 |
* $delegate.warn = $delegate.error;
|
4874 |
* return $delegate;
|
4875 |
* }]);
|
4876 |
+
* ```
|
4877 |
+
*/
|
4878 |
|
4879 |
|
4880 |
+
function createInjector(modulesToLoad, strictDi) {
|
4881 |
+
strictDi = (strictDi === true);
|
4882 |
+
var INSTANTIATING = {},
|
4883 |
+
providerSuffix = 'Provider',
|
4884 |
+
path = [],
|
4885 |
+
loadedModules = new NgMap(),
|
4886 |
+
providerCache = {
|
4887 |
+
$provide: {
|
4888 |
+
provider: supportObject(provider),
|
4889 |
+
factory: supportObject(factory),
|
4890 |
+
service: supportObject(service),
|
4891 |
+
value: supportObject(value),
|
4892 |
+
constant: supportObject(constant),
|
4893 |
+
decorator: decorator
|
4894 |
+
}
|
4895 |
+
},
|
4896 |
+
providerInjector = (providerCache.$injector =
|
4897 |
+
createInternalInjector(providerCache, function(serviceName, caller) {
|
4898 |
+
if (angular.isString(caller)) {
|
4899 |
+
path.push(caller);
|
4900 |
+
}
|
4901 |
+
throw $injectorMinErr('unpr', 'Unknown provider: {0}', path.join(' <- '));
|
4902 |
+
})),
|
4903 |
+
instanceCache = {},
|
4904 |
+
protoInstanceInjector =
|
4905 |
+
createInternalInjector(instanceCache, function(serviceName, caller) {
|
4906 |
+
var provider = providerInjector.get(serviceName + providerSuffix, caller);
|
4907 |
+
return instanceInjector.invoke(
|
4908 |
+
provider.$get, provider, undefined, serviceName);
|
4909 |
+
}),
|
4910 |
+
instanceInjector = protoInstanceInjector;
|
4911 |
+
|
4912 |
+
providerCache['$injector' + providerSuffix] = { $get: valueFn(protoInstanceInjector) };
|
4913 |
+
instanceInjector.modules = providerInjector.modules = createMap();
|
4914 |
+
var runBlocks = loadModules(modulesToLoad);
|
4915 |
+
instanceInjector = protoInstanceInjector.get('$injector');
|
4916 |
+
instanceInjector.strictDi = strictDi;
|
4917 |
+
forEach(runBlocks, function(fn) { if (fn) instanceInjector.invoke(fn); });
|
4918 |
+
|
4919 |
+
instanceInjector.loadNewModules = function(mods) {
|
4920 |
+
forEach(loadModules(mods), function(fn) { if (fn) instanceInjector.invoke(fn); });
|
4921 |
+
};
|
4922 |
+
|
4923 |
+
|
4924 |
+
return instanceInjector;
|
4925 |
+
|
4926 |
+
////////////////////////////////////
|
4927 |
+
// $provider
|
4928 |
+
////////////////////////////////////
|
4929 |
+
|
4930 |
+
function supportObject(delegate) {
|
4931 |
+
return function(key, value) {
|
4932 |
+
if (isObject(key)) {
|
4933 |
+
forEach(key, reverseParams(delegate));
|
4934 |
+
} else {
|
4935 |
+
return delegate(key, value);
|
4936 |
+
}
|
4937 |
+
};
|
4938 |
+
}
|
4939 |
|
4940 |
+
function provider(name, provider_) {
|
4941 |
+
assertNotHasOwnProperty(name, 'service');
|
4942 |
+
if (isFunction(provider_) || isArray(provider_)) {
|
4943 |
+
provider_ = providerInjector.instantiate(provider_);
|
4944 |
+
}
|
4945 |
+
if (!provider_.$get) {
|
4946 |
+
throw $injectorMinErr('pget', 'Provider \'{0}\' must define $get factory method.', name);
|
4947 |
+
}
|
4948 |
+
return (providerCache[name + providerSuffix] = provider_);
|
4949 |
+
}
|
4950 |
|
4951 |
+
function enforceReturnValue(name, factory) {
|
4952 |
+
return /** @this */ function enforcedReturnValue() {
|
4953 |
+
var result = instanceInjector.invoke(factory, this);
|
4954 |
+
if (isUndefined(result)) {
|
4955 |
+
throw $injectorMinErr('undef', 'Provider \'{0}\' must return a value from $get factory method.', name);
|
4956 |
+
}
|
4957 |
+
return result;
|
4958 |
+
};
|
4959 |
+
}
|
4960 |
|
4961 |
+
function factory(name, factoryFn, enforce) {
|
4962 |
+
return provider(name, {
|
4963 |
+
$get: enforce !== false ? enforceReturnValue(name, factoryFn) : factoryFn
|
4964 |
+
});
|
4965 |
+
}
|
4966 |
|
4967 |
+
function service(name, constructor) {
|
4968 |
+
return factory(name, ['$injector', function($injector) {
|
4969 |
+
return $injector.instantiate(constructor);
|
4970 |
+
}]);
|
4971 |
+
}
|
|
|
|
|
|
|
|
|
4972 |
|
4973 |
+
function value(name, val) { return factory(name, valueFn(val), false); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4974 |
|
4975 |
+
function constant(name, value) {
|
4976 |
+
assertNotHasOwnProperty(name, 'constant');
|
4977 |
+
providerCache[name] = value;
|
4978 |
+
instanceCache[name] = value;
|
4979 |
+
}
|
|
|
|
|
|
|
|
|
4980 |
|
4981 |
+
function decorator(serviceName, decorFn) {
|
4982 |
+
var origProvider = providerInjector.get(serviceName + providerSuffix),
|
4983 |
+
orig$get = origProvider.$get;
|
|
|
|
|
4984 |
|
4985 |
+
origProvider.$get = function() {
|
4986 |
+
var origInstance = instanceInjector.invoke(orig$get, origProvider);
|
4987 |
+
return instanceInjector.invoke(decorFn, null, {$delegate: origInstance});
|
4988 |
+
};
|
4989 |
+
}
|
4990 |
+
|
4991 |
+
////////////////////////////////////
|
4992 |
+
// Module Loading
|
4993 |
+
////////////////////////////////////
|
4994 |
+
function loadModules(modulesToLoad) {
|
4995 |
+
assertArg(isUndefined(modulesToLoad) || isArray(modulesToLoad), 'modulesToLoad', 'not an array');
|
4996 |
+
var runBlocks = [], moduleFn;
|
4997 |
+
forEach(modulesToLoad, function(module) {
|
4998 |
+
if (loadedModules.get(module)) return;
|
4999 |
+
loadedModules.set(module, true);
|
5000 |
+
|
5001 |
+
function runInvokeQueue(queue) {
|
5002 |
+
var i, ii;
|
5003 |
+
for (i = 0, ii = queue.length; i < ii; i++) {
|
5004 |
+
var invokeArgs = queue[i],
|
5005 |
+
provider = providerInjector.get(invokeArgs[0]);
|
5006 |
+
|
5007 |
+
provider[invokeArgs[1]].apply(provider, invokeArgs[2]);
|
5008 |
}
|
5009 |
+
}
|
5010 |
|
5011 |
+
try {
|
5012 |
+
if (isString(module)) {
|
5013 |
+
moduleFn = angularModule(module);
|
5014 |
+
instanceInjector.modules[module] = moduleFn;
|
5015 |
+
runBlocks = runBlocks.concat(loadModules(moduleFn.requires)).concat(moduleFn._runBlocks);
|
5016 |
+
runInvokeQueue(moduleFn._invokeQueue);
|
5017 |
+
runInvokeQueue(moduleFn._configBlocks);
|
5018 |
+
} else if (isFunction(module)) {
|
5019 |
+
runBlocks.push(providerInjector.invoke(module));
|
5020 |
+
} else if (isArray(module)) {
|
5021 |
+
runBlocks.push(providerInjector.invoke(module));
|
5022 |
+
} else {
|
5023 |
+
assertArgFn(module, 'module');
|
5024 |
+
}
|
5025 |
+
} catch (e) {
|
5026 |
+
if (isArray(module)) {
|
5027 |
+
module = module[module.length - 1];
|
5028 |
+
}
|
5029 |
+
if (e.message && e.stack && e.stack.indexOf(e.message) === -1) {
|
5030 |
+
// Safari & FF's stack traces don't contain error.message content
|
5031 |
+
// unlike those of Chrome and IE
|
5032 |
+
// So if stack doesn't contain message, we create a new string that contains both.
|
5033 |
+
// Since error.stack is read-only in Safari, I'm overriding e and not e.stack here.
|
5034 |
+
// eslint-disable-next-line no-ex-assign
|
5035 |
+
e = e.message + '\n' + e.stack;
|
5036 |
+
}
|
5037 |
+
throw $injectorMinErr('modulerr', 'Failed to instantiate module {0} due to:\n{1}',
|
5038 |
+
module, e.stack || e.message || e);
|
5039 |
+
}
|
5040 |
+
});
|
5041 |
+
return runBlocks;
|
5042 |
+
}
|
5043 |
|
5044 |
+
////////////////////////////////////
|
5045 |
+
// internal Injector
|
5046 |
+
////////////////////////////////////
|
|
|
|
|
5047 |
|
5048 |
+
function createInternalInjector(cache, factory) {
|
|
|
|
|
5049 |
|
5050 |
+
function getService(serviceName, caller) {
|
5051 |
+
if (cache.hasOwnProperty(serviceName)) {
|
5052 |
+
if (cache[serviceName] === INSTANTIATING) {
|
5053 |
+
throw $injectorMinErr('cdep', 'Circular dependency found: {0}',
|
5054 |
+
serviceName + ' <- ' + path.join(' <- '));
|
5055 |
}
|
5056 |
+
return cache[serviceName];
|
5057 |
+
} else {
|
5058 |
+
try {
|
5059 |
+
path.unshift(serviceName);
|
5060 |
+
cache[serviceName] = INSTANTIATING;
|
5061 |
+
cache[serviceName] = factory(serviceName, caller);
|
5062 |
+
return cache[serviceName];
|
5063 |
+
} catch (err) {
|
5064 |
+
if (cache[serviceName] === INSTANTIATING) {
|
5065 |
+
delete cache[serviceName];
|
5066 |
+
}
|
5067 |
+
throw err;
|
5068 |
+
} finally {
|
5069 |
+
path.shift();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5070 |
}
|
5071 |
+
}
|
5072 |
+
}
|
5073 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5074 |
|
5075 |
+
function injectionArgs(fn, locals, serviceName) {
|
5076 |
+
var args = [],
|
5077 |
+
$inject = createInjector.$$annotate(fn, strictDi, serviceName);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5078 |
|
5079 |
+
for (var i = 0, length = $inject.length; i < length; i++) {
|
5080 |
+
var key = $inject[i];
|
5081 |
+
if (typeof key !== 'string') {
|
5082 |
+
throw $injectorMinErr('itkn',
|
5083 |
+
'Incorrect injection token! Expected service name as string, got {0}', key);
|
5084 |
+
}
|
5085 |
+
args.push(locals && locals.hasOwnProperty(key) ? locals[key] :
|
5086 |
+
getService(key, serviceName));
|
5087 |
+
}
|
5088 |
+
return args;
|
5089 |
+
}
|
5090 |
|
5091 |
+
function isClass(func) {
|
5092 |
+
// Support: IE 9-11 only
|
5093 |
+
// IE 9-11 do not support classes and IE9 leaks with the code below.
|
5094 |
+
if (msie || typeof func !== 'function') {
|
5095 |
+
return false;
|
5096 |
+
}
|
5097 |
+
var result = func.$$ngIsClass;
|
5098 |
+
if (!isBoolean(result)) {
|
5099 |
+
result = func.$$ngIsClass = /^class\b/.test(stringifyFn(func));
|
5100 |
+
}
|
5101 |
+
return result;
|
5102 |
+
}
|
5103 |
|
5104 |
+
function invoke(fn, self, locals, serviceName) {
|
5105 |
+
if (typeof locals === 'string') {
|
5106 |
+
serviceName = locals;
|
5107 |
+
locals = null;
|
5108 |
+
}
|
|
|
|
|
|
|
|
|
5109 |
|
5110 |
+
var args = injectionArgs(fn, locals, serviceName);
|
5111 |
+
if (isArray(fn)) {
|
5112 |
+
fn = fn[fn.length - 1];
|
5113 |
+
}
|
5114 |
|
5115 |
+
if (!isClass(fn)) {
|
5116 |
+
// http://jsperf.com/angularjs-invoke-apply-vs-switch
|
5117 |
+
// #5388
|
5118 |
+
return fn.apply(self, args);
|
5119 |
+
} else {
|
5120 |
+
args.unshift(null);
|
5121 |
+
return new (Function.prototype.bind.apply(fn, args))();
|
5122 |
+
}
|
5123 |
+
}
|
5124 |
|
5125 |
|
5126 |
+
function instantiate(Type, locals, serviceName) {
|
5127 |
+
// Check if Type is annotated and use just the given function at n-1 as parameter
|
5128 |
+
// e.g. someModule.factory('greeter', ['$window', function(renamed$window) {}]);
|
5129 |
+
var ctor = (isArray(Type) ? Type[Type.length - 1] : Type);
|
5130 |
+
var args = injectionArgs(Type, locals, serviceName);
|
5131 |
+
// Empty object at position 0 is ignored for invocation with `new`, but required.
|
5132 |
+
args.unshift(null);
|
5133 |
+
return new (Function.prototype.bind.apply(ctor, args))();
|
|
|
|
|
5134 |
}
|
5135 |
|
|
|
5136 |
|
5137 |
+
return {
|
5138 |
+
invoke: invoke,
|
5139 |
+
instantiate: instantiate,
|
5140 |
+
get: getService,
|
5141 |
+
annotate: createInjector.$$annotate,
|
5142 |
+
has: function(name) {
|
5143 |
+
return providerCache.hasOwnProperty(name + providerSuffix) || cache.hasOwnProperty(name);
|
5144 |
+
}
|
5145 |
+
};
|
5146 |
+
}
|
5147 |
+
}
|
5148 |
|
5149 |
+
createInjector.$$annotate = annotate;
|
5150 |
|
5151 |
+
/**
|
5152 |
+
* @ngdoc provider
|
5153 |
+
* @name $anchorScrollProvider
|
5154 |
+
* @this
|
5155 |
+
*
|
5156 |
+
* @description
|
5157 |
+
* Use `$anchorScrollProvider` to disable automatic scrolling whenever
|
5158 |
+
* {@link ng.$location#hash $location.hash()} changes.
|
5159 |
+
*/
|
5160 |
+
function $AnchorScrollProvider() {
|
|
|
|
|
|
|
|
|
|
|
|
|
5161 |
|
5162 |
+
var autoScrollingEnabled = true;
|
5163 |
+
|
5164 |
+
/**
|
5165 |
+
* @ngdoc method
|
5166 |
+
* @name $anchorScrollProvider#disableAutoScrolling
|
5167 |
+
*
|
5168 |
+
* @description
|
5169 |
+
* By default, {@link ng.$anchorScroll $anchorScroll()} will automatically detect changes to
|
5170 |
+
* {@link ng.$location#hash $location.hash()} and scroll to the element matching the new hash.<br />
|
5171 |
+
* Use this method to disable automatic scrolling.
|
5172 |
+
*
|
5173 |
+
* If automatic scrolling is disabled, one must explicitly call
|
5174 |
+
* {@link ng.$anchorScroll $anchorScroll()} in order to scroll to the element related to the
|
5175 |
+
* current hash.
|
5176 |
+
*/
|
5177 |
+
this.disableAutoScrolling = function() {
|
5178 |
+
autoScrollingEnabled = false;
|
5179 |
+
};
|
5180 |
+
|
5181 |
+
/**
|
5182 |
+
* @ngdoc service
|
5183 |
+
* @name $anchorScroll
|
5184 |
+
* @kind function
|
5185 |
+
* @requires $window
|
5186 |
+
* @requires $location
|
5187 |
+
* @requires $rootScope
|
5188 |
+
*
|
5189 |
+
* @description
|
5190 |
+
* When called, it scrolls to the element related to the specified `hash` or (if omitted) to the
|
5191 |
+
* current value of {@link ng.$location#hash $location.hash()}, according to the rules specified
|
5192 |
+
* in the
|
5193 |
+
* [HTML5 spec](http://www.w3.org/html/wg/drafts/html/master/browsers.html#an-indicated-part-of-the-document).
|
5194 |
+
*
|
5195 |
+
* It also watches the {@link ng.$location#hash $location.hash()} and automatically scrolls to
|
5196 |
+
* match any anchor whenever it changes. This can be disabled by calling
|
5197 |
+
* {@link ng.$anchorScrollProvider#disableAutoScrolling $anchorScrollProvider.disableAutoScrolling()}.
|
5198 |
+
*
|
5199 |
+
* Additionally, you can use its {@link ng.$anchorScroll#yOffset yOffset} property to specify a
|
5200 |
+
* vertical scroll-offset (either fixed or dynamic).
|
5201 |
+
*
|
5202 |
+
* @param {string=} hash The hash specifying the element to scroll to. If omitted, the value of
|
5203 |
+
* {@link ng.$location#hash $location.hash()} will be used.
|
5204 |
+
*
|
5205 |
+
* @property {(number|function|jqLite)} yOffset
|
5206 |
+
* If set, specifies a vertical scroll-offset. This is often useful when there are fixed
|
5207 |
+
* positioned elements at the top of the page, such as navbars, headers etc.
|
5208 |
+
*
|
5209 |
+
* `yOffset` can be specified in various ways:
|
5210 |
+
* - **number**: A fixed number of pixels to be used as offset.<br /><br />
|
5211 |
+
* - **function**: A getter function called everytime `$anchorScroll()` is executed. Must return
|
5212 |
+
* a number representing the offset (in pixels).<br /><br />
|
5213 |
+
* - **jqLite**: A jqLite/jQuery element to be used for specifying the offset. The distance from
|
5214 |
+
* the top of the page to the element's bottom will be used as offset.<br />
|
5215 |
+
* **Note**: The element will be taken into account only as long as its `position` is set to
|
5216 |
+
* `fixed`. This option is useful, when dealing with responsive navbars/headers that adjust
|
5217 |
+
* their height and/or positioning according to the viewport's size.
|
5218 |
+
*
|
5219 |
+
* <br />
|
5220 |
+
* <div class="alert alert-warning">
|
5221 |
+
* In order for `yOffset` to work properly, scrolling should take place on the document's root and
|
5222 |
+
* not some child element.
|
5223 |
+
* </div>
|
5224 |
+
*
|
5225 |
+
* @example
|
5226 |
+
<example module="anchorScrollExample" name="anchor-scroll">
|
5227 |
+
<file name="index.html">
|
5228 |
<div id="scrollArea" ng-controller="ScrollController">
|
5229 |
+
<a ng-click="gotoBottom()">Go to bottom</a>
|
5230 |
+
<a id="bottom"></a> You're at the bottom!
|
5231 |
</div>
|
5232 |
+
</file>
|
5233 |
+
<file name="script.js">
|
5234 |
angular.module('anchorScrollExample', [])
|
5235 |
+
.controller('ScrollController', ['$scope', '$location', '$anchorScroll',
|
5236 |
+
function($scope, $location, $anchorScroll) {
|
5237 |
$scope.gotoBottom = function() {
|
5238 |
// set the location.hash to the id of
|
5239 |
// the element you wish to scroll to.
|
5243 |
$anchorScroll();
|
5244 |
};
|
5245 |
}]);
|
5246 |
+
</file>
|
5247 |
+
<file name="style.css">
|
5248 |
#scrollArea {
|
5249 |
height: 280px;
|
5250 |
overflow: auto;
|
5254 |
display: block;
|
5255 |
margin-top: 2000px;
|
5256 |
}
|
5257 |
+
</file>
|
5258 |
+
</example>
|
5259 |
+
*
|
5260 |
+
* <hr />
|
5261 |
+
* The example below illustrates the use of a vertical scroll-offset (specified as a fixed value).
|
5262 |
+
* See {@link ng.$anchorScroll#yOffset $anchorScroll.yOffset} for more details.
|
5263 |
+
*
|
5264 |
+
* @example
|
5265 |
+
<example module="anchorScrollOffsetExample" name="anchor-scroll-offset">
|
5266 |
+
<file name="index.html">
|
5267 |
<div class="fixed-header" ng-controller="headerCtrl">
|
5268 |
+
<a href="" ng-click="gotoAnchor(x)" ng-repeat="x in [1,2,3,4,5]">
|
5269 |
+
Go to anchor {{x}}
|
5270 |
+
</a>
|
5271 |
</div>
|
5272 |
<div id="anchor{{x}}" class="anchor" ng-repeat="x in [1,2,3,4,5]">
|
5273 |
+
Anchor {{x}} of 5
|
5274 |
</div>
|
5275 |
+
</file>
|
5276 |
+
<file name="script.js">
|
5277 |
angular.module('anchorScrollOffsetExample', [])
|
5278 |
+
.run(['$anchorScroll', function($anchorScroll) {
|
5279 |
$anchorScroll.yOffset = 50; // always scroll by 50 extra pixels
|
5280 |
}])
|
5281 |
+
.controller('headerCtrl', ['$anchorScroll', '$location', '$scope',
|
5282 |
+
function($anchorScroll, $location, $scope) {
|
5283 |
$scope.gotoAnchor = function(x) {
|
5284 |
var newHash = 'anchor' + x;
|
5285 |
if ($location.hash() !== newHash) {
|
5293 |
}
|
5294 |
};
|
5295 |
}
|
5296 |
+
]);
|
5297 |
+
</file>
|
5298 |
+
<file name="style.css">
|
5299 |
body {
|
5300 |
padding-top: 50px;
|
5301 |
}
|
5316 |
display: inline-block;
|
5317 |
margin: 5px 15px;
|
5318 |
}
|
5319 |
+
</file>
|
5320 |
+
</example>
|
5321 |
+
*/
|
5322 |
+
this.$get = ['$window', '$location', '$rootScope', function($window, $location, $rootScope) {
|
5323 |
+
var document = $window.document;
|
5324 |
+
|
5325 |
+
// Helper function to get first anchor from a NodeList
|
5326 |
+
// (using `Array#some()` instead of `angular#forEach()` since it's more performant
|
5327 |
+
// and working in all supported browsers.)
|
5328 |
+
function getFirstAnchor(list) {
|
5329 |
+
var result = null;
|
5330 |
+
Array.prototype.some.call(list, function(element) {
|
5331 |
+
if (nodeName_(element) === 'a') {
|
5332 |
+
result = element;
|
5333 |
+
return true;
|
5334 |
+
}
|
5335 |
+
});
|
5336 |
+
return result;
|
5337 |
+
}
|
|
|
|
|
|
|
|
|
5338 |
|
5339 |
+
function getYOffset() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5340 |
|
5341 |
+
var offset = scroll.yOffset;
|
|
|
5342 |
|
5343 |
+
if (isFunction(offset)) {
|
5344 |
+
offset = offset();
|
5345 |
+
} else if (isElement(offset)) {
|
5346 |
+
var elem = offset[0];
|
5347 |
+
var style = $window.getComputedStyle(elem);
|
5348 |
+
if (style.position !== 'fixed') {
|
5349 |
+
offset = 0;
|
5350 |
+
} else {
|
5351 |
+
offset = elem.getBoundingClientRect().bottom;
|
5352 |
+
}
|
5353 |
+
} else if (!isNumber(offset)) {
|
5354 |
+
offset = 0;
|
5355 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5356 |
|
5357 |
+
return offset;
|
5358 |
+
}
|
5359 |
+
|
5360 |
+
function scrollTo(elem) {
|
5361 |
+
if (elem) {
|
5362 |
+
elem.scrollIntoView();
|
5363 |
+
|
5364 |
+
var offset = getYOffset();
|
5365 |
+
|
5366 |
+
if (offset) {
|
5367 |
+
// `offset` is the number of pixels we should scroll UP in order to align `elem` properly.
|
5368 |
+
// This is true ONLY if the call to `elem.scrollIntoView()` initially aligns `elem` at the
|
5369 |
+
// top of the viewport.
|
5370 |
+
//
|
5371 |
+
// IF the number of pixels from the top of `elem` to the end of the page's content is less
|
5372 |
+
// than the height of the viewport, then `elem.scrollIntoView()` will align the `elem` some
|
5373 |
+
// way down the page.
|
5374 |
+
//
|
5375 |
+
// This is often the case for elements near the bottom of the page.
|
5376 |
+
//
|
5377 |
+
// In such cases we do not need to scroll the whole `offset` up, just the difference between
|
5378 |
+
// the top of the element and the offset, which is enough to align the top of `elem` at the
|
5379 |
+
// desired position.
|
5380 |
+
var elemTop = elem.getBoundingClientRect().top;
|
5381 |
+
$window.scrollBy(0, elemTop - offset);
|
5382 |
+
}
|
5383 |
+
} else {
|
5384 |
+
$window.scrollTo(0, 0);
|
5385 |
+
}
|
5386 |
+
}
|
5387 |
|
5388 |
+
function scroll(hash) {
|
5389 |
+
// Allow numeric hashes
|
5390 |
+
hash = isString(hash) ? hash : isNumber(hash) ? hash.toString() : $location.hash();
|
5391 |
+
var elm;
|
5392 |
|
5393 |
+
// empty hash, scroll to the top of the page
|
5394 |
+
if (!hash) scrollTo(null);
|
5395 |
|
5396 |
+
// element with given id
|
5397 |
+
else if ((elm = document.getElementById(hash))) scrollTo(elm);
|
5398 |
|
5399 |
+
// first anchor with given name :-D
|
5400 |
+
else if ((elm = getFirstAnchor(document.getElementsByName(hash)))) scrollTo(elm);
|
|
|
5401 |
|
5402 |
+
// no element and hash === 'top', scroll to the top of the page
|
5403 |
+
else if (hash === 'top') scrollTo(null);
|
5404 |
+
}
|
|
|
|
|
|
|
|
|
5405 |
|
5406 |
+
// does not scroll when user clicks on anchor link that is currently on
|
5407 |
+
// (no url change, no $location.hash() change), browser native does scroll
|
5408 |
+
if (autoScrollingEnabled) {
|
5409 |
+
$rootScope.$watch(function autoScrollWatch() {return $location.hash();},
|
5410 |
+
function autoScrollWatchAction(newVal, oldVal) {
|
5411 |
+
// skip the initial scroll if $location.hash is empty
|
5412 |
+
if (newVal === oldVal && newVal === '') return;
|
5413 |
|
5414 |
+
jqLiteDocumentLoaded(function() {
|
5415 |
+
$rootScope.$evalAsync(scroll);
|
5416 |
+
});
|
5417 |
+
});
|
5418 |
}
|
5419 |
|
5420 |
+
return scroll;
|
5421 |
+
}];
|
5422 |
+
}
|
5423 |
|
5424 |
+
var $animateMinErr = minErr('$animate');
|
5425 |
+
var ELEMENT_NODE = 1;
|
5426 |
+
var NG_ANIMATE_CLASSNAME = 'ng-animate';
|
5427 |
+
|
5428 |
+
function mergeClasses(a,b) {
|
5429 |
+
if (!a && !b) return '';
|
5430 |
+
if (!a) return b;
|
5431 |
+
if (!b) return a;
|
5432 |
+
if (isArray(a)) a = a.join(' ');
|
5433 |
+
if (isArray(b)) b = b.join(' ');
|
5434 |
+
return a + ' ' + b;
|
5435 |
+
}
|
5436 |
|
5437 |
+
function extractElementNode(element) {
|
5438 |
+
for (var i = 0; i < element.length; i++) {
|
5439 |
+
var elm = element[i];
|
5440 |
+
if (elm.nodeType === ELEMENT_NODE) {
|
5441 |
+
return elm;
|
|
|
|
|
5442 |
}
|
5443 |
+
}
|
5444 |
+
}
|
5445 |
|
5446 |
+
function splitClasses(classes) {
|
5447 |
+
if (isString(classes)) {
|
5448 |
+
classes = classes.split(' ');
|
5449 |
+
}
|
5450 |
|
5451 |
+
// Use createMap() to prevent class assumptions involving property names in
|
5452 |
+
// Object.prototype
|
5453 |
+
var obj = createMap();
|
5454 |
+
forEach(classes, function(klass) {
|
5455 |
+
// sometimes the split leaves empty string values
|
5456 |
+
// incase extra spaces were applied to the options
|
5457 |
+
if (klass.length) {
|
5458 |
+
obj[klass] = true;
|
|
|
|
|
|
|
5459 |
}
|
5460 |
+
});
|
5461 |
+
return obj;
|
5462 |
+
}
|
5463 |
|
5464 |
// if any other type of options value besides an Object value is
|
5465 |
// passed into the $animate.method() animation then this helper code
|
5468 |
// $animate to either call the callback (< 1.2) or return a promise
|
5469 |
// that can be changed. This helper function ensures that the options
|
5470 |
// are wiped clean incase a callback function is provided.
|
5471 |
+
function prepareAnimateOptions(options) {
|
5472 |
+
return isObject(options)
|
5473 |
+
? options
|
5474 |
+
: {};
|
5475 |
+
}
|
5476 |
|
5477 |
+
var $$CoreAnimateJsProvider = /** @this */ function() {
|
5478 |
+
this.$get = noop;
|
5479 |
+
};
|
5480 |
|
5481 |
// this is prefixed with Core since it conflicts with
|
5482 |
// the animateQueueProvider defined in ngAnimate/animateQueue.js
|
5483 |
+
var $$CoreAnimateQueueProvider = /** @this */ function() {
|
5484 |
+
var postDigestQueue = new NgMap();
|
5485 |
+
var postDigestElements = [];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5486 |
|
5487 |
+
this.$get = ['$$AnimateRunner', '$rootScope',
|
5488 |
+
function($$AnimateRunner, $rootScope) {
|
5489 |
+
return {
|
5490 |
+
enabled: noop,
|
5491 |
+
on: noop,
|
5492 |
+
off: noop,
|
5493 |
+
pin: noop,
|
5494 |
|
5495 |
+
push: function(element, event, options, domOperation) {
|
5496 |
+
if (domOperation) {
|
5497 |
+
domOperation();
|
5498 |
+
}
|
5499 |
|
5500 |
+
options = options || {};
|
5501 |
+
if (options.from) {
|
5502 |
+
element.css(options.from);
|
5503 |
+
}
|
5504 |
+
if (options.to) {
|
5505 |
+
element.css(options.to);
|
5506 |
+
}
|
5507 |
|
5508 |
+
if (options.addClass || options.removeClass) {
|
5509 |
+
addRemoveClassesPostDigest(element, options.addClass, options.removeClass);
|
5510 |
+
}
|
|
|
|
|
|
|
5511 |
|
5512 |
+
var runner = new $$AnimateRunner();
|
5513 |
|
5514 |
+
// since there are no animations to run the runner needs to be
|
5515 |
+
// notified that the animation call is complete.
|
5516 |
+
runner.complete();
|
5517 |
+
return runner;
|
5518 |
+
}
|
5519 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5520 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5521 |
|
5522 |
+
function updateData(data, classes, value) {
|
5523 |
+
var changed = false;
|
5524 |
+
if (classes) {
|
5525 |
+
classes = isString(classes) ? classes.split(' ') :
|
5526 |
+
isArray(classes) ? classes : [];
|
5527 |
+
forEach(classes, function(className) {
|
5528 |
+
if (className) {
|
5529 |
+
changed = true;
|
5530 |
+
data[className] = value;
|
5531 |
+
}
|
5532 |
+
});
|
5533 |
+
}
|
5534 |
+
return changed;
|
5535 |
+
}
|
5536 |
+
|
5537 |
+
function handleCSSClassChanges() {
|
5538 |
+
forEach(postDigestElements, function(element) {
|
5539 |
+
var data = postDigestQueue.get(element);
|
5540 |
+
if (data) {
|
5541 |
+
var existing = splitClasses(element.attr('class'));
|
5542 |
+
var toAdd = '';
|
5543 |
+
var toRemove = '';
|
5544 |
+
forEach(data, function(status, className) {
|
5545 |
+
var hasClass = !!existing[className];
|
5546 |
+
if (status !== hasClass) {
|
5547 |
+
if (status) {
|
5548 |
+
toAdd += (toAdd.length ? ' ' : '') + className;
|
5549 |
+
} else {
|
5550 |
+
toRemove += (toRemove.length ? ' ' : '') + className;
|
5551 |
+
}
|
5552 |
+
}
|
5553 |
+
});
|
5554 |
|
5555 |
+
forEach(element, function(elm) {
|
5556 |
+
if (toAdd) {
|
5557 |
+
jqLiteAddClass(elm, toAdd);
|
5558 |
+
}
|
5559 |
+
if (toRemove) {
|
5560 |
+
jqLiteRemoveClass(elm, toRemove);
|
5561 |
+
}
|
5562 |
+
});
|
5563 |
+
postDigestQueue.delete(element);
|
5564 |
+
}
|
5565 |
+
});
|
5566 |
+
postDigestElements.length = 0;
|
5567 |
+
}
|
5568 |
|
|
|
|
|
5569 |
|
5570 |
+
function addRemoveClassesPostDigest(element, add, remove) {
|
5571 |
+
var data = postDigestQueue.get(element) || {};
|
5572 |
|
5573 |
+
var classesAdded = updateData(data, add, true);
|
5574 |
+
var classesRemoved = updateData(data, remove, false);
|
5575 |
|
5576 |
+
if (classesAdded || classesRemoved) {
|
|
|
5577 |
|
5578 |
+
postDigestQueue.set(element, data);
|
5579 |
+
postDigestElements.push(element);
|
|
|
|
|
|
|
|
|
|
|
5580 |
|
5581 |
+
if (postDigestElements.length === 1) {
|
5582 |
+
$rootScope.$$postDigest(handleCSSClassChanges);
|
5583 |
+
}
|
5584 |
+
}
|
5585 |
+
}
|
5586 |
+
}];
|
5587 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5588 |
|
5589 |
+
/**
|
5590 |
+
* @ngdoc provider
|
5591 |
+
* @name $animateProvider
|
5592 |
+
*
|
5593 |
+
* @description
|
5594 |
+
* Default implementation of $animate that doesn't perform any animations, instead just
|
5595 |
+
* synchronously performs DOM updates and resolves the returned runner promise.
|
5596 |
+
*
|
5597 |
+
* In order to enable animations the `ngAnimate` module has to be loaded.
|
5598 |
+
*
|
5599 |
+
* To see the functional implementation check out `src/ngAnimate/animate.js`.
|
5600 |
+
*/
|
5601 |
+
var $AnimateProvider = ['$provide', /** @this */ function($provide) {
|
5602 |
+
var provider = this;
|
5603 |
+
var classNameFilter = null;
|
5604 |
+
var customFilter = null;
|
5605 |
|
5606 |
+
this.$$registeredAnimations = Object.create(null);
|
5607 |
+
|
5608 |
+
/**
|
5609 |
+
* @ngdoc method
|
5610 |
+
* @name $animateProvider#register
|
5611 |
+
*
|
5612 |
+
* @description
|
5613 |
+
* Registers a new injectable animation factory function. The factory function produces the
|
5614 |
+
* animation object which contains callback functions for each event that is expected to be
|
5615 |
+
* animated.
|
5616 |
+
*
|
5617 |
+
* * `eventFn`: `function(element, ... , doneFunction, options)`
|
5618 |
+
* The element to animate, the `doneFunction` and the options fed into the animation. Depending
|
5619 |
+
* on the type of animation additional arguments will be injected into the animation function. The
|
5620 |
+
* list below explains the function signatures for the different animation methods:
|
5621 |
+
*
|
5622 |
+
* - setClass: function(element, addedClasses, removedClasses, doneFunction, options)
|
5623 |
+
* - addClass: function(element, addedClasses, doneFunction, options)
|
5624 |
+
* - removeClass: function(element, removedClasses, doneFunction, options)
|
5625 |
+
* - enter, leave, move: function(element, doneFunction, options)
|
5626 |
+
* - animate: function(element, fromStyles, toStyles, doneFunction, options)
|
5627 |
+
*
|
5628 |
+
* Make sure to trigger the `doneFunction` once the animation is fully complete.
|
5629 |
+
*
|
5630 |
+
* ```js
|
5631 |
+
* return {
|
5632 |
* //enter, leave, move signature
|
5633 |
* eventFn : function(element, done, options) {
|
5634 |
* //code to run the animation
|
5638 |
* }
|
5639 |
* }
|
5640 |
* }
|
5641 |
+
* ```
|
5642 |
+
*
|
5643 |
+
* @param {string} name The name of the animation (this is what the class-based CSS value will be compared to).
|
5644 |
+
* @param {Function} factory The factory function that will be executed to return the animation
|
5645 |
+
* object.
|
5646 |
+
*/
|
5647 |
+
this.register = function(name, factory) {
|
5648 |
+
if (name && name.charAt(0) !== '.') {
|
5649 |
+
throw $animateMinErr('notcsel', 'Expecting class selector starting with \'.\' got \'{0}\'.', name);
|
5650 |
+
}
|
5651 |
|
5652 |
+
var key = name + '-animation';
|
5653 |
+
provider.$$registeredAnimations[name.substr(1)] = key;
|
5654 |
+
$provide.factory(key, factory);
|
5655 |
+
};
|
5656 |
|
5657 |
+
/**
|
5658 |
+
* @ngdoc method
|
5659 |
+
* @name $animateProvider#customFilter
|
5660 |
+
*
|
5661 |
+
* @description
|
5662 |
+
* Sets and/or returns the custom filter function that is used to "filter" animations, i.e.
|
5663 |
+
* determine if an animation is allowed or not. When no filter is specified (the default), no
|
5664 |
+
* animation will be blocked. Setting the `customFilter` value will only allow animations for
|
5665 |
+
* which the filter function's return value is truthy.
|
5666 |
+
*
|
5667 |
+
* This allows to easily create arbitrarily complex rules for filtering animations, such as
|
5668 |
+
* allowing specific events only, or enabling animations on specific subtrees of the DOM, etc.
|
5669 |
+
* Filtering animations can also boost performance for low-powered devices, as well as
|
5670 |
+
* applications containing a lot of structural operations.
|
5671 |
+
*
|
5672 |
+
* <div class="alert alert-success">
|
5673 |
+
* **Best Practice:**
|
5674 |
+
* Keep the filtering function as lean as possible, because it will be called for each DOM
|
5675 |
+
* action (e.g. insertion, removal, class change) performed by "animation-aware" directives.
|
5676 |
+
* See {@link guide/animations#which-directives-support-animations- here} for a list of built-in
|
5677 |
+
* directives that support animations.
|
5678 |
+
* Performing computationally expensive or time-consuming operations on each call of the
|
5679 |
+
* filtering function can make your animations sluggish.
|
5680 |
+
* </div>
|
5681 |
+
*
|
5682 |
+
* **Note:** If present, `customFilter` will be checked before
|
5683 |
+
* {@link $animateProvider#classNameFilter classNameFilter}.
|
5684 |
+
*
|
5685 |
+
* @param {Function=} filterFn - The filter function which will be used to filter all animations.
|
5686 |
+
* If a falsy value is returned, no animation will be performed. The function will be called
|
5687 |
+
* with the following arguments:
|
5688 |
+
* - **node** `{DOMElement}` - The DOM element to be animated.
|
5689 |
+
* - **event** `{String}` - The name of the animation event (e.g. `enter`, `leave`, `addClass`
|
5690 |
+
* etc).
|
5691 |
+
* - **options** `{Object}` - A collection of options/styles used for the animation.
|
5692 |
+
* @return {Function} The current filter function or `null` if there is none set.
|
5693 |
+
*/
|
5694 |
+
this.customFilter = function(filterFn) {
|
5695 |
+
if (arguments.length === 1) {
|
5696 |
+
customFilter = isFunction(filterFn) ? filterFn : null;
|
5697 |
+
}
|
5698 |
|
5699 |
+
return customFilter;
|
5700 |
+
};
|
5701 |
|
5702 |
+
/**
|
5703 |
+
* @ngdoc method
|
5704 |
+
* @name $animateProvider#classNameFilter
|
5705 |
+
*
|
5706 |
+
* @description
|
5707 |
+
* Sets and/or returns the CSS class regular expression that is checked when performing
|
5708 |
+
* an animation. Upon bootstrap the classNameFilter value is not set at all and will
|
5709 |
+
* therefore enable $animate to attempt to perform an animation on any element that is triggered.
|
5710 |
+
* When setting the `classNameFilter` value, animations will only be performed on elements
|
5711 |
+
* that successfully match the filter expression. This in turn can boost performance
|
5712 |
+
* for low-powered devices as well as applications containing a lot of structural operations.
|
5713 |
+
*
|
5714 |
+
* **Note:** If present, `classNameFilter` will be checked after
|
5715 |
+
* {@link $animateProvider#customFilter customFilter}. If `customFilter` is present and returns
|
5716 |
+
* false, `classNameFilter` will not be checked.
|
5717 |
+
*
|
5718 |
+
* @param {RegExp=} expression The className expression which will be checked against all animations
|
5719 |
+
* @return {RegExp} The current CSS className expression value. If null then there is no expression value
|
5720 |
+
*/
|
5721 |
+
this.classNameFilter = function(expression) {
|
5722 |
+
if (arguments.length === 1) {
|
5723 |
+
classNameFilter = (expression instanceof RegExp) ? expression : null;
|
5724 |
+
if (classNameFilter) {
|
5725 |
+
var reservedRegex = new RegExp('[(\\s|\\/)]' + NG_ANIMATE_CLASSNAME + '[(\\s|\\/)]');
|
5726 |
+
if (reservedRegex.test(classNameFilter.toString())) {
|
5727 |
+
classNameFilter = null;
|
5728 |
+
throw $animateMinErr('nongcls', '$animateProvider.classNameFilter(regex) prohibits accepting a regex value which matches/contains the "{0}" CSS class.', NG_ANIMATE_CLASSNAME);
|
5729 |
+
}
|
5730 |
+
}
|
5731 |
+
}
|
5732 |
+
return classNameFilter;
|
5733 |
+
};
|
5734 |
|
5735 |
+
this.$get = ['$$animateQueue', function($$animateQueue) {
|
5736 |
+
function domInsert(element, parentElement, afterElement) {
|
5737 |
+
// if for some reason the previous element was removed
|
5738 |
+
// from the dom sometime before this code runs then let's
|
5739 |
+
// just stick to using the parent element as the anchor
|
5740 |
+
if (afterElement) {
|
5741 |
+
var afterNode = extractElementNode(afterElement);
|
5742 |
+
if (afterNode && !afterNode.parentNode && !afterNode.previousElementSibling) {
|
5743 |
+
afterElement = null;
|
5744 |
+
}
|
5745 |
+
}
|
5746 |
+
if (afterElement) {
|
5747 |
+
afterElement.after(element);
|
5748 |
+
} else {
|
5749 |
+
parentElement.prepend(element);
|
5750 |
+
}
|
5751 |
+
}
|
5752 |
|
5753 |
+
/**
|
5754 |
+
* @ngdoc service
|
5755 |
+
* @name $animate
|
5756 |
+
* @description The $animate service exposes a series of DOM utility methods that provide support
|
5757 |
+
* for animation hooks. The default behavior is the application of DOM operations, however,
|
5758 |
+
* when an animation is detected (and animations are enabled), $animate will do the heavy lifting
|
5759 |
+
* to ensure that animation runs with the triggered DOM operation.
|
5760 |
+
*
|
5761 |
+
* By default $animate doesn't trigger any animations. This is because the `ngAnimate` module isn't
|
5762 |
+
* included and only when it is active then the animation hooks that `$animate` triggers will be
|
5763 |
+
* functional. Once active then all structural `ng-` directives will trigger animations as they perform
|
5764 |
+
* their DOM-related operations (enter, leave and move). Other directives such as `ngClass`,
|
5765 |
+
* `ngShow`, `ngHide` and `ngMessages` also provide support for animations.
|
5766 |
+
*
|
5767 |
+
* It is recommended that the`$animate` service is always used when executing DOM-related procedures within directives.
|
5768 |
+
*
|
5769 |
+
* To learn more about enabling animation support, click here to visit the
|
5770 |
+
* {@link ngAnimate ngAnimate module page}.
|
5771 |
+
*/
|
5772 |
+
return {
|
5773 |
+
// we don't call it directly since non-existant arguments may
|
5774 |
+
// be interpreted as null within the sub enabled function
|
5775 |
+
|
5776 |
+
/**
|
5777 |
+
*
|
5778 |
+
* @ngdoc method
|
5779 |
+
* @name $animate#on
|
5780 |
+
* @kind function
|
5781 |
+
* @description Sets up an event listener to fire whenever the animation event (enter, leave, move, etc...)
|
5782 |
+
* has fired on the given element or among any of its children. Once the listener is fired, the provided callback
|
5783 |
+
* is fired with the following params:
|
5784 |
+
*
|
5785 |
+
* ```js
|
5786 |
+
* $animate.on('enter', container,
|
5787 |
+
* function callback(element, phase) {
|
5788 |
* // cool we detected an enter animation within the container
|
5789 |
* }
|
5790 |
+
* );
|
5791 |
+
* ```
|
5792 |
+
*
|
5793 |
+
* <div class="alert alert-warning">
|
5794 |
+
* **Note**: Generally, the events that are fired correspond 1:1 to `$animate` method names,
|
5795 |
+
* e.g. {@link ng.$animate#addClass addClass()} will fire `addClass`, and {@link ng.ngClass}
|
5796 |
+
* will fire `addClass` if classes are added, and `removeClass` if classes are removed.
|
5797 |
+
* However, there are two exceptions:
|
5798 |
+
*
|
5799 |
+
* <ul>
|
5800 |
+
* <li>if both an {@link ng.$animate#addClass addClass()} and a
|
5801 |
+
* {@link ng.$animate#removeClass removeClass()} action are performed during the same
|
5802 |
+
* animation, the event fired will be `setClass`. This is true even for `ngClass`.</li>
|
5803 |
+
* <li>an {@link ng.$animate#animate animate()} call that adds and removes classes will fire
|
5804 |
+
* the `setClass` event, but if it either removes or adds classes,
|
5805 |
+
* it will fire `animate` instead.</li>
|
5806 |
+
* </ul>
|
5807 |
+
*
|
5808 |
+
* </div>
|
5809 |
+
*
|
5810 |
+
* @param {string} event the animation event that will be captured (e.g. enter, leave, move, addClass, removeClass, etc...)
|
5811 |
+
* @param {DOMElement} container the container element that will capture each of the animation events that are fired on itself
|
5812 |
+
* as well as among its children
|
5813 |
+
* @param {Function} callback the callback function that will be fired when the listener is triggered.
|
5814 |
+
*
|
5815 |
+
* The arguments present in the callback function are:
|
5816 |
+
* * `element` - The captured DOM element that the animation was fired on.
|
5817 |
+
* * `phase` - The phase of the animation. The two possible phases are **start** (when the animation starts) and **close** (when it ends).
|
5818 |
+
* * `data` - an object with these properties:
|
5819 |
+
* * addClass - `{string|null}` - space-separated CSS classes to add to the element
|
5820 |
+
* * removeClass - `{string|null}` - space-separated CSS classes to remove from the element
|
5821 |
+
* * from - `{Object|null}` - CSS properties & values at the beginning of the animation
|
5822 |
+
* * to - `{Object|null}` - CSS properties & values at the end of the animation
|
5823 |
+
*
|
5824 |
+
* Note that the callback does not trigger a scope digest. Wrap your call into a
|
5825 |
+
* {@link $rootScope.Scope#$apply scope.$apply} to propagate changes to the scope.
|
5826 |
+
*/
|
5827 |
+
on: $$animateQueue.on,
|
5828 |
+
|
5829 |
+
/**
|
5830 |
+
*
|
5831 |
+
* @ngdoc method
|
5832 |
+
* @name $animate#off
|
5833 |
+
* @kind function
|
5834 |
+
* @description Deregisters an event listener based on the event which has been associated with the provided element. This method
|
5835 |
+
* can be used in three different ways depending on the arguments:
|
5836 |
+
*
|
5837 |
+
* ```js
|
5838 |
+
* // remove all the animation event listeners listening for `enter`
|
5839 |
+
* $animate.off('enter');
|
5840 |
+
*
|
5841 |
+
* // remove listeners for all animation events from the container element
|
5842 |
+
* $animate.off(container);
|
5843 |
+
*
|
5844 |
+
* // remove all the animation event listeners listening for `enter` on the given element and its children
|
5845 |
+
* $animate.off('enter', container);
|
5846 |
+
*
|
5847 |
+
* // remove the event listener function provided by `callback` that is set
|
5848 |
+
* // to listen for `enter` on the given `container` as well as its children
|
5849 |
+
* $animate.off('enter', container, callback);
|
5850 |
+
* ```
|
5851 |
+
*
|
5852 |
+
* @param {string|DOMElement} event|container the animation event (e.g. enter, leave, move,
|
5853 |
+
* addClass, removeClass, etc...), or the container element. If it is the element, all other
|
5854 |
+
* arguments are ignored.
|
5855 |
+
* @param {DOMElement=} container the container element the event listener was placed on
|
5856 |
+
* @param {Function=} callback the callback function that was registered as the listener
|
5857 |
+
*/
|
5858 |
+
off: $$animateQueue.off,
|
5859 |
+
|
5860 |
+
/**
|
5861 |
+
* @ngdoc method
|
5862 |
+
* @name $animate#pin
|
5863 |
+
* @kind function
|
5864 |
+
* @description Associates the provided element with a host parent element to allow the element to be animated even if it exists
|
5865 |
+
* outside of the DOM structure of the AngularJS application. By doing so, any animation triggered via `$animate` can be issued on the
|
5866 |
+
* element despite being outside the realm of the application or within another application. Say for example if the application
|
5867 |
+
* was bootstrapped on an element that is somewhere inside of the `<body>` tag, but we wanted to allow for an element to be situated
|
5868 |
+
* as a direct child of `document.body`, then this can be achieved by pinning the element via `$animate.pin(element)`. Keep in mind
|
5869 |
+
* that calling `$animate.pin(element, parentElement)` will not actually insert into the DOM anywhere; it will just create the association.
|
5870 |
+
*
|
5871 |
+
* Note that this feature is only active when the `ngAnimate` module is used.
|
5872 |
+
*
|
5873 |
+
* @param {DOMElement} element the external element that will be pinned
|
5874 |
+
* @param {DOMElement} parentElement the host parent element that will be associated with the external element
|
5875 |
+
*/
|
5876 |
+
pin: $$animateQueue.pin,
|
5877 |
+
|
5878 |
+
/**
|
5879 |
+
*
|
5880 |
+
* @ngdoc method
|
5881 |
+
* @name $animate#enabled
|
5882 |
+
* @kind function
|
5883 |
+
* @description Used to get and set whether animations are enabled or not on the entire application or on an element and its children. This
|
5884 |
+
* function can be called in four ways:
|
5885 |
+
*
|
5886 |
+
* ```js
|
5887 |
+
* // returns true or false
|
5888 |
+
* $animate.enabled();
|
5889 |
+
*
|
5890 |
+
* // changes the enabled state for all animations
|
5891 |
+
* $animate.enabled(false);
|
5892 |
+
* $animate.enabled(true);
|
5893 |
+
*
|
5894 |
+
* // returns true or false if animations are enabled for an element
|
5895 |
+
* $animate.enabled(element);
|
5896 |
+
*
|
5897 |
+
* // changes the enabled state for an element and its children
|
5898 |
+
* $animate.enabled(element, true);
|
5899 |
+
* $animate.enabled(element, false);
|
5900 |
+
* ```
|
5901 |
+
*
|
5902 |
+
* @param {DOMElement=} element the element that will be considered for checking/setting the enabled state
|
5903 |
+
* @param {boolean=} enabled whether or not the animations will be enabled for the element
|
5904 |
+
*
|
5905 |
+
* @return {boolean} whether or not animations are enabled
|
5906 |
+
*/
|
5907 |
+
enabled: $$animateQueue.enabled,
|
5908 |
+
|
5909 |
+
/**
|
5910 |
+
* @ngdoc method
|
5911 |
+
* @name $animate#cancel
|
5912 |
+
* @kind function
|
5913 |
+
* @description Cancels the provided animation and applies the end state of the animation.
|
5914 |
+
* Note that this does not cancel the underlying operation, e.g. the setting of classes or
|
5915 |
+
* adding the element to the DOM.
|
5916 |
+
*
|
5917 |
+
* @param {animationRunner} animationRunner An animation runner returned by an $animate function.
|
5918 |
+
*
|
5919 |
+
* @example
|
5920 |
+
<example module="animationExample" deps="angular-animate.js" animations="true" name="animate-cancel">
|
5921 |
+
<file name="app.js">
|
5922 |
+
angular.module('animationExample', ['ngAnimate']).component('cancelExample', {
|
5923 |
templateUrl: 'template.html',
|
5924 |
controller: function($element, $animate) {
|
5925 |
this.runner = null;
|
5945 |
};
|
5946 |
}
|
5947 |
});
|
5948 |
+
</file>
|
5949 |
+
<file name="template.html">
|
5950 |
+
<p>
|
5951 |
+
<button id="add" ng-click="$ctrl.addClass()">Add</button>
|
5952 |
+
<button ng-click="$ctrl.removeClass()">Remove</button>
|
5953 |
+
<br>
|
5954 |
+
<button id="cancel" ng-click="$ctrl.cancel()" ng-disabled="!$ctrl.runner">Cancel</button>
|
5955 |
+
<br>
|
5956 |
+
<div id="target">CSS-Animated Text</div>
|
5957 |
+
</p>
|
5958 |
+
</file>
|
5959 |
+
<file name="index.html">
|
5960 |
+
<cancel-example></cancel-example>
|
5961 |
+
</file>
|
5962 |
+
<file name="style.css">
|
5963 |
+
.red-add, .red-remove {
|
5964 |
transition: all 4s cubic-bezier(0.250, 0.460, 0.450, 0.940);
|
5965 |
}
|
5966 |
|
5967 |
+
.red,
|
5968 |
+
.red-add.red-add-active {
|
5969 |
color: #FF0000;
|
5970 |
font-size: 40px;
|
5971 |
}
|
5972 |
|
5973 |
+
.red-remove.red-remove-active {
|
5974 |
font-size: 10px;
|
5975 |
color: black;
|
5976 |
}
|
5977 |
|
5978 |
+
</file>
|
5979 |
+
</example>
|
5980 |
+
*/
|
5981 |
+
cancel: function(runner) {
|
5982 |
+
if (runner.cancel) {
|
5983 |
+
runner.cancel();
|
5984 |
+
}
|
5985 |
+
},
|
5986 |
|
5987 |
+
/**
|
5988 |
+
*
|
5989 |
+
* @ngdoc method
|
5990 |
+
* @name $animate#enter
|
5991 |
+
* @kind function
|
5992 |
+
* @description Inserts the element into the DOM either after the `after` element (if provided) or
|
5993 |
+
* as the first child within the `parent` element and then triggers an animation.
|
5994 |
+
* A promise is returned that will be resolved during the next digest once the animation
|
5995 |
+
* has completed.
|
5996 |
+
*
|
5997 |
+
* @param {DOMElement} element the element which will be inserted into the DOM
|
5998 |
+
* @param {DOMElement} parent the parent element which will append the element as
|
5999 |
+
* a child (so long as the after element is not present)
|
6000 |
+
* @param {DOMElement=} after the sibling element after which the element will be appended
|
6001 |
+
* @param {object=} options an optional collection of options/styles that will be applied to the element.
|
6002 |
+
* The object can have the following properties:
|
6003 |
+
*
|
6004 |
+
* - **addClass** - `{string}` - space-separated CSS classes to add to element
|
6005 |
+
* - **from** - `{Object}` - CSS properties & values at the beginning of animation. Must have matching `to`
|
6006 |
+
* - **removeClass** - `{string}` - space-separated CSS classes to remove from element
|
6007 |
+
* - **to** - `{Object}` - CSS properties & values at end of animation. Must have matching `from`
|
6008 |
+
*
|
6009 |
+
* @return {Runner} the animation runner
|
6010 |
+
*/
|
6011 |
+
enter: function(element, parent, after, options) {
|
6012 |
+
parent = parent && jqLite(parent);
|
6013 |
+
after = after && jqLite(after);
|
6014 |
+
parent = parent || after.parent();
|
6015 |
+
domInsert(element, parent, after);
|
6016 |
+
return $$animateQueue.push(element, 'enter', prepareAnimateOptions(options));
|
6017 |
+
},
|
6018 |
|
6019 |
+
/**
|
6020 |
+
*
|
6021 |
+
* @ngdoc method
|
6022 |
+
* @name $animate#move
|
6023 |
+
* @kind function
|
6024 |
+
* @description Inserts (moves) the element into its new position in the DOM either after
|
6025 |
+
* the `after` element (if provided) or as the first child within the `parent` element
|
6026 |
+
* and then triggers an animation. A promise is returned that will be resolved
|
6027 |
+
* during the next digest once the animation has completed.
|
6028 |
+
*
|
6029 |
+
* @param {DOMElement} element the element which will be moved into the new DOM position
|
6030 |
+
* @param {DOMElement} parent the parent element which will append the element as
|
6031 |
+
* a child (so long as the after element is not present)
|
6032 |
+
* @param {DOMElement=} after the sibling element after which the element will be appended
|
6033 |
+
* @param {object=} options an optional collection of options/styles that will be applied to the element.
|
6034 |
+
* The object can have the following properties:
|
6035 |
+
*
|
6036 |
+
* - **addClass** - `{string}` - space-separated CSS classes to add to element
|
6037 |
+
* - **from** - `{Object}` - CSS properties & values at the beginning of animation. Must have matching `to`
|
6038 |
+
* - **removeClass** - `{string}` - space-separated CSS classes to remove from element
|
6039 |
+
* - **to** - `{Object}` - CSS properties & values at end of animation. Must have matching `from`
|
6040 |
+
*
|
6041 |
+
* @return {Runner} the animation runner
|
6042 |
+
*/
|
6043 |
+
move: function(element, parent, after, options) {
|
6044 |
+
parent = parent && jqLite(parent);
|
6045 |
+
after = after && jqLite(after);
|
6046 |
+
parent = parent || after.parent();
|
6047 |
+
domInsert(element, parent, after);
|
6048 |
+
return $$animateQueue.push(element, 'move', prepareAnimateOptions(options));
|
6049 |
+
},
|
6050 |
|
6051 |
+
/**
|
6052 |
+
* @ngdoc method
|
6053 |
+
* @name $animate#leave
|
6054 |
+
* @kind function
|
6055 |
+
* @description Triggers an animation and then removes the element from the DOM.
|
6056 |
+
* When the function is called a promise is returned that will be resolved during the next
|
6057 |
+
* digest once the animation has completed.
|
6058 |
+
*
|
6059 |
+
* @param {DOMElement} element the element which will be removed from the DOM
|
6060 |
+
* @param {object=} options an optional collection of options/styles that will be applied to the element.
|
6061 |
+
* The object can have the following properties:
|
6062 |
+
*
|
6063 |
+
* - **addClass** - `{string}` - space-separated CSS classes to add to element
|
6064 |
+
* - **from** - `{Object}` - CSS properties & values at the beginning of animation. Must have matching `to`
|
6065 |
+
* - **removeClass** - `{string}` - space-separated CSS classes to remove from element
|
6066 |
+
* - **to** - `{Object}` - CSS properties & values at end of animation. Must have matching `from`
|
6067 |
+
*
|
6068 |
+
* @return {Runner} the animation runner
|
6069 |
+
*/
|
6070 |
+
leave: function(element, options) {
|
6071 |
+
return $$animateQueue.push(element, 'leave', prepareAnimateOptions(options), function() {
|
6072 |
+
element.remove();
|
6073 |
+
});
|
6074 |
+
},
|
6075 |
|
6076 |
+
/**
|
6077 |
+
* @ngdoc method
|
6078 |
+
* @name $animate#addClass
|
6079 |
+
* @kind function
|
6080 |
+
*
|
6081 |
+
* @description Triggers an addClass animation surrounding the addition of the provided CSS class(es). Upon
|
6082 |
+
* execution, the addClass operation will only be handled after the next digest and it will not trigger an
|
6083 |
+
* animation if element already contains the CSS class or if the class is removed at a later step.
|
6084 |
+
* Note that class-based animations are treated differently compared to structural animations
|
6085 |
+
* (like enter, move and leave) since the CSS classes may be added/removed at different points
|
6086 |
+
* depending if CSS or JavaScript animations are used.
|
6087 |
+
*
|
6088 |
+
* @param {DOMElement} element the element which the CSS classes will be applied to
|
6089 |
+
* @param {string} className the CSS class(es) that will be added (multiple classes are separated via spaces)
|
6090 |
+
* @param {object=} options an optional collection of options/styles that will be applied to the element.
|
6091 |
+
* The object can have the following properties:
|
6092 |
+
*
|
6093 |
+
* - **removeClass** - `{string}` - space-separated CSS classes to remove from element
|
6094 |
+
* - **from** - `{Object}` - CSS properties & values at the beginning of animation. Must have matching `to`
|
6095 |
+
* - **to** - `{Object}` - CSS properties & values at end of animation. Must have matching `from`
|
6096 |
+
*
|
6097 |
+
* @return {Runner} animationRunner the animation runner
|
6098 |
+
*/
|
6099 |
+
addClass: function(element, className, options) {
|
6100 |
+
options = prepareAnimateOptions(options);
|
6101 |
+
options.addClass = mergeClasses(options.addclass, className);
|
6102 |
+
return $$animateQueue.push(element, 'addClass', options);
|
6103 |
+
},
|
6104 |
|
6105 |
+
/**
|
6106 |
+
* @ngdoc method
|
6107 |
+
* @name $animate#removeClass
|
6108 |
+
* @kind function
|
6109 |
+
*
|
6110 |
+
* @description Triggers a removeClass animation surrounding the removal of the provided CSS class(es). Upon
|
6111 |
+
* execution, the removeClass operation will only be handled after the next digest and it will not trigger an
|
6112 |
+
* animation if element does not contain the CSS class or if the class is added at a later step.
|
6113 |
+
* Note that class-based animations are treated differently compared to structural animations
|
6114 |
+
* (like enter, move and leave) since the CSS classes may be added/removed at different points
|
6115 |
+
* depending if CSS or JavaScript animations are used.
|
6116 |
+
*
|
6117 |
+
* @param {DOMElement} element the element which the CSS classes will be applied to
|
6118 |
+
* @param {string} className the CSS class(es) that will be removed (multiple classes are separated via spaces)
|
6119 |
+
* @param {object=} options an optional collection of options/styles that will be applied to the element.
|
6120 |
+
* The object can have the following properties:
|
6121 |
+
*
|
6122 |
+
* - **addClass** - `{string}` - space-separated CSS classes to add to element
|
6123 |
+
* - **from** - `{Object}` - CSS properties & values at the beginning of animation. Must have matching `to`
|
6124 |
+
* - **to** - `{Object}` - CSS properties & values at end of animation. Must have matching `from`
|
6125 |
+
*
|
6126 |
+
* @return {Runner} the animation runner
|
6127 |
+
*/
|
6128 |
+
removeClass: function(element, className, options) {
|
6129 |
+
options = prepareAnimateOptions(options);
|
6130 |
+
options.removeClass = mergeClasses(options.removeClass, className);
|
6131 |
+
return $$animateQueue.push(element, 'removeClass', options);
|
6132 |
+
},
|
6133 |
|
6134 |
+
/**
|
6135 |
+
* @ngdoc method
|
6136 |
+
* @name $animate#setClass
|
6137 |
+
* @kind function
|
6138 |
+
*
|
6139 |
+
* @description Performs both the addition and removal of a CSS classes on an element and (during the process)
|
6140 |
+
* triggers an animation surrounding the class addition/removal. Much like `$animate.addClass` and
|
6141 |
+
* `$animate.removeClass`, `setClass` will only evaluate the classes being added/removed once a digest has
|
6142 |
+
* passed. Note that class-based animations are treated differently compared to structural animations
|
6143 |
+
* (like enter, move and leave) since the CSS classes may be added/removed at different points
|
6144 |
+
* depending if CSS or JavaScript animations are used.
|
6145 |
+
*
|
6146 |
+
* @param {DOMElement} element the element which the CSS classes will be applied to
|
6147 |
+
* @param {string} add the CSS class(es) that will be added (multiple classes are separated via spaces)
|
6148 |
+
* @param {string} remove the CSS class(es) that will be removed (multiple classes are separated via spaces)
|
6149 |
+
* @param {object=} options an optional collection of options/styles that will be applied to the element.
|
6150 |
+
* The object can have the following properties:
|
6151 |
+
*
|
6152 |
+
* - **addClass** - `{string}` - space-separated CSS classes to add to element
|
6153 |
+
* - **removeClass** - `{string}` - space-separated CSS classes to remove from element
|
6154 |
+
* - **from** - `{Object}` - CSS properties & values at the beginning of animation. Must have matching `to`
|
6155 |
+
* - **to** - `{Object}` - CSS properties & values at end of animation. Must have matching `from`
|
6156 |
+
*
|
6157 |
+
* @return {Runner} the animation runner
|
6158 |
+
*/
|
6159 |
+
setClass: function(element, add, remove, options) {
|
6160 |
+
options = prepareAnimateOptions(options);
|
6161 |
+
options.addClass = mergeClasses(options.addClass, add);
|
6162 |
+
options.removeClass = mergeClasses(options.removeClass, remove);
|
6163 |
+
return $$animateQueue.push(element, 'setClass', options);
|
6164 |
+
},
|
6165 |
|
6166 |
+
/**
|
6167 |
+
* @ngdoc method
|
6168 |
+
* @name $animate#animate
|
6169 |
+
* @kind function
|
6170 |
+
*
|
6171 |
+
* @description Performs an inline animation on the element which applies the provided to and from CSS styles to the element.
|
6172 |
+
* If any detected CSS transition, keyframe or JavaScript matches the provided className value, then the animation will take
|
6173 |
+
* on the provided styles. For example, if a transition animation is set for the given className, then the provided `from` and
|
6174 |
+
* `to` styles will be applied alongside the given transition. If the CSS style provided in `from` does not have a corresponding
|
6175 |
+
* style in `to`, the style in `from` is applied immediately, and no animation is run.
|
6176 |
+
* If a JavaScript animation is detected then the provided styles will be given in as function parameters into the `animate`
|
6177 |
+
* method (or as part of the `options` parameter):
|
6178 |
+
*
|
6179 |
+
* ```js
|
6180 |
+
* ngModule.animation('.my-inline-animation', function() {
|
6181 |
* return {
|
6182 |
* animate : function(element, from, to, done, options) {
|
6183 |
* //animation
|
6185 |
* }
|
6186 |
* }
|
6187 |
* });
|
6188 |
+
* ```
|
6189 |
+
*
|
6190 |
+
* @param {DOMElement} element the element which the CSS styles will be applied to
|
6191 |
+
* @param {object} from the from (starting) CSS styles that will be applied to the element and across the animation.
|
6192 |
+
* @param {object} to the to (destination) CSS styles that will be applied to the element and across the animation.
|
6193 |
+
* @param {string=} className an optional CSS class that will be applied to the element for the duration of the animation. If
|
6194 |
+
* this value is left as empty then a CSS class of `ng-inline-animate` will be applied to the element.
|
6195 |
+
* (Note that if no animation is detected then this value will not be applied to the element.)
|
6196 |
+
* @param {object=} options an optional collection of options/styles that will be applied to the element.
|
6197 |
+
* The object can have the following properties:
|
6198 |
+
*
|
6199 |
+
* - **addClass** - `{string}` - space-separated CSS classes to add to element
|
6200 |
+
* - **from** - `{Object}` - CSS properties & values at the beginning of animation. Must have matching `to`
|
6201 |
+
* - **removeClass** - `{string}` - space-separated CSS classes to remove from element
|
6202 |
+
* - **to** - `{Object}` - CSS properties & values at end of animation. Must have matching `from`
|
6203 |
+
*
|
6204 |
+
* @return {Runner} the animation runner
|
6205 |
+
*/
|
6206 |
+
animate: function(element, from, to, className, options) {
|
6207 |
+
options = prepareAnimateOptions(options);
|
6208 |
+
options.from = options.from ? extend(options.from, from) : from;
|
6209 |
+
options.to = options.to ? extend(options.to, to) : to;
|
6210 |
+
|
6211 |
+
className = className || 'ng-inline-animate';
|
6212 |
+
options.tempClasses = mergeClasses(options.tempClasses, className);
|
6213 |
+
return $$animateQueue.push(element, 'animate', options);
|
6214 |
+
}
|
6215 |
+
};
|
6216 |
+
}];
|
6217 |
+
}];
|
6218 |
|
6219 |
+
var $$AnimateAsyncRunFactoryProvider = /** @this */ function() {
|
6220 |
+
this.$get = ['$$rAF', function($$rAF) {
|
6221 |
+
var waitQueue = [];
|
6222 |
|
6223 |
+
function waitForTick(fn) {
|
6224 |
+
waitQueue.push(fn);
|
6225 |
+
if (waitQueue.length > 1) return;
|
6226 |
+
$$rAF(function() {
|
6227 |
+
for (var i = 0; i < waitQueue.length; i++) {
|
6228 |
+
waitQueue[i]();
|
6229 |
+
}
|
6230 |
+
waitQueue = [];
|
6231 |
+
});
|
6232 |
+
}
|
6233 |
|
6234 |
+
return function() {
|
6235 |
+
var passed = false;
|
6236 |
+
waitForTick(function() {
|
6237 |
+
passed = true;
|
6238 |
+
});
|
6239 |
+
return function(callback) {
|
6240 |
+
if (passed) {
|
6241 |
+
callback();
|
6242 |
+
} else {
|
6243 |
+
waitForTick(callback);
|
6244 |
+
}
|
6245 |
+
};
|
|
|
|
|
6246 |
};
|
6247 |
+
}];
|
6248 |
+
};
|
6249 |
|
6250 |
+
var $$AnimateRunnerFactoryProvider = /** @this */ function() {
|
6251 |
+
this.$get = ['$q', '$sniffer', '$$animateAsyncRun', '$$isDocumentHidden', '$timeout',
|
6252 |
+
function($q, $sniffer, $$animateAsyncRun, $$isDocumentHidden, $timeout) {
|
6253 |
|
6254 |
+
var INITIAL_STATE = 0;
|
6255 |
+
var DONE_PENDING_STATE = 1;
|
6256 |
+
var DONE_COMPLETE_STATE = 2;
|
6257 |
|
6258 |
+
AnimateRunner.chain = function(chain, callback) {
|
6259 |
+
var index = 0;
|
6260 |
|
6261 |
+
next();
|
6262 |
+
function next() {
|
6263 |
+
if (index === chain.length) {
|
6264 |
+
callback(true);
|
6265 |
+
return;
|
6266 |
+
}
|
6267 |
|
6268 |
+
chain[index](function(response) {
|
6269 |
+
if (response === false) {
|
6270 |
+
callback(false);
|
6271 |
+
return;
|
6272 |
+
}
|
6273 |
+
index++;
|
6274 |
+
next();
|
6275 |
+
});
|
6276 |
+
}
|
6277 |
+
};
|
6278 |
|
6279 |
+
AnimateRunner.all = function(runners, callback) {
|
6280 |
+
var count = 0;
|
6281 |
+
var status = true;
|
6282 |
+
forEach(runners, function(runner) {
|
6283 |
+
runner.done(onProgress);
|
6284 |
+
});
|
6285 |
|
6286 |
+
function onProgress(response) {
|
6287 |
+
status = status && response;
|
6288 |
+
if (++count === runners.length) {
|
6289 |
+
callback(status);
|
6290 |
+
}
|
6291 |
+
}
|
6292 |
+
};
|
6293 |
|
6294 |
+
function AnimateRunner(host) {
|
6295 |
+
this.setHost(host);
|
6296 |
|
6297 |
+
var rafTick = $$animateAsyncRun();
|
6298 |
+
var timeoutTick = function(fn) {
|
6299 |
+
$timeout(fn, 0, false);
|
6300 |
+
};
|
6301 |
|
6302 |
+
this._doneCallbacks = [];
|
6303 |
+
this._tick = function(fn) {
|
6304 |
+
if ($$isDocumentHidden()) {
|
6305 |
+
timeoutTick(fn);
|
6306 |
+
} else {
|
6307 |
+
rafTick(fn);
|
6308 |
+
}
|
6309 |
+
};
|
6310 |
+
this._state = 0;
|
6311 |
+
}
|
6312 |
|
6313 |
+
AnimateRunner.prototype = {
|
6314 |
+
setHost: function(host) {
|
6315 |
+
this.host = host || {};
|
6316 |
+
},
|
6317 |
|
6318 |
+
done: function(fn) {
|
6319 |
+
if (this._state === DONE_COMPLETE_STATE) {
|
6320 |
+
fn();
|
6321 |
+
} else {
|
6322 |
+
this._doneCallbacks.push(fn);
|
6323 |
+
}
|
6324 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6325 |
|
6326 |
+
progress: noop,
|
6327 |
+
|
6328 |
+
getPromise: function() {
|
6329 |
+
if (!this.promise) {
|
6330 |
+
var self = this;
|
6331 |
+
this.promise = $q(function(resolve, reject) {
|
6332 |
+
self.done(function(status) {
|
6333 |
+
if (status === false) {
|
6334 |
+
reject();
|
6335 |
+
} else {
|
6336 |
+
resolve();
|
6337 |
+
}
|
6338 |
+
});
|
6339 |
+
});
|
6340 |
+
}
|
6341 |
+
return this.promise;
|
6342 |
+
},
|
6343 |
|
6344 |
+
then: function(resolveHandler, rejectHandler) {
|
6345 |
+
return this.getPromise().then(resolveHandler, rejectHandler);
|
6346 |
+
},
|
6347 |
|
6348 |
+
'catch': function(handler) {
|
6349 |
+
return this.getPromise()['catch'](handler);
|
6350 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6351 |
|
6352 |
+
'finally': function(handler) {
|
6353 |
+
return this.getPromise()['finally'](handler);
|
6354 |
+
},
|
6355 |
|
6356 |
+
pause: function() {
|
6357 |
+
if (this.host.pause) {
|
6358 |
+
this.host.pause();
|
6359 |
+
}
|
6360 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6361 |
|
6362 |
+
resume: function() {
|
6363 |
+
if (this.host.resume) {
|
6364 |
+
this.host.resume();
|
6365 |
+
}
|
6366 |
+
},
|
|
|
6367 |
|
6368 |
+
end: function() {
|
6369 |
+
if (this.host.end) {
|
6370 |
+
this.host.end();
|
6371 |
+
}
|
6372 |
+
this._resolve(true);
|
6373 |
+
},
|
6374 |
|
6375 |
+
cancel: function() {
|
6376 |
+
if (this.host.cancel) {
|
6377 |
+
this.host.cancel();
|
6378 |
+
}
|
6379 |
+
this._resolve(false);
|
6380 |
+
},
|
6381 |
|
6382 |
+
complete: function(response) {
|
6383 |
+
var self = this;
|
6384 |
+
if (self._state === INITIAL_STATE) {
|
6385 |
+
self._state = DONE_PENDING_STATE;
|
6386 |
+
self._tick(function() {
|
6387 |
+
self._resolve(response);
|
6388 |
+
});
|
6389 |
+
}
|
6390 |
+
},
|
|
|
6391 |
|
6392 |
+
_resolve: function(response) {
|
6393 |
+
if (this._state !== DONE_COMPLETE_STATE) {
|
6394 |
+
forEach(this._doneCallbacks, function(fn) {
|
6395 |
+
fn(response);
|
6396 |
+
});
|
6397 |
+
this._doneCallbacks.length = 0;
|
6398 |
+
this._state = DONE_COMPLETE_STATE;
|
6399 |
+
}
|
6400 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6401 |
};
|
6402 |
|
6403 |
+
return AnimateRunner;
|
6404 |
+
}];
|
6405 |
+
};
|
6406 |
|
6407 |
+
/* exported $CoreAnimateCssProvider */
|
|
|
|
|
|
|
6408 |
|
6409 |
+
/**
|
6410 |
+
* @ngdoc service
|
6411 |
+
* @name $animateCss
|
6412 |
+
* @kind object
|
6413 |
+
* @this
|
6414 |
+
*
|
6415 |
+
* @description
|
6416 |
+
* This is the core version of `$animateCss`. By default, only when the `ngAnimate` is included,
|
6417 |
+
* then the `$animateCss` service will actually perform animations.
|
6418 |
+
*
|
6419 |
+
* Click here {@link ngAnimate.$animateCss to read the documentation for $animateCss}.
|
6420 |
+
*/
|
6421 |
+
var $CoreAnimateCssProvider = function() {
|
6422 |
+
this.$get = ['$$rAF', '$q', '$$AnimateRunner', function($$rAF, $q, $$AnimateRunner) {
|
6423 |
+
|
6424 |
+
return function(element, initialOptions) {
|
6425 |
+
// all of the animation functions should create
|
6426 |
+
// a copy of the options data, however, if a
|
6427 |
+
// parent service has already created a copy then
|
6428 |
+
// we should stick to using that
|
6429 |
+
var options = initialOptions || {};
|
6430 |
+
if (!options.$$prepared) {
|
6431 |
+
options = copy(options);
|
6432 |
+
}
|
6433 |
|
6434 |
+
// there is no point in applying the styles since
|
6435 |
+
// there is no animation that goes on at all in
|
6436 |
+
// this version of $animateCss.
|
6437 |
+
if (options.cleanupStyles) {
|
6438 |
+
options.from = options.to = null;
|
6439 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6440 |
|
6441 |
+
if (options.from) {
|
6442 |
+
element.css(options.from);
|
6443 |
+
options.from = null;
|
6444 |
+
}
|
6445 |
|
6446 |
+
var closed, runner = new $$AnimateRunner();
|
6447 |
+
return {
|
6448 |
+
start: run,
|
6449 |
+
end: run
|
6450 |
+
};
|
6451 |
+
|
6452 |
+
function run() {
|
6453 |
+
$$rAF(function() {
|
6454 |
+
applyAnimationContents();
|
6455 |
+
if (!closed) {
|
6456 |
+
runner.complete();
|
6457 |
+
}
|
6458 |
+
closed = true;
|
6459 |
+
});
|
6460 |
+
return runner;
|
6461 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6462 |
|
6463 |
+
function applyAnimationContents() {
|
6464 |
+
if (options.addClass) {
|
6465 |
+
element.addClass(options.addClass);
|
6466 |
+
options.addClass = null;
|
6467 |
+
}
|
6468 |
+
if (options.removeClass) {
|
6469 |
+
element.removeClass(options.removeClass);
|
6470 |
+
options.removeClass = null;
|
6471 |
+
}
|
6472 |
+
if (options.to) {
|
6473 |
+
element.css(options.to);
|
6474 |
+
options.to = null;
|
6475 |
+
}
|
6476 |
+
}
|
6477 |
+
};
|
6478 |
+
}];
|
6479 |
+
};
|
6480 |
|
6481 |
+
/* global getHash: true, stripHash: false */
|
|
|
|
|
6482 |
|
6483 |
+
function getHash(url) {
|
6484 |
+
var index = url.indexOf('#');
|
6485 |
+
return index === -1 ? '' : url.substr(index);
|
6486 |
+
}
|
6487 |
|
6488 |
+
function trimEmptyHash(url) {
|
6489 |
+
return url.replace(/#$/, '');
|
6490 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6491 |
|
6492 |
+
/**
|
6493 |
+
* ! This is a private undocumented service !
|
6494 |
+
*
|
6495 |
+
* @name $browser
|
6496 |
+
* @requires $log
|
6497 |
+
* @description
|
6498 |
+
* This object has two goals:
|
6499 |
+
*
|
6500 |
+
* - hide all the global state in the browser caused by the window object
|
6501 |
+
* - abstract away all the browser specific features and inconsistencies
|
6502 |
+
*
|
6503 |
+
* For tests we provide {@link ngMock.$browser mock implementation} of the `$browser`
|
6504 |
+
* service, which can be used for convenient testing of the application without the interaction with
|
6505 |
+
* the real browser apis.
|
6506 |
+
*/
|
6507 |
+
/**
|
6508 |
+
* @param {object} window The global window object.
|
6509 |
+
* @param {object} document jQuery wrapped document.
|
6510 |
+
* @param {object} $log window.console or an object with the same interface.
|
6511 |
+
* @param {object} $sniffer $sniffer service
|
6512 |
+
*/
|
6513 |
+
function Browser(window, document, $log, $sniffer, $$taskTrackerFactory) {
|
6514 |
+
var self = this,
|
6515 |
+
location = window.location,
|
6516 |
+
history = window.history,
|
6517 |
+
setTimeout = window.setTimeout,
|
6518 |
+
clearTimeout = window.clearTimeout,
|
6519 |
+
pendingDeferIds = {},
|
6520 |
+
taskTracker = $$taskTrackerFactory($log);
|
6521 |
+
|
6522 |
+
self.isMock = false;
|
6523 |
+
|
6524 |
+
//////////////////////////////////////////////////////////////
|
6525 |
+
// Task-tracking API
|
6526 |
+
//////////////////////////////////////////////////////////////
|
6527 |
+
|
6528 |
+
// TODO(vojta): remove this temporary api
|
6529 |
+
self.$$completeOutstandingRequest = taskTracker.completeTask;
|
6530 |
+
self.$$incOutstandingRequestCount = taskTracker.incTaskCount;
|
6531 |
+
|
6532 |
+
// TODO(vojta): prefix this method with $$ ?
|
6533 |
+
self.notifyWhenNoOutstandingRequests = taskTracker.notifyWhenNoPendingTasks;
|
6534 |
+
|
6535 |
+
//////////////////////////////////////////////////////////////
|
6536 |
+
// URL API
|
6537 |
+
//////////////////////////////////////////////////////////////
|
6538 |
+
|
6539 |
+
var cachedState, lastHistoryState,
|
6540 |
+
lastBrowserUrl = location.href,
|
6541 |
+
baseElement = document.find('base'),
|
6542 |
+
pendingLocation = null,
|
6543 |
+
getCurrentState = !$sniffer.history ? noop : function getCurrentState() {
|
6544 |
+
try {
|
6545 |
+
return history.state;
|
6546 |
+
} catch (e) {
|
6547 |
+
// MSIE can reportedly throw when there is no state (UNCONFIRMED).
|
6548 |
+
}
|
6549 |
+
};
|
6550 |
|
6551 |
+
cacheState();
|
|
|
6552 |
|
6553 |
+
/**
|
6554 |
+
* @name $browser#url
|
6555 |
+
*
|
6556 |
+
* @description
|
6557 |
+
* GETTER:
|
6558 |
+
* Without any argument, this method just returns current value of `location.href` (with a
|
6559 |
+
* trailing `#` stripped of if the hash is empty).
|
6560 |
+
*
|
6561 |
+
* SETTER:
|
6562 |
+
* With at least one argument, this method sets url to new value.
|
6563 |
+
* If html5 history api supported, `pushState`/`replaceState` is used, otherwise
|
6564 |
+
* `location.href`/`location.replace` is used.
|
6565 |
+
* Returns its own instance to allow chaining.
|
6566 |
+
*
|
6567 |
+
* NOTE: this api is intended for use only by the `$location` service. Please use the
|
6568 |
+
* {@link ng.$location $location service} to change url.
|
6569 |
+
*
|
6570 |
+
* @param {string} url New url (when used as setter)
|
6571 |
+
* @param {boolean=} replace Should new url replace current history record?
|
6572 |
+
* @param {object=} state State object to use with `pushState`/`replaceState`
|
6573 |
+
*/
|
6574 |
+
self.url = function(url, replace, state) {
|
6575 |
+
// In modern browsers `history.state` is `null` by default; treating it separately
|
6576 |
+
// from `undefined` would cause `$browser.url('/foo')` to change `history.state`
|
6577 |
+
// to undefined via `pushState`. Instead, let's change `undefined` to `null` here.
|
6578 |
+
if (isUndefined(state)) {
|
6579 |
+
state = null;
|
6580 |
+
}
|
6581 |
+
|
6582 |
+
// Android Browser BFCache causes location, history reference to become stale.
|
6583 |
+
if (location !== window.location) location = window.location;
|
6584 |
+
if (history !== window.history) history = window.history;
|
6585 |
+
|
6586 |
+
// setter
|
6587 |
+
if (url) {
|
6588 |
+
var sameState = lastHistoryState === state;
|
6589 |
+
|
6590 |
+
// Normalize the inputted URL
|
6591 |
+
url = urlResolve(url).href;
|
6592 |
+
|
6593 |
+
// Don't change anything if previous and current URLs and states match. This also prevents
|
6594 |
+
// IE<10 from getting into redirect loop when in LocationHashbangInHtml5Url mode.
|
6595 |
+
// See https://github.com/angular/angular.js/commit/ffb2701
|
6596 |
+
if (lastBrowserUrl === url && (!$sniffer.history || sameState)) {
|
6597 |
+
return self;
|
6598 |
+
}
|
6599 |
+
var sameBase = lastBrowserUrl && stripHash(lastBrowserUrl) === stripHash(url);
|
6600 |
+
lastBrowserUrl = url;
|
6601 |
+
lastHistoryState = state;
|
6602 |
+
// Don't use history API if only the hash changed
|
6603 |
+
// due to a bug in IE10/IE11 which leads
|
6604 |
+
// to not firing a `hashchange` nor `popstate` event
|
6605 |
+
// in some cases (see #9143).
|
6606 |
+
if ($sniffer.history && (!sameBase || !sameState)) {
|
6607 |
+
history[replace ? 'replaceState' : 'pushState'](state, '', url);
|
6608 |
+
cacheState();
|
6609 |
+
} else {
|
6610 |
+
if (!sameBase) {
|
6611 |
+
pendingLocation = url;
|
6612 |
+
}
|
6613 |
+
if (replace) {
|
6614 |
+
location.replace(url);
|
6615 |
+
} else if (!sameBase) {
|
6616 |
+
location.href = url;
|
6617 |
+
} else {
|
6618 |
+
location.hash = getHash(url);
|
6619 |
}
|
6620 |
+
if (location.href !== url) {
|
6621 |
+
pendingLocation = url;
|
6622 |
+
}
|
6623 |
+
}
|
6624 |
+
if (pendingLocation) {
|
6625 |
+
pendingLocation = url;
|
6626 |
+
}
|
6627 |
+
return self;
|
6628 |
+
// getter
|
6629 |
+
} else {
|
6630 |
+
// - pendingLocation is needed as browsers don't allow to read out
|
6631 |
+
// the new location.href if a reload happened or if there is a bug like in iOS 9 (see
|
6632 |
+
// https://openradar.appspot.com/22186109).
|
6633 |
+
return trimEmptyHash(pendingLocation || location.href);
|
6634 |
+
}
|
6635 |
+
};
|
6636 |
|
6637 |
+
/**
|
6638 |
+
* @name $browser#state
|
6639 |
+
*
|
6640 |
+
* @description
|
6641 |
+
* This method is a getter.
|
6642 |
+
*
|
6643 |
+
* Return history.state or null if history.state is undefined.
|
6644 |
+
*
|
6645 |
+
* @returns {object} state
|
6646 |
+
*/
|
6647 |
+
self.state = function() {
|
6648 |
+
return cachedState;
|
6649 |
+
};
|
6650 |
|
6651 |
+
var urlChangeListeners = [],
|
6652 |
+
urlChangeInit = false;
|
|
|
|
|
6653 |
|
6654 |
+
function cacheStateAndFireUrlChange() {
|
6655 |
+
pendingLocation = null;
|
6656 |
+
fireStateOrUrlChange();
|
6657 |
+
}
|
6658 |
|
6659 |
+
// This variable should be used *only* inside the cacheState function.
|
6660 |
+
var lastCachedState = null;
|
6661 |
+
function cacheState() {
|
6662 |
+
// This should be the only place in $browser where `history.state` is read.
|
6663 |
+
cachedState = getCurrentState();
|
6664 |
+
cachedState = isUndefined(cachedState) ? null : cachedState;
|
6665 |
|
6666 |
+
// Prevent callbacks fo fire twice if both hashchange & popstate were fired.
|
6667 |
+
if (equals(cachedState, lastCachedState)) {
|
6668 |
+
cachedState = lastCachedState;
|
6669 |
+
}
|
6670 |
|
6671 |
+
lastCachedState = cachedState;
|
6672 |
+
lastHistoryState = cachedState;
|
6673 |
+
}
|
|
|
|
|
|
|
6674 |
|
6675 |
+
function fireStateOrUrlChange() {
|
6676 |
+
var prevLastHistoryState = lastHistoryState;
|
6677 |
+
cacheState();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6678 |
|
6679 |
+
if (lastBrowserUrl === self.url() && prevLastHistoryState === cachedState) {
|
6680 |
+
return;
|
6681 |
+
}
|
6682 |
|
6683 |
+
lastBrowserUrl = self.url();
|
6684 |
+
lastHistoryState = cachedState;
|
6685 |
+
forEach(urlChangeListeners, function(listener) {
|
6686 |
+
listener(self.url(), cachedState);
|
6687 |
+
});
|
6688 |
+
}
|
|
|
|
|
|
|
6689 |
|
6690 |
+
/**
|
6691 |
+
* @name $browser#onUrlChange
|
6692 |
+
*
|
6693 |
+
* @description
|
6694 |
+
* Register callback function that will be called, when url changes.
|
6695 |
+
*
|
6696 |
+
* It's only called when the url is changed from outside of AngularJS:
|
6697 |
+
* - user types different url into address bar
|
6698 |
+
* - user clicks on history (forward/back) button
|
6699 |
+
* - user clicks on a link
|
6700 |
+
*
|
6701 |
+
* It's not called when url is changed by $browser.url() method
|
6702 |
+
*
|
6703 |
+
* The listener gets called with new url as parameter.
|
6704 |
+
*
|
6705 |
+
* NOTE: this api is intended for use only by the $location service. Please use the
|
6706 |
+
* {@link ng.$location $location service} to monitor url changes in AngularJS apps.
|
6707 |
+
*
|
6708 |
+
* @param {function(string)} listener Listener function to be called when url changes.
|
6709 |
+
* @return {function(string)} Returns the registered listener fn - handy if the fn is anonymous.
|
6710 |
+
*/
|
6711 |
+
self.onUrlChange = function(callback) {
|
6712 |
+
// TODO(vojta): refactor to use node's syntax for events
|
6713 |
+
if (!urlChangeInit) {
|
6714 |
+
// We listen on both (hashchange/popstate) when available, as some browsers don't
|
6715 |
+
// fire popstate when user changes the address bar and don't fire hashchange when url
|
6716 |
+
// changed by push/replaceState
|
6717 |
|
6718 |
+
// html5 history api - popstate event
|
6719 |
+
if ($sniffer.history) jqLite(window).on('popstate', cacheStateAndFireUrlChange);
|
6720 |
+
// hashchange event
|
6721 |
+
jqLite(window).on('hashchange', cacheStateAndFireUrlChange);
|
6722 |
|
6723 |
+
urlChangeInit = true;
|
6724 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6725 |
|
6726 |
+
urlChangeListeners.push(callback);
|
6727 |
+
return callback;
|
6728 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6729 |
|
6730 |
+
/**
|
6731 |
+
* @private
|
6732 |
+
* Remove popstate and hashchange handler from window.
|
6733 |
+
*
|
6734 |
+
* NOTE: this api is intended for use only by $rootScope.
|
6735 |
+
*/
|
6736 |
+
self.$$applicationDestroyed = function() {
|
6737 |
+
jqLite(window).off('hashchange popstate', cacheStateAndFireUrlChange);
|
6738 |
+
};
|
6739 |
+
|
6740 |
+
/**
|
6741 |
+
* Checks whether the url has changed outside of AngularJS.
|
6742 |
+
* Needs to be exported to be able to check for changes that have been done in sync,
|
6743 |
+
* as hashchange/popstate events fire in async.
|
6744 |
+
*/
|
6745 |
+
self.$$checkUrlChange = fireStateOrUrlChange;
|
6746 |
|
6747 |
+
//////////////////////////////////////////////////////////////
|
6748 |
+
// Misc API
|
6749 |
+
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
6750 |
|
6751 |
+
/**
|
6752 |
+
* @name $browser#baseHref
|
6753 |
+
*
|
6754 |
+
* @description
|
6755 |
+
* Returns current <base href>
|
6756 |
+
* (always relative - without domain)
|
6757 |
+
*
|
6758 |
+
* @returns {string} The current base href
|
6759 |
+
*/
|
6760 |
+
self.baseHref = function() {
|
6761 |
+
var href = baseElement.attr('href');
|
6762 |
+
return href ? href.replace(/^(https?:)?\/\/[^/]*/, '') : '';
|
6763 |
+
};
|
6764 |
+
|
6765 |
+
/**
|
6766 |
+
* @name $browser#defer
|
6767 |
+
* @param {function()} fn A function, who's execution should be deferred.
|
6768 |
+
* @param {number=} [delay=0] Number of milliseconds to defer the function execution.
|
6769 |
+
* @param {string=} [taskType=DEFAULT_TASK_TYPE] The type of task that is deferred.
|
6770 |
+
* @returns {*} DeferId that can be used to cancel the task via `$browser.defer.cancel()`.
|
6771 |
+
*
|
6772 |
+
* @description
|
6773 |
+
* Executes a fn asynchronously via `setTimeout(fn, delay)`.
|
6774 |
+
*
|
6775 |
+
* Unlike when calling `setTimeout` directly, in test this function is mocked and instead of using
|
6776 |
+
* `setTimeout` in tests, the fns are queued in an array, which can be programmatically flushed
|
6777 |
+
* via `$browser.defer.flush()`.
|
6778 |
+
*
|
6779 |
+
*/
|
6780 |
+
self.defer = function(fn, delay, taskType) {
|
6781 |
+
var timeoutId;
|
6782 |
|
6783 |
+
delay = delay || 0;
|
6784 |
+
taskType = taskType || taskTracker.DEFAULT_TASK_TYPE;
|
6785 |
|
6786 |
+
taskTracker.incTaskCount(taskType);
|
6787 |
+
timeoutId = setTimeout(function() {
|
6788 |
+
delete pendingDeferIds[timeoutId];
|
6789 |
+
taskTracker.completeTask(fn, taskType);
|
6790 |
+
}, delay);
|
6791 |
+
pendingDeferIds[timeoutId] = taskType;
|
6792 |
+
|
6793 |
+
return timeoutId;
|
6794 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6795 |
|
|
|
6796 |
|
6797 |
+
/**
|
6798 |
+
* @name $browser#defer.cancel
|
6799 |
+
*
|
6800 |
+
* @description
|
6801 |
+
* Cancels a deferred task identified with `deferId`.
|
6802 |
+
*
|
6803 |
+
* @param {*} deferId Token returned by the `$browser.defer` function.
|
6804 |
+
* @returns {boolean} Returns `true` if the task hasn't executed yet and was successfully
|
6805 |
+
* canceled.
|
6806 |
+
*/
|
6807 |
+
self.defer.cancel = function(deferId) {
|
6808 |
+
if (pendingDeferIds.hasOwnProperty(deferId)) {
|
6809 |
+
var taskType = pendingDeferIds[deferId];
|
6810 |
+
delete pendingDeferIds[deferId];
|
6811 |
+
clearTimeout(deferId);
|
6812 |
+
taskTracker.completeTask(noop, taskType);
|
6813 |
+
return true;
|
6814 |
}
|
6815 |
+
return false;
|
6816 |
+
};
|
6817 |
|
6818 |
+
}
|
6819 |
+
|
6820 |
+
/** @this */
|
6821 |
+
function $BrowserProvider() {
|
6822 |
+
this.$get = ['$window', '$log', '$sniffer', '$document', '$$taskTrackerFactory',
|
6823 |
+
function($window, $log, $sniffer, $document, $$taskTrackerFactory) {
|
6824 |
+
return new Browser($window, $document, $log, $sniffer, $$taskTrackerFactory);
|
6825 |
+
}];
|
6826 |
+
}
|
6827 |
+
|
6828 |
+
/**
|
6829 |
+
* @ngdoc service
|
6830 |
+
* @name $cacheFactory
|
6831 |
+
* @this
|
6832 |
+
*
|
6833 |
+
* @description
|
6834 |
+
* Factory that constructs {@link $cacheFactory.Cache Cache} objects and gives access to
|
6835 |
+
* them.
|
6836 |
+
*
|
6837 |
+
* ```js
|
6838 |
+
*
|
6839 |
+
* var cache = $cacheFactory('cacheId');
|
6840 |
+
* expect($cacheFactory.get('cacheId')).toBe(cache);
|
6841 |
+
* expect($cacheFactory.get('noSuchCacheId')).not.toBeDefined();
|
6842 |
+
*
|
6843 |
+
* cache.put("key", "value");
|
6844 |
+
* cache.put("another key", "another value");
|
6845 |
+
*
|
6846 |
+
* // We've specified no options on creation
|
6847 |
+
* expect(cache.info()).toEqual({id: 'cacheId', size: 2});
|
6848 |
+
*
|
6849 |
+
* ```
|
6850 |
+
*
|
6851 |
+
*
|
6852 |
+
* @param {string} cacheId Name or id of the newly created cache.
|
6853 |
+
* @param {object=} options Options object that specifies the cache behavior. Properties:
|
6854 |
+
*
|
6855 |
+
* - `{number=}` `capacity` — turns the cache into LRU cache.
|
6856 |
+
*
|
6857 |
+
* @returns {object} Newly created cache object with the following set of methods:
|
6858 |
+
*
|
6859 |
+
* - `{object}` `info()` — Returns id, size, and options of cache.
|
6860 |
+
* - `{{*}}` `put({string} key, {*} value)` — Puts a new key-value pair into the cache and returns
|
6861 |
+
* it.
|
6862 |
+
* - `{{*}}` `get({string} key)` — Returns cached value for `key` or undefined for cache miss.
|
6863 |
+
* - `{void}` `remove({string} key)` — Removes a key-value pair from the cache.
|
6864 |
+
* - `{void}` `removeAll()` — Removes all cached values.
|
6865 |
+
* - `{void}` `destroy()` — Removes references to this cache from $cacheFactory.
|
6866 |
+
*
|
6867 |
+
* @example
|
6868 |
+
<example module="cacheExampleApp" name="cache-factory">
|
6869 |
<file name="index.html">
|
6870 |
+
<div ng-controller="CacheController">
|
6871 |
+
<input ng-model="newCacheKey" placeholder="Key">
|
6872 |
+
<input ng-model="newCacheValue" placeholder="Value">
|
6873 |
+
<button ng-click="put(newCacheKey, newCacheValue)">Cache</button>
|
6874 |
+
|
6875 |
+
<p ng-if="keys.length">Cached Values</p>
|
6876 |
+
<div ng-repeat="key in keys">
|
6877 |
+
<span ng-bind="key"></span>
|
6878 |
+
<span>: </span>
|
6879 |
+
<b ng-bind="cache.get(key)"></b>
|
6880 |
+
</div>
|
6881 |
|
6882 |
+
<p>Cache Info</p>
|
6883 |
+
<div ng-repeat="(key, value) in cache.info()">
|
6884 |
+
<span ng-bind="key"></span>
|
6885 |
+
<span>: </span>
|
6886 |
+
<b ng-bind="value"></b>
|
6887 |
+
</div>
|
6888 |
+
</div>
|
6889 |
</file>
|
6890 |
<file name="script.js">
|
6891 |
+
angular.module('cacheExampleApp', []).
|
6892 |
+
controller('CacheController', ['$scope', '$cacheFactory', function($scope, $cacheFactory) {
|
6893 |
$scope.keys = [];
|
6894 |
$scope.cache = $cacheFactory('cacheId');
|
6895 |
$scope.put = function(key, value) {
|
6901 |
}]);
|
6902 |
</file>
|
6903 |
<file name="style.css">
|
6904 |
+
p {
|
6905 |
margin: 10px 0 3px;
|
6906 |
}
|
6907 |
</file>
|
6908 |
+
</example>
|
6909 |
+
*/
|
6910 |
+
function $CacheFactoryProvider() {
|
6911 |
|
6912 |
+
this.$get = function() {
|
6913 |
+
var caches = {};
|
6914 |
|
6915 |
+
function cacheFactory(cacheId, options) {
|
6916 |
+
if (cacheId in caches) {
|
6917 |
+
throw minErr('$cacheFactory')('iid', 'CacheId \'{0}\' is already taken!', cacheId);
|
6918 |
+
}
|
6919 |
|
6920 |
+
var size = 0,
|
6921 |
+
stats = extend({}, options, {id: cacheId}),
|
6922 |
+
data = createMap(),
|
6923 |
+
capacity = (options && options.capacity) || Number.MAX_VALUE,
|
6924 |
+
lruHash = createMap(),
|
6925 |
+
freshEnd = null,
|
6926 |
+
staleEnd = null;
|
6927 |
+
|
6928 |
+
/**
|
6929 |
+
* @ngdoc type
|
6930 |
+
* @name $cacheFactory.Cache
|
6931 |
+
*
|
6932 |
+
* @description
|
6933 |
+
* A cache object used to store and retrieve data, primarily used by
|
6934 |
+
* {@link $templateRequest $templateRequest} and the {@link ng.directive:script script}
|
6935 |
+
* directive to cache templates and other data.
|
6936 |
+
*
|
6937 |
+
* ```js
|
6938 |
+
* angular.module('superCache')
|
6939 |
+
* .factory('superCache', ['$cacheFactory', function($cacheFactory) {
|
6940 |
* return $cacheFactory('super-cache');
|
6941 |
* }]);
|
6942 |
+
* ```
|
6943 |
+
*
|
6944 |
+
* Example test:
|
6945 |
+
*
|
6946 |
+
* ```js
|
6947 |
+
* it('should behave like a cache', inject(function(superCache) {
|
6948 |
+
* superCache.put('key', 'value');
|
6949 |
+
* superCache.put('another key', 'another value');
|
6950 |
*
|
6951 |
* expect(superCache.info()).toEqual({
|
6952 |
* id: 'super-cache',
|
6962 |
* size: 0
|
6963 |
* });
|
6964 |
* }));
|
6965 |
+
* ```
|
6966 |
+
*/
|
6967 |
+
return (caches[cacheId] = {
|
6968 |
|
6969 |
+
/**
|
6970 |
+
* @ngdoc method
|
6971 |
+
* @name $cacheFactory.Cache#put
|
6972 |
+
* @kind function
|
6973 |
+
*
|
6974 |
+
* @description
|
6975 |
+
* Inserts a named entry into the {@link $cacheFactory.Cache Cache} object to be
|
6976 |
+
* retrieved later, and incrementing the size of the cache if the key was not already
|
6977 |
+
* present in the cache. If behaving like an LRU cache, it will also remove stale
|
6978 |
+
* entries from the set.
|
6979 |
+
*
|
6980 |
+
* It will not insert undefined values into the cache.
|
6981 |
+
*
|
6982 |
+
* @param {string} key the key under which the cached data is stored.
|
6983 |
+
* @param {*} value the value to store alongside the key. If it is undefined, the key
|
6984 |
+
* will not be stored.
|
6985 |
+
* @returns {*} the value stored.
|
6986 |
+
*/
|
6987 |
+
put: function(key, value) {
|
6988 |
+
if (isUndefined(value)) return;
|
6989 |
+
if (capacity < Number.MAX_VALUE) {
|
6990 |
+
var lruEntry = lruHash[key] || (lruHash[key] = {key: key});
|
|
|
|
|
|
|
6991 |
|
6992 |
+
refresh(lruEntry);
|
6993 |
+
}
|
6994 |
|
6995 |
+
if (!(key in data)) size++;
|
6996 |
+
data[key] = value;
|
|
|
6997 |
|
6998 |
+
if (size > capacity) {
|
6999 |
+
this.remove(staleEnd.key);
|
7000 |
+
}
|
7001 |
|
7002 |
+
return value;
|
7003 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7004 |
|
7005 |
+
/**
|
7006 |
+
* @ngdoc method
|
7007 |
+
* @name $cacheFactory.Cache#get
|
7008 |
+
* @kind function
|
7009 |
+
*
|
7010 |
+
* @description
|
7011 |
+
* Retrieves named data stored in the {@link $cacheFactory.Cache Cache} object.
|
7012 |
+
*
|
7013 |
+
* @param {string} key the key of the data to be retrieved
|
7014 |
+
* @returns {*} the value stored.
|
7015 |
+
*/
|
7016 |
+
get: function(key) {
|
7017 |
+
if (capacity < Number.MAX_VALUE) {
|
7018 |
+
var lruEntry = lruHash[key];
|
7019 |
|
7020 |
+
if (!lruEntry) return;
|
7021 |
|
7022 |
+
refresh(lruEntry);
|
7023 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7024 |
|
7025 |
+
return data[key];
|
7026 |
+
},
|
7027 |
|
|
|
|
|
|
|
7028 |
|
7029 |
+
/**
|
7030 |
+
* @ngdoc method
|
7031 |
+
* @name $cacheFactory.Cache#remove
|
7032 |
+
* @kind function
|
7033 |
+
*
|
7034 |
+
* @description
|
7035 |
+
* Removes an entry from the {@link $cacheFactory.Cache Cache} object.
|
7036 |
+
*
|
7037 |
+
* @param {string} key the key of the entry to be removed
|
7038 |
+
*/
|
7039 |
+
remove: function(key) {
|
7040 |
+
if (capacity < Number.MAX_VALUE) {
|
7041 |
+
var lruEntry = lruHash[key];
|
7042 |
|
7043 |
+
if (!lruEntry) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7044 |
|
7045 |
+
if (lruEntry === freshEnd) freshEnd = lruEntry.p;
|
7046 |
+
if (lruEntry === staleEnd) staleEnd = lruEntry.n;
|
7047 |
+
link(lruEntry.n,lruEntry.p);
|
7048 |
|
7049 |
+
delete lruHash[key];
|
7050 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7051 |
|
7052 |
+
if (!(key in data)) return;
|
7053 |
|
7054 |
+
delete data[key];
|
7055 |
+
size--;
|
7056 |
+
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7057 |
|
7058 |
|
7059 |
+
/**
|
7060 |
+
* @ngdoc method
|
7061 |
+
* @name $cacheFactory.Cache#removeAll
|
7062 |
+
* @kind function
|
7063 |
+
*
|
7064 |
+
* @description
|
7065 |
+
* Clears the cache object of any entries.
|
7066 |
+
*/
|
7067 |
+
removeAll: function() {
|
7068 |
+
data = createMap();
|
7069 |
+
size = 0;
|
7070 |
+
lruHash = createMap();
|
7071 |
+
freshEnd = staleEnd = null;
|
7072 |
+
},
|
7073 |
|
|
|
|
|
|
|
|
|
|
|
|
|
7074 |
|
7075 |
+
/**
|
7076 |
+
* @ngdoc method
|
7077 |
+
* @name $cacheFactory.Cache#destroy
|
7078 |
+
* @kind function
|
7079 |
+
*
|
7080 |
+
* @description
|
7081 |
+
* Destroys the {@link $cacheFactory.Cache Cache} object entirely,
|
7082 |
+
* removing it from the {@link $cacheFactory $cacheFactory} set.
|
7083 |
+
*/
|
7084 |
+
destroy: function() {
|
7085 |
+
data = null;
|
7086 |
+
stats = null;
|
7087 |
+
lruHash = null;
|
7088 |
+
delete caches[cacheId];
|
7089 |
+
},
|
7090 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7091 |
|
7092 |
+
/**
|
7093 |
+
* @ngdoc method
|
7094 |
+
* @name $cacheFactory.Cache#info
|
7095 |
+
* @kind function
|
7096 |
+
*
|
7097 |
+
* @description
|
7098 |
+
* Retrieve information regarding a particular {@link $cacheFactory.Cache Cache}.
|
7099 |
+
*
|
7100 |
+
* @returns {object} an object with the following properties:
|
7101 |
+
* <ul>
|
7102 |
+
* <li>**id**: the id of the cache instance</li>
|
7103 |
+
* <li>**size**: the number of entries kept in the cache instance</li>
|
7104 |
+
* <li>**...**: any additional properties from the options object when creating the
|
7105 |
+
* cache.</li>
|
7106 |
+
* </ul>
|
7107 |
+
*/
|
7108 |
+
info: function() {
|
7109 |
+
return extend({}, stats, {size: size});
|
7110 |
+
}
|
7111 |
+
});
|
7112 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7113 |
|
7114 |
+
/**
|
7115 |
+
* makes the `entry` the freshEnd of the LRU linked list
|
7116 |
+
*/
|
7117 |
+
function refresh(entry) {
|
7118 |
+
if (entry !== freshEnd) {
|
7119 |
+
if (!staleEnd) {
|
7120 |
+
staleEnd = entry;
|
7121 |
+
} else if (staleEnd === entry) {
|
7122 |
+
staleEnd = entry.n;
|
7123 |
+
}
|
7124 |
|
7125 |
+
link(entry.n, entry.p);
|
7126 |
+
link(entry, freshEnd);
|
7127 |
+
freshEnd = entry;
|
7128 |
+
freshEnd.n = null;
|
7129 |
+
}
|
7130 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7131 |
|
7132 |
|
7133 |
+
/**
|
7134 |
+
* bidirectionally links two entries of the LRU linked list
|
7135 |
+
*/
|
7136 |
+
function link(nextEntry, prevEntry) {
|
7137 |
+
if (nextEntry !== prevEntry) {
|
7138 |
+
if (nextEntry) nextEntry.p = prevEntry; //p stands for previous, 'prev' didn't minify
|
7139 |
+
if (prevEntry) prevEntry.n = nextEntry; //n stands for next, 'next' didn't minify
|
7140 |
+
}
|
7141 |
+
}
|
7142 |
}
|
7143 |
|
7144 |
+
|
7145 |
+
/**
|
7146 |
+
* @ngdoc method
|
7147 |
+
* @name $cacheFactory#info
|
7148 |
+
*
|
7149 |
+
* @description
|
7150 |
+
* Get information about all the caches that have been created
|
7151 |
+
*
|
7152 |
+
* @returns {Object} - key-value map of `cacheId` to the result of calling `cache#info`
|
7153 |
+
*/
|
7154 |
+
cacheFactory.info = function() {
|
7155 |
+
var info = {};
|
7156 |
+
forEach(caches, function(cache, cacheId) {
|
7157 |
+
info[cacheId] = cache.info();
|
7158 |
+
});
|
7159 |
+
return info;
|
7160 |
+
};
|
7161 |
+
|
7162 |
+
|
7163 |
+
/**
|
7164 |
+
* @ngdoc method
|
7165 |
+
* @name $cacheFactory#get
|
7166 |
+
*
|
7167 |
+
* @description
|
7168 |
+
* Get access to a cache object by the `cacheId` used when it was created.
|
7169 |
+
*
|
7170 |
+
* @param {string} cacheId Name or id of a cache to access.
|
7171 |
+
* @returns {object} Cache object identified by the cacheId or undefined if no such cache.
|
7172 |
+
*/
|
7173 |
+
cacheFactory.get = function(cacheId) {
|
7174 |
+
return caches[cacheId];
|
7175 |
+
};
|
7176 |
+
|
7177 |
+
|
7178 |
+
return cacheFactory;
|
7179 |
+
};
|
7180 |
+
}
|
7181 |
+
|
7182 |
+
/**
|
7183 |
+
* @ngdoc service
|
7184 |
+
* @name $templateCache
|
7185 |
+
* @this
|
7186 |
+
*
|
7187 |
+
* @description
|
7188 |
+
* `$templateCache` is a {@link $cacheFactory.Cache Cache object} created by the
|
7189 |
+
* {@link ng.$cacheFactory $cacheFactory}.
|
7190 |
+
*
|
7191 |
+
* The first time a template is used, it is loaded in the template cache for quick retrieval. You
|
7192 |
+
* can load templates directly into the cache in a `script` tag, by using {@link $templateRequest},
|
7193 |
+
* or by consuming the `$templateCache` service directly.
|
7194 |
+
*
|
7195 |
+
* Adding via the `script` tag:
|
7196 |
+
*
|
7197 |
+
* ```html
|
7198 |
+
* <script type="text/ng-template" id="templateId.html">
|
7199 |
+
* <p>This is the content of the template</p>
|
7200 |
+
* </script>
|
7201 |
+
* ```
|
7202 |
+
*
|
7203 |
+
* **Note:** the `script` tag containing the template does not need to be included in the `head` of
|
7204 |
+
* the document, but it must be a descendent of the {@link ng.$rootElement $rootElement} (e.g.
|
7205 |
+
* element with {@link ngApp} attribute), otherwise the template will be ignored.
|
7206 |
+
*
|
7207 |
+
* Adding via the `$templateCache` service:
|
7208 |
+
*
|
7209 |
+
* ```js
|
7210 |
+
* var myApp = angular.module('myApp', []);
|
7211 |
+
* myApp.run(function($templateCache) {
|
7212 |
* $templateCache.put('templateId.html', 'This is the content of the template');
|
7213 |
* });
|
7214 |
+
* ```
|
7215 |
+
*
|
7216 |
+
* To retrieve the template later, simply use it in your component:
|
7217 |
+
* ```js
|
7218 |
+
* myApp.component('myComponent', {
|
7219 |
* templateUrl: 'templateId.html'
|
7220 |
* });
|
7221 |
+
* ```
|
7222 |
+
*
|
7223 |
+
* or get it via the `$templateCache` service:
|
7224 |
+
* ```js
|
7225 |
+
* $templateCache.get('templateId.html')
|
7226 |
+
* ```
|
7227 |
+
*
|
7228 |
+
*/
|
7229 |
+
function $TemplateCacheProvider() {
|
7230 |
+
this.$get = ['$cacheFactory', function($cacheFactory) {
|
7231 |
+
return $cacheFactory('templates');
|
7232 |
+
}];
|
7233 |
+
}
|
7234 |
|
7235 |
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
7236 |
* Any commits to this file should be reviewed with security in mind. *
|
7237 |
* Changes to this file can potentially create security vulnerabilities. *
|
7238 |
* An approval from 2 Core members with history of modifying *
|
7243 |
* Or gives undesired access to variables like document or window? *
|
7244 |
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
7245 |
|
7246 |
+
/* ! VARIABLE/FUNCTION NAMING CONVENTIONS THAT APPLY TO THIS FILE!
|
7247 |
*
|
7248 |
* DOM-related variables:
|
7249 |
*
|
7261 |
*/
|
7262 |
|
7263 |
|
7264 |
+
/**
|
7265 |
+
* @ngdoc service
|
7266 |
+
* @name $compile
|
7267 |
+
* @kind function
|
7268 |
+
*
|
7269 |
+
* @description
|
7270 |
+
* Compiles an HTML string or DOM into a template and produces a template function, which
|
7271 |
+
* can then be used to link {@link ng.$rootScope.Scope `scope`} and the template together.
|
7272 |
+
*
|
7273 |
+
* The compilation is a process of walking the DOM tree and matching DOM elements to
|
7274 |
+
* {@link ng.$compileProvider#directive directives}.
|
7275 |
+
*
|
7276 |
+
* <div class="alert alert-warning">
|
7277 |
+
* **Note:** This document is an in-depth reference of all directive options.
|
7278 |
+
* For a gentle introduction to directives with examples of common use cases,
|
7279 |
+
* see the {@link guide/directive directive guide}.
|
7280 |
+
* </div>
|
7281 |
+
*
|
7282 |
+
* ## Comprehensive Directive API
|
7283 |
+
*
|
7284 |
+
* There are many different options for a directive.
|
7285 |
+
*
|
7286 |
+
* The difference resides in the return value of the factory function.
|
7287 |
+
* You can either return a {@link $compile#directive-definition-object Directive Definition Object (see below)}
|
7288 |
+
* that defines the directive properties, or just the `postLink` function (all other properties will have
|
7289 |
+
* the default values).
|
7290 |
+
*
|
7291 |
+
* <div class="alert alert-success">
|
7292 |
+
* **Best Practice:** It's recommended to use the "directive definition object" form.
|
7293 |
+
* </div>
|
7294 |
+
*
|
7295 |
+
* Here's an example directive declared with a Directive Definition Object:
|
7296 |
+
*
|
7297 |
+
* ```js
|
7298 |
+
* var myModule = angular.module(...);
|
7299 |
+
*
|
7300 |
+
* myModule.directive('directiveName', function factory(injectables) {
|
7301 |
* var directiveDefinitionObject = {
|
7302 |
* {@link $compile#-priority- priority}: 0,
|
7303 |
* {@link $compile#-template- template}: '<div></div>', // or // function(tElement, tAttrs) { ... },
|
7330 |
* };
|
7331 |
* return directiveDefinitionObject;
|
7332 |
* });
|
7333 |
+
* ```
|
7334 |
+
*
|
7335 |
+
* <div class="alert alert-warning">
|
7336 |
+
* **Note:** Any unspecified options will use the default value. You can see the default values below.
|
7337 |
+
* </div>
|
7338 |
+
*
|
7339 |
+
* Therefore the above can be simplified as:
|
7340 |
+
*
|
7341 |
+
* ```js
|
7342 |
+
* var myModule = angular.module(...);
|
7343 |
+
*
|
7344 |
+
* myModule.directive('directiveName', function factory(injectables) {
|
7345 |
* var directiveDefinitionObject = {
|
7346 |
* link: function postLink(scope, iElement, iAttrs) { ... }
|
7347 |
* };
|
7349 |
* // or
|
7350 |
* // return function postLink(scope, iElement, iAttrs) { ... }
|
7351 |
* });
|
7352 |
+
* ```
|
7353 |
+
*
|
7354 |
+
* ### Life-cycle hooks
|
7355 |
+
* Directive controllers can provide the following methods that are called by AngularJS at points in the life-cycle of the
|
7356 |
+
* directive:
|
7357 |
+
* * `$onInit()` - Called on each controller after all the controllers on an element have been constructed and
|
7358 |
+
* had their bindings initialized (and before the pre & post linking functions for the directives on
|
7359 |
+
* this element). This is a good place to put initialization code for your controller.
|
7360 |
+
* * `$onChanges(changesObj)` - Called whenever one-way (`<`) or interpolation (`@`) bindings are updated. The
|
7361 |
+
* `changesObj` is a hash whose keys are the names of the bound properties that have changed, and the values are an
|
7362 |
+
* object of the form `{ currentValue, previousValue, isFirstChange() }`. Use this hook to trigger updates within a
|
7363 |
+
* component such as cloning the bound value to prevent accidental mutation of the outer value. Note that this will
|
7364 |
+
* also be called when your bindings are initialized.
|
7365 |
+
* * `$doCheck()` - Called on each turn of the digest cycle. Provides an opportunity to detect and act on
|
7366 |
+
* changes. Any actions that you wish to take in response to the changes that you detect must be
|
7367 |
+
* invoked from this hook; implementing this has no effect on when `$onChanges` is called. For example, this hook
|
7368 |
+
* could be useful if you wish to perform a deep equality check, or to check a Date object, changes to which would not
|
7369 |
+
* be detected by AngularJS's change detector and thus not trigger `$onChanges`. This hook is invoked with no arguments;
|
7370 |
+
* if detecting changes, you must store the previous value(s) for comparison to the current values.
|
7371 |
+
* * `$onDestroy()` - Called on a controller when its containing scope is destroyed. Use this hook for releasing
|
7372 |
+
* external resources, watches and event handlers. Note that components have their `$onDestroy()` hooks called in
|
7373 |
+
* the same order as the `$scope.$broadcast` events are triggered, which is top down. This means that parent
|
7374 |
+
* components will have their `$onDestroy()` hook called before child components.
|
7375 |
+
* * `$postLink()` - Called after this controller's element and its children have been linked. Similar to the post-link
|
7376 |
+
* function this hook can be used to set up DOM event handlers and do direct DOM manipulation.
|
7377 |
+
* Note that child elements that contain `templateUrl` directives will not have been compiled and linked since
|
7378 |
+
* they are waiting for their template to load asynchronously and their own compilation and linking has been
|
7379 |
+
* suspended until that occurs.
|
7380 |
+
*
|
7381 |
+
* #### Comparison with life-cycle hooks in the new Angular
|
7382 |
+
* The new Angular also uses life-cycle hooks for its components. While the AngularJS life-cycle hooks are similar there are
|
7383 |
+
* some differences that you should be aware of, especially when it comes to moving your code from AngularJS to Angular:
|
7384 |
+
*
|
7385 |
+
* * AngularJS hooks are prefixed with `$`, such as `$onInit`. Angular hooks are prefixed with `ng`, such as `ngOnInit`.
|
7386 |
+
* * AngularJS hooks can be defined on the controller prototype or added to the controller inside its constructor.
|
7387 |
+
* In Angular you can only define hooks on the prototype of the Component class.
|
7388 |
+
* * Due to the differences in change-detection, you may get many more calls to `$doCheck` in AngularJS than you would to
|
7389 |
+
* `ngDoCheck` in Angular.
|
7390 |
+
* * Changes to the model inside `$doCheck` will trigger new turns of the digest loop, which will cause the changes to be
|
7391 |
+
* propagated throughout the application.
|
7392 |
+
* Angular does not allow the `ngDoCheck` hook to trigger a change outside of the component. It will either throw an
|
7393 |
+
* error or do nothing depending upon the state of `enableProdMode()`.
|
7394 |
+
*
|
7395 |
+
* #### Life-cycle hook examples
|
7396 |
+
*
|
7397 |
+
* This example shows how you can check for mutations to a Date object even though the identity of the object
|
7398 |
+
* has not changed.
|
7399 |
+
*
|
7400 |
+
* <example name="doCheckDateExample" module="do-check-module">
|
7401 |
+
* <file name="app.js">
|
7402 |
+
* angular.module('do-check-module', [])
|
7403 |
+
* .component('app', {
|
7404 |
* template:
|
7405 |
* 'Month: <input ng-model="$ctrl.month" ng-change="$ctrl.updateDate()">' +
|
7406 |
* 'Date: {{ $ctrl.date }}' +
|
7413 |
* };
|
7414 |
* }
|
7415 |
* })
|
7416 |
+
* .component('test', {
|
7417 |
* bindings: { date: '<' },
|
7418 |
* template:
|
7419 |
* '<pre>{{ $ctrl.log | json }}</pre>',
|
7429 |
* };
|
7430 |
* }
|
7431 |
* });
|
7432 |
+
* </file>
|
7433 |
+
* <file name="index.html">
|
7434 |
+
* <app></app>
|
7435 |
+
* </file>
|
7436 |
+
* </example>
|
7437 |
+
*
|
7438 |
+
* This example show how you might use `$doCheck` to trigger changes in your component's inputs even if the
|
7439 |
+
* actual identity of the component doesn't change. (Be aware that cloning and deep equality checks on large
|
7440 |
+
* arrays or objects can have a negative impact on your application performance)
|
7441 |
+
*
|
7442 |
+
* <example name="doCheckArrayExample" module="do-check-module">
|
7443 |
+
* <file name="index.html">
|
7444 |
+
* <div ng-init="items = []">
|
7445 |
+
* <button ng-click="items.push(items.length)">Add Item</button>
|
7446 |
+
* <button ng-click="items = []">Reset Items</button>
|
7447 |
+
* <pre>{{ items }}</pre>
|
7448 |
+
* <test items="items"></test>
|
7449 |
+
* </div>
|
7450 |
+
* </file>
|
7451 |
+
* <file name="app.js">
|
7452 |
+
* angular.module('do-check-module', [])
|
7453 |
+
* .component('test', {
|
7454 |
* bindings: { items: '<' },
|
7455 |
* template:
|
7456 |
* '<pre>{{ $ctrl.log | json }}</pre>',
|
7469 |
* };
|
7470 |
* }
|
7471 |
* });
|
7472 |
+
* </file>
|
7473 |
+
* </example>
|
7474 |
+
*
|
7475 |
+
*
|
7476 |
+
* ### Directive Definition Object
|
7477 |
+
*
|
7478 |
+
* The directive definition object provides instructions to the {@link ng.$compile
|
7479 |
* compiler}. The attributes are:
|
7480 |
+
*
|
7481 |
+
* #### `multiElement`
|
7482 |
+
* When this property is set to true (default is `false`), the HTML compiler will collect DOM nodes between
|
7483 |
+
* nodes with the attributes `directive-name-start` and `directive-name-end`, and group them
|
7484 |
+
* together as the directive elements. It is recommended that this feature be used on directives
|
7485 |
+
* which are not strictly behavioral (such as {@link ngClick}), and which
|
7486 |
+
* do not manipulate or replace child nodes (such as {@link ngInclude}).
|
7487 |
+
*
|
7488 |
+
* #### `priority`
|
7489 |
+
* When there are multiple directives defined on a single DOM element, sometimes it
|
7490 |
+
* is necessary to specify the order in which the directives are applied. The `priority` is used
|
7491 |
+
* to sort the directives before their `compile` functions get called. Priority is defined as a
|
7492 |
+
* number. Directives with greater numerical `priority` are compiled first. Pre-link functions
|
7493 |
+
* are also run in priority order, but post-link functions are run in reverse order. The order
|
7494 |
+
* of directives with the same priority is undefined. The default priority is `0`.
|
7495 |
+
*
|
7496 |
+
* #### `terminal`
|
7497 |
+
* If set to true then the current `priority` will be the last set of directives
|
7498 |
+
* which will execute (any directives at the current priority will still execute
|
7499 |
+
* as the order of execution on same `priority` is undefined). Note that expressions
|
7500 |
+
* and other directives used in the directive's template will also be excluded from execution.
|
7501 |
+
*
|
7502 |
+
* #### `scope`
|
7503 |
+
* The scope property can be `false`, `true`, or an object:
|
7504 |
+
*
|
7505 |
+
* * **`false` (default):** No scope will be created for the directive. The directive will use its
|
7506 |
+
* parent's scope.
|
7507 |
+
*
|
7508 |
+
* * **`true`:** A new child scope that prototypically inherits from its parent will be created for
|
7509 |
+
* the directive's element. If multiple directives on the same element request a new scope,
|
7510 |
+
* only one new scope is created.
|
7511 |
+
*
|
7512 |
+
* * **`{...}` (an object hash):** A new "isolate" scope is created for the directive's template.
|
7513 |
+
* The 'isolate' scope differs from normal scope in that it does not prototypically
|
7514 |
+
* inherit from its parent scope. This is useful when creating reusable components, which should not
|
7515 |
+
* accidentally read or modify data in the parent scope. Note that an isolate scope
|
7516 |
+
* directive without a `template` or `templateUrl` will not apply the isolate scope
|
7517 |
+
* to its children elements.
|
7518 |
+
*
|
7519 |
+
* The 'isolate' scope object hash defines a set of local scope properties derived from attributes on the
|
7520 |
+
* directive's element. These local properties are useful for aliasing values for templates. The keys in
|
7521 |
+
* the object hash map to the name of the property on the isolate scope; the values define how the property
|
7522 |
+
* is bound to the parent scope, via matching attributes on the directive's element:
|
7523 |
+
*
|
7524 |
+
* * `@` or `@attr` - bind a local scope property to the value of DOM attribute. The result is
|
7525 |
+
* always a string since DOM attributes are strings. If no `attr` name is specified then the
|
7526 |
+
* attribute name is assumed to be the same as the local name. Given `<my-component
|
7527 |
+
* my-attr="hello {{name}}">` and the isolate scope definition `scope: { localName:'@myAttr' }`,
|
7528 |
+
* the directive's scope property `localName` will reflect the interpolated value of `hello
|
7529 |
+
* {{name}}`. As the `name` attribute changes so will the `localName` property on the directive's
|
7530 |
+
* scope. The `name` is read from the parent scope (not the directive's scope).
|
7531 |
+
*
|
7532 |
+
* * `=` or `=attr` - set up a bidirectional binding between a local scope property and an expression
|
7533 |
+
* passed via the attribute `attr`. The expression is evaluated in the context of the parent scope.
|
7534 |
+
* If no `attr` name is specified then the attribute name is assumed to be the same as the local
|
7535 |
+
* name. Given `<my-component my-attr="parentModel">` and the isolate scope definition `scope: {
|
7536 |
* localModel: '=myAttr' }`, the property `localModel` on the directive's scope will reflect the
|
7537 |
+
* value of `parentModel` on the parent scope. Changes to `parentModel` will be reflected in
|
7538 |
+
* `localModel` and vice versa. If the binding expression is non-assignable, or if the attribute
|
7539 |
+
* isn't optional and doesn't exist, an exception
|
7540 |
+
* ({@link error/$compile/nonassign `$compile:nonassign`}) will be thrown upon discovering changes
|
7541 |
+
* to the local value, since it will be impossible to sync them back to the parent scope.
|
7542 |
+
*
|
7543 |
+
* By default, the {@link ng.$rootScope.Scope#$watch `$watch`}
|
7544 |
+
* method is used for tracking changes, and the equality check is based on object identity.
|
7545 |
+
* However, if an object literal or an array literal is passed as the binding expression, the
|
7546 |
+
* equality check is done by value (using the {@link angular.equals} function). It's also possible
|
7547 |
+
* to watch the evaluated value shallowly with {@link ng.$rootScope.Scope#$watchCollection
|
7548 |
* `$watchCollection`}: use `=*` or `=*attr`
|
7549 |
+
*
|
7550 |
+
* * `<` or `<attr` - set up a one-way (one-directional) binding between a local scope property and an
|
7551 |
+
* expression passed via the attribute `attr`. The expression is evaluated in the context of the
|
7552 |
+
* parent scope. If no `attr` name is specified then the attribute name is assumed to be the same as the
|
7553 |
+
* local name.
|
7554 |
+
*
|
7555 |
+
* For example, given `<my-component my-attr="parentModel">` and directive definition of
|
7556 |
+
* `scope: { localModel:'<myAttr' }`, then the isolated scope property `localModel` will reflect the
|
7557 |
+
* value of `parentModel` on the parent scope. Any changes to `parentModel` will be reflected
|
7558 |
+
* in `localModel`, but changes in `localModel` will not reflect in `parentModel`. There are however
|
7559 |
+
* two caveats:
|
7560 |
+
* 1. one-way binding does not copy the value from the parent to the isolate scope, it simply
|
7561 |
+
* sets the same value. That means if your bound value is an object, changes to its properties
|
7562 |
+
* in the isolated scope will be reflected in the parent scope (because both reference the same object).
|
7563 |
+
* 2. one-way binding watches changes to the **identity** of the parent value. That means the
|
7564 |
+
* {@link ng.$rootScope.Scope#$watch `$watch`} on the parent value only fires if the reference
|
7565 |
+
* to the value has changed. In most cases, this should not be of concern, but can be important
|
7566 |
+
* to know if you one-way bind to an object, and then replace that object in the isolated scope.
|
7567 |
+
* If you now change a property of the object in your parent scope, the change will not be
|
7568 |
+
* propagated to the isolated scope, because the identity of the object on the parent scope
|
7569 |
+
* has not changed. Instead you must assign a new object.
|
7570 |
+
*
|
7571 |
+
* One-way binding is useful if you do not plan to propagate changes to your isolated scope bindings
|
7572 |
+
* back to the parent. However, it does not make this completely impossible.
|
7573 |
+
*
|
7574 |
+
* By default, the {@link ng.$rootScope.Scope#$watch `$watch`}
|
7575 |
+
* method is used for tracking changes, and the equality check is based on object identity.
|
7576 |
+
* It's also possible to watch the evaluated value shallowly with
|
7577 |
+
* {@link ng.$rootScope.Scope#$watchCollection `$watchCollection`}: use `<*` or `<*attr`
|
7578 |
+
*
|
7579 |
+
* * `&` or `&attr` - provides a way to execute an expression in the context of the parent scope. If
|
7580 |
+
* no `attr` name is specified then the attribute name is assumed to be the same as the local name.
|
7581 |
+
* Given `<my-component my-attr="count = count + value">` and the isolate scope definition `scope: {
|
7582 |
* localFn:'&myAttr' }`, the isolate scope property `localFn` will point to a function wrapper for
|
7583 |
+
* the `count = count + value` expression. Often it's desirable to pass data from the isolated scope
|
7584 |
+
* via an expression to the parent scope. This can be done by passing a map of local variable names
|
7585 |
+
* and values into the expression wrapper fn. For example, if the expression is `increment(amount)`
|
7586 |
+
* then we can specify the amount value by calling the `localFn` as `localFn({amount: 22})`.
|
7587 |
+
*
|
7588 |
+
* All 4 kinds of bindings (`@`, `=`, `<`, and `&`) can be made optional by adding `?` to the expression.
|
7589 |
+
* The marker must come after the mode and before the attribute name.
|
7590 |
+
* See the {@link error/$compile/iscp Invalid Isolate Scope Definition error} for definition examples.
|
7591 |
+
* This is useful to refine the interface directives provide.
|
7592 |
+
* One subtle difference between optional and non-optional happens **when the binding attribute is not
|
7593 |
+
* set**:
|
7594 |
+
* - the binding is optional: the property will not be defined
|
7595 |
+
* - the binding is not optional: the property is defined
|
7596 |
+
*
|
7597 |
+
* ```js
|
7598 |
+
*app.directive('testDir', function() {
|
7599 |
return {
|
7600 |
scope: {
|
7601 |
notoptional: '=',
|
7610 |
}
|
7611 |
}
|
7612 |
})
|
7613 |
+
*```
|
7614 |
+
*
|
7615 |
+
*
|
7616 |
+
* ##### Combining directives with different scope defintions
|
7617 |
+
*
|
7618 |
+
* In general it's possible to apply more than one directive to one element, but there might be limitations
|
7619 |
+
* depending on the type of scope required by the directives. The following points will help explain these limitations.
|
7620 |
+
* For simplicity only two directives are taken into account, but it is also applicable for several directives:
|
7621 |
+
*
|
7622 |
+
* * **no scope** + **no scope** => Two directives which don't require their own scope will use their parent's scope
|
7623 |
+
* * **child scope** + **no scope** => Both directives will share one single child scope
|
7624 |
+
* * **child scope** + **child scope** => Both directives will share one single child scope
|
7625 |
+
* * **isolated scope** + **no scope** => The isolated directive will use it's own created isolated scope. The other directive will use
|
7626 |
+
* its parent's scope
|
7627 |
+
* * **isolated scope** + **child scope** => **Won't work!** Only one scope can be related to one element. Therefore these directives cannot
|
7628 |
+
* be applied to the same element.
|
7629 |
+
* * **isolated scope** + **isolated scope** => **Won't work!** Only one scope can be related to one element. Therefore these directives
|
7630 |
+
* cannot be applied to the same element.
|
7631 |
+
*
|
7632 |
+
*
|
7633 |
+
* #### `bindToController`
|
7634 |
+
* This property is used to bind scope properties directly to the controller. It can be either
|
7635 |
+
* `true` or an object hash with the same format as the `scope` property.
|
7636 |
+
*
|
7637 |
+
* When an isolate scope is used for a directive (see above), `bindToController: true` will
|
7638 |
+
* allow a component to have its properties bound to the controller, rather than to scope.
|
7639 |
+
*
|
7640 |
+
* After the controller is instantiated, the initial values of the isolate scope bindings will be bound to the controller
|
7641 |
+
* properties. You can access these bindings once they have been initialized by providing a controller method called
|
7642 |
+
* `$onInit`, which is called after all the controllers on an element have been constructed and had their bindings
|
7643 |
+
* initialized.
|
7644 |
+
*
|
7645 |
+
* It is also possible to set `bindToController` to an object hash with the same format as the `scope` property.
|
7646 |
+
* This will set up the scope bindings to the controller directly. Note that `scope` can still be used
|
7647 |
+
* to define which kind of scope is created. By default, no scope is created. Use `scope: {}` to create an isolate
|
7648 |
+
* scope (useful for component directives).
|
7649 |
+
*
|
7650 |
+
* If both `bindToController` and `scope` are defined and have object hashes, `bindToController` overrides `scope`.
|
7651 |
+
*
|
7652 |
+
*
|
7653 |
+
* #### `controller`
|
7654 |
+
* Controller constructor function. The controller is instantiated before the
|
7655 |
+
* pre-linking phase and can be accessed by other directives (see
|
7656 |
+
* `require` attribute). This allows the directives to communicate with each other and augment
|
7657 |
+
* each other's behavior. The controller is injectable (and supports bracket notation) with the following locals:
|
7658 |
+
*
|
7659 |
+
* * `$scope` - Current scope associated with the element
|
7660 |
+
* * `$element` - Current element
|
7661 |
+
* * `$attrs` - Current attributes object for the element
|
7662 |
+
* * `$transclude` - A transclude linking function pre-bound to the correct transclusion scope:
|
7663 |
+
* `function([scope], cloneLinkingFn, futureParentElement, slotName)`:
|
7664 |
+
* * `scope`: (optional) override the scope.
|
7665 |
+
* * `cloneLinkingFn`: (optional) argument to create clones of the original transcluded content.
|
7666 |
+
* * `futureParentElement` (optional):
|
7667 |
+
* * defines the parent to which the `cloneLinkingFn` will add the cloned elements.
|
7668 |
+
* * default: `$element.parent()` resp. `$element` for `transclude:'element'` resp. `transclude:true`.
|
7669 |
+
* * only needed for transcludes that are allowed to contain non html elements (e.g. SVG elements)
|
7670 |
+
* and when the `cloneLinkingFn` is passed,
|
7671 |
+
* as those elements need to created and cloned in a special way when they are defined outside their
|
7672 |
+
* usual containers (e.g. like `<svg>`).
|
7673 |
+
* * See also the `directive.templateNamespace` property.
|
7674 |
+
* * `slotName`: (optional) the name of the slot to transclude. If falsy (e.g. `null`, `undefined` or `''`)
|
7675 |
+
* then the default transclusion is provided.
|
7676 |
+
* The `$transclude` function also has a method on it, `$transclude.isSlotFilled(slotName)`, which returns
|
7677 |
+
* `true` if the specified slot contains content (i.e. one or more DOM nodes).
|
7678 |
+
*
|
7679 |
+
* #### `require`
|
7680 |
+
* Require another directive and inject its controller as the fourth argument to the linking function. The
|
7681 |
+
* `require` property can be a string, an array or an object:
|
7682 |
+
* * a **string** containing the name of the directive to pass to the linking function
|
7683 |
+
* * an **array** containing the names of directives to pass to the linking function. The argument passed to the
|
7684 |
+
* linking function will be an array of controllers in the same order as the names in the `require` property
|
7685 |
+
* * an **object** whose property values are the names of the directives to pass to the linking function. The argument
|
7686 |
+
* passed to the linking function will also be an object with matching keys, whose values will hold the corresponding
|
7687 |
+
* controllers.
|
7688 |
+
*
|
7689 |
+
* If the `require` property is an object and `bindToController` is truthy, then the required controllers are
|
7690 |
+
* bound to the controller using the keys of the `require` property. This binding occurs after all the controllers
|
7691 |
+
* have been constructed but before `$onInit` is called.
|
7692 |
+
* If the name of the required controller is the same as the local name (the key), the name can be
|
7693 |
+
* omitted. For example, `{parentDir: '^^'}` is equivalent to `{parentDir: '^^parentDir'}`.
|
7694 |
+
* See the {@link $compileProvider#component} helper for an example of how this can be used.
|
7695 |
+
* If no such required directive(s) can be found, or if the directive does not have a controller, then an error is
|
7696 |
+
* raised (unless no link function is specified and the required controllers are not being bound to the directive
|
7697 |
+
* controller, in which case error checking is skipped). The name can be prefixed with:
|
7698 |
+
*
|
7699 |
+
* * (no prefix) - Locate the required controller on the current element. Throw an error if not found.
|
7700 |
+
* * `?` - Attempt to locate the required controller or pass `null` to the `link` fn if not found.
|
7701 |
+
* * `^` - Locate the required controller by searching the element and its parents. Throw an error if not found.
|
7702 |
+
* * `^^` - Locate the required controller by searching the element's parents. Throw an error if not found.
|
7703 |
+
* * `?^` - Attempt to locate the required controller by searching the element and its parents or pass
|
7704 |
+
* `null` to the `link` fn if not found.
|
7705 |
+
* * `?^^` - Attempt to locate the required controller by searching the element's parents, or pass
|
7706 |
+
* `null` to the `link` fn if not found.
|
7707 |
+
*
|
7708 |
+
*
|
7709 |
+
* #### `controllerAs`
|
7710 |
+
* Identifier name for a reference to the controller in the directive's scope.
|
7711 |
+
* This allows the controller to be referenced from the directive template. This is especially
|
7712 |
+
* useful when a directive is used as component, i.e. with an `isolate` scope. It's also possible
|
7713 |
+
* to use it in a directive without an `isolate` / `new` scope, but you need to be aware that the
|
7714 |
+
* `controllerAs` reference might overwrite a property that already exists on the parent scope.
|
7715 |
+
*
|
7716 |
+
*
|
7717 |
+
* #### `restrict`
|
7718 |
+
* String of subset of `EACM` which restricts the directive to a specific directive
|
7719 |
+
* declaration style. If omitted, the defaults (elements and attributes) are used.
|
7720 |
+
*
|
7721 |
+
* * `E` - Element name (default): `<my-directive></my-directive>`
|
7722 |
+
* * `A` - Attribute (default): `<div my-directive="exp"></div>`
|
7723 |
+
* * `C` - Class: `<div class="my-directive: exp;"></div>`
|
7724 |
+
* * `M` - Comment: `<!-- directive: my-directive exp -->`
|
7725 |
+
*
|
7726 |
+
*
|
7727 |
+
* #### `templateNamespace`
|
7728 |
+
* String representing the document type used by the markup in the template.
|
7729 |
+
* AngularJS needs this information as those elements need to be created and cloned
|
7730 |
+
* in a special way when they are defined outside their usual containers like `<svg>` and `<math>`.
|
7731 |
+
*
|
7732 |
+
* * `html` - All root nodes in the template are HTML. Root nodes may also be
|
7733 |
+
* top-level elements such as `<svg>` or `<math>`.
|
7734 |
+
* * `svg` - The root nodes in the template are SVG elements (excluding `<math>`).
|
7735 |
+
* * `math` - The root nodes in the template are MathML elements (excluding `<svg>`).
|
7736 |
+
*
|
7737 |
+
* If no `templateNamespace` is specified, then the namespace is considered to be `html`.
|
7738 |
+
*
|
7739 |
+
* #### `template`
|
7740 |
+
* HTML markup that may:
|
7741 |
+
* * Replace the contents of the directive's element (default).
|
7742 |
+
* * Replace the directive's element itself (if `replace` is true - DEPRECATED).
|
7743 |
+
* * Wrap the contents of the directive's element (if `transclude` is true).
|
7744 |
+
*
|
7745 |
+
* Value may be:
|
7746 |
+
*
|
7747 |
+
* * A string. For example `<div red-on-hover>{{delete_str}}</div>`.
|
7748 |
+
* * A function which takes two arguments `tElement` and `tAttrs` (described in the `compile`
|
7749 |
+
* function api below) and returns a string value.
|
7750 |
+
*
|
7751 |
+
*
|
7752 |
+
* #### `templateUrl`
|
7753 |
+
* This is similar to `template` but the template is loaded from the specified URL, asynchronously.
|
7754 |
+
*
|
7755 |
+
* Because template loading is asynchronous the compiler will suspend compilation of directives on that element
|
7756 |
+
* for later when the template has been resolved. In the meantime it will continue to compile and link
|
7757 |
+
* sibling and parent elements as though this element had not contained any directives.
|
7758 |
+
*
|
7759 |
+
* The compiler does not suspend the entire compilation to wait for templates to be loaded because this
|
7760 |
+
* would result in the whole app "stalling" until all templates are loaded asynchronously - even in the
|
7761 |
+
* case when only one deeply nested directive has `templateUrl`.
|
7762 |
+
*
|
7763 |
+
* Template loading is asynchronous even if the template has been preloaded into the {@link $templateCache}
|
7764 |
+
*
|
7765 |
+
* You can specify `templateUrl` as a string representing the URL or as a function which takes two
|
7766 |
+
* arguments `tElement` and `tAttrs` (described in the `compile` function api below) and returns
|
7767 |
+
* a string value representing the url. In either case, the template URL is passed through {@link
|
7768 |
+
* $sce#getTrustedResourceUrl $sce.getTrustedResourceUrl}.
|
7769 |
+
*
|
7770 |
+
*
|
7771 |
+
* #### `replace`
|
7772 |
+
* <div class="alert alert-danger">
|
7773 |
+
* **Note:** `replace` is deprecated in AngularJS and has been removed in the new Angular (v2+).
|
7774 |
+
* </div>
|
7775 |
+
*
|
7776 |
+
* Specifies what the template should replace. Defaults to `false`.
|
7777 |
+
*
|
7778 |
+
* * `true` - the template will replace the directive's element.
|
7779 |
+
* * `false` - the template will replace the contents of the directive's element.
|
7780 |
+
*
|
7781 |
+
* The replacement process migrates all of the attributes / classes from the old element to the new
|
7782 |
+
* one. See the {@link guide/directive#template-expanding-directive
|
7783 |
+
* Directives Guide} for an example.
|
7784 |
+
*
|
7785 |
+
* There are very few scenarios where element replacement is required for the application function,
|
7786 |
+
* the main one being reusable custom components that are used within SVG contexts
|
7787 |
+
* (because SVG doesn't work with custom elements in the DOM tree).
|
7788 |
+
*
|
7789 |
+
* #### `transclude`
|
7790 |
+
* Extract the contents of the element where the directive appears and make it available to the directive.
|
7791 |
+
* The contents are compiled and provided to the directive as a **transclusion function**. See the
|
7792 |
+
* {@link $compile#transclusion Transclusion} section below.
|
7793 |
+
*
|
7794 |
+
*
|
7795 |
+
* #### `compile`
|
7796 |
+
*
|
7797 |
+
* ```js
|
7798 |
+
* function compile(tElement, tAttrs, transclude) { ... }
|
7799 |
+
* ```
|
7800 |
+
*
|
7801 |
+
* The compile function deals with transforming the template DOM. Since most directives do not do
|
7802 |
+
* template transformation, it is not used often. The compile function takes the following arguments:
|
7803 |
+
*
|
7804 |
+
* * `tElement` - template element - The element where the directive has been declared. It is
|
7805 |
+
* safe to do template transformation on the element and child elements only.
|
7806 |
+
*
|
7807 |
+
* * `tAttrs` - template attributes - Normalized list of attributes declared on this element shared
|
7808 |
+
* between all directive compile functions.
|
7809 |
+
*
|
7810 |
+
* * `transclude` - [*DEPRECATED*!] A transclude linking function: `function(scope, cloneLinkingFn)`
|
7811 |
+
*
|
7812 |
+
* <div class="alert alert-warning">
|
7813 |
+
* **Note:** The template instance and the link instance may be different objects if the template has
|
7814 |
+
* been cloned. For this reason it is **not** safe to do anything other than DOM transformations that
|
7815 |
+
* apply to all cloned DOM nodes within the compile function. Specifically, DOM listener registration
|
7816 |
+
* should be done in a linking function rather than in a compile function.
|
7817 |
+
* </div>
|
7818 |
+
|
7819 |
+
* <div class="alert alert-warning">
|
7820 |
+
* **Note:** The compile function cannot handle directives that recursively use themselves in their
|
7821 |
+
* own templates or compile functions. Compiling these directives results in an infinite loop and
|
7822 |
+
* stack overflow errors.
|
7823 |
+
*
|
7824 |
+
* This can be avoided by manually using $compile in the postLink function to imperatively compile
|
7825 |
+
* a directive's template instead of relying on automatic template compilation via `template` or
|
7826 |
+
* `templateUrl` declaration or manual compilation inside the compile function.
|
7827 |
+
* </div>
|
7828 |
+
*
|
7829 |
+
* <div class="alert alert-danger">
|
7830 |
+
* **Note:** The `transclude` function that is passed to the compile function is deprecated, as it
|
7831 |
+
* e.g. does not know about the right outer scope. Please use the transclude function that is passed
|
7832 |
+
* to the link function instead.
|
7833 |
+
* </div>
|
7834 |
+
|
7835 |
+
* A compile function can have a return value which can be either a function or an object.
|
7836 |
+
*
|
7837 |
+
* * returning a (post-link) function - is equivalent to registering the linking function via the
|
7838 |
+
* `link` property of the config object when the compile function is empty.
|
7839 |
+
*
|
7840 |
+
* * returning an object with function(s) registered via `pre` and `post` properties - allows you to
|
7841 |
+
* control when a linking function should be called during the linking phase. See info about
|
7842 |
+
* pre-linking and post-linking functions below.
|
7843 |
+
*
|
7844 |
+
*
|
7845 |
+
* #### `link`
|
7846 |
+
* This property is used only if the `compile` property is not defined.
|
7847 |
+
*
|
7848 |
+
* ```js
|
7849 |
+
* function link(scope, iElement, iAttrs, controller, transcludeFn) { ... }
|
7850 |
+
* ```
|
7851 |
+
*
|
7852 |
+
* The link function is responsible for registering DOM listeners as well as updating the DOM. It is
|
7853 |
+
* executed after the template has been cloned. This is where most of the directive logic will be
|
7854 |
+
* put.
|
7855 |
+
*
|
7856 |
+
* * `scope` - {@link ng.$rootScope.Scope Scope} - The scope to be used by the
|
7857 |
+
* directive for registering {@link ng.$rootScope.Scope#$watch watches}.
|
7858 |
+
*
|
7859 |
+
* * `iElement` - instance element - The element where the directive is to be used. It is safe to
|
7860 |
+
* manipulate the children of the element only in `postLink` function since the children have
|
7861 |
+
* already been linked.
|
7862 |
+
*
|
7863 |
+
* * `iAttrs` - instance attributes - Normalized list of attributes declared on this element shared
|
7864 |
+
* between all directive linking functions.
|
7865 |
+
*
|
7866 |
+
* * `controller` - the directive's required controller instance(s) - Instances are shared
|
7867 |
+
* among all directives, which allows the directives to use the controllers as a communication
|
7868 |
+
* channel. The exact value depends on the directive's `require` property:
|
7869 |
+
* * no controller(s) required: the directive's own controller, or `undefined` if it doesn't have one
|
7870 |
+
* * `string`: the controller instance
|
7871 |
+
* * `array`: array of controller instances
|
7872 |
+
*
|
7873 |
+
* If a required controller cannot be found, and it is optional, the instance is `null`,
|
7874 |
+
* otherwise the {@link error:$compile:ctreq Missing Required Controller} error is thrown.
|
7875 |
+
*
|
7876 |
+
* Note that you can also require the directive's own controller - it will be made available like
|
7877 |
+
* any other controller.
|
7878 |
+
*
|
7879 |
+
* * `transcludeFn` - A transclude linking function pre-bound to the correct transclusion scope.
|
7880 |
+
* This is the same as the `$transclude` parameter of directive controllers,
|
7881 |
+
* see {@link ng.$compile#-controller- the controller section for details}.
|
7882 |
+
* `function([scope], cloneLinkingFn, futureParentElement)`.
|
7883 |
+
*
|
7884 |
+
* #### Pre-linking function
|
7885 |
+
*
|
7886 |
+
* Executed before the child elements are linked. Not safe to do DOM transformation since the
|
7887 |
+
* compiler linking function will fail to locate the correct elements for linking.
|
7888 |
+
*
|
7889 |
+
* #### Post-linking function
|
7890 |
+
*
|
7891 |
+
* Executed after the child elements are linked.
|
7892 |
+
*
|
7893 |
+
* Note that child elements that contain `templateUrl` directives will not have been compiled
|
7894 |
+
* and linked since they are waiting for their template to load asynchronously and their own
|
7895 |
+
* compilation and linking has been suspended until that occurs.
|
7896 |
+
*
|
7897 |
+
* It is safe to do DOM transformation in the post-linking function on elements that are not waiting
|
7898 |
+
* for their async templates to be resolved.
|
7899 |
+
*
|
7900 |
+
*
|
7901 |
+
* ### Transclusion
|
7902 |
+
*
|
7903 |
+
* Transclusion is the process of extracting a collection of DOM elements from one part of the DOM and
|
7904 |
+
* copying them to another part of the DOM, while maintaining their connection to the original AngularJS
|
7905 |
+
* scope from where they were taken.
|
7906 |
+
*
|
7907 |
+
* Transclusion is used (often with {@link ngTransclude}) to insert the
|
7908 |
+
* original contents of a directive's element into a specified place in the template of the directive.
|
7909 |
+
* The benefit of transclusion, over simply moving the DOM elements manually, is that the transcluded
|
7910 |
+
* content has access to the properties on the scope from which it was taken, even if the directive
|
7911 |
+
* has isolated scope.
|
7912 |
+
* See the {@link guide/directive#creating-a-directive-that-wraps-other-elements Directives Guide}.
|
7913 |
+
*
|
7914 |
+
* This makes it possible for the widget to have private state for its template, while the transcluded
|
7915 |
+
* content has access to its originating scope.
|
7916 |
+
*
|
7917 |
+
* <div class="alert alert-warning">
|
7918 |
+
* **Note:** When testing an element transclude directive you must not place the directive at the root of the
|
7919 |
+
* DOM fragment that is being compiled. See {@link guide/unit-testing#testing-transclusion-directives
|
7920 |
* Testing Transclusion Directives}.
|
7921 |
+
* </div>
|
7922 |
+
*
|
7923 |
+
* There are three kinds of transclusion depending upon whether you want to transclude just the contents of the
|
7924 |
+
* directive's element, the entire element or multiple parts of the element contents:
|
7925 |
+
*
|
7926 |
+
* * `true` - transclude the content (i.e. the child nodes) of the directive's element.
|
7927 |
+
* * `'element'` - transclude the whole of the directive's element including any directives on this
|
7928 |
+
* element that defined at a lower priority than this directive. When used, the `template`
|
7929 |
+
* property is ignored.
|
7930 |
+
* * **`{...}` (an object hash):** - map elements of the content onto transclusion "slots" in the template.
|
7931 |
+
*
|
7932 |
+
* **Mult-slot transclusion** is declared by providing an object for the `transclude` property.
|
7933 |
+
*
|
7934 |
+
* This object is a map where the keys are the name of the slot to fill and the value is an element selector
|
7935 |
+
* used to match the HTML to the slot. The element selector should be in normalized form (e.g. `myElement`)
|
7936 |
+
* and will match the standard element variants (e.g. `my-element`, `my:element`, `data-my-element`, etc).
|
7937 |
+
*
|
7938 |
+
* For further information check out the guide on {@link guide/directive#matching-directives Matching Directives}
|
7939 |
+
*
|
7940 |
+
* If the element selector is prefixed with a `?` then that slot is optional.
|
7941 |
+
*
|
7942 |
+
* For example, the transclude object `{ slotA: '?myCustomElement' }` maps `<my-custom-element>` elements to
|
7943 |
+
* the `slotA` slot, which can be accessed via the `$transclude` function or via the {@link ngTransclude} directive.
|
7944 |
+
*
|
7945 |
+
* Slots that are not marked as optional (`?`) will trigger a compile time error if there are no matching elements
|
7946 |
+
* in the transclude content. If you wish to know if an optional slot was filled with content, then you can call
|
7947 |
+
* `$transclude.isSlotFilled(slotName)` on the transclude function passed to the directive's link function and
|
7948 |
+
* injectable into the directive's controller.
|
7949 |
+
*
|
7950 |
+
*
|
7951 |
+
* #### Transclusion Functions
|
7952 |
+
*
|
7953 |
+
* When a directive requests transclusion, the compiler extracts its contents and provides a **transclusion
|
7954 |
+
* function** to the directive's `link` function and `controller`. This transclusion function is a special
|
7955 |
+
* **linking function** that will return the compiled contents linked to a new transclusion scope.
|
7956 |
+
*
|
7957 |
+
* <div class="alert alert-info">
|
7958 |
+
* If you are just using {@link ngTransclude} then you don't need to worry about this function, since
|
7959 |
+
* ngTransclude will deal with it for us.
|
7960 |
+
* </div>
|
7961 |
+
*
|
7962 |
+
* If you want to manually control the insertion and removal of the transcluded content in your directive
|
7963 |
+
* then you must use this transclude function. When you call a transclude function it returns a a jqLite/JQuery
|
7964 |
+
* object that contains the compiled DOM, which is linked to the correct transclusion scope.
|
7965 |
+
*
|
7966 |
+
* When you call a transclusion function you can pass in a **clone attach function**. This function accepts
|
7967 |
+
* two parameters, `function(clone, scope) { ... }`, where the `clone` is a fresh compiled copy of your transcluded
|
7968 |
+
* content and the `scope` is the newly created transclusion scope, which the clone will be linked to.
|
7969 |
+
*
|
7970 |
+
* <div class="alert alert-info">
|
7971 |
+
* **Best Practice**: Always provide a `cloneFn` (clone attach function) when you call a transclude function
|
7972 |
+
* since you then get a fresh clone of the original DOM and also have access to the new transclusion scope.
|
7973 |
+
* </div>
|
7974 |
+
*
|
7975 |
+
* It is normal practice to attach your transcluded content (`clone`) to the DOM inside your **clone
|
7976 |
+
* attach function**:
|
7977 |
+
*
|
7978 |
+
* ```js
|
7979 |
+
* var transcludedContent, transclusionScope;
|
7980 |
+
*
|
7981 |
+
* $transclude(function(clone, scope) {
|
7982 |
* element.append(clone);
|
7983 |
* transcludedContent = clone;
|
7984 |
* transclusionScope = scope;
|
7985 |
* });
|
7986 |
+
* ```
|
7987 |
+
*
|
7988 |
+
* Later, if you want to remove the transcluded content from your DOM then you should also destroy the
|
7989 |
+
* associated transclusion scope:
|
7990 |
+
*
|
7991 |
+
* ```js
|
7992 |
+
* transcludedContent.remove();
|
7993 |
+
* transclusionScope.$destroy();
|
7994 |
+
* ```
|
7995 |
+
*
|
7996 |
+
* <div class="alert alert-info">
|
7997 |
+
* **Best Practice**: if you intend to add and remove transcluded content manually in your directive
|
7998 |
+
* (by calling the transclude function to get the DOM and calling `element.remove()` to remove it),
|
7999 |
+
* then you are also responsible for calling `$destroy` on the transclusion scope.
|
8000 |
+
* </div>
|
8001 |
+
*
|
8002 |
+
* The built-in DOM manipulation directives, such as {@link ngIf}, {@link ngSwitch} and {@link ngRepeat}
|
8003 |
+
* automatically destroy their transcluded clones as necessary so you do not need to worry about this if
|
8004 |
+
* you are simply using {@link ngTransclude} to inject the transclusion into your directive.
|
8005 |
+
*
|
8006 |
+
*
|
8007 |
+
* #### Transclusion Scopes
|
8008 |
+
*
|
8009 |
+
* When you call a transclude function it returns a DOM fragment that is pre-bound to a **transclusion
|
8010 |
+
* scope**. This scope is special, in that it is a child of the directive's scope (and so gets destroyed
|
8011 |
+
* when the directive's scope gets destroyed) but it inherits the properties of the scope from which it
|
8012 |
+
* was taken.
|
8013 |
+
*
|
8014 |
+
* For example consider a directive that uses transclusion and isolated scope. The DOM hierarchy might look
|
8015 |
+
* like this:
|
8016 |
+
*
|
8017 |
+
* ```html
|
8018 |
+
* <div ng-app>
|
8019 |
+
* <div isolate>
|
8020 |
+
* <div transclusion>
|
8021 |
+
* </div>
|
8022 |
+
* </div>
|
8023 |
+
* </div>
|
8024 |
+
* ```
|
8025 |
+
*
|
8026 |
+
* The `$parent` scope hierarchy will look like this:
|
8027 |
+
*
|
8028 |
+
```
|
8029 |
+
- $rootScope
|
8030 |
- isolate
|
8031 |
+
- transclusion
|
8032 |
+
```
|
8033 |
+
*
|
8034 |
+
* but the scopes will inherit prototypically from different scopes to their `$parent`.
|
8035 |
+
*
|
8036 |
+
```
|
8037 |
+
- $rootScope
|
8038 |
- transclusion
|
8039 |
+
- isolate
|
8040 |
+
```
|
8041 |
+
*
|
8042 |
+
*
|
8043 |
+
* ### Attributes
|
8044 |
+
*
|
8045 |
+
* The {@link ng.$compile.directive.Attributes Attributes} object - passed as a parameter in the
|
8046 |
+
* `link()` or `compile()` functions. It has a variety of uses.
|
8047 |
+
*
|
8048 |
+
* * *Accessing normalized attribute names:* Directives like 'ngBind' can be expressed in many ways:
|
8049 |
+
* 'ng:bind', `data-ng-bind`, or 'x-ng-bind'. The attributes object allows for normalized access
|
8050 |
+
* to the attributes.
|
8051 |
+
*
|
8052 |
+
* * *Directive inter-communication:* All directives share the same instance of the attributes
|
8053 |
+
* object which allows the directives to use the attributes object as inter directive
|
8054 |
+
* communication.
|
8055 |
+
*
|
8056 |
+
* * *Supports interpolation:* Interpolation attributes are assigned to the attribute object
|
8057 |
+
* allowing other directives to read the interpolated value.
|
8058 |
+
*
|
8059 |
+
* * *Observing interpolated attributes:* Use `$observe` to observe the value changes of attributes
|
8060 |
+
* that contain interpolation (e.g. `src="{{bar}}"`). Not only is this very efficient but it's also
|
8061 |
+
* the only way to easily get the actual value because during the linking phase the interpolation
|
8062 |
+
* hasn't been evaluated yet and so the value is at this time set to `undefined`.
|
8063 |
+
*
|
8064 |
+
* ```js
|
8065 |
+
* function linkingFn(scope, elm, attrs, ctrl) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8066 |
* // get the attribute value
|
8067 |
* console.log(attrs.ngModel);
|
8068 |
*
|
8074 |
* console.log('ngModel has changed value to ' + value);
|
8075 |
* });
|
8076 |
* }
|
8077 |
+
* ```
|
8078 |
+
*
|
8079 |
+
* ## Example
|
8080 |
+
*
|
8081 |
+
* <div class="alert alert-warning">
|
8082 |
+
* **Note**: Typically directives are registered with `module.directive`. The example below is
|
8083 |
+
* to illustrate how `$compile` works.
|
8084 |
+
* </div>
|
8085 |
+
*
|
8086 |
+
<example module="compileExample" name="compile">
|
8087 |
+
<file name="index.html">
|
8088 |
+
<script>
|
8089 |
+
angular.module('compileExample', [], function($compileProvider) {
|
8090 |
// configure new 'compile' directive by passing a directive
|
8091 |
// factory function. The factory function injects the '$compile'
|
8092 |
$compileProvider.directive('compile', function($compile) {
|
8112 |
};
|
8113 |
});
|
8114 |
})
|
8115 |
+
.controller('GreeterController', ['$scope', function($scope) {
|
8116 |
$scope.name = 'AngularJS';
|
8117 |
$scope.html = 'Hello {{name}}';
|
8118 |
}]);
|
8119 |
+
</script>
|
8120 |
+
<div ng-controller="GreeterController">
|
8121 |
+
<input ng-model="name"> <br/>
|
8122 |
+
<textarea ng-model="html"></textarea> <br/>
|
8123 |
+
<div compile="html"></div>
|
8124 |
+
</div>
|
8125 |
+
</file>
|
8126 |
+
<file name="protractor.js" type="protractor">
|
8127 |
it('should auto compile', function() {
|
8128 |
var textarea = $('textarea');
|
8129 |
var output = $('div[compile]');
|
8133 |
textarea.sendKeys('{{name}}!');
|
8134 |
expect(output.getText()).toBe('AngularJS!');
|
8135 |
});
|
8136 |
+
</file>
|
8137 |
+
</example>
|
8138 |
|
8139 |
+
*
|
8140 |
+
*
|
8141 |
+
* @param {string|DOMElement} element Element or HTML string to compile into a template function.
|
8142 |
+
* @param {function(angular.Scope, cloneAttachFn=)} transclude function available to directives - DEPRECATED.
|
8143 |
+
*
|
8144 |
+
* <div class="alert alert-danger">
|
8145 |
+
* **Note:** Passing a `transclude` function to the $compile function is deprecated, as it
|
8146 |
+
* e.g. will not use the right outer scope. Please pass the transclude function as a
|
8147 |
+
* `parentBoundTranscludeFn` to the link function instead.
|
8148 |
+
* </div>
|
8149 |
+
*
|
8150 |
+
* @param {number} maxPriority only apply directives lower than given priority (Only effects the
|
8151 |
+
* root element(s), not their children)
|
8152 |
+
* @returns {function(scope, cloneAttachFn=, options=)} a link function which is used to bind template
|
8153 |
+
* (a DOM element/tree) to a scope. Where:
|
8154 |
+
*
|
8155 |
+
* * `scope` - A {@link ng.$rootScope.Scope Scope} to bind to.
|
8156 |
+
* * `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the
|
8157 |
+
* `template` and call the `cloneAttachFn` function allowing the caller to attach the
|
8158 |
+
* cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is
|
8159 |
+
* called as: <br/> `cloneAttachFn(clonedElement, scope)` where:
|
8160 |
+
*
|
8161 |
+
* * `clonedElement` - is a clone of the original `element` passed into the compiler.
|
8162 |
+
* * `scope` - is the current scope with which the linking function is working with.
|
8163 |
+
*
|
8164 |
+
* * `options` - An optional object hash with linking options. If `options` is provided, then the following
|
8165 |
+
* keys may be used to control linking behavior:
|
8166 |
+
*
|
8167 |
+
* * `parentBoundTranscludeFn` - the transclude function made available to
|
8168 |
+
* directives; if given, it will be passed through to the link functions of
|
8169 |
+
* directives found in `element` during compilation.
|
8170 |
+
* * `transcludeControllers` - an object hash with keys that map controller names
|
8171 |
+
* to a hash with the key `instance`, which maps to the controller instance;
|
8172 |
+
* if given, it will make the controllers available to directives on the compileNode:
|
8173 |
+
* ```
|
8174 |
+
* {
|
8175 |
* parent: {
|
8176 |
* instance: parentControllerInstance
|
8177 |
* }
|
8178 |
* }
|
8179 |
+
* ```
|
8180 |
+
* * `futureParentElement` - defines the parent to which the `cloneAttachFn` will add
|
8181 |
+
* the cloned elements; only needed for transcludes that are allowed to contain non html
|
8182 |
+
* elements (e.g. SVG elements). See also the directive.controller property.
|
8183 |
+
*
|
8184 |
+
* Calling the linking function returns the element of the template. It is either the original
|
8185 |
+
* element passed in, or the clone of the element if the `cloneAttachFn` is provided.
|
8186 |
+
*
|
8187 |
+
* After linking the view is not updated until after a call to $digest which typically is done by
|
8188 |
+
* AngularJS automatically.
|
8189 |
+
*
|
8190 |
+
* If you need access to the bound view, there are two ways to do it:
|
8191 |
+
*
|
8192 |
+
* - If you are not asking the linking function to clone the template, create the DOM element(s)
|
8193 |
+
* before you send them to the compiler and keep this reference around.
|
8194 |
+
* ```js
|
8195 |
+
* var element = $compile('<p>{{total}}</p>')(scope);
|
8196 |
+
* ```
|
8197 |
+
*
|
8198 |
+
* - if on the other hand, you need the element to be cloned, the view reference from the original
|
8199 |
+
* example would not point to the clone, but rather to the original template that was cloned. In
|
8200 |
+
* this case, you can access the clone via the cloneAttachFn:
|
8201 |
+
* ```js
|
8202 |
+
* var templateElement = angular.element('<p>{{total}}</p>'),
|
8203 |
+
* scope = ....;
|
8204 |
+
*
|
8205 |
+
* var clonedElement = $compile(templateElement)(scope, function(clonedElement, scope) {
|
8206 |
* //attach the clone to DOM document at the right place
|
8207 |
* });
|
8208 |
+
*
|
8209 |
+
* //now we have reference to the cloned DOM via `clonedElement`
|
8210 |
+
* ```
|
8211 |
+
*
|
8212 |
+
*
|
8213 |
+
* For information on how the compiler works, see the
|
8214 |
+
* {@link guide/compiler AngularJS HTML Compiler} section of the Developer Guide.
|
8215 |
+
*
|
8216 |
+
* @knownIssue
|
8217 |
+
*
|
8218 |
+
* ### Double Compilation
|
8219 |
+
*
|
8220 |
+
Double compilation occurs when an already compiled part of the DOM gets
|
8221 |
+
compiled again. This is an undesired effect and can lead to misbehaving directives, performance issues,
|
8222 |
+
and memory leaks. Refer to the Compiler Guide {@link guide/compiler#double-compilation-and-how-to-avoid-it
|
8223 |
section on double compilation} for an in-depth explanation and ways to avoid it.
|
8224 |
|
8225 |
+
* @knownIssue
|
8226 |
|
8227 |
+
### Issues with `replace: true`
|
8228 |
+
*
|
8229 |
+
* <div class="alert alert-danger">
|
8230 |
+
* **Note**: {@link $compile#-replace- `replace: true`} is deprecated and not recommended to use,
|
8231 |
+
* mainly due to the issues listed here. It has been completely removed in the new Angular.
|
8232 |
+
* </div>
|
8233 |
+
*
|
8234 |
+
* #### Attribute values are not merged
|
8235 |
+
*
|
8236 |
+
* When a `replace` directive encounters the same attribute on the original and the replace node,
|
8237 |
+
* it will simply deduplicate the attribute and join the values with a space or with a `;` in case of
|
8238 |
+
* the `style` attribute.
|
8239 |
+
* ```html
|
8240 |
+
* Original Node: <span class="original" style="color: red;"></span>
|
8241 |
+
* Replace Template: <span class="replaced" style="background: blue;"></span>
|
8242 |
+
* Result: <span class="original replaced" style="color: red; background: blue;"></span>
|
8243 |
+
* ```
|
8244 |
+
*
|
8245 |
+
* That means attributes that contain AngularJS expressions will not be merged correctly, e.g.
|
8246 |
+
* {@link ngShow} or {@link ngClass} will cause a {@link $parse} error:
|
8247 |
+
*
|
8248 |
+
* ```html
|
8249 |
+
* Original Node: <span ng-class="{'something': something}" ng-show="!condition"></span>
|
8250 |
+
* Replace Template: <span ng-class="{'else': else}" ng-show="otherCondition"></span>
|
8251 |
+
* Result: <span ng-class="{'something': something} {'else': else}" ng-show="!condition otherCondition"></span>
|
8252 |
+
* ```
|
8253 |
+
*
|
8254 |
+
* See issue [#5695](https://github.com/angular/angular.js/issues/5695).
|
8255 |
+
*
|
8256 |
+
* #### Directives are not deduplicated before compilation
|
8257 |
+
*
|
8258 |
+
* When the original node and the replace template declare the same directive(s), they will be
|
8259 |
+
* {@link guide/compiler#double-compilation-and-how-to-avoid-it compiled twice} because the compiler
|
8260 |
+
* does not deduplicate them. In many cases, this is not noticable, but e.g. {@link ngModel} will
|
8261 |
+
* attach `$formatters` and `$parsers` twice.
|
8262 |
+
*
|
8263 |
+
* See issue [#2573](https://github.com/angular/angular.js/issues/2573).
|
8264 |
+
*
|
8265 |
+
* #### `transclude: element` in the replace template root can have unexpected effects
|
8266 |
+
*
|
8267 |
+
* When the replace template has a directive at the root node that uses
|
8268 |
+
* {@link $compile#-transclude- `transclude: element`}, e.g.
|
8269 |
+
* {@link ngIf} or {@link ngRepeat}, the DOM structure or scope inheritance can be incorrect.
|
8270 |
+
* See the following issues:
|
8271 |
+
*
|
8272 |
+
* - Incorrect scope on replaced element:
|
8273 |
+
* [#9837](https://github.com/angular/angular.js/issues/9837)
|
8274 |
+
* - Different DOM between `template` and `templateUrl`:
|
8275 |
+
* [#10612](https://github.com/angular/angular.js/issues/14326)
|
8276 |
+
*
|
8277 |
+
*/
|
8278 |
|
8279 |
+
/**
|
8280 |
+
* @ngdoc directive
|
8281 |
+
* @name ngProp
|
8282 |
+
* @restrict A
|
8283 |
+
* @element ANY
|
8284 |
+
*
|
8285 |
+
* @usage
|
8286 |
+
*
|
8287 |
+
* ```html
|
8288 |
+
* <ANY ng-prop-propname="expression">
|
8289 |
+
* </ANY>
|
8290 |
+
* ```
|
8291 |
+
*
|
8292 |
+
* or with uppercase letters in property (e.g. "propName"):
|
8293 |
+
*
|
8294 |
+
*
|
8295 |
+
* ```html
|
8296 |
+
* <ANY ng-prop-prop_name="expression">
|
8297 |
+
* </ANY>
|
8298 |
+
* ```
|
8299 |
+
*
|
8300 |
+
*
|
8301 |
+
* @description
|
8302 |
+
* The `ngProp` directive binds an expression to a DOM element property.
|
8303 |
+
* `ngProp` allows writing to arbitrary properties by including
|
8304 |
+
* the property name in the attribute, e.g. `ng-prop-value="'my value'"` binds 'my value' to
|
8305 |
+
* the `value` property.
|
8306 |
+
*
|
8307 |
+
* Usually, it's not necessary to write to properties in AngularJS, as the built-in directives
|
8308 |
+
* handle the most common use cases (instead of the above example, you would use {@link ngValue}).
|
8309 |
+
*
|
8310 |
+
* However, [custom elements](https://developer.mozilla.org/docs/Web/Web_Components/Using_custom_elements)
|
8311 |
+
* often use custom properties to hold data, and `ngProp` can be used to provide input to these
|
8312 |
+
* custom elements.
|
8313 |
+
*
|
8314 |
+
* ## Binding to camelCase properties
|
8315 |
+
*
|
8316 |
+
* Since HTML attributes are case-insensitive, camelCase properties like `innerHTML` must be escaped.
|
8317 |
+
* AngularJS uses the underscore (_) in front of a character to indicate that it is uppercase, so
|
8318 |
+
* `innerHTML` must be written as `ng-prop-inner_h_t_m_l="expression"` (Note that this is just an
|
8319 |
+
* example, and for binding HTML {@link ngBindHtml} should be used.
|
8320 |
+
*
|
8321 |
+
* ## Security
|
8322 |
+
*
|
8323 |
+
* Binding expressions to arbitrary properties poses a security risk, as properties like `innerHTML`
|
8324 |
+
* can insert potentially dangerous HTML into the application, e.g. script tags that execute
|
8325 |
+
* malicious code.
|
8326 |
+
* For this reason, `ngProp` applies Strict Contextual Escaping with the {@link ng.$sce $sce service}.
|
8327 |
+
* This means vulnerable properties require their content to be "trusted", based on the
|
8328 |
+
* context of the property. For example, the `innerHTML` is in the `HTML` context, and the
|
8329 |
+
* `iframe.src` property is in the `RESOURCE_URL` context, which requires that values written to
|
8330 |
+
* this property are trusted as a `RESOURCE_URL`.
|
8331 |
+
*
|
8332 |
+
* This can be set explicitly by calling $sce.trustAs(type, value) on the value that is
|
8333 |
+
* trusted before passing it to the `ng-prop-*` directive. There are exist shorthand methods for
|
8334 |
+
* each context type in the form of {@link ng.$sce#trustAsResourceUrl $sce.trustAsResourceUrl()} et al.
|
8335 |
+
*
|
8336 |
+
* In some cases you can also rely upon automatic sanitization of untrusted values - see below.
|
8337 |
+
*
|
8338 |
+
* Based on the context, other options may exist to mark a value as trusted / configure the behavior
|
8339 |
+
* of {@link ng.$sce}. For example, to restrict the `RESOURCE_URL` context to specific origins, use
|
8340 |
+
* the {@link $sceDelegateProvider#resourceUrlWhitelist resourceUrlWhitelist()}
|
8341 |
+
* and {@link $sceDelegateProvider#resourceUrlBlacklist resourceUrlBlacklist()}.
|
8342 |
+
*
|
8343 |
+
* {@link ng.$sce#what-trusted-context-types-are-supported- Find out more about the different context types}.
|
8344 |
+
*
|
8345 |
+
* ### HTML Sanitization
|
8346 |
+
*
|
8347 |
+
* By default, `$sce` will throw an error if it detects untrusted HTML content, and will not bind the
|
8348 |
+
* content.
|
8349 |
+
* However, if you include the {@link ngSanitize ngSanitize module}, it will try to sanitize the
|
8350 |
+
* potentially dangerous HTML, e.g. strip non-whitelisted tags and attributes when binding to
|
8351 |
+
* `innerHTML`.
|
8352 |
+
*
|
8353 |
+
* @example
|
8354 |
+
* ### Binding to different contexts
|
8355 |
+
*
|
8356 |
+
* <example name="ngProp" module="exampleNgProp">
|
8357 |
+
* <file name="app.js">
|
8358 |
+
* angular.module('exampleNgProp', [])
|
8359 |
+
* .component('main', {
|
8360 |
* templateUrl: 'main.html',
|
8361 |
* controller: function($sce) {
|
8362 |
* this.safeContent = '<strong>Safe content</strong>';
|
8364 |
* this.trustedUnsafeContent = $sce.trustAsHtml(this.unsafeContent);
|
8365 |
* }
|
8366 |
* });
|
8367 |
+
* </file>
|
8368 |
+
* <file name="main.html">
|
8369 |
+
* <div>
|
8370 |
+
* <div class="prop-unit">
|
8371 |
+
* Binding to a property without security context:
|
8372 |
+
* <div class="prop-binding" ng-prop-inner_text="$ctrl.safeContent"></div>
|
8373 |
+
* <span class="prop-note">innerText</span> (safeContent)
|
8374 |
+
* </div>
|
8375 |
+
*
|
8376 |
+
* <div class="prop-unit">
|
8377 |
+
* "Safe" content that requires a security context will throw because the contents could potentially be dangerous ...
|
8378 |
+
* <div class="prop-binding" ng-prop-inner_h_t_m_l="$ctrl.safeContent"></div>
|
8379 |
+
* <span class="prop-note">innerHTML</span> (safeContent)
|
8380 |
+
* </div>
|
8381 |
+
*
|
8382 |
+
* <div class="prop-unit">
|
8383 |
+
* ... so that actually dangerous content cannot be executed:
|
8384 |
+
* <div class="prop-binding" ng-prop-inner_h_t_m_l="$ctrl.unsafeContent"></div>
|
8385 |
+
* <span class="prop-note">innerHTML</span> (unsafeContent)
|
8386 |
+
* </div>
|
8387 |
+
*
|
8388 |
+
* <div class="prop-unit">
|
8389 |
+
* ... but unsafe Content that has been trusted explicitly works - only do this if you are 100% sure!
|
8390 |
+
* <div class="prop-binding" ng-prop-inner_h_t_m_l="$ctrl.trustedUnsafeContent"></div>
|
8391 |
+
* <span class="prop-note">innerHTML</span> (trustedUnsafeContent)
|
8392 |
+
* </div>
|
8393 |
+
* </div>
|
8394 |
+
* </file>
|
8395 |
+
* <file name="index.html">
|
8396 |
+
* <main></main>
|
8397 |
+
* </file>
|
8398 |
+
* <file name="styles.css">
|
8399 |
+
* .prop-unit {
|
8400 |
* margin-bottom: 10px;
|
8401 |
* }
|
8402 |
+
*
|
8403 |
+
* .prop-binding {
|
8404 |
* min-height: 30px;
|
8405 |
* border: 1px solid blue;
|
8406 |
* }
|
8407 |
+
*
|
8408 |
+
* .prop-note {
|
8409 |
* font-family: Monospace;
|
8410 |
* }
|
8411 |
+
* </file>
|
8412 |
+
* </example>
|
8413 |
+
*
|
8414 |
+
*
|
8415 |
+
* @example
|
8416 |
+
* ### Binding to innerHTML with ngSanitize
|
8417 |
+
*
|
8418 |
+
* <example name="ngProp" module="exampleNgProp" deps="angular-sanitize.js">
|
8419 |
+
* <file name="app.js">
|
8420 |
+
* angular.module('exampleNgProp', ['ngSanitize'])
|
8421 |
+
* .component('main', {
|
8422 |
* templateUrl: 'main.html',
|
8423 |
* controller: function($sce) {
|
8424 |
* this.safeContent = '<strong>Safe content</strong>';
|
8426 |
* this.trustedUnsafeContent = $sce.trustAsHtml(this.unsafeContent);
|
8427 |
* }
|
8428 |
* });
|
8429 |
+
* </file>
|
8430 |
+
* <file name="main.html">
|
8431 |
+
* <div>
|
8432 |
+
* <div class="prop-unit">
|
8433 |
+
* "Safe" content will be sanitized ...
|
8434 |
+
* <div class="prop-binding" ng-prop-inner_h_t_m_l="$ctrl.safeContent"></div>
|
8435 |
+
* <span class="prop-note">innerHTML</span> (safeContent)
|
8436 |
+
* </div>
|
8437 |
+
*
|
8438 |
+
* <div class="prop-unit">
|
8439 |
+
* ... as will dangerous content:
|
8440 |
+
* <div class="prop-binding" ng-prop-inner_h_t_m_l="$ctrl.unsafeContent"></div>
|
8441 |
+
* <span class="prop-note">innerHTML</span> (unsafeContent)
|
8442 |
+
* </div>
|
8443 |
+
*
|
8444 |
+
* <div class="prop-unit">
|
8445 |
+
* ... and content that has been trusted explicitly works the same as without ngSanitize:
|
8446 |
+
* <div class="prop-binding" ng-prop-inner_h_t_m_l="$ctrl.trustedUnsafeContent"></div>
|
8447 |
+
* <span class="prop-note">innerHTML</span> (trustedUnsafeContent)
|
8448 |
+
* </div>
|
8449 |
+
* </div>
|
8450 |
+
* </file>
|
8451 |
+
* <file name="index.html">
|
8452 |
+
* <main></main>
|
8453 |
+
* </file>
|
8454 |
+
* <file name="styles.css">
|
8455 |
+
* .prop-unit {
|
8456 |
* margin-bottom: 10px;
|
8457 |
* }
|
8458 |
+
*
|
8459 |
+
* .prop-binding {
|
8460 |
* min-height: 30px;
|
8461 |
* border: 1px solid blue;
|
8462 |
* }
|
8463 |
+
*
|
8464 |
+
* .prop-note {
|
8465 |
* font-family: Monospace;
|
8466 |
* }
|
8467 |
+
* </file>
|
8468 |
+
* </example>
|
8469 |
+
*
|
8470 |
+
*/
|
8471 |
|
8472 |
+
/** @ngdoc directive
|
8473 |
+
* @name ngOn
|
8474 |
+
* @restrict A
|
8475 |
+
* @element ANY
|
8476 |
+
*
|
8477 |
+
* @usage
|
8478 |
+
*
|
8479 |
+
* ```html
|
8480 |
+
* <ANY ng-on-eventname="expression">
|
8481 |
+
* </ANY>
|
8482 |
+
* ```
|
8483 |
+
*
|
8484 |
+
* or with uppercase letters in property (e.g. "eventName"):
|
8485 |
+
*
|
8486 |
+
*
|
8487 |
+
* ```html
|
8488 |
+
* <ANY ng-on-event_name="expression">
|
8489 |
+
* </ANY>
|
8490 |
+
* ```
|
8491 |
+
*
|
8492 |
+
* @description
|
8493 |
+
* The `ngOn` directive adds an event listener to a DOM element via
|
8494 |
+
* {@link angular.element angular.element().on()}, and evaluates an expression when the event is
|
8495 |
+
* fired.
|
8496 |
+
* `ngOn` allows adding listeners for arbitrary events by including
|
8497 |
+
* the event name in the attribute, e.g. `ng-on-drop="onDrop()"` executes the 'onDrop()' expression
|
8498 |
+
* when the `drop` event is fired.
|
8499 |
+
*
|
8500 |
+
* AngularJS provides specific directives for many events, such as {@link ngClick}, so in most
|
8501 |
+
* cases it is not necessary to use `ngOn`. However, AngularJS does not support all events
|
8502 |
+
* (e.g. the `drop` event in the example above), and new events might be introduced in later DOM
|
8503 |
+
* standards.
|
8504 |
+
*
|
8505 |
+
* Another use-case for `ngOn` is listening to
|
8506 |
+
* [custom events](https://developer.mozilla.org/docs/Web/Guide/Events/Creating_and_triggering_events)
|
8507 |
+
* fired by
|
8508 |
+
* [custom elements](https://developer.mozilla.org/docs/Web/Web_Components/Using_custom_elements).
|
8509 |
+
*
|
8510 |
+
* ## Binding to camelCase properties
|
8511 |
+
*
|
8512 |
+
* Since HTML attributes are case-insensitive, camelCase properties like `myEvent` must be escaped.
|
8513 |
+
* AngularJS uses the underscore (_) in front of a character to indicate that it is uppercase, so
|
8514 |
+
* `myEvent` must be written as `ng-on-my_event="expression"`.
|
8515 |
+
*
|
8516 |
+
* @example
|
8517 |
+
* ### Bind to built-in DOM events
|
8518 |
+
*
|
8519 |
+
* <example name="ngOn" module="exampleNgOn">
|
8520 |
+
* <file name="app.js">
|
8521 |
+
* angular.module('exampleNgOn', [])
|
8522 |
+
* .component('main', {
|
8523 |
* templateUrl: 'main.html',
|
8524 |
* controller: function() {
|
8525 |
* this.clickCount = 0;
|
8528 |
* this.loadingState = 0;
|
8529 |
* }
|
8530 |
* });
|
8531 |
+
* </file>
|
8532 |
+
* <file name="main.html">
|
8533 |
+
* <div>
|
8534 |
+
* This is equivalent to `ngClick` and `ngMouseover`:<br>
|
8535 |
+
* <button
|
8536 |
+
* ng-on-click="$ctrl.clickCount = $ctrl.clickCount + 1"
|
8537 |
+
* ng-on-mouseover="$ctrl.mouseoverCount = $ctrl.mouseoverCount + 1">Click or mouseover</button><br>
|
8538 |
+
* clickCount: {{$ctrl.clickCount}}<br>
|
8539 |
+
* mouseover: {{$ctrl.mouseoverCount}}
|
8540 |
+
*
|
8541 |
+
* <hr>
|
8542 |
+
*
|
8543 |
+
* For the `error` and `load` event on images no built-in AngularJS directives exist:<br>
|
8544 |
+
* <img src="thisimagedoesnotexist.png" ng-on-error="$ctrl.loadingState = -1" ng-on-load="$ctrl.loadingState = 1"><br>
|
8545 |
+
* <div ng-switch="$ctrl.loadingState">
|
8546 |
+
* <span ng-switch-when="0">Image is loading</span>
|
8547 |
+
* <span ng-switch-when="-1">Image load error</span>
|
8548 |
+
* <span ng-switch-when="1">Image loaded successfully</span>
|
8549 |
+
* </div>
|
8550 |
+
* </div>
|
8551 |
+
* </file>
|
8552 |
+
* <file name="index.html">
|
8553 |
+
* <main></main>
|
8554 |
+
* </file>
|
8555 |
+
* </example>
|
8556 |
+
*
|
8557 |
+
*
|
8558 |
+
* @example
|
8559 |
+
* ### Bind to custom DOM events
|
8560 |
+
*
|
8561 |
+
* <example name="ngOnCustom" module="exampleNgOn">
|
8562 |
+
* <file name="app.js">
|
8563 |
+
* angular.module('exampleNgOn', [])
|
8564 |
+
* .component('main', {
|
8565 |
* templateUrl: 'main.html',
|
8566 |
* controller: function() {
|
8567 |
* this.eventLog = '';
|
8571 |
* };
|
8572 |
* }
|
8573 |
* })
|
8574 |
+
* .component('childComponent', {
|
8575 |
* templateUrl: 'child.html',
|
8576 |
* controller: function($element) {
|
8577 |
* this.fireEvent = function() {
|
8581 |
* };
|
8582 |
* }
|
8583 |
* });
|
8584 |
+
* </file>
|
8585 |
+
* <file name="main.html">
|
8586 |
+
* <child-component ng-on-customtype="$ctrl.listener($event)"></child-component><br>
|
8587 |
+
* <span>Event log: {{$ctrl.eventLog}}</span>
|
8588 |
+
* </file>
|
8589 |
+
* <file name="child.html">
|
8590 |
+
<button ng-click="$ctrl.fireEvent()">Fire custom event</button>
|
8591 |
+
* </file>
|
8592 |
+
* <file name="index.html">
|
8593 |
+
* <main></main>
|
8594 |
+
* </file>
|
8595 |
+
* </example>
|
8596 |
+
*/
|
|
|
|
|
8597 |
|
8598 |
+
var $compileMinErr = minErr('$compile');
|
|
|
8599 |
|
8600 |
+
function UNINITIALIZED_VALUE() {}
|
8601 |
+
var _UNINITIALIZED_VALUE = new UNINITIALIZED_VALUE();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8602 |
|
8603 |
+
/**
|
8604 |
+
* @ngdoc provider
|
8605 |
+
* @name $compileProvider
|
8606 |
+
*
|
8607 |
+
* @description
|
8608 |
+
*/
|
8609 |
+
$CompileProvider.$inject = ['$provide', '$$sanitizeUriProvider'];
|
8610 |
+
/** @this */
|
8611 |
+
function $CompileProvider($provide, $$sanitizeUriProvider) {
|
8612 |
+
var hasDirectives = {},
|
8613 |
+
Suffix = 'Directive',
|
8614 |
+
COMMENT_DIRECTIVE_REGEXP = /^\s*directive:\s*([\w-]+)\s+(.*)$/,
|
8615 |
+
CLASS_DIRECTIVE_REGEXP = /(([\w-]+)(?::([^;]+))?;?)/,
|
8616 |
+
ALL_OR_NOTHING_ATTRS = makeMap('ngSrc,ngSrcset,src,srcset'),
|
8617 |
+
REQUIRE_PREFIX_REGEXP = /^(?:(\^\^?)?(\?)?(\^\^?)?)?/;
|
8618 |
+
|
8619 |
+
// Ref: http://developers.whatwg.org/webappapis.html#event-handler-idl-attributes
|
8620 |
+
// The assumption is that future DOM event attribute names will begin with
|
8621 |
+
// 'on' and be composed of only English letters.
|
8622 |
+
var EVENT_HANDLER_ATTR_REGEXP = /^(on[a-z]+|formaction)$/;
|
8623 |
+
var bindingCache = createMap();
|
8624 |
+
|
8625 |
+
function parseIsolateBindings(scope, directiveName, isController) {
|
8626 |
+
var LOCAL_REGEXP = /^([@&]|[=<](\*?))(\??)\s*([\w$]*)$/;
|
8627 |
+
|
8628 |
+
var bindings = createMap();
|
8629 |
+
|
8630 |
+
forEach(scope, function(definition, scopeName) {
|
8631 |
+
definition = definition.trim();
|
8632 |
+
|
8633 |
+
if (definition in bindingCache) {
|
8634 |
+
bindings[scopeName] = bindingCache[definition];
|
8635 |
+
return;
|
8636 |
+
}
|
8637 |
+
var match = definition.match(LOCAL_REGEXP);
|
8638 |
+
|
8639 |
+
if (!match) {
|
8640 |
+
throw $compileMinErr('iscp',
|
8641 |
+
'Invalid {3} for directive \'{0}\'.' +
|
8642 |
+
' Definition: {... {1}: \'{2}\' ...}',
|
8643 |
+
directiveName, scopeName, definition,
|
8644 |
+
(isController ? 'controller bindings definition' :
|
8645 |
+
'isolate scope definition'));
|
8646 |
+
}
|
8647 |
|
8648 |
+
bindings[scopeName] = {
|
8649 |
+
mode: match[1][0],
|
8650 |
+
collection: match[2] === '*',
|
8651 |
+
optional: match[3] === '?',
|
8652 |
+
attrName: match[4] || scopeName
|
8653 |
+
};
|
8654 |
+
if (match[4]) {
|
8655 |
+
bindingCache[definition] = bindings[scopeName];
|
8656 |
+
}
|
8657 |
+
});
|
8658 |
|
8659 |
+
return bindings;
|
8660 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8661 |
|
8662 |
+
function parseDirectiveBindings(directive, directiveName) {
|
8663 |
+
var bindings = {
|
8664 |
+
isolateScope: null,
|
8665 |
+
bindToController: null
|
8666 |
+
};
|
8667 |
+
if (isObject(directive.scope)) {
|
8668 |
+
if (directive.bindToController === true) {
|
8669 |
+
bindings.bindToController = parseIsolateBindings(directive.scope,
|
8670 |
+
directiveName, true);
|
8671 |
+
bindings.isolateScope = {};
|
8672 |
+
} else {
|
8673 |
+
bindings.isolateScope = parseIsolateBindings(directive.scope,
|
8674 |
+
directiveName, false);
|
8675 |
+
}
|
8676 |
+
}
|
8677 |
+
if (isObject(directive.bindToController)) {
|
8678 |
+
bindings.bindToController =
|
8679 |
+
parseIsolateBindings(directive.bindToController, directiveName, true);
|
8680 |
+
}
|
8681 |
+
if (bindings.bindToController && !directive.controller) {
|
8682 |
+
// There is no controller
|
8683 |
+
throw $compileMinErr('noctrl',
|
8684 |
+
'Cannot bind to controller without directive \'{0}\'s controller.',
|
8685 |
+
directiveName);
|
8686 |
+
}
|
8687 |
+
return bindings;
|
8688 |
+
}
|
8689 |
|
8690 |
+
function assertValidDirectiveName(name) {
|
8691 |
+
var letter = name.charAt(0);
|
8692 |
+
if (!letter || letter !== lowercase(letter)) {
|
8693 |
+
throw $compileMinErr('baddir', 'Directive/Component name \'{0}\' is invalid. The first character must be a lowercase letter', name);
|
8694 |
+
}
|
8695 |
+
if (name !== name.trim()) {
|
8696 |
+
throw $compileMinErr('baddir',
|
8697 |
+
'Directive/Component name \'{0}\' is invalid. The name should not contain leading or trailing whitespaces',
|
8698 |
+
name);
|
8699 |
+
}
|
8700 |
+
}
|
8701 |
|
8702 |
+
function getDirectiveRequire(directive) {
|
8703 |
+
var require = directive.require || (directive.controller && directive.name);
|
|
|
|
|
|
|
|
|
|
|
8704 |
|
8705 |
+
if (!isArray(require) && isObject(require)) {
|
8706 |
+
forEach(require, function(value, key) {
|
8707 |
+
var match = value.match(REQUIRE_PREFIX_REGEXP);
|
8708 |
+
var name = value.substring(match[0].length);
|
8709 |
+
if (!name) require[key] = match[0] + key;
|
8710 |
+
});
|
8711 |
+
}
|
8712 |
|
8713 |
+
return require;
|
8714 |
+
}
|
|
|
|
|
|
|
|
|
|
|
8715 |
|
8716 |
+
function getDirectiveRestrict(restrict, name) {
|
8717 |
+
if (restrict && !(isString(restrict) && /[EACM]/.test(restrict))) {
|
8718 |
+
throw $compileMinErr('badrestrict',
|
8719 |
+
'Restrict property \'{0}\' of directive \'{1}\' is invalid',
|
8720 |
+
restrict,
|
8721 |
+
name);
|
8722 |
+
}
|
8723 |
|
8724 |
+
return restrict || 'EA';
|
8725 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8726 |
|
8727 |
+
/**
|
8728 |
+
* @ngdoc method
|
8729 |
+
* @name $compileProvider#directive
|
8730 |
+
* @kind function
|
8731 |
+
*
|
8732 |
+
* @description
|
8733 |
+
* Register a new directive with the compiler.
|
8734 |
+
*
|
8735 |
+
* @param {string|Object} name Name of the directive in camel-case (i.e. <code>ngBind</code> which
|
8736 |
+
* will match as <code>ng-bind</code>), or an object map of directives where the keys are the
|
8737 |
+
* names and the values are the factories.
|
8738 |
+
* @param {Function|Array} directiveFactory An injectable directive factory function. See the
|
8739 |
+
* {@link guide/directive directive guide} and the {@link $compile compile API} for more info.
|
8740 |
+
* @returns {ng.$compileProvider} Self for chaining.
|
8741 |
+
*/
|
8742 |
+
this.directive = function registerDirective(name, directiveFactory) {
|
8743 |
+
assertArg(name, 'name');
|
8744 |
+
assertNotHasOwnProperty(name, 'directive');
|
8745 |
+
if (isString(name)) {
|
8746 |
+
assertValidDirectiveName(name);
|
8747 |
+
assertArg(directiveFactory, 'directiveFactory');
|
8748 |
+
if (!hasDirectives.hasOwnProperty(name)) {
|
8749 |
+
hasDirectives[name] = [];
|
8750 |
+
$provide.factory(name + Suffix, ['$injector', '$exceptionHandler',
|
8751 |
+
function($injector, $exceptionHandler) {
|
8752 |
+
var directives = [];
|
8753 |
+
forEach(hasDirectives[name], function(directiveFactory, index) {
|
8754 |
+
try {
|
8755 |
+
var directive = $injector.invoke(directiveFactory);
|
8756 |
+
if (isFunction(directive)) {
|
8757 |
+
directive = { compile: valueFn(directive) };
|
8758 |
+
} else if (!directive.compile && directive.link) {
|
8759 |
+
directive.compile = valueFn(directive.link);
|
8760 |
+
}
|
8761 |
+
directive.priority = directive.priority || 0;
|
8762 |
+
directive.index = index;
|
8763 |
+
directive.name = directive.name || name;
|
8764 |
+
directive.require = getDirectiveRequire(directive);
|
8765 |
+
directive.restrict = getDirectiveRestrict(directive.restrict, name);
|
8766 |
+
directive.$$moduleName = directiveFactory.$$moduleName;
|
8767 |
+
directives.push(directive);
|
8768 |
+
} catch (e) {
|
8769 |
+
$exceptionHandler(e);
|
8770 |
+
}
|
8771 |
+
});
|
8772 |
+
return directives;
|
8773 |
+
}]);
|
8774 |
+
}
|
8775 |
+
hasDirectives[name].push(directiveFactory);
|
8776 |
+
} else {
|
8777 |
+
forEach(name, reverseParams(registerDirective));
|
8778 |
+
}
|
8779 |
+
return this;
|
8780 |
+
};
|
8781 |
+
|
8782 |
+
/**
|
8783 |
+
* @ngdoc method
|
8784 |
+
* @name $compileProvider#component
|
8785 |
+
* @module ng
|
8786 |
+
* @param {string|Object} name Name of the component in camelCase (i.e. `myComp` which will match `<my-comp>`),
|
8787 |
+
* or an object map of components where the keys are the names and the values are the component definition objects.
|
8788 |
+
* @param {Object} options Component definition object (a simplified
|
8789 |
+
* {@link ng.$compile#directive-definition-object directive definition object}),
|
8790 |
+
* with the following properties (all optional):
|
8791 |
+
*
|
8792 |
+
* - `controller` – `{(string|function()=}` – controller constructor function that should be
|
8793 |
+
* associated with newly created scope or the name of a {@link ng.$compile#-controller-
|
8794 |
* registered controller} if passed as a string. An empty `noop` function by default.
|
8795 |
+
* - `controllerAs` – `{string=}` – identifier name for to reference the controller in the component's scope.
|
8796 |
+
* If present, the controller will be published to scope under the `controllerAs` name.
|
8797 |
+
* If not present, this will default to be `$ctrl`.
|
8798 |
+
* - `template` – `{string=|function()=}` – html template as a string or a function that
|
8799 |
+
* returns an html template as a string which should be used as the contents of this component.
|
8800 |
+
* Empty string by default.
|
8801 |
+
*
|
8802 |
+
* If `template` is a function, then it is {@link auto.$injector#invoke injected} with
|
8803 |
+
* the following locals:
|
8804 |
+
*
|
8805 |
+
* - `$element` - Current element
|
8806 |
+
* - `$attrs` - Current attributes object for the element
|
8807 |
+
*
|
8808 |
+
* - `templateUrl` – `{string=|function()=}` – path or function that returns a path to an html
|
8809 |
+
* template that should be used as the contents of this component.
|
8810 |
+
*
|
8811 |
+
* If `templateUrl` is a function, then it is {@link auto.$injector#invoke injected} with
|
8812 |
+
* the following locals:
|
8813 |
+
*
|
8814 |
+
* - `$element` - Current element
|
8815 |
+
* - `$attrs` - Current attributes object for the element
|
8816 |
+
*
|
8817 |
+
* - `bindings` – `{object=}` – defines bindings between DOM attributes and component properties.
|
8818 |
+
* Component properties are always bound to the component controller and not to the scope.
|
8819 |
+
* See {@link ng.$compile#-bindtocontroller- `bindToController`}.
|
8820 |
+
* - `transclude` – `{boolean=}` – whether {@link $compile#transclusion content transclusion} is enabled.
|
8821 |
+
* Disabled by default.
|
8822 |
+
* - `require` - `{Object<string, string>=}` - requires the controllers of other directives and binds them to
|
8823 |
+
* this component's controller. The object keys specify the property names under which the required
|
8824 |
+
* controllers (object values) will be bound. See {@link ng.$compile#-require- `require`}.
|
8825 |
+
* - `$...` – additional properties to attach to the directive factory function and the controller
|
8826 |
+
* constructor function. (This is used by the component router to annotate)
|
8827 |
+
*
|
8828 |
+
* @returns {ng.$compileProvider} the compile provider itself, for chaining of function calls.
|
8829 |
+
* @description
|
8830 |
+
* Register a **component definition** with the compiler. This is a shorthand for registering a special
|
8831 |
+
* type of directive, which represents a self-contained UI component in your application. Such components
|
8832 |
+
* are always isolated (i.e. `scope: {}`) and are always restricted to elements (i.e. `restrict: 'E'`).
|
8833 |
+
*
|
8834 |
+
* Component definitions are very simple and do not require as much configuration as defining general
|
8835 |
+
* directives. Component definitions usually consist only of a template and a controller backing it.
|
8836 |
+
*
|
8837 |
+
* In order to make the definition easier, components enforce best practices like use of `controllerAs`,
|
8838 |
+
* `bindToController`. They always have **isolate scope** and are restricted to elements.
|
8839 |
+
*
|
8840 |
+
* Here are a few examples of how you would usually define components:
|
8841 |
+
*
|
8842 |
+
* ```js
|
8843 |
+
* var myMod = angular.module(...);
|
8844 |
+
* myMod.component('myComp', {
|
8845 |
* template: '<div>My name is {{$ctrl.name}}</div>',
|
8846 |
* controller: function() {
|
8847 |
* this.name = 'shahar';
|
8848 |
* }
|
8849 |
* });
|
8850 |
+
*
|
8851 |
+
* myMod.component('myComp', {
|
8852 |
* template: '<div>My name is {{$ctrl.name}}</div>',
|
8853 |
* bindings: {name: '@'}
|
8854 |
* });
|
8855 |
+
*
|
8856 |
+
* myMod.component('myComp', {
|
8857 |
* templateUrl: 'views/my-comp.html',
|
8858 |
* controller: 'MyCtrl',
|
8859 |
* controllerAs: 'ctrl',
|
8860 |
* bindings: {name: '@'}
|
8861 |
* });
|
8862 |
+
*
|
8863 |
+
* ```
|
8864 |
+
* For more examples, and an in-depth guide, see the {@link guide/component component guide}.
|
8865 |
+
*
|
8866 |
+
* <br />
|
8867 |
+
* See also {@link ng.$compileProvider#directive $compileProvider.directive()}.
|
8868 |
+
*/
|
8869 |
+
this.component = function registerComponent(name, options) {
|
8870 |
+
if (!isString(name)) {
|
8871 |
+
forEach(name, reverseParams(bind(this, registerComponent)));
|
8872 |
+
return this;
|
8873 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8874 |
|
8875 |
+
var controller = options.controller || function() {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8876 |
|
8877 |
+
function factory($injector) {
|
8878 |
+
function makeInjectable(fn) {
|
8879 |
+
if (isFunction(fn) || isArray(fn)) {
|
8880 |
+
return /** @this */ function(tElement, tAttrs) {
|
8881 |
+
return $injector.invoke(fn, this, {$element: tElement, $attrs: tAttrs});
|
8882 |
+
};
|
8883 |
+
} else {
|
8884 |
+
return fn;
|
8885 |
+
}
|
8886 |
+
}
|
8887 |
|
8888 |
+
var template = (!options.template && !options.templateUrl ? '' : options.template);
|
8889 |
+
var ddo = {
|
8890 |
+
controller: controller,
|
8891 |
+
controllerAs: identifierForController(options.controller) || options.controllerAs || '$ctrl',
|
8892 |
+
template: makeInjectable(template),
|
8893 |
+
templateUrl: makeInjectable(options.templateUrl),
|
8894 |
+
transclude: options.transclude,
|
8895 |
+
scope: {},
|
8896 |
+
bindToController: options.bindings || {},
|
8897 |
+
restrict: 'E',
|
8898 |
+
require: options.require
|
8899 |
+
};
|
8900 |
|
8901 |
+
// Copy annotations (starting with $) over to the DDO
|
8902 |
+
forEach(options, function(val, key) {
|
8903 |
+
if (key.charAt(0) === '$') ddo[key] = val;
|
8904 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8905 |
|
8906 |
+
return ddo;
|
8907 |
+
}
|
8908 |
|
8909 |
+
// TODO(pete) remove the following `forEach` before we release 1.6.0
|
8910 |
+
// The component-router@0.2.0 looks for the annotations on the controller constructor
|
8911 |
+
// Nothing in AngularJS looks for annotations on the factory function but we can't remove
|
8912 |
+
// it from 1.5.x yet.
|
8913 |
|
8914 |
+
// Copy any annotation properties (starting with $) over to the factory and controller constructor functions
|
8915 |
+
// These could be used by libraries such as the new component router
|
8916 |
+
forEach(options, function(val, key) {
|
8917 |
+
if (key.charAt(0) === '$') {
|
8918 |
+
factory[key] = val;
|
8919 |
+
// Don't try to copy over annotations to named controller
|
8920 |
+
if (isFunction(controller)) controller[key] = val;
|
8921 |
+
}
|
8922 |
+
});
|
8923 |
|
8924 |
+
factory.$inject = ['$injector'];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8925 |
|
8926 |
+
return this.directive(name, factory);
|
8927 |
+
};
|
8928 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8929 |
|
8930 |
+
/**
|
8931 |
+
* @ngdoc method
|
8932 |
+
* @name $compileProvider#aHrefSanitizationWhitelist
|
8933 |
+
* @kind function
|
8934 |
+
*
|
8935 |
+
* @description
|
8936 |
+
* Retrieves or overrides the default regular expression that is used for whitelisting of safe
|
8937 |
+
* urls during a[href] sanitization.
|
8938 |
+
*
|
8939 |
+
* The sanitization is a security measure aimed at preventing XSS attacks via html links.
|
8940 |
+
*
|
8941 |
+
* Any url about to be assigned to a[href] via data-binding is first normalized and turned into
|
8942 |
+
* an absolute url. Afterwards, the url is matched against the `aHrefSanitizationWhitelist`
|
8943 |
+
* regular expression. If a match is found, the original url is written into the dom. Otherwise,
|
8944 |
+
* the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
|
8945 |
+
*
|
8946 |
+
* @param {RegExp=} regexp New regexp to whitelist urls with.
|
8947 |
+
* @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
|
8948 |
+
* chaining otherwise.
|
8949 |
+
*/
|
8950 |
+
this.aHrefSanitizationWhitelist = function(regexp) {
|
8951 |
+
if (isDefined(regexp)) {
|
8952 |
+
$$sanitizeUriProvider.aHrefSanitizationWhitelist(regexp);
|
8953 |
+
return this;
|
8954 |
+
} else {
|
8955 |
+
return $$sanitizeUriProvider.aHrefSanitizationWhitelist();
|
8956 |
+
}
|
8957 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8958 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8959 |
|
8960 |
+
/**
|
8961 |
+
* @ngdoc method
|
8962 |
+
* @name $compileProvider#imgSrcSanitizationWhitelist
|
8963 |
+
* @kind function
|
8964 |
+
*
|
8965 |
+
* @description
|
8966 |
+
* Retrieves or overrides the default regular expression that is used for whitelisting of safe
|
8967 |
+
* urls during img[src] sanitization.
|
8968 |
+
*
|
8969 |
+
* The sanitization is a security measure aimed at prevent XSS attacks via html links.
|
8970 |
+
*
|
8971 |
+
* Any url about to be assigned to img[src] via data-binding is first normalized and turned into
|
8972 |
+
* an absolute url. Afterwards, the url is matched against the `imgSrcSanitizationWhitelist`
|
8973 |
+
* regular expression. If a match is found, the original url is written into the dom. Otherwise,
|
8974 |
+
* the absolute url is prefixed with `'unsafe:'` string and only then is it written into the DOM.
|
8975 |
+
*
|
8976 |
+
* @param {RegExp=} regexp New regexp to whitelist urls with.
|
8977 |
+
* @returns {RegExp|ng.$compileProvider} Current RegExp if called without value or self for
|
8978 |
+
* chaining otherwise.
|
8979 |
+
*/
|
8980 |
+
this.imgSrcSanitizationWhitelist = function(regexp) {
|
8981 |
+
if (isDefined(regexp)) {
|
8982 |
+
$$sanitizeUriProvider.imgSrcSanitizationWhitelist(regexp);
|
8983 |
+
return this;
|
8984 |
+
} else {
|
8985 |
+
return $$sanitizeUriProvider.imgSrcSanitizationWhitelist();
|
8986 |
+
}
|
8987 |
+
};
|
8988 |
|
8989 |
+
/**
|
8990 |
+
* @ngdoc method
|
8991 |
+
* @name $compileProvider#debugInfoEnabled
|
8992 |
+
*
|
8993 |
+
* @param {boolean=} enabled update the debugInfoEnabled state if provided, otherwise just return the
|
8994 |
+
* current debugInfoEnabled state
|
8995 |
+
* @returns {*} current value if used as getter or itself (chaining) if used as setter
|
8996 |
+
*
|
8997 |
+
* @kind function
|
8998 |
+
*
|
8999 |
+
* @description
|
9000 |
+
* Call this method to enable/disable various debug runtime information in the compiler such as adding
|
9001 |
+
* binding information and a reference to the current scope on to DOM elements.
|
9002 |
+
* If enabled, the compiler will add the following to DOM elements that have been bound to the scope
|
9003 |
+
* * `ng-binding` CSS class
|
9004 |
+
* * `ng-scope` and `ng-isolated-scope` CSS classes
|
9005 |
+
* * `$binding` data property containing an array of the binding expressions
|
9006 |
+
* * Data properties used by the {@link angular.element#methods `scope()`/`isolateScope()` methods} to return
|
9007 |
+
* the element's scope.
|
9008 |
+
* * Placeholder comments will contain information about what directive and binding caused the placeholder.
|
9009 |
+
* E.g. `<!-- ngIf: shouldShow() -->`.
|
9010 |
+
*
|
9011 |
+
* You may want to disable this in production for a significant performance boost. See
|
9012 |
+
* {@link guide/production#disabling-debug-data Disabling Debug Data} for more.
|
9013 |
+
*
|
9014 |
+
* The default value is true.
|
9015 |
+
*/
|
9016 |
+
var debugInfoEnabled = true;
|
9017 |
+
this.debugInfoEnabled = function(enabled) {
|
9018 |
+
if (isDefined(enabled)) {
|
9019 |
+
debugInfoEnabled = enabled;
|
9020 |
+
return this;
|
9021 |
+
}
|
9022 |
+
return debugInfoEnabled;
|
9023 |
+
};
|
9024 |
+
|
9025 |
+
/**
|
9026 |
+
* @ngdoc method
|
9027 |
+
* @name $compileProvider#strictComponentBindingsEnabled
|
9028 |
+
*
|
9029 |
+
* @param {boolean=} enabled update the strictComponentBindingsEnabled state if provided,
|
9030 |
+
* otherwise return the current strictComponentBindingsEnabled state.
|
9031 |
+
* @returns {*} current value if used as getter or itself (chaining) if used as setter
|
9032 |
+
*
|
9033 |
+
* @kind function
|
9034 |
+
*
|
9035 |
+
* @description
|
9036 |
+
* Call this method to enable / disable the strict component bindings check. If enabled, the
|
9037 |
+
* compiler will enforce that all scope / controller bindings of a
|
9038 |
+
* {@link $compileProvider#directive directive} / {@link $compileProvider#component component}
|
9039 |
+
* that are not set as optional with `?`, must be provided when the directive is instantiated.
|
9040 |
+
* If not provided, the compiler will throw the
|
9041 |
+
* {@link error/$compile/missingattr $compile:missingattr error}.
|
9042 |
+
*
|
9043 |
+
* The default value is false.
|
9044 |
+
*/
|
9045 |
+
var strictComponentBindingsEnabled = false;
|
9046 |
+
this.strictComponentBindingsEnabled = function(enabled) {
|
9047 |
+
if (isDefined(enabled)) {
|
9048 |
+
strictComponentBindingsEnabled = enabled;
|
9049 |
+
return this;
|
9050 |
+
}
|
9051 |
+
return strictComponentBindingsEnabled;
|
9052 |
+
};
|
9053 |
+
|
9054 |
+
var TTL = 10;
|
9055 |
+
/**
|
9056 |
+
* @ngdoc method
|
9057 |
+
* @name $compileProvider#onChangesTtl
|
9058 |
+
* @description
|
9059 |
+
*
|
9060 |
+
* Sets the number of times `$onChanges` hooks can trigger new changes before giving up and
|
9061 |
+
* assuming that the model is unstable.
|
9062 |
+
*
|
9063 |
+
* The current default is 10 iterations.
|
9064 |
+
*
|
9065 |
+
* In complex applications it's possible that dependencies between `$onChanges` hooks and bindings will result
|
9066 |
+
* in several iterations of calls to these hooks. However if an application needs more than the default 10
|
9067 |
+
* iterations to stabilize then you should investigate what is causing the model to continuously change during
|
9068 |
+
* the `$onChanges` hook execution.
|
9069 |
+
*
|
9070 |
+
* Increasing the TTL could have performance implications, so you should not change it without proper justification.
|
9071 |
+
*
|
9072 |
+
* @param {number} limit The number of `$onChanges` hook iterations.
|
9073 |
+
* @returns {number|object} the current limit (or `this` if called as a setter for chaining)
|
9074 |
+
*/
|
9075 |
+
this.onChangesTtl = function(value) {
|
9076 |
+
if (arguments.length) {
|
9077 |
+
TTL = value;
|
9078 |
+
return this;
|
9079 |
+
}
|
9080 |
+
return TTL;
|
9081 |
+
};
|
9082 |
+
|
9083 |
+
var commentDirectivesEnabledConfig = true;
|
9084 |
+
/**
|
9085 |
+
* @ngdoc method
|
9086 |
+
* @name $compileProvider#commentDirectivesEnabled
|
9087 |
+
* @description
|
9088 |
+
*
|
9089 |
+
* It indicates to the compiler
|
9090 |
+
* whether or not directives on comments should be compiled.
|
9091 |
+
* Defaults to `true`.
|
9092 |
+
*
|
9093 |
+
* Calling this function with false disables the compilation of directives
|
9094 |
+
* on comments for the whole application.
|
9095 |
+
* This results in a compilation performance gain,
|
9096 |
+
* as the compiler doesn't have to check comments when looking for directives.
|
9097 |
+
* This should however only be used if you are sure that no comment directives are used in
|
9098 |
+
* the application (including any 3rd party directives).
|
9099 |
+
*
|
9100 |
+
* @param {boolean} enabled `false` if the compiler may ignore directives on comments
|
9101 |
+
* @returns {boolean|object} the current value (or `this` if called as a setter for chaining)
|
9102 |
+
*/
|
9103 |
+
this.commentDirectivesEnabled = function(value) {
|
9104 |
+
if (arguments.length) {
|
9105 |
+
commentDirectivesEnabledConfig = value;
|
9106 |
+
return this;
|
9107 |
+
}
|
9108 |
+
return commentDirectivesEnabledConfig;
|
9109 |
+
};
|
9110 |
|
9111 |
|
9112 |
+
var cssClassDirectivesEnabledConfig = true;
|
9113 |
+
/**
|
9114 |
+
* @ngdoc method
|
9115 |
+
* @name $compileProvider#cssClassDirectivesEnabled
|
9116 |
+
* @description
|
9117 |
+
*
|
9118 |
+
* It indicates to the compiler
|
9119 |
+
* whether or not directives on element classes should be compiled.
|
9120 |
+
* Defaults to `true`.
|
9121 |
+
*
|
9122 |
+
* Calling this function with false disables the compilation of directives
|
9123 |
+
* on element classes for the whole application.
|
9124 |
+
* This results in a compilation performance gain,
|
9125 |
+
* as the compiler doesn't have to check element classes when looking for directives.
|
9126 |
+
* This should however only be used if you are sure that no class directives are used in
|
9127 |
+
* the application (including any 3rd party directives).
|
9128 |
+
*
|
9129 |
+
* @param {boolean} enabled `false` if the compiler may ignore directives on element classes
|
9130 |
+
* @returns {boolean|object} the current value (or `this` if called as a setter for chaining)
|
9131 |
+
*/
|
9132 |
+
this.cssClassDirectivesEnabled = function(value) {
|
9133 |
+
if (arguments.length) {
|
9134 |
+
cssClassDirectivesEnabledConfig = value;
|
9135 |
+
return this;
|
9136 |
+
}
|
9137 |
+
return cssClassDirectivesEnabledConfig;
|
9138 |
+
};
|
9139 |
|
9140 |
|
9141 |
+
/**
|
9142 |
+
* The security context of DOM Properties.
|
9143 |
+
* @private
|
9144 |
+
*/
|
9145 |
+
var PROP_CONTEXTS = createMap();
|
9146 |
|
9147 |
+
/**
|
9148 |
+
* @ngdoc method
|
9149 |
+
* @name $compileProvider#addPropertySecurityContext
|
9150 |
+
* @description
|
9151 |
+
*
|
9152 |
+
* Defines the security context for DOM properties bound by ng-prop-*.
|
9153 |
+
*
|
9154 |
+
* @param {string} elementName The element name or '*' to match any element.
|
9155 |
+
* @param {string} propertyName The DOM property name.
|
9156 |
+
* @param {string} ctx The {@link $sce} security context in which this value is safe for use, e.g. `$sce.URL`
|
9157 |
+
* @returns {object} `this` for chaining
|
9158 |
+
*/
|
9159 |
+
this.addPropertySecurityContext = function(elementName, propertyName, ctx) {
|
9160 |
+
var key = (elementName.toLowerCase() + '|' + propertyName.toLowerCase());
|
9161 |
|
9162 |
+
if (key in PROP_CONTEXTS && PROP_CONTEXTS[key] !== ctx) {
|
9163 |
+
throw $compileMinErr('ctxoverride', 'Property context \'{0}.{1}\' already set to \'{2}\', cannot override to \'{3}\'.', elementName, propertyName, PROP_CONTEXTS[key], ctx);
|
9164 |
+
}
|
9165 |
|
9166 |
+
PROP_CONTEXTS[key] = ctx;
|
9167 |
+
return this;
|
9168 |
+
};
|
9169 |
|
9170 |
+
/* Default property contexts.
|
9171 |
*
|
9172 |
* Copy of https://github.com/angular/angular/blob/6.0.6/packages/compiler/src/schema/dom_security_schema.ts#L31-L58
|
9173 |
* Changing:
|
9176 |
* - various URL => MEDIA_URL
|
9177 |
* - *|formAction, form|action URL => RESOURCE_URL (like the attribute)
|
9178 |
*/
|
9179 |
+
(function registerNativePropertyContexts() {
|
9180 |
+
function registerContext(ctx, values) {
|
9181 |
+
forEach(values, function(v) { PROP_CONTEXTS[v.toLowerCase()] = ctx; });
|
9182 |
+
}
|
9183 |
+
|
9184 |
+
registerContext(SCE_CONTEXTS.HTML, [
|
9185 |
+
'iframe|srcdoc',
|
9186 |
+
'*|innerHTML',
|
9187 |
+
'*|outerHTML'
|
9188 |
+
]);
|
9189 |
+
registerContext(SCE_CONTEXTS.CSS, ['*|style']);
|
9190 |
+
registerContext(SCE_CONTEXTS.URL, [
|
9191 |
+
'area|href', 'area|ping',
|
9192 |
+
'a|href', 'a|ping',
|
9193 |
+
'blockquote|cite',
|
9194 |
+
'body|background',
|
9195 |
+
'del|cite',
|
9196 |
+
'input|src',
|
9197 |
+
'ins|cite',
|
9198 |
+
'q|cite'
|
9199 |
+
]);
|
9200 |
+
registerContext(SCE_CONTEXTS.MEDIA_URL, [
|
9201 |
+
'audio|src',
|
9202 |
+
'img|src', 'img|srcset',
|
9203 |
+
'source|src', 'source|srcset',
|
9204 |
+
'track|src',
|
9205 |
+
'video|src', 'video|poster'
|
9206 |
+
]);
|
9207 |
+
registerContext(SCE_CONTEXTS.RESOURCE_URL, [
|
9208 |
+
'*|formAction',
|
9209 |
+
'applet|code', 'applet|codebase',
|
9210 |
+
'base|href',
|
9211 |
+
'embed|src',
|
9212 |
+
'frame|src',
|
9213 |
+
'form|action',
|
9214 |
+
'head|profile',
|
9215 |
+
'html|manifest',
|
9216 |
+
'iframe|src',
|
9217 |
+
'link|href',
|
9218 |
+
'media|src',
|
9219 |
+
'object|codebase', 'object|data',
|
9220 |
+
'script|src'
|
9221 |
+
]);
|
9222 |
+
})();
|
9223 |
|
9224 |
+
|
9225 |
+
this.$get = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9226 |
'$injector', '$interpolate', '$exceptionHandler', '$templateRequest', '$parse',
|
9227 |
'$controller', '$rootScope', '$sce', '$animate',
|
9228 |
+
function($injector, $interpolate, $exceptionHandler, $templateRequest, $parse,
|
9229 |
+
$controller, $rootScope, $sce, $animate) {
|
9230 |
|
9231 |
+
var SIMPLE_ATTR_NAME = /^\w/;
|
9232 |
+
var specialAttrHolder = window.document.createElement('div');
|
9233 |
|
9234 |
|
9235 |
+
var commentDirectivesEnabled = commentDirectivesEnabledConfig;
|
9236 |
+
var cssClassDirectivesEnabled = cssClassDirectivesEnabledConfig;
|
9237 |
|
9238 |
|
9239 |
+
var onChangesTtl = TTL;
|
9240 |
+
// The onChanges hooks should all be run together in a single digest
|
9241 |
+
// When changes occur, the call to trigger their hooks will be added to this queue
|
9242 |
+
var onChangesQueue;
|
9243 |
|
9244 |
+
// This function is called in a $$postDigest to trigger all the onChanges hooks in a single digest
|
9245 |
+
function flushOnChangesQueue() {
|
9246 |
+
try {
|
9247 |
+
if (!(--onChangesTtl)) {
|
9248 |
+
// We have hit the TTL limit so reset everything
|
9249 |
+
onChangesQueue = undefined;
|
9250 |
+
throw $compileMinErr('infchng', '{0} $onChanges() iterations reached. Aborting!\n', TTL);
|
9251 |
+
}
|
9252 |
+
// We must run this hook in an apply since the $$postDigest runs outside apply
|
9253 |
+
$rootScope.$apply(function() {
|
9254 |
+
for (var i = 0, ii = onChangesQueue.length; i < ii; ++i) {
|
9255 |
+
try {
|
9256 |
+
onChangesQueue[i]();
|
9257 |
+
} catch (e) {
|
9258 |
+
$exceptionHandler(e);
|
9259 |
+
}
|
9260 |
+
}
|
9261 |
+
// Reset the queue to trigger a new schedule next time there is a change
|
9262 |
+
onChangesQueue = undefined;
|
9263 |
+
});
|
9264 |
+
} finally {
|
9265 |
+
onChangesTtl++;
|
9266 |
+
}
|
9267 |
+
}
|
9268 |
|
9269 |
|
9270 |
+
function sanitizeSrcset(value, invokeType) {
|
9271 |
+
if (!value) {
|
9272 |
+
return value;
|
9273 |
+
}
|
9274 |
+
if (!isString(value)) {
|
9275 |
+
throw $compileMinErr('srcset', 'Can\'t pass trusted values to `{0}`: "{1}"', invokeType, value.toString());
|
9276 |
+
}
|
9277 |
|
9278 |
+
// Such values are a bit too complex to handle automatically inside $sce.
|
9279 |
+
// Instead, we sanitize each of the URIs individually, which works, even dynamically.
|
9280 |
+
|
9281 |
+
// It's not possible to work around this using `$sce.trustAsMediaUrl`.
|
9282 |
+
// If you want to programmatically set explicitly trusted unsafe URLs, you should use
|
9283 |
+
// `$sce.trustAsHtml` on the whole `img` tag and inject it into the DOM using the
|
9284 |
+
// `ng-bind-html` directive.
|
9285 |
+
|
9286 |
+
var result = '';
|
9287 |
+
|
9288 |
+
// first check if there are spaces because it's not the same pattern
|
9289 |
+
var trimmedSrcset = trim(value);
|
9290 |
+
// ( 999x ,| 999w ,| ,|, )
|
9291 |
+
var srcPattern = /(\s+\d+x\s*,|\s+\d+w\s*,|\s+,|,\s+)/;
|
9292 |
+
var pattern = /\s/.test(trimmedSrcset) ? srcPattern : /(,)/;
|
9293 |
+
|
9294 |
+
// split srcset into tuple of uri and descriptor except for the last item
|
9295 |
+
var rawUris = trimmedSrcset.split(pattern);
|
9296 |
+
|
9297 |
+
// for each tuples
|
9298 |
+
var nbrUrisWith2parts = Math.floor(rawUris.length / 2);
|
9299 |
+
for (var i = 0; i < nbrUrisWith2parts; i++) {
|
9300 |
+
var innerIdx = i * 2;
|
9301 |
+
// sanitize the uri
|
9302 |
+
result += $sce.getTrustedMediaUrl(trim(rawUris[innerIdx]));
|
9303 |
+
// add the descriptor
|
9304 |
+
result += ' ' + trim(rawUris[innerIdx + 1]);
|
9305 |
+
}
|
9306 |
|
9307 |
+
// split the last item into uri and descriptor
|
9308 |
+
var lastTuple = trim(rawUris[i * 2]).split(/\s/);
|
9309 |
|
9310 |
+
// sanitize the last uri
|
9311 |
+
result += $sce.getTrustedMediaUrl(trim(lastTuple[0]));
|
9312 |
|
9313 |
+
// and add the last descriptor if any
|
9314 |
+
if (lastTuple.length === 2) {
|
9315 |
+
result += (' ' + trim(lastTuple[1]));
|
9316 |
+
}
|
9317 |
+
return result;
|
9318 |
+
}
|
9319 |
|
9320 |
|
9321 |
+
function Attributes(element, attributesToCopy) {
|
9322 |
+
if (attributesToCopy) {
|
9323 |
+
var keys = Object.keys(attributesToCopy);
|
9324 |
+
var i, l, key;
|
9325 |
|
9326 |
+
for (i = 0, l = keys.length; i < l; i++) {
|
9327 |
+
key = keys[i];
|
9328 |
+
this[key] = attributesToCopy[key];
|
9329 |
+
}
|
9330 |
+
} else {
|
9331 |
+
this.$attr = {};
|
9332 |
+
}
|
9333 |
|
9334 |
+
this.$$element = element;
|
9335 |
+
}
|
9336 |
|
9337 |
+
Attributes.prototype = {
|
9338 |
+
/**
|
9339 |
+
* @ngdoc method
|
9340 |
+
* @name $compile.directive.Attributes#$normalize
|
9341 |
+
* @kind function
|
9342 |
+
*
|
9343 |
+
* @description
|
9344 |
+
* Converts an attribute name (e.g. dash/colon/underscore-delimited string, optionally prefixed with `x-` or
|
9345 |
+
* `data-`) to its normalized, camelCase form.
|
9346 |
+
*
|
9347 |
+
* Also there is special case for Moz prefix starting with upper case letter.
|
9348 |
+
*
|
9349 |
+
* For further information check out the guide on {@link guide/directive#matching-directives Matching Directives}
|
9350 |
+
*
|
9351 |
+
* @param {string} name Name to normalize
|
9352 |
+
*/
|
9353 |
+
$normalize: directiveNormalize,
|
9354 |
|
9355 |
|
9356 |
+
/**
|
9357 |
+
* @ngdoc method
|
9358 |
+
* @name $compile.directive.Attributes#$addClass
|
9359 |
+
* @kind function
|
9360 |
+
*
|
9361 |
+
* @description
|
9362 |
+
* Adds the CSS class value specified by the classVal parameter to the element. If animations
|
9363 |
+
* are enabled then an animation will be triggered for the class addition.
|
9364 |
+
*
|
9365 |
+
* @param {string} classVal The className value that will be added to the element
|
9366 |
+
*/
|
9367 |
+
$addClass: function(classVal) {
|
9368 |
+
if (classVal && classVal.length > 0) {
|
9369 |
+
$animate.addClass(this.$$element, classVal);
|
9370 |
+
}
|
9371 |
+
},
|
9372 |
|
9373 |
+
/**
|
9374 |
+
* @ngdoc method
|
9375 |
+
* @name $compile.directive.Attributes#$removeClass
|
9376 |
+
* @kind function
|
9377 |
+
*
|
9378 |
+
* @description
|
9379 |
+
* Removes the CSS class value specified by the classVal parameter from the element. If
|
9380 |
+
* animations are enabled then an animation will be triggered for the class removal.
|
9381 |
+
*
|
9382 |
+
* @param {string} classVal The className value that will be removed from the element
|
9383 |
+
*/
|
9384 |
+
$removeClass: function(classVal) {
|
9385 |
+
if (classVal && classVal.length > 0) {
|
9386 |
+
$animate.removeClass(this.$$element, classVal);
|
9387 |
+
}
|
9388 |
+
},
|
9389 |
|
9390 |
+
/**
|
9391 |
+
* @ngdoc method
|
9392 |
+
* @name $compile.directive.Attributes#$updateClass
|
9393 |
+
* @kind function
|
9394 |
+
*
|
9395 |
+
* @description
|
9396 |
+
* Adds and removes the appropriate CSS class values to the element based on the difference
|
9397 |
+
* between the new and old CSS class values (specified as newClasses and oldClasses).
|
9398 |
+
*
|
9399 |
+
* @param {string} newClasses The current CSS className value
|
9400 |
+
* @param {string} oldClasses The former CSS className value
|
9401 |
+
*/
|
9402 |
+
$updateClass: function(newClasses, oldClasses) {
|
9403 |
+
var toAdd = tokenDifference(newClasses, oldClasses);
|
9404 |
+
if (toAdd && toAdd.length) {
|
9405 |
+
$animate.addClass(this.$$element, toAdd);
|
9406 |
+
}
|
9407 |
|
9408 |
+
var toRemove = tokenDifference(oldClasses, newClasses);
|
9409 |
+
if (toRemove && toRemove.length) {
|
9410 |
+
$animate.removeClass(this.$$element, toRemove);
|
9411 |
+
}
|
9412 |
+
},
|
9413 |
|
9414 |
+
/**
|
9415 |
+
* Set a normalized attribute on the element in a way such that all directives
|
9416 |
+
* can share the attribute. This function properly handles boolean attributes.
|
9417 |
+
* @param {string} key Normalized key. (ie ngAttribute)
|
9418 |
+
* @param {string|boolean} value The value to set. If `null` attribute will be deleted.
|
9419 |
+
* @param {boolean=} writeAttr If false, does not write the value to DOM element attribute.
|
9420 |
+
* Defaults to true.
|
9421 |
+
* @param {string=} attrName Optional none normalized name. Defaults to key.
|
9422 |
+
*/
|
9423 |
+
$set: function(key, value, writeAttr, attrName) {
|
9424 |
+
// TODO: decide whether or not to throw an error if "class"
|
9425 |
+
// is set through this function since it may cause $updateClass to
|
9426 |
+
// become unstable.
|
9427 |
+
|
9428 |
+
var node = this.$$element[0],
|
9429 |
+
booleanKey = getBooleanAttrName(node, key),
|
9430 |
+
aliasedKey = getAliasedAttrName(key),
|
9431 |
+
observer = key,
|
9432 |
+
nodeName;
|
9433 |
+
|
9434 |
+
if (booleanKey) {
|
9435 |
+
this.$$element.prop(key, value);
|
9436 |
+
attrName = booleanKey;
|
9437 |
+
} else if (aliasedKey) {
|
9438 |
+
this[aliasedKey] = value;
|
9439 |
+
observer = aliasedKey;
|
9440 |
+
}
|
9441 |
+
|
9442 |
+
this[key] = value;
|
9443 |
+
|
9444 |
+
// translate normalized key to actual key
|
9445 |
+
if (attrName) {
|
9446 |
+
this.$attr[key] = attrName;
|
9447 |
+
} else {
|
9448 |
+
attrName = this.$attr[key];
|
9449 |
+
if (!attrName) {
|
9450 |
+
this.$attr[key] = attrName = snake_case(key, '-');
|
9451 |
+
}
|
9452 |
+
}
|
9453 |
|
9454 |
+
nodeName = nodeName_(this.$$element);
|
9455 |
|
9456 |
+
// Sanitize img[srcset] values.
|
9457 |
+
if (nodeName === 'img' && key === 'srcset') {
|
9458 |
+
this[key] = value = sanitizeSrcset(value, '$set(\'srcset\', value)');
|
9459 |
+
}
|
|
|
|
|
|
|
|
|
|
|
9460 |
|
9461 |
+
if (writeAttr !== false) {
|
9462 |
+
if (value === null || isUndefined(value)) {
|
9463 |
+
this.$$element.removeAttr(attrName);
|
9464 |
+
} else {
|
9465 |
+
if (SIMPLE_ATTR_NAME.test(attrName)) {
|
9466 |
+
// jQuery skips special boolean attrs treatment in XML nodes for
|
9467 |
+
// historical reasons and hence AngularJS cannot freely call
|
9468 |
+
// `.attr(attrName, false) with such attributes. To avoid issues
|
9469 |
+
// in XHTML, call `removeAttr` in such cases instead.
|
9470 |
+
// See https://github.com/jquery/jquery/issues/4249
|
9471 |
+
if (booleanKey && value === false) {
|
9472 |
+
this.$$element.removeAttr(attrName);
|
9473 |
+
} else {
|
9474 |
+
this.$$element.attr(attrName, value);
|
9475 |
+
}
|
9476 |
+
} else {
|
9477 |
+
setSpecialAttr(this.$$element[0], attrName, value);
|
9478 |
+
}
|
9479 |
+
}
|
9480 |
+
}
|
9481 |
|
9482 |
+
// fire observers
|
9483 |
+
var $$observers = this.$$observers;
|
9484 |
+
if ($$observers) {
|
9485 |
+
forEach($$observers[observer], function(fn) {
|
9486 |
+
try {
|
9487 |
+
fn(value);
|
9488 |
+
} catch (e) {
|
9489 |
+
$exceptionHandler(e);
|
9490 |
+
}
|
9491 |
+
});
|
9492 |
+
}
|
9493 |
+
},
|
9494 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9495 |
|
9496 |
+
/**
|
9497 |
+
* @ngdoc method
|
9498 |
+
* @name $compile.directive.Attributes#$observe
|
9499 |
+
* @kind function
|
9500 |
+
*
|
9501 |
+
* @description
|
9502 |
+
* Observes an interpolated attribute.
|
9503 |
+
*
|
9504 |
+
* The observer function will be invoked once during the next `$digest` following
|
9505 |
+
* compilation. The observer is then invoked whenever the interpolated value
|
9506 |
+
* changes.
|
9507 |
+
*
|
9508 |
+
* @param {string} key Normalized key. (ie ngAttribute) .
|
9509 |
+
* @param {function(interpolatedValue)} fn Function that will be called whenever
|
9510 |
+
the interpolated value of the attribute changes.
|
9511 |
+
* See the {@link guide/interpolation#how-text-and-attribute-bindings-work Interpolation
|
9512 |
+
* guide} for more info.
|
9513 |
+
* @returns {function()} Returns a deregistration function for this observer.
|
9514 |
+
*/
|
9515 |
+
$observe: function(key, fn) {
|
9516 |
+
var attrs = this,
|
9517 |
+
$$observers = (attrs.$$observers || (attrs.$$observers = createMap())),
|
9518 |
+
listeners = ($$observers[key] || ($$observers[key] = []));
|
9519 |
+
|
9520 |
+
listeners.push(fn);
|
9521 |
+
$rootScope.$evalAsync(function() {
|
9522 |
+
if (!listeners.$$inter && attrs.hasOwnProperty(key) && !isUndefined(attrs[key])) {
|
9523 |
+
// no one registered attribute interpolation function, so lets call it manually
|
9524 |
+
fn(attrs[key]);
|
9525 |
+
}
|
9526 |
+
});
|
9527 |
|
9528 |
+
return function() {
|
9529 |
+
arrayRemove(listeners, fn);
|
9530 |
+
};
|
9531 |
+
}
|
9532 |
+
};
|
9533 |
|
9534 |
+
function setSpecialAttr(element, attrName, value) {
|
9535 |
+
// Attributes names that do not start with letters (such as `(click)`) cannot be set using `setAttribute`
|
9536 |
+
// so we have to jump through some hoops to get such an attribute
|
9537 |
+
// https://github.com/angular/angular.js/pull/13318
|
9538 |
+
specialAttrHolder.innerHTML = '<span ' + attrName + '>';
|
9539 |
+
var attributes = specialAttrHolder.firstChild.attributes;
|
9540 |
+
var attribute = attributes[0];
|
9541 |
+
// We have to remove the attribute from its container element before we can add it to the destination element
|
9542 |
+
attributes.removeNamedItem(attribute.name);
|
9543 |
+
attribute.value = value;
|
9544 |
+
element.attributes.setNamedItem(attribute);
|
9545 |
+
}
|
9546 |
+
|
9547 |
+
function safeAddClass($element, className) {
|
9548 |
+
try {
|
9549 |
+
$element.addClass(className);
|
9550 |
+
} catch (e) {
|
9551 |
+
// ignore, since it means that we are trying to set class on
|
9552 |
+
// SVG element, where class name is read-only.
|
9553 |
+
}
|
9554 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9555 |
|
|
|
|
|
|
|
|
|
|
|
9556 |
|
9557 |
+
var startSymbol = $interpolate.startSymbol(),
|
9558 |
+
endSymbol = $interpolate.endSymbol(),
|
9559 |
+
denormalizeTemplate = (startSymbol === '{{' && endSymbol === '}}')
|
9560 |
+
? identity
|
9561 |
+
: function denormalizeTemplate(template) {
|
9562 |
+
return template.replace(/\{\{/g, startSymbol).replace(/}}/g, endSymbol);
|
9563 |
+
},
|
9564 |
+
NG_PREFIX_BINDING = /^ng(Attr|Prop|On)([A-Z].*)$/;
|
9565 |
+
var MULTI_ELEMENT_DIR_RE = /^(.+)Start$/;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9566 |
|
9567 |
+
compile.$$addBindingInfo = debugInfoEnabled ? function $$addBindingInfo($element, binding) {
|
9568 |
+
var bindings = $element.data('$binding') || [];
|
9569 |
|
9570 |
+
if (isArray(binding)) {
|
9571 |
+
bindings = bindings.concat(binding);
|
9572 |
+
} else {
|
9573 |
+
bindings.push(binding);
|
9574 |
+
}
|
|
|
|
|
|
|
|
|
9575 |
|
9576 |
+
$element.data('$binding', bindings);
|
9577 |
+
} : noop;
|
9578 |
|
9579 |
+
compile.$$addBindingClass = debugInfoEnabled ? function $$addBindingClass($element) {
|
9580 |
+
safeAddClass($element, 'ng-binding');
|
9581 |
+
} : noop;
|
|
|
|
|
9582 |
|
9583 |
+
compile.$$addScopeInfo = debugInfoEnabled ? function $$addScopeInfo($element, scope, isolated, noTemplate) {
|
9584 |
+
var dataName = isolated ? (noTemplate ? '$isolateScopeNoTemplate' : '$isolateScope') : '$scope';
|
9585 |
+
$element.data(dataName, scope);
|
9586 |
+
} : noop;
|
9587 |
|
9588 |
+
compile.$$addScopeClass = debugInfoEnabled ? function $$addScopeClass($element, isolated) {
|
9589 |
+
safeAddClass($element, isolated ? 'ng-isolate-scope' : 'ng-scope');
|
9590 |
+
} : noop;
|
9591 |
|
9592 |
+
compile.$$createComment = function(directiveName, comment) {
|
9593 |
+
var content = '';
|
9594 |
+
if (debugInfoEnabled) {
|
9595 |
+
content = ' ' + (directiveName || '') + ': ';
|
9596 |
+
if (comment) content += comment + ' ';
|
9597 |
+
}
|
9598 |
+
return window.document.createComment(content);
|
9599 |
+
};
|
9600 |
|
9601 |
+
return compile;
|
|
|
|
|
9602 |
|
9603 |
+
//================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9604 |
|
9605 |
+
function compile($compileNodes, transcludeFn, maxPriority, ignoreDirective,
|
9606 |
+
previousCompileContext) {
|
9607 |
+
if (!($compileNodes instanceof jqLite)) {
|
9608 |
+
// jquery always rewraps, whereas we need to preserve the original selector so that we can
|
9609 |
+
// modify it.
|
9610 |
+
$compileNodes = jqLite($compileNodes);
|
9611 |
+
}
|
9612 |
+
var compositeLinkFn =
|
9613 |
+
compileNodes($compileNodes, transcludeFn, $compileNodes,
|
9614 |
+
maxPriority, ignoreDirective, previousCompileContext);
|
9615 |
+
compile.$$addScopeClass($compileNodes);
|
9616 |
+
var namespace = null;
|
9617 |
+
return function publicLinkFn(scope, cloneConnectFn, options) {
|
9618 |
+
if (!$compileNodes) {
|
9619 |
+
throw $compileMinErr('multilink', 'This element has already been linked.');
|
9620 |
+
}
|
9621 |
+
assertArg(scope, 'scope');
|
9622 |
|
9623 |
+
if (previousCompileContext && previousCompileContext.needsNewScope) {
|
9624 |
+
// A parent directive did a replace and a directive on this element asked
|
9625 |
+
// for transclusion, which caused us to lose a layer of element on which
|
9626 |
+
// we could hold the new transclusion scope, so we will create it manually
|
9627 |
+
// here.
|
9628 |
+
scope = scope.$parent.$new();
|
9629 |
+
}
|
9630 |
|
9631 |
+
options = options || {};
|
9632 |
+
var parentBoundTranscludeFn = options.parentBoundTranscludeFn,
|
9633 |
+
transcludeControllers = options.transcludeControllers,
|
9634 |
+
futureParentElement = options.futureParentElement;
|
9635 |
+
|
9636 |
+
// When `parentBoundTranscludeFn` is passed, it is a
|
9637 |
+
// `controllersBoundTransclude` function (it was previously passed
|
9638 |
+
// as `transclude` to directive.link) so we must unwrap it to get
|
9639 |
+
// its `boundTranscludeFn`
|
9640 |
+
if (parentBoundTranscludeFn && parentBoundTranscludeFn.$$boundTransclude) {
|
9641 |
+
parentBoundTranscludeFn = parentBoundTranscludeFn.$$boundTransclude;
|
9642 |
+
}
|
9643 |
+
|
9644 |
+
if (!namespace) {
|
9645 |
+
namespace = detectNamespaceForChildElements(futureParentElement);
|
9646 |
+
}
|
9647 |
+
var $linkNode;
|
9648 |
+
if (namespace !== 'html') {
|
9649 |
+
// When using a directive with replace:true and templateUrl the $compileNodes
|
9650 |
+
// (or a child element inside of them)
|
9651 |
+
// might change, so we need to recreate the namespace adapted compileNodes
|
9652 |
+
// for call to the link function.
|
9653 |
+
// Note: This will already clone the nodes...
|
9654 |
+
$linkNode = jqLite(
|
9655 |
+
wrapTemplate(namespace, jqLite('<div></div>').append($compileNodes).html())
|
9656 |
+
);
|
9657 |
+
} else if (cloneConnectFn) {
|
9658 |
+
// important!!: we must call our jqLite.clone() since the jQuery one is trying to be smart
|
9659 |
+
// and sometimes changes the structure of the DOM.
|
9660 |
+
$linkNode = JQLitePrototype.clone.call($compileNodes);
|
9661 |
+
} else {
|
9662 |
+
$linkNode = $compileNodes;
|
9663 |
+
}
|
9664 |
|
9665 |
+
if (transcludeControllers) {
|
9666 |
+
for (var controllerName in transcludeControllers) {
|
9667 |
+
$linkNode.data('$' + controllerName + 'Controller', transcludeControllers[controllerName].instance);
|
9668 |
+
}
|
9669 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9670 |
|
9671 |
+
compile.$$addScopeInfo($linkNode, scope);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9672 |
|
9673 |
+
if (cloneConnectFn) cloneConnectFn($linkNode, scope);
|
9674 |
+
if (compositeLinkFn) compositeLinkFn(scope, $linkNode, $linkNode, parentBoundTranscludeFn);
|
|
|
|
|
|
|
9675 |
|
9676 |
+
if (!cloneConnectFn) {
|
9677 |
+
$compileNodes = compositeLinkFn = null;
|
9678 |
+
}
|
9679 |
+
return $linkNode;
|
9680 |
+
};
|
9681 |
+
}
|
9682 |
|
9683 |
+
function detectNamespaceForChildElements(parentElement) {
|
9684 |
+
// TODO: Make this detect MathML as well...
|
9685 |
+
var node = parentElement && parentElement[0];
|
9686 |
+
if (!node) {
|
9687 |
+
return 'html';
|
9688 |
+
} else {
|
9689 |
+
return nodeName_(node) !== 'foreignobject' && toString.call(node).match(/SVG/) ? 'svg' : 'html';
|
9690 |
+
}
|
9691 |
+
}
|
9692 |
|
9693 |
+
/**
|
9694 |
+
* Compile function matches each node in nodeList against the directives. Once all directives
|
9695 |
+
* for a particular node are collected their compile functions are executed. The compile
|
9696 |
+
* functions return values - the linking functions - are combined into a composite linking
|
9697 |
+
* function, which is the a linking function for the node.
|
9698 |
+
*
|
9699 |
+
* @param {NodeList} nodeList an array of nodes or NodeList to compile
|
9700 |
+
* @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
|
9701 |
+
* scope argument is auto-generated to the new child of the transcluded parent scope.
|
9702 |
+
* @param {DOMElement=} $rootElement If the nodeList is the root of the compilation tree then
|
9703 |
+
* the rootElement must be set the jqLite collection of the compile root. This is
|
9704 |
+
* needed so that the jqLite collection items can be replaced with widgets.
|
9705 |
+
* @param {number=} maxPriority Max directive priority.
|
9706 |
+
* @returns {Function} A composite linking function of all of the matched directives or null.
|
9707 |
+
*/
|
9708 |
+
function compileNodes(nodeList, transcludeFn, $rootElement, maxPriority, ignoreDirective,
|
9709 |
+
previousCompileContext) {
|
9710 |
+
var linkFns = [],
|
9711 |
+
// `nodeList` can be either an element's `.childNodes` (live NodeList)
|
9712 |
+
// or a jqLite/jQuery collection or an array
|
9713 |
+
notLiveList = isArray(nodeList) || (nodeList instanceof jqLite),
|
9714 |
+
attrs, directives, nodeLinkFn, childNodes, childLinkFn, linkFnFound, nodeLinkFnFound;
|
9715 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9716 |
|
9717 |
+
for (var i = 0; i < nodeList.length; i++) {
|
9718 |
+
attrs = new Attributes();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9719 |
|
9720 |
+
// Support: IE 11 only
|
9721 |
+
// Workaround for #11781 and #14924
|
9722 |
+
if (msie === 11) {
|
9723 |
+
mergeConsecutiveTextNodes(nodeList, i, notLiveList);
|
9724 |
+
}
|
9725 |
|
9726 |
+
// We must always refer to `nodeList[i]` hereafter,
|
9727 |
+
// since the nodes can be replaced underneath us.
|
9728 |
+
directives = collectDirectives(nodeList[i], [], attrs, i === 0 ? maxPriority : undefined,
|
9729 |
+
ignoreDirective);
|
9730 |
|
9731 |
+
nodeLinkFn = (directives.length)
|
9732 |
+
? applyDirectivesToNode(directives, nodeList[i], attrs, transcludeFn, $rootElement,
|
9733 |
+
null, [], [], previousCompileContext)
|
9734 |
+
: null;
|
9735 |
|
9736 |
+
if (nodeLinkFn && nodeLinkFn.scope) {
|
9737 |
+
compile.$$addScopeClass(attrs.$$element);
|
9738 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9739 |
|
9740 |
+
childLinkFn = (nodeLinkFn && nodeLinkFn.terminal ||
|
9741 |
+
!(childNodes = nodeList[i].childNodes) ||
|
9742 |
+
!childNodes.length)
|
9743 |
+
? null
|
9744 |
+
: compileNodes(childNodes,
|
9745 |
+
nodeLinkFn ? (
|
9746 |
+
(nodeLinkFn.transcludeOnThisElement || !nodeLinkFn.templateOnThisElement)
|
9747 |
+
&& nodeLinkFn.transclude) : transcludeFn);
|
9748 |
|
9749 |
+
if (nodeLinkFn || childLinkFn) {
|
9750 |
+
linkFns.push(i, nodeLinkFn, childLinkFn);
|
9751 |
+
linkFnFound = true;
|
9752 |
+
nodeLinkFnFound = nodeLinkFnFound || nodeLinkFn;
|
9753 |
+
}
|
9754 |
|
9755 |
+
//use the previous context only for the first element in the virtual group
|
9756 |
+
previousCompileContext = null;
|
9757 |
+
}
|
9758 |
|
9759 |
+
// return a linking function if we have found anything, null otherwise
|
9760 |
+
return linkFnFound ? compositeLinkFn : null;
|
9761 |
|
9762 |
+
function compositeLinkFn(scope, nodeList, $rootElement, parentBoundTranscludeFn) {
|
9763 |
+
var nodeLinkFn, childLinkFn, node, childScope, i, ii, idx, childBoundTranscludeFn;
|
9764 |
+
var stableNodeList;
|
|
|
|
|
9765 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9766 |
|
9767 |
+
if (nodeLinkFnFound) {
|
9768 |
+
// copy nodeList so that if a nodeLinkFn removes or adds an element at this DOM level our
|
9769 |
+
// offsets don't get screwed up
|
9770 |
+
var nodeListLength = nodeList.length;
|
9771 |
+
stableNodeList = new Array(nodeListLength);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9772 |
|
9773 |
+
// create a sparse array by only copying the elements which have a linkFn
|
9774 |
+
for (i = 0; i < linkFns.length; i += 3) {
|
9775 |
+
idx = linkFns[i];
|
9776 |
+
stableNodeList[idx] = nodeList[idx];
|
9777 |
+
}
|
9778 |
+
} else {
|
9779 |
+
stableNodeList = nodeList;
|
9780 |
+
}
|
9781 |
|
9782 |
+
for (i = 0, ii = linkFns.length; i < ii;) {
|
9783 |
+
node = stableNodeList[linkFns[i++]];
|
9784 |
+
nodeLinkFn = linkFns[i++];
|
9785 |
+
childLinkFn = linkFns[i++];
|
9786 |
|
9787 |
+
if (nodeLinkFn) {
|
9788 |
+
if (nodeLinkFn.scope) {
|
9789 |
+
childScope = scope.$new();
|
9790 |
+
compile.$$addScopeInfo(jqLite(node), childScope);
|
9791 |
+
} else {
|
9792 |
+
childScope = scope;
|
9793 |
+
}
|
9794 |
|
9795 |
+
if (nodeLinkFn.transcludeOnThisElement) {
|
9796 |
+
childBoundTranscludeFn = createBoundTranscludeFn(
|
9797 |
+
scope, nodeLinkFn.transclude, parentBoundTranscludeFn);
|
9798 |
|
9799 |
+
} else if (!nodeLinkFn.templateOnThisElement && parentBoundTranscludeFn) {
|
9800 |
+
childBoundTranscludeFn = parentBoundTranscludeFn;
|
9801 |
|
9802 |
+
} else if (!parentBoundTranscludeFn && transcludeFn) {
|
9803 |
+
childBoundTranscludeFn = createBoundTranscludeFn(scope, transcludeFn);
|
|
|
|
|
|
|
|
|
9804 |
|
9805 |
+
} else {
|
9806 |
+
childBoundTranscludeFn = null;
|
9807 |
+
}
|
|
|
9808 |
|
9809 |
+
nodeLinkFn(childLinkFn, childScope, node, $rootElement, childBoundTranscludeFn);
|
|
|
|
|
9810 |
|
9811 |
+
} else if (childLinkFn) {
|
9812 |
+
childLinkFn(scope, node.childNodes, undefined, parentBoundTranscludeFn);
|
9813 |
+
}
|
9814 |
+
}
|
9815 |
+
}
|
9816 |
+
}
|
9817 |
|
9818 |
+
function mergeConsecutiveTextNodes(nodeList, idx, notLiveList) {
|
9819 |
+
var node = nodeList[idx];
|
9820 |
+
var parent = node.parentNode;
|
9821 |
+
var sibling;
|
9822 |
|
9823 |
+
if (node.nodeType !== NODE_TYPE_TEXT) {
|
9824 |
+
return;
|
9825 |
+
}
|
|
|
|
|
|
|
|
|
|
|
9826 |
|
9827 |
+
while (true) {
|
9828 |
+
sibling = parent ? node.nextSibling : nodeList[idx + 1];
|
9829 |
+
if (!sibling || sibling.nodeType !== NODE_TYPE_TEXT) {
|
9830 |
+
break;
|
9831 |
+
}
|
9832 |
|
9833 |
+
node.nodeValue = node.nodeValue + sibling.nodeValue;
|
|
|
|
|
|
|
9834 |
|
9835 |
+
if (sibling.parentNode) {
|
9836 |
+
sibling.parentNode.removeChild(sibling);
|
9837 |
+
}
|
9838 |
+
if (notLiveList && sibling === nodeList[idx + 1]) {
|
9839 |
+
nodeList.splice(idx + 1, 1);
|
9840 |
+
}
|
9841 |
+
}
|
9842 |
+
}
|
9843 |
|
9844 |
+
function createBoundTranscludeFn(scope, transcludeFn, previousBoundTranscludeFn) {
|
9845 |
+
function boundTranscludeFn(transcludedScope, cloneFn, controllers, futureParentElement, containingScope) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9846 |
|
9847 |
+
if (!transcludedScope) {
|
9848 |
+
transcludedScope = scope.$new(false, containingScope);
|
9849 |
+
transcludedScope.$$transcluded = true;
|
9850 |
+
}
|
9851 |
|
9852 |
+
return transcludeFn(transcludedScope, cloneFn, {
|
9853 |
+
parentBoundTranscludeFn: previousBoundTranscludeFn,
|
9854 |
+
transcludeControllers: controllers,
|
9855 |
+
futureParentElement: futureParentElement
|
9856 |
+
});
|
9857 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9858 |
|
9859 |
+
// We need to attach the transclusion slots onto the `boundTranscludeFn`
|
9860 |
+
// so that they are available inside the `controllersBoundTransclude` function
|
9861 |
+
var boundSlots = boundTranscludeFn.$$slots = createMap();
|
9862 |
+
for (var slotName in transcludeFn.$$slots) {
|
9863 |
+
if (transcludeFn.$$slots[slotName]) {
|
9864 |
+
boundSlots[slotName] = createBoundTranscludeFn(scope, transcludeFn.$$slots[slotName], previousBoundTranscludeFn);
|
9865 |
+
} else {
|
9866 |
+
boundSlots[slotName] = null;
|
9867 |
+
}
|
9868 |
+
}
|
9869 |
|
9870 |
+
return boundTranscludeFn;
|
9871 |
+
}
|
|
|
9872 |
|
9873 |
+
/**
|
9874 |
+
* Looks for directives on the given node and adds them to the directive collection which is
|
9875 |
+
* sorted.
|
9876 |
+
*
|
9877 |
+
* @param node Node to search.
|
9878 |
+
* @param directives An array to which the directives are added to. This array is sorted before
|
9879 |
+
* the function returns.
|
9880 |
+
* @param attrs The shared attrs object which is used to populate the normalized attributes.
|
9881 |
+
* @param {number=} maxPriority Max directive priority.
|
9882 |
+
*/
|
9883 |
+
function collectDirectives(node, directives, attrs, maxPriority, ignoreDirective) {
|
9884 |
+
var nodeType = node.nodeType,
|
9885 |
+
attrsMap = attrs.$attr,
|
9886 |
+
match,
|
9887 |
+
nodeName,
|
9888 |
+
className;
|
9889 |
+
|
9890 |
+
switch (nodeType) {
|
9891 |
+
case NODE_TYPE_ELEMENT: /* Element */
|
9892 |
+
|
9893 |
+
nodeName = nodeName_(node);
|
9894 |
+
|
9895 |
+
// use the node name: <directive>
|
9896 |
+
addDirective(directives,
|
9897 |
+
directiveNormalize(nodeName), 'E', maxPriority, ignoreDirective);
|
9898 |
+
|
9899 |
+
// iterate over the attributes
|
9900 |
+
for (var attr, name, nName, value, ngPrefixMatch, nAttrs = node.attributes,
|
9901 |
+
j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {
|
9902 |
+
var attrStartName = false;
|
9903 |
+
var attrEndName = false;
|
9904 |
+
|
9905 |
+
var isNgAttr = false, isNgProp = false, isNgEvent = false;
|
9906 |
+
var multiElementMatch;
|
9907 |
+
|
9908 |
+
attr = nAttrs[j];
|
9909 |
+
name = attr.name;
|
9910 |
+
value = attr.value;
|
9911 |
+
|
9912 |
+
nName = directiveNormalize(name.toLowerCase());
|
9913 |
+
|
9914 |
+
// Support ng-attr-*, ng-prop-* and ng-on-*
|
9915 |
+
if ((ngPrefixMatch = nName.match(NG_PREFIX_BINDING))) {
|
9916 |
+
isNgAttr = ngPrefixMatch[1] === 'Attr';
|
9917 |
+
isNgProp = ngPrefixMatch[1] === 'Prop';
|
9918 |
+
isNgEvent = ngPrefixMatch[1] === 'On';
|
9919 |
+
|
9920 |
+
// Normalize the non-prefixed name
|
9921 |
+
name = name.replace(PREFIX_REGEXP, '')
|
9922 |
+
.toLowerCase()
|
9923 |
+
.substr(4 + ngPrefixMatch[1].length).replace(/_(.)/g, function(match, letter) {
|
9924 |
+
return letter.toUpperCase();
|
9925 |
+
});
|
9926 |
|
9927 |
+
// Support *-start / *-end multi element directives
|
9928 |
+
} else if ((multiElementMatch = nName.match(MULTI_ELEMENT_DIR_RE)) && directiveIsMultiElement(multiElementMatch[1])) {
|
9929 |
+
attrStartName = name;
|
9930 |
+
attrEndName = name.substr(0, name.length - 5) + 'end';
|
9931 |
+
name = name.substr(0, name.length - 6);
|
9932 |
+
}
|
9933 |
|
9934 |
+
if (isNgProp || isNgEvent) {
|
9935 |
+
attrs[nName] = value;
|
9936 |
+
attrsMap[nName] = attr.name;
|
|
|
|
|
9937 |
|
9938 |
+
if (isNgProp) {
|
9939 |
+
addPropertyDirective(node, directives, nName, name);
|
9940 |
+
} else {
|
9941 |
+
addEventDirective(directives, nName, name);
|
9942 |
+
}
|
9943 |
+
} else {
|
9944 |
+
// Update nName for cases where a prefix was removed
|
9945 |
+
// NOTE: the .toLowerCase() is unnecessary and causes https://github.com/angular/angular.js/issues/16624 for ng-attr-*
|
9946 |
+
nName = directiveNormalize(name.toLowerCase());
|
9947 |
+
attrsMap[nName] = name;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9948 |
|
9949 |
+
if (isNgAttr || !attrs.hasOwnProperty(nName)) {
|
9950 |
+
attrs[nName] = value;
|
9951 |
+
if (getBooleanAttrName(node, nName)) {
|
9952 |
+
attrs[nName] = true; // presence means true
|
9953 |
}
|
9954 |
+
}
|
9955 |
|
9956 |
+
addAttrInterpolateDirective(node, directives, value, nName, isNgAttr);
|
9957 |
+
addDirective(directives, nName, 'A', maxPriority, ignoreDirective, attrStartName,
|
9958 |
+
attrEndName);
|
9959 |
+
}
|
9960 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9961 |
|
9962 |
+
if (nodeName === 'input' && node.getAttribute('type') === 'hidden') {
|
9963 |
+
// Hidden input elements can have strange behaviour when navigating back to the page
|
9964 |
+
// This tells the browser not to try to cache and reinstate previous values
|
9965 |
+
node.setAttribute('autocomplete', 'off');
|
9966 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9967 |
|
9968 |
+
// use class as directive
|
9969 |
+
if (!cssClassDirectivesEnabled) break;
|
9970 |
+
className = node.className;
|
9971 |
+
if (isObject(className)) {
|
9972 |
+
// Maybe SVGAnimatedString
|
9973 |
+
className = className.animVal;
|
9974 |
+
}
|
9975 |
+
if (isString(className) && className !== '') {
|
9976 |
+
while ((match = CLASS_DIRECTIVE_REGEXP.exec(className))) {
|
9977 |
+
nName = directiveNormalize(match[2]);
|
9978 |
+
if (addDirective(directives, nName, 'C', maxPriority, ignoreDirective)) {
|
9979 |
+
attrs[nName] = trim(match[3]);
|
9980 |
+
}
|
9981 |
+
className = className.substr(match.index + match[0].length);
|
9982 |
+
}
|
9983 |
+
}
|
9984 |
+
break;
|
9985 |
+
case NODE_TYPE_TEXT: /* Text Node */
|
9986 |
+
addTextInterpolateDirective(directives, node.nodeValue);
|
9987 |
+
break;
|
9988 |
+
case NODE_TYPE_COMMENT: /* Comment */
|
9989 |
+
if (!commentDirectivesEnabled) break;
|
9990 |
+
collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective);
|
9991 |
+
break;
|
9992 |
+
}
|
9993 |
|
9994 |
+
directives.sort(byPriority);
|
9995 |
+
return directives;
|
9996 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9997 |
|
9998 |
+
function collectCommentDirectives(node, directives, attrs, maxPriority, ignoreDirective) {
|
9999 |
+
// function created because of performance, try/catch disables
|
10000 |
+
// the optimization of the whole function #14848
|
10001 |
+
try {
|
10002 |
+
var match = COMMENT_DIRECTIVE_REGEXP.exec(node.nodeValue);
|
10003 |
+
if (match) {
|
10004 |
+
var nName = directiveNormalize(match[1]);
|
10005 |
+
if (addDirective(directives, nName, 'M', maxPriority, ignoreDirective)) {
|
10006 |
+
attrs[nName] = trim(match[2]);
|
10007 |
+
}
|
10008 |
+
}
|
10009 |
+
} catch (e) {
|
10010 |
+
// turns out that under some circumstances IE9 throws errors when one attempts to read
|
10011 |
+
// comment's node value.
|
10012 |
+
// Just ignore it and continue. (Can't seem to reproduce in test case.)
|
10013 |
+
}
|
10014 |
+
}
|
|
|
|
|
|
|
10015 |
|
10016 |
+
/**
|
10017 |
+
* Given a node with a directive-start it collects all of the siblings until it finds
|
10018 |
+
* directive-end.
|
10019 |
+
* @param node
|
10020 |
+
* @param attrStart
|
10021 |
+
* @param attrEnd
|
10022 |
+
* @returns {*}
|
10023 |
+
*/
|
10024 |
+
function groupScan(node, attrStart, attrEnd) {
|
10025 |
+
var nodes = [];
|
10026 |
+
var depth = 0;
|
10027 |
+
if (attrStart && node.hasAttribute && node.hasAttribute(attrStart)) {
|
10028 |
+
do {
|
10029 |
+
if (!node) {
|
10030 |
+
throw $compileMinErr('uterdir',
|
10031 |
+
'Unterminated attribute, found \'{0}\' but no matching \'{1}\' found.',
|
10032 |
+
attrStart, attrEnd);
|
10033 |
+
}
|
10034 |
+
if (node.nodeType === NODE_TYPE_ELEMENT) {
|
10035 |
+
if (node.hasAttribute(attrStart)) depth++;
|
10036 |
+
if (node.hasAttribute(attrEnd)) depth--;
|
10037 |
+
}
|
10038 |
+
nodes.push(node);
|
10039 |
+
node = node.nextSibling;
|
10040 |
+
} while (depth > 0);
|
10041 |
+
} else {
|
10042 |
+
nodes.push(node);
|
10043 |
+
}
|
10044 |
|
10045 |
+
return jqLite(nodes);
|
10046 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10047 |
|
10048 |
+
/**
|
10049 |
+
* Wrapper for linking function which converts normal linking function into a grouped
|
10050 |
+
* linking function.
|
10051 |
+
* @param linkFn
|
10052 |
+
* @param attrStart
|
10053 |
+
* @param attrEnd
|
10054 |
+
* @returns {Function}
|
10055 |
+
*/
|
10056 |
+
function groupElementsLinkFnWrapper(linkFn, attrStart, attrEnd) {
|
10057 |
+
return function groupedElementsLink(scope, element, attrs, controllers, transcludeFn) {
|
10058 |
+
element = groupScan(element[0], attrStart, attrEnd);
|
10059 |
+
return linkFn(scope, element, attrs, controllers, transcludeFn);
|
10060 |
+
};
|
10061 |
+
}
|
10062 |
|
10063 |
+
/**
|
10064 |
+
* A function generator that is used to support both eager and lazy compilation
|
10065 |
+
* linking function.
|
10066 |
+
* @param eager
|
10067 |
+
* @param $compileNodes
|
10068 |
+
* @param transcludeFn
|
10069 |
+
* @param maxPriority
|
10070 |
+
* @param ignoreDirective
|
10071 |
+
* @param previousCompileContext
|
10072 |
+
* @returns {Function}
|
10073 |
+
*/
|
10074 |
+
function compilationGenerator(eager, $compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext) {
|
10075 |
+
var compiled;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10076 |
|
10077 |
+
if (eager) {
|
10078 |
+
return compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext);
|
10079 |
+
}
|
10080 |
+
return /** @this */ function lazyCompilation() {
|
10081 |
+
if (!compiled) {
|
10082 |
+
compiled = compile($compileNodes, transcludeFn, maxPriority, ignoreDirective, previousCompileContext);
|
10083 |
|
10084 |
+
// Null out all of these references in order to make them eligible for garbage collection
|
10085 |
+
// since this is a potentially long lived closure
|
10086 |
+
$compileNodes = transcludeFn = previousCompileContext = null;
|
10087 |
+
}
|
10088 |
+
return compiled.apply(this, arguments);
|
10089 |
+
};
|
10090 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10091 |
|
10092 |
+
/**
|
10093 |
+
* Once the directives have been collected, their compile functions are executed. This method
|
10094 |
+
* is responsible for inlining directive templates as well as terminating the application
|
10095 |
+
* of the directives if the terminal directive has been reached.
|
10096 |
+
*
|
10097 |
+
* @param {Array} directives Array of collected directives to execute their compile function.
|
10098 |
+
* this needs to be pre-sorted by priority order.
|
10099 |
+
* @param {Node} compileNode The raw DOM node to apply the compile functions to
|
10100 |
+
* @param {Object} templateAttrs The shared attribute function
|
10101 |
+
* @param {function(angular.Scope, cloneAttachFn=)} transcludeFn A linking function, where the
|
10102 |
+
* scope argument is auto-generated to the new
|
10103 |
+
* child of the transcluded parent scope.
|
10104 |
+
* @param {JQLite} jqCollection If we are working on the root of the compile tree then this
|
10105 |
+
* argument has the root jqLite array so that we can replace nodes
|
10106 |
+
* on it.
|
10107 |
+
* @param {Object=} originalReplaceDirective An optional directive that will be ignored when
|
10108 |
+
* compiling the transclusion.
|
10109 |
+
* @param {Array.<Function>} preLinkFns
|
10110 |
+
* @param {Array.<Function>} postLinkFns
|
10111 |
+
* @param {Object} previousCompileContext Context used for previous compilation of the current
|
10112 |
+
* node
|
10113 |
+
* @returns {Function} linkFn
|
10114 |
+
*/
|
10115 |
+
function applyDirectivesToNode(directives, compileNode, templateAttrs, transcludeFn,
|
10116 |
+
jqCollection, originalReplaceDirective, preLinkFns, postLinkFns,
|
10117 |
+
previousCompileContext) {
|
10118 |
+
previousCompileContext = previousCompileContext || {};
|
10119 |
+
|
10120 |
+
var terminalPriority = -Number.MAX_VALUE,
|
10121 |
+
newScopeDirective = previousCompileContext.newScopeDirective,
|
10122 |
+
controllerDirectives = previousCompileContext.controllerDirectives,
|
10123 |
+
newIsolateScopeDirective = previousCompileContext.newIsolateScopeDirective,
|
10124 |
+
templateDirective = previousCompileContext.templateDirective,
|
10125 |
+
nonTlbTranscludeDirective = previousCompileContext.nonTlbTranscludeDirective,
|
10126 |
+
hasTranscludeDirective = false,
|
10127 |
+
hasTemplate = false,
|
10128 |
+
hasElementTranscludeDirective = previousCompileContext.hasElementTranscludeDirective,
|
10129 |
+
$compileNode = templateAttrs.$$element = jqLite(compileNode),
|
10130 |
+
directive,
|
10131 |
+
directiveName,
|
10132 |
+
$template,
|
10133 |
+
replaceDirective = originalReplaceDirective,
|
10134 |
+
childTranscludeFn = transcludeFn,
|
10135 |
+
linkFn,
|
10136 |
+
didScanForMultipleTransclusion = false,
|
10137 |
+
mightHaveMultipleTransclusionError = false,
|
10138 |
+
directiveValue;
|
10139 |
+
|
10140 |
+
// executes all directives on the current element
|
10141 |
+
for (var i = 0, ii = directives.length; i < ii; i++) {
|
10142 |
+
directive = directives[i];
|
10143 |
+
var attrStart = directive.$$start;
|
10144 |
+
var attrEnd = directive.$$end;
|
10145 |
+
|
10146 |
+
// collect multiblock sections
|
10147 |
+
if (attrStart) {
|
10148 |
+
$compileNode = groupScan(compileNode, attrStart, attrEnd);
|
10149 |
+
}
|
10150 |
+
$template = undefined;
|
10151 |
+
|
10152 |
+
if (terminalPriority > directive.priority) {
|
10153 |
+
break; // prevent further processing of directives
|
10154 |
+
}
|
10155 |
+
|
10156 |
+
directiveValue = directive.scope;
|
10157 |
+
|
10158 |
+
if (directiveValue) {
|
10159 |
+
|
10160 |
+
// skip the check for directives with async templates, we'll check the derived sync
|
10161 |
+
// directive when the template arrives
|
10162 |
+
if (!directive.templateUrl) {
|
10163 |
+
if (isObject(directiveValue)) {
|
10164 |
+
// This directive is trying to add an isolated scope.
|
10165 |
+
// Check that there is no scope of any kind already
|
10166 |
+
assertNoDuplicate('new/isolated scope', newIsolateScopeDirective || newScopeDirective,
|
10167 |
+
directive, $compileNode);
|
10168 |
+
newIsolateScopeDirective = directive;
|
10169 |
+
} else {
|
10170 |
+
// This directive is trying to add a child scope.
|
10171 |
+
// Check that there is no isolated scope already
|
10172 |
+
assertNoDuplicate('new/isolated scope', newIsolateScopeDirective, directive,
|
10173 |
+
$compileNode);
|
10174 |
+
}
|
10175 |
+
}
|
10176 |
|
10177 |
+
newScopeDirective = newScopeDirective || directive;
|
10178 |
+
}
|
|
|
|
|
|
|
|
|
10179 |
|
10180 |
+
directiveName = directive.name;
|
10181 |
|
10182 |
+
// If we encounter a condition that can result in transclusion on the directive,
|
10183 |
+
// then scan ahead in the remaining directives for others that may cause a multiple
|
10184 |
+
// transclusion error to be thrown during the compilation process. If a matching directive
|
10185 |
+
// is found, then we know that when we encounter a transcluded directive, we need to eagerly
|
10186 |
+
// compile the `transclude` function rather than doing it lazily in order to throw
|
10187 |
+
// exceptions at the correct time
|
10188 |
+
if (!didScanForMultipleTransclusion && ((directive.replace && (directive.templateUrl || directive.template))
|
10189 |
+
|| (directive.transclude && !directive.$$tlb))) {
|
10190 |
+
var candidateDirective;
|
10191 |
|
10192 |
+
for (var scanningIndex = i + 1; (candidateDirective = directives[scanningIndex++]);) {
|
10193 |
+
if ((candidateDirective.transclude && !candidateDirective.$$tlb)
|
10194 |
+
|| (candidateDirective.replace && (candidateDirective.templateUrl || candidateDirective.template))) {
|
10195 |
+
mightHaveMultipleTransclusionError = true;
|
10196 |
+
break;
|
10197 |
+
}
|
10198 |
+
}
|
10199 |
|
10200 |
+
didScanForMultipleTransclusion = true;
|
10201 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10202 |
|
10203 |
+
if (!directive.templateUrl && directive.controller) {
|
10204 |
+
controllerDirectives = controllerDirectives || createMap();
|
10205 |
+
assertNoDuplicate('\'' + directiveName + '\' controller',
|
10206 |
+
controllerDirectives[directiveName], directive, $compileNode);
|
10207 |
+
controllerDirectives[directiveName] = directive;
|
10208 |
+
}
|
10209 |
|
10210 |
+
directiveValue = directive.transclude;
|
|
|
|
|
|
|
|
|
|
|
10211 |
|
10212 |
+
if (directiveValue) {
|
10213 |
+
hasTranscludeDirective = true;
|
|
|
|
|
10214 |
|
10215 |
+
// Special case ngIf and ngRepeat so that we don't complain about duplicate transclusion.
|
10216 |
+
// This option should only be used by directives that know how to safely handle element transclusion,
|
10217 |
+
// where the transcluded nodes are added or replaced after linking.
|
10218 |
+
if (!directive.$$tlb) {
|
10219 |
+
assertNoDuplicate('transclusion', nonTlbTranscludeDirective, directive, $compileNode);
|
10220 |
+
nonTlbTranscludeDirective = directive;
|
10221 |
+
}
|
10222 |
|
10223 |
+
if (directiveValue === 'element') {
|
10224 |
+
hasElementTranscludeDirective = true;
|
10225 |
+
terminalPriority = directive.priority;
|
10226 |
+
$template = $compileNode;
|
10227 |
+
$compileNode = templateAttrs.$$element =
|
10228 |
+
jqLite(compile.$$createComment(directiveName, templateAttrs[directiveName]));
|
10229 |
+
compileNode = $compileNode[0];
|
10230 |
+
replaceWith(jqCollection, sliceArgs($template), compileNode);
|
10231 |
+
|
10232 |
+
childTranscludeFn = compilationGenerator(mightHaveMultipleTransclusionError, $template, transcludeFn, terminalPriority,
|
10233 |
+
replaceDirective && replaceDirective.name, {
|
10234 |
+
// Don't pass in:
|
10235 |
+
// - controllerDirectives - otherwise we'll create duplicates controllers
|
10236 |
+
// - newIsolateScopeDirective or templateDirective - combining templates with
|
10237 |
+
// element transclusion doesn't make sense.
|
10238 |
+
//
|
10239 |
+
// We need only nonTlbTranscludeDirective so that we prevent putting transclusion
|
10240 |
+
// on the same element more than once.
|
10241 |
+
nonTlbTranscludeDirective: nonTlbTranscludeDirective
|
10242 |
+
});
|
10243 |
+
} else {
|
10244 |
|
10245 |
+
var slots = createMap();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10246 |
|
10247 |
+
if (!isObject(directiveValue)) {
|
10248 |
+
$template = jqLite(jqLiteClone(compileNode)).contents();
|
10249 |
+
} else {
|
|
|
|
|
10250 |
|
10251 |
+
// We have transclusion slots,
|
10252 |
+
// collect them up, compile them and store their transclusion functions
|
10253 |
+
$template = window.document.createDocumentFragment();
|
10254 |
|
10255 |
+
var slotMap = createMap();
|
10256 |
+
var filledSlots = createMap();
|
10257 |
|
10258 |
+
// Parse the element selectors
|
10259 |
+
forEach(directiveValue, function(elementSelector, slotName) {
|
10260 |
+
// If an element selector starts with a ? then it is optional
|
10261 |
+
var optional = (elementSelector.charAt(0) === '?');
|
10262 |
+
elementSelector = optional ? elementSelector.substring(1) : elementSelector;
|
|
|
|
|
10263 |
|
10264 |
+
slotMap[elementSelector] = slotName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10265 |
|
10266 |
+
// We explicitly assign `null` since this implies that a slot was defined but not filled.
|
10267 |
+
// Later when calling boundTransclusion functions with a slot name we only error if the
|
10268 |
+
// slot is `undefined`
|
10269 |
+
slots[slotName] = null;
|
|
|
10270 |
|
10271 |
+
// filledSlots contains `true` for all slots that are either optional or have been
|
10272 |
+
// filled. This is used to check that we have not missed any required slots
|
10273 |
+
filledSlots[slotName] = optional;
|
10274 |
+
});
|
10275 |
|
10276 |
+
// Add the matching elements into their slot
|
10277 |
+
forEach($compileNode.contents(), function(node) {
|
10278 |
+
var slotName = slotMap[directiveNormalize(nodeName_(node))];
|
10279 |
+
if (slotName) {
|
10280 |
+
filledSlots[slotName] = true;
|
10281 |
+
slots[slotName] = slots[slotName] || window.document.createDocumentFragment();
|
10282 |
+
slots[slotName].appendChild(node);
|
10283 |
+
} else {
|
10284 |
+
$template.appendChild(node);
|
10285 |
+
}
|
10286 |
+
});
|
10287 |
|
10288 |
+
// Check for required slots that were not filled
|
10289 |
+
forEach(filledSlots, function(filled, slotName) {
|
10290 |
+
if (!filled) {
|
10291 |
+
throw $compileMinErr('reqslot', 'Required transclusion slot `{0}` was not filled.', slotName);
|
10292 |
+
}
|
10293 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10294 |
|
10295 |
+
for (var slotName in slots) {
|
10296 |
+
if (slots[slotName]) {
|
10297 |
+
// Only define a transclusion function if the slot was filled
|
10298 |
+
var slotCompileNodes = jqLite(slots[slotName].childNodes);
|
10299 |
+
slots[slotName] = compilationGenerator(mightHaveMultipleTransclusionError, slotCompileNodes, transcludeFn);
|
10300 |
+
}
|
10301 |
+
}
|
10302 |
|
10303 |
+
$template = jqLite($template.childNodes);
|
10304 |
+
}
|
10305 |
|
10306 |
+
$compileNode.empty(); // clear contents
|
10307 |
+
childTranscludeFn = compilationGenerator(mightHaveMultipleTransclusionError, $template, transcludeFn, undefined,
|
10308 |
+
undefined, { needsNewScope: directive.$$isolateScope || directive.$$newScope});
|
10309 |
+
childTranscludeFn.$$slots = slots;
|
10310 |
+
}
|
10311 |
+
}
|
10312 |
|
10313 |
+
if (directive.template) {
|
10314 |
+
hasTemplate = true;
|
10315 |
+
assertNoDuplicate('template', templateDirective, directive, $compileNode);
|
10316 |
+
templateDirective = directive;
|
10317 |
|
10318 |
+
directiveValue = (isFunction(directive.template))
|
10319 |
+
? directive.template($compileNode, templateAttrs)
|
10320 |
+
: directive.template;
|
10321 |
|
10322 |
+
directiveValue = denormalizeTemplate(directiveValue);
|
10323 |
|
10324 |
+
if (directive.replace) {
|
10325 |
+
replaceDirective = directive;
|
10326 |
+
if (jqLiteIsTextNode(directiveValue)) {
|
10327 |
+
$template = [];
|
10328 |
+
} else {
|
10329 |
+
$template = removeComments(wrapTemplate(directive.templateNamespace, trim(directiveValue)));
|
10330 |
+
}
|
10331 |
+
compileNode = $template[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10332 |
|
10333 |
+
if ($template.length !== 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {
|
10334 |
+
throw $compileMinErr('tplrt',
|
10335 |
+
'Template for directive \'{0}\' must have exactly one root element. {1}',
|
10336 |
+
directiveName, '');
|
10337 |
+
}
|
10338 |
|
10339 |
+
replaceWith(jqCollection, $compileNode, compileNode);
|
|
|
|
|
|
|
|
|
|
|
|
|
10340 |
|
10341 |
+
var newTemplateAttrs = {$attr: {}};
|
|
|
|
|
|
|
|
|
|
|
10342 |
|
10343 |
+
// combine directives from the original node and from the template:
|
10344 |
+
// - take the array of directives for this element
|
10345 |
+
// - split it into two parts, those that already applied (processed) and those that weren't (unprocessed)
|
10346 |
+
// - collect directives from the template and sort them by priority
|
10347 |
+
// - combine directives as: processed + template + unprocessed
|
10348 |
+
var templateDirectives = collectDirectives(compileNode, [], newTemplateAttrs);
|
10349 |
+
var unprocessedDirectives = directives.splice(i + 1, directives.length - (i + 1));
|
|
|
|
|
|
|
10350 |
|
10351 |
+
if (newIsolateScopeDirective || newScopeDirective) {
|
10352 |
+
// The original directive caused the current element to be replaced but this element
|
10353 |
+
// also needs to have a new scope, so we need to tell the template directives
|
10354 |
+
// that they would need to get their scope from further up, if they require transclusion
|
10355 |
+
markDirectiveScope(templateDirectives, newIsolateScopeDirective, newScopeDirective);
|
10356 |
+
}
|
10357 |
+
directives = directives.concat(templateDirectives).concat(unprocessedDirectives);
|
10358 |
+
mergeTemplateAttributes(templateAttrs, newTemplateAttrs);
|
10359 |
|
10360 |
+
ii = directives.length;
|
10361 |
+
} else {
|
10362 |
+
$compileNode.html(directiveValue);
|
10363 |
+
}
|
10364 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10365 |
|
10366 |
+
if (directive.templateUrl) {
|
10367 |
+
hasTemplate = true;
|
10368 |
+
assertNoDuplicate('template', templateDirective, directive, $compileNode);
|
10369 |
+
templateDirective = directive;
|
|
|
10370 |
|
10371 |
+
if (directive.replace) {
|
10372 |
+
replaceDirective = directive;
|
10373 |
+
}
|
|
|
|
|
10374 |
|
10375 |
+
// eslint-disable-next-line no-func-assign
|
10376 |
+
nodeLinkFn = compileTemplateUrl(directives.splice(i, directives.length - i), $compileNode,
|
10377 |
+
templateAttrs, jqCollection, hasTranscludeDirective && childTranscludeFn, preLinkFns, postLinkFns, {
|
10378 |
+
controllerDirectives: controllerDirectives,
|
10379 |
+
newScopeDirective: (newScopeDirective !== directive) && newScopeDirective,
|
10380 |
+
newIsolateScopeDirective: newIsolateScopeDirective,
|
10381 |
+
templateDirective: templateDirective,
|
10382 |
+
nonTlbTranscludeDirective: nonTlbTranscludeDirective
|
10383 |
+
});
|
10384 |
+
ii = directives.length;
|
10385 |
+
} else if (directive.compile) {
|
10386 |
+
try {
|
10387 |
+
linkFn = directive.compile($compileNode, templateAttrs, childTranscludeFn);
|
10388 |
+
var context = directive.$$originalDirective || directive;
|
10389 |
+
if (isFunction(linkFn)) {
|
10390 |
+
addLinkFns(null, bind(context, linkFn), attrStart, attrEnd);
|
10391 |
+
} else if (linkFn) {
|
10392 |
+
addLinkFns(bind(context, linkFn.pre), bind(context, linkFn.post), attrStart, attrEnd);
|
10393 |
+
}
|
10394 |
+
} catch (e) {
|
10395 |
+
$exceptionHandler(e, startingTag($compileNode));
|
10396 |
+
}
|
10397 |
+
}
|
10398 |
|
10399 |
+
if (directive.terminal) {
|
10400 |
+
nodeLinkFn.terminal = true;
|
10401 |
+
terminalPriority = Math.max(terminalPriority, directive.priority);
|
10402 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10403 |
|
10404 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10405 |
|
10406 |
+
nodeLinkFn.scope = newScopeDirective && newScopeDirective.scope === true;
|
10407 |
+
nodeLinkFn.transcludeOnThisElement = hasTranscludeDirective;
|
10408 |
+
nodeLinkFn.templateOnThisElement = hasTemplate;
|
10409 |
+
nodeLinkFn.transclude = childTranscludeFn;
|
|
|
|
|
|
|
|
|
|
|
|
|
10410 |
|
10411 |
+
previousCompileContext.hasElementTranscludeDirective = hasElementTranscludeDirective;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10412 |
|
10413 |
+
// might be normal or delayed nodeLinkFn depending on if templateUrl is present
|
10414 |
+
return nodeLinkFn;
|
|
|
|
|
|
|
|
|
|
|
10415 |
|
10416 |
+
////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10417 |
|
10418 |
+
function addLinkFns(pre, post, attrStart, attrEnd) {
|
10419 |
+
if (pre) {
|
10420 |
+
if (attrStart) pre = groupElementsLinkFnWrapper(pre, attrStart, attrEnd);
|
10421 |
+
pre.require = directive.require;
|
10422 |
+
pre.directiveName = directiveName;
|
10423 |
+
if (newIsolateScopeDirective === directive || directive.$$isolateScope) {
|
10424 |
+
pre = cloneAndAnnotateFn(pre, {isolateScope: true});
|
10425 |
+
}
|
10426 |
+
preLinkFns.push(pre);
|
10427 |
+
}
|
10428 |
+
if (post) {
|
10429 |
+
if (attrStart) post = groupElementsLinkFnWrapper(post, attrStart, attrEnd);
|
10430 |
+
post.require = directive.require;
|
10431 |
+
post.directiveName = directiveName;
|
10432 |
+
if (newIsolateScopeDirective === directive || directive.$$isolateScope) {
|
10433 |
+
post = cloneAndAnnotateFn(post, {isolateScope: true});
|
10434 |
+
}
|
10435 |
+
postLinkFns.push(post);
|
10436 |
+
}
|
10437 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
10438 |
|
10439 |
+
function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) {
|
10440 |
+
var i, ii, linkFn, isolateScope, controllerScope, elementControllers, transcludeFn, $element,
|
10441 |
+
attrs, scopeBindingInfo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10442 |
|
10443 |
+
if (compileNode === linkNode) {
|
10444 |
+
attrs = templateAttrs;
|
10445 |
+
$element = templateAttrs.$$element;
|
10446 |
+
} else {
|
10447 |
+
$element = jqLite(linkNode);
|
10448 |
+
attrs = new Attributes($element, templateAttrs);
|
10449 |
+
}
|
10450 |
|
10451 |
+
controllerScope = scope;
|
10452 |
+
if (newIsolateScopeDirective) {
|
10453 |
+
isolateScope = scope.$new(true);
|
10454 |
+
} else if (newScopeDirective) {
|
10455 |
+
controllerScope = scope.$parent;
|
10456 |
+
}
|
|
|
|
|
10457 |
|
10458 |
+
if (boundTranscludeFn) {
|
10459 |
+
// track `boundTranscludeFn` so it can be unwrapped if `transcludeFn`
|
10460 |
+
// is later passed as `parentBoundTranscludeFn` to `publicLinkFn`
|
10461 |
+
transcludeFn = controllersBoundTransclude;
|
10462 |
+
transcludeFn.$$boundTransclude = boundTranscludeFn;
|
10463 |
+
// expose the slots on the `$transclude` function
|
10464 |
+
transcludeFn.isSlotFilled = function(slotName) {
|
10465 |
+
return !!boundTranscludeFn.$$slots[slotName];
|
10466 |
+
};
|
10467 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
10468 |
|
10469 |
+
if (controllerDirectives) {
|
10470 |
+
elementControllers = setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope, newIsolateScopeDirective);
|
10471 |
+
}
|
10472 |
|
10473 |
+
if (newIsolateScopeDirective) {
|
10474 |
+
// Initialize isolate scope bindings for new isolate scope directive.
|
10475 |
+
compile.$$addScopeInfo($element, isolateScope, true, !(templateDirective && (templateDirective === newIsolateScopeDirective ||
|
10476 |
+
templateDirective === newIsolateScopeDirective.$$originalDirective)));
|
10477 |
+
compile.$$addScopeClass($element, true);
|
10478 |
+
isolateScope.$$isolateBindings =
|
10479 |
+
newIsolateScopeDirective.$$isolateBindings;
|
10480 |
+
scopeBindingInfo = initializeDirectiveBindings(scope, attrs, isolateScope,
|
10481 |
+
isolateScope.$$isolateBindings,
|
10482 |
+
newIsolateScopeDirective);
|
10483 |
+
if (scopeBindingInfo.removeWatches) {
|
10484 |
+
isolateScope.$on('$destroy', scopeBindingInfo.removeWatches);
|
10485 |
+
}
|
10486 |
+
}
|
|
|
10487 |
|
10488 |
+
// Initialize bindToController bindings
|
10489 |
+
for (var name in elementControllers) {
|
10490 |
+
var controllerDirective = controllerDirectives[name];
|
10491 |
+
var controller = elementControllers[name];
|
10492 |
+
var bindings = controllerDirective.$$bindings.bindToController;
|
10493 |
|
10494 |
+
controller.instance = controller();
|
10495 |
+
$element.data('$' + controllerDirective.name + 'Controller', controller.instance);
|
10496 |
+
controller.bindingInfo =
|
10497 |
+
initializeDirectiveBindings(controllerScope, attrs, controller.instance, bindings, controllerDirective);
|
10498 |
+
}
|
|
|
|
|
|
|
|
|
10499 |
|
10500 |
+
// Bind the required controllers to the controller, if `require` is an object and `bindToController` is truthy
|
10501 |
+
forEach(controllerDirectives, function(controllerDirective, name) {
|
10502 |
+
var require = controllerDirective.require;
|
10503 |
+
if (controllerDirective.bindToController && !isArray(require) && isObject(require)) {
|
10504 |
+
extend(elementControllers[name].instance, getControllers(name, require, $element, elementControllers));
|
10505 |
+
}
|
10506 |
+
});
|
|
|
|
|
|
|
|
|
10507 |
|
10508 |
+
// Handle the init and destroy lifecycle hooks on all controllers that have them
|
10509 |
+
forEach(elementControllers, function(controller) {
|
10510 |
+
var controllerInstance = controller.instance;
|
10511 |
+
if (isFunction(controllerInstance.$onChanges)) {
|
10512 |
+
try {
|
10513 |
+
controllerInstance.$onChanges(controller.bindingInfo.initialChanges);
|
10514 |
+
} catch (e) {
|
10515 |
+
$exceptionHandler(e);
|
10516 |
+
}
|
10517 |
+
}
|
10518 |
+
if (isFunction(controllerInstance.$onInit)) {
|
10519 |
+
try {
|
10520 |
+
controllerInstance.$onInit();
|
10521 |
+
} catch (e) {
|
10522 |
+
$exceptionHandler(e);
|
10523 |
+
}
|
10524 |
+
}
|
10525 |
+
if (isFunction(controllerInstance.$doCheck)) {
|
10526 |
+
controllerScope.$watch(function() { controllerInstance.$doCheck(); });
|
10527 |
+
controllerInstance.$doCheck();
|
10528 |
+
}
|
10529 |
+
if (isFunction(controllerInstance.$onDestroy)) {
|
10530 |
+
controllerScope.$on('$destroy', function callOnDestroyHook() {
|
10531 |
+
controllerInstance.$onDestroy();
|
10532 |
+
});
|
10533 |
+
}
|
10534 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10535 |
|
10536 |
+
// PRELINKING
|
10537 |
+
for (i = 0, ii = preLinkFns.length; i < ii; i++) {
|
10538 |
+
linkFn = preLinkFns[i];
|
10539 |
+
invokeLinkFn(linkFn,
|
10540 |
+
linkFn.isolateScope ? isolateScope : scope,
|
10541 |
+
$element,
|
10542 |
+
attrs,
|
10543 |
+
linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),
|
10544 |
+
transcludeFn
|
10545 |
+
);
|
10546 |
+
}
|
10547 |
+
|
10548 |
+
// RECURSION
|
10549 |
+
// We only pass the isolate scope, if the isolate directive has a template,
|
10550 |
+
// otherwise the child elements do not belong to the isolate directive.
|
10551 |
+
var scopeToChild = scope;
|
10552 |
+
if (newIsolateScopeDirective && (newIsolateScopeDirective.template || newIsolateScopeDirective.templateUrl === null)) {
|
10553 |
+
scopeToChild = isolateScope;
|
10554 |
+
}
|
10555 |
+
if (childLinkFn) {
|
10556 |
+
childLinkFn(scopeToChild, linkNode.childNodes, undefined, boundTranscludeFn);
|
10557 |
+
}
|
10558 |
+
|
10559 |
+
// POSTLINKING
|
10560 |
+
for (i = postLinkFns.length - 1; i >= 0; i--) {
|
10561 |
+
linkFn = postLinkFns[i];
|
10562 |
+
invokeLinkFn(linkFn,
|
10563 |
+
linkFn.isolateScope ? isolateScope : scope,
|
10564 |
+
$element,
|
10565 |
+
attrs,
|
10566 |
+
linkFn.require && getControllers(linkFn.directiveName, linkFn.require, $element, elementControllers),
|
10567 |
+
transcludeFn
|
10568 |
+
);
|
10569 |
+
}
|
10570 |
+
|
10571 |
+
// Trigger $postLink lifecycle hooks
|
10572 |
+
forEach(elementControllers, function(controller) {
|
10573 |
+
var controllerInstance = controller.instance;
|
10574 |
+
if (isFunction(controllerInstance.$postLink)) {
|
10575 |
+
controllerInstance.$postLink();
|
10576 |
+
}
|
10577 |
+
});
|
10578 |
|
10579 |
+
// This is the function that is injected as `$transclude`.
|
10580 |
+
// Note: all arguments are optional!
|
10581 |
+
function controllersBoundTransclude(scope, cloneAttachFn, futureParentElement, slotName) {
|
10582 |
+
var transcludeControllers;
|
10583 |
+
// No scope passed in:
|
10584 |
+
if (!isScope(scope)) {
|
10585 |
+
slotName = futureParentElement;
|
10586 |
+
futureParentElement = cloneAttachFn;
|
10587 |
+
cloneAttachFn = scope;
|
10588 |
+
scope = undefined;
|
10589 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10590 |
|
10591 |
+
if (hasElementTranscludeDirective) {
|
10592 |
+
transcludeControllers = elementControllers;
|
10593 |
+
}
|
10594 |
+
if (!futureParentElement) {
|
10595 |
+
futureParentElement = hasElementTranscludeDirective ? $element.parent() : $element;
|
10596 |
+
}
|
10597 |
+
if (slotName) {
|
10598 |
+
// slotTranscludeFn can be one of three things:
|
10599 |
+
// * a transclude function - a filled slot
|
10600 |
+
// * `null` - an optional slot that was not filled
|
10601 |
+
// * `undefined` - a slot that was not declared (i.e. invalid)
|
10602 |
+
var slotTranscludeFn = boundTranscludeFn.$$slots[slotName];
|
10603 |
+
if (slotTranscludeFn) {
|
10604 |
+
return slotTranscludeFn(scope, cloneAttachFn, transcludeControllers, futureParentElement, scopeToChild);
|
10605 |
+
} else if (isUndefined(slotTranscludeFn)) {
|
10606 |
+
throw $compileMinErr('noslot',
|
10607 |
+
'No parent directive that requires a transclusion with slot name "{0}". ' +
|
10608 |
+
'Element: {1}',
|
10609 |
+
slotName, startingTag($element));
|
10610 |
+
}
|
10611 |
+
} else {
|
10612 |
+
return boundTranscludeFn(scope, cloneAttachFn, transcludeControllers, futureParentElement, scopeToChild);
|
10613 |
+
}
|
10614 |
+
}
|
10615 |
+
}
|
10616 |
+
}
|
10617 |
|
10618 |
+
function getControllers(directiveName, require, $element, elementControllers) {
|
10619 |
+
var value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10620 |
|
10621 |
+
if (isString(require)) {
|
10622 |
+
var match = require.match(REQUIRE_PREFIX_REGEXP);
|
10623 |
+
var name = require.substring(match[0].length);
|
10624 |
+
var inheritType = match[1] || match[3];
|
10625 |
+
var optional = match[2] === '?';
|
10626 |
|
10627 |
+
//If only parents then start at the parent element
|
10628 |
+
if (inheritType === '^^') {
|
10629 |
+
$element = $element.parent();
|
10630 |
+
//Otherwise attempt getting the controller from elementControllers in case
|
10631 |
+
//the element is transcluded (and has no data) and to avoid .data if possible
|
10632 |
+
} else {
|
10633 |
+
value = elementControllers && elementControllers[name];
|
10634 |
+
value = value && value.instance;
|
10635 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10636 |
|
10637 |
+
if (!value) {
|
10638 |
+
var dataName = '$' + name + 'Controller';
|
|
|
|
|
|
|
10639 |
|
10640 |
+
if (inheritType === '^^' && $element[0] && $element[0].nodeType === NODE_TYPE_DOCUMENT) {
|
10641 |
+
// inheritedData() uses the documentElement when it finds the document, so we would
|
10642 |
+
// require from the element itself.
|
10643 |
+
value = null;
|
10644 |
+
} else {
|
10645 |
+
value = inheritType ? $element.inheritedData(dataName) : $element.data(dataName);
|
10646 |
+
}
|
10647 |
+
}
|
10648 |
|
10649 |
+
if (!value && !optional) {
|
10650 |
+
throw $compileMinErr('ctreq',
|
10651 |
+
'Controller \'{0}\', required by directive \'{1}\', can\'t be found!',
|
10652 |
+
name, directiveName);
|
10653 |
+
}
|
10654 |
+
} else if (isArray(require)) {
|
10655 |
+
value = [];
|
10656 |
+
for (var i = 0, ii = require.length; i < ii; i++) {
|
10657 |
+
value[i] = getControllers(directiveName, require[i], $element, elementControllers);
|
10658 |
+
}
|
10659 |
+
} else if (isObject(require)) {
|
10660 |
+
value = {};
|
10661 |
+
forEach(require, function(controller, property) {
|
10662 |
+
value[property] = getControllers(directiveName, controller, $element, elementControllers);
|
10663 |
+
});
|
10664 |
+
}
|
10665 |
|
10666 |
+
return value || null;
|
10667 |
+
}
|
10668 |
|
10669 |
+
function setupControllers($element, attrs, transcludeFn, controllerDirectives, isolateScope, scope, newIsolateScopeDirective) {
|
10670 |
+
var elementControllers = createMap();
|
10671 |
+
for (var controllerKey in controllerDirectives) {
|
10672 |
+
var directive = controllerDirectives[controllerKey];
|
10673 |
+
var locals = {
|
10674 |
+
$scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
|
10675 |
+
$element: $element,
|
10676 |
+
$attrs: attrs,
|
10677 |
+
$transclude: transcludeFn
|
10678 |
+
};
|
10679 |
|
10680 |
+
var controller = directive.controller;
|
10681 |
+
if (controller === '@') {
|
10682 |
+
controller = attrs[directive.name];
|
10683 |
+
}
|
|
|
|
|
10684 |
|
10685 |
+
var controllerInstance = $controller(controller, locals, true, directive.controllerAs);
|
10686 |
|
10687 |
+
// For directives with element transclusion the element is a comment.
|
10688 |
+
// In this case .data will not attach any data.
|
10689 |
+
// Instead, we save the controllers for the element in a local hash and attach to .data
|
10690 |
+
// later, once we have the actual element.
|
10691 |
+
elementControllers[directive.name] = controllerInstance;
|
10692 |
+
$element.data('$' + directive.name + 'Controller', controllerInstance.instance);
|
10693 |
+
}
|
10694 |
+
return elementControllers;
|
10695 |
+
}
|
10696 |
+
|
10697 |
+
// Depending upon the context in which a directive finds itself it might need to have a new isolated
|
10698 |
+
// or child scope created. For instance:
|
10699 |
+
// * if the directive has been pulled into a template because another directive with a higher priority
|
10700 |
+
// asked for element transclusion
|
10701 |
+
// * if the directive itself asks for transclusion but it is at the root of a template and the original
|
10702 |
+
// element was replaced. See https://github.com/angular/angular.js/issues/12936
|
10703 |
+
function markDirectiveScope(directives, isolateScope, newScope) {
|
10704 |
+
for (var j = 0, jj = directives.length; j < jj; j++) {
|
10705 |
+
directives[j] = inherit(directives[j], {$$isolateScope: isolateScope, $$newScope: newScope});
|
10706 |
+
}
|
10707 |
+
}
|
10708 |
|
10709 |
+
/**
|
10710 |
+
* looks up the directive and decorates it with exception handling and proper parameters. We
|
10711 |
+
* call this the boundDirective.
|
10712 |
+
*
|
10713 |
+
* @param {string} name name of the directive to look up.
|
10714 |
+
* @param {string} location The directive must be found in specific format.
|
10715 |
+
* String containing any of theses characters:
|
10716 |
+
*
|
10717 |
+
* * `E`: element name
|
10718 |
+
* * `A': attribute
|
10719 |
+
* * `C`: class
|
10720 |
+
* * `M`: comment
|
10721 |
+
* @returns {boolean} true if directive was added.
|
10722 |
+
*/
|
10723 |
+
function addDirective(tDirectives, name, location, maxPriority, ignoreDirective, startAttrName,
|
10724 |
+
endAttrName) {
|
10725 |
+
if (name === ignoreDirective) return null;
|
10726 |
+
var match = null;
|
10727 |
+
if (hasDirectives.hasOwnProperty(name)) {
|
10728 |
+
for (var directive, directives = $injector.get(name + Suffix),
|
10729 |
+
i = 0, ii = directives.length; i < ii; i++) {
|
10730 |
+
directive = directives[i];
|
10731 |
+
if ((isUndefined(maxPriority) || maxPriority > directive.priority) &&
|
10732 |
+
directive.restrict.indexOf(location) !== -1) {
|
10733 |
+
if (startAttrName) {
|
10734 |
+
directive = inherit(directive, {$$start: startAttrName, $$end: endAttrName});
|
10735 |
+
}
|
10736 |
+
if (!directive.$$bindings) {
|
10737 |
+
var bindings = directive.$$bindings =
|
10738 |
+
parseDirectiveBindings(directive, directive.name);
|
10739 |
+
if (isObject(bindings.isolateScope)) {
|
10740 |
+
directive.$$isolateBindings = bindings.isolateScope;
|
10741 |
+
}
|
10742 |
+
}
|
10743 |
+
tDirectives.push(directive);
|
10744 |
+
match = directive;
|
10745 |
+
}
|
10746 |
+
}
|
10747 |
+
}
|
10748 |
+
return match;
|
10749 |
+
}
|
10750 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10751 |
|
10752 |
+
/**
|
10753 |
+
* looks up the directive and returns true if it is a multi-element directive,
|
10754 |
+
* and therefore requires DOM nodes between -start and -end markers to be grouped
|
10755 |
+
* together.
|
10756 |
+
*
|
10757 |
+
* @param {string} name name of the directive to look up.
|
10758 |
+
* @returns true if directive was registered as multi-element.
|
10759 |
+
*/
|
10760 |
+
function directiveIsMultiElement(name) {
|
10761 |
+
if (hasDirectives.hasOwnProperty(name)) {
|
10762 |
+
for (var directive, directives = $injector.get(name + Suffix),
|
10763 |
+
i = 0, ii = directives.length; i < ii; i++) {
|
10764 |
+
directive = directives[i];
|
10765 |
+
if (directive.multiElement) {
|
10766 |
+
return true;
|
10767 |
+
}
|
10768 |
+
}
|
10769 |
+
}
|
10770 |
+
return false;
|
10771 |
+
}
|
10772 |
|
10773 |
+
/**
|
10774 |
+
* When the element is replaced with HTML template then the new attributes
|
10775 |
+
* on the template need to be merged with the existing attributes in the DOM.
|
10776 |
+
* The desired effect is to have both of the attributes present.
|
10777 |
+
*
|
10778 |
+
* @param {object} dst destination attributes (original DOM)
|
10779 |
+
* @param {object} src source attributes (from the directive template)
|
10780 |
+
*/
|
10781 |
+
function mergeTemplateAttributes(dst, src) {
|
10782 |
+
var srcAttr = src.$attr,
|
10783 |
+
dstAttr = dst.$attr;
|
10784 |
+
|
10785 |
+
// reapply the old attributes to the new element
|
10786 |
+
forEach(dst, function(value, key) {
|
10787 |
+
if (key.charAt(0) !== '$') {
|
10788 |
+
if (src[key] && src[key] !== value) {
|
10789 |
+
if (value.length) {
|
10790 |
+
value += (key === 'style' ? ';' : ' ') + src[key];
|
10791 |
+
} else {
|
10792 |
+
value = src[key];
|
10793 |
+
}
|
10794 |
+
}
|
10795 |
+
dst.$set(key, value, true, srcAttr[key]);
|
10796 |
+
}
|
10797 |
+
});
|
10798 |
|
10799 |
+
// copy the new attributes on the old attrs object
|
10800 |
+
forEach(src, function(value, key) {
|
10801 |
+
// Check if we already set this attribute in the loop above.
|
10802 |
+
// `dst` will never contain hasOwnProperty as DOM parser won't let it.
|
10803 |
+
// You will get an "InvalidCharacterError: DOM Exception 5" error if you
|
10804 |
+
// have an attribute like "has-own-property" or "data-has-own-property", etc.
|
10805 |
+
if (!dst.hasOwnProperty(key) && key.charAt(0) !== '$') {
|
10806 |
+
dst[key] = value;
|
10807 |
+
|
10808 |
+
if (key !== 'class' && key !== 'style') {
|
10809 |
+
dstAttr[key] = srcAttr[key];
|
10810 |
+
}
|
10811 |
+
}
|
10812 |
+
});
|
10813 |
+
}
|
10814 |
|
|
|
10815 |
|
10816 |
+
function compileTemplateUrl(directives, $compileNode, tAttrs,
|
10817 |
+
$rootElement, childTranscludeFn, preLinkFns, postLinkFns, previousCompileContext) {
|
10818 |
+
var linkQueue = [],
|
10819 |
+
afterTemplateNodeLinkFn,
|
10820 |
+
afterTemplateChildLinkFn,
|
10821 |
+
beforeTemplateCompileNode = $compileNode[0],
|
10822 |
+
origAsyncDirective = directives.shift(),
|
10823 |
+
derivedSyncDirective = inherit(origAsyncDirective, {
|
10824 |
+
templateUrl: null, transclude: null, replace: null, $$originalDirective: origAsyncDirective
|
10825 |
+
}),
|
10826 |
+
templateUrl = (isFunction(origAsyncDirective.templateUrl))
|
10827 |
+
? origAsyncDirective.templateUrl($compileNode, tAttrs)
|
10828 |
+
: origAsyncDirective.templateUrl,
|
10829 |
+
templateNamespace = origAsyncDirective.templateNamespace;
|
10830 |
|
10831 |
+
$compileNode.empty();
|
|
|
|
|
|
|
|
|
|
|
10832 |
|
10833 |
+
$templateRequest(templateUrl)
|
10834 |
+
.then(function(content) {
|
10835 |
+
var compileNode, tempTemplateAttrs, $template, childBoundTranscludeFn;
|
10836 |
|
10837 |
+
content = denormalizeTemplate(content);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10838 |
|
10839 |
+
if (origAsyncDirective.replace) {
|
10840 |
+
if (jqLiteIsTextNode(content)) {
|
10841 |
+
$template = [];
|
10842 |
+
} else {
|
10843 |
+
$template = removeComments(wrapTemplate(templateNamespace, trim(content)));
|
10844 |
+
}
|
10845 |
+
compileNode = $template[0];
|
10846 |
|
10847 |
+
if ($template.length !== 1 || compileNode.nodeType !== NODE_TYPE_ELEMENT) {
|
10848 |
+
throw $compileMinErr('tplrt',
|
10849 |
+
'Template for directive \'{0}\' must have exactly one root element. {1}',
|
10850 |
+
origAsyncDirective.name, templateUrl);
|
10851 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10852 |
|
10853 |
+
tempTemplateAttrs = {$attr: {}};
|
10854 |
+
replaceWith($rootElement, $compileNode, compileNode);
|
10855 |
+
var templateDirectives = collectDirectives(compileNode, [], tempTemplateAttrs);
|
10856 |
|
10857 |
+
if (isObject(origAsyncDirective.scope)) {
|
10858 |
+
// the original directive that caused the template to be loaded async required
|
10859 |
+
// an isolate scope
|
10860 |
+
markDirectiveScope(templateDirectives, true);
|
10861 |
+
}
|
10862 |
+
directives = templateDirectives.concat(directives);
|
10863 |
+
mergeTemplateAttributes(tAttrs, tempTemplateAttrs);
|
10864 |
+
} else {
|
10865 |
+
compileNode = beforeTemplateCompileNode;
|
10866 |
+
$compileNode.html(content);
|
10867 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10868 |
|
10869 |
+
directives.unshift(derivedSyncDirective);
|
|
|
|
|
|
|
10870 |
|
10871 |
+
afterTemplateNodeLinkFn = applyDirectivesToNode(directives, compileNode, tAttrs,
|
10872 |
+
childTranscludeFn, $compileNode, origAsyncDirective, preLinkFns, postLinkFns,
|
10873 |
+
previousCompileContext);
|
10874 |
+
forEach($rootElement, function(node, i) {
|
10875 |
+
if (node === compileNode) {
|
10876 |
+
$rootElement[i] = $compileNode[0];
|
10877 |
+
}
|
10878 |
+
});
|
10879 |
+
afterTemplateChildLinkFn = compileNodes($compileNode[0].childNodes, childTranscludeFn);
|
10880 |
|
10881 |
+
while (linkQueue.length) {
|
10882 |
+
var scope = linkQueue.shift(),
|
10883 |
+
beforeTemplateLinkNode = linkQueue.shift(),
|
10884 |
+
linkRootElement = linkQueue.shift(),
|
10885 |
+
boundTranscludeFn = linkQueue.shift(),
|
10886 |
+
linkNode = $compileNode[0];
|
10887 |
|
10888 |
+
if (scope.$$destroyed) continue;
|
|
|
|
|
|
|
|
|
|
|
|
|
10889 |
|
10890 |
+
if (beforeTemplateLinkNode !== beforeTemplateCompileNode) {
|
10891 |
+
var oldClasses = beforeTemplateLinkNode.className;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10892 |
|
10893 |
+
if (!(previousCompileContext.hasElementTranscludeDirective &&
|
10894 |
+
origAsyncDirective.replace)) {
|
10895 |
+
// it was cloned therefore we have to clone as well.
|
10896 |
+
linkNode = jqLiteClone(compileNode);
|
10897 |
+
}
|
10898 |
+
replaceWith(linkRootElement, jqLite(beforeTemplateLinkNode), linkNode);
|
|
|
10899 |
|
10900 |
+
// Copy in CSS classes from original node
|
10901 |
+
safeAddClass(jqLite(linkNode), oldClasses);
|
10902 |
+
}
|
10903 |
+
if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
|
10904 |
+
childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);
|
10905 |
+
} else {
|
10906 |
+
childBoundTranscludeFn = boundTranscludeFn;
|
10907 |
+
}
|
10908 |
+
afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement,
|
10909 |
+
childBoundTranscludeFn);
|
10910 |
+
}
|
10911 |
+
linkQueue = null;
|
10912 |
+
}).catch(function(error) {
|
10913 |
+
if (isError(error)) {
|
10914 |
+
$exceptionHandler(error);
|
10915 |
+
}
|
10916 |
+
});
|
10917 |
|
10918 |
+
return function delayedNodeLinkFn(ignoreChildLinkFn, scope, node, rootElement, boundTranscludeFn) {
|
10919 |
+
var childBoundTranscludeFn = boundTranscludeFn;
|
10920 |
+
if (scope.$$destroyed) return;
|
10921 |
+
if (linkQueue) {
|
10922 |
+
linkQueue.push(scope,
|
10923 |
+
node,
|
10924 |
+
rootElement,
|
10925 |
+
childBoundTranscludeFn);
|
10926 |
+
} else {
|
10927 |
+
if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
|
10928 |
+
childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);
|
10929 |
+
}
|
10930 |
+
afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, childBoundTranscludeFn);
|
10931 |
+
}
|
10932 |
+
};
|
10933 |
+
}
|
10934 |
|
|
|
10935 |
|
10936 |
+
/**
|
10937 |
+
* Sorting function for bound directives.
|
10938 |
+
*/
|
10939 |
+
function byPriority(a, b) {
|
10940 |
+
var diff = b.priority - a.priority;
|
10941 |
+
if (diff !== 0) return diff;
|
10942 |
+
if (a.name !== b.name) return (a.name < b.name) ? -1 : 1;
|
10943 |
+
return a.index - b.index;
|
10944 |
+
}
|
10945 |
|
10946 |
+
function assertNoDuplicate(what, previousDirective, directive, element) {
|
|
|
|
|
|
|
|
|
10947 |
|
10948 |
+
function wrapModuleNameIfDefined(moduleName) {
|
10949 |
+
return moduleName ?
|
10950 |
+
(' (module: ' + moduleName + ')') :
|
10951 |
+
'';
|
10952 |
+
}
|
10953 |
|
10954 |
+
if (previousDirective) {
|
10955 |
+
throw $compileMinErr('multidir', 'Multiple directives [{0}{1}, {2}{3}] asking for {4} on: {5}',
|
10956 |
+
previousDirective.name, wrapModuleNameIfDefined(previousDirective.$$moduleName),
|
10957 |
+
directive.name, wrapModuleNameIfDefined(directive.$$moduleName), what, startingTag(element));
|
10958 |
+
}
|
10959 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10960 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10961 |
|
10962 |
+
function addTextInterpolateDirective(directives, text) {
|
10963 |
+
var interpolateFn = $interpolate(text, true);
|
10964 |
+
if (interpolateFn) {
|
10965 |
+
directives.push({
|
10966 |
+
priority: 0,
|
10967 |
+
compile: function textInterpolateCompileFn(templateNode) {
|
10968 |
+
var templateNodeParent = templateNode.parent(),
|
10969 |
+
hasCompileParent = !!templateNodeParent.length;
|
10970 |
|
10971 |
+
// When transcluding a template that has bindings in the root
|
10972 |
+
// we don't have a parent and thus need to add the class during linking fn.
|
10973 |
+
if (hasCompileParent) compile.$$addBindingClass(templateNodeParent);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10974 |
|
10975 |
+
return function textInterpolateLinkFn(scope, node) {
|
10976 |
+
var parent = node.parent();
|
10977 |
+
if (!hasCompileParent) compile.$$addBindingClass(parent);
|
10978 |
+
compile.$$addBindingInfo(parent, interpolateFn.expressions);
|
10979 |
+
scope.$watch(interpolateFn, function interpolateFnWatchAction(value) {
|
10980 |
+
node[0].nodeValue = value;
|
10981 |
+
});
|
10982 |
+
};
|
10983 |
+
}
|
10984 |
+
});
|
10985 |
+
}
|
10986 |
+
}
|
10987 |
|
|
|
|
|
|
|
10988 |
|
10989 |
+
function wrapTemplate(type, template) {
|
10990 |
+
type = lowercase(type || 'html');
|
10991 |
+
switch (type) {
|
10992 |
+
case 'svg':
|
10993 |
+
case 'math':
|
10994 |
+
var wrapper = window.document.createElement('div');
|
10995 |
+
wrapper.innerHTML = '<' + type + '>' + template + '</' + type + '>';
|
10996 |
+
return wrapper.childNodes[0].childNodes;
|
10997 |
+
default:
|
10998 |
+
return template;
|
10999 |
+
}
|
11000 |
+
}
|
11001 |
|
|
|
|
|
|
|
|
|
|
|
11002 |
|
11003 |
+
function getTrustedAttrContext(nodeName, attrNormalizedName) {
|
11004 |
+
if (attrNormalizedName === 'srcdoc') {
|
11005 |
+
return $sce.HTML;
|
11006 |
+
}
|
11007 |
+
// All nodes with src attributes require a RESOURCE_URL value, except for
|
11008 |
+
// img and various html5 media nodes, which require the MEDIA_URL context.
|
11009 |
+
if (attrNormalizedName === 'src' || attrNormalizedName === 'ngSrc') {
|
11010 |
+
if (['img', 'video', 'audio', 'source', 'track'].indexOf(nodeName) === -1) {
|
11011 |
+
return $sce.RESOURCE_URL;
|
11012 |
+
}
|
11013 |
+
return $sce.MEDIA_URL;
|
11014 |
+
} else if (attrNormalizedName === 'xlinkHref') {
|
11015 |
+
// Some xlink:href are okay, most aren't
|
11016 |
+
if (nodeName === 'image') return $sce.MEDIA_URL;
|
11017 |
+
if (nodeName === 'a') return $sce.URL;
|
11018 |
+
return $sce.RESOURCE_URL;
|
11019 |
+
} else if (
|
11020 |
+
// Formaction
|
11021 |
+
(nodeName === 'form' && attrNormalizedName === 'action') ||
|
11022 |
+
// If relative URLs can go where they are not expected to, then
|
11023 |
+
// all sorts of trust issues can arise.
|
11024 |
+
(nodeName === 'base' && attrNormalizedName === 'href') ||
|
11025 |
+
// links can be stylesheets or imports, which can run script in the current origin
|
11026 |
+
(nodeName === 'link' && attrNormalizedName === 'href')
|
11027 |
+
) {
|
11028 |
+
return $sce.RESOURCE_URL;
|
11029 |
+
} else if (nodeName === 'a' && (attrNormalizedName === 'href' ||
|
11030 |
+
attrNormalizedName === 'ngHref')) {
|
11031 |
+
return $sce.URL;
|
11032 |
+
}
|
11033 |
+
}
|
11034 |
|
11035 |
+
function getTrustedPropContext(nodeName, propNormalizedName) {
|
11036 |
+
var prop = propNormalizedName.toLowerCase();
|
11037 |
+
return PROP_CONTEXTS[nodeName + '|' + prop] || PROP_CONTEXTS['*|' + prop];
|
11038 |
+
}
|
11039 |
|
11040 |
+
function sanitizeSrcsetPropertyValue(value) {
|
11041 |
+
return sanitizeSrcset($sce.valueOf(value), 'ng-prop-srcset');
|
11042 |
+
}
|
11043 |
+
function addPropertyDirective(node, directives, attrName, propName) {
|
11044 |
+
if (EVENT_HANDLER_ATTR_REGEXP.test(propName)) {
|
11045 |
+
throw $compileMinErr('nodomevents', 'Property bindings for HTML DOM event properties are disallowed');
|
11046 |
+
}
|
11047 |
|
11048 |
+
var nodeName = nodeName_(node);
|
11049 |
+
var trustedContext = getTrustedPropContext(nodeName, propName);
|
11050 |
|
11051 |
+
var sanitizer = identity;
|
11052 |
+
// Sanitize img[srcset] + source[srcset] values.
|
11053 |
+
if (propName === 'srcset' && (nodeName === 'img' || nodeName === 'source')) {
|
11054 |
+
sanitizer = sanitizeSrcsetPropertyValue;
|
11055 |
+
} else if (trustedContext) {
|
11056 |
+
sanitizer = $sce.getTrusted.bind($sce, trustedContext);
|
11057 |
+
}
|
11058 |
|
11059 |
+
directives.push({
|
11060 |
+
priority: 100,
|
11061 |
+
compile: function ngPropCompileFn(_, attr) {
|
11062 |
+
var ngPropGetter = $parse(attr[attrName]);
|
11063 |
+
var ngPropWatch = $parse(attr[attrName], function sceValueOf(val) {
|
11064 |
+
// Unwrap the value to compare the actual inner safe value, not the wrapper object.
|
11065 |
+
return $sce.valueOf(val);
|
11066 |
+
});
|
11067 |
|
11068 |
+
return {
|
11069 |
+
pre: function ngPropPreLinkFn(scope, $element) {
|
11070 |
+
function applyPropValue() {
|
11071 |
+
var propValue = ngPropGetter(scope);
|
11072 |
+
$element[0][propName] = sanitizer(propValue);
|
11073 |
+
}
|
|
|
11074 |
|
11075 |
+
applyPropValue();
|
11076 |
+
scope.$watch(ngPropWatch, applyPropValue);
|
11077 |
+
}
|
11078 |
+
};
|
11079 |
+
}
|
11080 |
+
});
|
11081 |
+
}
|
11082 |
|
11083 |
+
function addEventDirective(directives, attrName, eventName) {
|
11084 |
+
directives.push(
|
11085 |
+
createEventDirective($parse, $rootScope, $exceptionHandler, attrName, eventName, /*forceAsync=*/false)
|
11086 |
+
);
|
11087 |
+
}
|
11088 |
|
11089 |
+
function addAttrInterpolateDirective(node, directives, value, name, isNgAttr) {
|
11090 |
+
var nodeName = nodeName_(node);
|
11091 |
+
var trustedContext = getTrustedAttrContext(nodeName, name);
|
11092 |
+
var mustHaveExpression = !isNgAttr;
|
11093 |
+
var allOrNothing = ALL_OR_NOTHING_ATTRS[name] || isNgAttr;
|
|
|
11094 |
|
11095 |
+
var interpolateFn = $interpolate(value, mustHaveExpression, trustedContext, allOrNothing);
|
11096 |
|
11097 |
+
// no interpolation found -> ignore
|
11098 |
+
if (!interpolateFn) return;
|
|
|
|
|
11099 |
|
11100 |
+
if (name === 'multiple' && nodeName === 'select') {
|
11101 |
+
throw $compileMinErr('selmulti',
|
11102 |
+
'Binding to the \'multiple\' attribute is not supported. Element: {0}',
|
11103 |
+
startingTag(node));
|
11104 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11105 |
|
11106 |
+
if (EVENT_HANDLER_ATTR_REGEXP.test(name)) {
|
11107 |
+
throw $compileMinErr('nodomevents', 'Interpolations for HTML DOM event attributes are disallowed');
|
11108 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11109 |
|
11110 |
+
directives.push({
|
11111 |
+
priority: 100,
|
11112 |
+
compile: function() {
|
11113 |
+
return {
|
11114 |
+
pre: function attrInterpolatePreLinkFn(scope, element, attr) {
|
11115 |
+
var $$observers = (attr.$$observers || (attr.$$observers = createMap()));
|
11116 |
+
|
11117 |
+
// If the attribute has changed since last $interpolate()ed
|
11118 |
+
var newValue = attr[name];
|
11119 |
+
if (newValue !== value) {
|
11120 |
+
// we need to interpolate again since the attribute value has been updated
|
11121 |
+
// (e.g. by another directive's compile function)
|
11122 |
+
// ensure unset/empty values make interpolateFn falsy
|
11123 |
+
interpolateFn = newValue && $interpolate(newValue, true, trustedContext, allOrNothing);
|
11124 |
+
value = newValue;
|
11125 |
+
}
|
11126 |
+
|
11127 |
+
// if attribute was updated so that there is no interpolation going on we don't want to
|
11128 |
+
// register any observers
|
11129 |
+
if (!interpolateFn) return;
|
11130 |
+
|
11131 |
+
// initialize attr object so that it's ready in case we need the value for isolate
|
11132 |
+
// scope initialization, otherwise the value would not be available from isolate
|
11133 |
+
// directive's linking fn during linking phase
|
11134 |
+
attr[name] = interpolateFn(scope);
|
11135 |
+
|
11136 |
+
($$observers[name] || ($$observers[name] = [])).$$inter = true;
|
11137 |
+
(attr.$$observers && attr.$$observers[name].$$scope || scope).
|
11138 |
+
$watch(interpolateFn, function interpolateFnWatchAction(newValue, oldValue) {
|
11139 |
+
//special case for class attribute addition + removal
|
11140 |
+
//so that class changes can tap into the animation
|
11141 |
+
//hooks provided by the $animate service. Be sure to
|
11142 |
+
//skip animations when the first digest occurs (when
|
11143 |
+
//both the new and the old values are the same) since
|
11144 |
+
//the CSS classes are the non-interpolated values
|
11145 |
+
if (name === 'class' && newValue !== oldValue) {
|
11146 |
+
attr.$updateClass(newValue, oldValue);
|
11147 |
+
} else {
|
11148 |
+
attr.$set(name, newValue);
|
11149 |
+
}
|
11150 |
+
});
|
11151 |
+
}
|
11152 |
+
};
|
11153 |
+
}
|
11154 |
+
});
|
11155 |
+
}
|
11156 |
|
|
|
|
|
11157 |
|
11158 |
+
/**
|
11159 |
+
* This is a special jqLite.replaceWith, which can replace items which
|
11160 |
+
* have no parents, provided that the containing jqLite collection is provided.
|
11161 |
+
*
|
11162 |
+
* @param {JqLite=} $rootElement The root of the compile tree. Used so that we can replace nodes
|
11163 |
+
* in the root of the tree.
|
11164 |
+
* @param {JqLite} elementsToRemove The jqLite element which we are going to replace. We keep
|
11165 |
+
* the shell, but replace its DOM node reference.
|
11166 |
+
* @param {Node} newNode The new DOM node.
|
11167 |
+
*/
|
11168 |
+
function replaceWith($rootElement, elementsToRemove, newNode) {
|
11169 |
+
var firstElementToRemove = elementsToRemove[0],
|
11170 |
+
removeCount = elementsToRemove.length,
|
11171 |
+
parent = firstElementToRemove.parentNode,
|
11172 |
+
i, ii;
|
11173 |
+
|
11174 |
+
if ($rootElement) {
|
11175 |
+
for (i = 0, ii = $rootElement.length; i < ii; i++) {
|
11176 |
+
if ($rootElement[i] === firstElementToRemove) {
|
11177 |
+
$rootElement[i++] = newNode;
|
11178 |
+
for (var j = i, j2 = j + removeCount - 1,
|
11179 |
+
jj = $rootElement.length;
|
11180 |
+
j < jj; j++, j2++) {
|
11181 |
+
if (j2 < jj) {
|
11182 |
+
$rootElement[j] = $rootElement[j2];
|
11183 |
+
} else {
|
11184 |
+
delete $rootElement[j];
|
11185 |
+
}
|
11186 |
+
}
|
11187 |
+
$rootElement.length -= removeCount - 1;
|
11188 |
|
11189 |
+
// If the replaced element is also the jQuery .context then replace it
|
11190 |
+
// .context is a deprecated jQuery api, so we should set it only when jQuery set it
|
11191 |
+
// http://api.jquery.com/context/
|
11192 |
+
if ($rootElement.context === firstElementToRemove) {
|
11193 |
+
$rootElement.context = newNode;
|
11194 |
+
}
|
11195 |
+
break;
|
11196 |
+
}
|
11197 |
+
}
|
11198 |
+
}
|
11199 |
|
11200 |
+
if (parent) {
|
11201 |
+
parent.replaceChild(newNode, firstElementToRemove);
|
11202 |
+
}
|
|
|
|
|
|
|
11203 |
|
11204 |
+
// Append all the `elementsToRemove` to a fragment. This will...
|
11205 |
+
// - remove them from the DOM
|
11206 |
+
// - allow them to still be traversed with .nextSibling
|
11207 |
+
// - allow a single fragment.qSA to fetch all elements being removed
|
11208 |
+
var fragment = window.document.createDocumentFragment();
|
11209 |
+
for (i = 0; i < removeCount; i++) {
|
11210 |
+
fragment.appendChild(elementsToRemove[i]);
|
11211 |
+
}
|
11212 |
|
11213 |
+
if (jqLite.hasData(firstElementToRemove)) {
|
11214 |
+
// Copy over user data (that includes AngularJS's $scope etc.). Don't copy private
|
11215 |
+
// data here because there's no public interface in jQuery to do that and copying over
|
11216 |
+
// event listeners (which is the main use of private data) wouldn't work anyway.
|
11217 |
+
jqLite.data(newNode, jqLite.data(firstElementToRemove));
|
|
|
11218 |
|
11219 |
+
// Remove $destroy event listeners from `firstElementToRemove`
|
11220 |
+
jqLite(firstElementToRemove).off('$destroy');
|
11221 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11222 |
|
11223 |
+
// Cleanup any data/listeners on the elements and children.
|
11224 |
+
// This includes invoking the $destroy event on any elements with listeners.
|
11225 |
+
jqLite.cleanData(fragment.querySelectorAll('*'));
|
|
|
|
|
11226 |
|
11227 |
+
// Update the jqLite collection to only contain the `newNode`
|
11228 |
+
for (i = 1; i < removeCount; i++) {
|
11229 |
+
delete elementsToRemove[i];
|
11230 |
+
}
|
11231 |
+
elementsToRemove[0] = newNode;
|
11232 |
+
elementsToRemove.length = 1;
|
|
|
|
|
|
|
|
|
11233 |
}
|
11234 |
|
11235 |
+
|
11236 |
+
function cloneAndAnnotateFn(fn, annotation) {
|
11237 |
+
return extend(function() { return fn.apply(null, arguments); }, fn, annotation);
|
11238 |
}
|
|
|
11239 |
|
11240 |
|
11241 |
+
function invokeLinkFn(linkFn, scope, $element, attrs, controllers, transcludeFn) {
|
11242 |
+
try {
|
11243 |
+
linkFn(scope, $element, attrs, controllers, transcludeFn);
|
11244 |
+
} catch (e) {
|
11245 |
+
$exceptionHandler(e, startingTag($element));
|
11246 |
+
}
|
11247 |
+
}
|
11248 |
|
11249 |
+
function strictBindingsCheck(attrName, directiveName) {
|
11250 |
+
if (strictComponentBindingsEnabled) {
|
11251 |
+
throw $compileMinErr('missingattr',
|
11252 |
+
'Attribute \'{0}\' of \'{1}\' is non-optional and must be set!',
|
11253 |
+
attrName, directiveName);
|
11254 |
+
}
|
|
|
|
|
|
|
|
|
11255 |
}
|
11256 |
|
11257 |
+
// Set up $watches for isolate scope and controller bindings.
|
11258 |
+
function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {
|
11259 |
+
var removeWatchCollection = [];
|
11260 |
+
var initialChanges = {};
|
11261 |
+
var changes;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11262 |
|
11263 |
+
forEach(bindings, function initializeBinding(definition, scopeName) {
|
11264 |
+
var attrName = definition.attrName,
|
11265 |
+
optional = definition.optional,
|
11266 |
+
mode = definition.mode, // @, =, <, or &
|
11267 |
+
lastValue,
|
11268 |
+
parentGet, parentSet, compare, removeWatch;
|
|
|
|
|
11269 |
|
11270 |
+
switch (mode) {
|
11271 |
|
11272 |
+
case '@':
|
11273 |
+
if (!optional && !hasOwnProperty.call(attrs, attrName)) {
|
11274 |
+
strictBindingsCheck(attrName, directive.name);
|
11275 |
+
destination[scopeName] = attrs[attrName] = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11276 |
|
11277 |
+
}
|
11278 |
+
removeWatch = attrs.$observe(attrName, function(value) {
|
11279 |
+
if (isString(value) || isBoolean(value)) {
|
11280 |
+
var oldValue = destination[scopeName];
|
11281 |
+
recordChanges(scopeName, value, oldValue);
|
11282 |
+
destination[scopeName] = value;
|
11283 |
+
}
|
11284 |
+
});
|
11285 |
+
attrs.$$observers[attrName].$$scope = scope;
|
11286 |
+
lastValue = attrs[attrName];
|
11287 |
+
if (isString(lastValue)) {
|
11288 |
+
// If the attribute has been provided then we trigger an interpolation to ensure
|
11289 |
+
// the value is there for use in the link fn
|
11290 |
+
destination[scopeName] = $interpolate(lastValue)(scope);
|
11291 |
+
} else if (isBoolean(lastValue)) {
|
11292 |
+
// If the attributes is one of the BOOLEAN_ATTR then AngularJS will have converted
|
11293 |
+
// the value to boolean rather than a string, so we special case this situation
|
11294 |
+
destination[scopeName] = lastValue;
|
11295 |
+
}
|
11296 |
+
initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);
|
11297 |
+
removeWatchCollection.push(removeWatch);
|
11298 |
+
break;
|
11299 |
+
|
11300 |
+
case '=':
|
11301 |
+
if (!hasOwnProperty.call(attrs, attrName)) {
|
11302 |
+
if (optional) break;
|
11303 |
+
strictBindingsCheck(attrName, directive.name);
|
11304 |
+
attrs[attrName] = undefined;
|
11305 |
+
}
|
11306 |
+
if (optional && !attrs[attrName]) break;
|
11307 |
+
|
11308 |
+
parentGet = $parse(attrs[attrName]);
|
11309 |
+
if (parentGet.literal) {
|
11310 |
+
compare = equals;
|
11311 |
+
} else {
|
11312 |
+
compare = simpleCompare;
|
11313 |
+
}
|
11314 |
+
parentSet = parentGet.assign || function() {
|
11315 |
+
// reset the change, or we will throw this exception on every $digest
|
11316 |
+
lastValue = destination[scopeName] = parentGet(scope);
|
11317 |
+
throw $compileMinErr('nonassign',
|
11318 |
+
'Expression \'{0}\' in attribute \'{1}\' used with directive \'{2}\' is non-assignable!',
|
11319 |
+
attrs[attrName], attrName, directive.name);
|
11320 |
+
};
|
11321 |
+
lastValue = destination[scopeName] = parentGet(scope);
|
11322 |
+
var parentValueWatch = function parentValueWatch(parentValue) {
|
11323 |
+
if (!compare(parentValue, destination[scopeName])) {
|
11324 |
+
// we are out of sync and need to copy
|
11325 |
+
if (!compare(parentValue, lastValue)) {
|
11326 |
+
// parent changed and it has precedence
|
11327 |
+
destination[scopeName] = parentValue;
|
11328 |
+
} else {
|
11329 |
+
// if the parent can be assigned then do so
|
11330 |
+
parentSet(scope, parentValue = destination[scopeName]);
|
11331 |
+
}
|
11332 |
+
}
|
11333 |
+
lastValue = parentValue;
|
11334 |
+
return lastValue;
|
11335 |
+
};
|
11336 |
+
parentValueWatch.$stateful = true;
|
11337 |
+
if (definition.collection) {
|
11338 |
+
removeWatch = scope.$watchCollection(attrs[attrName], parentValueWatch);
|
11339 |
+
} else {
|
11340 |
+
removeWatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal);
|
11341 |
+
}
|
11342 |
+
removeWatchCollection.push(removeWatch);
|
11343 |
+
break;
|
11344 |
|
11345 |
+
case '<':
|
11346 |
+
if (!hasOwnProperty.call(attrs, attrName)) {
|
11347 |
+
if (optional) break;
|
11348 |
+
strictBindingsCheck(attrName, directive.name);
|
11349 |
+
attrs[attrName] = undefined;
|
11350 |
+
}
|
11351 |
+
if (optional && !attrs[attrName]) break;
|
11352 |
|
11353 |
+
parentGet = $parse(attrs[attrName]);
|
11354 |
+
var isLiteral = parentGet.literal;
|
|
|
11355 |
|
11356 |
+
var initialValue = destination[scopeName] = parentGet(scope);
|
11357 |
+
initialChanges[scopeName] = new SimpleChange(_UNINITIALIZED_VALUE, destination[scopeName]);
|
11358 |
+
|
11359 |
+
removeWatch = scope[definition.collection ? '$watchCollection' : '$watch'](parentGet, function parentValueWatchAction(newValue, oldValue) {
|
11360 |
+
if (oldValue === newValue) {
|
11361 |
+
if (oldValue === initialValue || (isLiteral && equals(oldValue, initialValue))) {
|
11362 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11363 |
}
|
11364 |
+
oldValue = initialValue;
|
11365 |
+
}
|
11366 |
+
recordChanges(scopeName, newValue, oldValue);
|
11367 |
+
destination[scopeName] = newValue;
|
11368 |
+
});
|
11369 |
+
|
11370 |
+
removeWatchCollection.push(removeWatch);
|
11371 |
+
break;
|
11372 |
+
|
11373 |
+
case '&':
|
11374 |
+
if (!optional && !hasOwnProperty.call(attrs, attrName)) {
|
11375 |
+
strictBindingsCheck(attrName, directive.name);
|
11376 |
}
|
11377 |
+
// Don't assign Object.prototype method to scope
|
11378 |
+
parentGet = attrs.hasOwnProperty(attrName) ? $parse(attrs[attrName]) : noop;
|
11379 |
|
11380 |
+
// Don't assign noop to destination if expression is not valid
|
11381 |
+
if (parentGet === noop && optional) break;
|
|
|
11382 |
|
11383 |
+
destination[scopeName] = function(locals) {
|
11384 |
+
return parentGet(scope, locals);
|
11385 |
+
};
|
11386 |
+
break;
|
11387 |
}
|
11388 |
+
});
|
11389 |
|
11390 |
+
function recordChanges(key, currentValue, previousValue) {
|
11391 |
+
if (isFunction(destination.$onChanges) && !simpleCompare(currentValue, previousValue)) {
|
11392 |
+
// If we have not already scheduled the top level onChangesQueue handler then do so now
|
11393 |
+
if (!onChangesQueue) {
|
11394 |
+
scope.$$postDigest(flushOnChangesQueue);
|
11395 |
+
onChangesQueue = [];
|
11396 |
+
}
|
11397 |
+
// If we have not already queued a trigger of onChanges for this controller then do so now
|
11398 |
+
if (!changes) {
|
11399 |
+
changes = {};
|
11400 |
+
onChangesQueue.push(triggerOnChangesHook);
|
11401 |
+
}
|
11402 |
+
// If the has been a change on this property already then we need to reuse the previous value
|
11403 |
+
if (changes[key]) {
|
11404 |
+
previousValue = changes[key].previousValue;
|
11405 |
+
}
|
11406 |
+
// Store this change
|
11407 |
+
changes[key] = new SimpleChange(previousValue, currentValue);
|
11408 |
}
|
11409 |
+
}
|
|
|
|
|
|
|
11410 |
|
11411 |
+
function triggerOnChangesHook() {
|
11412 |
+
destination.$onChanges(changes);
|
11413 |
+
// Now clear the changes so that we schedule onChanges when more changes arrive
|
11414 |
+
changes = undefined;
|
11415 |
+
}
|
11416 |
|
11417 |
+
return {
|
11418 |
+
initialChanges: initialChanges,
|
11419 |
+
removeWatches: removeWatchCollection.length && function removeWatches() {
|
11420 |
+
for (var i = 0, ii = removeWatchCollection.length; i < ii; ++i) {
|
11421 |
+
removeWatchCollection[i]();
|
11422 |
+
}
|
11423 |
}
|
11424 |
+
};
|
11425 |
}
|
11426 |
+
}];
|
11427 |
+
}
|
11428 |
|
11429 |
+
function SimpleChange(previous, current) {
|
11430 |
+
this.previousValue = previous;
|
11431 |
+
this.currentValue = current;
|
11432 |
+
}
|
11433 |
+
SimpleChange.prototype.isFirstChange = function() { return this.previousValue === _UNINITIALIZED_VALUE; };
|
11434 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11435 |
|
11436 |
+
var PREFIX_REGEXP = /^((?:x|data)[:\-_])/i;
|
11437 |
+
var SPECIAL_CHARS_REGEXP = /[:\-_]+(.)/g;
|
|
|
|
|
|
|
|
|
|
|
|
|
11438 |
|
11439 |
+
/**
|
11440 |
+
* Converts all accepted directives format into proper directive name.
|
11441 |
+
* @param name Name to normalize
|
11442 |
+
*/
|
11443 |
+
function directiveNormalize(name) {
|
11444 |
+
return name
|
11445 |
+
.replace(PREFIX_REGEXP, '')
|
11446 |
+
.replace(SPECIAL_CHARS_REGEXP, function(_, letter, offset) {
|
11447 |
+
return offset ? letter.toUpperCase() : letter;
|
11448 |
+
});
|
11449 |
+
}
|
|
|
|
|
|
|
|
|
|
|
11450 |
|
11451 |
+
/**
|
11452 |
+
* @ngdoc type
|
11453 |
+
* @name $compile.directive.Attributes
|
11454 |
+
*
|
11455 |
+
* @description
|
11456 |
+
* A shared object between directive compile / linking functions which contains normalized DOM
|
11457 |
+
* element attributes. The values reflect current binding state `{{ }}`. The normalization is
|
11458 |
+
* needed since all of these are treated as equivalent in AngularJS:
|
11459 |
+
*
|
11460 |
+
* ```
|
11461 |
+
* <span ng:bind="a" ng-bind="a" data-ng-bind="a" x-ng-bind="a">
|
11462 |
+
* ```
|
11463 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11464 |
|
11465 |
+
/**
|
11466 |
+
* @ngdoc property
|
11467 |
+
* @name $compile.directive.Attributes#$attr
|
11468 |
+
*
|
11469 |
+
* @description
|
11470 |
+
* A map of DOM element attribute names to the normalized name. This is
|
11471 |
+
* needed to do reverse lookup from normalized name back to actual name.
|
11472 |
+
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11473 |
|
|
|
|
|
11474 |
|
11475 |
+
/**
|
11476 |
+
* @ngdoc method
|
11477 |
+
* @name $compile.directive.Attributes#$set
|
11478 |
+
* @kind function
|
11479 |
+
*
|
11480 |
+
* @description
|
11481 |
+
* Set DOM element attribute value.
|
11482 |
+
*
|
11483 |
+
*
|
11484 |
+
* @param {string} name Normalized element attribute name of the property to modify. The name is
|
11485 |
+
* reverse-translated using the {@link ng.$compile.directive.Attributes#$attr $attr}
|
11486 |
+
* property to the original name.
|
11487 |
+
* @param {string} value Value to set the attribute to. The value can be an interpolated string.
|
11488 |
+
*/
|
|
|
|
|
|
|
|
|
11489 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11490 |
|
|
|
11491 |
|
11492 |
+
/**
|
11493 |
+
* Closure compiler type information
|
11494 |
+
*/
|
11495 |
|
11496 |
+
function nodesetLinkingFn(
|
11497 |
+
/* angular.Scope */ scope,
|
11498 |
+
/* NodeList */ nodeList,
|
11499 |
+
/* Element */ rootElement,
|
11500 |
+
/* function(Function) */ boundTranscludeFn
|
11501 |
+
) {}
|
11502 |
+
|
11503 |
+
function directiveLinkingFn(
|
11504 |
+
/* nodesetLinkingFn */ nodesetLinkingFn,
|
11505 |
+
/* angular.Scope */ scope,
|
11506 |
+
/* Node */ node,
|
11507 |
+
/* Element */ rootElement,
|
11508 |
+
/* function(Function) */ boundTranscludeFn
|
11509 |
+
) {}
|
11510 |
+
|
11511 |
+
function tokenDifference(str1, str2) {
|
11512 |
+
var values = '',
|
11513 |
+
tokens1 = str1.split(/\s+/),
|
11514 |
+
tokens2 = str2.split(/\s+/);
|
11515 |
+
|
11516 |
+
outer:
|
11517 |
+
for (var i = 0; i < tokens1.length; i++) {
|
11518 |
+
var token = tokens1[i];
|
11519 |
+
for (var j = 0; j < tokens2.length; j++) {
|
11520 |
+
if (token === tokens2[j]) continue outer;
|
11521 |
+
}
|
11522 |
+
values += (values.length > 0 ? ' ' : '') + token;
|
11523 |
+
}
|
11524 |
+
return values;
|
11525 |
+
}
|
11526 |
|
11527 |
+
function removeComments(jqNodes) {
|
11528 |
+
jqNodes = jqLite(jqNodes);
|
11529 |
+
var i = jqNodes.length;
|
|
|
|
|
|
|
11530 |
|
11531 |
+
if (i <= 1) {
|
11532 |
+
return jqNodes;
|
11533 |
+
}
|
|
|
11534 |
|
11535 |
+
while (i--) {
|
11536 |
+
var node = jqNodes[i];
|
11537 |
+
if (node.nodeType === NODE_TYPE_COMMENT ||
|
11538 |
+
(node.nodeType === NODE_TYPE_TEXT && node.nodeValue.trim() === '')) {
|
11539 |
+
splice.call(jqNodes, i, 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11540 |
}
|
11541 |
+
}
|
11542 |
+
return jqNodes;
|
11543 |
+
}
|
11544 |
|
11545 |
+
var $controllerMinErr = minErr('$controller');
|
11546 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11547 |
|
11548 |
+
var CNTRL_REG = /^(\S+)(\s+as\s+([\w$]+))?$/;
|
11549 |
+
function identifierForController(controller, ident) {
|
11550 |
+
if (ident && isString(ident)) return ident;
|
11551 |
+
if (isString(controller)) {
|
11552 |
+
var match = CNTRL_REG.exec(controller);
|
11553 |
+
if (match) return match[3];
|
11554 |
+
}
|
11555 |
+
}
|
11556 |
|
|
|
|
|
|
|
11557 |
|
11558 |
+
/**
|
11559 |
+
* @ngdoc provider
|
11560 |
+
* @name $controllerProvider
|
11561 |
+
* @this
|
11562 |
+
*
|
11563 |
+
* @description
|
11564 |
+
* The {@link ng.$controller $controller service} is used by AngularJS to create new
|
11565 |
+
* controllers.
|
11566 |
+
*
|
11567 |
+
* This provider allows controller registration via the
|
11568 |
+
* {@link ng.$controllerProvider#register register} method.
|
11569 |
+
*/
|
11570 |
+
function $ControllerProvider() {
|
11571 |
+
var controllers = {};
|
11572 |
|
11573 |
+
/**
|
11574 |
+
* @ngdoc method
|
11575 |
+
* @name $controllerProvider#has
|
11576 |
+
* @param {string} name Controller name to check.
|
11577 |
+
*/
|
11578 |
+
this.has = function(name) {
|
11579 |
+
return controllers.hasOwnProperty(name);
|
11580 |
+
};
|
11581 |
+
|
11582 |
+
/**
|
11583 |
+
* @ngdoc method
|
11584 |
+
* @name $controllerProvider#register
|
11585 |
+
* @param {string|Object} name Controller name, or an object map of controllers where the keys are
|
11586 |
+
* the names and the values are the constructors.
|
11587 |
+
* @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI
|
11588 |
+
* annotations in the array notation).
|
11589 |
+
*/
|
11590 |
+
this.register = function(name, constructor) {
|
11591 |
+
assertNotHasOwnProperty(name, 'controller');
|
11592 |
+
if (isObject(name)) {
|
11593 |
+
extend(controllers, name);
|
11594 |
+
} else {
|
11595 |
+
controllers[name] = constructor;
|
11596 |
}
|
11597 |
+
};
|
11598 |
+
|
11599 |
+
this.$get = ['$injector', function($injector) {
|
11600 |
|
11601 |
/**
|
11602 |
* @ngdoc service
|
11603 |
+
* @name $controller
|
11604 |
+
* @requires $injector
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11605 |
*
|
11606 |
+
* @param {Function|string} constructor If called with a function then it's considered to be the
|
11607 |
+
* controller constructor function. Otherwise it's considered to be a string which is used
|
11608 |
+
* to retrieve the controller constructor using the following steps:
|
11609 |
*
|
11610 |
+
* * check if a controller with given name is registered via `$controllerProvider`
|
11611 |
+
* * check if evaluating the string on the current scope returns a constructor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11612 |
*
|
11613 |
+
* The string can use the `controller as property` syntax, where the controller instance is published
|
11614 |
+
* as the specified property on the `scope`; the `scope` must be injected into `locals` param for this
|
11615 |
+
* to work correctly.
|
|
|
11616 |
*
|
11617 |
+
* @param {Object} locals Injection locals for Controller.
|
11618 |
+
* @return {Object} Instance of given controller.
|
11619 |
*
|
11620 |
+
* @description
|
11621 |
+
* `$controller` service is responsible for instantiating controllers.
|
|
|
11622 |
*
|
11623 |
+
* It's just a simple call to {@link auto.$injector $injector}, but extracted into
|
11624 |
+
* a service, so that one can override this service with [BC version](https://gist.github.com/1649788).
|
11625 |
*/
|
11626 |
+
return function $controller(expression, locals, later, ident) {
|
11627 |
+
// PRIVATE API:
|
11628 |
+
// param `later` --- indicates that the controller's constructor is invoked at a later time.
|
11629 |
+
// If true, $controller will allocate the object with the correct
|
11630 |
+
// prototype chain, but will not invoke the controller until a returned
|
11631 |
+
// callback is invoked.
|
11632 |
+
// param `ident` --- An optional label which overrides the label parsed from the controller
|
11633 |
+
// expression, if any.
|
11634 |
+
var instance, match, constructor, identifier;
|
11635 |
+
later = later === true;
|
11636 |
+
if (ident && isString(ident)) {
|
11637 |
+
identifier = ident;
|
11638 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11639 |
|
11640 |
+
if (isString(expression)) {
|
11641 |
+
match = expression.match(CNTRL_REG);
|
11642 |
+
if (!match) {
|
11643 |
+
throw $controllerMinErr('ctrlfmt',
|
11644 |
+
'Badly formed controller string \'{0}\'. ' +
|
11645 |
+
'Must match `__name__ as __id__` or `__name__`.', expression);
|
11646 |
}
|
11647 |
+
constructor = match[1];
|
11648 |
+
identifier = identifier || match[3];
|
11649 |
+
expression = controllers.hasOwnProperty(constructor)
|
11650 |
+
? controllers[constructor]
|
11651 |
+
: getter(locals.$scope, constructor, true);
|
11652 |
|
11653 |
+
if (!expression) {
|
11654 |
+
throw $controllerMinErr('ctrlreg',
|
11655 |
+
'The controller with the name \'{0}\' is not registered.', constructor);
|
11656 |
+
}
|
11657 |
|
11658 |
+
assertArgFn(expression, constructor, true);
|
11659 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11660 |
|
11661 |
+
if (later) {
|
11662 |
+
// Instantiate controller later:
|
11663 |
+
// This machinery is used to create an instance of the object before calling the
|
11664 |
+
// controller's constructor itself.
|
11665 |
+
//
|
11666 |
+
// This allows properties to be added to the controller before the constructor is
|
11667 |
+
// invoked. Primarily, this is used for isolate scope bindings in $compile.
|
11668 |
+
//
|
11669 |
+
// This feature is not intended for use by applications, and is thus not documented
|
11670 |
+
// publicly.
|
11671 |
+
// Object creation: http://jsperf.com/create-constructor/2
|
11672 |
+
var controllerPrototype = (isArray(expression) ?
|
11673 |
+
expression[expression.length - 1] : expression).prototype;
|
11674 |
+
instance = Object.create(controllerPrototype || null);
|
11675 |
|
11676 |
+
if (identifier) {
|
11677 |
+
addIdentifier(locals, identifier, instance, constructor || expression.name);
|
11678 |
+
}
|
|
|
11679 |
|
11680 |
+
return extend(function $controllerInit() {
|
11681 |
+
var result = $injector.invoke(expression, instance, locals, constructor);
|
11682 |
+
if (result !== instance && (isObject(result) || isFunction(result))) {
|
11683 |
+
instance = result;
|
11684 |
+
if (identifier) {
|
11685 |
+
// If result changed, re-assign controllerAs value to scope.
|
11686 |
+
addIdentifier(locals, identifier, instance, constructor || expression.name);
|
11687 |
+
}
|
11688 |
+
}
|
11689 |
+
return instance;
|
11690 |
+
}, {
|
11691 |
+
instance: instance,
|
11692 |
+
identifier: identifier
|
11693 |
+
});
|
11694 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11695 |
|
11696 |
+
instance = $injector.instantiate(expression, locals, constructor);
|
|
|
|
|
|
|
11697 |
|
11698 |
+
if (identifier) {
|
11699 |
+
addIdentifier(locals, identifier, instance, constructor || expression.name);
|
11700 |
+
}
|
11701 |
|
11702 |
+
return instance;
|
11703 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11704 |
|
11705 |
+
function addIdentifier(locals, identifier, instance, name) {
|
11706 |
+
if (!(locals && isObject(locals.$scope))) {
|
11707 |
+
throw minErr('$controller')('noscp',
|
11708 |
+
'Cannot export controller \'{0}\' as \'{1}\'! No $scope object provided via `locals`.',
|
11709 |
+
name, identifier);
|
11710 |
+
}
|
11711 |
|
11712 |
+
locals.$scope[identifier] = instance;
|
|
|
|
|
11713 |
}
|
11714 |
+
}];
|
11715 |
+
}
|
11716 |
|
11717 |
+
/**
|
11718 |
+
* @ngdoc service
|
11719 |
+
* @name $document
|
11720 |
+
* @requires $window
|
11721 |
+
* @this
|
11722 |
+
*
|
11723 |
+
* @description
|
11724 |
+
* A {@link angular.element jQuery or jqLite} wrapper for the browser's `window.document` object.
|
11725 |
+
*
|
11726 |
+
* @example
|
11727 |
+
<example module="documentExample" name="document">
|
11728 |
+
<file name="index.html">
|
11729 |
+
<div ng-controller="ExampleController">
|
11730 |
+
<p>$document title: <b ng-bind="title"></b></p>
|
11731 |
+
<p>window.document title: <b ng-bind="windowTitle"></b></p>
|
11732 |
+
</div>
|
11733 |
+
</file>
|
11734 |
+
<file name="script.js">
|
11735 |
+
angular.module('documentExample', [])
|
11736 |
+
.controller('ExampleController', ['$scope', '$document', function($scope, $document) {
|
11737 |
+
$scope.title = $document[0].title;
|
11738 |
+
$scope.windowTitle = angular.element(window.document)[0].title;
|
11739 |
+
}]);
|
11740 |
+
</file>
|
11741 |
+
</example>
|
11742 |
+
*/
|
11743 |
+
function $DocumentProvider() {
|
11744 |
+
this.$get = ['$window', function(window) {
|
11745 |
+
return jqLite(window.document);
|
11746 |
+
}];
|
11747 |
+
}
|
11748 |
|
|
|
|
|
|
|
|
|
|
|
11749 |
|
11750 |
+
/**
|
11751 |
+
* @private
|
11752 |
+
* @this
|
11753 |
+
* Listens for document visibility change and makes the current status accessible.
|
11754 |
+
*/
|
11755 |
+
function $$IsDocumentHiddenProvider() {
|
11756 |
+
this.$get = ['$document', '$rootScope', function($document, $rootScope) {
|
11757 |
+
var doc = $document[0];
|
11758 |
+
var hidden = doc && doc.hidden;
|
|
|
11759 |
|
11760 |
+
$document.on('visibilitychange', changeListener);
|
11761 |
+
|
11762 |
+
$rootScope.$on('$destroy', function() {
|
11763 |
+
$document.off('visibilitychange', changeListener);
|
11764 |
+
});
|
11765 |
+
|
11766 |
+
function changeListener() {
|
11767 |
+
hidden = doc.hidden;
|
11768 |
}
|
11769 |
|
11770 |
+
return function() {
|
11771 |
+
return hidden;
|
11772 |
+
};
|
11773 |
+
}];
|
11774 |
+
}
|
11775 |
|
11776 |
+
/**
|
11777 |
+
* @ngdoc service
|
11778 |
+
* @name $exceptionHandler
|
11779 |
+
* @requires ng.$log
|
11780 |
+
* @this
|
11781 |
+
*
|
11782 |
+
* @description
|
11783 |
+
* Any uncaught exception in AngularJS expressions is delegated to this service.
|
11784 |
+
* The default implementation simply delegates to `$log.error` which logs it into
|
11785 |
+
* the browser console.
|
11786 |
+
*
|
11787 |
+
* In unit tests, if `angular-mocks.js` is loaded, this service is overridden by
|
11788 |
+
* {@link ngMock.$exceptionHandler mock $exceptionHandler} which aids in testing.
|
11789 |
+
*
|
11790 |
+
* ## Example:
|
11791 |
+
*
|
11792 |
+
* The example below will overwrite the default `$exceptionHandler` in order to (a) log uncaught
|
11793 |
+
* errors to the backend for later inspection by the developers and (b) to use `$log.warn()` instead
|
11794 |
+
* of `$log.error()`.
|
11795 |
+
*
|
11796 |
+
* ```js
|
11797 |
+
* angular.
|
11798 |
+
* module('exceptionOverwrite', []).
|
11799 |
+
* factory('$exceptionHandler', ['$log', 'logErrorsToBackend', function($log, logErrorsToBackend) {
|
11800 |
+
* return function myExceptionHandler(exception, cause) {
|
11801 |
+
* logErrorsToBackend(exception, cause);
|
11802 |
+
* $log.warn(exception, cause);
|
11803 |
+
* };
|
11804 |
+
* }]);
|
11805 |
+
* ```
|
11806 |
+
*
|
11807 |
+
* <hr />
|
11808 |
+
* Note, that code executed in event-listeners (even those registered using jqLite's `on`/`bind`
|
11809 |
+
* methods) does not delegate exceptions to the {@link ng.$exceptionHandler $exceptionHandler}
|
11810 |
+
* (unless executed during a digest).
|
11811 |
+
*
|
11812 |
+
* If you wish, you can manually delegate exceptions, e.g.
|
11813 |
+
* `try { ... } catch(e) { $exceptionHandler(e); }`
|
11814 |
+
*
|
11815 |
+
* @param {Error} exception Exception associated with the error.
|
11816 |
+
* @param {string=} cause Optional information about the context in which
|
11817 |
+
* the error was thrown.
|
11818 |
+
*
|
11819 |
+
*/
|
11820 |
+
function $ExceptionHandlerProvider() {
|
11821 |
+
this.$get = ['$log', function($log) {
|
11822 |
+
return function(exception, cause) {
|
11823 |
+
$log.error.apply($log, arguments);
|
11824 |
+
};
|
11825 |
+
}];
|
11826 |
+
}
|
11827 |
|
11828 |
+
var $$ForceReflowProvider = /** @this */ function() {
|
11829 |
+
this.$get = ['$document', function($document) {
|
11830 |
+
return function(domNode) {
|
11831 |
+
//the line below will force the browser to perform a repaint so
|
11832 |
+
//that all the animated elements within the animation frame will
|
11833 |
+
//be properly updated and drawn on screen. This is required to
|
11834 |
+
//ensure that the preparation animation is properly flushed so that
|
11835 |
+
//the active state picks up from there. DO NOT REMOVE THIS LINE.
|
11836 |
+
//DO NOT OPTIMIZE THIS LINE. THE MINIFIER WILL REMOVE IT OTHERWISE WHICH
|
11837 |
+
//WILL RESULT IN AN UNPREDICTABLE BUG THAT IS VERY HARD TO TRACK DOWN AND
|
11838 |
+
//WILL TAKE YEARS AWAY FROM YOUR LIFE.
|
11839 |
+
if (domNode) {
|
11840 |
+
if (!domNode.nodeType && domNode instanceof jqLite) {
|
11841 |
+
domNode = domNode[0];
|
11842 |
+
}
|
11843 |
+
} else {
|
11844 |
+
domNode = $document[0].body;
|
11845 |
+
}
|
11846 |
+
return domNode.offsetWidth + 1;
|
11847 |
+
};
|
11848 |
+
}];
|
11849 |
+
};
|
11850 |
+
|
11851 |
+
var APPLICATION_JSON = 'application/json';
|
11852 |
+
var CONTENT_TYPE_APPLICATION_JSON = {'Content-Type': APPLICATION_JSON + ';charset=utf-8'};
|
11853 |
+
var JSON_START = /^\[|^\{(?!\{)/;
|
11854 |
+
var JSON_ENDS = {
|
11855 |
+
'[': /]$/,
|
11856 |
+
'{': /}$/
|
11857 |
+
};
|
11858 |
+
var JSON_PROTECTION_PREFIX = /^\)]\}',?\n/;
|
11859 |
+
var $httpMinErr = minErr('$http');
|
11860 |
+
|
11861 |
+
function serializeValue(v) {
|
11862 |
+
if (isObject(v)) {
|
11863 |
+
return isDate(v) ? v.toISOString() : toJson(v);
|
11864 |
+
}
|
11865 |
+
return v;
|
11866 |
+
}
|
11867 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11868 |
|
11869 |
+
/** @this */
|
11870 |
+
function $HttpParamSerializerProvider() {
|
11871 |
+
/**
|
11872 |
+
* @ngdoc service
|
11873 |
+
* @name $httpParamSerializer
|
11874 |
+
* @description
|
11875 |
+
*
|
11876 |
+
* Default {@link $http `$http`} params serializer that converts objects to strings
|
11877 |
+
* according to the following rules:
|
11878 |
+
*
|
11879 |
+
* * `{'foo': 'bar'}` results in `foo=bar`
|
11880 |
+
* * `{'foo': Date.now()}` results in `foo=2015-04-01T09%3A50%3A49.262Z` (`toISOString()` and encoded representation of a Date object)
|
11881 |
+
* * `{'foo': ['bar', 'baz']}` results in `foo=bar&foo=baz` (repeated key for each array element)
|
11882 |
+
* * `{'foo': {'bar':'baz'}}` results in `foo=%7B%22bar%22%3A%22baz%22%7D` (stringified and encoded representation of an object)
|
11883 |
+
*
|
11884 |
+
* Note that serializer will sort the request parameters alphabetically.
|
11885 |
+
*/
|
11886 |
+
|
11887 |
+
this.$get = function() {
|
11888 |
+
return function ngParamSerializer(params) {
|
11889 |
+
if (!params) return '';
|
11890 |
+
var parts = [];
|
11891 |
+
forEachSorted(params, function(value, key) {
|
11892 |
+
if (value === null || isUndefined(value) || isFunction(value)) return;
|
11893 |
+
if (isArray(value)) {
|
11894 |
+
forEach(value, function(v) {
|
11895 |
+
parts.push(encodeUriQuery(key) + '=' + encodeUriQuery(serializeValue(v)));
|
11896 |
+
});
|
11897 |
+
} else {
|
11898 |
+
parts.push(encodeUriQuery(key) + '=' + encodeUriQuery(serializeValue(value)));
|
11899 |
+
}
|
11900 |
+
});
|
11901 |
|
11902 |
+
return parts.join('&');
|
11903 |
+
};
|
11904 |
+
};
|
11905 |
+
}
|
11906 |
|
11907 |
+
/** @this */
|
11908 |
+
function $HttpParamSerializerJQLikeProvider() {
|
11909 |
+
/**
|
11910 |
+
* @ngdoc service
|
11911 |
+
* @name $httpParamSerializerJQLike
|
11912 |
+
*
|
11913 |
+
* @description
|
11914 |
+
*
|
11915 |
+
* Alternative {@link $http `$http`} params serializer that follows
|
11916 |
+
* jQuery's [`param()`](http://api.jquery.com/jquery.param/) method logic.
|
11917 |
+
* The serializer will also sort the params alphabetically.
|
11918 |
+
*
|
11919 |
+
* To use it for serializing `$http` request parameters, set it as the `paramSerializer` property:
|
11920 |
+
*
|
11921 |
+
* ```js
|
11922 |
+
* $http({
|
11923 |
+
* url: myUrl,
|
11924 |
+
* method: 'GET',
|
11925 |
+
* params: myParams,
|
11926 |
+
* paramSerializer: '$httpParamSerializerJQLike'
|
11927 |
+
* });
|
11928 |
+
* ```
|
11929 |
+
*
|
11930 |
+
* It is also possible to set it as the default `paramSerializer` in the
|
11931 |
+
* {@link $httpProvider#defaults `$httpProvider`}.
|
11932 |
+
*
|
11933 |
+
* Additionally, you can inject the serializer and use it explicitly, for example to serialize
|
11934 |
+
* form data for submission:
|
11935 |
+
*
|
11936 |
+
* ```js
|
11937 |
+
* .controller(function($http, $httpParamSerializerJQLike) {
|
11938 |
+
* //...
|
11939 |
+
*
|
11940 |
+
* $http({
|
11941 |
+
* url: myUrl,
|
11942 |
+
* method: 'POST',
|
11943 |
+
* data: $httpParamSerializerJQLike(myData),
|
11944 |
+
* headers: {
|
11945 |
+
* 'Content-Type': 'application/x-www-form-urlencoded'
|
11946 |
+
* }
|
11947 |
+
* });
|
11948 |
+
*
|
11949 |
+
* });
|
11950 |
+
* ```
|
11951 |
+
*
|
11952 |
+
*/
|
11953 |
+
this.$get = function() {
|
11954 |
+
return function jQueryLikeParamSerializer(params) {
|
11955 |
+
if (!params) return '';
|
11956 |
+
var parts = [];
|
11957 |
+
serialize(params, '', true);
|
11958 |
+
return parts.join('&');
|
11959 |
+
|
11960 |
+
function serialize(toSerialize, prefix, topLevel) {
|
11961 |
+
if (isArray(toSerialize)) {
|
11962 |
+
forEach(toSerialize, function(value, index) {
|
11963 |
+
serialize(value, prefix + '[' + (isObject(value) ? index : '') + ']');
|
11964 |
+
});
|
11965 |
+
} else if (isObject(toSerialize) && !isDate(toSerialize)) {
|
11966 |
+
forEachSorted(toSerialize, function(value, key) {
|
11967 |
+
serialize(value, prefix +
|
11968 |
+
(topLevel ? '' : '[') +
|
11969 |
+
key +
|
11970 |
+
(topLevel ? '' : ']'));
|
11971 |
+
});
|
11972 |
+
} else {
|
11973 |
+
if (isFunction(toSerialize)) {
|
11974 |
+
toSerialize = toSerialize();
|
11975 |
+
}
|
11976 |
+
parts.push(encodeUriQuery(prefix) + '=' +
|
11977 |
+
(toSerialize == null ? '' : encodeUriQuery(serializeValue(toSerialize))));
|
11978 |
}
|
11979 |
+
}
|
11980 |
+
};
|
11981 |
+
};
|
11982 |
+
}
|
11983 |
|
11984 |
+
function defaultHttpResponseTransform(data, headers) {
|
11985 |
+
if (isString(data)) {
|
11986 |
+
// Strip json vulnerability protection prefix and trim whitespace
|
11987 |
+
var tempData = data.replace(JSON_PROTECTION_PREFIX, '').trim();
|
11988 |
|
11989 |
+
if (tempData) {
|
11990 |
+
var contentType = headers('Content-Type');
|
11991 |
+
var hasJsonContentType = contentType && (contentType.indexOf(APPLICATION_JSON) === 0);
|
11992 |
+
|
11993 |
+
if (hasJsonContentType || isJsonLike(tempData)) {
|
11994 |
+
try {
|
11995 |
+
data = fromJson(tempData);
|
11996 |
+
} catch (e) {
|
11997 |
+
if (!hasJsonContentType) {
|
11998 |
+
return data;
|
11999 |
+
}
|
12000 |
+
throw $httpMinErr('baddata', 'Data must be a valid JSON object. Received: "{0}". ' +
|
12001 |
+
'Parse error: "{1}"', data, e);
|
12002 |
+
}
|
12003 |
+
}
|
12004 |
}
|
12005 |
+
}
|
12006 |
+
|
12007 |
+
return data;
|
12008 |
+
}
|
12009 |
+
|
12010 |
+
function isJsonLike(str) {
|
12011 |
+
var jsonStart = str.match(JSON_START);
|
12012 |
+
return jsonStart && JSON_ENDS[jsonStart[0]].test(str);
|
12013 |
+
}
|
12014 |
|
12015 |
+
/**
|
12016 |
+
* Parse headers into key value object
|
12017 |
+
*
|
12018 |
+
* @param {string} headers Raw headers as a string
|
12019 |
+
* @returns {Object} Parsed headers as key value object
|
12020 |
+
*/
|
12021 |
+
function parseHeaders(headers) {
|
12022 |
+
var parsed = createMap(), i;
|
12023 |
|
12024 |
+
function fillInParsed(key, val) {
|
12025 |
+
if (key) {
|
12026 |
+
parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
|
12027 |
}
|
12028 |
+
}
|
12029 |
|
12030 |
+
if (isString(headers)) {
|
12031 |
+
forEach(headers.split('\n'), function(line) {
|
12032 |
+
i = line.indexOf(':');
|
12033 |
+
fillInParsed(lowercase(trim(line.substr(0, i))), trim(line.substr(i + 1)));
|
12034 |
+
});
|
12035 |
+
} else if (isObject(headers)) {
|
12036 |
+
forEach(headers, function(headerVal, headerKey) {
|
12037 |
+
fillInParsed(lowercase(headerKey), trim(headerVal));
|
12038 |
+
});
|
12039 |
+
}
|
12040 |
|
12041 |
+
return parsed;
|
12042 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12043 |
|
|
|
|
|
12044 |
|
12045 |
+
/**
|
12046 |
+
* Returns a function that provides access to parsed headers.
|
12047 |
+
*
|
12048 |
+
* Headers are lazy parsed when first requested.
|
12049 |
+
* @see parseHeaders
|
12050 |
+
*
|
12051 |
+
* @param {(string|Object)} headers Headers to provide access to.
|
12052 |
+
* @returns {function(string=)} Returns a getter function which if called with:
|
12053 |
+
*
|
12054 |
+
* - if called with an argument returns a single header value or null
|
12055 |
+
* - if called with no arguments returns an object containing all headers.
|
12056 |
+
*/
|
12057 |
+
function headersGetter(headers) {
|
12058 |
+
var headersObj;
|
12059 |
|
12060 |
+
return function(name) {
|
12061 |
+
if (!headersObj) headersObj = parseHeaders(headers);
|
12062 |
|
12063 |
+
if (name) {
|
12064 |
+
var value = headersObj[lowercase(name)];
|
12065 |
+
if (value === undefined) {
|
12066 |
+
value = null;
|
12067 |
+
}
|
12068 |
+
return value;
|
12069 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12070 |
|
12071 |
+
return headersObj;
|
12072 |
+
};
|
12073 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12074 |
|
12075 |
+
|
12076 |
+
/**
|
12077 |
+
* Chain all given functions
|
12078 |
+
*
|
12079 |
+
* This function is used for both request and response transforming
|
12080 |
+
*
|
12081 |
+
* @param {*} data Data to transform.
|
12082 |
+
* @param {function(string=)} headers HTTP headers getter fn.
|
12083 |
+
* @param {number} status HTTP status code of the response.
|
12084 |
+
* @param {(Function|Array.<Function>)} fns Function or an array of functions.
|
12085 |
+
* @returns {*} Transformed data.
|
12086 |
+
*/
|
12087 |
+
function transformData(data, headers, status, fns) {
|
12088 |
+
if (isFunction(fns)) {
|
12089 |
+
return fns(data, headers, status);
|
12090 |
+
}
|
12091 |
+
|
12092 |
+
forEach(fns, function(fn) {
|
12093 |
+
data = fn(data, headers, status);
|
12094 |
+
});
|
12095 |
+
|
12096 |
+
return data;
|
12097 |
+
}
|
12098 |
+
|
12099 |
+
|
12100 |
+
function isSuccess(status) {
|
12101 |
+
return 200 <= status && status < 300;
|
12102 |
+
}
|
12103 |
+
|
12104 |
+
|
12105 |
+
/**
|
12106 |
+
* @ngdoc provider
|
12107 |
+
* @name $httpProvider
|
12108 |
+
* @this
|
12109 |
+
*
|
12110 |
+
* @description
|
12111 |
+
* Use `$httpProvider` to change the default behavior of the {@link ng.$http $http} service.
|
12112 |
+
*/
|
12113 |
+
function $HttpProvider() {
|
12114 |
+
/**
|
12115 |
+
* @ngdoc property
|
12116 |
+
* @name $httpProvider#defaults
|
12117 |
+
* @description
|
12118 |
+
*
|
12119 |
+
* Object containing default values for all {@link ng.$http $http} requests.
|
12120 |
+
*
|
12121 |
+
* - **`defaults.cache`** - {boolean|Object} - A boolean value or object created with
|
12122 |
+
* {@link ng.$cacheFactory `$cacheFactory`} to enable or disable caching of HTTP responses
|
12123 |
+
* by default. See {@link $http#caching $http Caching} for more information.
|
12124 |
+
*
|
12125 |
+
* - **`defaults.headers`** - {Object} - Default headers for all $http requests.
|
12126 |
+
* Refer to {@link ng.$http#setting-http-headers $http} for documentation on
|
12127 |
+
* setting default headers.
|
12128 |
+
* - **`defaults.headers.common`**
|
12129 |
+
* - **`defaults.headers.post`**
|
12130 |
+
* - **`defaults.headers.put`**
|
12131 |
+
* - **`defaults.headers.patch`**
|
12132 |
+
*
|
12133 |
+
* - **`defaults.jsonpCallbackParam`** - `{string}` - the name of the query parameter that passes the name of the
|
12134 |
+
* callback in a JSONP request. The value of this parameter will be replaced with the expression generated by the
|
12135 |
+
* {@link $jsonpCallbacks} service. Defaults to `'callback'`.
|
12136 |
+
*
|
12137 |
+
* - **`defaults.paramSerializer`** - `{string|function(Object<string,string>):string}` - A function
|
12138 |
+
* used to the prepare string representation of request parameters (specified as an object).
|
12139 |
+
* If specified as string, it is interpreted as a function registered with the {@link auto.$injector $injector}.
|
12140 |
+
* Defaults to {@link ng.$httpParamSerializer $httpParamSerializer}.
|
12141 |
+
*
|
12142 |
+
* - **`defaults.transformRequest`** -
|
12143 |
+
* `{Array<function(data, headersGetter)>|function(data, headersGetter)}` -
|
12144 |
+
* An array of functions (or a single function) which are applied to the request data.
|
12145 |
+
* By default, this is an array with one request transformation function:
|
12146 |
+
*
|
12147 |
+
* - If the `data` property of the request configuration object contains an object, serialize it
|
12148 |
+
* into JSON format.
|
12149 |
+
*
|
12150 |
+
* - **`defaults.transformResponse`** -
|
12151 |
+
* `{Array<function(data, headersGetter, status)>|function(data, headersGetter, status)}` -
|
12152 |
+
* An array of functions (or a single function) which are applied to the response data. By default,
|
12153 |
+
* this is an array which applies one response transformation function that does two things:
|
12154 |
+
*
|
12155 |
+
* - If XSRF prefix is detected, strip it
|
12156 |
+
* (see {@link ng.$http#security-considerations Security Considerations in the $http docs}).
|
12157 |
+
* - If the `Content-Type` is `application/json` or the response looks like JSON,
|
12158 |
+
* deserialize it using a JSON parser.
|
12159 |
+
*
|
12160 |
+
* - **`defaults.xsrfCookieName`** - {string} - Name of cookie containing the XSRF token.
|
12161 |
+
* Defaults value is `'XSRF-TOKEN'`.
|
12162 |
+
*
|
12163 |
+
* - **`defaults.xsrfHeaderName`** - {string} - Name of HTTP header to populate with the
|
12164 |
+
* XSRF token. Defaults value is `'X-XSRF-TOKEN'`.
|
12165 |
+
*
|
12166 |
+
*/
|
12167 |
+
var defaults = this.defaults = {
|
12168 |
+
// transform incoming response data
|
12169 |
+
transformResponse: [defaultHttpResponseTransform],
|
12170 |
+
|
12171 |
+
// transform outgoing request data
|
12172 |
+
transformRequest: [function(d) {
|
12173 |
+
return isObject(d) && !isFile(d) && !isBlob(d) && !isFormData(d) ? toJson(d) : d;
|
12174 |
+
}],
|
12175 |
+
|
12176 |
+
// default headers
|
12177 |
+
headers: {
|
12178 |
+
common: {
|
12179 |
+
'Accept': 'application/json, text/plain, */*'
|
12180 |
+
},
|
12181 |
+
post: shallowCopy(CONTENT_TYPE_APPLICATION_JSON),
|
12182 |
+
put: shallowCopy(CONTENT_TYPE_APPLICATION_JSON),
|
12183 |
+
patch: shallowCopy(CONTENT_TYPE_APPLICATION_JSON)
|
12184 |
+
},
|
12185 |
+
|
12186 |
+
xsrfCookieName: 'XSRF-TOKEN',
|
12187 |
+
xsrfHeaderName: 'X-XSRF-TOKEN',
|
12188 |
+
|
12189 |
+
paramSerializer: '$httpParamSerializer',
|
12190 |
+
|
12191 |
+
jsonpCallbackParam: 'callback'
|
12192 |
+
};
|
12193 |
+
|
12194 |
+
var useApplyAsync = false;
|
12195 |
+
/**
|
12196 |
+
* @ngdoc method
|
12197 |
+
* @name $httpProvider#useApplyAsync
|
12198 |
+
* @description
|
12199 |
+
*
|
12200 |
+
* Configure $http service to combine processing of multiple http responses received at around
|
12201 |
+
* the same time via {@link ng.$rootScope.Scope#$applyAsync $rootScope.$applyAsync}. This can result in
|
12202 |
+
* significant performance improvement for bigger applications that make many HTTP requests
|
12203 |
+
* concurrently (common during application bootstrap).
|
12204 |
+
*
|
12205 |
+
* Defaults to false. If no value is specified, returns the current configured value.
|
12206 |
+
*
|
12207 |
+
* @param {boolean=} value If true, when requests are loaded, they will schedule a deferred
|
12208 |
+
* "apply" on the next tick, giving time for subsequent requests in a roughly ~10ms window
|
12209 |
+
* to load and share the same digest cycle.
|
12210 |
+
*
|
12211 |
+
* @returns {boolean|Object} If a value is specified, returns the $httpProvider for chaining.
|
12212 |
+
* otherwise, returns the current configured value.
|
12213 |
+
*/
|
12214 |
+
this.useApplyAsync = function(value) {
|
12215 |
+
if (isDefined(value)) {
|
12216 |
+
useApplyAsync = !!value;
|
12217 |
+
return this;
|
12218 |
+
}
|
12219 |
+
return useApplyAsync;
|
12220 |
+
};
|
12221 |
+
|
12222 |
+
/**
|
12223 |
+
* @ngdoc property
|
12224 |
+
* @name $httpProvider#interceptors
|
12225 |
+
* @description
|
12226 |
+
*
|
12227 |
+
* Array containing service factories for all synchronous or asynchronous {@link ng.$http $http}
|
12228 |
+
* pre-processing of request or postprocessing of responses.
|
12229 |
+
*
|
12230 |
+
* These service factories are ordered by request, i.e. they are applied in the same order as the
|
12231 |
+
* array, on request, but reverse order, on response.
|
12232 |
+
*
|
12233 |
+
* {@link ng.$http#interceptors Interceptors detailed info}
|
12234 |
+
*/
|
12235 |
+
var interceptorFactories = this.interceptors = [];
|
12236 |
+
|
12237 |
+
/**
|
12238 |
+
* @ngdoc property
|
12239 |
+
* @name $httpProvider#xsrfWhitelistedOrigins
|
12240 |
+
* @description
|
12241 |
+
*
|
12242 |
+
* Array containing URLs whose origins are trusted to receive the XSRF token. See the
|
12243 |
+
* {@link ng.$http#security-considerations Security Considerations} sections for more details on
|
12244 |
+
* XSRF.
|
12245 |
+
*
|
12246 |
+
* **Note:** An "origin" consists of the [URI scheme](https://en.wikipedia.org/wiki/URI_scheme),
|
12247 |
+
* the [hostname](https://en.wikipedia.org/wiki/Hostname) and the
|
12248 |
+
* [port number](https://en.wikipedia.org/wiki/Port_(computer_networking). For `http:` and
|
12249 |
+
* `https:`, the port number can be omitted if using th default ports (80 and 443 respectively).
|
12250 |
+
* Examples: `http://example.com`, `https://api.example.com:9876`
|
12251 |
+
*
|
12252 |
+
* <div class="alert alert-warning">
|
12253 |
+
* It is not possible to whitelist specific URLs/paths. The `path`, `query` and `fragment` parts
|
12254 |
+
* of a URL will be ignored. For example, `https://foo.com/path/bar?query=baz#fragment` will be
|
12255 |
+
* treated as `https://foo.com`, meaning that **all** requests to URLs starting with
|
12256 |
+
* `https://foo.com/` will include the XSRF token.
|
12257 |
+
* </div>
|
12258 |
+
*
|
12259 |
+
* @example
|
12260 |
+
*
|
12261 |
+
* ```js
|
12262 |
+
* // App served from `https://example.com/`.
|
12263 |
+
* angular.
|
12264 |
+
* module('xsrfWhitelistedOriginsExample', []).
|
12265 |
+
* config(['$httpProvider', function($httpProvider) {
|
12266 |
* $httpProvider.xsrfWhitelistedOrigins.push('https://api.example.com');
|
12267 |
* }]).
|
12268 |
+
* run(['$http', function($http) {
|
12269 |
* // The XSRF token will be sent.
|
12270 |
* $http.get('https://api.example.com/preferences').then(...);
|
12271 |
*
|
12272 |
* // The XSRF token will NOT be sent.
|
12273 |
* $http.get('https://stats.example.com/activity').then(...);
|
12274 |
* }]);
|
12275 |
+
* ```
|
12276 |
+
*/
|
12277 |
+
var xsrfWhitelistedOrigins = this.xsrfWhitelistedOrigins = [];
|
12278 |
|
12279 |
+
this.$get = ['$browser', '$httpBackend', '$$cookieReader', '$cacheFactory', '$rootScope', '$q', '$injector', '$sce',
|
12280 |
+
function($browser, $httpBackend, $$cookieReader, $cacheFactory, $rootScope, $q, $injector, $sce) {
|
12281 |
|
12282 |
+
var defaultCache = $cacheFactory('$http');
|
12283 |
|
12284 |
+
/**
|
12285 |
+
* Make sure that default param serializer is exposed as a function
|
12286 |
+
*/
|
12287 |
+
defaults.paramSerializer = isString(defaults.paramSerializer) ?
|
12288 |
+
$injector.get(defaults.paramSerializer) : defaults.paramSerializer;
|
12289 |
+
|
12290 |
+
/**
|
12291 |
+
* Interceptors stored in reverse order. Inner interceptors before outer interceptors.
|
12292 |
+
* The reversal is needed so that we can build up the interception chain around the
|
12293 |
+
* server request.
|
12294 |
+
*/
|
12295 |
+
var reversedInterceptors = [];
|
12296 |
|
12297 |
+
forEach(interceptorFactories, function(interceptorFactory) {
|
12298 |
+
reversedInterceptors.unshift(isString(interceptorFactory)
|
12299 |
+
? $injector.get(interceptorFactory) : $injector.invoke(interceptorFactory));
|
12300 |
+
});
|
|
|
|
|
12301 |
|
12302 |
+
/**
|
12303 |
+
* A function to check request URLs against a list of allowed origins.
|
12304 |
+
*/
|
12305 |
+
var urlIsAllowedOrigin = urlIsAllowedOriginFactory(xsrfWhitelistedOrigins);
|
12306 |
|
12307 |
+
/**
|
12308 |
+
* @ngdoc service
|
12309 |
+
* @kind function
|
12310 |
+
* @name $http
|
12311 |
+
* @requires ng.$httpBackend
|
12312 |
+
* @requires $cacheFactory
|
12313 |
+
* @requires $rootScope
|
12314 |
+
* @requires $q
|
12315 |
+
* @requires $injector
|
12316 |
+
*
|
12317 |
+
* @description
|
12318 |
+
* The `$http` service is a core AngularJS service that facilitates communication with the remote
|
12319 |
+
* HTTP servers via the browser's [XMLHttpRequest](https://developer.mozilla.org/en/xmlhttprequest)
|
12320 |
+
* object or via [JSONP](http://en.wikipedia.org/wiki/JSONP).
|
12321 |
+
*
|
12322 |
+
* For unit testing applications that use `$http` service, see
|
12323 |
+
* {@link ngMock.$httpBackend $httpBackend mock}.
|
12324 |
+
*
|
12325 |
+
* For a higher level of abstraction, please check out the {@link ngResource.$resource
|
|
|
|
|
|
|
|
|
|
|
12326 |
* $resource} service.
|
12327 |
+
*
|
12328 |
+
* The $http API is based on the {@link ng.$q deferred/promise APIs} exposed by
|
12329 |
+
* the $q service. While for simple usage patterns this doesn't matter much, for advanced usage
|
12330 |
+
* it is important to familiarize yourself with these APIs and the guarantees they provide.
|
12331 |
+
*
|
12332 |
+
*
|
12333 |
+
* ## General usage
|
12334 |
+
* The `$http` service is a function which takes a single argument — a {@link $http#usage configuration object} —
|
12335 |
+
* that is used to generate an HTTP request and returns a {@link ng.$q promise} that is
|
12336 |
+
* resolved (request success) or rejected (request failure) with a
|
12337 |
+
* {@link ng.$http#$http-returns response} object.
|
12338 |
+
*
|
12339 |
+
* ```js
|
12340 |
+
* // Simple GET request example:
|
12341 |
+
* $http({
|
12342 |
* method: 'GET',
|
12343 |
* url: '/someUrl'
|
12344 |
* }).then(function successCallback(response) {
|
12348 |
* // called asynchronously if an error occurs
|
12349 |
* // or server returns response with an error status.
|
12350 |
* });
|
12351 |
+
* ```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12352 |
*
|
|
|
|
|
12353 |
*
|
12354 |
+
* ## Shortcut methods
|
12355 |
+
*
|
12356 |
+
* Shortcut methods are also available. All shortcut methods require passing in the URL, and
|
12357 |
+
* request data must be passed in for POST/PUT requests. An optional config can be passed as the
|
12358 |
+
* last argument.
|
12359 |
+
*
|
12360 |
+
* ```js
|
12361 |
+
* $http.get('/someUrl', config).then(successCallback, errorCallback);
|
12362 |
+
* $http.post('/someUrl', data, config).then(successCallback, errorCallback);
|
12363 |
+
* ```
|
12364 |
+
*
|
12365 |
+
* Complete list of shortcut methods:
|
12366 |
+
*
|
12367 |
+
* - {@link ng.$http#get $http.get}
|
12368 |
+
* - {@link ng.$http#head $http.head}
|
12369 |
+
* - {@link ng.$http#post $http.post}
|
12370 |
+
* - {@link ng.$http#put $http.put}
|
12371 |
+
* - {@link ng.$http#delete $http.delete}
|
12372 |
+
* - {@link ng.$http#jsonp $http.jsonp}
|
12373 |
+
* - {@link ng.$http#patch $http.patch}
|
12374 |
+
*
|
12375 |
+
*
|
12376 |
+
* ## Writing Unit Tests that use $http
|
12377 |
+
* When unit testing (using {@link ngMock ngMock}), it is necessary to call
|
12378 |
+
* {@link ngMock.$httpBackend#flush $httpBackend.flush()} to flush each pending
|
12379 |
+
* request using trained responses.
|
12380 |
+
*
|
12381 |
+
* ```
|
12382 |
+
* $httpBackend.expectGET(...);
|
12383 |
+
* $http.get(...);
|
12384 |
+
* $httpBackend.flush();
|
12385 |
+
* ```
|
12386 |
+
*
|
12387 |
+
* ## Setting HTTP Headers
|
12388 |
+
*
|
12389 |
+
* The $http service will automatically add certain HTTP headers to all requests. These defaults
|
12390 |
+
* can be fully configured by accessing the `$httpProvider.defaults.headers` configuration
|
12391 |
+
* object, which currently contains this default configuration:
|
12392 |
+
*
|
12393 |
+
* - `$httpProvider.defaults.headers.common` (headers that are common for all requests):
|
12394 |
+
* - <code>Accept: application/json, text/plain, \*/\*</code>
|
12395 |
+
* - `$httpProvider.defaults.headers.post`: (header defaults for POST requests)
|
12396 |
+
* - `Content-Type: application/json`
|
12397 |
+
* - `$httpProvider.defaults.headers.put` (header defaults for PUT requests)
|
12398 |
+
* - `Content-Type: application/json`
|
12399 |
+
*
|
12400 |
+
* To add or overwrite these defaults, simply add or remove a property from these configuration
|
12401 |
+
* objects. To add headers for an HTTP method other than POST or PUT, simply add a new object
|
12402 |
+
* with the lowercased HTTP method name as the key, e.g.
|
12403 |
+
* `$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }`.
|
12404 |
+
*
|
12405 |
+
* The defaults can also be set at runtime via the `$http.defaults` object in the same
|
12406 |
+
* fashion. For example:
|
12407 |
+
*
|
12408 |
+
* ```
|
12409 |
+
* module.run(function($http) {
|
12410 |
+
* $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
|
12411 |
+
* });
|
12412 |
+
* ```
|
12413 |
+
*
|
12414 |
+
* In addition, you can supply a `headers` property in the config object passed when
|
12415 |
+
* calling `$http(config)`, which overrides the defaults without changing them globally.
|
12416 |
+
*
|
12417 |
+
* To explicitly remove a header automatically added via $httpProvider.defaults.headers on a per request basis,
|
12418 |
+
* Use the `headers` property, setting the desired header to `undefined`. For example:
|
12419 |
+
*
|
12420 |
+
* ```js
|
12421 |
+
* var req = {
|
12422 |
+
* method: 'POST',
|
12423 |
+
* url: 'http://example.com',
|
12424 |
+
* headers: {
|
12425 |
+
* 'Content-Type': undefined
|
12426 |
+
* },
|
12427 |
+
* data: { test: 'test' }
|
12428 |
+
* }
|
12429 |
+
*
|
12430 |
+
* $http(req).then(function(){...}, function(){...});
|
12431 |
+
* ```
|
12432 |
+
*
|
12433 |
+
* ## Transforming Requests and Responses
|
12434 |
+
*
|
12435 |
+
* Both requests and responses can be transformed using transformation functions: `transformRequest`
|
12436 |
+
* and `transformResponse`. These properties can be a single function that returns
|
12437 |
+
* the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions,
|
12438 |
+
* which allows you to `push` or `unshift` a new transformation function into the transformation chain.
|
12439 |
+
*
|
12440 |
+
* <div class="alert alert-warning">
|
12441 |
+
* **Note:** AngularJS does not make a copy of the `data` parameter before it is passed into the `transformRequest` pipeline.
|
12442 |
+
* That means changes to the properties of `data` are not local to the transform function (since Javascript passes objects by reference).
|
12443 |
+
* For example, when calling `$http.get(url, $scope.myObject)`, modifications to the object's properties in a transformRequest
|
12444 |
+
* function will be reflected on the scope and in any templates where the object is data-bound.
|
12445 |
+
* To prevent this, transform functions should have no side-effects.
|
12446 |
+
* If you need to modify properties, it is recommended to make a copy of the data, or create new object to return.
|
12447 |
+
* </div>
|
12448 |
+
*
|
12449 |
+
* ### Default Transformations
|
12450 |
+
*
|
12451 |
+
* The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and
|
12452 |
+
* `defaults.transformResponse` properties. If a request does not provide its own transformations
|
12453 |
+
* then these will be applied.
|
12454 |
+
*
|
12455 |
+
* You can augment or replace the default transformations by modifying these properties by adding to or
|
12456 |
+
* replacing the array.
|
12457 |
+
*
|
12458 |
+
* AngularJS provides the following default transformations:
|
12459 |
+
*
|
12460 |
+
* Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`) is
|
12461 |
+
* an array with one function that does the following:
|
12462 |
+
*
|
12463 |
+
* - If the `data` property of the request configuration object contains an object, serialize it
|
12464 |
+
* into JSON format.
|
12465 |
+
*
|
12466 |
+
* Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`) is
|
12467 |
+
* an array with one function that does the following:
|
12468 |
+
*
|
12469 |
+
* - If XSRF prefix is detected, strip it (see Security Considerations section below).
|
12470 |
+
* - If the `Content-Type` is `application/json` or the response looks like JSON,
|
12471 |
+
* deserialize it using a JSON parser.
|
12472 |
+
*
|
12473 |
+
*
|
12474 |
+
* ### Overriding the Default Transformations Per Request
|
12475 |
+
*
|
12476 |
+
* If you wish to override the request/response transformations only for a single request then provide
|
12477 |
+
* `transformRequest` and/or `transformResponse` properties on the configuration object passed
|
12478 |
+
* into `$http`.
|
12479 |
+
*
|
12480 |
+
* Note that if you provide these properties on the config object the default transformations will be
|
12481 |
+
* overwritten. If you wish to augment the default transformations then you must include them in your
|
12482 |
+
* local transformation array.
|
12483 |
+
*
|
12484 |
+
* The following code demonstrates adding a new response transformation to be run after the default response
|
12485 |
+
* transformations have been run.
|
12486 |
+
*
|
12487 |
+
* ```js
|
12488 |
+
* function appendTransform(defaults, transform) {
|
12489 |
+
*
|
12490 |
+
* // We can't guarantee that the default transformation is an array
|
12491 |
+
* defaults = angular.isArray(defaults) ? defaults : [defaults];
|
12492 |
+
*
|
12493 |
+
* // Append the new transformation to the defaults
|
12494 |
+
* return defaults.concat(transform);
|
12495 |
+
* }
|
12496 |
+
*
|
12497 |
+
* $http({
|
12498 |
+
* url: '...',
|
12499 |
+
* method: 'GET',
|
12500 |
+
* transformResponse: appendTransform($http.defaults.transformResponse, function(value) {
|
12501 |
* return doTransform(value);
|
12502 |
* })
|
12503 |
* });
|
12504 |
+
* ```
|
12505 |
+
*
|
12506 |
+
*
|
12507 |
+
* ## Caching
|
12508 |
+
*
|
12509 |
+
* {@link ng.$http `$http`} responses are not cached by default. To enable caching, you must
|
12510 |
+
* set the config.cache value or the default cache value to TRUE or to a cache object (created
|
12511 |
+
* with {@link ng.$cacheFactory `$cacheFactory`}). If defined, the value of config.cache takes
|
12512 |
+
* precedence over the default cache value.
|
12513 |
+
*
|
12514 |
+
* In order to:
|
12515 |
+
* * cache all responses - set the default cache value to TRUE or to a cache object
|
12516 |
+
* * cache a specific response - set config.cache value to TRUE or to a cache object
|
12517 |
+
*
|
12518 |
+
* If caching is enabled, but neither the default cache nor config.cache are set to a cache object,
|
12519 |
+
* then the default `$cacheFactory("$http")` object is used.
|
12520 |
+
*
|
12521 |
+
* The default cache value can be set by updating the
|
12522 |
+
* {@link ng.$http#defaults `$http.defaults.cache`} property or the
|
12523 |
+
* {@link $httpProvider#defaults `$httpProvider.defaults.cache`} property.
|
12524 |
+
*
|
12525 |
+
* When caching is enabled, {@link ng.$http `$http`} stores the response from the server using
|
12526 |
+
* the relevant cache object. The next time the same request is made, the response is returned
|
12527 |
+
* from the cache without sending a request to the server.
|
12528 |
+
*
|
12529 |
+
* Take note that:
|
12530 |
+
*
|
12531 |
+
* * Only GET and JSONP requests are cached.
|
12532 |
+
* * The cache key is the request URL including search parameters; headers are not considered.
|
12533 |
+
* * Cached responses are returned asynchronously, in the same way as responses from the server.
|
12534 |
+
* * If multiple identical requests are made using the same cache, which is not yet populated,
|
12535 |
+
* one request will be made to the server and remaining requests will return the same response.
|
12536 |
+
* * A cache-control header on the response does not affect if or how responses are cached.
|
12537 |
+
*
|
12538 |
+
*
|
12539 |
+
* ## Interceptors
|
12540 |
+
*
|
12541 |
+
* Before you start creating interceptors, be sure to understand the
|
12542 |
+
* {@link ng.$q $q and deferred/promise APIs}.
|
12543 |
+
*
|
12544 |
+
* For purposes of global error handling, authentication, or any kind of synchronous or
|
12545 |
+
* asynchronous pre-processing of request or postprocessing of responses, it is desirable to be
|
12546 |
+
* able to intercept requests before they are handed to the server and
|
12547 |
+
* responses before they are handed over to the application code that
|
12548 |
+
* initiated these requests. The interceptors leverage the {@link ng.$q
|
12549 |
* promise APIs} to fulfill this need for both synchronous and asynchronous pre-processing.
|
12550 |
+
*
|
12551 |
+
* The interceptors are service factories that are registered with the `$httpProvider` by
|
12552 |
+
* adding them to the `$httpProvider.interceptors` array. The factory is called and
|
12553 |
+
* injected with dependencies (if specified) and returns the interceptor.
|
12554 |
+
*
|
12555 |
+
* There are two kinds of interceptors (and two kinds of rejection interceptors):
|
12556 |
+
*
|
12557 |
+
* * `request`: interceptors get called with a http {@link $http#usage config} object. The function is free to
|
12558 |
+
* modify the `config` object or create a new one. The function needs to return the `config`
|
12559 |
+
* object directly, or a promise containing the `config` or a new `config` object.
|
12560 |
+
* * `requestError`: interceptor gets called when a previous interceptor threw an error or
|
12561 |
+
* resolved with a rejection.
|
12562 |
+
* * `response`: interceptors get called with http `response` object. The function is free to
|
12563 |
+
* modify the `response` object or create a new one. The function needs to return the `response`
|
12564 |
+
* object directly, or as a promise containing the `response` or a new `response` object.
|
12565 |
+
* * `responseError`: interceptor gets called when a previous interceptor threw an error or
|
12566 |
+
* resolved with a rejection.
|
12567 |
+
*
|
12568 |
+
*
|
12569 |
+
* ```js
|
12570 |
+
* // register the interceptor as a service
|
12571 |
+
* $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
|
12572 |
* return {
|
12573 |
* // optional method
|
12574 |
* 'request': function(config) {
|
12603 |
* }
|
12604 |
* };
|
12605 |
* });
|
12606 |
+
*
|
12607 |
+
* $httpProvider.interceptors.push('myHttpInterceptor');
|
12608 |
+
*
|
12609 |
+
*
|
12610 |
+
* // alternatively, register the interceptor via an anonymous factory
|
12611 |
+
* $httpProvider.interceptors.push(function($q, dependency1, dependency2) {
|
12612 |
* return {
|
12613 |
* 'request': function(config) {
|
12614 |
* // same as above
|
12619 |
* }
|
12620 |
* };
|
12621 |
* });
|
12622 |
+
* ```
|
12623 |
+
*
|
12624 |
+
* ## Security Considerations
|
12625 |
+
*
|
12626 |
+
* When designing web applications, consider security threats from:
|
12627 |
+
*
|
12628 |
+
* - [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
|
12629 |
+
* - [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
|
12630 |
+
*
|
12631 |
+
* Both server and the client must cooperate in order to eliminate these threats. AngularJS comes
|
12632 |
+
* pre-configured with strategies that address these issues, but for this to work backend server
|
12633 |
+
* cooperation is required.
|
12634 |
+
*
|
12635 |
+
* ### JSON Vulnerability Protection
|
12636 |
+
*
|
12637 |
+
* A [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
|
12638 |
+
* allows third party website to turn your JSON resource URL into
|
12639 |
+
* [JSONP](http://en.wikipedia.org/wiki/JSONP) request under some conditions. To
|
12640 |
+
* counter this your server can prefix all JSON requests with following string `")]}',\n"`.
|
12641 |
+
* AngularJS will automatically strip the prefix before processing it as JSON.
|
12642 |
+
*
|
12643 |
+
* For example if your server needs to return:
|
12644 |
+
* ```js
|
12645 |
+
* ['one','two']
|
12646 |
+
* ```
|
12647 |
+
*
|
12648 |
+
* which is vulnerable to attack, your server can return:
|
12649 |
+
* ```js
|
12650 |
+
* )]}',
|
12651 |
+
* ['one','two']
|
12652 |
+
* ```
|
12653 |
+
*
|
12654 |
+
* AngularJS will strip the prefix, before processing the JSON.
|
12655 |
+
*
|
12656 |
+
*
|
12657 |
+
* ### Cross Site Request Forgery (XSRF) Protection
|
12658 |
+
*
|
12659 |
+
* [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) is an attack technique by
|
12660 |
+
* which the attacker can trick an authenticated user into unknowingly executing actions on your
|
12661 |
+
* website. AngularJS provides a mechanism to counter XSRF. When performing XHR requests, the
|
12662 |
+
* $http service reads a token from a cookie (by default, `XSRF-TOKEN`) and sets it as an HTTP
|
12663 |
+
* header (by default `X-XSRF-TOKEN`). Since only JavaScript that runs on your domain could read
|
12664 |
+
* the cookie, your server can be assured that the XHR came from JavaScript running on your
|
12665 |
+
* domain.
|
12666 |
+
*
|
12667 |
+
* To take advantage of this, your server needs to set a token in a JavaScript readable session
|
12668 |
+
* cookie called `XSRF-TOKEN` on the first HTTP GET request. On subsequent XHR requests the
|
12669 |
+
* server can verify that the cookie matches the `X-XSRF-TOKEN` HTTP header, and therefore be
|
12670 |
+
* sure that only JavaScript running on your domain could have sent the request. The token must
|
12671 |
+
* be unique for each user and must be verifiable by the server (to prevent the JavaScript from
|
12672 |
+
* making up its own tokens). We recommend that the token is a digest of your site's
|
12673 |
+
* authentication cookie with a [salt](https://en.wikipedia.org/wiki/Salt_(cryptography))
|
12674 |
+
* for added security.
|
12675 |
+
*
|
12676 |
+
* The header will — by default — **not** be set for cross-domain requests. This
|
12677 |
+
* prevents unauthorized servers (e.g. malicious or compromised 3rd-party APIs) from gaining
|
12678 |
+
* access to your users' XSRF tokens and exposing them to Cross Site Request Forgery. If you
|
12679 |
+
* want to, you can whitelist additional origins to also receive the XSRF token, by adding them
|
12680 |
+
* to {@link ng.$httpProvider#xsrfWhitelistedOrigins xsrfWhitelistedOrigins}. This might be
|
12681 |
+
* useful, for example, if your application, served from `example.com`, needs to access your API
|
12682 |
+
* at `api.example.com`.
|
12683 |
+
* See {@link ng.$httpProvider#xsrfWhitelistedOrigins $httpProvider.xsrfWhitelistedOrigins} for
|
12684 |
+
* more details.
|
12685 |
+
*
|
12686 |
+
* <div class="alert alert-danger">
|
12687 |
+
* **Warning**<br />
|
12688 |
+
* Only whitelist origins that you have control over and make sure you understand the
|
12689 |
+
* implications of doing so.
|
12690 |
+
* </div>
|
12691 |
+
*
|
12692 |
+
* The name of the cookie and the header can be specified using the `xsrfCookieName` and
|
12693 |
+
* `xsrfHeaderName` properties of either `$httpProvider.defaults` at config-time,
|
12694 |
+
* `$http.defaults` at run-time, or the per-request config object.
|
12695 |
+
*
|
12696 |
+
* In order to prevent collisions in environments where multiple AngularJS apps share the
|
12697 |
+
* same domain or subdomain, we recommend that each application uses a unique cookie name.
|
12698 |
+
*
|
12699 |
+
*
|
12700 |
+
* @param {object} config Object describing the request to be made and how it should be
|
12701 |
+
* processed. The object has following properties:
|
12702 |
+
*
|
12703 |
+
* - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc)
|
12704 |
+
* - **url** – `{string|TrustedObject}` – Absolute or relative URL of the resource that is being requested;
|
12705 |
+
* or an object created by a call to `$sce.trustAsResourceUrl(url)`.
|
12706 |
+
* - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be serialized
|
12707 |
+
* with the `paramSerializer` and appended as GET parameters.
|
12708 |
+
* - **data** – `{string|Object}` – Data to be sent as the request message data.
|
12709 |
+
* - **headers** – `{Object}` – Map of strings or functions which return strings representing
|
12710 |
+
* HTTP headers to send to the server. If the return value of a function is null, the
|
12711 |
+
* header will not be sent. Functions accept a config object as an argument.
|
12712 |
+
* - **eventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest object.
|
12713 |
+
* To bind events to the XMLHttpRequest upload object, use `uploadEventHandlers`.
|
12714 |
+
* The handler will be called in the context of a `$apply` block.
|
12715 |
+
* - **uploadEventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest upload
|
12716 |
+
* object. To bind events to the XMLHttpRequest object, use `eventHandlers`.
|
12717 |
+
* The handler will be called in the context of a `$apply` block.
|
12718 |
+
* - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token.
|
12719 |
+
* - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token.
|
12720 |
+
* - **transformRequest** –
|
12721 |
+
* `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
|
12722 |
+
* transform function or an array of such functions. The transform function takes the http
|
12723 |
+
* request body and headers and returns its transformed (typically serialized) version.
|
12724 |
+
* See {@link ng.$http#overriding-the-default-transformations-per-request
|
12725 |
* Overriding the Default Transformations}
|
12726 |
+
* - **transformResponse** –
|
12727 |
+
* `{function(data, headersGetter, status)|Array.<function(data, headersGetter, status)>}` –
|
12728 |
+
* transform function or an array of such functions. The transform function takes the http
|
12729 |
+
* response body, headers and status and returns its transformed (typically deserialized) version.
|
12730 |
+
* See {@link ng.$http#overriding-the-default-transformations-per-request
|
12731 |
* Overriding the Default Transformations}
|
12732 |
+
* - **paramSerializer** - `{string|function(Object<string,string>):string}` - A function used to
|
12733 |
+
* prepare the string representation of request parameters (specified as an object).
|
12734 |
+
* If specified as string, it is interpreted as function registered with the
|
12735 |
+
* {@link $injector $injector}, which means you can create your own serializer
|
12736 |
+
* by registering it as a {@link auto.$provide#service service}.
|
12737 |
+
* The default serializer is the {@link $httpParamSerializer $httpParamSerializer};
|
12738 |
+
* alternatively, you can use the {@link $httpParamSerializerJQLike $httpParamSerializerJQLike}
|
12739 |
+
* - **cache** – `{boolean|Object}` – A boolean value or object created with
|
12740 |
+
* {@link ng.$cacheFactory `$cacheFactory`} to enable or disable caching of the HTTP response.
|
12741 |
+
* See {@link $http#caching $http Caching} for more information.
|
12742 |
+
* - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise}
|
12743 |
+
* that should abort the request when resolved.
|
12744 |
+
*
|
12745 |
+
* A numerical timeout or a promise returned from {@link ng.$timeout $timeout}, will set
|
12746 |
+
* the `xhrStatus` in the {@link $http#$http-returns response} to "timeout", and any other
|
12747 |
+
* resolved promise will set it to "abort", following standard XMLHttpRequest behavior.
|
12748 |
+
*
|
12749 |
+
* - **withCredentials** - `{boolean}` - whether to set the `withCredentials` flag on the
|
12750 |
+
* XHR object. See [requests with credentials](https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials)
|
12751 |
+
* for more information.
|
12752 |
+
* - **responseType** - `{string}` - see
|
12753 |
+
* [XMLHttpRequest.responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#xmlhttprequest-responsetype).
|
12754 |
+
*
|
12755 |
+
* @returns {HttpPromise} A {@link ng.$q `Promise}` that will be resolved (request success)
|
12756 |
+
* or rejected (request failure) with a response object.
|
12757 |
+
*
|
12758 |
+
* The response object has these properties:
|
12759 |
+
*
|
12760 |
+
* - **data** – `{string|Object}` – The response body transformed with
|
12761 |
+
* the transform functions.
|
12762 |
+
* - **status** – `{number}` – HTTP status code of the response.
|
12763 |
+
* - **headers** – `{function([headerName])}` – Header getter function.
|
12764 |
+
* - **config** – `{Object}` – The configuration object that was used
|
12765 |
+
* to generate the request.
|
12766 |
+
* - **statusText** – `{string}` – HTTP status text of the response.
|
12767 |
+
* - **xhrStatus** – `{string}` – Status of the XMLHttpRequest
|
12768 |
+
* (`complete`, `error`, `timeout` or `abort`).
|
12769 |
+
*
|
12770 |
+
*
|
12771 |
+
* A response status code between 200 and 299 is considered a success status
|
12772 |
+
* and will result in the success callback being called. Any response status
|
12773 |
+
* code outside of that range is considered an error status and will result
|
12774 |
+
* in the error callback being called.
|
12775 |
+
* Also, status codes less than -1 are normalized to zero. -1 usually means
|
12776 |
+
* the request was aborted, e.g. using a `config.timeout`. More information
|
12777 |
+
* about the status might be available in the `xhrStatus` property.
|
12778 |
+
*
|
12779 |
+
* Note that if the response is a redirect, XMLHttpRequest will transparently
|
12780 |
+
* follow it, meaning that the outcome (success or error) will be determined
|
12781 |
+
* by the final response status code.
|
12782 |
+
*
|
12783 |
+
*
|
12784 |
+
* @property {Array.<Object>} pendingRequests Array of config objects for currently pending
|
12785 |
+
* requests. This is primarily meant to be used for debugging purposes.
|
12786 |
+
*
|
12787 |
+
*
|
12788 |
+
* @example
|
12789 |
+
<example module="httpExample" name="http-service">
|
12790 |
+
<file name="index.html">
|
12791 |
+
<div ng-controller="FetchController">
|
12792 |
+
<select ng-model="method" aria-label="Request method">
|
12793 |
+
<option>GET</option>
|
12794 |
+
<option>JSONP</option>
|
12795 |
+
</select>
|
12796 |
+
<input type="text" ng-model="url" size="80" aria-label="URL" />
|
12797 |
+
<button id="fetchbtn" ng-click="fetch()">fetch</button><br>
|
12798 |
+
<button id="samplegetbtn" ng-click="updateModel('GET', 'http-hello.html')">Sample GET</button>
|
12799 |
+
<button id="samplejsonpbtn"
|
12800 |
+
ng-click="updateModel('JSONP',
|
12801 |
+
'https://angularjs.org/greet.php?name=Super%20Hero')">
|
12802 |
+
Sample JSONP
|
12803 |
+
</button>
|
12804 |
+
<button id="invalidjsonpbtn"
|
12805 |
+
ng-click="updateModel('JSONP', 'https://angularjs.org/doesntexist')">
|
12806 |
+
Invalid JSONP
|
12807 |
+
</button>
|
12808 |
+
<pre>http status code: {{status}}</pre>
|
12809 |
+
<pre>http response data: {{data}}</pre>
|
12810 |
+
</div>
|
12811 |
+
</file>
|
12812 |
+
<file name="script.js">
|
12813 |
+
angular.module('httpExample', [])
|
12814 |
+
.config(['$sceDelegateProvider', function($sceDelegateProvider) {
|
12815 |
// We must whitelist the JSONP endpoint that we are using to show that we trust it
|
12816 |
$sceDelegateProvider.resourceUrlWhitelist([
|
12817 |
'self',
|
12818 |
'https://angularjs.org/**'
|
12819 |
]);
|
12820 |
}])
|
12821 |
+
.controller('FetchController', ['$scope', '$http', '$templateCache',
|
12822 |
+
function($scope, $http, $templateCache) {
|
12823 |
$scope.method = 'GET';
|
12824 |
$scope.url = 'http-hello.html';
|
12825 |
|
12842 |
$scope.url = url;
|
12843 |
};
|
12844 |
}]);
|
12845 |
+
</file>
|
12846 |
+
<file name="http-hello.html">
|
12847 |
+
Hello, $http!
|
12848 |
+
</file>
|
12849 |
+
<file name="protractor.js" type="protractor">
|
12850 |
+
var status = element(by.binding('status'));
|
12851 |
+
var data = element(by.binding('data'));
|
12852 |
+
var fetchBtn = element(by.id('fetchbtn'));
|
12853 |
+
var sampleGetBtn = element(by.id('samplegetbtn'));
|
12854 |
+
var invalidJsonpBtn = element(by.id('invalidjsonpbtn'));
|
12855 |
+
|
12856 |
+
it('should make an xhr GET request', function() {
|
12857 |
sampleGetBtn.click();
|
12858 |
fetchBtn.click();
|
12859 |
expect(status.getText()).toMatch('200');
|
12860 |
expect(data.getText()).toMatch(/Hello, \$http!/);
|
12861 |
});
|
12862 |
|
12863 |
+
// Commented out due to flakes. See https://github.com/angular/angular.js/issues/9185
|
12864 |
+
// it('should make a JSONP request to angularjs.org', function() {
|
12865 |
// var sampleJsonpBtn = element(by.id('samplejsonpbtn'));
|
12866 |
// sampleJsonpBtn.click();
|
12867 |
// fetchBtn.click();
|
12869 |
// expect(data.getText()).toMatch(/Super Hero!/);
|
12870 |
// });
|
12871 |
|
12872 |
+
it('should make JSONP request to invalid URL and invoke the error handler',
|
12873 |
+
function() {
|
12874 |
invalidJsonpBtn.click();
|
12875 |
fetchBtn.click();
|
12876 |
expect(status.getText()).toMatch('0');
|
12877 |
expect(data.getText()).toMatch('Request failed');
|
12878 |
});
|
12879 |
+
</file>
|
12880 |
+
</example>
|
12881 |
+
*/
|
12882 |
+
function $http(requestConfig) {
|
12883 |
|
12884 |
+
if (!isObject(requestConfig)) {
|
12885 |
+
throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig);
|
12886 |
+
}
|
12887 |
|
12888 |
+
if (!isString($sce.valueOf(requestConfig.url))) {
|
12889 |
+
throw minErr('$http')('badreq', 'Http request configuration url must be a string or a $sce trusted object. Received: {0}', requestConfig.url);
|
12890 |
+
}
|
12891 |
|
12892 |
+
var config = extend({
|
12893 |
+
method: 'get',
|
12894 |
+
transformRequest: defaults.transformRequest,
|
12895 |
+
transformResponse: defaults.transformResponse,
|
12896 |
+
paramSerializer: defaults.paramSerializer,
|
12897 |
+
jsonpCallbackParam: defaults.jsonpCallbackParam
|
12898 |
+
}, requestConfig);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12899 |
|
12900 |
+
config.headers = mergeHeaders(requestConfig);
|
12901 |
+
config.method = uppercase(config.method);
|
12902 |
+
config.paramSerializer = isString(config.paramSerializer) ?
|
12903 |
+
$injector.get(config.paramSerializer) : config.paramSerializer;
|
12904 |
|
12905 |
+
$browser.$$incOutstandingRequestCount('$http');
|
12906 |
|
12907 |
+
var requestInterceptors = [];
|
12908 |
+
var responseInterceptors = [];
|
12909 |
+
var promise = $q.resolve(config);
|
12910 |
|
12911 |
+
// apply interceptors
|
12912 |
+
forEach(reversedInterceptors, function(interceptor) {
|
12913 |
+
if (interceptor.request || interceptor.requestError) {
|
12914 |
+
requestInterceptors.unshift(interceptor.request, interceptor.requestError);
|
12915 |
+
}
|
12916 |
+
if (interceptor.response || interceptor.responseError) {
|
12917 |
+
responseInterceptors.push(interceptor.response, interceptor.responseError);
|
12918 |
+
}
|
12919 |
+
});
|
12920 |
|
12921 |
+
promise = chainInterceptors(promise, requestInterceptors);
|
12922 |
+
promise = promise.then(serverRequest);
|
12923 |
+
promise = chainInterceptors(promise, responseInterceptors);
|
12924 |
+
promise = promise.finally(completeOutstandingRequest);
|
12925 |
|
12926 |
+
return promise;
|
12927 |
|
|
|
|
|
12928 |
|
12929 |
+
function chainInterceptors(promise, interceptors) {
|
12930 |
+
for (var i = 0, ii = interceptors.length; i < ii;) {
|
12931 |
+
var thenFn = interceptors[i++];
|
12932 |
+
var rejectFn = interceptors[i++];
|
12933 |
|
12934 |
+
promise = promise.then(thenFn, rejectFn);
|
12935 |
+
}
|
12936 |
|
12937 |
+
interceptors.length = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12938 |
|
12939 |
+
return promise;
|
12940 |
+
}
|
12941 |
|
12942 |
+
function completeOutstandingRequest() {
|
12943 |
+
$browser.$$completeOutstandingRequest(noop, '$http');
|
12944 |
+
}
|
|
|
12945 |
|
12946 |
+
function executeHeaderFns(headers, config) {
|
12947 |
+
var headerContent, processedHeaders = {};
|
12948 |
|
12949 |
+
forEach(headers, function(headerFn, header) {
|
12950 |
+
if (isFunction(headerFn)) {
|
12951 |
+
headerContent = headerFn(config);
|
12952 |
+
if (headerContent != null) {
|
12953 |
+
processedHeaders[header] = headerContent;
|
12954 |
+
}
|
12955 |
+
} else {
|
12956 |
+
processedHeaders[header] = headerFn;
|
12957 |
+
}
|
12958 |
+
});
|
12959 |
|
12960 |
+
return processedHeaders;
|
12961 |
+
}
|
|
|
|
|
|
|
12962 |
|
12963 |
+
function mergeHeaders(config) {
|
12964 |
+
var defHeaders = defaults.headers,
|
12965 |
+
reqHeaders = extend({}, config.headers),
|
12966 |
+
defHeaderName, lowercaseDefHeaderName, reqHeaderName;
|
12967 |
|
12968 |
+
defHeaders = extend({}, defHeaders.common, defHeaders[lowercase(config.method)]);
|
|
|
|
|
12969 |
|
12970 |
+
// using for-in instead of forEach to avoid unnecessary iteration after header has been found
|
12971 |
+
defaultHeadersIteration:
|
12972 |
+
for (defHeaderName in defHeaders) {
|
12973 |
+
lowercaseDefHeaderName = lowercase(defHeaderName);
|
12974 |
|
12975 |
+
for (reqHeaderName in reqHeaders) {
|
12976 |
+
if (lowercase(reqHeaderName) === lowercaseDefHeaderName) {
|
12977 |
+
continue defaultHeadersIteration;
|
12978 |
+
}
|
12979 |
+
}
|
|
|
|
|
|
|
12980 |
|
12981 |
+
reqHeaders[defHeaderName] = defHeaders[defHeaderName];
|
12982 |
+
}
|
|
|
12983 |
|
12984 |
+
// execute if header value is a function for merged headers
|
12985 |
+
return executeHeaderFns(reqHeaders, shallowCopy(config));
|
12986 |
+
}
|
12987 |
|
12988 |
+
function serverRequest(config) {
|
12989 |
+
var headers = config.headers;
|
12990 |
+
var reqData = transformData(config.data, headersGetter(headers), undefined, config.transformRequest);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12991 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|