Skip to content

Commit 4d473e4

Browse files
committed
MOBILE-1275 modules: Show full description in new view
1 parent 5e7323c commit 4d473e4

File tree

8 files changed

+108
-45
lines changed

8 files changed

+108
-45
lines changed

www/addons/mod_imscp/directives/bar.js

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ angular.module('mm.addons.mod_imscp')
2828
* @param {String} next ID of the next item.
2929
* @param {Function} action Function to call when an arrow is clicked. Will receive as a param the itemId to load.
3030
*/
31-
.directive('mmaModImscpBar', function($ionicModal) {
31+
.directive('mmaModImscpBar', function($state, $translate) {
3232
return {
3333
restrict: 'E',
3434
scope: {
@@ -39,20 +39,12 @@ angular.module('mm.addons.mod_imscp')
3939
},
4040
templateUrl: 'addons/mod_imscp/templates/bar.html',
4141
link: function(scope) {
42-
$ionicModal.fromTemplateUrl('addons/mod_imscp/templates/description.html', {
43-
scope: scope,
44-
animation: 'slide-in-up'
45-
}).then(function(modal) {
46-
scope.showDescription = function() {
47-
modal.show();
48-
};
49-
scope.closeDescription = function() {
50-
modal.hide();
51-
};
52-
scope.$on('$destroy', function() {
53-
modal.remove();
42+
scope.showDescription = function() {
43+
$state.go('site.mm_textviewer', {
44+
title: $translate.instant('mm.core.description'),
45+
content: scope.description
5446
});
55-
});
47+
};
5648
}
5749
};
5850
});

www/addons/mod_imscp/templates/description.html

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="card" ng-if="description">
22
<div class="item item-text-wrap item-body">
3-
<mm-format-text class="mm-content-with-float">{{ description }}</mm-format-text>
3+
<mm-format-text class="mm-content-with-float" shorten="100" fullview-on-click="true">{{ description }}</mm-format-text>
44
<p ng-if="note"><span class="item-note">{{ note }}</span></p>
55
</div>
66
</div>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.core.textviewer')
16+
17+
/**
18+
* Text viewer controller.
19+
*
20+
* @module mm.core.textviewer
21+
* @ngdoc controller
22+
* @name mmTextViewerIndexCtrl
23+
*/
24+
.controller('mmTextViewerIndexCtrl', function($stateParams, $scope) {
25+
$scope.title = $stateParams.title;
26+
$scope.content = $stateParams.content;
27+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// (C) Copyright 2015 Martin Dougiamas
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
angular.module('mm.core.textviewer', [])
16+
17+
.config(function($stateProvider) {
18+
19+
$stateProvider
20+
21+
.state('site.mm_textviewer', {
22+
url: '/mm_textviewer',
23+
params: {
24+
title: null,
25+
content: null
26+
},
27+
views: {
28+
'site': {
29+
templateUrl: 'core/components/textviewer/templates/textviewer.html',
30+
controller: 'mmTextViewerIndexCtrl'
31+
}
32+
}
33+
});
34+
35+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<ion-view>
2+
<ion-nav-title>{{ title }}</ion-nav-title>
3+
<ion-content class="padding">
4+
<mm-format-text class="mm-content-with-float">{{ content }}</mm-format-text>
5+
</ion-content>
6+
</ion-view>

www/core/directives/formattext.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

www/core/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"choose": "Choose",
1010
"clearsearch": "Clear search",
1111
"clicktohideshow": "Click to expand or collapse",
12+
"clicktoseefull": "Click to see full contents.",
1213
"close": "Close",
1314
"completion-alt-auto-fail": "Completed: {{$a}} (did not achieve pass grade)",
1415
"completion-alt-auto-n": "Not completed: {{$a}}",

0 commit comments

Comments
 (0)