@@ -30,10 +30,11 @@ angular.module('mm.core')
3030 * -singleline: True if new lines should be removed (all the text in a single line). Only valid if clean is true.
3131 * -shorten: Number of characters to shorten the text.
3232 * -expand-on-click: Indicate if contents should be expanded on click (undo shorten). Only applied if "shorten" is set.
33+ * -fullview-on-click: Indicate if should open a new state with the full contents on click. Only applied if "shorten" is set.
3334 * -watch: True if the variable used inside the directive should be watched for changes. If the variable data is retrieved
3435 * asynchronously, this value must be set to true, or the directive should be inside a ng-if, ng-repeat or similar.
3536 */
36- . directive ( 'mmFormatText' , function ( $interpolate , $mmText , $compile , $q , $translate ) {
37+ . directive ( 'mmFormatText' , function ( $interpolate , $mmText , $compile , $translate , $state ) {
3738
3839 var extractVariableRegex = new RegExp ( '{{([^|]+)(|.*)?}}' , 'i' ) ,
3940 tagsToIgnore = [ 'AUDIO' , 'VIDEO' , 'BUTTON' , 'INPUT' , 'SELECT' , 'TEXTAREA' , 'A' ] ;
@@ -45,14 +46,23 @@ angular.module('mm.core')
4546 * @param {Object } element Directive root DOM element.
4647 * @param {Object } attrs Directive attributes.
4748 * @param {String } text Directive contents.
48- * @return {Promise } Promise resolved with the formatted text.
49+ * @return {Void }
4950 */
5051 function formatAndRenderContents ( scope , element , attrs , text ) {
51- // If expandOnClick is set we won't shorten the text on interpolateAndFormat, we'll do it later.
52- var shorten = attrs . expandOnClick ? 0 : attrs . shorten ;
5352
54- interpolateAndFormat ( scope , element , attrs , text , shorten ) . then ( function ( fullText ) {
55- if ( attrs . shorten && attrs . expandOnClick ) {
53+ if ( typeof text == 'undefined' ) {
54+ element . removeClass ( 'hide' ) ;
55+ return ;
56+ }
57+
58+ // If expandOnClick or fullviewOnClick are set we won't shorten the text on formatContents, we'll do it later.
59+ var shorten = ( attrs . expandOnClick || attrs . fullviewOnClick ) ? 0 : attrs . shorten ;
60+
61+ text = $interpolate ( text ) ( scope ) ; // "Evaluate" scope variables.
62+ text = text . trim ( ) ;
63+
64+ formatContents ( scope , element , attrs , text , shorten ) . then ( function ( fullText ) {
65+ if ( attrs . shorten && ( attrs . expandOnClick || attrs . fullviewOnClick ) ) {
5666 var shortened = $mmText . shortenText ( $mmText . cleanTags ( fullText , false ) , parseInt ( attrs . shorten ) ) ,
5767 expanded = false ;
5868
@@ -69,7 +79,7 @@ angular.module('mm.core')
6979
7080 if ( hasContent ) {
7181 // The content has meaningful tags. Show a placeholder to expand the content.
72- shortened = $translate . instant ( 'mm.core.clicktohideshow' ) ;
82+ shortened = $translate . instant ( attrs . expandOnClick ? 'mm.core.clicktohideshow' : 'mm.core.clicktoseefull ') ;
7383 }
7484 }
7585
@@ -78,10 +88,19 @@ angular.module('mm.core')
7888 e . stopPropagation ( ) ;
7989 var target = e . target ;
8090 if ( tagsToIgnore . indexOf ( target . tagName ) === - 1 || ( target . tagName === 'A' && ! target . getAttribute ( 'href' ) ) ) {
81- expanded = ! expanded ;
82- element . html ( expanded ? fullText : shortened ) ;
83- if ( expanded ) {
84- $compile ( element . contents ( ) ) ( scope ) ;
91+ if ( attrs . expandOnClick ) {
92+ // Expand/collapse.
93+ expanded = ! expanded ;
94+ element . html ( expanded ? fullText : shortened ) ;
95+ if ( expanded ) {
96+ $compile ( element . contents ( ) ) ( scope ) ;
97+ }
98+ } else {
99+ // Open a new state with the interpolated contents.
100+ $state . go ( 'site.mm_textviewer' , {
101+ title : $translate . instant ( 'mm.core.description' ) ,
102+ content : text
103+ } ) ;
85104 }
86105 }
87106 } ) ;
@@ -94,7 +113,7 @@ angular.module('mm.core')
94113 }
95114
96115 /**
97- * Interpolate contents, apply formatText and set sub-directives.
116+ * Apply formatText and set sub-directives.
98117 *
99118 * @param {Object } scope Directive scope.
100119 * @param {Object } element Directive root DOM element.
@@ -103,20 +122,12 @@ angular.module('mm.core')
103122 * @param {Number } [shorten] Number of characters to shorten contents to. If not defined, don't shorten the text.
104123 * @return {Promise } Promise resolved with the formatted text.
105124 */
106- function interpolateAndFormat ( scope , element , attrs , text , shorten ) {
125+ function formatContents ( scope , element , attrs , text , shorten ) {
107126
108127 var siteId = scope . siteid ,
109128 component = attrs . component ,
110129 componentId = attrs . componentId ;
111130
112- if ( typeof text == 'undefined' ) {
113- element . removeClass ( 'hide' ) ;
114- return $q . reject ( ) ;
115- }
116-
117- text = $interpolate ( text ) ( scope ) ; // "Evaluate" scope variables.
118- text = text . trim ( ) ;
119-
120131 // Apply format text function.
121132 return $mmText . formatText ( text , attrs . clean , attrs . singleline , shorten ) . then ( function ( formatted ) {
122133
0 commit comments