@@ -294,10 +294,12 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
294
294
*
295
295
* @returns {obj } an `$mdDialogPreset` with the chainable configuration methods:
296
296
*
297
- * - $mdDialogPreset#title(string) - sets title to string
298
- * - $mdDialogPreset#content(string) - sets content / message to string
299
- * - $mdDialogPreset#ok(string) - sets okay button text to string
300
- * - $mdDialogPreset#theme(string) - sets the theme of the dialog
297
+ * - $mdDialogPreset#title(string) - Sets the alert title.
298
+ * - $mdDialogPreset#textContent(string) - Sets the alert message.
299
+ * - $mdDialogPreset#htmlContent(string) - Sets the alert message as HTML. Requires ngSanitize
300
+ * module to be loaded. HTML is not run through Angular's compiler.
301
+ * - $mdDialogPreset#ok(string) - Sets the alert "Okay" button text.
302
+ * - $mdDialogPreset#theme(string) - Sets the theme of the alert dialog.
301
303
*
302
304
*/
303
305
@@ -313,11 +315,13 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
313
315
*
314
316
* Additionally, it supports the following methods:
315
317
*
316
- * - $mdDialogPreset#title(string) - sets title to string
317
- * - $mdDialogPreset#content(string) - sets content / message to string
318
- * - $mdDialogPreset#ok(string) - sets okay button text to string
319
- * - $mdDialogPreset#cancel(string) - sets cancel button text to string
320
- * - $mdDialogPreset#theme(string) - sets the theme of the dialog
318
+ * - $mdDialogPreset#title(string) - Sets the confirm title.
319
+ * - $mdDialogPreset#textContent(string) - Sets the confirm message.
320
+ * - $mdDialogPreset#htmlContent(string) - Sets the confirm message as HTML. Requires ngSanitize
321
+ * module to be loaded. HTML is not run through Angular's compiler.
322
+ * - $mdDialogPreset#ok(string) - Sets the confirm "Okay" button text.
323
+ * - $mdDialogPreset#cancel(string) - Sets the confirm "Cancel" button text.
324
+ * - $mdDialogPreset#theme(string) - Sets the theme of the confirm dialog.
321
325
*
322
326
*/
323
327
@@ -332,7 +336,9 @@ function MdDialogDirective($$rAF, $mdTheming, $mdDialog) {
332
336
* `confirm()`, or an options object with the following properties:
333
337
* - `templateUrl` - `{string=}`: The url of a template that will be used as the content
334
338
* of the dialog.
335
- * - `template` - `{string=}`: Same as templateUrl, except this is an actual template string.
339
+ * - `template` - `{string=}`: HTML template to show in the dialog. This **must** be trusted HTML
340
+ * with respect to Angular's [$sce service](https://docs.angularjs.org/api/ng/service/$sce).
341
+ * This template should **never** be constructed with any kind of user input or user data.
336
342
* - `autoWrap` - `{boolean=}`: Whether or not to automatically wrap the template with a
337
343
* `<md-dialog>` tag if one is not provided. Defaults to true. Can be disabled if you provide a
338
344
* custom dialog directive.
@@ -416,11 +422,11 @@ function MdDialogProvider($$interimElementProvider) {
416
422
options : dialogDefaultOptions
417
423
} )
418
424
. addPreset ( 'alert' , {
419
- methods : [ 'title' , 'content ' , 'ariaLabel' , 'ok' , 'theme' , 'css' ] ,
425
+ methods : [ 'title' , 'htmlContent' , 'textContent ', 'ariaLabel' , 'ok' , 'theme' , 'css' ] ,
420
426
options : advancedDialogOptions
421
427
} )
422
428
. addPreset ( 'confirm' , {
423
- methods : [ 'title' , 'content ' , 'ariaLabel' , 'ok' , 'cancel' , 'theme' , 'css' ] ,
429
+ methods : [ 'title' , 'htmlContent' , 'textContent ', 'ariaLabel' , 'ok' , 'cancel' , 'theme' , 'css' ] ,
424
430
options : advancedDialogOptions
425
431
} ) ;
426
432
@@ -431,7 +437,11 @@ function MdDialogProvider($$interimElementProvider) {
431
437
'<md-dialog md-theme="{{ dialog.theme }}" aria-label="{{ dialog.ariaLabel }}" ng-class="dialog.css">' ,
432
438
' <md-dialog-content class="md-dialog-content" role="document" tabIndex="-1">' ,
433
439
' <h2 class="md-title">{{ dialog.title }}</h2>' ,
434
- ' <div class="md-dialog-content-body" md-template="::dialog.mdContent"></div>' ,
440
+ ' <div ng-if="::dialog.mdHtmlContent" class="md-dialog-content-body" ' ,
441
+ ' ng-bind-html="::dialog.mdHtmlContent"></div>' ,
442
+ ' <div ng-if="::!dialog.mdHtmlContent" class="md-dialog-content-body">' ,
443
+ ' <p>{{::dialog.mdTextContent}}</p>' ,
444
+ ' </div>' ,
435
445
' </md-dialog-content>' ,
436
446
' <md-dialog-actions>' ,
437
447
' <md-button ng-if="dialog.$type == \'confirm\'"' +
@@ -459,11 +469,12 @@ function MdDialogProvider($$interimElementProvider) {
459
469
}
460
470
461
471
/* @ngInject */
462
- function dialogDefaultOptions ( $mdDialog , $mdAria , $mdUtil , $mdConstant , $animate , $document , $window , $rootElement , $log ) {
472
+ function dialogDefaultOptions ( $mdDialog , $mdAria , $mdUtil , $mdConstant , $animate , $document , $window , $rootElement , $log , $injector ) {
463
473
return {
464
474
hasBackdrop : true ,
465
475
isolateScope : true ,
466
476
onShow : onShow ,
477
+ onShowing : beforeShow ,
467
478
onRemove : onRemove ,
468
479
clickOutsideToClose : false ,
469
480
escapeToClose : true ,
@@ -489,14 +500,25 @@ function MdDialogProvider($$interimElementProvider) {
489
500
}
490
501
} ;
491
502
492
- /**
493
- * Show method for dialogs
494
- */
503
+ function beforeShow ( scope , element , options , controller ) {
504
+ if ( controller ) {
505
+ controller . mdHtmlContent = controller . htmlContent || options . htmlContent || '' ;
506
+ controller . mdTextContent = controller . textContent || options . textContent || '' ;
507
+
508
+ if ( controller . mdHtmlContent && ! $injector . has ( '$sanitize' ) ) {
509
+ throw Error ( 'The ngSanitize module must be loaded in order to use htmlContent.' ) ;
510
+ }
511
+
512
+ if ( controller . mdHtmlContent && controller . mdTextContent ) {
513
+ throw Error ( 'md-dialog cannot have both `htmlContent` and `textContent`' ) ;
514
+ }
515
+ }
516
+ }
517
+
518
+ /** Show method for dialogs */
495
519
function onShow ( scope , element , options , controller ) {
496
520
angular . element ( $document [ 0 ] . body ) . addClass ( 'md-dialog-is-showing' ) ;
497
521
498
- wrapSimpleContent ( ) ;
499
-
500
522
captureParentAndFromToElements ( options ) ;
501
523
configureAria ( element . find ( 'md-dialog' ) , options ) ;
502
524
showBackdrop ( scope , element , options ) ;
@@ -548,27 +570,6 @@ function MdDialogProvider($$interimElementProvider) {
548
570
return angular . element ( closeButton ) ;
549
571
}
550
572
}
551
-
552
- /**
553
- * Wrap any simple content [specified via .content("")] in <p></p> tags.
554
- * otherwise accept HTML content within the dialog content area...
555
- * NOTE: Dialog uses the md-template directive to safely inject HTML content.
556
- */
557
- function wrapSimpleContent ( ) {
558
- if ( controller ) {
559
- var HTML_END_TAG = / < \/ [ \w - ] * > / gm;
560
- var content = controller . content || options . content || "" ;
561
-
562
- var hasHTML = HTML_END_TAG . test ( content ) ;
563
- if ( ! hasHTML ) {
564
- content = $mdUtil . supplant ( "<p>{0}</p>" , [ content ] ) ;
565
- }
566
-
567
- // Publish updated dialog content body... to be compiled by mdTemplate directive
568
- controller . mdContent = content ;
569
- }
570
- }
571
-
572
573
}
573
574
574
575
/**
0 commit comments